ShrinkWrapCommands.mesa
Copyright Ó 1992 by Xerox Corporation. All rights reserved.
Michael Plass, September 30, 1992 11:33 am PDT
Foote, October 26, 1992 11:46 am PST
DIRECTORY Basics, Commander, Convert, FileNames, Rope, IO, PFS, PFSNames, PFSBackdoor, SymTab, List, CommanderOps, Process, ProcessProps;
ShrinkWrapCommands: CEDAR PROGRAM
IMPORTS Basics, Commander, Convert, FileNames, Rope, IO, PFS, PFSNames, PFSBackdoor, SymTab, List, CommanderOps, Process, ProcessProps
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
log: REF READONLY PFSBackdoor.Event ¬ NIL;
StartLog: PROC ~ { log ¬ PFSBackdoor.NextEvent[] };
StartShrinkWrapLoggingCommand: Commander.CommandProc ~ {
log ¬ NIL;
Process.Detach[FORK StartLog];
Commander.Register["ShrinkWrapFilesList", ShrinkWrapFilesListCommand, "List all files referenced since StartShrinkWrapLogging command"];
Commander.Register["ShrinkWrapStop", ShrinkWrapStopCommand, "Usage: ShrinkWrapStop <packagedWorldName> <initialCommand>"];
Commander.Register["ShrinkWrapDF", ShrinkWrapDFCommand, "Usage: ShrinkWrapStop <packagedWorldName>"];
};
PutFilesList: PROC [s: IO.STREAM, files: LIST OF REF] ~ {
curDir: ROPE ¬ NIL;
FOR tail: LIST OF REF ¬ files, tail.rest UNTIL tail = NIL DO
fullName: ROPE ~ NARROW[NARROW[tail.first, LIST OF REF].first];
baseStart: INT ~ Rope.FindBackward[fullName, "/"] + 1;
IF Rope.Size[curDir] # baseStart OR Rope.Run[curDir, 0, fullName] # baseStart THEN {
curDir ¬ Rope.Substr[fullName, 0, baseStart];
IO.PutRope[s, curDir];
IO.PutRope[s, "\n"];
};
IO.PutRope[s, " "];
IO.PutRope[s, fullName];
IO.PutRope[s, "\n"];
ENDLOOP;
};
WriteFilesList: PROC [filename: ROPE, files: LIST OF REF] ~ {
s: IO.STREAM ~ PFS.StreamOpen[PFS.PathFromRope[filename], $create];
PutFilesList[s, files];
IO.Close[s];
};
PutDFFilesList: PROC [s: IO.STREAM, files: LIST OF REF] ~ {
curDir: ROPE ¬ NIL;
FOR tail: LIST OF REF ¬ files, tail.rest UNTIL tail = NIL DO
fullName: ROPE ~ NARROW[NARROW[tail.first, LIST OF REF].first];
base: ROPE ¬ FileNames.GetShortName[fullName];
directory: ROPE ¬ PFS.RopeFromPath[PFS.PathFromRope[FileNames.Directory[fullName]], brackets];
IF NOT Rope.Equal[directory, curDir, FALSE] THEN {
IO.PutF1[s, "\nDirectory %g\n", [rope[directory]]];
curDir ¬ directory;
};
IO.PutF1[s, " %g\n", [rope[base]]];
ENDLOOP;
};
WriteDFFilesList: PROC [filename: ROPE, files: LIST OF REF] ~ {
s: IO.STREAM ~ PFS.StreamOpen[PFS.PathFromRope[filename], $create];
Emit DF header:
IO.PutF1[s, "-- %g\n", [rope[filename]]];
IO.PutRope[s, "-- This file was automatically generated by ShrinkWrapDF\n"];
IO.PutF1[s, "-- on %g\n\n", IO.time[]];
PutDFFilesList[s, files];
IO.Close[s];
};
RepeatRope: PROC [rope: ROPE, n: NAT] RETURNS [list: LIST OF IO.Value ¬ NIL] ~ {
FOR i: NAT IN [0..n) DO
list ¬ CONS[[rope[rope]], list]
ENDLOOP;
};
WriteFilesMakeItFile: PROC [packageName: ROPE] ~ {
s: IO.STREAM ~ PFS.StreamOpen[PFS.PathFromRope[Rope.Concat[packageName, "Files.c.MakeIt"]], $create];
IO.PutFL[s,
"-- %gFiles.c.MakeIt\n-- { %g.files }\nDataCompileC %gFiles.c $(type %g.files)",
RepeatRope[packageName, 4]
];
IO.Close[s];
};
WriteMakeItFile: PROC [packageName: ROPE] ~ {
s: IO.STREAM ~ PFS.StreamOpen[PFS.PathFromRope[Rope.Concat[packageName, ".MakeIt"]], $create];
IO.PutFL[s,
"-- %g.MakeIt\n-- { sun4/%gFiles.o %g.ld}\nsh1 ./%g.ld\n",
RepeatRope[packageName, 4]
];
IO.Close[s];
};
ShrinkWrapFilesListCommand: Commander.CommandProc ~ {
PutFilesList[cmd.out, GetFilesList[]];
};
GetFilesList: PROC RETURNS [LIST OF REF] ~ {
tab: SymTab.Ref ~ SymTab.Create[case: FALSE];
list: LIST OF REF ¬ NIL;
FileOrder: PROC [k: ROPE] RETURNS [CARD] ~ {
RETURN [ORD[Rope.Match["*/sun4/*.o*", k, FALSE] OR Rope.Match["*/*.require*", k, FALSE]]]
};
MyCompare: List.CompareProc ~ {
key1: ROPE ~ NARROW[NARROW[ref1, LIST OF REF].first];
key2: ROPE ~ NARROW[NARROW[ref2, LIST OF REF].first];
low1: CARD ~ ORD[Rope.Match["*/sun4/*.o*", key1, FALSE]];
low2: CARD ~ ORD[Rope.Match["*/sun4/*.o*", key1, FALSE]];
c: Basics.Comparison ¬ Basics.CompareCard[FileOrder[key1], FileOrder[key2]];
IF c = $equal THEN c ¬ Rope.Compare[key1, key2, FALSE];
IF c = $equal THEN c ¬ Rope.Compare[key1, key2, TRUE];
RETURN [c]
};
MakeList: SymTab.EachPairAction ~ {
el: LIST OF REF ¬ LIST[key, val];
list ¬ CONS[el, list];
};
FOR e: REF READONLY PFSBackdoor.Event ¬ log, PFSBackdoor.NextEvent[e] UNTIL e = NIL OR e.chain = NIL DO
SELECT e.op FROM
endRetrieving, endRenaming, endCopying, fileInfo, readOpen => {
[] ¬ SymTab.Insert[tab, PFS.RopeFromPath[e.fName], e.fName]
};
ENDCASE;
ENDLOOP;
[] ¬ SymTab.Pairs[tab, MakeList];
list ¬ List.Sort[list, MyCompare];
RETURN [list]
};
ShrinkWrapStopCommand: Commander.CommandProc ~ {
packageName: ROPE ~ CommanderOps.NextArgument[cmd];
initialCommand: ROPE ~ CommanderOps.NextArgument[cmd];
IF initialCommand = NIL THEN CommanderOps.Failed[cmd.procData.doc];
WriteFilesList[Rope.Concat[packageName, ".files"], GetFilesList[]];
WriteFilesMakeItFile[packageName];
WriteMakeItFile[packageName];
[] ¬ CommanderOps.DoCommand[Rope.Cat["PackageIt ", packageName, " ", Convert.RopeFromRope[initialCommand]], cmd];
};
ShrinkWrapDFCommand: Commander.CommandProc ~ {
packageName: ROPE ~ CommanderOps.NextArgument[cmd];
WriteDFFilesList[Rope.Concat[packageName, ".df"], GetFilesList[]];
};
restoreCedar: ROPE ~ Rope.Concat["PMA ", CommanderOps.DoCommandRope["PMP /cedar", NIL, NIL].out];
restoreCedarRel: ROPE ~ Rope.Concat["PMA ", CommanderOps.DoCommandRope["PMP /cedar10.1", NIL, NIL].out]; -- Hopefully can get rid of this soon.
restoreImagerfonts: ROPE ~ Rope.Concat["PMA ", CommanderOps.DoCommandRope["PMP /imagerfonts", NIL, NIL].out];
NetwiseCedarCommand: Commander.CommandProc ~ {
[] ¬ CommanderOps.DoCommand[restoreCedar, NIL];
[] ¬ CommanderOps.DoCommand[restoreCedarRel, NIL];
};
NetwiseFontsCommand: Commander.CommandProc ~ {
[] ¬ CommanderOps.DoCommand[restoreImagerfonts, NIL];
};
BuiltinCedarCommand: Commander.CommandProc ~ {
[] ¬ CommanderOps.DoCommand["PMA /cedar -compiled:/cedar", NIL];
[] ¬ CommanderOps.DoCommand["PMA /imagerfonts -compiled:/imagerfonts", NIL];
[] ¬ CommanderOps.DoCommand["PMA /cedar10.1 -compiled:/cedar", NIL]; -- Hopefully can get rid of this soon.
};
UseFilesCommand: Commander.CommandProc ~ {
FOR arg: ROPE ¬ CommanderOps.NextArgument[cmd], CommanderOps.NextArgument[cmd] UNTIL arg = NIL DO
ENABLE PFS.Error => {result ¬ $Failure; cmd.err.PutRope[error.explanation]; cmd.err.PutRope["\n"]; LOOP};
n: INT ¬ 0;
Each: PFS.NameProc ~ {
ENABLE PFS.Error => {result ¬ $Failure; cmd.err.PutRope[error.explanation]; cmd.err.PutRope["\n"]; CONTINUE};
file: PFS.OpenFile ~ PFS.Open[name];
PFS.Close[file];
n ¬ n + 1;
};
pattern: PFS.PATH ¬ PFS.PathFromRope[arg];
IF PFSNames.ShortName[pattern].version.versionKind = $none THEN {
pattern ¬ PFSNames.SetVersionNumber[pattern, [versionKind: $highest]];
};
PFS.EnumerateForNames[pattern, Each];
IF n = 0 THEN {
result ¬ $Failure;
cmd.err.PutRope["no files matching "];
cmd.err.PutRope[arg];
cmd.err.PutRope["\n"];
};
ENDLOOP;
};
Commander.Register["NetwiseCedar", NetwiseCedarCommand, "Set prefix maps to use the network for /Cedar"];
Commander.Register["NetwiseFonts", NetwiseFontsCommand, "Set prefix maps to use the network for /imagerfonts"];
Commander.Register["BuiltinCedar", BuiltinCedarCommand, "Set prefix maps to use the compiled-in files"];
Commander.Register["StartShrinkWrapLogging", StartShrinkWrapLoggingCommand, "Start logging PFS events for creating a shrink-wrapped world"];
Commander.Register["UseFiles", UseFilesCommand, "Open and close the named files"];
IF ProcessProps.GetProp[$CommanderHandle] = NIL THEN {
In this case we're executing in a shrink-wrapped world, so switch to the builtin files.
[] ¬ BuiltinCedarCommand[NIL];
};
END.