diff main.c @ 15:f6177d3ed5c2

handle directives
author David A. Holland
date Sun, 19 Dec 2010 21:42:01 -0500
parents 5045b9678bb0
children 76da41da923f
line wrap: on
line diff
--- a/main.c	Sun Dec 19 19:51:36 2010 -0500
+++ b/main.c	Sun Dec 19 21:42:01 2010 -0500
@@ -12,6 +12,7 @@
 #include "mode.h"
 #include "place.h"
 #include "files.h"
+#include "directive.h"
 #include "macro.h"
 
 struct mode mode = {
@@ -57,6 +58,7 @@
 
 struct commandline_macro {
 	struct place where;
+	struct place where2;
 	const char *macro;
 	const char *expansion;
 };
@@ -79,13 +81,14 @@
 
 static
 void
-commandline_macro_add(const struct place *p,
-		      const char *macro, const char *expansion)
+commandline_macro_add(const struct place *p, const char *macro,
+		      const struct place *p2, const char *expansion)
 {
 	struct commandline_macro *cm;
 
 	cm = domalloc(sizeof(*cm));
 	cm->where = *p;
+	cm->where2 = *p2;
 	cm->macro = macro;
 	cm->expansion = expansion;
 }
@@ -94,6 +97,7 @@
 void
 commandline_def(const struct place *p, char *str)
 {
+	struct place p2;
 	char *val;
 
 	val = strchr(str, '=');
@@ -101,14 +105,21 @@
 		*val = '\0';
 		val++;
 	}
-	commandline_macro_add(p, str, val ? val : "1");
+
+	if (val) {
+		p2 = *p;
+		p2.column += strlen(str);
+	} else {
+		place_setbuiltin(&p2, 1);
+	}
+	commandline_macro_add(p, str, &p2, val ? val : "1");
 }
 
 static
 void
 commandline_undef(const struct place *p, char *str)
 {
-	commandline_macro_add(p, str, NULL);
+	commandline_macro_add(p, str, p, NULL);
 }
 
 static
@@ -122,7 +133,8 @@
 	for (i=0; i<num; i++) {
 		cm = array_get(&commandline_macros, i);
 		if (cm->expansion != NULL) {
-			macro_define(&cm->where, cm->macro, cm->expansion);
+			macro_define(&cm->where, cm->macro,
+				     &cm->where2, cm->expansion);
 		} else {
 			macro_undef(cm->macro);
 		}
@@ -138,7 +150,7 @@
 	struct place p;
 
 	place_setbuiltin(&p, num);
-	macro_define(&p, name, val);
+	macro_define(&p, name, &p, val);
 }
 
 static
@@ -859,6 +871,7 @@
 
 	place_init();
 	files_init();
+	directive_init();
 }
 
 static
@@ -867,6 +880,7 @@
 {
 	unsigned i, num;
 
+	directive_cleanup();
 	files_cleanup();
 	place_cleanup();