comparison old-trunk/lwasm/old/list.c @ 339:eb230fa7d28e

Prepare for migration to hg
author lost
date Fri, 19 Mar 2010 02:54:14 +0000
parents
children
comparison
equal deleted inserted replaced
338:e7885b3ee266 339:eb230fa7d28e
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 #include <config.h>
25
26 #include <stdio.h>
27 #include <stdlib.h>
28
29 #include "lwasm.h"
30
31 void lwasm_show_errors(asmstate_t *as)
32 {
33 lwasm_line_t *l;
34 lwasm_error_t *e;
35
36 for (l = as -> lineshead; l; l = l -> next)
37 {
38 if (l -> err)
39 {
40 for (e = l -> err; e; e = e -> next)
41 {
42 fprintf(stderr, "ERROR: %s\n", e -> mess);
43 }
44 fprintf(stderr, "%s:%d: %s\n", l -> filename, l -> lineno, l -> text);
45 }
46 }
47 }
48
49 void lwasm_list(asmstate_t *as)
50 {
51 FILE *lf;
52 lwasm_line_t *l;
53 int c, c3;
54 char *p;
55
56 if (!as -> listfile)
57 goto showerr;
58 if (as -> listfile[0] == '-' && as -> listfile[1] == '\0')
59 lf = stdout;
60 else
61 {
62 lf = fopen(as -> listfile, "w");
63 if (!lf)
64 {
65 fprintf(stderr, "Unable to open list file '%s'. No listing will be generated: ", as -> listfile);
66 perror("");
67 goto showerr;
68 }
69 }
70
71 for (l = as -> lineshead; l; l = l -> next)
72 {
73 if (l -> addrset == 1 || l -> codelen > 0 || l -> nocodelen > 0)
74 {
75 fprintf(lf, "%04X ", l -> codeaddr);
76 }
77 else
78 {
79 fprintf(lf, " ");
80 }
81
82 if (l -> addrset == 2)
83 {
84 fprintf(lf, "%04X ", l -> symaddr);
85 }
86 else
87 {
88 for (c = 0; c < l -> codelen && c < 5; c++)
89 {
90 fprintf(lf, "%02X", l -> bytes[c]);
91 }
92 while (c < 5)
93 {
94 fprintf(lf, " ");
95 c++;
96 }
97 }
98 fprintf(lf, " %20.20s:%05d ", l -> filename, l -> lineno);
99
100 // print line here
101 for (c3 = 0, c = 0, p = l -> text; *p; c++, p++)
102 {
103 if (*p == '\t')
104 {
105 int c2;
106 c2 = 8 - (c3 % 8);
107 c3 += c2;
108 while (c2--) fputc(' ', lf);
109 }
110 else
111 {
112 c3++;
113 fputc(*p, lf);
114 }
115 }
116 fputc('\n', lf);
117
118 if (l -> codelen > 5)
119 {
120 fprintf(lf, "%04X ", (l -> codeaddr + 5) & 0xFFFF);
121 for (c = 5; c < l -> codelen; c++)
122 {
123 if (!(c % 5) && c != 5)
124 {
125 fprintf(lf, "\n%04X ", (l -> codeaddr + c) & 0xFFFF);
126 }
127 fprintf(lf, "%02X", l -> bytes[c]);
128 }
129 fputc('\n', lf);
130 }
131 }
132
133 lwasm_list_symbols(as, lf);
134
135 if (lf != stdout)
136 fclose(lf);
137
138 showerr:
139 lwasm_show_errors(as);
140 }