~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000 MySQL AB
2
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.
6
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.
11
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 */
15
16
/*
17
**  print_default.c:
18
**  Print all parameters in a default file that will be given to some program.
19
**
20
**  Written by Monty
21
*/
22
212.5.39 by Monty Taylor
Phew. Moved my_base and my_global.
23
#include <drizzled/global.h>
212.5.13 by Monty Taylor
Moved my_sys/my_pthread/my_nosys and mysys_err to mysys.
24
#include <mysys/my_sys.h>
212.5.18 by Monty Taylor
Moved m_ctype, m_string and my_bitmap. Removed t_ctype.
25
#include <mystrings/m_string.h>
212.5.21 by Monty Taylor
Moved my_getopt.h
26
#include <mysys/my_getopt.h>
1 by brian
clean slate
27
1022.2.28 by Monty Taylor
Build/dist fixes. Added my_print_defaults back for now - test_run needs it. But now it's a noinst. Moving forward, it either needs to be renamed and installed properly, or it needs to have its functionality wrapped up into something else.
28
#include <stdio.h>
1 by brian
clean slate
29
1085.1.2 by Monty Taylor
Fixed -Wmissing-declarations
30
extern "C"
31
bool get_one_option(int optid, const struct my_option *, char *);
32
520.4.28 by Monty Taylor
Changed my.cnf to drizzle.cnf and /etc/mysql to /etc/drizzle.
33
const char *config_file="drizzle";		/* Default config file */
893 by Brian Aker
First pass of stripping uint
34
uint32_t verbose= 0, opt_defaults_file_used= 0;
1 by brian
clean slate
35
36
static struct my_option my_long_options[] =
37
{
38
  /*
39
    NB: --config-file is troublesome, because get_defaults_options() doesn't
40
    know about it, but we pretend --config-file is like --defaults-file.  In
41
    fact they behave differently: see the comments at the top of
42
    mysys/default.c for how --defaults-file should behave.
43
44
    This --config-file option behaves as:
45
    - If it has a directory name part (absolute or relative), then only this
46
      file is read; no error is given if the file doesn't exist
47
    - If the file has no directory name part, the standard locations are
48
      searched for a file of this name (and standard filename extensions are
49
      added if the file has no extension)
50
  */
51
  {"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",
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
52
   (char**) &config_file, (char**) &config_file, 0, GET_STR, REQUIRED_ARG,
1 by brian
clean slate
53
   0, 0, 0, 0, 0, 0},
54
  {"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",
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
55
   (char**) &config_file, (char**) &config_file, 0, GET_STR, REQUIRED_ARG,
1 by brian
clean slate
56
   0, 0, 0, 0, 0, 0},
57
  {"defaults-extra-file", 'e',
58
   "Read this file after the global config file and before the config file in the users home directory; should be the first option",
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
59
   (char**) &my_defaults_extra_file, (char**) &my_defaults_extra_file, 0,
1 by brian
clean slate
60
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
61
  {"defaults-group-suffix", 'g',
62
   "In addition to the given groups, read also groups with this suffix",
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
63
   (char**) &my_defaults_group_suffix, (char**) &my_defaults_group_suffix,
1 by brian
clean slate
64
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
65
  {"extra-file", 'e',
66
   "Deprecated. Synonym for --defaults-extra-file.",
77.1.77 by Monty Taylor
A crapton more warning cleanups (I turned on more warnings)
67
   (char**) &my_defaults_extra_file,
68
   (char**) &my_defaults_extra_file, 0, GET_STR,
1 by brian
clean slate
69
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
70
  {"no-defaults", 'n', "Return an empty string (useful for scripts).",
71
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
72
  {"help", '?', "Display this help message and exit.",
73
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
74
  {"verbose", 'v', "Increase the output level",
75
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
76
  {"version", 'V', "Output version information and exit.",
77
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
78
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
79
};
80
277 by Brian Aker
Cleanup of my_bool from extra and libdrizzle
81
static void usage(bool version)
1 by brian
clean slate
82
{
1081.1.1 by Monty Taylor
Whole boat-load of build fixes.
83
  printf("%s  Ver 1.6 for %s-%s at %s\n",my_progname,HOST_VENDOR,HOST_OS,
84
	 HOST_CPU);
1 by brian
clean slate
85
  if (version)
86
    return;
87
  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");
88
  puts("Prints all arguments that is give to some program using the default files");
89
  printf("Usage: %s [OPTIONS] groups\n", my_progname);
90
  my_print_help(my_long_options);
91
  my_print_default_files(config_file);
92
  my_print_variables(my_long_options);
93
  printf("\nExample usage:\n%s --defaults-file=example.cnf client mysql\n", my_progname);
94
}
95
1085.1.2 by Monty Taylor
Fixed -Wmissing-declarations
96
bool get_one_option(int optid, const struct my_option *, char *)
1 by brian
clean slate
97
{
98
  switch (optid) {
99
    case 'c':
100
      opt_defaults_file_used= 1;
101
      break;
102
    case 'n':
103
    exit(0);
104
    case 'I':
105
    case '?':
106
    usage(0);
107
    exit(0);
108
    case 'v':
109
      verbose++;
110
      break;
111
    case 'V':
112
    usage(1);
113
    exit(0);
114
  }
115
  return 0;
116
}
117
118
119
static int get_options(int *argc,char ***argv)
120
{
121
  int ho_error;
122
123
  if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
124
    exit(ho_error);
125
126
  if (*argc < 1)
127
  {
128
    usage(0);
129
    return 1;
130
  }
131
  return 0;
132
}
133
134
135
int main(int argc, char **argv)
136
{
137
  int count, error, args_used;
138
  char **load_default_groups, *tmp_arguments[6];
139
  char **argument, **arguments, **org_argv;
140
  char *defaults, *extra_defaults, *group_suffix;
141
  MY_INIT(argv[0]);
142
143
  org_argv= argv;
144
  args_used= get_defaults_options(argc, argv, &defaults, &extra_defaults,
145
                                  &group_suffix);
146
147
  /* Copy defaults-xxx arguments & program name */
148
  count=args_used+1;
149
  arguments= tmp_arguments;
212.6.11 by Mats Kindahl
emoving redundant use of casts in extra/ for memcmp(), memcpy(), memset(), and memmove().
150
  memcpy(arguments, org_argv, count * sizeof(*org_argv));
1 by brian
clean slate
151
  arguments[count]= 0;
152
153
  /* Check out the args */
656.1.26 by Monty Taylor
Finally removed all of the my_malloc stuff.
154
  if (!(load_default_groups=(char**) malloc((argc+1)*sizeof(char*))))
1 by brian
clean slate
155
    exit(1);
156
  if (get_options(&argc,&argv))
157
    exit(1);
212.6.11 by Mats Kindahl
emoving redundant use of casts in extra/ for memcmp(), memcpy(), memset(), and memmove().
158
  memcpy(load_default_groups, argv, (argc + 1) * sizeof(*argv));
1 by brian
clean slate
159
160
  if ((error= load_defaults(config_file, (const char **) load_default_groups,
161
			   &count, &arguments)))
162
  {
163
    if (verbose && opt_defaults_file_used)
164
    {
165
      if (error == 1)
166
	fprintf(stderr, "WARNING: Defaults file '%s' not found!\n",
167
		config_file);
168
      /* This error is not available now. For the future */
169
      if (error == 2)
170
	fprintf(stderr, "WARNING: Defaults file '%s' is not a regular file!\n",
171
		config_file);
172
    }
173
    error= 2;
174
  }
175
176
  for (argument= arguments+1 ; *argument ; argument++)
177
    puts(*argument);
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
178
  free((char*) load_default_groups);
1 by brian
clean slate
179
  free_defaults(arguments);
180
632.1.11 by Monty Taylor
Fixed Sun Studio warnings in mysys.
181
  return error;
1 by brian
clean slate
182
}