changeset 11:b9d50e786322

simplify places
author David A. Holland
date Sun, 19 Dec 2010 19:30:24 -0500
parents 800f3a560a3b
children 6c15ca895585
files main.c place.c place.h
diffstat 3 files changed, 19 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Sun Dec 19 19:27:14 2010 -0500
+++ b/main.c	Sun Dec 19 19:30:24 2010 -0500
@@ -56,7 +56,7 @@
 // commandline macros
 
 struct commandline_macro {
-	struct place *place;
+	struct place where;
 	const char *macro;
 	const char *expansion;
 };
@@ -85,7 +85,7 @@
 	struct commandline_macro *cm;
 
 	cm = domalloc(sizeof(*cm));
-	cm->place = place_clone(p);
+	cm->where = *p;
 	cm->macro = macro;
 	cm->expansion = expansion;
 }
@@ -122,11 +122,10 @@
 	for (i=0; i<num; i++) {
 		cm = array_get(&commandline_macros, i);
 		if (cm->expansion != NULL) {
-			macro_define(cm->place, cm->macro, cm->expansion);
+			macro_define(&cm->where, cm->macro, cm->expansion);
 		} else {
 			macro_undef(cm->macro);
 		}
-		place_destroy(cm->place);
 		free(cm);
 	}
 	array_setsize(&commandline_macros, 0);
@@ -136,12 +135,10 @@
 void
 apply_builtin_macro(unsigned num, const char *name, const char *val)
 {
-	struct place *p;
+	struct place p;
 
-	p = place_gettemporary();
-	place_setbuiltin(p, num);
-	macro_define(p, name, val);
-	place_puttemporary(p);
+	place_setbuiltin(&p, num);
+	macro_define(&p, name, val);
 }
 
 static
@@ -182,7 +179,7 @@
 // extra included files
 
 struct commandline_file {
-	struct place *place;
+	struct place where;
 	char *name;
 	bool suppress_output;
 };
@@ -210,7 +207,7 @@
 	struct commandline_file *cf;
 
 	cf = domalloc(sizeof(*cf));
-	cf->place = place_clone(p);
+	cf->where = *p;
 	cf->name = name;
 	cf->suppress_output = suppress_output;
 	array_add(&commandline_files, cf, NULL);
@@ -244,12 +241,11 @@
 		if (cf->suppress_output) {
 			save = mode.do_output;
 			mode.do_output = false;
-			file_readquote(cf->place, cf->name);
+			file_readquote(&cf->where, cf->name);
 			mode.do_output = save;
 		} else {
-			file_readquote(cf->place, cf->name);
+			file_readquote(&cf->where, cf->name);
 		}
-		place_destroy(cf->place);
 		free(cf);
 	}
 	array_setsize(&commandline_files, 0);
@@ -907,28 +903,27 @@
 {
 	const char *inputfile = NULL;
 	const char *outputfile = NULL;
-	struct place *p;
+	struct place cmdplace;
 	int i;
 
 	init();
-	p = place_gettemporary();
 
 	for (i=1; i<argc; i++) {
 		if (argv[i][0] != '-') {
 			break;
 		}
-		place_setcommandline(p, i);
+		place_setcommandline(&cmdplace, i);
 		if (check_flag_option(argv[i]+1)) {
 			continue;
 		}
 		if (check_act_option(argv[i]+1)) {
 			continue;
 		}
-		if (check_prefix_option(p, argv[i]+1)) {
+		if (check_prefix_option(&cmdplace, argv[i]+1)) {
 			continue;
 		}
-		place_setcommandline(p, i+1);
-		if (check_arg_option(argv[i]+1, p, argv[i+1])) {
+		place_setcommandline(&cmdplace, i+1);
+		if (check_arg_option(argv[i]+1, &cmdplace, argv[i+1])) {
 			i++;
 			continue;
 		}
@@ -950,10 +945,9 @@
 	apply_builtin_macros();
 	apply_commandline_macros();
 	read_commandline_files();
-	place_setnowhere(p);
-	file_readabsolute(p, inputfile);
+	place_setnowhere(&cmdplace);
+	file_readabsolute(&cmdplace, inputfile);
 
-	place_puttemporary(p);
 	cleanup();
 	if (complain_failed()) {
 		return EXIT_FAILURE;
--- a/place.c	Sun Dec 19 19:27:14 2010 -0500
+++ b/place.c	Sun Dec 19 19:30:24 2010 -0500
@@ -19,13 +19,9 @@
 DECLARRAY(seenfile);
 DEFARRAY(seenfile, );
 
+static struct seenfilearray seenfiles;
 static bool overall_failure;
 
-static struct place scratchplace;
-static bool scratchplace_inuse;
-
-static struct seenfilearray seenfiles;
-
 ////////////////////////////////////////////////////////////
 // seenfiles
 
@@ -86,48 +82,6 @@
 	return p->file == NULL && p->line == COMMANDLINE_LINE;
 }
 
-struct place *
-place_gettemporary(void)
-{
-	assert(!scratchplace_inuse);
-	scratchplace_inuse = true;
-	return &scratchplace;
-}
-
-void
-place_puttemporary(struct place *p)
-{
-	assert(scratchplace_inuse);
-	assert(p == &scratchplace);
-	scratchplace_inuse = false;
-}
-
-struct place *
-place_create(void)
-{
-	struct place *p;
-
-	p = domalloc(sizeof(*p));
-	place_setnowhere(p);
-	return p;
-}
-
-struct place *
-place_clone(const struct place *op)
-{
-	struct place *p;
-
-	p = domalloc(sizeof(*p));
-	*p = *op;
-	return p;
-}
-
-void
-place_destroy(struct place *p)
-{
-	free(p);
-}
-
 void
 place_setnowhere(struct place *p)
 {
--- a/place.h	Sun Dec 19 19:27:14 2010 -0500
+++ b/place.h	Sun Dec 19 19:30:24 2010 -0500
@@ -7,13 +7,8 @@
 void place_init(void);
 void place_cleanup(void);
 
-struct place *place_gettemporary(void);
-void place_puttemporary(struct place *p);
-struct place *place_create(void);
-struct place *place_clone(const struct place *p);
-void place_destroy(struct place *);
 void place_setnowhere(struct place *p);
 void place_setbuiltin(struct place *p, unsigned num);
-void place_setcommandline(struct place *p, unsigned column);
+void place_setcommandline(struct place *p, unsigned word);
 
 struct seenfile *place_seen_file(const struct place *p, char *name, bool fromsystemdir);