2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
17 #include "attr_store.h"
19 #include "attr_store_p.h"
22 dump_attrs (Attrstore *s, unsigned int entry)
25 FOR_ATTRS (s, entry, &ai)
27 fprintf (stdout, "%s:", id2str (s->pool, ai.name));
31 fprintf (stdout, "int %u\n", ai.as_int);
35 const char *str = attr_retrieve_blob (s, ai.as_chunk[0], ai.as_chunk[1]);
37 fprintf (stdout, "blob %s\n", str);
39 fprintf (stdout, "blob %u+%u\n", ai.as_chunk[0], ai.as_chunk[1]);
42 case TYPE_ATTR_STRING:
43 fprintf (stdout, "str %s\n", ai.as_string);
45 case TYPE_ATTR_INTLIST:
47 fprintf (stdout, "lint\n ");
51 get_num (ai.as_numlist, val);
52 fprintf (stdout, " %d", (val & 63) | ((val >> 1) & ~63));
56 fprintf (stdout, "\n");
59 case TYPE_ATTR_LOCALIDS:
61 fprintf (stdout, "lids");
65 get_num (ai.as_numlist, val);
68 fprintf (stdout, "\n %s(%d)", localid2str (s, val), val);
70 fprintf (stdout, "\n");
74 if (ai.type >= TYPE_ATTR_SPECIAL_START
75 && ai.type <= TYPE_ATTR_SPECIAL_END)
76 fprintf (stdout, "spec %d", ai.type - TYPE_ATTR_SPECIAL_START);
77 fprintf (stdout, "\n");
84 callback (Attrstore *s, unsigned entry, Id name, const char *str)
86 fprintf (stdout, "%d:%s:%s\n", entry, id2str (s->pool, name), str);
91 main (int argc, char *argv[])
94 Pool *pool = pool_create ();
95 Attrstore *s = attr_store_read (stdin, pool);
96 /* For now test the packing code. */
97 attr_store_unpack (s);
99 fprintf (stdout, "attribute store contains %d entities\n", s->entries);
101 for (i = 0; i < s->entries; i++)
103 fprintf (stdout, "\nentity %u:\n", i);
110 unsigned search_type;
114 search_type = SEARCH_SUBSTRING;
115 while ((g = getopt (argc, argv, "-n:bgeri")) >= 0)
118 case 'n': name = str2id (s->pool, optarg, 1); break;
119 case 'b': flags |= SEARCH_BLOBS; break;
120 case 'g': search_type = SEARCH_GLOB; break;
121 case 'e': search_type = SEARCH_STRING; break;
122 case 'r': search_type = SEARCH_REGEX; break;
123 case 'i': flags |= SEARCH_NOCASE; break;
125 attr_store_search_s (s, optarg, search_type | flags, name, callback);
128 search_type = SEARCH_SUBSTRING;