(*************************************************************************** OPEN FILE NAME: Legal CP/M file name. <14 characters max> LST: = PRINTER; CON: = CONSOLE; MODE: I = INPUT; O = OUTPUT; R = RANDOM; *DIRECTION*** input from output to random I/O from disk/console disk/console/printer *IORESULT*** FALSE - FALSE - FALSE - file does not exist file already exists file does not exist, so could not open file created file for write. TRUE - TRUE - TRUE - file exists. created file for write found requested file. FILE CONTROL BLOCK: file control block/file variable; ***************************************************************************) PROCEDURE OPEN ( FileName: DSTRING; MODE: CHAR; VAR FCB: TEXT ); LABEL 1; { fatal error exit } CONST idlen = 14; { max allowed chars for legal CP/M file name } VAR ipos: integer; flag: CHAR; BEGIN con_wanted := false; { * initialize flags * } printer_wanted := false; case mode of { * determine direction * } 'I': {input file} flag := '<'; 'O': {output file} flag := '>'; 'R': {random IO} flag := 'R'; else: begin {invalid MODE specified } writeln('+++INVALID MODE'); ioresult := false; {EXIT} goto 1 end end{case}; if pos('<|',filename)<>0 then { * determine default file names * } filename := 'PIPE.A' else if pos('>|',filename)<>0 then filename := 'PIPE.B' else if pos('CON:',filename)<>0 then begin filename := 'CON:'; con_wanted := true end else if pos('LST:',filename)<>0 then begin filename := 'LST:'; printer_wanted := true end else begin ipos := pos(flag,filename); if ( ipos<>0 ) then { a file name was specified } filename := copy(filename,ipos+1,length(filename)-ipos+1); end; if length(filename) > idlen then begin { length of file name exceeds requirements } writeln('+++INVALID FILE NAME: ', filename); ioresult := false; {EXIT} goto 1 end; case mode of 'I': { OPEN file FileName for READ assign FCB } begin if ( filename='LST:' ) then { error - printer is output device } ioresult := false else if ( filename='CON:' ) then begin RESET(filename, fcb); ioresult := true; end else begin RESET(filename, fcb); ioresult := not eof(fcb) end end; 'O': { OPEN file filename for WRITE assign FCB } begin if ( filename='CON:' ) OR ( filename='LST:' ) then begin REWRITE(filename, fcb); ioresult := true end else begin { * file must NOT already exist * } reset(filename,fcb); { * see if file already exists * } if not eof(fcb) then begin { report error } writeln('+++FILE "', filename, '" EXISTS'); ioresult := false end else begin { file does not exist } rewrite(filename,fcb); ioresult := true end end end; 'R': { OPEN FILE FILENAME FOR RANDOM IO ASSIGN FCB } begin reset(filename,fcb); { * see if file already exists * } if not eof(fcb) then { file exists } ioresult := true else begin { file does not exist so create it } rewrite(filename,fcb); ioresult := false end end; end{case}; 1: { fatal error exit } END{ OF OPEN }; te(filename,fcb); ioresult := false end end; end{case}; 1: { fatal error exit } END{ OF OPEN