From 6d08b4d647cb120c6b25eeee6caeb15566c441f7 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 20 Jul 2004 12:45:22 +0000 Subject: [PATCH] Add the '%ifdef' capability to lemon. Other minor changes. (CVS 1836) FossilOrigin-Name: 522ff721ccc33c4b89072fed4e451f0df82e8140 --- manifest | 22 ++++++------- manifest.uuid | 2 +- src/btree.c | 12 ++++--- src/build.c | 17 +++------- src/pager.c | 4 ++- src/sqliteInt.h | 3 +- test/join3.test | 3 +- tool/lemon.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++-- 8 files changed, 115 insertions(+), 35 deletions(-) diff --git a/manifest b/manifest index 4efd8fb609..c00f724760 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Handle\squotes\son\sthe\stable\sname\sin\sTABLE.*\sterms\sin\sSELECT\sstatements.\nTicket\s#680.\s(CVS\s1833) -D 2004-07-20T01:45:20 +C Add\sthe\s'%ifdef'\scapability\sto\slemon.\s\sOther\sminor\schanges.\s(CVS\s1836) +D 2004-07-20T12:45:22 F Makefile.in 4a5e570a9e2d35b09c31b3cf01b78cea764ade4b F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -27,9 +27,9 @@ F sqlite3.def 7610bb4092dcfa7db8fe6d9a92d3e51adce23566 F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a F src/attach.c 5e37aaac0907edad5da8ba785b94f04fbb4003d7 F src/auth.c 60db23b98bb94c8b0178180faaf49dc116674217 -F src/btree.c 3ed3c19e43bb243f502ee614f6ad0a52e53362a7 +F src/btree.c 23d4cbe6f612a77738caa636c48dd38e1efdfd76 F src/btree.h 934d0ad30b5b419e9291a11da878be349df2277e -F src/build.c 1d9a72adb51a544131b51bd4101846f781f3266d +F src/build.c a4b1e80b13c570c7c962f500fa58045450b5a0cd F src/date.c e1bb384a7856c18dce9cadb0afbe6934ba5ddb00 F src/delete.c e81545e546f6bc87d7508a93a09ca70695265af3 F src/encode.c a876af473d1d636faa3dca51c7571f2e007eea37 @@ -51,7 +51,7 @@ F src/os_unix.c ee607890d9062b51e27de56e9cb14a7f5a598d8c F src/os_unix.h f3097815e041e82e24d92505e1ff61ba24172d13 F src/os_win.c 54181eb73cb4783c4241feca9eaa490768b39008 F src/os_win.h babd4e912967c6b09088cfe38a45e8005a07ba44 -F src/pager.c 3fb0fa47da302a6de2a613f755d0b637932b27d4 +F src/pager.c 53a310a7539c7550dc7cbad8e46c62926a40fb31 F src/pager.h 269b6cfc114dba0148203446e41dd19f9647dd53 F src/parse.y 51c8e696276c409618e66a4ccf316fcff245506e F src/pragma.c 8326df8c400f573eb43004dfb8e53e5102acb3e4 @@ -60,7 +60,7 @@ F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3 F src/select.c aefda626660086addca4ce85c34aeef5d0f44c25 F src/shell.c ebec5da57ea401f4886eefc790917b939d94d595 F src/sqlite.h.in aaf46c8d458efd8aca694ec4f18c6ecf616ee55e -F src/sqliteInt.h aeae6793d1db335ec1179ad9f26b0affc0ec658a +F src/sqliteInt.h 788b13a74c421ab68068ab7fe50ec68ee22db1be F src/table.c 4521c278892f60e4d630788c0ea5cf4db1e75c49 F src/tclsqlite.c 62848128011e59291902c6e5c6f910c05956fcbb F src/test1.c 004885b49a7b5a594192f137c671135920f64c94 @@ -125,7 +125,7 @@ F test/intpkey.test c8efd06db62b8b27216558ef439cc867d113cfec F test/ioerr.test 7d087bfd1a1a53442940e000df936e0df0c5b886 F test/join.test 9ef6aabaac9de51d5fc41e68d1f4355da05a84cd F test/join2.test c97e4c5aa65dea462145529e58212a709b4722b8 -F test/join3.test 8d989e52413199065bd630b3d0a6b2329d173099 +F test/join3.test 67dc0d7c8dab3fff25796d0f3c3fd9c999aeded3 F test/join4.test 8dec387d06b3a4685e1104048065cf5236b99b93 F test/lastinsert.test 31382f88b9b0270333ac9e4a17f2c2f4732da718 F test/laststmtchanges.test 417aa27eb2b5cdfafb46e390e2c9ddd0a20eba43 @@ -185,7 +185,7 @@ F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 F test/view.test ca5c296989d3045f121be9a67588ff88c64874a8 F test/where.test 9c5752b807b78078fab8da6f52e689832579ca20 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b -F tool/lemon.c db6a3bfaf3388c0f7aea3adb5e05acddcd427016 +F tool/lemon.c b771c5147d0e7eb3240f5be754deb5c87d0aae6a F tool/lempar.c 0b5e7a58634e0d448929b8e85f7981c2aa708d57 F tool/memleak.awk b744b6109566206c746d826f6ecdba34662216bc F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8 @@ -237,7 +237,7 @@ F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P 4d77037be34b357d24d18d1e13b5f0df580b83ff -R 05526bc7d5efd58f2fcd959a0a53ce11 +P 826b6797a9f08c69b9378cb403d746e91a54dcde +R 81fe5ff7dba086ebc8b9e46590e3934b U drh -Z 539496cd59c5e82424ba168888729c0a +Z b94ed056d995c2892f36ab8ddb7dedb9 diff --git a/manifest.uuid b/manifest.uuid index 89ab41d68c..34c0f72d67 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -826b6797a9f08c69b9378cb403d746e91a54dcde \ No newline at end of file +522ff721ccc33c4b89072fed4e451f0df82e8140 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 4179a2cd81..6bfe24cf43 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.176 2004/06/30 08:20:16 danielk1977 Exp $ +** $Id: btree.c,v 1.177 2004/07/20 12:45:22 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to @@ -410,9 +410,13 @@ static u8 *findCell(MemPage *pPage, int iCell){ static u8 *findOverflowCell(MemPage *pPage, int iCell){ int i; for(i=pPage->nOverflow-1; i>=0; i--){ - if( pPage->aOvfl[i].idx<=iCell ){ - if( pPage->aOvfl[i].idx==iCell ){ - return pPage->aOvfl[i].pCell; + int k; + struct _OvflCell *pOvfl; + pOvfl = &pPage->aOvfl[i]; + k = pOvfl->idx; + if( k<=iCell ){ + if( k==iCell ){ + return pOvfl->pCell; } iCell--; } diff --git a/src/build.c b/src/build.c index 871b996759..2acf308501 100644 --- a/src/build.c +++ b/src/build.c @@ -23,7 +23,7 @@ ** ROLLBACK ** PRAGMA ** -** $Id: build.c,v 1.238 2004/07/19 17:25:25 drh Exp $ +** $Id: build.c,v 1.239 2004/07/20 12:45:22 drh Exp $ */ #include "sqliteInt.h" #include @@ -951,18 +951,9 @@ CollSeq *sqlite3FindCollSeq( int create ){ CollSeq *pColl = findCollSeqEntry(db, zName, nName, create); - if( pColl ) switch( enc ){ - case SQLITE_UTF8: - break; - case SQLITE_UTF16LE: - pColl = &pColl[1]; - break; - case SQLITE_UTF16BE: - pColl = &pColl[2]; - break; - default: - assert(!"Cannot happen"); - } + assert( SQLITE_UTF8==1 && SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 ); + assert( enc>=SQLITE_UTF8 && enc<=SQLITE_UTF16BE ); + if( pColl ) pColl += enc-1; return pColl; } diff --git a/src/pager.c b/src/pager.c index 2361d9fe58..3f5b9fff63 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.150 2004/07/19 22:08:10 drh Exp $ +** @(#) $Id: pager.c,v 1.151 2004/07/20 12:45:22 drh Exp $ */ #include "os.h" /* Must be first to enable large file support */ #include "sqliteInt.h" @@ -1468,7 +1468,9 @@ int sqlite3pager_open( sqliteFree(zFullPathname); strcpy(&pPager->zJournal[nameLen], "-journal"); pPager->fd = fd; +#if OS_UNIX pPager->fd.pPager = pPager; +#endif pPager->journalOpen = 0; pPager->useJournal = useJournal && !memDb; pPager->stmtOpen = 0; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index e8b15e564b..6296648272 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.305 2004/07/15 13:37:22 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.306 2004/07/20 12:45:22 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -464,7 +464,6 @@ struct Column { u8 notNull; /* True if there is a NOT NULL constraint */ u8 isPrimKey; /* True if this column is part of the PRIMARY KEY */ char affinity; /* One of the SQLITE_AFF_... values */ - u8 dottedName; /* True if zName contains a "." character */ }; /* diff --git a/test/join3.test b/test/join3.test index 19bdf01cde..7ce51f4089 100644 --- a/test/join3.test +++ b/test/join3.test @@ -13,13 +13,14 @@ # This file implements tests for joins, including outer joins, where # there are a large number of tables involved in the join. # -# $Id: join3.test,v 1.2 2004/07/19 17:25:25 drh Exp $ +# $Id: join3.test,v 1.3 2004/07/20 12:45:22 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # An unrestricted join # +catch {unset ::result} set result {} for {set N 1} {$N<=40} {incr N} { lappend result $N diff --git a/tool/lemon.c b/tool/lemon.c index 5940950f83..f816de2309 100644 --- a/tool/lemon.c +++ b/tool/lemon.c @@ -1311,6 +1311,31 @@ void memory_error(){ exit(1); } +static int nDefine = 0; /* Number of -D options on the command line */ +static char **azDefine = 0; /* Name of the -D macros */ + +/* This routine is called with the argument to each -D command-line option. +** Add the macro defined to the azDefine array. +*/ +static void handle_D_option(char *z){ + char **paz; + nDefine++; + azDefine = realloc(azDefine, sizeof(azDefine[0])*nDefine); + if( azDefine==0 ){ + fprintf(stderr,"out of memory\n"); + exit(1); + } + paz = &azDefine[nDefine-1]; + *paz = malloc( strlen(z)+1 ); + if( *paz==0 ){ + fprintf(stderr,"out of memory\n"); + exit(1); + } + strcpy(*paz, z); + for(z=*paz; *z && *z!='='; z++){} + *z = 0; +} + /* The main program. Parse the command line and do it... */ int main(argc,argv) @@ -1327,10 +1352,12 @@ char **argv; static struct s_options options[] = { {OPT_FLAG, "b", (char*)&basisflag, "Print only the basis in report."}, {OPT_FLAG, "c", (char*)&compress, "Don't compress the action table."}, + {OPT_FSTR, "D", (char*)handle_D_option, "Define an %ifdef macro."}, {OPT_FLAG, "g", (char*)&rpflag, "Print grammar without actions."}, {OPT_FLAG, "m", (char*)&mhflag, "Output a makeheaders compatible file"}, {OPT_FLAG, "q", (char*)&quiet, "(Quiet) Don't print the report file."}, - {OPT_FLAG, "s", (char*)&statistics, "Print parser stats to standard output."}, + {OPT_FLAG, "s", (char*)&statistics, + "Print parser stats to standard output."}, {OPT_FLAG, "x", (char*)&version, "Print the version number."}, {OPT_FLAG,0,0,0} }; @@ -1629,7 +1656,7 @@ FILE *err; int errcnt = 0; int j; for(j=0; op[j].label; j++){ - if( strcmp(&argv[i][1],op[j].label)==0 ) break; + if( strncmp(&argv[i][1],op[j].label,strlen(op[j].label))==0 ) break; } v = argv[i][0]=='-' ? 1 : 0; if( op[j].label==0 ){ @@ -1642,6 +1669,8 @@ FILE *err; *((int*)op[j].arg) = v; }else if( op[j].type==OPT_FFLAG ){ (*(void(*)())(op[j].arg))(v); + }else if( op[j].type==OPT_FSTR ){ + (*(void(*)())(op[j].arg))(&argv[i][2]); }else{ if( err ){ fprintf(err,"%smissing argument on switch.\n",emsg); @@ -2271,6 +2300,57 @@ to follow the previous rule."); } } +/* Run the proprocessor over the input file text. The global variables +** azDefine[0] through azDefine[nDefine-1] contains the names of all defined +** macros. This routine looks for "%ifdef" and "%ifndef" and "%endif" and +** comments them out. Text in between is also commented out as appropriate. +*/ +static preprocess_input(char *z){ + int i, j, k, n; + int exclude = 0; + int start; + int lineno = 1; + int start_lineno; + for(i=0; z[i]; i++){ + if( z[i]=='\n' ) lineno++; + if( z[i]!='%' || (i>0 && z[i-1]!='\n') ) continue; + if( strncmp(&z[i],"%endif",6)==0 && isspace(z[i+6]) ){ + if( exclude ){ + exclude--; + if( exclude==0 ){ + for(j=start; j