Fossil SCM

Take over "Fixes to the editline support" and "Updates to the command-line shell" from SQLite trunk, keeping the two in sync better. Except for the addition of the ".save" command in "fossil sqlite3", it has no effect.

jan.nijtmans 2014-02-13 15:17 trunk
Commit e327614047ebc42941c58b87a9bc3eea8c5f7605
1 file changed +44 -10
+44 -10
--- src/shell.c
+++ src/shell.c
@@ -43,18 +43,21 @@
4343
# endif
4444
# include <unistd.h>
4545
# include <sys/types.h>
4646
#endif
4747
48
-#ifdef HAVE_EDITLINE
49
-# include <editline/editline.h>
50
-#endif
51
-#if defined(HAVE_READLINE) && HAVE_READLINE==1
48
+#if defined(HAVE_READLINE) && HAVE_READLINE!=0
5249
# include <readline/readline.h>
5350
# include <readline/history.h>
51
+#else
52
+# undef HAVE_READLINE
53
+#endif
54
+#if defined(HAVE_EDITLINE) && !defined(HAVE_READLINE)
55
+# define HAVE_READLINE 1
56
+# include <editline/readline.h>
5457
#endif
55
-#if !defined(HAVE_EDITLINE) && (!defined(HAVE_READLINE) || HAVE_READLINE!=1)
58
+#if !defined(HAVE_READLINE)
5659
# define add_history(X)
5760
# define read_history(X)
5861
# define write_history(X)
5962
# define stifle_history(X)
6063
#endif
@@ -411,11 +414,11 @@
411414
char *zResult;
412415
if( in!=0 ){
413416
zResult = local_getline(zPrior, in);
414417
}else{
415418
zPrompt = isContinuation ? continuePrompt : mainPrompt;
416
-#if defined(HAVE_READLINE) && HAVE_READLINE==1
419
+#if defined(HAVE_READLINE)
417420
free(zPrior);
418421
zResult = readline(zPrompt);
419422
if( zResult && *zResult ) add_history(zResult);
420423
#else
421424
printf("%s", zPrompt);
@@ -1581,10 +1584,11 @@
15811584
".print STRING... Print literal STRING\n"
15821585
".prompt MAIN CONTINUE Replace the standard prompts\n"
15831586
".quit Exit this program\n"
15841587
".read FILENAME Execute SQL in FILENAME\n"
15851588
".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
1589
+ ".save FILE Write in-memory database into FILE\n"
15861590
".schema ?TABLE? Show the CREATE statements\n"
15871591
" If TABLE specified, only show tables matching\n"
15881592
" LIKE pattern TABLE.\n"
15891593
".separator STRING Change separator used by output mode and .import\n"
15901594
".show Show the current values for various settings\n"
@@ -2150,11 +2154,13 @@
21502154
/* Process the input line.
21512155
*/
21522156
if( nArg==0 ) return 0; /* no tokens, no error */
21532157
n = strlen30(azArg[0]);
21542158
c = azArg[0][0];
2155
- if( c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0 ){
2159
+ if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
2160
+ || (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
2161
+ ){
21562162
const char *zDestFile = 0;
21572163
const char *zDb = 0;
21582164
sqlite3 *pDest;
21592165
sqlite3_backup *pBackup;
21602166
int j;
@@ -3498,10 +3504,30 @@
34983504
sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> ");
34993505
sqlite3_snprintf(sizeof(continuePrompt), continuePrompt," ...> ");
35003506
sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
35013507
}
35023508
3509
+/*
3510
+** Output text to the console in a font that attracts extra attention.
3511
+*/
3512
+#ifdef _WIN32
3513
+static void printBold(const char *zText){
3514
+ HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
3515
+ CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo;
3516
+ GetConsoleScreenBufferInfo(out, &defaultScreenInfo);
3517
+ SetConsoleTextAttribute(out,
3518
+ FOREGROUND_RED|FOREGROUND_INTENSITY
3519
+ );
3520
+ printf("%s", zText);
3521
+ SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes);
3522
+}
3523
+#else
3524
+static void printBold(const char *zText){
3525
+ printf("\033[1m%s\033[0m", zText);
3526
+}
3527
+#endif
3528
+
35033529
/*
35043530
** Get the argument to an --option. Throw an error and die if no argument
35053531
** is available.
35063532
*/
35073533
static char *cmdline_option_value(int argc, char **argv, int i){
@@ -3518,10 +3544,11 @@
35183544
struct callback_data data;
35193545
const char *zInitFile = 0;
35203546
char *zFirstCmd = 0;
35213547
int i;
35223548
int rc = 0;
3549
+ int warnInmemoryDb = 0;
35233550
35243551
if( sqlite3_libversion_number()<3008003 ){
35253552
fprintf(stderr, "Unsuitable SQLite version %s, must be at least 3.8.3",
35263553
sqlite3_libversion());
35273554
exit(1);
@@ -3612,18 +3639,20 @@
36123639
}
36133640
}
36143641
if( data.zDbFilename==0 ){
36153642
#ifndef SQLITE_OMIT_MEMORYDB
36163643
data.zDbFilename = ":memory:";
3644
+ warnInmemoryDb = argc==1;
36173645
#else
36183646
fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
36193647
return 1;
36203648
#endif
36213649
/***** Begin Fossil Patch *****/
36223650
{
36233651
extern void fossil_open(const char **);
36243652
fossil_open(&data.zDbFilename);
3653
+ warnInmemoryDb = 0;
36253654
}
36263655
/***** End Fossil Patch *****/
36273656
}
36283657
data.out = stdout;
36293658
@@ -3754,22 +3783,27 @@
37543783
char *zHome;
37553784
char *zHistory = 0;
37563785
int nHistory;
37573786
printf(
37583787
"SQLite version %s %.19s\n" /*extra-version-info*/
3759
- "Enter \".help\" for instructions\n"
3760
- "Enter SQL statements terminated with a \";\"\n",
3788
+ "Enter \".help\" for usage hints.\n",
37613789
sqlite3_libversion(), sqlite3_sourceid()
37623790
);
3791
+ if( warnInmemoryDb ){
3792
+ printf("Connected to a ");
3793
+ printBold("transient in-memory database.");
3794
+ printf("\nUse \".open FILENAME\" to reopen on a "
3795
+ "persistent database.\n");
3796
+ }
37633797
zHome = find_home_dir();
37643798
if( zHome ){
37653799
nHistory = strlen30(zHome) + 20;
37663800
if( (zHistory = malloc(nHistory))!=0 ){
37673801
sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
37683802
}
37693803
}
3770
-#if defined(HAVE_READLINE) && HAVE_READLINE==1
3804
+#if defined(HAVE_READLINE)
37713805
if( zHistory ) read_history(zHistory);
37723806
#endif
37733807
rc = process_input(&data, 0);
37743808
if( zHistory ){
37753809
stifle_history(100);
37763810
--- src/shell.c
+++ src/shell.c
@@ -43,18 +43,21 @@
43 # endif
44 # include <unistd.h>
45 # include <sys/types.h>
46 #endif
47
48 #ifdef HAVE_EDITLINE
49 # include <editline/editline.h>
50 #endif
51 #if defined(HAVE_READLINE) && HAVE_READLINE==1
52 # include <readline/readline.h>
53 # include <readline/history.h>
 
 
 
 
 
 
54 #endif
55 #if !defined(HAVE_EDITLINE) && (!defined(HAVE_READLINE) || HAVE_READLINE!=1)
56 # define add_history(X)
57 # define read_history(X)
58 # define write_history(X)
59 # define stifle_history(X)
60 #endif
@@ -411,11 +414,11 @@
411 char *zResult;
412 if( in!=0 ){
413 zResult = local_getline(zPrior, in);
414 }else{
415 zPrompt = isContinuation ? continuePrompt : mainPrompt;
416 #if defined(HAVE_READLINE) && HAVE_READLINE==1
417 free(zPrior);
418 zResult = readline(zPrompt);
419 if( zResult && *zResult ) add_history(zResult);
420 #else
421 printf("%s", zPrompt);
@@ -1581,10 +1584,11 @@
1581 ".print STRING... Print literal STRING\n"
1582 ".prompt MAIN CONTINUE Replace the standard prompts\n"
1583 ".quit Exit this program\n"
1584 ".read FILENAME Execute SQL in FILENAME\n"
1585 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
 
1586 ".schema ?TABLE? Show the CREATE statements\n"
1587 " If TABLE specified, only show tables matching\n"
1588 " LIKE pattern TABLE.\n"
1589 ".separator STRING Change separator used by output mode and .import\n"
1590 ".show Show the current values for various settings\n"
@@ -2150,11 +2154,13 @@
2150 /* Process the input line.
2151 */
2152 if( nArg==0 ) return 0; /* no tokens, no error */
2153 n = strlen30(azArg[0]);
2154 c = azArg[0][0];
2155 if( c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0 ){
 
 
2156 const char *zDestFile = 0;
2157 const char *zDb = 0;
2158 sqlite3 *pDest;
2159 sqlite3_backup *pBackup;
2160 int j;
@@ -3498,10 +3504,30 @@
3498 sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> ");
3499 sqlite3_snprintf(sizeof(continuePrompt), continuePrompt," ...> ");
3500 sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
3501 }
3502
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3503 /*
3504 ** Get the argument to an --option. Throw an error and die if no argument
3505 ** is available.
3506 */
3507 static char *cmdline_option_value(int argc, char **argv, int i){
@@ -3518,10 +3544,11 @@
3518 struct callback_data data;
3519 const char *zInitFile = 0;
3520 char *zFirstCmd = 0;
3521 int i;
3522 int rc = 0;
 
3523
3524 if( sqlite3_libversion_number()<3008003 ){
3525 fprintf(stderr, "Unsuitable SQLite version %s, must be at least 3.8.3",
3526 sqlite3_libversion());
3527 exit(1);
@@ -3612,18 +3639,20 @@
3612 }
3613 }
3614 if( data.zDbFilename==0 ){
3615 #ifndef SQLITE_OMIT_MEMORYDB
3616 data.zDbFilename = ":memory:";
 
3617 #else
3618 fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
3619 return 1;
3620 #endif
3621 /***** Begin Fossil Patch *****/
3622 {
3623 extern void fossil_open(const char **);
3624 fossil_open(&data.zDbFilename);
 
3625 }
3626 /***** End Fossil Patch *****/
3627 }
3628 data.out = stdout;
3629
@@ -3754,22 +3783,27 @@
3754 char *zHome;
3755 char *zHistory = 0;
3756 int nHistory;
3757 printf(
3758 "SQLite version %s %.19s\n" /*extra-version-info*/
3759 "Enter \".help\" for instructions\n"
3760 "Enter SQL statements terminated with a \";\"\n",
3761 sqlite3_libversion(), sqlite3_sourceid()
3762 );
 
 
 
 
 
 
3763 zHome = find_home_dir();
3764 if( zHome ){
3765 nHistory = strlen30(zHome) + 20;
3766 if( (zHistory = malloc(nHistory))!=0 ){
3767 sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
3768 }
3769 }
3770 #if defined(HAVE_READLINE) && HAVE_READLINE==1
3771 if( zHistory ) read_history(zHistory);
3772 #endif
3773 rc = process_input(&data, 0);
3774 if( zHistory ){
3775 stifle_history(100);
3776
--- src/shell.c
+++ src/shell.c
@@ -43,18 +43,21 @@
43 # endif
44 # include <unistd.h>
45 # include <sys/types.h>
46 #endif
47
48 #if defined(HAVE_READLINE) && HAVE_READLINE!=0
 
 
 
49 # include <readline/readline.h>
50 # include <readline/history.h>
51 #else
52 # undef HAVE_READLINE
53 #endif
54 #if defined(HAVE_EDITLINE) && !defined(HAVE_READLINE)
55 # define HAVE_READLINE 1
56 # include <editline/readline.h>
57 #endif
58 #if !defined(HAVE_READLINE)
59 # define add_history(X)
60 # define read_history(X)
61 # define write_history(X)
62 # define stifle_history(X)
63 #endif
@@ -411,11 +414,11 @@
414 char *zResult;
415 if( in!=0 ){
416 zResult = local_getline(zPrior, in);
417 }else{
418 zPrompt = isContinuation ? continuePrompt : mainPrompt;
419 #if defined(HAVE_READLINE)
420 free(zPrior);
421 zResult = readline(zPrompt);
422 if( zResult && *zResult ) add_history(zResult);
423 #else
424 printf("%s", zPrompt);
@@ -1581,10 +1584,11 @@
1584 ".print STRING... Print literal STRING\n"
1585 ".prompt MAIN CONTINUE Replace the standard prompts\n"
1586 ".quit Exit this program\n"
1587 ".read FILENAME Execute SQL in FILENAME\n"
1588 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
1589 ".save FILE Write in-memory database into FILE\n"
1590 ".schema ?TABLE? Show the CREATE statements\n"
1591 " If TABLE specified, only show tables matching\n"
1592 " LIKE pattern TABLE.\n"
1593 ".separator STRING Change separator used by output mode and .import\n"
1594 ".show Show the current values for various settings\n"
@@ -2150,11 +2154,13 @@
2154 /* Process the input line.
2155 */
2156 if( nArg==0 ) return 0; /* no tokens, no error */
2157 n = strlen30(azArg[0]);
2158 c = azArg[0][0];
2159 if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
2160 || (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
2161 ){
2162 const char *zDestFile = 0;
2163 const char *zDb = 0;
2164 sqlite3 *pDest;
2165 sqlite3_backup *pBackup;
2166 int j;
@@ -3498,10 +3504,30 @@
3504 sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> ");
3505 sqlite3_snprintf(sizeof(continuePrompt), continuePrompt," ...> ");
3506 sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
3507 }
3508
3509 /*
3510 ** Output text to the console in a font that attracts extra attention.
3511 */
3512 #ifdef _WIN32
3513 static void printBold(const char *zText){
3514 HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
3515 CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo;
3516 GetConsoleScreenBufferInfo(out, &defaultScreenInfo);
3517 SetConsoleTextAttribute(out,
3518 FOREGROUND_RED|FOREGROUND_INTENSITY
3519 );
3520 printf("%s", zText);
3521 SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes);
3522 }
3523 #else
3524 static void printBold(const char *zText){
3525 printf("\033[1m%s\033[0m", zText);
3526 }
3527 #endif
3528
3529 /*
3530 ** Get the argument to an --option. Throw an error and die if no argument
3531 ** is available.
3532 */
3533 static char *cmdline_option_value(int argc, char **argv, int i){
@@ -3518,10 +3544,11 @@
3544 struct callback_data data;
3545 const char *zInitFile = 0;
3546 char *zFirstCmd = 0;
3547 int i;
3548 int rc = 0;
3549 int warnInmemoryDb = 0;
3550
3551 if( sqlite3_libversion_number()<3008003 ){
3552 fprintf(stderr, "Unsuitable SQLite version %s, must be at least 3.8.3",
3553 sqlite3_libversion());
3554 exit(1);
@@ -3612,18 +3639,20 @@
3639 }
3640 }
3641 if( data.zDbFilename==0 ){
3642 #ifndef SQLITE_OMIT_MEMORYDB
3643 data.zDbFilename = ":memory:";
3644 warnInmemoryDb = argc==1;
3645 #else
3646 fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
3647 return 1;
3648 #endif
3649 /***** Begin Fossil Patch *****/
3650 {
3651 extern void fossil_open(const char **);
3652 fossil_open(&data.zDbFilename);
3653 warnInmemoryDb = 0;
3654 }
3655 /***** End Fossil Patch *****/
3656 }
3657 data.out = stdout;
3658
@@ -3754,22 +3783,27 @@
3783 char *zHome;
3784 char *zHistory = 0;
3785 int nHistory;
3786 printf(
3787 "SQLite version %s %.19s\n" /*extra-version-info*/
3788 "Enter \".help\" for usage hints.\n",
 
3789 sqlite3_libversion(), sqlite3_sourceid()
3790 );
3791 if( warnInmemoryDb ){
3792 printf("Connected to a ");
3793 printBold("transient in-memory database.");
3794 printf("\nUse \".open FILENAME\" to reopen on a "
3795 "persistent database.\n");
3796 }
3797 zHome = find_home_dir();
3798 if( zHome ){
3799 nHistory = strlen30(zHome) + 20;
3800 if( (zHistory = malloc(nHistory))!=0 ){
3801 sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
3802 }
3803 }
3804 #if defined(HAVE_READLINE)
3805 if( zHistory ) read_history(zHistory);
3806 #endif
3807 rc = process_input(&data, 0);
3808 if( zHistory ){
3809 stifle_history(100);
3810

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button