126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
+
|
**
** results in nByte being set to 2.
*/
static int thNextCommand(Th_Interp*, const char *z, int n, int *pN);
static int thNextEscape (Th_Interp*, const char *z, int n, int *pN);
static int thNextVarname(Th_Interp*, const char *z, int n, int *pN);
static int thNextNumber (Th_Interp*, const char *z, int n, int *pN);
static int thNextInteger (Th_Interp*, const char *z, int n, int *pN);
static int thNextSpace (Th_Interp*, const char *z, int n, int *pN);
/*
** Given that the input string (z, n) contains a language construct of
** the relevant type (a command enclosed in [], an escape sequence
** like "\xFF" or a variable reference like "${varname}", perform
** substitution on the string and store the resulting string in
|
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
|
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
|
{">", OP_GT, 5, ARG_NUMBER},
{"&", OP_BITWISE_AND, 8, ARG_INTEGER},
{"^", OP_BITWISE_XOR, 9, ARG_INTEGER},
{"|", OP_BITWISE_OR, 10, ARG_INTEGER},
{0,0,0,0}
};
/*
** The first part of the string (zInput,nInput) contains an integer.
** Set *pnVarname to the number of bytes in the numeric string.
*/
static int thNextInteger(
Th_Interp *interp,
const char *zInput,
int nInput,
int *pnLiteral
){
int i = 0;
int seenDot = 0;
int (*isdigit)(char) = th_isdigit;
if( nInput>2 ){
if( zInput[1]=='x' || zInput[1]=='X' ){
i=2;
isdigit = th_ishexdig;
}else if( zInput[1]=='o' || zInput[1]=='O' ){
i=2;
isdigit = th_isoctdig;
}else if( zInput[1]=='b' || zInput[1]=='B' ){
i=2;
isdigit = th_isbindig;
}
}
for(; i<nInput; i++){
char c = zInput[i];
if( !isdigit(c) ){
i = 0;
break;
}
}
*pnLiteral = i;
return TH_OK;
}
/*
** The first part of the string (zInput,nInput) contains a number.
** Set *pnVarname to the number of bytes in the numeric string.
*/
static int thNextNumber(
Th_Interp *interp,
const char *zInput,
int nInput,
int *pnLiteral
){
int i = 0;
int seenDot = 0;
int (*isdigit)(char) = th_isdigit;
if( nInput>2 ){
if( zInput[0]=='0' && (zInput[1]=='x' || zInput[1]=='X') ){
i=2;
isdigit = th_ishexdig;
}
if( zInput[0]=='0' && (zInput[1]=='o' || zInput[1]=='O') ){
i=2;
isdigit = th_isoctdig;
}
if( zInput[0]=='0' && (zInput[1]=='b' || zInput[1]=='B') ){
i=2;
isdigit = th_isbindig;
}
}
for(; i<nInput; i++){
char c = zInput[i];
if( (seenDot || c!='.') && !isdigit(c) ) break;
if( (seenDot || c!='.') && !th_isdigit(c) ) break;
if( c=='.' ) seenDot = 1;
}
*pnLiteral = i;
return TH_OK;
}
/*
|
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
|
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
|
+
+
+
+
+
+
-
-
+
+
|
if( th_isspace(c) ){ /* White-space */
i++;
}else{
Expr *pNew = (Expr *)Th_Malloc(interp, sizeof(Expr));
const char *z = &zExpr[i];
switch (c) {
case '0':
if( (i+2<nExpr) && th_isalpha(zExpr[i+1]) ){
thNextInteger(interp, z, nExpr-i, &pNew->nValue);
break;
}
/* fall through */
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
thNextNumber(interp, z, nExpr-i, &pNew->nValue);
break;
case '$':
thNextVarname(interp, z, nExpr-i, &pNew->nValue);
break;
|
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
|
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
|
+
+
+
|
}
int th_isspecial(char c){
return (aCharProp[(unsigned char)c] & 0x11);
}
int th_isalnum(char c){
return (aCharProp[(unsigned char)c] & 0x0A);
}
int th_isalpha(char c){
return (aCharProp[(unsigned char)c] & 0x08);
}
int th_ishexdig(char c){
return (aCharProp[(unsigned char)c] & 0x20);
}
int th_isoctdig(char c){
return ((c|7) == '7');
}
int th_isbindig(char c){
|
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
|
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
|
-
-
+
+
-
-
-
-
+
+
+
+
-
+
-
+
|
i += 2;
base = 2;
isdigit = th_isbindig;
}
}
}
for(; i<n; i++){
int shift;
if( !isdigit(z[i]) ){
char c = z[i];
if( !isdigit(c) ){
Th_ErrorMessage(interp, "expected integer, got: \"", z, n);
return TH_ERROR;
}
if( z[i]>='a' ){
shift = 'a' - 10;
}else if( z[i]>='A' ){
shift = 'A' - 10;
if( c>='a' ){
c -= 'a'-10;
}else if( c>='A' ){
c -= 'A'-10;
}else{
shift = '0';
c -= '0';
}
iOut = iOut * base + (z[i] - shift);
iOut = iOut * base + c;
}
if( n>0 && z[0]=='-' ){
iOut *= -1;
}
*piOut = iOut;
|