Abusing filename[0] as type is just too much of a hack. -- From 05364072042ff37904a7b0b14cdd85a1ea1ca11d
Showing the changes to libtcc.c (1 of 4 files). Show all
Unified · Split
| @@ -1304,7 +1304,8 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags, · 1303 unmodified lines | |||
| 1304 | parse_flags = 0; | 1304 | parse_flags = 0; |
| 1305 | #ifdef CONFIG_TCC_ASM | 1305 | #ifdef CONFIG_TCC_ASM |
| 1306 | /* if .S file, define __ASSEMBLER__ like gcc does */ | 1306 | /* if .S file, define __ASSEMBLER__ like gcc does */ |
| 1307 | if ((filetype == TCC_FILETYPE_ASM) || (filetype == TCC_FILETYPE_ASM_PP)) { | 1307 | if (filetype == TCC_FILETYPE_ASM |
| 1308 | || filetype == TCC_FILETYPE_ASM_PP) { | ||
| 1308 | tcc_define_symbol(s1, "__ASSEMBLER__", NULL); | 1309 | tcc_define_symbol(s1, "__ASSEMBLER__", NULL); |
| 1309 | parse_flags = PARSE_FLAG_ASM_FILE; | 1310 | parse_flags = PARSE_FLAG_ASM_FILE; |
| 1310 | } | 1311 | } |
| @@ -2048,33 +2049,29 @@ static void parse_option_D(TCCState *s1, const char *optarg) · 737 unmodified lines | |||
| 2048 | 2049 | ||
| 2049 | static void args_parser_add_file(TCCState *s, const char* filename, int filetype) | 2050 | static void args_parser_add_file(TCCState *s, const char* filename, int filetype) |
| 2050 | { | 2051 | { |
| 2051 | int len = strlen(filename); | 2052 | struct filespec *f = tcc_malloc(sizeof *f + strlen(filename)); |
| 2052 | char *p = tcc_malloc(len + 2); | 2053 | |
| 2053 | if (filetype) { | 2054 | if (filetype == 0) { |
| 2054 | *p = filetype; | ||
| 2055 | } | ||
| 2056 | else { | ||
| 2057 | /* use a file extension to detect a filetype */ | 2055 | /* use a file extension to detect a filetype */ |
| 2058 | const char *ext = tcc_fileextension(filename); | 2056 | const char *ext = tcc_fileextension(filename); |
| 2059 | if (ext[0]) { | 2057 | if (ext[0]) { |
| 2060 | ext++; | 2058 | ext++; |
| 2061 | if (!strcmp(ext, "S")) | 2059 | if (!strcmp(ext, "S")) |
| 2062 | *p = TCC_FILETYPE_ASM_PP; | 2060 | filetype = TCC_FILETYPE_ASM_PP; |
| 2063 | else | 2061 | else if (!strcmp(ext, "s")) |
| 2064 | if (!strcmp(ext, "s")) | 2062 | filetype = TCC_FILETYPE_ASM; |
| 2065 | *p = TCC_FILETYPE_ASM; | 2063 | else if (!PATHCMP(ext, "c") || !PATHCMP(ext, "i")) |
| 2064 | filetype = TCC_FILETYPE_C; | ||
| 2066 | else | 2065 | else |
| 2067 | if (!PATHCMP(ext, "c") || !PATHCMP(ext, "i")) | 2066 | filetype = TCC_FILETYPE_BINARY; |
| 2068 | *p = TCC_FILETYPE_C; | 2067 | } else { |
| 2069 | else | 2068 | filetype = TCC_FILETYPE_C; |
| 2070 | *p = TCC_FILETYPE_BINARY; | ||
| 2071 | } | ||
| 2072 | else { | ||
| 2073 | *p = TCC_FILETYPE_C; | ||
| 2074 | } | 2069 | } |
| 2075 | } | 2070 | } |
| 2076 | strcpy(p+1, filename); | 2071 | |
| 2077 | dynarray_add((void ***)&s->files, &s->nb_files, p); | 2072 | f->type = filetype; |
| 2073 | strcpy(f->name, filename); | ||
| 2074 | dynarray_add((void ***)&s->files, &s->nb_files, f); | ||
| 2078 | } | 2075 | } |
| 2079 | 2076 | ||
| 2080 | ST_FUNC int tcc_parse_args1(TCCState *s, int argc, char **argv) | 2077 | ST_FUNC int tcc_parse_args1(TCCState *s, int argc, char **argv) |
| @@ -2158,7 +2155,7 @@ ST_FUNC int tcc_parse_args1(TCCState *s, int argc, char **argv) · 77 unmodified lines | |||
| 2158 | tcc_set_lib_path(s, optarg); | 2155 | tcc_set_lib_path(s, optarg); |
| 2159 | break; | 2156 | break; |
| 2160 | case TCC_OPTION_l: | 2157 | case TCC_OPTION_l: |
| 2161 | args_parser_add_file(s, r, TCC_FILETYPE_BINARY); | 2158 | args_parser_add_file(s, optarg, 'l'); |
| 2162 | s->nb_libraries++; | 2159 | s->nb_libraries++; |
| 2163 | break; | 2160 | break; |
| 2164 | case TCC_OPTION_pthread: | 2161 | case TCC_OPTION_pthread: |