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