Check-in [3af1fdf57a]

Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
SHA1 Hash:3af1fdf57ab1a303c320a0bf103bce5188c1dbd9
Date: 2008-11-13 18:11:40
User: stephan
Comment:a number of small cleanups and bug fixes
Changes
hide diffs unified diffs patch

Changes to include/s11n.net/c11n/io/c11n_io.h

Old (7601bb59936d7d90) New (9dbf5d93642321c4)
1 #ifndef S11N_NET_C11N_IO_H_INCLUDED 1 #ifndef S11N_NET_C11N_IO_H_INCLUDED
2 #define S11N_NET_C11N_IO_H_INCLUDED 1 2 #define S11N_NET_C11N_IO_H_INCLUDED 1
3 /* 3 /*
4 This file contains declarations and documentation for the generic 4 This file contains declarations and documentation for the generic
5 i/o routines for c11n. The core does not know about this API and no 5 i/o routines for c11n. The core does not know about this API and no
573 hidden lines
579 /** 579 /**
580 Tries to register the given (non-0) cookie as a lookup key for 580 Tries to register the given (non-0) cookie as a lookup key for
581 a factory function which can generate c11n_io_handler objects. On 581 a factory function which can generate c11n_io_handler objects. On
582 success it returns true. It can fail for these reasons: 582 success it returns true. It can fail for these reasons:
583 583
584 - The number of registration slots is static and quite limited. It can run out. | 584 - The number of registration slots is static and quite limited. It
| 585 can run out. The library guarantees that at least 10 slots are
| 586 left open for client-side use, over and above what registrations
| 587 the library has hard-wired in.
585 588
586 - A different factory was already registered with that name. 589 - A different factory was already registered with that name.
587 590
588 - cookie is 0. 591 - cookie is 0.
589 592
200 hidden lines
790 #ifdef __cplusplus 793 #ifdef __cplusplus
791 } /* extern "C" */ 794 } /* extern "C" */
792 #endif 795 #endif
793 796
794 #endif // S11N_NET_C11N_IO_H_INCLUDED 797 #endif // S11N_NET_C11N_IO_H_INCLUDED

Changes to include/s11n.net/c11n/io/c11n_io_handler_expat.h

Old (325d453e3ac3c316) New (fc528579da23b3cc)
1 #if !defined(_S11N_NET_C11N_IO_HANDLER_EXPAT_H_INCLUDED_) 1 #if !defined(_S11N_NET_C11N_IO_HANDLER_EXPAT_H_INCLUDED_)
2 #define _S11N_NET_C11N_IO_HANDLER_EXPAT_H_INCLUDED_ 1 2 #define _S11N_NET_C11N_IO_HANDLER_EXPAT_H_INCLUDED_ 1
3 3
4 #include "c11n_io.h" 4 #include "c11n_io.h"
5 #ifdef __cplusplus 5 #ifdef __cplusplus
11 hidden lines
17 17
18 Compat mode is turned off by default because it is possible (and 18 Compat mode is turned off by default because it is possible (and
19 more efficient) to use the "binarish" format to convert data 19 more efficient) to use the "binarish" format to convert data
20 between libs11n and libc11n. 20 between libs11n and libc11n.
21 */ 21 */
22 #define C11N_IO_HANDLER_EXPAT_S11N_COMPAT 0 | 22 #define C11N_IO_HANDLER_EXPAT_S11N_COMPAT 1
23 23
24 /** @def C11N_IO_HANDLER_EXPAT_COOKIE 24 /** @def C11N_IO_HANDLER_EXPAT_COOKIE
25 Unfortunately C11N_IO_HANDLER_EXPAT_COOKIE must be defined as a macro 25 Unfortunately C11N_IO_HANDLER_EXPAT_COOKIE must be defined as a macro
26 instead of a (extern char const *) because C won't allow non-const 26 instead of a (extern char const *) because C won't allow non-const
27 initializers and we may use this cookie in static registration code. 27 initializers and we may use this cookie in static registration code.
22 hidden lines
50 50
51 #ifdef __cplusplus 51 #ifdef __cplusplus
52 } /* extern "C" */ 52 } /* extern "C" */
53 #endif 53 #endif
54 #endif /* _S11N_NET_C11N_IO_HANDLER_EXPAT_H_INCLUDED_ */ 54 #endif /* _S11N_NET_C11N_IO_HANDLER_EXPAT_H_INCLUDED_ */

