Skip to content

Commit

Permalink
move "number" to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan-Piet Mens committed May 31, 2017
1 parent c14e963 commit 58d54ee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
21 changes: 0 additions & 21 deletions recorder.c
Expand Up @@ -66,27 +66,6 @@

static int run = 1;

double number(JsonNode *j, char *element)
{
JsonNode *m;
double d;

if ((m = json_find_member(j, element)) != NULL) {
if (m->tag == JSON_NUMBER) {
return (m->number_);
} else if (m->tag == JSON_STRING) {
d = atof(m->string_);
/* Normalize to number */
json_remove_from_parent(m);
json_delete(m);
json_append_member(j, element, json_mknumber(d));
return (d);
}
}

return (NAN);
}

static const char *ltime(time_t t) {
static char buf[] = "HH:MM:SS";

Expand Down
21 changes: 21 additions & 0 deletions util.c
Expand Up @@ -617,3 +617,24 @@ void chomp(char *s)
*p-- = 0;
}
}

double number(JsonNode *j, char *element)
{
JsonNode *m;
double d;

if ((m = json_find_member(j, element)) != NULL) {
if (m->tag == JSON_NUMBER) {
return (m->number_);
} else if (m->tag == JSON_STRING) {
d = atof(m->string_);
/* Normalize to number */
json_remove_from_parent(m);
json_delete(m);
json_append_member(j, element, json_mknumber(d));
return (d);
}
}

return (NAN);
}
2 changes: 2 additions & 0 deletions util.h
Expand Up @@ -8,6 +8,7 @@

#include <time.h>
#include <syslog.h>
#include <math.h>
#include "json.h"
#include "udata.h"
#include "utstring.h"
Expand Down Expand Up @@ -38,5 +39,6 @@ void lowercase(char *s);
double haversine_dist(double th1, double ph1, double th2, double ph2);
void debug(struct udata *, char *fmt, ...);
void chomp(char *s);
double number(JsonNode *j, char *element);

#endif

0 comments on commit 58d54ee

Please sign in to comment.