File: JukeboxCommandsImpl.mesa
This file prints information about a given Jukebox.
L. Stewart January 6, 1984 3:34 pm
Last Edited by: Swinehart, September 23, 1984 9:57:18 pm PDT
Ades, February 25, 1986 3:19:35 pm PST
DIRECTORY
Commander USING [CommandProc, Register],
CommandTool USING [ArgumentVector, Failed, Parse],
Convert USING [IntFromRope],
IO USING [int, PutF, STREAM],
Jukebox USING [CloseJukebox, CreateJukebox, DeleteJukebox, Error, FindJukebox, Handle, OpenJukebox, Scavenge, instances],
Rope USING [Equal, ROPE];
JukeboxCommandsImpl: PROGRAM
IMPORTS Commander, CommandTool, Convert, IO, Jukebox, Rope =
BEGIN
CreateJukebox: Commander.CommandProc = TRUSTED {
{
ENABLE Jukebox.Error => {
msg ← rope;
GOTO Quit;
};
argv: CommandTool.ArgumentVector;
nPages: INT;
nTunes: INT;
argv ← CommandTool.Parse[cmd ! CommandTool.Failed => { msg ← errorMsg; GOTO Quit;}];
IF argv.argc # 4 THEN RETURN[$Failure, "Usage: CreateJukebox jukeboxName nPages nTunes"];
nPages ← Convert.IntFromRope[argv[2]];
nTunes ← Convert.IntFromRope[argv[3]];
Jukebox.CreateJukebox[nPages: nPages, nTunes: nTunes, name: argv[1]]
}
EXITS
Quit => RETURN[$Failure, msg];
};
OpenJukebox: Commander.CommandProc = TRUSTED {
{
ENABLE Jukebox.Error => {
msg ← rope;
GOTO Quit;
};
argv: CommandTool.ArgumentVector ← CommandTool.Parse[cmd ! CommandTool.Failed => { msg ← errorMsg; GOTO Quit;}];
IF argv.argc # 2 THEN RETURN[$Failure, "Usage: OpenJukebox jukeboxName"];
[] ← Jukebox.OpenJukebox[name: argv[1]]
}
EXITS
Quit => RETURN[$Failure, msg];
};
CloseJukebox: Commander.CommandProc = TRUSTED {
{
ENABLE Jukebox.Error => {
msg ← rope;
GOTO Quit;
};
argv: CommandTool.ArgumentVector;
jukebox: Jukebox.Handle ← NIL;
argv ← CommandTool.Parse[cmd ! CommandTool.Failed => { msg ← errorMsg; GOTO Quit;}];
IF argv.argc # 2 THEN RETURN[$Failure, "Usage: CloseJukebox jukeboxName"];
jukebox ← Jukebox.FindJukebox[argv[1]];
IF jukebox = NIL THEN RETURN[$Failure, "jukebox not open"];
jukebox ← Jukebox.CloseJukebox[self: jukebox];
};
EXITS
Quit => RETURN[$Failure, msg];
};
DeleteJukebox: Commander.CommandProc = TRUSTED {
{
ENABLE Jukebox.Error => {
msg ← rope;
GOTO Quit;
};
argv: CommandTool.ArgumentVector ← CommandTool.Parse[cmd ! CommandTool.Failed => { msg ← errorMsg; GOTO Quit;}];
IF argv.argc # 2 THEN RETURN[$Failure, "Usage: DeleteJukebox jukeboxName"];
Jukebox.DeleteJukebox[name: argv[1]]
};
EXITS
Quit => RETURN[$Failure, msg];
};
ScavengeJukebox: Commander.CommandProc = TRUSTED {
jukebox: Jukebox.Handle ← NIL;
weOpened: BOOLEANFALSE;
{
ENABLE Jukebox.Error => {
msg ← rope;
GOTO Quit;
};
argv: CommandTool.ArgumentVector;
nFree, recovered: INT;
argv ← CommandTool.Parse[cmd ! CommandTool.Failed => { msg ← errorMsg; GOTO Quit}];
IF argv.argc # 2 THEN {msg ← "Usage: ScavengeJukebox jukeboxName|#"; GOTO Quit};
IF argv[1].Equal["#"] THEN {
IF Jukebox.instances=NIL THEN { msg ← "No jukebox open"; GOTO Quit};
jukebox ← Jukebox.instances.first;
}
ELSE jukebox ← Jukebox.FindJukebox[argv[1]];
IF jukebox = NIL THEN {
jukebox ← Jukebox.OpenJukebox[argv[1]];
weOpened ← TRUE
};
[nFree: nFree, recovered: recovered] ← Jukebox.Scavenge[self: jukebox, stream: cmd.out, makeFixes: TRUE];
cmd.out.PutF["%d chirps recovered, now %d chirps free\n", IO.int[recovered], IO.int[nFree]];
IF weOpened THEN jukebox ← Jukebox.CloseJukebox[jukebox]
EXITS
Quit =>
{ IF weOpened AND jukebox # NIL THEN jukebox ← Jukebox.CloseJukebox[jukebox];
RETURN[$Failure, msg];
}
}};
Init: PROC = {
Commander.Register[key: "CreateJukebox", proc: CreateJukebox, doc: "CreateJukebox jukeboxName nPages nTunes: the total length of sound in seconds which can be recorded in the jukebox will be roughly (nPages-2*nTunes)/16"];
Commander.Register[key: "OpenJukebox", proc: OpenJukebox, doc: "OpenJukebox jukeboxName"];
Commander.Register[key: "CloseJukebox", proc: CloseJukebox, doc: "OpenJukebox jukeboxName"];
Commander.Register[key: "DeleteJukebox", proc: DeleteJukebox, doc: "DeleteJukebox jukeboxName"];
Commander.Register[key: "ScavengeJukebox", proc: ScavengeJukebox, doc: "ScavengeJukebox jukeboxName|#: # represents the first currently open jukebox"];
};
initialization
Init[];
END.
L. Stewart, April 11, 1983 1:09 pm, created
L. Stewart, December 27, 1983 2:28 pm, Cedar 5
L. Stewart, January 6, 1984 3:34 pm, FixTune