From eba20a73f2b3396f617747e789e35a679eb09606 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 30 Apr 2002 20:53:55 +0000 Subject: NASM 0.98p3 --- listing.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 22 deletions(-) (limited to 'listing.c') diff --git a/listing.c b/listing.c index 89b722a6..af8a9bf8 100644 --- a/listing.c +++ b/listing.c @@ -50,31 +50,39 @@ static int listlevel, listlevel_e; static FILE *listfp; -static void list_emit (void) { +static void list_emit (void) +{ if (!listlinep && !listdata[0]) return; + fprintf(listfp, "%6ld ", ++listlineno); + if (listdata[0]) fprintf(listfp, "%08lX %-*s", listoffset, LIST_HEXBIT+1, listdata); else fprintf(listfp, "%*s", LIST_HEXBIT+10, ""); + if (listlevel_e) fprintf(listfp, "%s<%d>", (listlevel < 10 ? " " : ""), listlevel_e); else if (listlinep) fprintf(listfp, " "); + if (listlinep) fprintf(listfp, " %s", listline); + fputc('\n', listfp); listlinep = FALSE; listdata[0] = '\0'; } -static void list_init (char *fname, efunc error) { +static void list_init (char *fname, efunc error) +{ listfp = fopen (fname, "w"); if (!listfp) { error (ERR_NONFATAL, "unable to open listing file `%s'", fname); return; } + *listline = '\0'; listlineno = 0; listp = TRUE; @@ -86,19 +94,23 @@ static void list_init (char *fname, efunc error) { mistack->inhibiting = TRUE; } -static void list_cleanup (void) { +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 (long offset, char *str) { +static void list_out (long offset, char *str) +{ if (strlen(listdata) + strlen(str) > LIST_HEXBIT) { strcat(listdata, "-"); list_emit(); @@ -108,7 +120,8 @@ static void list_out (long offset, char *str) { strcat(listdata, str); } -static void list_output (long offset, void *data, unsigned long type) { +static void list_output (long offset, void *data, unsigned long type) +{ long typ, size; if (!listp || suppress) @@ -117,20 +130,25 @@ static void list_output (long offset, void *data, unsigned long type) { typ = type & OUT_TYPMASK; size = type & OUT_SIZMASK; - if (typ == OUT_RAWDATA) { + if (typ == OUT_RAWDATA) + { unsigned char *p = data; char q[3]; - while (size--) { + while (size--) + { HEX (q, *p); q[2] = '\0'; list_out (offset++, q); p++; } - } else if (typ == OUT_ADDRESS) { + } + else if (typ == OUT_ADDRESS) + { unsigned long d = *(long *)data; char q[11]; unsigned char p[4], *r = p; - if (size == 4) { + if (size == 4) + { q[0] = '['; q[9] = ']'; q[10] = '\0'; WRITELONG (r, d); HEX (q+1, p[0]); @@ -138,14 +156,17 @@ static void list_output (long offset, void *data, unsigned long type) { HEX (q+5, p[2]); HEX (q+7, p[3]); list_out (offset, q); - } else { + } + else { q[0] = '['; q[5] = ']'; q[6] = '\0'; WRITESHORT (r, d); HEX (q+1, p[0]); HEX (q+3, p[1]); list_out (offset, q); } - } else if (typ == OUT_REL2ADR) { + } + else if (typ == OUT_REL2ADR) + { unsigned long d = *(long *)data; char q[11]; unsigned char p[4], *r = p; @@ -154,7 +175,9 @@ static void list_output (long offset, void *data, unsigned long type) { HEX (q+1, p[0]); HEX (q+3, p[1]); list_out (offset, q); - } else if (typ == OUT_REL4ADR) { + } + else if (typ == OUT_REL4ADR) + { unsigned long d = *(long *)data; char q[11]; unsigned char p[4], *r = p; @@ -165,17 +188,22 @@ static void list_output (long offset, void *data, unsigned long type) { HEX (q+5, p[2]); HEX (q+7, p[3]); list_out (offset, q); - } else if (typ == OUT_RESERVE) { + } + else if (typ == OUT_RESERVE) + { char q[20]; sprintf(q, "", size); list_out (offset, q); } } -static void list_line (int type, char *line) { +static void list_line (int type, char *line) +{ if (!listp) return; - if (mistack && mistack->inhibiting) { + + if (mistack && mistack->inhibiting) + { if (type == LIST_MACRO) return; else { /* pop the m i stack */ @@ -191,22 +219,29 @@ static void list_line (int type, char *line) { listlevel_e = listlevel; } -static void list_uplevel (int type) { +static void list_uplevel (int type) +{ if (!listp) return; - if (type == LIST_INCBIN || type == LIST_TIMES) { + if (type == LIST_INCBIN || type == LIST_TIMES) + { suppress |= (type == LIST_INCBIN ? 1 : 2); list_out (listoffset, type == LIST_INCBIN ? "" : ""); return; } + listlevel++; - if (mistack && mistack->inhibiting && type == LIST_INCLUDE) { + + if (mistack && mistack->inhibiting && type == LIST_INCLUDE) + { MacroInhibit *temp = nasm_malloc(sizeof(MacroInhibit)); temp->next = mistack; temp->level = listlevel; temp->inhibiting = FALSE; mistack = temp; - } else if (type == LIST_MACRO_NOLIST) { + } + else if (type == LIST_MACRO_NOLIST) + { MacroInhibit *temp = nasm_malloc(sizeof(MacroInhibit)); temp->next = mistack; temp->level = listlevel; @@ -215,15 +250,20 @@ static void list_uplevel (int type) { } } -static void list_downlevel (int type) { +static void list_downlevel (int type) +{ if (!listp) return; - if (type == LIST_INCBIN || type == LIST_TIMES) { + + if (type == LIST_INCBIN || type == LIST_TIMES) + { suppress &= ~(type == LIST_INCBIN ? 1 : 2); return; } + listlevel--; - while (mistack && mistack->level > listlevel) { + while (mistack && mistack->level > listlevel) + { MacroInhibit *temp = mistack; mistack = temp->next; nasm_free (temp); -- cgit v1.2.1