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.
- checksums.yaml +15 -0
- data/Gemfile +2 -1
- data/README.md +49 -0
- data/Rakefile +19 -0
- data/bench.rb +28 -0
- data/ctags.rb.gemspec +1 -1
- data/ext/.gitignore +1 -1
- data/ext/extconf.rb +30 -6
- data/ext/vendor/exuberant-ctags/entry.c +70 -1
- data/ext/vendor/exuberant-ctags/main.c +68 -7
- data/ext/vendor/exuberant-ctags/options.c +12 -12
- data/ext/vendor/exuberant-ctags/options.h +1 -1
- data/ext/vendor/exuberant-ctags/parse.c +2 -2
- data/ext/vendor/exuberant-ctags/read.c +8 -3
- data/ext/vendor/exuberant-ctags/read.h +4 -1
- data/ext/vendor/exuberant-ctags/routines.c +31 -8
- data/ext/vendor/exuberant-ctags/ruby.c +62 -7
- data/ext/vendor/fmemopen/README.md +49 -0
- data/ext/vendor/fmemopen/fmemopen.c +92 -0
- data/ext/vendor/fmemopen/fmemopen.h +52 -0
- data/ext/vendor/jansson-2.5/CHANGES +554 -0
- data/ext/vendor/jansson-2.5/LICENSE +19 -0
- data/ext/vendor/jansson-2.5/Makefile.am +15 -0
- data/ext/vendor/jansson-2.5/Makefile.in +825 -0
- data/ext/vendor/jansson-2.5/README.rst +63 -0
- data/ext/vendor/jansson-2.5/aclocal.m4 +9674 -0
- data/ext/vendor/jansson-2.5/config.guess +1530 -0
- data/ext/vendor/jansson-2.5/config.h.in +84 -0
- data/ext/vendor/jansson-2.5/config.sub +1782 -0
- data/ext/vendor/jansson-2.5/configure +13931 -0
- data/ext/vendor/jansson-2.5/configure.ac +57 -0
- data/ext/vendor/jansson-2.5/depcomp +708 -0
- data/ext/vendor/jansson-2.5/doc/Makefile.am +20 -0
- data/ext/vendor/jansson-2.5/doc/Makefile.in +401 -0
- data/ext/vendor/jansson-2.5/doc/README +5 -0
- data/ext/vendor/jansson-2.5/doc/apiref.rst +1487 -0
- data/ext/vendor/jansson-2.5/doc/changes.rst +5 -0
- data/ext/vendor/jansson-2.5/doc/conf.py +217 -0
- data/ext/vendor/jansson-2.5/doc/conformance.rst +114 -0
- data/ext/vendor/jansson-2.5/doc/ext/refcounting.py +59 -0
- data/ext/vendor/jansson-2.5/doc/gettingstarted.rst +237 -0
- data/ext/vendor/jansson-2.5/doc/github_commits.c +192 -0
- data/ext/vendor/jansson-2.5/doc/index.rst +53 -0
- data/ext/vendor/jansson-2.5/doc/portability.rst +52 -0
- data/ext/vendor/jansson-2.5/doc/tutorial.rst +286 -0
- data/ext/vendor/jansson-2.5/doc/upgrading.rst +76 -0
- data/ext/vendor/jansson-2.5/install-sh +527 -0
- data/ext/vendor/jansson-2.5/jansson.pc.in +10 -0
- data/ext/vendor/jansson-2.5/ltmain.sh +9661 -0
- data/ext/vendor/jansson-2.5/missing +331 -0
- data/ext/vendor/jansson-2.5/src/Makefile.am +24 -0
- data/ext/vendor/jansson-2.5/src/Makefile.in +613 -0
- data/ext/vendor/jansson-2.5/src/dump.c +456 -0
- data/ext/vendor/jansson-2.5/src/error.c +63 -0
- data/ext/vendor/jansson-2.5/src/hashtable.c +360 -0
- data/ext/vendor/jansson-2.5/src/hashtable.h +180 -0
- data/ext/vendor/jansson-2.5/src/jansson.def +63 -0
- data/ext/vendor/jansson-2.5/src/jansson.h +281 -0
- data/ext/vendor/jansson-2.5/src/jansson_config.h +39 -0
- data/ext/vendor/jansson-2.5/src/jansson_config.h.in +39 -0
- data/ext/vendor/jansson-2.5/src/jansson_private.h +93 -0
- data/ext/vendor/jansson-2.5/src/load.c +1077 -0
- data/ext/vendor/jansson-2.5/src/memory.c +56 -0
- data/ext/vendor/jansson-2.5/src/pack_unpack.c +762 -0
- data/ext/vendor/jansson-2.5/src/strbuffer.c +116 -0
- data/ext/vendor/jansson-2.5/src/strbuffer.h +33 -0
- data/ext/vendor/jansson-2.5/src/strconv.c +134 -0
- data/ext/vendor/jansson-2.5/src/utf.c +190 -0
- data/ext/vendor/jansson-2.5/src/utf.h +39 -0
- data/ext/vendor/jansson-2.5/src/value.c +950 -0
- data/ext/vendor/jansson-2.5/test/Makefile.am +10 -0
- data/ext/vendor/jansson-2.5/test/Makefile.in +684 -0
- data/ext/vendor/jansson-2.5/test/bin/Makefile.am +5 -0
- data/ext/vendor/jansson-2.5/test/bin/Makefile.in +498 -0
- data/ext/vendor/jansson-2.5/test/bin/json_process.c +349 -0
- data/ext/vendor/jansson-2.5/test/run-suites +50 -0
- data/ext/vendor/jansson-2.5/test/scripts/run-tests.sh +100 -0
- data/ext/vendor/jansson-2.5/test/scripts/valgrind.sh +35 -0
- data/ext/vendor/jansson-2.5/test/suites/Makefile.am +2 -0
- data/ext/vendor/jansson-2.5/test/suites/Makefile.in +580 -0
- data/ext/vendor/jansson-2.5/test/suites/api/Makefile.am +34 -0
- data/ext/vendor/jansson-2.5/test/suites/api/Makefile.in +632 -0
- data/ext/vendor/jansson-2.5/test/suites/api/check-exports +23 -0
- data/ext/vendor/jansson-2.5/test/suites/api/run +36 -0
- data/ext/vendor/jansson-2.5/test/suites/api/test_array.c +432 -0
- data/ext/vendor/jansson-2.5/test/suites/api/test_copy.c +318 -0
- data/ext/vendor/jansson-2.5/test/suites/api/test_dump.c +190 -0
- data/ext/vendor/jansson-2.5/test/suites/api/test_dump_callback.c +81 -0
- data/ext/vendor/jansson-2.5/test/suites/api/test_equal.c +189 -0
- data/ext/vendor/jansson-2.5/test/suites/api/test_load.c +166 -0
- data/ext/vendor/jansson-2.5/test/suites/api/test_load_callback.c +75 -0
- data/ext/vendor/jansson-2.5/test/suites/api/test_loadb.c +36 -0
- data/ext/vendor/jansson-2.5/test/suites/api/test_memory_funcs.c +82 -0
- data/ext/vendor/jansson-2.5/test/suites/api/test_number.c +73 -0
- data/ext/vendor/jansson-2.5/test/suites/api/test_object.c +511 -0
- data/ext/vendor/jansson-2.5/test/suites/api/test_pack.c +283 -0
- data/ext/vendor/jansson-2.5/test/suites/api/test_simple.c +199 -0
- data/ext/vendor/jansson-2.5/test/suites/api/test_unpack.c +373 -0
- data/ext/vendor/jansson-2.5/test/suites/api/util.h +74 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/encoded-surrogate-half/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/encoded-surrogate-half/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-after-backslash/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-after-backslash/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-array/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-array/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-bigger-int/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-bigger-int/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-escape/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-escape/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-exponent/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-exponent/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-identifier/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-identifier/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-int/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-int/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-real-after-e/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-real-after-e/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-string/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/invalid-utf-8-in-string/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/lone-invalid-utf-8/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/lone-invalid-utf-8/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/lone-utf-8-continuation-byte/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/lone-utf-8-continuation-byte/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/not-in-unicode-range/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/not-in-unicode-range/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/overlong-3-byte-encoding/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/overlong-3-byte-encoding/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/overlong-4-byte-encoding/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/overlong-4-byte-encoding/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/overlong-ascii-encoding/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/overlong-ascii-encoding/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/restricted-utf-8/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/restricted-utf-8/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/run +27 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/truncated-utf-8/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid-unicode/truncated-utf-8/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/apostrophe/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/apostrophe/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/ascii-unicode-identifier/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/ascii-unicode-identifier/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/brace-comma/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/brace-comma/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/bracket-comma/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/bracket-comma/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/bracket-one-comma/error.normal +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/bracket-one-comma/error.strip +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/bracket-one-comma/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/empty/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/empty/input +0 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/escaped-null-byte-in-string/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/escaped-null-byte-in-string/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/extra-comma-in-array/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/extra-comma-in-array/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/extra-comma-in-multiline-array/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/extra-comma-in-multiline-array/input +6 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/garbage-after-newline/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/garbage-after-newline/input +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/garbage-at-the-end/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/garbage-at-the-end/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/integer-starting-with-zero/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/integer-starting-with-zero/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-escape/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-escape/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-identifier/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-identifier/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-negative-integer/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-negative-integer/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-negative-real/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-negative-real/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-second-surrogate/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/invalid-second-surrogate/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/lone-open-brace/error.normal +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/lone-open-brace/error.strip +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/lone-open-brace/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/lone-open-bracket/error.normal +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/lone-open-bracket/error.strip +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/lone-open-bracket/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/lone-second-surrogate/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/lone-second-surrogate/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/minus-sign-without-number/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/minus-sign-without-number/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/negative-integer-starting-with-zero/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/negative-integer-starting-with-zero/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/null-byte-in-string/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/null-byte-in-string/input +0 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/null-byte-in-string/nostrip +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/null-byte-outside-string/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/null-byte-outside-string/input +0 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/null-byte-outside-string/nostrip +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/null/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/null/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/object-apostrophes/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/object-apostrophes/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/object-garbage-at-end/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/object-garbage-at-end/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/object-in-unterminated-array/error.normal +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/object-in-unterminated-array/error.strip +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/object-in-unterminated-array/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/object-no-colon/error.normal +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/object-no-colon/error.strip +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/object-no-colon/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/object-no-value/error.normal +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/object-no-value/error.strip +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/object-no-value/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/object-unterminated-value/error.normal +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/object-unterminated-value/error.strip +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/object-unterminated-value/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/real-garbage-after-e/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/real-garbage-after-e/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/real-negative-overflow/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/real-negative-overflow/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/real-positive-overflow/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/real-positive-overflow/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/real-truncated-at-e/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/real-truncated-at-e/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/real-truncated-at-point/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/real-truncated-at-point/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/run +57 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/tab-character-in-string/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/tab-character-in-string/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/too-big-negative-integer/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/too-big-negative-integer/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/too-big-positive-integer/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/too-big-positive-integer/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/truncated-unicode-surrogate/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/truncated-unicode-surrogate/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unicode-identifier/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unicode-identifier/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-array-and-object/error.normal +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-array-and-object/error.strip +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-array-and-object/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-array/error.normal +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-array/error.strip +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-array/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-empty-key/error.normal +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-empty-key/error.strip +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-empty-key/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-key/error.normal +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-key/error.strip +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-key/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-object-and-array/error +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-object-and-array/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-string/error.normal +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-string/error.strip +2 -0
- data/ext/vendor/jansson-2.5/test/suites/invalid/unterminated-string/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/complex-array/env +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/complex-array/input +5 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/complex-array/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/empty-array/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/empty-array/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/empty-object-in-array/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/empty-object-in-array/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/empty-object/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/empty-object/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/empty-string/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/empty-string/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/escaped-utf-control-char/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/escaped-utf-control-char/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/false/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/false/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/negative-int/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/negative-int/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/negative-one/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/negative-one/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/negative-zero/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/negative-zero/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/null/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/null/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/one-byte-utf-8/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/one-byte-utf-8/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/real-capital-e-negative-exponent/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/real-capital-e-negative-exponent/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/real-capital-e-positive-exponent/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/real-capital-e-positive-exponent/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/real-capital-e/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/real-capital-e/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/real-exponent/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/real-exponent/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/real-fraction-exponent/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/real-fraction-exponent/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/real-negative-exponent/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/real-negative-exponent/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/real-positive-exponent/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/real-positive-exponent/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/real-underflow/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/real-underflow/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/run +56 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/short-string/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/short-string/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/simple-ascii-string/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/simple-ascii-string/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/simple-int-0/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/simple-int-0/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/simple-int-1/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/simple-int-1/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/simple-int-123/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/simple-int-123/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/simple-object/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/simple-object/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/simple-real/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/simple-real/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/string-escapes/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/string-escapes/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/three-byte-utf-8/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/three-byte-utf-8/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/true/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/true/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/two-byte-utf-8/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/two-byte-utf-8/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/utf-8-string/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/utf-8-string/output +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/utf-surrogate-four-byte-encoding/input +1 -0
- data/ext/vendor/jansson-2.5/test/suites/valid/utf-surrogate-four-byte-encoding/output +1 -0
- data/ext/vendor/jansson-2.5/win32/jansson_config.h +39 -0
- data/ext/vendor/jansson-2.5/win32/vs2010/jansson.sln +20 -0
- data/ext/vendor/jansson-2.5/win32/vs2010/jansson.vcxproj +108 -0
- data/ext/vendor/jansson-2.5/win32/vs2010/jansson.vcxproj.filters +69 -0
- data/ext/vendor/jansson-2.5/win32/vs2010/jansson.vcxproj.user +3 -0
- data/lib/ctags.cnf +2 -0
- data/lib/ctags/exuberant.rb +129 -17
- data/lib/ctags/version.rb +1 -1
- data/test/test_ctags.rb +14 -7
- metadata +350 -69
@@ -0,0 +1,192 @@
|
|
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
|
+
#include <stdlib.h>
|
9
|
+
#include <string.h>
|
10
|
+
|
11
|
+
#include <jansson.h>
|
12
|
+
#include <curl/curl.h>
|
13
|
+
|
14
|
+
#define BUFFER_SIZE (256 * 1024) /* 256 KB */
|
15
|
+
|
16
|
+
#define URL_FORMAT "https://api.github.com/repos/%s/%s/commits"
|
17
|
+
#define URL_SIZE 256
|
18
|
+
|
19
|
+
/* Return the offset of the first newline in text or the length of
|
20
|
+
text if there's no newline */
|
21
|
+
static int newline_offset(const char *text)
|
22
|
+
{
|
23
|
+
const char *newline = strchr(text, '\n');
|
24
|
+
if(!newline)
|
25
|
+
return strlen(text);
|
26
|
+
else
|
27
|
+
return (int)(newline - text);
|
28
|
+
}
|
29
|
+
|
30
|
+
struct write_result
|
31
|
+
{
|
32
|
+
char *data;
|
33
|
+
int pos;
|
34
|
+
};
|
35
|
+
|
36
|
+
static size_t write_response(void *ptr, size_t size, size_t nmemb, void *stream)
|
37
|
+
{
|
38
|
+
struct write_result *result = (struct write_result *)stream;
|
39
|
+
|
40
|
+
if(result->pos + size * nmemb >= BUFFER_SIZE - 1)
|
41
|
+
{
|
42
|
+
fprintf(stderr, "error: too small buffer\n");
|
43
|
+
return 0;
|
44
|
+
}
|
45
|
+
|
46
|
+
memcpy(result->data + result->pos, ptr, size * nmemb);
|
47
|
+
result->pos += size * nmemb;
|
48
|
+
|
49
|
+
return size * nmemb;
|
50
|
+
}
|
51
|
+
|
52
|
+
static char *request(const char *url)
|
53
|
+
{
|
54
|
+
CURL *curl = NULL;
|
55
|
+
CURLcode status;
|
56
|
+
char *data = NULL;
|
57
|
+
long code;
|
58
|
+
|
59
|
+
curl_global_init(CURL_GLOBAL_ALL);
|
60
|
+
curl = curl_easy_init();
|
61
|
+
if(!curl)
|
62
|
+
goto error;
|
63
|
+
|
64
|
+
data = malloc(BUFFER_SIZE);
|
65
|
+
if(!data)
|
66
|
+
goto error;
|
67
|
+
|
68
|
+
struct write_result write_result = {
|
69
|
+
.data = data,
|
70
|
+
.pos = 0
|
71
|
+
};
|
72
|
+
|
73
|
+
curl_easy_setopt(curl, CURLOPT_URL, url);
|
74
|
+
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_response);
|
75
|
+
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &write_result);
|
76
|
+
|
77
|
+
status = curl_easy_perform(curl);
|
78
|
+
if(status != 0)
|
79
|
+
{
|
80
|
+
fprintf(stderr, "error: unable to request data from %s:\n", url);
|
81
|
+
fprintf(stderr, "%s\n", curl_easy_strerror(status));
|
82
|
+
goto error;
|
83
|
+
}
|
84
|
+
|
85
|
+
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
|
86
|
+
if(code != 200)
|
87
|
+
{
|
88
|
+
fprintf(stderr, "error: server responded with code %ld\n", code);
|
89
|
+
goto error;
|
90
|
+
}
|
91
|
+
|
92
|
+
curl_easy_cleanup(curl);
|
93
|
+
curl_global_cleanup();
|
94
|
+
|
95
|
+
/* zero-terminate the result */
|
96
|
+
data[write_result.pos] = '\0';
|
97
|
+
|
98
|
+
return data;
|
99
|
+
|
100
|
+
error:
|
101
|
+
if(data)
|
102
|
+
free(data);
|
103
|
+
if(curl)
|
104
|
+
curl_easy_cleanup(curl);
|
105
|
+
curl_global_cleanup();
|
106
|
+
return NULL;
|
107
|
+
}
|
108
|
+
|
109
|
+
int main(int argc, char *argv[])
|
110
|
+
{
|
111
|
+
size_t i;
|
112
|
+
char *text;
|
113
|
+
char url[URL_SIZE];
|
114
|
+
|
115
|
+
json_t *root;
|
116
|
+
json_error_t error;
|
117
|
+
|
118
|
+
if(argc != 3)
|
119
|
+
{
|
120
|
+
fprintf(stderr, "usage: %s USER REPOSITORY\n\n", argv[0]);
|
121
|
+
fprintf(stderr, "List commits at USER's REPOSITORY.\n\n");
|
122
|
+
return 2;
|
123
|
+
}
|
124
|
+
|
125
|
+
snprintf(url, URL_SIZE, URL_FORMAT, argv[1], argv[2]);
|
126
|
+
|
127
|
+
text = request(url);
|
128
|
+
if(!text)
|
129
|
+
return 1;
|
130
|
+
|
131
|
+
root = json_loads(text, 0, &error);
|
132
|
+
free(text);
|
133
|
+
|
134
|
+
if(!root)
|
135
|
+
{
|
136
|
+
fprintf(stderr, "error: on line %d: %s\n", error.line, error.text);
|
137
|
+
return 1;
|
138
|
+
}
|
139
|
+
|
140
|
+
if(!json_is_array(root))
|
141
|
+
{
|
142
|
+
fprintf(stderr, "error: root is not an array\n");
|
143
|
+
json_decref(root);
|
144
|
+
return 1;
|
145
|
+
}
|
146
|
+
|
147
|
+
for(i = 0; i < json_array_size(root); i++)
|
148
|
+
{
|
149
|
+
json_t *data, *sha, *commit, *message;
|
150
|
+
const char *message_text;
|
151
|
+
|
152
|
+
data = json_array_get(root, i);
|
153
|
+
if(!json_is_object(data))
|
154
|
+
{
|
155
|
+
fprintf(stderr, "error: commit data %d is not an object\n", (int)(i + 1));
|
156
|
+
json_decref(root);
|
157
|
+
return 1;
|
158
|
+
}
|
159
|
+
|
160
|
+
sha = json_object_get(data, "sha");
|
161
|
+
if(!json_is_string(sha))
|
162
|
+
{
|
163
|
+
fprintf(stderr, "error: commit %d: sha is not a string\n", (int)(i + 1));
|
164
|
+
return 1;
|
165
|
+
}
|
166
|
+
|
167
|
+
commit = json_object_get(data, "commit");
|
168
|
+
if(!json_is_object(commit))
|
169
|
+
{
|
170
|
+
fprintf(stderr, "error: commit %d: commit is not an object\n", (int)(i + 1));
|
171
|
+
json_decref(root);
|
172
|
+
return 1;
|
173
|
+
}
|
174
|
+
|
175
|
+
message = json_object_get(commit, "message");
|
176
|
+
if(!json_is_string(message))
|
177
|
+
{
|
178
|
+
fprintf(stderr, "error: commit %d: message is not a string\n", (int)(i + 1));
|
179
|
+
json_decref(root);
|
180
|
+
return 1;
|
181
|
+
}
|
182
|
+
|
183
|
+
message_text = json_string_value(message);
|
184
|
+
printf("%.8s %.*s\n",
|
185
|
+
json_string_value(sha),
|
186
|
+
newline_offset(message_text),
|
187
|
+
message_text);
|
188
|
+
}
|
189
|
+
|
190
|
+
json_decref(root);
|
191
|
+
return 0;
|
192
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
Jansson Documentation
|
2
|
+
=====================
|
3
|
+
|
4
|
+
This is the documentation for Jansson_ |release|, last updated |today|.
|
5
|
+
|
6
|
+
Introduction
|
7
|
+
------------
|
8
|
+
|
9
|
+
Jansson_ is a C library for encoding, decoding and manipulating JSON
|
10
|
+
data. Its main features and design principles are:
|
11
|
+
|
12
|
+
- Simple and intuitive API and data model
|
13
|
+
|
14
|
+
- Comprehensive documentation
|
15
|
+
|
16
|
+
- No dependencies on other libraries
|
17
|
+
|
18
|
+
- Full Unicode support (UTF-8)
|
19
|
+
|
20
|
+
- Extensive test suite
|
21
|
+
|
22
|
+
Jansson is licensed under the `MIT license`_; see LICENSE in the
|
23
|
+
source distribution for details.
|
24
|
+
|
25
|
+
Jansson is used in production and its API is stable. It works on
|
26
|
+
numerous platforms, including numerous Unix like systems and Windows.
|
27
|
+
It's suitable for use on any system, including desktop, server, and
|
28
|
+
small embedded systems.
|
29
|
+
|
30
|
+
|
31
|
+
.. _`MIT license`: http://www.opensource.org/licenses/mit-license.php
|
32
|
+
.. _Jansson: http://www.digip.org/jansson/
|
33
|
+
|
34
|
+
Contents
|
35
|
+
--------
|
36
|
+
|
37
|
+
.. toctree::
|
38
|
+
:maxdepth: 2
|
39
|
+
|
40
|
+
gettingstarted
|
41
|
+
upgrading
|
42
|
+
tutorial
|
43
|
+
conformance
|
44
|
+
portability
|
45
|
+
apiref
|
46
|
+
changes
|
47
|
+
|
48
|
+
|
49
|
+
Indices and Tables
|
50
|
+
==================
|
51
|
+
|
52
|
+
* :ref:`genindex`
|
53
|
+
* :ref:`search`
|
@@ -0,0 +1,52 @@
|
|
1
|
+
***********
|
2
|
+
Portability
|
3
|
+
***********
|
4
|
+
|
5
|
+
Thread safety
|
6
|
+
-------------
|
7
|
+
|
8
|
+
Jansson is thread safe and has no mutable global state. The only
|
9
|
+
exception are the memory allocation functions, that should be set at
|
10
|
+
most once, and only on program startup. See
|
11
|
+
:ref:`apiref-custom-memory-allocation`.
|
12
|
+
|
13
|
+
There's no locking performed inside Jansson's code, so a multithreaded
|
14
|
+
program must perform its own locking if JSON values are shared by
|
15
|
+
multiple threads. Jansson's reference counting semantics may make this
|
16
|
+
a bit harder than it seems, as it's possible to have a reference to a
|
17
|
+
value that's also stored inside a list or object. Modifying the
|
18
|
+
container (adding or removing values) may trigger concurrent access to
|
19
|
+
such values, as containers manage the reference count of their
|
20
|
+
contained values. Bugs involving concurrent incrementing or
|
21
|
+
decrementing of deference counts may be hard to track.
|
22
|
+
|
23
|
+
The encoding functions (:func:`json_dumps()` and friends) track
|
24
|
+
reference loops by modifying the internal state of objects and arrays.
|
25
|
+
For this reason, encoding functions must not be run on the same JSON
|
26
|
+
values in two separate threads at the same time. As already noted
|
27
|
+
above, be especially careful if two arrays or objects share their
|
28
|
+
contained values with another array or object.
|
29
|
+
|
30
|
+
If you want to make sure that two JSON value hierarchies do not
|
31
|
+
contain shared values, use :func:`json_deep_copy()` to make copies.
|
32
|
+
|
33
|
+
Locale
|
34
|
+
------
|
35
|
+
|
36
|
+
Jansson works fine under any locale.
|
37
|
+
|
38
|
+
However, if the host program is multithreaded and uses ``setlocale()``
|
39
|
+
to switch the locale in one thread while Jansson is currently encoding
|
40
|
+
or decoding JSON data in another thread, the result may be wrong or
|
41
|
+
the program may even crash.
|
42
|
+
|
43
|
+
Jansson uses locale specific functions for certain string conversions
|
44
|
+
in the encoder and decoder, and then converts the locale specific
|
45
|
+
values to/from the JSON representation. This fails if the locale
|
46
|
+
changes between the string conversion and the locale-to-JSON
|
47
|
+
conversion. This can only happen in multithreaded programs that use
|
48
|
+
``setlocale()``, because ``setlocale()`` switches the locale for all
|
49
|
+
running threads, not only the thread that calls ``setlocale()``.
|
50
|
+
|
51
|
+
If your program uses ``setlocale()`` as described above, consider
|
52
|
+
using the thread-safe ``uselocale()`` instead.
|
@@ -0,0 +1,286 @@
|
|
1
|
+
.. _tutorial:
|
2
|
+
|
3
|
+
********
|
4
|
+
Tutorial
|
5
|
+
********
|
6
|
+
|
7
|
+
.. highlight:: c
|
8
|
+
|
9
|
+
In this tutorial, we create a program that fetches the latest commits
|
10
|
+
of a repository in GitHub_ over the web. `GitHub API`_ uses JSON, so
|
11
|
+
the result can be parsed using Jansson.
|
12
|
+
|
13
|
+
To stick to the the scope of this tutorial, we will only cover the the
|
14
|
+
parts of the program related to handling JSON data. For the best user
|
15
|
+
experience, the full source code is available:
|
16
|
+
:download:`github_commits.c`. To compile it (on Unix-like systems with
|
17
|
+
gcc), use the following command::
|
18
|
+
|
19
|
+
gcc -o github_commits github_commits.c -ljansson -lcurl
|
20
|
+
|
21
|
+
libcurl_ is used to communicate over the web, so it is required to
|
22
|
+
compile the program.
|
23
|
+
|
24
|
+
The command line syntax is::
|
25
|
+
|
26
|
+
github_commits USER REPOSITORY
|
27
|
+
|
28
|
+
``USER`` is a GitHub user ID and ``REPOSITORY`` is the repository
|
29
|
+
name. Please note that the GitHub API is rate limited, so if you run
|
30
|
+
the program too many times within a short period of time, the sever
|
31
|
+
starts to respond with an error.
|
32
|
+
|
33
|
+
.. _GitHub: https://github.com/
|
34
|
+
.. _GitHub API: http://developer.github.com/
|
35
|
+
.. _libcurl: http://curl.haxx.se/
|
36
|
+
|
37
|
+
|
38
|
+
.. _tutorial-github-commits-api:
|
39
|
+
|
40
|
+
The GitHub Repo Commits API
|
41
|
+
===========================
|
42
|
+
|
43
|
+
The `GitHub Repo Commits API`_ is used by sending HTTP requests to
|
44
|
+
URLs like ``https://api.github.com/repos/USER/REPOSITORY/commits``,
|
45
|
+
where ``USER`` and ``REPOSITORY`` are the GitHub user ID and the name
|
46
|
+
of the repository whose commits are to be listed, respectively.
|
47
|
+
|
48
|
+
GitHub responds with a JSON array of the following form:
|
49
|
+
|
50
|
+
.. code-block:: none
|
51
|
+
|
52
|
+
[
|
53
|
+
{
|
54
|
+
"sha": "<the commit ID>",
|
55
|
+
"commit": {
|
56
|
+
"message": "<the commit message>",
|
57
|
+
<more fields, not important to this tutorial...>
|
58
|
+
},
|
59
|
+
<more fields...>
|
60
|
+
},
|
61
|
+
{
|
62
|
+
"sha": "<the commit ID>",
|
63
|
+
"commit": {
|
64
|
+
"message": "<the commit message>",
|
65
|
+
<more fields...>
|
66
|
+
},
|
67
|
+
<more fields...>
|
68
|
+
},
|
69
|
+
<more commits...>
|
70
|
+
]
|
71
|
+
|
72
|
+
In our program, the HTTP request is sent using the following
|
73
|
+
function::
|
74
|
+
|
75
|
+
static char *request(const char *url);
|
76
|
+
|
77
|
+
It takes the URL as a parameter, preforms a HTTP GET request, and
|
78
|
+
returns a newly allocated string that contains the response body. If
|
79
|
+
the request fails, an error message is printed to stderr and the
|
80
|
+
return value is *NULL*. For full details, refer to :download:`the code
|
81
|
+
<github_commits.c>`, as the actual implementation is not important
|
82
|
+
here.
|
83
|
+
|
84
|
+
.. _GitHub Repo Commits API: http://developer.github.com/v3/repos/commits/
|
85
|
+
|
86
|
+
.. _tutorial-the-program:
|
87
|
+
|
88
|
+
The Program
|
89
|
+
===========
|
90
|
+
|
91
|
+
First the includes::
|
92
|
+
|
93
|
+
#include <string.h>
|
94
|
+
#include <jansson.h>
|
95
|
+
|
96
|
+
Like all the programs using Jansson, we need to include
|
97
|
+
:file:`jansson.h`.
|
98
|
+
|
99
|
+
The following definitions are used to build the GitHub API request
|
100
|
+
URL::
|
101
|
+
|
102
|
+
#define URL_FORMAT "https://api.github.com/repos/%s/%s/commits"
|
103
|
+
#define URL_SIZE 256
|
104
|
+
|
105
|
+
The following function is used when formatting the result to find the
|
106
|
+
first newline in the commit message::
|
107
|
+
|
108
|
+
/* Return the offset of the first newline in text or the length of
|
109
|
+
text if there's no newline */
|
110
|
+
static int newline_offset(const char *text)
|
111
|
+
{
|
112
|
+
const char *newline = strchr(text, '\n');
|
113
|
+
if(!newline)
|
114
|
+
return strlen(text);
|
115
|
+
else
|
116
|
+
return (int)(newline - text);
|
117
|
+
}
|
118
|
+
|
119
|
+
The main function follows. In the beginning, we first declare a bunch
|
120
|
+
of variables and check the command line parameters::
|
121
|
+
|
122
|
+
int main(int argc, char *argv[])
|
123
|
+
{
|
124
|
+
size_t i;
|
125
|
+
char *text;
|
126
|
+
char url[URL_SIZE];
|
127
|
+
|
128
|
+
json_t *root;
|
129
|
+
json_error_t error;
|
130
|
+
|
131
|
+
if(argc != 3)
|
132
|
+
{
|
133
|
+
fprintf(stderr, "usage: %s USER REPOSITORY\n\n", argv[0]);
|
134
|
+
fprintf(stderr, "List commits at USER's REPOSITORY.\n\n");
|
135
|
+
return 2;
|
136
|
+
}
|
137
|
+
|
138
|
+
Then we build the request URL using the user and repository names
|
139
|
+
given as command line parameters::
|
140
|
+
|
141
|
+
snprintf(url, URL_SIZE, URL_FORMAT, argv[1], argv[2]);
|
142
|
+
|
143
|
+
This uses the ``URL_SIZE`` and ``URL_FORMAT`` constants defined above.
|
144
|
+
Now we're ready to actually request the JSON data over the web::
|
145
|
+
|
146
|
+
text = request(url);
|
147
|
+
if(!text)
|
148
|
+
return 1;
|
149
|
+
|
150
|
+
If an error occurs, our function ``request`` prints the error and
|
151
|
+
returns *NULL*, so it's enough to just return 1 from the main
|
152
|
+
function.
|
153
|
+
|
154
|
+
Next we'll call :func:`json_loads()` to decode the JSON text we got
|
155
|
+
as a response::
|
156
|
+
|
157
|
+
root = json_loads(text, 0, &error);
|
158
|
+
free(text);
|
159
|
+
|
160
|
+
if(!root)
|
161
|
+
{
|
162
|
+
fprintf(stderr, "error: on line %d: %s\n", error.line, error.text);
|
163
|
+
return 1;
|
164
|
+
}
|
165
|
+
|
166
|
+
We don't need the JSON text anymore, so we can free the ``text``
|
167
|
+
variable right after decoding it. If :func:`json_loads()` fails, it
|
168
|
+
returns *NULL* and sets error information to the :type:`json_error_t`
|
169
|
+
structure given as the second parameter. In this case, our program
|
170
|
+
prints the error information out and returns 1 from the main function.
|
171
|
+
|
172
|
+
Now we're ready to extract the data out of the decoded JSON response.
|
173
|
+
The structure of the response JSON was explained in section
|
174
|
+
:ref:`tutorial-github-commits-api`.
|
175
|
+
|
176
|
+
We check that the returned value really is an array::
|
177
|
+
|
178
|
+
if(!json_is_array(root))
|
179
|
+
{
|
180
|
+
fprintf(stderr, "error: root is not an array\n");
|
181
|
+
json_decref(root);
|
182
|
+
return 1;
|
183
|
+
}
|
184
|
+
|
185
|
+
Then we proceed to loop over all the commits in the array::
|
186
|
+
|
187
|
+
for(i = 0; i < json_array_size(root); i++)
|
188
|
+
{
|
189
|
+
json_t *data, *sha, *commit, *message;
|
190
|
+
const char *message_text;
|
191
|
+
|
192
|
+
data = json_array_get(root, i);
|
193
|
+
if(!json_is_object(data))
|
194
|
+
{
|
195
|
+
fprintf(stderr, "error: commit data %d is not an object\n", i + 1);
|
196
|
+
json_decref(root);
|
197
|
+
return 1;
|
198
|
+
}
|
199
|
+
...
|
200
|
+
|
201
|
+
The function :func:`json_array_size()` returns the size of a JSON
|
202
|
+
array. First, we again declare some variables and then extract the
|
203
|
+
i'th element of the ``root`` array using :func:`json_array_get()`.
|
204
|
+
We also check that the resulting value is a JSON object.
|
205
|
+
|
206
|
+
Next we'll extract the commit ID (a hexadecimal SHA-1 sum),
|
207
|
+
intermediate commit info object, and the commit message from that
|
208
|
+
object. We also do proper type checks::
|
209
|
+
|
210
|
+
sha = json_object_get(data, "sha");
|
211
|
+
if(!json_is_string(sha))
|
212
|
+
{
|
213
|
+
fprintf(stderr, "error: commit %d: sha is not a string\n", i + 1);
|
214
|
+
json_decref(root);
|
215
|
+
return 1;
|
216
|
+
}
|
217
|
+
|
218
|
+
commit = json_object_get(data, "commit");
|
219
|
+
if(!json_is_object(commit))
|
220
|
+
{
|
221
|
+
fprintf(stderr, "error: commit %d: commit is not an object\n", i + 1);
|
222
|
+
json_decref(root);
|
223
|
+
return 1;
|
224
|
+
}
|
225
|
+
|
226
|
+
message = json_object_get(commit, "message");
|
227
|
+
if(!json_is_string(message))
|
228
|
+
{
|
229
|
+
fprintf(stderr, "error: commit %d: message is not a string\n", i + 1);
|
230
|
+
json_decref(root);
|
231
|
+
return 1;
|
232
|
+
}
|
233
|
+
...
|
234
|
+
|
235
|
+
And finally, we'll print the first 8 characters of the commit ID and
|
236
|
+
the first line of the commit message. A C-style string is extracted
|
237
|
+
from a JSON string using :func:`json_string_value()`::
|
238
|
+
|
239
|
+
message_text = json_string_value(message);
|
240
|
+
printf("%.8s %.*s\n",
|
241
|
+
json_string_value(id),
|
242
|
+
newline_offset(message_text),
|
243
|
+
message_text);
|
244
|
+
}
|
245
|
+
|
246
|
+
After sending the HTTP request, we decoded the JSON text using
|
247
|
+
:func:`json_loads()`, remember? It returns a *new reference* to the
|
248
|
+
JSON value it decodes. When we're finished with the value, we'll need
|
249
|
+
to decrease the reference count using :func:`json_decref()`. This way
|
250
|
+
Jansson can release the resources::
|
251
|
+
|
252
|
+
json_decref(root);
|
253
|
+
return 0;
|
254
|
+
|
255
|
+
For a detailed explanation of reference counting in Jansson, see
|
256
|
+
:ref:`apiref-reference-count` in :ref:`apiref`.
|
257
|
+
|
258
|
+
The program's ready, let's test it and view the latest commits in
|
259
|
+
Jansson's repository::
|
260
|
+
|
261
|
+
$ ./github_commits akheron jansson
|
262
|
+
1581f26a Merge branch '2.3'
|
263
|
+
aabfd493 load: Change buffer_pos to be a size_t
|
264
|
+
bd72efbd load: Avoid unexpected behaviour in macro expansion
|
265
|
+
e8fd3e30 Document and tweak json_load_callback()
|
266
|
+
873eddaf Merge pull request #60 from rogerz/contrib
|
267
|
+
bd2c0c73 Ignore the binary test_load_callback
|
268
|
+
17a51a4b Merge branch '2.3'
|
269
|
+
09c39adc Add json_load_callback to the list of exported symbols
|
270
|
+
cbb80baf Merge pull request #57 from rogerz/contrib
|
271
|
+
040bd7b0 Add json_load_callback()
|
272
|
+
2637faa4 Make test stripping locale independent
|
273
|
+
<...>
|
274
|
+
|
275
|
+
|
276
|
+
Conclusion
|
277
|
+
==========
|
278
|
+
|
279
|
+
In this tutorial, we implemented a program that fetches the latest
|
280
|
+
commits of a GitHub repository using the GitHub Repo Commits API.
|
281
|
+
Jansson was used to decode the JSON response and to extract the commit
|
282
|
+
data.
|
283
|
+
|
284
|
+
This tutorial only covered a small part of Jansson. For example, we
|
285
|
+
did not create or manipulate JSON values at all. Proceed to
|
286
|
+
:ref:`apiref` to explore all features of Jansson.
|