From 2d2398a11f1d45cd46d51e4886408d5773e09d44 Mon Sep 17 00:00:00 2001 From: Janusz Dziedzic Date: Sun, 5 Aug 2012 20:46:34 +0300 Subject: [PATCH] edit: Add support for setting prompt string Signed-hostap: Janusz Dziedzic --- hostapd/hostapd_cli.c | 2 +- src/utils/edit.c | 2 +- src/utils/edit.h | 2 +- src/utils/edit_readline.c | 2 +- src/utils/edit_simple.c | 8 +++++--- wlantest/wlantest_cli.c | 2 +- wpa_supplicant/wpa_cli.c | 2 +- 7 files changed, 11 insertions(+), 9 deletions(-) diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c index 0c33d5bc6..cca488ffa 100644 --- a/hostapd/hostapd_cli.c +++ b/hostapd/hostapd_cli.c @@ -977,7 +977,7 @@ static void hostapd_cli_interactive(void) eloop_register_signal_terminate(hostapd_cli_eloop_terminate, NULL); 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_run(); diff --git a/src/utils/edit.c b/src/utils/edit.c index 280d24474..4ccef21aa 100644 --- a/src/utils/edit.c +++ b/src/utils/edit.c @@ -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), 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) { currbuf[0] = '\0'; dl_list_init(&history_list); diff --git a/src/utils/edit.h b/src/utils/edit.h index e8d04e7fa..ad27f1c7a 100644 --- a/src/utils/edit.h +++ b/src/utils/edit.h @@ -12,7 +12,7 @@ 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); void edit_deinit(const char *history_file, int (*filter_cb)(void *ctx, const char *cmd)); void edit_clear_line(void); diff --git a/src/utils/edit_readline.c b/src/utils/edit_readline.c index c9ff0e6dc..9c27d7269 100644 --- a/src/utils/edit_readline.c +++ b/src/utils/edit_readline.c @@ -112,7 +112,7 @@ static void readline_cmd_handler(char *cmd) 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; diff --git a/src/utils/edit_simple.c b/src/utils/edit_simple.c index 0e3637cbb..a095ea6ab 100644 --- a/src/utils/edit_simple.c +++ b/src/utils/edit_simple.c @@ -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; diff --git a/wlantest/wlantest_cli.c b/wlantest/wlantest_cli.c index ce95081ca..a417b3cce 100644 --- a/wlantest/wlantest_cli.c +++ b/wlantest/wlantest_cli.c @@ -1663,7 +1663,7 @@ static void wlantest_cli_interactive(int s) cli.s = s; eloop_register_signal_terminate(wlantest_cli_eloop_terminate, &cli); 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(); diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c index 880aa1381..21f473f89 100644 --- a/wpa_supplicant/wpa_cli.c +++ b/wpa_supplicant/wpa_cli.c @@ -3820,7 +3820,7 @@ static void wpa_cli_interactive(void) eloop_register_signal_terminate(wpa_cli_eloop_terminate, NULL); 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_run();