From 91f0a91fc5e24aadece59764da630cfdc1d4967e Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Sun, 23 Aug 2015 10:59:17 +0200 Subject: [PATCH] add -f raw mode --- ocat.c | 10 ++++++++-- storage.c | 7 ++++++- storage.h | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ocat.c b/ocat.c index ea8d74b..aaa698d 100644 --- a/ocat.c +++ b/ocat.c @@ -12,6 +12,7 @@ typedef enum { GEOJSON, CSV, JSON, + RAW, } output_type; void csv_output(JsonNode *json, output_type otype) @@ -85,6 +86,7 @@ void usage(char *prog) printf(" --format json -f output format (default: JSON)\n"); printf(" csv\n"); printf(" geojson\n"); + printf(" raw\n"); printf(" tabular\n"); exit(1); @@ -143,6 +145,8 @@ int main(int argc, char **argv) otype = TABULAR; else if (!strcmp(optarg, "geojson")) otype = GEOJSON; + else if (!strcmp(optarg, "raw")) + otype = RAW; else if (!strcmp(optarg, "csv")) otype = CSV; else { @@ -217,7 +221,7 @@ int main(int argc, char **argv) int n; for (n = 0; n < argc; n++) { - locations(argv[n], obj, locs, s_lo, s_hi); + locations(argv[n], obj, locs, s_lo, s_hi, (otype == RAW) ? 1 : 0); } } else { JsonNode *arr, *f; @@ -226,7 +230,7 @@ int main(int argc, char **argv) if ((arr = json_find_member(json, "results")) != NULL) { // get array json_foreach(f, arr) { // fprintf(stderr, "%s\n", f->string_); - locations(f->string_, obj, locs, s_lo, s_hi); + locations(f->string_, obj, locs, s_lo, s_hi, (otype == RAW) ? 1 : 0); } } json_delete(json); @@ -248,6 +252,8 @@ int main(int argc, char **argv) csv_output(obj, TABULAR); } else if (otype == CSV) { csv_output(obj, CSV); + } else if (otype == RAW) { + /* We've already done what we need to do in locations() */ } else if (otype == GEOJSON) { JsonNode *geojson = geo_json(locs); char *js; diff --git a/storage.c b/storage.c index dbd596b..a67aabc 100644 --- a/storage.c +++ b/storage.c @@ -264,7 +264,7 @@ JsonNode *lister(char *user, char *device, time_t s_lo, time_t s_hi) * contains `arr'. */ -void locations(char *filename, JsonNode *obj, JsonNode *arr, time_t s_lo, time_t s_hi) +void locations(char *filename, JsonNode *obj, JsonNode *arr, time_t s_lo, time_t s_hi, int rawmode) { JsonNode *o, *json, *j; FILE *fp; @@ -314,6 +314,11 @@ void locations(char *filename, JsonNode *obj, JsonNode *arr, time_t s_lo, time_t continue; } + if (rawmode) { + printf("%s", buf); + continue; + } + if ((bp = strstr(buf, "Z\t* ")) != NULL) { if ((bp = strrchr(bp, '\t')) == NULL) { continue; diff --git a/storage.h b/storage.h index 69af01d..aba3c1c 100644 --- a/storage.h +++ b/storage.h @@ -6,7 +6,7 @@ JsonNode *lister(char *username, char *device, time_t s_lo, time_t s_hi); -void locations(char *filename, JsonNode *obj, JsonNode *arr, time_t s_lo, time_t s_hi); +void locations(char *filename, JsonNode *obj, JsonNode *arr, time_t s_lo, time_t s_hi, int rawmode); int make_times(char *time_from, time_t *s_lo, char *time_to, time_t *s_to); JsonNode *geo_json(JsonNode *json);