ffi-yajl 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +114 -30
  3. data/ext/ffi_yajl/ext/encoder/extconf.rb +5 -5
  4. data/ext/ffi_yajl/ext/parser/extconf.rb +5 -5
  5. data/lib/ffi_yajl/ffi.rb +2 -1
  6. data/lib/ffi_yajl/version.rb +1 -1
  7. data/spec/ffi_yajl/encoder_spec.rb +6 -6
  8. data/spec/ffi_yajl/json_gem_spec.rb +13 -13
  9. data/spec/ffi_yajl/parser_spec.rb +9 -9
  10. metadata +16 -174
  11. data/ext/libyajl2/extconf.rb +0 -60
  12. data/ext/libyajl2/vendored/.gitignore +0 -3
  13. data/ext/libyajl2/vendored/BUILDING +0 -23
  14. data/ext/libyajl2/vendored/BUILDING.win32 +0 -27
  15. data/ext/libyajl2/vendored/CMakeLists.txt +0 -79
  16. data/ext/libyajl2/vendored/COPYING +0 -13
  17. data/ext/libyajl2/vendored/ChangeLog +0 -175
  18. data/ext/libyajl2/vendored/README +0 -74
  19. data/ext/libyajl2/vendored/TODO +0 -9
  20. data/ext/libyajl2/vendored/YAJLDoc.cmake +0 -26
  21. data/ext/libyajl2/vendored/configure +0 -79
  22. data/ext/libyajl2/vendored/example/CMakeLists.txt +0 -23
  23. data/ext/libyajl2/vendored/example/README.md +0 -7
  24. data/ext/libyajl2/vendored/example/parse_config.c +0 -69
  25. data/ext/libyajl2/vendored/example/sample.config +0 -101
  26. data/ext/libyajl2/vendored/perf/CMakeLists.txt +0 -23
  27. data/ext/libyajl2/vendored/perf/documents.c +0 -1418
  28. data/ext/libyajl2/vendored/perf/documents.h +0 -28
  29. data/ext/libyajl2/vendored/perf/perftest.c +0 -134
  30. data/ext/libyajl2/vendored/reformatter/CMakeLists.txt +0 -39
  31. data/ext/libyajl2/vendored/reformatter/json_reformat.c +0 -194
  32. data/ext/libyajl2/vendored/src/CMakeLists.txt +0 -86
  33. data/ext/libyajl2/vendored/src/YAJL.dxy +0 -1258
  34. data/ext/libyajl2/vendored/src/api/yajl_common.h +0 -75
  35. data/ext/libyajl2/vendored/src/api/yajl_gen.h +0 -157
  36. data/ext/libyajl2/vendored/src/api/yajl_parse.h +0 -226
  37. data/ext/libyajl2/vendored/src/api/yajl_tree.h +0 -185
  38. data/ext/libyajl2/vendored/src/api/yajl_version.h.cmake +0 -23
  39. data/ext/libyajl2/vendored/src/yajl +0 -33
  40. data/ext/libyajl2/vendored/src/yajl.c +0 -175
  41. data/ext/libyajl2/vendored/src/yajl.pc.cmake +0 -9
  42. data/ext/libyajl2/vendored/src/yajl_alloc.c +0 -52
  43. data/ext/libyajl2/vendored/src/yajl_alloc.h +0 -34
  44. data/ext/libyajl2/vendored/src/yajl_buf.c +0 -103
  45. data/ext/libyajl2/vendored/src/yajl_buf.h +0 -57
  46. data/ext/libyajl2/vendored/src/yajl_bytestack.h +0 -69
  47. data/ext/libyajl2/vendored/src/yajl_encode.c +0 -220
  48. data/ext/libyajl2/vendored/src/yajl_encode.h +0 -34
  49. data/ext/libyajl2/vendored/src/yajl_gen.c +0 -354
  50. data/ext/libyajl2/vendored/src/yajl_lex.c +0 -763
  51. data/ext/libyajl2/vendored/src/yajl_lex.h +0 -117
  52. data/ext/libyajl2/vendored/src/yajl_parser.c +0 -498
  53. data/ext/libyajl2/vendored/src/yajl_parser.h +0 -78
  54. data/ext/libyajl2/vendored/src/yajl_tree.c +0 -503
  55. data/ext/libyajl2/vendored/src/yajl_version.c +0 -7
  56. data/ext/libyajl2/vendored/test/CMakeLists.txt +0 -23
  57. data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json +0 -1
  58. data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json.gold +0 -36
  59. data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json +0 -11
  60. data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json.gold +0 -9
  61. data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json +0 -1
  62. data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json.gold +0 -2
  63. data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json +0 -1
  64. data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json.gold +0 -2
  65. data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json +0 -1
  66. data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json.gold +0 -2
  67. data/ext/libyajl2/vendored/test/cases/am_eof.json +0 -1
  68. data/ext/libyajl2/vendored/test/cases/am_eof.json.gold +0 -4
  69. data/ext/libyajl2/vendored/test/cases/am_integers.json +0 -1
  70. data/ext/libyajl2/vendored/test/cases/am_integers.json.gold +0 -3
  71. data/ext/libyajl2/vendored/test/cases/am_multiple.json +0 -3
  72. data/ext/libyajl2/vendored/test/cases/am_multiple.json.gold +0 -5
  73. data/ext/libyajl2/vendored/test/cases/am_stuff.json +0 -7
  74. data/ext/libyajl2/vendored/test/cases/am_stuff.json.gold +0 -14
  75. data/ext/libyajl2/vendored/test/cases/ap_array_open.json +0 -1
  76. data/ext/libyajl2/vendored/test/cases/ap_array_open.json.gold +0 -2
  77. data/ext/libyajl2/vendored/test/cases/ap_eof_str.json +0 -1
  78. data/ext/libyajl2/vendored/test/cases/ap_eof_str.json.gold +0 -1
  79. data/ext/libyajl2/vendored/test/cases/ap_map_open.json +0 -1
  80. data/ext/libyajl2/vendored/test/cases/ap_map_open.json.gold +0 -2
  81. data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json +0 -1
  82. data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json.gold +0 -4
  83. data/ext/libyajl2/vendored/test/cases/array.json +0 -6
  84. data/ext/libyajl2/vendored/test/cases/array.json.gold +0 -22
  85. data/ext/libyajl2/vendored/test/cases/array_close.json +0 -1
  86. data/ext/libyajl2/vendored/test/cases/array_close.json.gold +0 -2
  87. data/ext/libyajl2/vendored/test/cases/bignums.json +0 -1
  88. data/ext/libyajl2/vendored/test/cases/bignums.json.gold +0 -5
  89. data/ext/libyajl2/vendored/test/cases/bogus_char.json +0 -4
  90. data/ext/libyajl2/vendored/test/cases/bogus_char.json.gold +0 -10
  91. data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json +0 -1
  92. data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json.gold +0 -2
  93. data/ext/libyajl2/vendored/test/cases/deep_arrays.json +0 -1
  94. data/ext/libyajl2/vendored/test/cases/deep_arrays.json.gold +0 -2049
  95. data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json +0 -1
  96. data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json.gold +0 -36
  97. data/ext/libyajl2/vendored/test/cases/doubles.json +0 -1
  98. data/ext/libyajl2/vendored/test/cases/doubles.json.gold +0 -7
  99. data/ext/libyajl2/vendored/test/cases/doubles_in_array.json +0 -1
  100. data/ext/libyajl2/vendored/test/cases/doubles_in_array.json.gold +0 -8
  101. data/ext/libyajl2/vendored/test/cases/empty_array.json +0 -1
  102. data/ext/libyajl2/vendored/test/cases/empty_array.json.gold +0 -3
  103. data/ext/libyajl2/vendored/test/cases/empty_string.json +0 -1
  104. data/ext/libyajl2/vendored/test/cases/empty_string.json.gold +0 -2
  105. data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json +0 -4
  106. data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json.gold +0 -7
  107. data/ext/libyajl2/vendored/test/cases/escaped_foobar.json +0 -1
  108. data/ext/libyajl2/vendored/test/cases/escaped_foobar.json.gold +0 -2
  109. data/ext/libyajl2/vendored/test/cases/false.json +0 -1
  110. data/ext/libyajl2/vendored/test/cases/false.json.gold +0 -2
  111. data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json +0 -1
  112. data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json.gold +0 -3
  113. data/ext/libyajl2/vendored/test/cases/fg_issue_7.json +0 -1
  114. data/ext/libyajl2/vendored/test/cases/fg_issue_7.json.gold +0 -3
  115. data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json +0 -1
  116. data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json.gold +0 -3
  117. data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json +0 -1
  118. data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json.gold +0 -3
  119. data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json +0 -2
  120. data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json.gold +0 -5
  121. data/ext/libyajl2/vendored/test/cases/high_overflow.json +0 -1
  122. data/ext/libyajl2/vendored/test/cases/high_overflow.json.gold +0 -2
  123. data/ext/libyajl2/vendored/test/cases/integers.json +0 -3
  124. data/ext/libyajl2/vendored/test/cases/integers.json.gold +0 -14
  125. data/ext/libyajl2/vendored/test/cases/invalid_utf8.json +0 -1
  126. data/ext/libyajl2/vendored/test/cases/invalid_utf8.json.gold +0 -3
  127. data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json +0 -1
  128. data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json.gold +0 -2
  129. data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json +0 -1
  130. data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json.gold +0 -5
  131. data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json +0 -7
  132. data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json.gold +0 -9
  133. data/ext/libyajl2/vendored/test/cases/lonely_number.json +0 -1
  134. data/ext/libyajl2/vendored/test/cases/lonely_number.json.gold +0 -2
  135. data/ext/libyajl2/vendored/test/cases/low_overflow.json +0 -1
  136. data/ext/libyajl2/vendored/test/cases/low_overflow.json.gold +0 -2
  137. data/ext/libyajl2/vendored/test/cases/map_close.json +0 -1
  138. data/ext/libyajl2/vendored/test/cases/map_close.json.gold +0 -2
  139. data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json +0 -1
  140. data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json.gold +0 -2
  141. data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json +0 -1
  142. data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json.gold +0 -2
  143. data/ext/libyajl2/vendored/test/cases/multiple.json +0 -3
  144. data/ext/libyajl2/vendored/test/cases/multiple.json.gold +0 -4
  145. data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json +0 -1
  146. data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json.gold +0 -8
  147. data/ext/libyajl2/vendored/test/cases/np_partial_bad.json +0 -1
  148. data/ext/libyajl2/vendored/test/cases/np_partial_bad.json.gold +0 -5
  149. data/ext/libyajl2/vendored/test/cases/null.json +0 -1
  150. data/ext/libyajl2/vendored/test/cases/null.json.gold +0 -2
  151. data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json +0 -5
  152. data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json.gold +0 -9
  153. data/ext/libyajl2/vendored/test/cases/simple.json +0 -5
  154. data/ext/libyajl2/vendored/test/cases/simple.json.gold +0 -9
  155. data/ext/libyajl2/vendored/test/cases/simple_with_comments.json +0 -11
  156. data/ext/libyajl2/vendored/test/cases/simple_with_comments.json.gold +0 -5
  157. data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json +0 -1
  158. data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json.gold +0 -3
  159. data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json +0 -1
  160. data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json.gold +0 -2
  161. data/ext/libyajl2/vendored/test/cases/string_with_escapes.json +0 -3
  162. data/ext/libyajl2/vendored/test/cases/string_with_escapes.json.gold +0 -7
  163. data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json +0 -2
  164. data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json.gold +0 -2
  165. data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json +0 -1
  166. data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json.gold +0 -7
  167. data/ext/libyajl2/vendored/test/cases/true.json +0 -1
  168. data/ext/libyajl2/vendored/test/cases/true.json.gold +0 -2
  169. data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json +0 -1
  170. data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json.gold +0 -4
  171. data/ext/libyajl2/vendored/test/cases/zerobyte.json +0 -1
  172. data/ext/libyajl2/vendored/test/cases/zerobyte.json.gold +0 -0
  173. data/ext/libyajl2/vendored/test/run_tests.sh +0 -94
  174. data/ext/libyajl2/vendored/test/yajl_test.c +0 -281
  175. data/ext/libyajl2/vendored/verify/CMakeLists.txt +0 -39
  176. data/ext/libyajl2/vendored/verify/json_verify.c +0 -116
  177. data/lib/libyajl.so +0 -0
  178. data/lib/libyajl.so.2 +0 -0
  179. data/lib/libyajl.so.2.0.5 +0 -0
  180. data/lib/libyajl_s.a +0 -0
