ctags.rb 1.0.0 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (323) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +2 -1
  3. data/README.md +49 -0
  4. data/Rakefile +19 -0
  5. data/bench.rb +28 -0
  6. data/ctags.rb.gemspec +1 -1
  7. data/ext/.gitignore +1 -1
  8. data/ext/extconf.rb +30 -6
  9. data/ext/vendor/exuberant-ctags/entry.c +70 -1
  10. data/ext/vendor/exuberant-ctags/main.c +68 -7
  11. data/ext/vendor/exuberant-ctags/options.c +12 -12
  12. data/ext/vendor/exuberant-ctags/options.h +1 -1
  13. data/ext/vendor/exuberant-ctags/parse.c +2 -2
  14. data/ext/vendor/exuberant-ctags/read.c +8 -3
  15. data/ext/vendor/exuberant-ctags/read.h +4 -1
  16. data/ext/vendor/exuberant-ctags/routines.c +31 -8
  17. data/ext/vendor/exuberant-ctags/ruby.c +62 -7
  18. data/ext/vendor/fmemopen/README.md +49 -0
  19. data/ext/vendor/fmemopen/fmemopen.c +92 -0
  20. data/ext/vendor/fmemopen/fmemopen.h +52 -0
  21. data/ext/vendor/jansson-2.5/CHANGES +554 -0
  22. data/ext/vendor/jansson-2.5/LICENSE +19 -0
  23. data/ext/vendor/jansson-2.5/Makefile.am +15 -0
  24. data/ext/vendor/jansson-2.5/Makefile.in +825 -0
  25. data/ext/vendor/jansson-2.5/README.rst +63 -0
  26. data/ext/vendor/jansson-2.5/aclocal.m4 +9674 -0
  27. data/ext/vendor/jansson-2.5/config.guess +1530 -0
  28. data/ext/vendor/jansson-2.5/config.h.in +84 -0
  29. data/ext/vendor/jansson-2.5/config.sub +1782 -0
  30. data/ext/vendor/jansson-2.5/configure +13931 -0
  31. data/ext/vendor/jansson-2.5/configure.ac +57 -0
  32. data/ext/vendor/jansson-2.5/depcomp +708 -0
  33. data/ext/vendor/jansson-2.5/doc/Makefile.am +20 -0
  34. data/ext/vendor/jansson-2.5/doc/Makefile.in +401 -0
  35. data/ext/vendor/jansson-2.5/doc/README +5 -0
  36. data/ext/vendor/jansson-2.5/doc/apiref.rst +1487 -0
  37. data/ext/vendor/jansson-2.5/doc/changes.rst +5 -0
  38. data/ext/vendor/jansson-2.5/doc/conf.py +217 -0
  39. data/ext/vendor/jansson-2.5/doc/conformance.rst +114 -0
  40. data/ext/vendor/jansson-2.5/doc/ext/refcounting.py +59 -0
  41. data/ext/vendor/jansson-2.5/doc/gettingstarted.rst +237 -0
  42. data/ext/vendor/jansson-2.5/doc/github_commits.c +192 -0
  43. data/ext/vendor/jansson-2.5/doc/index.rst +53 -0
  44. data/ext/vendor/jansson-2.5/doc/portability.rst +52 -0
  45. data/ext/vendor/jansson-2.5/doc/tutorial.rst +286 -0
  46. data/ext/vendor/jansson-2.5/doc/upgrading.rst +76 -0
  47. data/ext/vendor/jansson-2.5/install-sh +527 -0
  48. data/ext/vendor/jansson-2.5/jansson.pc.in +10 -0
  49. data/ext/vendor/jansson-2.5/ltmain.sh +9661 -0
  50. data/ext/vendor/jansson-2.5/missing +331 -0
  51. data/ext/vendor/jansson-2.5/src/Makefile.am +24 -0
  52. data/ext/vendor/jansson-2.5/src/Makefile.in +613 -0
  53. data/ext/vendor/jansson-2.5/src/dump.c +456 -0
  54. data/ext/vendor/jansson-2.5/src/error.c +63 -0
  55. data/ext/vendor/jansson-2.5/src/hashtable.c +360 -0
  56. data/ext/vendor/jansson-2.5/src/hashtable.h +180 -0
  57. data/ext/vendor/jansson-2.5/src/jansson.def +63 -0
  58. data/ext/vendor/jansson-2.5/src/jansson.h +281 -0
  59. data/ext/vendor/jansson-2.5/src/jansson_config.h +39 -0
  60. data/ext/vendor/jansson-2.5/src/jansson_config.h.in +39 -0
  61. data/ext/vendor/jansson-2.5/src/jansson_private.h +93 -0
  62. data/ext/vendor/jansson-2.5/src/load.c +1077 -0
  63. data/ext/vendor/jansson-2.5/src/memory.c +56 -0
  64. data/ext/vendor/jansson-2.5/src/pack_unpack.c +762 -0
  65. data/ext/vendor/jansson-2.5/src/strbuffer.c +116 -0
  66. data/ext/vendor/jansson-2.5/src/strbuffer.h +33 -0
  67. data/ext/vendor/jansson-2.5/src/strconv.c +134 -0
  68. data/ext/vendor/jansson-2.5/src/utf.c +190 -0
  69. data/ext/vendor/jansson-2.5/src/utf.h +39 -0
  70. data/ext/vendor/jansson-2.5/src/value.c +950 -0
  71. data/ext/vendor/jansson-2.5/test/Makefile.am +10 -0
  72. data/ext/vendor/jansson-2.5/test/Makefile.in +684 -0
  73. data/ext/vendor/jansson-2.5/test/bin/Makefile.am +5 -0
  74. data/ext/vendor/jansson-2.5/test/bin/Makefile.in +498 -0
  75. data/ext/vendor/jansson-2.5/test/bin/json_process.c +349 -0
  76. data/ext/vendor/jansson-2.5/test/run-suites +50 -0
  77. data/ext/vendor/jansson-2.5/test/scripts/run-tests.sh +100 -0
  78. data/ext/vendor/jansson-2.5/test/scripts/valgrind.sh +35 -0
  79. data/ext/vendor/jansson-2.5/test/suites/Makefile.am +2 -0
  80. data/ext/vendor/jansson-2.5/test/suites/Makefile.in +580 -0
  81. data/ext/vendor/jansson-2.5/test/suites/api/Makefile.am +34 -0
  82. data/ext/vendor/jansson-2.5/test/suites/api/Makefile.in +632 -0
  83. data/ext/vendor/jansson-2.5/test/suites/api/check-exports +23 -0
  84. data/ext/vendor/jansson-2.5/test/suites/api/run +36 -0
  85. data/ext/vendor/jansson-2.5/test/suites/api/test_array.c +432 -0
  86. data/ext/vendor/jansson-2.5/test/suites/api/test_copy.c +318 -0
  87. data/ext/vendor/jansson-2.5/test/suites/api/test_dump.c +190 -0
  88. data/ext/vendor/jansson-2.5/test/suites/api/test_dump_callback.c +81 -0
  89. data/ext/vendor/jansson-2.5/test/suites/api/test_equal.c +189 -0
  90. data/ext/vendor/jansson-2.5/test/suites/api/test_load.c +166 -0
  91. data/ext/vendor/jansson-2.5/test/suites/api/test_load_callback.c +75 -0
  92. data/ext/vendor/jansson-2.5/test/suites/api/test_loadb.c +36 -0
  93. data/ext/vendor/jansson-2.5/test/suites/api/test_memory_funcs.c +82 -0
  94. data/ext/vendor/jansson-2.5/test/suites/api/test_number.c +73 -0
  95. data/ext/vendor/jansson-2.5/test/suites/api/test_object.c +511 -0
  96. data/ext/vendor/jansson-2.5/test/suites/api/test_pack.c +283 -0
  97. data/ext/vendor/jansson-2.5/test/suites/api/test_simple.c +199 -0
  98. data/ext/vendor/jansson-2.5/test/suites/api/test_unpack.c +373 -0
  99. data/ext/vendor/jansson-2.5/test/suites/api/util.h +74 -0
  100. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/encoded-surrogate-half/error +2 -0
  101. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/encoded-surrogate-half/input +1 -0
  102. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-after-backslash/error +2 -0
  103. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-after-backslash/input +1 -0
  104. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-array/error +2 -0
  105. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-array/input +1 -0
  106. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-bigger-int/error +2 -0
  107. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-bigger-int/input +1 -0
  108. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-escape/error +2 -0
  109. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-escape/input +1 -0
  110. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-exponent/error +2 -0
  111. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-exponent/input +1 -0
  112. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-identifier/error +2 -0
  113. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-identifier/input +1 -0
  114. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-int/error +2 -0
  115. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-int/input +1 -0
  116. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-real-after-e/error +2 -0
  117. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-real-after-e/input +1 -0
  118. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-string/error +2 -0
  119. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-string/input +1 -0
  120. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/lone-invalid-utf-8/error +2 -0
  121. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/lone-invalid-utf-8/input +1 -0
  122. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/lone-utf-8-continuation-byte/error +2 -0
  123. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/lone-utf-8-continuation-byte/input +1 -0
  124. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/not-in-unicode-range/error +2 -0
  125. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/not-in-unicode-range/input +1 -0
  126. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/overlong-3-byte-encoding/error +2 -0
  127. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/overlong-3-byte-encoding/input +1 -0
  128. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/overlong-4-byte-encoding/error +2 -0
  129. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/overlong-4-byte-encoding/input +1 -0
  130. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/overlong-ascii-encoding/error +2 -0
  131. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/overlong-ascii-encoding/input +1 -0
  132. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/restricted-utf-8/error +2 -0
  133. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/restricted-utf-8/input +1 -0
  134. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/run +27 -0
  135. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/truncated-utf-8/error +2 -0
  136. data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/truncated-utf-8/input +1 -0
  137. data/ext/vendor/jansson-2.5/test/suites/invalid/apostrophe/error +2 -0
  138. data/ext/vendor/jansson-2.5/test/suites/invalid/apostrophe/input +1 -0
  139. data/ext/vendor/jansson-2.5/test/suites/invalid/ascii-unicode-identifier/error +2 -0
  140. data/ext/vendor/jansson-2.5/test/suites/invalid/ascii-unicode-identifier/input +1 -0
  141. data/ext/vendor/jansson-2.5/test/suites/invalid/brace-comma/error +2 -0
  142. data/ext/vendor/jansson-2.5/test/suites/invalid/brace-comma/input +1 -0
  143. data/ext/vendor/jansson-2.5/test/suites/invalid/bracket-comma/error +2 -0
  144. data/ext/vendor/jansson-2.5/test/suites/invalid/bracket-comma/input +1 -0
  145. data/ext/vendor/jansson-2.5/test/suites/invalid/bracket-one-comma/error.normal +2 -0
  146. data/ext/vendor/jansson-2.5/test/suites/invalid/bracket-one-comma/error.strip +2 -0
  147. data/ext/vendor/jansson-2.5/test/suites/invalid/bracket-one-comma/input +1 -0
  148. data/ext/vendor/jansson-2.5/test/suites/invalid/empty/error +2 -0
  149. data/ext/vendor/jansson-2.5/test/suites/invalid/empty/input +0 -0
  150. data/ext/vendor/jansson-2.5/test/suites/invalid/escaped-null-byte-in-string/error +2 -0
  151. data/ext/vendor/jansson-2.5/test/suites/invalid/escaped-null-byte-in-string/input +1 -0
  152. data/ext/vendor/jansson-2.5/test/suites/invalid/extra-comma-in-array/error +2 -0
  153. data/ext/vendor/jansson-2.5/test/suites/invalid/extra-comma-in-array/input +1 -0
  154. data/ext/vendor/jansson-2.5/test/suites/invalid/extra-comma-in-multiline-array/error +2 -0
  155. data/ext/vendor/jansson-2.5/test/suites/invalid/extra-comma-in-multiline-array/input +6 -0
  156. data/ext/vendor/jansson-2.5/test/suites/invalid/garbage-after-newline/error +2 -0
  157. data/ext/vendor/jansson-2.5/test/suites/invalid/garbage-after-newline/input +2 -0
  158. data/ext/vendor/jansson-2.5/test/suites/invalid/garbage-at-the-end/error +2 -0
  159. data/ext/vendor/jansson-2.5/test/suites/invalid/garbage-at-the-end/input +1 -0
  160. data/ext/vendor/jansson-2.5/test/suites/invalid/integer-starting-with-zero/error +2 -0
  161. data/ext/vendor/jansson-2.5/test/suites/invalid/integer-starting-with-zero/input +1 -0
  162. data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-escape/error +2 -0
  163. data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-escape/input +1 -0
  164. data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-identifier/error +2 -0
  165. data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-identifier/input +1 -0
  166. data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-negative-integer/error +2 -0
  167. data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-negative-integer/input +1 -0
  168. data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-negative-real/error +2 -0
  169. data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-negative-real/input +1 -0
  170. data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-second-surrogate/error +2 -0
  171. data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-second-surrogate/input +1 -0
  172. data/ext/vendor/jansson-2.5/test/suites/invalid/lone-open-brace/error.normal +2 -0
  173. data/ext/vendor/jansson-2.5/test/suites/invalid/lone-open-brace/error.strip +2 -0
  174. data/ext/vendor/jansson-2.5/test/suites/invalid/lone-open-brace/input +1 -0
  175. data/ext/vendor/jansson-2.5/test/suites/invalid/lone-open-bracket/error.normal +2 -0
  176. data/ext/vendor/jansson-2.5/test/suites/invalid/lone-open-bracket/error.strip +2 -0
  177. data/ext/vendor/jansson-2.5/test/suites/invalid/lone-open-bracket/input +1 -0
  178. data/ext/vendor/jansson-2.5/test/suites/invalid/lone-second-surrogate/error +2 -0
  179. data/ext/vendor/jansson-2.5/test/suites/invalid/lone-second-surrogate/input +1 -0
  180. data/ext/vendor/jansson-2.5/test/suites/invalid/minus-sign-without-number/error +2 -0
  181. data/ext/vendor/jansson-2.5/test/suites/invalid/minus-sign-without-number/input +1 -0
  182. data/ext/vendor/jansson-2.5/test/suites/invalid/negative-integer-starting-with-zero/error +2 -0
  183. data/ext/vendor/jansson-2.5/test/suites/invalid/negative-integer-starting-with-zero/input +1 -0
  184. data/ext/vendor/jansson-2.5/test/suites/invalid/null-byte-in-string/error +2 -0
  185. data/ext/vendor/jansson-2.5/test/suites/invalid/null-byte-in-string/input +0 -0
  186. data/ext/vendor/jansson-2.5/test/suites/invalid/null-byte-in-string/nostrip +2 -0
  187. data/ext/vendor/jansson-2.5/test/suites/invalid/null-byte-outside-string/error +2 -0
  188. data/ext/vendor/jansson-2.5/test/suites/invalid/null-byte-outside-string/input +0 -0
  189. data/ext/vendor/jansson-2.5/test/suites/invalid/null-byte-outside-string/nostrip +2 -0
  190. data/ext/vendor/jansson-2.5/test/suites/invalid/null/error +2 -0
  191. data/ext/vendor/jansson-2.5/test/suites/invalid/null/input +1 -0
  192. data/ext/vendor/jansson-2.5/test/suites/invalid/object-apostrophes/error +2 -0
  193. data/ext/vendor/jansson-2.5/test/suites/invalid/object-apostrophes/input +1 -0
  194. data/ext/vendor/jansson-2.5/test/suites/invalid/object-garbage-at-end/error +2 -0
  195. data/ext/vendor/jansson-2.5/test/suites/invalid/object-garbage-at-end/input +1 -0
  196. data/ext/vendor/jansson-2.5/test/suites/invalid/object-in-unterminated-array/error.normal +2 -0
  197. data/ext/vendor/jansson-2.5/test/suites/invalid/object-in-unterminated-array/error.strip +2 -0
  198. data/ext/vendor/jansson-2.5/test/suites/invalid/object-in-unterminated-array/input +1 -0
  199. data/ext/vendor/jansson-2.5/test/suites/invalid/object-no-colon/error.normal +2 -0
  200. data/ext/vendor/jansson-2.5/test/suites/invalid/object-no-colon/error.strip +2 -0
  201. data/ext/vendor/jansson-2.5/test/suites/invalid/object-no-colon/input +1 -0
  202. data/ext/vendor/jansson-2.5/test/suites/invalid/object-no-value/error.normal +2 -0
  203. data/ext/vendor/jansson-2.5/test/suites/invalid/object-no-value/error.strip +2 -0
  204. data/ext/vendor/jansson-2.5/test/suites/invalid/object-no-value/input +1 -0
  205. data/ext/vendor/jansson-2.5/test/suites/invalid/object-unterminated-value/error.normal +2 -0
  206. data/ext/vendor/jansson-2.5/test/suites/invalid/object-unterminated-value/error.strip +2 -0
  207. data/ext/vendor/jansson-2.5/test/suites/invalid/object-unterminated-value/input +1 -0
  208. data/ext/vendor/jansson-2.5/test/suites/invalid/real-garbage-after-e/error +2 -0
  209. data/ext/vendor/jansson-2.5/test/suites/invalid/real-garbage-after-e/input +1 -0
  210. data/ext/vendor/jansson-2.5/test/suites/invalid/real-negative-overflow/error +2 -0
  211. data/ext/vendor/jansson-2.5/test/suites/invalid/real-negative-overflow/input +1 -0
  212. data/ext/vendor/jansson-2.5/test/suites/invalid/real-positive-overflow/error +2 -0
  213. data/ext/vendor/jansson-2.5/test/suites/invalid/real-positive-overflow/input +1 -0
  214. data/ext/vendor/jansson-2.5/test/suites/invalid/real-truncated-at-e/error +2 -0
  215. data/ext/vendor/jansson-2.5/test/suites/invalid/real-truncated-at-e/input +1 -0
  216. data/ext/vendor/jansson-2.5/test/suites/invalid/real-truncated-at-point/error +2 -0
  217. data/ext/vendor/jansson-2.5/test/suites/invalid/real-truncated-at-point/input +1 -0
  218. data/ext/vendor/jansson-2.5/test/suites/invalid/run +57 -0
  219. data/ext/vendor/jansson-2.5/test/suites/invalid/tab-character-in-string/error +2 -0
  220. data/ext/vendor/jansson-2.5/test/suites/invalid/tab-character-in-string/input +1 -0
  221. data/ext/vendor/jansson-2.5/test/suites/invalid/too-big-negative-integer/error +2 -0
  222. data/ext/vendor/jansson-2.5/test/suites/invalid/too-big-negative-integer/input +1 -0
  223. data/ext/vendor/jansson-2.5/test/suites/invalid/too-big-positive-integer/error +2 -0
  224. data/ext/vendor/jansson-2.5/test/suites/invalid/too-big-positive-integer/input +1 -0
  225. data/ext/vendor/jansson-2.5/test/suites/invalid/truncated-unicode-surrogate/error +2 -0
  226. data/ext/vendor/jansson-2.5/test/suites/invalid/truncated-unicode-surrogate/input +1 -0
  227. data/ext/vendor/jansson-2.5/test/suites/invalid/unicode-identifier/error +2 -0
  228. data/ext/vendor/jansson-2.5/test/suites/invalid/unicode-identifier/input +1 -0
  229. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-array-and-object/error.normal +2 -0
  230. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-array-and-object/error.strip +2 -0
  231. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-array-and-object/input +1 -0
  232. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-array/error.normal +2 -0
  233. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-array/error.strip +2 -0
  234. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-array/input +1 -0
  235. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-empty-key/error.normal +2 -0
  236. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-empty-key/error.strip +2 -0
  237. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-empty-key/input +1 -0
  238. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-key/error.normal +2 -0
  239. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-key/error.strip +2 -0
  240. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-key/input +1 -0
  241. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-object-and-array/error +2 -0
  242. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-object-and-array/input +1 -0
  243. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-string/error.normal +2 -0
  244. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-string/error.strip +2 -0
  245. data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-string/input +1 -0
  246. data/ext/vendor/jansson-2.5/test/suites/valid/complex-array/env +1 -0
  247. data/ext/vendor/jansson-2.5/test/suites/valid/complex-array/input +5 -0
  248. data/ext/vendor/jansson-2.5/test/suites/valid/complex-array/output +1 -0
  249. data/ext/vendor/jansson-2.5/test/suites/valid/empty-array/input +1 -0
  250. data/ext/vendor/jansson-2.5/test/suites/valid/empty-array/output +1 -0
  251. data/ext/vendor/jansson-2.5/test/suites/valid/empty-object-in-array/input +1 -0
  252. data/ext/vendor/jansson-2.5/test/suites/valid/empty-object-in-array/output +1 -0
  253. data/ext/vendor/jansson-2.5/test/suites/valid/empty-object/input +1 -0
  254. data/ext/vendor/jansson-2.5/test/suites/valid/empty-object/output +1 -0
  255. data/ext/vendor/jansson-2.5/test/suites/valid/empty-string/input +1 -0
  256. data/ext/vendor/jansson-2.5/test/suites/valid/empty-string/output +1 -0
  257. data/ext/vendor/jansson-2.5/test/suites/valid/escaped-utf-control-char/input +1 -0
  258. data/ext/vendor/jansson-2.5/test/suites/valid/escaped-utf-control-char/output +1 -0
  259. data/ext/vendor/jansson-2.5/test/suites/valid/false/input +1 -0
  260. data/ext/vendor/jansson-2.5/test/suites/valid/false/output +1 -0
  261. data/ext/vendor/jansson-2.5/test/suites/valid/negative-int/input +1 -0
  262. data/ext/vendor/jansson-2.5/test/suites/valid/negative-int/output +1 -0
  263. data/ext/vendor/jansson-2.5/test/suites/valid/negative-one/input +1 -0
  264. data/ext/vendor/jansson-2.5/test/suites/valid/negative-one/output +1 -0
  265. data/ext/vendor/jansson-2.5/test/suites/valid/negative-zero/input +1 -0
  266. data/ext/vendor/jansson-2.5/test/suites/valid/negative-zero/output +1 -0
  267. data/ext/vendor/jansson-2.5/test/suites/valid/null/input +1 -0
  268. data/ext/vendor/jansson-2.5/test/suites/valid/null/output +1 -0
  269. data/ext/vendor/jansson-2.5/test/suites/valid/one-byte-utf-8/input +1 -0
  270. data/ext/vendor/jansson-2.5/test/suites/valid/one-byte-utf-8/output +1 -0
  271. data/ext/vendor/jansson-2.5/test/suites/valid/real-capital-e-negative-exponent/input +1 -0
  272. data/ext/vendor/jansson-2.5/test/suites/valid/real-capital-e-negative-exponent/output +1 -0
  273. data/ext/vendor/jansson-2.5/test/suites/valid/real-capital-e-positive-exponent/input +1 -0
  274. data/ext/vendor/jansson-2.5/test/suites/valid/real-capital-e-positive-exponent/output +1 -0
  275. data/ext/vendor/jansson-2.5/test/suites/valid/real-capital-e/input +1 -0
  276. data/ext/vendor/jansson-2.5/test/suites/valid/real-capital-e/output +1 -0
  277. data/ext/vendor/jansson-2.5/test/suites/valid/real-exponent/input +1 -0
  278. data/ext/vendor/jansson-2.5/test/suites/valid/real-exponent/output +1 -0
  279. data/ext/vendor/jansson-2.5/test/suites/valid/real-fraction-exponent/input +1 -0
  280. data/ext/vendor/jansson-2.5/test/suites/valid/real-fraction-exponent/output +1 -0
  281. data/ext/vendor/jansson-2.5/test/suites/valid/real-negative-exponent/input +1 -0
  282. data/ext/vendor/jansson-2.5/test/suites/valid/real-negative-exponent/output +1 -0
  283. data/ext/vendor/jansson-2.5/test/suites/valid/real-positive-exponent/input +1 -0
  284. data/ext/vendor/jansson-2.5/test/suites/valid/real-positive-exponent/output +1 -0
  285. data/ext/vendor/jansson-2.5/test/suites/valid/real-underflow/input +1 -0
  286. data/ext/vendor/jansson-2.5/test/suites/valid/real-underflow/output +1 -0
  287. data/ext/vendor/jansson-2.5/test/suites/valid/run +56 -0
  288. data/ext/vendor/jansson-2.5/test/suites/valid/short-string/input +1 -0
  289. data/ext/vendor/jansson-2.5/test/suites/valid/short-string/output +1 -0
  290. data/ext/vendor/jansson-2.5/test/suites/valid/simple-ascii-string/input +1 -0
  291. data/ext/vendor/jansson-2.5/test/suites/valid/simple-ascii-string/output +1 -0
  292. data/ext/vendor/jansson-2.5/test/suites/valid/simple-int-0/input +1 -0
  293. data/ext/vendor/jansson-2.5/test/suites/valid/simple-int-0/output +1 -0
  294. data/ext/vendor/jansson-2.5/test/suites/valid/simple-int-1/input +1 -0
  295. data/ext/vendor/jansson-2.5/test/suites/valid/simple-int-1/output +1 -0
  296. data/ext/vendor/jansson-2.5/test/suites/valid/simple-int-123/input +1 -0
  297. data/ext/vendor/jansson-2.5/test/suites/valid/simple-int-123/output +1 -0
  298. data/ext/vendor/jansson-2.5/test/suites/valid/simple-object/input +1 -0
  299. data/ext/vendor/jansson-2.5/test/suites/valid/simple-object/output +1 -0
  300. data/ext/vendor/jansson-2.5/test/suites/valid/simple-real/input +1 -0
  301. data/ext/vendor/jansson-2.5/test/suites/valid/simple-real/output +1 -0
  302. data/ext/vendor/jansson-2.5/test/suites/valid/string-escapes/input +1 -0
  303. data/ext/vendor/jansson-2.5/test/suites/valid/string-escapes/output +1 -0
  304. data/ext/vendor/jansson-2.5/test/suites/valid/three-byte-utf-8/input +1 -0
  305. data/ext/vendor/jansson-2.5/test/suites/valid/three-byte-utf-8/output +1 -0
  306. data/ext/vendor/jansson-2.5/test/suites/valid/true/input +1 -0
  307. data/ext/vendor/jansson-2.5/test/suites/valid/true/output +1 -0
  308. data/ext/vendor/jansson-2.5/test/suites/valid/two-byte-utf-8/input +1 -0
  309. data/ext/vendor/jansson-2.5/test/suites/valid/two-byte-utf-8/output +1 -0
  310. data/ext/vendor/jansson-2.5/test/suites/valid/utf-8-string/input +1 -0
  311. data/ext/vendor/jansson-2.5/test/suites/valid/utf-8-string/output +1 -0
  312. data/ext/vendor/jansson-2.5/test/suites/valid/utf-surrogate-four-byte-encoding/input +1 -0
  313. data/ext/vendor/jansson-2.5/test/suites/valid/utf-surrogate-four-byte-encoding/output +1 -0
  314. data/ext/vendor/jansson-2.5/win32/jansson_config.h +39 -0
  315. data/ext/vendor/jansson-2.5/win32/vs2010/jansson.sln +20 -0
  316. data/ext/vendor/jansson-2.5/win32/vs2010/jansson.vcxproj +108 -0
  317. data/ext/vendor/jansson-2.5/win32/vs2010/jansson.vcxproj.filters +69 -0
  318. data/ext/vendor/jansson-2.5/win32/vs2010/jansson.vcxproj.user +3 -0
  319. data/lib/ctags.cnf +2 -0
  320. data/lib/ctags/exuberant.rb +129 -17
  321. data/lib/ctags/version.rb +1 -1
  322. data/test/test_ctags.rb +14 -7
  323. metadata +350 -69
