|
Revision 1497, 1.3 kB
(checked in by darix, 21 months ago)
|
|
- merged missing parts of the "print config to stdout" changes
|
-
Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 | #include <string.h> |
|---|
| 2 | #include <stdio.h> |
|---|
| 3 | #include <stdlib.h> |
|---|
| 4 | |
|---|
| 5 | #include "array.h" |
|---|
| 6 | |
|---|
| 7 | static data_unset *data_count_copy(const data_unset *s) { |
|---|
| 8 | data_count *src = (data_count *)s; |
|---|
| 9 | data_count *ds = data_count_init(); |
|---|
| 10 | |
|---|
| 11 | buffer_copy_string_buffer(ds->key, src->key); |
|---|
| 12 | ds->count = src->count; |
|---|
| 13 | ds->is_index_key = src->is_index_key; |
|---|
| 14 | return (data_unset *)ds; |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | static void data_count_free(data_unset *d) { |
|---|
| 18 | data_count *ds = (data_count *)d; |
|---|
| 19 | |
|---|
| 20 | buffer_free(ds->key); |
|---|
| 21 | |
|---|
| 22 | free(d); |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | static void data_count_reset(data_unset *d) { |
|---|
| 26 | data_count *ds = (data_count *)d; |
|---|
| 27 | |
|---|
| 28 | buffer_reset(ds->key); |
|---|
| 29 | |
|---|
| 30 | ds->count = 0; |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | static int data_count_insert_dup(data_unset *dst, data_unset *src) { |
|---|
| 34 | data_count *ds_dst = (data_count *)dst; |
|---|
| 35 | data_count *ds_src = (data_count *)src; |
|---|
| 36 | |
|---|
| 37 | ds_dst->count += ds_src->count; |
|---|
| 38 | |
|---|
| 39 | src->free(src); |
|---|
| 40 | |
|---|
| 41 | return 0; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | static void data_count_print(const data_unset *d, int depth) { |
|---|
| 45 | data_count *ds = (data_count *)d; |
|---|
| 46 | UNUSED(depth); |
|---|
| 47 | |
|---|
| 48 | fprintf(stdout, "count(%d)", ds->count); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | data_count *data_count_init(void) { |
|---|
| 53 | data_count *ds; |
|---|
| 54 | |
|---|
| 55 | ds = calloc(1, sizeof(*ds)); |
|---|
| 56 | |
|---|
| 57 | ds->key = buffer_init(); |
|---|
| 58 | ds->count = 1; |
|---|
| 59 | |
|---|
| 60 | ds->copy = data_count_copy; |
|---|
| 61 | ds->free = data_count_free; |
|---|
| 62 | ds->reset = data_count_reset; |
|---|
| 63 | ds->insert_dup = data_count_insert_dup; |
|---|
| 64 | ds->print = data_count_print; |
|---|
| 65 | ds->type = TYPE_COUNT; |
|---|
| 66 | |
|---|
| 67 | return ds; |
|---|
| 68 | } |
|---|