cpp w/DOS line feeds
Mon Jan 25 12:48:00 GMT 1999
I have some comments on read_and_prescan:
1) The comment about the size of the intermdiate buffer is good, but I'd like
to see it expressed in the code. I'd like to see the number of bytes to be read
defined as a macro and the buffer size expressed as an expression using this
#define READ_LENGTH 4096
U_CHAR intermed[READ_LENGTH + 2 + 2];
count = read (desc, intermed + 2, READ_LENGTH);
Then the size of the buffer could be easily changed.
2) I don't undertand the code which ends up deciding that the file is too
large. What is the limit? I think I don't understand it because the variable
names ip, op, ol, etc. are not very descriptive.
3) There should be a comment explaining why the default label needs to be at
Zack Weinberg wrote:
> On Sat, 23 Jan 1999 17:46:21 +0100, "Matthias Urlichs" wrote:
> >Per Bothner:
> >> > Four. When you compile and/or run the code on a Mac, you might get the
> >> > equivalent of \n\r when reading DOS files.
> >> Presumably only when opening the file in text mode - not when opining
> >> it in binary mode?
> >I've heard of at least one compiler which switches the ASCII codes
> >of \r and \n. Thus, if you use code compiled by this thing, and if you
> >open the file in text mode, it would come out OK again. :-/
> 'nuff talk - here's some code. This patch makes cpplib understand any
> of \n, \r, \r\n, \n\r as the line terminator. It also adds trigraph
> support, which we didn't have before. (It was convenient to do them
> both in the same place.) There is a slight performance hit, which I
> believe I can win back elsewhere; I didn't want to make this patch too
> big. You'll need the previous patch I posted for cpplib.c to make
> this install cleanly. Bootstrap is successful, libc build is
> successful if my cppexp.c patch is present. I haven't tortured the
> alternate-line-terminator code much, but it does work in simple cases.
> The switch has the default label at the top to work around an
> infelicity in gcc's register allocation; I'll post separately on that.
> 1999-01-24 01:14 -0500 Zack Weinberg <email@example.com>
> * cppfiles.c (safe_read): Deleted.
> (read_and_prescan): New function, replaces safe_read, converts
> and/or warns about trigraphs, silently converts odd line
> terminators (\r, \n\r, \r\n). Warns about no newline at EOF.
> (finclude): Use read_and_prescan; turn off nonblocking mode on
> the input descriptor; remove file-size-examination and
> no-newline-at-EOF gunk which is longer necessary; be more
> careful about checking that we've been handed a legitimate
> file to read (only real files, pipes, and ttys are acceptable).
> * cpplib.h (cpp_options): Rename no_trigraphs flag to
> `trigraphs' and invert its sense.
> (trigraph_table): Declare.
> (cpp_warning_with_line): Prototype.
> * cpplib.c: Remove all references to trigraph_pcp. Define
> trigraph_table; initialize it in initialize_char_syntax. Open
> files in nonblocking mode. s/no_trigraphs/trigraphs/
> throughout, and invert sense. Put cpp_warning_with_line back
> in and export it.
More information about the Gcc-patches