1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
** Print all parameters in a default file that will be given to some program.
23
#include <drizzled/global.h>
24
#include <mysys/my_sys.h>
25
#include <mystrings/m_string.h>
26
#include <mysys/my_getopt.h>
30
const char *config_file="drizzle"; /* Default config file */
31
uint32_t verbose= 0, opt_defaults_file_used= 0;
33
static struct my_option my_long_options[] =
36
NB: --config-file is troublesome, because get_defaults_options() doesn't
37
know about it, but we pretend --config-file is like --defaults-file. In
38
fact they behave differently: see the comments at the top of
39
mysys/default.c for how --defaults-file should behave.
41
This --config-file option behaves as:
42
- If it has a directory name part (absolute or relative), then only this
43
file is read; no error is given if the file doesn't exist
44
- If the file has no directory name part, the standard locations are
45
searched for a file of this name (and standard filename extensions are
46
added if the file has no extension)
48
{"config-file", 'c', "Deprecated, please use --defaults-file instead. Name of config file to read; if no extension is given, default extension (e.g., .ini or .cnf) will be added",
49
(char**) &config_file, (char**) &config_file, 0, GET_STR, REQUIRED_ARG,
51
{"defaults-file", 'c', "Like --config-file, except: if first option, then read this file only, do not read global or per-user config files; should be the first option",
52
(char**) &config_file, (char**) &config_file, 0, GET_STR, REQUIRED_ARG,
54
{"defaults-extra-file", 'e',
55
"Read this file after the global config file and before the config file in the users home directory; should be the first option",
56
(char**) &my_defaults_extra_file, (char**) &my_defaults_extra_file, 0,
57
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
58
{"defaults-group-suffix", 'g',
59
"In addition to the given groups, read also groups with this suffix",
60
(char**) &my_defaults_group_suffix, (char**) &my_defaults_group_suffix,
61
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
63
"Deprecated. Synonym for --defaults-extra-file.",
64
(char**) &my_defaults_extra_file,
65
(char**) &my_defaults_extra_file, 0, GET_STR,
66
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
67
{"no-defaults", 'n', "Return an empty string (useful for scripts).",
68
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
69
{"help", '?', "Display this help message and exit.",
70
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
71
{"verbose", 'v', "Increase the output level",
72
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
73
{"version", 'V', "Output version information and exit.",
74
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
75
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
78
static void usage(bool version)
80
printf("%s Ver 1.6 for %s at %s\n",my_progname,SYSTEM_TYPE,
84
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");
85
puts("Prints all arguments that is give to some program using the default files");
86
printf("Usage: %s [OPTIONS] groups\n", my_progname);
87
my_print_help(my_long_options);
88
my_print_default_files(config_file);
89
my_print_variables(my_long_options);
90
printf("\nExample usage:\n%s --defaults-file=example.cnf client mysql\n", my_progname);
95
get_one_option(int optid, const struct my_option *, char *)
99
opt_defaults_file_used= 1;
118
static int get_options(int *argc,char ***argv)
122
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
134
int main(int argc, char **argv)
136
int count, error, args_used;
137
char **load_default_groups, *tmp_arguments[6];
138
char **argument, **arguments, **org_argv;
139
char *defaults, *extra_defaults, *group_suffix;
143
args_used= get_defaults_options(argc, argv, &defaults, &extra_defaults,
146
/* Copy defaults-xxx arguments & program name */
148
arguments= tmp_arguments;
149
memcpy(arguments, org_argv, count * sizeof(*org_argv));
152
/* Check out the args */
153
if (!(load_default_groups=(char**) malloc((argc+1)*sizeof(char*))))
155
if (get_options(&argc,&argv))
157
memcpy(load_default_groups, argv, (argc + 1) * sizeof(*argv));
159
if ((error= load_defaults(config_file, (const char **) load_default_groups,
160
&count, &arguments)))
162
if (verbose && opt_defaults_file_used)
165
fprintf(stderr, "WARNING: Defaults file '%s' not found!\n",
167
/* This error is not available now. For the future */
169
fprintf(stderr, "WARNING: Defaults file '%s' is not a regular file!\n",
175
for (argument= arguments+1 ; *argument ; argument++)
177
free((char*) load_default_groups);
178
free_defaults(arguments);