summaryrefslogtreecommitdiff
path: root/gs/src/ansi2knr.c
diff options
context:
space:
mode:
authorL Peter Deutsch <lpd@ghostscript.com>2000-04-13 03:41:48 +0000
committerL Peter Deutsch <lpd@ghostscript.com>2000-04-13 03:41:48 +0000
commit7c19d23e23954f4879f9925de6e3d78d45d79d05 (patch)
treefc439484ba63dcc560ff131f38e14ba799f5a426 /gs/src/ansi2knr.c
parent455dc200d287bb066334fc40d184246c9923f090 (diff)
downloadghostpdl-7c19d23e23954f4879f9925de6e3d78d45d79d05.tar.gz
Fix: Backs out contributed changes of 2000-03-05 because of bugs.
git-svn-id: http://svn.ghostscript.com/ghostscript/trunk@312 a1074d23-0009-0410-80fe-cf8c14f379e6
Diffstat (limited to 'gs/src/ansi2knr.c')
-rw-r--r--gs/src/ansi2knr.c115
1 files changed, 20 insertions, 95 deletions
diff --git a/gs/src/ansi2knr.c b/gs/src/ansi2knr.c
index 613ce3bc5..2ff9d6198 100644
--- a/gs/src/ansi2knr.c
+++ b/gs/src/ansi2knr.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1989, 1997, 1998, 1999, 2000 Aladdin Enterprises. All rights reserved. */
+/* Copyright (C) 1989, 2000 Aladdin Enterprises. All rights reserved. */
/*$Id$*/
/* Convert ANSI C function definitions to K&R ("traditional C") syntax */
@@ -62,6 +62,12 @@ program under the GPL.
* <ghost@aladdin.com>. Other authors are noted in the change history
* that follows (in reverse chronological order):
+ lpd 2000-04-12 backs out Eggert's changes because of bugs:
+ - concatlits didn't declare the type of its bufend argument;
+ - concatlits didn't't recognize when it was inside a comment;
+ - scanstring could scan backward past the beginning of the string; when
+ - the check for \ + newline in scanstring was unnecessary.
+
2000-03-05 Paul Eggert <eggert@twinsun.com>
Add support for concatenated string literals.
@@ -218,7 +224,6 @@ char *scanstring();
int writeblanks();
int test1();
int convert1();
-int concatlits();
/* The main program */
int
@@ -342,7 +347,6 @@ f: if ( line >= buf + (bufsize - 1) ) /* overflow check */
continue;
/* falls through */
default: /* not a function */
- concatlits(buf, line, buf + bufsize, in);
wl: fputs(buf, out);
break;
}
@@ -402,7 +406,10 @@ ppdirbackward(p, limit)
}
}
-/* Skip over whitespace and comments, in either direction. */
+/*
+ * Skip over whitespace, comments, and preprocessor directives,
+ * in either direction.
+ */
char *
skipspace(p, dir)
char *p;
@@ -430,24 +437,9 @@ scanstring(p, dir)
char *p;
int dir;
{
- char quote = *p;
-
- for (p += dir; *p; p += dir) {
- if (*p == quote) {
- char *q = p;
- int backslashed;
-
- for (backslashed = 0; ; backslashed ^= 1) {
- for (q--; *q == '\n' && q[-1] == '\\'; q -= 2)
- continue;
- if (*q != '\\')
- break;
- }
- if (!backslashed)
- return p + dir;
- }
- }
- return p; /* unterminated string */
+ for (p += dir; ; p += dir)
+ if (*p == '"' && p[-dir] != '\\')
+ return p + dir;
}
/*
@@ -458,13 +450,11 @@ int
writeblanks(start, end)
char *start;
char *end;
-{
- char *p;
-
- for ( p = start; p < end; p++ )
- if ( *p != '\r' && *p != '\n' )
+{ char *p;
+ for ( p = start; p < end; p++ )
+ if ( *p != '\r' && *p != '\n' )
*p = ' ';
- return 0;
+ return 0;
}
/*
@@ -629,7 +619,7 @@ top: p = endfn;
if (p[1] == '*')
p = skipspace(p, 1) - 1;
break;
- case '"': case '\'':
+ case '"':
p = scanstring(p, 1) - 1;
break;
default:
@@ -663,7 +653,7 @@ top: p = endfn;
if (p > buf && p[-1] == '*')
p = skipspace(p, -1) + 1;
break;
- case '"': case '\'':
+ case '"':
p = scanstring(p, -1) + 1;
break;
default: ;
@@ -747,68 +737,3 @@ found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )
free((char *)breaks);
return 0;
}
-
-/* Append a line to a buffer. Return the end of the appended line. */
-char *
-appendline(lineend, bufend, in)
- char *lineend;
- char *bufend;
- FILE *in;
-{
- if (bufend == lineend)
- return NULL;
- if (fgets(lineend, (unsigned)(bufend - lineend), in) == NULL)
- return NULL;
- return lineend + strlen(lineend);
-}
-
-/*
- * Concatenate string literals in a non-function line, appending
- * new lines if a string literal crosses a line boundary or ends a line.
- */
-int
-concatlits(line, lineend, bufend, in)
- char *line;
- char *lineend;
- FILE *in;
-{
- char *d = line;
- char *s = line;
- char *s1;
- int pending_newlines = 0;
-
- if (lineend[-1] != '\n')
- return 0;
- if (*skipspace(s, 1) == '#')
- return 0;
- while (*s) {
- switch ((*d++ = *s++))
- {
- case '"': case '\'':
- for (;;) {
- while ((s1 = scanstring(s - 1, 1)) == lineend)
- if (!(lineend = appendline(lineend, bufend, in)))
- goto finish;
- do {
- *d++ = *s++;
- } while (s != s1);
- if (s[-1] != '"')
- break;
- while ((s1 = skipspace(s, 1)) == lineend)
- if (!(lineend = appendline(lineend, bufend, in)))
- goto finish;
- if (*s1 != '"')
- break;
- d--;
- do {
- pending_newlines += *s++ == '\n';
- } while (s <= s1);
- }
- }
- }
- while (pending_newlines--)
- *d++ = '\n';
-finish:
- strcpy(d, s);
- return 0;
-}