aboutsummaryrefslogtreecommitdiff
path: root/src/tool_getparam.c
diff options
context:
space:
mode:
authorSteve Holme <steve_holme@hotmail.com>2014-02-02 14:58:25 +0000
committerSteve Holme <steve_holme@hotmail.com>2014-02-03 18:38:14 +0000
commitc35d05aa62cbeed14629769293e3c30ec59fc728 (patch)
tree7b020b05b46d1d9deea087f395fb14f579032dea /src/tool_getparam.c
parent8034b08e0e49b21ab8b186575d638dee8c7dfb17 (diff)
tool_operate: Moved command line argument parsing into separate function
Diffstat (limited to 'src/tool_getparam.c')
-rw-r--r--src/tool_getparam.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
index dcb358411..2938f88b2 100644
--- a/src/tool_getparam.c
+++ b/src/tool_getparam.c
@@ -1847,3 +1847,47 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
return PARAM_OK;
}
+
+ParameterError parse_args(struct Configurable *config, int argc,
+ argv_item_t argv[])
+{
+ int i;
+ bool stillflags;
+ char *orig_opt;
+ ParameterError result = PARAM_OK;
+
+ for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
+ orig_opt = argv[i];
+
+ if(stillflags && ('-' == argv[i][0])) {
+ char *nextarg;
+ bool passarg;
+ char *flag = argv[i];
+
+ if(curlx_strequal("--", argv[i]))
+ /* This indicates the end of the flags and thus enables the
+ following (URL) argument to start with -. */
+ stillflags = FALSE;
+ else {
+ nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
+
+ result = getparameter(flag, nextarg, &passarg, config);
+ if(!result && passarg)
+ i++; /* we're supposed to skip this */
+ }
+ }
+ else {
+ bool used;
+
+ /* Just add the URL please */
+ result = getparameter((char *)"--url", argv[i], &used, config);
+ }
+ }
+
+ if(result && result != PARAM_HELP_REQUESTED) {
+ const char *reason = param2text(result);
+ helpf(config->errors, "option %s: %s\n", orig_opt, reason);
+ }
+
+ return result;
+}