]> Shamusworld >> Repos - rmac/blob - error.c
Small fix for FU_JR fixups.
[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         setfnum(cfileno);
51
52         if (err_fname != NULL)
53         {
54                 strcpy(fnbuf, err_fname);
55
56                 if (*fnbuf == EOS)
57                         strcpy(fnbuf, firstfname);
58
59                 err_fname = NULL;
60
61                 if ((err_fd = open(fnbuf, _OPEN_FLAGS, _PERM_MODE)) < 0)
62                         cantcreat(fnbuf);
63
64                 err_flag = 1;
65         }
66 }
67
68
69 //
70 // Display Error Message
71 //
72 int error(const char * s)
73 {
74         char buf[EBUFSIZ];
75         unsigned int length;
76
77         err_setup();
78
79         if (listing > 0)
80                 ship_ln(s);
81
82         sprintf(buf, "%s%d: Error: %s%s", curfname, curlineno, s, nl);
83         length = strlen(buf);
84
85         if (err_flag)
86                 write(err_fd, buf, length);
87         else
88                 printf("%s", buf);
89
90         taglist('E');
91         errcnt++;
92
93         return ERROR;
94 }
95
96 int errors(char * s, char * s1)
97 {
98         char buf[EBUFSIZ];
99         char buf1[EBUFSIZ];
100
101         err_setup();
102         sprintf(buf, s, s1);
103
104         if (listing > 0)
105                 ship_ln(buf);
106
107         sprintf(buf1, "%s%d: Error: %s%s", curfname, curlineno, buf, nl);
108
109         if (err_flag)
110                 write(err_fd, buf1, (LONG)strlen(buf1));
111         else
112                 printf("%s", buf1);
113
114         taglist('E');
115         ++errcnt;
116
117         return ERROR;
118 }
119
120 int warn(char * s)
121 {
122         char buf[EBUFSIZ];
123
124         err_setup();
125
126         if (listing > 0)
127                 ship_ln(s);
128
129         sprintf(buf, "%s%d: Warning: %s%s", curfname, curlineno, s, nl);
130
131         if (err_flag)
132                 write(err_fd, buf, (LONG)strlen(buf));
133         else
134                 printf("%s", buf);
135
136         taglist('W');
137
138         return OK;
139 }
140
141 int warns(char * s, char * s1)
142 {
143         char buf[EBUFSIZ];
144         char buf1[EBUFSIZ];
145
146         err_setup();
147         sprintf(buf, s, s1);
148
149         if (listing > 0)
150                 ship_ln(s);
151
152         sprintf(buf1, "%s%d: Warning: %s%s", curfname, curlineno, buf, nl);
153
154         if (err_flag)
155                 write(err_fd, buf1, (LONG)strlen(buf1));
156         else
157                 printf("%s", buf1);
158
159         taglist('W');
160
161         return OK;
162 }
163
164 int warni(char * s, unsigned i)
165 {
166         char buf[EBUFSIZ];
167         char buf1[EBUFSIZ];
168
169         err_setup();
170         sprintf(buf, s, i);
171
172         if (listing > 0)
173                 ship_ln(buf);
174
175         sprintf(buf1, "%s%d: Warning: %s%s", curfname, curlineno, buf, nl);
176
177         if (err_flag)
178                 write(err_fd, buf1, (LONG)strlen(buf1));
179         else
180                 printf("%s", buf1);
181
182         taglist('W');
183
184         return OK;
185 }
186
187 int fatal(char * s)
188 {
189         char buf[EBUFSIZ];
190
191         err_setup();
192
193         if (listing > 0)
194                 ship_ln(s);
195
196         sprintf(buf, "%s%d: Fatal: %s%s", curfname, curlineno, s, nl);
197
198         if (err_flag)
199                 write(err_fd, buf, (LONG)strlen(buf));
200         else
201                 printf("%s", buf);
202
203         exit(1);
204 }
205
206 int interror(int n)
207 {
208         char buf[EBUFSIZ];
209
210         err_setup();
211         sprintf(buf, "%s%d: Internal Error Number %d%s", curfname, curlineno, n, nl);
212
213         if (listing > 0)
214                 ship_ln(buf);
215
216         if (err_flag)
217                 write(err_fd, buf, (LONG)strlen(buf));
218         else
219                 printf("%s", buf);
220
221         exit(1);
222 }