From: larrybr Date: Wed, 13 Apr 2022 03:48:28 +0000 (+0000) Subject: Extension interface cleanup, and rename MetaCommand to DotCommand (to better match... X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=34ddefc41977036e4a3a7536241acda2fc4d0e0c;p=thirdparty%2Fsqlite.git Extension interface cleanup, and rename MetaCommand to DotCommand (to better match docs) FossilOrigin-Name: f78d7b8b89b667daba486fdb67de105bd8524203cc44bb02c3cb94acd85560e9 --- diff --git a/ext/misc/tclshext.c.in b/ext/misc/tclshext.c.in index b27c698cf9..37ff3486d6 100644 --- a/ext/misc/tclshext.c.in +++ b/ext/misc/tclshext.c.in @@ -317,25 +317,25 @@ DERIVED_METHOD(DotCmdRC, runScript, ScriptSupport,TclSS, return DCR_Error; /* Silent error because it should not happen. */ } -DERIVED_METHOD(void, destruct, MetaCommand,TclCmd, 0, ()){ +DERIVED_METHOD(void, destruct, DotCommand,TclCmd, 0, ()){ /* Nothing to do, instance data is static. */ (void)(pThis); } -static DERIVED_METHOD(void, destruct, MetaCommand,UnkCmd, 0, ()); +static DERIVED_METHOD(void, destruct, DotCommand,UnkCmd, 0, ()); DERIVED_METHOD(void, destruct, ScriptSupport,TclSS, 0, ()){ /* Nothing to do, instance data is static. */ (void)(pThis); } -DERIVED_METHOD(const char *, name, MetaCommand,TclCmd, 0,()){ +DERIVED_METHOD(const char *, name, DotCommand,TclCmd, 0,()){ return "tcl"; } -DERIVED_METHOD(const char *, name, MetaCommand,UnkCmd, 0,()){ +DERIVED_METHOD(const char *, name, DotCommand,UnkCmd, 0,()){ return "unknown"; } -DERIVED_METHOD(const char *, help, MetaCommand,TclCmd, 1,(const char *zHK)){ +DERIVED_METHOD(const char *, help, DotCommand,TclCmd, 1,(const char *zHK)){ (void)(pThis); if( zHK==0 ) return @@ -356,13 +356,13 @@ DERIVED_METHOD(const char *, help, MetaCommand,TclCmd, 1,(const char *zHK)){ return 0; } -DERIVED_METHOD(const char *, help, MetaCommand,UnkCmd, 1,(const char *zHK)); +DERIVED_METHOD(const char *, help, DotCommand,UnkCmd, 1,(const char *zHK)); -DERIVED_METHOD(DotCmdRC, argsCheck, MetaCommand,TclCmd, 3, +DERIVED_METHOD(DotCmdRC, argsCheck, DotCommand,TclCmd, 3, (char **pzErrMsg, int nArgs, char *azArgs[])){ return DCR_Ok; } -DERIVED_METHOD(DotCmdRC, argsCheck, MetaCommand,UnkCmd, 3, +DERIVED_METHOD(DotCmdRC, argsCheck, DotCommand,UnkCmd, 3, (char **pzErrMsg, int nArgs, char *azArgs[])){ return DCR_Ok; } @@ -523,7 +523,7 @@ static DotCmdRC runTclREPL(Tcl_Interp *interp, char **pzErrMsg){ return DCR_Ok; } -DERIVED_METHOD(DotCmdRC, execute, MetaCommand,TclCmd, 4, +DERIVED_METHOD(DotCmdRC, execute, DotCommand,TclCmd, 4, (ShellExState *psx, char **pzErrMsg, int nArgs, char *azArgs[])){ FILE *out = SHX_HELPER(currentOutputFile)(psx); TclCmd *ptc = (TclCmd *)pThis; @@ -545,7 +545,7 @@ DERIVED_METHOD(DotCmdRC, execute, MetaCommand,TclCmd, 4, } } -DERIVED_METHOD(DotCmdRC, execute, MetaCommand,UnkCmd, 4, +DERIVED_METHOD(DotCmdRC, execute, DotCommand,UnkCmd, 4, (ShellExState *psx, char **pzErrMsg, int nArgs, char *azArgs[])){ Tcl_Interp *interp = getInterp(); Tcl_Obj **ppo; @@ -590,9 +590,9 @@ DERIVED_METHOD(DotCmdRC, execute, MetaCommand,UnkCmd, 4, } } -/* Define MetaCommand v-tables initialized to reference most above methods. */ -MetaCommand_IMPLEMENT_VTABLE(TclCmd, tclcmd_methods); -MetaCommand_IMPLEMENT_VTABLE(UnkCmd, unkcmd_methods); +/* Define DotCommand v-tables initialized to reference most above methods. */ +DotCommand_IMPLEMENT_VTABLE(TclCmd, tclcmd_methods); +DotCommand_IMPLEMENT_VTABLE(UnkCmd, unkcmd_methods); /* Define ScriptSupport v-table initialized to reference the others. */ ScriptSupport_IMPLEMENT_VTABLE(TclSS, tclss_methods); @@ -614,11 +614,11 @@ INSTANCE_END(UnkCmd) unkcmd = { &unkcmd_methods }; -static DERIVED_METHOD(void, destruct, MetaCommand,UnkCmd, 0, ()){ +static DERIVED_METHOD(void, destruct, DotCommand,UnkCmd, 0, ()){ (void)(pThis); } -DERIVED_METHOD(const char *, help, MetaCommand,UnkCmd, 1,(const char *zHK)){ +DERIVED_METHOD(const char *, help, DotCommand,UnkCmd, 1,(const char *zHK)){ (void)(pThis); if( !zHK ) return @@ -813,21 +813,21 @@ static int registerAdHocCommand(/* ShellExState */ void *pv, /* C implementation of TCL unknown to (maybe) delegate to dot commands */ static int unknownDotDelegate(void *pvSS, Tcl_Interp *interp, - int nArgs, const char *azArgs[]){ + int nArgs, const char *azArgs[]){ const char *name = (nArgs>1 && *azArgs[1]=='.')? azArgs[1]+1 : 0; ShellExState *psx = (ShellExState *)pvSS; - MetaCommand *pmc = 0; + DotCommand *pdc = 0; int nFound = 0; int ia, rc; - if( name ) pmc = SHX_HELPER(findMetaCommand)(name, psx, &nFound); - if( pmc==(MetaCommand*)&tclcmd && nArgs==2 ){ + if( name ) pdc = SHX_HELPER(findDotCommand)(name, psx, &nFound); + if( pdc==(DotCommand*)&tclcmd && nArgs==2 ){ /* Will not do a nested REPL, just silently semi-fake it. */ return TCL_OK; } - if( pmc && nFound==1 ){ + if( pdc && nFound==1 ){ /* Run the dot command and interpret its returns. */ - DotCmdRC drc = SHX_HELPER(runMetaCommand)(pmc, (char **)azArgs+1, + DotCmdRC drc = SHX_HELPER(runDotCommand)(pdc, (char **)azArgs+1, nArgs-1, psx); if( drc==DCR_Ok ) return TCL_OK; else if( drc==DCR_Return ){ @@ -1154,10 +1154,10 @@ int sqlite3_tclshext_init( } } } - rc = SHX_API(registerMetaCommand)(psx, sqlite3_tclshext_init, - (MetaCommand *)&unkcmd); - rc = SHX_API(registerMetaCommand)(psx, sqlite3_tclshext_init, - (MetaCommand *)&tclcmd); + rc = SHX_API(registerDotCommand)(psx, sqlite3_tclshext_init, + (DotCommand *)&unkcmd); + rc = SHX_API(registerDotCommand)(psx, sqlite3_tclshext_init, + (DotCommand *)&tclcmd); if( rc==SQLITE_OK && (rc = Tcl_BringUp( #ifdef SHELL_ENABLE_TK diff --git a/manifest b/manifest index 8dbf590a7f..5df1eeb5ab 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Further\sclarification\sof\sTcl\sextension\sintro. -D 2022-04-12T10:06:21.517 +C Extension\sinterface\scleanup,\sand\srename\sMetaCommand\sto\sDotCommand\s(to\sbetter\smatch\sdocs) +D 2022-04-13T03:48:28.689 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -330,7 +330,7 @@ F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 F ext/misc/spellfix.c 94df9bbfa514a563c1484f684a2df3d128a2f7209a84ca3ca100c68a0163e29f F ext/misc/sqlar.c 0ace5d3c10fe736dc584bf1159a36b8e2e60fab309d310cd8a0eecd9036621b6 F ext/misc/stmt.c 35063044a388ead95557e4b84b89c1b93accc2f1c6ddea3f9710e8486a7af94a -F ext/misc/tclshext.c.in c29c3aa45cc477106aa6995308c8e1f8fe68e6ff4b10b2d906acefbbd62c4196 +F ext/misc/tclshext.c.in 93228dbc48e6b300aa3d8632d2a061edaafcab60a83664ae7549e5e682e3b48b F ext/misc/templatevtab.c 8a16a91a5ceaccfcbd6aaaa56d46828806e460dd194965b3f77bf38f14b942c4 F ext/misc/totype.c fa4aedeb07f66169005dffa8de3b0a2b621779fd44f85c103228a42afa71853b F ext/misc/uint.c 053fed3bce2e89583afcd4bf804d75d659879bbcedac74d0fa9ed548839a030b @@ -557,8 +557,8 @@ F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c F src/resolve.c 18d99e7146852d6064559561769fcca0743eb32b14a97da6dbed373a30ee0e76 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 F src/select.c 7c106b3f36d483242b0a9c696614cd53d6f29e1ac81da6a3f0e9ea92f4211cc3 -F src/shell.c.in 7b5eab1401536e6df969664ba85bbeb8f757a586839dfd52b5ef903e1798f1fc -F src/shext_linkage.h 4f58ea112273f3e6769221739b7160852cf0d7cdd4ee757f6c696e90fb7ffcb9 +F src/shell.c.in 244d069485fd1ce481ea19302b4f4b24e2a603991fc450778814142c55788a50 +F src/shext_linkage.h 41e7e665fffd125b38b8211dc650233d4fe54941acd8177f23d3deb9d6f70154 F src/sqlite.h.in 2a35f62185eb5e7ecc64a2f68442b538ce9be74f80f28a00abc24837edcf1c17 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h f49e28c25bd941e79794db5415fdf7b202deb3bc072ed6f1ed273d578703684e @@ -607,8 +607,8 @@ F src/test_quota.h 2a8ad1952d1d2ca9af0ce0465e56e6c023b5e15d F src/test_rtree.c 671f3fae50ff116ef2e32a3bf1fe21b5615b4b7b F src/test_schema.c f5d6067dfc2f2845c4dd56df63e66ee826fb23877855c785f75cc2ca83fd0c1b F src/test_server.c a2615049954cbb9cfb4a62e18e2f0616e4dc38fe -F src/test_shellext.c fa658ee13e39d2b4bbb49c1b7fe060990ee0928e0412ffcdecbf98ddba3ef12e -F src/test_shellext.cpp 95d1f67570683b0cc61e6b5a447aadba39ffe10fffa7d6015ba855fb05f10865 +F src/test_shellext.c 9a1ca8619f036daa6b23d18e0fec1c75721be05e4eb6fe3ad3282dabae625592 +F src/test_shellext.cpp 741d9ebd864e058b7b03c3ecf3ede059075464871af5ed9822da792488dfeaf4 F src/test_sqllog.c 540feaea7280cd5f926168aee9deb1065ae136d0bbbe7361e2ef3541783e187a F src/test_superlock.c 4839644b9201da822f181c5bc406c0b2385f672e F src/test_syscall.c 1073306ba2e9bfc886771871a13d3de281ed3939 @@ -1887,7 +1887,7 @@ F tool/mkopcodec.tcl 33d20791e191df43209b77d37f0ff0904620b28465cca6990cf8d60da61 F tool/mkopcodeh.tcl 5dab48c49a25452257494e9601702ab63adaba6bd54a9b382615fa52661c8f8c F tool/mkopts.tcl 680f785fdb09729fd9ac50632413da4eadbdf9071535e3f26d03795828ab07fa F tool/mkpragmatab.tcl bd07bd59d45d0f3448e123d6937e9811195f9908a51e09d774609883055bfd3d -F tool/mkshellc.tcl e6fd439b1c2934d666cd43d4d1698e223dbbcf40f5c824a898454b5437242493 x +F tool/mkshellc.tcl 59d53f5667a2946042be81519371e1305a2bc954a3292a29c430fca6dbd6e412 x F tool/mksourceid.c 36aa8020014aed0836fd13c51d6dc9219b0df1761d6b5f58ff5b616211b079b9 F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 F tool/mksqlite3c-noext.tcl 4f7cfef5152b0c91920355cbfc1d608a4ad242cb819f1aea07f6d0274f584a7f @@ -1953,8 +1953,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6ccdd9b7519bf8945c5187742c8ea9c335cb6a89b87f6b005bf2ba9dc6890b2f -R 4a0f912c8f980bd74e9d39fc8fe464fe +P 29ab6e90372d216a0cb9d86861c804d356cd2f11ad835443da08651bec0da398 +R 1510482cb2995d161d76a9fbb3e87be4 U larrybr -Z e768dbcccb579b99dc457c9712116706 +Z cc8481583ec9f4daf594610712a79a07 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 10efda26e0..afdf965666 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -29ab6e90372d216a0cb9d86861c804d356cd2f11ad835443da08651bec0da398 \ No newline at end of file +f78d7b8b89b667daba486fdb67de105bd8524203cc44bb02c3cb94acd85560e9 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index a090b89f63..692973fb6e 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -1281,13 +1281,13 @@ typedef struct ShExtInfo { * arrays. The dbShell DB keeps indices into these arrays and into * an array of this struct's instances to facilitate lookup by name * of pointers to the implementations. */ - int numMetaCommands; - MetaCommand **ppMetaCommands; + int numDotCommands; + DotCommand **ppDotCommands; int numExportHandlers; ExportHandler **ppExportHandlers; int numImportHandlers; ImportHandler **ppImportHandlers; - MetaCommand *pUnknown; /* .unknown registered for this extension */ + DotCommand *pUnknown; /* .unknown registered for this extension */ } ShExtInfo; #endif @@ -1428,7 +1428,7 @@ typedef struct ShellInState { ShellEventNotify eventHandler; } *pSubscriptions; /* The current shell event subscriptions */ u8 bDbDispatch; /* Cache fact of dbShell dispatch table */ - MetaCommand *pUnknown; /* Last registered "unknown" dot command */ + DotCommand *pUnknown; /* Last registered "unknown" dot command */ #endif ShellExState *pSXS; /* Pointer to companion, exposed shell state */ @@ -1442,7 +1442,7 @@ typedef struct ShellInState { /* ** This procedure updates the bSafeMode flag after completion of any -** operation (meta-command, SQL submission, or script execution) that +** operation (dot-command, SQL submission, or script execution) that ** counts as one for which safe mode might be suspended. ** bSafeModeFuture has 3 states salient here: ** equal 0 => Safe mode is and will remain inactive. @@ -1619,7 +1619,7 @@ static void shellPutsFunc( ** the caller of the shell's main, "do shell things" entry point. ** ** It is an error, (perhaps with only minor effect such as memory leak), -** for a meta-command to call this function while it holds resources in +** for a dot-command to call this function while it holds resources in ** need of freeing. Instead, it should be called before acquiring them. ** ** The return is true if failing, 0 otherwise. @@ -4795,7 +4795,7 @@ static int run_schema_dump_query( /* Configure help text generation to have coalesced secondary help lines * with trailing newlines on all help lines. This allow help text to be - * representable as an array of two C-strings per meta-command. + * representable as an array of two C-strings per dot-command. */ DISPATCH_CONFIG[ HELP_COALESCE=1 @@ -4809,7 +4809,7 @@ DISPATCH_CONFIG[ /* Forward references */ static int showHelp(FILE *out, const char *zPattern, ShellExState *); static DotCmdRC process_input(ShellInState *psx); -static MetaCommand *builtInCommand(int ix); +static DotCommand *builtInCommand(int ix); /* ** Read the content of file zName into memory obtained from sqlite3_malloc64() @@ -7952,9 +7952,9 @@ static ShExtInfo *pending_ext_info(ShellInState *psi){ return &psi->pShxLoaded[ixpe]; } -/* Register a meta-command, to be called during extension load/init. */ -static int register_meta_command(ShellExState *p, - ExtensionId eid, MetaCommand *pMC){ +/* Register a dot-command, to be called during extension load/init. */ +static int register_dot_command(ShellExState *p, + ExtensionId eid, DotCommand *pMC){ ShellInState *psi = ISS(p); ShExtInfo *psei = pending_ext_info(psi); const char *zSql @@ -7965,23 +7965,23 @@ static int register_meta_command(ShellExState *p, else{ const char *zName = pMC->pMethods->name(pMC); sqlite3_stmt *pStmt; - int nc = psei->numMetaCommands; + int nc = psei->numDotCommands; int rc; if( psei->extId!=0 && psei->extId!=eid ) return SQLITE_MISUSE; psei->extId = eid; rc = sqlite3_prepare_v2(p->dbShell, zSql, -1, &pStmt, 0); if( rc!=SQLITE_OK ) return rc; - psei->ppMetaCommands - = sqlite3_realloc(psei->ppMetaCommands, (nc+1)*sizeof(MetaCommand *)); - shell_check_oom(psei->ppMetaCommands); + psei->ppDotCommands + = sqlite3_realloc(psei->ppDotCommands, (nc+1)*sizeof(DotCommand *)); + shell_check_oom(psei->ppDotCommands); sqlite3_bind_text(pStmt, 1, zName, -1, 0); sqlite3_bind_int(pStmt, 2, ie); sqlite3_bind_int(pStmt, 3, nc); rc = sqlite3_step(pStmt); sqlite3_finalize(pStmt); if( rc==SQLITE_DONE ){ - psei->ppMetaCommands[nc++] = pMC; - psei->numMetaCommands = nc; + psei->ppDotCommands[nc++] = pMC; + psei->numDotCommands = nc; notify_subscribers(psi, NK_NewDotCommand, pMC); if( strcmp("unknown", zName)==0 ){ psi->pUnknown = pMC; @@ -7989,7 +7989,7 @@ static int register_meta_command(ShellExState *p, } return SQLITE_OK; }else{ - psei->ppMetaCommands[nc] = 0; + psei->ppDotCommands[nc] = 0; } } return SQLITE_ERROR; @@ -8160,8 +8160,8 @@ static const char *shellStartupDir(void){ } static void setColumnWidths(ShellExState *p, char *azWidths[], int nWidths); -static MetaCommand * findMetaCommand(const char *, ShellExState *, int *); -static DotCmdRC runMetaCommand(MetaCommand*, char *[], int na, ShellExState*); +static DotCommand * findDotCommand(const char *, ShellExState *, int *); +static DotCmdRC runDotCommand(DotCommand*, char *[], int na, ShellExState*); static ExtensionHelpers extHelpers = { 13, @@ -8170,8 +8170,8 @@ static ExtensionHelpers extHelpers = { currentOutputFile, currentInputSource, strLineGet, - findMetaCommand, - runMetaCommand, + findDotCommand, + runDotCommand, setColumnWidths, nowInteractive, shellInvokedAs, @@ -8185,7 +8185,7 @@ static ExtensionHelpers extHelpers = { static ShellExtensionAPI shellExtAPI = { &extHelpers, 6, { - register_meta_command, + register_dot_command, register_exporter, register_importer, register_scripting, @@ -8250,30 +8250,30 @@ static int begin_db_dispatch(ShellExState *psx){ if( ensure_dispatch_table(psx)!=SQLITE_OK ) return 1; psi->pShxLoaded = (ShExtInfo *)sqlite3_malloc(2*sizeof(ShExtInfo)); - sei.ppMetaCommands - = (MetaCommand **)sqlite3_malloc((numCommands+2)*sizeof(MetaCommand *)); + sei.ppDotCommands + = (DotCommand **)sqlite3_malloc((numCommands+2)*sizeof(DotCommand *)); sei.ppExportHandlers = (ExportHandler **)sqlite3_malloc(2*sizeof(ExportHandler *)); sei.ppImportHandlers = (ImportHandler **)sqlite3_malloc(2*sizeof(ImportHandler *)); - if( sei.ppMetaCommands==0||sei.ppExportHandlers==0||sei.ppImportHandlers==0 + if( sei.ppDotCommands==0||sei.ppExportHandlers==0||sei.ppImportHandlers==0 || psi->pShxLoaded==0 ){ shell_out_of_memory(); } sei.numExportHandlers = 0; sei.numImportHandlers = 0; for( ic=0; icpShxLoaded[psi->numExtLoaded++] = sei; zSql = "INSERT INTO "SHELL_DISP_TAB"(name, extIx, cmdIx) VALUES(?, 0, ?)"; rc1 = sqlite3_prepare_v2(psx->dbShell, zSql, -1, &pStmt, 0); rc2 = sqlite3_exec(psx->dbShell, "BEGIN TRANSACTION", 0, 0, &zErr); if( rc1!=SQLITE_OK || rc2!=SQLITE_OK ) return 1; - assert(sei.numMetaCommands>0); - for( ic=0; ic0); + for( ic=0; icpMethods->name(pmc); sqlite3_reset(pStmt); sqlite3_bind_text(pStmt, 1, zName, -1, 0); @@ -8299,12 +8299,12 @@ static int begin_db_dispatch(ShellExState *psx){ */ static void free_one_shext_tracking(ShExtInfo *psei){ int j; - if( psei->ppMetaCommands!=0 ){ - for( j=psei->numMetaCommands; j>0; --j ){ - MetaCommand *pmc = psei->ppMetaCommands[j-1]; + if( psei->ppDotCommands!=0 ){ + for( j=psei->numDotCommands; j>0; --j ){ + DotCommand *pmc = psei->ppDotCommands[j-1]; if( pmc->pMethods->destruct!=0 ) pmc->pMethods->destruct(pmc); } - sqlite3_free(psei->ppMetaCommands); + sqlite3_free(psei->ppDotCommands); } if( psei->ppExportHandlers!=0 ){ for( j=psei->numExportHandlers; j>0; --j ){ @@ -8350,12 +8350,12 @@ static void free_all_shext_tracking(ShellInState *psi){ } } -static MetaCommand *command_by_index(ShellInState *psi, int extIx, int cmdIx){ +static DotCommand *command_by_index(ShellInState *psi, int extIx, int cmdIx){ assert(extIx>=0); if( extIx>=0 && extIxnumExtLoaded ){ ShExtInfo *psei = & psi->pShxLoaded[extIx]; - if( cmdIx>=0 && cmdIxnumMetaCommands ){ - return psei->ppMetaCommands[cmdIx]; + if( cmdIx>=0 && cmdIxnumDotCommands ){ + return psei->ppDotCommands[cmdIx]; } } return 0; @@ -8424,17 +8424,17 @@ static int load_shell_extension(ShellExState *psx, const char *zFile, } #endif -/* Meta-command implementation functions are defined in this section. -COMMENT Define meta-commands and provide for their dispatch and .help text. +/* Dot-command implementation functions are defined in this section. +COMMENT Define dot-commands and provide for their dispatch and .help text. COMMENT These should be kept in command name order for coding convenience -COMMENT except where meta-commands share implementation. (The ordering +COMMENT except where dot-commands share implementation. (The ordering COMMENT required for dispatch and help text is effected regardless.) The COMMENT effect of this configuration can be seen in generated output or by COMMENT executing tool/mkshellc.tcl --parameters (or --details or --help). COMMENT Generally, this section defines dispatchable functions inline and COMMENT causes collection of command_table entry initializers, to be later -COMMENT emitted by a mkshellc macro. (See EMIT_METACMD_INIT further on.) -** All dispatchable meta-command execute functions have this signature: +COMMENT emitted by a mkshellc macro. (See EMIT_DOTCMD_INIT further on.) +** All dispatchable dot-command execute functions have this signature: static int someCommand(char *azArg[], int nArg, ShellExState *p, char **pzErr); */ DISPATCH_CONFIG[ @@ -8442,7 +8442,7 @@ DISPATCH_CONFIG[ STORAGE_CLASS=static ARGS_SIGNATURE=char *$arg4\[\], int $arg5, ShellExState *$arg6, char **$arg7 DISPATCH_ENTRY={ "$cmd", ${cmd}Command, $arg1, $arg2, $arg3 }, - METACMD_INIT=META_CMD_INFO(${cmd}, $arg1,$arg2,$arg3, , ), + DOTCMD_INIT=DOT_CMD_INFO(${cmd}, $arg1,$arg2,$arg3, , ), CMD_CAPTURE_RE=^\s*{\s*"(\w+)" DISPATCHEE_NAME=${cmd}Command DC_ARG1_DEFAULT=[string length $cmd] @@ -10553,7 +10553,7 @@ DISPATCHABLE_COMMAND( nonce ? 2 2 ){ psi->pInSource->lineno, azArg[1]); exit(1); } - /* Suspend safe mode for 1 meta-command after this. */ + /* Suspend safe mode for 1 dot-command after this. */ psi->bSafeModeFuture = 2; return DCR_Ok; } @@ -13584,40 +13584,40 @@ DISPATCHABLE_COMMAND( x ? 1 0 ){ return (rv==DCR_Error)? DCR_CmdErred : rv; } -/* End of published, standard meta-command implementation functions -COMMENT Build-time overrides of above meta-commands or new meta-commands may be +/* End of published, standard dot-command implementation functions +COMMENT Build-time overrides of above dot-commands or new dot-commands may be COMMENT incorporated into shell.c via: -it COMMAND_CUSTOMIZE= COMMENT where names a file using the above methodology to -COMMENT define new or altered meta-commands and their help text. +COMMENT define new or altered dot-commands and their help text. */ INCLUDE( COMMAND_CUSTOMIZE ); -COMMENT This help text is set seperately from meta-command definition section +COMMENT This help text is set seperately from dot-command definition section COMMENT for the always-built-in, non-customizable commands with visible help. COLLECT_HELP_TEXT[ ".exit ?CODE? Exit this program with return-code CODE or 0", ".quit Exit this program", ]; -static void MetaCommand_dtor(MetaCommand *); -static const char * MetaCommand_name(MetaCommand *); -static const char * MetaCommand_help(MetaCommand *, const char *); +static void DotCommand_dtor(DotCommand *); +static const char * DotCommand_name(DotCommand *); +static const char * DotCommand_help(DotCommand *, const char *); static DotCmdRC - MetaCommand_argsCheck(MetaCommand *, char **, int nArgs, char *azArgs[]); + DotCommand_argsCheck(DotCommand *, char **, int nArgs, char *azArgs[]); static DotCmdRC - MetaCommand_execute(MetaCommand *, ShellExState *, char **, int, char *[]); - -static VTABLE_NAME(MetaCommand) meta_cmd_VtabBuiltIn = { - MetaCommand_dtor, - MetaCommand_name, - MetaCommand_help, - MetaCommand_argsCheck, - MetaCommand_execute + DotCommand_execute(DotCommand *, ShellExState *, char **, int, char *[]); + +static VTABLE_NAME(DotCommand) dot_cmd_VtabBuiltIn = { + DotCommand_dtor, + DotCommand_name, + DotCommand_help, + DotCommand_argsCheck, + DotCommand_execute }; /* Define and populate command dispatch table. */ static struct CommandInfo { - VTABLE_NAME(MetaCommand) *mcVtabBuiltIn; + VTABLE_NAME(DotCommand) *mcVtabBuiltIn; const char * cmdName; DotCmdRC (*cmdDoer)(char *azArg[], int nArg, ShellExState *, char **pzErr); @@ -13626,31 +13626,31 @@ static struct CommandInfo { void * pCmdData; } command_table[] = { COMMENT Emit the dispatch table entries generated and collected above. -#define META_CMD_INFO(cmd, nlenMin, minArgs, maxArgs, ht0, ht1 ) \ - { &meta_cmd_VtabBuiltIn, #cmd, cmd ## Command, \ +#define DOT_CMD_INFO(cmd, nlenMin, minArgs, maxArgs, ht0, ht1 ) \ + { &dot_cmd_VtabBuiltIn, #cmd, cmd ## Command, \ nlenMin, minArgs, maxArgs, { ht0, ht1 }, 0 \ } - EMIT_METACMD_INIT(2); -#undef META_CMD_INFO + EMIT_DOTCMD_INIT(2); +#undef DOT_CMD_INFO { 0, 0, 0, 0, ~0, ~0, {0,0}, 0 } }; static unsigned numCommands = sizeof(command_table)/sizeof(struct CommandInfo) - 1; -static MetaCommand *builtInCommand(int ix){ +static DotCommand *builtInCommand(int ix){ if( ix<0 || ix>=numCommands ) return 0; - return (MetaCommand *)&command_table[ix]; + return (DotCommand *)&command_table[ix]; } -static void MetaCommand_dtor(MetaCommand *pMe){ +static void DotCommand_dtor(DotCommand *pMe){ UNUSED_PARAMETER(pMe); } -static const char * MetaCommand_name(MetaCommand *pMe){ +static const char * DotCommand_name(DotCommand *pMe){ return ((struct CommandInfo *)pMe)->cmdName; } -static const char * MetaCommand_help(MetaCommand *pMe, const char * zWhat){ +static const char * DotCommand_help(DotCommand *pMe, const char * zWhat){ struct CommandInfo *pci = (struct CommandInfo *)pMe; if( zWhat==0 ) return pci->azHelp[0]; if( *zWhat==0 ) return pci->azHelp[1]; @@ -13658,7 +13658,7 @@ static const char * MetaCommand_help(MetaCommand *pMe, const char * zWhat){ } static DotCmdRC - MetaCommand_argsCheck(MetaCommand *pMe, + DotCommand_argsCheck(DotCommand *pMe, char **pzErrMsg, int nArgs, char *azArgs[]){ struct CommandInfo *pci = (struct CommandInfo *)pMe; UNUSED_PARAMETER(azArgs); @@ -13678,25 +13678,25 @@ static DotCmdRC } static DotCmdRC - MetaCommand_execute(MetaCommand *pMe, ShellExState *pssx, + DotCommand_execute(DotCommand *pMe, ShellExState *pssx, char **pzErrMsg, int nArgs, char *azArgs[]){ return (((struct CommandInfo *)pMe)->cmdDoer)(azArgs, nArgs, pssx, pzErrMsg); } /***************** -** MetaCommand iteration by name match, used by the .help meta-command. -** MetaCommands, or their ad-hoc stand-ins, having matching names are produced +** DotCommand iteration by name match, used by the .help dot-command. +** DotCommands, or their ad-hoc stand-ins, having matching names are produced ** in lexical order, with the iterator indicating which has been produced. -** If .zAdhocHelpName == 0, it is a regular MetaCommand. Otherwise, the -** ".unknown" MetaCommand is returned, whose help() method is to be used. -** Any returned MetaMatchIter must eventually be passed to freeMetaMatchIter(). +** If .zAdhocHelpName == 0, it is a regular DotCommand. Otherwise, the +** ".unknown" DotCommand is returned, whose help() method is to be used. +** Any returned CmdMatchIter must eventually be passed to freeCmdMatchIter(). */ -typedef struct MetaMatchIter { +typedef struct CmdMatchIter { ShellExState *psx; /* 0 indicates prepared statement; non-0 is the glob pattern. */ const char *zPattern; union { - MetaCommand *pMC; + DotCommand *pDotCmd; #if SHELL_DYNAMIC_EXTENSION sqlite3_stmt *stmt; #endif @@ -13704,14 +13704,14 @@ typedef struct MetaMatchIter { #if SHELL_DYNAMIC_EXTENSION char *zAdhocHelpText; /* registered extension ad-hoc help */ #endif -} MetaMatchIter; +} CmdMatchIter; /* Release resources held by the iterator and clear it. */ -static void freeMetaMatchIter(MetaMatchIter *pMMI){ +static void freeCmdMatchIter(CmdMatchIter *pMMI){ if( pMMI->zPattern!=0 ){ sqlite3_free((void *)pMMI->zPattern); pMMI->zPattern = 0; - pMMI->pMC = 0; + pMMI->pDotCmd = 0; } #if SHELL_DYNAMIC_EXTENSION else{ @@ -13723,13 +13723,13 @@ static void freeMetaMatchIter(MetaMatchIter *pMMI){ #endif } -/* Prepare an iterator that will produce a sequence of MetaCommand +/* Prepare an iterator that will produce a sequence of DotCommand * pointers whose referents' names match the given cmdFragment. * Return how many will match (if iterated upon return.) */ -static int findMatchingMetaCmds(const char *cmdFragment, - MetaMatchIter *pMMI, +static int findMatchingDotCmds(const char *cmdFragment, + CmdMatchIter *pMMI, ShellExState *psx){ - MetaMatchIter mmi = { psx, 0, 0 }; + CmdMatchIter mmi = { psx, 0, 0 }; int rv = 0; #if SHELL_DYNAMIC_EXTENSION if( ISS(psx)->bDbDispatch ){ @@ -13759,20 +13759,20 @@ static int findMatchingMetaCmds(const char *cmdFragment, shell_check_oom((void *)mmi.zPattern); struct CommandInfo *pCI = command_table; - mmi.pMC = (MetaCommand *)command_table; + mmi.pDotCmd = (DotCommand *)command_table; while( pCIcmdName)==0 ) ++rv; ++pCI; } } if( pMMI ) *pMMI = mmi; - else freeMetaMatchIter(&mmi); + else freeCmdMatchIter(&mmi); return rv; } -/* Produce the next MetaCommand pointer from the iterator, or 0 if no next. */ -static MetaCommand * nextMatchingMetaCmd(MetaMatchIter *pMMI){ - MetaCommand *rv = 0; +/* Produce the next DotCommand pointer from the iterator, or 0 if no next. */ +static DotCommand * nextMatchingDotCmd(CmdMatchIter *pMMI){ + DotCommand *rv = 0; #if SHELL_DYNAMIC_EXTENSION if( pMMI->zPattern==0 ){ int rc = sqlite3_step(pMMI->stmt); @@ -13800,11 +13800,11 @@ static MetaCommand * nextMatchingMetaCmd(MetaMatchIter *pMMI){ }else #endif { - struct CommandInfo *pCI = (struct CommandInfo *)(pMMI->pMC); + struct CommandInfo *pCI = (struct CommandInfo *)(pMMI->pDotCmd); assert(pCI>=command_table && pCI<=command_table+numCommands); while( pCIzPattern, pCI->cmdName)==0 ) rv = pMMI->pMC; - pMMI->pMC = (MetaCommand *)(++pCI); + if( sqlite3_strglob(pMMI->zPattern, pCI->cmdName)==0 ) rv = pMMI->pDotCmd; + pMMI->pDotCmd = (DotCommand *)(++pCI); if( rv!=0 ) break; } } @@ -13812,12 +13812,12 @@ static MetaCommand * nextMatchingMetaCmd(MetaMatchIter *pMMI){ } /***************** -** MetaCommand lookup +** DotCommand lookup ** ** For the non-extended or non-extensible shell, this function does -** a binary search of the fixed list of meta-command info structs. +** a binary search of the fixed list of dot-command info structs. ** For an extended shell, it queries the shell's DB. Either way, -** this function returns a MetaCommand pointer if one can be found +** this function returns a DotCommand pointer if one can be found ** with an adequate match for the given name. Here, "adequate" may ** vary according to whether shell extensions have been loaded. If ** not, the match must be for as many characters as set within the @@ -13825,7 +13825,7 @@ static MetaCommand * nextMatchingMetaCmd(MetaMatchIter *pMMI){ ** If shell extensions are loaded, the match must be long enough to ** result in a unique lookup. */ -MetaCommand *findMetaCommand(const char *cmdName, ShellExState *psx, +DotCommand *findDotCommand(const char *cmdName, ShellExState *psx, /* out */ int *pnFound){ if( pnFound ) *pnFound = 0; #if SHELL_DYNAMIC_EXTENSION @@ -13878,12 +13878,12 @@ MetaCommand *findMetaCommand(const char *cmdName, ShellExState *psx, } } if( pnFound && pci ) *pnFound = 1; - return (MetaCommand *)pci; + return (DotCommand *)pci; } } /* -** Given a MetaCommand, desired help level, +** Given a DotCommand, desired help level, ** ( possibly retreived ad-hoc help text for extensible shell, ) ** and an optional all-text search pattern, then ** when level==0 and primary help available, output it @@ -13894,7 +13894,7 @@ MetaCommand *findMetaCommand(const char *cmdName, ShellExState *psx, ** is restricted to those commands whose primary help begins with cLead. ** Return 1 if anything output, else 0. */ -static int putSelectedCmdHelp(MetaCommand *pmc, int iLevel, char cLead, +static int putSelectedCmdHelp(DotCommand *pmc, int iLevel, char cLead, #if SHELL_DYNAMIC_EXTENSION const char *zHelpText, #endif @@ -13963,17 +13963,17 @@ static int putSelectedCmdHelp(MetaCommand *pmc, int iLevel, char cLead, ** Output primary (single-line) help for a known command. */ static void showPrimaryHelp(FILE *out, const char *zCmd, ShellExState *psx){ - MetaMatchIter mmi = {0}; - int nm = findMatchingMetaCmds(zCmd, &mmi, psx); - MetaCommand *pmc = nextMatchingMetaCmd(&mmi); - if( pmc!=0 ){ - putSelectedCmdHelp(pmc, 0, 0, + CmdMatchIter cmi = {0}; + int nm = findMatchingDotCmds(zCmd, &cmi, psx); + DotCommand *pdc = nextMatchingDotCmd(&cmi); + if( pdc!=0 ){ + putSelectedCmdHelp(pdc, 0, 0, #if SHELL_DYNAMIC_EXTENSION - mmi.zAdhocHelpText, + cmi.zAdhocHelpText, #endif out, 0); } - freeMetaMatchIter(&mmi); + freeCmdMatchIter(&cmi); } /* @@ -13999,8 +13999,8 @@ static int showHelp(FILE *out, const char *zPattern, ShellExState *psx){ u8 bShowUndoc = zPattern==zHelpAll; u8 bEmptyPattern = !bNullPattern && (*zPattern==0 || bShowUndoc); int npm = 0; /* track how many matches found */ - MetaMatchIter mmi = {0}; - MetaCommand *pmc; + CmdMatchIter cmi = {0}; + DotCommand *pdc; char *zPat = 0; char cLead = (bShowUndoc)? ',' : '.'; int iLevel = 0; @@ -14027,7 +14027,7 @@ static int showHelp(FILE *out, const char *zPattern, ShellExState *psx){ } return npm; } - npm = findMatchingMetaCmds(zPattern, &mmi, psx); + npm = findMatchingDotCmds(zPattern, &cmi, psx); if( bNullPattern ) hoKind = HO_AllP; else if( bEmptyPattern ) hoKind = HO_AllX; else if( npm>1 ) hoKind = HO_LikeP; @@ -14038,32 +14038,30 @@ static int showHelp(FILE *out, const char *zPattern, ShellExState *psx){ shell_check_oom(zPat); } zPattern = 0; + iLevel = 1; switch( hoKind ){ case HO_AllP: case HO_LikeP: iLevel = 0; break; case HO_AllX: - iLevel = 1; break; case HO_OneX: - iLevel = 1; cLead = 0; break; case HO_LikeT: zPattern = zPat; - iLevel = 1; break; default: return 0; } npm = 0; - while( 0 != (pmc = nextMatchingMetaCmd(&mmi)) ){ - npm += putSelectedCmdHelp(pmc, iLevel, cLead, + while( 0 != (pdc = nextMatchingDotCmd(&cmi)) ){ + npm += putSelectedCmdHelp(pdc, iLevel, cLead, #if SHELL_DYNAMIC_EXTENSION - mmi.zAdhocHelpText, + cmi.zAdhocHelpText, #endif out, zPattern); } - freeMetaMatchIter(&mmi); + freeCmdMatchIter(&cmi); sqlite3_free(zPat); return npm; } @@ -14090,7 +14088,7 @@ static void command_post(ShellInState *psi){ /* Issue errors per returned DotCmdRC and error message, handle certain * exceptional returns, and translate return to the sanitized first 8. */ -static DotCmdRC meta_command_errors(char *zErr, char *azArg[], int nArg, +static DotCmdRC dot_command_errors(char *zErr, char *azArg[], int nArg, DotCmdRC dcr, ShellExState *psx){ if( psx->shellAbruptExit!=0 ){ if( psx->shellAbruptExit>0x1ff ) dcr = DCR_AbortError; @@ -14210,7 +14208,7 @@ static DotCmdRC meta_command_errors(char *zErr, char *azArg[], int nArg, return dcr; } -/* Argument-check and execute a found MetaCommand, wrapping execution +/* Argument-check and execute a found DotCommand, wrapping execution * with command_{prep,post}(...), and issue errors as made evident. * Return one of the "Post-execute action and success/error status" * codes from the DotCmdRC enum. @@ -14218,11 +14216,11 @@ static DotCmdRC meta_command_errors(char *zErr, char *azArg[], int nArg, * Note that this function is exposed for shell extensions to use. * * This should be called for "top-level" dot command execution only. - * Should an extension wrap or use a MetaCommand object to effect its + * Should an extension wrap or use a DotCommand object to effect its * own functionality, that object's execute() method should be called * directly, without going through this function. */ -static DotCmdRC runMetaCommand(MetaCommand *pmc, char *azArg[], int nArg, +static DotCmdRC runDotCommand(DotCommand *pmc, char *azArg[], int nArg, ShellExState *psx){ char *zErr = 0; DotCmdRC dcr = pmc->pMethods->argsCheck(pmc, &zErr, nArg, azArg); @@ -14232,7 +14230,7 @@ static DotCmdRC runMetaCommand(MetaCommand *pmc, char *azArg[], int nArg, dcr = pmc->pMethods->execute(pmc, psx, &zErr, nArg, azArg); } if( dcr!=DCR_Ok ){ - dcr = meta_command_errors(zErr, azArg, nArg, dcr, psx); + dcr = dot_command_errors(zErr, azArg, nArg, dcr, psx); } sqlite3_free(zErr); command_post(ISS(psx)); @@ -14249,7 +14247,7 @@ static DotCmdRC runMetaCommand(MetaCommand *pmc, char *azArg[], int nArg, ** ** Any applicable error messages are issued along with output messages. */ -static DotCmdRC do_meta_command(char *zLine, ShellExState *psx){ +static DotCmdRC do_dot_command(char *zLine, ShellExState *psx){ int h = 1; /* Passing over leading '.' */ int nArg = 0; char *azArg[52]; @@ -14290,27 +14288,27 @@ static DotCmdRC do_meta_command(char *zLine, ShellExState *psx){ */ if( nArg>0 ){ int nFound; - MetaCommand *pmc = findMetaCommand(azArg[0], psx, &nFound); + DotCommand *pmc = findDotCommand(azArg[0], psx, &nFound); if( pmc==0 || nFound>1 ){ if( nFound==0 ){ dcr = DCR_Unknown; #if SHELL_DYNAMIC_EXTENSION pmc = ISS(psx)->pUnknown; - if( pmc ) dcr = runMetaCommand(pmc, azArg, nArg, psx); + if( pmc ) dcr = runDotCommand(pmc, azArg, nArg, psx); #endif }else{ dcr = DCR_Ambiguous; } if( dcr > DCR_ArgIxMask ){ /* Issue error for unknown or inadequately specified dot command. */ - dcr = meta_command_errors(0, azArg, nArg, dcr, psx); + dcr = dot_command_errors(0, azArg, nArg, dcr, psx); } } else{ char *arg0 = azArg[0]; azArg[0] = (char *)(pmc->pMethods->name(pmc)); /* Run found command and issue or handle any errors it may report. */ - dcr = runMetaCommand(pmc, azArg, nArg, psx); + dcr = runDotCommand(pmc, azArg, nArg, psx); azArg[0] = arg0; } } @@ -14918,7 +14916,7 @@ static DotCmdRC process_input(ShellInState *psi){ case Cmd: { DotCmdRC dcr; echo_group_input(psi, *pzLineUse); - dcr = do_meta_command(*pzLineUse+nLeadWhite, XSS(psi)); + dcr = do_dot_command(*pzLineUse+nLeadWhite, XSS(psi)); nErrors += (dcr & DCR_Error); dcr &= ~DCR_Error; if( dcr > termKind ) termKind = dcr; @@ -15738,7 +15736,7 @@ int SQLITE_CDECL SHELL_MAIN(int argc, wchar_t **wargv){ if( i==argc-1 ) break; z = cmdline_option_value(argc,argv,++i); if( z[0]=='.' ){ - drc = do_meta_command(z, &datax); + drc = do_dot_command(z, &datax); rc = (drc>2)? 2 : drc; }else{ rc = run_single_query(&datax, z); @@ -15789,7 +15787,7 @@ int SQLITE_CDECL SHELL_MAIN(int argc, wchar_t **wargv){ */ for(i=0; i2)? 2 : drc; }else{ rc = run_single_query(&datax, azCmd[i]); diff --git a/src/shext_linkage.h b/src/shext_linkage.h index d582a03b12..5e9b936e02 100644 --- a/src/shext_linkage.h +++ b/src/shext_linkage.h @@ -28,14 +28,14 @@ extern "C" { /***************** * See "Shell Extensions, Programming" for purposes and usage of the following - * interfaces supporting extended meta-commands and import and output modes. + * interfaces supporting extended dot-commands and import and output modes. */ -/* Define status codes returned by a meta-command, either during its argument +/* Define status codes returned by a dot-command, either during its argument * checking or during its execution (to which checking may be deferred.) The - * code has 1 or 2 parts. The low-valued codes, below MCR_ArgIxMask, have an + * code has 1 or 2 parts. The low-valued codes, below DCR_ArgIxMask, have an * action part and an error flag. Higher-valued codes are bitwise-or'ed with - * a small integer and indicate problems with the meta-command itself. + * a small integer and indicate problems with the dot-command itself. */ typedef enum DotCmdRC { /* Post-execute action and success/error status (semi-ordered) */ @@ -66,20 +66,11 @@ typedef enum DotCmdRC { DCR_CmdErred = 0x7fff /* non-specific error for which complaint is done */ } DotCmdRC; -/* Convey data to, from and/or between I/O handlers and meta-commands. */ +/* Convey data to, from and/or between I/O handlers and dot-commands. */ typedef struct ShellExState { /* A sizeof(*) to permit extensions to guard against too-old hosts */ int sizeofThis; - /* A semi-transient holder of arbitrary data used during operations - * not interrupted by meta-command invocations. Any not-null pointer - * left after a meta-command has completed is, by contract, to be - * freeable using sqlite3_free(), unless freeHandlerData is non-zero, - * in which case it is used for the free, then zeroed too. This - * pointer's use is otherwise unconstrained. */ - void *pvHandlerData; - void (*freeHandlerData)(void *); - /* The user's currently open and primary DB connection * Extensions may use this DB, but must not modify this pointer * and must never close the database. The shell is exclusively @@ -124,7 +115,7 @@ typedef struct ShellExState { char *zNullValue; /* Name of table for which inserts are to be written or performed */ const char *zDestTable; - /* Next 3 members should be set and/or allocated by .width meta-command. + /* Next 3 members should be set and/or allocated by .width dot-command. * The values of pSpecWidths[i] and pHaveWidths[i] can be modified or * used by extensions, but setColumnWidths(...) must resize those lists. */ @@ -140,20 +131,20 @@ typedef struct ShellExState { } ShellExState; /* An object implementing below interface is registered with the - * shell to make new or overriding meta-commands available to it. + * shell to make new or overriding dot-commands available to it. */ -INTERFACE_BEGIN( MetaCommand ); +INTERFACE_BEGIN( DotCommand ); /* The whole, true name for this command */ -PURE_VMETHOD(const char *, name, MetaCommand, 0,()); +PURE_VMETHOD(const char *, name, DotCommand, 0,()); /* Help text; zWhat=0 => primary, zWhat="" => secondary, other ? */ -PURE_VMETHOD(const char *, help, MetaCommand, 1,(const char *zWhat)); +PURE_VMETHOD(const char *, help, DotCommand, 1,(const char *zWhat)); /* Validate arguments, blocking execute for returns != DCR_Ok */ -PURE_VMETHOD(DotCmdRC, argsCheck, MetaCommand, +PURE_VMETHOD(DotCmdRC, argsCheck, DotCommand, 3, (char **pzErrMsg, int nArgs, char *azArgs[])); /* Do whatever this command does, or return error of some kind */ -PURE_VMETHOD(DotCmdRC, execute, MetaCommand, +PURE_VMETHOD(DotCmdRC, execute, DotCommand, 4,(ShellExState *, char **pzErrMsg, int nArgs, char *azArgs[])); -INTERFACE_END( MetaCommand ); +INTERFACE_END( DotCommand ); /* An object implementing below interface is registered with the * shell to make new or overriding output modes available to it. @@ -274,16 +265,16 @@ CONCRETE_END(Derived) vtname = { \ DECORATE_METHOD(Derived,resetCompletionScan), \ DECORATE_METHOD(Derived,runScript) \ } -/* Define an implementation's v-table matching the MetaCommand interface. +/* Define an implementation's v-table matching the DotCommand interface. * Method signatures are copied and pasted from above interface declaration. */ -#define MetaCommand_IMPLEMENT_VTABLE(Derived, vtname) \ -CONCRETE_BEGIN(MetaCommand, Derived); \ -CONCRETE_METHOD(const char *, name, MetaCommand, 0,()); \ -CONCRETE_METHOD(const char *, help, MetaCommand, 1,(const char *zWhat)); \ -CONCRETE_METHOD(DotCmdRC, argsCheck, MetaCommand, 3, \ +#define DotCommand_IMPLEMENT_VTABLE(Derived, vtname) \ +CONCRETE_BEGIN(DotCommand, Derived); \ +CONCRETE_METHOD(const char *, name, DotCommand, 0,()); \ +CONCRETE_METHOD(const char *, help, DotCommand, 1,(const char *zWhat)); \ +CONCRETE_METHOD(DotCmdRC, argsCheck, DotCommand, 3, \ (char **pzErrMsg, int nArgs, char *azArgs[])); \ -CONCRETE_METHOD(DotCmdRC, execute, MetaCommand, 4, \ +CONCRETE_METHOD(DotCmdRC, execute, DotCommand, 4, \ (ShellExState *, char **pzErrMsg, int nArgs, char *azArgs[])); \ CONCRETE_END(Derived) vtname = { \ DECORATE_METHOD(Derived,destruct), \ @@ -312,10 +303,10 @@ AGGTYPE_BEGIN(ExtensionHelpers) { FILE * (*currentOutputFile)(ShellExState *p); struct InSource * (*currentInputSource)(ShellExState *p); char * (*strLineGet)(char *zBuf, int ncMax, struct InSource *pInSrc); - MetaCommand * (*findMetaCommand)(const char *cmdName, ShellExState *p, - /* out */ int *pnFound); - DotCmdRC (*runMetaCommand)(MetaCommand *pmc, char *azArg[], int nArg, - ShellExState *psx); + DotCommand * (*findDotCommand)(const char *cmdName, ShellExState *p, + /* out */ int *pnFound); + DotCmdRC (*runDotCommand)(DotCommand *pmc, char *azArg[], int nArg, + ShellExState *psx); void (*setColumnWidths)(ShellExState *p, char *azWidths[], int nWidths); int (*nowInteractive)(ShellExState *p); const char * (*shellInvokedAs)(void); @@ -353,8 +344,8 @@ typedef enum { NK_ExtensionUnload, /* The ShellExState .dbShell DB will soon be closed, * soon to be followed by unloading of all dynamic * extensions; pvSubject is the DB's sqlite3 pointer. */ - NK_NewDotCommand, /* A new MetaCommand has been registered, pvSubject - * is the just-added MetaCommand object (pointer). */ + NK_NewDotCommand, /* A new DotCommand has been registered, pvSubject + * is the just-added DotCommand object (pointer). */ NK_CountOf /* Present count of preceding members (evolves) */ } NoticeKind; @@ -370,9 +361,9 @@ AGGTYPE_BEGIN(ShellExtensionAPI) { /* Functions for an extension to register its implementors with shell */ const int numRegistrars; /* 6 for this version */ struct ShExtAPI { - /* Register a meta-command */ - int (*registerMetaCommand)(ShellExState *p, - ExtensionId eid, MetaCommand *pMC); + /* Register a dot-command */ + int (*registerDotCommand)(ShellExState *p, + ExtensionId eid, DotCommand *pMC); /* Register query result data display (or other disposition) mode */ int (*registerExporter)(ShellExState *p, ExtensionId eid, ExportHandler *pEH); @@ -388,7 +379,7 @@ AGGTYPE_BEGIN(ShellExtensionAPI) { NoticeKind nkMin, ShellEventNotify eventHandler); /* Notify host shell that an ad-hoc dot command exists and provide for * its help text to appear in .help output. Only an extension which has - * registered an "unknown" MetaCommand may use this. + * registered an "unknown" DotCommand may use this. * If zHelp==0, any such provision is removed. If zHelp!=0, original or * replacement help text is associated with command zName. * Help text before the first newline is primary, issued as summary help. diff --git a/src/test_shellext.c b/src/test_shellext.c index 3eb2863425..ed5b54af48 100644 --- a/src/test_shellext.c +++ b/src/test_shellext.c @@ -26,19 +26,19 @@ typedef struct BatBeing BatBeing; static void sayHowMany( BatBeing *pbb, FILE *out, ShellExState *psx ); /* These DERIVED_METHOD(...) macro calls' arguments were copied and - * pasted from the MetaCommand interface declaration in shext_linkage.h , + * pasted from the DotCommand interface declaration in shext_linkage.h , * but with "Interface,Derived" substituted for the interface typename. * The function bodies are not so easily written, of course. */ -DERIVED_METHOD(void, destruct, MetaCommand,BatBeing, 0, ()){ +DERIVED_METHOD(void, destruct, DotCommand,BatBeing, 0, ()){ fprintf(stderr, "BatBeing unbecoming.\n"); } -DERIVED_METHOD(const char *, name, MetaCommand,BatBeing, 0,()){ +DERIVED_METHOD(const char *, name, DotCommand,BatBeing, 0,()){ return "bat_being"; } -DERIVED_METHOD(const char *, help, MetaCommand,BatBeing, 1,(const char *zHK)){ +DERIVED_METHOD(const char *, help, DotCommand,BatBeing, 1,(const char *zHK)){ if( !zHK ) return ".bat_being ?whatever? Demonstrates vigilantism weekly\n"; if( !*zHK ) @@ -46,12 +46,12 @@ DERIVED_METHOD(const char *, help, MetaCommand,BatBeing, 1,(const char *zHK)){ return 0; } -DERIVED_METHOD(DotCmdRC, argsCheck, MetaCommand,BatBeing, 3, +DERIVED_METHOD(DotCmdRC, argsCheck, DotCommand,BatBeing, 3, (char **pzErrMsg, int nArgs, char *azArgs[])){ return DCR_Ok; } -DERIVED_METHOD(DotCmdRC, execute, MetaCommand,BatBeing, 4, +DERIVED_METHOD(DotCmdRC, execute, DotCommand,BatBeing, 4, (ShellExState *psx, char **pzErrMsg, int nArgs, char *azArgs[])){ FILE *out = pExtHelpers->currentOutputFile(psx); switch( nArgs ){ @@ -63,16 +63,16 @@ DERIVED_METHOD(DotCmdRC, execute, MetaCommand,BatBeing, 4, return DCR_Ok; } -/* Define a MetaCommand v-table initialized to reference above methods. */ -MetaCommand_IMPLEMENT_VTABLE(BatBeing, batty_methods); +/* Define a DotCommand v-table initialized to reference above methods. */ +DotCommand_IMPLEMENT_VTABLE(BatBeing, batty_methods); -/* Define/initialize BatBeing as a MetaCommand subclass using above v-table. +/* Define/initialize BatBeing as a DotCommand subclass using above v-table. * This compiles in a type-safe manner because the batty_methods v-table - * and methods it incorporates strictly match the MetaCommand interface. + * and methods it incorporates strictly match the DotCommand interface. */ INSTANCE_BEGIN(BatBeing); int numCalls; - MetaCommand * pPrint; + DotCommand * pPrint; INSTANCE_END(BatBeing) batty = { &batty_methods, 0, 0 @@ -82,11 +82,11 @@ static void sayHowMany( BatBeing *pbb, FILE *out, ShellExState *psx ){ if( pbb->pPrint ){ char *az[] = { "print", 0 }; char *zErr = 0; - MetaCommand * pmcPrint = pbb->pPrint; + DotCommand * pdcPrint = pbb->pPrint; DotCmdRC rc; az[1] = sqlite3_mprintf("This execute has been called %d times.\n", ++pbb->numCalls); - rc = pmcPrint->pMethods->execute(pmcPrint, psx, &zErr, 2, az); + rc = pdcPrint->pMethods->execute(pdcPrint, psx, &zErr, 2, az); sqlite3_free(az[1]); if( rc!= DCR_Ok ){ fprintf(out, "print() failed: %d\n", rc); @@ -136,13 +136,13 @@ int sqlite3_testshellext_init( return SQLITE_ERROR; }else{ ShellExState *psx = pShExtLink->pSXS; - MetaCommand *pmc = (MetaCommand *)&batty; + DotCommand *pdc = (DotCommand *)&batty; int rc; SHX_API(subscribeEvents)(psx, sqlite3_testshellext_init, &batty, NK_CountOf, shellEventHandle); - batty.pPrint = SHX_HELPER(findMetaCommand)("print", psx, &rc); - rc = SHX_API(registerMetaCommand)(psx, sqlite3_testshellext_init, pmc); + batty.pPrint = SHX_HELPER(findDotCommand)("print", psx, &rc); + rc = SHX_API(registerDotCommand)(psx, sqlite3_testshellext_init, pdc); if( rc!=0 ) ++nErr; pShExtLink->eid = sqlite3_testshellext_init; } diff --git a/src/test_shellext.cpp b/src/test_shellext.cpp index 89d52181a7..473f77bfb8 100644 --- a/src/test_shellext.cpp +++ b/src/test_shellext.cpp @@ -22,7 +22,7 @@ SHELL_EXTENSION_INIT1(pShExtApi, pExtHelpers, shextLinkFetcher); #define SHX_API(entry) pShExtApi->entry #define SHX_HELPER(entry) pExtHelpers->entry -struct BatBeing : MetaCommand { +struct BatBeing : DotCommand { ~BatBeing() {}; // No held resources; copy/assign is fine and dying is easy. @@ -44,7 +44,7 @@ struct BatBeing : MetaCommand { DotCmdRC execute(ShellExState *psx, char **pzErrMsg, int nArgs, char *azArgs[]); - BatBeing(MetaCommand *pp = 0) { + BatBeing(DotCommand *pp = 0) { numCalls = 0; pPrint = pp; }; @@ -52,7 +52,7 @@ struct BatBeing : MetaCommand { // Default copy/assign are fine; nothing held. int numCalls; - MetaCommand * pPrint; + DotCommand * pPrint; }; static void sayHowMany( BatBeing *pbb, FILE *out, ShellExState *psx ){ @@ -83,9 +83,9 @@ DotCmdRC BatBeing::execute(ShellExState *psx, char **pzErrMsg, return DCR_Ok; } -/* Define/initialize BatBeing as a MetaCommand subclass using above v-table. +/* Define/initialize BatBeing as a DotCommand subclass using above v-table. * This compiles in a type-safe manner because the batty_methods v-table - * and methods it incorporates strictly match the MetaCommand interface. + * and methods it incorporates strictly match the DotCommand interface. */ static BatBeing batty(0); @@ -136,8 +136,8 @@ int sqlite3_testshellext_init( SHX_API(subscribeEvents)(psx, sqlite3_testshellext_init, &batty, NK_CountOf, shellEventHandle); - batty.pPrint = SHX_HELPER(findMetaCommand)("print", psx, &rc); - rc = SHX_API(registerMetaCommand)(psx, sqlite3_testshellext_init, &batty); + batty.pPrint = SHX_HELPER(findDotCommand)("print", psx, &rc); + rc = SHX_API(registerDotCommand)(psx, sqlite3_testshellext_init, &batty); if( rc!=0 ) ++nErr; pShExtLink->eid = sqlite3_testshellext_init; } diff --git a/tool/mkshellc.tcl b/tool/mkshellc.tcl index 0d3e270ea9..9e641325a5 100755 --- a/tool/mkshellc.tcl +++ b/tool/mkshellc.tcl @@ -183,7 +183,7 @@ proc project_path {relPath} { } if {$::lineTags >= 3} { - # These k/v stores hold {lineNum filename} lists keyed by meta-command, + # These k/v stores hold {lineNum filename} lists keyed by dot-command, # which are used to get #line directives on all dispatch and help table # entries, and any conditionals affecting their compilation. array set ::cmd_help_tags {} @@ -255,7 +255,7 @@ proc emit_sync { lines ostrm precLines {fromFile ""} } { array set ::cmd_help {} array set ::cmd_condition {} -array set ::metacmd_init {} +array set ::dotcmd_init {} array set ::inc_type_files {} set ::iShuffleErrors 0 # Ease use of { and } in literals. Instead, $::lb and $::rb can be used. @@ -275,7 +275,7 @@ set ::parametersHelp { HELP_COALESCE sets whether to coalesce secondary help text and add newlines. Within values set for ARGS_SIGNATURE, DISPATCHEE_NAME, and DISPATCH_ENTRY parameters, the variables $cmd and $arg# (where # is an integer) may appear, - to be replaced by the meta-command name or the #'th effective argument to + to be replaced by the dot-command name or the #'th effective argument to DISPATCHABLE_COMMAND(). The "effective" argument is either what is provided, or a default value when the actual argument is missing (at the right end of the provided argument list) or the argument has the value ? . The expansion @@ -290,8 +290,8 @@ array set ::dispCfg [list \ "{ \"\$cmd\", \${cmd}Command, \$arg1,\$arg2,\$arg3 }," \ DISPATCHEE_NAME {${cmd}Command} \ HELP_COALESCE 0 \ - METACMD_INIT \ - "META_CMD_INFO( \${cmd}, \$arg1,\$arg2,\$arg3,\n ,\n )," \ + DOTCMD_INIT \ + "DOT_CMD_INFO( \${cmd}, \$arg1,\$arg2,\$arg3,\n ,\n )," \ ] # Other config keys: # DC_ARG_COUNT= @@ -402,7 +402,7 @@ array set ::macroTailREs [list \ CONDITION_COMMAND {^\(\s*(\w+)\s+([^;]+)\);} \ DISPATCH_CONFIG {^\[} \ DISPATCHABLE_COMMAND {^\(([\w\? ]+)\)(\S)\s*$} \ - EMIT_METACMD_INIT {^\((\d*)\)} \ + EMIT_DOTCMD_INIT {^\((\d*)\)} \ INCLUDE {^(?:\(\s*(\w+)\s*\))|(?:\s+([\w./\\]+)\M)} \ IGNORE_COMMANDS {^\(\s*([-+\w ]*)\)\s*;\s*} \ TCL_CSTR_LITERAL {^\(([ \w*=]+)\)(\S)\s*$} \ @@ -413,7 +413,7 @@ array set ::macroTailREs [list \ # CONFIGURE_DISPATCH tailCapture_Empty # COLLECT_HELP_TEXT tailCapture_Empty # DISPATCHABLE_COMMAND tailCapture_ArgsGlom_TrailChar -# EMIT_METACMD_INIT tailCapture_Indent +# EMIT_DOTCMD_INIT tailCapture_Indent # IGNORED_COMMANDS tailCapture_SignedCmdGlom # INCLUDE tailCapture_IncType_Filename @@ -424,7 +424,7 @@ array set ::macroUsages [list \ DISPATCH_CONFIG "\[\n \n \];" \ DISPATCHABLE_COMMAND \ "( name args... ){\n \n }" \ - EMIT_METACMD_INIT "( indent );" \ + EMIT_DOTCMD_INIT "( indent );" \ INCLUDE {( )} \ SKIP_COMMANDS "( );" \ TCL_CSTR_LITERAL \ @@ -652,21 +652,21 @@ proc DISPATCHABLE_COMMAND {inSrc tailCapture ostrm} { set argexp [subst $::dispCfg(ARGS_SIGNATURE)] set fname [subst $::dispCfg(DISPATCHEE_NAME)] set funcOpen "$rsct $fname\($argexp\)$::lb" - set mcInit [subst $::dispCfg(METACMD_INIT)] + set mcInit [subst $::dispCfg(DOTCMD_INIT)] emit_conditionally $cmd [linsert $body 0 $funcOpen] $inSrc $ostrm - set ::metacmd_init($cmd) $mcInit + set ::dotcmd_init($cmd) $mcInit set_src_tags dispatch $cmd $inSrc } } return $iAte } -proc EMIT_METACMD_INIT {inSrc tailCap ostrm} { - # Emit the collected metacommand init table entries, in command order, maybe +proc EMIT_DOTCMD_INIT {inSrc tailCap ostrm} { + # Emit the collected dotcommand init table entries, in command order, maybe # wrapped with a conditional construct as set by CONDITION_COMMAND(). Prior # to the emit, substitute markers with help text for the command. - foreach cmd [lsort [array names ::metacmd_init]] { - set initem $::metacmd_init($cmd) + foreach cmd [lsort [array names ::dotcmd_init]] { + set initem $::dotcmd_init($cmd) set ht0i -1 if {[info exists ::cmd_help($cmd)]} { set ht $::cmd_help($cmd) ; # ht is a list.