<> <> <> <> DIRECTORY BasicTime, Commander, FS, IO, MessageWindow, PascalBasic, PascalWizardFiles, Process, Rope, SirPress, TexTypes, TexInit, TexSysdep, TexSysdepInline, TexInteraction, TexMemory, TexSymbols, TexScan, TexDvi, TexOps, TexParagraph, TexBuildPage, TexMath, TexRest, TexExtensions, TeXExport, UserProfile USING [Token]; TexSysdepImpl: PROGRAM IMPORTS PascalBasic, PascalWizardFiles, TexInteraction, TexScan, TexDvi, TexSysdepInline, TexRest, SirPress, FS, IO, Rope, UserProfile, BasicTime, Process, TexSymbols, TexOps, MessageWindow EXPORTS TexSysdep, TeXExport = BEGIN OPEN PascalBasic, PascalWizardFiles, TexTypes, TexInteraction; RopeFromNameOfFile: PROCEDURE [] RETURNS [fileName: Rope.ROPE] = { i: NAT _ 0; P: SAFE PROC RETURNS [CHAR] = TRUSTED {i _ i+1; RETURN[TexInteraction.NameOfFile[i]]}; length: NAT _ 0; WHILE length RETURN[TRUE]; Rope.Equal[s1: fmt, s2: "DVI", case: FALSE] => RETURN[FALSE]; ENDCASE => ScreamAboutIllegalPrintFileFormat; RETURN[TRUE]; }; PressOpenOut: PUBLIC PROCEDURE RETURNS [BOOLEAN] = { TexSysdepInline.pressFileStream _ FS.StreamOpen[RopeFromNameOfFile[], $create ! FS.Error => TRUSTED{GOTO openFailed}]; TexSysdepInline.pressHandle _ SirPress.Create[TexSysdepInline.pressFileStream, RopeFromNameOfFile[], NIL, normal, NIL]; TexSysdepInline.pyping _ FALSE; TexSysdepInline.pype _ SirPress.NewPipe[TexSysdepInline.pypePosnsLimit]; RETURN[TRUE]; EXITS openFailed => RETURN[FALSE]; }; ReadTheClock: PUBLIC PROCEDURE [Ttime, Dday, Mmonth, Yyear: LONG POINTER TO INT] = { now: BasicTime.Unpacked_BasicTime.Unpack[BasicTime.Now[]]; Ttime^ _ now.hour*BasicTime.minutesPerHour+now.minute; Dday^ _ now.day; Mmonth^ _ SELECT now.month FROM January=>1, February=>2, March=>3, April=>4, May=>5, June=>6, July=>7, August=>8, September=>9, October=>10, November=>11, December=>12, ENDCASE=>ERROR; Yyear^ _ now.year; }; AOpenIn: PUBLIC PROCEDURE [F: LONG POINTER TO AlphaFile] RETURNS [AOpenInResult: PascalBoolean] = { inStream: IO.STREAM; AOpenInResult _ TRUE; inStream _ FS.StreamOpen[RopeFromNameOfFile[] ! FS.Error => TRUSTED {Post[error]; AOpenInResult _ FALSE; GO TO Quit} ]; PascalOpenTextFileWithStream[F, inStream]; PascalTextRESET[F]; EXITS Quit => NULL }; AOpenOut: PUBLIC PROCEDURE [F: LONG POINTER TO AlphaFile] RETURNS [AOpenOutResult: PascalBoolean] = { outStream: IO.STREAM; AOpenOutResult _ TRUE; outStream _ FS.StreamOpen[RopeFromNameOfFile[], $create ! FS.Error => TRUSTED {Post[error]; AOpenOutResult _ FALSE; GO TO Quit} ]; PascalOpenTextFileWithStream[F, outStream]; PascalTextREWRITE[F]; EXITS Quit => NULL }; BOpenIn: PUBLIC PROCEDURE [F: LONG POINTER TO ByteFile] RETURNS [BOpenInResult: PascalBoolean] = { inStream: IO.STREAM; so: FS.StreamOptions _ FS.defaultStreamOptions; so[tiogaRead] _ FALSE; BOpenInResult _ TRUE; inStream _ FS.StreamOpen[fileName: RopeFromNameOfFile[], streamOptions: so ! FS.Error => TRUSTED {Post[error]; BOpenInResult _ FALSE; GO TO Quit} ]; PascalOpenFileWithStream[@(F^.baseFile), inStream]; PascalRESET[file: @(F^.baseFile), length: 1, element: @(F^.element)]; EXITS Quit => NULL }; BOpenOut: PUBLIC PROCEDURE [F: LONG POINTER TO ByteFile] RETURNS [BOpenOutResult: PascalBoolean] = { outStream: IO.STREAM; BOpenOutResult _ TRUE; outStream _ FS.StreamOpen[RopeFromNameOfFile[], $create ! FS.Error => TRUSTED {Post[error]; BOpenOutResult _ FALSE; GO TO Quit} ]; PascalOpenFileWithStream[@(F^.baseFile), outStream]; EXITS Quit => NULL }; WOpenIn: PUBLIC PROCEDURE [F: LONG POINTER TO WordFile] RETURNS [WOpenInResult: PascalBoolean] = { inStream: IO.STREAM; so: FS.StreamOptions _ FS.defaultStreamOptions; so[tiogaRead] _ FALSE; WOpenInResult _ TRUE; inStream _ FS.StreamOpen[fileName: RopeFromNameOfFile[], streamOptions: so ! FS.Error => TRUSTED {Post[error]; WOpenInResult _ FALSE; GO TO Quit} ]; PascalOpenFileWithStream[@(F^.baseFile), inStream]; PascalRESET[file: @(F^.baseFile), length: 4, element: @(F^.element)]; EXITS Quit => NULL }; WOpenOut: PUBLIC PROCEDURE [F: LONG POINTER TO WordFile] RETURNS [WOpenOutResult: PascalBoolean] = { outStream: IO.STREAM; WOpenOutResult _ TRUE; outStream _ FS.StreamOpen[RopeFromNameOfFile[], $create ! FS.Error => TRUSTED {Post[error]; WOpenOutResult _ FALSE; GO TO Quit} ]; PascalOpenFileWithStream[@(F^.baseFile), outStream]; EXITS Quit => NULL }; Post: PRIVATE PROCEDURE [e: FS.ErrorDesc] = { IF e.group # user THEN {MessageWindow.Append[message: e.explanation, clearFirst: TRUE]; MessageWindow.Blink}; }; AClose: PUBLIC PROCEDURE [F: LONG POINTER TO AlphaFile] = { PascalCloseTextFile[F]; }; BClose: PUBLIC PROCEDURE [F: LONG POINTER TO ByteFile] = { PascalCloseFile[@(F^.baseFile)]; }; WClose: PUBLIC PROCEDURE [F: LONG POINTER TO WordFile] = { PascalCloseFile[@(F^.baseFile)]; }; AMakeNameString: PUBLIC PROCEDURE [F: LONG POINTER TO AlphaFile] RETURNS [AMakeNameStringResult: StrNumber] = {RETURN[MakeNameStringFromFileStream[F^.baseFile^.str]]}; BMakeNameString: PUBLIC PROCEDURE [F: LONG POINTER TO ByteFile] RETURNS [BMakeNameStringResult: StrNumber] = {RETURN[MakeNameStringFromFileStream[F^.baseFile^.str]]}; WMakeNameString: PUBLIC PROCEDURE [F: LONG POINTER TO WordFile] RETURNS [WMakeNameStringResult: StrNumber] = {RETURN[MakeNameStringFromFileStream[F^.baseFile^.str]]}; PressMakeNameString: PUBLIC PROCEDURE RETURNS [PressMakeNameStringResult: StrNumber] = {RETURN[MakeNameStringFromFileStream[TexSysdepInline.pressFileStream]]}; MakeNameStringFromFileStream: PRIVATE PROCEDURE [s: IO.STREAM] RETURNS [StrNumber] = {local, global, name: Rope.ROPE; [fullFName: local, attachedTo: global] _ FS.GetName[FS.OpenFileFromStream[s]]; IF global = NIL THEN name _ local ELSE name _ global; NameOfFileFromRope[name]; RETURN[TexScan.MakeNameString[]]}; finalDviBufLength: NAT = 8; finalDviBuf: REF TEXT _ NEW[TEXT[finalDviBufLength]]; WriteDvi: PUBLIC PROCEDURE [A, B: DviIndex] = { outPtr: NAT _ 0; IF TexSymbols.UsePressFormat THEN RETURN; finalDviBuf.length _ finalDviBufLength; FOR i: NAT IN [A..B] DO finalDviBuf[outPtr] _ LOOPHOLE[TexDvi.DviBuf[i]]; outPtr _ outPtr+1; IF outPtr=finalDviBufLength THEN { TexScan.DviFile.baseFile.str.PutBlock[finalDviBuf]; outPtr _ 0; }; ENDLOOP; IF outPtr>0 THEN { finalDviBuf.length _ outPtr; TexScan.DviFile.baseFile.str.PutBlock[finalDviBuf]; }; }; FileGetPos: PUBLIC PROC [F: PascalTextFilePtr] RETURNS [FileGetPosResult: PascalInteger] = BEGIN FileGetPosResult _ 0; -- in case of error below FileGetPosResult _ F.baseFile.str.GetIndex[ ! IO.Error => IF ec = NotImplementedForThisStream THEN CONTINUE]; END; RopeFromStringNumber: PROCEDURE [s: StrNumber] RETURNS [r: Rope.ROPE] = { i: PoolPointer _ StrStart^[s]; length: NAT _ StrStart^[s+1]-i; P: SAFE PROC RETURNS [c:CHAR] = TRUSTED {c _ Xchr[StrPool[i]]; i _ i+1}; r _ Rope.FromProc[length, P]; RETURN[r]; }; GetPypeCode: PUBLIC PROCEDURE [F: InternalFontNumber, AtSizeInHnm:PascalInteger] RETURNS [GetPypeCodeResult: CedarNat] = { IF TexSysdepInline.pyping THEN FlushPype[]; RETURN[SirPress.GetFontCode[ p: TexSysdepInline.pressHandle, family: RopeFromStringNumber[TexOps.FontFamily[F]], size: AtSizeInHnm+50, --round instead of truncating, to avoid font substitutions face: TexOps.FontFace[F], rotation: 0, unit: 100]]; }; PressSetFont: PUBLIC PROCEDURE [C: NAT] = { IF TexSysdepInline.pyping THEN FlushPype[]; SirPress.SetFontFromCode[TexSysdepInline.pressHandle, C]; }; PressShowRule: PUBLIC PROCEDURE [Xstart, Ystart, Xlen, Ylen: INT] = { IF TexSysdepInline.pyping THEN FlushPype[]; SirPress.PutRectangle[p: TexSysdepInline.pressHandle, xstart: Xstart, ystart: Ystart, xlen: Xlen, ylen: Ylen, unit: 100]}; FlushPype: PUBLIC PROCEDURE = { IF TexSysdepInline.pyping THEN { SirPress.ClosePipe[ p: TexSysdepInline.pressHandle, pipe: TexSysdepInline.pype, y: TexSysdepInline.yCoord]; TexSysdepInline.pyping _ FALSE}; }; PressWritePage: PUBLIC PROCEDURE = { IF TexSysdepInline.pyping THEN FlushPype[]; SirPress.WritePage[TexSysdepInline.pressHandle]; }; PressCloseFile: PUBLIC PROCEDURE = { SirPress.ClosePress[TexSysdepInline.pressHandle]; }; SetNormalPriority: PUBLIC PROCEDURE = { Process.SetPriority[Process.priorityNormal]; }; SetBackgroundPriority: PUBLIC PROCEDURE = { Process.SetPriority[Process.priorityBackground]; }; <<>> < {command line was all blank}; 1=> {command line had non-blank stuff, and it has been loaded into the buffer}; -1=> {command line had so much non-blank stuff that it overflowed the buffer (which is unlikely, but we are running with bounds checks off, so it pays to be careful)}.>> StuffOnCmdLine: PUBLIC PROCEDURE RETURNS [StuffOnCmdLineResult: INT] = { tail: Rope.ROPE _ PascalBasic.commandLineTail; cmdStr: IO.STREAM _ IO.RIS[tail]; curChar: CHAR; myLoc: NAT _ First; lastNonBlank: NAT; DO curChar _ '\n; -- in case of EndOfStream curChar _ cmdStr.GetChar[! IO.EndOfStream => CONTINUE]; SELECT curChar FROM ' => LOOP; -- ignore leading whitespace '\n => RETURN[0]; -- everything was blank ENDCASE => EXIT; -- aha, a nonblank ENDLOOP; IF myLoc >= BufSize-1 THEN RETURN[-1]; Buffer[myLoc] _ Xord[curChar]; myLoc _ myLoc+1; lastNonBlank _ myLoc; DO curChar _ '\n; -- in case of EndOfStream curChar _ cmdStr.GetChar[! IO.EndOfStream => CONTINUE]; IF curChar = '\n THEN EXIT; IF myLoc >= BufSize-1 THEN RETURN[-1]; Buffer[myLoc] _ Xord[curChar]; myLoc _ myLoc+1; IF curChar # ' THEN lastNonBlank _ myLoc; ENDLOOP; Last _ lastNonBlank; TexSymbols.CurInput.LocField _ First; RETURN[1]}; RopeFromBuffer: PRIVATE PROCEDURE [A: INT, B: INT] RETURNS [Rope.ROPE]= { i: NAT _ A-1; P: SAFE PROC RETURNS [CHAR] = TRUSTED {i _ i+1; RETURN[Xchr[Buffer[i]]]}; RETURN[Rope.FromProc[B-A+1, P]]; }; PackBufferedName: PUBLIC PROCEDURE [A: INT, B: INT] = { NameOfFileFromRope[Rope.Cat[RopeFromBuffer[A,B], ".fmt"]]; }; DefaultFormatFile: PROCEDURE RETURNS [default: Rope.ROPE] = { default _ UserProfile.Token[key: "TeX.DefaultFormatFile", default: "/Cyan/TeX/Formats/Plain.fmt"]; }; PackDefaultArea: PUBLIC PROCEDURE [A: INT, B: INT] = { default: Rope.ROPE _ DefaultFormatFile[]; cp: FS.ComponentPositions; fullName: Rope.ROPE; [fullName, cp] _ FS.ExpandName[default]; NameOfFileFromRope[Rope.Cat[ fullName.Substr[start:0, len: cp.base.start], RopeFromBuffer[A,B], ".fmt"]]; }; PackAllDefault: PUBLIC PROCEDURE = { default: Rope.ROPE _ DefaultFormatFile[]; NameOfFileFromRope[default]; }; <> <<>> <> <<>> <> <<>> <> <<1) In order to be sure of overriding the default PasMesa registration, we need to wait until after TeX.bcd has been run before doing our work.>> <<2) In order to make it easy to maintain the differences between the conventions of the CommandTool and those of the Compute Server.>> ExclusiveProc: PUBLIC Commander.CommandProc = TRUSTED { [result, msg] _ PascalBasic.ExclusiveProc[cmd]; }; <> <<>> TwiddlePascal: PUBLIC SAFE PROC = TRUSTED { PascalBasic.SubsystemProcRec.p _ TexOrInitexDependingUponClientData; }; TexOrInitexDependingUponClientData: PascalBasic.UnsafeCommandProc = { actLikeInitex: REF BOOL _ NARROW[PascalBasic.clientData]; TexRest.StartLikeInitex _ actLikeInitex^; TexRest.TheRealTex; }; InterruptTex: PUBLIC Commander.CommandProc = CHECKED { Interrupt _ 1; }; END.