From 8d561cd94e3bd6ed496eac9bffd4b221e37d4207 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Tue, 30 Dec 2014 08:44:36 +0200 Subject: [PATCH] examples/simple_parse.c: Reindent, fix warnings & style --- examples/simple_parse.c | 169 +++++++++++++++++++++------------------- 1 file changed, 88 insertions(+), 81 deletions(-) diff --git a/examples/simple_parse.c b/examples/simple_parse.c index 945cf0f..044337b 100644 --- a/examples/simple_parse.c +++ b/examples/simple_parse.c @@ -15,7 +15,7 @@ * JSON Object of 1 pair: * JSON Key: "name" * JSON String: "barney" - * + * * Copyright (c) 2014 Robert Poor * * Jansson is free software; you can redistribute it and/or modify @@ -24,7 +24,7 @@ #include #include -#include "jansson.h" +#include /* forward refs */ void print_json(json_t *root); @@ -41,119 +41,126 @@ void print_json_false(json_t *element, int indent); void print_json_null(json_t *element, int indent); void print_json(json_t *root) { - print_json_aux(root, 0); + print_json_aux(root, 0); } void print_json_aux(json_t *element, int indent) { - switch json_typeof(element) { + switch (json_typeof(element)) { case JSON_OBJECT: - print_json_object(element, indent); - break; + print_json_object(element, indent); + break; case JSON_ARRAY: - print_json_array(element, indent); - break; + print_json_array(element, indent); + break; case JSON_STRING: - print_json_string(element, indent); - break; + print_json_string(element, indent); + break; case JSON_INTEGER: - print_json_integer(element, indent); - break; + print_json_integer(element, indent); + break; case JSON_REAL: - print_json_real(element, indent); - break; + print_json_real(element, indent); + break; case JSON_TRUE: - print_json_true(element, indent); - break; + print_json_true(element, indent); + break; case JSON_FALSE: - print_json_false(element, indent); - break; + print_json_false(element, indent); + break; case JSON_NULL: - print_json_null(element, indent); - break; + print_json_null(element, indent); + break; default: - fprintf(stderr, "unrecognized JSON type %d\n", json_typeof(element)); + fprintf(stderr, "unrecognized JSON type %d\n", json_typeof(element)); } } void print_json_indent(int indent) { - for (int i=0; i "); - fflush(stdout); - return fgets(line, max_chars, stdin); + printf("Type some JSON > "); + fflush(stdout); + return fgets(line, max_chars, stdin); } /* ================================================================ @@ -173,24 +180,24 @@ char *read_line(char *line, int max_chars) { #define MAX_CHARS 4096 int main(int argc, char *argv[]) { - char line[MAX_CHARS]; - - if (argc != 1) { - fprintf(stderr, "Usage: %s\n", argv[0]); - exit(-1); - } + char line[MAX_CHARS]; - while (read_line(line, MAX_CHARS) != (char *)NULL) { - - /* parse text into JSON structure */ - json_t *root = load_json(line); - - if (root) { - /* print and release the JSON structure */ - print_json(root); - json_decref(root); + if (argc != 1) { + fprintf(stderr, "Usage: %s\n", argv[0]); + exit(-1); } - } - return 0; + while (read_line(line, MAX_CHARS) != (char *)NULL) { + + /* parse text into JSON structure */ + json_t *root = load_json(line); + + if (root) { + /* print and release the JSON structure */ + print_json(root); + json_decref(root); + } + } + + return 0; }