#include #include #include #include #include #include #include #include #include #include struct kcommand_s { char *name; char *help; faux_list_t *params; faux_list_t *actions; }; // Simple attributes // Name KGET_STR(command, name); // Help KGET_STR(command, help); KSET_STR(command, help); // PARAM list KGET(command, faux_list_t *, params); static KCMP_NESTED(command, param, name); static KCMP_NESTED_BY_KEY(command, param, name); KADD_NESTED(command, kparam_t *, params); KFIND_NESTED(command, param); KNESTED_LEN(command, params); KNESTED_ITER(command, params); KNESTED_EACH(command, kparam_t *, params); // ACTION list KGET(command, faux_list_t *, actions); KADD_NESTED(command, kaction_t *, actions); KNESTED_LEN(command, actions); KNESTED_ITER(command, actions); KNESTED_EACH(command, kaction_t *, actions); kcommand_t *kcommand_new(const char *name) { kcommand_t *command = NULL; if (faux_str_is_empty(name)) return NULL; command = faux_zmalloc(sizeof(*command)); assert(command); if (!command) return NULL; // Initialize command->name = faux_str_dup(name); command->help = NULL; // PARAM list command->params = faux_list_new(FAUX_LIST_UNSORTED, FAUX_LIST_UNIQUE, kcommand_param_compare, kcommand_param_kcompare, (void (*)(void *))kparam_free); assert(command->params); // ACTION list command->actions = faux_list_new(FAUX_LIST_UNSORTED, FAUX_LIST_NONUNIQUE, NULL, NULL, (void (*)(void *))kaction_free); assert(command->actions); return command; } void kcommand_free(kcommand_t *command) { if (!command) return; faux_str_free(command->name); faux_str_free(command->help); faux_list_free(command->params); faux_list_free(command->actions); faux_free(command); }