SetDateLikeRemote.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Russ Atkinson, March 12, 1985 3:19:51 pm PST
SetDateLikeRemote:
CEDAR PROGRAM
IMPORTS Commander, FS, IO, Rope = BEGIN
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
SetDateLikeRemoteCommand: Commander.CommandProc = {
cmdStream: STREAM = IO.RIS[cmd.commandLine];
remoteName,localName: ROPE ← NIL;
remoteName ←
IO.GetTokenRope[cmdStream,
IO.IDProc
! IO.EndOfStream => GO TO badUsage].token;
localName ←
IO.GetTokenRope[cmdStream,
IO.IDProc
! IO.EndOfStream => CONTINUE].token;
IF Rope.Length[localName] = 0
THEN {
Use the short version of the remote name
bang: INT ← Rope.Length[remoteName];
pos: INT ← bang;
WHILE pos > 0
DO
pos ← pos - 1;
SELECT Rope.Fetch[remoteName, pos]
FROM
'>, '], '/ => {pos ← pos + 1; EXIT};
'! => bang ← pos;
ENDCASE;
ENDLOOP;
localName ← Rope.Flatten[remoteName, pos, bang - pos];
};
{
ENABLE
FS.Error =>
IF error.group # bug
THEN {msg ← error.explanation;
GO
TO fail};
remote: FS.OpenFile ← FS.Open[remoteName];
local: FS.OpenFile ← FS.Open[localName, $write];
time: BasicTime.GMT ← FS.GetInfo[remote].created;
FS.SetByteCountAndCreatedTime[local, -1, time];
FS.Close[local];
FS.Close[remote];
};
GO TO quit;
EXITS
badUsage => msg ← "Usage error: SetDateLikeRemote remote local\n";
quit => msg ← "\n";
fail => result ← $Failure;
};
Commander.Register["SetDateLikeRemote", SetDateLikeRemoteCommand, "[SetDateLikeRemote remote local] sets the create date of the local file to be the same as the given remote file."];