Permalink
Browse files

put win32,posix,standard all in env.c, minor fixes, and astyled

  • Loading branch information...
gerald-lindsly committed Dec 22, 2012
1 parent 19d14fd commit 3a849c0c4e42a613f12485a7c5572cea89ab5e19
Showing with 868 additions and 848 deletions.
  1. +3 −5 SConstruct
  2. +56 −56 src/bcon.c
  3. +12 −9 src/bson.c
  4. +11 −11 src/bson.h
  5. +7 −7 src/encoding.c
  6. +554 −0 src/env.c
  7. +0 −200 src/env_posix.c
  8. +0 −168 src/env_standard.c
  9. +0 −178 src/env_win32.c
  10. +19 −14 src/gridfs.c
  11. +6 −6 src/gridfs.h
  12. +92 −95 src/md5.c
  13. +14 −14 src/md5.h
  14. +76 −67 src/mongo.c
  15. +18 −18 src/mongo.h
View
@@ -86,16 +86,14 @@ env.AlwaysBuild("docs")
# ---- Platforms ----
PLATFORM_TESTS = []
+NET_LIB = "src/env.c"
if GetOption('standard_env'):
- NET_LIB = "src/env_standard.c"
+ env.Append( CPPFLAGS=" -D_POSIX_SOURCE" )
elif os.sys.platform in ["darwin", "linux2"]:
- NET_LIB = "src/env_posix.c"
PLATFORM_TESTS = [ "env_posix", "unix_socket" ]
elif 'win32' == os.sys.platform:
- NET_LIB = "src/env_win32.c"
PLATFORM_TESTS = [ "env_win32" ]
-else:
- NET_LIB = "src/env_standard.c"
+
# ---- Libraries ----
if os.sys.platform in ["darwin", "linux2"]:
View
@@ -46,8 +46,8 @@ bcon_token_t bcon_token(char *s) {
if (s == 0) return Token_EOD;
switch (s[0]) {
case ':': if (s[1] != '\0' && s[2] != '\0' && s[3] != '\0' && s[4] == '\0' &&
- s[3] == ':' && (s[1] == '_' || s[1] == 'P' || s[1] == 'R'))
- return Token_Typespec; break;
+ s[3] == ':' && (s[1] == '_' || s[1] == 'P' || s[1] == 'R'))
+ return Token_Typespec; break;
case '{': if (s[1] == '\0') return Token_OpenBrace; break;
case '}': if (s[1] == '\0') return Token_CloseBrace; break;
case '[': if (s[1] == '\0') return Token_OpenBracket; break;
@@ -69,14 +69,14 @@ bcon_error_t bson_bcon_key_value(bson *b, const char *key, const char *typespec,
case 's': bson_append_string( b, key, bci.s ); break; /* common case */
case 'f': bson_append_double( b, key, bci.f ); break;
case 'D':
- bson_append_start_object( b, key );
- ret = bson_append_bcon( b, bci.D );
- bson_append_finish_object( b );
+ bson_append_start_object( b, key );
+ ret = bson_append_bcon( b, bci.D );
+ bson_append_finish_object( b );
break;
case 'A':
- bson_append_start_array( b, key );
- ret = bson_append_bcon_array( b, bci.A );
- bson_append_finish_array( b );
+ bson_append_start_array( b, key );
+ ret = bson_append_bcon_array( b, bci.A );
+ bson_append_finish_array( b );
break;
case 'o': if (*bci.o == '\0') bson_oid_gen( &oid ); else bson_oid_from_string( &oid, bci.o ); bson_append_oid( b, key, &oid ); break;
case 'b': bson_append_bool( b, key, bci.b ); break;
@@ -93,14 +93,14 @@ bcon_error_t bson_bcon_key_value(bson *b, const char *key, const char *typespec,
case 'f': bson_append_double( b, key, *bci.Rf ); break;
case 's': bson_append_string( b, key, bci.Rs ); break;
case 'D':
- bson_append_start_object( b, key );
- ret = bson_append_bcon( b, bci.RD );
- bson_append_finish_object( b );
+ bson_append_start_object( b, key );
+ ret = bson_append_bcon( b, bci.RD );
+ bson_append_finish_object( b );
break;
case 'A':
- bson_append_start_array( b, key );
- ret = bson_append_bcon_array( b, bci.RA );
- bson_append_finish_array( b );
+ bson_append_start_array( b, key );
+ ret = bson_append_bcon_array( b, bci.RA );
+ bson_append_finish_array( b );
break;
case 'o': if (*bci.o == '\0') bson_oid_gen( &oid ); else bson_oid_from_string( &oid, bci.o ); bson_append_oid( b, key, &oid ); break;
case 'b': bson_append_bool( b, key, *bci.Rb ); break;
@@ -117,19 +117,19 @@ bcon_error_t bson_bcon_key_value(bson *b, const char *key, const char *typespec,
case 'f': bson_append_double( b, key, **bci.Pf ); break;
case 's': bson_append_string( b, key, *bci.Ps ); break;
case 'D':
- bson_append_start_object( b, key );
- ret = bson_append_bcon( b, *bci.PD );
- bson_append_finish_object( b );
+ bson_append_start_object( b, key );
+ ret = bson_append_bcon( b, *bci.PD );
+ bson_append_finish_object( b );
break;
case 'A':
- bson_append_start_array( b, key );
- ret = bson_append_bcon_array( b, *bci.PA );
- bson_append_finish_array( b );
+ bson_append_start_array( b, key );
+ ret = bson_append_bcon_array( b, *bci.PA );
+ bson_append_finish_array( b );
break;
case 'o': if (**bci.Po == '\0') bson_oid_gen( &oid );
- else bson_oid_from_string( &oid, *bci.Po );
- bson_append_oid( b, key, &oid );
- break;
+ else bson_oid_from_string( &oid, *bci.Po );
+ bson_append_oid( b, key, &oid );
+ break;
case 'b': bson_append_bool( b, key, **bci.Pb ); break;
case 't': bson_append_time_t( b, key, **bci.Pt ); break;
case 'x': if (*bci.Px != 0) bson_append_symbol( b, key, *bci.Px ); break;
@@ -383,41 +383,41 @@ void bcon_json_print(bcon *bc, int n) {
bcon *bcp;
putchar('{');
for (end_of_data = 0, bcp = bc; !end_of_data; bcp++) {
- bcon bci = *bcp;
- switch (t) {
- case 'l':
- if (key_value_count & 0x1) putchar(':');
- printf("%ld", bci.l);
- t = 0;
- key_value_count++;
- break;
- case 's': /* fall through */
- default:
- s = bci.s;
- switch (*s) {
- case ':':
- ++s;
- t = *++s;
- break;
- case '{':
- if (key_value_count & 0x1) putchar(':');
- putchar(*s);
- key_value_count = 0;
- break;
- case '}':
- putchar(*s);
- key_value_count = 2;
- break;
+ bcon bci = *bcp;
+ switch (t) {
+ case 'l':
+ if (key_value_count & 0x1) putchar(':');
+ printf("%ld", bci.l);
+ t = 0;
+ key_value_count++;
+ break;
+ case 's': /* fall through */
default:
- if (key_value_count & 0x1) putchar(':');
- else if (key_value_count > 1) putchar(',');
- printf("\"%s\"", s);
- t = 0;
- key_value_count++;
- break;
+ s = bci.s;
+ switch (*s) {
+ case ':':
+ ++s;
+ t = *++s;
+ break;
+ case '{':
+ if (key_value_count & 0x1) putchar(':');
+ putchar(*s);
+ key_value_count = 0;
+ break;
+ case '}':
+ putchar(*s);
+ key_value_count = 2;
+ break;
+ default:
+ if (key_value_count & 0x1) putchar(':');
+ else if (key_value_count > 1) putchar(',');
+ printf("\"%s\"", s);
+ t = 0;
+ key_value_count++;
+ break;
+ }
+ break;
}
- break;
- }
}
putchar('}');
}
View
@@ -53,11 +53,11 @@ static int ( *oid_inc_func )( void ) = NULL;
------------------------------ */
MONGO_EXPORT bson* bson_create( void ) {
- return (bson*)bson_malloc(sizeof(bson));
+ return (bson*)bson_malloc(sizeof(bson));
}
MONGO_EXPORT void bson_dispose(bson* b) {
- bson_free(b);
+ bson_free(b);
}
MONGO_EXPORT bson *bson_empty( bson *obj ) {
@@ -527,7 +527,8 @@ MONGO_EXPORT void bson_iterator_code_scope( const bson_iterator *i, bson *scope
bson_init_data( scope, ( void * )( bson_iterator_value( i )+8+code_len ) );
_bson_reset( scope );
scope->finished = 1;
- } else {
+ }
+ else {
bson_empty( scope );
}
}
@@ -741,7 +742,7 @@ MONGO_EXPORT int bson_append_undefined( bson *b, const char *name ) {
}
static int bson_append_string_base( bson *b, const char *name,
- const char *value, int len, bson_type type ) {
+ const char *value, int len, bson_type type ) {
int sl = len + 1;
if ( bson_check_string( b, ( const char * )value, sl - 1 ) == BSON_ERROR )
@@ -780,7 +781,7 @@ MONGO_EXPORT int bson_append_code_n( bson *b, const char *name, const char *valu
}
MONGO_EXPORT int bson_append_code_w_scope_n( bson *b, const char *name,
- const char *code, int len, const bson *scope ) {
+ const char *code, int len, const bson *scope ) {
int sl, size;
if ( !scope ) return BSON_ERROR;
@@ -808,7 +809,8 @@ MONGO_EXPORT int bson_append_binary( bson *b, const char *name, char type, const
bson_append_byte( b, type );
bson_append32( b, &len );
bson_append( b, str, len );
- } else {
+ }
+ else {
if ( bson_append_estart( b, BSON_BINDATA, name, 4+1+len ) == BSON_ERROR )
return BSON_ERROR;
bson_append32( b, &len );
@@ -862,7 +864,8 @@ MONGO_EXPORT int bson_append_element( bson *b, const char *name_or_null, const b
if( bson_ensure_space( b, size ) == BSON_ERROR )
return BSON_ERROR;
bson_append( b, elem->cur, size );
- } else {
+ }
+ else {
int data_size = size - 2 - strlen( bson_iterator_key( elem ) );
bson_append_estart( b, elem->cur[0], name_or_null, data_size );
bson_append( b, bson_iterator_value( elem ), data_size );
@@ -926,7 +929,7 @@ MONGO_EXPORT int bson_append_finish_object( bson *b ) {
}
MONGO_EXPORT double bson_int64_to_double( int64_t i64 ) {
- return (double)i64;
+ return (double)i64;
}
MONGO_EXPORT int bson_append_finish_array( bson *b ) {
@@ -963,7 +966,7 @@ void *bson_realloc( void *ptr, int size ) {
int _bson_errprintf( const char *format, ... ) {
va_list ap;
- int ret;
+ int ret = 0;
va_start( ap, format );
#ifndef R_SAFETY_NET
ret = vfprintf( stderr, format, ap );
View
@@ -22,23 +22,23 @@
#define BSON_H_
#include <time.h>
-#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <stdlib.h>
#include <stdarg.h>
#ifdef __GNUC__
- #define MONGO_INLINE static __inline__
- #define MONGO_EXPORT
+#define MONGO_INLINE static __inline__
+#define MONGO_EXPORT
#else
- #define MONGO_INLINE static
- #ifdef MONGO_STATIC_BUILD
- #define MONGO_EXPORT
- #elif defined(MONGO_DLL_BUILD)
- #define MONGO_EXPORT __declspec(dllexport)
- #else
- #define MONGO_EXPORT __declspec(dllimport)
- #endif
+#define MONGO_INLINE static
+#ifdef MONGO_STATIC_BUILD
+#define MONGO_EXPORT
+#elif defined(MONGO_DLL_BUILD)
+#define MONGO_EXPORT __declspec(dllexport)
+#else
+#define MONGO_EXPORT __declspec(dllimport)
+#endif
#endif
#ifdef __cplusplus
View
@@ -106,17 +106,17 @@ static int bson_string_is_db_ref( const unsigned char *string, const int length
int result = 0;
if( length >= 4 ) {
- if( string[1] == 'r' && string[2] == 'e' && string[3] == 'f' )
- result = 1;
+ if( string[1] == 'r' && string[2] == 'e' && string[3] == 'f' )
+ result = 1;
}
else if( length >= 3 ) {
- if( string[1] == 'i' && string[2] == 'd' )
- result = 1;
- else if( string[1] == 'd' && string[2] == 'b' )
- result = 1;
+ if( string[1] == 'i' && string[2] == 'd' )
+ result = 1;
+ else if( string[1] == 'd' && string[2] == 'b' )
+ result = 1;
}
- return result;
+ return result;
}
static int bson_validate_string( bson *b, const unsigned char *string,
Oops, something went wrong.

0 comments on commit 3a849c0

Please sign in to comment.