diff mc-macro.c @ 609:af6b9ae79583 udpcl

modificatioon for udpcl
author kono
date Thu, 16 Mar 2006 17:03:24 +0900
parents e055df7c1082
children e4e007f4026d
line wrap: on
line diff
--- a/mc-macro.c	Sat Feb 18 21:33:43 2006 +0900
+++ b/mc-macro.c	Thu Mar 16 17:03:24 2006 +0900
@@ -312,6 +312,7 @@
     int i;
     int c;
     char num[10];
+    char *p;
 
     if (next_eof) {
 	next_eof=0;
@@ -335,6 +336,16 @@
 	    i=0;
 	    while ((*chptr++ = c = getc(filep->fcb)) != '\n') {
 		if (++i > LBUFSIZE-2) error(LNERR);
+		if (c=='\r') {
+		    c = getc(filep->fcb);
+		    if (c == '\n') {
+			chptr[-1]='\n'; break;
+		    } else {
+			// single cr equal to nl
+			ungetc(c,filep->fcb);
+			chptr[-1]=c='\n'; i--; break;
+		    }
+		}
 		if (c==EOF) {
 		    next_eof=1;
 		    --chptr;
@@ -349,7 +360,6 @@
 		// inline mode 
 		int i=0;
 		int c;
-		char *p;
 		// should be done in some init
 		if (!st_cheap) {
 		    st_cheap = cheap1 = new_cheap();
@@ -377,7 +387,9 @@
 		}
 	    }
 	}
-	if (*(chptr = linebuf) == '#' && !in_comment && !in_quote) {
+	p = chptr = linebuf; while(*p==' '||*p=='\t') p++;
+	if (*p == '#' && !in_comment && !in_quote) {
+	    chptr = p;
 	    if (macro_processing()) return;
 	}
     } while(!in_quote && (macro_if_skip || linebuf[0] == '#'));
@@ -549,10 +561,16 @@
 	    return 0;
 	}
 	break;
+    case 'p':
+	if (macroeq("pragma")) {
+	    getline();
+	    return 0;
+	}
+	break;
 #if ASM_CODE
     // deprecated, use asm function
     case 'a':
-	if (c=='a'&&macroeq("asm")) {
+	if (macroeq("asm")) {
 	    if (asmf) error(MCERR);
 	    asmf = 1;
 	    getline();
@@ -571,7 +589,7 @@
 	}
 	break;
 #endif
-    case ' ': case '\t':
+    case ' ': case '\t': case '\n': case 0:
 	getline();
 	return 0;
     }
@@ -925,12 +943,12 @@
     *result = cheap->ptr;
     for(;lists;lists = cadr(lists)) {
         p = (char *)car(lists);
-        for(;(*cheap->ptr=*p++);cheap = increment_cheap(cheap,0)) {
+        for(;(*cheap->ptr = *p++);cheap = increment_cheap(cheap,result)) {
 	    // in_quote + \n case ? should be \n.
 	    if (p[-1]=='\n') cheap->ptr[0]=' ';
 	}
     }
-    cheap = increment_cheap(cheap,0);
+    cheap = increment_cheap(cheap,result);
     return *result;
 }
 
@@ -942,12 +960,12 @@
     *result = cheap->ptr;
     for(;lists;lists = cadr(lists)) {
         p = (char *)car(lists);
-        for(;(*cheap->ptr=*p++);cheap = increment_cheap(cheap,0)) {
+        for(;(*cheap->ptr=*p++);cheap = increment_cheap(cheap,result)) {
 	    // in_quote + \n case ? should be \n.
 	    // if (p[-1]=='\n') cheap->ptr[0]=' ';
 	}
     }
-    cheap = increment_cheap(cheap,0);
+    cheap = increment_cheap(cheap,result);
     return *result;
 }