DFCommands.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Russ Atkinson (RRA) January 21, 1985 6:41:18 pm PST
DIRECTORY
Ascii USING [Lower],
Commander USING [CommandProc, Register, Handle],
CommandTool USING [ArgumentVector, Parse, Failed],
DFInternal USING [DefaultInteractionProc],
DFOperations USING [BringOver, BringOverAction, BringOverFilter, SModel, SModelAction, Verify],
IO USING [PutF, STREAM],
Rope USING [Compare, Concat, Fetch, Find, Length, Match, ROPE, Substr];
DFCommands:
CEDAR
PROGRAM
IMPORTS Ascii, Commander, CommandTool, DFInternal, DFOperations, IO, Rope = BEGIN
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
DoBringover: Commander.CommandProc = {
PROC [cmd: Commander.Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]
errors, warnings, filesActedUpon: INT;
oSwitch: BOOL ← FALSE;
out: STREAM = cmd.out;
filter: DFOperations.BringOverFilter ← [filterA: $all, filterB: $all, filterC: $all, list: NIL];
action: DFOperations.BringOverAction ← $enter;
argv: CommandTool.ArgumentVector ← CommandTool.Parse[cmd
! CommandTool.Failed => {msg ← errorMsg; GO TO fail}];
IF argv = NIL OR argv.argc < 2 THEN {msg ← bringoverHelpText; GO TO fail};
FOR i:
NAT
IN [1..argv.argc)
DO
arg: ROPE = argv[i];
IF Rope.Match["-*", arg]
THEN {
FOR j:
INT
IN [1..Rope.Length[arg])
DO
c: CHAR ← Ascii.Lower[Rope.Fetch[arg, j]];
SELECT c
FROM
'b => filter.filterA ← $derived;
'f => action ← $fetch;
'o => {oSwitch ← TRUE; filter.list ← NIL};
'p => filter.filterB ← $public;
'r => filter.filterC ← $imported;
's => filter.filterA ← $source;
'u => {filter ← [filterA: $all, filterB: $all, filterC: $all, list: NIL]; action ← $enter};
'v => action ← $check;
'w => filter.filterC ← $defining;
'x => oSwitch ← FALSE;
ENDCASE;
ENDLOOP;
LOOP;
};
IF oSwitch
AND i < argv.argc-1
THEN {
just add this file to the filter list
filter.list ← CONS[arg, filter.list];
LOOP;
};
At this point we can do the bringover of the file.
[errors, warnings, filesActedUpon] ← DFOperations.BringOver[
dfFile: CompleteDFFileName[arg], filter: filter, action: action,
interact: DFInternal.DefaultInteractionProc, clientData: NIL, log: out];
filter.list ← NIL;
oSwitch ← FALSE;
IF errors + warnings # 0
THEN
IO.PutF[out, "%g errors, %g warnings, %g files acted upon\n",
[integer[errors]], [integer[warnings]], [integer[filesActedUpon]]]
ELSE
IO.PutF[out, "%g files acted upon\n", [integer[filesActedUpon]]];
ENDLOOP;
EXITS fail => result ← $Failure;
};
DoSModel: Commander.CommandProc = {
PROC [cmd: Commander.Handle] RETURNS [result: REF ← NIL, msg: ROPE ← NIL]
errors, warnings, filesActedUpon: INT;
oSwitch: BOOL ← FALSE;
out: STREAM = cmd.out;
action: DFOperations.SModelAction ← [remoteCheck: TRUE, storeChanged: TRUE];
argv: CommandTool.ArgumentVector ← CommandTool.Parse[cmd
! CommandTool.Failed => {msg ← errorMsg; GO TO fail}];
IF argv = NIL OR argv.argc < 2 THEN {msg ← smodelHelpText; GO TO fail};
FOR i:
NAT
IN [1..argv.argc)
DO
arg: ROPE = argv[i];
IF Rope.Match["-*", arg]
THEN {
FOR j:
INT
IN [1..Rope.Length[arg])
DO
c: CHAR ← Ascii.Lower[Rope.Fetch[arg, j]];
SELECT c
FROM
'd => action.remoteCheck ← FALSE;
'n => action.storeChanged ← FALSE;
'u => action.storeChanged ← action.remoteCheck ← TRUE;
ENDCASE;
ENDLOOP;
LOOP;
};
At this point we can do the smodel of the file.
[errors, warnings, filesActedUpon] ← DFOperations.SModel[
dfFile: CompleteDFFileName[arg], action: action,
interact: DFInternal.DefaultInteractionProc, clientData: NIL, log: out];
IF errors + warnings # 0
THEN IO.PutF[out, "%g errors, %g warnings, %g files acted upon\n", [integer[errors]], [integer[warnings]], [integer[filesActedUpon]]]
ELSE IO.PutF[out, "%g files acted upon\n", [integer[filesActedUpon]]];
ENDLOOP;
EXITS fail => result ← $Failure;
};
DoVerifyDF: Commander.CommandProc = {
PROC [cmd: Commander.Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]
errors, warnings, filesActedUpon: INT;
oSwitch: BOOL ← FALSE;
out: STREAM = cmd.out;
argv: CommandTool.ArgumentVector ← CommandTool.Parse[cmd
! CommandTool.Failed => {msg ← errorMsg; GO TO fail}];
IF argv = NIL OR argv.argc < 2 THEN {msg ← verifydfHelpText; GO TO fail};
FOR i:
NAT
IN [1..argv.argc)
DO
arg: ROPE = argv[i];
IF Rope.Match["-*", arg] THEN LOOP;
At this point we can do the verification of the file.
[errors, warnings, filesActedUpon] ← DFOperations.Verify[
dfFile: CompleteDFFileName[arg],
interact: DFInternal.DefaultInteractionProc, clientData: NIL, log: out];
IF errors + warnings # 0
THEN IO.PutF[out, "%g errors, %g warnings, %g files acted upon\n", [integer[errors]], [integer[warnings]], [integer[filesActedUpon]]]
ELSE IO.PutF[out, "%g files acted upon\n", [integer[filesActedUpon]]];
ENDLOOP;
EXITS fail => result ← $Failure;
};
CompleteDFFileName:
PROC [dfFileName:
ROPE]
RETURNS [
ROPE] = {
length: INT = dfFileName.Length[];
IF length < 4
OR (Rope.Compare[Rope.Substr[dfFileName, length - 3, 3], ".df",
FALSE] # equal
AND Rope.Find[dfFileName, "!"] = -1)
THEN RETURN[Rope.Concat[dfFileName, ".df"]]
ELSE RETURN[dfFileName];
};
bringoverHelpText: ROPE = "Usage: Bringover {-p (access: public), -s (origin: source), -b (origin: derived), -r (reference: imported), -w (reference: defining), -v (action: check), -f (action: fetch), -o list-of-files (selected files: list-of-files) -u (use defaults)} dfFile\nUnless changed by switches, Bringover uses (Auto-Confirm: yes, access: all, origin: all, reference: all, selected files: (no filtering), action: enter).\n";
smodelHelpText: ROPE = "Usage: SModel {-d (Check on server: no),\n\t-n (Store changed files: no)} dfFile\nUnless changed by switches, SModel uses (Auto-Confirm: yes, Check existence on server: yes, Store changed files: yes).\n";
verifydfHelpText: ROPE = "Usage: VerifyDF dfFile\nVerifyDF uses (Auto-Confirm: yes).\n";
Commander.Register["Bringover", DoBringover, bringoverHelpText];
Commander.Register["SModel", DoSModel, smodelHelpText];
Commander.Register["VerifyDF", DoVerifyDF, verifydfHelpText];
END.