]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Remove undocumented extensions from sqlite_mprintf() and friends in order to
authordrh <drh@noemail.net>
Mon, 2 Feb 2004 12:29:25 +0000 (12:29 +0000)
committerdrh <drh@noemail.net>
Mon, 2 Feb 2004 12:29:25 +0000 (12:29 +0000)
make it about 10% smaller. (CVS 1207)

FossilOrigin-Name: 0b3f552b986fd89c48c350b0746be93b9d276ecc

manifest
manifest.uuid
src/printf.c
test/printf.test
test/tableapi.test

index 050dbc593551a263bf750386c00e5123b2635205..727e589a45552a4601919d79d4f6577b0791de64 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sthe\shandling\sof\s-init\soption\sto\sthe\ssqlite\sshell.\sTicket\s#568.\nAlso\sadd\shooks\sfor\sencrypting\sthe\sdatabase.\s(CVS\s1206)
-D 2004-02-01T01:22:51
+C Remove\sundocumented\sextensions\sfrom\ssqlite_mprintf()\sand\sfriends\sin\sorder\sto\nmake\sit\sabout\s10%\ssmaller.\s(CVS\s1207)
+D 2004-02-02T12:29:25
 F Makefile.in 0515ff9218ad8d5a8f6220f0494b8ef94c67013b
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -44,7 +44,7 @@ F src/pager.c 289328d8efba620eae99f6c2f6062710838a3eb4
 F src/pager.h 5da62c83443f26b1792cfd72c96c422f91aadd31
 F src/parse.y 7a121554c0c0c0150a77ab05417b01fa44813ac4
 F src/pragma.c 89d62c31c6f0a43376fe8d20549b87a6d30c467a
-F src/printf.c 292a7bfc5a815cb6465e32b2d5c9fe9bd43b27f0
+F src/printf.c 84e4ea4ba49cbbf930e95e82295127ad5843ae1f
 F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe
 F src/select.c b7694067df8d57fd0c85ddcc0840532d181552ad
 F src/shell.c a069d35277983d54348105aa3c73be3c45eb9c38
@@ -112,7 +112,7 @@ F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0
 F test/null.test c14d0f4739f21e929b8115b72bf0c765b6bb1721
 F test/pager.test dd31da9bee94a82e2e87e58cf286cfe809f8fc5f
 F test/pragma.test 17ff54f4abe187fa1e9dd20afef63d14c650d737
-F test/printf.test 3ed02f1361402c0767492cd5cef4650e61df8308
+F test/printf.test bdb5f66eb4a63abab9e26ab7277f2f8c886138a5
 F test/progress.test 701b6115c2613128ececdfe1398a1bd0e1a4cfb3 x
 F test/quick.test c527bdb899b12a8cd8ceecce45f72922099f4095
 F test/quote.test 08f23385c685d3dc7914ec760d492cacea7f6e3d
@@ -126,7 +126,7 @@ F test/select6.test a9e31906e700e7c7592c4d0acfc022808f718baf
 F test/sort.test ba07b107c16070208e6aab3cadea66ba079d85ba
 F test/subselect.test f0fea8cf9f386d416d64d152e3c65f9116d0f50f
 F test/table.test 371a1fc1c470982b2f68f9732f903a5d96f949c4
-F test/tableapi.test d881e787779a175238b72f55b5e50d3a85ab47a6
+F test/tableapi.test e0c4cce61e58343caa84dab33fa6823cb35fe1e1
 F test/tclsqlite.test 97233f45db35a76ceae9e56d244af68fc8061ceb
 F test/temptable.test c82bd6f800f10e8cf96921af6315e5f1c21e2692
 F test/tester.tcl 2671536d3650c29e7c105219f277568b0884cb58
@@ -182,7 +182,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
 F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P 04cf22785e68fcd4098e6c10a89386108cd0bf07
-R 6b544ab7468b55cbc9dfec6b7298d72d
+P 3c796de8d1af55944f396f08feaa9e69c1652896
+R eeb1a65670905e806f11ab1b63f5e8e7
 U drh
