89
/* Dump a set of attributes */
91
lu_ent_dump_attributes(GArray *attrs, FILE *fp)
95
for (i = 0; i < attrs->len; i++) {
96
struct lu_attribute *attribute;
99
attribute = &g_array_index(attrs, struct lu_attribute, i);
100
for (j = 0; j < attribute->values->n_values; j++) {
103
value = g_value_array_get_nth(attribute->values, j);
104
fprintf(fp, " %s = ",
105
g_quark_to_string(attribute->name));
106
if (G_VALUE_HOLDS_STRING(value))
107
fprintf(fp, "`%s'\n",
108
g_value_get_string(value));
109
else if (G_VALUE_HOLDS_LONG(value))
110
fprintf(fp, "%ld\n", g_value_get_long(value));
111
else if (G_VALUE_HOLDS_INT64(value))
112
fprintf(fp, "%lld\n",
113
(long long)g_value_get_int64(value));
115
fprintf(fp, "???\n");
93
120
/* Dump the contents of an entity structure. This is primarily for
96
123
lu_ent_dump(struct lu_ent *ent, FILE *fp)
99
struct lu_attribute *attribute;
101
127
g_return_if_fail(ent != NULL);
102
128
fprintf(fp, "dump of struct lu_ent at %p:\n", ent);
103
129
fprintf(fp, " magic = %08x\n", ent->magic);
120
146
/* Print the module list. */
121
147
fprintf(fp, " modules = (");
122
148
for (i = 0; i < ent->modules->n_values; i++) {
123
151
value = g_value_array_get_nth(ent->modules, i);
125
153
fprintf(fp, ", ");
127
154
if (G_VALUE_HOLDS_STRING(value))
128
155
fprintf(fp, "`%s'", g_value_get_string(value));
129
else if (G_VALUE_HOLDS_LONG(value))
130
fprintf(fp, "%ld", g_value_get_long(value));
131
else if (G_VALUE_HOLDS_INT64(value))
133
(long long)g_value_get_int64(value));
135
157
fprintf(fp, "?");
137
159
fprintf(fp, ")\n");
138
160
/* Print the current data values. */
139
for (i = 0; i < ent->current->len; i++) {
140
attribute = &g_array_index(ent->current,
143
for (j = 0; j < attribute->values->n_values; j++) {
144
value = g_value_array_get_nth(attribute->values, j);
145
if (G_VALUE_HOLDS_STRING(value))
146
fprintf(fp, " %s = `%s'\n",
147
g_quark_to_string(attribute->name),
148
g_value_get_string(value));
149
else if (G_VALUE_HOLDS_LONG(value))
150
fprintf(fp, " %s = %ld\n",
151
g_quark_to_string(attribute->name),
152
g_value_get_long(value));
154
else if (G_VALUE_HOLDS_INT64(value))
155
fprintf(fp, " %s = %lld\n",
156
g_quark_to_string(attribute->name),
157
(long long)g_value_get_int64(value));
161
lu_ent_dump_attributes(ent->current, fp);
161
162
fprintf(fp, "\n");
162
for (i = 0; i < ent->pending->len; i++) {
163
attribute = &g_array_index(ent->pending,
166
for (j = 0; j < attribute->values->n_values; j++) {
167
value = g_value_array_get_nth(attribute->values, j);
168
if (G_VALUE_HOLDS_STRING(value))
169
fprintf(fp, " %s = `%s'\n",
170
g_quark_to_string(attribute->name),
171
g_value_get_string(value));
172
else if (G_VALUE_HOLDS_LONG(value))
173
fprintf(fp, " %s = %ld\n",
174
g_quark_to_string(attribute->name),
175
g_value_get_long(value));
176
else if (G_VALUE_HOLDS_INT64(value))
177
fprintf(fp, " %s = %lld\n",
178
g_quark_to_string(attribute->name),
179
(long long)g_value_get_int64(value));
163
lu_ent_dump_attributes(ent->pending, fp);
184
166
/* Add a module to the list of modules kept for this entity. */
186
168
lu_ent_add_module(struct lu_ent *ent, const char *source)
190
172
g_return_if_fail(ent != NULL);
191
173
g_return_if_fail(ent->magic == LU_ENT_MAGIC);
192
174
g_return_if_fail(ent->modules != NULL);
193
/* Initialize a value with the string. */
194
memset(&value, 0, sizeof(value));
195
g_value_init(&value, G_TYPE_STRING);
196
g_value_set_string(&value, source);
197
/* Now scan the array for the value. */
198
175
for (i = 0; i < ent->modules->n_values; i++) {
202
179
/* We only add strings, so there had better be only strings
203
180
* in this list, otherwise someone is messing with us. */
204
181
g_assert(G_VALUE_HOLDS_STRING(val));
205
if (strcmp(g_value_get_string(val),
206
g_value_get_string(&value)) == 0) {
182
if (strcmp(g_value_get_string(val), source) == 0)
210
185
/* If we fell of the end of the array, then the new value is not
211
186
* in there, so we should add it. */
212
187
if (i >= ent->modules->n_values) {
190
/* Initialize a value with the string. */
191
memset(&value, 0, sizeof(value));
192
g_value_init(&value, G_TYPE_STRING);
193
g_value_set_string(&value, source);
213
194
g_value_array_append(ent->modules, &value);
195
g_value_unset(&value);
215
g_value_unset(&value);
218
199
/* Clear the list of modules which affect this module, by freeing the array
443
424
g_return_if_fail(strlen(attr) > 0);
444
425
dest = lu_ent_get_int(list, attr);
445
426
if (dest != NULL) {
448
svalue = g_strdup_value_contents(value);
449
427
for (i = 0; i < dest->n_values; i++) {
453
430
tvalue = g_value_array_get_nth(dest, i);
454
tmp = g_strdup_value_contents(tvalue);
455
if (strcmp(tmp, svalue) == 0) {
431
if (G_VALUE_TYPE(value) == G_VALUE_TYPE(tvalue)
432
&& lu_values_equal(value, tvalue))
462
435
if (i < dest->n_values) {
463
436
g_value_array_remove(dest, i);
464
437
if (dest->n_values == 0)