Commit 1e18a243 by Zack Weinberg

[multiple changes]

2000-07-20  Zack Weinberg  <zack@wolery.cumb.org>

	* tradcpp.c (main): Don't munge -D options.
	(make_definition): Bring -D handling in line with cpplib.
	(do_define): Strip all leading whitespace from macro definitions.

2000-07-20  David Billinghurst <David.Billinghurst@riotinto.com.au>

	* Makefile.in (tradcpp): Depend on intl.o and version.o.

From-SVN: r35145
parent 5685bed3
...@@ -1822,7 +1822,7 @@ mkdeps.o: mkdeps.c $(CONFIG_H) system.h mkdeps.h ...@@ -1822,7 +1822,7 @@ mkdeps.o: mkdeps.c $(CONFIG_H) system.h mkdeps.h
# The traditional mode preprocessor, a separate program for ease of # The traditional mode preprocessor, a separate program for ease of
# maintenance. Some code is shared with the ISO-C cpp. # maintenance. Some code is shared with the ISO-C cpp.
tradcpp$(exeext): tradcpp.o tradcif.o cppdefault.o $(LIBDEPS) tradcpp$(exeext): tradcpp.o tradcif.o cppdefault.o version.o intl.o $(LIBDEPS)
$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o tradcpp$(exeext) \ $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o tradcpp$(exeext) \
tradcpp.o tradcif.o cppdefault.o version.o intl.o $(LIBS) tradcpp.o tradcif.o cppdefault.o version.o intl.o $(LIBS)
......
...@@ -610,7 +610,7 @@ main (argc, argv) ...@@ -610,7 +610,7 @@ main (argc, argv)
case 'D': case 'D':
{ {
char *p, *p1; char *p;
if (argv[i][2] != 0) if (argv[i][2] != 0)
p = argv[i] + 2; p = argv[i] + 2;
...@@ -619,8 +619,6 @@ main (argc, argv) ...@@ -619,8 +619,6 @@ main (argc, argv)
else else
p = argv[++i]; p = argv[++i];
if ((p1 = (char *) strchr (p, '=')) != NULL)
*p1 = ' ';
pend_defs[i] = p; pend_defs[i] = p;
} }
break; break;
...@@ -2543,8 +2541,8 @@ do_define (buf, limit, op, keyword) ...@@ -2543,8 +2541,8 @@ do_define (buf, limit, op, keyword)
} }
++bp; /* skip paren */ ++bp; /* skip paren */
/* Skip exactly one space or tab if any. */ while (is_hor_space[*bp]) /* and leading whitespace */
if (bp < limit && (*bp == ' ' || *bp == '\t')) ++bp; ++bp;
/* now everything from bp before limit is the definition. */ /* now everything from bp before limit is the definition. */
defn = collect_expansion (bp, limit, argno, arg_ptrs); defn = collect_expansion (bp, limit, argno, arg_ptrs);
...@@ -2566,9 +2564,9 @@ do_define (buf, limit, op, keyword) ...@@ -2566,9 +2564,9 @@ do_define (buf, limit, op, keyword)
defn->argnames[i] = 0; defn->argnames[i] = 0;
} }
} else { } else {
/* simple expansion or empty definition; gobble it */ /* simple expansion or empty definition; skip leading whitespace */
if (is_hor_space[*bp]) while (is_hor_space[*bp])
++bp; /* skip exactly one blank/tab char */ ++bp;
/* now everything from bp before limit is the definition. */ /* now everything from bp before limit is the definition. */
defn = collect_expansion (bp, limit, -1, 0); defn = collect_expansion (bp, limit, -1, 0);
defn->argnames = (U_CHAR *) ""; defn->argnames = (U_CHAR *) "";
...@@ -4667,52 +4665,26 @@ make_definition (str) ...@@ -4667,52 +4665,26 @@ make_definition (str)
FILE_BUF *ip; FILE_BUF *ip;
struct directive *kt; struct directive *kt;
U_CHAR *buf, *p; U_CHAR *buf, *p;
size_t len = strlen ((char *)str);
buf = str;
p = str; p = (U_CHAR *) strchr ((char *)str, '=');
while (is_idchar[*p]) p++; if (p == NULL) {
if (p == str) { /* Change -DFOO into #define FOO 1 */
error ("malformed option `-D %s'", str); buf = (U_CHAR *) alloca (len + 3);
return; memcpy (buf, str, len);
} memcpy (buf + len, " 1", 3);
if (*p == 0) { len += 2;
buf = (U_CHAR *) alloca (p - buf + 4);
strcpy ((char *)buf, (char *)str);
strcat ((char *)buf, " 1");
} else if (*p != ' ') {
error ("malformed option `-D %s'", str);
return;
} else { } else {
U_CHAR *q; buf = (U_CHAR *) alloca (len + 1);
/* Copy the entire option so we can modify it. */ memcpy (buf, str, len + 1);
buf = (U_CHAR *) alloca (2 * strlen ((char *)str) + 1);
strncpy ((char *)buf, (char *)str, p - str);
/* Change the = to a space. */
buf[p - str] = ' '; buf[p - str] = ' ';
/* Scan for any backslash-newline and remove it. */
p++;
q = &buf[p - str];
while (*p) {
if (*p == '\\' && p[1] == '\n')
p += 2;
/* Change newline chars into newline-markers. */
else if (*p == '\n')
{
*q++ = '\n';
*q++ = '\n';
p++;
}
else
*q++ = *p++;
}
*q = 0;
} }
ip = &instack[++indepth]; ip = &instack[++indepth];
ip->fname = "*Initialization*"; ip->fname = "*Initialization*";
ip->buf = ip->bufp = buf; ip->buf = ip->bufp = buf;
ip->length = strlen ((char *)buf); ip->length = len;
ip->lineno = 1; ip->lineno = 1;
ip->macro = 0; ip->macro = 0;
ip->free_ptr = 0; ip->free_ptr = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment