Commit f9042ec9 authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

msi: Use a binary search to find sql keywords.

parent a8ae03f2
......@@ -39,6 +39,8 @@ struct Keyword {
int tokenType; /* The token value for this keyword */
};
#define MAX_TOKEN_LEN 11
static const WCHAR ABORT_W[] = { 'A','B','O','R','T',0 };
static const WCHAR AFTER_W[] = { 'A','F','T','E','R',0 };
static const WCHAR ALTER_W[] = { 'A','L','T','E','R',0 };
......@@ -264,20 +266,33 @@ static const Keyword aKeywordTable[] = {
#define KEYWORD_COUNT ( sizeof aKeywordTable/sizeof (Keyword) )
/*
** Comparison function for binary search.
*/
static int compKeyword(const void *m1, const void *m2){
const Keyword *k1 = m1, *k2 = m2;
return strcmpiW( k1->zName, k2->zName );
}
/*
** This function looks up an identifier to determine if it is a
** keyword. If it is a keyword, the token code of that keyword is
** returned. If the input is not a keyword, TK_ID is returned.
*/
static int sqliteKeywordCode(const WCHAR *z, int n){
UINT i;
WCHAR str[MAX_TOKEN_LEN+1];
Keyword key, *r;
for(i=0; i<KEYWORD_COUNT; i++)
{
if(strncmpiW(z, aKeywordTable[i].zName, n))
continue;
if(lstrlenW(aKeywordTable[i].zName) == n )
return aKeywordTable[i].tokenType;
}
if( n>MAX_TOKEN_LEN )
return TK_ID;
memcpy( str, z, n*sizeof (WCHAR) );
str[n] = 0;
key.tokenType = 0;
key.zName = str;
r = bsearch( &key, aKeywordTable, KEYWORD_COUNT, sizeof (Keyword), compKeyword );
if( r )
return r->tokenType;
return TK_ID;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment