Mercurial > hg-old > index.cgi
view src/list.c @ 67:d5fe306f1ab1
Fixed numerous bugs in macro handling
author | lost |
---|---|
date | Mon, 05 Jan 2009 05:40:33 +0000 |
parents | b1d81800bc91 |
children | 9fa4f77dd119 |
line wrap: on
line source
/* list.c Copyright © 2009 William Astle This file is part of LWASM. LWASM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. Contains code for displaying a program listings, etc. */ #define __list_c_seen__ #include <stdio.h> #include <stdlib.h> #include "lwasm.h" void lwasm_show_errors(asmstate_t *as) { lwasm_line_t *l; lwasm_error_t *e; for (l = as -> lineshead; l; l = l -> next) { if (l -> err) { for (e = l -> err; e; e = e -> next) { fprintf(stderr, "ERROR: %s\n", e -> mess); } fprintf(stderr, "%s:%d: %s\n", l -> filename, l -> lineno, l -> text); } } } void lwasm_list(asmstate_t *as) { FILE *lf; lwasm_line_t *l; int c; char *p; if (as -> listfile[0] == '-' && as -> listfile[1] == '\0') lf = stdout; else { lf = fopen(as -> listfile, "w"); if (!lf) { fprintf(stderr, "Unable to open list file '%s'. No listing will be generated: ", as -> listfile); perror(""); goto showerr; } } for (l = as -> lineshead; l; l = l -> next) { if (l -> addrset == 1 || l -> codelen > 0 || l -> nocodelen > 0) { fprintf(lf, "%04X ", l -> codeaddr); } else { fprintf(lf, " "); } if (l -> addrset == 2) { fprintf(lf, "%04X ", l -> symaddr); } else { for (c = 0; c < l -> codelen && c < 5; c++) { fprintf(lf, "%02X", l -> bytes[c]); } while (c < 5) { fprintf(lf, " "); c++; } } fprintf(lf, " %20.20s:%05d ", l -> filename, l -> lineno); // print line here for (c = 0, p = l -> text; *p; c++, p++) { if (*p == '\t') { int c2; c2 = 8 - (c % 8); while (c2--) fputc(' ', lf); } else fputc(*p, lf); } fputc('\n', lf); if (l -> codelen > 5) { fprintf(lf, " "); for (c = 5; c < l -> codelen; c++) { if (!(c % 5) && c != 5) { fprintf(lf, "\n "); } fprintf(lf, "%02X", l -> bytes[c]); } fputc('\n', lf); } } lwasm_list_symbols(as, lf); if (lf != stdout) fclose(lf); showerr: lwasm_show_errors(as); }