Differences From:
File
src/subscript.c
part of check-in
[92f6081d11]
- Add basic math operators to subscript.
by
drh on
2007-11-03 04:23:43.
[view]
To:
File
src/subscript.c
part of check-in
[a67fbd784d]
- Add support for built-in variables in subscript.
by
drh on
2007-11-03 04:39:37.
[view]
@@ -616,8 +616,22 @@
{ "set", 3, setCmd, 0 },
{ "sub", 3, bopCmd, (void*)SBSOP_SUB },
};
+/*
+** A table of built-in string and integer values
+*/
+static const struct {
+ const char *zVar;
+ int nVar;
+ int *pI;
+ char *z;
+} aVars[] = {
+ { "okAdmin", 7, &g.okAdmin, 0 },
+ { "okSetup", 7, &g.okSetup, 0 },
+};
+
+
/*
** Create a new subscript interpreter
*/
@@ -668,10 +682,13 @@
rc = SbS_Push(p, (char*)&zScript[1], n-2, 0);
break;
}
case SBSTT_VERB: {
+ /* First look up the verb in the hash table */
const SbSValue *pVal = sbs_fetch(&p->symTab, (char*)zScript, n);
if( pVal==0 ){
+ /* If the verb is not in the hash table, look for a
+ ** built-in command */
int upr = sizeof(aBuiltin)/sizeof(aBuiltin[0]) - 1;
int lwr = 0;
rc = SBS_ERROR;
while( upr>=lwr ){
@@ -683,8 +700,31 @@
}else if( c<0 ){
upr = i-1;
}else{
lwr = i+1;
+ }
+ }
+ if( upr<lwr ){
+ /* If it is not a built-in command, look for a built-in
+ ** variable */
+ upr = sizeof(aVars)/sizeof(aVars[0]) - 1;
+ lwr = 0;
+ while( upr>=lwr ){
+ int i = (upr+lwr)/2;
+ int c = strncmp(zScript, aVars[i].zVar, n);
+ if( c==0 ){
+ if( aVars[i].pI ){
+ SbS_PushInt(p, *aVars[i].pI);
+ }else{
+ SbS_Push(p, aVars[i].z, -1, 0);
+ }
+ rc = SBS_OK;
+ break;
+ }else if( c<0 ){
+ upr = i-1;
+ }else{
+ lwr = i+1;
+ }
}
}
}else if( pVal->flags & SBSVAL_VERB ){
rc = pVal->u.verb.xVerb(p, pVal->u.verb.pArg);