HostNameImpl.mesa
Spreitzer, August 13, 1985 10:47:26 am PDT
DIRECTORY Commander, IO, PupDefs, PupTypes, Rope;
HostName: CEDAR PROGRAM IMPORTS Commander, IO, PupDefs = {
ROPE: TYPE = Rope.ROPE;
HostNameCmd: PROC [cmd: Commander.Handle] RETURNS [result: REF ANYNIL, msg: ROPENIL] --Commander.CommandProc-- = {
cmdStream: IO.STREAMIO.RIS[cmd.commandLine];
someArgs: BOOLFALSE;
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"];
}.