diff options
| author | Vlad Vissoultchev <wqweto@gmail.com> | 2016-04-12 20:43:15 +0300 |
|---|---|---|
| committer | Vlad Vissoultchev <wqweto@gmail.com> | 2016-04-13 11:35:24 +0300 |
| commit | cb5f6b063b2b75e29f91fc1a523372bf48ae8bff (patch) | |
| tree | eed1f9f140c9913a10e3f92c9b3a348b76e7d7e5 /libtcc.c | |
| parent | b3782c3cf5e66f74207303c381a305daabccdb12 (diff) | |
| download | tinycc-cb5f6b063b2b75e29f91fc1a523372bf48ae8bff.tar.gz tinycc-cb5f6b063b2b75e29f91fc1a523372bf48ae8bff.tar.bz2 | |
Simplify @listfiles parsing
This moves listfiles parsing inline in `tcc_parse_args1`
Diffstat (limited to 'libtcc.c')
| -rw-r--r-- | libtcc.c | 56 |
1 files changed, 17 insertions, 39 deletions
@@ -2081,44 +2081,6 @@ static void args_parser_add_file(TCCState *s, const char* filename, int filetype dynarray_add((void ***)&s->files, &s->nb_files, p); } -ST_FUNC int tcc_parse_args1(TCCState *s, int argc, char **argv); - -ST_FUNC void args_parser_trim_ws() -{ - for (; ch != CH_EOF; inp()) { - if (ch != '\n' && ch != '\r' && !is_space(ch)) - break; - } -} - -ST_FUNC void args_parser_add_listfile(TCCState *s, const char *filename) -{ - char buf[sizeof file->filename], *pb = buf; - char **argv = NULL; - int argc = 0; - - if (tcc_open(s, filename) < 0) - tcc_error("list file '%s' not found", filename); - - for (ch = handle_eob(), args_parser_trim_ws(); ; inp()) { - /* on new line or buffer overflow */ - if (ch == '\n' || ch == '\r' || ch == CH_EOF - || pb - buf >= sizeof(buf) - 1) { - if (pb > buf) { - *pb = 0, pb = buf; - dynarray_add((void ***)&argv, &argc, tcc_strdup(buf)); - args_parser_trim_ws(); - } - } - if (ch == CH_EOF) - break; - *pb++ = ch; - } - tcc_close(); - tcc_parse_args1(s, argc, argv); - dynarray_reset(&argv, &argc); -} - ST_FUNC int tcc_parse_args1(TCCState *s, int argc, char **argv) { const TCCOption *popt; @@ -2132,7 +2094,23 @@ ST_FUNC int tcc_parse_args1(TCCState *s, int argc, char **argv) if (r[0] != '-' || r[1] == '\0') { /* handle list files */ if (r[0] == '@' && r[1]) { - args_parser_add_listfile(s, r + 1); + char buf[sizeof file->filename], *p; + char **argv = NULL; + int argc = 0; + FILE *fp; + + fp = fopen(r + 1, "rb"); + if (fp == NULL) + tcc_error("list file '%s' not found", r + 1); + while (fgets(buf, sizeof buf, fp)) { + p = trimfront(trimback(buf, strchr(buf, 0))); + if (0 == *p || ';' == *p) + continue; + dynarray_add((void ***)&argv, &argc, tcc_strdup(p)); + } + fclose(fp); + tcc_parse_args1(s, argc, argv); + dynarray_reset(&argv, &argc); } else { args_parser_add_file(s, r, pas->filetype); if (pas->run) { |
