Mercurial > hg-old > index.cgi
comparison src/list.c @ 44:2330b88f9600
Added simple output listing
author | lost |
---|---|
date | Sun, 04 Jan 2009 06:52:18 +0000 |
parents | 39d750ee8d34 |
children | be459d69f481 |
comparison
equal
deleted
inserted
replaced
43:b33eca135258 | 44:2330b88f9600 |
---|---|
38 { | 38 { |
39 for (e = l -> err; e; e = e -> next) | 39 for (e = l -> err; e; e = e -> next) |
40 { | 40 { |
41 fprintf(stderr, "ERROR: %s\n", e -> mess); | 41 fprintf(stderr, "ERROR: %s\n", e -> mess); |
42 } | 42 } |
43 fprintf(stderr, "%s\n", l -> text); | 43 fprintf(stderr, "%s:%d: %s\n", l -> filename, l -> lineno, l -> text); |
44 } | 44 } |
45 } | 45 } |
46 } | 46 } |
47 | 47 |
48 void lwasm_list(asmstate_t *as) | 48 void lwasm_list(asmstate_t *as) |
49 { | 49 { |
50 FILE *lf; | |
51 lwasm_line_t *l; | |
52 int c; | |
53 char *p; | |
54 | |
55 if (as -> listfile[0] == '-' && as -> listfile[1] == '\0') | |
56 lf = stdout; | |
57 else | |
58 { | |
59 lf = fopen(as -> listfile, "o"); | |
60 if (!lf) | |
61 { | |
62 fprintf(stderr, "Unable to open list file. No listing will be generated!\n"); | |
63 goto showerr; | |
64 } | |
65 } | |
66 | |
67 for (l = as -> lineshead; l; l = l -> next) | |
68 { | |
69 fprintf(lf, "%04X ", l -> codeaddr); | |
70 | |
71 if (l -> codelen > 0) | |
72 { | |
73 for (c = 0; c < l -> codelen && c < 5; c++) | |
74 { | |
75 fprintf(lf, "%02X", l -> bytes[c]); | |
76 } | |
77 } | |
78 while (c < 5) | |
79 { | |
80 fprintf(lf, " "); | |
81 c++; | |
82 } | |
83 fprintf(lf, " %20.20s:%05d ", l -> filename, l -> lineno); | |
84 | |
85 // print line here | |
86 for (c = 0, p = l -> text; *p; c++, p++) | |
87 { | |
88 if (*p == '\t') | |
89 { | |
90 int c2; | |
91 c2 = 8 - (c % 8); | |
92 while (c2--) fputc(' ', lf); | |
93 } | |
94 else | |
95 fputc(*p, lf); | |
96 } | |
97 fputc('\n', lf); | |
98 | |
99 if (l -> codelen > 5) | |
100 { | |
101 fprintf(lf, " "); | |
102 for (c = 5; c < l -> codelen; c++) | |
103 { | |
104 if (!(c % 5) && c != 5) | |
105 { | |
106 fprintf(lf, "\n "); | |
107 } | |
108 fprintf(lf, "%02X", l -> bytes[c]); | |
109 } | |
110 fputc('\n', lf); | |
111 } | |
112 } | |
113 if (lf != stdout) | |
114 fclose(lf); | |
115 | |
116 showerr: | |
50 lwasm_show_errors(as); | 117 lwasm_show_errors(as); |
51 } | 118 } |