Changes to src/c11n_io_handler_binarish.c

Old (a15017b2225be2d6) New (253bb514b07d1350)
1 #include "s11n.net/c11n/io/c11n_io.h" 1 #include "s11n.net/c11n/io/c11n_io.h"
2 #include "s11n.net/c11n/detail/whclob.h" 2 #include "s11n.net/c11n/detail/whclob.h"
3 3
4 #include <stdlib.h> 4 #include <stdlib.h>
5 #include <ctype.h> /* isspace() and friends. */ 5 #include <ctype.h> /* isspace() and friends. */
290 hidden lines
296 */ 296 */
297 static bool binarish_read_token(c11n_io_handler * self, size_t size, bool skipWS ) 297 static bool binarish_read_token(c11n_io_handler * self, size_t size, bool skipWS )
298 { 298 {
299 IMPLDECL(false); 299 IMPLDECL(false);
300 if( !self || (0 == size) ) return false; 300 if( !self || (0 == size) ) return false;
301 #if 0 | 301 #if 1
| 302 /*
| 303 This requires much fewer allocs than whclob_reset(), though it
| 304 also means that impl->clob will stay the size of the largest
| 305 token throughout the parse process.
| 306 */
302 whclob_reserve( impl->clob, size ? size : 1 ); 307 whclob_reserve( impl->clob, size ? size : 1 );
303 whclob_truncate( impl->clob, 0, 1 ); | 308 whclob_truncate( impl->clob, 0, 0 );
304 #else 309 #else
305 whclob_reset(impl->clob); 310 whclob_reset(impl->clob);
306 whclob_reserve( impl->clob, size ); 311 whclob_reserve( impl->clob, size );
307 #endif 312 #endif
308 char * buf = whclob_buffer(impl->clob); 313 char * buf = whclob_buffer(impl->clob);
218 hidden lines
527 532
528 c11n_io_handler * c11n_io_handler_factory_binarish( c11n_const_string_t ignored ) 533 c11n_io_handler * c11n_io_handler_factory_binarish( c11n_const_string_t ignored )
529 { 534 {
530 return c11n_io_handler_create_binarish(); 535 return c11n_io_handler_create_binarish();
531 } 536 }

Changes to src/c11n_io_handler_expat.c

Old (857a85d9653cb677) New (735eeeee89d7518e)
1 #include "s11n.net/c11n/io/c11n_io.h" 1 #include "s11n.net/c11n/io/c11n_io.h"
2 #include "s11n.net/c11n/io/c11n_io_handler_expat.h" 2 #include "s11n.net/c11n/io/c11n_io_handler_expat.h"
3 #include "s11n.net/c11n/detail/whclob.h" 3 #include "s11n.net/c11n/detail/whclob.h"
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
49 hidden lines
55 {"<",1,"&lt;",4}, 55 {"<",1,"&lt;",4},
56 {">",1,"&gt;",4}, 56 {">",1,"&gt;",4},
57 #if C11N_IO_HANDLER_EXPAT_S11N_COMPAT 57 #if C11N_IO_HANDLER_EXPAT_S11N_COMPAT
58 /** 58 /**
59 The next two would be here only here to accomodate an old mistake in 59 The next two would be here only here to accomodate an old mistake in
60 libs11n's expat format (with which we may want to be compatible here): | 60 libs11n's expat format (with which we want to be compatible here).
61 */ | 61 In theory we don't need them - expat does the unescaping for us, so libs11n
| 62 should be able to cope with unescaped quotes.
| 63
62 {"\"",1,"&quot;",6}, 64 {"\"",1,"&quot;",6},
63 {"'",1,"&apos;",6}, 65 {"'",1,"&apos;",6},
> 66 */
64 #endif 67 #endif
65 {0,0,0,0} 68 {0,0,0,0}
66 }; 69 };
67 70
68 71
18 hidden lines
87 c11n_stream * dest = impl->stream; 90 c11n_stream * dest = impl->stream;
88 91
89 if( impl->indentLevel++ != 0 ) 92 if( impl->indentLevel++ != 0 )
90 { 93 {
91 whclob_append( impl->tabs, "\t", 1 ); 94 whclob_append( impl->tabs, "\t", 1 );
> 95 //whclob_null_terminate( impl->tabs );
92 } 96 }
93 char const * tabs = whclob_bufferc( impl->tabs ); 97 char const * tabs = whclob_bufferc( impl->tabs );
> 98 if( ! tabs || !*tabs ) tabs = "";
> 99
94 WF( dest, "%s<%s class=\"%s\">\n", tabs, c11n_node_get_name( src ), c11n_node_get_class(src) ); 100 WF( dest, "%s<%s class=\"%s\">\n", tabs, c11n_node_get_name( src ), c11n_node_get_class(src) );
95 #if 1 101 #if 1
96 c11n_prop_iter piter = c11n_node_prop_iter(src); 102 c11n_prop_iter piter = c11n_node_prop_iter(src);
97 while( c11n_prop_iter_isvalid( &piter ) ) 103 while( c11n_prop_iter_isvalid( &piter ) )
98 { 104 {
2 hidden lines
101 whclob_truncate( impl->xlate, 0, 0 ); 107 whclob_truncate( impl->xlate, 0, 0 );
102 if( val ) 108 if( val )
103 { 109 {
104 c11n_io_escape_string( val, c11n_strlen( val ), expat_val_escapes, true, impl->xlate ); 110 c11n_io_escape_string( val, c11n_strlen( val ), expat_val_escapes, true, impl->xlate );
105 } 111 }
106 WF( dest, "%s\t<%s>%s</%s>\n", tabs, key, | 112 WF( dest, "\t%s<%s>%s</%s>\n", tabs, key,
107 whclob_size(impl->xlate) ? whclob_bufferc(impl->xlate) : "", 113 whclob_size(impl->xlate) ? whclob_bufferc(impl->xlate) : "",
108 key ); 114 key );
109 c11n_prop_iter_next(&piter); 115 c11n_prop_iter_next(&piter);
110 } 116 }
111 #endif 117 #endif
3 hidden lines
115 { 121 {
116 if( ! expat_save_node( self, chi.node ) ) return false; 122 if( ! expat_save_node( self, chi.node ) ) return false;
117 c11n_node_iter_next_c(&chi); 123 c11n_node_iter_next_c(&chi);
118 } 124 }
119 #endif 125 #endif
> 126 --impl->indentLevel;
> 127 whclob_truncate( impl->tabs, impl->indentLevel, 0 );
120 WF( dest, "%s</%s>\n", tabs, c11n_node_get_name( src ) ); 128 WF( dest, "%s</%s>\n", tabs, c11n_node_get_name( src ) );
121 #undef WF 129 #undef WF
122 #undef W 130 #undef W
123 whclob_resize( impl->tabs, --impl->indentLevel ); | 131 //whclob_null_terminate( impl->tabs );
124 return true; 132 return true;
125 } 133 }
126 134
127 static bool expat_save_root_node( c11n_io_handler * self, 135 static bool expat_save_root_node( c11n_io_handler * self,
128 c11n_node const * src, 136 c11n_node const * src,
2 hidden lines
131 IMPLDECL(false); 139 IMPLDECL(false);
132 if( !src || (!dest || !dest->api->isgood(dest)) ) return false; 140 if( !src || (!dest || !dest->api->isgood(dest)) ) return false;
133 if(0) return expat_save_root_node(self,src,dest);/* kludge to avoid "static func defined but not used" warning*/ 141 if(0) return expat_save_root_node(self,src,dest);/* kludge to avoid "static func defined but not used" warning*/
134 self->api->clear(self); 142 self->api->clear(self);
135 impl->stream = dest; 143 impl->stream = dest;
136 #define WF c11n_stream_writef <
137 #define LEN(S) c11n_strlen(S) <
138 <
139 impl->tabs = whclob_new(); 144 impl->tabs = whclob_new();
140 impl->xlate = whclob_new(); 145 impl->xlate = whclob_new();
141 WF( dest, "%s\n", self->api->cookie_string ); | 146 c11n_stream_writef( dest, "%s\n", self->api->cookie_string );
142 bool ret = expat_save_node( self, src ); 147 bool ret = expat_save_node( self, src );
143 self->api->clear(self); 148 self->api->clear(self);
144 #undef LEN <
145 #undef WF <
146 return ret; 149 return ret;
147 } 150 }
148 151
149 152
150 #define XSELFDECL c11n_io_expat_data * impl = (c11n_io_expat_data *)uArg; assert(impl && "impl failed!"); if(!impl) return 153 #define XSELFDECL c11n_io_expat_data * impl = (c11n_io_expat_data *)uArg; assert(impl && "impl failed!"); if(!impl) return
149 hidden lines
300 303
301 c11n_io_handler * c11n_io_handler_factory_expat( c11n_const_string_t ignored ) 304 c11n_io_handler * c11n_io_handler_factory_expat( c11n_const_string_t ignored )
302 { 305 {
303 return c11n_io_handler_create_expat(); 306 return c11n_io_handler_create_expat();
304 } 307 }

