Fossil SCM
Enhance translate.c to interpret backslash at the end of a cgi_printf() "@" line as a directive to omit the newline
Commit
e193e21be335c5e36a1303615bd5ea7e06c9edd8
Parent
3cb9ba4de68923d…
1 file changed
+13
-2
+13
-2
| --- src/translate.c | ||
| +++ src/translate.c | ||
| @@ -46,10 +46,15 @@ | ||
| 46 | 46 | ** cause CC to become a comment character for the @-substitution. |
| 47 | 47 | ** Typical values for CC are "--" (for SQL text) or "#" (for Tcl script) |
| 48 | 48 | ** or "//" (for C++ code). Lines of subsequent @-blocks that begin with |
| 49 | 49 | ** CC are omitted from the output. |
| 50 | 50 | ** |
| 51 | +** Enhancement #3: | |
| 52 | +** | |
| 53 | +** If a non-enhancement #1 line ends in backslash, the backslash and the | |
| 54 | +** newline (\n) are not included in the argument to cgi_printf(). This | |
| 55 | +** is used to split one long output line across multiple source lines. | |
| 51 | 56 | */ |
| 52 | 57 | #include <stdio.h> |
| 53 | 58 | #include <ctype.h> |
| 54 | 59 | #include <stdlib.h> |
| 55 | 60 | #include <string.h> |
| @@ -141,17 +146,23 @@ | ||
| 141 | 146 | ** a cgi_printf() statement whose format is the text following the '@'. |
| 142 | 147 | ** Substrings of the form "%C(...)" (where C is any sequence of |
| 143 | 148 | ** characters other than \000 and '(') will put "%C" in the |
| 144 | 149 | ** format and add the "(...)" as an argument to the cgi_printf call. |
| 145 | 150 | */ |
| 151 | + const char *zNewline = "\\n"; | |
| 146 | 152 | int indent; |
| 147 | 153 | int nC; |
| 148 | 154 | char c; |
| 149 | 155 | i++; |
| 150 | 156 | if( isspace(zLine[i]) ){ i++; } |
| 151 | 157 | indent = i; |
| 152 | 158 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 159 | + if( zLine[i]=='\\' && (!zLine[i+1] || zLine[i+1]=='\r' | |
| 160 | + || zLine[i+1]=='\n') ){ | |
| 161 | + zNewline = ""; | |
| 162 | + break; | |
| 163 | + } | |
| 153 | 164 | if( zLine[i]=='"' || zLine[i]=='\\' ){ zOut[j++] = '\\'; } |
| 154 | 165 | zOut[j++] = zLine[i]; |
| 155 | 166 | if( zLine[i]!='%' || zLine[i+1]=='%' || zLine[i+1]==0 ) continue; |
| 156 | 167 | for(nC=1; zLine[i+nC] && zLine[i+nC]!='('; nC++){} |
| 157 | 168 | if( zLine[i+nC]!='(' || !isalpha(zLine[i+nC-1]) ) continue; |
| @@ -169,14 +180,14 @@ | ||
| 169 | 180 | i++; |
| 170 | 181 | } |
| 171 | 182 | } |
| 172 | 183 | zOut[j] = 0; |
| 173 | 184 | if( !inPrint ){ |
| 174 | - fprintf(out,"%*scgi_printf(\"%s\\n\"",indent-2,"", zOut); | |
| 185 | + fprintf(out,"%*scgi_printf(\"%s%s\"",indent-2,"", zOut, zNewline); | |
| 175 | 186 | inPrint = 1; |
| 176 | 187 | }else{ |
| 177 | - fprintf(out,"\n%*s\"%s\\n\"",indent+5, "", zOut); | |
| 188 | + fprintf(out,"\n%*s\"%s%s\"",indent+5, "", zOut, zNewline); | |
| 178 | 189 | } |
| 179 | 190 | } |
| 180 | 191 | } |
| 181 | 192 | } |
| 182 | 193 | |
| 183 | 194 |
| --- src/translate.c | |
| +++ src/translate.c | |
| @@ -46,10 +46,15 @@ | |
| 46 | ** cause CC to become a comment character for the @-substitution. |
| 47 | ** Typical values for CC are "--" (for SQL text) or "#" (for Tcl script) |
| 48 | ** or "//" (for C++ code). Lines of subsequent @-blocks that begin with |
| 49 | ** CC are omitted from the output. |
| 50 | ** |
| 51 | */ |
| 52 | #include <stdio.h> |
| 53 | #include <ctype.h> |
| 54 | #include <stdlib.h> |
| 55 | #include <string.h> |
| @@ -141,17 +146,23 @@ | |
| 141 | ** a cgi_printf() statement whose format is the text following the '@'. |
| 142 | ** Substrings of the form "%C(...)" (where C is any sequence of |
| 143 | ** characters other than \000 and '(') will put "%C" in the |
| 144 | ** format and add the "(...)" as an argument to the cgi_printf call. |
| 145 | */ |
| 146 | int indent; |
| 147 | int nC; |
| 148 | char c; |
| 149 | i++; |
| 150 | if( isspace(zLine[i]) ){ i++; } |
| 151 | indent = i; |
| 152 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 153 | if( zLine[i]=='"' || zLine[i]=='\\' ){ zOut[j++] = '\\'; } |
| 154 | zOut[j++] = zLine[i]; |
| 155 | if( zLine[i]!='%' || zLine[i+1]=='%' || zLine[i+1]==0 ) continue; |
| 156 | for(nC=1; zLine[i+nC] && zLine[i+nC]!='('; nC++){} |
| 157 | if( zLine[i+nC]!='(' || !isalpha(zLine[i+nC-1]) ) continue; |
| @@ -169,14 +180,14 @@ | |
| 169 | i++; |
| 170 | } |
| 171 | } |
| 172 | zOut[j] = 0; |
| 173 | if( !inPrint ){ |
| 174 | fprintf(out,"%*scgi_printf(\"%s\\n\"",indent-2,"", zOut); |
| 175 | inPrint = 1; |
| 176 | }else{ |
| 177 | fprintf(out,"\n%*s\"%s\\n\"",indent+5, "", zOut); |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 |
| --- src/translate.c | |
| +++ src/translate.c | |
| @@ -46,10 +46,15 @@ | |
| 46 | ** cause CC to become a comment character for the @-substitution. |
| 47 | ** Typical values for CC are "--" (for SQL text) or "#" (for Tcl script) |
| 48 | ** or "//" (for C++ code). Lines of subsequent @-blocks that begin with |
| 49 | ** CC are omitted from the output. |
| 50 | ** |
| 51 | ** Enhancement #3: |
| 52 | ** |
| 53 | ** If a non-enhancement #1 line ends in backslash, the backslash and the |
| 54 | ** newline (\n) are not included in the argument to cgi_printf(). This |
| 55 | ** is used to split one long output line across multiple source lines. |
| 56 | */ |
| 57 | #include <stdio.h> |
| 58 | #include <ctype.h> |
| 59 | #include <stdlib.h> |
| 60 | #include <string.h> |
| @@ -141,17 +146,23 @@ | |
| 146 | ** a cgi_printf() statement whose format is the text following the '@'. |
| 147 | ** Substrings of the form "%C(...)" (where C is any sequence of |
| 148 | ** characters other than \000 and '(') will put "%C" in the |
| 149 | ** format and add the "(...)" as an argument to the cgi_printf call. |
| 150 | */ |
| 151 | const char *zNewline = "\\n"; |
| 152 | int indent; |
| 153 | int nC; |
| 154 | char c; |
| 155 | i++; |
| 156 | if( isspace(zLine[i]) ){ i++; } |
| 157 | indent = i; |
| 158 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 159 | if( zLine[i]=='\\' && (!zLine[i+1] || zLine[i+1]=='\r' |
| 160 | || zLine[i+1]=='\n') ){ |
| 161 | zNewline = ""; |
| 162 | break; |
| 163 | } |
| 164 | if( zLine[i]=='"' || zLine[i]=='\\' ){ zOut[j++] = '\\'; } |
| 165 | zOut[j++] = zLine[i]; |
| 166 | if( zLine[i]!='%' || zLine[i+1]=='%' || zLine[i+1]==0 ) continue; |
| 167 | for(nC=1; zLine[i+nC] && zLine[i+nC]!='('; nC++){} |
| 168 | if( zLine[i+nC]!='(' || !isalpha(zLine[i+nC-1]) ) continue; |
| @@ -169,14 +180,14 @@ | |
| 180 | i++; |
| 181 | } |
| 182 | } |
| 183 | zOut[j] = 0; |
| 184 | if( !inPrint ){ |
| 185 | fprintf(out,"%*scgi_printf(\"%s%s\"",indent-2,"", zOut, zNewline); |
| 186 | inPrint = 1; |
| 187 | }else{ |
| 188 | fprintf(out,"\n%*s\"%s%s\"",indent+5, "", zOut, zNewline); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 |