mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Add framework for UDDF importer
There are several sample UDDF files around on the net, so we might as well start importing some of it. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
0e3bbd4102
commit
4d19f42a4e
1 changed files with 25 additions and 3 deletions
28
parse-xml.c
28
parse-xml.c
|
@ -70,12 +70,17 @@ static int match(const char *pattern, int plen,
|
||||||
static struct units {
|
static struct units {
|
||||||
enum { METERS, FEET } length;
|
enum { METERS, FEET } length;
|
||||||
enum { LITER, CUFT } volume;
|
enum { LITER, CUFT } volume;
|
||||||
enum { BAR, PSI } pressure;
|
enum { BAR, PSI, PASCAL } pressure;
|
||||||
enum { CELSIUS, FAHRENHEIT } temperature;
|
enum { CELSIUS, FAHRENHEIT, KELVIN } temperature;
|
||||||
enum { KG, LBS } weight;
|
enum { KG, LBS } weight;
|
||||||
} units;
|
} units;
|
||||||
|
|
||||||
/* We're going to default to SI units for input */
|
/*
|
||||||
|
* We're going to default to SI units for input. Yes,
|
||||||
|
* technically the SI unit for pressure is Pascal, but
|
||||||
|
* we default to bar (10^5 pascal), which people
|
||||||
|
* actually use. Similarly, C instead of Kelvin.
|
||||||
|
*/
|
||||||
static const struct units SI_units = {
|
static const struct units SI_units = {
|
||||||
.length = METERS,
|
.length = METERS,
|
||||||
.volume = LITER,
|
.volume = LITER,
|
||||||
|
@ -99,6 +104,7 @@ static enum import_source {
|
||||||
SUUNTO,
|
SUUNTO,
|
||||||
UEMIS,
|
UEMIS,
|
||||||
DIVINGLOG,
|
DIVINGLOG,
|
||||||
|
UDDF,
|
||||||
} import_source;
|
} import_source;
|
||||||
|
|
||||||
static time_t utc_mktime(struct tm *tm)
|
static time_t utc_mktime(struct tm *tm)
|
||||||
|
@ -238,6 +244,9 @@ static void pressure(char *buffer, void *_press)
|
||||||
if (!val.fp)
|
if (!val.fp)
|
||||||
break;
|
break;
|
||||||
switch (units.pressure) {
|
switch (units.pressure) {
|
||||||
|
case PASCAL:
|
||||||
|
mbar = val.fp / 100;
|
||||||
|
break;
|
||||||
case BAR:
|
case BAR:
|
||||||
/* Assume mbar, but if it's really small, it's bar */
|
/* Assume mbar, but if it's really small, it's bar */
|
||||||
mbar = val.fp;
|
mbar = val.fp;
|
||||||
|
@ -293,6 +302,9 @@ static void temperature(char *buffer, void *_temperature)
|
||||||
break;
|
break;
|
||||||
/* Celsius */
|
/* Celsius */
|
||||||
switch (units.temperature) {
|
switch (units.temperature) {
|
||||||
|
case KELVIN:
|
||||||
|
temperature->mkelvin = val.fp * 1000;
|
||||||
|
break;
|
||||||
case CELSIUS:
|
case CELSIUS:
|
||||||
temperature->mkelvin = (val.fp + 273.15) * 1000 + 0.5;
|
temperature->mkelvin = (val.fp + 273.15) * 1000 + 0.5;
|
||||||
break;
|
break;
|
||||||
|
@ -1171,6 +1183,14 @@ static void DivingLog_importer(void)
|
||||||
units.pressure = PSI;
|
units.pressure = PSI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void uddf_importer(void)
|
||||||
|
{
|
||||||
|
import_source = UDDF;
|
||||||
|
units = SI_units;
|
||||||
|
units.pressure = PASCAL;
|
||||||
|
units.temperature = KELVIN;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* I'm sure this could be done as some fancy DTD rules.
|
* I'm sure this could be done as some fancy DTD rules.
|
||||||
* It's just not worth the headache.
|
* It's just not worth the headache.
|
||||||
|
@ -1182,6 +1202,7 @@ static struct nesting {
|
||||||
{ "dive", dive_start, dive_end },
|
{ "dive", dive_start, dive_end },
|
||||||
{ "Dive", dive_start, dive_end },
|
{ "Dive", dive_start, dive_end },
|
||||||
{ "sample", sample_start, sample_end },
|
{ "sample", sample_start, sample_end },
|
||||||
|
{ "waypoint", sample_start, sample_end },
|
||||||
{ "SAMPLE", sample_start, sample_end },
|
{ "SAMPLE", sample_start, sample_end },
|
||||||
{ "reading", sample_start, sample_end },
|
{ "reading", sample_start, sample_end },
|
||||||
{ "event", event_start, event_end },
|
{ "event", event_start, event_end },
|
||||||
|
@ -1193,6 +1214,7 @@ static struct nesting {
|
||||||
{ "SUUNTO", suunto_importer },
|
{ "SUUNTO", suunto_importer },
|
||||||
{ "Divinglog", DivingLog_importer },
|
{ "Divinglog", DivingLog_importer },
|
||||||
{ "pre_dive", uemis_importer },
|
{ "pre_dive", uemis_importer },
|
||||||
|
{ "uddf", uddf_importer },
|
||||||
|
|
||||||
{ NULL, }
|
{ NULL, }
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue