(parse_opt): Try to catch arguments separated from
the option by whitespace. Solution proposed by Helmut Leitner. Avoid queueing multiple "set mode=send" options.
Showing
1 changed file
with
11 additions
and
16 deletions
... | @@ -82,6 +82,12 @@ parse_opt (int key, char *arg, struct argp_state *state) | ... | @@ -82,6 +82,12 @@ parse_opt (int key, char *arg, struct argp_state *state) |
82 | case 'f': | 82 | case 'f': |
83 | if (arg != NULL) | 83 | if (arg != NULL) |
84 | args->file = arg; | 84 | args->file = arg; |
85 | /* People often tend to separate -f option from its argument | ||
86 | with a whitespace. This heuristics tries to catch the | ||
87 | error: */ | ||
88 | else if (state->next < state->argc | ||
89 | && state->argv[state->next][0] != '-') | ||
90 | args->file = state->argv[state->next++]; | ||
85 | else | 91 | else |
86 | { | 92 | { |
87 | int len; | 93 | int len; |
... | @@ -141,22 +147,11 @@ parse_opt (int key, char *arg, struct argp_state *state) | ... | @@ -141,22 +147,11 @@ parse_opt (int key, char *arg, struct argp_state *state) |
141 | break; | 147 | break; |
142 | 148 | ||
143 | case ARGP_KEY_ARG: | 149 | case ARGP_KEY_ARG: |
144 | /* People often tend to separate -f option from its argument | 150 | args->args = realloc (args->args, |
145 | with a whitespace. This heuristics tries to catch the | 151 | sizeof (char *) * (state->arg_num + 2)); |
146 | error: */ | 152 | args->args[state->arg_num] = arg; |
147 | 153 | args->args[state->arg_num + 1] = NULL; | |
148 | if (args->file) | 154 | args->send_mode = 1; |
149 | { | ||
150 | args->file = arg; | ||
151 | } | ||
152 | else | ||
153 | { | ||
154 | args->args = realloc (args->args, | ||
155 | sizeof (char *) * (state->arg_num + 2)); | ||
156 | args->args[state->arg_num] = arg; | ||
157 | args->args[state->arg_num + 1] = NULL; | ||
158 | util_cache_command (&command_list, "set mode=send"); | ||
159 | } | ||
160 | break; | 155 | break; |
161 | 156 | ||
162 | case ARGP_KEY_FINI: | 157 | case ARGP_KEY_FINI: | ... | ... |
-
Please register or sign in to post a comment