summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 644fb8c)
raw | patch | inline | side by side (parent: 644fb8c)
author | Jouni Malinen <j@w1.fi> | |
Sun, 14 Nov 2010 09:30:19 +0000 (11:30 +0200) | ||
committer | Jouni Malinen <j@w1.fi> | |
Sun, 14 Nov 2010 09:30:19 +0000 (11:30 +0200) |
Instead of multiple #ifdef blocks for readline within the function,
use two copies of the functions, one for readline, one without any
readline functionality.
use two copies of the functions, one for readline, one without any
readline functionality.
wpa_supplicant/wpa_cli.c | patch | blob | history |
index 30d1f7b7e87fd33e6578dfa926758586f1cb1433..71be4999369b304c0a306851f98d1ada4c1aff1c 100644 (file)
--- a/wpa_supplicant/wpa_cli.c
+++ b/wpa_supplicant/wpa_cli.c
}
}
+#define max_args 10
+
+static int tokenize_cmd(char *cmd, char *argv[])
+{
+ char *pos;
+ int argc = 0;
+
+ pos = cmd;
+ for (;;) {
+ while (*pos == ' ')
+ pos++;
+ if (*pos == '\0')
+ break;
+ argv[argc] = pos;
+ argc++;
+ if (argc == max_args)
+ break;
+ if (*pos == '"') {
+ char *pos2 = os_strrchr(pos, '"');
+ if (pos2)
+ pos = pos2 + 1;
+ }
+ while (*pos != '\0' && *pos != ' ')
+ pos++;
+ if (*pos == ' ')
+ *pos++ = '\0';
+ }
+
+ return argc;
+}
+
+
+static void trunc_nl(char *str)
+{
+ char *pos = str;
+ while (*pos != '\0') {
+ if (*pos == '\n') {
+ *pos = '\0';
+ break;
+ }
+ pos++;
+ }
+}
+
#ifdef CONFIG_READLINE
+
static char * wpa_cli_cmd_gen(const char *text, int state)
{
static int i, len;
func = wpa_cli_dummy_gen;
return rl_completion_matches(text, func);
}
-#endif /* CONFIG_READLINE */
static void wpa_cli_interactive(void)
{
-#define max_args 10
- char cmdbuf[256], *cmd, *argv[max_args], *pos;
+ char cmdbuf[256], *cmd, *argv[max_args];
int argc;
-#ifdef CONFIG_READLINE
char *home, *hfile = NULL;
-#endif /* CONFIG_READLINE */
printf("\nInteractive mode\n\n");
-#ifdef CONFIG_READLINE
rl_attempted_completion_function = wpa_cli_completion;
home = getenv("HOME");
if (home) {
}
}
}
-#endif /* CONFIG_READLINE */
do {
wpa_cli_recv_pending(mon_conn, 0, 0);
if (mon_pid)
kill(mon_pid, SIGUSR1);
#endif /* CONFIG_WPA_CLI_FORK */
-#ifdef CONFIG_READLINE
cmd = readline("> ");
if (cmd && *cmd) {
HIST_ENTRY *h;
add_history(cmd);
next_history();
}
-#else /* CONFIG_READLINE */
- printf("> ");
- cmd = fgets(cmdbuf, sizeof(cmdbuf), stdin);
-#endif /* CONFIG_READLINE */
#ifndef CONFIG_NATIVE_WINDOWS
alarm(0);
#endif /* CONFIG_NATIVE_WINDOWS */
if (cmd == NULL)
break;
wpa_cli_recv_pending(mon_conn, 0, 0);
- pos = cmd;
- while (*pos != '\0') {
- if (*pos == '\n') {
- *pos = '\0';
- break;
- }
- pos++;
- }
- argc = 0;
- pos = cmd;
- for (;;) {
- while (*pos == ' ')
- pos++;
- if (*pos == '\0')
- break;
- argv[argc] = pos;
- argc++;
- if (argc == max_args)
- break;
- if (*pos == '"') {
- char *pos2 = os_strrchr(pos, '"');
- if (pos2)
- pos = pos2 + 1;
- }
- while (*pos != '\0' && *pos != ' ')
- pos++;
- if (*pos == ' ')
- *pos++ = '\0';
- }
+ trunc_nl(cmd);
+ argc = tokenize_cmd(cmd, argv);
if (argc)
wpa_request(ctrl_conn, argc, argv);
#endif /* CONFIG_WPA_CLI_FORK */
} while (!wpa_cli_quit);
-#ifdef CONFIG_READLINE
if (hfile) {
/* Save command history, excluding lines that may contain
* passwords. */
write_history(hfile);
os_free(hfile);
}
-#endif /* CONFIG_READLINE */
}
+#else /* CONFIG_READLINE */
+
+static void wpa_cli_interactive(void)
+{
+ char cmdbuf[256], *cmd, *argv[max_args];
+ int argc;
+
+ printf("\nInteractive mode\n\n");
+
+ do {
+ wpa_cli_recv_pending(mon_conn, 0, 0);
+#ifndef CONFIG_NATIVE_WINDOWS
+ alarm(ping_interval);
+#endif /* CONFIG_NATIVE_WINDOWS */
+#ifdef CONFIG_WPA_CLI_FORK
+ if (mon_pid)
+ kill(mon_pid, SIGUSR1);
+#endif /* CONFIG_WPA_CLI_FORK */
+ printf("> ");
+ cmd = fgets(cmdbuf, sizeof(cmdbuf), stdin);
+#ifndef CONFIG_NATIVE_WINDOWS
+ alarm(0);
+#endif /* CONFIG_NATIVE_WINDOWS */
+ if (cmd == NULL)
+ break;
+ wpa_cli_recv_pending(mon_conn, 0, 0);
+ trunc_nl(cmd);
+ argc = tokenize_cmd(cmd, argv);
+ if (argc)
+ wpa_request(ctrl_conn, argc, argv);
+
+ if (cmd != cmdbuf)
+ free(cmd);
+#ifdef CONFIG_WPA_CLI_FORK
+ if (mon_pid)
+ kill(mon_pid, SIGUSR2);
+#endif /* CONFIG_WPA_CLI_FORK */
+ } while (!wpa_cli_quit);
+}
+
+#endif /* CONFIG_READLINE */
+
static void wpa_cli_action(struct wpa_ctrl *ctrl)
{