fixed bug, added -o option
This commit is contained in:
parent
cccb0dd197
commit
bdbbf32404
5 changed files with 27 additions and 11 deletions
|
@ -77,7 +77,7 @@ GENERATED = tokenfile.g Lpars.h LLfiles LL.output lint.out \
|
||||||
all: cc
|
all: cc
|
||||||
|
|
||||||
cc: hfiles LLfiles
|
cc: hfiles LLfiles
|
||||||
make "EMHOME="$(EMHOME) ncpp
|
make "EMHOME="$(EMHOME) "CC="$(CC) ncpp
|
||||||
|
|
||||||
hfiles: Parameters char.c
|
hfiles: Parameters char.c
|
||||||
./make.hfiles Parameters
|
./make.hfiles Parameters
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
|
|
||||||
|
extern char options[];
|
||||||
extern char **inctable; /* list of include directories */
|
extern char **inctable; /* list of include directories */
|
||||||
extern char *getwdir();
|
extern char *getwdir();
|
||||||
char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */
|
char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */
|
||||||
|
@ -225,8 +226,10 @@ int to_endif;
|
||||||
error("#else after #else");
|
error("#else after #else");
|
||||||
++(ifstack[nestlevel]);
|
++(ifstack[nestlevel]);
|
||||||
if (!to_endif && nestlevel == skiplevel) {
|
if (!to_endif && nestlevel == skiplevel) {
|
||||||
if (SkipToNewLine(1))
|
if (SkipToNewLine(1)) {
|
||||||
strict("garbage following #else");
|
if (!options['o'])
|
||||||
|
strict("garbage following #else");
|
||||||
|
}
|
||||||
NoUnstack--;
|
NoUnstack--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -235,8 +238,10 @@ int to_endif;
|
||||||
case K_ENDIF:
|
case K_ENDIF:
|
||||||
assert(nestlevel > svnestlevel[nestcount]);
|
assert(nestlevel > svnestlevel[nestcount]);
|
||||||
if (nestlevel == skiplevel) {
|
if (nestlevel == skiplevel) {
|
||||||
if (SkipToNewLine(1))
|
if (SkipToNewLine(1)) {
|
||||||
strict("garbage following #endif");
|
if (!options['o'])
|
||||||
|
strict("garbage following #endif");
|
||||||
|
}
|
||||||
nestlevel--;
|
nestlevel--;
|
||||||
NoUnstack--;
|
NoUnstack--;
|
||||||
return;
|
return;
|
||||||
|
@ -377,8 +382,10 @@ do_elif()
|
||||||
|
|
||||||
do_else()
|
do_else()
|
||||||
{
|
{
|
||||||
if (SkipToNewLine(1))
|
if (SkipToNewLine(1)) {
|
||||||
strict("garbage following #else");
|
if (!options['o'])
|
||||||
|
strict("garbage following #else");
|
||||||
|
}
|
||||||
if (nestlevel <= svnestlevel[nestcount])
|
if (nestlevel <= svnestlevel[nestcount])
|
||||||
error("#else without corresponding #if");
|
error("#else without corresponding #if");
|
||||||
else { /* mark this level as else-d */
|
else { /* mark this level as else-d */
|
||||||
|
@ -392,8 +399,10 @@ do_else()
|
||||||
|
|
||||||
do_endif()
|
do_endif()
|
||||||
{
|
{
|
||||||
if (SkipToNewLine(1))
|
if (SkipToNewLine(1)) {
|
||||||
strict("garbage following #endif");
|
if (!options['o'])
|
||||||
|
strict("garbage following #endif");
|
||||||
|
}
|
||||||
if (nestlevel <= svnestlevel[nestcount]) {
|
if (nestlevel <= svnestlevel[nestcount]) {
|
||||||
error("#endif without corresponding #if");
|
error("#endif without corresponding #if");
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,9 @@ do_option(text)
|
||||||
default:
|
default:
|
||||||
error("illegal option: %c", text[-1]);
|
error("illegal option: %c", text[-1]);
|
||||||
break;
|
break;
|
||||||
|
case 'o': /* ignore garbage after #else or #endif */
|
||||||
|
options['o'] = 1;
|
||||||
|
break;
|
||||||
case 'C' : /* comment output */
|
case 'C' : /* comment output */
|
||||||
options['C'] = 1;
|
options['C'] = 1;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -205,12 +205,16 @@ preprocess(fn)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case STNUM:
|
case STNUM:
|
||||||
|
/* The following code is quit ugly. This because
|
||||||
|
* ..3 == . .3 , whereas ...3 == ... 3
|
||||||
|
*/
|
||||||
echo(c);
|
echo(c);
|
||||||
if (c == '.') {
|
if (c == '.') {
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
if (c == '.') {
|
if (c == '.') {
|
||||||
if ((c = GetChar()) == '.') {
|
if ((c = GetChar()) == '.') {
|
||||||
echo('.'); echo('.');
|
echo('.'); echo('.');
|
||||||
|
c = GetChar();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
UnGetChar();
|
UnGetChar();
|
||||||
|
|
|
@ -532,7 +532,7 @@ macro2buffer(repl, idf, args)
|
||||||
replacement list.
|
replacement list.
|
||||||
*/
|
*/
|
||||||
if (repl->r_ptr == repl->r_text
|
if (repl->r_ptr == repl->r_text
|
||||||
&& is_wsp(*repl->r_text)) {
|
&& is_wsp(*repl->r_ptr)) {
|
||||||
err = 1;
|
err = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -590,7 +590,7 @@ macro2buffer(repl, idf, args)
|
||||||
assert(n > 0);
|
assert(n > 0);
|
||||||
|
|
||||||
/* This is VERY dirty, we look ahead for the
|
/* This is VERY dirty, we look ahead for the
|
||||||
## operater. If it's found we use the raw
|
## operator. If it's found we use the raw
|
||||||
argument buffer instead of the expanded
|
argument buffer instead of the expanded
|
||||||
one.
|
one.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue