--- libaitcli/inc/aitcli.h 2010/06/04 12:08:32 1.2.2.1 +++ libaitcli/inc/aitcli.h 2010/06/04 13:51:21 1.2.2.3 @@ -3,13 +3,15 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitcli.h,v 1.2.2.1 2010/06/04 12:08:32 misho Exp $ +* $Id: aitcli.h,v 1.2.2.3 2010/06/04 13:51:21 misho Exp $ * *************************************************************************/ #ifndef __AITCLI_H #define __AITCLI_H +#define STRSIZ 256 + /* Key definitions */ #define K_F1 "\x1b\x4f\x50" @@ -207,12 +209,78 @@ inline const char *cli_GetError(); /* CLI Functions */ /* + * cli_BindKey() Bind function to key + * @key = key structure + * @buffer = CLI buffer + * return: RETCODE_ERR error, RETCODE_OK ok, >0 bind at position +*/ +int cli_BindKey(bindkey_t * __restrict key, linebuffer_t * __restrict buffer); + +/* + * cli_addHistory() Add line to history + * @buffer = CLI buffer + * @str = Add text + * return: RETCODE_ERR error, RETCODE_OK ok +*/ +int cli_addHistory(linebuffer_t * __restrict buffer, const char * __restrict str); +/* + * cli_saveHistory() Save history to file + * @buffer = CLI buffer + * @histfile = History filename, if NULL will be use default name + * @lines = Maximum history lines to save + * return: RETCODE_ERR error, RETCODE_OK ok +*/ +int cli_saveHistory(linebuffer_t * __restrict buffer, const char *histfile, int lines); +/* + * cli_loadHistory() Load history from file + * @buffer = CLI buffer + * @histfile = History filename, if NULL will be use default name + * return: RETCODE_ERR error, RETCODE_OK ok +*/ +int cli_loadHistory(linebuffer_t * __restrict buffer, const char *histfile); +/* + * cli_resetHistory() Reset history search in CLI session + * @buffer = CLI buffer + * return: none +*/ +inline void cli_resetHistory(linebuffer_t * __restrict buffer); + +/* + * cli_freeLine() Clear entire line + * @buffer = CLI buffer + * return: RETCODE_ERR error, RETCODE_OK ok +*/ +inline int cli_freeLine(linebuffer_t * __restrict buffer); +/* + * cli_setPrompt() Set new prompt for CLI session + * @buffer = CLI buffer + * @prompt = new text for prompt or if NULL disable prompt + * return: none +*/ +inline void cli_setPrompt(linebuffer_t * __restrict buffer, const char *prompt); + +/* + * cliEnd() Clear data, Free resources and close CLI session + * @buffer = CLI buffer + * return: RETCODE_ERR error, RETCODE_OK ok +*/ +void cliEnd(linebuffer_t * __restrict buffer); +/* + * cliInit() Start CLI session, allocate memory for resources and bind keys + * @fin = Input device handle + * @fout = Output device handle + * @prompt = text for prompt, if NULL disable prompt + * return: NULL if error or !=NULL CLI buffer +*/ +linebuffer_t *cliInit(int fin, int fout, const char *prompt); + +/* * cliExec() Execute CLI main loop * @cmdList = Commands list * @csPrompt = Prompt text * return: -1 error, 0 = exit w/^+D, 1 done. */ -int cliExec(cliCommands_t *cmdList, const char *csPrompt); +int cliExec(commands_t *cmdList, const char *csPrompt); /* * cliNetExec() Execute net CLI main loop * @cmdList = Commands list @@ -222,7 +290,7 @@ int cliExec(cliCommands_t *cmdList, const char *csProm * @win = window size of tty * return: -1 error, 0 = exit w/^+D, 1 done. */ -int cliNetExec(cliCommands_t *cmdList, const char *csPrompt, int sock, struct termios *term, struct winsize *win); +int cliNetExec(commands_t *cmdList, const char *csPrompt, int sock, struct termios *term, struct winsize *win); /* CLI Helper functions */