<> <> <> <<>> DIRECTORY BasicTime USING [FromNSTime, GMT], DFUtilities USING [DirectoryItem, FileItem, ParseFromStream, ProcessItemProc, SyntaxError], FS USING [ComponentPositions, Copy, Error, ExpandName, StreamOpen], IO USING [card, Close, Flush, GetTokenRope, PutChar, PutF, PutF1, PutFR, PutRope, rope, STREAM, time, TokenProc], PrintingP4V3 USING [Attribute, InterpressMasterStatus, Option, PrintAttributes, PrintOptions, RequestID], Rope USING [Cat, ROPE, Substr], SystemNames USING [ReleaseName], XNSPSCommander USING [CommandProc, Confirm, GetArg, GetNumber, RegisterCommand], XNSPSMessages USING [LogMessage], XNSPSPrint USING [GetMargins, SetMargins], XNSPSSpooler USING [EnumerateQueue] ; XNSPSNewUserImpl: CEDAR PROGRAM IMPORTS BasicTime, DFUtilities, FS, IO, Rope, SystemNames, XNSPSCommander, XNSPSMessages, XNSPSPrint, XNSPSSpooler EXPORTS ~ BEGIN ROPE: TYPE ~ Rope.ROPE; STREAM: TYPE ~ IO.STREAM; SetPrinterParams: XNSPSCommander.CommandProc = BEGIN <> sMargin, fMargin, newsMargin, newfMargin: CARDINAL; IO.PutRope[out, " \nGetting current parameters ... "]; [sMargin, fMargin] _ XNSPSPrint.GetMargins[]; IO.PutF[out, " Current Parameters: sMargin: %g, fMargin: %g \n", IO.card[sMargin], IO.card[fMargin]]; newsMargin _ XNSPSCommander.GetNumber[in: in, out: out, default: sMargin, prompt: "\nNew sMargin: ", help: NIL]; IF newsMargin NOT IN [1..30] THEN { IO.PutRope[out, " must be in [1..30] \n"]; RETURN; }; newfMargin _ XNSPSCommander.GetNumber[in: in, out: out, default: fMargin, prompt: "\nNew fMargin: ", help: NIL]; IF newfMargin NOT IN [10..43] THEN { IO.PutRope[out, " must be in [10..43]\n"]; RETURN; }; IO.PutRope[out, " You sure? "]; IF XNSPSCommander.Confirm[in: in, out: out] THEN { XNSPSPrint.SetMargins[newsMargin, newfMargin]; [sMargin, fMargin] _ XNSPSPrint.GetMargins[]; XNSPSMessages.LogMessage[ IO.PutFR["Setting margins to: sMargin: %g, fMargin: %g", IO.card[sMargin], IO.card[fMargin]]]; }; IO.PutRope[out, "\n"]; END; InstallFonts: XNSPSCommander.CommandProc = BEGIN <> errorRope: ROPE _ NIL; BEGIN -- for exit ENABLE {UNWIND => NULL; FS.Error => {errorRope _ error.explanation; GOTO Error}}; HelpFontClass: PROC [] = BEGIN IO.PutRope[out, "Specify font type (ie. XC1-2-2 or PressFonts)\n"]; END; HelpDFName: PROC [] = BEGIN IO.PutRope[out, "Specify df file name (ie. [Fonts]Top>XC1-2-2-CD-Splines.df)\n"]; END; ProcessItem: DFUtilities.ProcessItemProc = BEGIN <<[item: REF ANY] RETURNS [stop: BOOL _ FALSE];>> WITH item SELECT FROM dir: REF DFUtilities.DirectoryItem => {root _ dir.path1}; file: REF DFUtilities.FileItem => { fullFName, toName: ROPE; cp: FS.ComponentPositions; [fullFName, ] _ FS.ExpandName[name: file.name, wDir: root]; -- glue it together [toName, cp] _ FS.ExpandName[name: file.name, wDir: localDir]; -- glue it together toName _ Rope.Substr[base: toName, start: 0, len: cp.ver.start-1]; -- strip off version toName _ FS.Copy[from: fullFName, to: toName, setKeep: TRUE, keep: 1, attach: FALSE]; -- don't attach it IO.PutF[out, "Copied %g => %g\n", IO.rope[fullFName], IO.rope[toName]]; IO.Flush[out]; }; ENDCASE => NULL; END; root, remoteName, localDir, fontType: ROPE _ NIL; df: STREAM; fontType _ XNSPSCommander.GetArg[in: in, out: out, prompt: "\nFont type: ", default: "XC1-2-2", help: HelpFontClass]; IF fontType = NIL THEN GOTO Abort; localDir _ Rope.Cat["///", SystemNames.ReleaseName[], "/Fonts/Xerox/", fontType, "/"]; remoteName _ XNSPSCommander.GetArg[in: in, out: out, prompt: "\nDF file name: ", default: "[Fonts]Top>XC1-2-2-CD-Splines.df", help: HelpDFName]; IF remoteName = NIL THEN GOTO Abort; IO.PutRope[out, "\nFetching ...\n"]; df _ FS.StreamOpen[remoteName, read ! FS.Error => {errorRope _ error.explanation; GOTO Error}]; DFUtilities.ParseFromStream[df, ProcessItem ! DFUtilities.SyntaxError => {errorRope _ reason; GOTO Error}]; IO.Close[df]; EXITS Error => IO.PutF1[out, "\nError: %g while fetching fonts\n", IO.rope[errorRope]]; Abort => IO.PutRope[out, "\nAborted\n"]; END; END; Login: XNSPSCommander.CommandProc = BEGIN <> name, password: ROPE _ NIL; IO.PutRope[out, "\nName: "]; name _ IO.GetTokenRope[stream: in, breakProc: IO.TokenProc].token; IO.PutF1[out, " %g Password: ", IO.rope[name]]; password _ IO.GetTokenRope[stream: in, breakProc: IO.TokenProc].token; IO.PutRope[out, "\nDone"]; END; ListFonts: XNSPSCommander.CommandProc = BEGIN <> END; <<>> ListQueue: XNSPSCommander.CommandProc = BEGIN Proc: PROC [id: PrintingP4V3.RequestID, status: PrintingP4V3.InterpressMasterStatus, printAttributes: PrintingP4V3.PrintAttributes, printOptions: PrintingP4V3.PrintOptions] RETURNS [continue: BOOL] = TRUSTED { md: MACHINE DEPENDENT RECORD [lo, hi: CARDINAL]; md.lo _ id[4]; md.hi _ id[3]; IO.PutF[out, "ID: %g\tStatus: %g\n", IO.card[LOOPHOLE[md]], IO.rope[(SELECT status FROM pending => "pending", inProgress => "in progress", completed => "completed", completedWithWarning => "completed with warnings", unknown => "unknown", rejected => "rejected", aborted => "aborted", canceled => "canceled", held => "held", ENDCASE => NIL)] ]; IO.PutRope[out, "Print Attributes:\n"]; IF printAttributes # NIL THEN FOR i: CARDINAL IN [0 .. printAttributes.length) DO option: PrintingP4V3.Attribute _ printAttributes.body[i]; WITH option: option SELECT FROM printObjectName => {IO.PutF1[out, " name: %g\n", IO.rope[option.printObjectName]]}; printObjectCreateDate => { time: BasicTime.GMT _ BasicTime.FromNSTime[option.printObjectCreateDate]; IO.PutF1[out, " createTime: %g\n", IO.time[time]]}; senderName => {IO.PutF1[out, " name: %g\n", IO.rope[option.senderName]]}; ENDCASE => NULL; ENDLOOP; IO.PutRope[out, "Print Options:\n"]; IF printOptions # NIL THEN FOR i: CARDINAL IN [0 .. printOptions.length) DO option: PrintingP4V3.Option _ printOptions.body[i]; WITH option: option SELECT FROM printObjectSize => IO.PutF1[out, " size: %g\n", IO.card[option.printObjectSize]]; recipientName => IO.PutF1[out, " recipientName: %g\n", IO.rope[option.recipientName]]; message => IO.PutF1[out, " message: %g\n", IO.rope[option.message]]; copyCount => IO.PutF1[out, " copies: %g\n", IO.card[option.copyCount]]; ENDCASE => NULL; ENDLOOP; IO.Flush[out]; }; IO.PutChar[out, '\n]; XNSPSSpooler.EnumerateQueue[Proc]; IO.PutChar[out, '\n]; END; Init: PROC [] = BEGIN XNSPSCommander.RegisterCommand[[SetPrinterParams, "Set Printer Parmeters"]]; XNSPSCommander.RegisterCommand[[InstallFonts, "Install Fonts"]]; XNSPSCommander.RegisterCommand[[Login, "Login"]]; XNSPSCommander.RegisterCommand[[ListFonts, "List Fonts"]]; XNSPSCommander.RegisterCommand[[ListQueue, "List Queue"]]; END; Init[]; END.