diff options
Diffstat (limited to 'test/core/json/json_rewrite.c')
-rw-r--r-- | test/core/json/json_rewrite.c | 88 |
1 files changed, 45 insertions, 43 deletions
diff --git a/test/core/json/json_rewrite.c b/test/core/json/json_rewrite.c index dfe32f5adf..3bd50e67b3 100644 --- a/test/core/json/json_rewrite.c +++ b/test/core/json/json_rewrite.c @@ -26,37 +26,39 @@ #include "src/core/lib/json/json_reader.h" #include "src/core/lib/json/json_writer.h" -typedef struct json_writer_userdata { FILE *out; } json_writer_userdata; +typedef struct json_writer_userdata { + FILE* out; +} json_writer_userdata; typedef struct stacked_container { grpc_json_type type; - struct stacked_container *next; + struct stacked_container* next; } stacked_container; typedef struct json_reader_userdata { - FILE *in; - grpc_json_writer *writer; - char *scratchpad; - char *ptr; + FILE* in; + grpc_json_writer* writer; + char* scratchpad; + char* ptr; size_t free_space; size_t allocated; size_t string_len; - stacked_container *top; + stacked_container* top; } json_reader_userdata; -static void json_writer_output_char(void *userdata, char c) { - json_writer_userdata *state = userdata; +static void json_writer_output_char(void* userdata, char c) { + json_writer_userdata* state = userdata; fputc(c, state->out); } -static void json_writer_output_string(void *userdata, const char *str) { - json_writer_userdata *state = userdata; +static void json_writer_output_string(void* userdata, const char* str) { + json_writer_userdata* state = userdata; fputs(str, state->out); } -static void json_writer_output_string_with_len(void *userdata, const char *str, +static void json_writer_output_string_with_len(void* userdata, const char* str, size_t len) { - json_writer_userdata *state = userdata; + json_writer_userdata* state = userdata; fwrite(str, len, 1, state->out); } @@ -64,7 +66,7 @@ grpc_json_writer_vtable writer_vtable = {json_writer_output_char, json_writer_output_string, json_writer_output_string_with_len}; -static void check_string(json_reader_userdata *state, size_t needed) { +static void check_string(json_reader_userdata* state, size_t needed) { if (state->free_space >= needed) return; needed -= state->free_space; needed = (needed + 0xffu) & ~0xffu; @@ -73,20 +75,20 @@ static void check_string(json_reader_userdata *state, size_t needed) { state->allocated += needed; } -static void json_reader_string_clear(void *userdata) { - json_reader_userdata *state = userdata; +static void json_reader_string_clear(void* userdata) { + json_reader_userdata* state = userdata; state->free_space = state->allocated; state->string_len = 0; } -static void json_reader_string_add_char(void *userdata, uint32_t c) { - json_reader_userdata *state = userdata; +static void json_reader_string_add_char(void* userdata, uint32_t c) { + json_reader_userdata* state = userdata; check_string(state, 1); GPR_ASSERT(c < 256); state->scratchpad[state->string_len++] = (char)c; } -static void json_reader_string_add_utf32(void *userdata, uint32_t c) { +static void json_reader_string_add_utf32(void* userdata, uint32_t c) { if (c <= 0x7f) { json_reader_string_add_char(userdata, c); } else if (c <= 0x7ff) { @@ -113,18 +115,18 @@ static void json_reader_string_add_utf32(void *userdata, uint32_t c) { } } -static uint32_t json_reader_read_char(void *userdata) { +static uint32_t json_reader_read_char(void* userdata) { int r; - json_reader_userdata *state = userdata; + json_reader_userdata* state = userdata; r = fgetc(state->in); if (r == EOF) r = GRPC_JSON_READ_CHAR_EOF; return (uint32_t)r; } -static void json_reader_container_begins(void *userdata, grpc_json_type type) { - json_reader_userdata *state = userdata; - stacked_container *container = gpr_malloc(sizeof(stacked_container)); +static void json_reader_container_begins(void* userdata, grpc_json_type type) { + json_reader_userdata* state = userdata; + stacked_container* container = gpr_malloc(sizeof(stacked_container)); container->type = type; container->next = state->top; @@ -133,9 +135,9 @@ static void json_reader_container_begins(void *userdata, grpc_json_type type) { grpc_json_writer_container_begins(state->writer, type); } -static grpc_json_type json_reader_container_ends(void *userdata) { - json_reader_userdata *state = userdata; - stacked_container *container = state->top; +static grpc_json_type json_reader_container_ends(void* userdata) { + json_reader_userdata* state = userdata; + stacked_container* container = state->top; grpc_json_writer_container_ends(state->writer, container->type); state->top = container->next; @@ -143,22 +145,22 @@ static grpc_json_type json_reader_container_ends(void *userdata) { return state->top ? state->top->type : GRPC_JSON_TOP_LEVEL; } -static void json_reader_set_key(void *userdata) { - json_reader_userdata *state = userdata; +static void json_reader_set_key(void* userdata) { + json_reader_userdata* state = userdata; json_reader_string_add_char(userdata, 0); grpc_json_writer_object_key(state->writer, state->scratchpad); } -static void json_reader_set_string(void *userdata) { - json_reader_userdata *state = userdata; +static void json_reader_set_string(void* userdata) { + json_reader_userdata* state = userdata; json_reader_string_add_char(userdata, 0); grpc_json_writer_value_string(state->writer, state->scratchpad); } -static int json_reader_set_number(void *userdata) { - json_reader_userdata *state = userdata; +static int json_reader_set_number(void* userdata) { + json_reader_userdata* state = userdata; grpc_json_writer_value_raw_with_len(state->writer, state->scratchpad, state->string_len); @@ -166,20 +168,20 @@ static int json_reader_set_number(void *userdata) { return 1; } -static void json_reader_set_true(void *userdata) { - json_reader_userdata *state = userdata; +static void json_reader_set_true(void* userdata) { + json_reader_userdata* state = userdata; grpc_json_writer_value_raw_with_len(state->writer, "true", 4); } -static void json_reader_set_false(void *userdata) { - json_reader_userdata *state = userdata; +static void json_reader_set_false(void* userdata) { + json_reader_userdata* state = userdata; grpc_json_writer_value_raw_with_len(state->writer, "false", 5); } -static void json_reader_set_null(void *userdata) { - json_reader_userdata *state = userdata; +static void json_reader_set_null(void* userdata) { + json_reader_userdata* state = userdata; grpc_json_writer_value_raw_with_len(state->writer, "null", 4); } @@ -192,7 +194,7 @@ static grpc_json_reader_vtable reader_vtable = { json_reader_set_number, json_reader_set_true, json_reader_set_false, json_reader_set_null}; -int rewrite(FILE *in, FILE *out, int indent) { +int rewrite(FILE* in, FILE* out, int indent) { grpc_json_writer writer; grpc_json_reader reader; grpc_json_reader_status status; @@ -216,7 +218,7 @@ int rewrite(FILE *in, FILE *out, int indent) { free(reader_user.scratchpad); while (reader_user.top) { - stacked_container *container = reader_user.top; + stacked_container* container = reader_user.top; reader_user.top = container->next; free(container); } @@ -224,9 +226,9 @@ int rewrite(FILE *in, FILE *out, int indent) { return status == GRPC_JSON_DONE; } -int main(int argc, char **argv) { +int main(int argc, char** argv) { int indent = 2; - gpr_cmdline *cl; + gpr_cmdline* cl; cl = gpr_cmdline_create(NULL); gpr_cmdline_add_int(cl, "indent", NULL, &indent); |