ColorizeViewPointCmdsImpl.mesa
Copyright Ó 1988 by Xerox Corporation. All rights reserved.
Eric Nickell, May 18, 1989 11:51:29 am PDT
Bob Coleman, June 5, 1990 2:55:28 pm PDT
Dave Rumph, June 8, 1989 7:39:19 pm PDT
DIRECTORY
ColorizeViewPoint, Commander, CommandTool, FileNames, FS, IO, Profiles, Rope;
ColorizeViewPointCmdsImpl: CEDAR PROGRAM
IMPORTS ColorizeViewPoint, Commander, CommandTool, FileNames, FS, IO, Profiles, Rope
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
registrationDir: ROPE ~ CommandTool.CurrentWorkingDirectory[];
ColorizeVP: Commander.CommandProc = {
[cmd: Commander.Handle] RETURNS [result: REF ANY ← NIL, msg: ROPE ← NIL]
ENABLE {
FS.Error => {
result ← $Failure;
msg ← error.explanation;
GOTO Out;
};
IO.Error => {
result ← $Failure;
msg ← "IO Problems";
GOTO Out;
};
};
CheckSystemSetting: ColorizeViewPoint.CheckSystemSettingProc ~ {
FOR each: LIST OF ColorizeViewPoint.Setting ← inForce, each.rest UNTIL each=NIL DO
IF key.Equal[each.first.key] THEN RETURN [each.first.default];
ENDLOOP;
ERROR;
};
settings: LIST OF ColorizeViewPoint.Setting ~ ColorizeViewPoint.ExaminesTheseSettings[];
inForce: LIST OF ColorizeViewPoint.Setting ← settings;
profile: Profiles.Profile;
defaultSlice: Profiles.Slice ~ [file[FileNames.FileWithSearchRules[root: "DefaultPalette.data", defaultExtension: NIL, requireExtension: FALSE, requireExact: FALSE, searchRules: LIST[registrationDir]].fullPath]];
dummySlices: LIST OF Profiles.Slice ← LIST[[rope[NIL]]];
tail: LIST OF Profiles.Slice ← dummySlices;
from, to: ROPENIL;
tokens: LIST OF ROPE;
nTokens: NAT;
[list: tokens, length: nTokens] ← CommandTool.ParseToList[cmd: cmd];
WHILE tokens#NIL AND tokens.first.Size>0 AND tokens.first.Fetch='- DO
value: BOOLTRUE;
short: ROPE ← tokens.first.Substr[1];
full: ROPENIL;
IF short.Size=1 THEN {--one letter switch indicating that following token should be used as a profile entry
tokens ← tokens.rest; nTokens ← nTokens-1;
SELECT short.Fetch FROM
'p => tail ← (tail.rest ← LIST[[file[fileName: tokens.first]]]);
'c => tail ← (tail.rest ← LIST[[rope[text: tokens.first.Concat[" \n"]]]]);
ENDCASE => RETURN [result: $Failure, msg: IO.PutFR[format: "Option \"%g\" is not valid.", v1: [rope[short]]]];
}
ELSE {
IF short.Size>0 AND short.Fetch='~ THEN {
short ← short.Substr[1];
value ← FALSE;
};
FOR each: LIST OF ColorizeViewPoint.Setting ← settings, each.rest UNTIL each=NIL DO
IF short.Run[s2: each.first.key, case: FALSE]=short.Size THEN {
IF full=NIL THEN full ← each.first.key
ELSE RETURN [result: $Failure, msg: IO.PutFR[format: "Option \"%g\" is ambiguous. (%g, %g, ...)", v1: [rope[short]], v2: [rope[full]], v3: [rope[each.first.key]]]];
};
ENDLOOP;
IF full=NIL THEN RETURN [result: $Failure, msg: IO.PutFR[format: "Option \"%g\" is not valid.", v1: [rope[short]]]];
inForce ← CONS[[key: full, description: NIL, default: value], inForce];
};
tokens ← tokens.rest; nTokens ← nTokens-1;
ENDLOOP;
IF nTokens=3 AND tokens.rest.first.Equal["←"] THEN {
from ← tokens.rest.rest.first;
to ← tokens.first;
}
ELSE RETURN [result: $Failure, msg: Rope.Concat["Syntax: ", usageMsg]];
profile ← Profiles.CreateFromSlices[slices: CONS[defaultSlice, dummySlices.rest], keepFresh: FALSE];
ColorizeViewPoint.Do[fromFile: from, toFile: to, palette: profile, checkSystemSetting: CheckSystemSetting !
ColorizeViewPoint.Warning => {
IO.PutF[stream: cmd.out, format: "Colorizer Warning: %g\n", v1: [rope[explanation]]];
RESUME;
};
ColorizeViewPoint.Error => {
IO.PutF[stream: cmd.out, format: "Colorizer Error: %g\nColorization not done!\n", v1: [rope[explanation]]];
CONTINUE;
};
];
EXITS
Out => RETURN;
};
usageMsg: ROPE ~ "ColorizeViewPoint [-[~]option ...] file ← file";
BuildDocRope: PROC RETURNS [doc: ROPE] ~ {
doc ← usageMsg.Concat["\nOptions:"];
FOR each: LIST OF ColorizeViewPoint.Setting ← ColorizeViewPoint.ExaminesTheseSettings[], each.rest UNTIL each=NIL DO
doc ← doc.Concat[IO.PutFR[format: "\n\t%g: %g\t%g", v1: [rope[each.first.key]], v2: [boolean[each.first.default]], v3: [rope[each.first.description]]]];
ENDLOOP;
doc ← doc.Concat["\n\t-p <fullFileName> \tTo specify files to use as [p]alette entries. Multiple -p switches: later files listed take priority \n\t-c \"palette entry in quotes\": \tTo add particular [c]olor definitions or [c]ontrols different from those contained in the palette files. Multiple -c switches: later color defs take priority over earlier."];
};
Commander.Register[key: "ColorizeViewPoint", proc: ColorizeVP, doc: BuildDocRope[]];
Commander.Register[key: "CVP", proc: ColorizeVP, doc: BuildDocRope[]];
END.