Index: tool/mkkeywordhash.c ================================================================== --- tool/mkkeywordhash.c +++ tool/mkkeywordhash.c @@ -334,12 +334,12 @@ int i, j, k, h; int bestSize, bestCount; int count; int nChar; int totalLen = 0; - int aHash[1000]; /* 1000 is much bigger than nKeyword */ - char zText[2000]; + int aKWHash[1000]; /* 1000 is much bigger than nKeyword */ + char zKWText[2000]; /* Remove entries from the list of keywords that have mask==0 */ for(i=j=0; isubstrId ) continue; - memcpy(&zText[k], p->zName, p->len); + memcpy(&zKWText[k], p->zName, p->len); k += p->len; if( j+p->len>70 ){ printf("%*s */\n", 74-j, ""); j = 0; } if( j==0 ){ - printf(" /* "); + printf("/* "); j = 8; } printf("%s", p->zName); j += p->len; } if( j>0 ){ printf("%*s */\n", 74-j, ""); } - printf(" static const char zText[%d] = {\n", nChar); - zText[nChar] = 0; + printf("static const char zKWText[%d] = {\n", nChar); + zKWText[nChar] = 0; for(i=j=0; i68 ){ printf("\n"); j = 0; } } if( j>0 ) printf("\n"); - printf(" };\n"); + printf("};\n"); - printf(" static const unsigned char aHash[%d] = {\n", bestSize); + printf("/* aKWHash[i] is the hash value for the i-th keyword */\n"); + printf("static const unsigned char aKWHash[%d] = {\n", bestSize); for(i=j=0; i12 ){ printf("\n"); j = 0; } } - printf("%s };\n", j==0 ? "" : "\n"); + printf("%s};\n", j==0 ? "" : "\n"); - printf(" static const unsigned char aNext[%d] = {\n", nKeyword); + printf("/* aKWNext[] forms the hash collision chain. If aKWHash[i]==0\n"); + printf("** then the i-th keyword has no more hash collisions. Otherwise,\n"); + printf("** the next keyword with the same hash is aKWHash[i]-1. */\n"); + printf("static const unsigned char aKWNext[%d] = {\n", nKeyword); for(i=j=0; i12 ){ printf("\n"); j = 0; } } - printf("%s };\n", j==0 ? "" : "\n"); + printf("%s};\n", j==0 ? "" : "\n"); - printf(" static const unsigned char aLen[%d] = {\n", nKeyword); + printf("/* aKWLen[i] is the length (in bytes) of the i-th keyword */\n"); + printf("static const unsigned char aKWLen[%d] = {\n", nKeyword); for(i=j=0; i12 ){ printf("\n"); j = 0; } } - printf("%s };\n", j==0 ? "" : "\n"); + printf("%s};\n", j==0 ? "" : "\n"); - printf(" static const unsigned short int aOffset[%d] = {\n", nKeyword); + printf("/* aKWOffset[i] is the index into zKWText[] of the start of\n"); + printf("** the text for the i-th keyword. */\n"); + printf("static const unsigned short int aKWOffset[%d] = {\n", nKeyword); for(i=j=0; i12 ){ printf("\n"); j = 0; } } - printf("%s };\n", j==0 ? "" : "\n"); + printf("%s};\n", j==0 ? "" : "\n"); - printf(" static const unsigned char aCode[%d] = {\n", nKeyword); + printf("/* aKWCode[i] is the parser symbol code for the i-th keyword */\n"); + printf("static const unsigned char aKWCode[%d] = {\n", nKeyword); for(i=j=0; i=5 ){ printf("\n"); j = 0; } } - printf("%s };\n", j==0 ? "" : "\n"); - + printf("%s};\n", j==0 ? "" : "\n"); + printf("/* Check to see if z[0..n-1] is a keyword. If it is, write the\n"); + printf("** parser symbol code for that keyword into *pType. Always\n"); + printf("** return the integer n (the length of the token). */\n"); + printf("static int keywordCode(const char *z, int n, int *pType){\n"); printf(" int i, j;\n"); printf(" const char *zKW;\n"); printf(" if( n>=2 ){\n"); printf(" i = ((charMap(z[0])*4) ^ (charMap(z[n-1])*3) ^ n) %% %d;\n", bestSize); - printf(" for(i=((int)aHash[i])-1; i>=0; i=((int)aNext[i])-1){\n"); - printf(" if( aLen[i]!=n ) continue;\n"); + printf(" for(i=((int)aKWHash[i])-1; i>=0; i=((int)aKWNext[i])-1){\n"); + printf(" if( aKWLen[i]!=n ) continue;\n"); printf(" j = 0;\n"); - printf(" zKW = &zText[aOffset[i]];\n"); + printf(" zKW = &zKWText[aKWOffset[i]];\n"); printf("#ifdef SQLITE_ASCII\n"); printf(" while( j