comparison lwasm/list.c @ 151:427e268e876b

renamed src to lwasm to better reflect its purpose
author lost
date Fri, 30 Jan 2009 04:01:55 +0000
parents src/list.c@dbf1b926c2f1
children 586069fb17a1
comparison
equal deleted inserted replaced
150:f0881c115010 151:427e268e876b
1 /*
2 list.c
3 Copyright © 2009 William Astle
4
5 This file is part of LWASM.
6
7 LWASM is free software: you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation, either version 3 of the License, or (at your option) any later
10 version.
11
12 This program is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 more details.
16
17 You should have received a copy of the GNU General Public License along with
18 this program. If not, see <http://www.gnu.org/licenses/>.
19
20 Contains code for displaying a program listings, etc.
21 */
22
23 #define __list_c_seen__
24
25 #include <stdio.h>
26 #include <stdlib.h>
27
28 #include "lwasm.h"
29
30 void lwasm_show_errors(asmstate_t *as)
31 {
32 lwasm_line_t *l;
33 lwasm_error_t *e;
34
35 for (l = as -> lineshead; l; l = l -> next)
36 {
37 if (l -> err)
38 {
39 for (e = l -> err; e; e = e -> next)
40 {
41 fprintf(stderr, "ERROR: %s\n", e -> mess);
42 }
43 fprintf(stderr, "%s:%d: %s\n", l -> filename, l -> lineno, l -> text);
44 }
45 }
46 }
47
48 void lwasm_list(asmstate_t *as)
49 {
50 FILE *lf;
51 lwasm_line_t *l;
52 int c, c3;
53 char *p;
54
55 if (!as -> listfile)
56 return;
57 if (as -> listfile[0] == '-' && as -> listfile[1] == '\0')
58 lf = stdout;
59 else
60 {
61 lf = fopen(as -> listfile, "w");
62 if (!lf)
63 {
64 fprintf(stderr, "Unable to open list file '%s'. No listing will be generated: ", as -> listfile);
65 perror("");
66 goto showerr;
67 }
68 }
69
70 for (l = as -> lineshead; l; l = l -> next)
71 {
72 if (l -> addrset == 1 || l -> codelen > 0 || l -> nocodelen > 0)
73 {
74 fprintf(lf, "%04X ", l -> codeaddr);
75 }
76 else
77 {
78 fprintf(lf, " ");
79 }
80
81 if (l -> addrset == 2)
82 {
83 fprintf(lf, "%04X ", l -> symaddr);
84 }
85 else
86 {
87 for (c = 0; c < l -> codelen && c < 5; c++)
88 {
89 fprintf(lf, "%02X", l -> bytes[c]);
90 }
91 while (c < 5)
92 {
93 fprintf(lf, " ");
94 c++;
95 }
96 }
97 fprintf(lf, " %20.20s:%05d ", l -> filename, l -> lineno);
98
99 // print line here
100 for (c3 = 0, c = 0, p = l -> text; *p; c++, p++)
101 {
102 if (*p == '\t')
103 {
104 int c2;
105 c2 = 8 - (c3 % 8);
106 c3 += c2;
107 while (c2--) fputc(' ', lf);
108 }
109 else
110 {
111 c3++;
112 fputc(*p, lf);
113 }
114 }
115 fputc('\n', lf);
116
117 if (l -> codelen > 5)
118 {
119 fprintf(lf, "%04X ", (l -> codeaddr + 5) & 0xFFFF);
120 for (c = 5; c < l -> codelen; c++)
121 {
122 if (!(c % 5) && c != 5)
123 {
124 fprintf(lf, "\n%04X ", (l -> codeaddr + c) & 0xFFFF);
125 }
126 fprintf(lf, "%02X", l -> bytes[c]);
127 }
128 fputc('\n', lf);
129 }
130 }
131
132 lwasm_list_symbols(as, lf);
133
134 if (lf != stdout)
135 fclose(lf);
136
137 showerr:
138 lwasm_show_errors(as);
139 }