DIRECTORY Commander USING [CommandProc, Register], Convert USING [RopeFromInt], FS USING [ComponentPositions, Error, ExpandName, FileInfo, Rename], Imager USING [Context], ImagerInterpress USING [Close, Create, DoPage, Ref], Interpress USING [DoPage, Master, Open], IO, Rope USING [Cat, Concat, Equal, Length, ROPE, Substr, ToRefText]; InterpressPageImpl: CEDAR PROGRAM IMPORTS Commander, Convert, FS, ImagerInterpress, Interpress, IO, Rope ~ BEGIN ROPE: TYPE ~ Rope.ROPE; CmdTokenBreak: PROC [char: CHAR] RETURNS [IO.CharClass] = { IF char = '_ THEN RETURN [break]; IF char = ' OR char = '\t OR char = ', OR char = '; OR char = '\n THEN RETURN [sepr]; RETURN [other]; }; GetCmdToken: PROC [stream: IO.STREAM] RETURNS [rope: ROPE] = { rope _ NIL; rope _ stream.GetTokenRope[CmdTokenBreak ! IO.EndOfStream => CONTINUE].token; }; ExpandedName: TYPE ~ RECORD [fullFName: ROPE, cp: FS.ComponentPositions]; ExpandName: PROC [inputName: ROPE] RETURNS [e: ExpandedName] ~ INLINE { [e.fullFName, e.cp] _ FS.ExpandName[inputName]; }; PageRange: TYPE ~ RECORD [startPage, nPages: INT]; SpecError: PUBLIC ERROR [offset: INT] ~ CODE; DoExtract: PUBLIC PROC [inputFile, outputFile: ROPE, pageSpec: LIST OF PageRange, log: IO.STREAM] RETURNS [success: BOOLEAN _ TRUE] ~ { logProc: PROC [class: INT, code: ATOM, explanation: ROPE] ~ { IO.PutRope[log, "\n *** Interpress Error "]; IO.PutRope[log, explanation]; success _ FALSE; }; n: ExpandedName ~ ExpandName[FS.FileInfo[inputFile].fullFName]; master: Interpress.Master ~ Interpress.Open[n.fullFName, logProc]; out: ImagerInterpress.Ref ~ ImagerInterpress.Create[outputFile]; IO.PutRope[log, "Reading "]; IO.PutRope[log, n.fullFName]; IO.PutRope[log, " . . . "]; FOR each: LIST OF PageRange _ pageSpec, each.rest UNTIL each=NIL DO pageRange: PageRange ~ each.first; FOR i: INT IN [pageRange.startPage..MIN[pageRange.startPage+pageRange.nPages-1, master.pages]] DO OnePage: PROC [context: Imager.Context] ~ {Interpress.DoPage[master, i, context, logProc]}; IO.PutF[stream: log, format: " [%g", v1: [integer[i]]]; ImagerInterpress.DoPage[out, OnePage]; IO.PutRope[self: log, r: "]"]; ENDLOOP; ENDLOOP; ImagerInterpress.Close[out]; IO.PutRope[log, " written.\n"]; }; InterpressExtractCommand: Commander.CommandProc ~ { GetToken: PROC [stream: IO.STREAM] RETURNS [token: ROPE _ NIL] = { Break: PROC [char: CHAR] RETURNS [IO.CharClass] = { IF char = '_ THEN RETURN [break]; IF char = ' OR char = ' OR char = ', OR char = '; OR char = '\n THEN RETURN [sepr]; RETURN [other]; }; token _ stream.GetTokenRope[Break ! IO.EndOfStream => CONTINUE].token; }; ParsePageSpec: PUBLIC PROC [pageSpecRope: ROPE] RETURNS [pageSpec: LIST OF PageRange, charsParsed: INT] ~ { Reverse: PROC [pageSpec: LIST OF PageRange] RETURNS [reversed: LIST OF PageRange] ~ { WHILE pageSpec # NIL DO t: LIST OF PageRange _ pageSpec; pageSpec _ t.rest; t.rest _ reversed; reversed _ t; ENDLOOP; }; text: REF TEXT ~ pageSpecRope.ToRefText; i: NAT _ 0; c: CHAR; SkipSpaces: PROC ~ {c _ ' ; WHILE i < text.length AND ((c _ text[i]) = ', OR c = ' OR c = ' OR c = '\n) DO i _ i+1 ENDLOOP}; GetChar: PROC RETURNS [CHAR] ~ {IF i < text.length THEN {i _ i+1; RETURN [text[i-1]]} ELSE RETURN ['\000]}; Int: PROC RETURNS [value: INT_0] ~ { SkipSpaces[]; IF NOT c IN ['0..'9] THEN ERROR SpecError[i]; WHILE i < text.length AND (c _ text[i]) IN ['0..'9] DO value _ value * 10 + (c-'0); i _ i+1; ENDLOOP; }; spec: LIST OF PageRange _ NIL; SkipSpaces[]; WHILE i < text.length DO SELECT text[i] FROM IN ['0..'9] => spec _ CONS[[Int[], 1], spec]; '[, '( => { open: CHAR _ GetChar[]; start: INT _ Int[]; end: INT; SkipSpaces[]; IF i < text.length AND text[i] = '. THEN i _ i+1 ELSE ERROR SpecError[i]; IF i < text.length AND text[i] = '. THEN i _ i+1 ELSE ERROR SpecError[i]; end _ Int[]; SkipSpaces[]; IF (c _ GetChar[]) = '] OR c = ') THEN { IF open = '( THEN start _ start + 1; IF c = '] THEN end _ end + 1; IF end > start THEN spec _ CONS[[start, end-start], spec] } ELSE ERROR SpecError[i]; }; ENDCASE => EXIT; SkipSpaces[]; ENDLOOP; RETURN [Reverse[spec], i] }; stream: IO.STREAM _ IO.RIS[cmd.commandLine]; outputName: ROPE _ GetToken[stream]; inputName: ROPE; pagesToken: ROPE; pageSpec: LIST OF PageRange; IF outputName.Length = 0 THEN {cmd.out.PutRope["Output file missing.\n"]; RETURN}; IF NOT GetToken[stream].Equal["_"] THEN {cmd.out.PutRope["Missing \"_\".\n"]; RETURN}; inputName _ GetToken[stream]; pagesToken _ GetToken[stream]; IF pagesToken.Equal["PAGE", FALSE] OR pagesToken.Equal["PAGES", FALSE] THEN { skip: INT; [pageSpec, skip] _ ParsePageSpec[cmd.commandLine.Substr[stream.GetIndex]]; stream.SetIndex[stream.GetIndex+skip]; } ELSE pageSpec _ LIST[[1, 1000000]]; IF NOT DoExtract[inputName, outputName, pageSpec, cmd.out] THEN { cmd.out.PutRope["Unable to extract any pages from "]; cmd.out.PutRope[inputName]; cmd.out.PutChar['\n]; } ELSE {cmd.out.PutRope[outputName]; cmd.out.PutRope[" Written.\n"]}; IF NOT stream.EndOf THEN {cmd.out.PutRope["Ignored: "]; cmd.out.PutRope[cmd.commandLine.Substr[stream.GetIndex]]; cmd.out.PutChar['\n]}; }; DoBreakup: PROC [inputName: ROPE, log: IO.STREAM] ~ { logProc: PROC [class: INT, code: ATOM, explanation: ROPE] ~ { IO.PutRope[log, "\n *** Interpress Error "]; IO.PutRope[log, explanation]; }; n: ExpandedName ~ ExpandName[FS.FileInfo[inputName].fullFName]; base: ROPE ~ Rope.Substr[n.fullFName, n.cp.base.start, n.cp.base.length]; ext: ROPE ~ Rope.Substr[n.fullFName, n.cp.ext.start, n.cp.ext.length]; master: Interpress.Master ~ Interpress.Open[n.fullFName, logProc]; IO.PutRope[log, "Reading "]; IO.PutRope[log, n.fullFName]; IO.PutRope[log, " . . . "]; FOR i: INT IN [1..master.pages] DO name: ROPE ~ Rope.Cat[base, "-", Convert.RopeFromInt[i], ".", ext]; out: ImagerInterpress.Ref ~ ImagerInterpress.Create[name]; onePage: PROC [context: Imager.Context] ~ {Interpress.DoPage[master, i, context, logProc]}; IO.PutRope[log, FS.FileInfo[name].fullFName]; ImagerInterpress.DoPage[out, onePage]; IO.PutRope[log, " "]; ImagerInterpress.Close[out]; ENDLOOP; IO.PutRope[log, "written.\n"]; }; InterpressBreakupCommand: Commander.CommandProc ~ { stream: IO.STREAM _ IO.RIS[cmd.commandLine]; inputName: ROPE _ GetCmdToken[stream]; IF inputName = NIL THEN RETURN[result: $Failure, msg: cmd.procData.doc]; DoBreakup[inputName, cmd.out ! FS.Error => IF error.group = user THEN {result _ $Failure; msg _ error.explanation; CONTINUE}]; }; DoConcatenate: PROC [outputName: ROPE, cmdLineStream: IO.STREAM, log: IO.STREAM] ~ { pageNumber: INT _ 0; logProc: PROC [class: INT, code: ATOM, explanation: ROPE] ~ { IO.PutRope[log, "\n *** Interpress Error "]; IO.PutRope[log, explanation]; }; n: ExpandedName ~ ExpandName[outputName]; extendedName: ROPE ~ IF n.cp.ext.length = 0 THEN Rope.Substr[n.fullFName, 0, n.cp.base.start+n.cp.base.length].Concat[".interpress"] ELSE n.fullFName; tempName: ROPE _ "TempConcatenation.interpress"; out: ImagerInterpress.Ref ~ ImagerInterpress.Create[tempName]; tempName _ FS.FileInfo[tempName].fullFName; IO.PutRope[log, "Reading "]; FOR inputName: ROPE _ GetCmdToken[cmdLineStream], GetCmdToken[cmdLineStream] UNTIL inputName = NIL DO fullInputName: ROPE ~ FS.FileInfo[inputName].fullFName; master: Interpress.Master ~ Interpress.Open[fullInputName, logProc]; IO.PutRope[log, fullInputName]; IO.PutRope[log, " "]; FOR i: INT IN [1..master.pages] DO onePage: PROC [context: Imager.Context] ~ {Interpress.DoPage[master, i, context, logProc]}; IO.PutRope[log, "["]; IO.PutRope[log, Convert.RopeFromInt[pageNumber _ pageNumber + 1]]; ImagerInterpress.DoPage[out, onePage]; IO.PutRope[log, "] "]; ENDLOOP; ENDLOOP; ImagerInterpress.Close[out]; FS.Rename[from: tempName, to: extendedName]; IO.PutRope[log, FS.FileInfo[extendedName].fullFName]; IO.PutRope[log, " written.\n"]; }; InterpressConcatenateCommand: Commander.CommandProc ~ { stream: IO.STREAM _ IO.RIS[cmd.commandLine]; outputName: ROPE _ GetCmdToken[stream]; gets: ROPE _ GetCmdToken[stream]; IF outputName = NIL OR NOT gets.Equal["_"] THEN RETURN[result: $Failure, msg: cmd.procData.doc]; DoConcatenate[outputName, stream, cmd.out ! FS.Error => IF error.group = user THEN {result _ $Failure; msg _ error.explanation; CONTINUE}]; }; Commander.Register[key: "InterpressExtract", proc: InterpressExtractCommand, doc: "Extract pages from interpress files, e.g. result.ip _ source.ip PAGES 1, 3, [10..15]"]; Commander.Register[key: "IPExtract", proc: InterpressExtractCommand, doc: "Extract pages from interpress files, e.g. result.ip _ source.ip PAGES 1, 3, [10..15] (alias for InterpressExtract)"]; Commander.Register[key: "InterpressBreakup", proc: InterpressBreakupCommand, doc: "Breaks an interpress master into a collection of one-page interpress masters"]; Commander.Register[key: "IPBreakup", proc: InterpressBreakupCommand, doc: "Breaks an interpress master into a collection of one-page interpress masters (alias for InterpressBreakup)"]; Commander.Register[key: "InterpressConcatenate", proc: InterpressConcatenateCommand, doc: "Concatenates a collection of Interpress masters into one. (output _ input1 input2 . . .)"]; Commander.Register[key: "IPConcatenate", proc: InterpressConcatenateCommand, doc: "Concatenates a collection of Interpress masters into one. (output _ input1 input2 . . .) (alias for InterpressConcatenate)"]; END. ΜInterpressPageImpl.mesa Copyright c 1986 by Xerox Corporation. All rights reserved. Michael Plass, June 13, 1986 12:57:33 pm PDT Provides commands for making an Interpress package by splitting out and combining pages of other Interpress masters. Copied Types Command parsing aids Extracting pages Breaking into single pages Concatenating masters together Write it with a temp name to avoid lock conflicts if it is also an input. Command Registration Κ³˜codešœ™Kšœ Οmœ1™K– "cedar" stylešœžœ˜ K– "cedar" stylešœ+žœžœ˜MKšœ˜K˜—– "cedar" styleš œžœžœ žœžœ˜IK– "cedar" style˜—– "cedar" styleš   œžœ žœžœžœ˜GJšœžœ˜/Kšœ˜K– "cedar" style˜——™Jšœ žœžœžœ˜2Jš œ žœžœ žœžœ˜-š  œžœžœžœ žœžœžœžœžœ žœžœ˜‡š œ žœ žœžœžœ˜=Kšžœ*˜,Kšžœ˜Kšœ žœ˜Kšœ˜—Jšœžœ ˜?JšœB˜BKšœ@˜@Jšžœ˜Jšžœ˜Jšžœ˜š žœžœžœ!žœžœž˜CK˜"š žœžœžœžœ8ž˜aKšœ žœN˜[K•StartOfExpansion―[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œ‘˜7Kšœ&˜&K–elf: STREAM, r: ROPE]šžœ˜Kšžœ˜—Kšžœ˜—Jšœ˜Jšžœ˜J˜J˜—code2š œ˜3– "cedar" styleš œžœ žœžœžœ žœžœ˜B– "cedar" styleš  œžœžœžœžœ˜3Mšžœ žœžœ ˜!Mšžœ žœ žœ žœ žœ žœžœ˜UMšžœ ˜Mšœ˜—Mšœ$žœžœ˜FMšœ˜—š  œžœžœžœžœ žœžœžœ˜kš œžœ žœžœ žœ žœžœ˜Ušžœ žœž˜Mšœžœžœ˜ Mšœ˜Mšœ˜Mšœ ˜ Mšžœ˜—Mšœ˜—Mšœžœžœ˜(Mšœžœ˜ Mšœžœ˜Mš  œžœ žœžœžœžœžœ žœ žœ˜|Mš œžœžœžœžœžœ žœžœžœ ˜kš œžœžœ žœ˜$Mšœ ˜ Mš žœžœžœ žœžœ˜-šžœžœžœ ž˜6Mšœ˜Mšœ˜Mšžœ˜—Mšœ˜—Mšœžœžœ žœ˜Mšœ ˜ šžœž˜šžœ ž˜Mšžœžœ˜-šœ ˜ Mšœžœ ˜Mšœžœ ˜Mšœžœ˜ Mšœ ˜ Mš žœžœžœ žœžœ˜IMš žœžœžœ žœžœ˜IMšœ ˜ Mšœ ˜ šžœžœžœ˜(Mšžœ žœ˜$Mšžœžœ˜Mšžœ žœžœ˜9Mšœ˜—Mšžœžœ˜Mšœ˜—Mšžœžœ˜—Mšœ ˜ Mšžœ˜—Mšžœ˜Mšœ˜—Mš œžœžœžœžœ˜,Mšœ žœ˜$Mšœ žœ˜Mšœ žœ˜Mšœ žœžœ ˜Mšžœžœ-žœ˜RMšžœžœžœ'žœ˜VMšœ˜Mšœ˜š žœžœžœžœžœ˜MMšœžœ˜ MšœJ˜JMšœ&˜&Mšœ˜—Mšžœ žœ˜#šžœžœ5žœ˜AMšœ5˜5Mšœ˜Mšœ˜Mšœ˜—Mšžœ?˜CMšžœžœžœp˜ˆMšœ˜——™š   œžœ žœžœžœ˜5š œ žœ žœžœžœ˜=Kšžœ*˜,Kšžœ˜Kšœ˜—Jšœžœ ˜?Jšœžœ?˜IJšœžœ=˜FJšœB˜BJšžœ˜Jšžœ˜Jšžœ˜šžœžœžœž˜"Kšœžœ9˜CKšœ:˜:Kšœ žœN˜[Jšžœžœ˜-Jšœ&˜&Jšžœ˜Jšœ˜Kšžœ˜—Jšžœ˜J˜J˜—š œ˜3Kš œžœžœžœžœ˜,Kšœ žœ˜&Kšžœ žœžœžœ*˜HJš œžœ žœžœ.žœ˜~J˜J˜——™š  œžœžœžœžœžœžœ˜TKšœ žœ˜š œ žœ žœžœžœ˜=Kšžœ*˜,Kšžœ˜Kšœ˜—Jšœ)˜)šœžœžœ˜+KšžœT˜XKšžœ ˜—šœ žœ"˜0K™I—Kšœ>˜>Jšœ žœ˜+Jšžœ˜š žœ žœ:žœ žœž˜eJšœžœžœ˜7JšœD˜DJšžœ˜Jšžœ˜šžœžœžœž˜"Kšœ žœN˜[Jšžœ˜Jšžœ@˜BJšœ&˜&Jšžœ˜Kšžœ˜—Kšžœ˜—Jšœ˜J–†[from: ROPE, to: ROPE, setKeep: BOOL _ FALSE, keep: CARDINAL _ 1B (1), wantedCreatedTime: GMT _ nullGMT, wDir: ROPE _ NIL]šžœ*˜,Jšžœžœ#˜5Jšžœ˜J˜J˜—š œ˜7Kš œžœžœžœžœ˜,Kšœ žœ˜'Kšœžœ˜!Kš žœžœžœžœžœžœ*˜`Jš œ,žœ žœžœ.žœ˜‹J˜J˜——™K–x[key: ROPE, proc: Commander.CommandProc, doc: ROPE _ NIL, clientData: REF ANY _ NIL, interpreted: BOOL _ TRUE]šœͺ˜ͺK˜K–x[key: ROPE, proc: Commander.CommandProc, doc: ROPE _ NIL, clientData: REF ANY _ NIL, interpreted: BOOL _ TRUE]šœΐ˜ΐK˜šœ’˜’J˜—–x[key: ROPE, proc: Commander.CommandProc, doc: ROPE _ NIL, clientData: REF ANY _ NIL, interpreted: BOOL _ TRUE]šœΈ˜ΈJ˜—–x[key: ROPE, proc: Commander.CommandProc, doc: ROPE _ NIL, clientData: REF ANY _ NIL, interpreted: BOOL _ TRUE]šœΆ˜ΆJ˜—–x[key: ROPE, proc: Commander.CommandProc, doc: ROPE _ NIL, clientData: REF ANY _ NIL, interpreted: BOOL _ TRUE]šœΠ˜ΠJ˜——Kšžœ˜—…—$H5Η