-Z e87a644a943e033216fc69c960947b44
+Z f7f5c0bf32582b04f90ec08e5433a558
index 985787fcb02613e36acfeb6aa42504b170d0ef18..6d0289d0d427305eae6d91bdad8a31994df8b921 100644 (file)
@@ -1 +1 @@
-3c796de8d1af55944f396f08feaa9e69c1652896
\ No newline at end of file
+0b3f552b986fd89c48c350b0746be93b9d276ecc
\ No newline at end of file
index a8af91434e1f4b8d27f8f69dcfa3f71fe123f33d..9e46882455c528f14a060305c1fad285cc9c3331 100644 (file)
@@ -1,7 +1,11 @@
 /*
 ** The "printf" code that follows dates from the 1980's.  It is in
 ** the public domain.  The original comments are included here for
-** completeness.  They are slightly out-of-date.
+** completeness.  They are very out-of-date but might be useful as
+** an historical reference.  Most of the "enhancements" have been backed
+** out so that the functionality is now the same as standard printf().
+**
+**************************************************************************
 **
 ** The following modules is an enhanced replacement for the "printf" subroutines
 ** found in the standard C library.  The following enhancements are
 ** Conversion types fall into various categories as defined by the
 ** following enumeration.
 */
-enum et_type {    /* The type of the format field */
-   etRADIX,            /* Integer types.  %d, %x, %o, and so forth */
-   etFLOAT,            /* Floating point.  %f */
-   etEXP,              /* Exponentional notation. %e and %E */
-   etGENERIC,          /* Floating or exponential, depending on exponent. %g */
-   etSIZE,             /* Return number of characters processed so far. %n */
-   etSTRING,           /* Strings. %s */
-   etDYNSTRING,        /* Dynamically allocated strings. %z */
-   etPERCENT,          /* Percent symbol. %% */
-   etCHARX,            /* Characters. %c */
-   etERROR,            /* Used to indicate no such conversion type */
+#define etRADIX       1 /* Integer types.  %d, %x, %o, and so forth */
+#define etFLOAT       2 /* Floating point.  %f */
+#define etEXP         3 /* Exponentional notation. %e and %E */
+#define etGENERIC     4 /* Floating or exponential, depending on exponent. %g */
+#define etSIZE        5 /* Return number of characters processed so far. %n */
+#define etSTRING      6 /* Strings. %s */
+#define etDYNSTRING   7 /* Dynamically allocated strings. %z */
+#define etPERCENT     8 /* Percent symbol. %% */
+#define etCHARX       9 /* Characters. %c */
+#define etERROR      10 /* Used to indicate no such conversion type */
 /* The rest are extensions, not normally found in printf() */
-   etCHARLIT,          /* Literal characters.  %' */
-   etSQLESCAPE,        /* Strings with '\'' doubled.  %q */
-   etSQLESCAPE2,       /* Strings with '\'' doubled and enclosed in '',
+#define etCHARLIT    11 /* Literal characters.  %' */
+#define etSQLESCAPE  12 /* Strings with '\'' doubled.  %q */
+#define etSQLESCAPE2 13 /* Strings with '\'' doubled and enclosed in '',
                           NULL pointers replaced by SQL NULL.  %Q */
-   etORDINAL           /* 1st, 2nd, 3rd and so forth */
-};
+
+
+/*
+** An "etByte" is an 8-bit unsigned value.
+*/
+typedef unsigned char etByte;
 
 /*
 ** Each builtin conversion character (ex: the 'd' in "%d") is described
 ** by an instance of the following structure
 */
 typedef struct et_info {   /* Information about each format field */
-  int  fmttype;              /* The format field code letter */
-  int  base;                 /* The base for radix conversion */
-  char *charset;             /* The character set for conversion */
-  int  flag_signed;          /* Is the quantity signed? */
-  char *prefix;              /* Prefix on non-zero values in alt format */
-  enum et_type type;          /* Conversion paradigm */
+  char fmttype;            /* The format field code letter */
+  etByte base;             /* The base for radix conversion */
+  etByte flags;            /* One or more of FLAG_ constants below */
+  etByte type;             /* Conversion paradigm */
+  char *charset;           /* The character set for conversion */
+  char *prefix;            /* Prefix on non-zero values in alt format */
 } et_info;
 
