mirror of
https://github.com/moparisthebest/curl
synced 2025-02-28 09:21:50 -05:00
tool_getparam: Added global config to getparameter()
In preparation for parsing global options added the GlobalConfig structure to the getparameter() function.
This commit is contained in:
parent
ad388a7d37
commit
0704dd770d
@ -373,6 +373,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
|
|||||||
char *nextarg, /* NULL if unset */
|
char *nextarg, /* NULL if unset */
|
||||||
bool *usedarg, /* set to TRUE if the arg
|
bool *usedarg, /* set to TRUE if the arg
|
||||||
has been used */
|
has been used */
|
||||||
|
struct GlobalConfig *global,
|
||||||
struct OperationConfig *config)
|
struct OperationConfig *config)
|
||||||
{
|
{
|
||||||
char letter;
|
char letter;
|
||||||
@ -1433,7 +1434,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
|
|||||||
config->insecure_ok = toggle;
|
config->insecure_ok = toggle;
|
||||||
break;
|
break;
|
||||||
case 'K': /* parse config file */
|
case 'K': /* parse config file */
|
||||||
if(parseconfig(nextarg, config))
|
if(parseconfig(nextarg, global))
|
||||||
warnf(config, "error trying read config from the '%s' file\n",
|
warnf(config, "error trying read config from the '%s' file\n",
|
||||||
nextarg);
|
nextarg);
|
||||||
break;
|
break;
|
||||||
@ -1847,7 +1848,7 @@ ParameterError parse_args(struct GlobalConfig *config, int argc,
|
|||||||
else {
|
else {
|
||||||
nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
|
nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
|
||||||
|
|
||||||
result = getparameter(flag, nextarg, &passarg, operation);
|
result = getparameter(flag, nextarg, &passarg, config, operation);
|
||||||
if(!result && passarg)
|
if(!result && passarg)
|
||||||
i++; /* we're supposed to skip this */
|
i++; /* we're supposed to skip this */
|
||||||
}
|
}
|
||||||
@ -1856,7 +1857,7 @@ ParameterError parse_args(struct GlobalConfig *config, int argc,
|
|||||||
bool used;
|
bool used;
|
||||||
|
|
||||||
/* Just add the URL please */
|
/* Just add the URL please */
|
||||||
result = getparameter((char *)"--url", argv[i], &used, operation);
|
result = getparameter((char *)"--url", argv[i], &used, config, operation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,10 +44,9 @@ typedef enum {
|
|||||||
struct GlobalConfig;
|
struct GlobalConfig;
|
||||||
struct OperationConfig;
|
struct OperationConfig;
|
||||||
|
|
||||||
ParameterError getparameter(char *flag,
|
ParameterError getparameter(char *flag, char *nextarg, bool *usedarg,
|
||||||
char *nextarg,
|
struct GlobalConfig *global,
|
||||||
bool *usedarg,
|
struct OperationConfig *operation);
|
||||||
struct OperationConfig *config);
|
|
||||||
|
|
||||||
#ifdef UNITTESTS
|
#ifdef UNITTESTS
|
||||||
void parse_cert_parameter(const char *cert_parameter,
|
void parse_cert_parameter(const char *cert_parameter,
|
||||||
|
@ -1789,7 +1789,7 @@ CURLcode operate(struct GlobalConfig *config, int argc, argv_item_t argv[])
|
|||||||
|
|
||||||
/* Parse .curlrc if necessary */
|
/* Parse .curlrc if necessary */
|
||||||
if((argc == 1) || (!curlx_strequal(argv[1], "-q"))) {
|
if((argc == 1) || (!curlx_strequal(argv[1], "-q"))) {
|
||||||
parseconfig(NULL, config->first); /* ignore possible failure */
|
parseconfig(NULL, config); /* ignore possible failure */
|
||||||
|
|
||||||
/* If we had no arguments then make sure a url was specified in .curlrc */
|
/* If we had no arguments then make sure a url was specified in .curlrc */
|
||||||
if((argc < 2) && (!config->first->url_list)) {
|
if((argc < 2) && (!config->first->url_list)) {
|
||||||
|
@ -44,7 +44,7 @@ static const char *unslashquote(const char *line, char *param);
|
|||||||
static char *my_get_line(FILE *fp);
|
static char *my_get_line(FILE *fp);
|
||||||
|
|
||||||
/* return 0 on everything-is-fine, and non-zero otherwise */
|
/* return 0 on everything-is-fine, and non-zero otherwise */
|
||||||
int parseconfig(const char *filename, struct OperationConfig *config)
|
int parseconfig(const char *filename, struct GlobalConfig *global)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
@ -52,6 +52,7 @@ int parseconfig(const char *filename, struct OperationConfig *config)
|
|||||||
bool usedarg;
|
bool usedarg;
|
||||||
char *home;
|
char *home;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
struct OperationConfig *operation = global->first;
|
||||||
|
|
||||||
if(!filename || !*filename) {
|
if(!filename || !*filename) {
|
||||||
/* NULL or no file name attempts to load .curlrc from the homedir! */
|
/* NULL or no file name attempts to load .curlrc from the homedir! */
|
||||||
@ -201,8 +202,8 @@ int parseconfig(const char *filename, struct OperationConfig *config)
|
|||||||
case '#': /* comment */
|
case '#': /* comment */
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
warnf(config, "%s:%d: warning: '%s' uses unquoted white space in the"
|
warnf(operation, "%s:%d: warning: '%s' uses unquoted white space in"
|
||||||
" line that may cause side-effects!\n",
|
" the line that may cause side-effects!\n",
|
||||||
filename, lineno, option);
|
filename, lineno, option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,7 +219,7 @@ int parseconfig(const char *filename, struct OperationConfig *config)
|
|||||||
#ifdef DEBUG_CONFIG
|
#ifdef DEBUG_CONFIG
|
||||||
fprintf(stderr, "PARAM: \"%s\"\n",(param ? param : "(null)"));
|
fprintf(stderr, "PARAM: \"%s\"\n",(param ? param : "(null)"));
|
||||||
#endif
|
#endif
|
||||||
res = getparameter(option, param, &usedarg, config);
|
res = getparameter(option, param, &usedarg, global, operation);
|
||||||
|
|
||||||
if(param && *param && !usedarg)
|
if(param && *param && !usedarg)
|
||||||
/* we passed in a parameter that wasn't used! */
|
/* we passed in a parameter that wasn't used! */
|
||||||
@ -234,7 +235,7 @@ int parseconfig(const char *filename, struct OperationConfig *config)
|
|||||||
res != PARAM_VERSION_INFO_REQUESTED &&
|
res != PARAM_VERSION_INFO_REQUESTED &&
|
||||||
res != PARAM_ENGINES_REQUESTED) {
|
res != PARAM_ENGINES_REQUESTED) {
|
||||||
const char *reason = param2text(res);
|
const char *reason = param2text(res);
|
||||||
warnf(config, "%s:%d: warning: '%s' %s\n",
|
warnf(operation, "%s:%d: warning: '%s' %s\n",
|
||||||
filename, lineno, option, reason);
|
filename, lineno, option, reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#include "tool_setup.h"
|
#include "tool_setup.h"
|
||||||
|
|
||||||
int parseconfig(const char *filename, struct OperationConfig *config);
|
int parseconfig(const char *filename, struct GlobalConfig *config);
|
||||||
|
|
||||||
#endif /* HEADER_CURL_TOOL_PARSECFG_H */
|
#endif /* HEADER_CURL_TOOL_PARSECFG_H */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user