VersionMapCommandsImpl.Mesa
Last tweaked by Mike Spreitzer on July 10, 1990 1:55 pm PDT
DIRECTORY Atom, BasicTime, Commander, CommandTool, Convert, FS, IO, Rope, VersionMap, VersionMapDefaults, VersionMapExtended;
VersionMapCommandsImpl: CEDAR PROGRAM
IMPORTS Atom, Commander, CommandTool, Convert, FS, IO, Rope, VersionMap, VersionMapDefaults, VersionMapExtended
=
BEGIN
ROPE: TYPE ~ Rope.ROPE;
Halves: NAT ~ BYTES[VersionMap.VersionStamp]/BYTES[CARD16];
HS: TYPE ~ PACKED ARRAY [0 .. Halves) OF CARD16;
VLS: PROC [cmd: Commander.Handle] RETURNS [result: REF ANYNIL, msg: ROPENIL] --Commander.CommandProc-- ~ {
argv: CommandTool.ArgumentVector;
mapList: VersionMap.MapList;
rangeList: VersionMap.RangeList;
argv ← CommandTool.Parse[cmd !CommandTool.Failed => {msg ← errorMsg; GOTO Fail}];
IF argv.argc # 3 THEN RETURN [$Failure, "Usage: VLS <fileName or $mapName> <shortName>"];
{ENABLE FS.Error => {
msg ← IO.PutFR["FS.Error[%g, %g]", [atom[error.code]], [rope[error.explanation]] ];
GOTO Fail};
IF argv[1].Length[] > 0 AND argv[1].Fetch[0] = '$
THEN mapList ← VersionMapDefaults.GetMapList[Atom.MakeAtom[argv[1].Substr[1]]]
ELSE mapList ← LIST[VersionMap.RestoreMapFromFile[argv[1]]]};
rangeList ← VersionMap.ShortNameToRanges[mapList, argv[2]];
FOR rangeList ← rangeList, rangeList.rest WHILE rangeList # NIL DO
range: VersionMap.Range ← rangeList.first;
DO
name: ROPE;
stamp: VersionMap.VersionStamp;
hs: HS;
created: BasicTime.GMT;
[name, stamp, created, range] ← VersionMap.RangeToEntry[range];
IF name=NIL THEN EXIT;
hs ← LOOPHOLE[stamp];
cmd.out.PutF["%g %g ", [rope[name]], [time[created]] ];
FOR i: NAT IN [0 .. Halves) DO
IF i#0 THEN cmd.out.PutChar[':];
cmd.out.PutF["%04x", [cardinal[hs[i]]] ];
ENDLOOP;
cmd.out.PutChar['\n];
ENDLOOP;
ENDLOOP;
RETURN;
EXITS Fail => result ← $Failure};
VersionQuery: PROC [cmd: Commander.Handle] RETURNS [result: REF ANYNIL, msg: ROPENIL] --Commander.CommandProc-- ~ {
argv: CommandTool.ArgumentVector;
mapList: VersionMap.MapList;
hs: HSALL[0];
stamp: VersionMap.VersionStamp;
manl: VersionMap.MapAndNameList;
argv ← CommandTool.Parse[cmd !CommandTool.Failed => {msg ← errorMsg; GOTO Fail}];
IF argv.argc # 3 THEN RETURN [$Failure, "Usage: VersionQuery <fileName or $mapName> <versionStamp>"];
{ENABLE FS.Error => {
msg ← IO.PutFR["FS.Error[%g, %g]", [atom[error.code]], [rope[error.explanation]] ];
GOTO Fail};
IF argv[1].Length[] > 0 AND argv[1].Fetch[0] = '$
THEN mapList ← VersionMapDefaults.GetMapList[Atom.MakeAtom[argv[1].Substr[1]]]
ELSE mapList ← LIST[VersionMap.RestoreMapFromFile[argv[1]]]};
FOR i: NAT IN [0 .. Halves) DO
hs[i] ← Convert.IntFromRope[argv[2].Substr[start: i*5, len: 4], 16 !Convert.Error => {msg ← IO.PutFR["Convert error at index %g in 2nd arg", [integer[index]] ]; GOTO Fail}];
ENDLOOP;
stamp ← LOOPHOLE[hs];
manl ← VersionMap.VersionToAllNames[mapList, stamp];
FOR manl ← manl, manl.rest WHILE manl # NIL DO
cmd.out.PutF["%g of %g\n", [rope[manl.first.name]], [time[manl.first.created]] ];
ENDLOOP;
RETURN;
EXITS Fail => result ← $Failure};
VMCopy: PROC [cmd: Commander.Handle] RETURNS [result: REF ANYNIL, msg: ROPENIL] --Commander.CommandProc-- ~ {
argv: CommandTool.ArgumentVector;
map: VersionMap.Map;
long, randomize: BOOLFALSE;
argv ← CommandTool.Parse[cmd !CommandTool.Failed => {msg ← errorMsg; GOTO Fail}];
IF argv.argc # 4 THEN RETURN [$Failure, copyUsage];
SELECT TRUE FROM
argv[3].Equal["48"] => long ← FALSE;
argv[3].Equal["64"] => long ← TRUE;
argv[3].Equal["r64"] => long ← randomize ← TRUE;
ENDCASE => RETURN [$Failure, copyUsage];
{
ENABLE FS.Error => {
msg ← IO.PutFR["FS.Error[%g, %g]", [atom[error.code]], [rope[error.explanation]] ];
GOTO Fail};
map ← VersionMap.RestoreMapFromFile[argv[1]];
IF randomize THEN FOR i: CARDINAL IN [0 .. map.len) DO map[i].stamp.extra ← (i*i*i + i*i + i) MOD 65536 ENDLOOP;
VersionMapExtended.GeneralSaveMapToFile[map, argv[2], long];
};
RETURN;
EXITS Fail => result ← $Failure};
copyUsage: ROPE ~ "Usage: VersionMapCopy <fromFileName> <toFileName> 48|64|r64";
Commander.Register["VersionMapList", VLS, "<fileName or $mapName> <shortName> - queries the named version map by short name"];
Commander.Register["VersionQuery", VersionQuery, "<fileName or $mapName> <versionStamp> - queries the named version map by version stamp"];
Commander.Register["VersionMapCopy", VMCopy, "<fromFileName> <toFileName> - reads and writes a version map"];
END.