X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Fcmdline%2Fcmdline_rdline.h;h=1b4cc7ce57738422c51d44894fbd5eed3fc878c0;hb=6e858b4d9244cf53505589673755ab18ac2a4a83;hp=d2170293de8ac5983a3e16681b8ebc8acb28233d;hpb=99a2dd955fba6e4cc23b77d590a033650ced9c45;p=dpdk.git diff --git a/lib/cmdline/cmdline_rdline.h b/lib/cmdline/cmdline_rdline.h index d2170293de..1b4cc7ce57 100644 --- a/lib/cmdline/cmdline_rdline.h +++ b/lib/cmdline/cmdline_rdline.h @@ -10,9 +10,7 @@ /** * This file is a small equivalent to the GNU readline library, but it * was originally designed for small systems, like Atmel AVR - * microcontrollers (8 bits). Indeed, we don't use any malloc that is - * sometimes not implemented (or just not recommended) on such - * systems. + * microcontrollers (8 bits). It only uses malloc() on object creation. * * Obviously, it does not support as many things as the GNU readline, * but at least it supports some interesting features like a kill @@ -31,6 +29,7 @@ */ #include +#include #include #include @@ -38,19 +37,6 @@ extern "C" { #endif -/* configuration */ -#define RDLINE_BUF_SIZE 512 -#define RDLINE_PROMPT_SIZE 32 -#define RDLINE_VT100_BUF_SIZE 8 -#define RDLINE_HISTORY_BUF_SIZE BUFSIZ -#define RDLINE_HISTORY_MAX_LINE 64 - -enum rdline_status { - RDLINE_INIT, - RDLINE_RUNNING, - RDLINE_EXITED -}; - struct rdline; typedef int (rdline_write_char_t)(struct rdline *rdl, char); @@ -60,52 +46,32 @@ typedef int (rdline_complete_t)(struct rdline *rdl, const char *buf, char *dstbuf, unsigned int dstsize, int *state); -struct rdline { - enum rdline_status status; - /* rdline bufs */ - struct cirbuf left; - struct cirbuf right; - char left_buf[RDLINE_BUF_SIZE+2]; /* reserve 2 chars for the \n\0 */ - char right_buf[RDLINE_BUF_SIZE]; - - char prompt[RDLINE_PROMPT_SIZE]; - unsigned int prompt_size; - - char kill_buf[RDLINE_BUF_SIZE]; - unsigned int kill_size; - - /* history */ - struct cirbuf history; - char history_buf[RDLINE_HISTORY_BUF_SIZE]; - int history_cur_line; - - /* callbacks and func pointers */ - rdline_write_char_t *write_char; - rdline_validate_t *validate; - rdline_complete_t *complete; - - /* vt100 parser */ - struct cmdline_vt100 vt100; - - /* opaque pointer */ - void *opaque; -}; - /** - * Init fields for a struct rdline. Call this only once at the beginning - * of your program. - * \param rdl A pointer to an uninitialized struct rdline + * Allocate and initialize a new rdline instance. + * * \param write_char The function used by the function to write a character * \param validate A pointer to the function to execute when the * user validates the buffer. * \param complete A pointer to the function to execute when the * user completes the buffer. + * \param opaque User data for use in the callbacks. + * + * \return New rdline object on success, NULL on failure. */ -int rdline_init(struct rdline *rdl, - rdline_write_char_t *write_char, - rdline_validate_t *validate, - rdline_complete_t *complete); +__rte_experimental +struct rdline *rdline_new(rdline_write_char_t *write_char, + rdline_validate_t *validate, + rdline_complete_t *complete, + void *opaque); +/** + * Free an rdline instance. + * + * \param rdl A pointer to an initialized struct rdline. + * If NULL, this function is a no-op. + */ +__rte_experimental +void rdline_free(struct rdline *rdl); /** * Init the current buffer, and display a prompt. @@ -194,6 +160,18 @@ void rdline_clear_history(struct rdline *rdl); */ char *rdline_get_history_item(struct rdline *rdl, unsigned int i); +/** + * Get maximum history buffer size. + */ +__rte_experimental +size_t rdline_get_history_buffer_size(struct rdline *rdl); + +/** + * Get the opaque pointer supplied on struct rdline creation. + */ +__rte_experimental +void *rdline_get_opaque(struct rdline *rdl); + #ifdef __cplusplus } #endif