FixIFSFileDate.mesa
Copyright (C) 1984, Xerox Corporation. All rights reserved.
Last edited by Tim Diebert: November 29, 1984 7:21:08 am PST
DIRECTORY
Ascii,
BasicTime USING [earliestGMT, Unpacked, Unpack, nullGMT, Now, GMT],
Commander USING [CommandProc, Register],
FS USING [ComponentPositions, ExpandName, Error],
IO USING [BreakProc, int, GetTokenRope, EndOfStream, noWhereStream, PutFR, PutF, PutRope, RIS, rope, STREAM],
STP USING [Close, Create, Error, Open, Login, Handle],
STPOps USING [Handle, CheckConnection, ResetPList, UserStateToPList, NameToPList, PutPList, GetCommand, GenerateProtocolError, GenerateErrorString, markRename, MyGetMark, markEOC, markYes],
Rope USING [IsEmpty, ROPE, Substr],
UserCredentials USING [Get];
FixFileDate: CEDAR PROGRAM
IMPORTS BasicTime, Commander, FS, IO, Rope, STP, STPOps, UserCredentials
= BEGIN OPEN Ascii;
ROPE: TYPE ~ Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
Break: IO.BreakProc = BEGIN
RETURN[SELECT char FROM
IN [NUL .. SP], ',, ':, '; => sepr,
ENDCASE => other]
END;
FixIt: PUBLIC PROC
[fullFName: ROPE, messageStream: STREAMNIL]
RETURNS [BOOL] = BEGIN
stp: STP.Handle ← STP.Create[];
cp: FS.ComponentPositions;
name, password, fileName: ROPE;
IF messageStream = NIL THEN messageStream ← IO.noWhereStream;
messageStream.PutF["Fixing %g ... \n", IO.rope[fullFName]];
BEGIN -- For Enable
[cp: cp, fullFName: fullFName] ← FS.ExpandName[fullFName
! FS.Error => {messageStream.PutF["%g\n", IO.rope[error.explanation]]; GOTO Out1;}];
IF cp.ver.length = 0 THEN
{messageStream.PutRope["Version not specified\n"]; RETURN [FALSE]; };
messageStream.PutF["%g\n", IO.rope[stp.Open[fullFName.Substr[cp.server.start, cp.server.length]]]];
fileName ← fullFName.Substr[cp.server.start + cp.server.length + 1];
[name, password] ← UserCredentials.Get[];
stp.Login[name, password];
TRUSTED {Rename[LOOPHOLE[stp], fileName
! STP.Error => BEGIN
messageStream.PutF["Error: %g\n", IO.rope[error]];
GOTO Out;
END]; };
stp.Close[];
messageStream.PutRope[" Done.\n"];
RETURN[TRUE];
EXITS
Out => {stp.Close[]; RETURN [FALSE];};
Out1 => RETURN [FALSE];
END;
END;
Rename: PUBLIC PROCEDURE [stp: STPOps.Handle, name: Rope.ROPE] =
BEGIN OPEN STPOps;
mark, saveMark: [0..256);
code: CHARACTER ← 0C;
newTime: ROPE ← GMTToFTPDate[BasicTime.earliestGMT];
CheckConnection[stp];
ResetPList[stp.plist];
UserStateToPList[stp];
NameToPList[stp.plist, name, alto];
PutPList[stp, markRename, FALSE];
ResetPList[stp.plist];
UserStateToPList[stp];
NameToPList[stp.plist, name, alto];
stp.plist[createDate] ← newTime;
PutPList[stp, 0B];
[saveMark, code, stp.remoteString] ← GetCommand[stp];
IF (mark ← MyGetMark[stp]) # markEOC THEN
GenerateProtocolError[stp, eocExpected, mark];
IF saveMark # markYes THEN
GenerateErrorString[stp, requestRefused, stp.remoteString, code];
END;
GMTToFTPDate: PROC[gmt: BasicTime.GMT← BasicTime.nullGMT] RETURNS[date: ROPE] =
-- generates ftp standard time, dd-mmm-yy hh:mm:ss zzz
BEGIN OPEN IO;
upt: BasicTime.Unpacked ←
BasicTime.Unpack[IF gmt = BasicTime.nullGMT THEN BasicTime.Now[] ELSE gmt];
zone: ROPE;
month, tyme, year: ROPE;
timeFormat: ROPE = "%02g:%02g:%02g %g"; -- "hh:mm:ss zzz"
dateFormat: ROPE = "%2g-%g-%g %g";  -- "dd-mmm-yy timeFormat"
arpaNeg: BOOL← upt.zone > 0;
aZone: INTABS[upt.zone];
zDif: INT← aZone / 60;
zMul: INT← zDif * 60;
IF (zMul = aZone) AND arpaNeg THEN
BEGIN IF upt.dst = yes
THEN
SELECT zDif FROM
0 => zone← "UT";
4 => zone← "EDT";
5 => zone← "CDT";
6 => zone← "MDT";
8 => zone← "PDT";
ENDCASE
ELSE
SELECT zDif FROM
0 => zone← "UT";
5 => zone← "EST";
6 => zone← "CST";
7 => zone← "MST";
8 => zone← "PST";
ENDCASE;
END;
IF zone = NIL THEN BEGIN
mm: INT← aZone - zMul;
zone← PutFR[IF arpaNeg THEN "-%02g%02g" ELSE "+%02g%02g", int[zDif], int[mm]];
END;
SELECT upt.month FROM
January => month← "Jan";
February => month← "Feb";
March => month← "Mar";
April => month← "Apr";
May => month← "May";
June => month← "Jun";
July => month← "Jul";
August => month← "Aug";
September => month← "Sep";
October => month← "Oct";
November => month← "Nov";
December => month← "Dec";
unspecified => ERROR;
ENDCASE => ERROR;
year← Rope.Substr[PutFR[NIL, int[upt.year]], 2];
tyme← PutFR[timeFormat, int[upt.hour], int[upt.minute], int[upt.second], rope[zone]];
date← PutFR[dateFormat, int[upt.day], rope[month], rope[year], rope[tyme]];
END;
FixDate: Commander.CommandProc = BEGIN
stream: IO.STREAM;
newDate, file: ROPENIL;
IF cmd.commandLine.IsEmpty THEN RETURN;
stream ← IO.RIS[cmd.commandLine];
file ← stream.GetTokenRope[Break ! IO.EndOfStream => GOTO BailOut].token;
[] ← FixIt[file, cmd.out];
EXITS
BailOut => RETURN;
END;
Commander.Register["FixDate", FixDate, "Fix IFS Create date\nUsage FixDate [Indigo]<Diebert>Junk.tioga!3\n"];
END........