Diff
Not logged in

Differences From:

File src/printf.c part of check-in [c7278fd013] - Win32 port now functional except network operations. This commit was done on windows :-). See win32.txt for status of all commands. No networking commands are functional yet. All path operations are now functioning. by jnc on 2007-09-22 06:47:11. Also file src/printf.c part of check-in [3c5482959c] - Merge in the w32 changes. by drh on 2007-09-22 19:43:55. [view]

To:

File src/printf.c part of check-in [285929373757b] - Add the %w and %W formatting options for internal printf usage. Use these formatting characters to render wiki. Fix additional problems of unterminated wiki on webpage rendering by using %w. (There are probably more problems yet to be discovered and fixed.) by drh on 2007-11-22 22:55:05. Also file src/printf.c part of check-in [d0305b305a] - Merged mainline into my branch to get the newest application. by aku on 2007-12-05 08:07:46. [view]

@@ -51,8 +51,10 @@
 #define etHTTPIZE    17 /* Make text safe for HTTP.  "/" encoded as %2f */
 #define etURLIZE     18 /* Make text safe for HTTP.  "/" not encoded */
 #define etFOSSILIZE  19 /* The fossil header encoding format. */
 #define etPATH       20 /* Path type */
+#define etWIKISTR    21 /* Wiki text rendered from a char* */
+#define etWIKIBLOB   22 /* Wiki text rendered from a Blob* */
 
 
 /*
 ** An "etByte" is an 8-bit unsigned value.
@@ -94,8 +96,10 @@
   {  'q',  0, 4, etSQLESCAPE,  0,  0 },
   {  'Q',  0, 4, etSQLESCAPE2, 0,  0 },
   {  'b',  0, 2, etBLOB,       0,  0 },
   {  'B',  0, 2, etBLOBSQL,    0,  0 },
+  {  'w',  0, 2, etWIKISTR,    0,  0 },
+  {  'W',  0, 2, etWIKIBLOB,   0,  0 },
   {  'h',  0, 4, etHTMLIZE,    0,  0 },
   {  't',  0, 4, etHTTPIZE,    0,  0 },  /* "/" -> "%2F" */
   {  'T',  0, 4, etURLIZE,     0,  0 },  /* "/" unchanged */
   {  'F',  0, 4, etFOSSILIZE,  0,  0 },
@@ -172,10 +176,9 @@
 ** seems to make a big difference in determining how fast this beast
 ** will run.
 */
 int vxprintf(
-  void (*func)(void*,const char*,int),     /* Consumer of text */
-  void *arg,                         /* First argument to the consumer */
+  Blob *pBlob,                       /* Append output to this blob */
   const char *fmt,                   /* Format string */
   va_list ap                         /* arguments */
 ){
   int c;                     /* Next character in the format string */
@@ -211,9 +214,8 @@
   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 */
 
-  func(arg,"",0);
   count = length = 0;
   bufpt = 0;
   for(; (c=(*fmt))!=0; ++fmt){
     if( c!='%' ){
@@ -220,15 +222,15 @@
       int amt;
       bufpt = (char *)fmt;
       amt = 1;
       while( (c=(*++fmt))!='%' && c!=0 ) amt++;
-      (*func)(arg,bufpt,amt);
+      blob_append(pBlob,bufpt,amt);
       count += amt;
       if( c==0 ) break;
     }
     if( (c=(*++fmt))==0 ){
       errorflag = 1;
-      (*func)(arg,"%",1);
+      blob_append(pBlob,"%",1);
       count++;
       break;
     }
     /* Find out what flags are present */
@@ -660,14 +662,29 @@
         length = strlen(bufpt);
         if( precision>=0 && precision<length ) length = precision;
         break;
       }
+      case etWIKISTR: {
+        char *zWiki = va_arg(ap, char*);
+        Blob wiki;
+        blob_init(&wiki, zWiki, -1);
+        wiki_convert(&wiki, pBlob, WIKI_INLINE);
+        blob_reset(&wiki);
+        length = width = 0;
+        break;
+      }
+      case etWIKIBLOB: {
+        Blob *pWiki = va_arg(ap, Blob*);
+        wiki_convert(pWiki, pBlob, WIKI_INLINE);
+        length = width = 0;
+        break;
+      }
       case etERROR:
         buf[0] = '%';
         buf[1] = c;
         errorflag = 0;
         idx = 1+(c!=0);
-        (*func)(arg,"%",idx);
+        blob_append(pBlob,"%",idx);
         count += idx;
         if( c==0 ) fmt--;
         break;
     }/* End switch over the format type */
@@ -681,16 +698,16 @@
       nspace = width-length;
       if( nspace>0 ){
         count += nspace;
         while( nspace>=etSPACESIZE ){
-          (*func)(arg,spaces,etSPACESIZE);
+          blob_append(pBlob,spaces,etSPACESIZE);
           nspace -= etSPACESIZE;
         }
-        if( nspace>0 ) (*func)(arg,spaces,nspace);
+        if( nspace>0 ) blob_append(pBlob,spaces,nspace);
       }
     }
     if( length>0 ){
-      (*func)(arg,bufpt,length);
+      blob_append(pBlob,bufpt,length);
       count += length;
     }
     if( flag_leftjustify ){
       register int nspace;
@@ -697,12 +714,12 @@
       nspace = width-length;
       if( nspace>0 ){
         count += nspace;
         while( nspace>=etSPACESIZE ){
-          (*func)(arg,spaces,etSPACESIZE);
+          blob_append(pBlob,spaces,etSPACESIZE);
           nspace -= etSPACESIZE;
         }
-        if( nspace>0 ) (*func)(arg,spaces,nspace);
+        if( nspace>0 ) blob_append(pBlob,spaces,nspace);
       }
     }
     if( zExtra ){
       free(zExtra);