| ... | ... |
@@ -157,7 +157,7 @@ makemacro(char *name, FILE *f) |
| 157 | 157 |
return error("Macro name is invalid", name);
|
| 158 | 158 |
m = &p.macros[p.mlen++]; |
| 159 | 159 |
scpy(name, m->name, 64); |
| 160 |
- while(fscanf(f, "%63s", word)) {
|
|
| 160 |
+ while(fscanf(f, "%63s", word) == 1) {
|
|
| 161 | 161 |
if(word[0] == '{') continue;
|
| 162 | 162 |
if(word[0] == '}') break; |
| 163 | 163 |
if(m->len > 64) |
| ... | ... |
@@ -284,6 +284,21 @@ parsetoken(char *w) |
| 284 | 284 |
return error("Invalid token", w);
|
| 285 | 285 |
} |
| 286 | 286 |
|
| 287 |
+static int |
|
| 288 |
+doinclude(FILE *f, int (*pass)(FILE *)) |
|
| 289 |
+{
|
|
| 290 |
+ char word[64]; |
|
| 291 |
+ FILE *finc; |
|
| 292 |
+ int ret; |
|
| 293 |
+ if(fscanf(f, "%63s", word) != 1) |
|
| 294 |
+ return error("End of input", "include");
|
|
| 295 |
+ if(!(finc = fopen(word, "r"))) |
|
| 296 |
+ return error("Include failed to open", word);
|
|
| 297 |
+ ret = pass(finc); |
|
| 298 |
+ fclose(finc); |
|
| 299 |
+ return ret; |
|
| 300 |
+} |
|
| 301 |
+ |
|
| 287 | 302 |
static int |
| 288 | 303 |
pass1(FILE *f) |
| 289 | 304 |
{
|
| ... | ... |
@@ -308,6 +323,9 @@ pass1(FILE *f) |
| 308 | 323 |
} else if(w[0] == '&') {
|
| 309 | 324 |
if(!makelabel(sublabel(subw, scope, w + 1), addr)) |
| 310 | 325 |
return error("Pass 1 - Invalid sublabel", w);
|
| 326 |
+ } else if(scmp(w, "include", 8)) {
|
|
| 327 |
+ if(!doinclude(f, pass1)) |
|
| 328 |
+ return 0; |
|
| 311 | 329 |
} else if(sihx(w)) |
| 312 | 330 |
addr += slen(w) / 2; |
| 313 | 331 |
else |
| ... | ... |
@@ -340,6 +358,10 @@ pass2(FILE *f) |
| 340 | 358 |
} else if(w[0] == '@') {
|
| 341 | 359 |
scpy(w + 1, scope, 64); |
| 342 | 360 |
continue; |
| 361 |
+ } else if(scmp(w, "include", 8)) {
|
|
| 362 |
+ if(!doinclude(f, pass2)) |
|
| 363 |
+ return 0; |
|
| 364 |
+ continue; |
|
| 343 | 365 |
} |
| 344 | 366 |
if(w[1] == '&') |
| 345 | 367 |
scpy(sublabel(subw, scope, w + 2), w + 1, 64); |