X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fjson_out%2F_info;fp=ccan%2Fjson_out%2F_info;h=fbb4fa56783c3428f2b461826e66c71d06c2fc31;hb=2fd44331077429da94f8f7eb43513068257742f8;hp=0000000000000000000000000000000000000000;hpb=3ceb24bf19adbe59bf8aeda9cc1426b4ba2244c2;p=ccan diff --git a/ccan/json_out/_info b/ccan/json_out/_info new file mode 100644 index 00000000..fbb4fa56 --- /dev/null +++ b/ccan/json_out/_info @@ -0,0 +1,82 @@ +#include "config.h" +#include +#include + +/** + * json_out - Code for creating simple JSON output. + * + * This code helps you create well-formed JSON strings. + * + * Author: Rusty Russell + * License: BSD-MIT + * + * Example: + * // Given "a 1 true" outputs {"argv1":"a","argv2":1,"argv3":true} + * // Print arguments as a JSON array. + * #include + * #include + * #include + * #include + * + * // Simplistic test to see if str needs quotes. + * static bool can_be_json_literal(const char *str) + * { + * char *endp; + * if (strtol(str, &endp, 10) != LONG_MIN + * && endp != str + * && *endp == '\0') + * return true; + * return !strcmp(str, "true") + * || !strcmp(str, "false") + * || !strcmp(str, "null"); + * } + * + * int main(int argc, char *argv[]) + * { + * struct json_out *jout = json_out_new(NULL); + * size_t len; + * const char *p; + * + * json_out_start(jout, NULL, '{'); + * for (int i = 1; i < argc; i++) { + * char fieldname[80]; + * sprintf(fieldname, "argv%i", i); + * json_out_add(jout, fieldname, + * !can_be_json_literal(argv[i]), + * "%s", argv[i]); + * } + * json_out_end(jout, '}'); + * // Force appending of \n + * json_out_direct(jout, 1)[0] = '\n'; + * json_out_finished(jout); + * + * // Now write it out. + * while ((p = json_out_contents(jout, &len)) != NULL) { + * int i = write(STDOUT_FILENO, p, len); + * if (i <= 0) + * exit(1); + * json_out_consume(jout, i); + * } + * + * tal_free(jout); + * return 0; + * } + * + */ +int main(int argc, char *argv[]) +{ + /* Expect exactly one argument */ + if (argc != 2) + return 1; + + if (strcmp(argv[1], "depends") == 0) { + printf("ccan/compiler\n"); + printf("ccan/json_escape\n"); + printf("ccan/membuf\n"); + printf("ccan/tal\n"); + printf("ccan/typesafe_cb\n"); + return 0; + } + + return 1; +}