home *** CD-ROM | disk | FTP | other *** search
- { Replace non-printing characters in Turbo Pascal strings with #???.
- Terminate and restart the string if necessary.
- A file which contains non-printing characters can confuse many printers,
- including the IDS Prism. Public domain program ALLCHAR.PAS showed me that
- Turbo allows either 255 or 256 characters in a quoted string. This converter
- let me print out that program. It could be useful for other programs as
- well.
-
- Lew Paper
- 12/10/85}
-
-
- PROGRAM repnonpr;
-
- CONST
- quote = 39;
-
- TYPE
- str255 = STRING[255];
- str80 = STRING[80];
- str3 = STRING[3];
-
- VAR
- instr: str255;
- name_in, name_out: str255;
- infile, outfile: TEXT;
- good_name: INTEGER;
- answer: CHAR;
- i: INTEGER;
- quoted: BOOLEAN;
- char_str: str3;
-
- BEGIN {PROGRAM repnonpr}
-
- CLRSCR;
- WRITELN('Replace nonprinting characters in strings with #...');
- WRITELN;
-
- {Get input file}
- REPEAT {UNTIL good_name = 0;}
- GOTOXY(1, 3);
- WRITE('Input file: ');
- READLN(name_in);
- CLREOL;
- ASSIGN(infile, name_in);
- {$I-}
- RESET(infile);
- {$I+}
- good_name := IORESULT;
- IF good_name > 0
- THEN
- WRITE('Unable to open file ', name_in, '. Enter new name');
- UNTIL good_name = 0;
-
- {Get output file}
- REPEAT {UNTIL good_name = 0;}
- GOTOXY(1, 5);
- WRITE('Output file: ');
- READLN(name_out);
- CLREOL;
- ASSIGN(outfile, name_out);
- {$I-}
- RESET(outfile);
- {$I+}
- IF IORESULT = 0
- THEN
- BEGIN
- CLOSE(outfile);
- REPEAT {UNTIL answer IN ['Y', 'N']}
- GOTOXY(1, 6);
- WRITE('Overwrite file ', name_out, ' (Y or N)? ');
- READLN(answer);
- CLREOL;
- answer := UPCASE(answer);
- CASE answer OF
- 'Y':
- good_name := 0;
-
- 'N':
- good_name := 1;
- ELSE
- WRITE('"Y" or "N" only please');
- END; { CASE answer }
- IF answer IN ['Y', 'N']
- THEN
- BEGIN
- GOTOXY(1,6);
- CLREOL;
- END; {IF answer IN ['Y', 'N']}
- UNTIL answer IN ['Y', 'N'];
- END {IF IORESULT = 0}
- ELSE
- good_name := 0;
- IF good_name = 0
- THEN
- BEGIN
- {$I-}
- REWRITE(outfile);
- {$I+}
- good_name := IORESULT;
- IF good_name > 0
- THEN
- WRITE('Unable to open file ', name_in, '. Enter new name');
- END; {IF good_name = 0}
- UNTIL good_name = 0;
-
- {Process file}
- WHILE NOT EOF(infile)
- DO
- BEGIN
- READLN(infile, instr);
- quoted := FALSE;
- i := 0;
- WHILE i < LENGTH(instr)
- DO
- BEGIN
- i := SUCC(i);
- IF quoted
- THEN
- IF (ORD(instr[i]) < 32) OR (ORD(instr[i]) > 126)
- THEN
- BEGIN
- STR(ORD(instr[i]), char_str);
- IF ORD(instr[i + 1]) = quote
- THEN
- DELETE(instr, i + 1, 1) {Remove trailing quote}
- ELSE
- INSERT(CHR(quote), instr, i + 1); {End split}
- INSERT('#' + char_str, instr, i + 1); {Printing character}
- DELETE(instr, i, 1); {Remove character}
- IF ORD(instr[i - 1]) = quote
- THEN
- BEGIN
- DELETE(instr, i - 1, 1); {Remove leading quote}
- quoted := FALSE;
- END {ORD(instr[i - 1]) = quote} {Start split}
- ELSE
- INSERT(CHR(quote), instr, i);
- END; {IF (ORD(instr[i]) < 32) OR (ORD(instr[i]) > 126)}
- IF ORD(instr[i]) = quote
- THEN
- quoted := NOT quoted;
- END; {WHILE i < LENGTH(instr)}
- WRITELN(outfile, instr);
- END; {WHILE NOT EOF(infile)}
-
- CLOSE(infile);
- CLOSE(outfile);
-
- END. {PROGRAM repnonpr}