26 #include <my_global.h>
29 #include <my_getopt.h>
30 #include "my_default.h"
33 const char *config_file=
"my";
34 static char *my_login_path;
35 uint verbose= 0, opt_defaults_file_used= 0;
36 const char *default_dbug_option=
"d:t:o,/tmp/my_print_defaults.trace";
38 static struct my_option my_long_options[] =
53 {
"config-file",
'c',
"Deprecated, please use --defaults-file instead. "
54 "Name of config file to read; if no extension is given, default "
55 "extension (e.g., .ini or .cnf) will be added",
56 &config_file, &config_file, 0, GET_STR, REQUIRED_ARG,
59 {
"debug",
'#',
"This is a non-debug version. Catch this and exit",
60 0,0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
62 {
"debug",
'#',
"Output debug log", &default_dbug_option,
63 &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
65 {
"defaults-file",
'c',
"Like --config-file, except: if first option, "
66 "then read this file only, do not read global or per-user config "
67 "files; should be the first option",
68 &config_file, &config_file, 0, GET_STR, REQUIRED_ARG,
70 {
"defaults-extra-file",
'e',
71 "Read this file after the global config file and before the config "
72 "file in the users home directory; should be the first option",
73 &my_defaults_extra_file, &my_defaults_extra_file, 0,
74 GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
75 {
"defaults-group-suffix",
'g',
76 "In addition to the given groups, read also groups with this suffix",
77 &my_defaults_group_suffix, &my_defaults_group_suffix,
78 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
80 "Deprecated. Synonym for --defaults-extra-file.",
81 &my_defaults_extra_file,
82 &my_defaults_extra_file, 0, GET_STR,
83 REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
84 {
"no-defaults",
'n',
"Ignore reading of default option file(s), "
85 "except for login file.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0,
87 {
"login-path",
'l',
"Path to be read from under the login file.",
88 &my_login_path, &my_login_path, 0, GET_STR, REQUIRED_ARG,
90 {
"help",
'?',
"Display this help message and exit.",
91 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
92 {
"verbose",
'v',
"Increase the output level",
93 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
94 {
"version",
'V',
"Output version information and exit.",
95 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
96 {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
100 static void usage(my_bool version)
102 printf(
"%s Ver 1.6 for %s at %s\n",my_progname,SYSTEM_TYPE,
106 puts(
"This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
107 puts(
"Prints all arguments that is give to some program using the default files");
108 printf(
"Usage: %s [OPTIONS] groups\n", my_progname);
109 my_print_help(my_long_options);
110 my_print_default_files(config_file);
111 my_print_variables(my_long_options);
112 printf(
"\nExample usage:\n%s --defaults-file=example.cnf client mysql\n", my_progname);
117 get_one_option(
int optid,
const struct my_option *opt __attribute__((unused)),
118 char *argument __attribute__((unused)))
122 opt_defaults_file_used= 1;
137 DBUG_PUSH(argument ? argument : default_dbug_option);
144 static int get_options(
int *argc,
char ***argv)
148 if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
160 int main(
int argc,
char **argv)
162 int count, error, args_used;
163 char **load_default_groups, *tmp_arguments[6];
164 char **argument, **arguments, **org_argv;
165 char *defaults, *extra_defaults, *group_suffix, *login_path;
170 args_used= get_defaults_options(argc, argv, &defaults, &extra_defaults,
171 &group_suffix, &login_path);
175 arguments= tmp_arguments;
176 memcpy((
char*) arguments, (
char*) org_argv, count *
sizeof(*org_argv));
180 if (!(load_default_groups=(
char**) my_malloc((argc+1)*
sizeof(
char*),
183 if (get_options(&argc,&argv))
185 memcpy((
char*) load_default_groups, (
char*) argv, (argc + 1) *
sizeof(*argv));
187 if ((error= load_defaults(config_file, (
const char **) load_default_groups,
188 &count, &arguments)))
190 if (verbose && opt_defaults_file_used)
193 fprintf(stderr,
"WARNING: Defaults file '%s' not found!\n",
197 fprintf(stderr,
"WARNING: Defaults file '%s' is not a regular file!\n",
204 for (argument= arguments+1 ; *argument ; argument++)
205 if (!my_getopt_is_args_separator(*argument))
207 my_free(load_default_groups);
208 free_defaults(arguments);