Mercurial > hg > index.cgi
diff lwcc/cpp-main.c @ 306:b08787e5b9f3 ccdev
Add include search paths and command line macro definitions
Added command line macro definitions. Also implemented include paths. There
is no default include path; that will be supplied by the driver program.
author | William Astle <lost@l-w.ca> |
---|---|
date | Wed, 18 Sep 2013 20:41:41 -0600 |
parents | 54f213c8fb81 |
children | 9e342c4e4b66 |
line wrap: on
line diff
--- a/lwcc/cpp-main.c Wed Sep 18 19:17:52 2013 -0600 +++ b/lwcc/cpp-main.c Wed Sep 18 20:41:41 2013 -0600 @@ -40,6 +40,9 @@ /* input files */ lw_stringlist_t input_files; +lw_stringlist_t includedirs; +lw_stringlist_t sysincludedirs; +lw_stringlist_t macrolist; /* various flags */ int trigraphs = 0; @@ -70,6 +73,18 @@ case 0x100: trigraphs = 1; break; + + case 'I': + lw_stringlist_addstring(includedirs, arg); + break; + + case 'S': + lw_stringlist_addstring(sysincludedirs, arg); + break; + + case 'D': + lw_stringlist_addstring(macrolist, arg); + break; case lw_cmdline_key_end: break; @@ -99,7 +114,10 @@ int retval = 0; input_files = lw_stringlist_create(); - + includedirs = lw_stringlist_create(); + sysincludedirs = lw_stringlist_create(); + macrolist = lw_stringlist_create(); + /* parse command line arguments */ lw_cmdline_parse(&cmdline_parser, argc, argv, 0, 0, NULL); @@ -134,7 +152,9 @@ } } lw_stringlist_destroy(input_files); - + lw_stringlist_destroy(includedirs); + lw_stringlist_destroy(sysincludedirs); + lw_stringlist_destroy(macrolist); exit(retval); } @@ -162,11 +182,32 @@ struct token *tok = NULL; int last_line = 0; char *last_fn = NULL; + char *tstr; pp = preproc_init(fn); if (!pp) return -1; + /* set up the include paths */ + lw_stringlist_reset(includedirs); + for (tstr = lw_stringlist_current(includedirs); tstr; tstr = lw_stringlist_next(includedirs)) + { + preproc_add_include(pp, tstr, 0); + } + + lw_stringlist_reset(sysincludedirs); + for (tstr = lw_stringlist_current(sysincludedirs); tstr; tstr = lw_stringlist_next(sysincludedirs)) + { + preproc_add_include(pp, tstr, 1); + } + + /* set up pre-defined macros */ + lw_stringlist_reset(macrolist); + for (tstr = lw_stringlist_current(macrolist); tstr; tstr = lw_stringlist_next(macrolist)) + { + preproc_add_macro(pp, tstr); + } + print_line_marker(output_fp, 1, fn, 1); last_fn = lw_strdup(fn); for (;;)