Fossil SCM

Enhance translate.c to interpret backslash at the end of a cgi_printf() "@" line as a directive to omit the newline

andygoth 2016-11-05 06:37 trunk
Commit e193e21be335c5e36a1303615bd5ea7e06c9edd8
1 file changed +13 -2
+13 -2
--- src/translate.c
+++ src/translate.c
@@ -46,10 +46,15 @@
4646
** cause CC to become a comment character for the @-substitution.
4747
** Typical values for CC are "--" (for SQL text) or "#" (for Tcl script)
4848
** or "//" (for C++ code). Lines of subsequent @-blocks that begin with
4949
** CC are omitted from the output.
5050
**
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.
5156
*/
5257
#include <stdio.h>
5358
#include <ctype.h>
5459
#include <stdlib.h>
5560
#include <string.h>
@@ -141,17 +146,23 @@
141146
** a cgi_printf() statement whose format is the text following the '@'.
142147
** Substrings of the form "%C(...)" (where C is any sequence of
143148
** characters other than \000 and '(') will put "%C" in the
144149
** format and add the "(...)" as an argument to the cgi_printf call.
145150
*/
151
+ const char *zNewline = "\\n";
146152
int indent;
147153
int nC;
148154
char c;
149155
i++;
150156
if( isspace(zLine[i]) ){ i++; }
151157
indent = i;
152158
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
+ }
153164
if( zLine[i]=='"' || zLine[i]=='\\' ){ zOut[j++] = '\\'; }
154165
zOut[j++] = zLine[i];
155166
if( zLine[i]!='%' || zLine[i+1]=='%' || zLine[i+1]==0 ) continue;
156167
for(nC=1; zLine[i+nC] && zLine[i+nC]!='('; nC++){}
157168
if( zLine[i+nC]!='(' || !isalpha(zLine[i+nC-1]) ) continue;
@@ -169,14 +180,14 @@
169180
i++;
170181
}
171182
}
172183
zOut[j] = 0;
173184
if( !inPrint ){
174
- fprintf(out,"%*scgi_printf(\"%s\\n\"",indent-2,"", zOut);
185
+ fprintf(out,"%*scgi_printf(\"%s%s\"",indent-2,"", zOut, zNewline);
175186
inPrint = 1;
176187
}else{
177
- fprintf(out,"\n%*s\"%s\\n\"",indent+5, "", zOut);
188
+ fprintf(out,"\n%*s\"%s%s\"",indent+5, "", zOut, zNewline);
178189
}
179190
}
180191
}
181192
}
182193
183194
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button