Mercurial > hg-old > index.cgi
diff src/list.c @ 35:39d750ee8d34
Added error display and fixed infinite loop in lwasm_parse_line()
author | lost |
---|---|
date | Fri, 02 Jan 2009 06:07:10 +0000 |
parents | 34568fab6058 |
children | 2330b88f9600 |
line wrap: on
line diff
--- a/src/list.c Fri Jan 02 05:17:00 2009 +0000 +++ b/src/list.c Fri Jan 02 06:07:10 2009 +0000 @@ -1,6 +1,6 @@ /* list.c -Copyright © 2008 William Astle +Copyright © 2009 William Astle This file is part of LWASM. @@ -17,154 +17,35 @@ 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 listing in lwasm +Contains code for displaying a program listings, etc. */ -//#include <ctype.h> -#include <errno.h> +#define __list_c_seen__ + #include <stdio.h> -//#include <stdlib.h> -#include <string.h> -#define __list_c_seen__ -//#include "instab.h" +#include <stdlib.h> + #include "lwasm.h" -const char *errlist[] = +void lwasm_show_errors(asmstate_t *as) { - "No error", - "Bad opcode", - "Illegal Symbol", - "Multiply defined symbol", - "Symbol required but not present", - "Forward references not permitted", - "Byte overflow", - "Phase error", - "Bad operand", - "Symbol not permitted here", - "Undefined symbol", - "Bit number out of range", - "Invalid expression", - "Invalid register", - "Bad file name", - "ENDM without MACRO", - "Redefined macro", - "Nested namespace", - "Bad condition", - "User error", - "Bad pragma", - "" -}; - -void list_code(asmstate_t *as) -{ - FILE *lf; - sourceline_t *cl; - int bn; - int c; - char *t; + lwasm_line_t *l; + lwasm_error_t *e; - if (as -> listfile && strcmp(as -> listfile, "-")) + for (l = as -> lineshead; l; l = l -> next) { - lf = fopen(as -> listfile, "w"); - if (!lf) + if (l -> err) { - perror("Cannot open list file"); - return; + for (e = l -> err; e; e = e -> next) + { + fprintf(stderr, "ERROR: %s\n", e -> mess); + } + fprintf(stderr, "%s\n", l -> text); } } - else - { - lf = stdout; - } - - for (cl = as -> source_head; cl; cl = cl -> next) - { - bn = 0; - if (cl -> errors) - { - errortab_t *e; - for (e = cl -> errors; e; e = e -> next) - { - if (e -> errnum < ERR_MAXERR && e -> errnum != ERR_USER) - fprintf(lf, "*****ERROR: %s\n", errlist[e -> errnum]); - } - if (cl -> user_error) - { - fprintf(lf, "*****ERROR: %s\n", cl -> user_error); - } - } - if (cl -> skipped) - { - fprintf(lf, "%-15.15s", "<skipped>"); - } - else if (cl -> macrodef) - { - fprintf(lf, "%-15.15s", "<macrodef>"); - } - else if (cl -> opcode >= 0 && cl -> numcodebytes > 0) - { - fprintf(lf, "%04X ", cl -> addr); - while (bn < 5 && bn < cl -> numcodebytes) - { - fprintf(lf, "%02X", cl -> codebytes[bn]); - bn++; - } - while (bn < 5) - { - fprintf(lf, " "); - bn++; - } - } - else if (cl -> addrset || (cl -> len && cl -> numcodebytes == 0)) - { - fprintf(lf, "%04X %10s", cl -> addr, ""); - } - else if (cl -> isequ) - { - fprintf(lf, " %04X ", cl -> symaddr); - } - else if (cl -> issetdp) - { - fprintf(lf, " %02X ", cl -> dpval); - } - else - fprintf(lf, " "); - fprintf(lf, " %15.15s:%06d ", cl -> sourcefile, cl -> lineno); - // actually display the line from the file - for (c = 0, t = cl -> line; *t; t++) - { - if (*t == '\n' || *t == '\r') - break; - if (*t == '\t') - { - do - { - fprintf(lf, " "); - c++; - } while (c % 8); - } - else - { - c++; - fprintf(lf, "%c", *t); - } - } -// fprintf(lf, "\n"); - - while (bn < cl -> numcodebytes) - { - if (bn % 5 == 0) - fprintf(lf, "\n%04X ", (cl -> addr + bn) & 0xFFFF); - fprintf(lf, "%02X", cl -> codebytes[bn]); - bn++; - } - fprintf(lf, "\n"); - } - - fprintf(lf, "\n"); - list_symbols(as, lf); - - if (lf != stdout) - fclose(lf); } +void lwasm_list(asmstate_t *as) +{ + lwasm_show_errors(as); +}