9
9
#include " odin_util.h"
10
10
#include < stdbool.h>
11
11
#include < regex>
12
+ #include < string>
12
13
13
14
#include " odin_buffer.hpp"
14
15
@@ -75,7 +76,6 @@ void push(veri_flag_stack *stack, int flag);
75
76
76
77
/* General Utility methods ------------------------------------------------- */
77
78
static char * get_line (FILE *source, bool *eof, bool *multiline_comment, const char *one_line_comment, const char *n_line_comment_ST, const char *n_line_comment_END);
78
- FILE* open_source_file (char * filename, std::string parent_path);
79
79
80
80
81
81
/* Globals */
@@ -322,39 +322,6 @@ int veri_is_defined(const char * symbol)
322
322
return -1 ;
323
323
}
324
324
325
- /*
326
- * Return an open file handle
327
- * if the file is not in the pwd try the paths indicated by char* list_of_file_names int current_parse_file
328
- *
329
- * Return NULL if unable to find and open the file
330
- */
331
- FILE* open_source_file (char * filename, std::string path)
332
- {
333
- auto loc = path.find_last_of (' /' );
334
- if (loc != std::string::npos) /* No other path to try to find the file */
335
- path = path.substr (0 ,loc+1 );
336
-
337
- path += filename;
338
-
339
- // look in the directory where the file with the include directory resides in
340
- FILE* src_file = fopen (path.c_str (), " r" );
341
- if (src_file != NULL )
342
- return src_file;
343
-
344
- // else Look for the file in the PWD as a last resort TODO: this should go away... not standard behavior
345
- src_file = fopen (filename, " r" );
346
- if (src_file != NULL )
347
- {
348
- fprintf (stderr, " Warning: Unable to find %s, opening in current working directory instead\n " ,
349
- path.c_str ());
350
- return src_file;
351
- }
352
-
353
-
354
-
355
- return NULL ;
356
- }
357
-
358
325
/*
359
326
* Bootstraps our preprocessor
360
327
*/
@@ -511,7 +478,22 @@ void veri_preproc_bootstraped(FILE *original_source, FILE *preproc_producer, ver
511
478
*/
512
479
513
480
token = strtok (NULL , " \" " );
514
- FILE *included_file = open_source_file (token,current_include->path );
481
+
482
+ std::string current_path = current_include->path ;
483
+ auto loc = current_path.find_last_of (' /' );
484
+ if (loc != std::string::npos) /* No other path to try to find the file */
485
+ {
486
+ current_path = current_path.substr (0 ,loc+1 );
487
+ }
488
+ else
489
+ {
490
+ current_path = " " ;
491
+ }
492
+
493
+ std::string file_path = current_path + token;
494
+
495
+ FILE* included_file = fopen (file_path.c_str (), " r" );
496
+
515
497
516
498
/* If we failed to open the included file handle the error */
517
499
if (!included_file)
@@ -521,7 +503,7 @@ void veri_preproc_bootstraped(FILE *original_source, FILE *preproc_producer, ver
521
503
perror (" included_file : fopen" );
522
504
/* return erro or exit ? */
523
505
}
524
- else if (NULL != (new_include = add_veri_include (token , line_number, current_include)))
506
+ else if (NULL != (new_include = add_veri_include (file_path. c_str () , line_number, current_include)))
525
507
{
526
508
printf (" Including file %s\n " , new_include->path );
527
509
veri_preproc_bootstraped (included_file, preproc_producer, new_include);
0 commit comments