#include #include #include #include #include #include #include #define BSHELL_TYPE_GET_VERB (bshell_get_verb_get_type()) fx_type_id bshell_get_verb_get_type(void); FX_DECLARE_TYPE(bshell_get_verb); FX_TYPE_CLASS_DECLARATION_BEGIN(bshell_get_verb) FX_TYPE_CLASS_DECLARATION_END(bshell_get_verb) struct bshell_get_verb_p { fx_hashtable *c_verbs; const fx_iterator *c_it; }; static enum bshell_status begin_processing( bshell_cmdlet *cmdlet, enum bshell_command_position position) { struct bshell_get_verb_p *p = fx_object_get_private(cmdlet, BSHELL_TYPE_GET_VERB); p->c_verbs = bshell_get_all_verbs(); p->c_it = fx_iterator_begin(p->c_verbs); return BSHELL_SUCCESS; } static enum bshell_status process_record( bshell_cmdlet *cmdlet, bshell_pipeline *pipeline, struct bshell_runtime *rt) { struct bshell_get_verb_p *p = fx_object_get_private(cmdlet, BSHELL_TYPE_GET_VERB); do { const fx_value *v = fx_iterator_get_value(p->c_it); if (!v) { return BSHELL_SUCCESS; } fx_hashtable_item *item = NULL; fx_value_get_object(v, &item); v = fx_hashtable_item_get_value(item); bshell_verb *verb = NULL; fx_value_get_object(v, &verb); fx_iterator_move_next(p->c_it); if (bshell_verb_is_reserved(verb)) { continue; } bshell_pipeline_write_value(pipeline, *v, false); break; } while (1); return BSHELL_SUCCESS; } static enum bshell_status end_processing(bshell_cmdlet *cmdlet) { struct bshell_get_verb_p *p = fx_object_get_private(cmdlet, BSHELL_TYPE_GET_VERB); if (p->c_it) { fx_iterator_unref(p->c_it); p->c_it = NULL; } return BSHELL_SUCCESS; } static void init(fx_object *obj, void *priv) { } FX_TYPE_CLASS_BEGIN(bshell_get_verb) FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT) FX_INTERFACE_ENTRY(to_string) = NULL; FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT) FX_TYPE_VTABLE_INTERFACE_BEGIN(bshell_cmdlet, BSHELL_TYPE_CMDLET) FX_INTERFACE_ENTRY(c_verb) = BSHELL_VERB_GET; FX_INTERFACE_ENTRY(c_noun) = "Verb"; FX_TYPE_VTABLE_INTERFACE_END(bshell_cmdlet, BSHELL_TYPE_CMDLET) FX_TYPE_VTABLE_INTERFACE_BEGIN(bshell_command, BSHELL_TYPE_COMMAND) FX_INTERFACE_ENTRY(c_begin_processing) = begin_processing; FX_INTERFACE_ENTRY(c_process_record) = process_record; FX_INTERFACE_ENTRY(c_end_processing) = end_processing; FX_TYPE_VTABLE_INTERFACE_END(bshell_cmdlet, BSHELL_TYPE_CMDLET) FX_TYPE_CLASS_END(bshell_get_verb) FX_TYPE_DEFINITION_BEGIN(bshell_get_verb) FX_TYPE_ID(0xa47976a6, 0xf7d8, 0x447f, 0x887b, 0x6c5d78b7bd2e); FX_TYPE_NAME("bshell.core.get_verb"); FX_TYPE_EXTENDS(BSHELL_TYPE_CMDLET); FX_TYPE_CLASS(bshell_get_verb_class); FX_TYPE_INSTANCE_INIT(init); FX_TYPE_INSTANCE_PRIVATE(struct bshell_get_verb_p); FX_TYPE_DEFINITION_END(bshell_get_verb)