Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

minor: astyle

  • Loading branch information...
commit 70bc545d62b2d07ae7070b0a6f0442703639b8a0 1 parent 720a83e
Kyle Banker banker authored

Showing 35 changed files with 2,677 additions and 2,570 deletions. Show diff stats Hide diff stats

  1. +4 0 .astylerc
  2. +405 323 src/bson.c
  3. +117 117 src/bson.h
  4. +41 29 src/encoding.c
  5. +4 4 src/encoding.h
  6. +582 590 src/gridfs.c
  7. +67 67 src/gridfs.h
  8. +160 166 src/md5.c
  9. +3 3 src/md5.h
  10. +337 345 src/mongo.c
  11. +63 63 src/mongo.h
  12. +15 15 src/net.c
  13. +2 2 src/net.h
  14. +6 6 src/platform.h
  15. +23 23 src/platform/linux/net.c
  16. +2 2 src/platform/linux/net.h
  17. +11 11 test/auth.c
  18. +251 220 test/benchmark.c
  19. +181 181 test/bson.c
  20. +25 25 test/count_delete.c
  21. +2 2 test/cursors.c
  22. +12 12 test/endian_swap.c
  23. +36 36 test/errors.c
  24. +12 12 test/examples.c
  25. +2 2 test/functions.c
  26. +93 93 test/gridfs.c
  27. +4 4 test/helpers.c
  28. +36 37 test/json.c
  29. +1 1  test/oid.c
  30. +21 22 test/replica_set.c
  31. +20 20 test/resize.c
  32. +47 47 test/simple.c
  33. +8 8 test/sizes.c
  34. +63 61 test/update.c
  35. +21 21 test/validate.c
4 .astylerc
... ... @@ -0,0 +1,4 @@
  1 +--style=java
  2 +--pad-paren-in
  3 +--pad-paren-in
  4 +--align-pointer=name
728 src/bson.c
@@ -30,108 +30,125 @@ const int initialBufferSize = 128;
30 30 static const int zero = 0;
31 31
32 32 /* Custom standard function pointers. */
33   -static void *(*malloc_func)( size_t ) = NULL;
34   -static void *(*realloc_func)( void *, size_t ) = NULL;
35   -static void (*free_func)( void * ) = NULL;
36   -static int (*printf_func)( const char *, va_list ) = NULL;
37   -static int (*fprintf_func)( FILE*, const char *, va_list ) = NULL;
38   -static int (*sprintf_func)( char *, const char *, va_list ) = NULL;
39   -static int (*oid_fuzz_func)( void ) = NULL;
40   -static int (*oid_inc_func)( void ) = NULL;
  33 +static void *( *malloc_func )( size_t ) = NULL;
  34 +static void *( *realloc_func )( void *, size_t ) = NULL;
  35 +static void ( *free_func )( void * ) = NULL;
  36 +static int ( *printf_func )( const char *, va_list ) = NULL;
  37 +static int ( *fprintf_func )( FILE *, const char *, va_list ) = NULL;
  38 +static int ( *sprintf_func )( char *, const char *, va_list ) = NULL;
  39 +static int ( *oid_fuzz_func )( void ) = NULL;
  40 +static int ( *oid_inc_func )( void ) = NULL;
