/ Check-in [34eb6911]
Login

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

Overview
Comment:Fix uses of ctype functions (ex: isspace()) on signed characters in test programs and in some obscure extensions. No changes to the core.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 34eb6911afee09e779318b79baf953f616200128
User & Date: drh 2015-10-29 13:48:15
Context
2015-10-30
14:25
Add the --enable-editline option to various autoconf scripts. check-in: 866f0277 user: drh tags: trunk
2015-10-29
13:48
Fix uses of ctype functions (ex: isspace()) on signed characters in test programs and in some obscure extensions. No changes to the core. check-in: 34eb6911 user: drh tags: trunk
01:11
Enhance comments in the MSVC batch build tool. check-in: 2964ce25 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to autoconf/tea/win/nmakehlp.c.

   599    599   	/*
   600    600   	 * Build a list of substutitions from the first filename
   601    601   	 */
   602    602   
   603    603   	sp = fopen(substitutions, "rt");
   604    604   	if (sp != NULL) {
   605    605   	    while (fgets(szBuffer, cbBuffer, sp) != NULL) {
   606         -		char *ks, *ke, *vs, *ve;
   607         -		ks = szBuffer;
          606  +		unsigned char *ks, *ke, *vs, *ve;
          607  +		ks = (unsigned char*)szBuffer;
   608    608   		while (ks && *ks && isspace(*ks)) ++ks;
   609    609   		ke = ks;
   610    610   		while (ke && *ke && !isspace(*ke)) ++ke;
   611    611   		vs = ke;
   612    612   		while (vs && *vs && isspace(*vs)) ++vs;
   613    613   		ve = vs;
   614    614   		while (ve && *ve && !(*ve == '\r' || *ve == '\n')) ++ve;
   615    615   		*ke = 0, *ve = 0;
   616         -		list_insert(&substPtr, ks, vs);
          616  +		list_insert(&substPtr, (char*)ks, (char*)vs);
   617    617   	    }
   618    618   	    fclose(sp);
   619    619   	}
   620    620   
   621    621   	/* debug: dump the list */
   622    622   #ifdef _DEBUG
   623    623   	{

Changes to ext/fts1/fts1.c.

   201    201   */
   202    202   /* TODO(shess) The snippet-generation code should be using the
   203    203   ** tokenizer-generated tokens rather than doing its own local
   204    204   ** tokenization.
   205    205   */
   206    206   /* TODO(shess) Is __isascii() a portable version of (c&0x80)==0? */
   207    207   static int safe_isspace(char c){
   208         -  return (c&0x80)==0 ? isspace(c) : 0;
          208  +  return (c&0x80)==0 ? isspace((unsigned char)c) : 0;
   209    209   }
   210    210   static int safe_tolower(char c){
   211         -  return (c&0x80)==0 ? tolower(c) : c;
          211  +  return (c&0x80)==0 ? tolower((unsigned char)c) : c;
   212    212   }
   213    213   static int safe_isalnum(char c){
   214         -  return (c&0x80)==0 ? isalnum(c) : 0;
          214  +  return (c&0x80)==0 ? isalnum((unsigned char)c) : 0;
   215    215   }
   216    216   
   217    217   typedef enum DocListType {
   218    218     DL_DOCIDS,              /* docids only */
   219    219     DL_POSITIONS,           /* docids + positions */
   220    220     DL_POSITIONS_OFFSETS    /* docids + positions + offsets */
   221    221   } DocListType;

Changes to ext/fts1/simple_tokenizer.c.

   134    134           c->zToken = realloc(c->zToken, n+1);
   135    135         }
   136    136         for(ii=0; ii<n; ii++){
   137    137           /* TODO(shess) This needs expansion to handle UTF-8
   138    138           ** case-insensitivity.
   139    139           */
   140    140           char ch = c->pCurrent[ii];
   141         -        c->zToken[ii] = (unsigned char)ch<0x80 ? tolower(ch) : ch;
          141  +        c->zToken[ii] = (unsigned char)ch<0x80 ? tolower((unsigned char)ch):ch;
   142    142         }
   143    143         c->zToken[n] = '\0';
   144    144         *ppToken = c->zToken;
   145    145         *pnBytes = n;
   146    146         *piStartOffset = (int) (c->pCurrent-c->pInput);
   147    147         *piEndOffset = *piStartOffset+n;
   148    148         *piPosition = c->iToken++;

Changes to ext/misc/amatch.c.

   812    812   */
   813    813   static const char *amatchValueOfKey(const char *zKey, const char *zStr){
   814    814     int nKey = (int)strlen(zKey);
   815    815     int nStr = (int)strlen(zStr);
   816    816     int i;
   817    817     if( nStr<nKey+1 ) return 0;
   818    818     if( memcmp(zStr, zKey, nKey)!=0 ) return 0;
   819         -  for(i=nKey; isspace(zStr[i]); i++){}
          819  +  for(i=nKey; isspace((unsigned char)zStr[i]); i++){}
   820    820     if( zStr[i]!='=' ) return 0;
   821    821     i++;
   822         -  while( isspace(zStr[i]) ){ i++; }
          822  +  while( isspace((unsigned char)zStr[i]) ){ i++; }
   823    823     return zStr+i;
   824    824   }
   825    825   
   826    826   /*
   827    827   ** xConnect/xCreate method for the amatch module. Arguments are:
   828    828   **
   829    829   **   argv[0]    -> module name  ("approximate_match")

Changes to ext/misc/closure.c.

   482    482   */
   483    483   static const char *closureValueOfKey(const char *zKey, const char *zStr){
   484    484     int nKey = (int)strlen(zKey);
   485    485     int nStr = (int)strlen(zStr);
   486    486     int i;
   487    487     if( nStr<nKey+1 ) return 0;
   488    488     if( memcmp(zStr, zKey, nKey)!=0 ) return 0;
   489         -  for(i=nKey; isspace(zStr[i]); i++){}
          489  +  for(i=nKey; isspace((unsigned char)zStr[i]); i++){}
   490    490     if( zStr[i]!='=' ) return 0;
   491    491     i++;
   492         -  while( isspace(zStr[i]) ){ i++; }
          492  +  while( isspace((unsigned char)zStr[i]) ){ i++; }
   493    493     return zStr+i;
   494    494   }
   495    495   
   496    496   /*
   497    497   ** xConnect/xCreate method for the closure module. Arguments are:
   498    498   **
   499    499   **   argv[0]    -> module name  ("transitive_closure")

Changes to ext/misc/spellfix.c.

  1847   1847   ** Make a copy of a string.  Remove leading and trailing whitespace
  1848   1848   ** and dequote it.
  1849   1849   */
  1850   1850   static char *spellfix1Dequote(const char *zIn){
  1851   1851     char *zOut;
  1852   1852     int i, j;
  1853   1853     char c;
  1854         -  while( isspace(zIn[0]) ) zIn++;
         1854  +  while( isspace((unsigned char)zIn[0]) ) zIn++;
  1855   1855     zOut = sqlite3_mprintf("%s", zIn);
  1856   1856     if( zOut==0 ) return 0;
  1857   1857     i = (int)strlen(zOut);
  1858   1858   #if 0  /* The parser will never leave spaces at the end */
  1859   1859     while( i>0 && isspace(zOut[i-1]) ){ i--; }
  1860   1860   #endif
  1861   1861     zOut[i] = 0;

Changes to mptest/mptest.c.

    41     41   #else
    42     42   # include <unistd.h>
    43     43   #endif
    44     44   #include <stdlib.h>
    45     45   #include <string.h>
    46     46   #include <assert.h>
    47     47   #include <ctype.h>
           48  +
           49  +#define ISSPACE(X) isspace((unsigned char)(X))
           50  +#define ISDIGIT(X) isdigit((unsigned char)(X))
    48     51   
    49     52   /* The suffix to append to the child command lines, if any */
    50     53   #if defined(_WIN32)
    51     54   # define GETPID (int)GetCurrentProcessId
    52     55   #else
    53     56   # define GETPID getpid
    54     57   #endif
................................................................................
   183    186             }
   184    187             prior_c = c2;
   185    188           }
   186    189           c2 = *(zGlob++);
   187    190         }
   188    191         if( c2==0 || (seen ^ invert)==0 ) return 0;
   189    192       }else if( c=='#' ){
   190         -      if( (z[0]=='-' || z[0]=='+') && isdigit(z[1]) ) z++;
   191         -      if( !isdigit(z[0]) ) return 0;
          193  +      if( (z[0]=='-' || z[0]=='+') && ISDIGIT(z[1]) ) z++;
          194  +      if( !ISDIGIT(z[0]) ) return 0;
   192    195         z++;
   193         -      while( isdigit(z[0]) ){ z++; }
          196  +      while( ISDIGIT(z[0]) ){ z++; }
   194    197       }else{
   195    198         if( c!=(*(z++)) ) return 0;
   196    199       }
   197    200     }
   198    201     return *z==0;
   199    202   }
   200    203   
