DFCommands.mesa
last edited by vanLeunen on December 19, 1983 11:40 am
DIRECTORY
Ascii USING [Lower],
Commander USING [CommandProc, Register, Handle],
CommandTool USING [ArgumentVector, Parse, Failed],
DFInternal,
DFOperations,
IO USING [int, STREAM, PutF, PutFR, rope],
Rope USING [Compare, Concat, Fetch, Find, Length, 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: REFNIL, msg: Rope.ROPENIL]
argv: CommandTool.ArgumentVector ← NIL;
i: NAT ← 1;
oSwitch: BOOLFALSE;
selectedFileAdded: BOOL;
dfFile: ROPE;
filter: DFOperations.BringOverFilter ← [
filterA: $all,
filterB: $all,
filterC: $all,
list: NIL
];
action: DFOperations.BringOverAction ← $enter;
{ -- interpret the command line, modifying dfFile, filter, action
argv ← CommandTool.Parse[cmd ! CommandTool.Failed => { msg ← errorMsg; CONTINUE; }];
IF argv = NIL OR argv.argc < 2 THEN RETURN[$Failure, bringoverHelpText];
DO {
IF i = argv.argc - 1 THEN EXIT;
IF oSwitch THEN {
IF argv[i].Length[] = 0 THEN GOTO fileNameSyntaxError;
IF argv[i].Fetch[0] = '- THEN {
IF selectedFileAdded THEN oSwitch ← FALSE ELSE GOTO oSwitchSyntaxError
}
ELSE {
filter.list ← CONS[argv[i], filter.list];
selectedFileAdded ← TRUE;
GOTO nextArg
}
};
IF argv[i].Length[] # 2 OR argv[i].Fetch[0] # '- THEN GOTO switchSyntaxError;
SELECT Ascii.Lower[argv[i].Fetch[1]] FROM
'b => filter.filterA ← $derived;
'f => action ← $fetch;
'o => { oSwitch ← TRUE; selectedFileAdded ← FALSE };
'p => filter.filterB ← $public;
'r => filter.filterC ← $imported;
's => filter.filterA ← $source;
'v => action ← $check;
'w => filter.filterC ← $defining;
ENDCASE => GOTO switchSyntaxError;
GOTO nextArg
EXITS nextArg => i ← i.SUCC }
ENDLOOP;
IF oSwitch AND NOT selectedFileAdded THEN GOTO oSwitchSyntaxError;
dfFile ← CompleteDFFileName[argv[i]];
EXITS
fileNameSyntaxError => RETURN[
$Failure, IO.PutFR["Illegal file name: \"%g\"\n", IO.rope[argv[i]]]];
switchSyntaxError => RETURN[
$Failure, IO.PutFR["Unrecognized switch: \"%g\"\n", IO.rope[argv[i]]]];
oSwitchSyntaxError => RETURN[
$Failure, "No list-of-selected-files following \"o\" switch"];
};
{ -- do the Bringover
errors, warnings, filesActedUpon: INT;
[errors, warnings, filesActedUpon] ← DFOperations.BringOver[
dfFile: dfFile, filter: filter, action: action,
interact: DFInternal.DefaultInteractionProc, clientData: NIL, log: cmd.out];
IF errors + warnings > 0 THEN
cmd.out.PutF["%g errors, %g warnings, %g files acted upon\n",
IO.int[errors], IO.int[warnings], IO.int[filesActedUpon]]
ELSE
cmd.out.PutF["%g files acted upon\n", IO.int[filesActedUpon]];
RETURN[NIL, NIL]
}
};
DoSModel: Commander.CommandProc = {
PROC [cmd: Commander.Handle] RETURNS [result: REFNIL, msg: Rope.ROPENIL]
argv: CommandTool.ArgumentVector ← NIL;
i: NAT ← 1;
dfFile: ROPE;
action: DFOperations.SModelAction ← [remoteCheck: TRUE, storeChanged: TRUE];
{ -- interpret the command line, modifying dfFile, action
argv ← CommandTool.Parse[cmd ! CommandTool.Failed => { msg ← errorMsg; CONTINUE; }];
IF argv = NIL OR argv.argc < 2 THEN RETURN[$Failure, smodelHelpText];
DO
IF i = argv.argc - 1 THEN EXIT;
IF argv[i].Length[] # 2 OR argv[i].Fetch[0] # '- THEN GOTO switchSyntaxError;
SELECT Ascii.Lower[argv[i].Fetch[1]] FROM
'd => action.remoteCheck ← FALSE;
'n => action.storeChanged ← FALSE;
ENDCASE => GOTO switchSyntaxError;
i ← i.SUCC
ENDLOOP;
dfFile ← CompleteDFFileName[argv[i]];
EXITS
switchSyntaxError => RETURN[
$Failure, IO.PutFR["Unrecognized switch: \"%g\"\n", IO.rope[argv[i]]]];
};
{ -- do the SModel
errors, warnings, filesActedUpon: INT;
[errors, warnings, filesActedUpon] ← DFOperations.SModel[
dfFile: dfFile, action: action,
interact: DFInternal.DefaultInteractionProc, clientData: NIL, log: cmd.out];
IF errors + warnings > 0 THEN
cmd.out.PutF["%g errors, %g warnings, %g files acted upon\n",
IO.int[errors], IO.int[warnings], IO.int[filesActedUpon]]
ELSE
cmd.out.PutF["%g files acted upon\n", IO.int[filesActedUpon]];
RETURN[NIL, NIL]
}
};
DoVerifyDF: Commander.CommandProc = {
PROC [cmd: Commander.Handle] RETURNS [result: REFNIL, msg: Rope.ROPENIL]
argv: CommandTool.ArgumentVector ← NIL;
dfFile: ROPE;
{ -- interpret the command line, modifying dfFile
argv ← CommandTool.Parse[cmd ! CommandTool.Failed => { msg ← errorMsg; CONTINUE; }];
IF argv = NIL OR argv.argc # 2 THEN RETURN[$Failure, verifydfHelpText];
dfFile ← CompleteDFFileName[argv[1]];
};
{ -- do the VerifyDF
errors, warnings, filesActedUpon: INT;
[errors, warnings, filesActedUpon] ← DFOperations.Verify[
dfFile: dfFile,
interact: DFInternal.DefaultInteractionProc, clientData: NIL, log: cmd.out];
IF errors + warnings > 0 THEN
cmd.out.PutF["%g errors, %g warnings, %g files acted upon\n",
IO.int[errors], IO.int[warnings], IO.int[filesActedUpon]]
ELSE
cmd.out.PutF["%g files acted upon\n", IO.int[filesActedUpon]];
RETURN[NIL, NIL]
}
};
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),\n\t-s (origin: source), -b (origin: derived),\n\t-r (reference: imported), -w (reference: defining),\n\t-v (action: check), -f (action: fetch),\n\t-o list-of-files (selected files: list-of-files)} 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.