aboutsummaryrefslogtreecommitdiff
path: root/libtcc.c
diff options
context:
space:
mode:
authorgrischka <grischka>2016-10-01 20:04:58 +0200
committergrischka <grischka>2016-10-01 20:04:58 +0200
commit09a487eb2b2bcabeaeec8d2c7ca422993df0efb5 (patch)
treeb164eb23745cf39999d7d3e2bf1691a05931977f /libtcc.c
parente63011377173062d688a08e8a98abbdada453302 (diff)
downloadtinycc-09a487eb2b2bcabeaeec8d2c7ca422993df0efb5.tar.gz
tinycc-09a487eb2b2bcabeaeec8d2c7ca422993df0efb5.tar.bz2
libtcc: cleanup -x<filetype> switch code
Abusing filename[0] as type is just too much of a hack. -- From 05364072042ff37904a7b0b14cdd85a1ea1ca11d
Diffstat (limited to 'libtcc.c')
-rw-r--r--libtcc.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/libtcc.c b/libtcc.c
index 5467298..ee149aa 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -1304,7 +1304,8 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags,
parse_flags = 0;
#ifdef CONFIG_TCC_ASM
/* if .S file, define __ASSEMBLER__ like gcc does */
- if ((filetype == TCC_FILETYPE_ASM) || (filetype == TCC_FILETYPE_ASM_PP)) {
+ if (filetype == TCC_FILETYPE_ASM
+ || filetype == TCC_FILETYPE_ASM_PP) {
tcc_define_symbol(s1, "__ASSEMBLER__", NULL);
parse_flags = PARSE_FLAG_ASM_FILE;
}
@@ -2048,33 +2049,29 @@ static void parse_option_D(TCCState *s1, const char *optarg)
static void args_parser_add_file(TCCState *s, const char* filename, int filetype)
{
- int len = strlen(filename);
- char *p = tcc_malloc(len + 2);
- if (filetype) {
- *p = filetype;
- }
- else {
+ struct filespec *f = tcc_malloc(sizeof *f + strlen(filename));
+
+ if (filetype == 0) {
/* use a file extension to detect a filetype */
const char *ext = tcc_fileextension(filename);
if (ext[0]) {
ext++;
if (!strcmp(ext, "S"))
- *p = TCC_FILETYPE_ASM_PP;
- else
- if (!strcmp(ext, "s"))
- *p = TCC_FILETYPE_ASM;
+ filetype = TCC_FILETYPE_ASM_PP;
+ else if (!strcmp(ext, "s"))
+ filetype = TCC_FILETYPE_ASM;
+ else if (!PATHCMP(ext, "c") || !PATHCMP(ext, "i"))
+ filetype = TCC_FILETYPE_C;
else
- if (!PATHCMP(ext, "c") || !PATHCMP(ext, "i"))
- *p = TCC_FILETYPE_C;
- else
- *p = TCC_FILETYPE_BINARY;
- }
- else {
- *p = TCC_FILETYPE_C;
+ filetype = TCC_FILETYPE_BINARY;
+ } else {
+ filetype = TCC_FILETYPE_C;
}
}
- strcpy(p+1, filename);
- dynarray_add((void ***)&s->files, &s->nb_files, p);
+
+ f->type = filetype;
+ strcpy(f->name, filename);
+ dynarray_add((void ***)&s->files, &s->nb_files, f);
}
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)
tcc_set_lib_path(s, optarg);
break;
case TCC_OPTION_l:
- args_parser_add_file(s, r, TCC_FILETYPE_BINARY);
+ args_parser_add_file(s, optarg, 'l');
s->nb_libraries++;
break;
case TCC_OPTION_pthread: