program Tape; {$MODE OBJFPC} uses SysUtils; type //Tape file path and reset state TapeState = record Path: shortstring; Reset: boolean; Pos: integer; end; var Reader, Punch: TapeState; //States of the reader and punch State: file of TapeState; //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: tape reader/punch/both'); halt; 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: tape reader/punch/both'); halt; 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.