Changes to src/c11n_io_handler_sql.c

Old (8d436283c0bcbe1c) New (f6ec0e47e47cda19)
1 #include <stdlib.h> /* malloc()/free() */ 1 #include <stdlib.h> /* malloc()/free() */
2 #include <sqlite3.h> 2 #include <sqlite3.h>
3 #include <assert.h> 3 #include <assert.h>
4 #include "s11n.net/c11n/io/c11n_io_handler_sql.h" 4 #include "s11n.net/c11n/io/c11n_io_handler_sql.h"
5 #include "s11n.net/c11n/io/c11n_stream_whclob.h" 5 #include "s11n.net/c11n/io/c11n_stream_whclob.h"
277 hidden lines
283 { 283 {
284 #define PUL(X) ((unsigned long)(X)) 284 #define PUL(X) ((unsigned long)(X))
285 c11n_node const * par = c11n_node_parent_c( src ); 285 c11n_node const * par = c11n_node_parent_c( src );
286 /** 286 /**
287 Maybe todo: replace the %Q writef specifiers with 287 Maybe todo: replace the %Q writef specifiers with
288 c11n_io_escape_string(). %Q is an extension of vappendf(), | 288 c11n_io_escape_string(). %Q is an extension of vappendf(),
289 inherited from the sqlite3 origins of vappendf()'s 289 inherited from the sqlite3 origins of vappendf()'s
290 implementation. 290 implementation.
291 */ 291 */
292 c11n_stream_writef( dest, 292 c11n_stream_writef( dest,
293 "INSERT INTO n (id,pid,name,class) " 293 "INSERT INTO n (id,pid,name,class) "
13 hidden lines
307 c11n_prop_iter_key( &piter ), 307 c11n_prop_iter_key( &piter ),
308 c11n_prop_iter_val( &piter ) ); 308 c11n_prop_iter_val( &piter ) );
309 if( ! rc ) return false; 309 if( ! rc ) return false;
310 c11n_prop_iter_next(&piter); 310 c11n_prop_iter_next(&piter);
311 } 311 }
312 #undef PUL /* i sometimes find it interesting that even though macros do not respect scope, we programmers tend to respect it when defining/undefining macros. */ | 312 #undef PUL /* i sometimes find it interesting that even though macros
| 313 do not respect scope, we programmers tend to respect
| 314 scopes when defining/undefining macros. */
313 c11n_node_iter_c chi = c11n_node_children_iter_c( src ); 315 c11n_node_iter_c chi = c11n_node_children_iter_c( src );
314 while( c11n_node_iter_isvalid_c( &chi ) ) 316 while( c11n_node_iter_isvalid_c( &chi ) )
315 { 317 {
316 if( ! c11n_io_handler_sql_save_one_node( self, chi.node, dest ) ) return false; 318 if( ! c11n_io_handler_sql_save_one_node( self, chi.node, dest ) ) return false;
317 c11n_node_iter_next_c(&chi); 319 c11n_node_iter_next_c(&chi);
117 hidden lines
435 437
436 c11n_io_handler * c11n_io_handler_factory_sql( c11n_const_string_t ignored ) 438 c11n_io_handler * c11n_io_handler_factory_sql( c11n_const_string_t ignored )
437 { 439 {
438 return c11n_io_handler_sql_new(); 440 return c11n_io_handler_sql_new();
439 } 441 }

Changes to src/c11nconvert.c

Old (556642b4ed472aef) New (8470a76984a6c793)
1 #include "s11n.net/c11n/c11n.h" 1 #include "s11n.net/c11n/c11n.h"
2 #include "s11n.net/c11n/io/c11n_io.h" 2 #include "s11n.net/c11n/io/c11n_io.h"
3 #include "s11n.net/c11n/io/c11n_stream_FILE.h" 3 #include "s11n.net/c11n/io/c11n_stream_FILE.h"
4 4
5 #include <stdio.h> 5 #include <stdio.h>
162 hidden lines
168 { 168 {
169 ERROR("Could not read c11n_node from stdin!"); 169 ERROR("Could not read c11n_node from stdin!");
170 return ErrIO; 170 return ErrIO;
171 } 171 }
172 whgc_add( ThisApp.gc, nodeIn, gc_c11n_node ); 172 whgc_add( ThisApp.gc, nodeIn, gc_c11n_node );
173 | 173 //c11n_dump_node( nodeIn, true );
174 if( ! writer->api->save_node( writer, nodeIn, outStream ) ) 174 if( ! writer->api->save_node( writer, nodeIn, outStream ) )
175 { 175 {
176 ERROR("Save failed!"); 176 ERROR("Save failed!");
177 return ErrIO; 177 return ErrIO;
178 178
2 hidden lines
181 (0==rc) 181 (0==rc)
182 ? "You win :)" 182 ? "You win :)"
183 : "You lose :("); 183 : "You lose :(");
184 return rc; 184 return rc;
185 } 185 }

