127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
#define MAC_BNOT 0xFFC8
#define MAC_CAT 0xFFC9
#define MAC_BIT 0xFFCA
#define MAC_VERSION 0xFFE0
#define MAC_DEFINE 0xFFE1
#define MAC_INCLUDE 0xFFE2
#define MAC_CALL 0xFFE3
#define MAC_UNDEFINED 0xFFFF
static TokenList*add_macro(void) {
TokenList*o=malloc(sizeof(TokenList));
if(!o) fatal("Allocation failed\n");
o->t=tokent;
o->v=tokenv;
|
>
|
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
#define MAC_BNOT 0xFFC8
#define MAC_CAT 0xFFC9
#define MAC_BIT 0xFFCA
#define MAC_VERSION 0xFFE0
#define MAC_DEFINE 0xFFE1
#define MAC_INCLUDE 0xFFE2
#define MAC_CALL 0xFFE3
#define MAC_APPEND 0xFFE4
#define MAC_UNDEFINED 0xFFFF
static TokenList*add_macro(void) {
TokenList*o=malloc(sizeof(TokenList));
if(!o) fatal("Allocation failed\n");
o->t=tokent;
o->v=tokenv;
|
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
|
}
}
ParseError("Invalid Hero Mesh key name: %s\n",tokenstr);
break;
}
}
static void define_macro(Uint16 name) {
int i;
TokenList**t;
if(glohash[name].id<0xC000) fatal("Confusion\n");
if(glohash[name].id<MAX_MACRO+0xC000) {
free_macro(macros[i=glohash[name].id-0xC000]);
macros[i]=0;
} else {
for(i=0;i<MAX_MACRO;i++) if(!macros[i]) break;
if(i==MAX_MACRO) ParseError("Too many macro definitions\n");
}
glohash[name].id=i+0xC000;
t=macros+i;
i=1;
for(;;) {
nxttok1();
if(tokent==TF_MACRO+TF_OPEN && ++i>65000) ParseError("Too much macro nesting\n");
if(tokent==TF_MACRO+TF_CLOSE && !--i) break;
*t=add_macro();
t=&(*t)->next;
}
}
static void begin_include_file(const char*name) {
InputStack*nxt=inpstack;
inpstack=malloc(sizeof(InputStack));
if(!inpstack) fatal("Allocation failed\n");
inpstack->classfp=classfp;
|
|
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
|
}
}
ParseError("Invalid Hero Mesh key name: %s\n",tokenstr);
break;
}
}
static void define_macro(Uint16 name,Uint8 q) {
int i;
TokenList**t;
if(main_options['M']) printf("M< %04X %04X \"%s\" %d\n",name,glohash[name].id,glohash[name].txt,q);
if(glohash[name].id<0xC000) fatal("Confusion\n");
if(glohash[name].id<MAX_MACRO+0xC000) {
i=glohash[name].id-0xC000;
if(q) {
free_macro(macros[i]);
macros[i]=0;
}
} else {
q=1;
for(i=0;i<MAX_MACRO;i++) if(!macros[i]) break;
if(i==MAX_MACRO) ParseError("Too many macro definitions\n");
}
glohash[name].id=i+0xC000;
t=macros+i;
if(!q) while(*t) t=&(*t)->next;
i=1;
for(;;) {
nxttok1();
if(main_options['L'] && main_options['M']) {
int j;
printf("*: %5d %04X %08X \"",i,tokent,tokenv);
for(j=0;tokenstr[j];j++) {
if(tokenstr[j]<32 || tokenstr[j]>126) printf("<%02X>",tokenstr[j]&255);
else putchar(tokenstr[j]);
}
printf("\"\n");
}
if(tokent==TF_MACRO+TF_OPEN && ++i>65000) ParseError("Too much macro nesting\n");
if(tokent==TF_MACRO+TF_CLOSE && !--i) break;
*t=add_macro();
t=&(*t)->next;
}
if(main_options['M']) printf("M> %04X %04X %p\n",name,glohash[name].id,macros[glohash[name].id-0xC000]);
}
static void begin_include_file(const char*name) {
InputStack*nxt=inpstack;
inpstack=malloc(sizeof(InputStack));
if(!inpstack) fatal("Allocation failed\n");
inpstack->classfp=classfp;
|
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
|
case MAC_DEFINE:
if(!macros) {
macros=calloc(MAX_MACRO,sizeof(TokenList*));
if(!macros) fatal("Allocation failed\n");
}
nxttok();
if(!(tokent&TF_NAME) || tokenv!=OP_STRING) ParseError("String literal expected\n");
define_macro(look_hash_mac());
goto again;
case MAC_INCLUDE:
if(macstack) ParseError("Cannot use {include} inside of a macro\n");
nxttok1();
if(tokent==TF_MACRO && tokenv==1) ReturnToken(TF_EOF,0);
if(!(tokent&TF_NAME) || tokenv!=OP_STRING) ParseError("String literal expected\n");
n=look_hash_mac();
nxttok1();
if(tokent!=TF_MACRO+TF_CLOSE) ParseError("Too many macro arguments\n");
begin_include_file(glohash[n].txt);
goto again;
case MAC_CALL:
nxttok();
if(!(tokent&TF_NAME) || tokenv!=OP_STRING) ParseError("String literal expected\n");
tokenv=look_hash_mac();
goto call;
case MAC_UNDEFINED:
ParseError("Undefined macro: {%s}\n",tokenstr);
break;
default:
ParseError("Strange macro token: 0x%04X\n",glohash[tokenv].id);
}
if(main_options['M']) printf("M-\n");
|
|
>
>
>
>
>
>
>
>
>
|
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
|
case MAC_DEFINE:
if(!macros) {
macros=calloc(MAX_MACRO,sizeof(TokenList*));
if(!macros) fatal("Allocation failed\n");
}
nxttok();
if(!(tokent&TF_NAME) || tokenv!=OP_STRING) ParseError("String literal expected\n");
define_macro(look_hash_mac(),1);
goto again;
case MAC_INCLUDE:
if(macstack) ParseError("Cannot use {include} inside of a macro\n");
nxttok1();
if(tokent==TF_MACRO && tokenv==1) ReturnToken(TF_EOF,0);
if(!(tokent&TF_NAME) || tokenv!=OP_STRING) ParseError("String literal expected\n");
n=look_hash_mac();
nxttok1();
if(tokent!=TF_MACRO+TF_CLOSE) ParseError("Too many macro arguments\n");
begin_include_file(glohash[n].txt);
goto again;
case MAC_CALL:
nxttok();
if(!(tokent&TF_NAME) || tokenv!=OP_STRING) ParseError("String literal expected\n");
tokenv=look_hash_mac();
goto call;
case MAC_APPEND:
if(!macros) {
macros=calloc(MAX_MACRO,sizeof(TokenList*));
if(!macros) fatal("Allocation failed\n");
}
nxttok();
if(!(tokent&TF_NAME) || tokenv!=OP_STRING) ParseError("String literal expected\n");
define_macro(look_hash_mac(),0);
goto again;
case MAC_UNDEFINED:
ParseError("Undefined macro: {%s}\n",tokenstr);
break;
default:
ParseError("Strange macro token: 0x%04X\n",glohash[tokenv].id);
}
if(main_options['M']) printf("M-\n");
|
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
|
strcpy(tokenstr,"bnot"); glohash[look_hash_mac()].id=MAC_BNOT;
strcpy(tokenstr,"cat"); glohash[look_hash_mac()].id=MAC_CAT;
strcpy(tokenstr,"bit"); glohash[look_hash_mac()].id=MAC_BIT;
strcpy(tokenstr,"version"); glohash[look_hash_mac()].id=MAC_VERSION;
strcpy(tokenstr,"define"); glohash[look_hash_mac()].id=MAC_DEFINE;
strcpy(tokenstr,"include"); glohash[look_hash_mac()].id=MAC_INCLUDE;
strcpy(tokenstr,"call"); glohash[look_hash_mac()].id=MAC_CALL;
if(main_options['L']) {
for(;;) {
nxttok();
printf("** %5d %04X %08X \"",linenum,tokent,tokenv);
for(i=0;tokenstr[i];i++) {
if(tokenstr[i]<32 || tokenstr[i]>126) printf("<%02X>",tokenstr[i]&255);
else putchar(tokenstr[i]);
|
>
|
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
|
strcpy(tokenstr,"bnot"); glohash[look_hash_mac()].id=MAC_BNOT;
strcpy(tokenstr,"cat"); glohash[look_hash_mac()].id=MAC_CAT;
strcpy(tokenstr,"bit"); glohash[look_hash_mac()].id=MAC_BIT;
strcpy(tokenstr,"version"); glohash[look_hash_mac()].id=MAC_VERSION;
strcpy(tokenstr,"define"); glohash[look_hash_mac()].id=MAC_DEFINE;
strcpy(tokenstr,"include"); glohash[look_hash_mac()].id=MAC_INCLUDE;
strcpy(tokenstr,"call"); glohash[look_hash_mac()].id=MAC_CALL;
strcpy(tokenstr,"append"); glohash[look_hash_mac()].id=MAC_APPEND;
if(main_options['L']) {
for(;;) {
nxttok();
printf("** %5d %04X %08X \"",linenum,tokent,tokenv);
for(i=0;tokenstr[i];i++) {
if(tokenstr[i]<32 || tokenstr[i]>126) printf("<%02X>",tokenstr[i]&255);
else putchar(tokenstr[i]);
|