DIRECTORY Ascii, BasicTime, Buttons, Commander USING [CommandProc, Register], Containers USING [ChildXBound, ChildYBound, Container, Create], Convert, FS, IO, MessageWindow, RefText, Rope, PrintDirDefs, Rules USING [Create, Rule], SafeStorage, SirPress, TSFont, TSTypes, TypeScript, VFonts, ViewerClasses USING [Viewer, ViewerClassRec], ViewerIO USING [CreateViewerStreams], ViewerOps USING [CreateViewer, PaintViewer], ViewerTools USING [GetContents, MakeNewTextViewer, SetSelection]; PrintDir: CEDAR PROGRAM IMPORTS BasicTime, Buttons, Commander, Containers, Convert, FS, IO, MessageWindow, RefText, Rope, Rules, SafeStorage, SirPress, TSFont, TSTypes, TypeScript, VFonts, ViewerIO, ViewerOps, ViewerTools = BEGIN OPEN PrintDirDefs; entryHeight: CARDINAL = 15; -- how tall to make each line of items entryVSpace: CARDINAL = 8; -- vertical leading space between lines entryHSpace: CARDINAL = 10; -- horizontal space between items in a line ROPE: TYPE = Rope.ROPE; STREAM: TYPE = IO.STREAM; dash: CHAR = Ascii.ControlV; Problem: ERROR = CODE; MakeTool: Commander.CommandProc = BEGIN rule: Rules.Rule; my: Handle _ NEW[MyRec]; my.outer _ Containers.Create[[-- construct the outer container name: "Directory Printer", -- name displayed in the caption iconic: TRUE, -- so tool will be iconic (small) when first created column: left, -- initially in the left column scrollable: FALSE ]]; -- inhibit user from scrolling contents MakeCommands[my]; -- build each (sub)viewer in turn rule _ Rules.Create [[parent: my.outer, wy: my.height, ww: my.outer.cw, wh: 2]]; Containers.ChildXBound[my.outer, rule]; my.height _ my.height + entryHeight + 2; -- interline spacing MakeTypescript[my]; ViewerOps.PaintViewer[my.outer, all]; -- reflect above change END; faceNormal: CARDINAL = 0; faceItalic: CARDINAL = 1; faceBold: CARDINAL = 2; faceBoldItalic: CARDINAL = 3; LookupFonts: PROC [handle: Handle] = { DoFont: PROC [class: FontClass, family: ROPE, size: INT, face: CARDINAL _ faceNormal] = { handle.fontCode[class] _ handle.press.GetFontCode[ family: family, size: size, face: face]; handle.fontInfo[class] _ TSFont.Lookup[ (SELECT face FROM faceItalic => Rope.Concat[family, "I"], faceBold => Rope.Concat[family, "B"], faceBoldItalic => Rope.Concat[family, "BI"], ENDCASE => family), TSTypes.IntDimn[size, TSTypes.bp]]; }; DoFont[body, "TimesRoman", handle.dim.fontSize]; DoFont[bodyBold, "TimesRoman", handle.dim.fontSize, faceBold]; DoFont[bodyItalic, "TimesRoman", handle.dim.fontSize, faceItalic]; DoFont[bodyBoldItalic, "TimesRoman", handle.dim.fontSize + 1, faceBoldItalic]; DoFont[headingLarge, "TimesRoman", 12]; DoFont[headingSmall, "TimesRoman", 10]; DoFont[pageNum, "TimesRoman", 10]; DoFont[date, "Helvetica", 10]; DoFont[tabs, "Helvetica", handle.dim.tabHeight]; DoFont[display, "TimesRoman", handle.dim.displayHeight, faceBold]; DoFont[symbols, "Math", 10]; DoFont[campaign, "Gacha", handle.dim.fontSize]; DoFont[comment, "Helvetica", 8, faceItalic]; }; MakeTypescript: PROC [handle: Handle] = BEGIN handle.height _ handle.height + entryVSpace; -- space down from the top of the viewer handle.ts _ TypeScript.Create[ info: [name: "PrintDir.ts", wy: handle.height, parent: handle.outer, border: FALSE ]]; [handle.tsIn, handle.tsOut] _ ViewerIO.CreateViewerStreams [ name: "PrintDir.ts", viewer: handle.ts, backingFile: "PrintDir.ts", editedStream: FALSE]; Containers.ChildXBound[handle.outer, handle.ts]; Containers.ChildYBound[handle.outer, handle.ts]; END; MakeCommands: PROC [handle: Handle] = BEGIN initialData: Rope.ROPE = NIL; wx: INT _ 0; NewLine: PROC = {handle.height _ handle.height + entryHeight + entryVSpace; wx _ 0}; LabeledItem: PROC [label: ROPE, width: INT, data: ROPE _ NIL] RETURNS [v: ViewerClasses.Viewer] = { ph: PromptHandle _ NEW [PromptRec _ [handle: handle]]; t: Buttons.Button _ Buttons.Create[ info: [ name: Rope.Concat[label, ":"], wy: handle.height, wh: entryHeight, -- specify rather than defaulting so line is uniform wx: wx, parent: handle.outer, border: FALSE ], proc: Prompt, clientData: ph]; -- this will be passed to our button proc wx _ wx + t.ww + entryHSpace; v _ ViewerTools.MakeNewTextViewer[ [ parent: handle.outer, wx: wx, wy: handle.height, ww: width*VFonts.CharWidth['0], wh: entryHeight, data: data, scrollable: FALSE, border: FALSE]]; ph.viewer _ v; wx _ wx + v.ww + entryHSpace}; Cmd: PROC [label: ROPE, proc: Buttons.ButtonProc] = { t: Buttons.Button _ Buttons.Create[ info: [ name: label, wx: wx, wy: handle.height, wh: entryHeight, -- specify rather than defaulting so line is uniform parent: handle.outer, border: TRUE ], proc: proc, clientData: handle]; -- this will be passed to our button proc wx _ wx + t.ww + entryHSpace}; Bool: PROC [label: ROPE, initial: BOOL] RETURNS [flag: REF BOOL] = { t: Buttons.Button; flag _ NEW[BOOL _ initial]; t _ Buttons.Create[ info: [ name: label, wx: wx, wy: handle.height, wh: entryHeight, -- specify rather than defaulting so line is uniform parent: handle.outer, border: TRUE ], proc: ToggleBool, clientData: flag]; -- this will be passed to our button proc Buttons.SetDisplayStyle[ button: t, style: IF initial THEN $WhiteOnBlack ELSE $BlackOnWhite, paint: FALSE]; wx _ wx + t.ww + entryHSpace}; NewLine[]; Cmd["Print", DoIt]; NewLine[]; handle.cmd.inputFile _ LabeledItem["input", 50, "///FUMC/"]; NewLine[]; handle.cmd.pressFile _ LabeledItem["press", 50, "///FUMC/"]; NewLine[]; handle.cmd.heading _ LabeledItem["heading", 50]; NewLine[]; handle.actualLevel _ Bool["actualLevel", FALSE]; handle.mailingOnly _ Bool["mailing only", FALSE]; handle.flagCallers _ Bool["flag callers", FALSE]; handle.callersOnly _ Bool["callers only", FALSE]; handle.cmd.callers _ LabeledItem["callers", 40, "///FUMC/CallerNames.txt"]; NewLine[]; handle.cmd.firstRecruiter _ LabeledItem["first Recruiter #", 5, "2"]; handle.cmd.lastRecruiter _ LabeledItem["last Recruiter #", 5, "12"]; NewLine[]; handle.duplex _ Bool["duplex", FALSE]; handle.cmd.yLead _ LabeledItem["paraLead", 5, "8"]; handle.cmd.fontSize _ LabeledItem["fontSize", 5, "10"]; handle.cmd.lineHeight _ LabeledItem["lineHeight", 5, "12"]; NewLine[]; handle.separatePages _ Bool["separatePages", FALSE]; handle.showCallers _ Bool["showCallers", FALSE]; handle.alphaSort _ Bool["alphaSort", TRUE]; handle.zipSort _ Bool["zipSort", FALSE]; handle.ageSort _ Bool["ageSort", FALSE]; handle.dinnerSort _ Bool["dinnerSort", FALSE]; NewLine[]; handle.cmd.topMargin _ LabeledItem["topMargin", 5, "72"]; handle.cmd.bottomMargin _ LabeledItem["bottomMargin", 5, "66"]; handle.cmd.leftMargin _ LabeledItem["leftMargin", 5, "72"]; handle.cmd.rightMargin _ LabeledItem["rightMargin", 5, "72"]; NewLine[]; handle.cmd.displayHeight _ LabeledItem["displayFontSize", 5, "18"]; handle.cmd.tabHeight _ LabeledItem["indexFontSize", 5, "8"]; handle.cmd.nameIndent _ LabeledItem["nameIndent", 5, "18"]; NewLine[]; END; Prompt: Buttons.ButtonProc -- [parent: REF ANY, clientData: REF ANY _ NIL, mouseButton: Menus.MouseButton _ red, shift: BOOL _ FALSE, control: BOOL _ FALSE] -- = BEGIN ph: PromptHandle _ NARROW[clientData]; ViewerTools.SetSelection[ph.viewer]; -- force the selection END; ToggleBool: Buttons.ButtonProc = { switch: REF BOOL _ NARROW [clientData]; switch^ _ ~switch^; Buttons.SetDisplayStyle[ button: NARROW[parent], style: IF switch^ THEN $WhiteOnBlack ELSE $BlackOnWhite]; }; DoIt: Buttons.ButtonProc -- [parent: REF ANY, clientData: REF ANY _ NIL, mouseButton: Menus.MouseButton _ red, shift: BOOL _ FALSE, control: BOOL _ FALSE] -- = BEGIN handle: Handle _ NARROW[clientData]; -- get our data BEGIN ENABLE { UNWIND => {IF handle.in # NIL THEN handle.in.Close[]; handle.in _ NIL}; Problem, ABORTED => {handle.tsOut.PutText[" aborted"]; GO TO done}}; fName: ROPE = ViewerTools.GetContents[handle.cmd.inputFile]; pName: ROPE = ViewerTools.GetContents[handle.cmd.pressFile]; Val: PROC [v: ViewerClasses.Viewer, default: INT] RETURNS [n: INT] = { n _ Convert.IntFromRope[ViewerTools.GetContents[v] ! SafeStorage.NarrowFault => {n _ default; GO TO gub}; Convert.Error => { MessageWindow.Append[message: "invalid number", clearFirst: TRUE]; n _ default; GO TO gub}; ]; EXITS gub => NULL; }; IF fName = NIL OR pName = NIL THEN { handle.tsOut.Put[[rope["specify input file name"]], [character['\n]]]; RETURN}; handle.in _ OpenFile[fName]; IF handle.in # NIL THEN handle.eof _ FALSE; handle.pageNumber _ 1; IF pName # NIL AND Rope.Length[pName] # 0 THEN { nameAddr, fumcWidth: INT; handle.heading _ ViewerTools.GetContents[handle.cmd.heading]; handle.out _ FS.StreamOpen[fileName: pName, accessOptions: $create]; handle.press _ SirPress.Create[outputStream: handle.out, fileNameForHeaderPage: pName]; handle.date _ Convert.RopeFromTime[BasicTime.Now[], $years, $days]; handle.dim.yLead _ Val[handle.cmd.yLead, 8]; handle.dim.fontSize _ Val[handle.cmd.fontSize, 10]; handle.dim.lineHeight _ Val[handle.cmd.lineHeight, 12]; handle.dim.topMargin _ Val[handle.cmd.topMargin, 72]; handle.dim.bottomMargin _ Val[handle.cmd.bottomMargin, 60]; handle.dim.leftMargin _ Val[handle.cmd.leftMargin, 54]; handle.dim.rightMargin _ Val[handle.cmd.rightMargin, 72]; handle.dim.displayHeight _ Val[handle.cmd.displayHeight, 18]; handle.dim.tabHeight _ Val[handle.cmd.tabHeight, 8]; handle.dim.tabHeight _ Val[handle.cmd.tabHeight, 8]; handle.dim.firstRecruiter _ Val[handle.cmd.firstRecruiter, 18]; handle.dim.lastRecruiter _ Val[handle.cmd.lastRecruiter, 18]; handle.press.SetPageSize[110, 85]; LookupFonts[handle]; handle.yTop _ pageHeight - handle.dim.topMargin; handle.callerRight _ handle.dim.leftMargin - PWidth[handle, "mmmm ", campaign] - 4; handle.phoneX _ handle.dim.leftMargin; handle.phoneX2 _ handle.phoneX + PWidth[handle, "(415) ", body]; handle.nameX _ handle.phoneX + PWidth[handle, "(415) 321-9039", body] + 12; handle.zipX _ pageWidth - handle.dim.rightMargin - PWidth[handle, "94303", body]; handle.townX _ handle.zipX - PWidth[handle, "EPA", body] - 9; nameAddr _ handle.townX - handle.nameX; handle.addrX _ handle.nameX + (6*nameAddr)/10; handle.callerX _ handle.addrX; handle.recruiterX _ handle.callerX + (pageWidth - handle.dim.rightMargin - handle.callerX)/2; handle.addrPWidth _ handle.townX - handle.addrX; fumcWidth _ PWidth[handle, handle.heading, headingLarge]; handle.fumcX _ CenterX[handle, fumcWidth]; handle.dateX _ RightX[handle, PWidth[handle, handle.date, date]]; handle.prevInitial _ 0C; handle.prevZip _ NIL; handle.firstOnPage _ NIL; handle.affiliateThisPage _ FALSE; IF handle.callersOnly^ AND handle.callerName = NIL THEN handle.callerName _ ParseCallerNames[handle]; } ELSE handle.press _ NIL; handle.tsOut.PutText["Processing:"]; WHILE ~handle.eof DO ProcessEntry[handle]; ENDLOOP; IF handle.press # NIL THEN { FinishPage[handle]; handle.press.ClosePress[]; handle.press _ NIL}; EXITS done => NULL; END; -- of Enable IF handle.in # NIL THEN handle.in.Close[]; IF handle.out # NIL THEN handle.out.Close[]; handle.tsOut.Put[[character['\n]], [rope["done"]], [character['\n]]]; END; CenterX: PROC [h: Handle, w: INT] RETURNS [x: INT] = { RETURN[ h.dim.leftMargin + (pageWidth - h.dim.leftMargin - h.dim.rightMargin - w)/2]}; RightX: PROC [h: Handle, w: INT] RETURNS [x: INT] = { RETURN[pageWidth - h.dim.rightMargin - w]}; PWidth: PROC [h: Handle, s: ROPE, class: FontClass] RETURNS [INT] = { w: TSTypes.Dimn _ [0]; ref: TSFont.Ref _ h.fontInfo[class]; IF ref = NIL THEN RETURN [0]; FOR i: INT IN [0..Rope.Length[s]) DO w _ [w + TSFont.Width[ref, Rope.Fetch[s, i]]]; ENDLOOP; RETURN [TSTypes.DimnInt[w, TSTypes.pt]]; }; UC: PROC [c: CHAR] RETURNS [CHAR] = { RETURN[IF c IN ['a..'z] THEN VAL[c.ORD - ORD['a] + ORD['A]] ELSE c]}; CFName: PROC [h: Handle, name: ROPE] RETURNS [cf: ROPE] = { funny: BOOLEAN _ FALSE; lastName: REF TEXT _ NEW[TEXT[Rope.Length[name]]]; -- plenty long FOR i: INT IN [0..Rope.Length[name]) DO c: CHAR _ UC[Rope.Fetch[name, i]]; SELECT c FROM ', => EXIT; '*, '+ => LOOP; ENDCASE => { IF c = ' AND ~funny THEN { funny _ TRUE; h.tsOut.Put[[character['\n]], [rope[name]], [character['\n]]]}; lastName[lastName.length] _ c; lastName.length _ lastName.length + 1}; ENDLOOP; RETURN[Rope.FromRefText[lastName]]}; PressNames: PROC [h: Handle, name: ARRAY [0..4) OF ROPE, flag: BOOLEAN] = { ascent: INT = h.dim.fontSize; PT: PROC [t: ROPE, x, y: INT] = { SirPress.PutText[p: h.press, textString: t, xCoordinateOfLeftEdge: x, yCoordinateOfBaseline: y, unit: SirPress.pt]}; PTH: PROC [t: ROPE, f: FontClass] = { h.press.SetFontFromCode[h.fontCode[f]]; SirPress.PutTextHere[p: h.press, textString: t]}; SF: PROC [class: FontClass] = {h.press.SetFontFromCode[h.fontCode[class]]}; NameBreak: IO.BreakProc = { RETURN [SELECT char FROM '&, ', => break, '\t => sepr, -- blanks are allowed in names ENDCASE => other]}; default: FontClass _ bodyBold; ns: STREAM _ NIL; GetName: PROC RETURNS [r: ROPE, cl: FontClass, affiliate: BOOLEAN, brk: CHAR] = { cl _ default; affiliate _ FALSE; [] _ ns.SkipWhitespace[]; IF ns.EndOf[] THEN RETURN [NIL, cl, FALSE, 0C]; SELECT ns.PeekChar[] FROM '+ => {h.affiliateThisPage _ affiliate _ TRUE; [] _ ns.GetChar[]}; '* => {cl _ bodyItalic; [] _ ns.GetChar[]}; ENDCASE; r _ GetTokenRope[ns, NameBreak].token; IF ns.EndOf[] THEN brk _ 0C ELSE brk _ ns.GetChar[]}; t: ROPE; bk: CHAR; affiliate: BOOLEAN; fc: FontClass; ns _ IO.RIS[name[0]]; [t, default, affiliate, bk] _ GetName[]; -- last name IF flag THEN default _ bodyBoldItalic; IF affiliate THEN { SF[symbols]; PT[t: "!", x: h.nameX - PWidth[h, "!", symbols], y: h.yTop - ascent]}; SF[default]; PT[t: t, x: h.nameX, y: h.yTop - ascent]; PTH[", ", default]; DO [t, fc, affiliate, bk] _ GetName[]; IF t = NIL THEN EXIT; IF affiliate THEN PTH["!", symbols]; PTH[t, fc]; SELECT bk FROM '& => PTH["& ", default]; ', => PTH[", ", default]; ENDCASE; ENDLOOP; FOR i: CARDINAL IN [1..4) WHILE name[i] # NIL DO y: INT = h.yTop - i*h.dim.lineHeight - ascent; ns _ IO.RIS[name[i], ns]; [t, fc, affiliate, bk] _ GetName[]; IF t = NIL THEN LOOP; IF affiliate THEN { SF[symbols]; PT[t: "!", x: h.nameX + h.dim.nameIndent - PWidth[h, "!", symbols], y: y]}; SF[fc]; PT[t: t, x: h.nameX + h.dim.nameIndent, y: h.yTop - i*h.dim.lineHeight - ascent]; DO SELECT bk FROM '& => PTH["& ", default]; ', => PTH[", ", default]; ENDCASE; [t, fc, affiliate, bk] _ GetName[]; IF t = NIL THEN EXIT; IF affiliate THEN PTH["!", symbols]; PTH[t, fc]; ENDLOOP; ENDLOOP; }; PressPhone: PROC [h: Handle, phone: ARRAY [0..4) OF ROPE] = { ascent: INT = h.dim.fontSize; SF: PROC [class: FontClass] = {h.press.SetFontFromCode[h.fontCode[class]]}; PT: PROC [t: ROPE, x, y: INT] = { SirPress.PutText[p: h.press, textString: t, xCoordinateOfLeftEdge: x, yCoordinateOfBaseline: y, unit: SirPress.pt]}; FOR i: INT IN [0..4) WHILE phone[i] # NIL DO p: ROPE = phone[i]; y: INT = h.yTop - i*h.dim.lineHeight - ascent; x: INT _ h.phoneX; first: INT _ 0; work: BOOLEAN _ FALSE; IF UC[Rope.Fetch[p, 0]] = 'W THEN {work _ TRUE; first _ 1}; IF Rope.Fetch[p, first] # '( THEN x _ h.phoneX2 ELSE IF Rope.Length[p] > first+6 AND Rope.Equal[Rope.Substr[p, first, 6], "(415) "] THEN { x _ h.phoneX2; first _ first + 6}; IF UC[Rope.Fetch[p, first]] = 'X THEN x _ h.phoneX2 + 12; IF work THEN { SF[bodyItalic]; PT[t: "w", x: x-PWidth[h, "w", bodyItalic]-2, y: y]}; SF[body]; PT[t: Rope.Substr[p, first, Rope.Length[p] - first], x: x, y: y]; ENDLOOP}; PressEntry: PROC [h: Handle, e: Entry] = { ascent: INT = h.dim.fontSize; lastName: ROPE; eLines: CARDINAL _ 1; tLine, zLine: CARDINAL _ 0; newLetter: BOOLEAN _ FALSE; SF: PROC [class: FontClass] = {h.press.SetFontFromCode[h.fontCode[class]]}; PT: PROC [t: ROPE, x, y: INT] = { SirPress.PutText[p: h.press, textString: t, xCoordinateOfLeftEdge: x, yCoordinateOfBaseline: y, unit: SirPress.pt]}; x, eh, eh2: INT; myFirst: CHAR; ez: ROPE _ IF e.zip = NIL THEN "" ELSE e.zip; FOR i: CARDINAL DECREASING IN [0..4) DO IF e.phone[i] # NIL THEN {eLines _ MAX[eLines, i+1]; EXIT}; ENDLOOP; FOR i: CARDINAL DECREASING IN [0..4) DO IF e.name[i] # NIL THEN {eLines _ MAX[eLines, i+1]; EXIT}; ENDLOOP; IF ~h.callersOnly^ THEN { FOR i: CARDINAL DECREASING IN [0..4) DO IF e.addr [i] # NIL THEN {eLines _ MAX[eLines, i+1]; EXIT}; ENDLOOP; IF e.town # NIL THEN { WHILE PWidth[h, e.addr[tLine], body] > h.addrPWidth DO IF tLine = 4 THEN Quit[h, "no room for town"]; tLine _ tLine + 1; ENDLOOP; zLine _ tLine} ELSE FOR i: CARDINAL DECREASING IN [0..4) DO IF e.addr[i] # NIL THEN {zLine _ i; EXIT}; ENDLOOP; }; eLines _ MAX[eLines, tLine+1, zLine+1]; eh _ eLines * h.dim.lineHeight; lastName _ CFName[h, e.name[0]]; myFirst _ SELECT TRUE FROM h.alphaSort^ => Rope.Fetch[lastName, 0], h.ageSort^ => e.age, h.dinnerSort^ => e.dinner, ENDCASE => 0C; newLetter _ SELECT TRUE FROM h.alphaSort^, h.ageSort^, h.dinnerSort^ => h.prevInitial # myFirst, h.zipSort^ => (h.prevZip = NIL OR ~Rope.Equal[h.prevZip, ez]), ENDCASE => FALSE; IF newLetter THEN eh2 _ eh + 2*h.dim.displayHeight ELSE eh2 _ eh; IF h.yTop - eh2 < h.dim.bottomMargin THEN FinishPage[h]; IF newLetter THEN { l: ROPE = IF h.zipSort^ THEN ez ELSE Rope.FromChar[myFirst]; IF h.separatePages^ AND h.firstOnPage # NIL THEN FinishPage[h]; h.yTop _ h.yTop - h.dim.displayHeight; h.press.SetFontFromCode[h.fontCode[display]]; PT[t: l, x: CenterX[h, PWidth[h, l, display]], y: h.yTop]; IF h.zipSort^ THEN h.tsOut.Put[[rope[ez]], [character[' ]]] ELSE h.tsOut.PutChar[myFirst]; h.yTop _ h.yTop - h.dim.displayHeight; h.prevInitial _ myFirst; h.prevZip _ ez}; SF[body]; IF h.showCallers^ THEN { t: ROPE = Convert.RopeFromInt[e.caller]; PT[t: t, x: h.callerRight - PWidth[h, t, body], y: h.yTop - ascent]}; SF[campaign]; PT[t: Rope.FromChar[e.activity], x: h.dim.leftMargin - PWidth[h, "mmmm ", campaign], y: h.yTop - ascent]; IF ~h.actualLevel^ AND e.level IN ['1..'9] THEN e.level _ 'p; PT[t: Rope.FromChar[e.level], x: h.dim.leftMargin - PWidth[h, "mmm ", campaign], y: h.yTop - ascent]; PT[t: Rope.FromChar[e.dinner], x: h.dim.leftMargin - PWidth[h, "mm ", campaign], y: h.yTop - ascent]; PT[t: Rope.FromChar[e.age], x: h.dim.leftMargin - PWidth[h, "m ", campaign], y: h.yTop - ascent]; SF[body]; PressPhone[h, e.phone]; PressNames[h, e.name, h.flagCallers^ AND e.caller IN [h.dim.firstRecruiter..h.dim.lastRecruiter]]; SF[body]; IF h.mailingOnly^ THEN { IF e.mailing # NIL THEN PT[t: e.mailing, x: h.callerX, y: h.yTop - ascent]} ELSE IF h.callersOnly^ THEN { c: ROPE; r: CallerNumber; rn: ROPE; [name: c, recruiter: r] _ h.callerName[e.caller]; rn _ h.callerName[r].name; IF c # NIL THEN PT[t: c, x: h.callerX, y: h.yTop - ascent]; IF rn # NIL THEN PT[t: rn, x: h.recruiterX, y: h.yTop - ascent]; } ELSE { x _ h.addrX; FOR i: CARDINAL IN [0..4) DO IF e.addr[i] = NIL THEN EXIT; PT[t: e.addr[i], x: x, y: h.yTop - i*h.dim.lineHeight - ascent]; ENDLOOP; IF e.town # NIL THEN PT[t: e.town, x: h.townX, y: h.yTop - tLine*h.dim.lineHeight - ascent]; IF e.zip # NIL THEN PT[t: e.zip, x: h.zipX, y: h.yTop - zLine*h.dim.lineHeight - ascent]; IF e.comment # NIL THEN { SF[comment]; PT[t: e.comment, x: pageWidth - h.dim.rightMargin + 6, y: h.yTop - ascent]}; }; h.yTop _ h.yTop - eh - h.dim.yLead; h.lastOnPage _ IF h.alphaSort^ THEN lastName ELSE ez; IF h.firstOnPage = NIL THEN h.firstOnPage _ h.lastOnPage; }; FinishPage: PROC [h: Handle] = { names, pageText: ROPE; nx, dx, hy: INT; PT: PROC [t: ROPE, x, y: INT] = { SirPress.PutText[p: h.press, textString: t, xCoordinateOfLeftEdge: x, yCoordinateOfBaseline: y, unit: SirPress.pt]}; PTH: PROC [t: ROPE, f: FontClass] = { h.press.SetFontFromCode[h.fontCode[f]]; SirPress.PutTextHere[p: h.press, textString: t]}; SF: PROC [class: FontClass] = {h.press.SetFontFromCode[h.fontCode[class]]}; h.press.PutRectangle[ xstart: h.dim.leftMargin, ystart: pageHeight - h.dim.topMargin + h.dim.lineHeight, xlen: pageWidth - h.dim.leftMargin - h.dim.rightMargin, ylen: 1, unit: SirPress.pt]; names _ IF ~(h.alphaSort^ OR h.zipSort^) THEN NIL ELSE IF Rope.Equal[h.firstOnPage, h.lastOnPage] THEN h.firstOnPage ELSE Rope.Cat[h.firstOnPage, Rope.FromChar[dash], h.lastOnPage]; hy _ pageHeight - h.dim.topMargin + 2*h.dim.lineHeight; IF ~h.duplex^ OR (h.pageNumber MOD 2 = 1) THEN { nx _ RightX[h, PWidth[h, names, tabs]]; dx _ h.dim.leftMargin} ELSE {nx _ h.dim.leftMargin; dx _ h.dateX}; SF[tabs]; PT[t: names, x: nx, y: hy]; SF[date]; PT[t: h.date, x: dx, y: hy]; SF[headingLarge]; PT[t: h.heading, x: h.fumcX, y: hy]; pageText _ Convert.RopeFromInt[h.pageNumber]; nx _ CenterX[h, PWidth[h, pageText, pageNum]]; SF[pageNum]; PT[t: pageText, x: nx, y: h.dim.bottomMargin - 3*h.dim.lineHeight]; IF h.affiliateThisPage THEN { SF[symbols]; PT["!", h.dim.leftMargin, h.dim.bottomMargin - 2*h.dim.lineHeight]; PTH[" affiliate member", bodyItalic]}; h.press.WritePage[]; h.yTop _ pageHeight - h.dim.topMargin; h.firstOnPage _ h.lastOnPage _ NIL; h.affiliateThisPage _ FALSE; h.pageNumber _ h.pageNumber + 1; }; MyBreak: IO.BreakProc -- [char: CHAR] RETURNS [IO.CharClass] -- = { RETURN [SELECT char FROM '\\, '|, '}, '\n => break, '\t, ', ' => sepr, ENDCASE => other]; }; OpenFile: PROC [name: ROPE] RETURNS [st: STREAM] = { st _ FS.StreamOpen[name, $read ! FS.Error => IF error.group # bug THEN CONTINUE]}; ProcessEntry: PROC [handle: Handle] = { e: Entry; IF handle.eof THEN RETURN; IF handle.in = NIL THEN { MessageWindow.Append[ message: "Please open a file first", clearFirst: TRUE]; MessageWindow.Blink[ ]; ERROR ABORTED}; [] _ handle.in.SkipWhitespace[]; IF handle.in.EndOf[] THEN {handle.eof _ TRUE; GO TO done}; e _ ReadEntry[handle]; IF handle.press # NIL THEN PressEntry[handle, e]; EXITS done => NULL; }; ReadEntry: PROC [handle: Handle] RETURNS [e: Entry] = { ENABLE IO.EndOfStream => {handle.eof _ TRUE; Quit[handle, "Syntax error "]}; st: STREAM _ handle.in; ch: CHAR; caller: ROPE; i: CARDINAL; IF (ch _ st.GetChar[]) # '{ THEN Quit[handle, "Syntax error "]; caller _ GetTokenRope[st, MyBreak].token; IF caller # NIL THEN e.caller _ Convert.IntFromRope[caller ! Convert.Error => Quit[handle, "bad caller #"]]; IF (ch _ st.GetChar[]) # '| THEN Quit[handle, "Syntax error "]; BEGIN -- get campaign info IF (ch _ st.GetChar[]) = '| THEN GO TO done; e.activity _ ch; IF (ch _ st.GetChar[]) = '| THEN GO TO done; e.level _ ch; IF (ch _ st.GetChar[]) = '| THEN GO TO done; e.dinner _ ch; IF (ch _ st.GetChar[]) = '| THEN GO TO done; e.age _ ch; IF (ch _ st.GetChar[]) # '| THEN Quit[handle, "Syntax error "]; EXITS done => NULL; END; i _ 0; DO e.phone[i] _ GetTokenRope[st, MyBreak].token; SELECT (ch _ st.GetChar[]) FROM '\\ => IF i = 2 THEN Quit[handle, "Syntax error "]; '| => EXIT; '} => RETURN; ENDCASE => Quit[handle, "Syntax error "]; i _ i + 1; ENDLOOP; i _ 0; DO e.name[i] _ GetTokenRope[st, MyBreak].token; SELECT (ch _ st.GetChar[]) FROM '\\ => IF i = 3 THEN Quit[handle, "Syntax error "]; '| => EXIT; '} => RETURN; ENDCASE => Quit[handle, "Syntax error "]; i _ i + 1; ENDLOOP; i _ 0; DO e.addr[i] _ GetTokenRope[st, MyBreak].token; SELECT (ch _ st.GetChar[]) FROM '\\ => IF i = 3 THEN Quit[handle, "Syntax error "]; '| => EXIT; '} => RETURN; ENDCASE => GO TO badsyntax; i _ i + 1; ENDLOOP; e.town _ GetTokenRope[st, MyBreak].token; IF st.GetChar[] = '} THEN RETURN; e.zip _ GetTokenRope[st, MyBreak].token; IF st.GetChar[] = '} THEN RETURN; e.mailing _ GetTokenRope[st, MyBreak].token; IF st.GetChar[] = '} THEN RETURN; e.comment _ GetTokenRope[st, MyBreak].token; IF st.GetChar[] # '} THEN Quit[handle, "Syntax error "]; EXITS badsyntax => Quit[handle, "Syntax error "]; }; ParseCallerNames: PROC [h: Handle] RETURNS [n: REF CallerNameRec] = { cnfile: ROPE _ ViewerTools.GetContents[h.cmd.callers]; ch: CHAR; r: INT _ 0; index: INT; c, p: ROPE; st: STREAM; n _ NEW[CallerNameRec _ ALL[[NIL, NIL, 0]]]; st _ OpenFile[cnfile]; IF st = NIL THEN Quit2[h, st, "No caller names"]; WHILE ~st.EndOf[] DO ENABLE IO.Error => Quit2[h, st, "invalid callernames"]; c _ p _ NIL; [] _ st.SkipWhitespace[]; IF st.EndOf[] THEN RETURN; index _ st.GetInt[]; IF NOT (index IN CallerNumber) THEN Quit2[h, st, "Index invalid in callernames"]; IF st.GetChar[] # '\t THEN Quit2[h, st, "Missing tab in callernames"]; c _ GetTokenRope[st, MyBreak].token; BEGIN IF ~st.EndOf[] THEN SELECT (ch _ st.GetChar[]) FROM '\n => GO TO done; '| => NULL; ENDCASE => Quit2[h, st, "Syntax error in callernames"]; p _ GetTokenRope[st, MyBreak].token; IF ~st.EndOf[] THEN SELECT (ch _ st.GetChar[]) FROM '\n => GO TO done; '| => NULL; ENDCASE => Quit2[h, st, "Syntax error in callernames"]; [] _ st.SkipWhitespace[]; IF st.EndOf[] THEN RETURN; r _ st.GetInt[]; IF st.GetChar[] # '\n THEN Quit2[h, st, "Missing CR in callernames"]; EXITS done => NULL; END; n[index] _ [name: c, phone: p, recruiter: r]; ENDLOOP; st.Close[]}; Quit: PROC [handle: Handle, reason: ROPE _ NIL] = { loc: INT = handle.in.GetIndex[]; handle.in.Close[]; handle.in _ NIL; handle.eof _ TRUE; handle.tsOut.Put[[rope[reason]], [integer[loc]], [character['\n]]]; ERROR Problem}; Quit2: PROC [handle: Handle, st: STREAM, reason: ROPE _ NIL] = { loc: INT = st.GetIndex[]; st.Close[]; handle.tsOut.Put[[rope[reason]], [integer[loc]], [character['\n]]]; ERROR Problem}; GetToken: PROC [stream: STREAM, breakProc: IO.BreakProc, buffer: REF TEXT] RETURNS[token: REF TEXT, charsSkipped: INT] = { quit, include: BOOL _ FALSE; anySeen: BOOL _ FALSE; charsSkipped _ 0; buffer.length _ 0; DO char: CHAR _ stream.GetChar[ ! IO.EndOfStream => IF buffer.length > 0 THEN EXIT ELSE REJECT]; SELECT breakProc[char] FROM break => {include _ FALSE; quit _ TRUE}; sepr => {include _ FALSE; quit _ anySeen }; other => {include _ TRUE; quit _ FALSE; anySeen _ TRUE}; ENDCASE => ERROR; IF include THEN buffer _ RefText.InlineAppendChar[buffer, char] ELSE IF quit THEN stream.Backup[char] ELSE charsSkipped _ charsSkipped + 1; IF quit THEN EXIT; ENDLOOP; RETURN[buffer, charsSkipped]; }; GetTokenRope: PUBLIC PROC [stream: STREAM, breakProc: IO.BreakProc] RETURNS [token: ROPE, charsSkipped: INT] = { buffer: REF TEXT = RefText.ObtainScratch[100]; { ENABLE UNWIND => RefText.ReleaseScratch[buffer]; tokenText: REF TEXT; [tokenText, charsSkipped] _ GetToken[stream, breakProc, buffer]; token _ IF tokenText.length = 0 THEN NIL ELSE Rope.FromRefText[tokenText]; }; RefText.ReleaseScratch[buffer]; RETURN [token, charsSkipped]; }; Commander.Register[key: "PrintDir", proc: MakeTool, doc: "Create a church directory printer" ]; [ ] _ MakeTool[NIL]; -- and create an instance END. °PrintDir.mesa; Last Edited by: Sweet, October 8, 1984 11:08:58 am PDT The Containers interface is used to create an outer envelope or "container" for the different sections below. For uniformity, we define some standard distances between entries in the tool. default the width so that it will be computed for us -- default the width so that it will be computed for us -- default the width so that it will be computed for us -- force the selection into the user input field force the selection into the user input field do I have to close ns? NO. one should SkipWhitespace before calling (and check for eof) copied from IOSearchImpl because it didn't handle empty tokens properly Κ!O– "Cedar" style˜Iproc– "Cedar" stylešœ™J™6unitšΟk ˜ Lšœ˜J˜ Jšœ˜Jšœ œ˜(Jšœ œ/˜?J˜Jšœ˜Jšœ˜J˜J˜Jšœ˜J˜ Jšœœ˜J˜ J˜ J˜J˜J˜ J˜Jšœœ˜-Jšœ œ˜%Jšœ œ˜,Jšœ œ0˜A—šœ œœ˜Jšœ9œ…˜Η—Lšœœ˜Jšœ½™½Jšœ œΟc&˜BJšœ œž'˜CJšœ œž+˜HJšœœœ˜Jšœœœœ˜Jšœœ˜J˜J˜Jšœ œœ˜L˜šœ"˜'Jšœ˜Jšœ œ˜emphasisšœžœ˜>Jšœž ˜;Jšœœž4˜DJšœž˜0Jšœ œœž'˜>—Jšœž!˜4JšœP˜PJšœ'˜'Jšœ)ž˜=Jšœ˜Jšœ)ž˜@Jšœ˜—Jšœ œ˜Jšœ œ˜Jšœ œ˜Jšœœ˜J˜šΟn œœ˜&š Ÿœœœœ œ˜Zšœ2˜2J˜J˜ J˜ —˜(˜J˜'J˜%J˜,J˜—J˜#—J˜—J˜0Jšœ>˜>JšœB˜BJšœN˜NJšœ'˜'Jšœ'˜'Jšœ"˜"J˜J˜0JšœB˜BJšœ˜Jšœ/˜/Jšœ,˜,Jšœ˜—šŸœœœ˜.Jšœ-ž(˜Ušœ˜JšœMœ˜V—šœ<˜Jšœ%˜%Jšœœ ˜6šœ#˜#šœ˜Jšœ˜Jšœ˜Jšœ7™7Jšœž4˜EJšœ˜Jšœ˜Jšœœ˜—Jšœ ˜ Jšœž)˜:—Jšœ˜šœ$˜$Jšœ˜Jšœ˜Jšœ˜Jšœ˜Jšœ˜Jšœ ˜ Jšœ œ˜Jšœœ˜—J˜Jšœ˜—šŸœœ œ˜5šœ#˜#šœ˜Jšœ ˜ J˜Jšœ˜Jšœ7™7Jšœž4˜EJšœ˜Jšœœ˜—Jšœ ˜ Jšœž(œ˜>—Jšœ˜—šŸœœ œ œœœœ˜DJ˜Jšœœœ ˜šœ˜šœ˜Jšœ ˜ J˜Jšœ˜Jšœ7™7Jšœž4˜EJšœ˜Jšœœ˜—Jšœ˜Jšœž(œ˜<—J•StartOfExpansion[]š œ,œ œœœ˜lJšœ˜—J˜Jšœ ˜ J˜Jšœ ˜ Jšœ<˜Jš œœ˜—Jšœ œ!˜2Jšœ ˜Jšœ#œ˜8šœ œ˜Jšœœ5˜—Jšœ'˜+Jšœ#˜%J˜ J˜J˜J˜$J˜-J˜/J˜ J˜Cšœœ˜Jšœ œA˜PJšœ#˜&—J˜J˜&Jšœœœ˜@J˜ J˜J˜—J˜–+ -- [char: CHAR] RETURNS [IO.CharClass] -- šœ œ  *œ˜Dšœœ˜Jšœ˜J˜Jšœ ˜—J˜J˜—š Ÿœœœœœ˜4šœœ˜Jš œœ œœœ˜3—J˜—šŸ œœ˜'J˜ Jšœ œœ˜šœ œœ˜šœ˜Jšœ$˜$Jšœ œ˜—Jšœ˜Jš œ˜—Jšœ ˜ Jš œœœœœ˜:Jšœ˜Jšœœœ˜1š˜Jšœœ˜ —J˜—J˜šŸ œœœ˜7Jšœ<™