1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-06 15:49:35 +03:00

Change shell.c so that it will compile under windows. Shorten the help

command somewhat.  Add the state of ".header" to the output of ".show". (CVS 534)

FossilOrigin-Name: 0582168b8b853559b484f4a024d28c67192160c4
This commit is contained in:
drh
2002-04-18 12:39:03 +00:00
parent 45698a3a03
commit dd45df8a5b
3 changed files with 23 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
C Updated\sto\smatch\snew\sshell.c\sfunctionality.\s(CVS\s533) C Change\sshell.c\sso\sthat\sit\swill\scompile\sunder\swindows.\s\sShorten\sthe\shelp\ncommand\ssomewhat.\s\sAdd\sthe\sstate\sof\s".header"\sto\sthe\soutput\sof\s".show".\s(CVS\s534)
D 2002-04-18T02:53:54 D 2002-04-18T12:39:03
F Makefile.in 50f1b3351df109b5774771350d8c1b8d3640130d F Makefile.in 50f1b3351df109b5774771350d8c1b8d3640130d
F Makefile.template 89e373b2dad0321df00400fa968dc14b61a03296 F Makefile.template 89e373b2dad0321df00400fa968dc14b61a03296
F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0 F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
@@ -39,7 +39,7 @@ F src/parse.y 9a8a2311dd95101bb02b3991042e619eea49729a
F src/printf.c 300a90554345751f26e1fc0c0333b90a66110a1d F src/printf.c 300a90554345751f26e1fc0c0333b90a66110a1d
F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe
F src/select.c 92aef3f69e90dc065d680d88b1f075409e9249bb F src/select.c 92aef3f69e90dc065d680d88b1f075409e9249bb
F src/shell.c e473e19509c5c9b02bb2fb674be4b223cb052334 F src/shell.c 4a225aa846f494488d9bab324b68749d25a890b7
F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
F src/sqlite.h.in ffcacf73b5ed1a4939205d29a704a185758fa6a6 F src/sqlite.h.in ffcacf73b5ed1a4939205d29a704a185758fa6a6
F src/sqliteInt.h e47ca9267a4c4a98e9f8d90c2df994a18f23d699 F src/sqliteInt.h e47ca9267a4c4a98e9f8d90c2df994a18f23d699
@@ -131,7 +131,7 @@ F www/speed.tcl da8afcc1d3ccc5696cfb388a68982bc3d9f7f00f
F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279 F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
P 4bdd040e4810565c91bcbb5f065580520c5e3c45 P ff67ad40106a20fb85797cca4c495dc34ad5519b
R fccec3c1f56efdafc771baab879ce3fe R 83edff024b8dcab1f99c47b3727e4d20
U persicom U drh
Z f4c9300a9a77dcec47079904c2bfe5db Z 1f0ab834158fafdf0840052f540be94f

View File

@@ -1 +1 @@
ff67ad40106a20fb85797cca4c495dc34ad5519b 0582168b8b853559b484f4a024d28c67192160c4

View File

