mirror of
https://github.com/fachat/xa65.git
synced 2025-04-08 18:37:12 +00:00
Fix the handling of comments/colons within preprocessor replacements (as
they appear there as well).
This commit is contained in:
parent
42310222ad
commit
e39d58fc6d
36
xa/src/xa.c
36
xa/src/xa.c
@ -92,6 +92,7 @@ static int x_init(void);
|
||||
static int pass1(void);
|
||||
static int pass2(void);
|
||||
static int puttmp(int);
|
||||
static int puttmpw(int);
|
||||
static int puttmps(signed char *, int);
|
||||
static void chrput(int);
|
||||
static int getline(char *);
|
||||
@ -457,7 +458,7 @@ int main(int argc,char *argv[])
|
||||
if(verbose) logout(out);
|
||||
|
||||
er=pp_open(ifile);
|
||||
puttmp(0);
|
||||
puttmpw(0);
|
||||
puttmp(T_FILE);
|
||||
puttmp(0);
|
||||
puttmp(0);
|
||||
@ -678,7 +679,9 @@ static int pass2(void)
|
||||
|
||||
while((ner_max==0 || ner<ner_max) && afile->mn.tmpe<afile->mn.tmpz)
|
||||
{
|
||||
l=afile->mn.tmp[afile->mn.tmpe++];
|
||||
// get the length of the entry (now two byte - need to handle the sign)
|
||||
l = afile->mn.tmp[afile->mn.tmpe++];
|
||||
l |= afile->mn.tmp[afile->mn.tmpe++] << 8;
|
||||
ll=l;
|
||||
|
||||
// printf("%p: l=%d first=%02x\n", afile->mn.tmp+afile->mn.tmpe-1, l, 0xff & afile->mn.tmp[afile->mn.tmpe]);
|
||||
@ -842,14 +845,14 @@ static int pass1(void)
|
||||
{
|
||||
if(er==E_OKDEF)
|
||||
{
|
||||
if(!(er=puttmp(l)))
|
||||
if(!(er=puttmpw(l)))
|
||||
er=puttmps(o,l);
|
||||
} else
|
||||
if(er==E_NOLINE)
|
||||
er=E_OK;
|
||||
} else
|
||||
{
|
||||
if(!(er=puttmp(-l)))
|
||||
if(!(er=puttmpw(-l)))
|
||||
er=puttmps(o,l);
|
||||
}
|
||||
}
|
||||
@ -1054,6 +1057,21 @@ static int puttmp(int c)
|
||||
return(er);
|
||||
}
|
||||
|
||||
static int puttmpw(int c)
|
||||
{
|
||||
int er=E_NOMEM;
|
||||
|
||||
//printf("puttmp: %02x -> %p \n",0xff & c, afile->mn.tmp+afile->mn.tmpz);
|
||||
|
||||
if(afile->mn.tmpz<TMPMEM-1)
|
||||
{
|
||||
afile->mn.tmp[afile->mn.tmpz++]= c & 0xff;
|
||||
afile->mn.tmp[afile->mn.tmpz++]= (c >> 8) & 0xff;
|
||||
er=E_OK;
|
||||
}
|
||||
return(er);
|
||||
}
|
||||
|
||||
static int puttmps(signed char *s, int l)
|
||||
{
|
||||
int i=0,er=E_NOMEM;
|
||||
@ -1099,20 +1117,18 @@ static int getline(char *s)
|
||||
|
||||
if(ec==E_NEWLINE)
|
||||
{
|
||||
puttmp(0);
|
||||
puttmpw(0);
|
||||
puttmp(T_LINE);
|
||||
puttmp((filep->fline)&255);
|
||||
puttmp(((filep->fline)>>8)&255);
|
||||
puttmpw(filep->fline);
|
||||
ec=E_OK;
|
||||
|
||||
}
|
||||
else
|
||||
if(ec==E_NEWFILE)
|
||||
{
|
||||
puttmp(0);
|
||||
puttmpw(0);
|
||||
puttmp(T_FILE);
|
||||
puttmp((filep->fline)&255);
|
||||
puttmp(((filep->fline)>>8)&255);
|
||||
puttmpw(filep->fline);
|
||||
puttmps((signed char*)&(filep->fname), sizeof(filep->fname));
|
||||
ec=E_OK;
|
||||
}
|
||||
|
22
xa/src/xap.c
22
xa/src/xap.c
@ -711,12 +711,24 @@ int pp_replace(char *to, char *ti, int a,int b)
|
||||
while(t[0]!='\0' && t[0] != ';')
|
||||
{
|
||||
// skip over the whitespace
|
||||
// comment handling is NASTY NASTY NASTY
|
||||
// but I currently don't see another way, as comments and colons
|
||||
// can (and do) appear in preprocessor replacements
|
||||
char quotefl = 0;
|
||||
while(!isalpha(t[0]) && t[0]!='_') {
|
||||
if(t[0]=='\0' || (t[0] == ';' && !quotefl))
|
||||
char commentfl = 0;
|
||||
while((t[0] != 0) && (commentfl || ((!isalpha(t[0]) && t[0]!='_')))) {
|
||||
if (t[0]=='\0') {
|
||||
break; /*return(E_OK);*/
|
||||
else
|
||||
{
|
||||
} else
|
||||
{
|
||||
if (t[0] == ';' && !quotefl) {
|
||||
commentfl = 1;
|
||||
}
|
||||
if (t[0] == ':' && !quotefl && !ca65 && !masm) {
|
||||
// note that both ca65 and masm allow colons in comments
|
||||
// so in these cases we cannot reset the comment handling here
|
||||
commentfl = 0;
|
||||
}
|
||||
if (quotefl) {
|
||||
// ignore other quotes within a quote
|
||||
if (t[0] == quotefl) {
|
||||
@ -728,7 +740,7 @@ int pp_replace(char *to, char *ti, int a,int b)
|
||||
}
|
||||
t++;
|
||||
ti++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// determine the length of the name
|
||||
|
15
xa/src/xat.c
15
xa/src/xat.c
@ -23,6 +23,7 @@
|
||||
/* enable this to turn on (copious) optimization output */
|
||||
/* #define DEBUG_AM */
|
||||
#undef LISTING_DEBUG
|
||||
#undef DEBUG_CONV
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
@ -431,7 +432,8 @@ fprintf(stderr, "- p1 %d starting -\n", pc[segment]);
|
||||
/* copy the buffer */
|
||||
memcpy(t+tlen, t+6+inp, l-inp);
|
||||
|
||||
#if 0
|
||||
#ifdef DEBUG_CONV
|
||||
printf("t_conv s:%s\n",s);
|
||||
printf("t_conv (er=%d, t=%p, tlen=%d, inp=%d):",er, t, tlen, inp);
|
||||
for(i=0;i<l+6;i++)
|
||||
printf("%02x,",t[i] & 0xff);
|
||||
@ -1010,7 +1012,7 @@ fprintf(stderr, "guessing instruction length is %d\n", bl);
|
||||
if(segment==SEG_ABS) pc[SEG_TEXT]+=bl;
|
||||
|
||||
/* adjust length by token listing buffer length */
|
||||
#if 0
|
||||
#ifdef DEBUG_CONV
|
||||
printf("converted: (er=%d, t=%p, ll=%d):",er, t, *ll);
|
||||
for(i=0;i<*ll;i++)
|
||||
printf("%02x,",t[i] & 0xff);
|
||||
@ -1073,6 +1075,15 @@ int t_p2_l(signed char *t, int *ll, int *al)
|
||||
*ll=(*ll) - tlen;
|
||||
}
|
||||
|
||||
if (tlen > l)
|
||||
{
|
||||
// that is corrupt data and should not happen
|
||||
printf("t_p2_l (ll=%d, t=%p):", *ll, t);
|
||||
for(int i=0;i<l;i++)
|
||||
printf("%02x,",t[i] & 0xff);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (*ll != 0) {
|
||||
er = t_p2(t+tlen, ll, 1, al);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user