History

libtcc: cleanup -x<filetype> switch code

Abusing filename[0] as type is just too much of a hack. -- From 05364072042ff37904a7b0b14cdd85a1ea1ca11d

grischka committed 10 years ago

Commit 09a487e1 parent e6301134 files · +34 −39Browse files

Showing the changes to libtcc.c (1 of 4 files). Show all

Unified · Split

libtcc.c+18−21
@@ -1304,7 +1304,8 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags, · 1303 unmodified lines
13041304 parse_flags = 0;
13051305 #ifdef CONFIG_TCC_ASM
13061306 /* 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) {
13081309 tcc_define_symbol(s1, "__ASSEMBLER__", NULL);
13091310 parse_flags = PARSE_FLAG_ASM_FILE;
13101311 }
@@ -2048,33 +2049,29 @@ static void parse_option_D(TCCState *s1, const char *optarg) · 737 unmodified lines
20482049
20492050 static void args_parser_add_file(TCCState *s, const char* filename, int filetype)
20502051 {
2051− int len = strlen(filename);
2052− char *p = tcc_malloc(len + 2);
2053− if (filetype) {
2054− *p = filetype;
2055− }
2056− else {
2052+ struct filespec *f = tcc_malloc(sizeof *f + strlen(filename));
2053+
2054+ if (filetype == 0) {
20572055 /* use a file extension to detect a filetype */
20582056 const char *ext = tcc_fileextension(filename);
20592057 if (ext[0]) {
20602058 ext++;
20612059 if (!strcmp(ext, "S"))
2062− *p = TCC_FILETYPE_ASM_PP;
2063− else
2064− if (!strcmp(ext, "s"))
2065− *p = TCC_FILETYPE_ASM;
2060+ filetype = TCC_FILETYPE_ASM_PP;
2061+ else if (!strcmp(ext, "s"))
2062+ filetype = TCC_FILETYPE_ASM;
2063+ else if (!PATHCMP(ext, "c") || !PATHCMP(ext, "i"))
2064+ filetype = TCC_FILETYPE_C;
20662065 else
2067− if (!PATHCMP(ext, "c") || !PATHCMP(ext, "i"))
2068− *p = TCC_FILETYPE_C;
2069− else
2070− *p = TCC_FILETYPE_BINARY;
2071− }
2072− else {
2073− *p = TCC_FILETYPE_C;
2066+ filetype = TCC_FILETYPE_BINARY;
2067+ } else {
2068+ filetype = TCC_FILETYPE_C;
20742069 }
20752070 }
2076− strcpy(p+1, filename);
2077− dynarray_add((void ***)&s->files, &s->nb_files, p);
2071+
2072+ f->type = filetype;
2073+ strcpy(f->name, filename);
2074+ dynarray_add((void ***)&s->files, &s->nb_files, f);
20782075 }
20792076
20802077 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
21582155 tcc_set_lib_path(s, optarg);
21592156 break;
21602157 case TCC_OPTION_l:
2161− args_parser_add_file(s, r, TCC_FILETYPE_BINARY);
2158+ args_parser_add_file(s, optarg, 'l');
21622159 s->nb_libraries++;
21632160 break;
21642161 case TCC_OPTION_pthread:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t