@@ -12,18 +12,19 @@
** This file contains code to implement the "sqlite" command line ** This file contains code to implement the "sqlite" command line
** utility for accessing SQLite databases. ** utility for accessing SQLite databases.
** **
** $Id: shell.c,v 1.52 2002/04/18 02:53:05 persicom Exp $ ** $Id: shell.c,v 1.53 2002/04/18 12:39:03 drh Exp $
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include "sqlite.h" #include "sqlite.h"
#include <ctype.h> #include <ctype.h>
#include <pwd.h>
#include <sys/types.h>
#if !defined(_WIN32) && !defined(WIN32) #if !defined(_WIN32) && !defined(WIN32)
# include <signal.h> # include <signal.h>
# include <pwd.h>
# include <unistd.h>
# include <sys/types.h>
#endif #endif
#if defined(HAVE_READLINE) && HAVE_READLINE==1 #if defined(HAVE_READLINE) && HAVE_READLINE==1
@@ -473,8 +474,6 @@ static char zHelp[] =
".echo ON|OFF Turn command echo on or off\n" ".echo ON|OFF Turn command echo on or off\n"
".exit Exit this program\n" ".exit Exit this program\n"
".explain ON|OFF Turn output mode suitable for EXPLAIN on or off.\n" ".explain ON|OFF Turn output mode suitable for EXPLAIN on or off.\n"
" \"off\" will revert to the output mode that was\n"
" previously in effect\n"
".header(s) ON|OFF Turn display of headers on or off\n" ".header(s) ON|OFF Turn display of headers on or off\n"
".help Show this message\n" ".help Show this message\n"
".indices TABLE Show names of all indices on TABLE\n" ".indices TABLE Show names of all indices on TABLE\n"
@@ -485,23 +484,13 @@ static char zHelp[] =
".output FILENAME Send output to FILENAME\n" ".output FILENAME Send output to FILENAME\n"
".output stdout Send output to the screen\n" ".output stdout Send output to the screen\n"
".prompt MAIN CONTINUE Replace the standard prompts\n" ".prompt MAIN CONTINUE Replace the standard prompts\n"
" \"sqlite > \" and \" ...> \"\n"
" with the strings MAIN and CONTINUE\n"
" CONTINUE is optional.\n"
".quit Exit this program\n" ".quit Exit this program\n"
".read FILENAME Execute SQL in FILENAME\n" ".read FILENAME Execute SQL in FILENAME\n"
".reindex ?TABLE? Rebuild indices\n" ".reindex ?TABLE? Rebuild indices\n"
/* ".rename OLD NEW Change the name of a table or index\n" */ /* ".rename OLD NEW Change the name of a table or index\n" */
".schema ?TABLE? Show the CREATE statements\n" ".schema ?TABLE? Show the CREATE statements\n"
".separator STRING Change separator string for \"list\" mode\n" ".separator STRING Change separator string for \"list\" mode\n"
".show Show the current values for the following:\n" ".show Show the current values for various settings\n"
" .echo\n"
" .explain\n"
" .mode\n"
" .nullvalue\n"
" .output\n"
" .separator\n"
" .width\n"
".tables ?PATTERN? List names of tables matching a pattern\n" ".tables ?PATTERN? List names of tables matching a pattern\n"
".timeout MS Try opening locked tables for MS milliseconds\n" ".timeout MS Try opening locked tables for MS milliseconds\n"
".width NUM NUM ... Set column widths for \"column\" mode\n" ".width NUM NUM ... Set column widths for \"column\" mode\n"
@@ -592,10 +581,10 @@ static void do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
exit(0); exit(0);
}else }else
if( c=='e' && strncmp(azArg[0], "explain", n)==0 && nArg>1){ if( c=='e' && strncmp(azArg[0], "explain", n)==0 ){
int j; int j;
char *z = azArg[1]; char *z = nArg>=2 ? azArg[1] : "1";
int val = atoi(azArg[1]); int val = atoi(z);
for(j=0; z[j]; j++){ for(j=0; z[j]; j++){
if( isupper(z[j]) ) z[j] = tolower(z[j]); if( isupper(z[j]) ) z[j] = tolower(z[j]);
} }
@@ -721,7 +710,7 @@ static void do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
} }
}else }else
if( c=='p' && strncmp(azArg[0], "prompt", n)==0 && nArg==2 || nArg==3){ if( c=='p' && strncmp(azArg[0], "prompt", n)==0 && (nArg==2 || nArg==3)){
if( nArg >= 2) { if( nArg >= 2) {
strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1); strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
} }
@@ -829,6 +818,7 @@ static void do_meta_command(char *zLine, sqlite *db, struct callback_data *p){
int i; int i;
fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off"); fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" : "off"); fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" : "off");
fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]); fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
fprintf(p->out,"%9.9s: %s\n","nullvalue", p->nullvalue); fprintf(p->out,"%9.9s: %s\n","nullvalue", p->nullvalue);
fprintf(p->out,"%9.9s: %s\n","output", strlen(p->outfile) ? p->outfile : "stdout"); fprintf(p->out,"%9.9s: %s\n","output", strlen(p->outfile) ? p->outfile : "stdout");
@@ -960,18 +950,20 @@ static void process_sqliterc(struct callback_data *p,
char *home_dir = NULL; char *home_dir = NULL;
char *sqliterc = sqliterc_override; char *sqliterc = sqliterc_override;
struct passwd *pwent;
uid_t uid = getuid();
FILE *in = NULL; FILE *in = NULL;
if (sqliterc == NULL) { if (sqliterc == NULL) {
/* Figure out the user's home directory */ /* Figure out the user's home directory */
#if !defined(_WIN32) && !defined(WIN32)
struct passwd *pwent;
uid_t uid = getuid();
while( (pwent=getpwent()) != NULL) { while( (pwent=getpwent()) != NULL) {
if(pwent->pw_uid == uid) { if(pwent->pw_uid == uid) {
home_dir = pwent->pw_dir; home_dir = pwent->pw_dir;
break; break;
} }
} }
#endif
if (!home_dir) { if (!home_dir) {
home_dir = getenv("HOME"); home_dir = getenv("HOME");
@@ -1003,7 +995,7 @@ static void process_sqliterc(struct callback_data *p,
} else { } else {
printf("Loading resources from %s\n",sqliterc); printf("Loading resources from %s\n",sqliterc);
process_input(p,in); process_input(p,in);
close (in); fclose(in);
} }
return; return;
} }