version 1.1.1.1, 2010/04/16 13:20:29
|
version 1.1.1.1.2.4, 2010/04/20 11:48:49
|
Line 27 char cli_Error[STRSIZ];
|
Line 27 char cli_Error[STRSIZ];
|
#pragma GCC visibility pop |
#pragma GCC visibility pop |
|
|
|
|
|
static void cli_Null_Prep_Term(int meta) |
|
{ |
|
} |
|
|
|
static void cli_Null_Deprep_Term() |
|
{ |
|
} |
|
|
|
static int cli_Pre_Input_Change_Mode() |
|
{ |
|
return 0; |
|
} |
|
|
|
static int cli_GetC(FILE *dummy) |
|
{ |
|
int ch = rl_getc(stdin); |
|
|
|
/* |
|
if (is_special_char(ch)) { |
|
pending_special_char = ch; |
|
return '\r'; |
|
} |
|
*/ |
|
|
|
return ch; |
|
} |
|
|
|
|
// cli_GetErrno() Get error code of last operation |
// cli_GetErrno() Get error code of last operation |
inline int cli_GetErrno() |
inline int cli_GetErrno() |
{ |
{ |
Line 57 inline void cli_SetErr(int eno, char *estr, ...)
|
Line 85 inline void cli_SetErr(int eno, char *estr, ...)
|
* cli_Printf() Printf CLI features |
* cli_Printf() Printf CLI features |
* @out = Output stream |
* @out = Output stream |
* @csFormat = Printf format string |
* @csFormat = Printf format string |
* return: none | * return: -1 error, != -1 printed chars |
*/ |
*/ |
inline int cli_Printf(FILE *out, const char *csFormat, ...) |
inline int cli_Printf(FILE *out, const char *csFormat, ...) |
{ |
{ |
Line 89 inline void cliComp(cli_Completion_t *cmdComplete, cli
|
Line 117 inline void cliComp(cli_Completion_t *cmdComplete, cli
|
} |
} |
|
|
/* |
/* |
|
* cliTTY() Initialize I/O TTY CLI features |
|
* @term = terminal name |
|
* @inp = input handle |
|
* @out = output handle |
|
* @win = window size |
|
* return: -1 error, != -1 ok |
|
*/ |
|
inline int cliTTY(const char *term, FILE *inp, FILE *out, struct winsize *win) |
|
{ |
|
if (term) |
|
rl_terminal_name = term; |
|
|
|
if (inp) |
|
rl_instream = inp; |
|
if (out) |
|
rl_outstream = out; |
|
|
|
if (win) |
|
if (ioctl(!rl_outstream ? STDOUT_FILENO : fileno(rl_outstream), TIOCSWINSZ, win) == -1) { |
|
LOGERR; |
|
return -1; |
|
} |
|
|
|
return 0; |
|
} |
|
|
|
/* |
|
* cliInit() Initialize Readline |
|
* @csProg = program name |
|
* return: none |
|
*/ |
|
inline void cliInit(const char *csProg) |
|
{ |
|
rl_readline_name = csProg; |
|
|
|
rl_variable_bind("editing-mode", "emacs"); |
|
} |
|
|
|
/* |
|
* cliNetInit() Initialize Readline if CLI bind to socket |
|
* @csProg = program name |
|
* @pty = Master pty |
|
* @term = stdin termios |
|
* return: none |
|
*/ |
|
void cliNetInit(const char *csProg, int pty, struct termios *term) |
|
{ |
|
struct termios t; |
|
|
|
if (term) { |
|
t = *term; |
|
t.c_lflag &= ~(ICANON | ISIG | ECHO | ECHOCTL | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT); |
|
t.c_iflag &= ~ICRNL; |
|
t.c_iflag |= IGNBRK; |
|
t.c_cc[VMIN] = 1; |
|
t.c_cc[VTIME] = 0; |
|
tcsetattr(pty, TCSANOW, &t); |
|
} |
|
|
|
cliInit(csProg); |
|
|
|
rl_instream = fdopen(pty, "r"); |
|
|
|
rl_prep_term_function = cli_Null_Prep_Term; |
|
rl_deprep_term_function = cli_Null_Deprep_Term; |
|
rl_pre_input_hook = cli_Pre_Input_Change_Mode; |
|
|
|
rl_getc_function = cli_GetC; |
|
|
|
} |
|
|
|
/* |
* cliExec() Execute CLI main loop |
* cliExec() Execute CLI main loop |
* @cmdList = Commands list |
* @cmdList = Commands list |
* @out = Output handle |
|
* @csPrompt = Prompt text |
* @csPrompt = Prompt text |
* return: -1 error, 0 = exit w/^+D, 1 done. |
* return: -1 error, 0 = exit w/^+D, 1 done. |
*/ |
*/ |
int cliExec(cliCommands_t *cmdList, FILE *out, const char *csPrompt) | int cliExec(cliCommands_t *cmdList, const char *csPrompt) |
{ |
{ |
char *line, *s, *t, **app, *items[MAX_PROMPT_ITEMS]; |
char *line, *s, *t, **app, *items[MAX_PROMPT_ITEMS]; |
int ret = 0; |
int ret = 0; |
register int i; |
register int i; |
cliCommands_t *cmd = NULL; |
cliCommands_t *cmd = NULL; |
|
FILE *out; |
|
|
inline int inline_help() |
inline int inline_help() |
{ |
{ |
Line 145 int cliExec(cliCommands_t *cmdList, FILE *out, const c
|
Line 245 int cliExec(cliCommands_t *cmdList, FILE *out, const c
|
} |
} |
|
|
/* --- main body of CLI --- */ |
/* --- main body of CLI --- */ |
|
|
|
out = rl_outstream; |
|
if (!out) |
|
out = stdout; |
|
|
rl_bind_key('?', inline_help); |
rl_bind_key('?', inline_help); |
if (!rl_attempted_completion_function) |
if (!rl_attempted_completion_function) |