1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <assert.h>
- #include <faux/str.h>
- #include <faux/list.h>
- #include <klish/kcommand.h>
- #include <klish/kaction.h>
- struct kaction_s {
- bool_t is_static;
- kaction_info_t info;
- faux_list_t *commands;
- };
- static kaction_t *kaction_new_internal(kaction_info_t info, bool_t is_static)
- {
- kaction_t *action = NULL;
- action = faux_zmalloc(sizeof(*action));
- assert(action);
- if (!action)
- return NULL;
- // Initialize
- action->is_static = is_static;
- action->info = info;
- return action;
- }
- kaction_t *kaction_new(kaction_info_t info)
- {
- return kaction_new_internal(info, BOOL_FALSE);
- }
- kaction_t *kaction_new_static(kaction_info_t info)
- {
- return kaction_new_internal(info, BOOL_TRUE);
- }
- void kaction_free(kaction_t *action)
- {
- if (!action)
- return;
- if (!action->is_static) {
- faux_str_free(action->info.sym);
- }
- faux_free(action);
- }
- const char *kaction_sym_str(const kaction_t *action)
- {
- assert(action);
- if (!action)
- return NULL;
- return action->info.sym;
- }
|