From: drh Date: Thu, 17 Mar 2011 16:45:50 +0000 (+0000) Subject: Update the implementation of ".testctrl" in the command-line shell to use X-Git-Tag: version-3.7.6~94 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d416fe799569ff1a570009187d218e5d0dc7c86c;p=thirdparty%2Fsqlite.git Update the implementation of ".testctrl" in the command-line shell to use a look-up table rather than a long sequence of if-elses. Shorten source code lines of shell.c to 80 characters or less. FossilOrigin-Name: 54bacb95dd6e2d6ac4971391a40484ccb9126d29 --- diff --git a/manifest b/manifest index a9110cb28d..13539c3ab4 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 -C Comment\senhancement\sto\sbetter\sexplain\sthe\slogic\sin\sthe\s"x\sIS\sNULL"\s\noptimization. -D 2011-03-17T01:58:21.662 +C Update\sthe\simplementation\sof\s".testctrl"\sin\sthe\scommand-line\sshell\sto\suse\na\slook-up\stable\srather\sthan\sa\slong\ssequence\sof\sif-elses.\s\sShorten\ssource\ncode\slines\sof\sshell.c\sto\s80\scharacters\sor\sless. +D 2011-03-17T16:45:50.769 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 27701a1653595a1f2187dc61c8117e00a6c1d50f F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -180,7 +180,7 @@ F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 F src/resolve.c 1c0f32b64f8e3f555fe1f732f9d6f501a7f05706 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697 F src/select.c d24406c45dd2442eb2eeaac413439066b149c944 -F src/shell.c 75ec746b9661e9b5cf956ef4cd9833c0545ef037 +F src/shell.c 4a5e0ad845475c84881f0b25b1abba2ddaab0a72 F src/sqlite.h.in 369c767e6b9f101d63d8e4c5e40279f975ccec08 F src/sqlite3ext.h c90bd5507099f62043832d73f6425d8d5c5da754 F src/sqliteInt.h 2cea3e47997e3f4d9b4f1ce62f99c35be1b5a586 @@ -917,14 +917,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 2353176811f752a16c1f2351a3d3431919b062a9 -R ceaf122e76347e0b045461abe9cbfd0f +P 869f894798a65f8bc0e0b083866a784fa0189f68 +R a8def7fc552253bddf0337de8f57667b U drh -Z 6e216a7f32c457388fcc438c6cd929ce +Z f32baca0676f04528da8db7e35d99aa0 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) -iD8DBQFNgWrBoxKgR168RlERAg4rAJ0ZbgbEbrWUz8iIL7EI7v8AcMLRpQCfZka3 -v7cQP/zk4VcNw9IakEHnWtw= -=fknb +iD8DBQFNgjx3oxKgR168RlERAkZlAJ9g0EAzYOwFcF/NGcxGCGlF65eaGACfcZkt +bA9BP3Fet3XmbiRxAgQtxR0= +=Yzeg -----END PGP SIGNATURE----- diff --git a/manifest.uuid b/manifest.uuid index 9f597732d4..4be64fc574 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -869f894798a65f8bc0e0b083866a784fa0189f68 \ No newline at end of file +54bacb95dd6e2d6ac4971391a40484ccb9126d29 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 9d51aa95dc..7eed290918 100644 --- a/src/shell.c +++ b/src/shell.c @@ -2173,29 +2173,45 @@ static int do_meta_command(char *zLine, struct callback_data *p){ }else if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){ + static const struct { + const char *zCtrlName; /* Name of a test-control option */ + int ctrlCode; /* Integer code for that option */ + } aCtrl[] = { + { "prng_save", SQLITE_TESTCTRL_PRNG_SAVE }, + { "prng_restore", SQLITE_TESTCTRL_PRNG_RESTORE }, + { "prng_reset", SQLITE_TESTCTRL_PRNG_RESET }, + { "bitvec_test", SQLITE_TESTCTRL_BITVEC_TEST }, + { "fault_install", SQLITE_TESTCTRL_FAULT_INSTALL }, + { "benign_malloc_hooks", SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS }, + { "pending_byte", SQLITE_TESTCTRL_PENDING_BYTE }, + { "assert", SQLITE_TESTCTRL_ASSERT }, + { "always", SQLITE_TESTCTRL_ALWAYS }, + { "reserve", SQLITE_TESTCTRL_RESERVE }, + { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS }, + { "iskeyword", SQLITE_TESTCTRL_ISKEYWORD }, + { "pghdrsz", SQLITE_TESTCTRL_PGHDRSZ }, + { "scratchmalloc", SQLITE_TESTCTRL_SCRATCHMALLOC }, + }; int testctrl = -1; int rc = 0; + int i, n; open_db(p); - /* convert testctrl text option to value. allow only the first - ** three characters of the option to be used or the numerical - ** value. */ - if( strncmp( azArg[1], "prng_save", 6 )==0 ) testctrl = SQLITE_TESTCTRL_PRNG_SAVE; - else if( strncmp( azArg[1], "prng_restore", 10 )==0 ) testctrl = SQLITE_TESTCTRL_PRNG_RESTORE; - else if( strncmp( azArg[1], "prng_reset", 10 )==0 ) testctrl = SQLITE_TESTCTRL_PRNG_RESET; - else if( strncmp( azArg[1], "bitvec_test", 6 )==3 ) testctrl = SQLITE_TESTCTRL_BITVEC_TEST; - else if( strncmp( azArg[1], "fault_install", 6 )==3 ) testctrl = SQLITE_TESTCTRL_FAULT_INSTALL; - else if( strncmp( azArg[1], "benign_malloc_hooks", 3 )==0 ) testctrl = SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS; - else if( strncmp( azArg[1], "pending_byte", 3 )==0 ) testctrl = SQLITE_TESTCTRL_PENDING_BYTE; - else if( strncmp( azArg[1], "assert", 3 )==0 ) testctrl = SQLITE_TESTCTRL_ASSERT; - else if( strncmp( azArg[1], "always", 3 )==0 ) testctrl = SQLITE_TESTCTRL_ALWAYS; - else if( strncmp( azArg[1], "reserve", 3 )==0 ) testctrl = SQLITE_TESTCTRL_RESERVE; - else if( strncmp( azArg[1], "optimizations", 3 )==0 ) testctrl = SQLITE_TESTCTRL_OPTIMIZATIONS; - else if( strncmp( azArg[1], "iskeyword", 3 )==0 ) testctrl = SQLITE_TESTCTRL_ISKEYWORD; - else if( strncmp( azArg[1], "pghdrsz", 3 )==0 ) testctrl = SQLITE_TESTCTRL_PGHDRSZ; - else if( strncmp( azArg[1], "scratchmalloc", 3 )==0 ) testctrl = SQLITE_TESTCTRL_SCRATCHMALLOC; - else testctrl = atoi(azArg[1]); - + /* convert testctrl text option to value. allow any unique prefix + ** of the option name, or a numerical value. */ + n = strlen(azArg[1]); + for(i=0; iSQLITE_TESTCTRL_LAST) ){ fprintf(stderr,"Error: invalid testctrl option: %s\n", azArg[1]); }else{ @@ -2209,7 +2225,8 @@ static int do_meta_command(char *zLine, struct callback_data *p){ rc = sqlite3_test_control(testctrl, p->db, opt); printf("%d (0x%08x)\n", rc, rc); } else { - fprintf(stderr,"Error: testctrl %s takes a single int option\n", azArg[1]); + fprintf(stderr,"Error: testctrl %s takes a single int option\n", + azArg[1]); } break; @@ -2233,7 +2250,8 @@ static int do_meta_command(char *zLine, struct callback_data *p){ rc = sqlite3_test_control(testctrl, opt); printf("%d (0x%08x)\n", rc, rc); } else { - fprintf(stderr,"Error: testctrl %s takes a single unsigned int option\n", azArg[1]); + fprintf(stderr,"Error: testctrl %s takes a single unsigned" + " int option\n", azArg[1]); } break; @@ -2245,7 +2263,8 @@ static int do_meta_command(char *zLine, struct callback_data *p){ rc = sqlite3_test_control(testctrl, opt); printf("%d (0x%08x)\n", rc, rc); } else { - fprintf(stderr,"Error: testctrl %s takes a single int option\n", azArg[1]); + fprintf(stderr,"Error: testctrl %s takes a single int option\n", + azArg[1]); } break; @@ -2257,7 +2276,8 @@ static int do_meta_command(char *zLine, struct callback_data *p){ rc = sqlite3_test_control(testctrl, opt); printf("%d (0x%08x)\n", rc, rc); } else { - fprintf(stderr,"Error: testctrl %s takes a single char * option\n", azArg[1]); + fprintf(stderr,"Error: testctrl %s takes a single char * option\n", + azArg[1]); } break; #endif @@ -2267,7 +2287,8 @@ static int do_meta_command(char *zLine, struct callback_data *p){ case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS: case SQLITE_TESTCTRL_SCRATCHMALLOC: default: - fprintf(stderr,"Error: CLI support for testctrl %s not implemented\n", azArg[1]); + fprintf(stderr,"Error: CLI support for testctrl %s not implemented\n", + azArg[1]); break; } } @@ -2278,7 +2299,9 @@ static int do_meta_command(char *zLine, struct callback_data *p){ sqlite3_busy_timeout(p->db, atoi(azArg[1])); }else - if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0 && nArg==2 ){ + if( HAS_TIMER && c=='t' && n>=5 && strncmp(azArg[0], "timer", n)==0 + && nArg==2 + ){ enableTimer = booleanValue(azArg[1]); }else @@ -2465,7 +2488,9 @@ static int process_input(struct callback_data *p, FILE *in){ } } if( zSql ){ - if( !_all_whitespace(zSql) ) fprintf(stderr, "Error: incomplete SQL: %s\n", zSql); + if( !_all_whitespace(zSql) ){ + fprintf(stderr, "Error: incomplete SQL: %s\n", zSql); + } free(zSql); } free(zLine);