-- GroupReset.mesa May 3, 1982 11:06 am
-- L. Stewart
-- Schroeder, February 3, 1983 2:21 pm
DIRECTORY
CIFS: TYPE USING [AddSearchRule, DeleteContext, Error, GetSearchRules,
GetWDir, Reset, SetWDir],
ConvertUnsafe: TYPE USING [AppendRope, ToRope],
IO: TYPE USING [PutF, rope, STREAM],
LSD: TYPE USING [Entry, Enumerate, EProc],
Rope: TYPE USING [Lower, ROPE],
Runtime: TYPE USING [BoundsFault],
UECP: TYPE USING [Parse, Argv],
UserExec: TYPE USING [RegisterCommand, UserAbort, ResetUserAbort,
GetStreams, CommandProc];
GroupReset: MONITOR
IMPORTS CIFS, ConvertUnsafe, IO, LSD, Rope, Runtime, UECP, UserExec
= {
GRP: UserExec.CommandProc = TRUSTED {
-- Enumerates all of the files in the LSD and resets those whose
-- initial strings match the given string.
initial: STRING ← [100];
rl: LIST OF Rope.ROPE ← NIL;
wdir: Rope.ROPE;
searchRules: LIST OF Rope.ROPE ← NIL;
argv: UECP.Argv;
out: IO.STREAM;
proc: LSD.EProc = {
lsdname: LONG STRING ← @entry.name;
IF lsdname.length < initial.length THEN RETURN[UserExec.UserAbort[exec]];
FOR i: NAT IN [0..initial.length) DO
IF Rope.Lower[lsdname[i]]#initial[i] THEN RETURN[UserExec.UserAbort[exec]];
ENDLOOP;
rl ← CONS[ConvertUnsafe.ToRope[lsdname], rl];
RETURN[UserExec.UserAbort[exec]];
};
{
[ , out ] ← exec.GetStreams[];
out.PutF["\nGroupReset: Version of March 26, 1982 6:31 pm\n\n"];
-- first, point working directory at a harmless spot
wdir ← CIFS.GetWDir[];
searchRules ← CIFS.GetSearchRules[];
CIFS.DeleteContext[];
argv ← UECP.Parse[event.commandLine];
IF argv.argc<2 THEN GOTO Cleanup;
ConvertUnsafe.AppendRope[to: initial, from: argv[1] ! Runtime.BoundsFault => GOTO Cleanup];
FOR i: NAT IN [0..initial.length) DO
initial[i] ← Rope.Lower[initial[i]];
ENDLOOP;
LSD.Enumerate[proc];
IF UserExec.UserAbort[exec] THEN GOTO Cleanup;
WHILE rl#NIL DO
out.PutF["%s\n", IO.rope[rl.first]];
IF UserExec.UserAbort[exec] THEN GOTO Cleanup;
CIFS.Reset[rl.first ! CIFS.Error => {
out.PutF["%g\n", IO.rope[error]];
CONTINUE;
};];
rl ← rl.rest;
ENDLOOP;
GOTO Cleanup;
EXITS
Cleanup => {
-- Now reset context back to what it was
CIFS.SetWDir[wdir];
WHILE searchRules#NIL DO
CIFS.AddSearchRule[path: searchRules.first, before: FALSE];
searchRules ← searchRules.rest;
ENDLOOP;
UserExec.ResetUserAbort[exec];
};
};
};
UserExec.RegisterCommand["GroupReset.~", GRP, "Reset multiple files", NIL];
}.