Fossil SCM
fixed [6b498a792c]
Commit
0e2281fc8a757d9dac7adfa62382184675c87d4c
Parent
0ee44737e88ad02…
1 file changed
+27
-23
+27
-23
| --- src/encode.c | ||
| +++ src/encode.c | ||
| @@ -229,43 +229,47 @@ | ||
| 229 | 229 | ** |
| 230 | 230 | ** The fossilize() routine does an encoding of its input and |
| 231 | 231 | ** returns a pointer to the encoding in space obtained from |
| 232 | 232 | ** malloc. |
| 233 | 233 | */ |
| 234 | + | |
| 235 | +#ifdef __MINGW32__ | |
| 236 | +int isspace(int c) | |
| 237 | +{ | |
| 238 | + return (c==' ' || c=='\n' || c=='\r' || c=='\r' || c=='\f' || c=='\v' ) ; | |
| 239 | +} | |
| 240 | +#endif | |
| 241 | + | |
| 234 | 242 | char *fossilize(const char *zIn, int nIn){ |
| 235 | - int n, i, j, c; | |
| 243 | + int n, i, j; | |
| 244 | + char c; | |
| 236 | 245 | char *zOut; |
| 237 | 246 | if( nIn<0 ) nIn = strlen(zIn); |
| 238 | 247 | for(i=n=0; i<nIn; i++){ |
| 239 | 248 | c = zIn[i]; |
| 240 | 249 | if( c==0 || isspace(c) || c=='\\' ) n++; |
| 241 | 250 | } |
| 242 | 251 | n += nIn; |
| 243 | 252 | zOut = malloc( n+1 ); |
| 244 | 253 | if( zOut ){ |
| 245 | - for(i=j=0; i<nIn; i++){ | |
| 246 | - int c = zIn[i]; | |
| 247 | - if( c==0 ){ | |
| 248 | - zOut[j++] = '\\'; | |
| 249 | - zOut[j++] = '0'; | |
| 250 | - }else if( c=='\\' ){ | |
| 251 | - zOut[j++] = '\\'; | |
| 252 | - zOut[j++] = '\\'; | |
| 253 | - }else if( isspace(c) ){ | |
| 254 | - zOut[j++] = '\\'; | |
| 255 | - switch( c ){ | |
| 256 | - case '\n': c = 'n'; break; | |
| 257 | - case ' ': c = 's'; break; | |
| 258 | - case '\t': c = 't'; break; | |
| 259 | - case '\r': c = 'r'; break; | |
| 260 | - case '\v': c = 'v'; break; | |
| 261 | - case '\f': c = 'f'; break; | |
| 262 | - } | |
| 263 | - zOut[j++] = c; | |
| 264 | - }else{ | |
| 265 | - zOut[j++] = c; | |
| 266 | - } | |
| 254 | + j = 0; | |
| 255 | + while (*zIn != '\0') { | |
| 256 | + c = *zIn; | |
| 257 | + if( c=='\\' || isspace(c)) { | |
| 258 | + zOut[j++] = '\\'; | |
| 259 | + switch( c ){ | |
| 260 | + case '\\': c = '\\'; break; | |
| 261 | + case '\n': c = 'n'; break; | |
| 262 | + case ' ': c = 's'; break; | |
| 263 | + case '\t': c = 't'; break; | |
| 264 | + case '\r': c = 'r'; break; | |
| 265 | + case '\v': c = 'v'; break; | |
| 266 | + case '\f': c = 'f'; break; | |
| 267 | + } | |
| 268 | + } | |
| 269 | + zOut[j++] = c; | |
| 270 | + ++zIn; | |
| 267 | 271 | } |
| 268 | 272 | zOut[j] = 0; |
| 269 | 273 | } |
| 270 | 274 | return zOut; |
| 271 | 275 | } |
| 272 | 276 |
| --- src/encode.c | |
| +++ src/encode.c | |
| @@ -229,43 +229,47 @@ | |
| 229 | ** |
| 230 | ** The fossilize() routine does an encoding of its input and |
| 231 | ** returns a pointer to the encoding in space obtained from |
| 232 | ** malloc. |
| 233 | */ |
| 234 | char *fossilize(const char *zIn, int nIn){ |
| 235 | int n, i, j, c; |
| 236 | char *zOut; |
| 237 | if( nIn<0 ) nIn = strlen(zIn); |
| 238 | for(i=n=0; i<nIn; i++){ |
| 239 | c = zIn[i]; |
| 240 | if( c==0 || isspace(c) || c=='\\' ) n++; |
| 241 | } |
| 242 | n += nIn; |
| 243 | zOut = malloc( n+1 ); |
| 244 | if( zOut ){ |
| 245 | for(i=j=0; i<nIn; i++){ |
| 246 | int c = zIn[i]; |
| 247 | if( c==0 ){ |
| 248 | zOut[j++] = '\\'; |
| 249 | zOut[j++] = '0'; |
| 250 | }else if( c=='\\' ){ |
| 251 | zOut[j++] = '\\'; |
| 252 | zOut[j++] = '\\'; |
| 253 | }else if( isspace(c) ){ |
| 254 | zOut[j++] = '\\'; |
| 255 | switch( c ){ |
| 256 | case '\n': c = 'n'; break; |
| 257 | case ' ': c = 's'; break; |
| 258 | case '\t': c = 't'; break; |
| 259 | case '\r': c = 'r'; break; |
| 260 | case '\v': c = 'v'; break; |
| 261 | case '\f': c = 'f'; break; |
| 262 | } |
| 263 | zOut[j++] = c; |
| 264 | }else{ |
| 265 | zOut[j++] = c; |
| 266 | } |
| 267 | } |
| 268 | zOut[j] = 0; |
| 269 | } |
| 270 | return zOut; |
| 271 | } |
| 272 |
| --- src/encode.c | |
| +++ src/encode.c | |
| @@ -229,43 +229,47 @@ | |
| 229 | ** |
| 230 | ** The fossilize() routine does an encoding of its input and |
| 231 | ** returns a pointer to the encoding in space obtained from |
| 232 | ** malloc. |
| 233 | */ |
| 234 | |
| 235 | #ifdef __MINGW32__ |
| 236 | int isspace(int c) |
| 237 | { |
| 238 | return (c==' ' || c=='\n' || c=='\r' || c=='\r' || c=='\f' || c=='\v' ) ; |
| 239 | } |
| 240 | #endif |
| 241 | |
| 242 | char *fossilize(const char *zIn, int nIn){ |
| 243 | int n, i, j; |
| 244 | char c; |
| 245 | char *zOut; |
| 246 | if( nIn<0 ) nIn = strlen(zIn); |
| 247 | for(i=n=0; i<nIn; i++){ |
| 248 | c = zIn[i]; |
| 249 | if( c==0 || isspace(c) || c=='\\' ) n++; |
| 250 | } |
| 251 | n += nIn; |
| 252 | zOut = malloc( n+1 ); |
| 253 | if( zOut ){ |
| 254 | j = 0; |
| 255 | while (*zIn != '\0') { |
| 256 | c = *zIn; |
| 257 | if( c=='\\' || isspace(c)) { |
| 258 | zOut[j++] = '\\'; |
| 259 | switch( c ){ |
| 260 | case '\\': c = '\\'; break; |
| 261 | case '\n': c = 'n'; break; |
| 262 | case ' ': c = 's'; break; |
| 263 | case '\t': c = 't'; break; |
| 264 | case '\r': c = 'r'; break; |
| 265 | case '\v': c = 'v'; break; |
| 266 | case '\f': c = 'f'; break; |
| 267 | } |
| 268 | } |
| 269 | zOut[j++] = c; |
| 270 | ++zIn; |
| 271 | } |
| 272 | zOut[j] = 0; |
| 273 | } |
| 274 | return zOut; |
| 275 | } |
| 276 |