comparison lwasm/input.c @ 73:1f77ae5c3590

Added --dependnoerr flag to list dependencies on non-existent files without bailing out; also suppress error reports during dependency generation
author lost@l-w.ca
date Tue, 12 Apr 2011 17:56:51 -0600
parents 127e5b1e01c0
children e95eaf2f7fe0
comparison
equal deleted inserted replaced
72:84eb35251849 73:1f77ae5c3590
37 #include "lwasm.h" 37 #include "lwasm.h"
38 38
39 /* 39 /*
40 Data type for storing input buffers 40 Data type for storing input buffers
41 */ 41 */
42
43 #define IGNOREERROR (errno == ENOENT && (as -> flags & FLAG_DEPENDNOERR))
42 44
43 enum input_types_e 45 enum input_types_e
44 { 46 {
45 input_type_file, // regular file, no search path 47 input_type_file, // regular file, no search path
46 input_type_include, // include path, start from "local" 48 input_type_include, // include path, start from "local"
177 if (*s == '/') 179 if (*s == '/')
178 { 180 {
179 /* absolute path */ 181 /* absolute path */
180 IS -> data = fopen(s, "rb"); 182 IS -> data = fopen(s, "rb");
181 debug_message(as, 1, "Opening (abs) %s", s); 183 debug_message(as, 1, "Opening (abs) %s", s);
182 if (!IS -> data) 184 if (!IS -> data && !IGNOREERROR)
183 { 185 {
184 lw_error("Cannot open file '%s': %s", s, strerror(errno)); 186 lw_error("Cannot open file '%s': %s", s, strerror(errno));
185 } 187 }
186 input_pushpath(as, s); 188 input_pushpath(as, s);
187 return; 189 return;
215 return; 217 return;
216 } 218 }
217 debug_message(as, 2, "Failed to open: (sp) %s (%s)\n", p2, strerror(errno)); 219 debug_message(as, 2, "Failed to open: (sp) %s (%s)\n", p2, strerror(errno));
218 lw_free(p2); 220 lw_free(p2);
219 lw_stringlist_next(as -> include_list); 221 lw_stringlist_next(as -> include_list);
222 }
223 if (IGNOREERROR)
224 {
225 input_pushpath(as, s);
226 return;
220 } 227 }
221 lw_error("Cannot open include file '%s': %s", s, strerror(errno)); 228 lw_error("Cannot open include file '%s': %s", s, strerror(errno));
222 break; 229 break;
223 230
224 case input_type_file: 231 case input_type_file:
310 /* read from a file */ 317 /* read from a file */
311 lbloc = 0; 318 lbloc = 0;
312 for (;;) 319 for (;;)
313 { 320 {
314 int c, c2; 321 int c, c2;
315 c = fgetc(IS -> data); 322 c = EOF;
323 if (IS -> data)
324 c = fgetc(IS -> data);
316 if (c == EOF) 325 if (c == EOF)
317 { 326 {
318 if (lbloc == 0) 327 if (lbloc == 0)
319 { 328 {
320 struct input_stack *t; 329 struct input_stack *t;
321 fclose(IS -> data); 330 if (IS -> data)
331 fclose(IS -> data);
322 lw_free(lw_stack_pop(as -> file_dir)); 332 lw_free(lw_stack_pop(as -> file_dir));
323 lw_free(IS -> filespec); 333 lw_free(IS -> filespec);
324 t = IS -> next; 334 t = IS -> next;
325 lw_free(IS); 335 lw_free(IS);
326 as -> input_data = t; 336 as -> input_data = t;