...
|
...
|
@@ -60,6 +60,7 @@ static int scmp(char *a, char *b, int len) { int i = 0; while(a[i] == b[i]) if
|
60
|
60
|
static int sihx(char *s) { int i = 0; char c; while((c = s[i++])) if(!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f')) return 0; return i > 1; } /* string is hexadecimal */
|
61
|
61
|
static int shex(char *s) { int n = 0, i = 0; char c; while((c = s[i++])) if(c >= '0' && c <= '9') n = n * 16 + (c - '0'); else if(c >= 'a' && c <= 'f') n = n * 16 + 10 + (c - 'a'); return n; } /* string to num */
|
62
|
62
|
static int slen(char *s) { int i = 0; while(s[i]) i++; return i; } /* string length */
|
|
63
|
+static int spos(char *s, char c) { Uint8 i = 0, j; while((j = s[i++])) if(j == c) return i; return -1; } /* character position */
|
63
|
64
|
static char *scpy(char *src, char *dst, int len) { int i = 0; while((dst[i] = src[i]) && i < len - 2) i++; dst[i + 1] = '\0'; return dst; } /* string copy */
|
64
|
65
|
static char *scat(char *dst, const char *src) { char *ptr = dst + slen(dst); while(*src) *ptr++ = *src++; *ptr = '\0'; return dst; } /* string cat */
|
65
|
66
|
|
...
|
...
|
@@ -174,15 +175,22 @@ makelabel(char *name)
|
174
|
175
|
static int
|
175
|
176
|
makereference(char *scope, char *label, Uint16 addr)
|
176
|
177
|
{
|
177
|
|
- char subw[0x40];
|
|
178
|
+ char subw[0x40], parent[0x40];
|
178
|
179
|
Reference *r;
|
179
|
180
|
if(p.rlen == 0x800)
|
180
|
181
|
return error("References limit exceeded", label);
|
181
|
182
|
r = &p.refs[p.rlen++];
|
182
|
183
|
if(label[1] == '&')
|
183
|
184
|
scpy(sublabel(subw, scope, label + 2), r->name, 0x40);
|
184
|
|
- else
|
|
185
|
+ else {
|
|
186
|
+ int p = spos(label + 1, '/');
|
|
187
|
+ if(p > 0) {
|
|
188
|
+ Label *l;
|
|
189
|
+ if((l = findlabel(scpy(label + 1, parent, p))))
|
|
190
|
+ l->refs++;
|
|
191
|
+ }
|
185
|
192
|
scpy(label + 1, r->name, 0x40);
|
|
193
|
+ }
|
186
|
194
|
r->rune = label[0];
|
187
|
195
|
r->addr = addr;
|
188
|
196
|
return 1;
|
...
|
...
|
@@ -308,7 +316,6 @@ parse(char *w, FILE *f)
|
308
|
316
|
case '&': /* sublabel */
|
309
|
317
|
if(!makelabel(sublabel(subw, p.scope, w + 1)))
|
310
|
318
|
return error("Invalid sublabel", w);
|
311
|
|
- findlabel(p.scope)->refs++;
|
312
|
319
|
litlast = 0;
|
313
|
320
|
break;
|
314
|
321
|
case '#': /* literals hex */
|