Like __FILE__ but always refers to the command line file name also from inside headers.
Unified · Split
| @@ -3465,6 +3465,7 @@ ST_INLN void unget_tok(int last_tok) · 3464 unmodified lines | ||
| 3465 | 3465 | |
| 3466 | 3466 | ST_FUNC void preprocess_start(TCCState *s1) |
| 3467 | 3467 | { |
| 3468 | + char *buf; | |
| 3468 | 3469 | s1->include_stack_ptr = s1->include_stack; |
| 3469 | 3470 | /* XXX: move that before to avoid having to initialize |
| 3470 | 3471 | file->ifdef_stack_ptr ? */ |
| @@ -3480,6 +3481,11 @@ ST_FUNC void preprocess_start(TCCState *s1) · 9 unmodified lines | ||
| 3480 | 3481 | s1->dollars_in_identifiers ? IS_ID : 0; |
| 3481 | 3482 | isidnum_table['.' - CH_EOF] = |
| 3482 | 3483 | (parse_flags & PARSE_FLAG_ASM_FILE) ? IS_ID : 0; |
| 3484 | + buf = tcc_malloc(3 + strlen(file->filename)); | |
| 3485 | + sprintf(buf, "\"%s\"", file->filename); | |
| 3486 | + tcc_undefine_symbol(s1, "__BASE_FILE__"); | |
| 3487 | + tcc_define_symbol(s1, "__BASE_FILE__", buf); | |
| 3488 | + tcc_free(buf); | |
| 3483 | 3489 | if (s1->nb_cmd_include_files) { |
| 3484 | 3490 | CString cstr; |
| 3485 | 3491 | int i; |
| @@ -59,6 +59,8 @@ · 58 unmodified lines | ||
| 59 | 59 | |
| 60 | 60 | #include "tcclib.h" |
| 61 | 61 | |
| 62 | +#include "tcctest.h" | |
| 63 | + | |
| 62 | 64 | void intdiv_test(); |
| 63 | 65 | void string_test(); |
| 64 | 66 | void expr_test(); |
| @@ -389,6 +391,11 @@ comment · 324 unmodified lines | ||
| 389 | 391 | /* And again when the name and parenthes are separated by a |
| 390 | 392 | comment. */ |
| 391 | 393 | TEST2 /* the comment */ (); |
| 394 | + | |
| 395 | + printf("%s\n", get_basefile_from_header()); | |
| 396 | + printf("%s\n", __BASE_FILE__); | |
| 397 | + printf("%s\n", get_file_from_header()); | |
| 398 | + printf("%s\n", __FILE__); | |
| 392 | 399 | } |
| 393 | 400 | |
| 394 | 401 | |
| @@ -0,0 +1,9 @@ | ||
| 1 | +static inline const char *get_basefile_from_header(void) | |
| 2 | +{ | |
| 3 | + return __BASE_FILE__; | |
| 4 | +} | |
| 5 | + | |
| 6 | +static inline const char *get_file_from_header(void) | |
| 7 | +{ | |
| 8 | + return __FILE__; | |
| 9 | +} | |