2 Copyright (c) 2012 Frank Lahm <franklahm@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
17 #endif /* HAVE_CONFIG_H */
27 #include <atalk/errchk.h>
28 #include <atalk/util.h>
29 #include <atalk/logger.h>
30 #include <atalk/talloc.h>
31 #include <atalk/bstrlib.h>
33 #include "spotlight.h"
37 static const char *neststrings[] = {
47 static int dd_dump(DALLOC_CTX *dd, int nestinglevel)
51 printf("%sArray(#%d): {\n", neststrings[nestinglevel], talloc_array_length(dd->dd_talloc_array));
53 for (int n = 0; n < talloc_array_length(dd->dd_talloc_array); n++) {
55 type = talloc_get_name(dd->dd_talloc_array[n]);
57 if (STRCMP(type, ==, "int64_t")) {
59 memcpy(&i, dd->dd_talloc_array[n], sizeof(int64_t));
60 printf("%s%d:\t%" PRId64 "\n", neststrings[nestinglevel + 1], n, i);
61 } else if (STRCMP(type, ==, "uint32_t")) {
63 memcpy(&i, dd->dd_talloc_array[n], sizeof(uint32_t));
64 printf("%s%d:\t%" PRIu32 "\n", neststrings[nestinglevel + 1], n, i);
65 } else if (STRCMP(type, ==, "char *")) {
67 memcpy(&s, dd->dd_talloc_array[n], sizeof(char *));
68 printf("%s%d:\t%s\n", neststrings[nestinglevel + 1], n, s);
69 } else if (STRCMP(type, ==, "_Bool")) {
71 memcpy(&bl, dd->dd_talloc_array[n], sizeof(bool));
72 printf("%s%d:\t%s\n", neststrings[nestinglevel + 1], n, bl ? "true" : "false");
73 } else if (STRCMP(type, ==, "dd_t")) {
75 memcpy(&nested, dd->dd_talloc_array[n], sizeof(DALLOC_CTX *));
76 dd_dump(nested, nestinglevel + 1);
77 } else if (STRCMP(type, ==, "cnid_array_t")) {
79 memcpy(&cnids, dd->dd_talloc_array[n], sizeof(cnid_array_t *));
80 printf("%s%d:\tunkn1: %" PRIu16 ", unkn2: %" PRIu32,
81 neststrings[nestinglevel + 1], n, cnids->ca_unkn1, cnids->ca_unkn2);
83 dd_dump(cnids->ca_cnids, nestinglevel + 1);
86 printf("%s}\n", neststrings[nestinglevel]);
91 int main(int argc, char **argv)
93 TALLOC_CTX *mem_ctx = talloc_new(NULL);
94 DALLOC_CTX *dd = talloc_zero(mem_ctx, DALLOC_CTX);
97 set_processname("spot");
98 setuplog("default:info", "/dev/tty");
100 LOG(logtype_default, log_info, "Start");
103 dalloc_add(dd, &i, int64_t);
106 dalloc_add(dd, &i, int64_t);
109 char *str = talloc_strdup(dd, "hello world");
110 dalloc_add(dd, &str, char *);
113 dalloc_add(dd, &b, bool);
116 dalloc_add(dd, &b, bool);
119 /* add a nested array */
120 DALLOC_CTX *nested = talloc_zero(dd, DALLOC_CTX);
122 dalloc_add(nested, &i, int64_t);
123 dalloc_add(dd, &nested, DALLOC_CTX);
125 /* test a CNID array */
127 cnid_array_t *cnids = talloc_zero(dd, cnid_array_t);
129 cnids->ca_cnids = talloc_zero(cnids, DALLOC_CTX);
134 dalloc_add(cnids->ca_cnids, &id, uint32_t);
135 dalloc_add(dd, &cnids, cnid_array_t);
139 talloc_free(mem_ctx);