-- [parent: REF ANY, clientData: REF ANY ← NIL, mouseButton: Menus.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE] -- =
BEGIN
ENABLE {
UNWIND => {IF handle.in # NIL THEN handle.in.Close[]; handle.in ← NIL; ExitTool[handle]};
Problem, ABORTED => {handle.tsOut.PutText[" aborted"]; GO TO done};
};
iName: ROPE ← ViewerTools.GetContents[handle.cmd.inputFile];
oName: ROPE ← ViewerTools.GetContents[handle.cmd.outputFile];
pName: ROPE ← ViewerTools.GetContents[handle.cmd.pdlFile];
wDir: ROPE = ViewerTools.GetContents[handle.cmd.workingDir];
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};
];
};
various initializations
handle.item ← NEW[EntrySeqBody[Val[handle.cmd.size, 5000]]];
handle.stopFlag ← FALSE;
do the work
IF iName =
NIL
THEN {
handle.tsOut.Put[[rope["specify input file"]], [character['\n]]];
ExitTool[handle];
RETURN;
};
handle.textOutput ← handle.textP^;
handle.pdlOutput ← handle.pdlP^;
iName ← FS.ExpandName[iName, wDir !
FS.Error => Quit[handle, "bad input file"]].fullFName;
IF handle.textOutput
THEN
IF oName #
NIL
AND Rope.Length[oName] # 0
THEN oName ←
FS.ExpandName[oName, wDir !
FS.Error => Quit[handle, "bad text output file"]].fullFName
ELSE Quit[handle, "specify text output file"];
IF handle.pdlOutput
THEN
IF pName #
NIL
AND Rope.Length[pName] # 0
THEN pName ←
FS.ExpandName[pName, wDir !
FS.Error => Quit[handle, "bad label output file"]].fullFName
ELSE Quit[handle, "specify label output"];
IF ~handle.textOutput
AND ~handle.pdlOutput
THEN {
handle.tsOut.Put[[rope["specify either text or label output file (or both)"]], [character['\n]]];
ExitTool[handle];
RETURN;
};
handle.in ← OpenFile[iName];
IF handle.in # NIL THEN handle.eof ← FALSE ELSE Quit[handle, "no input file"];
total ← handle.in.GetLength[];
handle.in.SetIndex[0];
handle.doTioga ← handle.tiogaOut^;
handle.doZip ← handle.zip^;
handle.doByLastName ← handle.byLastName^;
handle.doProof ← handle.proof^;
handle.maxLines ← 7;
handle.numberProof ← handle.nProof^;
handle.numEntries ← 0;
handle.pages ← 0;
handle.row ← 0; handle.col ← 0;
handle.entryCount ← 0;
handle.entries ← handle.entryTail ← NIL;
handle.consumer ← NIL;
IF handle.pdlOutput
THEN {
ipHeader: ROPE ~ "Interpress/Xerox/2.0 ";
family: ROPE ← ViewerTools.GetContents[handle.cmd.fontFamily];
fontPattern: ROPE ← "Xerox/XC1-1-1/%g";
IF family.Find["/"] < 0 THEN family ← IO.PutFR1[fontPattern, IO.rope[family]];
handle.pdlOut ← ImagerInterpress.Create[fileName: pName, header: ipHeader];
handle.dim.fontSize ← Val[handle.cmd.fontSize, 8];
handle.dim.leftMargin ← Val[handle.cmd.leftMargin, 18];
handle.dim.lineHeight ← handle.dim.fontSize;
handle.font ← ImagerFont.FindScaled[family, handle.dim.fontSize/Imager.pointsPerInch];
};
Labels.Set[handle.cmd.status, "reading"];
WHILE ~handle.eof
DO
IF handle.stopFlag THEN {handle.tsOut.PutText["input aborted, no output"]; GO TO done};
EnterItem[handle ! IO.EndOfStream => EXIT];
PieViewers.Set[handle.pie, 1 - handle.in.GetIndex[] / total];
ENDLOOP;
PieViewers.Set[handle.pie, 0];
IF handle.doByLastName
OR handle.doZip
THEN {
Labels.Set[handle.cmd.status, "sorting"];
SortEntries[handle]};
total ← handle.item.count;
Labels.Set[handle.cmd.status, "writing"];
IF handle.textOutput
THEN {
IF handle.doTioga
THEN {
handle.root ← TiogaFileOps.CreateRoot[];
handle.prevLast ← NIL}
ELSE handle.out ← FS.StreamOpen[fileName: oName, accessOptions: $create];
};
FOR i:
INT
IN [0..handle.item.count)
DO
IF handle.stopFlag THEN {handle.tsOut.PutText["output truncated"]; EXIT};
WriteEntry[handle, handle.item[i]];
PieViewers.Set[handle.pie, 1 - i/total];
handle.item[i] ← NIL;
ENDLOOP;
PieViewers.Set[handle.pie, 0];
IF handle.pdlOutput THEN WriteEntry[handle, NIL];
IF handle.textOutput
AND handle.doTioga
THEN {
Labels.Set[handle.cmd.status, "storing"];
TiogaFileOps.Store[handle.root, oName]};
Labels.Set[handle.cmd.status, NIL];
END; -- of Enable