+/*
+** Allowed values for et_info.flags
+*/
+#define FLAG_SIGNED  1     /* True if the value to convert is signed */
+#define FLAG_INTERN  2     /* True if for internal use only */
+
+
 /*
 ** The following table is searched linearly, so it is good to put the
 ** most frequently used conversion types first.
 */
 static et_info fmtinfo[] = {
-  { 'd',  10,  "0123456789",       1,    0, etRADIX,      },
-  { 's',   0,  0,                  0,    0, etSTRING,     }, 
-  { 'z',   0,  0,                  0,    0, etDYNSTRING,  }, 
-  { 'q',   0,  0,                  0,    0, etSQLESCAPE,  },
-  { 'Q',   0,  0,                  0,    0, etSQLESCAPE2, },
-  { 'c',   0,  0,                  0,    0, etCHARX,      },
-  { 'o',   8,  "01234567",         0,  "0", etRADIX,      },
-  { 'u',  10,  "0123456789",       0,    0, etRADIX,      },
-  { 'x',  16,  "0123456789abcdef", 0, "x0", etRADIX,      },
-  { 'X',  16,  "0123456789ABCDEF", 0, "X0", etRADIX,      },
-  { 'r',  10,  "0123456789",       0,    0, etORDINAL,    },
-  { 'f',   0,  0,                  1,    0, etFLOAT,      },
-  { 'e',   0,  "e",                1,    0, etEXP,        },
-  { 'E',   0,  "E",                1,    0, etEXP,        },
-  { 'g',   0,  "e",                1,    0, etGENERIC,    },
-  { 'G',   0,  "E",                1,    0, etGENERIC,    },
-  { 'i',  10,  "0123456789",       1,    0, etRADIX,      },
-  { 'n',   0,  0,                  0,    0, etSIZE,       },
-  { '%',   0,  0,                  0,    0, etPERCENT,    },
-  { 'b',   2,  "01",               0, "b0", etRADIX,      }, /* Binary */
-  { 'p',  10,  "0123456789",       0,    0, etRADIX,      }, /* Pointers */
-  { '\'',  0,  0,                  0,    0, etCHARLIT,    }, /* Literal char */
+  {  'd', 10, 1, etRADIX,      "0123456789",       0    },
+  {  's',  0, 0, etSTRING,     0,                  0    },
+  {  'z',  0, 2, etDYNSTRING,  0,                  0    },
+  {  'q',  0, 0, etSQLESCAPE,  0,                  0    },
+  {  'Q',  0, 0, etSQLESCAPE2, 0,                  0    },
+  {  'c',  0, 0, etCHARX,      0,                  0    },
+  {  'o',  8, 0, etRADIX,      "01234567",         "0"  },
+  {  'u', 10, 0, etRADIX,      "0123456789",       0    },
+  {  'x', 16, 0, etRADIX,      "0123456789abcdef", "x0" },
+  {  'X', 16, 0, etRADIX,      "0123456789ABCDEF", "X0" },
+  {  'f',  0, 1, etFLOAT,      0,                  0    },
+  {  'e',  0, 1, etEXP,        "e",                0    },
+  {  'E',  0, 1, etEXP,        "E",                0    },
+  {  'g',  0, 1, etGENERIC,    "e",                0    },
+  {  'G',  0, 1, etGENERIC,    "E",                0    },
+  {  'i', 10, 1, etRADIX,      "0123456789",       0    },
+  {  'n',  0, 0, etSIZE,       0,                  0    },
+  {  '%',  0, 0, etPERCENT,    0,                  0    },
+  {  'p', 10, 0, etRADIX,      "0123456789",       0    },
 };
 #define etNINFO  (sizeof(fmtinfo)/sizeof(fmtinfo[0]))
 
