HostNameImpl.mesa
Spreitzer, August 13, 1985 10:47:26 am PDT
Hal Murray, April 16, 1986 1:31:36 am PST
DIRECTORY Commander, IO, Pup, PupName, Rope;
HostName: CEDAR PROGRAM IMPORTS Commander, IO, PupName = {
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
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"];
}.