mirror of
https://github.com/frida/tinycc
synced 2025-03-13 11:12:57 +03:00
Simplify @listfiles parsing
This moves listfiles parsing inline in `tcc_parse_args1`
This commit is contained in:
parent
b3782c3cf5
commit
cb5f6b063b
56
libtcc.c
56
libtcc.c
@ -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);
|
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)
|
ST_FUNC int tcc_parse_args1(TCCState *s, int argc, char **argv)
|
||||||
{
|
{
|
||||||
const TCCOption *popt;
|
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') {
|
if (r[0] != '-' || r[1] == '\0') {
|
||||||
/* handle list files */
|
/* handle list files */
|
||||||
if (r[0] == '@' && r[1]) {
|
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 {
|
} else {
|
||||||
args_parser_add_file(s, r, pas->filetype);
|
args_parser_add_file(s, r, pas->filetype);
|
||||||
if (pas->run) {
|
if (pas->run) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user