uses dos; var f, g: file; m, c, confirm, return: char; name, out: string; r: word; reverse: boolean; function fe(filename: string): boolean; var f : file; begin assign(f,filename); reset(f,1); close(f); fe := (ioresult = 0) and (filename <> ''); end; begin reverse := false; name := paramstr(1); if (name='/?') or (name='?') or (name='-?') then begin writeln('USE: tr [source file] [destination file]'); writeln; writeln('Converts a linux/unix text file into a ms-dos text file'); writeln('adding the ascii #13 value before the ascii #10 value.'); writeln('Performing the operation twice is perfectly safe because'); writeln('the program checks if the file is already formatted.'); halt(0); end; case paramcount of 0: begin write('File: '); readln(name); write('Output: '); readln(out); end; 1: begin name:=paramstr(1); write('Output: '); readln(out); end; 2: begin name:= paramstr(1); out:=paramstr(2); end; 3: begin name:= paramstr(1); out:=paramstr(2); reverse := true; end; end; if out='' then out:='out.txt'; if not fe(name) then begin writeln('File does not exist!'); halt(1); end; if fe(out) then begin if out=name then begin writeln('Overwriting source file not supported yet.'); halt(0); end; write('Warning: output file already exists. Overwrite? [Y/N] (y): '); readln(confirm);if confirm='' then confirm:='Y';confirm := upcase(confirm); if confirm<>'Y' then halt(0); end; assign(f, name); reset(f, 1); assign(g, out); rewrite(g, 1); return := #13; m := #42; while not eof(f) do begin blockread(f, c, 1, r); if reverse then begin if (c<>#13) then blockwrite(g, c, 1, r); end else begin if (c=#10) and (m<>#13) then blockwrite(g, return, 1, r); blockwrite(g, c, 1, r); m := c; end; end; writeln('Done. Formatted file saved in ', out); end.