fixing problems with blank characters after the \ at line end

This commit is contained in:
Enno Rehling 2007-02-05 20:02:07 +00:00
parent 7c258dde41
commit 6f45043f19
1 changed files with 63 additions and 63 deletions

View File

@ -340,25 +340,25 @@ static char lbuf[MAXLINE];
static char * static char *
getbuf(FILE * F) getbuf(FILE * F)
{ {
boolean cont = false; boolean cont = false;
boolean quote = false; boolean quote = false;
boolean comment = false; boolean comment = false;
char * cp = buf; char * cp = buf;
lbuf[MAXLINE-1] = '@'; lbuf[MAXLINE-1] = '@';
do { do {
boolean eatwhite = true; boolean eatwhite = true;
boolean start = true; boolean start = true;
unsigned char * end; unsigned char * end;
unsigned char * bp = (unsigned char * )fgets(lbuf, MAXLINE, F); unsigned char * bp = (unsigned char * )fgets(lbuf, MAXLINE, F);
comment = (boolean)(comment && cont); comment = (boolean)(comment && cont);
if (!bp) return NULL; if (!bp) return NULL;
end = bp + strlen((const char *)bp); end = bp + strlen((const char *)bp);
if (*(end-1)=='\n') *(--end) = 0; if (*(end-1)=='\n') *(--end) = 0;
else { else {
/* wenn die zeile länger als erlaubt war, ist sie ungültig, /* wenn die zeile länger als erlaubt war, ist sie ungültig,
* und wird mit dem rest weggeworfen: */ * und wird mit dem rest weggeworfen: */
@ -372,53 +372,53 @@ getbuf(FILE * F)
comment = false; comment = false;
bp = NULL; bp = NULL;
} }
cont = false; cont = false;
while (bp!=NULL && *bp && cp!=buf+MAXLINE && (char*)bp!=lbuf+MAXLINE) { while (bp!=NULL && *bp && cp!=buf+MAXLINE && (char*)bp!=lbuf+MAXLINE) {
if (isspace(*bp)) { if (isspace(*bp)) {
if (eatwhite) { if (cont) ++bp; /* removes spaces and \r afer a backslash */
do { ++bp; } while ((char*)bp!=lbuf+MAXLINE && isspace(*bp)); else if (eatwhite) {
if (!quote && !start && !comment) *(cp++)=' '; do { ++bp; } while ((char*)bp!=lbuf+MAXLINE && isspace(*bp));
} if (!quote && !start && !comment) *(cp++)=' ';
else { }
else {
if (!comment) *(cp++)=*(bp++); if (!comment) *(cp++)=*(bp++);
while (cp!=buf+MAXLINE && (char*)bp!=lbuf+MAXLINE && isspace(*bp)) { while (cp!=buf+MAXLINE && (char*)bp!=lbuf+MAXLINE && isspace(*bp)) {
if (!comment) *(cp++)=*bp; if (!comment) *(cp++)=*bp;
++bp; ++bp;
} }
if (*bp==0) --cp; if (*bp==0) --cp;
} }
} }
else if (iscntrl(*bp)) { else if (iscntrl(*bp)) {
*(cp++) = '?'; *(cp++) = '?';
++bp; ++bp;
} else { } else {
cont = false; cont = false;
if (*bp==COMMENT_CHAR && !quote) { if (*bp==COMMENT_CHAR && !quote) {
/* bp = max(end-1, bp+1); */ comment=true;
comment=true; }
} else {
else { if (*bp=='"') {
if (*bp=='"') { quote = (boolean)!quote;
quote = (boolean)!quote;
*cp++ = *bp; *cp++ = *bp;
eatwhite=true; eatwhite=true;
} }
else if (*bp=='\\') cont=true; else if (*bp=='\\') cont=true;
else { else {
if (!comment) *(cp++) = *bp; if (!comment) *(cp++) = *bp;
eatwhite = (boolean)!quote; eatwhite = (boolean)!quote;
} }
} }
++bp; ++bp;
} }
start = false; start = false;
} }
if (cp==buf+MAXLINE) { if (cp==buf+MAXLINE) {
--cp; --cp;
} }
*cp=0; *cp=0;
} while (cont || cp==buf); } while (cont || cp==buf);
return buf; return buf;
} }
#ifdef ENEMIES #ifdef ENEMIES