Fossil SCM

Back out the changes of [0e2281fc8a757] since they were causing a segfault while trying to enter a new ticket. The ticket [6b498a792c0] should still be fixed.

drh 2010-02-24 22:39 trunk
Commit 5a6634c453eccfcf08bf5572e164d387b0924eba
1 file changed +25 -28
+25 -28
--- src/encode.c
+++ src/encode.c
@@ -229,47 +229,44 @@
229229
**
230230
** The fossilize() routine does an encoding of its input and
231231
** returns a pointer to the encoding in space obtained from
232232
** malloc.
233233
*/
234
-
235
-#ifdef __MINGW32__
236
-int isspace(int c)
237
-{
238
- return (c==' ' || c=='\n' || c=='\t' || c=='\r' || c=='\f' || c=='\v' ) ;
239
-}
240
-#endif
241
-
242234
char *fossilize(const char *zIn, int nIn){
243
- int n, i, j;
244
- char c;
235
+ int n, i, j, c;
245236
char *zOut;
246237
if( nIn<0 ) nIn = strlen(zIn);
247238
for(i=n=0; i<nIn; i++){
248239
c = zIn[i];
249
- if( c==0 || isspace(c) || c=='\\' ) n++;
240
+ if( c==0 || c==' ' || c=='\n' || c=='\t' || c=='\r' || c=='\f' || c=='\v'
241
+ || c=='\\' ) n++;
250242
}
251243
n += nIn;
252244
zOut = malloc( n+1 );
253245
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;
246
+ for(i=j=0; i<nIn; i++){
247
+ int c = zIn[i];
248
+ if( c==0 ){
249
+ zOut[j++] = '\\';
250
+ zOut[j++] = '0';
251
+ }else if( c=='\\' ){
252
+ zOut[j++] = '\\';
253
+ zOut[j++] = '\\';
254
+ }else if( isspace(c) ){
255
+ zOut[j++] = '\\';
256
+ switch( c ){
257
+ case '\n': c = 'n'; break;
258
+ case ' ': c = 's'; break;
259
+ case '\t': c = 't'; break;
260
+ case '\r': c = 'r'; break;
261
+ case '\v': c = 'v'; break;
262
+ case '\f': c = 'f'; break;
263
+ }
264
+ zOut[j++] = c;
265
+ }else{
266
+ zOut[j++] = c;
267
+ }
271268
}
272269
zOut[j] = 0;
273270
}
274271
return zOut;
275272
}
276273
--- src/encode.c
+++ src/encode.c
@@ -229,47 +229,44 @@
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=='\t' || 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
--- src/encode.c
+++ src/encode.c
@@ -229,47 +229,44 @@
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 || c==' ' || c=='\n' || c=='\t' || c=='\r' || c=='\f' || c=='\v'
241 || c=='\\' ) n++;
242 }
243 n += nIn;
244 zOut = malloc( n+1 );
245 if( zOut ){
246 for(i=j=0; i<nIn; i++){
247 int c = zIn[i];
248 if( c==0 ){
249 zOut[j++] = '\\';
250 zOut[j++] = '0';
251 }else if( c=='\\' ){
252 zOut[j++] = '\\';
253 zOut[j++] = '\\';
254 }else if( isspace(c) ){
255 zOut[j++] = '\\';
256 switch( c ){
257 case '\n': c = 'n'; break;
258 case ' ': c = 's'; break;
259 case '\t': c = 't'; break;
260 case '\r': c = 'r'; break;
261 case '\v': c = 'v'; break;
262 case '\f': c = 'f'; break;
263 }
264 zOut[j++] = c;
265 }else{
266 zOut[j++] = c;
267 }
268 }
269 zOut[j] = 0;
270 }
271 return zOut;
272 }
273

Keyboard Shortcuts

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