Example #1
0
static void sample_parser(char *line, struct divecomputer *dc)
{
	int m, s = 0;
	struct sample *sample = new_sample(dc);

	m = strtol(line, &line, 10);
	if (*line == ':')
		s = strtol(line+1, &line, 10);
	sample->time.seconds = m*60+s;

	for (;;) {
		char c;

		while (isspace(c = *line))
			line++;
		if (!c)
			break;
		/* Less common sample entries have a name */
		if (c >= 'a' && c <= 'z') {
			line = parse_keyvalue_entry(parse_sample_keyvalue, sample, line);
		} else {
			const char *end;
			double val = ascii_strtod(line, &end);
			if (end == line) {
				report_error("Odd sample data: %s", line);
				break;
			}
			line = (char *)end;
			line = parse_sample_unit(sample, val, line);
		}
	}
	finish_sample(dc);
}
Example #2
0
static void parse_dc_event(char *line, struct membuffer *str, void *_dc)
{
	int m, s = 0;
	const char *name;
	struct divecomputer *dc = _dc;
	struct event event = { 0 };

	m = strtol(line, &line, 10);
	if (*line == ':')
		s = strtol(line+1, &line, 10);
	event.time.seconds = m*60+s;

	for (;;) {
		char c;
		while (isspace(c = *line))
			line++;
		if (!c)
			break;
		line = parse_keyvalue_entry(parse_event_keyvalue, &event, line);
	}

	name = "";
	if (str->len)
		name = mb_cstring(str);
	add_event(dc, event.time.seconds, event.type, event.flags, event.value, name);
}
Example #3
0
static void parse_dive_weightsystem(char *line, struct membuffer *str, void *_dive)
{
	struct dive *dive = _dive;
	weightsystem_t *ws = dive->weightsystem + weightsystem_index;

	weightsystem_index++;
	ws->description = get_utf8(str);
	for (;;) {
		char c;
		while (isspace(c = *line))
			line++;
		if (!c)
			break;
		line = parse_keyvalue_entry(parse_weightsystem_keyvalue, ws, line);
	}
}
Example #4
0
static void parse_dive_cylinder(char *line, struct membuffer *str, void *_dive)
{
	struct dive *dive = _dive;
	cylinder_t *cylinder = dive->cylinder + cylinder_index;

	cylinder_index++;
	cylinder->type.description = get_utf8(str);
	for (;;) {
		char c;
		while (isspace(c = *line))
			line++;
		if (!c)
			break;
		line = parse_keyvalue_entry(parse_cylinder_keyvalue, cylinder, line);
	}
}
Example #5
0
static void parse_dc_event(char *line, struct membuffer *str, void *_dc)
{
	int m, s = 0;
	const char *name;
	struct divecomputer *dc = _dc;
	struct event event = { 0 }, *ev;

	m = strtol(line, &line, 10);
	if (*line == ':')
		s = strtol(line+1, &line, 10);
	event.time.seconds = m*60+s;

	for (;;) {
		char c;
		while (isspace(c = *line))
			line++;
		if (!c)
			break;
		line = parse_keyvalue_entry(parse_event_keyvalue, &event, line);
	}

	name = "";
	if (str->len)
		name = mb_cstring(str);
	ev = add_event(dc, event.time.seconds, event.type, event.flags, event.value, name);

	/*
	 * Older logs might mark the dive to be CCR by having an "SP change" event at time 0:00.
	 * Better to mark them being CCR on import so no need for special treatments elsewhere on
	 * the code.
	 */
	if (ev && event.time.seconds == 0 && event.type == SAMPLE_EVENT_PO2 && dc->divemode==OC) {
		dc->divemode = CCR;
	}

	if (ev && event_is_gaschange(ev)) {
		/*
		 * We subtract one here because "0" is "no index",
		 * and the parsing will add one for actual cylinder
		 * index data (see parse_event_keyvalue)
		 */
		ev->gas.index = event.gas.index-1;
		if (event.gas.mix.o2.permille || event.gas.mix.he.permille)
			ev->gas.mix = event.gas.mix;
	}
}
Example #6
0
/*
 * The 'divecomputerid' is a bit harder to parse than some other things, because
 * it can have multiple strings (but see the tag parsing for another example of
 * that) in addition to the non-string entries.
 *
 * We keep the "next" string in "id.cstr" and update it as we use it.
 */
static void parse_settings_divecomputerid(char *line, struct membuffer *str, void *_unused)
{
	struct divecomputerid id = { mb_cstring(str) };

	id.cstr = id.model + strlen(id.model) + 1;

	/* Skip the '"' that stood for the model string */
	line++;

	for (;;) {
		char c;
		while (isspace(c = *line))
			line++;
		if (!c)
			break;
		line = parse_keyvalue_entry(parse_divecomputerid_keyvalue, &id, line);
	}
	create_device_node(id.model, id.deviceid, id.serial, id.firmware, id.nickname);
}
Example #7
0
static void parse_dc_event(char *line, struct membuffer *str, void *_dc)
{
	int m, s = 0;
	const char *name;
	struct divecomputer *dc = _dc;
	struct event event = { 0 }, *ev;

	m = strtol(line, &line, 10);
	if (*line == ':')
		s = strtol(line+1, &line, 10);
	event.time.seconds = m*60+s;

	for (;;) {
		char c;
		while (isspace(c = *line))
			line++;
		if (!c)
			break;
		line = parse_keyvalue_entry(parse_event_keyvalue, &event, line);
	}

	name = "";
	if (str->len)
		name = mb_cstring(str);
	ev = add_event(dc, event.time.seconds, event.type, event.flags, event.value, name);
	if (ev && event_is_gaschange(ev)) {
		/*
		 * We subtract one here because "0" is "no index",
		 * and the parsing will add one for actual cylinder
		 * index data (see parse_event_keyvalue)
		 */
		ev->gas.index = event.gas.index-1;
		if (event.gas.mix.o2.permille || event.gas.mix.he.permille)
			ev->gas.mix = event.gas.mix;
	}
}