/ Check-in [0582168b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0582168b8b853559b484f4a024d28c67192160c4
User & Date: drh 2002-04-18 12:39:03
Context
2002-04-19
01:00
Added rights release for Matthew O. Persico (CVS 535) check-in: 6c32c07e user: persicom tags: trunk
2002-04-18
12:39
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) check-in: 0582168b user: drh tags: trunk
02:53
Updated to match new shell.c functionality. (CVS 533) check-in: ff67ad40 user: persicom tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code to implement the "sqlite" command line
    13     13   ** utility for accessing SQLite databases.
    14     14   **
    15         -** $Id: shell.c,v 1.52 2002/04/18 02:53:05 persicom Exp $
           15  +** $Id: shell.c,v 1.53 2002/04/18 12:39:03 drh Exp $
    16     16   */
    17     17   #include <stdlib.h>
    18     18   #include <string.h>
    19     19   #include <stdio.h>
    20     20   #include "sqlite.h"
    21     21   #include <ctype.h>
    22         -#include <pwd.h>
    23         -#include <sys/types.h>
    24     22   
    25     23   #if !defined(_WIN32) && !defined(WIN32)
    26     24   # include <signal.h>
           25  +# include <pwd.h>
           26  +# include <unistd.h>
           27  +# include <sys/types.h>
    27     28   #endif
    28     29   
    29     30   #if defined(HAVE_READLINE) && HAVE_READLINE==1
    30     31   # include <readline/readline.h>
    31     32   # include <readline/history.h>
    32     33   #else
    33     34   # define readline(p) getline(p,stdin)
................................................................................
   469    470   ** Text of a help message
   470    471   */
   471    472   static char zHelp[] =
   472    473     ".dump ?TABLE? ...      Dump the database in an text format\n"
   473    474     ".echo ON|OFF           Turn command echo on or off\n"
   474    475     ".exit                  Exit this program\n"
   475    476     ".explain ON|OFF        Turn output mode suitable for EXPLAIN on or off.\n"
   476         -  "                       \"off\" will revert to the output mode that was\n"
   477         -  "                       previously in effect\n"
   478    477     ".header(s) ON|OFF      Turn display of headers on or off\n"
   479    478     ".help                  Show this message\n"
   480    479     ".indices TABLE         Show names of all indices on TABLE\n"
   481    480     ".mode MODE             Set mode to one of \"line(s)\", \"column(s)\", \n"
   482    481     "                       \"insert\", \"list\", or \"html\"\n"
   483    482     ".mode insert TABLE     Generate SQL insert statements for TABLE\n"
   484    483     ".nullvalue STRING      Print STRING instead of nothing for NULL data\n"
   485    484     ".output FILENAME       Send output to FILENAME\n"
   486    485     ".output stdout         Send output to the screen\n"
   487    486     ".prompt MAIN CONTINUE  Replace the standard prompts\n"
   488         -  "                       \"sqlite > \" and \"   ...> \"\n"
   489         -  "                       with the strings MAIN and CONTINUE\n"
   490         -  "                       CONTINUE is optional.\n"
   491    487     ".quit                  Exit this program\n"
   492    488     ".read FILENAME         Execute SQL in FILENAME\n"
   493    489     ".reindex ?TABLE?       Rebuild indices\n"
   494    490   /*  ".rename OLD NEW        Change the name of a table or index\n" */
   495    491     ".schema ?TABLE?        Show the CREATE statements\n"
   496    492     ".separator STRING      Change separator string for \"list\" mode\n"
   497         -  ".show                  Show the current values for the following:\n"
   498         -  "                       .echo\n"
   499         -  "                       .explain\n"
   500         -  "                       .mode\n"
   501         -  "                       .nullvalue\n"
   502         -  "                       .output\n"
   503         -  "                       .separator\n"
   504         -  "                       .width\n"
          493  +  ".show                  Show the current values for various settings\n"
   505    494     ".tables ?PATTERN?      List names of tables matching a pattern\n"
   506    495     ".timeout MS            Try opening locked tables for MS milliseconds\n"
   507    496     ".width NUM NUM ...     Set column widths for \"column\" mode\n"
   508    497   ;
   509    498   
   510    499   /* Forward reference */
   511    500   static void process_input(struct callback_data *p, FILE *in);
