@ -26,8 +26,13 @@
# include <my_sys.h>
# include <m_string.h>
# include <my_getopt.h>
# include <mysql_version.h>
# define load_default_groups mysqld_groups
# include <mysqld_default_groups.h>
# undef load_default_groups
my_bool opt_mysqld ;
const char * config_file = " my " ; /* Default config file */
uint verbose = 0 , opt_defaults_file_used = 0 ;
const char * default_dbug_option = " d:t:o,/tmp/my_print_defaults.trace " ;
@ -78,6 +83,8 @@ static struct my_option my_long_options[] =
( void * ) & my_defaults_extra_file ,
( void * ) & my_defaults_extra_file , 0 , GET_STR ,
REQUIRED_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ " mysqld " , 0 , " Read the same set of groups that the mysqld binary does. " ,
& opt_mysqld , & opt_mysqld , 0 , GET_BOOL , NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ " no-defaults " , ' n ' , " Return an empty string (useful for scripts). " ,
0 , 0 , 0 , GET_NO_ARG , NO_ARG , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ " help " , ' ? ' , " Display this help message and exit. " ,
@ -98,11 +105,12 @@ static void usage(my_bool version)
return ;
puts ( " This software comes with ABSOLUTELY NO WARRANTY. This is free software, \n and you are welcome to modify and redistribute it under the GPL license \n " ) ;
puts ( " Prints all arguments that is give to some program using the default files " ) ;
printf ( " Usage: %s [OPTIONS] groups \n " , my_progname ) ;
printf ( " Usage: %s [OPTIONS] [ groups] \n " , my_progname ) ;
my_print_help ( my_long_options ) ;
my_print_default_files ( config_file ) ;
my_print_variables ( my_long_options ) ;
printf ( " \n Example usage: \n %s --defaults-file=example.cnf client client-server mysql \n " , my_progname ) ;
exit ( 0 ) ;
}
@ -115,17 +123,15 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
opt_defaults_file_used = 1 ;
break ;
case ' n ' :
exit ( 0 ) ;
exit ( 0 ) ;
case ' I ' :
case ' ? ' :
usage ( 0 ) ;
exit ( 0 ) ;
usage ( 0 ) ;
case ' v ' :
verbose + + ;
break ;
case ' V ' :
usage ( 1 ) ;
exit ( 0 ) ;
usage ( 1 ) ;
case ' # ' :
DBUG_PUSH ( argument ? argument : default_dbug_option ) ;
break ;
@ -141,11 +147,6 @@ static int get_options(int *argc,char ***argv)
if ( ( ho_error = handle_options ( argc , argv , my_long_options , get_one_option ) ) )
exit ( ho_error ) ;
if ( * argc < 1 )
{
usage ( 0 ) ;
return 1 ;
}
return 0 ;
}
@ -153,9 +154,10 @@ static int get_options(int *argc,char ***argv)
int main ( int argc , char * * argv )
{
int count , error , args_used ;
char * * load_default_groups , * tmp_arguments [ 6 ] ;
char * * load_default_groups = 0 , * tmp_arguments [ 6 ] ;
char * * argument , * * arguments , * * org_argv ;
char * defaults , * extra_defaults , * group_suffix ;
int nargs , i = 0 ;
MY_INIT ( argv [ 0 ] ) ;
org_argv = argv ;
@ -169,13 +171,25 @@ int main(int argc, char **argv)
arguments [ count ] = 0 ;
/* Check out the args */
if ( ! ( load_default_groups = ( char * * ) my_malloc ( ( argc + 1 ) * sizeof ( char * ) ,
MYF ( MY_WME ) ) ) )
exit ( 1 ) ;
if ( get_options ( & argc , & argv ) )
exit ( 1 ) ;
memcpy ( ( char * ) load_default_groups , ( char * ) argv , ( argc + 1 ) * sizeof ( * argv ) ) ;
nargs = argc + 1 ;
if ( opt_mysqld )
nargs + = array_elements ( mysqld_groups ) ;
if ( nargs < 2 )
usage ( 0 ) ;
load_default_groups = ( char * * ) my_malloc ( nargs * sizeof ( char * ) , MYF ( MY_WME ) ) ;
if ( ! load_default_groups )
exit ( 1 ) ;
if ( opt_mysqld )
{
for ( ; mysqld_groups [ i ] ; i + + )
load_default_groups [ i ] = ( char * ) mysqld_groups [ i ] ;
}
memcpy ( load_default_groups + i , argv , ( argc + 1 ) * sizeof ( * argv ) ) ;
if ( ( error = load_defaults ( config_file , ( const char * * ) load_default_groups ,
& count , & arguments ) ) )
{
@ -198,6 +212,6 @@ int main(int argc, char **argv)
puts ( * argument ) ;
my_free ( load_default_groups ) ;
free_defaults ( arguments ) ;
my_end ( 0 ) ;
exit ( 0 ) ;
}