]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Get tclshext made with Tk, optionally, and make unknown work as in tclsh.
authorlarrybr <larrybr@noemail.net>
Sat, 9 Apr 2022 14:57:17 +0000 (14:57 +0000)
committerlarrybr <larrybr@noemail.net>
Sat, 9 Apr 2022 14:57:17 +0000 (14:57 +0000)
FossilOrigin-Name: 43eb311e517b79cde9e17c1a80baed8d13d9d943dd9ee44b31831159df8715fc

Makefile.in
ext/misc/tclshext.c.in
manifest
manifest.uuid
src/shell.c.in

index 2e024bb49834408d9a65feae9bbbfc50a2d6e5d2..8a39bd6a03393add944ff4aba67ca0fd91104092 100644 (file)
@@ -1254,11 +1254,24 @@ shx_link.h:     $(SHX_LINK_SRC)
 
 tcl_shell_extension:   tclshext$(SHLIB_SUFFIX)
 
+# This is a work-around for building Tk variant. Ultimately, the configure
+# script will find the Tk library with the same version as the Tcl library.
+# This has the same effect with the lib naming now used by the Tcl project,
+# but, if it will fail, does so when make rather than configure is run.
+TCL_LIBS = $(LIBTCL)
+ifdef WITH_TK
+ ifneq ($(WITH_TK),0)
+TCLEXT_OPTS += -DSHELL_ENABLE_TK
+LIBTK := $(patsubst -ltcl%,-ltk%,$(LIBTCL))
+TCL_LIBS += $(LIBTK)
+ endif
+endif
+
 tclshext.c:    $(TOP)/ext/misc/tclshext.c.in $(TOP)/src/tclsqlite.c
        $(MKSHELL_TOOL) $(TOP)/ext/misc/tclshext.c.in > $@
 
 tclshext$(SHLIB_SUFFIX): tclshext.c shx_link.h
-       $(TCCX) $(TCLEXT_OPTS) tclshext.c -o $@ $(LIBTCL)
+       $(TCCX) $(TCLEXT_OPTS) tclshext.c -o $@ $(TCL_LIBS) $(TCLEXT_LDOPTS)
 
 # Rules to build the 'testfixture' application.
 #
index 677843ebb388ee0c21cfd33598467306a7e22a95..5374c66701ff286c2914591c57d5df74dbc4c596 100644 (file)
      tool/mkshellc.tcl ext/misc/tclshext.c.in > tclshext.c
      gcc -shared -fPIC -O2 -I. -Isrc -I/usr/include/tcl8.6 \
        tclshext.c -o tclshext.so -ltcl8.6
-** Or, use the provided Makefile and build target tcl_shell_extension .
-   If the Tk library is available, it can be linked and used thusly:
+** Or, (after ./configure ...), use the provided Makefile thusly:
+     make tcl_shell_extension
+** If the Tk library is available, it can be linked and used thusly:
      gcc -shared -fPIC -O2 -I. -Isrc -I/usr/include/tcl8.6 \
        -DSHELL_ENABLE_TK tclshext.c -o tclshext.so -ltcl8.6 -ltk8.6
-** Or, make the same target, with 'TCLEXT_OPTS=-DSHELL_ENABLE_TK'.
-** Later TCL versions can be used if desired.
-  "TCL scripting support is added with a registerScripting() call in the\n"
-  "ShellExtensionAPI, per ScriptingSupport interface requirements. This\n"
-  "support lasts until the scripting object destructor is called.\n"
+** Or, make the same target with Tk thusly:
+     make tcl_shell_extension WITH_TK=1
+** Later TCL versions can be used if desired (and installed.)
+**
+** TCL scripting support is added with a registerScripting() call (in the
+** ShellExtensionAPI), meeting ScriptingSupport interface requirements.
 */
 static const char * const zTclHelp =
   "This extension adds these features to the host shell:\n"
   " 1. TCL scripting support is added.\n"
   " 2. TCL commands are added: udb shdb now_interactive get_tcl_group ..\n"
   " 3. The .tcl and .unknown dot commands are added.\n"
-  " 4. If built with Tk capability, the gui TCL command will be added if\n"
-  "  this extension was loaded using the shell via: .load ... -shext -tk .\n"
-  "  Any other arguments beyond -shext are in TCL's argv variable.\n"
+  " 4. If built with Tk capability, the gui TCL command will be added if this\n"
+  "  extension was loaded using shell command: .load tclshext -shext -tk .\n"
+  "  Any other arguments beyond -shext are copied into TCL's argv variable.\n"
   "Operation:\n"
   " Shell input groups beginning with \"..\" are treated as TCL input, in\n"
   " these ways: (1) When a bare \"..\" is entered, a TCL REPL loop is run\n"
