SELECT commandCode
FROM
login => {
registryMissing: BOOLEAN ← TRUE;
PutString[" --User-- "];
user ← GetStringToSpace[];
registryMissing ← Rope.Find[user, "."] < 0;
IF registryMissing
THEN {
user ← Rope.Concat[user, defaultRegistry];
PutString[defaultRegistry];
};
PutString[" --Password-- "];
echo ← FALSE;
password ← GetStringToSpace[ ! UNWIND => echo ← TRUE];
echo ← TRUE;
IF sep # '\n
THEN {
PutString[" --Account-- "];
account ← GetStringToSpace[];
};
PutString[" -- Authenticating ... "];
SendNow[];
SELECT GVNames.Authenticate[user, password]
FROM
individual => {PutString["OK"]; loggedIn ← TRUE};
allDown => {PutString["all GV servers down; I'll have to trust you."]; loggedIn ← TRUE};
badPwd => {PutString["bad password"]; loggedIn ← FALSE};
ENDCASE => {PutString["bad name"]; loggedIn ← FALSE};
PutChar['\n];
PutChar['\l];
IO.Flush[stream];
IF loginMessage.Length > 0
THEN {
IO.PutF1[stream, "%g\n\l", IO.rope[loginMessage]];
};
};
print => {
fileName: ROPE;
separator: ROPE;
time: ROPE;
requestNumber: INT ← 0;
createDate: ROPE ← NIL;
bytes: INT ← 0;
copies: INT ← 1;
IF
NOT accessAllowed
THEN {
PutString["\n\lSorry, you are not allowed to queue requests at this time."];
};
PutString[" --File-- "];
fileName ← GetStringToSpace[];
IF sep # '\n
THEN {
PutString[" --Copies-- "];
copies ← MIN[GetNumber[default: 1], CARDINAL.LAST];
};
IF sep # '\n
THEN {
PutString[" --Title-- "];
separator ← GetStringToCR[];
};
[fileName, bytes, createDate] ← IPPrinterRemoteStream.Lookup[fileName, BasicTime.nullGMT, user, password !
IPPrinterRemoteStream.Error => {IO.PutF1[stream, "Error: %g\n\l", IO.rope[expl]]; GOTO Bad}];
time ← IO.PutR[IO.time[BasicTime.Now[]]];
requestNumber ← IPPrinterQueue.QueueRequest[[fileName, time, user, password, separator, copies]];
IF requestNumber < 0 THEN {PutString["\n\lPrint queue full, request denied.\n\l"]; GOTO Bad};
PutString[IO.PutFR["\n\lPrint request %g queued for %g of %g (%g bytes)\n\l", IO.int[requestNumber], IO.rope[fileName], IO.rope[createDate], IO.int[bytes]]];
{
msg: ROPE ← IO.PutFR["Version of %g; %g bytes.", IO.rope[createDate], IO.int[bytes]];
IPPrinterQueue.LogMessage[msg, requestNumber];
};
lastRequest ← requestNumber;
EXITS Bad => NULL
};
check => {
requestNumber: INT;
action:
PROC [request: IPPrinterQueue.Request, status: IPPrinterQueue.RequestStatus] = {
PutString[IO.PutFR1["%g ", IO.int[requestNumber]]];
IF status = notFound
THEN {
PutString[" not found.\n\l"];
}
ELSE PutRequestStatus[request, status];
};
PutString[" --Request Number<"];
IF lastRequest # -1 THEN IO.Put[stream, IO.int[lastRequest]];
PutString[">-- "];
lastRequest ← requestNumber ← GetNumber[default: lastRequest];
IF requestNumber = -1 THEN {PutChar['\n]; PutChar['\l]}
ELSE IF ABS[requestNumber] > NAT.LAST THEN action[[NIL,NIL,NIL,NIL,NIL,1], notFound]
ELSE IPPrinterQueue.CheckRequest[requestNumber, action];
};
cancel => {
requestNumber: INT;
PutString[" --Request Number-- "];
requestNumber ← GetNumber[default: -1];
IF requestNumber = -1 THEN {PutChar['\n]; PutChar['\l]}
ELSE {
owner: ROPE ← NIL;
reqSatus: IPPrinterQueue.RequestStatus ← notFound;
action:
PROC [request: IPPrinterQueue.Request, status: IPPrinterQueue.RequestStatus] = {
reqSatus ← status;
IF status # notFound THEN owner ← request.requestor;
};
IPPrinterQueue.CheckRequest[requestNumber, action];
PutChar['\n]; PutChar['\l];
IF IPPrinterQueue.CancelRequest[requestNumber].ok
THEN {
msg: ROPE;
IF reqSatus = printing THEN IPPrinterQueue.CancelReprint[];
msg ← IO.PutFR["Cancelled by %g", IO.rope[user]];
IPPrinterQueue.LogMessage[msg, requestNumber, IF Rope.IsEmpty[owner] THEN NIL ELSE owner];
PutString["Print request cancelled."];
}
ELSE {PutString["No such request in queue."]};
PutChar['\n]; PutChar['\l];
};
};
listFiles =>
{
{ -- For enable
ENABLE
FS.Error => {PutString[error.explanation]; PutString["\n\l"];
GOTO Bad};
Proc:
FS.NameProc =
TRUSTED {
-- [fullFName: ROPE] RETURNS [continue: BOOL];
PutString[fullFName];
PutString["\n\l"];
RETURN [TRUE];
};
fileNames: ROPE; cp: FS.ComponentPositions;
PutString[" --Pattern-- "];
fileNames ← GetStringToSpace[];
IF fileNames =
NIL
THEN {
PutString[" No file specified.\n\l"];
GOTO Bad;
};
[fileNames, cp, ] ← FS.ExpandName[fileNames];
IF cp.server.length # 0
THEN {
PutString[" Illegal file specified (not a local file).\n\l"];
GOTO Bad;
};
FS.EnumerateForNames[fileNames, Proc];
}; -- For enable
EXITS Bad => NULL
};
listQueue => {
action:
PROC [requestNumber:
CARDINAL, request: IPPrinterQueue.Request, status: IPPrinterQueue.RequestStatus]
RETURNS [continue:
BOOLEAN ←
TRUE] = {
IO.Put[stream, IO.int[requestNumber]];
PutChar[' ];
PutRequestStatus[request, status];
};
PutChar['\n]; PutChar['\l];
IF IPPrinterQueue.GetSuspended[]
THEN {
PutString[" *** Printing is suspended ***"];
PutChar['\n]; PutChar['\l];
};
IPPrinterQueue.EnumerateRequests[action];
};
messages => {
action:
PROC [message:
ROPE]
RETURNS [continue:
BOOLEAN ←
TRUE] = {
IF Match[message]
THEN {
PutString[message];
PutChar['\n]; PutChar['\l];
};
};
key: ROPE ← NIL;
Match:
PROC [message:
ROPE]
RETURNS [
BOOLEAN] = {
IF Rope.IsEmpty[key] THEN RETURN [TRUE];
RETURN [Rope.Find[s1: message, s2: key, case: FALSE]>=0];
};
IF sep # '\n
THEN {
PutString[" --matching string-- "];
key ← GetStringToCR[];
};
PutChar['\n]; PutChar['\l];
IPPrinterQueue.EnumerateMessages[action];
};
start => {
IF IPPrinterQueue.SetSuspended[
FALSE].old =
TRUE
THEN {
IPPrinterQueue.LogMessage["Printing started.",,user];
};
PutOK[];
};
stop => {
IF IPPrinterQueue.SetSuspended[
TRUE].old =
FALSE
THEN {
IPPrinterQueue.LogMessage["Printing suspended.",,user];
};
PutOK[];
};
setPrinterParams => {
sMargin, fMargin, newsMargin, newfMargin: CARDINAL;
PutString[" \n\lGetting current parameters. "];
[sMargin, fMargin] ← IPPrinterMain.GetMargins[];
PutString[IO.PutFR[" -- Current Parameters: sMargin: %g, fMargin: %g \n\l",
IO.card[sMargin], IO.card[fMargin]]];
PutString[" -- New sMargin<"];
IO.Put[stream, IO.card[sMargin]];
PutString[">-- "];
newsMargin ← GetNumber[default: sMargin];
IF newsMargin
NOT
IN [1..30]
THEN {
PutString[" --must be in [1..30]-- "];
PutChar['\n]; PutChar['\l];
RETURN;
};
PutString[" -- New fMargin<"];
IO.Put[stream, IO.card[fMargin]];
PutString[">-- "];
newfMargin ← GetNumber[default: fMargin];
IF newfMargin
NOT
IN [10..43]
THEN {
PutString[" --must be in [10..43]-- "];
PutChar['\n]; PutChar['\l];
RETURN;
};
PutString[" -- You sure? -- "];
IF EasyConfirm[]
THEN {
PutOK[];
IPPrinterMain.SetMargins[newsMargin, newfMargin];
[sMargin, fMargin] ← IPPrinterMain.GetMargins[];
IPPrinterQueue.LogMessage[
IO.PutFR["Setting margins to: sMargin: %g, fMargin: %g",
IO.card[sMargin], IO.card[fMargin]],,user];
};
};
resetQueue => {
PutString[" --Do you really want to reset the entire queue?-- "];
IF Confirm[]
THEN {
PutOK[];
IPPrinterQueue.Reset[];
IPPrinterQueue.LogMessage["Queue reset",,user];
};
};
help, illegal => {
PutString["\n\lValid commands are: "];
FOR cmd: CommandCode
IN [login..quit]
DO
candidate: ROPE ← commandTable[cmd];
PutString[candidate];
IF cmd # quit THEN PutString[", "];
ENDLOOP;
PutChar['\n]; PutChar['\l];
};
quit => {loggedIn ← FALSE; PutChar['\n]; PutChar['\l]; SendNow[]; quitting ← TRUE};
watch => {
stats: WatchStats.WatchStatsRecord ← WatchStats.GetWatchStats[];
IO.PutF[stream, " Free disk:\t%g\n\l", IO.int[stats.diskFree]];
IO.PutF[stream, " Free mds:\t%g\n\l", IO.int[stats.mdsFree]];
IO.PutF[stream, " Free gfi:\t%g\n\l", IO.int[stats.gfiFree]];
IO.PutF[stream, " Free VM:\t%g\n\l", IO.int[stats.vmFree]];
IO.PutF[stream, " VM run:\t%g\n\l", IO.int[stats.vmRun]];
IO.PutF[stream, " Load:\t%g\n\l", IO.real[stats.cpuLoad]];
flushed ← FALSE;
};
wait => {
requestNumber: INT ← lastRequest;
requestStatus: IPPrinterQueue.RequestStatus ← waiting;
action:
PROC [request: IPPrinterQueue.Request, status: IPPrinterQueue.RequestStatus] = {
requestStatus ← status;
};
toldUserThatItIsPrinting: BOOLEAN ← FALSE;
DoPrintingMsg:
PROC = {
IF requestStatus = printing
AND
NOT toldUserThatItIsPrinting
THEN {
PutString["Printing..."];
toldUserThatItIsPrinting ← TRUE;
};
};
IF sep # '\n
THEN {
PutString[" --Request Number<"];
IF lastRequest # -1 THEN IO.Put[stream, IO.int[lastRequest]];
PutString[">-- "];
lastRequest ← requestNumber ← GetNumber[default: lastRequest];
};
PutChar['\n]; PutChar['\l];
IF requestNumber
IN [0..
NAT.
LAST]
THEN {
IPPrinterQueue.CheckRequest[requestNumber, action];
IF requestStatus = waiting
THEN {
PutString["Waiting..."];
};
DoPrintingMsg[];
UNTIL requestStatus = notFound
OR requestStatus = canceled
DO
SendNow[];
Process.Pause[Process.MsecToTicks[10000]];
IPPrinterQueue.CheckRequest[requestNumber, action];
DoPrintingMsg[];
PutChar['.];
ENDLOOP;
PutString["Done.\n\l"];
};
};
ambiguous => {
PutString["\n\lAmbiguous command (type Help<CR> for help)\n\l"];
};
ENDCASE => ERROR;