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