Fossil SCM
Enhance the "translate" utility so that formatting characters can occur in between the "%" and "C" of a printf-style conversion on @-lines.
Commit
f9711803e22ee8887484b981dc227b19d69d58c5
Parent
c7d6e334f8c1520…
1 file changed
+17
-12
+17
-12
| --- src/translate.c | ||
| +++ src/translate.c | ||
| @@ -12,10 +12,12 @@ | ||
| 12 | 12 | ** Author contact information: |
| 13 | 13 | ** [email protected] |
| 14 | 14 | ** http://www.hwaci.com/drh/ |
| 15 | 15 | ** |
| 16 | 16 | ******************************************************************************* |
| 17 | +** | |
| 18 | +** SYNOPSIS: | |
| 17 | 19 | ** |
| 18 | 20 | ** Input lines that begin with the "@" character are translated into |
| 19 | 21 | ** either cgi_printf() statements or string literals and the |
| 20 | 22 | ** translated code is written on standard output. |
| 21 | 23 | ** |
| @@ -28,10 +30,11 @@ | ||
| 28 | 30 | ** |
| 29 | 31 | ** This tool allows us to put raw HTML, without the special codes, in |
| 30 | 32 | ** the middle of a C program. This program then translates the text |
| 31 | 33 | ** into standard C by inserting all necessary backslashes and other |
| 32 | 34 | ** punctuation. |
| 35 | +** | |
| 33 | 36 | */ |
| 34 | 37 | #include <stdio.h> |
| 35 | 38 | #include <ctype.h> |
| 36 | 39 | #include <stdlib.h> |
| 37 | 40 | #include <string.h> |
| @@ -119,36 +122,38 @@ | ||
| 119 | 122 | fprintf(out,"%*s\"%s\\n\"\n",indent, "", zOut); |
| 120 | 123 | } |
| 121 | 124 | }else{ |
| 122 | 125 | /* Otherwise (if the last non-whitespace was not '=') then generate |
| 123 | 126 | ** a cgi_printf() statement whose format is the text following the '@'. |
| 124 | - ** Substrings of the form "%C(...)" where C is any character will | |
| 125 | - ** puts "%C" in the format and add the "..." as an argument to the | |
| 126 | - ** cgi_printf call. | |
| 127 | + ** Substrings of the form "%C(...)" (where C is any sequence of | |
| 128 | + ** characters other than \000 and '(') will put "%C" in the | |
| 129 | + ** format and add the "(...)" as an argument to the cgi_printf call. | |
| 127 | 130 | */ |
| 128 | 131 | int indent; |
| 132 | + int nC; | |
| 133 | + char c; | |
| 129 | 134 | i++; |
| 130 | 135 | if( isspace(zLine[i]) ){ i++; } |
| 131 | 136 | indent = i; |
| 132 | 137 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 133 | 138 | if( zLine[i]=='"' || zLine[i]=='\\' ){ zOut[j++] = '\\'; } |
| 134 | 139 | zOut[j++] = zLine[i]; |
| 135 | 140 | if( zLine[i]!='%' || zLine[i+1]=='%' || zLine[i+1]==0 ) continue; |
| 136 | - if( zLine[i+2]!='(' ) continue; | |
| 137 | - i++; | |
| 138 | - zOut[j++] = zLine[i]; | |
| 141 | + for(nC=1; zLine[i+nC] && zLine[i+nC]!='('; nC++){} | |
| 142 | + if( zLine[i+nC]!='(' || !isalpha(zLine[i+nC-1]) ) continue; | |
| 143 | + while( --nC ) zOut[j++] = zLine[++i]; | |
| 139 | 144 | zArg[nArg++] = ','; |
| 140 | - i += 2; | |
| 141 | - k = 1; | |
| 142 | - while( zLine[i] ){ | |
| 143 | - if( zLine[i]==')' ){ | |
| 145 | + k = 0; i++; | |
| 146 | + while( (c = zLine[i])!=0 ){ | |
| 147 | + zArg[nArg++] = c; | |
| 148 | + if( c==')' ){ | |
| 144 | 149 | k--; |
| 145 | 150 | if( k==0 ) break; |
| 146 | - }else if( zLine[i]=='(' ){ | |
| 151 | + }else if( c=='(' ){ | |
| 147 | 152 | k++; |
| 148 | 153 | } |
| 149 | - zArg[nArg++] = zLine[i++]; | |
| 154 | + i++; | |
| 150 | 155 | } |
| 151 | 156 | } |
| 152 | 157 | zOut[j] = 0; |
| 153 | 158 | if( !inPrint ){ |
| 154 | 159 | fprintf(out,"%*scgi_printf(\"%s\\n\"",indent-2,"", zOut); |
| 155 | 160 |
| --- src/translate.c | |
| +++ src/translate.c | |
| @@ -12,10 +12,12 @@ | |
| 12 | ** Author contact information: |
| 13 | ** [email protected] |
| 14 | ** http://www.hwaci.com/drh/ |
| 15 | ** |
| 16 | ******************************************************************************* |
| 17 | ** |
| 18 | ** Input lines that begin with the "@" character are translated into |
| 19 | ** either cgi_printf() statements or string literals and the |
| 20 | ** translated code is written on standard output. |
| 21 | ** |
| @@ -28,10 +30,11 @@ | |
| 28 | ** |
| 29 | ** This tool allows us to put raw HTML, without the special codes, in |
| 30 | ** the middle of a C program. This program then translates the text |
| 31 | ** into standard C by inserting all necessary backslashes and other |
| 32 | ** punctuation. |
| 33 | */ |
| 34 | #include <stdio.h> |
| 35 | #include <ctype.h> |
| 36 | #include <stdlib.h> |
| 37 | #include <string.h> |
| @@ -119,36 +122,38 @@ | |
| 119 | fprintf(out,"%*s\"%s\\n\"\n",indent, "", zOut); |
| 120 | } |
| 121 | }else{ |
| 122 | /* Otherwise (if the last non-whitespace was not '=') then generate |
| 123 | ** a cgi_printf() statement whose format is the text following the '@'. |
| 124 | ** Substrings of the form "%C(...)" where C is any character will |
| 125 | ** puts "%C" in the format and add the "..." as an argument to the |
| 126 | ** cgi_printf call. |
| 127 | */ |
| 128 | int indent; |
| 129 | i++; |
| 130 | if( isspace(zLine[i]) ){ i++; } |
| 131 | indent = i; |
| 132 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 133 | if( zLine[i]=='"' || zLine[i]=='\\' ){ zOut[j++] = '\\'; } |
| 134 | zOut[j++] = zLine[i]; |
| 135 | if( zLine[i]!='%' || zLine[i+1]=='%' || zLine[i+1]==0 ) continue; |
| 136 | if( zLine[i+2]!='(' ) continue; |
| 137 | i++; |
| 138 | zOut[j++] = zLine[i]; |
| 139 | zArg[nArg++] = ','; |
| 140 | i += 2; |
| 141 | k = 1; |
| 142 | while( zLine[i] ){ |
| 143 | if( zLine[i]==')' ){ |
| 144 | k--; |
| 145 | if( k==0 ) break; |
| 146 | }else if( zLine[i]=='(' ){ |
| 147 | k++; |
| 148 | } |
| 149 | zArg[nArg++] = zLine[i++]; |
| 150 | } |
| 151 | } |
| 152 | zOut[j] = 0; |
| 153 | if( !inPrint ){ |
| 154 | fprintf(out,"%*scgi_printf(\"%s\\n\"",indent-2,"", zOut); |
| 155 |
| --- src/translate.c | |
| +++ src/translate.c | |
| @@ -12,10 +12,12 @@ | |
| 12 | ** Author contact information: |
| 13 | ** [email protected] |
| 14 | ** http://www.hwaci.com/drh/ |
| 15 | ** |
| 16 | ******************************************************************************* |
| 17 | ** |
| 18 | ** SYNOPSIS: |
| 19 | ** |
| 20 | ** Input lines that begin with the "@" character are translated into |
| 21 | ** either cgi_printf() statements or string literals and the |
| 22 | ** translated code is written on standard output. |
| 23 | ** |
| @@ -28,10 +30,11 @@ | |
| 30 | ** |
| 31 | ** This tool allows us to put raw HTML, without the special codes, in |
| 32 | ** the middle of a C program. This program then translates the text |
| 33 | ** into standard C by inserting all necessary backslashes and other |
| 34 | ** punctuation. |
| 35 | ** |
| 36 | */ |
| 37 | #include <stdio.h> |
| 38 | #include <ctype.h> |
| 39 | #include <stdlib.h> |
| 40 | #include <string.h> |
| @@ -119,36 +122,38 @@ | |
| 122 | fprintf(out,"%*s\"%s\\n\"\n",indent, "", zOut); |
| 123 | } |
| 124 | }else{ |
| 125 | /* Otherwise (if the last non-whitespace was not '=') then generate |
| 126 | ** a cgi_printf() statement whose format is the text following the '@'. |
| 127 | ** Substrings of the form "%C(...)" (where C is any sequence of |
| 128 | ** characters other than \000 and '(') will put "%C" in the |
| 129 | ** format and add the "(...)" as an argument to the cgi_printf call. |
| 130 | */ |
| 131 | int indent; |
| 132 | int nC; |
| 133 | char c; |
| 134 | i++; |
| 135 | if( isspace(zLine[i]) ){ i++; } |
| 136 | indent = i; |
| 137 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 138 | if( zLine[i]=='"' || zLine[i]=='\\' ){ zOut[j++] = '\\'; } |
| 139 | zOut[j++] = zLine[i]; |
| 140 | if( zLine[i]!='%' || zLine[i+1]=='%' || zLine[i+1]==0 ) continue; |
| 141 | for(nC=1; zLine[i+nC] && zLine[i+nC]!='('; nC++){} |
| 142 | if( zLine[i+nC]!='(' || !isalpha(zLine[i+nC-1]) ) continue; |
| 143 | while( --nC ) zOut[j++] = zLine[++i]; |
| 144 | zArg[nArg++] = ','; |
| 145 | k = 0; i++; |
| 146 | while( (c = zLine[i])!=0 ){ |
| 147 | zArg[nArg++] = c; |
| 148 | if( c==')' ){ |
| 149 | k--; |
| 150 | if( k==0 ) break; |
| 151 | }else if( c=='(' ){ |
| 152 | k++; |
| 153 | } |
| 154 | i++; |
| 155 | } |
| 156 | } |
| 157 | zOut[j] = 0; |
| 158 | if( !inPrint ){ |
| 159 | fprintf(out,"%*scgi_printf(\"%s\\n\"",indent-2,"", zOut); |
| 160 |