<> <> <> <> <<>> DIRECTORY Atom USING [DottedPairNode], Basics USING [UnsafeBlock], BasicTime USING [earliestGMT, GetClockPulses, GMT, Now, Period, Pulses, PulsesToMicroseconds], Commander USING [CommandProc], ComputeServerServer USING [Register], Convert USING [RopeFromInt, RopeFromReal], FS USING [ComponentPositions, Error, ExpandName, GetName, OpenFileFromStream, StreamOpen], IO USING [CharsAvail, GetChar, PutChar, PutRope, SetLength, STREAM, UnsafePutBlock], NodeStyle USING [Ref], ProcessProps USING [AddPropList], PutGet USING [FromFile], Rope USING [Cat, Concat, Equal, Fetch, Index, Length, ROPE, Substr], SafeStorage USING [ReclaimCollectibleObjects], SirPress USING [CursorObject, CursorObjectRec, CursorProc], TEditInput USING [FreeTree], TextNode USING [LastLocWithin, LocNumber, Ref], TSJaMPageBuilder USING [RunPageBuilder], TSObject USING [ItemList], TSOutput USING [Close, Handle], TSOutputPress USING [CreateWithCursor], TSTranslate USING [FontNotFound, ProgressProc, TreeToVlist], TSViewer USING [Tool, ToolRec], UserProfile USING [Boolean], ViewerTools USING [SetContents]; TSRemoteServerImpl: CEDAR MONITOR IMPORTS BasicTime, ComputeServerServer, Convert, FS, IO, ProcessProps, PutGet, Rope, SafeStorage, TEditInput, TextNode, TSOutput, TSOutputPress, TSJaMPageBuilder, TSTranslate, UserProfile, ViewerTools = BEGIN OPEN TSViewer; ROPE: TYPE = Rope.ROPE; cursorData: TYPE = REF cursorDataObject; cursorDataObject: TYPE = RECORD [ out: IO.STREAM _ NIL, lastSendTime: BasicTime.GMT _ BasicTime.earliestGMT, lastPulse: BasicTime.Pulses _ 0 ]; ShowMessage: ENTRY PROCEDURE [out: IO.STREAM, prefix: CHAR, msg: ROPE] = { ENABLE UNWIND => NULL; out.PutChar[prefix]; out.PutRope[msg]; out.PutChar['$]; }; CreateOutputHandle: PROCEDURE [tool: Tool, node: TextNode.Ref, cursorObject: SirPress.CursorObject] RETURNS [outputHandle: TSOutput.Handle] = { stream: IO.STREAM _ FS.StreamOpen[GetPressName[tool], $create]; inputLength: INT _ TextNode.LocNumber[TextNode.LastLocWithin[node], 0]; stream.SetLength[MIN[1024, inputLength+inputLength-inputLength/3]]; tool.pressName _ FS.GetName[FS.OpenFileFromStream[stream]].fullFName; IF node=NIL THEN ERROR; outputHandle _ TSOutputPress.CreateWithCursor[ stream: stream, documentName: tool.currentName, cursorObject: cursorObject ]; }; GetPressName: PROCEDURE [tool: Tool] RETURNS [pressName: ROPE] = { nameLen: INT _ 0; cp: FS.ComponentPositions; dirOmitted: BOOL; [tool.currentName, cp, dirOmitted] _ FS.ExpandName[tool.currentName]; IF tool.currentName.Substr[cp.ext.start, cp.ext.length].Equal["Tioga", FALSE] THEN pressName _ tool.currentName.Substr[cp.base.start, cp.base.length] ELSE pressName _ tool.currentName.Substr[cp.base.start, cp.ext.start+cp.ext.length-cp.base.start]; IF tool.singleOutputFile THEN pressName _ pressName.Concat[".etc"]; pressName _ pressName.Concat[".press"]; IF cp.server.length = 0 THEN { pressName _ tool.currentName.Substr[0, cp.base.start].Concat[pressName]; }; IF tool.tempPress THEN pressName _ pressName.Concat["$"]; IF pressName.Equal[tool.pressName] THEN { ViewerTools.SetContents[tool.serverMsg, ""] } }; CursorProc: ENTRY SirPress.CursorProc = CHECKED { ENABLE UNWIND => NULL; cursor: cursorData = NARROW[clientData]; out: IO.STREAM = cursor.out; block: Basics.UnsafeBlock; now: BasicTime.GMT = BasicTime.Now[]; nowPulse: BasicTime.Pulses = BasicTime.GetClockPulses[]; IF bits = NIL OR BasicTime.Period[cursor.lastSendTime, now] > 0 OR BasicTime.PulsesToMicroseconds[nowPulse - cursor.lastPulse] > 200000 THEN { cursor.lastSendTime _ now; cursor.lastPulse _ nowPulse; IF bits = NIL THEN out.PutRope["c$"] ELSE { out.PutChar['b]; block _ [LOOPHOLE[bits], 0, 32]; out.UnsafePutBlock[block]; out.PutChar['$]; }; }; }; RemoteTSetterProc: Commander.CommandProc = { tool: Tool _ NEW[ToolRec _ [tempPress: UserProfile.Boolean["Hardcopy.TemporaryPressFiles"], stop: FALSE]]; aborted: BOOL; lastProgressReported: REAL _ -2.0; IsAborted: PROC RETURNS [BOOL] = { IF cmd.in.CharsAvail[] > 0 THEN { inChar: CHAR ; inChar _ cmd.in.GetChar[]; IF inChar = 's THEN tool.stop _ TRUE; }; RETURN[tool.stop]; }; ProgressProc: ENTRY TSTranslate.ProgressProc = { ENABLE UNWIND => NULL; IF progress > lastProgressReported + 1.0 THEN { realString: ROPE _ Rope.Cat["p", Convert.RopeFromReal[from: progress, precision: 3, useE: FALSE], "$"]; lastProgressReported _ progress; cmd.out.PutRope[realString]; IF cmd.in.CharsAvail[] > 0 THEN { inChar: CHAR ; inChar _ cmd.in.GetChar[]; IF inChar = 's THEN tool.stop _ TRUE; }; IF tool.stop THEN ERROR ABORTED; }; }; galley: TSObject.ItemList; style: NodeStyle.Ref; outputHandle: TSOutput.Handle _ NIL; names: ROPE _ cmd.commandLine; IF names.Substr[0, 3].Equal["-t "] THEN { tool.tempPress _ TRUE; names _ names.Substr[3]; } ELSE tool.tempPress _ FALSE; WHILE names.Length[] > 0 AND ~tool.stop DO ENABLE TSTranslate.FontNotFound => { msg _ Rope.Cat["Unable to find font ", fontName, "; position including comment nodes = ", Convert.RopeFromInt[location]]; tool.stop _ TRUE; GOTO Quit }; errorMsg: ROPE _ NIL; end: INT; node: TextNode.Ref; IF names.Fetch[0] = ' THEN { names _ names.Substr[1]; LOOP; }; end _ names.Index[0," "]; tool.currentName _ names.Substr[0, end]; names _ names.Substr[end]; node _ PutGet.FromFile[tool.currentName ! FS.Error => {errorMsg _ error.explanation; CONTINUE}]; IF errorMsg = NIL THEN { cursor: cursorData _ NEW[cursorDataObject]; cursor.out _ cmd.out; cursor.lastPulse _ BasicTime.GetClockPulses[]; IF outputHandle = NIL THEN outputHandle _ CreateOutputHandle[tool, node, NEW[SirPress.CursorObjectRec _ [cursorProc: CursorProc, clientData: cursor]]]; ShowMessage[cmd.out, 'm, Rope.Concat[IF tool.singleOutputFile THEN "Typesetting member " ELSE "Typesetting ", tool.currentName]]; { FormatFile: PROC ~ { [galley, style] _ TSTranslate.TreeToVlist[node, ProgressProc]; aborted _ TSJaMPageBuilder.RunPageBuilder[ galley: galley, style: style, output: outputHandle, abortCheckProc: IsAborted, documentName: tool.currentName ! ABORTED => { aborted _ TRUE; }] }; wd: Rope.ROPE _ ExtractWorkingDirectory[tool.currentName]; ProcessProps.AddPropList[propList: LIST[NEW[Atom.DottedPairNode _ [$WorkingDirectory, wd]]], inner: FormatFile]; }; tool.stop _ tool.stop OR aborted; TEditInput.FreeTree[node]; SafeStorage.ReclaimCollectibleObjects[]; } ELSE ShowMessage[cmd.out, 'e, errorMsg]; ENDLOOP; IF outputHandle # NIL THEN outputHandle.Close; EXITS Quit => {} }; ExtractWorkingDirectory: PROC [fileName: Rope.ROPE] RETURNS [wd: Rope.ROPE]~ { fullFName: Rope.ROPE; cp: FS.ComponentPositions; [fullFName, cp] _ FS.ExpandName[fileName]; wd _ Rope.Substr[fullFName, 0, cp.base.start]; }; ComputeServerServer.Register[ key: "RemoteTSetter", proc: RemoteTSetterProc ]; END. << >> <<>> <> <> <<>> <> <> <<>> <> <> <> <<>>