Board index » delphi » Text files containing the ESC (Chr(27)) character

Text files containing the ESC (Chr(27)) character

Simple question - is there an easy way to disable the end-of-file use of
#27 in BP (Dos)? I know that I can use binary mode, but I'd rather not.
(The #27 character occurs in a text file as a left-arrow, and of-course
my software currently aborts when it is met.)

I'm sure I've seen some way of telling the library textfile code to
ignore #27 (or perhaps set it to something else) but I can't remember
what it was - perhaps it was all a dream.

Mark.
--
int MeaningOfLife (void) { return 42; }   // m...@holly.demon.co.uk
function MeaningOfLife :integer; begin MeaningOfLife := 6 * 9 end;

 

Re:Text files containing the ESC (Chr(27)) character


In article <805587915...@holly.demon.co.uk>, m...@holly.demon.co.uk says...

Quote
>Simple question - is there an easy way to disable the end-of-file use of
>#27 in BP (Dos)? I know that I can use binary mode, but I'd rather not.
>(The #27 character occurs in a text file as a left-arrow, and of-course
>my software currently aborts when it is met.)

This is not true. Only ^Z (#26) generates an EOF. An ESC (^[ or #27) cannot be
entered on input line, but it can read from a file.
Quote

>I'm sure I've seen some way of telling the library textfile code to
>ignore #27 (or perhaps set it to something else) but I can't remember
>what it was - perhaps it was all a dream.

I look also for this hint, but - see above - for the character #26.
--
Henrik Haftmann           ||email: henrik.haftm...@e-technik.tu-chemnitz.de
09126 Chemnitz            ||  www: http://www.tu-chemnitz.de/~heha
Reichenhainer Str. 51/105 || talk: he...@grill.csn.tu-chemnitz.de

Re:Text files containing the ESC (Chr(27)) character


In article <3uau7n$...@pyrrhus-f.hrz.tu-chemnitz.de>
   Henrik.Haftm...@E-Technik.TU-Chemnitz.DE (Henrik Haftmann) writes:

Quote
> This is not true. Only ^Z (#26) generates an EOF. An ESC (^[ or #27) cannot be
> entered on input line, but it can read from a file.

As a couple of people have pointed out, I meant #26 rather than #27. (I
knew that if I'd thought about it, which obviously I failed to do in this
case). The question still stands, though.

However, I've been looking through the RTL code, and the only places that
"eof" is used appear to be hard-coded, so it looks like I'm left with
rewriting my code to work with binary files (this looks most likely), or
else putting up with the problem. (I don't fancy patching the RTL, and in
any case I suspect that a lot of the problem is internal to DOS so an RTL
patch wouldn't fix the problem.)

I suppose I could redefine some other chars (#16 and #17 seem good
candidates) to look like the #26/#27 arrow characters on screen, but that
isn't really solving the problem; it would mean that the input file has
to be written by someone aware of the limitations.

Mark.
--
int MeaningOfLife (void) { return 42; }   // m...@holly.demon.co.uk
function MeaningOfLife :integer; begin MeaningOfLife := 6 * 9 end;

Re:Text files containing the ESC (Chr(27)) character


Quote
Mark Rogers <m...@holly.demon.co.uk> wrote:

>Simple question - is there an easy way to disable the end-of-file use of
>#27 in BP (Dos)? I know that I can use binary mode, but I'd rather not.
>(The #27 character occurs in a text file as a left-arrow, and of-course
>my software currently aborts when it is met.)

The EOF character is actually Ctrl-Z (#26). The #27 is Esc, and is usually
used in a DOS file to denote the beginning of an ANSI code sequence.

The problem with disabling the EOF (#26) character is that the function
Eof(F: File): boolean checks specifically for that character (as far as I
remember). Generally, if you have files that have an EOF in them, they
*are* binary files and need to be treated as such. I've just recently written
programs which search for an Esc (#27), though, so I know that TP
doesn't have any problem with them. (You are correct about it appearing
as a left-arrow, but that character doesn't cause TP to generate an EOF).

Alan

Re:Text files containing the ESC (Chr(27)) character


In article <806012343...@holly.demon.co.uk>,
Mark Rogers  <m...@holly.demon.co.uk> wrote:

Quote

>However, I've been looking through the RTL code, and the only places that
>"eof" is used appear to be hard-coded, so it looks like I'm left with
>rewriting my code to work with binary files (this looks most likely), or
>else putting up with the problem. (I don't fancy patching the RTL, and in
>any case I suspect that a lot of the problem is internal to DOS so an RTL
>patch wouldn't fix the problem.)

The problem is indeed internal to DOS. DOS used to store the length of
a file in allocation units; this meant that extra (redundant) code was
loaded in at the end of an executable file but an EOF character is
needed at the end of text files.

Quote
>I suppose I could redefine some other chars (#16 and #17 seem good
>candidates) to look like the #26/#27 arrow characters on screen, but that
>isn't really solving the problem; it would mean that the input file has
>to be written by someone aware of the limitations.

It sounds like the file that you have isn't really a text file at
all. (Been using emacs too much lately?) Consider changing a left
arrow to \LEFT and a right arrow to \RIGHT (and \ to \\) - that way
you will have a bona-fide text file that will be portable between
different operating systems.

[Multilingual sig deleted]

Peter

Re:Text files containing the ESC (Chr(27)) character


In article <3uet85$...@lyra.csx.cam.ac.uk>, pjb1...@cam.ac.uk says...

Quote
>The problem is indeed internal to DOS.

True for CP/M and DOS 1.0, NOT for other versions!!!

Quote
>Consider changing a left
>arrow to \LEFT and a right arrow to \RIGHT (and \ to \\)

This is not a solution, only a boring walkaround.
Do you ever live in a CP/M era?
--
Henrik Haftmann           ||email: henrik.haftm...@e-technik.tu-chemnitz.de
09126 Chemnitz            ||  www: http://www.tu-chemnitz.de/~heha
Reichenhainer Str. 51/105 || talk: he...@grill.csn.tu-chemnitz.de

Other Threads