/ Check-in [fd7f51a1]
Login

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

Overview
Comment:Rearrange some routines in shell.c to avoid the need to forward reference a static function.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: fd7f51a107806666d5c3a3a7a62528ec3e1fb71c4256f49d57b4dcdac4bf8680
User & Date: drh 2018-01-10 00:53:55
Context
2018-01-10
13:11
Work on the ".archive" command. (1) Add the --dryrun option. (2) Do not require --file when open on a ZIP archive. (3) Miscellaneous code simplifications. This is an incremental check-in of work in progress. check-in: a2baada4 user: drh tags: archive-improvements
11:56
Fix a problem in os_unix.c causing it to return SQLITE_CANTOPEN instead of SQLITE_READONLY_RECOVERY. check-in: 6a16f554 user: dan tags: trunk
00:53
Rearrange some routines in shell.c to avoid the need to forward reference a static function. check-in: fd7f51a1 user: drh tags: trunk
00:40
Compute the correct column name even if the column identifier is the very last token in the SQL statement. This fixes a problem introduced by check-in [0fdf97efe5df745510c6b] and reported by the community during beta-testing. check-in: 36b89d72 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.in.

   348    348   #endif
   349    349   
   350    350   /*
   351    351   ** Used to prevent warnings about unused parameters
   352    352   */
   353    353   #define UNUSED_PARAMETER(x) (void)(x)
   354    354   
          355  +/*
          356  +** Number of elements in an array
          357  +*/
          358  +#define ArraySize(X)  (int)(sizeof(X)/sizeof(X[0]))
          359  +
   355    360   /*
   356    361   ** If the following flag is set, then command execution stops
   357    362   ** at an error if we are not interactive.
   358    363   */
   359    364   static int bail_on_error = 0;
   360    365   
   361    366   /*
................................................................................
   620    625       free(zPrior);
   621    626       zResult = shell_readline(zPrompt);
   622    627       if( zResult && *zResult ) shell_add_history(zResult);
   623    628   #endif
   624    629     }
   625    630     return zResult;
   626    631   }
          632  +
          633  +
          634  +/*
          635  +** Return the value of a hexadecimal digit.  Return -1 if the input
          636  +** is not a hex digit.
          637  +*/
          638  +static int hexDigitValue(char c){
          639  +  if( c>='0' && c<='9' ) return c - '0';
          640  +  if( c>='a' && c<='f' ) return c - 'a' + 10;
          641  +  if( c>='A' && c<='F' ) return c - 'A' + 10;
          642  +  return -1;
          643  +}
          644  +
          645  +/*
          646  +** Interpret zArg as an integer value, possibly with suffixes.
          647  +*/
          648  +static sqlite3_int64 integerValue(const char *zArg){
          649  +  sqlite3_int64 v = 0;
          650  +  static const struct { char *zSuffix; int iMult; } aMult[] = {
          651  +    { "KiB", 1024 },
          652  +    { "MiB", 1024*1024 },
          653  +    { "GiB", 1024*1024*1024 },
          654  +    { "KB",  1000 },
          655  +    { "MB",  1000000 },
          656  +    { "GB",  1000000000 },
          657  +    { "K",   1000 },
          658  +    { "M",   1000000 },
          659  +    { "G",   1000000000 },
          660  +  };
          661  +  int i;
          662  +  int isNeg = 0;
          663  +  if( zArg[0]=='-' ){
          664  +    isNeg = 1;
          665  +    zArg++;
          666  +  }else if( zArg[0]=='+' ){
          667  +    zArg++;
          668  +  }
          669  +  if( zArg[0]=='0' && zArg[1]=='x' ){
          670  +    int x;
          671  +    zArg += 2;
          672  +    while( (x = hexDigitValue(zArg[0]))>=0 ){
          673  +      v = (v<<4) + x;
          674  +      zArg++;
          675  +    }
          676  +  }else{
          677  +    while( IsDigit(zArg[0]) ){
          678  +      v = v*10 + zArg[0] - '0';
          679  +      zArg++;
          680  +    }
          681  +  }
          682  +  for(i=0; i<ArraySize(aMult); i++){
          683  +    if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
          684  +      v *= aMult[i].iMult;
          685  +      break;
          686  +    }
          687  +  }
          688  +  return isNeg? -v : v;
          689  +}
          690  +
   627    691   /*
   628    692   ** A variable length string to which one can append text.
   629    693   */
   630    694   typedef struct ShellText ShellText;
   631    695   struct ShellText {
   632    696     char *z;
   633    697     int n;
................................................................................
  1057   1121   #define SEP_Tab       "\t"
  1058   1122   #define SEP_Space     " "
  1059   1123   #define SEP_Comma     ","
  1060   1124   #define SEP_CrLf      "\r\n"
  1061   1125   #define SEP_Unit      "\x1F"
  1062   1126   #define SEP_Record    "\x1E"
  1063   1127   
  1064         -/*
  1065         -** Number of elements in an array
  1066         -*/
  1067         -#define ArraySize(X)  (int)(sizeof(X)/sizeof(X[0]))
  1068         -
  1069   1128   /*
  1070   1129   ** A callback for the sqlite3_log() interface.
  1071   1130   */
  1072   1131   static void shellLog(void *pArg, int iErrCode, const char *zMsg){
  1073   1132     ShellState *p = (ShellState*)pArg;
  1074   1133     if( p->pLog==0 ) return;
  1075   1134     utf8_printf(p->pLog, "(%d) %s\n", iErrCode, zMsg);
................................................................................
  2469   2528       }
  2470   2529     }
  2471   2530     sqlite3_expert_destroy(p);
  2472   2531     pState->expert.pExpert = 0;
  2473   2532     return rc;
  2474   2533   }
  2475   2534   
  2476         -static sqlite3_int64 integerValue(const char *zArg);
  2477         -
  2478   2535   /*
  2479   2536   ** Implementation of ".expert" dot command.
  2480   2537   */
  2481   2538   static int expertDotCommand(
  2482   2539     ShellState *pState,             /* Current shell tool state */
  2483   2540     char **azArg,                   /* Array of arguments passed to dot command */
  2484   2541     int nArg                        /* Number of entries in azArg[] */
................................................................................
  3379   3436         }
  3380   3437       }
  3381   3438       z[j] = c;
  3382   3439     }
  3383   3440     if( j<i ) z[j] = 0;
  3384   3441   }
  3385   3442   
  3386         -/*
  3387         -** Return the value of a hexadecimal digit.  Return -1 if the input
  3388         -** is not a hex digit.
  3389         -*/
  3390         -static int hexDigitValue(char c){
  3391         -  if( c>='0' && c<='9' ) return c - '0';
  3392         -  if( c>='a' && c<='f' ) return c - 'a' + 10;
  3393         -  if( c>='A' && c<='F' ) return c - 'A' + 10;
  3394         -  return -1;
  3395         -}
  3396         -
  3397         -/*
  3398         -** Interpret zArg as an integer value, possibly with suffixes.
  3399         -*/
  3400         -static sqlite3_int64 integerValue(const char *zArg){
  3401         -  sqlite3_int64 v = 0;
  3402         -  static const struct { char *zSuffix; int iMult; } aMult[] = {
  3403         -    { "KiB", 1024 },
  3404         -    { "MiB", 1024*1024 },
  3405         -    { "GiB", 1024*1024*1024 },
  3406         -    { "KB",  1000 },
  3407         -    { "MB",  1000000 },
  3408         -    { "GB",  1000000000 },
  3409         -    { "K",   1000 },
  3410         -    { "M",   1000000 },
  3411         -    { "G",   1000000000 },
  3412         -  };
  3413         -  int i;
  3414         -  int isNeg = 0;
  3415         -  if( zArg[0]=='-' ){
  3416         -    isNeg = 1;
  3417         -    zArg++;
  3418         -  }else if( zArg[0]=='+' ){
  3419         -    zArg++;
  3420         -  }
  3421         -  if( zArg[0]=='0' && zArg[1]=='x' ){
  3422         -    int x;
  3423         -    zArg += 2;
  3424         -    while( (x = hexDigitValue(zArg[0]))>=0 ){
  3425         -      v = (v<<4) + x;
  3426         -      zArg++;
  3427         -    }
  3428         -  }else{
  3429         -    while( IsDigit(zArg[0]) ){
  3430         -      v = v*10 + zArg[0] - '0';
  3431         -      zArg++;
  3432         -    }
  3433         -  }
  3434         -  for(i=0; i<ArraySize(aMult); i++){
  3435         -    if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
  3436         -      v *= aMult[i].iMult;
  3437         -      break;
  3438         -    }
  3439         -  }
  3440         -  return isNeg? -v : v;
  3441         -}
  3442         -
  3443   3443   /*
  3444   3444   ** Interpret zArg as either an integer or a boolean value.  Return 1 or 0
  3445   3445   ** for TRUE and FALSE.  Return the integer value if appropriate.
  3446   3446   */
  3447   3447   static int booleanValue(const char *zArg){
  3448   3448     int i;
  3449   3449     if( zArg[0]=='0' && zArg[1]=='x' ){