BootSmash.mesa
Russ Atkinson, May 31, 1984 2:22:34 am PDT
DIRECTORY
Commander, CommandTool, FS, IO, Rope;
BootSmash: CEDAR PROGRAM
IMPORTS Commander, CommandTool, FS, IO, Rope = {OPEN IO, ROPE;
Smash: Commander.CommandProc = {
names: LIST OF Rope.ROPE = CommandTool.ParseToList[cmd];
buffer: REF TEXT = NEW[TEXT[512]];
FOR each: LIST OF Rope.ROPE ← names, each.rest WHILE each # NIL DO
inStream, outStream: IO.STREAMNIL;
name: ROPE = each.first;
bytes: NAT ← 0;
timeBytes: PACKED ARRAY [0..3] OF CARDINAL =
LOOPHOLE[BasicTime.ToPupTime[BasicTime.Now[]]];
IF Rope.Equal[name, "-n", FALSE] THEN {useNebula ← TRUE; LOOP};
IO.PutF[cmd.out, "Open %g", [rope[name]]];
inStream ← FS.StreamOpen[name
! FS.Error => {IO.PutF[cmd.out, "\n Error - %g\n", [rope[error.explanation]]]; LOOP};
];
outStream ← FS.StreamOpen[
IF useNebula THEN Rope.Concat["/Nebula//", name] ELSE name, create
! FS.Error => {IO.PutF[cmd.out, "\n Error - %g\n", [rope[error.explanation]]]; LOOP};
];
IO.PutRope[cmd.out, " ."];
bytes ← IO.GetBlock[inStream, buffer, 0, 512];
We must scramble a certain 4 bytes in the file to be a funny-format date.
buffer[6+0] ← timeBytes[2];
buffer[6+1] ← timeBytes[3];
buffer[6+2] ← timeBytes[0];
buffer[6+3] ← timeBytes[1];
DO
IO.PutRope[cmd.out, "."];
IO.PutBlock[outStream, buffer, 0, bytes];
bytes ← IO.GetBlock[inStream, buffer, 0, 512 ! IO.EndOfStream => EXIT];
ENDLOOP;
IO.Close[outStream];
IO.Close[inStream];
IO.PutRope[cmd.out, "\n"];
ENDLOOP;
};
Commander.Register[
"SmashBoot", Smash, "Smashes the date of a boot file so we can propagate changes."];
}.