Loading...
Searching...
No Matches
complete.h
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
*/
#pragma once
#include <stdio.h>
#include <sys/queue.h>
#include <sys/types.h>
struct ec_node;
struct ec_strvec;
struct ec_comp_item;
struct ec_comp_group;
struct ec_comp;
enum ec_comp_type {
EC_COMP_UNKNOWN = 0x1,
EC_COMP_FULL = 0x2,
EC_COMP_PARTIAL = 0x4,
EC_COMP_ALL = 0x7,
};
struct ec_comp *ec_complete(const struct ec_node *node, const char *str);
struct ec_comp *ec_complete_strvec(const struct ec_node *node, const struct ec_strvec *strvec);
struct ec_strvec *ec_complete_strvec_expand(
const struct ec_node *node,
enum ec_comp_type type,
const struct ec_strvec *strvec
);
int ec_complete_child(
const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec
);
struct ec_comp *ec_comp(void);
void ec_comp_free(struct ec_comp *comp);
void ec_comp_dump(FILE *out, const struct ec_comp *comp);
int ec_comp_merge(struct ec_comp *to, struct ec_comp *from);
struct ec_pnode *ec_comp_get_cur_pstate(const struct ec_comp *comp);
struct ec_comp_group *ec_comp_get_cur_group(const struct ec_comp *comp);
struct ec_dict *ec_comp_get_attrs(const struct ec_comp *comp);
struct ec_comp_item *ec_comp_add_item(
struct ec_comp *comp,
const struct ec_node *node,
enum ec_comp_type type,
const char *current,
const char *full
);
const char *ec_comp_item_get_str(const struct ec_comp_item *item);
const char *ec_comp_item_get_display(const struct ec_comp_item *item);
const char *ec_comp_item_get_completion(const struct ec_comp_item *item);
const char *ec_comp_item_get_current(const struct ec_comp_item *item);
const struct ec_comp_group *ec_comp_item_get_grp(const struct ec_comp_item *item);
enum ec_comp_type ec_comp_item_get_type(const struct ec_comp_item *item);
const struct ec_node *ec_comp_item_get_node(const struct ec_comp_item *item);
int ec_comp_item_set_str(struct ec_comp_item *item, const char *str);
int ec_comp_item_set_display(struct ec_comp_item *item, const char *display);
int ec_comp_item_set_completion(struct ec_comp_item *item, const char *completion);
const struct ec_node *ec_comp_group_get_node(const struct ec_comp_group *grp);
const struct ec_pnode *ec_comp_group_get_pstate(const struct ec_comp_group *grp);
const struct ec_dict *ec_comp_group_get_attrs(const struct ec_comp_group *grp);
int ec_complete_unknown(
const struct ec_node *node,
struct ec_comp *comp,
const struct ec_strvec *strvec
);
size_t ec_comp_count(const struct ec_comp *comp, enum ec_comp_type type);
struct ec_comp_item *ec_comp_iter_first(const struct ec_comp *comp, enum ec_comp_type type);
struct ec_comp_item *ec_comp_iter_next(struct ec_comp_item *item, enum ec_comp_type type);
#define EC_COMP_FOREACH(item, comp, type) \
for (item = ec_comp_iter_first(comp, type); item != NULL; \
item = ec_comp_iter_next(item, type))
ec_comp_item_get_grp
const struct ec_comp_group * ec_comp_item_get_grp(const struct ec_comp_item *item)
Get the group of a completion item.
ec_comp_group_get_node
const struct ec_node * ec_comp_group_get_node(const struct ec_comp_group *grp)
Get the completion group node.
ec_complete_strvec_expand
struct ec_strvec * ec_complete_strvec_expand(const struct ec_node *node, enum ec_comp_type type, const struct ec_strvec *strvec)
Return a new string vector based on the provided one using completion to expand non-ambiguous tokens ...
ec_comp_iter_next
struct ec_comp_item * ec_comp_iter_next(struct ec_comp_item *item, enum ec_comp_type type)
Get the next completion item matching the type.
ec_comp_dump
void ec_comp_dump(FILE *out, const struct ec_comp *comp)
Dump the content of a completions list.
ec_comp_item_get_completion
const char * ec_comp_item_get_completion(const struct ec_comp_item *item)
Get the completion string value of a completion item.
ec_complete_child
int ec_complete_child(const struct ec_node *node, struct ec_comp *comp, const struct ec_strvec *strvec)
Get the list of completions of a child node.
ec_comp_get_cur_group
struct ec_comp_group * ec_comp_get_cur_group(const struct ec_comp *comp)
Get current completion group.
ec_comp_get_attrs
struct ec_dict * ec_comp_get_attrs(const struct ec_comp *comp)
Get completion attributes.
ec_comp_item_set_display
int ec_comp_item_set_display(struct ec_comp_item *item, const char *display)
Set the display value of an item.
ec_comp_group_get_pstate
const struct ec_pnode * ec_comp_group_get_pstate(const struct ec_comp_group *grp)
Get the completion group parsing state.
ec_comp
struct ec_comp * ec_comp(void)
Create an empty completion object (list of completion items).
ec_complete
struct ec_comp * ec_complete(const struct ec_node *node, const char *str)
Get the list of completions from a string input.
ec_comp_group_get_attrs
const struct ec_dict * ec_comp_group_get_attrs(const struct ec_comp_group *grp)
Get the completion group attributes.
ec_comp_iter_first
struct ec_comp_item * ec_comp_iter_first(const struct ec_comp *comp, enum ec_comp_type type)
Get the first completion item matching the type.
ec_complete_unknown
int ec_complete_unknown(const struct ec_node *node, struct ec_comp *comp, const struct ec_strvec *strvec)
Default node completion callback.
ec_comp_item_get_display
const char * ec_comp_item_get_display(const struct ec_comp_item *item)
Get the display string value of a completion item.
ec_comp_item_get_node
const struct ec_node * ec_comp_item_get_node(const struct ec_comp_item *item)
Get the node associated with a completion item.
ec_complete_strvec
struct ec_comp * ec_complete_strvec(const struct ec_node *node, const struct ec_strvec *strvec)
Get the list of completions from a string vector input.
ec_comp_count
size_t ec_comp_count(const struct ec_comp *comp, enum ec_comp_type type)
Get the number of completion items.
ec_comp_free
void ec_comp_free(struct ec_comp *comp)
Free a completion object and all its items.
ec_comp_add_item
struct ec_comp_item * ec_comp_add_item(struct ec_comp *comp, const struct ec_node *node, enum ec_comp_type type, const char *current, const char *full)
Add an item in completion list.
ec_comp_type
ec_comp_type
Completion item type.
Definition complete.h:47
ec_comp_get_cur_pstate
struct ec_pnode * ec_comp_get_cur_pstate(const struct ec_comp *comp)
Get current parsing state of completion.
ec_comp_merge
int ec_comp_merge(struct ec_comp *to, struct ec_comp *from)
Merge items contained in from into to.
ec_comp_item_get_current
const char * ec_comp_item_get_current(const struct ec_comp_item *item)
Get the current string value (before completion) of a completion item.
ec_comp_item_set_completion
int ec_comp_item_set_completion(struct ec_comp_item *item, const char *completion)
Set the completion value of an item.
ec_comp_item_set_str
int ec_comp_item_set_str(struct ec_comp_item *item, const char *str)
Set the completion item string.
ec_comp_item_get_str
const char * ec_comp_item_get_str(const struct ec_comp_item *item)
Get the string value of a completion item.
ec_comp_item_get_type
enum ec_comp_type ec_comp_item_get_type(const struct ec_comp_item *item)
Get the type of a completion item.
EC_COMP_FULL
@ EC_COMP_FULL
The item is fully completed.
Definition complete.h:49
EC_COMP_PARTIAL
@ EC_COMP_PARTIAL
The item is partially completed.
Definition complete.h:50
EC_COMP_UNKNOWN
@ EC_COMP_UNKNOWN
Valid token but completion not possible.
Definition complete.h:48
EC_COMP_ALL
@ EC_COMP_ALL
All completion types.
Definition complete.h:51
ec_dict
struct ec_dict * ec_dict(void)
Create a hash table.
ec_node
struct ec_node * ec_node(const char *typename, const char *id)
Create a new node from its type name.
ec_pnode
struct ec_pnode * ec_pnode(const struct ec_node *node)
Create an empty parsing tree.
ec_strvec
struct ec_strvec * ec_strvec(void)
Allocate a new empty string vector.