diff directive.c @ 18:c08a947d8f30

deal with macro parameters
author David A. Holland
date Mon, 20 Dec 2010 01:51:47 -0500
parents 9dda765ee85c
children 76c114899f63
line wrap: on
line diff
--- a/directive.c	Mon Dec 20 01:15:43 2010 -0500
+++ b/directive.c	Mon Dec 20 01:51:47 2010 -0500
@@ -171,8 +171,8 @@
 void
 d_define(struct place *p, struct place *p2, char *line, size_t len)
 {
-	size_t pos;
-	struct place p3;
+	size_t pos, argpos;
+	struct place p3, p4;
 
 	/*
 	 * line may be:
@@ -182,7 +182,8 @@
 
 	pos = strcspn(line, " \t\f\v(");
 	if (line[pos] == '(') {
-		pos++;
+		line[pos++] = '\0';
+		argpos = pos;
 		pos = pos + strcspn(line+pos, "()");
 		if (line[pos] == '(') {
 			p2->column += pos;
@@ -196,25 +197,35 @@
 			complain_fail();
 			return;
 		}
-		pos++;
+		line[pos++] = '\0';
 		if (!strchr(ws, line[pos])) {
 			p2->column += pos;
 			complain(p2, "Trash after macro parameter list");
 			complain_fail();
 			return;
 		}
-		line[pos++] = '\0';
 	} else if (line[pos] == '\0') {
-		/* nothing */
+		argpos = 0;
 	} else {
 		line[pos++] = '\0';
+		argpos = 0;
 	}
 
 	pos += strspn(line+pos, ws);
 
 	p3 = *p2;
-	p3.column += pos;
-	macro_define(p2, line, &p3, line + pos);
+	p3.column += argpos;
+
+	p4 = *p2;
+	p4.column += pos;
+
+	if (argpos) {
+		macro_define_params(p2, line, &p3,
+				    line + argpos, &p4,
+				    line + pos);
+	} else {
+		macro_define_plain(p2, line, &p4, line + pos);
+	}
 }
 
 static
@@ -337,16 +348,6 @@
 static const unsigned numdirectives = HOWMANY(directives);
 
 static
-size_t
-notrailingws(char *buf, size_t len)
-{
-	while (len > 0 && strchr(ws, buf[len-1])) {
-		buf[--len] = '\0';
-	}
-	return len;
-}
-
-static
 void
 directive_gotdirective(struct place *p, char *line, size_t linelen)
 {