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