From 65b5c1dad4d5981b581b07fe9e1fc5978baf9dbf Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Tue, 15 Sep 2015 19:38:34 +0200 Subject: [PATCH] support CSV output closes #22 --- ocat.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/ocat.c b/ocat.c index 698e811..4d12fdd 100644 --- a/ocat.c +++ b/ocat.c @@ -377,13 +377,24 @@ int main(int argc, char **argv) JsonNode *user_array; if ((user_array = last_users(username, device)) != NULL) { - char *js; - if ((js = json_stringify(user_array, JSON_INDENT)) != NULL) { - printf("%s\n", js); - free(js); + if (otype == JSON) { + char *js; + if ((js = json_stringify(user_array, JSON_INDENT)) != NULL) { + printf("%s\n", js); + free(js); + } + json_delete(user_array); + } else if (otype == CSV) { + JsonNode *o = json_mkobject(); + + json_append_member(o, "locations", user_array); + csv_output(o, CSV, fields); + json_delete(o); + + } else { + fprintf(stderr, "%s: unsupported output type for LAST\n", progname); } - json_delete(user_array); } return (0); }