41 41
42 42 /* ----------------------------
43 43 READING
44 44 ------------------------------ */
45 45
46   -bson *bson_empty(bson * obj){
47   - static char * data = "\005\0\0\0\0";
48   - bson_init_data(obj, data);
  46 +bson *bson_empty( bson *obj ) {
  47 + static char *data = "\005\0\0\0\0";
  48 + bson_init_data( obj, data );
49 49 return obj;
50 50 }
51 51
52 52 void bson_copy_basic( bson *out, const bson *in ) {
53   - if (!out) return;
  53 + if ( !out ) return;
54 54 bson_init_size( out, bson_size( in ) );
55   - memcpy(out->data, in->data, bson_size(in));
  55 + memcpy( out->data, in->data, bson_size( in ) );
56 56 }
57 57
58   -void bson_copy(bson* out, const bson* in) {
  58 +void bson_copy( bson *out, const bson *in ) {
59 59 int i;
60 60
61   - if (!out) return;
  61 + if ( !out ) return;
62 62 bson_copy_basic( out, in );
63 63 out->cur = in->cur;
64 64 out->dataSize = in->dataSize;
65 65 out->finished = in->finished;
66 66 out->stackPos = in->stackPos;
67   - for(i=0; i<out->stackPos; i++)
68   - out->stack[i] = in->stack[i];
  67 + for( i=0; i<out->stackPos; i++ )
  68 + out->stack[i] = in->stack[i];
69 69 out->err = in->err;
70 70 }
71 71
72   -int bson_init_data( bson * b, char * data ){
  72 +int bson_init_data( bson *b, char *data ) {
73 73 b->data = data;
74 74 return BSON_OK;
75 75 }
76 76
77   -int bson_size(const bson * b ){
  77 +int bson_size( const bson *b ) {
78 78 int i;
79 79 if ( ! b || ! b->data )
80 80 return 0;
81   - bson_little_endian32(&i, b->data);
  81 + bson_little_endian32( &i, b->data );
82 82 return i;
83 83 }
84 84
85   -static char hexbyte(char hex){
86   - switch (hex){
87   - case '0': return 0x0;
88   - case '1': return 0x1;
89   - case '2': return 0x2;
90   - case '3': return 0x3;
91   - case '4': return 0x4;
92   - case '5': return 0x5;
93   - case '6': return 0x6;
94   - case '7': return 0x7;
95   - case '8': return 0x8;
96   - case '9': return 0x9;
97   - case 'a':
98   - case 'A': return 0xa;
99   - case 'b':
100   - case 'B': return 0xb;
101   - case 'c':
102   - case 'C': return 0xc;
103   - case 'd':
104   - case 'D': return 0xd;
105   - case 'e':
106   - case 'E': return 0xe;
107   - case 'f':
108   - case 'F': return 0xf;
109   - default: return 0x0; /* something smarter? */
  85 +static char hexbyte( char hex ) {
  86 + switch ( hex ) {
  87 + case '0':
  88 + return 0x0;
  89 + case '1':
  90 + return 0x1;
  91 + case '2':
  92 + return 0x2;
  93 + case '3':
  94 + return 0x3;
  95 + case '4':
  96 + return 0x4;
  97 + case '5':
  98 + return 0x5;
  99 + case '6':
  100 + return 0x6;
  101 + case '7':
  102 + return 0x7;
  103 + case '8':
  104 + return 0x8;
  105 + case '9':
  106 + return 0x9;
  107 + case 'a':
  108 + case 'A':
  109 + return 0xa;
  110 + case 'b':
  111 + case 'B':
  112 + return 0xb;
  113 + case 'c':
  114 + case 'C':
  115 + return 0xc;
  116 + case 'd':
  117 + case 'D':
  118 + return 0xd;
  119 + case 'e':
  120 + case 'E':
  121 + return 0xe;
  122 + case 'f':
  123 + case 'F':
  124 + return 0xf;
  125 + default:
  126 + return 0x0; /* something smarter? */
110 127 }
111 128 }
112 129
113   -void bson_oid_from_string(bson_oid_t* oid, const char* str){
  130 +void bson_oid_from_string( bson_oid_t *oid, const char *str ) {
114 131 int i;
115   - for (i=0; i<12; i++){
116   - oid->bytes[i] = (hexbyte(str[2*i]) << 4) | hexbyte(str[2*i + 1]);
  132 + for ( i=0; i<12; i++ ) {
  133 + oid->bytes[i] = ( hexbyte( str[2*i] ) << 4 ) | hexbyte( str[2*i + 1] );
117 134 }
118 135 }
119 136
120   -void bson_oid_to_string(const bson_oid_t* oid, char* str){
  137 +void bson_oid_to_string( const bson_oid_t *oid, char *str ) {
121 138 static const char hex[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
122 139 int i;
123   - for (i=0; i<12; i++){
124   - str[2*i] = hex[(oid->bytes[i] & 0xf0) >> 4];
  140 + for ( i=0; i<12; i++ ) {
  141 + str[2*i] = hex[( oid->bytes[i] & 0xf0 ) >> 4];
125 142 str[2*i + 1] = hex[ oid->bytes[i] & 0x0f ];
126 143 }
127 144 str[24] = '\0';
128 145 }
129 146
130   -void bson_set_oid_fuzz( int (*func)(void) ) {
  147 +void bson_set_oid_fuzz( int ( *func )( void ) ) {
131 148 oid_fuzz_func = func;
132 149 }
133 150
134   -void bson_set_oid_inc( int (*func)(void) ) {
  151 +void bson_set_oid_inc( int ( *func )( void ) ) {
135 152 oid_inc_func = func;
136 153 }
137 154
@@ -139,47 +156,47 @@ void bson_oid_gen( bson_oid_t *oid ) {
139 156 static int incr = 0;
140 157 static int fuzz = 0;
141 158 int i;
142   - int t = time(NULL);
  159 + int t = time( NULL );
143 160
144 161 if( oid_inc_func )
145 162 i = oid_inc_func();
146 163 else
147 164 i = incr++;
148 165
149   - if (!fuzz) {
  166 + if ( !fuzz ) {
150 167 if ( oid_fuzz_func )
151 168 fuzz = oid_fuzz_func();
152 169 else {
153   - srand(t);
  170 + srand( t );
154 171 fuzz = rand();
155 172 }
156 173 }
157 174
158   - bson_big_endian32(&oid->ints[0], &t);
  175 + bson_big_endian32( &oid->ints[0], &t );
159 176 oid->ints[1] = fuzz;
160   - bson_big_endian32(&oid->ints[2], &i);
  177 + bson_big_endian32( &oid->ints[2], &i );
161 178 }
162 179
163   -time_t bson_oid_generated_time(bson_oid_t* oid){
  180 +time_t bson_oid_generated_time( bson_oid_t *oid ) {
164 181 time_t out;
165   - bson_big_endian32(&out, &oid->ints[0]);
  182 + bson_big_endian32( &out, &oid->ints[0] );
166 183 return out;
167 184
168 185 }
169   -void bson_print( bson * b ){
  186 +void bson_print( bson *b ) {
170 187 bson_print_raw( b->data , 0 );
171 188 }
172 189
173   -void bson_print_raw( const char * data , int depth ){
  190 +void bson_print_raw( const char *data , int depth ) {
174 191 bson_iterator i;
175   - const char * key;
  192 + const char *key;
176 193 int temp;
177 194 bson_timestamp_t ts;
178 195 char oidhex[25];
179 196 bson scope;
180 197 bson_iterator_init( &i , data );
181 198
182   - while ( bson_iterator_next( &i ) ){
  199 + while ( bson_iterator_next( &i ) ) {
183 200 bson_type t = bson_iterator_type( &i );
184 201 if ( t == 0 )
185 202 break;
@@ -188,30 +205,57 @@ void bson_print_raw( const char * data , int depth ){
188 205 for ( temp=0; temp<=depth; temp++ )
189 206 printf( "\t" );
190 207 bson_printf( "%s : %d \t " , key , t );
191   - switch ( t ){
192   - case BSON_DOUBLE: printf( "%f" , bson_iterator_double( &i ) ); break;
193   - case BSON_STRING: printf( "%s" , bson_iterator_string( &i ) ); break;
194   - case BSON_SYMBOL: printf( "SYMBOL: %s" , bson_iterator_string( &i ) ); break;
195   - case BSON_OID: bson_oid_to_string(bson_iterator_oid(&i), oidhex); printf( "%s" , oidhex ); break;
196   - case BSON_BOOL: printf( "%s" , bson_iterator_bool( &i ) ? "true" : "false" ); break;
197   - case BSON_DATE: printf( "%ld" , (long int)bson_iterator_date( &i ) ); break;
198   - case BSON_BINDATA: printf( "BSON_BINDATA" ); break;
199   - case BSON_UNDEFINED: printf( "BSON_UNDEFINED" ); break;
200   - case BSON_NULL: printf( "BSON_NULL" ); break;
201   - case BSON_REGEX: printf( "BSON_REGEX: %s", bson_iterator_regex( &i ) ); break;
202   - case BSON_CODE: printf( "BSON_CODE: %s", bson_iterator_code( &i ) ); break;
  208 + switch ( t ) {
  209 + case BSON_DOUBLE:
  210 + printf( "%f" , bson_iterator_double( &i ) );
  211 + break;
  212 + case BSON_STRING:
  213 + printf( "%s" , bson_iterator_string( &i ) );
  214 + break;
  215 + case BSON_SYMBOL:
  216 + printf( "SYMBOL: %s" , bson_iterator_string( &i ) );
  217 + break;
  218 + case BSON_OID:
  219 + bson_oid_to_string( bson_iterator_oid( &i ), oidhex );
  220 + printf( "%s" , oidhex );
  221 + break;
  222 + case BSON_BOOL:
  223 + printf( "%s" , bson_iterator_bool( &i ) ? "true" : "false" );
  224 + break;
  225 + case BSON_DATE:
  226 + printf( "%ld" , ( long int )bson_iterator_date( &i ) );
  227 + break;
  228 + case BSON_BINDATA:
  229 + printf( "BSON_BINDATA" );
  230 + break;
  231 + case BSON_UNDEFINED:
  232 + printf( "BSON_UNDEFINED" );
  233 + break;
  234 + case BSON_NULL:
  235 + printf( "BSON_NULL" );
  236 + break;
  237 + case BSON_REGEX:
  238 + printf( "BSON_REGEX: %s", bson_iterator_regex( &i ) );
  239 + break;
  240 + case BSON_CODE:
  241 + printf( "BSON_CODE: %s", bson_iterator_code( &i ) );
  242 + break;
203 243 case BSON_CODEWSCOPE:
204 244 printf( "BSON_CODE_W_SCOPE: %s", bson_iterator_code( &i ) );
205 245 bson_init( &scope );
206 246 bson_iterator_code_scope( &i, &scope );
207   - printf("\n\t SCOPE: ");
  247 + printf( "\n\t SCOPE: " );
208 248 bson_print( &scope );
209 249 break;
210   - case BSON_INT: printf( "%d" , bson_iterator_int( &i ) ); break;
211   - case BSON_LONG: printf( "%ld" , bson_iterator_long( &i ) ); break;
  250 + case BSON_INT:
  251 + printf( "%d" , bson_iterator_int( &i ) );
  252 + break;
  253 + case BSON_LONG:
  254 + printf( "%ld" , bson_iterator_long( &i ) );
  255 + break;
212 256 case BSON_TIMESTAMP:
213 257 ts = bson_iterator_timestamp( &i );
214   - printf("i: %d, t: %d", ts.i, ts.t);
  258 + printf( "i: %d, t: %d", ts.i, ts.t );
215 259 break;
216 260 case BSON_OBJECT:
217 261 case BSON_ARRAY:
@@ -229,221 +273,259 @@ void bson_print_raw( const char * data , int depth ){
229 273 ITERATOR
230 274 ------------------------------ */
231 275
232   -void bson_iterator_init( bson_iterator * i , const char * bson ){
  276 +void bson_iterator_init( bson_iterator *i , const char *bson ) {
233 277 i->cur = bson + 4;
234 278 i->first = 1;
235 279 }
236 280
237   -bson_type bson_find(bson_iterator* it, const bson* obj, const char* name){
238   - bson_iterator_init(it, obj->data);
239   - while(bson_iterator_next(it)){
240   - if (strcmp(name, bson_iterator_key(it)) == 0)
  281 +bson_type bson_find( bson_iterator *it, const bson *obj, const char *name ) {
  282 + bson_iterator_init( it, obj->data );
  283 + while( bson_iterator_next( it ) ) {
  284 + if ( strcmp( name, bson_iterator_key( it ) ) == 0 )
241 285 break;
242 286 }
243   - return bson_iterator_type(it);
  287 + return bson_iterator_type( it );
244 288 }
245 289
246   -bson_bool_t bson_iterator_more( const bson_iterator * i ){
247   - return *(i->cur);
  290 +bson_bool_t bson_iterator_more( const bson_iterator *i ) {
  291 + return *( i->cur );
248 292 }
249 293
250   -bson_type bson_iterator_next( bson_iterator * i ){
  294 +bson_type bson_iterator_next( bson_iterator *i ) {
251 295 int ds;
252 296
253   - if ( i->first ){
  297 + if ( i->first ) {
254 298 i->first = 0;
255   - return (bson_type)(*i->cur);
  299 + return ( bson_type )( *i->cur );
256 300 }
257 301
258   - switch ( bson_iterator_type(i) ){
259   - case BSON_EOO: return BSON_EOO; /* don't advance */
  302 + switch ( bson_iterator_type( i ) ) {
  303 + case BSON_EOO:
  304 + return BSON_EOO; /* don't advance */
260 305 case BSON_UNDEFINED:
261   - case BSON_NULL: ds = 0; break;
262   - case BSON_BOOL: ds = 1; break;
263   - case BSON_INT: ds = 4; break;
  306 + case BSON_NULL:
  307 + ds = 0;
  308 + break;
  309 + case BSON_BOOL:
  310 + ds = 1;
  311 + break;
  312 + case BSON_INT:
  313 + ds = 4;
  314 + break;
264 315 case BSON_LONG:
265 316 case BSON_DOUBLE:
266 317 case BSON_TIMESTAMP:
267   - case BSON_DATE: ds = 8; break;
268   - case BSON_OID: ds = 12; break;
  318 + case BSON_DATE:
  319 + ds = 8;
  320 + break;
  321 + case BSON_OID:
  322 + ds = 12;
  323 + break;
269 324 case BSON_STRING:
270 325 case BSON_SYMBOL:
271   - case BSON_CODE: ds = 4 + bson_iterator_int_raw(i); break;
272   - case BSON_BINDATA: ds = 5 + bson_iterator_int_raw(i); break;
  326 + case BSON_CODE:
  327 + ds = 4 + bson_iterator_int_raw( i );
  328 + break;
  329 + case BSON_BINDATA:
  330 + ds = 5 + bson_iterator_int_raw( i );
  331 + break;
273 332 case BSON_OBJECT:
274 333 case BSON_ARRAY:
275   - case BSON_CODEWSCOPE: ds = bson_iterator_int_raw(i); break;
276   - case BSON_DBREF: ds = 4+12 + bson_iterator_int_raw(i); break;
277   - case BSON_REGEX:
278   - {
279   - const char * s = bson_iterator_value(i);
280   - const char * p = s;
281   - p += strlen(p)+1;
282   - p += strlen(p)+1;
283   - ds = p-s;
284   - break;
285   - }
  334 + case BSON_CODEWSCOPE:
  335 + ds = bson_iterator_int_raw( i );
  336 + break;
  337 + case BSON_DBREF:
  338 + ds = 4+12 + bson_iterator_int_raw( i );
  339 + break;
  340 + case BSON_REGEX: {
  341 + const char *s = bson_iterator_value( i );
  342 + const char *p = s;
  343 + p += strlen( p )+1;
  344 + p += strlen( p )+1;
  345 + ds = p-s;
  346 + break;
  347 + }
286 348
287   - default:
288   - {
289   - char msg[] = "unknown type: 000000000000";
290   - bson_numstr(msg+14, (unsigned)(i->cur[0]));
291   - bson_fatal_msg(0, msg);
292   - return 0;
293   - }
  349 + default: {
  350 + char msg[] = "unknown type: 000000000000";
  351 + bson_numstr( msg+14, ( unsigned )( i->cur[0] ) );
  352 + bson_fatal_msg( 0, msg );
  353 + return 0;
294 354 }
295   -
  355 + }
  356 +
296 357 i->cur += 1 + strlen( i->cur + 1 ) + 1 + ds;
297 358
298   - return (bson_type)(*i->cur);
  359 + return ( bson_type )( *i->cur );
299 360 }
300 361
301   -bson_type bson_iterator_type( const bson_iterator * i ){
302   - return (bson_type)i->cur[0];
  362 +bson_type bson_iterator_type( const bson_iterator *i ) {
  363 + return ( bson_type )i->cur[0];
303 364 }
304   -const char * bson_iterator_key( const bson_iterator * i ){
  365 +const char *bson_iterator_key( const bson_iterator *i ) {
305 366 return i->cur + 1;
306 367 }
307   -const char * bson_iterator_value( const bson_iterator * i ){
308   - const char * t = i->cur + 1;
  368 +const char *bson_iterator_value( const bson_iterator *i ) {
  369 + const char *t = i->cur + 1;
309 370 t += strlen( t ) + 1;
310 371 return t;
311 372 }
312 373
313 374 /* types */
314 375
315   -int bson_iterator_int_raw( const bson_iterator * i ){
  376 +int bson_iterator_int_raw( const bson_iterator *i ) {
316 377 int out;
317   - bson_little_endian32(&out, bson_iterator_value( i ));
  378 + bson_little_endian32( &out, bson_iterator_value( i ) );
318 379 return out;
319 380 }
320   -double bson_iterator_double_raw( const bson_iterator * i ){
  381 +double bson_iterator_double_raw( const bson_iterator *i ) {
321 382 double out;
322   - bson_little_endian64(&out, bson_iterator_value( i ));
  383 + bson_little_endian64( &out, bson_iterator_value( i ) );
323 384 return out;
324 385 }
325   -int64_t bson_iterator_long_raw( const bson_iterator * i ){
  386 +int64_t bson_iterator_long_raw( const bson_iterator *i ) {
326 387 int64_t out;
327   - bson_little_endian64(&out, bson_iterator_value( i ));
  388 + bson_little_endian64( &out, bson_iterator_value( i ) );
328 389 return out;
329 390 }
330 391
331   -bson_bool_t bson_iterator_bool_raw( const bson_iterator * i ){
  392 +bson_bool_t bson_iterator_bool_raw( const bson_iterator *i ) {
332 393 return bson_iterator_value( i )[0];
333 394 }
334 395
335   -bson_oid_t * bson_iterator_oid( const bson_iterator * i ){
336   - return (bson_oid_t*)bson_iterator_value(i);
  396 +bson_oid_t *bson_iterator_oid( const bson_iterator *i ) {
  397 + return ( bson_oid_t * )bson_iterator_value( i );
337 398 }
338 399
339   -int bson_iterator_int( const bson_iterator * i ){
340   - switch (bson_iterator_type(i)){
341   - case BSON_INT: return bson_iterator_int_raw(i);
342   - case BSON_LONG: return bson_iterator_long_raw(i);
343   - case BSON_DOUBLE: return bson_iterator_double_raw(i);
344   - default: return 0;
  400 +int bson_iterator_int( const bson_iterator *i ) {
  401 + switch ( bson_iterator_type( i ) ) {
  402 + case BSON_INT:
  403 + return bson_iterator_int_raw( i );
  404 + case BSON_LONG:
  405 + return bson_iterator_long_raw( i );
  406 + case BSON_DOUBLE:
  407 + return bson_iterator_double_raw( i );
  408 + default:
  409 + return 0;
345 410 }
346 411 }
347   -double bson_iterator_double( const bson_iterator * i ){
348   - switch (bson_iterator_type(i)){
349   - case BSON_INT: return bson_iterator_int_raw(i);
350   - case BSON_LONG: return bson_iterator_long_raw(i);
351   - case BSON_DOUBLE: return bson_iterator_double_raw(i);
352   - default: return 0;
  412 +double bson_iterator_double( const bson_iterator *i ) {
  413 + switch ( bson_iterator_type( i ) ) {
  414 + case BSON_INT:
  415 + return bson_iterator_int_raw( i );
  416 + case BSON_LONG:
  417 + return bson_iterator_long_raw( i );
  418 + case BSON_DOUBLE:
  419 + return bson_iterator_double_raw( i );
  420 + default:
  421 + return 0;
353 422 }
354 423 }
355   -int64_t bson_iterator_long( const bson_iterator * i ){
356   - switch (bson_iterator_type(i)){
357   - case BSON_INT: return bson_iterator_int_raw(i);
358   - case BSON_LONG: return bson_iterator_long_raw(i);
359   - case BSON_DOUBLE: return bson_iterator_double_raw(i);
360   - default: return 0;
  424 +int64_t bson_iterator_long( const bson_iterator *i ) {
  425 + switch ( bson_iterator_type( i ) ) {
  426 + case BSON_INT:
  427 + return bson_iterator_int_raw( i );
  428 + case BSON_LONG:
  429 + return bson_iterator_long_raw( i );
  430 + case BSON_DOUBLE:
  431 + return bson_iterator_double_raw( i );
  432 + default:
  433 + return 0;
361 434 }
362 435 }
363 436
364   -bson_timestamp_t bson_iterator_timestamp( const bson_iterator * i){
  437 +bson_timestamp_t bson_iterator_timestamp( const bson_iterator *i ) {
365 438 bson_timestamp_t ts;
366   - bson_little_endian32(&(ts.i), bson_iterator_value(i));
367   - bson_little_endian32(&(ts.t), bson_iterator_value(i) + 4);
  439 + bson_little_endian32( &( ts.i ), bson_iterator_value( i ) );
  440 + bson_little_endian32( &( ts.t ), bson_iterator_value( i ) + 4 );
368 441 return ts;
369 442 }
370 443
371   -bson_bool_t bson_iterator_bool( const bson_iterator * i ){
372   - switch (bson_iterator_type(i)){
373   - case BSON_BOOL: return bson_iterator_bool_raw(i);
374   - case BSON_INT: return bson_iterator_int_raw(i) != 0;
375   - case BSON_LONG: return bson_iterator_long_raw(i) != 0;
376   - case BSON_DOUBLE: return bson_iterator_double_raw(i) != 0;
377   - case BSON_EOO:
378   - case BSON_NULL: return 0;
379   - default: return 1;
  444 +bson_bool_t bson_iterator_bool( const bson_iterator *i ) {
  445 + switch ( bson_iterator_type( i ) ) {
  446 + case BSON_BOOL:
  447 + return bson_iterator_bool_raw( i );
  448 + case BSON_INT:
  449 + return bson_iterator_int_raw( i ) != 0;
  450 + case BSON_LONG:
  451 + return bson_iterator_long_raw( i ) != 0;
  452 + case BSON_DOUBLE:
  453 + return bson_iterator_double_raw( i ) != 0;
  454 + case BSON_EOO:
  455 + case BSON_NULL:
  456 + return 0;
  457 + default:
  458 + return 1;
380 459 }
381 460 }
382 461
383   -const char * bson_iterator_string( const bson_iterator * i ){
  462 +const char *bson_iterator_string( const bson_iterator *i ) {
384 463 return bson_iterator_value( i ) + 4;
385 464 }
386   -int bson_iterator_string_len( const bson_iterator * i ){
  465 +int bson_iterator_string_len( const bson_iterator *i ) {
387 466 return bson_iterator_int_raw( i );
388 467 }
389 468
390   -const char * bson_iterator_code( const bson_iterator * i ){
391   - switch (bson_iterator_type(i)){
392   - case BSON_STRING:
393   - case BSON_CODE: return bson_iterator_value(i) + 4;
394   - case BSON_CODEWSCOPE: return bson_iterator_value(i) + 8;
395   - default: return NULL;
  469 +const char *bson_iterator_code( const bson_iterator *i ) {
  470 + switch ( bson_iterator_type( i ) ) {
  471 + case BSON_STRING:
  472 + case BSON_CODE:
  473 + return bson_iterator_value( i ) + 4;
  474 + case BSON_CODEWSCOPE:
  475 + return bson_iterator_value( i ) + 8;
  476 + default:
  477 + return NULL;
396 478 }
397 479 }
398 480
399   -void bson_iterator_code_scope(const bson_iterator * i, bson * scope){
400   - if (bson_iterator_type(i) == BSON_CODEWSCOPE){
  481 +void bson_iterator_code_scope( const bson_iterator *i, bson *scope ) {
  482 + if ( bson_iterator_type( i ) == BSON_CODEWSCOPE ) {
401 483 int code_len;
402   - bson_little_endian32(&code_len, bson_iterator_value(i)+4);
403   - bson_init_data(scope, (void*)(bson_iterator_value(i)+8+code_len));
404   - }else{
405   - bson_empty(scope);
  484 + bson_little_endian32( &code_len, bson_iterator_value( i )+4 );
  485 + bson_init_data( scope, ( void * )( bson_iterator_value( i )+8+code_len ) );
  486 + } else {
  487 + bson_empty( scope );
406 488 }
407 489 }
408 490
409   -bson_date_t bson_iterator_date(const bson_iterator * i){
410   - return bson_iterator_long_raw(i);
  491 +bson_date_t bson_iterator_date( const bson_iterator *i ) {
  492 + return bson_iterator_long_raw( i );
411 493 }
412 494
413   -time_t bson_iterator_time_t(const bson_iterator * i){
414   - return bson_iterator_date(i) / 1000;
  495 +time_t bson_iterator_time_t( const bson_iterator *i ) {
  496 + return bson_iterator_date( i ) / 1000;
415 497 }
416 498
417   -int bson_iterator_bin_len( const bson_iterator * i ){
418   - return (bson_iterator_bin_type(i) == BSON_BIN_BINARY_OLD )
419   - ? bson_iterator_int_raw( i ) - 4
420   - : bson_iterator_int_raw( i );
  499 +int bson_iterator_bin_len( const bson_iterator *i ) {
  500 + return ( bson_iterator_bin_type( i ) == BSON_BIN_BINARY_OLD )
  501 + ? bson_iterator_int_raw( i ) - 4
  502 + : bson_iterator_int_raw( i );
421 503 }
422 504
423   -char bson_iterator_bin_type( const bson_iterator * i ){
424   - return bson_iterator_value(i)[4];
  505 +char bson_iterator_bin_type( const bson_iterator *i ) {
  506 + return bson_iterator_value( i )[4];
425 507 }
426 508
427   -const char * bson_iterator_bin_data( const bson_iterator * i ){
428   - return (bson_iterator_bin_type( i ) == BSON_BIN_BINARY_OLD )
429   - ? bson_iterator_value( i ) + 9
430   - : bson_iterator_value( i ) + 5;
  509 +const char *bson_iterator_bin_data( const bson_iterator *i ) {
  510 + return ( bson_iterator_bin_type( i ) == BSON_BIN_BINARY_OLD )
  511 + ? bson_iterator_value( i ) + 9
  512 + : bson_iterator_value( i ) + 5;
431 513 }
432 514
433   -const char * bson_iterator_regex( const bson_iterator * i ){
  515 +const char *bson_iterator_regex( const bson_iterator *i ) {
434 516 return bson_iterator_value( i );
435 517 }
436   -const char * bson_iterator_regex_opts( const bson_iterator * i ){
437   - const char* p = bson_iterator_value( i );
438   - return p + strlen(p) + 1;
  518 +const char *bson_iterator_regex_opts( const bson_iterator *i ) {
  519 + const char *p = bson_iterator_value( i );
  520 + return p + strlen( p ) + 1;
439 521
440 522 }
441 523
442   -void bson_iterator_subobject(const bson_iterator * i, bson * sub){
443   - bson_init_data(sub, (char*)bson_iterator_value(i));
  524 +void bson_iterator_subobject( const bson_iterator *i, bson *sub ) {
  525 + bson_init_data( sub, ( char * )bson_iterator_value( i ) );
444 526 }
445   -void bson_iterator_subiterator(const bson_iterator * i, bson_iterator * sub){
446   - bson_iterator_init(sub, bson_iterator_value(i));
  527 +void bson_iterator_subiterator( const bson_iterator *i, bson_iterator *sub ) {
  528 + bson_iterator_init( sub, bson_iterator_value( i ) );
447 529 }
448 530
449 531 /* ----------------------------
@@ -454,7 +536,7 @@ static void _bson_init_size( bson *b, int size ) {
454 536 if( size == 0 )
455 537 b->data = NULL;
456 538 else
457   - b->data = (char*)bson_malloc( size );
  539 + b->data = ( char * )bson_malloc( size );
458 540 b->dataSize = size;
459 541 b->cur = b->data + 4;
460 542 b->finished = 0;
@@ -471,40 +553,40 @@ void bson_init_size( bson *b, int size ) {
471 553 _bson_init_size( b, size );
472 554 }
473 555
474   -void bson_append_byte( bson * b, char c ){
  556 +void bson_append_byte( bson *b, char c ) {
475 557 b->cur[0] = c;
476 558 b->cur++;
477 559 }
478 560
479   -void bson_append( bson * b, const void * data, int len ){
  561 +void bson_append( bson *b, const void *data, int len ) {
480 562 memcpy( b->cur , data , len );
481 563 b->cur += len;
482 564 }
483 565
484   -void bson_append32(bson * b, const void * data){
485   - bson_little_endian32(b->cur, data);
  566 +void bson_append32( bson *b, const void *data ) {
  567 + bson_little_endian32( b->cur, data );
486 568 b->cur += 4;
487 569 }
488 570
489   -void bson_append64(bson * b, const void * data){
490   - bson_little_endian64(b->cur, data);
  571 +void bson_append64( bson *b, const void *data ) {
  572 + bson_little_endian64( b->cur, data );
491 573 b->cur += 8;
492 574 }
493 575
494   -int bson_ensure_space( bson * b, const int bytesNeeded ){
  576 +int bson_ensure_space( bson *b, const int bytesNeeded ) {
495 577 int pos = b->cur - b->data;
496   - char * orig = b->data;
  578 + char *orig = b->data;
497 579 int new_size;
498 580
499   - if (b->finished) {
  581 + if ( b->finished ) {
500 582 b->err = BSON_OBJECT_FINISHED;
501 583 return BSON_ERROR;
502 584 }
503 585
504   - if (pos + bytesNeeded <= b->dataSize)
  586 + if ( pos + bytesNeeded <= b->dataSize )
505 587 return BSON_OK;
506 588
507   - new_size = 1.5 * (b->dataSize + bytesNeeded);
  589 + new_size = 1.5 * ( b->dataSize + bytesNeeded );
508 590
509 591 if( new_size < b->dataSize ) {
510 592 if( ( b->dataSize + bytesNeeded ) < INT_MAX )
@@ -515,9 +597,9 @@ int bson_ensure_space( bson * b, const int bytesNeeded ){
515 597 }
516 598 }
517 599
518   - b->data = realloc(b->data, new_size);
519   - if (!b->data)
520   - bson_fatal_msg(!!b->data, "realloc() failed");
  600 + b->data = realloc( b->data, new_size );
  601 + if ( !b->data )
  602 + bson_fatal_msg( !!b->data, "realloc() failed" );
521 603
522 604 b->dataSize = new_size;
523 605 b->cur += b->data - orig;
@@ -532,20 +614,20 @@ int bson_ensure_space( bson * b, const int bytesNeeded ){
532 614 * This buffer is then deallocated by calling
533 615 * bson_destroy().
534 616 */
535   -int bson_finish( bson * b ){
  617 +int bson_finish( bson *b ) {
536 618 int i;
537   - if ( ! b->finished ){
  619 + if ( ! b->finished ) {
538 620 if ( bson_ensure_space( b, 1 ) == BSON_ERROR ) return BSON_ERROR;
539 621 bson_append_byte( b, 0 );
540 622 i = b->cur - b->data;
541   - bson_little_endian32(b->data, &i);
  623 + bson_little_endian32( b->data, &i );
542 624 b->finished = 1;
543 625 }
544 626
545 627 return BSON_OK;
546 628 }
547 629
548   -void bson_destroy( bson * b ){
  630 +void bson_destroy( bson *b ) {
549 631 bson_free( b->data );
550 632 b->err = 0;
551 633 b->data = 0;
@@ -553,18 +635,18 @@ void bson_destroy( bson * b ){
553 635 b->finished = 1;
554 636 }
555 637
556   -static int bson_append_estart( bson * b, int type, const char * name, const int dataSize ){
557   - const int len = strlen(name) + 1;
  638 +static int bson_append_estart( bson *b, int type, const char *name, const int dataSize ) {
  639 + const int len = strlen( name ) + 1;
558 640 if ( bson_ensure_space( b, 1 + len + dataSize ) == BSON_ERROR ) {
559 641 return BSON_ERROR;
560 642 }
561 643
562   - if( bson_check_field_name( b, (const char* )name, len - 1 ) == BSON_ERROR ) {
  644 + if( bson_check_field_name( b, ( const char * )name, len - 1 ) == BSON_ERROR ) {
563 645 bson_builder_error( b );
564 646 return BSON_ERROR;
565 647 }
566 648
567   - bson_append_byte( b, (char)type );
  649 + bson_append_byte( b, ( char )type );
568 650 bson_append( b, name, len );
569 651 return BSON_OK;
570 652 }
@@ -573,138 +655,138 @@ static int bson_append_estart( bson * b, int type, const char * name, const int
573 655 BUILDING TYPES
574 656 ------------------------------ */
575 657
576   -int bson_append_int( bson * b, const char * name, const int i ) {
  658 +int bson_append_int( bson *b, const char *name, const int i ) {
577 659 if ( bson_append_estart( b, BSON_INT, name, 4 ) == BSON_ERROR )
578 660 return BSON_ERROR;
579 661 bson_append32( b , &i );
580 662 return BSON_OK;
581 663 }
582 664
583   -int bson_append_long( bson * b, const char * name, const int64_t i ) {
  665 +int bson_append_long( bson *b, const char *name, const int64_t i ) {
584 666 if ( bson_append_estart( b , BSON_LONG, name, 8 ) == BSON_ERROR )
585 667 return BSON_ERROR;
586 668 bson_append64( b , &i );
587 669 return BSON_OK;
588 670 }
589 671
590   -int bson_append_double( bson * b, const char * name, const double d ) {
  672 +int bson_append_double( bson *b, const char *name, const double d ) {
591 673 if ( bson_append_estart( b, BSON_DOUBLE, name, 8 ) == BSON_ERROR )
592 674 return BSON_ERROR;
593 675 bson_append64( b , &d );
594 676 return BSON_OK;
595 677 }
596 678
597   -int bson_append_bool( bson * b, const char * name, const bson_bool_t i ) {
  679 +int bson_append_bool( bson *b, const char *name, const bson_bool_t i ) {
598 680 if ( bson_append_estart( b, BSON_BOOL, name, 1 ) == BSON_ERROR )
599 681 return BSON_ERROR;
600 682 bson_append_byte( b , i != 0 );
601 683 return BSON_OK;
602 684 }
603 685
604   -int bson_append_null( bson * b, const char * name ) {
  686 +int bson_append_null( bson *b, const char *name ) {
605 687 if ( bson_append_estart( b , BSON_NULL, name, 0 ) == BSON_ERROR )
606 688 return BSON_ERROR;
607 689 return BSON_OK;
608 690 }
609 691
610   -int bson_append_undefined( bson * b, const char * name ) {
  692 +int bson_append_undefined( bson *b, const char *name ) {
611 693 if ( bson_append_estart( b, BSON_UNDEFINED, name, 0 ) == BSON_ERROR )
612 694 return BSON_ERROR;
613 695 return BSON_OK;
614 696 }
615 697
616   -int bson_append_string_base( bson * b, const char * name,
617   - const char * value, int len, bson_type type) {
  698 +int bson_append_string_base( bson *b, const char *name,
  699 + const char *value, int len, bson_type type ) {
618 700
619 701 int sl = len + 1;
620   - if ( bson_check_string( b, (const char *)value, sl - 1 ) == BSON_ERROR )
  702 + if ( bson_check_string( b, ( const char * )value, sl - 1 ) == BSON_ERROR )
621 703 return BSON_ERROR;
622 704 if ( bson_append_estart( b, type, name, 4 + sl ) == BSON_ERROR ) {
623 705 return BSON_ERROR;
624 706 }
625   - bson_append32( b , &sl);
  707 + bson_append32( b , &sl );
626 708 bson_append( b , value , sl - 1 );
627 709 bson_append( b , "\0" , 1 );
628 710 return BSON_OK;
629 711 }
630 712
631   -int bson_append_string( bson * b, const char * name, const char * value ) {
632   - return bson_append_string_base(b, name, value, strlen ( value ), BSON_STRING);
  713 +int bson_append_string( bson *b, const char *name, const char *value ) {
  714 + return bson_append_string_base( b, name, value, strlen ( value ), BSON_STRING );
633 715 }
634 716
635   -int bson_append_symbol( bson * b, const char * name, const char * value ) {
636   - return bson_append_string_base(b, name, value, strlen ( value ), BSON_SYMBOL);
  717 +int bson_append_symbol( bson *b, const char *name, const char *value ) {
  718 + return bson_append_string_base( b, name, value, strlen ( value ), BSON_SYMBOL );
637 719 }
638 720
639   -int bson_append_code( bson * b, const char * name, const char * value ) {
640   - return bson_append_string_base(b, name, value, strlen ( value ), BSON_CODE);
  721 +int bson_append_code( bson *b, const char *name, const char *value ) {
  722 + return bson_append_string_base( b, name, value, strlen ( value ), BSON_CODE );
641 723 }
642 724
643   -int bson_append_string_n( bson * b, const char * name, const char * value, int len ) {
644   - return bson_append_string_base(b, name, value, len, BSON_STRING);
  725 +int bson_append_string_n( bson *b, const char *name, const char *value, int len ) {
  726 + return bson_append_string_base( b, name, value, len, BSON_STRING );
645 727 }
646 728
647   -int bson_append_symbol_n( bson * b, const char * name, const char * value, int len ) {
648   - return bson_append_string_base(b, name, value, len, BSON_SYMBOL);
  729 +int bson_append_symbol_n( bson *b, const char *name, const char *value, int len ) {
  730 + return bson_append_string_base( b, name, value, len, BSON_SYMBOL );
649 731 }
650 732
651   -int bson_append_code_n( bson * b, const char * name, const char * value, int len ) {
652   - return bson_append_string_base(b, name, value, len, BSON_CODE);
  733 +int bson_append_code_n( bson *b, const char *name, const char *value, int len ) {
  734 + return bson_append_string_base( b, name, value, len, BSON_CODE );
653 735 }
654 736
655   -int bson_append_code_w_scope_n( bson * b, const char * name,
656   - const char * code, int len, const bson * scope) {
  737 +int bson_append_code_w_scope_n( bson *b, const char *name,
  738 + const char *code, int len, const bson *scope ) {
657 739
658 740 int sl = len + 1;
659   - int size = 4 + 4 + sl + bson_size(scope);
660   - if ( bson_append_estart(b, BSON_CODEWSCOPE, name, size) == BSON_ERROR )
  741 + int size = 4 + 4 + sl + bson_size( scope );
  742 + if ( bson_append_estart( b, BSON_CODEWSCOPE, name, size ) == BSON_ERROR )
661 743 return BSON_ERROR;
662   - bson_append32(b, &size);
663   - bson_append32(b, &sl);
664   - bson_append(b, code, sl);
665   - bson_append(b, scope->data, bson_size(scope));
  744 + bson_append32( b, &size );
  745 + bson_append32( b, &sl );
  746 + bson_append( b, code, sl );
  747 + bson_append( b, scope->data, bson_size( scope ) );
666 748 return BSON_OK;
667 749 }
668 750
669   -int bson_append_code_w_scope( bson * b, const char * name, const char * code, const bson * scope){
  751 +int bson_append_code_w_scope( bson *b, const char *name, const char *code, const bson *scope ) {
670 752 return bson_append_code_w_scope_n( b, name, code, strlen ( code ), scope );
671 753 }
672 754
673   -int bson_append_binary( bson * b, const char * name, char type, const char * str, int len ){
674   - if ( type == BSON_BIN_BINARY_OLD ){
  755 +int bson_append_binary( bson *b, const char *name, char type, const char *str, int len ) {
  756 + if ( type == BSON_BIN_BINARY_OLD ) {
675 757 int subtwolen = len + 4;
676 758 if ( bson_append_estart( b, BSON_BINDATA, name, 4+1+4+len ) == BSON_ERROR )
677 759 return BSON_ERROR;
678   - bson_append32(b, &subtwolen);
679   - bson_append_byte(b, type);
680   - bson_append32(b, &len);
681   - bson_append(b, str, len);
  760 + bson_append32( b, &subtwolen );
  761 + bson_append_byte( b, type );
  762 + bson_append32( b, &len );
  763 + bson_append( b, str, len );
682 764 } else {
683 765 if ( bson_append_estart( b, BSON_BINDATA, name, 4+1+len ) == BSON_ERROR )
684 766 return BSON_ERROR;
685   - bson_append32(b, &len);
686   - bson_append_byte(b, type);
687   - bson_append(b, str, len);
  767 + bson_append32( b, &len );
  768 + bson_append_byte( b, type );
  769 + bson_append( b, str, len );
688 770 }
689 771 return BSON_OK;
690 772 }
691 773
692   -int bson_append_oid( bson * b, const char * name, const bson_oid_t * oid ){
  774 +int bson_append_oid( bson *b, const char *name, const bson_oid_t *oid ) {
693 775 if ( bson_append_estart( b, BSON_OID, name, 12 ) == BSON_ERROR )
694 776 return BSON_ERROR;
695 777 bson_append( b , oid , 12 );
696 778 return BSON_OK;
697 779 }
698 780
699   -int bson_append_new_oid( bson * b, const char * name ){
  781 +int bson_append_new_oid( bson *b, const char *name ) {
700 782 bson_oid_t oid;
701   - bson_oid_gen(&oid);
702   - return bson_append_oid(b, name, &oid);
  783 + bson_oid_gen( &oid );
  784 + return bson_append_oid( b, name, &oid );
703 785 }
704 786
705   -int bson_append_regex( bson * b, const char * name, const char * pattern, const char * opts ){
706   - const int plen = strlen(pattern)+1;
707   - const int olen = strlen(opts)+1;
  787 +int bson_append_regex( bson *b, const char *name, const char *pattern, const char *opts ) {
  788 + const int plen = strlen( pattern )+1;
  789 + const int olen = strlen( opts )+1;
708 790 if ( bson_append_estart( b, BSON_REGEX, name, plen + olen ) == BSON_ERROR )
709 791 return BSON_ERROR;
710 792 if ( bson_check_string( b, pattern, plen - 1 ) == BSON_ERROR )
@@ -714,116 +796,116 @@ int bson_append_regex( bson * b, const char * name, const char * pattern, const
714 796 return BSON_OK;
715 797 }
716 798
717   -int bson_append_bson( bson * b, const char * name, const bson* bson){
718   - if ( bson_append_estart( b, BSON_OBJECT, name, bson_size(bson) ) == BSON_ERROR )
  799 +int bson_append_bson( bson *b, const char *name, const bson *bson ) {
  800 + if ( bson_append_estart( b, BSON_OBJECT, name, bson_size( bson ) ) == BSON_ERROR )
719 801 return BSON_ERROR;
720   - bson_append( b , bson->data , bson_size(bson) );
  802 + bson_append( b , bson->data , bson_size( bson ) );
721 803 return BSON_OK;
722 804 }
723 805
724   -int bson_append_element( bson * b, const char * name_or_null, const bson_iterator* elem){
  806 +int bson_append_element( bson *b, const char *name_or_null, const bson_iterator *elem ) {
725 807 bson_iterator next = *elem;
726 808 int size;
727 809
728   - bson_iterator_next(&next);
  810 + bson_iterator_next( &next );
729 811 size = next.cur - elem->cur;
730 812
731   - if (name_or_null == NULL){
732   - if( bson_ensure_space(b, size) == BSON_ERROR )
  813 + if ( name_or_null == NULL ) {
  814 + if( bson_ensure_space( b, size ) == BSON_ERROR )
733 815 return BSON_ERROR;
734   - bson_append(b, elem->cur, size);
735   - }else{
736   - int data_size = size - 2 - strlen(bson_iterator_key(elem));
737   - bson_append_estart(b, elem->cur[0], name_or_null, data_size);
738   - bson_append(b, bson_iterator_value(elem), data_size);
  816 + bson_append( b, elem->cur, size );
  817 + } else {
  818 + int data_size = size - 2 - strlen( bson_iterator_key( elem ) );
  819 + bson_append_estart( b, elem->cur[0], name_or_null, data_size );
  820 + bson_append( b, bson_iterator_value( elem ), data_size );
739 821 }
740 822
741 823 return BSON_OK;
742 824 }
743 825
744   -int bson_append_timestamp( bson * b, const char * name, bson_timestamp_t * ts ){
  826 +int bson_append_timestamp( bson *b, const char *name, bson_timestamp_t *ts ) {
745 827 if ( bson_append_estart( b, BSON_TIMESTAMP, name, 8 ) == BSON_ERROR ) return BSON_ERROR;
746 828
747   - bson_append32( b , &(ts->i) );
748   - bson_append32( b , &(ts->t) );
  829 + bson_append32( b , &( ts->i ) );
  830 + bson_append32( b , &( ts->t ) );
749 831
750 832 return BSON_OK;
751 833 }
752 834
753   -int bson_append_date( bson * b, const char * name, bson_date_t millis ) {
  835 +int bson_append_date( bson *b, const char *name, bson_date_t millis ) {
754 836 if ( bson_append_estart( b, BSON_DATE, name, 8 ) == BSON_ERROR ) return BSON_ERROR;
755 837 bson_append64( b , &millis );
756 838 return BSON_OK;
757 839 }
758 840
759   -int bson_append_time_t( bson * b, const char * name, time_t secs) {
760   - return bson_append_date(b, name, (bson_date_t)secs * 1000);
  841 +int bson_append_time_t( bson *b, const char *name, time_t secs ) {
  842 + return bson_append_date( b, name, ( bson_date_t )secs * 1000 );
761 843 }
762 844
763   -int bson_append_start_object( bson * b, const char * name ) {
  845 +int bson_append_start_object( bson *b, const char *name ) {
764 846 if ( bson_append_estart( b, BSON_OBJECT, name, 5 ) == BSON_ERROR ) return BSON_ERROR;
765 847 b->stack[ b->stackPos++ ] = b->cur - b->data;
766 848 bson_append32( b , &zero );
767 849 return BSON_OK;
768 850 }
769 851
770   -int bson_append_start_array( bson * b, const char * name ) {
  852 +int bson_append_start_array( bson *b, const char *name ) {
771 853 if ( bson_append_estart( b, BSON_ARRAY, name, 5 ) == BSON_ERROR ) return BSON_ERROR;
772 854 b->stack[ b->stackPos++ ] = b->cur - b->data;
773 855 bson_append32( b , &zero );
774 856 return BSON_OK;
775 857 }
776 858
777   -int bson_append_finish_object( bson * b ){
778   - char * start;
  859 +int bson_append_finish_object( bson *b ) {
  860 + char *start;
779 861 int i;
780 862 if ( bson_ensure_space( b, 1 ) == BSON_ERROR ) return BSON_ERROR;
781 863 bson_append_byte( b , 0 );
782 864
783 865 start = b->data + b->stack[ --b->stackPos ];
784 866 i = b->cur - start;
785   - bson_little_endian32(start, &i);
  867 + bson_little_endian32( start, &i );
786 868
787 869 return BSON_OK;
788 870 }
789 871
790 872 static bson_err_handler err_handler = NULL;
791 873
792   -bson_err_handler set_bson_err_handler(bson_err_handler func){
  874 +bson_err_handler set_bson_err_handler( bson_err_handler func ) {
793 875 bson_err_handler old = err_handler;
794 876 err_handler = func;
795 877 return old;
796 878 }
797 879
798   -void bson_set_malloc( void *(*func)( size_t ) ) {
  880 +void bson_set_malloc( void *( *func )( size_t ) ) {
799 881 malloc_func = func;
800 882 }
801 883
802   -void *bson_malloc(int size) {
  884 +void *bson_malloc( int size ) {
803 885 void *p;
804   - if( malloc_func)
805   - p = malloc_func(size);
  886 + if( malloc_func )
  887 + p = malloc_func( size );
806 888 else
807   - p = malloc(size);
808   - bson_fatal_msg(!!p, "malloc() failed");
  889 + p = malloc( size );
  890 + bson_fatal_msg( !!p, "malloc() failed" );
809 891 return p;
810 892 }
811 893
812   -void bson_set_realloc( void *(*func)( void *, size_t ) ) {
  894 +void bson_set_realloc( void *( *func )( void *, size_t ) ) {
813 895 realloc_func = func;
814 896 }
815 897
816   -void* bson_realloc(void* ptr, int size){
  898 +void *bson_realloc( void *ptr, int size ) {
817 899 void *p;
818 900 if( realloc_func )
819   - p = realloc_func(ptr, size);
  901 + p = realloc_func( ptr, size );
820 902 else
821   - p = realloc(ptr, size);
822   - bson_fatal_msg(!!p, "realloc() failed");
  903 + p = realloc( ptr, size );
  904 + bson_fatal_msg( !!p, "realloc() failed" );
823 905 return p;
824 906 }
825 907
826   -void bson_set_free( void (*func)( void * ) ) {
  908 +void bson_set_free( void ( *func )( void * ) ) {
827 909 free_func = func;
828 910 }
829 911
@@ -834,7 +916,7 @@ void bson_free( void *ptr ) {
834 916 free( ptr );
835 917 }
836 918
837   -void bson_set_printf( int (*func)( const char *, va_list ) ) {
  919 +void bson_set_printf( int ( *func )( const char *, va_list ) ) {
838 920 printf_func = func;
839 921 }
840 922
@@ -851,7 +933,7 @@ int bson_printf( const char *format, ... ) {
851 933 return ret;
852 934 }
853 935
854   -void bson_set_fprintf( int (*func)( FILE*, const char *, va_list ) ) {
  936 +void bson_set_fprintf( int ( *func )( FILE *, const char *, va_list ) ) {
855 937 fprintf_func = func;
856 938 }
857 939
@@ -868,11 +950,11 @@ int bson_fprintf( FILE *fp, const char *format, ... ) {
868 950 return ret;
869 951 }
870 952
871   -void bson_set_sprintf( int (*func)( char *, const char *, va_list ) ) {
  953 +void bson_set_sprintf( int ( *func )( char *, const char *, va_list ) ) {
872 954 sprintf_func = func;
873 955 }
874 956
875   -int bson_sprintf( char* s, const char *format, ... ) {
  957 +int bson_sprintf( char *s, const char *format, ... ) {
876 958 va_list ap;
877 959 int ret;
878 960 va_start( ap, format );
@@ -891,32 +973,32 @@ int bson_sprintf( char* s, const char *format, ... ) {
891 973 *
892 974 * @param