-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to the ruminate-jansson code
- Loading branch information
Russell Harmon
committed
Nov 26, 2013
1 parent
2340b05
commit 14d7bc9
Showing
11 changed files
with
209 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
add_subdirectory(backtrace) | ||
add_subdirectory(json) | ||
add_subdirectory(ruminate-jansson-test) | ||
add_subdirectory(stdout) | ||
add_subdirectory(memory) | ||
add_subdirectory(main) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,17 @@ | ||
find_package(Jansson) | ||
find_package(Talloc) | ||
|
||
if(JANSSON_FOUND AND TALLOC_FOUND) | ||
if(JANSSON_FOUND) | ||
add_executable(ruminate-jansson-test | ||
ruminate-jansson-test.c | ||
) | ||
set_target_properties(ruminate-jansson-test PROPERTIES COMPILE_FLAGS "-std=c99 -g") | ||
set_target_properties(ruminate-jansson-test PROPERTIES COMPILE_FLAGS "-std=c11 -g") | ||
target_link_libraries(ruminate-jansson-test | ||
ruminate | ||
ruminate-jansson | ||
jansson | ||
${GLIB2_LIBRARIES} | ||
${JANSSON_LIBRARIES} | ||
${TALLOC_LIBRARIES} | ||
) | ||
include_directories( | ||
${JANSSON_INCLUDE_DIRS} | ||
${GLIB2_INCLUDE_DIRS} | ||
${TALLOC_INCLUDE_DIRS} | ||
) | ||
endif(JANSSON_FOUND AND TALLOC_FOUND) | ||
endif(JANSSON_FOUND) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
if(JANSSON_FOUND) | ||
add_executable(stdout | ||
stdout.c | ||
) | ||
set_target_properties(stdout PROPERTIES COMPILE_FLAGS "-std=c99 -g") | ||
target_link_libraries(stdout | ||
ruminate | ||
ruminate-jansson | ||
jansson | ||
${GLIB2_LIBRARIES} | ||
${JANSSON_LIBRARIES} | ||
) | ||
include_directories( | ||
${JANSSON_INCLUDE_DIRS} | ||
${GLIB2_INCLUDE_DIRS} | ||
) | ||
endif(JANSSON_FOUND) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <ctype.h> | ||
|
||
#include <ruminate.h> | ||
#include <jansson.h> | ||
#include <glib.h> | ||
#include <ruminate-jansson.h> | ||
|
||
static void die_if_error( GError *err ) { | ||
if( err == NULL ) return; | ||
fprintf(stderr, "%s\n", err->message); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
static json_t *serialize_void( JsonSerializerArgs args, void *data, GError **error ) { | ||
(void) args, (void) data, (void) error; | ||
return NULL; | ||
} | ||
|
||
static JsonHook void_hook = { | ||
.serializer = serialize_void | ||
}; | ||
|
||
static json_t *serialize_char_ptr( JsonSerializerArgs args, void *data, GError **error ) { | ||
(void) data; | ||
g_assert(args.value != NULL); | ||
char *str = *((char **) args.value); | ||
if( str == NULL ) return json_null(); | ||
|
||
bool is_string = false; | ||
while( true ) { | ||
if( *str == '\0' ) { | ||
is_string = true; | ||
break; | ||
} | ||
if( !isalnum(*str) ) break; | ||
str++; | ||
} | ||
|
||
if( is_string ) return json_string(str); | ||
return args.cont(args.state, args.type, args.value, error); | ||
} | ||
|
||
static JsonHook char_ptr_hook = { | ||
.serializer = serialize_char_ptr | ||
}; | ||
|
||
int main( int argc, char *argv[] ) { | ||
(void) argc; | ||
GError *err = NULL; | ||
|
||
ruminate_init(argv[0], &err); | ||
die_if_error(err); | ||
|
||
RType *rt = ruminate_get_type(stdout, &err); | ||
die_if_error(err); | ||
|
||
JsonState *st = json_state_new(); | ||
json_state_add_hook(st, g_quark_from_static_string("void"), &void_hook); | ||
json_state_add_hook(st, g_quark_from_static_string("char *"), &char_ptr_hook); | ||
json_state_set_flags(st, JSON_FLAG_SKIP_UNKNOWN); | ||
|
||
printf("Hello World!"); | ||
json_t *serialized = json_serialize(st, rt, &stdout, &err); | ||
die_if_error(err); | ||
|
||
printf("\n"); | ||
json_dumpf(serialized, stdout, 0); | ||
printf("\n"); | ||
|
||
json_decref(serialized); | ||
r_type_unref(rt); | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
find_package(Jansson) | ||
find_package(Talloc) | ||
|
||
if(JANSSON_FOUND AND TALLOC_FOUND) | ||
if(JANSSON_FOUND) | ||
add_library(ruminate-jansson | ||
serialize.c | ||
deserialize.c | ||
json_state.c | ||
) | ||
set_target_properties(ruminate-jansson PROPERTIES COMPILE_FLAGS "-std=c99 -g") | ||
set_target_properties(ruminate-jansson PROPERTIES COMPILE_FLAGS "-std=c11 -g") | ||
target_link_libraries(ruminate-jansson | ||
LINK_PRIVATE ruminate jansson ${GLIB2_LIBRARIES} ${TALLOC_LIBRARIES} | ||
LINK_PRIVATE ruminate jansson ${GLIB2_LIBRARIES} | ||
) | ||
target_include_directories(ruminate-jansson | ||
PUBLIC ${JANSSON_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} | ||
PRIVATE ${TALLOC_INCLUDE_DIRS} | ||
) | ||
endif(JANSSON_FOUND AND TALLOC_FOUND) | ||
endif(JANSSON_FOUND) |
Oops, something went wrong.