@@ -1,28 +0,0 @@
1
- /*
2
- * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
3
- *
4
- * Permission to use, copy, modify, and/or distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
- #ifndef __DOCUMENTS_H__
18
- #define __DOCUMENTS_H__
19
-
20
- /* a header that provides access to several json documents broken into chunks of
21
- * less than 4k, cause C99 says that's what we should do and YAJL likes streams */
22
-
23
- extern const char ** g_documents[];
24
- int num_docs(void);
25
- const char ** get_doc(int i);
26
- unsigned int doc_size(int i);
27
-
28
- #endif
@@ -1,134 +0,0 @@
1
- /*
2
- * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
3
- *
4
- * Permission to use, copy, modify, and/or distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
- #include <yajl/yajl_parse.h>
18
- #include <stdio.h>
19
- #include <stdlib.h>
20
- #include <string.h>
21
-
22
- #include "documents.h"
23
-
24
- /* a platform specific defn' of a function to get a high res time in a
25
- * portable format */
26
- #ifndef WIN32
27
- #include <sys/time.h>
28
- static double mygettime(void) {
29
- struct timeval now;
30
- gettimeofday(&now, NULL);
31
- return now.tv_sec + (now.tv_usec / 1000000.0);
32
- }
33
- #else
34
- #define _WIN32 1
35
- #include <windows.h>
36
- static double mygettime(void) {
37
- long long tval;
38
- FILETIME ft;
39
- GetSystemTimeAsFileTime(&ft);
40
- tval = ft.dwHighDateTime;
41
- tval <<=32;
42
- tval |= ft.dwLowDateTime;
43
- return tval / 10000000.00;
44
- }
45
- #endif
46
-
47
- #define PARSE_TIME_SECS 3
48
-
49
- static int
50
- run(int validate_utf8)
51
- {
52
- long long times = 0;
53
- double starttime;
54
-
55
- starttime = mygettime();
56
-
57
- /* allocate a parser */
58
- for (;;) {
59
- int i;
60
- {
61
- double now = mygettime();
62
- if (now - starttime >= PARSE_TIME_SECS) break;
63
- }
64
-
65
- for (i = 0; i < 100; i++) {
66
- yajl_handle hand = yajl_alloc(NULL, NULL, NULL);
67
- yajl_status stat;
68
- const char ** d;
69
-
70
- yajl_config(hand, yajl_dont_validate_strings, validate_utf8 ? 0 : 1);
71
-
72
- for (d = get_doc(times % num_docs()); *d; d++) {
73
- stat = yajl_parse(hand, (unsigned char *) *d, strlen(*d));
74
- if (stat != yajl_status_ok) break;
75
- }
76
-
77
- stat = yajl_complete_parse(hand);
78
-
79
- if (stat != yajl_status_ok) {
80
- unsigned char * str =
81
- yajl_get_error(hand, 1,
82
- (unsigned char *) *d,
83
- (*d ? strlen(*d) : 0));
84
- fprintf(stderr, "%s", (const char *) str);
85
- yajl_free_error(hand, str);
86
- return 1;
87
- }
88
- yajl_free(hand);
89
- times++;
90
- }
91
- }
92
-
93
- /* parsed doc 'times' times */
94
- {
95
- double throughput;
96
- double now;
97
- const char * all_units[] = { "B/s", "KB/s", "MB/s", (char *) 0 };
98
- const char ** units = all_units;
99
- int i, avg_doc_size = 0;
100
-
101
- now = mygettime();
102
-
103
- for (i = 0; i < num_docs(); i++) avg_doc_size += doc_size(i);
104
- avg_doc_size /= num_docs();
105
-
106
- throughput = (times * avg_doc_size) / (now - starttime);
107
-
108
- while (*(units + 1) && throughput > 1024) {
109
- throughput /= 1024;
110
- units++;
111
- }
112
-
113
- printf("Parsing speed: %g %s\n", throughput, *units);
114
- }
115
-
116
- return 0;
117
- }
118
-
119
- int
120
- main(void)
121
- {
122
- int rv = 0;
123
-
124
- printf("-- speed tests determine parsing throughput given %d different sample documents --\n",
125
- num_docs());
126
-
127
- printf("With UTF8 validation:\n");
128
- rv = run(1);
129
- if (rv != 0) return rv;
130
- printf("Without UTF8 validation:\n");
131
- rv = run(0);
132
- return rv;
133
- }
134
-
@@ -1,39 +0,0 @@
1
- # Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
2
- #
3
- # Permission to use, copy, modify, and/or distribute this software for any
4
- # purpose with or without fee is hereby granted, provided that the above
5
- # copyright notice and this permission notice appear in all copies.
6
- #
7
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
- # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
- # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
- # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
- # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
- # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
- # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
-
15
- # set up a paths
16
- SET (binDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/bin)
17
-
18
- # create a directories
19
- FILE(MAKE_DIRECTORY ${binDir})
20
-
21
- SET (SRCS json_reformat.c)
22
-
23
- # use the library we build, duh.
24
- INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/include)
25
- LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
26
-
27
- ADD_EXECUTABLE(json_reformat ${SRCS})
28
-
29
- TARGET_LINK_LIBRARIES(json_reformat yajl_s)
30
-
31
- # copy the binary into the output directory
32
- GET_TARGET_PROPERTY(binPath json_reformat LOCATION)
33
-
34
- ADD_CUSTOM_COMMAND(TARGET json_reformat POST_BUILD
35
- COMMAND ${CMAKE_COMMAND} -E copy_if_different ${binPath} ${binDir})
36
-
37
- IF (NOT WIN32)
38
- INSTALL(TARGETS json_reformat RUNTIME DESTINATION bin)
39
- ENDIF ()
@@ -1,194 +0,0 @@
1
- /*
2
- * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
3
- *
4
- * Permission to use, copy, modify, and/or distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
- #include <yajl/yajl_parse.h>
18
- #include <yajl/yajl_gen.h>
19
-
20
- #include <stdio.h>
21
- #include <stdlib.h>
22
- #include <string.h>
23
-
24
- static int reformat_null(void * ctx)
25
- {
26
- yajl_gen g = (yajl_gen) ctx;
27
- return yajl_gen_status_ok == yajl_gen_null(g);
28
- }
29
-
30
- static int reformat_boolean(void * ctx, int boolean)
31
- {
32
- yajl_gen g = (yajl_gen) ctx;
33
- return yajl_gen_status_ok == yajl_gen_bool(g, boolean);
34
- }
35
-
36
- static int reformat_number(void * ctx, const char * s, size_t l)
37
- {
38
- yajl_gen g = (yajl_gen) ctx;
39
- return yajl_gen_status_ok == yajl_gen_number(g, s, l);
40
- }
41
-
42
- static int reformat_string(void * ctx, const unsigned char * stringVal,
43
- size_t stringLen)
44
- {
45
- yajl_gen g = (yajl_gen) ctx;
46
- return yajl_gen_status_ok == yajl_gen_string(g, stringVal, stringLen);
47
- }
48
-
49
- static int reformat_map_key(void * ctx, const unsigned char * stringVal,
50
- size_t stringLen)
51
- {
52
- yajl_gen g = (yajl_gen) ctx;
53
- return yajl_gen_status_ok == yajl_gen_string(g, stringVal, stringLen);
54
- }
55
-
56
- static int reformat_start_map(void * ctx)
57
- {
58
- yajl_gen g = (yajl_gen) ctx;
59
- return yajl_gen_status_ok == yajl_gen_map_open(g);
60
- }
61
-
62
-
63
- static int reformat_end_map(void * ctx)
64
- {
65
- yajl_gen g = (yajl_gen) ctx;
66
- return yajl_gen_status_ok == yajl_gen_map_close(g);
67
- }
68
-
69
- static int reformat_start_array(void * ctx)
70
- {
71
- yajl_gen g = (yajl_gen) ctx;
72
- return yajl_gen_status_ok == yajl_gen_array_open(g);
73
- }
74
-
75
- static int reformat_end_array(void * ctx)
76
- {
77
- yajl_gen g = (yajl_gen) ctx;
78
- return yajl_gen_status_ok == yajl_gen_array_close(g);
79
- }
80
-
81
- static yajl_callbacks callbacks = {
82
- reformat_null,
83
- reformat_boolean,
84
- NULL,
85
- NULL,
86
- reformat_number,
87
- reformat_string,
88
- reformat_start_map,
89
- reformat_map_key,
90
- reformat_end_map,
91
- reformat_start_array,
92
- reformat_end_array
93
- };
94
-
95
- static void
96
- usage(const char * progname)
97
- {
98
- fprintf(stderr, "%s: reformat json from stdin\n"
99
- "usage: json_reformat [options]\n"
100
- " -m minimize json rather than beautify (default)\n"
101
- " -u allow invalid UTF8 inside strings during parsing\n"
102
- " -e escape any forward slashes (for embedding in HTML)\n",
103
- progname);
104
- exit(1);
105
- }
106
-
107
-
108
- int
109
- main(int argc, char ** argv)
110
- {
111
- yajl_handle hand;
112
- static unsigned char fileData[65536];
113
- /* generator config */
114
- yajl_gen g;
115
- yajl_status stat;
116
- size_t rd;
117
- int retval = 0;
118
- int a = 1;
119
-
120
- g = yajl_gen_alloc(NULL);
121
- yajl_gen_config(g, yajl_gen_beautify, 1);
122
- yajl_gen_config(g, yajl_gen_validate_utf8, 1);
123
-
124
- /* ok. open file. let's read and parse */
125
- hand = yajl_alloc(&callbacks, NULL, (void *) g);
126
- /* and let's allow comments by default */
127
- yajl_config(hand, yajl_allow_comments, 1);
128
-
129
- /* check arguments.*/
130
- while ((a < argc) && (argv[a][0] == '-') && (strlen(argv[a]) > 1)) {
131
- unsigned int i;
132
- for ( i=1; i < strlen(argv[a]); i++) {
133
- switch (argv[a][i]) {
134
- case 'm':
135
- yajl_gen_config(g, yajl_gen_beautify, 0);
136
- break;
137
- case 'u':
138
- yajl_config(hand, yajl_dont_validate_strings, 1);
139
- break;
140
- case 'e':
141
- yajl_gen_config(g, yajl_gen_escape_solidus, 1);
142
- break;
143
- default:
144
- fprintf(stderr, "unrecognized option: '%c'\n\n",
145
- argv[a][i]);
146
- usage(argv[0]);
147
- }
148
- }
149
- ++a;
150
- }
151
- if (a < argc) {
152
- usage(argv[0]);
153
- }
154
-
155
-
156
- for (;;) {
157
- rd = fread((void *) fileData, 1, sizeof(fileData) - 1, stdin);
158
-
159
- if (rd == 0) {
160
- if (!feof(stdin)) {
161
- fprintf(stderr, "error on file read.\n");
162
- retval = 1;
163
- }
164
- break;
165
- }
166
- fileData[rd] = 0;
167
-
168
- stat = yajl_parse(hand, fileData, rd);
169
-
170
- if (stat != yajl_status_ok) break;
171
-
172
- {
173
- const unsigned char * buf;
174
- size_t len;
175
- yajl_gen_get_buf(g, &buf, &len);
176
- fwrite(buf, 1, len, stdout);
177
- yajl_gen_clear(g);
178
- }
179
- }
180
-
181
- stat = yajl_complete_parse(hand);
182
-
183
- if (stat != yajl_status_ok) {
184
- unsigned char * str = yajl_get_error(hand, 1, fileData, rd);
185
- fprintf(stderr, "%s", (const char *) str);
186
- yajl_free_error(hand, str);
187
- retval = 1;
188
- }
189
-
190
- yajl_gen_free(g);
191
- yajl_free(hand);
192
-
193
- return retval;
194
- }
@@ -1,86 +0,0 @@
1
- # Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
2
- #
3
- # Permission to use, copy, modify, and/or distribute this software for any
4
- # purpose with or without fee is hereby granted, provided that the above
5
- # copyright notice and this permission notice appear in all copies.
6
- #
7
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
- # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
- # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
- # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
- # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
- # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
- # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
-
15
- SET (SRCS yajl.c yajl_lex.c yajl_parser.c yajl_buf.c
16
- yajl_encode.c yajl_gen.c yajl_alloc.c
17
- yajl_tree.c yajl_version.c
18
- )
19
- SET (HDRS yajl_parser.h yajl_lex.h yajl_buf.h yajl_encode.h yajl_alloc.h)
20
- SET (PUB_HDRS api/yajl_parse.h api/yajl_gen.h api/yajl_common.h api/yajl_tree.h)
21
-
22
- # useful when fixing lexer bugs.
23
- #ADD_DEFINITIONS(-DYAJL_LEXER_DEBUG)
24
-
25
- # Ensure defined when building YAJL (as opposed to using it from
26
- # another project). Used to ensure correct function export when
27
- # building win32 DLL.
28
- ADD_DEFINITIONS(-DYAJL_BUILD)
29
-
30
- # set up some paths
31
- SET (libDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
32
- SET (incDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/include/yajl)
33
- SET (shareDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/share/pkgconfig)
34
-
35
- # set the output path for libraries
36
- SET(LIBRARY_OUTPUT_PATH ${libDir})
37
-
38
- ADD_LIBRARY(yajl_s STATIC ${SRCS} ${HDRS} ${PUB_HDRS})
39
-
40
- ADD_LIBRARY(yajl SHARED ${SRCS} ${HDRS} ${PUB_HDRS})
41
-
42
- #### setup shared library version number
43
- SET_TARGET_PROPERTIES(yajl PROPERTIES
44
- DEFINE_SYMBOL YAJL_SHARED
45
- SOVERSION ${YAJL_MAJOR}
46
- VERSION ${YAJL_MAJOR}.${YAJL_MINOR}.${YAJL_MICRO})
47
-
48
- #### ensure a .dylib has correct absolute installation paths upon installation
49
- IF(APPLE)
50
- MESSAGE("INSTALL_NAME_DIR: ${CMAKE_INSTALL_PREFIX}/lib")
51
- SET_TARGET_PROPERTIES(yajl PROPERTIES
52
- INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
53
- ENDIF(APPLE)
54
-
55
- #### build up an sdk as a post build step
56
-
57
- # create some directories
58
- FILE(MAKE_DIRECTORY ${libDir})
59
- FILE(MAKE_DIRECTORY ${incDir})
60
-
61
- # generate build-time source
62
- SET(dollar $)
63
- CONFIGURE_FILE(api/yajl_version.h.cmake ${incDir}/yajl_version.h)
64
- CONFIGURE_FILE(yajl.pc.cmake ${shareDir}/yajl.pc)
65
-
66
- # copy public headers to output directory
67
- FOREACH (header ${PUB_HDRS})
68
- SET (header ${CMAKE_CURRENT_SOURCE_DIR}/${header})
69
-
70
- EXEC_PROGRAM(${CMAKE_COMMAND} ARGS -E copy_if_different ${header} ${incDir})
71
-
72
- ADD_CUSTOM_COMMAND(TARGET yajl_s POST_BUILD
73
- COMMAND ${CMAKE_COMMAND} -E copy_if_different ${header} ${incDir})
74
- ENDFOREACH (header ${PUB_HDRS})
75
-
76
- INCLUDE_DIRECTORIES(${incDir}/..)
77
-
78
- IF(NOT WIN32)
79
- # at build time you may specify the cmake variable LIB_SUFFIX to handle
80
- # 64-bit systems which use 'lib64'
81
- INSTALL(TARGETS yajl LIBRARY DESTINATION lib${LIB_SUFFIX})
82
- INSTALL(TARGETS yajl_s ARCHIVE DESTINATION lib${LIB_SUFFIX})
83
- INSTALL(FILES ${PUB_HDRS} DESTINATION include/yajl)
84
- INSTALL(FILES ${incDir}/yajl_version.h DESTINATION include/yajl)
85
- INSTALL(FILES ${shareDir}/yajl.pc DESTINATION share/pkgconfig)
86
- ENDIF()