]> Shamusworld >> Repos - rmac/blob - error.c
Fixed word reversed fixup problem.
[rmac] / error.c
1 //
2 // RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System
3 // ERROR.C - Error Handling
4 // Copyright (C) 199x Landon Dyer, 2011 Reboot and Friends
5 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
6 // Source Utilised with the Kind Permission of Landon Dyer
7 //
8
9 #include "error.h"
10 #include "token.h"
11 #include "listing.h"
12
13 int errcnt;                                             // Error count
14 char * err_fname;                               // Name of error message file
15
16 static const char nl[] = "\n";
17 static long unused;                             // For supressing 'write' warnings
18
19
20 //
21 // Report error if not at EOL
22 //
23 int at_eol(void)
24 {
25         char msg[256];
26
27         if (*tok != EOL)
28         {
29 //              error("syntax error");
30                 sprintf(msg, "syntax error. expected EOL, found $%X ('%c')", *tok, *tok);
31                 error(msg);
32         }
33
34         return 0;
35 }
36
37
38 //
39 // Cannot Create a File
40 //
41 void cantcreat(const char * fn)
42 {
43         printf("cannot create: '%s'\n", fn);
44         exit(1);
45 }
46
47
48 //
49 // Setup for Error Message
50 // o  Create error listing file (if necessary)
51 // o  Set current filename
52 //
53 void err_setup(void)
54 {
55         char fnbuf[FNSIZ];
56
57 // This seems like it's unnecessary, as token.c seems to take care of this all by itself.
58 // Can restore if it's really needed. If not, into the bit bucket it goes. :-)
59 //      setfnum(cfileno);
60
61         if (err_fname != NULL)
62         {
63                 strcpy(fnbuf, err_fname);
64
65                 if (*fnbuf == EOS)
66                         strcpy(fnbuf, firstfname);
67
68                 err_fname = NULL;
69
70                 if ((err_fd = open(fnbuf, _OPEN_FLAGS, _PERM_MODE)) < 0)
71                         cantcreat(fnbuf);
72
73                 err_flag = 1;
74         }
75 }
76
77
78 //
79 // Display Error Message
80 //
81 int error(const char * s)
82 {
83         char buf[EBUFSIZ];
84         unsigned int length;
85
86         err_setup();
87
88         if (listing > 0)
89                 ship_ln(s);
90
91         sprintf(buf, "%s %d: Error: %s%s", curfname, curlineno, s, nl);
92         length = strlen(buf);
93
94         if (err_flag)
95                 unused = write(err_fd, buf, length);
96         else
97                 printf("%s", buf);
98
99         taglist('E');
100         errcnt++;
101
102         return ERROR;
103 }
104
105
106 int errors(const char * s, char * s1)
107 {
108         char buf[EBUFSIZ];
109         char buf1[EBUFSIZ];
110
111         err_setup();
112         sprintf(buf, s, s1);
113
114         if (listing > 0)
115                 ship_ln(buf);
116
117         sprintf(buf1, "%s %d: Error: %s%s", curfname, curlineno, buf, nl);
118
119         if (err_flag)
120                 unused = write(err_fd, buf1, (LONG)strlen(buf1));
121         else
122                 printf("%s", buf1);
123
124         taglist('E');
125         ++errcnt;
126
127         return ERROR;
128 }
129
130
131 int warn(const char * s)
132 {
133         char buf[EBUFSIZ];
134
135         err_setup();
136
137         if (listing > 0)
138                 ship_ln(s);
139
140         sprintf(buf, "%s %d: Warning: %s%s", curfname, curlineno, s, nl);
141
142         if (err_flag)
143                 unused = write(err_fd, buf, (LONG)strlen(buf));
144         else
145                 printf("%s", buf);
146
147         taglist('W');
148
149         return OK;
150 }
151
152
153 int warns(const char * s, char * s1)
154 {
155         char buf[EBUFSIZ];
156         char buf1[EBUFSIZ];
157
158         err_setup();
159         sprintf(buf, s, s1);
160
161         if (listing > 0)
162                 ship_ln(s);
163
164         sprintf(buf1, "%s %d: Warning: %s%s", curfname, curlineno, buf, nl);
165
166         if (err_flag)
167                 unused = write(err_fd, buf1, (LONG)strlen(buf1));
168         else
169                 printf("%s", buf1);
170
171         taglist('W');
172
173         return OK;
174 }
175
176
177 int warni(const char * s, unsigned i)
178 {
179         char buf[EBUFSIZ];
180         char buf1[EBUFSIZ];
181
182         err_setup();
183         sprintf(buf, s, i);
184
185         if (listing > 0)
186                 ship_ln(buf);
187
188         sprintf(buf1, "%s %d: Warning: %s%s", curfname, curlineno, buf, nl);
189
190         if (err_flag)
191                 unused = write(err_fd, buf1, (LONG)strlen(buf1));
192         else
193                 printf("%s", buf1);
194
195         taglist('W');
196
197         return OK;
198 }
199
200
201 int fatal(const char * s)
202 {
203         char buf[EBUFSIZ];
204
205         err_setup();
206
207         if (listing > 0)
208                 ship_ln(s);
209
210         sprintf(buf, "%s %d: Fatal: %s%s", curfname, curlineno, s, nl);
211
212         if (err_flag)
213                 unused = write(err_fd, buf, (LONG)strlen(buf));
214         else
215                 printf("%s", buf);
216
217         exit(1);
218 }
219
220
221 int interror(int n)
222 {
223         char buf[EBUFSIZ];
224
225         err_setup();
226         sprintf(buf, "%s %d: Internal Error Number %d%s", curfname, curlineno, n, nl);
227
228         if (listing > 0)
229                 ship_ln(buf);
230
231         if (err_flag)
232                 unused = write(err_fd, buf, (LONG)strlen(buf));
233         else
234                 printf("%s", buf);
235
236         exit(1);
237 }
238