2005-02-20 14:27:00 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "array.h"
|
|
|
|
|
|
|
|
static void data_array_free(data_unset *d) {
|
|
|
|
data_array *ds = (data_array *)d;
|
|
|
|
|
|
|
|
buffer_free(ds->key);
|
|
|
|
array_free(ds->value);
|
|
|
|
|
|
|
|
free(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void data_array_reset(data_unset *d) {
|
|
|
|
data_array *ds = (data_array *)d;
|
|
|
|
|
|
|
|
/* reused array elements */
|
|
|
|
buffer_reset(ds->key);
|
|
|
|
array_reset(ds->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int data_array_insert_dup(data_unset *dst, data_unset *src) {
|
|
|
|
UNUSED(dst);
|
|
|
|
|
|
|
|
src->free(src);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-08 10:16:53 +00:00
|
|
|
static void data_array_print(data_unset *d, int depth) {
|
2005-02-20 14:27:00 +00:00
|
|
|
data_array *ds = (data_array *)d;
|
2005-08-08 10:16:53 +00:00
|
|
|
|
|
|
|
array_print_indent(depth);
|
|
|
|
fprintf(stderr, "{%s:\n", ds->key->ptr);
|
|
|
|
array_print(ds->value, depth + 1);
|
|
|
|
array_print_indent(depth);
|
|
|
|
fprintf(stderr, "}");
|
2005-02-20 14:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data_array *data_array_init(void) {
|
|
|
|
data_array *ds;
|
|
|
|
|
|
|
|
ds = calloc(1, sizeof(*ds));
|
|
|
|
|
|
|
|
ds->key = buffer_init();
|
|
|
|
ds->value = array_init();
|
|
|
|
|
|
|
|
ds->free = data_array_free;
|
|
|
|
ds->reset = data_array_reset;
|
|
|
|
ds->insert_dup = data_array_insert_dup;
|
|
|
|
ds->print = data_array_print;
|
|
|
|
ds->type = TYPE_ARRAY;
|
|
|
|
|
|
|
|
return ds;
|
|
|
|
}
|