#include #include #include #include #include #include "json.h" #include "storage.h" #include "util.h" typedef enum { TABULAR = 0, GEOJSON, CSV, JSON, RAW, } output_type; void csv_output(JsonNode *json, output_type otype) { JsonNode *arr, *one, *j; time_t tst = 0L; double lat = 0.0, lon = 0.0; char *tid = "", *addr; if (otype == CSV) { printf("tst,tid,lat,lon,addr\n"); } arr = json_find_member(json, "locations"); json_foreach(one, arr) { tid = addr = ""; lat = lon = 0.0; if ((j = json_find_member(one, "tid")) != NULL) { tid = j->string_; } if ((j = json_find_member(one, "addr")) != NULL) { addr = j->string_; } if ((j = json_find_member(one, "tst")) != NULL) { tst = j->number_; } if ((j = json_find_member(one, "lat")) != NULL) { lat = j->number_; } if ((j = json_find_member(one, "lon")) != NULL) { lon = j->number_; } if (otype == CSV) { printf("%s,%s,%lf,%lf,%s\n", isotime(tst), tid, lat, lon, addr); } else { printf("%s %-2.2s %9.5lf %9.5lf %s\n", isotime(tst), tid, lat, lon, addr); } } } void usage(char *prog) { printf("Usage: %s [options..] [file ...]\n", prog); printf(" --help -h this message\n"); printf(" --list -l list users (or a user's (-u) devices\n"); printf(" --user username -u specify username\n"); printf(" --device devicename -d specify device name\n"); printf(" --from