From 963495e14603177d453f3ec55284218c1c19e883 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Sun, 26 Jan 2025 17:00:29 -0800 Subject: [PATCH] Support nested response files. This allows response files specified with -@ to reference other response files. This keeps parity with many other common toolchains such as MSVC, GCC, and Clang which all support nested response files. Signed-off-by: Zachary Turner --- asm/nasm.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/asm/nasm.c b/asm/nasm.c index 4d30e457..fec47462 100644 --- a/asm/nasm.c +++ b/asm/nasm.c @@ -72,6 +72,7 @@ struct forwrefinfo { /* info held on forward refs. */ const char *_progname; +static void open_and_process_respfile(char *, int); static void parse_cmdline(int, char **, int); static void assemble_file(const char *, struct strlist *); static bool skip_this_pass(errflags severity); @@ -1000,13 +1001,16 @@ static bool process_arg(char *p, char *q, int pass) return false; if (p[0] == '-' && !stopoptions) { - if (strchr("oOfpPdDiIlLFXuUZwW", p[1])) { + if (strchr("oOfpPdDiIlLFXuUZwW@", p[1])) { /* These parameters take values */ if (!(param = get_param(p, q, &advance))) return advance; } switch (p[1]) { + case '@': + open_and_process_respfile(param, pass); + break; case 's': if (pass == 1) error_file = stdout; @@ -1480,10 +1484,22 @@ static void process_response_file(const char *file, int pass) fclose(f); } -static void parse_cmdline(int argc, char **argv, int pass) +static void open_and_process_respfile(char *respfile, int pass) { FILE *rfile; - char *envreal, *envcopy = NULL, *p; + + rfile = nasm_open_read(respfile, NF_TEXT); + if (rfile) { + process_respfile(rfile, pass); + fclose(rfile); + } else { + nasm_nonfatalf(ERR_USAGE, "unable to open response file `%s'", respfile); + } +} + +static void parse_cmdline(int argc, char **argv, int pass) +{ + char *envreal, *envcopy = NULL; /* * Initialize all the warnings to their default state, including @@ -1519,19 +1535,8 @@ static void parse_cmdline(int argc, char **argv, int pass) argc--; argv++; } - if (!stopoptions && argv[0][0] == '-' && argv[0][1] == '@') { - p = get_param(argv[0], argc > 1 ? argv[1] : NULL, &advance); - if (p) { - rfile = nasm_open_read(p, NF_TEXT); - if (rfile) { - process_respfile(rfile, pass); - fclose(rfile); - } else { - nasm_nonfatalf(ERR_USAGE, "unable to open response file `%s'", p); - } - } - } else - advance = process_arg(argv[0], argc > 1 ? argv[1] : NULL, pass); + + advance = process_arg(argv[0], argc > 1 ? argv[1] : NULL, pass); argv += advance, argc -= advance; }