edit: Add support for setting prompt string

Signed-hostap: Janusz Dziedzic <janusz.dziedzic@tieto.com>
This commit is contained in:
Janusz Dziedzic 2012-08-05 20:46:34 +03:00 committed by Jouni Malinen
parent 0eed2a8d11
commit 2d2398a11f
7 changed files with 11 additions and 9 deletions

View file

@ -16,6 +16,7 @@
#define CMD_BUF_LEN 256
static char cmdbuf[CMD_BUF_LEN];
static int cmdbuf_pos = 0;
static const char *ps2 = NULL;
static void *edit_cb_ctx;
static void (*edit_cmd_cb)(void *ctx, char *cmd);
@ -41,7 +42,7 @@ static void edit_read_char(int sock, void *eloop_ctx, void *sock_ctx)
cmdbuf[cmdbuf_pos] = '\0';
cmdbuf_pos = 0;
edit_cmd_cb(edit_cb_ctx, cmdbuf);
printf("> ");
printf("%s> ", ps2 ? ps2 : "");
fflush(stdout);
return;
}
@ -57,14 +58,15 @@ static void edit_read_char(int sock, void *eloop_ctx, void *sock_ctx)
int edit_init(void (*cmd_cb)(void *ctx, char *cmd),
void (*eof_cb)(void *ctx),
char ** (*completion_cb)(void *ctx, const char *cmd, int pos),
void *ctx, const char *history_file)
void *ctx, const char *history_file, const char *ps)
{
edit_cb_ctx = ctx;
edit_cmd_cb = cmd_cb;
edit_eof_cb = eof_cb;
eloop_register_read_sock(STDIN_FILENO, edit_read_char, NULL, NULL);
ps2 = ps;
printf("> ");
printf("%s> ", ps2 ? ps2 : "");
fflush(stdout);
return 0;