summaryrefslogtreecommitdiff
path: root/sdas/asxxsrc/assubr.c
blob: 98aa519cd53837378f117889ca66ddbceb65a1a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/* assubr.c */

/*
 *  Copyright (C) 1989-2010  Alan R. Baldwin
 *
 *  This program 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/>.
 *
 *
 * Alan R. Baldwin
 * 721 Berkeley St.
 * Kent, Ohio  44240
 */

#include "sdas.h"
#include "asxxxx.h"

/*)Module       assubr.c
 *
 *      The module assubr.c contains the error
 *      processing routines.
 *
 *      assubr.c contains the following functions:
 *              VOID    aerr()
 *              VOID    diag()
 *              VOID    err()
 *              VOID    qerr()
 *              VOID    rerr()
 *              char *  geterr()
 *
 *      assubr.c contains the local array of *error[]
 */

/*)Function     VOID    err(c)
 *
 *              int     c               error type character
 *
 *      The function err() logs the error code character
 *      suppressing duplicate errors.  If the error code
 *      is 'q' then the parse of the current assembler-source
 *      text line is terminated.
 *
 *      local variables:
 *              char *  p               pointer to the error array
 *
 *      global variables:
 *              int     aserr           error counter
 *              char    eb[]            array of generated error codes
 *
 *      functions called:
 *              VOID    longjmp()       c_library
 *
 *      side effects:
 *              The error code may be inserted into the
 *              error code array eb[] or the parse terminated.
 */

VOID
err(int c)
{
        char *p;

        aserr++;
        p = eb;
        while (p < ep)
                if (*p++ == c)
                        return;
        if (p < &eb[NERR]) {
                *p++ = c;
                ep = p;
        }
        if (c == 'q')
                longjmp(jump_env, -1);
}

/*)Function     VOID    diag()
 *
 *      The function diag() prints any error codes and
 *      the source line number to the stderr output device.
 *
 *      local variables:
 *              char *  p               pointer to error code array eb[]
 *
 *      global variables:
 *              char    eb[]            array of generated error codes
 *              char *  ep              pointer into error list
 *              int     incline         include file line number
 *              char    afn[]           afile() constructed filespec
 *              FILE *  stderr          c_library
 *
 *      functions called:
 *              int     fprintf()       c_library
 *              char *  geterr()        assubr.c
 *              int     getlnm()        assubr.c
 *
 *      side effects:
 *              none
 */

VOID
diag()
{
        char *p,*errstr;

        if (eb != ep) {
                p = eb;
                if (!is_sdas()) {
                        fprintf(stderr, "?ASxxxx-Error-<");
                        while (p < ep) {
                                fprintf(stderr, "%c", *p++);
                        }
                        fprintf(stderr, "> in line ");
                        fprintf(stderr, "%d", getlnm());
                        fprintf(stderr, " of %s\n", afn);
                        p = eb;
                }
                while (p < ep) {
                        if ((errstr = geterr(*p++)) != NULL) {
                                if (!is_sdas()) {
                                        fprintf(stderr, "              %s\n", errstr);
                                } else {
                                        /* Modified to conform to gcc error standard, M. Hope, 7 Feb 98. */
                                        fprintf(stderr, "%s:", afn);
                                        fprintf(stderr, "%d: Error:", getlnm());
                                        fprintf(stderr, " %s\n", errstr);
                                }
                        }
                }
        }
}

/* sdas specific */
/*)Function     VOID    warnBanner()
 *
 *      The function warnBanner() prints a generic warning message
 *      header (including the current source file/line) and positions
 *      the output for a more specific warning message.
 *
 *      It is assumed that the call to warnBanner will be followed with
 *      a fprintf to stderr (or equivalent) with the specific warning
 *      text.
 *
 *      local variables:
 *              none
 *
 *      global variables:
 *              char    afn[]           afile() constructed filespec
 *              FILE *  stderr          c_library
 *
 *      functions called:
 *              int     fprintf()       c_library
 *              int     getlnm()        assubr.c
 *
 *      side effects:
 *              none
 */
VOID
warnBanner(void)
{
        fprintf(stderr, "?ASxxxx-Warning in line ");
        fprintf(stderr, "%d", getlnm());
        fprintf(stderr, " of %s\n", afn);
        fprintf(stderr, "               ");
}       
/* end sdas specific */

/*)Functions:   VOID    aerr()
 *              VOID    qerr()
 *              VOID    rerr()
 *
 *      The functions aerr(), qerr(), and rerr() report their
 *      respective error type.  These are included only for
 *      convenience.
 *
 *      local variables:
 *              none
 *
 *      global variables:
 *              none
 *
 *      functions called:
 *              VOID    err()           assubr.c
 *
 *      side effects:
 *              The appropriate error code is inserted into the
 *              error array and the parse may be terminated.
 */

/*
 * Note an 'r' error.
 */
VOID
rerr()
{
        err('r');
}

/*
 * Note an 'a' error.
 */
VOID
aerr()
{
        err('a');
}

/*
 * Note a 'q' error.
 */
VOID
qerr()
{
        err('q');
}

/*
 * ASxxxx assembler errors
 */
char *errors[] = {
        "<.> use \". = . + <arg>\" not \". = <arg>\"",
        "<a> machine specific addressing or addressing mode error",
        "<b> direct page boundary error",
        "<d> direct page addressing error",
        "<i> .include file error or an .if/.endif mismatch",
        "<m> multiple definitions error",
        "<o> .org in REL area or directive / mnemonic error",
        "<p> phase error: label location changing between passes 2 and 3",
        "<q> missing or improper operators, terminators, or delimiters",
        "<r> relocation error",
        "<u> undefined symbol encountered during assembly",
        NULL
};

/*)Function:    char    *geterr(c)
 *
 *              int     c               the error code character
 *
 *      The function geterr() scans the list of errors returning the
 *      error string corresponding to the input error character.
 *
 *      local variables:
 *              int     i               error index counter
 *
 *      global variables:
 *              char    *errors[]       array of pointers to the
 *                                      error strings
 *              char    erb[]           Error string buffer
 *
 *      functions called:
 *              none
 *
 *      side effects:
 *              A pointer to the appropriate
 *              error code string is returned.
 */
char *
geterr(c)
int c;
{
        int i;

        for (i=0; errors[i]!=NULL; i++) {
                if (c == errors[i][1]) {
                        return(errors[i]);
                }
        }
        sprintf(erb, "<e> %.*s", (int) (sizeof(erb)-5), ib);
        return(erb);
}