Overview
SHA1 Hash: | a67fbd784d355e407c0025f20084a3d39ae4e1b0 |
---|---|
Date: | 2007-11-03 04:39:37 |
User: | drh |
Comment: | Add support for built-in variables in subscript. |
Timelines: | ancestors | descendants | both | trunk |
Other Links: | files | ZIP archive | manifest |
Tags And Properties
- branch=trunk inherited from [a28c83647d]
- sym-trunk inherited from [a28c83647d]
Changes
[hide diffs]Modified src/subscript.c from [4016468877] to [a19913b6c5].
@@ -615,10 +615,24 @@ { "puts", 4, putsCmd, 0 }, { "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 */ struct Subscript *SbS_Create(void){ @@ -667,12 +681,15 @@ case SBSTT_STRING: { 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 ){ int i = (upr+lwr)/2; @@ -682,10 +699,33 @@ break; }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); }else if( pVal->flags & SBSVAL_EXEC ){