Fossil SCM
Fix a small inconvenience in the `translate' utility program discovered while working with MSVC debug builds.
Commit
8defefd3ff8dfe1f5be167da14ee188aac5cdd231a952ad32d7e036f67fa6e63
Parent
bee9b3016870835…
1 file changed
+16
-5
+16
-5
| --- tools/translate.c | ||
| +++ tools/translate.c | ||
| @@ -78,10 +78,21 @@ | ||
| 78 | 78 | |
| 79 | 79 | /* |
| 80 | 80 | ** Name of files being processed |
| 81 | 81 | */ |
| 82 | 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 | +} | |
| 83 | 94 | |
| 84 | 95 | /* |
| 85 | 96 | ** Terminate an active cgi_printf() or free string |
| 86 | 97 | */ |
| 87 | 98 | static void end_block(FILE *out){ |
| @@ -106,21 +117,21 @@ | ||
| 106 | 117 | char zOut[4000]; /* The input line translated into appropriate output */ |
| 107 | 118 | |
| 108 | 119 | c1 = c2 = '-'; |
| 109 | 120 | while( fgets(zLine, sizeof(zLine), in) ){ |
| 110 | 121 | lineNo++; |
| 111 | - for(i=0; zLine[i] && isspace(zLine[i]); i++){} | |
| 122 | + for(i=0; zLine[i] && fossil_isspace(zLine[i]); i++){} | |
| 112 | 123 | if( zLine[i]!='@' ){ |
| 113 | 124 | if( inPrint || inStr ) end_block(out); |
| 114 | 125 | fprintf(out,"%s",zLine); |
| 115 | 126 | /* 0123456789 12345 */ |
| 116 | 127 | if( strncmp(zLine, "/* @-comment: ", 14)==0 ){ |
| 117 | 128 | c1 = zLine[14]; |
| 118 | 129 | c2 = zLine[15]; |
| 119 | 130 | } |
| 120 | 131 | i += strlen(&zLine[i]); |
| 121 | - while( i>0 && isspace(zLine[i-1]) ){ i--; } | |
| 132 | + while( i>0 && fossil_isspace(zLine[i-1]) ){ i--; } | |
| 122 | 133 | lastWasEq = i>0 && zLine[i-1]=='='; |
| 123 | 134 | lastWasComma = i>0 && zLine[i-1]==','; |
| 124 | 135 | }else if( lastWasEq || lastWasComma){ |
| 125 | 136 | /* If the last non-whitespace character before the first @ was |
| 126 | 137 | ** an "="(var init/set) or a ","(const definition in list) then |
| @@ -129,11 +140,11 @@ | ||
| 129 | 140 | ** and end of line. |
| 130 | 141 | */ |
| 131 | 142 | int indent, omitline; |
| 132 | 143 | char *zNewline = "\\n"; |
| 133 | 144 | i++; |
| 134 | - if( isspace(zLine[i]) ){ i++; } | |
| 145 | + if( fossil_isspace(zLine[i]) ){ i++; } | |
| 135 | 146 | indent = i - 2; |
| 136 | 147 | if( indent<0 ) indent = 0; |
| 137 | 148 | omitline = 0; |
| 138 | 149 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 139 | 150 | if( zLine[i]==c1 && (c2==' ' || zLine[i+1]==c2) ){ |
| @@ -147,11 +158,11 @@ | ||
| 147 | 158 | break; |
| 148 | 159 | } |
| 149 | 160 | if( zLine[i]=='\\' || zLine[i]=='"' ){ zOut[j++] = '\\'; } |
| 150 | 161 | zOut[j++] = zLine[i]; |
| 151 | 162 | } |
| 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--; } | |
| 153 | 164 | zOut[j] = 0; |
| 154 | 165 | if( j<=0 && omitline ){ |
| 155 | 166 | fprintf(out,"\n"); |
| 156 | 167 | }else{ |
| 157 | 168 | fprintf(out,"%*s\"%s%s\"\n",indent, "", zOut, zNewline); |
| @@ -171,11 +182,11 @@ | ||
| 171 | 182 | int indent; |
| 172 | 183 | int nC; |
| 173 | 184 | int nParam; |
| 174 | 185 | char c; |
| 175 | 186 | i++; |
| 176 | - if( isspace(zLine[i]) ){ i++; } | |
| 187 | + if( fossil_isspace(zLine[i]) ){ i++; } | |
| 177 | 188 | indent = i; |
| 178 | 189 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 179 | 190 | if( zLine[i]=='\\' && (!zLine[i+1] || zLine[i+1]=='\r' |
| 180 | 191 | || zLine[i+1]=='\n') ){ |
| 181 | 192 | zNewline = ""; |
| 182 | 193 |
| --- 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 |