HostNameCmd:
PROC [cmd: Commander.Handle]
RETURNS [result:
REF
ANY ←
NIL, msg:
ROPE ←
NIL]
--Commander.CommandProc-- = {
cmdStream: IO.STREAM ← IO.RIS[cmd.commandLine];
someArgs: BOOL ← FALSE;
FOR i:
INT ← cmdStream.SkipWhitespace[], cmdStream.SkipWhitespace[]
WHILE
NOT cmdStream.EndOf[]
DO
ENABLE
PupName.Error => {
cmd.err.PutF[" %g ", IO.rope[text]];
LOOP;
};
host: ROPE ← cmdStream.GetTokenRope[IO.IDProc].token;
name: ROPE;
address: Pup.Address;
someArgs ← TRUE;
address ← PupName.NameLookup[host, Pup.nullSocket];
name ← PupName.HisName[address];
cmd.out.PutF[" %g(%g)", IO.rope[name], IO.rope[PupName.AddressToRope[address]]];
ENDLOOP;
IF
NOT someArgs
THEN {
cmd.out.PutF["%g(%g)", IO.rope[PupName.MyName[]], IO.rope[PupName.MyRope[]]];
};
cmd.out.PutRope["\n"];
};
Commander.Register["HostName", HostNameCmd, "gives name and address of given hosts, or self if no args"];
}.