comparison 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
comparison
equal deleted inserted replaced
305:54f213c8fb81 306:b08787e5b9f3
38 #define PROGVER "lwcc-cpp from " PACKAGE_STRING 38 #define PROGVER "lwcc-cpp from " PACKAGE_STRING
39 char *program_name; 39 char *program_name;
40 40
41 /* input files */ 41 /* input files */
42 lw_stringlist_t input_files; 42 lw_stringlist_t input_files;
43 lw_stringlist_t includedirs;
44 lw_stringlist_t sysincludedirs;
45 lw_stringlist_t macrolist;
43 46
44 /* various flags */ 47 /* various flags */
45 int trigraphs = 0; 48 int trigraphs = 0;
46 char *output_file = NULL; 49 char *output_file = NULL;
47 FILE *output_fp = NULL; 50 FILE *output_fp = NULL;
68 break; 71 break;
69 72
70 case 0x100: 73 case 0x100:
71 trigraphs = 1; 74 trigraphs = 1;
72 break; 75 break;
76
77 case 'I':
78 lw_stringlist_addstring(includedirs, arg);
79 break;
80
81 case 'S':
82 lw_stringlist_addstring(sysincludedirs, arg);
83 break;
84
85 case 'D':
86 lw_stringlist_addstring(macrolist, arg);
87 break;
73 88
74 case lw_cmdline_key_end: 89 case lw_cmdline_key_end:
75 break; 90 break;
76 91
77 case lw_cmdline_key_arg: 92 case lw_cmdline_key_arg:
97 { 112 {
98 program_name = argv[0]; 113 program_name = argv[0];
99 int retval = 0; 114 int retval = 0;
100 115
101 input_files = lw_stringlist_create(); 116 input_files = lw_stringlist_create();
102 117 includedirs = lw_stringlist_create();
118 sysincludedirs = lw_stringlist_create();
119 macrolist = lw_stringlist_create();
120
103 /* parse command line arguments */ 121 /* parse command line arguments */
104 lw_cmdline_parse(&cmdline_parser, argc, argv, 0, 0, NULL); 122 lw_cmdline_parse(&cmdline_parser, argc, argv, 0, 0, NULL);
105 123
106 /* set up output file */ 124 /* set up output file */
107 if (output_file == NULL || strcmp(output_file, "-") == 0) 125 if (output_file == NULL || strcmp(output_file, "-") == 0)
132 if (retval != 0) 150 if (retval != 0)
133 break; 151 break;
134 } 152 }
135 } 153 }
136 lw_stringlist_destroy(input_files); 154 lw_stringlist_destroy(input_files);
137 155 lw_stringlist_destroy(includedirs);
156 lw_stringlist_destroy(sysincludedirs);
157 lw_stringlist_destroy(macrolist);
138 exit(retval); 158 exit(retval);
139 } 159 }
140 160
141 static void print_line_marker(FILE *fp, int line, const char *fn, int flag) 161 static void print_line_marker(FILE *fp, int line, const char *fn, int flag)
142 { 162 {
160 { 180 {
161 struct preproc_info *pp; 181 struct preproc_info *pp;
162 struct token *tok = NULL; 182 struct token *tok = NULL;
163 int last_line = 0; 183 int last_line = 0;
164 char *last_fn = NULL; 184 char *last_fn = NULL;
185 char *tstr;
165 186
166 pp = preproc_init(fn); 187 pp = preproc_init(fn);
167 if (!pp) 188 if (!pp)
168 return -1; 189 return -1;
190
191 /* set up the include paths */
192 lw_stringlist_reset(includedirs);
193 for (tstr = lw_stringlist_current(includedirs); tstr; tstr = lw_stringlist_next(includedirs))
194 {
195 preproc_add_include(pp, tstr, 0);
196 }
197
198 lw_stringlist_reset(sysincludedirs);
199 for (tstr = lw_stringlist_current(sysincludedirs); tstr; tstr = lw_stringlist_next(sysincludedirs))
200 {
201 preproc_add_include(pp, tstr, 1);
202 }
203
204 /* set up pre-defined macros */
205 lw_stringlist_reset(macrolist);
206 for (tstr = lw_stringlist_current(macrolist); tstr; tstr = lw_stringlist_next(macrolist))
207 {
208 preproc_add_macro(pp, tstr);
209 }
169 210
170 print_line_marker(output_fp, 1, fn, 1); 211 print_line_marker(output_fp, 1, fn, 1);
171 last_fn = lw_strdup(fn); 212 last_fn = lw_strdup(fn);
172 for (;;) 213 for (;;)
173 { 214 {