Skip to content

Commit cd1c7ff

Browse files
committed
bin/xbps-create: use process_dict() for alternatives too
1 parent ad88254 commit cd1c7ff

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

bin/xbps-create/main.c

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,55 @@ process_array(const char *key, const char *val, bool (*validate)(const char *s))
233233
xbps_object_release(array);
234234
}
235235

236+
static void
237+
process_keyval_array(const char *prop, const char *keyval, const char delim,
238+
bool (*validate_key)(const char *),
239+
bool (*validate_val)(const char *)) {
240+
xbps_dictionary_t d;
241+
xbps_array_t a;
242+
char *key, *valstr;
243+
bool alloc = false;
244+
245+
if ((d = xbps_dictionary_get(pkg_propsd, prop)) == NULL) {
246+
d = xbps_dictionary_create();
247+
if (d == NULL)
248+
die("xbps_dictionary_create");
249+
alloc = true;
250+
}
251+
252+
key = strdup(keyval);
253+
if (key == NULL)
254+
die("strdup");
255+
valstr = strchr(key, delim);
256+
*valstr = '\0';
257+
valstr = valstr + 1;
258+
assert(valstr);
259+
260+
printf("%s: %s = %s with delim %c\n", prop, key, valstr, delim);
261+
262+
if (validate_key && !validate_key(key)) {
263+
diex("%s: invalid key: %s", prop, key);
264+
}
265+
266+
if ((a = xbps_dictionary_get(d, key)) == NULL) {
267+
a = xbps_array_create();
268+
if (a == NULL)
269+
die("xbps_array_create");
270+
}
271+
272+
if (validate_val && !validate_val(valstr)) {
273+
diex("%s: invalid value: %s", prop, valstr);
274+
}
275+
276+
xbps_array_add_cstring(a, valstr);
277+
xbps_dictionary_set(d, key, a);
278+
xbps_dictionary_set(pkg_propsd, prop, d);
279+
if (alloc) {
280+
xbps_object_release(a);
281+
xbps_object_release(d);
282+
}
283+
}
284+
236285
static void
237286
process_keyval_uint64(const char *prop, const char *keyval, const char delim,
238287
bool (*validate_key)(const char *),
@@ -344,7 +393,6 @@ process_one_alternative(const char *altgrname, const char *val)
344393
}
345394
}
346395

347-
348396
static void
349397
process_dict_of_arrays(const char *key UNUSED, const char *val)
350398
{
@@ -1162,7 +1210,7 @@ main(int argc, char **argv)
11621210
process_array("reverts", reverts, NULL);
11631211
process_array("shlib-provides", shlib_provides, NULL);
11641212
process_array("shlib-requires", shlib_requires, NULL);
1165-
process_dict_of_arrays("alternatives", alternatives);
1213+
process_dict("alternatives", alternatives, ':', process_keyval_array, NULL, NULL);
11661214

11671215
/* save cwd */
11681216
memset(&cwd, 0, sizeof(cwd));

0 commit comments

Comments
 (0)