2
// The data required for writing the various not-quoted escape sequences.
4
// This file is shared between GRFCodec and NFORenum.
5
// NFORenum defines NFORENUM. GRFCodec does not.
10
#define START_ESCAPES()\
18
#define ESCAPE(byte,str,action,off)\
19
{(char)0x##byte,(char*)("\\" str),(char)0x##action,off},
21
#define ESCAPE_79(byte,str,off)\
22
ESCAPE(byte,str,7,off)
24
#define ESCAPE_AD(byte,str,action,off,adtl)\
25
{(char)0x##byte,(char*)("\\" str),(char)0x##action,off},
27
#define ESCAPE_OVR(byte,str,action,ovr)\
28
{(char)0x##byte,(char*)("\\" str),(char)0x##action,0},
32
#define START_ESCAPES()\
38
bool (*additional)(const U8*,uint);\
39
bool (*override)(const U8*,uint);\
42
#define ESCAPE(byte,str,action,off)\
43
{(char)0x##byte,(char*)("\\" str),(char)0x##action,off,NULL,NULL},
45
#define ESCAPE_79(byte,str,off)\
46
ESCAPE(byte,str,7,off) ESCAPE(byte,str,9,off)
48
#define ESCAPE_AD(byte,str,action,off,adtl)\
49
{(char)0x##byte,(char*)("\\" str),(char)0x##action,off,__ESC_AD__##adtl,NULL},
51
#define ESCAPE_OVR(byte,str,action,ovr)\
52
{(char)0x##byte,(char*)("\\" str),(char)0x##action,0,NULL,__ESC_OVR__##ovr},
54
#define CALLBACK_AD(name)\
55
bool __ESC_AD__##name(const U8*data,uint len)
56
#define CALLBACK_OVR(name)\
57
bool __ESC_OVR__##name(const U8*data,uint pos)
61
#define END_ESCAPES() };\
62
static const unsigned int num_esc=sizeof(escapes)/sizeof(escapes[0]);
66
// ***********************************************************************
67
// Define callback functions for ESCAPE_* here
68
// Use the same value for the argument to the CALLBACK_* macro and the last
69
// argument to ESCAPE_*
70
// The signature for CALLBACK_AD is:
71
// bool func(const U8*data, uint len)
72
// The signature for CALLBACK_OVR is:
73
// bool func(const U8*data, uint pos)
74
// ***********************************************************************
77
return len==9&&data[2]==0&&data[4]==0xFE&&data[5]==0xFF;
81
if(pos<7||!(data[3]&0x80)||data[3]==0x80||data[3]==0x83)return false;
82
uint w = 1<<((data[3]>>2)&3);
83
uint loc=4;//Start at first <var>
84
while(true){//read <var> [<param>] <varadjust> [<op> ...]. loc reports byte to be checked.
85
if((data[loc++/*<var>*/]&0xE0)==0x60)loc++;//<param>
86
if(loc>=pos)return false;
87
if(!(data[loc]&0x20))return false;//end of advanced
88
if(data[loc++/*<shift>*/]&0xC0)
89
loc+=2*w;//<add> and <div>/<mod>
91
if(loc==pos)return true;//This is an operation byte
92
if(loc++/*<op>*/>pos)return false;//past proposed op byte
100
// ***********************************************************************
101
// Define escape sequences here.
102
// The arguments to ESCAPE* are:
103
// byte: the byte value for this escape sequence, in hex.
104
// str: the string for this escape sequence, excluding the \.
105
// action: the action for this escape sequence, eg 2, 7, D, &c.
106
// Note that 7 and 9 are usually paired, with ESCAPE_79, which does
107
// not take an action argument.
108
// off: the offset in the action where this escape sequence appears
109
// ESCAPE_AD takes an additional argument; the CALLBACK to call if the
110
// byte, action, and off checks all pass.
111
// EXCAPE_OVR takes an argument in place of off, the CALLBACK to call
112
// instead of running the off check.
113
// ***********************************************************************
115
ESCAPE_OVR(00,"2+",2,Is2Op)
116
ESCAPE_OVR(01,"2-",2,Is2Op)
117
ESCAPE_OVR(02,"2<",2,Is2Op)
118
ESCAPE_OVR(03,"2>",2,Is2Op)
119
ESCAPE_OVR(04,"2u<",2,Is2Op)
120
ESCAPE_OVR(05,"2u>",2,Is2Op)
121
ESCAPE_OVR(06,"2/",2,Is2Op)
122
ESCAPE_OVR(07,"2%",2,Is2Op)
123
ESCAPE_OVR(08,"2u/",2,Is2Op)
124
ESCAPE_OVR(09,"2u%",2,Is2Op)
125
ESCAPE_OVR(0A,"2*",2,Is2Op)
126
ESCAPE_OVR(0B,"2&",2,Is2Op)
127
ESCAPE_OVR(0C,"2|",2,Is2Op)
128
ESCAPE_OVR(0D,"2^",2,Is2Op)
129
ESCAPE_OVR(0E,"2sto",2,Is2Op)
130
ESCAPE_OVR(0E,"2s",2,Is2Op)
131
ESCAPE_OVR(0F,"2rst",2,Is2Op)
132
ESCAPE_OVR(0F,"2r",2,Is2Op)
133
ESCAPE_OVR(10,"2psto",2,Is2Op)
134
ESCAPE_OVR(11,"2ror",2,Is2Op)
135
ESCAPE_OVR(11,"2rot",2,Is2Op)
136
ESCAPE_OVR(12,"2cmp",2,Is2Op)
137
ESCAPE_OVR(13,"2ucmp",2,Is2Op)
138
ESCAPE_OVR(14,"2<<",2,Is2Op)
139
ESCAPE_OVR(15,"2u>>",2,Is2Op)
140
ESCAPE_OVR(16,"2>>",2,Is2Op)
150
ESCAPE_79(08,"7gG",3)
151
ESCAPE_79(09,"7GG",3)
152
ESCAPE_79(0A,"7gg",3)
161
ESCAPE(05,"Du<<",D,2)
170
ESCAPE_AD(00,"DR",D,3,IsGRM)
171
ESCAPE_AD(01,"DF",D,3,IsGRM)
172
ESCAPE_AD(02,"DC",D,3,IsGRM)
173
ESCAPE_AD(03,"DM",D,3,IsGRM)
174
ESCAPE_AD(04,"DnF",D,3,IsGRM)
175
ESCAPE_AD(05,"DnC",D,3,IsGRM)
176
ESCAPE_AD(06,"DO",D,3,IsGRM)