assert(out_fd >= 0);
assert(item);
- const char *const title = item->fields[INI_FIELD_TITLE];
- const char *const path = item->fields[INI_FIELD_PATH];
- const char *const args = item->fields[INI_FIELD_ARGS] ?: "";
- const char *const env = item->fields[INI_FIELD_ENV] ?: "";
- const char *const flag = item->fields[INI_FIELD_FLAG];
+ char *const title = item->fields[INI_FIELD_TITLE];
+ char *const path = item->fields[INI_FIELD_PATH];
+ char *const args = item->fields[INI_FIELD_ARGS] ?: "";
+ char *const env = item->fields[INI_FIELD_ENV] ?: "";
++ char *const flag = item->fields[INI_FIELD_FLAG];
+
+ if (!check_cmdflag(flag, argc, argv))
+ return 0;
if (!title || !path) {
fprintf_fd(out_fd, "\nNo title or path in extra program config");
return 0;
}
- typedef int (*handle_ini_section_t)(int out_fd, struct extra_dump_item *);
+ typedef int (*handle_ini_section_t)(int out_fd, struct extra_dump_item *, int argc, char **argv);
- static int handle_ini_Nth_section(int out_fd, dictionary *ini, int n, handle_ini_section_t handle_ini_section)
-static int handle_ini_Nth_section(struct extra_dump_item *item, const dictionary *ini, int n)
++static int handle_ini_Nth_section(struct extra_dump_item *item, dictionary *ini, int n)
{
- assert(out_fd >= 0);
+ assert(item);
assert(ini);
assert(n >= 0);
assert(n < iniparser_getnsec(ini));
- assert(handle_ini_section);
- const char *const secname = iniparser_getsecname(ini, n);
+ char *const secname = iniparser_getsecname(ini, n);
assert(secname); // can only be NULL if `ini` is NULL or `n` is outta bounds
const size_t secname_len = strlen(secname);
memcpy(key_buf, secname, secname_len);
key_buf[secname_len] = ':';
- char *const key_suffix_ptr = key_buf + secname_len + 1;
- struct extra_dump_item item;
- for (size_t i = 0; i < ARRAY_SIZE(item.fields); ++i) {
+ int ret = 0;
- char *const key_suffix_ptr = key_buf + secname_len + 1;
++ char *key_suffix_ptr = key_buf + secname_len + 1;
+ for (size_t i = 0; i < ARRAY_SIZE(item->fields); ++i) {
strcpy(key_suffix_ptr, INI_KEYS[i]);
- item.fields[i] = iniparser_getstring(ini, key_buf, NULL);
+
- const char *tmp = iniparser_getstring(ini, key_buf, NULL);
++ char *tmp = iniparser_getstring(ini, key_buf, NULL);
+ if (!tmp) {
+ item->fields[i] = NULL;
+ continue;
+ }
+
+ item->fields[i] = strdup(tmp);
+ if (!item->fields[i])
+ ret |= EXIT_ERR;
}
- return handle_ini_section(out_fd, &item);
+ strcpy(key_suffix_ptr, "order");
- const char *tmp = iniparser_getstring(ini, key_buf, NULL);
++ char *tmp = iniparser_getstring(ini, key_buf, NULL);
+ item->order = tmp ? atoi(tmp) : INT_MAX;
+
+ return ret;
}
- static int handle_extra_ini(int out_fd, const char *ini_path, handle_ini_section_t handle_ini_section)
+ static int handle_extra_ini(int out_fd, struct extra_items_vector *eiv, const char *ini_path)
{
assert(out_fd >= 0);
+ assert(eiv);
assert(ini_path);
- assert(handle_ini_section);
__attribute__((cleanup(cleanup_dictionary))) dictionary *ini = iniparser_load(ini_path);
if (!ini) {