PSExecBImpl.mesa
Copyright (C) Xerox Corporation 1983, 1984, 1985. All rights reserved.
Last edited by Jacks 13-Dec-85 16:43:20
Ruseli Binsol: December 10, 1986 11:11:01 am PST
DIRECTORY
BasicTime USING [GMT],
NSExec USING [CheckForAbort, ClientID, Error, ExecProc, GetTTY, Handle, OutputHandle],
NSString USING [AppendLongDecimal, CopyString, FreeString, nullString, String],
PaperHandling USING [TwoPaperSizes],
PaperTypes USING [PaperSize],
PrincOps USING [bytesPerPage],
PrintingTypes USING [Option],
PSCommand USING [DeleteFile, DeleteFont, Error, FileFilter, FileProc, FontProc, GetPrintServiceStatus, ListFiles, ListFonts, PaperTray, PrintFile, PrintFileOptions],
PSExec USING [GetClientID],
PSExecInternal USING [DisplayCount, ExpandKeyAndPrint, GetList, KeyList, KeyListRep],
PSExecMessages USING [Key],
PSKMessages USING [GetHandle],
PSState USING [StateHandle],
TextInput USING [ChoiceIndex, GetChoice, GetDecimal, GetYesNo, YesOrNo],
TTY USING [Handle, Rubout],
XFormat USING [Blanks, CR, Date, Handle, NSLine, NSString, NSStringObject],
XMessage USING [Get, Handle, Compose, StringArray];
PSExecBImpl:
CEDAR
PROGRAM
IMPORTS NSExec, NSString, PSCommand, PSExec, PSExecInternal, PSKMessages, TextInput, TTY, XFormat, XMessage
EXPORTS PSExecInternal
SHARES NSString = BEGIN
psClientID: NSExec.ClientID ← PSExec.GetClientID[];
Variables used for listing fonts and test patterns:
stringArray: REF XMessage.StringArray ← NEW[XMessage.StringArray[3]];
Used for displaying dates from stored files:
nsDateAndTime: NSString.String ← NEW[TEXT[40]];
nsDateTimeObject: XFormat.Handle ← XFormat.NSStringObject[nsDateAndTime];
Message domain handle:
execMsgs: XMessage.Handle ← PSKMessages.GetHandle[exec];
DisplayFonts:
PUBLIC NSExec.ExecProc =
BEGIN
Lists all fonts for current printing option installed on the Print Service. Displays font name, size in pages and create date.
ENABLE NSExec.Error => IF type = invalidExec THEN GOTO Exit;
fontsDisplayed: CARDINAL ← 0;
printingOption: PrintingTypes.Option ← PSCommand.GetPrintServiceStatus[].option;
DisplayFont: PSCommand.FontProc =
BEGIN
Displays data for each font enumerated.
sizeInPages:
LONG
CARDINAL ←
(sizeInBytes + PrincOps.bytesPerPage - 1)/PrincOps.bytesPerPage;
DisplayData[exec, packageName, sizeInPages, createDate];
fontsDisplayed ← fontsDisplayed + 1;
IF fontsDisplayed
MOD 4 = 0
THEN
--check for user abort every 4 fonts
IF NSExec.CheckForAbort[exec] = TRUE THEN continue ← FALSE;
PSCommand.ListFonts[proc: DisplayFont]; --enumerate every font installed
PSExecInternal.DisplayCount[exec, fontsDisplayed, mFontsListed];
EXITS Exit => NULL;
END; --DisplayFonts
DeleteFonts:
PUBLIC NSExec.ExecProc =
BEGIN
ENABLE NSExec.Error => IF type = invalidExec THEN GOTO Exit;
tty: TTY.Handle ← NSExec.GetTTY[exec];
outputHandle: XFormat.Handle ← NSExec.OutputHandle[exec];
fontsDeleted: CARDINAL ← 0;
stringArray: REF XMessage.StringArray ← NEW [XMessage.StringArray[1]];
stringArray: ARRAY [0..1) OF NSString.String;
freeThisString: NSString.String;
yes: BOOLEAN ← FALSE;
state: PSState.StateHandle ← PSCommand.GetPrintServiceStatus[];
DeleteFont: PSCommand.FontProc =
BEGIN
stringArray[0] ← packageName;
freeThisString ← XMessage.Compose[M[mDeletePrompt], stringArray];
yes ← TextInput.GetYesNo[
tty: tty, prompt: freeThisString, default: no ! TTY.Rubout => GOTO Stop] = yes;
NSString.FreeString[freeThisString];
IF yes
THEN
BEGIN
freeThisString ← XMessage.Compose[M[mDeleting], stringArray];
outputHandle.Blanks[8];
outputHandle.NSString[freeThisString];
NSString.FreeString[freeThisString];
PSCommand.DeleteFont[packageName ! PSCommand.Error =>
WITH p: problem
SELECT
FROM
disallowedInCurrentMode =>
BEGIN
XFormat.CR[outputHandle];
stringArray[0] ← M[mDeleteFonts];
freeThisString ← XMessage.Compose[M[mConflictingMode], stringArray];
outputHandle.NSLine[freeThisString];
GOTO Stop;
END;
documentInProgress =>
BEGIN
--We CAN get here since, with the advent of remote administration, two users may be logged at the same time. One could start printing before the other finishes deleting fonts.
stringArray: REF XMessage.StringArray;
outputHandle.NSLine[M[mDocInProgress]];
stringArray[0] ← M[mDeleteFonts];
freeThisString ← XMessage.Compose[M[mPleaseStopPrinting], stringArray];
outputHandle.NSLine[freeThisString];
GOTO Stop;
END;
ENDCASE;
];
outputHandle.NSLine[M[mDone]];
fontsDeleted ← fontsDeleted + 1;
END;
IF NSExec.CheckForAbort[exec] THEN continue ← FALSE;
EXITS Stop => {
NSString.FreeString[freeThisString];
RETURN [continue:
FALSE]};
END; --DeleteFont
IF state.clientControl.formatterEnabled
OR
state.clientControl.markerEnabled
THEN
BEGIN
stringArray: REF XMessage.StringArray;
stringArray[0] ← M[mDeleteFonts];
outputHandle.Blanks[2];
PSExecInternal.ExpandKeyAndPrint[exec, mPleaseStopPrinting, stringArray];
END
ELSE
BEGIN
PSCommand.ListFonts[proc: DeleteFont];
PSExecInternal.DisplayCount[exec, fontsDeleted, mFontsDeleted];
END;
EXITS Exit => NULL;
END; --DeleteFonts
DisplayTestPatterns:
PUBLIC NSExec.ExecProc =
BEGIN
tpsDisplayed: CARDINAL ← 0;
tpFilter: PSCommand.FileFilter ← [type: testPattern];
DisplayTestPattern: PSCommand.FileProc =
BEGIN
sizeInPages: LONG CARDINAL ←
(sizeInBytes + PrincOps.bytesPerPage - 1)/PrincOps.bytesPerPage;
DisplayData[exec, name, sizeInPages, createDate];
tpsDisplayed ← tpsDisplayed + 1;
END; --DisplayTestPattern
PSCommand.ListFiles[DisplayTestPattern, tpFilter];
PSExecInternal.DisplayCount[exec, tpsDisplayed, mTPsListed];
END; --DisplayTestPatterns
DeleteTestPatterns:
PUBLIC NSExec.ExecProc =
BEGIN
ENABLE NSExec.Error => IF type = invalidExec THEN GOTO Exit;
tty: TTY.Handle ← NSExec.GetTTY[exec];
outputHandle: XFormat.Handle ← NSExec.OutputHandle[exec];
tpsDeleted: CARDINAL ← 0;
stringArray: REF XMessage.StringArray;
freeThisString: NSString.String;
yes: BOOLEAN ← FALSE;
DeleteTP: PSCommand.FileProc =
BEGIN
stringArray.data[0] ← name;
freeThisString ← XMessage.Compose[M[mDeletePrompt], stringArray];
yes ← TextInput.GetYesNo[
tty: tty, prompt: freeThisString, default: no ! TTY.Rubout => GOTO Stop] = yes;
NSString.FreeString[freeThisString];
IF yes
THEN
BEGIN
freeThisString ← XMessage.Compose[M[mDeleting], stringArray];
outputHandle.Blanks[8];
outputHandle.NSString[freeThisString];
NSString.FreeString[freeThisString];
PSCommand.DeleteFile[name ! PSCommand.Error =>
WITH problem
SELECT
FROM
disallowedInCurrentMode =>
BEGIN
XFormat.CR[outputHandle];
stringArray[0] ← M[mDeleteTPs];
freeThisString ← XMessage.Compose[M[mConflictingMode], stringArray];
outputHandle.NSLine[freeThisString];
GOTO Stop;
END;
ENDCASE;
];
outputHandle.NSLine[M[mDone]];
tpsDeleted ← tpsDeleted + 1;
END;
IF NSExec.CheckForAbort[exec] THEN continue ← FALSE;
EXITS Stop => {
NSString.FreeString[freeThisString];
RETURN [continue:
FALSE]};
END; --DeleteTP
PSCommand.ListFiles[DeleteTP];
PSExecInternal.DisplayCount[exec, tpsDeleted, mTPsDeleted];
EXITS Exit => NULL;
END; --DeleteTestPatterns
PrintTestPattern:
PUBLIC NSExec.ExecProc =
BEGIN
--Formerly SelectTestPattern
PROCEDURE [exec: Handle];
ENABLE NSExec.Error => IF type = invalidExec THEN GOTO Exit;
tty: TTY.Handle ← NSExec.GetTTY[exec];
outputHandle: XFormat.Handle ← NSExec.OutputHandle[exec];
TestPatternArray: TYPE = RECORD [data: SEQUENCE length: CARDINAL OF NSString.String];
tpArrayLengthIncrement: CARDINAL = 5;
maxTPIndex: CARDINAL ← 0;
tpChoices: REF XMessage.StringArray ← NEW[XMessage.StringArray[tpArrayLengthIncrement]]; --an array of strings which are the names of the test patterns available
tpChoice: TextInput.ChoiceIndex;
tpFilter: PSCommand.FileFilter ← [type: testPattern];
options: PSCommand.PrintFileOptions ← [unknown[]];
phoneNumber: NSString.String ← NSString.nullString;
state: PSState.StateHandle ← PSCommand.GetPrintServiceStatus[];
copies: INTEGER ← 1;
TRUSTED
BEGIN
ENABLE
UNWIND =>
NULL;
CacheTPs: PSCommand.FileProc =
TRUSTED
BEGIN
type: FileType, name: NSString.String, sizeInBytes: LONG CARDINAL, createDate: BasicTime.GMT] RETURNS [continue: BOOLEAN ← TRUE];
GrowTPArray:
PROCEDURE [larger:
CARDINAL] =
TRUSTED
BEGIN
oldTPChoices: REF XMessage.StringArray ← tpChoices;
oldLength: CARDINAL = oldTPChoices.length;
newLength: CARDINAL = oldLength + larger;
tpChoices ← NEW[XMessage.StringArray[newLength]];
FOR i:
CARDINAL
IN [0..oldLength)
DO
tpChoices.data[i] ← oldTPChoices.data[i];
ENDLOOP;
FOR i:
CARDINAL
IN [oldLength..newLength)
DO
tpChoices.data[i] ← NSString.nullString;
ENDLOOP;
END; --GrowTPArray
IF maxTPIndex >= tpChoices.length THEN GrowTPArray[tpArrayLengthIncrement];
tpChoices.data[maxTPIndex] ← NSString.CopyString[name];
maxTPIndex ← maxTPIndex + 1;
END; --CacheTPs
GetFaxPaperSize:
PROCEDURE [letterLegalSizeSupported:
BOOLEAN]
RETURNS [PaperTypes.PaperSize] =
TRUSTED
BEGIN
--Proc determines whether size should be letter, legal or a4.
IF letterLegalSizeSupported
THEN
BEGIN
choices: CARDINAL = 2;
sizeChoice: TextInput.ChoiceIndex;
defaultSizeChoice: TextInput.ChoiceIndex = 0;
msgKeys: PSExecInternal.KeyList ← NEW[PSExecInternal.KeyListRep[choices]];
sizeChoices: REF XMessage.StringArray ← NEW [XMessage.StringArray[2]];
PSExecInternal.GetList[choices, msgKeys, sizeChoices];
sizeChoice ← TextInput.GetChoice[tty: tty, prompt: M[mSelPaperSizeForTestPat],
choices: sizeChoices, default: defaultSizeChoice];
RETURN [
SELECT sizeChoice
FROM
0 => letter, ENDCASE => legal];
END
ELSE RETURN [a4]; --only one choice for a4 width paper.
END; --GetFaxPaperSize
GetTrayChoice:
PROCEDURE [paperSupply: PaperHandling.TwoPaperSizes]
RETURNS [PSCommand.PaperTray] =
TRUSTED
BEGIN
--Used for raven and fx3500.
choices: CARDINAL = 2;
trayChoice: TextInput.ChoiceIndex;
defaultSizeChoice: TextInput.ChoiceIndex = 1;
msgKeys: PSExecInternal.KeyList ← NEW[PSExecInternal.KeyListRep[choices]];
paperChoices: ARRAY [0..choices) OF NSString.String;
paperChoices: REF XMessage.StringArray ← NEW [XMessage.StringArray[choices]];
msgKeys[0] ←
SELECT paperSupply.size2
FROM
letter => mLetter,
legal => mLegal,
a4 => mA4,
a5 => mA5,
jisB4 => mB4,
jisB5 => mB5
ENDCASE => mAsterisk;
msgKeys[1] ←
SELECT paperSupply.size1
FROM
letter => mLetter,
legal => mLegal,
a4 => mA4,
a5 => mA5,
jisB4 => mB4,
jisB5 => mB5
ENDCASE => mAsterisk;
IF msgKeys[0] = mAsterisk
OR msgKeys[1] = mAsterisk
THEN RETURN [default]
ELSE
BEGIN
PSExecInternal.GetList[choices, msgKeys, paperChoices];
trayChoice ← TextInput.GetChoice[tty: tty, prompt: M[mSelPaperSizeForTestPat], choices: paperChoices, default: defaultSizeChoice];
RETURN [SELECT trayChoice FROM 0 => top, ENDCASE => bottom];
END;
END; --GetTrayChoice
FOR i:
CARDINAL
IN [0..tpChoices.length)
DO
--initialize tp array
tpChoices.data[i] ← NSString.nullString;
ENDLOOP;
PSCommand.ListFiles[CacheTPs, tpFilter]; --store tp name strings in array
IF maxTPIndex = 0 THEN {outputHandle.NSLine[M[mNoTPs]]; RETURN};
tpChoice ← TextInput.GetChoice[tty: tty, prompt: NSString.nullString, choices: tpChoices];
copies ← TextInput.GetDecimal[tty: tty, prompt: M[mEnterCopyC],
min: 1, max: 999, default: 1];
WITH s: state
SELECT
FROM
bansheeDl => options ← [bansheeDl[]];
d1 => options ← [d1[]];
fax295 => options ← [fax295[paperSize: GetFaxPaperSize[
s.paperWidth = PaperTypes.PaperMMDimension[letter].short]]];
fax495 =>
BEGIN
localPrint, remotePrint: BOOLEAN ← FALSE;
paperSize: PaperTypes.PaperSize ← GetFaxPaperSize[
s.paperWidth = PaperTypes.PaperMMDimension[letter].short];
phoneNumber ← NSString.MakeString[PSCommand.maxPhoneNoLength];
localPrint ← TextInput.GetYesNo[tty, M[mLocalPrint]] = yes;
IF remotePrint ← (TextInput.GetYesNo[tty, M[mRemotePrint]] = yes) THEN
phoneNumber ← TextInput.GetText[
tty: tty, prompt: M[mEnterPhoneNo], text: phoneNumber,
minLength: 1, maxLength: PSCommand.maxPhoneNoLength];
options ← [fax495[localPrint, remotePrint, phoneNumber, paperSize]];
END;
feps9700 => options ← [feps9700[]];
fx3500 => {};
IF s.paperSupply.size1 # s.paperSupply.size2 THEN
options ← [fx3500[GetTrayChoice[s.paperSupply]]]
ELSE options ← [fx3500[]];
raven =>
{
IF s.paperSupply.size1 # s.paperSupply.size2
THEN options ← [raven[GetTrayChoice[s.paperSupply], aligned]]
ELSE options ← [raven[]]};
outputHandle.Blanks[2];
PSCommand.PrintFile[tpChoices[tpChoice], M[mPrintTP], copies, options !
PSCommand.Error => {
WITH problem
SELECT
FROM
fileNotFound => outputHandle.NSLine[M[mTPNotavailable]];
invalidPhoneNumber =>
BEGIN
outputHandle.NSString[M[mInvalidPhoneNo]];
outputHandle.NSLine[M[mCantQueueTP]];
END;
ENDCASE => outputHandle.NSLine[M[mCantQueueTP]];
IF phoneNumber # NSString.nullString THEN
NSString.FreeString[phoneNumber];
GOTO Exit};
];
outputHandle.NSLine[M[mTPQueued]];
IF phoneNumber # NSString.nullString
THEN
NSString.FreeString[phoneNumber];
FOR i:
CARDINAL
IN [0..maxTPIndex)
DO
NSString.FreeString[tpChoices[i]];
ENDLOOP;
END; --Enable and code
EXITS Exit => NULL;
END; --PrintTestPattern
DisplayData:
PROCEDURE [exec: NSExec.Handle, name: NSString.String, sizeInPages:
LONG
CARDINAL, createDate: BasicTime.
GMT] =
BEGIN
outputHandle: XFormat.Handle ← NSExec.OutputHandle[exec];
stringArray[0] ← name;
XFormat.NSString[outputHandle, NSString.AppendLongDecimal[NIL, sizeInPages]];
stringArray[1] ← NEW[TEXT[20]];
nsDateAndTime.length ← 0;
XFormat.Date[nsDateTimeObject, createDate]; --appends date to nsDateAndTime
stringArray[2] ← nsDateAndTime;
PSExecInternal.ExpandKeyAndPrint[exec, mFontList, stringArray];
END; --DisplayData
M:
PROCEDURE [key: PSExecMessages.Key]
RETURNS [string: NSString.String] = {
RETURN[XMessage.Get[execMsgs, ORD[key]]]};
END. --PSExecBImpl
LOG
Date - Who - What
24-Oct-83 17:48:31 - Jacks - Created by splitting up PSTTYExecImpl.
2-Nov-83 13:27:34 - Jacks - Various small adjustments in InstallFromFloppy.
11-Nov-83 9:51:57 - Jacks - Replace PSExec interface with PSState.StateHandle and PSCommand.GetPrintServiceStatus.
21-Nov-83 10:58:39 - Jacks - Changed default value (yes or no) when asking whether to load a font; removed "Another floppy?" question.
28-Nov-83 17:11:49 - Jacks - Reset firstPieceFile in LoadPiece; Added catch phrases for PSCommand.Error[insufficientSpace]; renamed Abort Error to UserAbort; and added global var systemAbort; made many multi-floppy procs return dataSink parameter, in the case that it has been deleted it will return nullSinkStream value.
5-Dec-83 16:59:32 - Jacks - Removed erroneous comments.
20-Dec-83 7:59:54 - Jacks - Converted to PSFileTypes.
23-Dec-83 11:09:37 - Jacks - No longer reference PSFileTypes.tFont (=tFont300Portrait).
9-Jan-84 13:08:46 - Jacks - Added OPEN PSTTYExecInternal.
12-Jan-84 18:14:28 - Jacks - Added PrintTestPattern functionality for fax.
26-Jan-84 23:25:00 - Jacks - Converted to 8.0 SCS; added fix to SendFloppyData to send only exact byte count of file.
9-Feb-84 11:28:04 - Jacks - Improved mBadFontFileType message; added PrintFile functionality for fx3500.
23-Feb-84 21:07:48 - Jacks - Minor message key changes; converted to private heap.
26-Mar-84 10:46:27 - Jacks - Added fix to GetCommand to allow spaces in file names in mulit-floppy script.
30-Mar-84 14:44:35 - Jacks - Minor error message change; extra NIL checks in FreeGlobalSpace.
3-Apr-84 18:55:22 - Jacks - Added support for multiple execs.
18-Apr-84 10:38:33 - Jacks - Added tp paper size prompt for fax.
26-Apr-84 9:43:27 - Jacks - Removed dependence on TestPattern interface in PrintTestPattern.
31-May-84 9:48:46 - Jacks - Removed maxBytes constant from GetCommand which limited script file size; added enable clause to InterpreteScript.
15-Jun-84 11:10:23 - Jacks - Got rid of come truncation warnings in SendFloppyData.
20-Sep-84 13:26:42 - Jacks - For 9.0: added banshee, feps9700 and fax295; got rid of aps5.
5-Oct-84 13:48:07 - Jacks - Renamed from PSTTYExecBImpl to PSExecBImpl; added NSExec.CheckForAbort to many procs.
17-Oct-84 15:37:29 - Jacks - Renamed ttyHeap to execHeap.
14-Nov-84 14:07:35 - Jacks - Updated to new PSCommand/PSState interfaces; removed some TTY.Rubout catch phrases.
5-Feb-85 15:11:38 - Jacks - Added code to Install proc to avoid prompting user with names of test patterns inappropriate for the current printing option.
28-Feb-85 15:28:08 - Jacks - Now use PSCommandExtras.InstallFontX and InstallFileX instead of PSCommand.InstallFont and InstallFile.
13-Mar-85 10:02:27 - Jacks - Now use TestPattern interface for getting names of test patterns in Install proc.
20-Jun-85 11:11:25 - Jacks - Added copyright notice; updated to PS Euclid interfaces; turned off public error catching by SCS in all exec procs.
28-Jun-85 15:04:49 - Jacks - Added d1 code; removed SetCatching calls.
18-Jul-85 15:00:32 - Jacks - Converted to XMessage.
1-Aug-85 17:53:51 - Jacks - Converted to DeleteFontX and ListFontsX from PSCommandExtras; added catch phrases to PSCommandExtras.DeleteFont and PSCommand.DeleteFile.
14-Aug-85 12:01:08 - Jacks - Added catch for PSCommand.Erorr[undefined] which means "documentInProgress" in DeleteFonts.
9-Sep-85 13:26:46 - Jacks - Moved a string into the msg file.
11-Sep-85 13:32:52 - Jacks - Went back to using PSCommand.DeleteFont and ListFonts instead of PSCommandExtras.
24-Sep-85 14:27:25 - Jacks - PSCommandExtras folded into PSCommand.
6-Nov-85 13:07:46 - Jacks - Call PSKMessages for msg handle.
13-Dec-85 16:43:01 - Jacks - ExecMessages renamed to PSExecMessages.