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: boolean; //Whether to reset the reader or the punch
|
|
|
|
begin
|
|
|
|
//Check whether to set the reader, the punch, or both
|
|
if ParamCount <> 1 then begin
|
|
writeln ('Usage: tapectl reader/punch/both');
|
|
halt (1);
|
|
end;
|
|
if ParamStr (1) = 'reader' then begin
|
|
DoRead := true;
|
|
DoPunch := false;
|
|
end
|
|
else if ParamStr (1) = 'punch' then begin
|
|
DoRead := false;
|
|
DoPunch := true;
|
|
end
|
|
else if ParamStr (1) = 'both' then begin
|
|
DoRead := true;
|
|
DoPunch := true;
|
|
end
|
|
else begin
|
|
writeln ('Usage: tapectl reader/punch/both');
|
|
halt (1);
|
|
end;
|
|
|
|
//Assign the state file
|
|
assign (State, ExpandFileName ('~/.tapes.thingamajig'));
|
|
|
|
//Read existing state if any
|
|
if FileExists (ExpandFileName ('~/.tapes.thingamajig')) 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;
|
|
|
|
//Input the files to be read from or punched to
|
|
if DoRead then begin
|
|
write ('Reader: ');
|
|
readln (Reader.Path);
|
|
Reader.Path := ExpandFileName (Reader.Path);
|
|
Reader.Reset := true;
|
|
Reader.Pos := 0;
|
|
end;
|
|
if DoPunch then begin
|
|
write ('Punch: ');
|
|
readln (Punch.Path);
|
|
Punch.Path := ExpandFileName (Punch.Path);
|
|
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.
|