Skip to content

Commit

Permalink
Support nested response files.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
zturnerbx committed Jan 27, 2025
1 parent 888d9ab commit 963495e
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions asm/nasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 963495e

Please sign in to comment.