mirror of
https://github.com/owntracks/recorder.git
synced 2026-04-09 00:36:50 +00:00
add -f raw mode
This commit is contained in:
10
ocat.c
10
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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user