MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ndb_opts.c
1 /*
2  Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #define OPTEXPORT
19 #include <ndb_opts.h>
20 
21 #include <ndb_version.h>
22 
23 
24 static void default_ndb_opt_short(void)
25 {
26  ndb_short_usage_sub(NULL);
27 }
28 
29 static void default_ndb_opt_usage(void)
30 {
31  struct my_option my_long_options[] =
32  {
33  NDB_STD_OPTS("ndbapi_program")
34  };
35  const char *load_default_groups[]= { "mysql_cluster", 0 };
36 
37  ndb_usage(default_ndb_opt_short, load_default_groups, my_long_options);
38 }
39 
40 static void (*g_ndb_opt_short_usage)(void)= default_ndb_opt_short;
41 static void (*g_ndb_opt_usage)(void)= default_ndb_opt_usage;
42 
43 void ndb_opt_set_usage_funcs(void (*short_usage)(void),
44  void (*usage)(void))
45 {
46  /* Check that the program name has been set already */
47  assert(my_progname);
48 
49  if(short_usage)
50  g_ndb_opt_short_usage= short_usage;
51  if(usage)
52  g_ndb_opt_usage= usage;
53 }
54 
55 static inline
56 const char* ndb_progname(void)
57 {
58  if (my_progname)
59  return my_progname;
60  return "<unknown program>";
61 }
62 
63 void ndb_short_usage_sub(const char* extra)
64 {
65  printf("Usage: %s [OPTIONS]%s%s\n", ndb_progname(),
66  (extra)?" ":"",
67  (extra)?extra:"");
68 }
69 
70 void ndb_usage(void (*usagefunc)(void), const char *load_default_groups[],
71  struct my_option *my_long_options)
72 {
73  (*usagefunc)();
74 
75  ndb_std_print_version();
76  print_defaults(MYSQL_CONFIG_NAME,load_default_groups);
77  puts("");
78  my_print_help(my_long_options);
79  my_print_variables(my_long_options);
80 }
81 
82 
83 my_bool
84 ndb_std_get_one_option(int optid,
85  const struct my_option *opt __attribute__((unused)),
86  char *argument __attribute__((unused)))
87 {
88  switch (optid) {
89 #ifndef DBUG_OFF
90  case '#':
91  if (!opt_debug)
92  opt_debug= "d:t";
93  DBUG_SET_INITIAL(argument ? argument : opt_debug);
94  opt_ndb_endinfo= 1;
95  break;
96 #endif
97  case 'V':
98  ndb_std_print_version();
99  exit(0);
100  case '?':
101  (*g_ndb_opt_usage)();
102  exit(0);
103  }
104  return 0;
105 }
106 
107 void ndb_std_print_version()
108 {
109 #ifndef DBUG_OFF
110  const char *suffix= "-debug";
111 #else
112  const char *suffix= "";
113 #endif
114  printf("MySQL distrib %s%s, for %s (%s)\n",
115  NDB_VERSION_STRING,suffix,SYSTEM_TYPE,MACHINE_TYPE);
116 }
117 
118 my_bool ndb_is_load_default_arg_separator(const char* arg)
119 {
120 #ifndef MYSQL_VERSION_ID
121 #error "Need MYSQL_VERSION_ID defined"
122 #endif
123 
124 #if MYSQL_VERSION_ID >= 50510
125  /*
126  load_default() in 5.5+ returns an extra arg which has to
127  be skipped when processing the argv array
128  */
129  if (my_getopt_is_args_separator(arg))
130  return TRUE;
131 #elif MYSQL_VERSION_ID >= 50501
132  if (arg == args_separator)
133  return TRUE;
134 #else
135  (void)arg;
136 #endif
137  return FALSE;
138 }
139