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 = { 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: ROPE _ NIL; 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: BOOL _ TRUE; short: ROPE _ tokens.first.Substr[1]; full: ROPE _ NIL; 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 \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. (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 [cmd: Commander.Handle] RETURNS [result: REF ANY _ NIL, msg: ROPE _ NIL] Κό˜™Icode™K˜—–L -- [cmd: Commander.Handle] RETURNS [result: REF ANY _ NIL, msg: ROPE _ NIL]šΟn œ˜%KšΠckH™H–I[cmd: Commander.Handle, starExpand: BOOL _ FALSE, switchChar: CHAR]šœ˜šœ ˜ K˜K˜Kšœ˜ K˜—šœ ˜ K˜K˜Kšœ˜ K˜—K˜—šŸœ.˜@š œœœ0œœ˜RKšœœœ˜>Kšœ˜—Kšœ˜K˜—Kšœ œœG˜XKšœ œœ&˜6K–1[files: LIST OF ROPE, keepFresh: BOOL _ TRUE]˜Kš œrœœœœ˜ΤKš œ œœœœ˜8Kšœœœ˜+Kšœ œœ˜Kšœœœœ˜Kšœ œ˜ KšœD˜Dš œœœœ˜EKšœœœ˜Kšœœ˜%Kšœœœ˜šœœΟcU˜kK˜*šœ ˜Kšœœ"˜@Kšœœ,˜JKšœœœB˜n—K˜—šœ˜šœœœ˜)K˜Kšœœ˜Kšœ˜—š œœœ1œœ˜S–O[s1: ROPE, pos1: INT _ 0, s2: ROPE, pos2: INT _ 0, case: BOOL _ TRUE]šœ%œ œ˜?Kšœœœ˜&K–[format: ROPE _ NIL, v1: IO.Value _ [null[]], v2: IO.Value _ [null[]], v3: IO.Value _ [null[]], v4: IO.Value _ [null[]], v5: IO.Value _ [null[]]]šœœœ˜₯Kšœ˜—Kšœ˜—K–[format: ROPE _ NIL, v1: IO.Value _ [null[]], v2: IO.Value _ [null[]], v3: IO.Value _ [null[]], v4: IO.Value _ [null[]], v5: IO.Value _ [null[]]]š œœœœœB˜tKšœ œœ˜GK˜—K˜*Kšœ˜—šœ œœ˜4K˜K˜Kšœ˜—Kšœœ=˜HK–1[files: LIST OF ROPE, keepFresh: BOOL _ TRUE]šœ,œ-œ˜dšœk˜kšœ˜K–―[stream: STREAM, format: ROPE _ NIL, v1: IO.Value _ [null[]], v2: IO.Value _ [null[]], v3: IO.Value _ [null[]], v4: IO.Value _ [null[]], v5: IO.Value _ [null[]]]šœT˜VKšœ˜Kšœ˜—šœ˜K–―[stream: STREAM, format: ROPE _ NIL, v1: IO.Value _ [null[]], v2: IO.Value _ [null[]], v3: IO.Value _ [null[]], v4: IO.Value _ [null[]], v5: IO.Value _ [null[]]]šœj˜lKšœ˜ Kšœ˜—Kšœ˜—š˜Kšœœ˜—K˜K˜—šœ œ4˜BK˜—šŸ œœœœ˜*K˜$–[]š œœœRœœ˜tK–[format: ROPE _ NIL, v1: IO.Value _ [null[]], v2: IO.Value _ [null[]], v3: IO.Value _ [null[]], v4: IO.Value _ [null[]], v5: IO.Value _ [null[]]]šœœ…˜˜Kšœ˜K˜δ—K˜K˜—KšœT˜TKšœF˜F—K˜Kšœ˜—…—ͺΞ