--- z02.c.dist Sat Nov 30 12:38:22 1996 +++ z02.c Tue Nov 4 21:02:15 1997 @@ -314,6 +314,30 @@ Error(2, 4, "illegal macro invocation in database", FATAL, &fpos(next_token)); res = ftell(fp) - (limit - chpt) - (buf - frst); +#if BINARY_FTELL_WORKAROUND + /* uwe: 1997-11-04 + * + * On NT under Visual C++ ftell() and fseek() always use binary + * positions, even if the file was opened in text mode. This means + * that every LF in between the CHPT and LIMIT was counted by + * ftell() as *TWO* bytes. The pointer arithmetic above adjusts the + * ftold value as lout has not yet read chars past CHPT, but it + * counts each LF as *ONE* byte, naturally. + * + * The code below compensates for this binary/text brain death. + * + * PS: gcc from Cygnus' gnuwin32 has sane ftell() and does *NOT* + * need this workaround (I haven't tried compiling lout with gcc + * though, as the result will need cygwin.dll to run). + */ + { + register FULL_CHAR *p; + for (p = chpt; p < limit; ++p) { + if (*p == (FULL_CHAR) CH_NEWLINE) + --res; + } + } +#endif /* BINARY_FTELL_WORKAROUND */ debug1(DLA, D, "LexNextTokenPos() returning %ld", res); return res; }