GlobalRunDefaultsImpl.mesa
Copyright Ó 1990, 1991 by Xerox Corporation. All rights reserved.
Peter B. Kessler, August 20, 1990 1:53 pm PDT
Willie-s, June 25, 1992 12:02 pm PDT
Christian Jacobi, July 21, 1992 5:55 pm PDT
GlobalRunDefaultsImpl:
CEDAR
MONITOR
IMPORTS Commander, IO, Rope
EXPORTS GlobalRunDefaults
~ {
globalDefaultSwitches: Rope.
ROPE ¬ "-";
This is the global data protected by the monitor.
GetGlobalRunDefaults:
PUBLIC
ENTRY
PROCEDURE []
RETURNS [Rope.
ROPE] ~ {
RETURN [globalDefaultSwitches];
};
SetGlobalRunDefaults:
PUBLIC
ENTRY
PROCEDURE [defaults: Rope.
ROPE]
RETURNS [old: Rope.
ROPE] ~ {
old ¬ globalDefaultSwitches;
globalDefaultSwitches ¬ defaults;
RETURN [old: old];
};
RunGlobalDefaultsCmd: Commander.CommandProc ~ {
{
-- extra scope to contain EXITS.
cmds: IO.STREAM ~ IO.RIS[cmd.commandLine];
switches: Rope.
ROPE ~ GetCmdToken[cmds
! QuotedStringError => {
msg ¬ "Mismatched quotes";
GO TO Failure;
}];
IF Rope.Size[switches] > 0
AND Rope.Fetch[switches, 0] = '-
THEN {
[] ¬ SetGlobalRunDefaults[defaults: switches];
};
EXITS
Failure => {
result ¬ $Failure;
};
};
msg ¬ Rope.Concat["Global default switches for Run are ", GetGlobalRunDefaults[]];
RETURN [result: result, msg: msg];
};
QuotedStringError:
ERROR ~
CODE;
CmdTokenBreak:
PROCEDURE [char:
CHAR]
RETURNS [
IO.CharClass] = {
IF char = '" THEN RETURN [break];
IF char = ' OR char = '\t OR char = ', OR char = '\l OR char = '\r THEN RETURN [sepr];
RETURN [other];
};
GetCmdToken:
PROCEDURE [stream:
IO.
STREAM]
RETURNS [token: Rope.
ROPE ¬
NIL] ~ {
token ¬ IO.GetTokenRope[stream, CmdTokenBreak ! IO.EndOfStream => CONTINUE].token;
IF Rope.Equal[token, "\""]
THEN {
ref: REF;
IO.Backup[self: stream, char: '"];
ref ¬ IO.GetRefAny[stream ! IO.Error, IO.EndOfStream => ERROR QuotedStringError];
WITH ref
SELECT
FROM
rope: Rope.ROPE => token ¬ rope;
ENDCASE => ERROR QuotedStringError;
};
RETURN [token: token];
};
RegisterWithCommander:
PROCEDURE []
RETURNS [] ~ {
Commander.Register[
key: "RunGlobalDefaultSwitches",
proc: RunGlobalDefaultsCmd,
doc: "Set global default switches for the Run command"];
RETURN;
};
}.