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

@ -977,7 +977,7 @@ static void hostapd_cli_interactive(void)
eloop_register_signal_terminate(hostapd_cli_eloop_terminate, NULL); eloop_register_signal_terminate(hostapd_cli_eloop_terminate, NULL);
edit_init(hostapd_cli_edit_cmd_cb, hostapd_cli_edit_eof_cb, edit_init(hostapd_cli_edit_cmd_cb, hostapd_cli_edit_eof_cb,
NULL, NULL, NULL); NULL, NULL, NULL, NULL);
eloop_register_timeout(ping_interval, 0, hostapd_cli_ping, NULL, NULL); eloop_register_timeout(ping_interval, 0, hostapd_cli_ping, NULL, NULL);
eloop_run(); eloop_run();

View file

@ -1112,7 +1112,7 @@ static void edit_read_char(int sock, void *eloop_ctx, void *sock_ctx)
int edit_init(void (*cmd_cb)(void *ctx, char *cmd), int edit_init(void (*cmd_cb)(void *ctx, char *cmd),
void (*eof_cb)(void *ctx), void (*eof_cb)(void *ctx),
char ** (*completion_cb)(void *ctx, const char *cmd, int pos), 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)
{ {
currbuf[0] = '\0'; currbuf[0] = '\0';
dl_list_init(&history_list); dl_list_init(&history_list);

View file

@ -12,7 +12,7 @@
int edit_init(void (*cmd_cb)(void *ctx, char *cmd), int edit_init(void (*cmd_cb)(void *ctx, char *cmd),
void (*eof_cb)(void *ctx), void (*eof_cb)(void *ctx),
char ** (*completion_cb)(void *ctx, const char *cmd, int pos), 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);
void edit_deinit(const char *history_file, void edit_deinit(const char *history_file,
int (*filter_cb)(void *ctx, const char *cmd)); int (*filter_cb)(void *ctx, const char *cmd));
void edit_clear_line(void); void edit_clear_line(void);

View file

@ -112,7 +112,7 @@ static void readline_cmd_handler(char *cmd)
int edit_init(void (*cmd_cb)(void *ctx, char *cmd), int edit_init(void (*cmd_cb)(void *ctx, char *cmd),
void (*eof_cb)(void *ctx), void (*eof_cb)(void *ctx),
char ** (*completion_cb)(void *ctx, const char *cmd, int pos), 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_cb_ctx = ctx;
edit_cmd_cb = cmd_cb; edit_cmd_cb = cmd_cb;

View file

@ -16,6 +16,7 @@
#define CMD_BUF_LEN 256 #define CMD_BUF_LEN 256
static char cmdbuf[CMD_BUF_LEN]; static char cmdbuf[CMD_BUF_LEN];
static int cmdbuf_pos = 0; static int cmdbuf_pos = 0;
static const char *ps2 = NULL;
static void *edit_cb_ctx; static void *edit_cb_ctx;
static void (*edit_cmd_cb)(void *ctx, char *cmd); 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[cmdbuf_pos] = '\0';
cmdbuf_pos = 0; cmdbuf_pos = 0;
edit_cmd_cb(edit_cb_ctx, cmdbuf); edit_cmd_cb(edit_cb_ctx, cmdbuf);
printf("> "); printf("%s> ", ps2 ? ps2 : "");
fflush(stdout); fflush(stdout);
return; 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), int edit_init(void (*cmd_cb)(void *ctx, char *cmd),
void (*eof_cb)(void *ctx), void (*eof_cb)(void *ctx),
char ** (*completion_cb)(void *ctx, const char *cmd, int pos), 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_cb_ctx = ctx;
edit_cmd_cb = cmd_cb; edit_cmd_cb = cmd_cb;
edit_eof_cb = eof_cb; edit_eof_cb = eof_cb;
eloop_register_read_sock(STDIN_FILENO, edit_read_char, NULL, NULL); eloop_register_read_sock(STDIN_FILENO, edit_read_char, NULL, NULL);
ps2 = ps;
printf("> "); printf("%s> ", ps2 ? ps2 : "");
fflush(stdout); fflush(stdout);
return 0; return 0;

View file

@ -1663,7 +1663,7 @@ static void wlantest_cli_interactive(int s)
cli.s = s; cli.s = s;
eloop_register_signal_terminate(wlantest_cli_eloop_terminate, &cli); eloop_register_signal_terminate(wlantest_cli_eloop_terminate, &cli);
edit_init(wlantest_cli_edit_cmd_cb, wlantest_cli_edit_eof_cb, edit_init(wlantest_cli_edit_cmd_cb, wlantest_cli_edit_eof_cb,
wlantest_cli_edit_completion_cb, &cli, hfile); wlantest_cli_edit_completion_cb, &cli, hfile, NULL);
eloop_run(); eloop_run();

View file

@ -3820,7 +3820,7 @@ static void wpa_cli_interactive(void)
eloop_register_signal_terminate(wpa_cli_eloop_terminate, NULL); eloop_register_signal_terminate(wpa_cli_eloop_terminate, NULL);
edit_init(wpa_cli_edit_cmd_cb, wpa_cli_edit_eof_cb, edit_init(wpa_cli_edit_cmd_cb, wpa_cli_edit_eof_cb,
wpa_cli_edit_completion_cb, NULL, hfile); wpa_cli_edit_completion_cb, NULL, hfile, NULL);
eloop_register_timeout(ping_interval, 0, wpa_cli_ping, NULL, NULL); eloop_register_timeout(ping_interval, 0, wpa_cli_ping, NULL, NULL);
eloop_run(); eloop_run();