Ver código fonte

fixed bug, added -o option

eck 35 anos atrás
pai
commit
bac0ae9da3

+ 1 - 1
lang/cem/cpp.ansi/Makefile

@@ -77,7 +77,7 @@ GENERATED = tokenfile.g Lpars.h LLfiles LL.output lint.out \
 all:	cc
 
 cc:	hfiles LLfiles
-	make "EMHOME="$(EMHOME) ncpp
+	make "EMHOME="$(EMHOME) "CC="$(CC) ncpp
 
 hfiles: Parameters char.c
 	./make.hfiles Parameters

+ 17 - 8
lang/cem/cpp.ansi/domacro.c

@@ -23,6 +23,7 @@
 #include	"macro.h"
 #include	"bits.h"
 
+extern char options[];
 extern	char **inctable;	/* list of include directories		*/
 extern	char *getwdir();
 char ifstack[IFDEPTH];	/* if-stack: the content of an entry is	*/
@@ -225,8 +226,10 @@ int to_endif;
 				error("#else after #else");
 			++(ifstack[nestlevel]);
 			if (!to_endif && nestlevel == skiplevel) {
-				if (SkipToNewLine(1))
-					strict("garbage following #else");
+				if (SkipToNewLine(1)) {
+					if (!options['o'])
+						strict("garbage following #else");
+				}
 				NoUnstack--;
 				return;
 			}
@@ -235,8 +238,10 @@ int to_endif;
 		case K_ENDIF:
 			assert(nestlevel > svnestlevel[nestcount]);
 			if (nestlevel == skiplevel) {
-				if (SkipToNewLine(1))
-					strict("garbage following #endif");
+				if (SkipToNewLine(1)) {
+					if (!options['o'])
+						strict("garbage following #endif");
+				}
 				nestlevel--;
 				NoUnstack--;
 				return;
@@ -377,8 +382,10 @@ do_elif()
 
 do_else()
 {
-	if (SkipToNewLine(1))
-		strict("garbage following #else");
+	if (SkipToNewLine(1)) {
+		if (!options['o'])
+			strict("garbage following #else");
+	}
 	if (nestlevel <= svnestlevel[nestcount])
 		error("#else without corresponding #if");
 	else {	/* mark this level as else-d */
@@ -392,8 +399,10 @@ do_else()
 
 do_endif()
 {
-	if (SkipToNewLine(1))
-		strict("garbage following #endif");
+	if (SkipToNewLine(1)) {
+		if (!options['o'])
+			strict("garbage following #endif");
+	}
 	if (nestlevel <= svnestlevel[nestcount])	{
 		error("#endif without corresponding #if");
 	}

+ 3 - 0
lang/cem/cpp.ansi/options.c

@@ -31,6 +31,9 @@ do_option(text)
 	default:
 		error("illegal option: %c", text[-1]);
 		break;
+	case 'o':	/* ignore garbage after #else or #endif */
+		options['o'] = 1;
+		break;
 	case 'C' :	/* comment output		*/
 		options['C'] = 1;
 		break;

+ 4 - 0
lang/cem/cpp.ansi/preprocess.c

@@ -205,12 +205,16 @@ preprocess(fn)
 				continue;
 				}
 			case STNUM:
+			/* The following code is quit ugly. This because
+			 * ..3 == . .3 , whereas ...3 == ... 3
+			 */
 				echo(c);
 				if (c == '.') {
 					c = GetChar();
 					if (c == '.') {
 						if ((c = GetChar()) == '.') {
 							echo('.'); echo('.');
+							c = GetChar();
 							continue;
 						}
 						UnGetChar();

+ 2 - 2
lang/cem/cpp.ansi/replace.c

@@ -532,7 +532,7 @@ macro2buffer(repl, idf, args)
 			    replacement list.
 		    */
 		    if (repl->r_ptr == repl->r_text
-				&& is_wsp(*repl->r_text)) {
+				&& is_wsp(*repl->r_ptr)) {
 			    err = 1;
 			    break;
 		    }
@@ -590,7 +590,7 @@ macro2buffer(repl, idf, args)
 		assert(n > 0);
 
 		/*	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
 			one.
 		*/