summaryrefslogtreecommitdiffstats
path: root/parse-xml.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-09-12 12:56:34 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-09-12 12:56:34 -0700
commitaa416e3c96dfa53db5ae277e72f6a03821c45cac (patch)
treed0adaa4ac077f64fa08e084348281c49821ff3fe /parse-xml.c
parentd45db9fac7b3d2ea0426a96158432f54d938f5c7 (diff)
downloadsubsurface-aa416e3c96dfa53db5ae277e72f6a03821c45cac.tar.gz
Abstract out dive/sample allocation a bit
We're going to start to want to allocate dives and samples for the libdivecomputer import too, so let's clean things up a bit for that. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'parse-xml.c')
-rw-r--r--parse-xml.c32
1 files changed, 4 insertions, 28 deletions
diff --git a/parse-xml.c b/parse-xml.c
index d17f7a8ee..4d6912e72 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -16,7 +16,7 @@ struct dive_table dive_table;
/*
* Add a dive into the dive_table array
*/
-static void record_dive(struct dive *dive)
+void record_dive(struct dive *dive)
{
int nr = dive_table.nr, allocated = dive_table.allocated;
struct dive **dives = dive_table.dives;
@@ -90,7 +90,6 @@ const struct units IMPERIAL_units = {
/*
* Dive info as it is being built up..
*/
-static int alloc_samples;
static struct dive *dive;
static struct sample *sample;
static struct tm tm;
@@ -984,17 +983,9 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf)
*/
static void dive_start(void)
{
- unsigned int size;
-
if (dive)
return;
-
- alloc_samples = 5;
- size = dive_size(alloc_samples);
- dive = malloc(size);
- if (!dive)
- exit(1);
- memset(dive, 0, size);
+ dive = alloc_dive();
memset(&tm, 0, sizeof(tm));
}
@@ -1143,22 +1134,7 @@ static void cylinder_end(void)
static void sample_start(void)
{
- int nr;
-
- if (!dive)
- return;
- nr = dive->samples;
- if (nr >= alloc_samples) {
- unsigned int size;
-
- alloc_samples = (alloc_samples * 3)/2 + 10;
- size = dive_size(alloc_samples);
- dive = realloc(dive, size);
- if (!dive)
- return;
- }
- sample = dive->sample + nr;
- memset(sample, 0, sizeof(*sample));
+ sample = prepare_sample(&dive);
event_index = 0;
}
@@ -1167,8 +1143,8 @@ static void sample_end(void)
if (!dive)
return;
+ finish_sample(dive, sample);
sample = NULL;
- dive->samples++;
}
static void entry(const char *name, int size, const char *raw)