Mercurial > ~dholland > hg > tradcpp > index.cgi
diff main.c @ 11:b9d50e786322
simplify places
author | David A. Holland |
---|---|
date | Sun, 19 Dec 2010 19:30:24 -0500 |
parents | 800f3a560a3b |
children | 5045b9678bb0 |
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;