@@ -0,0 +1,1077 @@
1
+ /*
2
+ * Copyright (c) 2009-2013 Petri Lehtinen <petri@digip.org>
3
+ *
4
+ * Jansson is free software; you can redistribute it and/or modify
5
+ * it under the terms of the MIT license. See LICENSE for details.
6
+ */
7
+
8
+ #ifndef _GNU_SOURCE
9
+ #define _GNU_SOURCE
10
+ #endif
11
+
12
+ #include <errno.h>
13
+ #include <limits.h>
14
+ #include <stdio.h>
15
+ #include <stdlib.h>
16
+ #include <string.h>
17
+ #include <assert.h>
18
+
19
+ #include "jansson.h"
20
+ #include "jansson_private.h"
21
+ #include "strbuffer.h"
22
+ #include "utf.h"
23
+
24
+ #define STREAM_STATE_OK 0
25
+ #define STREAM_STATE_EOF -1
26
+ #define STREAM_STATE_ERROR -2
27
+
28
+ #define TOKEN_INVALID -1
29
+ #define TOKEN_EOF 0
30
+ #define TOKEN_STRING 256
31
+ #define TOKEN_INTEGER 257
32
+ #define TOKEN_REAL 258
33
+ #define TOKEN_TRUE 259
34
+ #define TOKEN_FALSE 260
35
+ #define TOKEN_NULL 261
36
+
37
+ /* Locale independent versions of isxxx() functions */
38
+ #define l_isupper(c) ('A' <= (c) && (c) <= 'Z')
39
+ #define l_islower(c) ('a' <= (c) && (c) <= 'z')
40
+ #define l_isalpha(c) (l_isupper(c) || l_islower(c))
41
+ #define l_isdigit(c) ('0' <= (c) && (c) <= '9')
42
+ #define l_isxdigit(c) \
43
+ (l_isdigit(c) || ('A' <= (c) && (c) <= 'F') || ('a' <= (c) && (c) <= 'f'))
44
+
45
+ /* Read one byte from stream, convert to unsigned char, then int, and
46
+ return. return EOF on end of file. This corresponds to the
47
+ behaviour of fgetc(). */
48
+ typedef int (*get_func)(void *data);
49
+
50
+ typedef struct {
51
+ get_func get;
52
+ void *data;
53
+ char buffer[5];
54
+ size_t buffer_pos;
55
+ int state;
56
+ int line;
57
+ int column, last_column;
58
+ size_t position;
59
+ } stream_t;
60
+
61
+ typedef struct {
62
+ stream_t stream;
63
+ strbuffer_t saved_text;
64
+ int token;
65
+ union {
66
+ char *string;
67
+ json_int_t integer;
68
+ double real;
69
+ } value;
70
+ } lex_t;
71
+
72
+ #define stream_to_lex(stream) container_of(stream, lex_t, stream)
73
+
74
+
75
+ /*** error reporting ***/
76
+
77
+ static void error_set(json_error_t *error, const lex_t *lex,
78
+ const char *msg, ...)
79
+ {
80
+ va_list ap;
81
+ char msg_text[JSON_ERROR_TEXT_LENGTH];
82
+ char msg_with_context[JSON_ERROR_TEXT_LENGTH];
83
+
84
+ int line = -1, col = -1;
85
+ size_t pos = 0;
86
+ const char *result = msg_text;
87
+
88
+ if(!error)
89
+ return;
90
+
91
+ va_start(ap, msg);
92
+ vsnprintf(msg_text, JSON_ERROR_TEXT_LENGTH, msg, ap);
93
+ msg_text[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
94
+ va_end(ap);
95
+
96
+ if(lex)
97
+ {
98
+ const char *saved_text = strbuffer_value(&lex->saved_text);
99
+
100
+ line = lex->stream.line;
101
+ col = lex->stream.column;
102
+ pos = lex->stream.position;
103
+
104
+ if(saved_text && saved_text[0])
105
+ {
106
+ if(lex->saved_text.length <= 20) {
107
+ snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH,
108
+ "%s near '%s'", msg_text, saved_text);
109
+ msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
110
+ result = msg_with_context;
111
+ }
112
+ }
113
+ else
114
+ {
115
+ if(lex->stream.state == STREAM_STATE_ERROR) {
116
+ /* No context for UTF-8 decoding errors */
117
+ result = msg_text;
118
+ }
119
+ else {
120
+ snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH,
121
+ "%s near end of file", msg_text);
122
+ msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
123
+ result = msg_with_context;
124
+ }
125
+ }
126
+ }
127
+
128
+ jsonp_error_set(error, line, col, pos, "%s", result);
129
+ }
130
+
131
+
132
+ /*** lexical analyzer ***/
133
+
134
+ static void
135
+ stream_init(stream_t *stream, get_func get, void *data)
136
+ {
137
+ stream->get = get;
138
+ stream->data = data;
139
+ stream->buffer[0] = '\0';
140
+ stream->buffer_pos = 0;
141
+
142
+ stream->state = STREAM_STATE_OK;
143
+ stream->line = 1;
144
+ stream->column = 0;
145
+ stream->position = 0;
146
+ }
147
+
148
+ static int stream_get(stream_t *stream, json_error_t *error)
149
+ {
150
+ int c;
151
+
152
+ if(stream->state != STREAM_STATE_OK)
153
+ return stream->state;
154
+
155
+ if(!stream->buffer[stream->buffer_pos])
156
+ {
157
+ c = stream->get(stream->data);
158
+ if(c == EOF) {
159
+ stream->state = STREAM_STATE_EOF;
160
+ return STREAM_STATE_EOF;
161
+ }
162
+
163
+ stream->buffer[0] = c;
164
+ stream->buffer_pos = 0;
165
+
166
+ if(0x80 <= c && c <= 0xFF)
167
+ {
168
+ /* multi-byte UTF-8 sequence */
169
+ int i, count;
170
+
171
+ count = utf8_check_first(c);
172
+ if(!count)
173
+ goto out;
174
+
175
+ assert(count >= 2);
176
+
177
+ for(i = 1; i < count; i++)
178
+ stream->buffer[i] = stream->get(stream->data);
179
+
180
+ if(!utf8_check_full(stream->buffer, count, NULL))
181
+ goto out;
182
+
183
+ stream->buffer[count] = '\0';
184
+ }
185
+ else
186
+ stream->buffer[1] = '\0';
187
+ }
188
+
189
+ c = stream->buffer[stream->buffer_pos++];
190
+
191
+ stream->position++;
192
+ if(c == '\n') {
193
+ stream->line++;
194
+ stream->last_column = stream->column;
195
+ stream->column = 0;
196
+ }
197
+ else if(utf8_check_first(c)) {
198
+ /* track the Unicode character column, so increment only if
199
+ this is the first character of a UTF-8 sequence */
200
+ stream->column++;
201
+ }
202
+
203
+ return c;
204
+
205
+ out:
206
+ stream->state = STREAM_STATE_ERROR;
207
+ error_set(error, stream_to_lex(stream), "unable to decode byte 0x%x", c);
208
+ return STREAM_STATE_ERROR;
209
+ }
210
+
211
+ static void stream_unget(stream_t *stream, int c)
212
+ {
213
+ if(c == STREAM_STATE_EOF || c == STREAM_STATE_ERROR)
214
+ return;
215
+
216
+ stream->position--;
217
+ if(c == '\n') {
218
+ stream->line--;
219
+ stream->column = stream->last_column;
220
+ }
221
+ else if(utf8_check_first(c))
222
+ stream->column--;
223
+
224
+ assert(stream->buffer_pos > 0);
225
+ stream->buffer_pos--;
226
+ assert(stream->buffer[stream->buffer_pos] == c);
227
+ }
228
+
229
+
230
+ static int lex_get(lex_t *lex, json_error_t *error)
231
+ {
232
+ return stream_get(&lex->stream, error);
233
+ }
234
+
235
+ static void lex_save(lex_t *lex, int c)
236
+ {
237
+ strbuffer_append_byte(&lex->saved_text, c);
238
+ }
239
+
240
+ static int lex_get_save(lex_t *lex, json_error_t *error)
241
+ {
242
+ int c = stream_get(&lex->stream, error);
243
+ if(c != STREAM_STATE_EOF && c != STREAM_STATE_ERROR)
244
+ lex_save(lex, c);
245
+ return c;
246
+ }
247
+
248
+ static void lex_unget(lex_t *lex, int c)
249
+ {
250
+ stream_unget(&lex->stream, c);
251
+ }
252
+
253
+ static void lex_unget_unsave(lex_t *lex, int c)
254
+ {
255
+ if(c != STREAM_STATE_EOF && c != STREAM_STATE_ERROR) {
256
+ /* Since we treat warnings as errors, when assertions are turned
257
+ * off the "d" variable would be set but never used. Which is
258
+ * treated as an error by GCC.
259
+ */
260
+ #ifndef NDEBUG
261
+ char d;
262
+ #endif
263
+ stream_unget(&lex->stream, c);
264
+ #ifndef NDEBUG
265
+ d =
266
+ #endif
267
+ strbuffer_pop(&lex->saved_text);
268
+ assert(c == d);
269
+ }
270
+ }
271
+
272
+ static void lex_save_cached(lex_t *lex)
273
+ {
274
+ while(lex->stream.buffer[lex->stream.buffer_pos] != '\0')
275
+ {
276
+ lex_save(lex, lex->stream.buffer[lex->stream.buffer_pos]);
277
+ lex->stream.buffer_pos++;
278
+ lex->stream.position++;
279
+ }
280
+ }
281
+
282
+ /* assumes that str points to 'u' plus at least 4 valid hex digits */
283
+ static int32_t decode_unicode_escape(const char *str)
284
+ {
285
+ int i;
286
+ int32_t value = 0;
287
+
288
+ assert(str[0] == 'u');
289
+
290
+ for(i = 1; i <= 4; i++) {
291
+ char c = str[i];
292
+ value <<= 4;
293
+ if(l_isdigit(c))
294
+ value += c - '0';
295
+ else if(l_islower(c))
296
+ value += c - 'a' + 10;
297
+ else if(l_isupper(c))
298
+ value += c - 'A' + 10;
299
+ else
300
+ assert(0);
301
+ }
302
+
303
+ return value;
304
+ }
305
+
306
+ static void lex_scan_string(lex_t *lex, json_error_t *error)
307
+ {
308
+ int c;
309
+ const char *p;
310
+ char *t;
311
+ int i;
312
+
313
+ lex->value.string = NULL;
314
+ lex->token = TOKEN_INVALID;
315
+
316
+ c = lex_get_save(lex, error);
317
+
318
+ while(c != '"') {
319
+ if(c == STREAM_STATE_ERROR)
320
+ goto out;
321
+
322
+ else if(c == STREAM_STATE_EOF) {
323
+ error_set(error, lex, "premature end of input");
324
+ goto out;
325
+ }
326
+
327
+ else if(0 <= c && c <= 0x1F) {
328
+ /* control character */
329
+ lex_unget_unsave(lex, c);
330
+ if(c == '\n')
331
+ error_set(error, lex, "unexpected newline", c);
332
+ else
333
+ error_set(error, lex, "control character 0x%x", c);
334
+ goto out;
335
+ }
336
+
337
+ else if(c == '\\') {
338
+ c = lex_get_save(lex, error);
339
+ if(c == 'u') {
340
+ c = lex_get_save(lex, error);
341
+ for(i = 0; i < 4; i++) {
342
+ if(!l_isxdigit(c)) {
343
+ error_set(error, lex, "invalid escape");
344
+ goto out;
345
+ }
346
+ c = lex_get_save(lex, error);
347
+ }
348
+ }
349
+ else if(c == '"' || c == '\\' || c == '/' || c == 'b' ||
350
+ c == 'f' || c == 'n' || c == 'r' || c == 't')
351
+ c = lex_get_save(lex, error);
352
+ else {
353
+ error_set(error, lex, "invalid escape");
354
+ goto out;
355
+ }
356
+ }
357
+ else
358
+ c = lex_get_save(lex, error);
359
+ }
360
+
361
+ /* the actual value is at most of the same length as the source
362
+ string, because:
363
+ - shortcut escapes (e.g. "\t") (length 2) are converted to 1 byte
364
+ - a single \uXXXX escape (length 6) is converted to at most 3 bytes
365
+ - two \uXXXX escapes (length 12) forming an UTF-16 surrogate pair
366
+ are converted to 4 bytes
367
+ */
368
+ lex->value.string = jsonp_malloc(lex->saved_text.length + 1);
369
+ if(!lex->value.string) {
370
+ /* this is not very nice, since TOKEN_INVALID is returned */
371
+ goto out;
372
+ }
373
+
374
+ /* the target */
375
+ t = lex->value.string;
376
+
377
+ /* + 1 to skip the " */
378
+ p = strbuffer_value(&lex->saved_text) + 1;
379
+
380
+ while(*p != '"') {
381
+ if(*p == '\\') {
382
+ p++;
383
+ if(*p == 'u') {
384
+ char buffer[4];
385
+ int length;
386
+ int32_t value;
387
+
388
+ value = decode_unicode_escape(p);
389
+ p += 5;
390
+
391
+ if(0xD800 <= value && value <= 0xDBFF) {
392
+ /* surrogate pair */
393
+ if(*p == '\\' && *(p + 1) == 'u') {
394
+ int32_t value2 = decode_unicode_escape(++p);
395
+ p += 5;
396
+
397
+ if(0xDC00 <= value2 && value2 <= 0xDFFF) {
398
+ /* valid second surrogate */
399
+ value =
400
+ ((value - 0xD800) << 10) +
401
+ (value2 - 0xDC00) +
402
+ 0x10000;
403
+ }
404
+ else {
405
+ /* invalid second surrogate */
406
+ error_set(error, lex,
407
+ "invalid Unicode '\\u%04X\\u%04X'",
408
+ value, value2);
409
+ goto out;
410
+ }
411
+ }
412
+ else {
413
+ /* no second surrogate */
414
+ error_set(error, lex, "invalid Unicode '\\u%04X'",
415
+ value);
416
+ goto out;
417
+ }
418
+ }
419
+ else if(0xDC00 <= value && value <= 0xDFFF) {
420
+ error_set(error, lex, "invalid Unicode '\\u%04X'", value);
421
+ goto out;
422
+ }
423
+ else if(value == 0)
424
+ {
425
+ error_set(error, lex, "\\u0000 is not allowed");
426
+ goto out;
427
+ }
428
+
429
+ if(utf8_encode(value, buffer, &length))
430
+ assert(0);
431
+
432
+ memcpy(t, buffer, length);
433
+ t += length;
434
+ }
435
+ else {
436
+ switch(*p) {
437
+ case '"': case '\\': case '/':
438
+ *t = *p; break;
439
+ case 'b': *t = '\b'; break;
440
+ case 'f': *t = '\f'; break;
441
+ case 'n': *t = '\n'; break;
442
+ case 'r': *t = '\r'; break;
443
+ case 't': *t = '\t'; break;
444
+ default: assert(0);
445
+ }
446
+ t++;
447
+ p++;
448
+ }
449
+ }
450
+ else
451
+ *(t++) = *(p++);
452
+ }
453
+ *t = '\0';
454
+ lex->token = TOKEN_STRING;
455
+ return;
456
+
457
+ out:
458
+ jsonp_free(lex->value.string);
459
+ }
460
+
461
+ #ifndef JANSSON_USING_CMAKE /* disabled if using cmake */
462
+ #if JSON_INTEGER_IS_LONG_LONG
463
+ #ifdef _MSC_VER /* Microsoft Visual Studio */
464
+ #define json_strtoint _strtoi64
465
+ #else
466
+ #define json_strtoint strtoll
467
+ #endif
468
+ #else
469
+ #define json_strtoint strtol
470
+ #endif
471
+ #endif
472
+
473
+ static int lex_scan_number(lex_t *lex, int c, json_error_t *error)
474
+ {
475
+ const char *saved_text;
476
+ char *end;
477
+ double value;
478
+
479
+ lex->token = TOKEN_INVALID;
480
+
481
+ if(c == '-')
482
+ c = lex_get_save(lex, error);
483
+
484
+ if(c == '0') {
485
+ c = lex_get_save(lex, error);
486
+ if(l_isdigit(c)) {
487
+ lex_unget_unsave(lex, c);
488
+ goto out;
489
+ }
490
+ }
491
+ else if(l_isdigit(c)) {
492
+ c = lex_get_save(lex, error);
493
+ while(l_isdigit(c))
494
+ c = lex_get_save(lex, error);
495
+ }
496
+ else {
497
+ lex_unget_unsave(lex, c);
498
+ goto out;
499
+ }
500
+
501
+ if(c != '.' && c != 'E' && c != 'e') {
502
+ json_int_t value;
503
+
504
+ lex_unget_unsave(lex, c);
505
+
506
+ saved_text = strbuffer_value(&lex->saved_text);
507
+
508
+ errno = 0;
509
+ value = json_strtoint(saved_text, &end, 10);
510
+ if(errno == ERANGE) {
511
+ if(value < 0)
512
+ error_set(error, lex, "too big negative integer");
513
+ else
514
+ error_set(error, lex, "too big integer");
515
+ goto out;
516
+ }
517
+
518
+ assert(end == saved_text + lex->saved_text.length);
519
+
520
+ lex->token = TOKEN_INTEGER;
521
+ lex->value.integer = value;
522
+ return 0;
523
+ }
524
+
525
+ if(c == '.') {
526
+ c = lex_get(lex, error);
527
+ if(!l_isdigit(c)) {
528
+ lex_unget(lex, c);
529
+ goto out;
530
+ }
531
+ lex_save(lex, c);
532
+
533
+ c = lex_get_save(lex, error);
534
+ while(l_isdigit(c))
535
+ c = lex_get_save(lex, error);
536
+ }
537
+
538
+ if(c == 'E' || c == 'e') {
539
+ c = lex_get_save(lex, error);
540
+ if(c == '+' || c == '-')
541
+ c = lex_get_save(lex, error);
542
+
543
+ if(!l_isdigit(c)) {
544
+ lex_unget_unsave(lex, c);
545
+ goto out;
546
+ }
547
+
548
+ c = lex_get_save(lex, error);
549
+ while(l_isdigit(c))
550
+ c = lex_get_save(lex, error);
551
+ }
552
+
553
+ lex_unget_unsave(lex, c);
554
+
555
+ if(jsonp_strtod(&lex->saved_text, &value)) {
556
+ error_set(error, lex, "real number overflow");
557
+ goto out;
558
+ }
559
+
560
+ lex->token = TOKEN_REAL;
561
+ lex->value.real = value;
562
+ return 0;
563
+
564
+ out:
565
+ return -1;
566
+ }
567
+
568
+ static int lex_scan(lex_t *lex, json_error_t *error)
569
+ {
570
+ int c;
571
+
572
+ strbuffer_clear(&lex->saved_text);
573
+
574
+ if(lex->token == TOKEN_STRING) {
575
+ jsonp_free(lex->value.string);
576
+ lex->value.string = NULL;
577
+ }
578
+
579
+ c = lex_get(lex, error);
580
+ while(c == ' ' || c == '\t' || c == '\n' || c == '\r')
581
+ c = lex_get(lex, error);
582
+
583
+ if(c == STREAM_STATE_EOF) {
584
+ lex->token = TOKEN_EOF;
585
+ goto out;
586
+ }
587
+
588
+ if(c == STREAM_STATE_ERROR) {
589
+ lex->token = TOKEN_INVALID;
590
+ goto out;
591
+ }
592
+
593
+ lex_save(lex, c);
594
+
595
+ if(c == '{' || c == '}' || c == '[' || c == ']' || c == ':' || c == ',')
596
+ lex->token = c;
597
+
598
+ else if(c == '"')
599
+ lex_scan_string(lex, error);
600
+
601
+ else if(l_isdigit(c) || c == '-') {
602
+ if(lex_scan_number(lex, c, error))
603
+ goto out;
604
+ }
605
+
606
+ else if(l_isalpha(c)) {
607
+ /* eat up the whole identifier for clearer error messages */
608
+ const char *saved_text;
609
+
610
+ c = lex_get_save(lex, error);
611
+ while(l_isalpha(c))
612
+ c = lex_get_save(lex, error);
613
+ lex_unget_unsave(lex, c);
614
+
615
+ saved_text = strbuffer_value(&lex->saved_text);
616
+
617
+ if(strcmp(saved_text, "true") == 0)
618
+ lex->token = TOKEN_TRUE;
619
+ else if(strcmp(saved_text, "false") == 0)
620
+ lex->token = TOKEN_FALSE;
621
+ else if(strcmp(saved_text, "null") == 0)
622
+ lex->token = TOKEN_NULL;
623
+ else
624
+ lex->token = TOKEN_INVALID;
625
+ }
626
+
627
+ else {
628
+ /* save the rest of the input UTF-8 sequence to get an error
629
+ message of valid UTF-8 */
630
+ lex_save_cached(lex);
631
+ lex->token = TOKEN_INVALID;
632
+ }
633
+
634
+ out:
635
+ return lex->token;
636
+ }
637
+
638
+ static char *lex_steal_string(lex_t *lex)
639
+ {
640
+ char *result = NULL;
641
+ if(lex->token == TOKEN_STRING)
642
+ {
643
+ result = lex->value.string;
644
+ lex->value.string = NULL;
645
+ }
646
+ return result;
647
+ }
648
+
649
+ static int lex_init(lex_t *lex, get_func get, void *data)
650
+ {
651
+ stream_init(&lex->stream, get, data);
652
+ if(strbuffer_init(&lex->saved_text))
653
+ return -1;
654
+
655
+ lex->token = TOKEN_INVALID;
656
+ return 0;
657
+ }
658
+
659
+ static void lex_close(lex_t *lex)
660
+ {
661
+ if(lex->token == TOKEN_STRING)
662
+ jsonp_free(lex->value.string);
663
+ strbuffer_close(&lex->saved_text);
664
+ }
665
+
666
+
667
+ /*** parser ***/
668
+
669
+ static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error);
670
+
671
+ static json_t *parse_object(lex_t *lex, size_t flags, json_error_t *error)
672
+ {
673
+ json_t *object = json_object();
674
+ if(!object)
675
+ return NULL;
676
+
677
+ lex_scan(lex, error);
678
+ if(lex->token == '}')
679
+ return object;
680
+
681
+ while(1) {
682
+ char *key;
683
+ json_t *value;
684
+
685
+ if(lex->token != TOKEN_STRING) {
686
+ error_set(error, lex, "string or '}' expected");
687
+ goto error;
688
+ }
689
+
690
+ key = lex_steal_string(lex);
691
+ if(!key)
692
+ return NULL;
693
+
694
+ if(flags & JSON_REJECT_DUPLICATES) {
695
+ if(json_object_get(object, key)) {
696
+ jsonp_free(key);
697
+ error_set(error, lex, "duplicate object key");
698
+ goto error;
699
+ }
700
+ }
701
+
702
+ lex_scan(lex, error);
703
+ if(lex->token != ':') {
704
+ jsonp_free(key);
705
+ error_set(error, lex, "':' expected");
706
+ goto error;
707
+ }
708
+
709
+ lex_scan(lex, error);
710
+ value = parse_value(lex, flags, error);
711
+ if(!value) {
712
+ jsonp_free(key);
713
+ goto error;
714
+ }
715
+
716
+ if(json_object_set_nocheck(object, key, value)) {
717
+ jsonp_free(key);
718
+ json_decref(value);
719
+ goto error;
720
+ }
721
+
722
+ json_decref(value);
723
+ jsonp_free(key);
724
+
725
+ lex_scan(lex, error);
726
+ if(lex->token != ',')
727
+ break;
728
+
729
+ lex_scan(lex, error);
730
+ }
731
+
732
+ if(lex->token != '}') {
733
+ error_set(error, lex, "'}' expected");
734
+ goto error;
735
+ }
736
+
737
+ return object;
738
+
739
+ error:
740
+ json_decref(object);
741
+ return NULL;
742
+ }
743
+
744
+ static json_t *parse_array(lex_t *lex, size_t flags, json_error_t *error)
745
+ {
746
+ json_t *array = json_array();
747
+ if(!array)
748
+ return NULL;
749
+
750
+ lex_scan(lex, error);
751
+ if(lex->token == ']')
752
+ return array;
753
+
754
+ while(lex->token) {
755
+ json_t *elem = parse_value(lex, flags, error);
756
+ if(!elem)
757
+ goto error;
758
+
759
+ if(json_array_append(array, elem)) {
760
+ json_decref(elem);
761
+ goto error;
762
+ }
763
+ json_decref(elem);
764
+
765
+ lex_scan(lex, error);
766
+ if(lex->token != ',')
767
+ break;
768
+
769
+ lex_scan(lex, error);
770
+ }
771
+
772
+ if(lex->token != ']') {
773
+ error_set(error, lex, "']' expected");
774
+ goto error;
775
+ }
776
+
777
+ return array;
778
+
779
+ error:
780
+ json_decref(array);
781
+ return NULL;
782
+ }
783
+
784
+ static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error)
785
+ {
786
+ json_t *json;
787
+ double value;
788
+
789
+ switch(lex->token) {
790
+ case TOKEN_STRING: {
791
+ json = json_string_nocheck(lex->value.string);
792
+ break;
793
+ }
794
+
795
+ case TOKEN_INTEGER: {
796
+ if (flags & JSON_DECODE_INT_AS_REAL) {
797
+ if(jsonp_strtod(&lex->saved_text, &value)) {
798
+ error_set(error, lex, "real number overflow");
799
+ return NULL;
800
+ }
801
+ json = json_real(value);
802
+ } else {
803
+ json = json_integer(lex->value.integer);
804
+ }
805
+ break;
806
+ }
807
+
808
+ case TOKEN_REAL: {
809
+ json = json_real(lex->value.real);
810
+ break;
811
+ }
812
+
813
+ case TOKEN_TRUE:
814
+ json = json_true();
815
+ break;
816
+
817
+ case TOKEN_FALSE:
818
+ json = json_false();
819
+ break;
820
+
821
+ case TOKEN_NULL:
822
+ json = json_null();
823
+ break;
824
+
825
+ case '{':
826
+ json = parse_object(lex, flags, error);
827
+ break;
828
+
829
+ case '[':
830
+ json = parse_array(lex, flags, error);
831
+ break;
832
+
833
+ case TOKEN_INVALID:
834
+ error_set(error, lex, "invalid token");
835
+ return NULL;
836
+
837
+ default:
838
+ error_set(error, lex, "unexpected token");
839
+ return NULL;
840
+ }
841
+
842
+ if(!json)
843
+ return NULL;
844
+
845
+ return json;
846
+ }
847
+
848
+ static json_t *parse_json(lex_t *lex, size_t flags, json_error_t *error)
849
+ {
850
+ json_t *result;
851
+
852
+ lex_scan(lex, error);
853
+ if(!(flags & JSON_DECODE_ANY)) {
854
+ if(lex->token != '[' && lex->token != '{') {
855
+ error_set(error, lex, "'[' or '{' expected");
856
+ return NULL;
857
+ }
858
+ }
859
+
860
+ result = parse_value(lex, flags, error);
861
+ if(!result)
862
+ return NULL;
863
+
864
+ if(!(flags & JSON_DISABLE_EOF_CHECK)) {
865
+ lex_scan(lex, error);
866
+ if(lex->token != TOKEN_EOF) {
867
+ error_set(error, lex, "end of file expected");
868
+ json_decref(result);
869
+ return NULL;
870
+ }
871
+ }
872
+
873
+ if(error) {
874
+ /* Save the position even though there was no error */
875
+ error->position = lex->stream.position;
876
+ }
877
+
878
+ return result;
879
+ }
880
+
881
+ typedef struct
882
+ {
883
+ const char *data;
884
+ int pos;
885
+ } string_data_t;
886
+
887
+ static int string_get(void *data)
888
+ {
889
+ char c;
890
+ string_data_t *stream = (string_data_t *)data;
891
+ c = stream->data[stream->pos];
892
+ if(c == '\0')
893
+ return EOF;
894
+ else
895
+ {
896
+ stream->pos++;
897
+ return (unsigned char)c;
898
+ }
899
+ }
900
+
901
+ json_t *json_loads(const char *string, size_t flags, json_error_t *error)
902
+ {
903
+ lex_t lex;
904
+ json_t *result;
905
+ string_data_t stream_data;
906
+
907
+ jsonp_error_init(error, "<string>");
908
+
909
+ if (string == NULL) {
910
+ error_set(error, NULL, "wrong arguments");
911
+ return NULL;
912
+ }
913
+
914
+ stream_data.data = string;
915
+ stream_data.pos = 0;
916
+
917
+ if(lex_init(&lex, string_get, (void *)&stream_data))
918
+ return NULL;
919
+
920
+ result = parse_json(&lex, flags, error);
921
+
922
+ lex_close(&lex);
923
+ return result;
924
+ }
925
+
926
+ typedef struct
927
+ {
928
+ const char *data;
929
+ size_t len;
930
+ size_t pos;
931
+ } buffer_data_t;
932
+
933
+ static int buffer_get(void *data)
934
+ {
935
+ char c;
936
+ buffer_data_t *stream = data;
937
+ if(stream->pos >= stream->len)
938
+ return EOF;
939
+
940
+ c = stream->data[stream->pos];
941
+ stream->pos++;
942
+ return (unsigned char)c;
943
+ }
944
+
945
+ json_t *json_loadb(const char *buffer, size_t buflen, size_t flags, json_error_t *error)
946
+ {
947
+ lex_t lex;
948
+ json_t *result;
949
+ buffer_data_t stream_data;
950
+
951
+ jsonp_error_init(error, "<buffer>");
952
+
953
+ if (buffer == NULL) {
954
+ error_set(error, NULL, "wrong arguments");
955
+ return NULL;
956
+ }
957
+
958
+ stream_data.data = buffer;
959
+ stream_data.pos = 0;
960
+ stream_data.len = buflen;
961
+
962
+ if(lex_init(&lex, buffer_get, (void *)&stream_data))
963
+ return NULL;
964
+
965
+ result = parse_json(&lex, flags, error);
966
+
967
+ lex_close(&lex);
968
+ return result;
969
+ }
970
+
971
+ json_t *json_loadf(FILE *input, size_t flags, json_error_t *error)
972
+ {
973
+ lex_t lex;
974
+ const char *source;
975
+ json_t *result;
976
+
977
+ if(input == stdin)
978
+ source = "<stdin>";
979
+ else
980
+ source = "<stream>";
981
+
982
+ jsonp_error_init(error, source);
983
+
984
+ if (input == NULL) {
985
+ error_set(error, NULL, "wrong arguments");
986
+ return NULL;
987
+ }
988
+
989
+ if(lex_init(&lex, (get_func)fgetc, input))
990
+ return NULL;
991
+
992
+ result = parse_json(&lex, flags, error);
993
+
994
+ lex_close(&lex);
995
+ return result;
996
+ }
997
+
998
+ json_t *json_load_file(const char *path, size_t flags, json_error_t *error)
999
+ {
1000
+ json_t *result;
1001
+ FILE *fp;
1002
+
1003
+ jsonp_error_init(error, path);
1004
+
1005
+ if (path == NULL) {
1006
+ error_set(error, NULL, "wrong arguments");
1007
+ return NULL;
1008
+ }
1009
+
1010
+ fp = fopen(path, "rb");
1011
+ if(!fp)
1012
+ {
1013
+ error_set(error, NULL, "unable to open %s: %s",
1014
+ path, strerror(errno));
1015
+ return NULL;
1016
+ }
1017
+
1018
+ result = json_loadf(fp, flags, error);
1019
+
1020
+ fclose(fp);
1021
+ return result;
1022
+ }
1023
+
1024
+ #define MAX_BUF_LEN 1024
1025
+
1026
+ typedef struct
1027
+ {
1028
+ char data[MAX_BUF_LEN];
1029
+ size_t len;
1030
+ size_t pos;
1031
+ json_load_callback_t callback;
1032
+ void *arg;
1033
+ } callback_data_t;
1034
+
1035
+ static int callback_get(void *data)
1036
+ {
1037
+ char c;
1038
+ callback_data_t *stream = data;
1039
+
1040
+ if(stream->pos >= stream->len) {
1041
+ stream->pos = 0;
1042
+ stream->len = stream->callback(stream->data, MAX_BUF_LEN, stream->arg);
1043
+ if(stream->len == 0 || stream->len == (size_t)-1)
1044
+ return EOF;
1045
+ }
1046
+
1047
+ c = stream->data[stream->pos];
1048
+ stream->pos++;
1049
+ return (unsigned char)c;
1050
+ }
1051
+
1052
+ json_t *json_load_callback(json_load_callback_t callback, void *arg, size_t flags, json_error_t *error)
1053
+ {
1054
+ lex_t lex;
1055
+ json_t *result;
1056
+
1057
+ callback_data_t stream_data;
1058
+
1059
+ memset(&stream_data, 0, sizeof(stream_data));
1060
+ stream_data.callback = callback;
1061
+ stream_data.arg = arg;
1062
+
1063
+ jsonp_error_init(error, "<callback>");
1064
+
1065
+ if (callback == NULL) {
1066
+ error_set(error, NULL, "wrong arguments");
1067
+ return NULL;
1068
+ }
1069
+
1070
+ if(lex_init(&lex, (get_func)callback_get, &stream_data))
1071
+ return NULL;
1072
+
1073
+ result = parse_json(&lex, flags, error);
1074
+
1075
+ lex_close(&lex);
1076
+ return result;
1077
+ }