summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--handler.h34
-rw-r--r--pikul.c8
2 files changed, 21 insertions, 21 deletions
diff --git a/handler.h b/handler.h
index 3a38831..7b2ac90 100644
--- a/handler.h
+++ b/handler.h
@@ -23,34 +23,34 @@ inline void handle_services(const char *contents, size_t num_bytes, const char *
recurse(response, status_trail, &status);
if (json_object_get_int(status) != 200)
return;
- struct json_object *objects = NULL;
- recurse(response, trail, &objects);
- size_t length = json_object_array_length(objects);
+ struct json_object *array = NULL;
+ recurse(response, trail, &array);
+ size_t length = json_object_array_length(array);
*services = malloc(sizeof(struct pikul_services) + sizeof(struct pikul_service *[length]));
(*services)->length = length;
enum { CODE, NAME, ETD, COST };
for (size_t i = 0; i < length; i++) {
(*services)->list[i] = malloc(sizeof(struct pikul_service));
struct pikul_service *service = (*services)->list[i];
- json_object *object = json_object_array_get_idx(objects, i);
+ json_object *object = json_object_array_get_idx(array, i);
struct json_object_iterator iterator = json_object_iter_begin(object);
struct json_object_iterator iterator_end = json_object_iter_end(object);
while (!json_object_iter_equal(&iterator, &iterator_end)) {
- const char *key = json_object_iter_peek_name(&iterator);
- json_object *val = json_object_iter_peek_value(&iterator);
- if (!strcmp(key, attributes[COST]))
- service->cost = json_object_get_double(val);
+ const char *name = json_object_iter_peek_name(&iterator);
+ json_object *value = json_object_iter_peek_value(&iterator);
+ if (!strcmp(name, attributes[COST]))
+ service->cost = json_object_get_double(value);
else {
- int len = json_object_get_string_len(val);
+ int len = json_object_get_string_len(value);
if (len) {
- char *value = malloc(len + 1);
- strcpy(value, json_object_get_string(val));
- if (!strcmp(key, attributes[CODE]))
- service->code = value;
- else if (!strcmp(key, attributes[NAME]))
- service->name = value;
- else if (!strcmp(key, attributes[ETD]))
- service->etd = value;
+ char *string = malloc(len + 1);
+ strcpy(string, json_object_get_string(value));
+ if (!strcmp(name, attributes[CODE]))
+ service->code = string;
+ else if (!strcmp(name, attributes[NAME]))
+ service->name = string;
+ else if (!strcmp(name, attributes[ETD]))
+ service->etd = string;
}
}
json_object_iter_next(&iterator);
diff --git a/pikul.c b/pikul.c
index 94ef6fb..8e657b8 100644
--- a/pikul.c
+++ b/pikul.c
@@ -32,12 +32,12 @@ void pikul_init(enum pikul_company company, char *provisions[])
tokener = json_tokener_new();
}
-void recurse(struct json_object *outer, const char *keys[], struct json_object **last)
+void recurse(struct json_object *outer, const char *trail[], struct json_object **last)
{
struct json_object *inner = NULL;
- json_object_object_get_ex(outer, *keys, &inner);
- if (*++keys)
- recurse(inner, keys, last);
+ json_object_object_get_ex(outer, *trail, &inner);
+ if (*++trail)
+ recurse(inner, trail, last);
else
*last = inner;
}