Fossil SCM

Fix a small inconvenience in the `translate' utility program discovered while working with MSVC debug builds.

florian 2024-12-19 07:28 trunk
Commit 8defefd3ff8dfe1f5be167da14ee188aac5cdd231a952ad32d7e036f67fa6e63
1 file changed +16 -5
--- tools/translate.c
+++ tools/translate.c
@@ -78,10 +78,21 @@
7878
7979
/*
8080
** Name of files being processed
8181
*/
8282
static const char *zInFile = "(stdin)";
83
+
84
+/*
85
+** The `fossil_isspace()' function copied from the Fossil source code.
86
+** Some MSVC runtime library versions of `isspace()' fail with an assertion that
87
+** the input is smaller than -1 or greater than 255 in debug builds, due to sign
88
+** extension when promoting `signed char' to `int' for non-ASCII characters. Use
89
+** an `isspace()' replacement instead of explicit type casts to `unsigned char'.
90
+*/
91
+int fossil_isspace(char c){
92
+ return c==' ' || (c<='\r' && c>='\t');
93
+}
8394
8495
/*
8596
** Terminate an active cgi_printf() or free string
8697
*/
8798
static void end_block(FILE *out){
@@ -106,21 +117,21 @@
106117
char zOut[4000]; /* The input line translated into appropriate output */
107118
108119
c1 = c2 = '-';
109120
while( fgets(zLine, sizeof(zLine), in) ){
110121
lineNo++;
111
- for(i=0; zLine[i] && isspace(zLine[i]); i++){}
122
+ for(i=0; zLine[i] && fossil_isspace(zLine[i]); i++){}
112123
if( zLine[i]!='@' ){
113124
if( inPrint || inStr ) end_block(out);
114125
fprintf(out,"%s",zLine);
115126
/* 0123456789 12345 */
116127
if( strncmp(zLine, "/* @-comment: ", 14)==0 ){
117128
c1 = zLine[14];
118129
c2 = zLine[15];
119130
}
120131
i += strlen(&zLine[i]);
121
- while( i>0 && isspace(zLine[i-1]) ){ i--; }
132
+ while( i>0 && fossil_isspace(zLine[i-1]) ){ i--; }
122133
lastWasEq = i>0 && zLine[i-1]=='=';
123134
lastWasComma = i>0 && zLine[i-1]==',';
124135
}else if( lastWasEq || lastWasComma){
125136
/* If the last non-whitespace character before the first @ was
126137
** an "="(var init/set) or a ","(const definition in list) then
@@ -129,11 +140,11 @@
129140
** and end of line.
130141
*/
131142
int indent, omitline;
132143
char *zNewline = "\\n";
133144
i++;
134
- if( isspace(zLine[i]) ){ i++; }
145
+ if( fossil_isspace(zLine[i]) ){ i++; }
135146
indent = i - 2;
136147
if( indent<0 ) indent = 0;
137148
omitline = 0;
138149
for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){
139150
if( zLine[i]==c1 && (c2==' ' || zLine[i+1]==c2) ){
@@ -147,11 +158,11 @@
147158
break;
148159
}
149160
if( zLine[i]=='\\' || zLine[i]=='"' ){ zOut[j++] = '\\'; }
150161
zOut[j++] = zLine[i];
151162
}
152
- if( zNewline[0] ) while( j>0 && isspace(zOut[j-1]) ){ j--; }
163
+ if( zNewline[0] ) while( j>0 && fossil_isspace(zOut[j-1]) ){ j--; }
153164
zOut[j] = 0;
154165
if( j<=0 && omitline ){
155166
fprintf(out,"\n");
156167
}else{
157168
fprintf(out,"%*s\"%s%s\"\n",indent, "", zOut, zNewline);
@@ -171,11 +182,11 @@
171182
int indent;
172183
int nC;
173184
int nParam;
174185
char c;
175186
i++;
176
- if( isspace(zLine[i]) ){ i++; }
187
+ if( fossil_isspace(zLine[i]) ){ i++; }
177188
indent = i;
178189
for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){
179190
if( zLine[i]=='\\' && (!zLine[i+1] || zLine[i+1]=='\r'
180191
|| zLine[i+1]=='\n') ){
181192
zNewline = "";
182193
--- tools/translate.c
+++ tools/translate.c
@@ -78,10 +78,21 @@
78
79 /*
80 ** Name of files being processed
81 */
82 static const char *zInFile = "(stdin)";
 
 
 
 
 
 
 
 
 
 
 
83
84 /*
85 ** Terminate an active cgi_printf() or free string
86 */
87 static void end_block(FILE *out){
@@ -106,21 +117,21 @@
106 char zOut[4000]; /* The input line translated into appropriate output */
107
108 c1 = c2 = '-';
109 while( fgets(zLine, sizeof(zLine), in) ){
110 lineNo++;
111 for(i=0; zLine[i] && isspace(zLine[i]); i++){}
112 if( zLine[i]!='@' ){
113 if( inPrint || inStr ) end_block(out);
114 fprintf(out,"%s",zLine);
115 /* 0123456789 12345 */
116 if( strncmp(zLine, "/* @-comment: ", 14)==0 ){
117 c1 = zLine[14];
118 c2 = zLine[15];
119 }
120 i += strlen(&zLine[i]);
121 while( i>0 && isspace(zLine[i-1]) ){ i--; }
122 lastWasEq = i>0 && zLine[i-1]=='=';
123 lastWasComma = i>0 && zLine[i-1]==',';
124 }else if( lastWasEq || lastWasComma){
125 /* If the last non-whitespace character before the first @ was
126 ** an "="(var init/set) or a ","(const definition in list) then
@@ -129,11 +140,11 @@
129 ** and end of line.
130 */
131 int indent, omitline;
132 char *zNewline = "\\n";
133 i++;
134 if( isspace(zLine[i]) ){ i++; }
135 indent = i - 2;
136 if( indent<0 ) indent = 0;
137 omitline = 0;
138 for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){
139 if( zLine[i]==c1 && (c2==' ' || zLine[i+1]==c2) ){
@@ -147,11 +158,11 @@
147 break;
148 }
149 if( zLine[i]=='\\' || zLine[i]=='"' ){ zOut[j++] = '\\'; }
150 zOut[j++] = zLine[i];
151 }
152 if( zNewline[0] ) while( j>0 && isspace(zOut[j-1]) ){ j--; }
153 zOut[j] = 0;
154 if( j<=0 && omitline ){
155 fprintf(out,"\n");
156 }else{
157 fprintf(out,"%*s\"%s%s\"\n",indent, "", zOut, zNewline);
@@ -171,11 +182,11 @@
171 int indent;
172 int nC;
173 int nParam;
174 char c;
175 i++;
176 if( isspace(zLine[i]) ){ i++; }
177 indent = i;
178 for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){
179 if( zLine[i]=='\\' && (!zLine[i+1] || zLine[i+1]=='\r'
180 || zLine[i+1]=='\n') ){
181 zNewline = "";
182
--- tools/translate.c
+++ tools/translate.c
@@ -78,10 +78,21 @@
78
79 /*
80 ** Name of files being processed
81 */
82 static const char *zInFile = "(stdin)";
83
84 /*
85 ** The `fossil_isspace()' function copied from the Fossil source code.
86 ** Some MSVC runtime library versions of `isspace()' fail with an assertion that
87 ** the input is smaller than -1 or greater than 255 in debug builds, due to sign
88 ** extension when promoting `signed char' to `int' for non-ASCII characters. Use
89 ** an `isspace()' replacement instead of explicit type casts to `unsigned char'.
90 */
91 int fossil_isspace(char c){
92 return c==' ' || (c<='\r' && c>='\t');
93 }
94
95 /*
96 ** Terminate an active cgi_printf() or free string
97 */
98 static void end_block(FILE *out){
@@ -106,21 +117,21 @@
117 char zOut[4000]; /* The input line translated into appropriate output */
118
119 c1 = c2 = '-';
120 while( fgets(zLine, sizeof(zLine), in) ){
121 lineNo++;
122 for(i=0; zLine[i] && fossil_isspace(zLine[i]); i++){}
123 if( zLine[i]!='@' ){
124 if( inPrint || inStr ) end_block(out);
125 fprintf(out,"%s",zLine);
126 /* 0123456789 12345 */
127 if( strncmp(zLine, "/* @-comment: ", 14)==0 ){
128 c1 = zLine[14];
129 c2 = zLine[15];
130 }
131 i += strlen(&zLine[i]);
132 while( i>0 && fossil_isspace(zLine[i-1]) ){ i--; }
133 lastWasEq = i>0 && zLine[i-1]=='=';
134 lastWasComma = i>0 && zLine[i-1]==',';
135 }else if( lastWasEq || lastWasComma){
136 /* If the last non-whitespace character before the first @ was
137 ** an "="(var init/set) or a ","(const definition in list) then
@@ -129,11 +140,11 @@
140 ** and end of line.
141 */
142 int indent, omitline;
143 char *zNewline = "\\n";
144 i++;
145 if( fossil_isspace(zLine[i]) ){ i++; }
146 indent = i - 2;
147 if( indent<0 ) indent = 0;
148 omitline = 0;
149 for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){
150 if( zLine[i]==c1 && (c2==' ' || zLine[i+1]==c2) ){
@@ -147,11 +158,11 @@
158 break;
159 }
160 if( zLine[i]=='\\' || zLine[i]=='"' ){ zOut[j++] = '\\'; }
161 zOut[j++] = zLine[i];
162 }
163 if( zNewline[0] ) while( j>0 && fossil_isspace(zOut[j-1]) ){ j--; }
164 zOut[j] = 0;
165 if( j<=0 && omitline ){
166 fprintf(out,"\n");
167 }else{
168 fprintf(out,"%*s\"%s%s\"\n",indent, "", zOut, zNewline);
@@ -171,11 +182,11 @@
182 int indent;
183 int nC;
184 int nParam;
185 char c;
186 i++;
187 if( fossil_isspace(zLine[i]) ){ i++; }
188 indent = i;
189 for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){
190 if( zLine[i]=='\\' && (!zLine[i+1] || zLine[i+1]=='\r'
191 || zLine[i+1]=='\n') ){
192 zNewline = "";
193

Keyboard Shortcuts

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