diff options
author | H. Peter Anvin <hpa@zytor.com> | 2019-08-10 05:31:51 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2019-08-10 05:31:51 -0700 |
commit | 3f51082bcdfe31e625bf857cdeb953d69c639b62 (patch) | |
tree | c94f402739da32ccdd57998ffee9e74e77e2adb4 /asm | |
parent | a2c1c7d0d4581e3ae58effff449d6fedec06aaae (diff) | |
download | nasm-3f51082bcdfe31e625bf857cdeb953d69c639b62.tar.gz |
listing: clean up before a restart
With the -Lp option, the listing generator gets invoked multiple times
in the same session. If we already have a list file open, call
list_cleanup() before reinitializing; otherwise we get stray output in
the updated file.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'asm')
-rw-r--r-- | asm/listing.c | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/asm/listing.c b/asm/listing.c index f1215660..1104d8ea 100644 --- a/asm/listing.c +++ b/asm/listing.c @@ -71,8 +71,6 @@ static int32_t listoffset; static int32_t listlineno; -static int32_t listp; - static int suppress; /* for INCBIN & TIMES special cases */ static int listlevel, listlevel_e; @@ -130,8 +128,27 @@ static void list_emit(void) } } +static void list_cleanup(void) +{ + if (!listfp) + return; + + while (mistack) { + MacroInhibit *temp = mistack; + mistack = temp->next; + nasm_free(temp); + } + + list_emit(); + fclose(listfp); + listfp = NULL; +} + static void list_init(const char *fname) { + if (listfp) + list_cleanup(); + if (!fname || fname[0] == '\0') { listfp = NULL; return; @@ -146,30 +163,14 @@ static void list_init(const char *fname) *listline = '\0'; listlineno = 0; list_errors = NULL; - listp = true; listlevel = 0; suppress = 0; - mistack = nasm_malloc(sizeof(MacroInhibit)); + nasm_new(mistack); mistack->next = NULL; mistack->level = 0; mistack->inhibiting = true; } -static void list_cleanup(void) -{ - if (!listp) - return; - - while (mistack) { - MacroInhibit *temp = mistack; - mistack = temp->next; - nasm_free(temp); - } - - list_emit(); - fclose(listfp); -} - static void list_out(int64_t offset, char *str) { if (strlen(listdata) + strlen(str) > LIST_HEXBIT) { @@ -222,7 +223,7 @@ static void list_output(const struct out_data *data) const uint8_t *p = data->data; - if (!listp || suppress || user_nolist) + if (!listfp || suppress || user_nolist) return; switch (data->type) { @@ -279,7 +280,7 @@ static void list_output(const struct out_data *data) static void list_line(int type, int32_t lineno, const char *line) { - if (!listp) + if (!listfp) return; if (user_nolist) @@ -314,7 +315,7 @@ static void mistack_push(bool inhibiting) static void list_uplevel(int type, int64_t size) { - if (!listp) + if (!listfp) return; switch (type) { @@ -347,7 +348,7 @@ static void list_uplevel(int type, int64_t size) static void list_downlevel(int type) { - if (!listp) + if (!listfp) return; switch (type) { |