From: Eric S. Raymond Date: Thu, 25 Sep 2014 19:42:18 +0000 (-0400) Subject: Remove time support until we figure out what's up with mkgmtime(). X-Git-Tag: 1.0~5 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=d189b4e18d3ebe236785027ccf4aa4f85d441989;p=microjson.git Remove time support until we figure out what's up with mkgmtime(). --- diff --git a/mjson.c b/mjson.c index 4ba83f3..cd28ec5 100644 --- a/mjson.c +++ b/mjson.c @@ -28,8 +28,8 @@ will match the right spec against the actual data. The dialect this parses has some limitations. First, it cannot recognize the JSON "null" value. Second, all elements of an array must -be of the same type. Third, some types (t_time, t_character) may not -be array elements (this restriction could be lifted) +be of the same type. Third, characters may not be array elements (this +restriction could be lifted) There are separate entry points for beginning a parse of either JSON object or a JSON array. JSON "float" quantities are actually @@ -109,51 +109,6 @@ static void json_trace(int errlevel, const char *fmt, ...) # define json_debug_trace(args) /*@i1@*/do { } while (0) #endif /* DEBUG_ENABLE */ -#define MONTHSPERYEAR 12 /* months per calendar year */ - -static time_t mkutctime(register struct tm * t) -/* struct tm to seconds since Unix epoch */ -{ - register int year; - register time_t result; - static const int cumdays[MONTHSPERYEAR] = - { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; - - /*@ +matchanyintegral @*/ - year = 1900 + t->tm_year + t->tm_mon / MONTHSPERYEAR; - result = (year - 1970) * 365 + cumdays[t->tm_mon % MONTHSPERYEAR]; - result += (year - 1968) / 4; - result -= (year - 1900) / 100; - result += (year - 1600) / 400; - if ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0) && - (t->tm_mon % MONTHSPERYEAR) < 2) - result--; - result += t->tm_mday - 1; - result *= 24; - result += t->tm_hour; - result *= 60; - result += t->tm_min; - result *= 60; - result += t->tm_sec; - /*@ -matchanyintegral @*/ - return (result); -} - -static double iso8601_to_unix(/*@in@*/const char *isotime) -/* ISO8601 UTC to Unix UTC */ -{ - char *dp = NULL; - double usec; - struct tm tm; - - /*@i1@*/ dp = strptime(isotime, "%Y-%m-%dT%H:%M:%S", &tm); - if (dp != NULL && *dp == '.') - usec = strtod(dp, NULL); - else - usec = 0; - return mkutctime(&tm) + usec; -} - /*@-immediatetrans -dependenttrans -usereleased -compdef@*/ static /*@null@*/ char *json_target_address(const struct json_attr_t *cursor, /*@null@*/ @@ -173,7 +128,6 @@ static /*@null@*/ char *json_target_address(const struct json_attr_t *cursor, case t_uinteger: targetaddr = (char *)&cursor->addr.uinteger[offset]; break; - case t_time: case t_real: targetaddr = (char *)&cursor->addr.real[offset]; break; @@ -251,7 +205,6 @@ static int json_internal_read_object(const char *cp, case t_uinteger: memcpy(lptr, &cursor->dflt.uinteger, sizeof(unsigned int)); break; - case t_time: case t_real: memcpy(lptr, &cursor->dflt.real, sizeof(double)); break; @@ -332,7 +285,7 @@ static int json_internal_read_object(const char *cp, maxlen = (int)cursor->len - 1; else if (cursor->type == t_check) maxlen = (int)strlen(cursor->dflt.check); - else if (cursor->type == t_time || cursor->type == t_ignore) + else if (cursor->type == t_ignore) maxlen = JSON_VAL_MAX; else if (cursor->map != NULL) maxlen = (int)sizeof(valbuf) - 1; @@ -445,7 +398,7 @@ static int json_internal_read_object(const char *cp, */ for (;;) { int seeking = cursor->type; - if (value_quoted && (cursor->type == t_string || cursor->type == t_time)) + if (value_quoted && cursor->type == t_string) break; if ((strcmp(valbuf, "true")==0 || strcmp(valbuf, "false")==0) && seeking == t_boolean) @@ -465,7 +418,7 @@ static int json_internal_read_object(const char *cp, } if (value_quoted && (cursor->type != t_string && cursor->type != t_character - && cursor->type != t_check && cursor->type != t_time + && cursor->type != t_check && cursor->type != t_ignore && cursor->map == 0)) { json_debug_trace((1, "Saw quoted value when expecting non-string.\n")); @@ -473,7 +426,7 @@ static int json_internal_read_object(const char *cp, } if (!value_quoted && (cursor->type == t_string || cursor->type == t_check - || cursor->type == t_time || cursor->map != 0)) { + || cursor->map != 0)) { json_debug_trace((1, "Didn't see quoted value when expecting string.\n")); return JSON_ERR_NONQSTRING; @@ -504,12 +457,6 @@ static int json_internal_read_object(const char *cp, memcpy(lptr, &tmp, sizeof(unsigned int)); } break; - case t_time: - { - double tmp = iso8601_to_unix(valbuf); - memcpy(lptr, &tmp, sizeof(double)); - } - break; case t_real: { double tmp = atof(valbuf); @@ -675,7 +622,6 @@ int json_read_array(const char *cp, const struct json_array_t *arr, cp += 5; } break; - case t_time: case t_character: case t_array: case t_check: diff --git a/test_microjson.c b/test_microjson.c index 0660bf9..042f14e 100644 --- a/test_microjson.c +++ b/test_microjson.c @@ -142,10 +142,6 @@ static int json_tpv_read(const char *buf, struct gps_data_t *gpsdata, {"class", t_check, .dflt.check = "TPV"}, {"device", t_string, .addr.string = gpsdata->dev.path, .len = sizeof(gpsdata->dev.path)}, - {"time", t_time, .addr.real = &gpsdata->fix.time, - .dflt.real = NAN}, - {"time", t_real, .addr.real = &gpsdata->fix.time, - .dflt.real = NAN}, {"ept", t_real, .addr.real = &gpsdata->fix.ept, .dflt.real = NAN}, {"lon", t_real, .addr.real = &gpsdata->fix.longitude, @@ -202,10 +198,6 @@ static int json_sky_read(const char *buf, struct gps_data_t *gpsdata, {"class", t_check, .dflt.check = "SKY"}, {"device", t_string, .addr.string = gpsdata->dev.path, .len = sizeof(gpsdata->dev.path)}, - {"time", t_time, .addr.real = &gpsdata->skyview_time, - .dflt.real = NAN}, - {"time", t_real, .addr.real = &gpsdata->skyview_time, - .dflt.real = NAN}, {"hdop", t_real, .addr.real = &gpsdata->dop.hdop, .dflt.real = NAN}, {"xdop", t_real, .addr.real = &gpsdata->dop.xdop, @@ -263,7 +255,6 @@ static int json_devicelist_read(const char *buf, struct gps_data_t *gpsdata, {"class", t_check, .dflt.check = "DEVICE"}, {"path", t_string, STRUCTOBJECT(struct devconfig_t, path), .len = sizeof(gpsdata->devices.list[0].path)}, - {"activated", t_time, STRUCTOBJECT(struct devconfig_t, activated)}, {"activated", t_real, STRUCTOBJECT(struct devconfig_t, activated)}, {"flags", t_integer, STRUCTOBJECT(struct devconfig_t, flags)}, {"driver", t_string, STRUCTOBJECT(struct devconfig_t, driver), @@ -484,13 +475,12 @@ static void assert_real(char *attr, double fld, double check) /* *INDENT-OFF* */ static const char json_str1[] = "{\"class\":\"TPV\",\ \"device\":\"GPS#1\", \ - \"time\":\"2005-06-19T08:12:41.89Z\",\"lon\":46.498203637,\"lat\":7.568074350,\ + \"lon\":46.498203637,\"lat\":7.568074350,\ \"alt\":1327.780,\"epx\":21.000,\"epy\":23.000,\"epv\":124.484,\"mode\":3}"; /* Case 2: SKY report */ static const char *json_str2 = "{\"class\":\"SKY\",\ - \"time\":\"2005-06-19T12:12:42.03Z\", \ \"satellites\":[\ {\"PRN\":10,\"el\":45,\"az\":196,\"ss\":34,\"used\":true},\ {\"PRN\":29,\"el\":67,\"az\":310,\"ss\":40,\"used\":true},\ @@ -664,7 +654,6 @@ static void jsontest(int i) assert_case(1, status); assert_string("device", gpsdata.dev.path, "GPS#1"); assert_integer("mode", gpsdata.fix.mode, 3); - assert_real("time", gpsdata.fix.time, 1119168761.8900001); assert_real("lon", gpsdata.fix.longitude, 46.498203637); assert_real("lat", gpsdata.fix.latitude, 7.568074350); break;