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.
Commit
e327614047ebc42941c58b87a9bc3eea8c5f7605
Parent
dce0566b2ad6691…
1 file changed
+44
-10
+44
-10
| --- src/shell.c | ||
| +++ src/shell.c | ||
| @@ -43,18 +43,21 @@ | ||
| 43 | 43 | # endif |
| 44 | 44 | # include <unistd.h> |
| 45 | 45 | # include <sys/types.h> |
| 46 | 46 | #endif |
| 47 | 47 | |
| 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 | |
| 52 | 49 | # include <readline/readline.h> |
| 53 | 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> | |
| 54 | 57 | #endif |
| 55 | -#if !defined(HAVE_EDITLINE) && (!defined(HAVE_READLINE) || HAVE_READLINE!=1) | |
| 58 | +#if !defined(HAVE_READLINE) | |
| 56 | 59 | # define add_history(X) |
| 57 | 60 | # define read_history(X) |
| 58 | 61 | # define write_history(X) |
| 59 | 62 | # define stifle_history(X) |
| 60 | 63 | #endif |
| @@ -411,11 +414,11 @@ | ||
| 411 | 414 | char *zResult; |
| 412 | 415 | if( in!=0 ){ |
| 413 | 416 | zResult = local_getline(zPrior, in); |
| 414 | 417 | }else{ |
| 415 | 418 | zPrompt = isContinuation ? continuePrompt : mainPrompt; |
| 416 | -#if defined(HAVE_READLINE) && HAVE_READLINE==1 | |
| 419 | +#if defined(HAVE_READLINE) | |
| 417 | 420 | free(zPrior); |
| 418 | 421 | zResult = readline(zPrompt); |
| 419 | 422 | if( zResult && *zResult ) add_history(zResult); |
| 420 | 423 | #else |
| 421 | 424 | printf("%s", zPrompt); |
| @@ -1581,10 +1584,11 @@ | ||
| 1581 | 1584 | ".print STRING... Print literal STRING\n" |
| 1582 | 1585 | ".prompt MAIN CONTINUE Replace the standard prompts\n" |
| 1583 | 1586 | ".quit Exit this program\n" |
| 1584 | 1587 | ".read FILENAME Execute SQL in FILENAME\n" |
| 1585 | 1588 | ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n" |
| 1589 | + ".save FILE Write in-memory database into FILE\n" | |
| 1586 | 1590 | ".schema ?TABLE? Show the CREATE statements\n" |
| 1587 | 1591 | " If TABLE specified, only show tables matching\n" |
| 1588 | 1592 | " LIKE pattern TABLE.\n" |
| 1589 | 1593 | ".separator STRING Change separator used by output mode and .import\n" |
| 1590 | 1594 | ".show Show the current values for various settings\n" |
| @@ -2150,11 +2154,13 @@ | ||
| 2150 | 2154 | /* Process the input line. |
| 2151 | 2155 | */ |
| 2152 | 2156 | if( nArg==0 ) return 0; /* no tokens, no error */ |
| 2153 | 2157 | n = strlen30(azArg[0]); |
| 2154 | 2158 | 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 | + ){ | |
| 2156 | 2162 | const char *zDestFile = 0; |
| 2157 | 2163 | const char *zDb = 0; |
| 2158 | 2164 | sqlite3 *pDest; |
| 2159 | 2165 | sqlite3_backup *pBackup; |
| 2160 | 2166 | int j; |
| @@ -3498,10 +3504,30 @@ | ||
| 3498 | 3504 | sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> "); |
| 3499 | 3505 | sqlite3_snprintf(sizeof(continuePrompt), continuePrompt," ...> "); |
| 3500 | 3506 | sqlite3_config(SQLITE_CONFIG_SINGLETHREAD); |
| 3501 | 3507 | } |
| 3502 | 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 | + | |
| 3503 | 3529 | /* |
| 3504 | 3530 | ** Get the argument to an --option. Throw an error and die if no argument |
| 3505 | 3531 | ** is available. |
| 3506 | 3532 | */ |
| 3507 | 3533 | static char *cmdline_option_value(int argc, char **argv, int i){ |
| @@ -3518,10 +3544,11 @@ | ||
| 3518 | 3544 | struct callback_data data; |
| 3519 | 3545 | const char *zInitFile = 0; |
| 3520 | 3546 | char *zFirstCmd = 0; |
| 3521 | 3547 | int i; |
| 3522 | 3548 | int rc = 0; |
| 3549 | + int warnInmemoryDb = 0; | |
| 3523 | 3550 | |
| 3524 | 3551 | if( sqlite3_libversion_number()<3008003 ){ |
| 3525 | 3552 | fprintf(stderr, "Unsuitable SQLite version %s, must be at least 3.8.3", |
| 3526 | 3553 | sqlite3_libversion()); |
| 3527 | 3554 | exit(1); |
| @@ -3612,18 +3639,20 @@ | ||
| 3612 | 3639 | } |
| 3613 | 3640 | } |
| 3614 | 3641 | if( data.zDbFilename==0 ){ |
| 3615 | 3642 | #ifndef SQLITE_OMIT_MEMORYDB |
| 3616 | 3643 | data.zDbFilename = ":memory:"; |
| 3644 | + warnInmemoryDb = argc==1; | |
| 3617 | 3645 | #else |
| 3618 | 3646 | fprintf(stderr,"%s: Error: no database filename specified\n", Argv0); |
| 3619 | 3647 | return 1; |
| 3620 | 3648 | #endif |
| 3621 | 3649 | /***** Begin Fossil Patch *****/ |
| 3622 | 3650 | { |
| 3623 | 3651 | extern void fossil_open(const char **); |
| 3624 | 3652 | fossil_open(&data.zDbFilename); |
| 3653 | + warnInmemoryDb = 0; | |
| 3625 | 3654 | } |
| 3626 | 3655 | /***** End Fossil Patch *****/ |
| 3627 | 3656 | } |
| 3628 | 3657 | data.out = stdout; |
| 3629 | 3658 | |
| @@ -3754,22 +3783,27 @@ | ||
| 3754 | 3783 | char *zHome; |
| 3755 | 3784 | char *zHistory = 0; |
| 3756 | 3785 | int nHistory; |
| 3757 | 3786 | printf( |
| 3758 | 3787 | "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", | |
| 3761 | 3789 | sqlite3_libversion(), sqlite3_sourceid() |
| 3762 | 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 | + } | |
| 3763 | 3797 | zHome = find_home_dir(); |
| 3764 | 3798 | if( zHome ){ |
| 3765 | 3799 | nHistory = strlen30(zHome) + 20; |
| 3766 | 3800 | if( (zHistory = malloc(nHistory))!=0 ){ |
| 3767 | 3801 | sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome); |
| 3768 | 3802 | } |
| 3769 | 3803 | } |
| 3770 | -#if defined(HAVE_READLINE) && HAVE_READLINE==1 | |
| 3804 | +#if defined(HAVE_READLINE) | |
| 3771 | 3805 | if( zHistory ) read_history(zHistory); |
| 3772 | 3806 | #endif |
| 3773 | 3807 | rc = process_input(&data, 0); |
| 3774 | 3808 | if( zHistory ){ |
| 3775 | 3809 | stifle_history(100); |
| 3776 | 3810 |
| --- 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 |