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
PupDefs.PupNameTrouble => {
cmd.err.PutF[" %g ", IO.rope[e]];
LOOP;
};
host: ROPE ← cmdStream.GetTokenRope[IO.IDProc].token;
name: ROPE;
address: PupDefs.PupAddress;
someArgs ← TRUE;
address ← PupDefs.GetPupAddress[PupTypes.fillInSocketID, host];
name ← PupDefs.GetHostName[address];
cmd.out.PutF[" %g(%g)", IO.rope[name], IO.rope[PupDefs.PupAddressToRope[address]]];
ENDLOOP;
IF
NOT someArgs
THEN {
address: PupDefs.PupAddress ← PupDefs.AnyLocalPupAddress[PupTypes.fillInSocketID];
name: ROPE ← PupDefs.GetMyName[];
address.socket ← PupTypes.fillInSocketID;
cmd.out.PutF["%g(%g)", IO.rope[name], IO.rope[PupDefs.PupAddressToRope[address]]];
};
cmd.out.PutRope["\n"];
};
Commander.Register["HostName", HostNameCmd, "gives name and address of given hosts, or self if no args"];
}.