Use dynamic indexing instead of hard coded

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
This commit is contained in:
Miika Turkia 2018-01-07 14:58:17 +02:00 committed by mturkia
parent d23600eb9e
commit 9cf013235c

View file

@ -76,6 +76,7 @@ int parse_dan_format(const char *filename, char **params, int pnr)
while ((end_ptr < mem.size) && (ptr = strstr(mem.buffer + end_ptr, "ZDH"))) { while ((end_ptr < mem.size) && (ptr = strstr(mem.buffer + end_ptr, "ZDH"))) {
char *iter_end = NULL; char *iter_end = NULL;
unsigned int pnr_local = pnr;
/* /*
* Process the dives, but let the last round be parsed * Process the dives, but let the last round be parsed
@ -93,8 +94,8 @@ int parse_dan_format(const char *filename, char **params, int pnr)
if (iter) { if (iter) {
memcpy(tmpbuf, ptr + 4, iter - ptr - 4); memcpy(tmpbuf, ptr + 4, iter - ptr - 4);
tmpbuf[iter - ptr - 4] = 0; tmpbuf[iter - ptr - 4] = 0;
params[pnr] = "diveNro"; params[pnr_local++] = "diveNro";
params[pnr + 1] = strdup(tmpbuf); params[pnr_local++] = strdup(tmpbuf);
} }
//fprintf(stderr, "DEBUG: BEGIN end_ptr %d round %d <%s>\n", end_ptr, j++, ptr); //fprintf(stderr, "DEBUG: BEGIN end_ptr %d round %d <%s>\n", end_ptr, j++, ptr);
@ -113,8 +114,8 @@ int parse_dan_format(const char *filename, char **params, int pnr)
/* Setting date */ /* Setting date */
memcpy(tmpbuf, iter, 8); memcpy(tmpbuf, iter, 8);
tmpbuf[8] = 0; tmpbuf[8] = 0;
params[pnr + 2] = "date"; params[pnr_local++] = "date";
params[pnr + 3] = strdup(tmpbuf); params[pnr_local++] = strdup(tmpbuf);
/* Setting time, gotta prepend it with 1 to /* Setting time, gotta prepend it with 1 to
* avoid octal parsing (this is stripped out in * avoid octal parsing (this is stripped out in
@ -122,9 +123,8 @@ int parse_dan_format(const char *filename, char **params, int pnr)
tmpbuf[0] = '1'; tmpbuf[0] = '1';
memcpy(tmpbuf + 1, iter + 8, 6); memcpy(tmpbuf + 1, iter + 8, 6);
tmpbuf[7] = 0; tmpbuf[7] = 0;
params[pnr + 4] = "time"; params[pnr_local++] = "time";
params[pnr + 5] = strdup(tmpbuf); params[pnr_local++] = strdup(tmpbuf);
params[pnr + 6] = NULL;
/* Air temperature */ /* Air temperature */
memset(tmpbuf, 0, sizeof(tmpbuf)); memset(tmpbuf, 0, sizeof(tmpbuf));
@ -136,12 +136,11 @@ int parse_dan_format(const char *filename, char **params, int pnr)
if (iter_end) { if (iter_end) {
memcpy(tmpbuf, iter, iter_end - iter); memcpy(tmpbuf, iter, iter_end - iter);
params[pnr + 6] = "airTemp"; params[pnr_local++] = "airTemp";
params[pnr + 7] = strdup(tmpbuf); params[pnr_local++] = strdup(tmpbuf);
params[pnr + 8] = NULL;
} }
} }
params[pnr_local] = NULL;
/* Search for the next line */ /* Search for the next line */
if (iter) if (iter)