Changes to src/test.c

Old (879583fb44743ad1) New (9063e71e1dcb9858)
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <string.h> 3 #include <string.h>
4 #include <ctype.h> 4 #include <ctype.h>
5 #include <assert.h> 5 #include <assert.h>
449 hidden lines
455 //whclob_finalize(cb); 455 //whclob_finalize(cb);
456 return 0; 456 return 0;
457 } 457 }
458 458
459 #if C11N_IO_USE_SQL 459 #if C11N_IO_USE_SQL
460 #include "s11n.net/c11n/io/c11n_io_handler_sql.h" <
461 int test_sql() 460 int test_sql()
462 { 461 {
463 c11n_io_handler * ioh = c11n_io_handler_for_sql(); | 462 c11n_io_handler * ioh =
| 463 //c11n_io_handler_by_name("binarish")
| 464 c11n_io_handler_by_name("sql")
| 465 ;
464 MARKER("ioh @ %p\n",ioh); 466 MARKER("ioh @ %p\n",ioh);
465 467
466 c11n_io_tree_builder bob = c11n_io_tree_builder_init; 468 c11n_io_tree_builder bob = c11n_io_tree_builder_init;
467 bob.open_node( &bob, "myNode", "SumDumType" ); 469 bob.open_node( &bob, "myNode", "SumDumType" );
468 bob.set_prop( &bob, "foo", "donkey ears" ); 470 bob.set_prop( &bob, "foo", "donkey ears" );
68 hidden lines
537 : "You lose :("); 539 : "You lose :(");
538 ThisApp.cout->api->destroy(ThisApp.cout); 540 ThisApp.cout->api->destroy(ThisApp.cout);
539 whgc_destroy_context(ThisApp.gc); 541 whgc_destroy_context(ThisApp.gc);
540 return rc; 542 return rc;
541 } 543 }

