|
@@ -8,6 +8,7 @@
|
|
|
#include <faux/error.h>
|
|
#include <faux/error.h>
|
|
|
#include <klish/khelper.h>
|
|
#include <klish/khelper.h>
|
|
|
#include <klish/kparam.h>
|
|
#include <klish/kparam.h>
|
|
|
|
|
+#include <klish/kaction.h>
|
|
|
#include <klish/kcommand.h>
|
|
#include <klish/kcommand.h>
|
|
|
|
|
|
|
|
|
|
|
|
@@ -15,6 +16,7 @@ struct kcommand_s {
|
|
|
char *name;
|
|
char *name;
|
|
|
char *help;
|
|
char *help;
|
|
|
faux_list_t *params;
|
|
faux_list_t *params;
|
|
|
|
|
+ faux_list_t *actions;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// Simple attributes
|
|
// Simple attributes
|
|
@@ -33,6 +35,9 @@ static KCMP_NESTED_BY_KEY(command, param, name);
|
|
|
KADD_NESTED(command, param);
|
|
KADD_NESTED(command, param);
|
|
|
KFIND_NESTED(command, param);
|
|
KFIND_NESTED(command, param);
|
|
|
|
|
|
|
|
|
|
+// ACTION list
|
|
|
|
|
+KADD_NESTED(command, action);
|
|
|
|
|
+
|
|
|
|
|
|
|
|
static kcommand_t *kcommand_new_empty(void)
|
|
static kcommand_t *kcommand_new_empty(void)
|
|
|
{
|
|
{
|
|
@@ -47,11 +52,17 @@ static kcommand_t *kcommand_new_empty(void)
|
|
|
command->name = NULL;
|
|
command->name = NULL;
|
|
|
command->help = NULL;
|
|
command->help = NULL;
|
|
|
|
|
|
|
|
|
|
+ // PARAM list
|
|
|
command->params = faux_list_new(FAUX_LIST_UNSORTED, FAUX_LIST_UNIQUE,
|
|
command->params = faux_list_new(FAUX_LIST_UNSORTED, FAUX_LIST_UNIQUE,
|
|
|
kcommand_param_compare, kcommand_param_kcompare,
|
|
kcommand_param_compare, kcommand_param_kcompare,
|
|
|
(void (*)(void *))kcommand_free);
|
|
(void (*)(void *))kcommand_free);
|
|
|
assert(command->params);
|
|
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;
|
|
return command;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -88,6 +99,7 @@ void kcommand_free(kcommand_t *command)
|
|
|
faux_str_free(command->name);
|
|
faux_str_free(command->name);
|
|
|
faux_str_free(command->help);
|
|
faux_str_free(command->help);
|
|
|
faux_list_free(command->params);
|
|
faux_list_free(command->params);
|
|
|
|
|
+ faux_list_free(command->actions);
|
|
|
|
|
|
|
|
faux_free(command);
|
|
faux_free(command);
|
|
|
}
|
|
}
|
|
@@ -161,24 +173,64 @@ bool_t kcommand_nested_from_icommand(kcommand_t *kcommand, icommand_t *icommand,
|
|
|
return BOOL_FALSE;
|
|
return BOOL_FALSE;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/*
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // PARAM list
|
|
|
|
|
+ if (icommand->params) {
|
|
|
|
|
+ iparam_t **p_iparam = NULL;
|
|
|
|
|
+ for (p_iparam = *icommand->params; *p_iparam; p_iparam++) {
|
|
|
|
|
+ kparam_t *kparam = NULL;
|
|
|
|
|
+ iparam_t *iparam = *p_iparam;
|
|
|
|
|
+
|
|
|
|
|
+ kparam = kparam_from_iparam(iparam, error_stack);
|
|
|
|
|
+ if (!kparam) {
|
|
|
|
|
+ retval = BOOL_FALSE;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!kcommand_add_param(kcommand, kparam)) {
|
|
|
|
|
+ char *msg = NULL;
|
|
|
|
|
+ // Search for PARAM duplicates
|
|
|
|
|
+ if (kcommand_find_param(kcommand,
|
|
|
|
|
+ kparam_name(kparam))) {
|
|
|
|
|
+ msg = faux_str_sprintf("COMMAND: "
|
|
|
|
|
+ "Can't add duplicate PARAM "
|
|
|
|
|
+ "\"%s\"",
|
|
|
|
|
+ kparam_name(kparam));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ msg = faux_str_sprintf("COMMAND: "
|
|
|
|
|
+ "Can't add PARAM \"%s\"",
|
|
|
|
|
+ kparam_name(kparam));
|
|
|
|
|
+ }
|
|
|
|
|
+ faux_error_add(error_stack, msg);
|
|
|
|
|
+ faux_str_free(msg);
|
|
|
|
|
+ retval = BOOL_FALSE;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// ACTION list
|
|
// ACTION list
|
|
|
if (icommand->actions) {
|
|
if (icommand->actions) {
|
|
|
iaction_t **p_iaction = NULL;
|
|
iaction_t **p_iaction = NULL;
|
|
|
for (p_iaction = *icommand->actions; *p_iaction; p_iaction++) {
|
|
for (p_iaction = *icommand->actions; *p_iaction; p_iaction++) {
|
|
|
kaction_t *kaction = NULL;
|
|
kaction_t *kaction = NULL;
|
|
|
iaction_t *iaction = *p_iaction;
|
|
iaction_t *iaction = *p_iaction;
|
|
|
-iaction = iaction;
|
|
|
|
|
-printf("action\n");
|
|
|
|
|
-// kaction = kaction_from_iaction(iaction, error_stack);
|
|
|
|
|
-// if (!kaction) {
|
|
|
|
|
-// retval = BOOL_FALSE;
|
|
|
|
|
-// continue;
|
|
|
|
|
-// }
|
|
|
|
|
-kaction = kaction;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ kaction = kaction_from_iaction(iaction, error_stack);
|
|
|
|
|
+ if (!kaction) {
|
|
|
|
|
+ retval = BOOL_FALSE;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!kcommand_add_action(kcommand, kaction)) {
|
|
|
|
|
+ char *msg = NULL;
|
|
|
|
|
+ msg = faux_str_sprintf("COMMAND: "
|
|
|
|
|
+ "Can't add ACTION #%d",
|
|
|
|
|
+ faux_list_len(kcommand->actions) + 1);
|
|
|
|
|
+ faux_error_add(error_stack, msg);
|
|
|
|
|
+ faux_str_free(msg);
|
|
|
|
|
+ retval = BOOL_FALSE;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-*/
|
|
|
|
|
|
|
+
|
|
|
return retval;
|
|
return retval;
|
|
|
}
|
|
}
|
|
|
|
|
|