@@ -42,7 +44,7 @@ static const char * const zTclHelp =
   " is entered, (where \"T\" is a TCL command name), that TCL command and its\n"
   " arguments will be collected and expanded according to TCL parsing rules,\n"
   " then run in the TCL execution environment (in its global namespace), but\n"
-  " the shell execution environment remains in effect afterward.\n"
+  " the shell REPL and execution environment remains in effect afterward.\n"
   "\n"
   " Note that cases 2 and 3 differ in having space after the leading \"..\".\n"
   "\n"
@@ -471,11 +473,14 @@ TCL_CSTR_LITERAL(static const char * const zREPL = ){
 };
 #elif TCL_REPL==3
 /* using shell's input collection with line editing (if configured) */
-static const char * const zREPL = "sqlite_shell_REPL";
+static const char * const zREPL = "uplevel #0 sqlite_shell_REPL";
 
 TCL_CSTR_LITERAL(static const char * const zDefineREPL = ){
   proc sqlite_shell_REPL {} {
-    set interactive [now_interactive]
+    if {[info exists ::tcl_interactive]} {
+      set save_interactive $::tcl_interactive
+    }
+    set ::tcl_interactive [now_interactive]
     while {1} {
       foreach {group ready} [get_tcl_group] {}
       set trimmed [string trim $group]
@@ -498,6 +503,9 @@ TCL_CSTR_LITERAL(static const char * const zDefineREPL = ){
     }
     if {$interactive && $trimmed ne "."} {puts {}}
     read stdin 0
+    if {[info exists save_interactive]} {
+      set ::tcl_interactive $save_interactive
+    } else { unset ::tcl_interactive }
   }
 };
 #else
@@ -629,7 +637,7 @@ DERIVED_METHOD(const char *, help, MetaCommand,UnkCmd, 1,(const char *zHK)){
   return 0;
 }
 
-#if TCL_REPL==2
+#if TCL_REPL==1 || TCL_REPL==2
 #define GETLINE_MAXLEN 1000
 
 /* C implementation of TCL proc, get_input_line */
@@ -783,7 +791,7 @@ static int runTkGUI(void *pvSS, Tcl_Interp *interp,
 }
 #endif /* defined(SHELL_ENABLE_TK) */
 
-#define UNKNOWN_RENAME "::_original_unknown"
+#define UNKNOWN_RENAME "_original_unknown"
 
 /* C implementation of TCL ::register_adhoc_command name ?help? */
 static int registerAdHocCommand(/* ShellExState */ void *pv,
@@ -803,7 +811,7 @@ static int registerAdHocCommand(/* ShellExState */ void *pv,
   return TCL_ERROR;
 }
 
-/* C implementation of TCL ::unknown to (maybe) delegate to dot commands */
+/* C implementation of TCL unknown to (maybe) delegate to dot commands */
 static int unknownDotDelegate(void *pvSS, Tcl_Interp *interp,
                                 int nArgs, const char *azArgs[]){
   const char *name = (nArgs>1 && *azArgs[1]=='.')? azArgs[1]+1 : 0;
@@ -829,7 +837,7 @@ static int unknownDotDelegate(void *pvSS, Tcl_Interp *interp,
       return TCL_ERROR;
     }
   }else{
-    /* Defer to the TCL-default ::unknown command, or fail here. */
+    /* Defer to the TCL-default unknown command, or fail here. */
     if( 0!=Tcl_FindCommand(interp, UNKNOWN_RENAME, 0, TCL_GLOBAL_ONLY) ){
       Tcl_Obj **ppo = sqlite3_malloc((nArgs+1)*sizeof(Tcl_Obj*));
       if( ppo==0 ) return TCL_ERROR;
@@ -839,6 +847,7 @@ static int unknownDotDelegate(void *pvSS, Tcl_Interp *interp,
         ppo[ia] = Tcl_NewStringObj(azArgs[ia], -1);
         Tcl_IncrRefCount(ppo[ia]);
       }
+      ppo[ia] = 0;
       rc = Tcl_EvalObjv(interp, nArgs, ppo, TCL_EVAL_GLOBAL);
       for( ia=0; ia<nArgs; ++ia ) Tcl_DecrRefCount(ppo[ia]);
       sqlite3_free(ppo);
@@ -1134,7 +1143,7 @@ int sqlite3_tclshext_init(
 #ifdef SHELL_ENABLE_TK
           ldTk = 1;
 #else
-          *pzErrMsg = sqlite3_mprintf("Option -tk not supported by this"
+          *pzErrMsg = sqlite3_mprintf("Option -tk not supported by this "
                                       "tclshext extension as built.\n");
           return SQLITE_ERROR;
 #endif
index fa048f198e9784740c0f8ac759f12e97e6164a37..84a243c4b5cd74f908cc26d24f8cdff9fd5c532a 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,9 +1,9 @@
-C Fix\sTCL\sextension\sbuild\sissue.
-D 2022-04-09T03:12:40.948
+C Get\stclshext\smade\swith\sTk,\soptionally,\sand\smake\sunknown\swork\sas\sin\stclsh.
+D 2022-04-09T14:57:17.905
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
-F Makefile.in 45a1174d1eb69015620b82a87f598e7558137e5ff0276ca622e976649cf7c30f
+F Makefile.in f96bf52d014571fe3bbabd575a2824a7ea9d7ef2f40bf23315efacda81d59ee1
 F Makefile.linux-gcc f609543700659711fbd230eced1f01353117621dccae7b9fb70daa64236c5241
 F Makefile.msc 689726a2785027e0eb34ea9ce8e67ac94bc4aebbaa6def20ddb6fa9f7b0c43b5
 F README.md 2dd87a5c1d108b224921f3dd47dea567973f706e1f6959386282a626f459a70c
@@ -329,7 +329,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 419d8dde92b5be9ef289056e6d661d5aeccb48bb93deb4e6cb7986b8bc1cd4dc
+F ext/misc/tclshext.c.in 026416fd5c1e84eb8c8e98edc9dcd826e3c0d32fd0883ab306829642867128e8
 F ext/misc/templatevtab.c 8a16a91a5ceaccfcbd6aaaa56d46828806e460dd194965b3f77bf38f14b942c4
 F ext/misc/totype.c fa4aedeb07f66169005dffa8de3b0a2b621779fd44f85c103228a42afa71853b
 F ext/misc/uint.c 053fed3bce2e89583afcd4bf804d75d659879bbcedac74d0fa9ed548839a030b
@@ -556,7 +556,7 @@ F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c
 F src/resolve.c 18d99e7146852d6064559561769fcca0743eb32b14a97da6dbed373a30ee0e76
 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
 F src/select.c d6c04eb93395024af80f61a8c278a33c2a0333aeb7d57bb6aa737a6f1c4af4b8
-F src/shell.c.in a32d50c687fc79e4d19992810dfa358d0342f4b9e464f791e6db011cc6c5f0ec
+F src/shell.c.in 8e2ad2912ae381786653ce9db04522f8058873d690f434016ecda5a419c0cdc5
 F src/shext_linkage.h 88a3f215fdb090fcc3b3577a05bafd234f1a556bad3f2f4ac990a177aebf4b2c
 F src/sqlite.h.in 2a35f62185eb5e7ecc64a2f68442b538ce9be74f80f28a00abc24837edcf1c17
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
@@ -1951,8 +1951,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 2cd49df502a7cd250c453cbbd6a2651e588d69dd755bbdf5a55b58715e548760
-R 9e007e781c4f098c2fd1d0e6fa36b03e
+P 0b3bb0e793f8c7fd79042322b7748a75d17a3c3d0752cfb0f2c544af49b1d6d6
+R fd77dc9b9d6010cf74b598e30b2c6a7a
 U larrybr
-Z 0a2834b5db7d2e730016c4d403bccffd
+Z 41d0aa7cc99a4d24d4e075af36bc0e99
 # Remove this line to create a well-formed Fossil manifest.
index b4bf416bdcf7c3cf6050339fd88873d4f2933447..3448532c48603b87b410b02235a788c8474c6915 100644 (file)
@@ -1 +1 @@
-0b3bb0e793f8c7fd79042322b7748a75d17a3c3d0752cfb0f2c544af49b1d6d6
\ No newline at end of file
+43eb311e517b79cde9e17c1a80baed8d13d9d943dd9ee44b31831159df8715fc
\ No newline at end of file
index 169240dadb8444643f368149700c1d993206be7e..e8a3046395dfb188f365166987145c73296ce4a7 100644 (file)
@@ -15801,7 +15801,6 @@ int SQLITE_CDECL SHELL_MAIN(int argc, wchar_t **wargv){
     if( stdin_is_interactive ){
       char *zHome;
       char *zHistory;
-      int nHistory;
       if( bQuiet ){
         /* bQuiet is almost like normal interactive, but quieter. */
         mainPrompt[0] = 0;
@@ -15822,7 +15821,7 @@ int SQLITE_CDECL SHELL_MAIN(int argc, wchar_t **wargv){
         if( zHistory ){
           zHistory = strdup(zHistory);
         }else if( (zHome = find_home_dir(0))!=0 ){
-          nHistory = strlen30(zHome) + 20;
+          int nHistory = strlen30(zHome) + 20;
           if( (zHistory = malloc(nHistory))!=0 ){
             sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
           }