................................................................................
   588    577     }else
   589    578   
   590    579     if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
   591    580       sqlite_close(db);
   592    581       exit(0);
   593    582     }else
   594    583   
   595         -  if( c=='e' && strncmp(azArg[0], "explain", n)==0 && nArg>1){
          584  +  if( c=='e' && strncmp(azArg[0], "explain", n)==0 ){
   596    585       int j;
   597         -    char *z = azArg[1];
   598         -    int val = atoi(azArg[1]);
          586  +    char *z = nArg>=2 ? azArg[1] : "1";
          587  +    int val = atoi(z);
   599    588       for(j=0; z[j]; j++){
   600    589         if( isupper(z[j]) ) z[j] = tolower(z[j]);
   601    590       }
   602    591       if( strcmp(z,"on")==0 ){
   603    592         val = 1;
   604    593       }else if( strcmp(z,"yes")==0 ){
   605    594         val = 1;
................................................................................
   717    706           p->out = stdout;
   718    707         } else {
   719    708            strcpy(p->outfile,azArg[1]);
   720    709         }
   721    710       }
   722    711     }else
   723    712   
   724         -  if( c=='p' && strncmp(azArg[0], "prompt", n)==0 && nArg==2 || nArg==3){
          713  +  if( c=='p' && strncmp(azArg[0], "prompt", n)==0 && (nArg==2 || nArg==3)){
   725    714       if( nArg >= 2) {
   726    715         strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
   727    716       }
   728    717       if( nArg >= 3) {
   729    718         strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
   730    719       }
   731    720     }else
................................................................................
   825    814       sprintf(p->separator, "%.*s", (int)ArraySize(p->separator)-1, azArg[1]);
   826    815     }else
   827    816   
   828    817     if( c=='s' && strncmp(azArg[0], "show", n)==0){
   829    818       int i;
   830    819       fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
   831    820       fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" : "off");
          821  +    fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
   832    822       fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
   833    823       fprintf(p->out,"%9.9s: %s\n","nullvalue", p->nullvalue);
   834    824       fprintf(p->out,"%9.9s: %s\n","output", strlen(p->outfile) ? p->outfile : "stdout");
   835    825       fprintf(p->out,"%9.9s: %s\n","separator", p->separator);
   836    826       fprintf(p->out,"%9.9s: ","width");
   837    827       for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
   838    828           fprintf(p->out,"%d ",p->colWidth[i]);
................................................................................
   956    946   }
   957    947   
   958    948   static void process_sqliterc(struct callback_data *p,
   959    949                                char *sqliterc_override){
   960    950   
   961    951     char *home_dir = NULL;
   962    952     char *sqliterc = sqliterc_override;
   963         -  struct passwd *pwent;
   964         -  uid_t uid = getuid();
   965    953     FILE *in = NULL;
   966    954   
   967    955     if (sqliterc == NULL) {
   968    956       /* Figure out the user's home directory */
          957  +#if !defined(_WIN32) && !defined(WIN32)
          958  +    struct passwd *pwent;
          959  +    uid_t uid = getuid();
   969    960       while( (pwent=getpwent()) != NULL) {
   970    961         if(pwent->pw_uid == uid) {
   971    962           home_dir = pwent->pw_dir;
   972    963           break;
   973    964         }
   974    965       }
          966  +#endif
   975    967   
   976    968       if (!home_dir) {
   977    969         home_dir = getenv("HOME");
   978    970         if (!home_dir) {
   979    971           home_dir = getenv("HOMEPATH"); /* Windows? */
   980    972         }
   981    973         if (!home_dir) {
................................................................................
   999    991     if(!in) {
  1000    992       /* File either had an error or was not found. Since I cannot
  1001    993        * tell, I cannot bark. */
  1002    994       return;
  1003    995     } else {
  1004    996       printf("Loading resources from %s\n",sqliterc);
  1005    997       process_input(p,in);
  1006         -    close (in);
          998  +    fclose(in);
  1007    999     }
  1008   1000     return;
  1009   1001   }
  1010   1002   
  1011   1003   void main_init(struct callback_data *data) {
  1012   1004     memset(data, 0, sizeof(*data));
  1013   1005     data->mode = MODE_List;