mirror of
https://github.com/owntracks/recorder.git
synced 2026-08-23 11:26:16 +00:00
move "number" to utils
This commit is contained in:
-21
@@ -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";
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <time.h>
|
||||
#include <syslog.h>
|
||||
#include <math.h>
|
||||
#include "json.h"
|
||||
#include "udata.h"
|
||||
#include "utstring.h"
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user