93 lines
2.2 KiB
ObjectPascal
93 lines
2.2 KiB
ObjectPascal
program TapeCtl;
|
|
|
|
{$MODE OBJFPC}
|
|
|
|
uses SysUtils;
|
|
|
|
type
|
|
//Tape file path and reset state
|
|
Tape = record
|
|
Path: shortstring;
|
|
Reset: boolean;
|
|
Pos: integer;
|
|
end;
|
|
|
|
var
|
|
Reader, Punch: Tape; //States of the reader and punch
|
|
State: file of Tape; //File storing the states of the reader and punch
|
|
DoRead, DoPunch: integer; //Whether to (re)set the reader or the punch
|
|
|
|
begin
|
|
|
|
//Check the arguments
|
|
if ParamCount > 4 then begin
|
|
writeln ('Usage: tapectl (-r tape) (-p tape)');
|
|
halt (1);
|
|
end
|
|
else if ParamCount mod 2 <> 0 then begin
|
|
writeln ('Usage: tapectl (-r tape) (-p tape)');
|
|
halt (1);
|
|
end;
|
|
if ParamStr (1) = '-r' then begin
|
|
DoRead := 2;
|
|
DoPunch := 0;
|
|
if ParamStr (3) = '-p' then begin
|
|
DoPunch := 4;
|
|
end;
|
|
end
|
|
else if ParamStr (1) = '-p' then begin
|
|
DoRead := 0;
|
|
DoPunch := 2;
|
|
if ParamStr (3) = '-r' then DoRead := 4;
|
|
end
|
|
else begin
|
|
writeln ('Usage: tapectl (-r tape) (-p tape)');
|
|
halt (1);
|
|
end;
|
|
|
|
//Assign the state file
|
|
assign (State, ExpandFileName ('~/.thingamajig/tapes'));
|
|
|
|
//Read existing state if any
|
|
if FileExists (ExpandFileName ('~/.thingamajig/tapes')) then begin
|
|
try
|
|
reset (State);
|
|
read (State, Reader);
|
|
read (State, Punch);
|
|
close (State);
|
|
except
|
|
end;
|
|
end
|
|
//Or else assign a default state
|
|
else begin
|
|
Reader.Path := '';
|
|
Reader.Reset := true;
|
|
Reader.Pos := 0;
|
|
Punch.Path := '';
|
|
Punch.Reset := true;
|
|
Punch.Pos := 0;
|
|
end;
|
|
|
|
//Get the files to be read from or punched to
|
|
if DoRead <> 0 then begin
|
|
Reader.Path := ExpandFileName (ParamStr (DoRead));
|
|
Reader.Reset := true;
|
|
Reader.Pos := 0;
|
|
end;
|
|
if DoPunch <> 0 then begin
|
|
Punch.Path := ExpandFileName (ParamStr (DoPunch));
|
|
Punch.Reset := true;
|
|
Punch.Pos := 0;
|
|
end;
|
|
|
|
//Write the state
|
|
try
|
|
rewrite (State);
|
|
write (State, Reader);
|
|
write (State, Punch);
|
|
close (State);
|
|
except
|
|
writeln ('Error: could not set the tape(s)');
|
|
end;
|
|
|
|
end.
|