................................................................................
   285    288   }
   286    289   
   287    290   /*
   288    291   ** Return the length of a string omitting trailing whitespace
   289    292   */
   290    293   static int clipLength(const char *z){
   291    294     int n = (int)strlen(z);
   292         -  while( n>0 && isspace(z[n-1]) ){ n--; }
          295  +  while( n>0 && ISSPACE(z[n-1]) ){ n--; }
   293    296     return n;
   294    297   }
   295    298   
   296    299   /*
   297    300   ** Auxiliary SQL function to return the name of the VFS
   298    301   */
   299    302   static void vfsNameFunc(
................................................................................
   440    443   static void stringAppendTerm(String *p, const char *z){
   441    444     int i;
   442    445     if( p->n ) stringAppend(p, " ", 1);
   443    446     if( z==0 ){
   444    447       stringAppend(p, "nil", 3);
   445    448       return;
   446    449     }
   447         -  for(i=0; z[i] && !isspace(z[i]); i++){}
          450  +  for(i=0; z[i] && !ISSPACE(z[i]); i++){}
   448    451     if( i>0 && z[i]==0 ){
   449    452       stringAppend(p, z, i);
   450    453       return;
   451    454     }
   452    455     stringAppend(p, "'", 1);
   453    456     while( z[0] ){
   454    457       for(i=0; z[i] && z[i]!='\''; i++){}
................................................................................
   695    698   }
   696    699   
   697    700   /*
   698    701   ** Return the length of the next token.
   699    702   */
   700    703   static int tokenLength(const char *z, int *pnLine){
   701    704     int n = 0;
   702         -  if( isspace(z[0]) || (z[0]=='/' && z[1]=='*') ){
          705  +  if( ISSPACE(z[0]) || (z[0]=='/' && z[1]=='*') ){
   703    706       int inC = 0;
   704    707       int c;
   705    708       if( z[0]=='/' ){
   706    709         inC = 1;
   707    710         n = 2;
   708    711       }
   709    712       while( (c = z[n++])!=0 ){
   710    713         if( c=='\n' ) (*pnLine)++;
   711         -      if( isspace(c) ) continue;
          714  +      if( ISSPACE(c) ) continue;
   712    715         if( inC && c=='*' && z[n]=='/' ){
   713    716           n++;
   714    717           inC = 0;
   715    718         }else if( !inC && c=='/' && z[n]=='*' ){
   716    719           n++;
   717    720           inC = 1;
   718    721         }else if( !inC ){
................................................................................
   730    733         if( z[n]==delim ){
   731    734           n++;
   732    735           if( z[n+1]!=delim ) break;
   733    736         }
   734    737       }
   735    738     }else{
   736    739       int c;
   737         -    for(n=1; (c = z[n])!=0 && !isspace(c) && c!='"' && c!='\'' && c!=';'; n++){}
          740  +    for(n=1; (c = z[n])!=0 && !ISSPACE(c) && c!='"' && c!='\'' && c!=';'; n++){}
   738    741     }
   739    742     return n;
   740    743   }
   741    744   
   742    745   /*
   743    746   ** Copy a single token into a string buffer.
   744    747   */
   745    748   static int extractToken(const char *zIn, int nIn, char *zOut, int nOut){
   746    749     int i;
   747    750     if( nIn<=0 ){
   748    751       zOut[0] = 0;
   749    752       return 0;
   750    753     }
   751         -  for(i=0; i<nIn && i<nOut-1 && !isspace(zIn[i]); i++){ zOut[i] = zIn[i]; }
          754  +  for(i=0; i<nIn && i<nOut-1 && !ISSPACE(zIn[i]); i++){ zOut[i] = zIn[i]; }
   752    755     zOut[i] = 0;
   753    756     return i;
   754    757   }
   755    758   
   756    759   /*
   757    760   ** Find the number of characters up to the start of the next "--end" token.
   758    761   */
   759    762   static int findEnd(const char *z, int *pnLine){
   760    763     int n = 0;
   761         -  while( z[n] && (strncmp(z+n,"--end",5) || !isspace(z[n+5])) ){
          764  +  while( z[n] && (strncmp(z+n,"--end",5) || !ISSPACE(z[n+5])) ){
   762    765       n += tokenLength(z+n, pnLine);
   763    766     }
   764    767     return n;
   765    768   }
   766    769   
   767    770   /*
   768    771   ** Find the number of characters up to the first character past the
................................................................................
   769    772   ** of the next "--endif"  or "--else" token. Nested --if commands are
   770    773   ** also skipped.
   771    774   */
   772    775   static int findEndif(const char *z, int stopAtElse, int *pnLine){
   773    776     int n = 0;
   774    777     while( z[n] ){
   775    778       int len = tokenLength(z+n, pnLine);
   776         -    if( (strncmp(z+n,"--endif",7)==0 && isspace(z[n+7]))
   777         -     || (stopAtElse && strncmp(z+n,"--else",6)==0 && isspace(z[n+6]))
          779  +    if( (strncmp(z+n,"--endif",7)==0 && ISSPACE(z[n+7]))
          780  +     || (stopAtElse && strncmp(z+n,"--else",6)==0 && ISSPACE(z[n+6]))
   778    781       ){
   779    782         return n+len;
   780    783       }
   781         -    if( strncmp(z+n,"--if",4)==0 && isspace(z[n+4]) ){
          784  +    if( strncmp(z+n,"--if",4)==0 && ISSPACE(z[n+4]) ){
   782    785         int skip = findEndif(z+n+len, 0, pnLine);
   783    786         n += skip + len;
   784    787       }else{
   785    788         n += len;
   786    789       }
   787    790     }
   788    791     return n;
................................................................................
   884    887     char azArg[MX_ARG][100];
   885    888   
   886    889     memset(&sResult, 0, sizeof(sResult));
   887    890     stringReset(&sResult);
   888    891     while( (c = zScript[ii])!=0 ){
   889    892       prevLine = lineno;
   890    893       len = tokenLength(zScript+ii, &lineno);
   891         -    if( isspace(c) || (c=='/' && zScript[ii+1]=='*') ){
          894  +    if( ISSPACE(c) || (c=='/' && zScript[ii+1]=='*') ){
   892    895         ii += len;
   893    896         continue;
   894    897       }
   895    898       if( c!='-' || zScript[ii+1]!='-' || !isalpha(zScript[ii+2]) ){
   896    899         ii += len;
   897    900         continue;
   898    901       }
................................................................................
   905    908         iBegin = ii + len;
   906    909       }
   907    910   
   908    911       /* Parse the --command */
   909    912       if( g.iTrace>=2 ) logMessage("%.*s", len, zScript+ii);
   910    913       n = extractToken(zScript+ii+2, len-2, zCmd, sizeof(zCmd));
   911    914       for(nArg=0; n<len-2 && nArg<MX_ARG; nArg++){
   912         -      while( n<len-2 && isspace(zScript[ii+2+n]) ){ n++; }
          915  +      while( n<len-2 && ISSPACE(zScript[ii+2+n]) ){ n++; }
   913    916         if( n>=len-2 ) break;
   914    917         n += extractToken(zScript+ii+2+n, len-2-n,
   915    918                           azArg[nArg], sizeof(azArg[nArg]));
   916    919       }
   917    920       for(j=nArg; j<MX_ARG; j++) azArg[j++][0] = 0;
   918    921   
   919    922       /*
................................................................................
   972    975       **  --match ANSWER...
   973    976       **
   974    977       ** Check to see if output matches ANSWER.  Report an error if not.
   975    978       */
   976    979       if( strcmp(zCmd, "match")==0 ){
   977    980         int jj;
   978    981         char *zAns = zScript+ii;
   979         -      for(jj=7; jj<len-1 && isspace(zAns[jj]); jj++){}
          982  +      for(jj=7; jj<len-1 && ISSPACE(zAns[jj]); jj++){}
   980    983         zAns += jj;
   981    984         if( len-jj-1!=sResult.n || strncmp(sResult.z, zAns, len-jj-1) ){
   982    985           errorMessage("line %d of %s:\nExpected [%.*s]\n     Got [%s]",
   983    986             prevLine, zFilename, len-jj-1, zAns, sResult.z);
   984    987         }
   985    988         g.nTest++;
   986    989         stringReset(&sResult);
................................................................................
   994    997       ** ANSWER.
   995    998       */
   996    999       if( strcmp(zCmd, "glob")==0 || strcmp(zCmd, "notglob")==0 ){
   997   1000         int jj;
   998   1001         char *zAns = zScript+ii;
   999   1002         char *zCopy;
  1000   1003         int isGlob = (zCmd[0]=='g');
  1001         -      for(jj=9-3*isGlob; jj<len-1 && isspace(zAns[jj]); jj++){}
         1004  +      for(jj=9-3*isGlob; jj<len-1 && ISSPACE(zAns[jj]); jj++){}
  1002   1005         zAns += jj;
  1003   1006         zCopy = sqlite3_mprintf("%.*s", len-jj-1, zAns);
  1004   1007         if( (sqlite3_strglob(zCopy, sResult.z)==0)^isGlob ){
  1005   1008           errorMessage("line %d of %s:\nExpected [%s]\n     Got [%s]",
  1006   1009             prevLine, zFilename, zCopy, sResult.z);
  1007   1010         }
  1008   1011         sqlite3_free(zCopy);
................................................................................
  1046   1049       /*
  1047   1050       **  --print MESSAGE....
  1048   1051       **
  1049   1052       ** Output the remainder of the line to the log file
  1050   1053       */
  1051   1054       if( strcmp(zCmd, "print")==0 ){
  1052   1055         int jj;
  1053         -      for(jj=7; jj<len && isspace(zScript[ii+jj]); jj++){}
         1056  +      for(jj=7; jj<len && ISSPACE(zScript[ii+jj]); jj++){}
  1054   1057         logMessage("%.*s", len-jj, zScript+ii+jj);
  1055   1058       }else
  1056   1059   
  1057   1060       /*
  1058   1061       **  --if EXPR
  1059   1062       **
  1060   1063       ** Skip forward to the next matching --endif or --else if EXPR is false.
  1061   1064       */
  1062   1065       if( strcmp(zCmd, "if")==0 ){
  1063   1066         int jj, rc;
  1064   1067         sqlite3_stmt *pStmt;
  1065         -      for(jj=4; jj<len && isspace(zScript[ii+jj]); jj++){}
         1068  +      for(jj=4; jj<len && ISSPACE(zScript[ii+jj]); jj++){}
  1066   1069         pStmt = prepareSql("SELECT %.*s", len-jj, zScript+ii+jj);
  1067   1070         rc = sqlite3_step(pStmt);
  1068   1071         if( rc!=SQLITE_ROW || sqlite3_column_int(pStmt, 0)==0 ){
  1069   1072           ii += findEndif(zScript+ii+len, 1, &lineno);
  1070   1073         }
  1071   1074         sqlite3_finalize(pStmt);
  1072   1075       }else

Changes to test/fuzzcheck.c.

    66     66   */
    67     67   #include <stdio.h>
    68     68   #include <stdlib.h>
    69     69   #include <string.h>
    70     70   #include <stdarg.h>
    71     71   #include <ctype.h>
    72     72   #include "sqlite3.h"
           73  +#define ISSPACE(X) isspace((unsigned char)(X))
           74  +#define ISDIGIT(X) isdigit((unsigned char)(X))
           75  +
    73     76   
    74     77   #ifdef __unix__
    75     78   # include <signal.h>
    76     79   # include <unistd.h>
    77     80   #endif
    78     81   
    79     82   /*
................................................................................
   629    632       zMore = 0;
   630    633       pStmt = 0;
   631    634       sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zMore);
   632    635       if( zMore==zSql ) break;
   633    636       if( runFlags & SQL_TRACE ){
   634    637         const char *z = zSql;
   635    638         int n;
   636         -      while( z<zMore && isspace(z[0]) ) z++;
          639  +      while( z<zMore && ISSPACE(z[0]) ) z++;
   637    640         n = (int)(zMore - z);
   638         -      while( n>0 && isspace(z[n-1]) ) n--;
          641  +      while( n>0 && ISSPACE(z[n-1]) ) n--;
   639    642         if( n==0 ) break;
   640    643         if( pStmt==0 ){
   641    644           printf("TRACE: %.*s (error: %s)\n", n, z, sqlite3_errmsg(db));
   642    645         }else{
   643    646           printf("TRACE: %.*s\n", n, z);
   644    647         }
   645    648       }
................................................................................
   753    756       int x;
   754    757       zArg += 2;
   755    758       while( (x = hexDigitValue(zArg[0]))>=0 ){
   756    759         v = (v<<4) + x;
   757    760         zArg++;
   758    761       }
   759    762     }else{
   760         -    while( isdigit(zArg[0]) ){
          763  +    while( ISDIGIT(zArg[0]) ){
   761    764         v = v*10 + zArg[0] - '0';
   762    765         zArg++;
   763    766       }
   764    767     }
   765    768     for(i=0; i<sizeof(aMult)/sizeof(aMult[0]); i++){
   766    769       if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
   767    770         v *= aMult[i].iMult;

Changes to test/speedtest1.c.

    43     43   #include "sqlite3.h"
    44     44   #include <assert.h>
    45     45   #include <stdio.h>
    46     46   #include <stdlib.h>
    47     47   #include <stdarg.h>
    48     48   #include <string.h>
    49     49   #include <ctype.h>
           50  +#define ISSPACE(X) isspace((unsigned char)(X))
           51  +#define ISDIGIT(X) isdigit((unsigned char)(X))
    50     52   
    51     53   #if SQLITE_VERSION_NUMBER<3005000
    52     54   # define sqlite3_int64 sqlite_int64
    53     55   #endif
    54     56   #ifdef SQLITE_ENABLE_RBU
    55     57   # include "sqlite3rbu.h"
    56     58   #endif
................................................................................
   311    313              (int)(g.iTotal/1000), (int)(g.iTotal%1000));
   312    314     }
   313    315   }
   314    316   
   315    317   /* Print an SQL statement to standard output */
   316    318   static void printSql(const char *zSql){
   317    319     int n = (int)strlen(zSql);
   318         -  while( n>0 && (zSql[n-1]==';' || isspace(zSql[n-1])) ){ n--; }
          320  +  while( n>0 && (zSql[n-1]==';' || ISSPACE(zSql[n-1])) ){ n--; }
   319    321     if( g.bExplain ) printf("EXPLAIN ");
   320    322     printf("%.*s;\n", n, zSql);
   321    323     if( g.bExplain
   322    324   #if SQLITE_VERSION_NUMBER>=3007017 
   323    325      && ( sqlite3_strglob("CREATE *", zSql)==0
   324    326        || sqlite3_strglob("DROP *", zSql)==0
   325    327        || sqlite3_strglob("ALTER *", zSql)==0
................................................................................
   410    412     }
   411    413     speedtest1_shrink_memory();
   412    414   }
   413    415   
   414    416   /* The sqlite3_trace() callback function */
   415    417   static void traceCallback(void *NotUsed, const char *zSql){
   416    418     int n = (int)strlen(zSql);
   417         -  while( n>0 && (zSql[n-1]==';' || isspace(zSql[n-1])) ) n--;
          419  +  while( n>0 && (zSql[n-1]==';' || ISSPACE(zSql[n-1])) ) n--;
   418    420     fprintf(stderr,"%.*s;\n", n, zSql);
   419    421   }
   420    422   
   421    423   /* Substitute random() function that gives the same random
   422    424   ** sequence on each run, for repeatability. */
   423    425   static void randomFunc(
   424    426     sqlite3_context *context,

Changes to test/wordcount.c.

    76     76   */
    77     77   #include <stdio.h>
    78     78   #include <string.h>
    79     79   #include <ctype.h>
    80     80   #include <stdlib.h>
    81     81   #include <stdarg.h>
    82     82   #include "sqlite3.h"
           83  +#define ISALPHA(X) isalpha((unsigned char)(X))
    83     84   
    84     85   /* Return the current wall-clock time */
    85     86   static sqlite3_int64 realTime(void){
    86     87     static sqlite3_vfs *clockVfs = 0;
    87     88     sqlite3_int64 t;
    88     89     if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
    89     90     if( clockVfs->iVersion>=1 && clockVfs->xCurrentTimeInt64!=0 ){
................................................................................
   388    389       if( rc ) fatal_error("Could not prepare the DELETE statement: %s\n",
   389    390                            sqlite3_errmsg(db));
   390    391     }
   391    392   
   392    393     /* Process the input file */
   393    394     while( fgets(zInput, sizeof(zInput), in) ){
   394    395       for(i=0; zInput[i]; i++){
   395         -      if( !isalpha(zInput[i]) ) continue;
   396         -      for(j=i+1; isalpha(zInput[j]); j++){}
          396  +      if( !ISALPHA(zInput[i]) ) continue;
          397  +      for(j=i+1; ISALPHA(zInput[j]); j++){}
   397    398   
   398    399         /* Found a new word at zInput[i] that is j-i bytes long. 
   399    400         ** Process it into the wordcount table.  */
   400    401         if( iMode==MODE_DELETE ){
   401    402           sqlite3_bind_text(pDelete, 1, zInput+i, j-i, SQLITE_STATIC);
   402    403           if( sqlite3_step(pDelete)!=SQLITE_DONE ){
   403    404             fatal_error("DELETE failed: %s\n", sqlite3_errmsg(db));

Changes to tool/fuzzershell.c.

    63     63   */
    64     64   #include <stdio.h>
    65     65   #include <stdlib.h>
    66     66   #include <string.h>
    67     67   #include <stdarg.h>
    68     68   #include <ctype.h>
    69     69   #include "sqlite3.h"
           70  +#define ISDIGIT(X) isdigit((unsigned char)(X))
    70     71   
    71     72   /*
    72     73   ** All global variables are gathered into the "g" singleton.
    73     74   */
    74     75   struct GlobalVars {
    75     76     const char *zArgv0;              /* Name of program */
    76     77     sqlite3_mem_methods sOrigMem;    /* Original memory methods */
................................................................................
   379    380       int x;
   380    381       zArg += 2;
   381    382       while( (x = hexDigitValue(zArg[0]))>=0 ){
   382    383         v = (v<<4) + x;
   383    384         zArg++;
   384    385       }
   385    386     }else{
   386         -    while( isdigit(zArg[0]) ){
          387  +    while( ISDIGIT(zArg[0]) ){
   387    388         v = v*10 + zArg[0] - '0';
   388    389         zArg++;
   389    390       }
   390    391     }
   391    392     for(i=0; i<sizeof(aMult)/sizeof(aMult[0]); i++){
   392    393       if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
   393    394         v *= aMult[i].iMult;

Changes to tool/lemon.c.

     8      8   */
     9      9   #include <stdio.h>
    10     10   #include <stdarg.h>
    11     11   #include <string.h>
    12     12   #include <ctype.h>
    13     13   #include <stdlib.h>
    14     14   #include <assert.h>
           15  +
           16  +#define ISSPACE(X) isspace((unsigned char)(X))
           17  +#define ISDIGIT(X) isdigit((unsigned char)(X))
           18  +#define ISALNUM(X) isalnum((unsigned char)(X))
           19  +#define ISALPHA(X) isalpha((unsigned char)(X))
           20  +#define ISUPPER(X) isupper((unsigned char)(X))
           21  +#define ISLOWER(X) islower((unsigned char)(X))
           22  +
    15     23   
    16     24   #ifndef __WIN32__
    17     25   #   if defined(_WIN32) || defined(WIN32)
    18     26   #       define __WIN32__
    19     27   #   endif
    20     28   #endif
    21     29   
................................................................................
    89     97     char zTemp[50];
    90     98     str[0] = 0;
    91     99     for(i=j=0; (c = zFormat[i])!=0; i++){
    92    100       if( c=='%' ){
    93    101         int iWidth = 0;
    94    102         lemon_addtext(str, &nUsed, &zFormat[j], i-j, 0);
    95    103         c = zFormat[++i];
    96         -      if( isdigit(c) || (c=='-' && isdigit(zFormat[i+1])) ){
          104  +      if( ISDIGIT(c) || (c=='-' && ISDIGIT(zFormat[i+1])) ){
    97    105           if( c=='-' ) i++;
    98         -        while( isdigit(zFormat[i]) ) iWidth = iWidth*10 + zFormat[i++] - '0';
          106  +        while( ISDIGIT(zFormat[i]) ) iWidth = iWidth*10 + zFormat[i++] - '0';
    99    107           if( c=='-' ) iWidth = -iWidth;
   100    108           c = zFormat[i];
   101    109         }
   102    110         if( c=='d' ){
   103    111           int v = va_arg(ap, int);
   104    112           if( v<0 ){
   105    113             lemon_addtext(str, &nUsed, "-", 1, iWidth);
................................................................................
  1574   1582     lem.symbols = Symbol_arrayof();
  1575   1583     for(i=0; i<lem.nsymbol; i++) lem.symbols[i]->index = i;
  1576   1584     qsort(lem.symbols,lem.nsymbol,sizeof(struct symbol*), Symbolcmpp);
  1577   1585     for(i=0; i<lem.nsymbol; i++) lem.symbols[i]->index = i;
  1578   1586     while( lem.symbols[i-1]->type==MULTITERMINAL ){ i--; }
  1579   1587     assert( strcmp(lem.symbols[i-1]->name,"{default}")==0 );
  1580   1588     lem.nsymbol = i - 1;
  1581         -  for(i=1; isupper(lem.symbols[i]->name[0]); i++);
         1589  +  for(i=1; ISUPPER(lem.symbols[i]->name[0]); i++);
  1582   1590     lem.nterminal = i;
  1583   1591   
  1584   1592     /* Generate a reprint of the grammar, if requested on the command line */
  1585   1593     if( rpflag ){
  1586   1594       Reprint(&lem);
  1587   1595     }else{
  1588   1596       /* Initialize the size for all follow and first sets */
................................................................................
  2117   2125         psp->preccounter = 0;
  2118   2126         psp->firstrule = psp->lastrule = 0;
  2119   2127         psp->gp->nrule = 0;
  2120   2128         /* Fall thru to next case */
  2121   2129       case WAITING_FOR_DECL_OR_RULE:
  2122   2130         if( x[0]=='%' ){
  2123   2131           psp->state = WAITING_FOR_DECL_KEYWORD;
  2124         -      }else if( islower(x[0]) ){
         2132  +      }else if( ISLOWER(x[0]) ){
  2125   2133           psp->lhs = Symbol_new(x);
  2126   2134           psp->nrhs = 0;
  2127   2135           psp->lhsalias = 0;
  2128   2136           psp->state = WAITING_FOR_ARROW;
  2129   2137         }else if( x[0]=='{' ){
  2130   2138           if( psp->prevrule==0 ){
  2131   2139             ErrorMsg(psp->filename,psp->tokenlineno,
................................................................................
  2147   2155           ErrorMsg(psp->filename,psp->tokenlineno,
  2148   2156             "Token \"%s\" should be either \"%%\" or a nonterminal name.",
  2149   2157             x);
  2150   2158           psp->errorcnt++;
  2151   2159         }
  2152   2160         break;
  2153   2161       case PRECEDENCE_MARK_1:
  2154         -      if( !isupper(x[0]) ){
         2162  +      if( !ISUPPER(x[0]) ){
  2155   2163           ErrorMsg(psp->filename,psp->tokenlineno,
  2156   2164             "The precedence symbol must be a terminal.");
  2157   2165           psp->errorcnt++;
  2158   2166         }else if( psp->prevrule==0 ){
  2159   2167           ErrorMsg(psp->filename,psp->tokenlineno,
  2160   2168             "There is no prior rule to assign precedence \"[%s]\".",x);
  2161   2169           psp->errorcnt++;
................................................................................
  2187   2195             "Expected to see a \":\" following the LHS symbol \"%s\".",
  2188   2196             psp->lhs->name);
  2189   2197           psp->errorcnt++;
  2190   2198           psp->state = RESYNC_AFTER_RULE_ERROR;
  2191   2199         }
  2192   2200         break;
  2193   2201       case LHS_ALIAS_1:
  2194         -      if( isalpha(x[0]) ){
         2202  +      if( ISALPHA(x[0]) ){
  2195   2203           psp->lhsalias = x;
  2196   2204           psp->state = LHS_ALIAS_2;
  2197   2205         }else{
  2198   2206           ErrorMsg(psp->filename,psp->tokenlineno,
  2199   2207             "\"%s\" is not a valid alias for the LHS \"%s\"\n",
  2200   2208             x,psp->lhs->name);
  2201   2209           psp->errorcnt++;
................................................................................
  2256   2264             }else{
  2257   2265               psp->lastrule->next = rp;
  2258   2266               psp->lastrule = rp;
  2259   2267             }
  2260   2268             psp->prevrule = rp;
  2261   2269           }
  2262   2270           psp->state = WAITING_FOR_DECL_OR_RULE;
  2263         -      }else if( isalpha(x[0]) ){
         2271  +      }else if( ISALPHA(x[0]) ){
  2264   2272           if( psp->nrhs>=MAXRHS ){
  2265   2273             ErrorMsg(psp->filename,psp->tokenlineno,
  2266   2274               "Too many symbols on RHS of rule beginning at \"%s\".",
  2267   2275               x);
  2268   2276             psp->errorcnt++;
  2269   2277             psp->state = RESYNC_AFTER_RULE_ERROR;
  2270   2278           }else{
................................................................................
  2285   2293             msp->name = origsp->name;
  2286   2294             psp->rhs[psp->nrhs-1] = msp;
  2287   2295           }
  2288   2296           msp->nsubsym++;
  2289   2297           msp->subsym = (struct symbol **) realloc(msp->subsym,
  2290   2298             sizeof(struct symbol*)*msp->nsubsym);
  2291   2299           msp->subsym[msp->nsubsym-1] = Symbol_new(&x[1]);
  2292         -        if( islower(x[1]) || islower(msp->subsym[0]->name[0]) ){
         2300  +        if( ISLOWER(x[1]) || ISLOWER(msp->subsym[0]->name[0]) ){
  2293   2301             ErrorMsg(psp->filename,psp->tokenlineno,
  2294   2302               "Cannot form a compound containing a non-terminal");
  2295   2303             psp->errorcnt++;
  2296   2304           }
  2297   2305         }else if( x[0]=='(' && psp->nrhs>0 ){
  2298   2306           psp->state = RHS_ALIAS_1;
  2299   2307         }else{
................................................................................
  2300   2308           ErrorMsg(psp->filename,psp->tokenlineno,
  2301   2309             "Illegal character on RHS of rule: \"%s\".",x);
  2302   2310           psp->errorcnt++;
  2303   2311           psp->state = RESYNC_AFTER_RULE_ERROR;
  2304   2312         }
  2305   2313         break;
  2306   2314       case RHS_ALIAS_1:
  2307         -      if( isalpha(x[0]) ){
         2315  +      if( ISALPHA(x[0]) ){
  2308   2316           psp->alias[psp->nrhs-1] = x;
  2309   2317           psp->state = RHS_ALIAS_2;
  2310   2318         }else{
  2311   2319           ErrorMsg(psp->filename,psp->tokenlineno,
  2312   2320             "\"%s\" is not a valid alias for the RHS symbol \"%s\"\n",
  2313   2321             x,psp->rhs[psp->nrhs-1]->name);
  2314   2322           psp->errorcnt++;
................................................................................
  2322   2330           ErrorMsg(psp->filename,psp->tokenlineno,
  2323   2331             "Missing \")\" following LHS alias name \"%s\".",psp->lhsalias);
  2324   2332           psp->errorcnt++;
  2325   2333           psp->state = RESYNC_AFTER_RULE_ERROR;
  2326   2334         }
  2327   2335         break;
  2328   2336       case WAITING_FOR_DECL_KEYWORD:
  2329         -      if( isalpha(x[0]) ){
         2337  +      if( ISALPHA(x[0]) ){
  2330   2338           psp->declkeyword = x;
  2331   2339           psp->declargslot = 0;
  2332   2340           psp->decllinenoslot = 0;
  2333   2341           psp->insertLineMacro = 1;
  2334   2342           psp->state = WAITING_FOR_DECL_ARG;
  2335   2343           if( strcmp(x,"name")==0 ){
  2336   2344             psp->declargslot = &(psp->gp->name);
................................................................................
  2402   2410           ErrorMsg(psp->filename,psp->tokenlineno,
  2403   2411             "Illegal declaration keyword: \"%s\".",x);
  2404   2412           psp->errorcnt++;
  2405   2413           psp->state = RESYNC_AFTER_DECL_ERROR;
  2406   2414         }
  2407   2415         break;
  2408   2416       case WAITING_FOR_DESTRUCTOR_SYMBOL:
  2409         -      if( !isalpha(x[0]) ){
         2417  +      if( !ISALPHA(x[0]) ){
  2410   2418           ErrorMsg(psp->filename,psp->tokenlineno,
  2411   2419             "Symbol name missing after %%destructor keyword");
  2412   2420           psp->errorcnt++;
  2413   2421           psp->state = RESYNC_AFTER_DECL_ERROR;
  2414   2422         }else{
  2415   2423           struct symbol *sp = Symbol_new(x);
  2416   2424           psp->declargslot = &sp->destructor;
  2417   2425           psp->decllinenoslot = &sp->destLineno;
  2418   2426           psp->insertLineMacro = 1;
  2419   2427           psp->state = WAITING_FOR_DECL_ARG;
  2420   2428         }
  2421   2429         break;
  2422   2430       case WAITING_FOR_DATATYPE_SYMBOL:
  2423         -      if( !isalpha(x[0]) ){
         2431  +      if( !ISALPHA(x[0]) ){
  2424   2432           ErrorMsg(psp->filename,psp->tokenlineno,
  2425   2433             "Symbol name missing after %%type keyword");
  2426   2434           psp->errorcnt++;
  2427   2435           psp->state = RESYNC_AFTER_DECL_ERROR;
  2428   2436         }else{
  2429   2437           struct symbol *sp = Symbol_find(x);
  2430   2438           if((sp) && (sp->datatype)){
................................................................................
  2441   2449             psp->state = WAITING_FOR_DECL_ARG;
  2442   2450           }
  2443   2451         }
  2444   2452         break;
  2445   2453       case WAITING_FOR_PRECEDENCE_SYMBOL:
  2446   2454         if( x[0]=='.' ){
  2447   2455           psp->state = WAITING_FOR_DECL_OR_RULE;
  2448         -      }else if( isupper(x[0]) ){
         2456  +      }else if( ISUPPER(x[0]) ){
  2449   2457           struct symbol *sp;
  2450   2458           sp = Symbol_new(x);
  2451   2459           if( sp->prec>=0 ){
  2452   2460             ErrorMsg(psp->filename,psp->tokenlineno,
  2453   2461               "Symbol \"%s\" has already be given a precedence.",x);
  2454   2462             psp->errorcnt++;
  2455   2463           }else{
................................................................................
  2459   2467         }else{
  2460   2468           ErrorMsg(psp->filename,psp->tokenlineno,
  2461   2469             "Can't assign a precedence to \"%s\".",x);
  2462   2470           psp->errorcnt++;
  2463   2471         }
  2464   2472         break;
  2465   2473       case WAITING_FOR_DECL_ARG:
  2466         -      if( x[0]=='{' || x[0]=='\"' || isalnum(x[0]) ){
         2474  +      if( x[0]=='{' || x[0]=='\"' || ISALNUM(x[0]) ){
  2467   2475           const char *zOld, *zNew;
  2468   2476           char *zBuf, *z;
  2469   2477           int nOld, n, nLine = 0, nNew, nBack;
  2470   2478           int addLineMacro;
  2471   2479           char zLine[50];
  2472   2480           zNew = x;
  2473   2481           if( zNew[0]=='"' || zNew[0]=='{' ) zNew++;
................................................................................
  2520   2528           psp->errorcnt++;
  2521   2529           psp->state = RESYNC_AFTER_DECL_ERROR;
  2522   2530         }
  2523   2531         break;
  2524   2532       case WAITING_FOR_FALLBACK_ID:
  2525   2533         if( x[0]=='.' ){
  2526   2534           psp->state = WAITING_FOR_DECL_OR_RULE;
  2527         -      }else if( !isupper(x[0]) ){
         2535  +      }else if( !ISUPPER(x[0]) ){
  2528   2536           ErrorMsg(psp->filename, psp->tokenlineno,
  2529   2537             "%%fallback argument \"%s\" should be a token", x);
  2530   2538           psp->errorcnt++;
  2531   2539         }else{
  2532   2540           struct symbol *sp = Symbol_new(x);
  2533   2541           if( psp->fallback==0 ){
  2534   2542             psp->fallback = sp;
................................................................................
  2541   2549             psp->gp->has_fallback = 1;
  2542   2550           }
  2543   2551         }
  2544   2552         break;
  2545   2553       case WAITING_FOR_WILDCARD_ID:
  2546   2554         if( x[0]=='.' ){
  2547   2555           psp->state = WAITING_FOR_DECL_OR_RULE;
  2548         -      }else if( !isupper(x[0]) ){
         2556  +      }else if( !ISUPPER(x[0]) ){
  2549   2557           ErrorMsg(psp->filename, psp->tokenlineno,
  2550   2558             "%%wildcard argument \"%s\" should be a token", x);
  2551   2559           psp->errorcnt++;
  2552   2560         }else{
  2553   2561           struct symbol *sp = Symbol_new(x);
  2554   2562           if( psp->gp->wildcard==0 ){
  2555   2563             psp->gp->wildcard = sp;
................................................................................
  2557   2565             ErrorMsg(psp->filename, psp->tokenlineno,
  2558   2566               "Extra wildcard to token: %s", x);
  2559   2567             psp->errorcnt++;
  2560   2568           }
  2561   2569         }
  2562   2570         break;
  2563   2571       case WAITING_FOR_CLASS_ID:
  2564         -      if( !islower(x[0]) ){
         2572  +      if( !ISLOWER(x[0]) ){
  2565   2573           ErrorMsg(psp->filename, psp->tokenlineno,
  2566   2574             "%%token_class must be followed by an identifier: ", x);
  2567   2575           psp->errorcnt++;
  2568   2576           psp->state = RESYNC_AFTER_DECL_ERROR;
  2569   2577        }else if( Symbol_find(x) ){
  2570   2578           ErrorMsg(psp->filename, psp->tokenlineno,
  2571   2579             "Symbol \"%s\" already used", x);
................................................................................
  2576   2584           psp->tkclass->type = MULTITERMINAL;
  2577   2585           psp->state = WAITING_FOR_CLASS_TOKEN;
  2578   2586         }
  2579   2587         break;
  2580   2588       case WAITING_FOR_CLASS_TOKEN:
  2581   2589         if( x[0]=='.' ){
  2582   2590           psp->state = WAITING_FOR_DECL_OR_RULE;
  2583         -      }else if( isupper(x[0]) || ((x[0]=='|' || x[0]=='/') && isupper(x[1])) ){
         2591  +      }else if( ISUPPER(x[0]) || ((x[0]=='|' || x[0]=='/') && ISUPPER(x[1])) ){
  2584   2592           struct symbol *msp = psp->tkclass;
  2585   2593           msp->nsubsym++;
  2586   2594           msp->subsym = (struct symbol **) realloc(msp->subsym,
  2587   2595             sizeof(struct symbol*)*msp->nsubsym);
  2588         -        if( !isupper(x[0]) ) x++;
         2596  +        if( !ISUPPER(x[0]) ) x++;
  2589   2597           msp->subsym[msp->nsubsym-1] = Symbol_new(x);
  2590   2598         }else{
  2591   2599           ErrorMsg(psp->filename, psp->tokenlineno,
  2592   2600             "%%token_class argument \"%s\" should be a token", x);
  2593   2601           psp->errorcnt++;
  2594   2602           psp->state = RESYNC_AFTER_DECL_ERROR;
  2595   2603         }
................................................................................
  2614   2622     int exclude = 0;
  2615   2623     int start = 0;
  2616   2624     int lineno = 1;
  2617   2625     int start_lineno = 1;
  2618   2626     for(i=0; z[i]; i++){
  2619   2627       if( z[i]=='\n' ) lineno++;
  2620   2628       if( z[i]!='%' || (i>0 && z[i-1]!='\n') ) continue;
  2621         -    if( strncmp(&z[i],"%endif",6)==0 && isspace(z[i+6]) ){
         2629  +    if( strncmp(&z[i],"%endif",6)==0 && ISSPACE(z[i+6]) ){
  2622   2630         if( exclude ){
  2623   2631           exclude--;
  2624   2632           if( exclude==0 ){
  2625   2633             for(j=start; j<i; j++) if( z[j]!='\n' ) z[j] = ' ';
  2626   2634           }
  2627   2635         }
  2628   2636         for(j=i; z[j] && z[j]!='\n'; j++) z[j] = ' ';
  2629         -    }else if( (strncmp(&z[i],"%ifdef",6)==0 && isspace(z[i+6]))
  2630         -          || (strncmp(&z[i],"%ifndef",7)==0 && isspace(z[i+7])) ){
         2637  +    }else if( (strncmp(&z[i],"%ifdef",6)==0 && ISSPACE(z[i+6]))
         2638  +          || (strncmp(&z[i],"%ifndef",7)==0 && ISSPACE(z[i+7])) ){
  2631   2639         if( exclude ){
  2632   2640           exclude++;
  2633   2641         }else{
  2634         -        for(j=i+7; isspace(z[j]); j++){}
  2635         -        for(n=0; z[j+n] && !isspace(z[j+n]); n++){}
         2642  +        for(j=i+7; ISSPACE(z[j]); j++){}
         2643  +        for(n=0; z[j+n] && !ISSPACE(z[j+n]); n++){}
  2636   2644           exclude = 1;
  2637   2645           for(k=0; k<nDefine; k++){
  2638   2646             if( strncmp(azDefine[k],&z[j],n)==0 && lemonStrlen(azDefine[k])==n ){
  2639   2647               exclude = 0;
  2640   2648               break;
  2641   2649             }
  2642   2650           }
................................................................................
  2708   2716     /* Make an initial pass through the file to handle %ifdef and %ifndef */
  2709   2717     preprocess_input(filebuf);
  2710   2718   
  2711   2719     /* Now scan the text of the input file */
  2712   2720     lineno = 1;
  2713   2721     for(cp=filebuf; (c= *cp)!=0; ){
  2714   2722       if( c=='\n' ) lineno++;              /* Keep track of the line number */
  2715         -    if( isspace(c) ){ cp++; continue; }  /* Skip all white space */
         2723  +    if( ISSPACE(c) ){ cp++; continue; }  /* Skip all white space */
  2716   2724       if( c=='/' && cp[1]=='/' ){          /* Skip C++ style comments */
  2717   2725         cp+=2;
  2718   2726         while( (c= *cp)!=0 && c!='\n' ) cp++;
  2719   2727         continue;
  2720   2728       }
  2721   2729       if( c=='/' && cp[1]=='*' ){          /* Skip C style comments */
  2722   2730         cp+=2;
................................................................................
  2778   2786           ErrorMsg(ps.filename,ps.tokenlineno,
  2779   2787   "C code starting on this line is not terminated before the end of the file.");
  2780   2788           ps.errorcnt++;
  2781   2789           nextcp = cp;
  2782   2790         }else{
  2783   2791           nextcp = cp+1;
  2784   2792         }
  2785         -    }else if( isalnum(c) ){          /* Identifiers */
  2786         -      while( (c= *cp)!=0 && (isalnum(c) || c=='_') ) cp++;
         2793  +    }else if( ISALNUM(c) ){          /* Identifiers */
         2794  +      while( (c= *cp)!=0 && (ISALNUM(c) || c=='_') ) cp++;
  2787   2795         nextcp = cp;
  2788   2796       }else if( c==':' && cp[1]==':' && cp[2]=='=' ){ /* The operator "::=" */
  2789   2797         cp += 3;
  2790   2798         nextcp = cp;
  2791         -    }else if( (c=='/' || c=='|') && isalpha(cp[1]) ){
         2799  +    }else if( (c=='/' || c=='|') && ISALPHA(cp[1]) ){
  2792   2800         cp += 2;
  2793         -      while( (c = *cp)!=0 && (isalnum(c) || c=='_') ) cp++;
         2801  +      while( (c = *cp)!=0 && (ISALNUM(c) || c=='_') ) cp++;
  2794   2802         nextcp = cp;
  2795   2803       }else{                          /* All other (one character) operators */
  2796   2804         cp++;
  2797   2805         nextcp = cp;
  2798   2806       }
  2799   2807       c = *cp;
  2800   2808       *cp = 0;                        /* Null terminate the token */
................................................................................
  3237   3245     char line[LINESIZE];
  3238   3246     while( fgets(line,LINESIZE,in) && (line[0]!='%' || line[1]!='%') ){
  3239   3247       (*lineno)++;
  3240   3248       iStart = 0;
  3241   3249       if( name ){
  3242   3250         for(i=0; line[i]; i++){
  3243   3251           if( line[i]=='P' && strncmp(&line[i],"Parse",5)==0
  3244         -          && (i==0 || !isalpha(line[i-1]))
         3252  +          && (i==0 || !ISALPHA(line[i-1]))
  3245   3253           ){
  3246   3254             if( i>iStart ) fprintf(out,"%.*s",i-iStart,&line[iStart]);
  3247   3255             fprintf(out,"%s",name);
  3248   3256             i += 4;
  3249   3257             iStart = i+1;
  3250   3258           }
  3251   3259         }
................................................................................
  3474   3482       rp->line = rp->ruleline;
  3475   3483     }
  3476   3484   
  3477   3485     append_str(0,0,0,0);
  3478   3486   
  3479   3487     /* This const cast is wrong but harmless, if we're careful. */
  3480   3488     for(cp=(char *)rp->code; *cp; cp++){
  3481         -    if( isalpha(*cp) && (cp==rp->code || (!isalnum(cp[-1]) && cp[-1]!='_')) ){
         3489  +    if( ISALPHA(*cp) && (cp==rp->code || (!ISALNUM(cp[-1]) && cp[-1]!='_')) ){
  3482   3490         char saved;
  3483         -      for(xp= &cp[1]; isalnum(*xp) || *xp=='_'; xp++);
         3491  +      for(xp= &cp[1]; ISALNUM(*xp) || *xp=='_'; xp++);
  3484   3492         saved = *xp;
  3485   3493         *xp = 0;
  3486   3494         if( rp->lhsalias && strcmp(cp,rp->lhsalias)==0 ){
  3487   3495           append_str("yygotominor.yy%d",0,rp->lhs->dtnum,0);
  3488   3496           cp = xp;
  3489   3497           lhsused = 1;
  3490   3498         }else{
................................................................................
  3641   3649       if( sp->type!=NONTERMINAL || (sp->datatype==0 && lemp->vartype==0) ){
  3642   3650         sp->dtnum = 0;
  3643   3651         continue;
  3644   3652       }
  3645   3653       cp = sp->datatype;
  3646   3654       if( cp==0 ) cp = lemp->vartype;
  3647   3655       j = 0;
  3648         -    while( isspace(*cp) ) cp++;
         3656  +    while( ISSPACE(*cp) ) cp++;
  3649   3657       while( *cp ) stddt[j++] = *cp++;
  3650         -    while( j>0 && isspace(stddt[j-1]) ) j--;
         3658  +    while( j>0 && ISSPACE(stddt[j-1]) ) j--;
  3651   3659       stddt[j] = 0;
  3652   3660       if( lemp->tokentype && strcmp(stddt, lemp->tokentype)==0 ){
  3653   3661         sp->dtnum = 0;
  3654   3662         continue;
  3655   3663       }
  3656   3664       hash = 0;
  3657   3665       for(j=0; stddt[j]; j++){
................................................................................
  3853   3861     fprintf(out, "#endif\n"); lineno++;
  3854   3862     if( mhflag ){
  3855   3863       fprintf(out,"#if INTERFACE\n"); lineno++;
  3856   3864     }
  3857   3865     name = lemp->name ? lemp->name : "Parse";
  3858   3866     if( lemp->arg && lemp->arg[0] ){
  3859   3867       i = lemonStrlen(lemp->arg);
  3860         -    while( i>=1 && isspace(lemp->arg[i-1]) ) i--;
  3861         -    while( i>=1 && (isalnum(lemp->arg[i-1]) || lemp->arg[i-1]=='_') ) i--;
         3868  +    while( i>=1 && ISSPACE(lemp->arg[i-1]) ) i--;
         3869  +    while( i>=1 && (ISALNUM(lemp->arg[i-1]) || lemp->arg[i-1]=='_') ) i--;
  3862   3870       fprintf(out,"#define %sARG_SDECL %s;\n",name,lemp->arg);  lineno++;
  3863   3871       fprintf(out,"#define %sARG_PDECL ,%s\n",name,lemp->arg);  lineno++;
  3864   3872       fprintf(out,"#define %sARG_FETCH %s = yypParser->%s\n",
  3865   3873                    name,lemp->arg,&lemp->arg[i]);  lineno++;
  3866   3874       fprintf(out,"#define %sARG_STORE yypParser->%s = %s\n",
  3867   3875                    name,&lemp->arg[i],&lemp->arg[i]);  lineno++;
  3868   3876     }else{
................................................................................
  4662   4670     struct symbol *sp;
  4663   4671   
  4664   4672     sp = Symbol_find(x);
  4665   4673     if( sp==0 ){
  4666   4674       sp = (struct symbol *)calloc(1, sizeof(struct symbol) );
  4667   4675       MemoryCheck(sp);
  4668   4676       sp->name = Strsafe(x);
  4669         -    sp->type = isupper(*x) ? TERMINAL : NONTERMINAL;
         4677  +    sp->type = ISUPPER(*x) ? TERMINAL : NONTERMINAL;
  4670   4678       sp->rule = 0;
  4671   4679       sp->fallback = 0;
  4672   4680       sp->prec = -1;
  4673   4681       sp->assoc = UNK;
  4674   4682       sp->firstset = 0;
  4675   4683       sp->lambda = LEMON_FALSE;
  4676   4684       sp->destructor = 0;

Changes to tool/showdb.c.

     1      1   /*
     2      2   ** A utility for printing all or part of an SQLite database file.
     3      3   */
     4      4   #include <stdio.h>
     5      5   #include <ctype.h>
            6  +#define ISDIGIT(X) isdigit((unsigned char)(X))
            7  +#define ISPRINT(X) isprint((unsigned char)(X))
     6      8   #include <sys/types.h>
     7      9   #include <sys/stat.h>
     8     10   #include <fcntl.h>
     9     11   
    10     12   #if !defined(_MSC_VER)
    11     13   #include <unistd.h>
    12     14   #else
................................................................................
   213    215           fprintf(stdout,"%02x ", aData[i+j]);
   214    216         }
   215    217       }
   216    218       for(j=0; j<g.perLine; j++){
   217    219         if( i+j>nByte ){
   218    220           fprintf(stdout, " ");
   219    221         }else{
   220         -        fprintf(stdout,"%c", isprint(aData[i+j]) ? aData[i+j] : '.');
          222  +        fprintf(stdout,"%c", ISPRINT(aData[i+j]) ? aData[i+j] : '.');
   221    223         }
   222    224       }
   223    225       fprintf(stdout,"\n");
   224    226     }
   225    227     return aData;
   226    228   }
   227    229   
................................................................................
   596    598              zConst[1] = '\'';
   597    599              for(ii=2, jj=0; jj<szCol[i] && ii<24; jj++, ii+=2){
   598    600                sprintf(zConst+ii, "%02x", pData[jj]);
   599    601              }
   600    602            }else{
   601    603              zConst[0] = '\'';
   602    604              for(ii=1, jj=0; jj<szCol[i] && ii<24; jj++, ii++){
   603         -             zConst[ii] = isprint(pData[jj]) ? pData[jj] : '.';
          605  +             zConst[ii] = ISPRINT(pData[jj]) ? pData[jj] : '.';
   604    606              }
   605    607              zConst[ii] = 0;
   606    608            }
   607    609            if( jj<szCol[i] ){
   608    610              memcpy(zConst+ii, "...'", 5);
   609    611            }else{
   610    612              memcpy(zConst+ii, "'", 2);
................................................................................
   649    651       case 13: zType = "table leaf";           break;
   650    652     }
   651    653     while( zArgs[0] ){
   652    654       switch( zArgs[0] ){
   653    655         case 'c': showCellContent = 1;  break;
   654    656         case 'm': showMap = 1;          break;
   655    657         case 'd': {
   656         -        if( !isdigit(zArgs[1]) ){
          658  +        if( !ISDIGIT(zArgs[1]) ){
   657    659             cellToDecode = -1;
   658    660           }else{
   659    661             cellToDecode = 0;
   660         -          while( isdigit(zArgs[1]) ){
          662  +          while( ISDIGIT(zArgs[1]) ){
   661    663               zArgs++;
   662    664               cellToDecode = cellToDecode*10 + zArgs[0] - '0';
   663    665             }
   664    666           }
   665    667           break;
   666    668         }
   667    669       }
................................................................................
  1119   1121           ptrmap_coverage_report(azArg[1]);
  1120   1122           continue;
  1121   1123         }
  1122   1124         if( strcmp(azArg[i], "help")==0 ){
  1123   1125           usage(zPrg);
  1124   1126           continue;
  1125   1127         }
  1126         -      if( !isdigit(azArg[i][0]) ){
         1128  +      if( !ISDIGIT(azArg[i][0]) ){
  1127   1129           fprintf(stderr, "%s: unknown option: [%s]\n", zPrg, azArg[i]);
  1128   1130           continue;
  1129   1131         }
  1130   1132         iStart = strtol(azArg[i], &zLeft, 0);
  1131   1133         if( zLeft && strcmp(zLeft,"..end")==0 ){
  1132   1134           iEnd = g.mxPage;
  1133   1135         }else if( zLeft && zLeft[0]=='.' && zLeft[1]=='.' ){

Changes to tool/showstat4.c.

     4      4   ** line.
     5      5   */
     6      6   #include <stdio.h>
     7      7   #include <string.h>
     8      8   #include <stdlib.h>
     9      9   #include <ctype.h>
    10     10   #include "sqlite3.h"
           11  +
           12  +#define ISPRINT(X)  isprint((unsigned char)(X))
    11     13   
    12     14   typedef sqlite3_int64 i64;   /* 64-bit signed integer type */
    13     15   
    14     16   
    15     17   /*
    16     18   ** Convert the var-int format into i64.  Return the number of bytes
    17     19   ** in the var-int.  Write the var-int value into *pVal.
................................................................................
   127    129             printf("%02x", aSample[y+j]);
   128    130           }
   129    131           printf("'");
   130    132         }else{
   131    133           printf("%s\"", zSep);
   132    134           for(j=0; j<sz; j++){
   133    135             char c = (char)aSample[y+j];
   134         -          if( isprint(c) ){
          136  +          if( ISPRINT(c) ){
   135    137               if( c=='"' || c=='\\' ) putchar('\\');
   136    138               putchar(c);
   137    139             }else if( c=='\n' ){
   138    140               printf("\\n");
   139    141             }else if( c=='\t' ){
   140    142               printf("\\t");
   141    143             }else if( c=='\r' ){

Changes to tool/showwal.c.

     3      3   */
     4      4   #include <stdio.h>
     5      5   #include <ctype.h>
     6      6   #include <sys/types.h>
     7      7   #include <sys/stat.h>
     8      8   #include <fcntl.h>
     9      9   
           10  +#define ISDIGIT(X)  isdigit((unsigned char)(X))
           11  +#define ISPRINT(X)  isprint((unsigned char)(X))
           12  +
    10     13   #if !defined(_MSC_VER)
    11     14   #include <unistd.h>
    12     15   #else
    13     16   #include <io.h>
    14     17   #endif
    15     18   
    16     19   #include <stdlib.h>
................................................................................
   155    158           fprintf(stdout,"%02x ", aData[i+j]);
   156    159         }
   157    160       }
   158    161       for(j=0; j<perLine; j++){
   159    162         if( i+j>nByte ){
   160    163           fprintf(stdout, " ");
   161    164         }else{
   162         -        fprintf(stdout,"%c", isprint(aData[i+j]) ? aData[i+j] : '.');
          165  +        fprintf(stdout,"%c", ISPRINT(aData[i+j]) ? aData[i+j] : '.');
   163    166         }
   164    167       }
   165    168       fprintf(stdout,"\n");
   166    169     }
   167    170   }
   168    171   
   169    172   /* Print a line of decode output showing a 4-byte integer.
................................................................................
   546    549       for(i=2; i<argc; i++){
   547    550         int iStart, iEnd;
   548    551         char *zLeft;
   549    552         if( strcmp(argv[i], "header")==0 ){
   550    553           print_wal_header(0);
   551    554           continue;
   552    555         }
   553         -      if( !isdigit(argv[i][0]) ){
          556  +      if( !ISDIGIT(argv[i][0]) ){
   554    557           fprintf(stderr, "%s: unknown option: [%s]\n", argv[0], argv[i]);
   555    558           continue;
   556    559         }
   557    560         iStart = strtol(argv[i], &zLeft, 0);
   558    561         if( zLeft && strcmp(zLeft,"..end")==0 ){
   559    562           iEnd = mxFrame;
   560    563         }else if( zLeft && zLeft[0]=='.' && zLeft[1]=='.' ){

Changes to tool/speedtest16.c.

    25     25   #include <stdio.h>
    26     26   #include <string.h>
    27     27   #include <stdlib.h>
    28     28   #include <ctype.h>
    29     29   #include <unistd.h>
    30     30   #include "sqlite3.h"
    31     31   
           32  +#define ISSPACE(X)  isspace((unsigned char)(X))
           33  +
    32     34   /* 
    33     35   ** hwtime.h contains inline assembler code for implementing 
    34     36   ** high-performance timing routines.
    35     37   */
    36     38   #include "hwtime.h"
    37     39   
    38     40   /*
................................................................................
   136    138         int isComplete;
   137    139         char c = zSql[j+1];
   138    140         zSql[j+1] = 0;
   139    141         isComplete = sqlite3_complete(&zSql[i]);
   140    142         zSql[j+1] = c;
   141    143         if( isComplete ){
   142    144           zSql[j] = 0;
   143         -        while( i<j && isspace(zSql[i]) ){ i++; }
          145  +        while( i<j && ISSPACE(zSql[i]) ){ i++; }
   144    146           if( i<j ){
   145    147             nStmt++;
   146    148             nByte += j-i;
   147    149             prepareAndRun(db, &zSql[i]);
   148    150           }
   149    151           zSql[j] = ';';
   150    152           i = j+1;

Changes to tool/speedtest8inst1.c.

    25     25   #include <string.h>
    26     26   #include <stdlib.h>
    27     27   #include <ctype.h>
    28     28   #include <unistd.h>
    29     29   #include <stdarg.h>
    30     30   #include "sqlite3.h"
    31     31   
           32  +#define ISSPACE(X)  isspace((unsigned char)(X))
           33  +
    32     34   #include "test_osinst.c"
    33     35   
    34     36   /*
    35     37   ** Prepare and run a single statement of SQL.
    36     38   */
    37     39   static void prepareAndRun(sqlite3_vfs *pInstVfs, sqlite3 *db, const char *zSql){
    38     40     sqlite3_stmt *pStmt;
................................................................................
   193    195         int isComplete;
   194    196         char c = zSql[j+1];
   195    197         zSql[j+1] = 0;
   196    198         isComplete = sqlite3_complete(&zSql[i]);
   197    199         zSql[j+1] = c;
   198    200         if( isComplete ){
   199    201           zSql[j] = 0;
   200         -        while( i<j && isspace(zSql[i]) ){ i++; }
          202  +        while( i<j && ISSPACE(zSql[i]) ){ i++; }
   201    203           if( i<j ){
   202    204             prepareAndRun(pInstVfs, db, &zSql[i]);
   203    205           }
   204    206           zSql[j] = ';';
   205    207           i = j+1;
   206    208         }
   207    209       }