Thingamajig/floppyctl.pas

74 lines
1.7 KiB
Plaintext

program FloppyCtl;
{$MODE OBJFPC}
uses SysUtils;
var
Disc0, Disc1: shortstring; //States of the floppy discs
State: file of shortstring; //File storing the states of the floppy discs
Set0, Set1: integer; //Whether to (re)set the discs
begin
//Check the arguments
if ParamCount > 4 then begin
writeln ('Usage: floppyctl (-0 disc) (-1 disc)');
halt (1);
end
else if ParamCount mod 2 <> 0 then begin
writeln ('Usage: floppyctl (-0 disc) (-1 disc)');
halt (1);
end;
if ParamStr (1) = '-0' then begin
Set0 := 2;
Set1 := 0;
if ParamStr (3) = '-1' then begin
Set1 := 4;
end;
end
else if ParamStr (1) = '-1' then begin
Set0 := 0;
Set1 := 2;
if ParamStr (3) = '-0' then Set0 := 4;
end
else begin
writeln ('Usage: floppyctl (-0 disc) (-1 disc)');
halt (1);
end;
//Assign the state file
assign (State, ExpandFileName ('~/.thingamajig/discs'));
//Read existing state if any
if FileExists (ExpandFileName ('~/.thingamajig/discs')) then begin
try
reset (State);
read (State, Disc0);
read (State, Disc1);
close (State);
except
end;
end
//Or else assign a default state
else begin
Disc0 := '';
Disc1 := '';
end;
//Get the files
if Set0 <> 0 then Disc0 := ExpandFileName (ParamStr (Set0));
if Set1 <> 0 then Disc1 := ExpandFileName (ParamStr (Set1));
//Write the state
try
rewrite (State);
write (State, Disc0);
write (State, Disc1);
close (State);
except
writeln ('Error: could not set the disc(s)');
end;
end.