SetPressPrintingModeImpl.mesa
Copyright (C) 1984, Xerox Corporation. All rights reserved.
Michael Plass, November 1, 1984 4:21:07 pm PST
DIRECTORY Ascii, Commander, Basics, Rope, FS, IO, PressFormat;
SetPressPrintingModeImpl: CEDAR PROGRAM
IMPORTS Ascii, Commander, FS, IO, Rope
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
Bad: ERROR ~ CODE;
bytesPerPressPage: INT ~ 512;
bytesPerWord: INT ~ Basics.bytesPerWord;
ReadDirectory: PROC [input: IO.STREAM] RETURNS [REF PressFormat.DDV] ~ TRUSTED {
ddv: REF PressFormat.DDVNEW[PressFormat.DDV];
fileLength: INT ← input.GetLength;
IF fileLength MOD bytesPerPressPage # 0 THEN ERROR Bad;
IF fileLength < bytesPerPressPage THEN ERROR Bad;
input.SetIndex[fileLength-bytesPerPressPage];
[] ← input.UnsafeGetBlock[block: [base: LOOPHOLE[ddv], startIndex: 0, count: bytesPerWord*SIZE[PressFormat.DDV]]];
IF ddv.Passwd # PressFormat.PressPasswd THEN ERROR Bad;
IF ddv.nRecs*bytesPerPressPage # fileLength THEN ERROR Bad;
RETURN [ddv];
};
GetToken: PROC [stream: IO.STREAM] RETURNS [token: ROPENIL] = {
token ← stream.GetTokenRope[Break ! IO.EndOfStream => CONTINUE].token;
};
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];
};
SetMode: PROC [fileName: ROPE, mode: CHAR] RETURNS [expl: ROPE] ~ {
file: IO.STREAMFS.StreamOpen[fileName: fileName, accessOptions: $write, streamOptions: [tiogaRead: FALSE, commitAndReopenTransOnFlush: TRUE, truncatePagesOnClose: FALSE, finishTransOnClose: TRUE, closeFSOpenFileOnClose: TRUE]];
documentDirectory: REF PressFormat.DDV ← ReadDirectory[file ! Bad => GOTO Quit];
was: CARDINAL ← documentDirectory.spare3[0];
documentDirectory.spare3[0] ← IF mode = '\000 THEN CARDINAL.LAST ELSE ORD[mode];
file.SetIndex[file.GetLength-bytesPerPressPage];
file.UnsafePutBlock[block: [base: LOOPHOLE[documentDirectory], startIndex: 0, count: bytesPerWord*SIZE[PressFormat.DDV]]];
file.Close;
expl ← IO.PutFR["Mode used to be %g", IF was < 128 THEN IO.char[LOOPHOLE[was]] ELSE IF was = CARDINAL.LAST THEN IO.rope["normal"] ELSE IO.int[was]];
EXITS Quit => {
expl ← "Sorry, not a press file";
};
};
SetPressPrintingModeCommand: Commander.CommandProc ~ {
stream: IO.STREAMIO.RIS[cmd.commandLine];
fileName: ROPE ← GetToken[stream];
mode: ROPE ← GetToken[stream];
charMode: CHARIF mode.Length = 0 THEN '\000 ELSE Ascii.Upper[mode.Fetch[0]];
expl: ROPE;
IF fileName = NIL THEN {cmd.out.PutRope["Please supply a file name.\n"]; RETURN};
SELECT charMode FROM
'\000, 'R, 'S, 'T => NULL;
ENDCASE => {cmd.out.PutRope["Mode options are (R = reverse, S = solid, T = transparent)\n"]; RETURN};
expl ← SetMode[fileName, charMode !
FS.Error => {expl ← error.explanation; CONTINUE};
IO.Error => {expl ← FS.ErrorFromStream[stream].explanation; CONTINUE}
];
cmd.out.PutRope[expl];
cmd.out.PutRope["\n"];
};
Commander.Register["SetPressPrintingMode", SetPressPrintingModeCommand, "Force the Printing mode of a press file (R = reverse, S = solid, T = transparent), e.g.,\n SetPressPrintingMode myPress.press T"];
END.