Changes to src/whclob.c

Old (bf41c0a532db1e43) New (7a37db85b2a5c1fc)
1 #include <string.h> 1 #include <string.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <stdio.h> 3 #include <stdio.h>
4 #include <stdarg.h> 4 #include <stdarg.h>
5 5
158 hidden lines
164 164
165 static long whclob_do_resize( whclob * cb, 165 static long whclob_do_resize( whclob * cb,
166 unsigned int sz, 166 unsigned int sz,
167 short usePolicyHint) 167 short usePolicyHint)
168 { 168 {
169 static const int fudge = 1; | 169 static const int fudge = 2;
170 char const * zOld = 0; 170 char const * zOld = 0;
171 long oldUsed = 0; 171 long oldUsed = 0;
172 long oldAlloc = 0; 172 long oldAlloc = 0;
173 long allocsize = 0; 173 long allocsize = 0;
174 char * pNew = 0; 174 char * pNew = 0;
286 hidden lines
461 461
462 462
463 long whclob_append( whclob * cb, char const * data, long dsize ) 463 long whclob_append( whclob * cb, char const * data, long dsize )
464 { 464 {
465 long old = cb->nUsed; 465 long old = cb->nUsed;
466 cb->nUsed += whclob_writeat( cb, cb->nUsed, data, dsize ); | 466 long rc = whclob_writeat( cb, cb->nUsed, data, dsize );
| 467 if( rc < whclob_rc.OK ) return rc;
| 468 cb->nUsed += rc;
| 469 //cb->aData[cb->nUsed] = 0;
| 470 whclob_null_terminate(cb);
467 return cb->nUsed - old; 471 return cb->nUsed - old;
468 } 472 }
469 473
470 long whclob_append_char_n( whclob * cb, char c, long n ) 474 long whclob_append_char_n( whclob * cb, char c, long n )
471 { 475 {
473 if( !cb || (n <= 0) ) return whclob_rc.RangeError; 477 if( !cb || (n <= 0) ) return whclob_rc.RangeError;
474 rc = whclob_reserve( cb, cb->nUsed + n ); 478 rc = whclob_reserve( cb, cb->nUsed + n );
475 if( rc < 0 ) return rc; 479 if( rc < 0 ) return rc;
476 memset( cb->aData + cb->nUsed, c, n ); 480 memset( cb->aData + cb->nUsed, c, n );
477 cb->nUsed += n; 481 cb->nUsed += n;
> 482 /* do we want to do a whclob_null_terminate() here? */
> 483 /* whclob_null_terminate(cb); */
478 return n; 484 return n;
479 } 485 }
480 486
481 487
482 long whclob_copy( whclob * src, whclob * dest ) 488 long whclob_copy( whclob * src, whclob * dest )
709 hidden lines
1192 } 1198 }
1193 #endif /* WHCLOB_USE_FILE */ 1199 #endif /* WHCLOB_USE_FILE */
1194 1200
1195 #undef WHCLOB_USE_ZLIB 1201 #undef WHCLOB_USE_ZLIB
1196 #undef WHCLOB_DEBUG 1202 #undef WHCLOB_DEBUG