@@ -183,50 +194,47 @@ static int et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
 static int vxprintf(
   void (*func)(void*,char*,int),
   void *arg,
-  const char *format,
+  const char *fmt,
   va_list ap
 ){
-  register const char *fmt; /* The format string. */
-  register int c;           /* Next character in the format string */
-  register char *bufpt;     /* Pointer to the conversion buffer */
-  register int  precision;  /* Precision of the current field */
-  register int  length;     /* Length of the field */
-  register int  idx;        /* A general purpose loop counter */
-  int count;                /* Total number of characters output */
-  int width;                /* Width of the current field */
-  int flag_leftjustify;     /* True if "-" flag is present */
-  int flag_plussign;        /* True if "+" flag is present */
-  int flag_blanksign;       /* True if " " flag is present */
-  int flag_alternateform;   /* True if "#" flag is present */
-  int flag_zeropad;         /* True if field width constant starts with zero */
-  int flag_long;            /* True if "l" flag is present */
-  int flag_center;          /* True if "=" flag is present */
-  unsigned long longvalue;  /* Value for integer types */
+  int c;                     /* Next character in the format string */
+  char *bufpt;               /* Pointer to the conversion buffer */
+  int precision;             /* Precision of the current field */
+  int length;                /* Length of the field */
+  int idx;                   /* A general purpose loop counter */
+  int count;                 /* Total number of characters output */
+  int width;                 /* Width of the current field */
+  etByte flag_leftjustify;   /* True if "-" flag is present */
+  etByte flag_plussign;      /* True if "+" flag is present */
+  etByte flag_blanksign;     /* True if " " flag is present */
+  etByte flag_alternateform; /* True if "#" flag is present */
+  etByte flag_zeropad;       /* True if field width constant starts with zero */
+  etByte flag_long;          /* True if "l" flag is present */
+  unsigned long longvalue;   /* Value for integer types */
   LONGDOUBLE_TYPE realvalue; /* Value for real types */
-  et_info *infop;           /* Pointer to the appropriate info structure */
-  char buf[etBUFSIZE];      /* Conversion buffer */
-  char prefix;              /* Prefix character.  "+" or "-" or " " or '\0'. */
-  int  errorflag = 0;       /* True if an error is encountered */
-  enum et_type xtype;       /* Conversion paradigm */
-  char *zExtra;             /* Extra memory used for etTCLESCAPE conversions */
+  et_info *infop;            /* Pointer to the appropriate info structure */
+  char buf[etBUFSIZE];       /* Conversion buffer */
+  char prefix;               /* Prefix character.  "+" or "-" or " " or '\0'. */
+  etByte errorflag = 0;      /* True if an error is encountered */
+  etByte xtype;              /* Conversion paradigm */
+  char *zExtra;              /* Extra memory used for etTCLESCAPE conversions */
   static char spaces[] = "                                                  "
      "                                                                      ";
 #define etSPACESIZE (sizeof(spaces)-1)
 #ifndef etNOFLOATINGPOINT
-  int  exp;                 /* exponent of real numbers */
-  double rounder;           /* Used for rounding floating point values */
-  int flag_dp;              /* True if decimal point should be shown */
-  int flag_rtz;             /* True if trailing zeros should be removed */
-  int flag_exp;             /* True to force display of the exponent */
-  int nsd;                  /* Number of significant digits returned */
+  int  exp;                  /* exponent of real numbers */
+  double rounder;            /* Used for rounding floating point values */
+  etByte flag_dp;            /* True if decimal point should be shown */
+  etByte flag_rtz;           /* True if trailing zeros should be removed */
+  etByte flag_exp;           /* True to force display of the exponent */
+  int nsd;                   /* Number of significant digits returned */
 #endif
 
-  fmt = format;                     /* Put in a register for speed */
   count = length = 0;
   bufpt = 0;
   for(; (c=(*fmt))!=0; ++fmt){
     if( c!='%' ){
-      register int amt;
+      int amt;
       bufpt = (char *)fmt;
       amt = 1;
       while( (c=(*++fmt))!='%' && c!=0 ) amt++;
@@ -242,7 +250,7 @@ static int vxprintf(
     }
     /* Find out what flags are present */
     flag_leftjustify = flag_plussign = flag_blanksign = 
-     flag_alternateform = flag_zeropad = flag_center = 0;
+     flag_alternateform = flag_zeropad = 0;
     do{
       switch( c ){
         case '-':   flag_leftjustify = 1;     c = 0;   break;
@@ -250,11 +258,9 @@ static int vxprintf(
         case ' ':   flag_blanksign = 1;       c = 0;   break;
         case '#':   flag_alternateform = 1;   c = 0;   break;
         case '0':   flag_zeropad = 1;         c = 0;   break;
-        case '=':   flag_center = 1;          c = 0;   break;
         default:                                       break;
       }
     }while( c==0 && (c=(*++fmt))!=0 );
-    if( flag_center ) flag_leftjustify = 0;
     /* Get the field width */
     width = 0;
     if( c=='*' ){
@@ -304,18 +310,14 @@ static int vxprintf(
     }
     /* Fetch the info entry for the field */
     infop = 0;
+    xtype = etERROR;
     for(idx=0; idx<etNINFO; idx++){
       if( c==fmtinfo[idx].fmttype ){
         infop = &fmtinfo[idx];
+        xtype = infop->type;
         break;
       }
     }
-    /* No info entry found.  It must be an error. */
-    if( infop==0 ){
-      xtype = etERROR;
-    }else{
-      xtype = infop->type;
-    }
     zExtra = 0;
 
     /*
@@ -337,7 +339,6 @@ static int vxprintf(
     **   infop                       Pointer to the appropriate info struct.
     */
     switch( xtype ){
-      case etORDINAL:
       case etRADIX:
         if( flag_long )  longvalue = va_arg(ap,long);
         else             longvalue = va_arg(ap,int);
@@ -350,7 +351,7 @@ static int vxprintf(
         ** but leave the prefix for hex. */
         if( longvalue==0 && infop->base==8 ) flag_alternateform = 0;
 #endif
-        if( infop->flag_signed ){
+        if( infop->flags & FLAG_SIGNED ){
           if( *(long*)&longvalue<0 ){
             longvalue = -*(long*)&longvalue;
             prefix = '-';
@@ -362,25 +363,6 @@ static int vxprintf(
           precision = width-(prefix!=0);
         }
         bufpt = &buf[etBUFSIZE];
-        if( xtype==etORDINAL ){
-          long a,b;
-          a = longvalue%10;
-          b = longvalue%100;
-          bufpt -= 2;
-          if( a==0 || a>3 || (b>10 && b<14) ){
-            bufpt[0] = 't';
-            bufpt[1] = 'h';
-          }else if( a==1 ){
-            bufpt[0] = 's';
-            bufpt[1] = 't';
-          }else if( a==2 ){
-            bufpt[0] = 'n';
-            bufpt[1] = 'd';
-          }else if( a==3 ){
-            bufpt[0] = 'r';
-            bufpt[1] = 'd';
-          }
-        }
         {
           register char *cset;      /* Use registers for speed */
           register int base;
@@ -609,11 +591,6 @@ static int vxprintf(
       register int nspace;
       nspace = width-length;
       if( nspace>0 ){
-        if( flag_center ){
-          nspace = nspace/2;
-          width -= nspace;
-          flag_leftjustify = 1;
-        }
         count += nspace;
         while( nspace>=etSPACESIZE ){
           (*func)(arg,spaces,etSPACESIZE);
index b3e9698fa7b62b1145428e753a0510f58b00439c..875091b6bfdd8aa6884efc9b291bbc92c946b321 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the sqlite_*_printf() interface.
 #
-# $Id: printf.test,v 1.6 2003/06/16 03:08:19 drh Exp $
+# $Id: printf.test,v 1.7 2004/02/02 12:29:25 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -107,9 +107,6 @@ do_test printf-5.1 {
 do_test printf-5.2 {
   sqlite_mprintf_str {%d %d (%-10.10s) %} -9 -10 {HelloHelloHello}
 } {-9 -10 (HelloHello) %}
-do_test printf-5.3 {
-  sqlite_mprintf_str {%% %d %d (%=10s)} 5 6 Hello
-} {% 5 6 (  Hello   )}
 
 do_test printf-6.1 {
   sqlite_mprintf_z_test , one two three four five six
index eeff3c329e9ffeef018bef2ad0b3acceed92a119..bdb5816d6f8b46a6e636b66854d5059ef5796e2a 100644 (file)
@@ -12,7 +12,7 @@
 # focus of this file is testing the sqlite_exec_printf() and
 # sqlite_get_table_printf() APIs.
 #
-# $Id: tableapi.test,v 1.6 2003/09/09 00:47:47 drh Exp $
+# $Id: tableapi.test,v 1.7 2004/02/02 12:29:25 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -62,7 +62,14 @@ do_test tableapi-2.3.2 {
   } {}
 } {0 3 2 a b 48 (48) 49 (49) 50 (50)}
 do_test tableapi-2.4 {
-  set ::big_str [sqlite_mprintf_str {%500'* Hello %500'*} 0 0 {}]
+  set manyquote ''''''''
+  append manyquote $manyquote
+  append manyquote $manyquote
+  append manyquote $manyquote
+  append manyquote $manyquote
+  append manyquote $manyquote
+  append manyquote $manyquote
+  set ::big_str "$manyquote Hello $manyquote"
   sqlite_get_table_printf $::dbx {
     INSERT INTO xyz VALUES(51,'%q')
   } $::big_str
@@ -120,7 +127,6 @@ do_test tableapi-3.3.2 {
   } {}
 } {0 3 2 a b 48 (48) 49 (49) 50 (50)}
 do_test tableapi-3.4 {
-  set ::big_str [sqlite_mprintf_str {%500'* Hello %500'*} 0 0 {}]
   sqlite_get_table_printf $::dbx {
     INSERT INTO xyz VALUES(51,'%q')
   } $::big_str