Commit c2205c75 authored by jani@hynda.(none)'s avatar jani@hynda.(none)
Browse files

Changed mysqlbinlog, mysqlmanager-pwgen, mysqlmanagerc, mysqltest,

thread_test and isamchk to use my_getopt.

Fixed a bug in my_getopt.
parent cca212ff
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -61,3 +61,4 @@ tonu@x3.internalnet
venu@work.mysql.com
zak@balfor.local
zak@linux.local
jani@hynda.(none)
+91 −109
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include "client_priv.h"
#include <time.h>
#include "log_event.h"
#include <my_getopt.h>

#define PROBE_HEADER_LEN (4+EVENT_LEN_OFFSET+4)

@@ -38,26 +39,6 @@ static FILE *result_file;
static const char* default_dbug_option = "d:t:o,/tmp/mysqlbinlog.trace";
#endif

static struct option long_options[] =
{
#ifndef DBUG_OFF
  {"debug", 	  optional_argument, 	0, '#'},
#endif
  {"database",    required_argument,    0, 'd'},
  {"help", 	  no_argument, 		0, '?'},
  {"host", 	  required_argument,	0, 'h'},
  {"offset", 	  required_argument,	0, 'o'},
  {"password",	  required_argument,	0, 'p'},
  {"port", 	  required_argument,	0, 'P'},
  {"position",	  required_argument,	0, 'j'},
  {"result-file", required_argument,    0, 'r'},
  {"short-form",  no_argument,		0, 's'},
  {"table", 	  required_argument, 	0, 't'},
  {"user",	  required_argument,	0, 'u'},
  {"version",	  no_argument, 		0, 'V'},
  {0,0,0,0}
};

void sql_print_error(const char *format,...);

static bool one_database = 0;
@@ -82,6 +63,44 @@ static void dump_remote_table(NET* net, const char* db, const char* table);
static void die(const char* fmt, ...);
static MYSQL* safe_connect();

static struct my_option my_long_options[] =
{
#ifndef DBUG_OFF
  {"debug", '#', "Output debug log.", (gptr*) &default_dbug_option,
   (gptr*) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
#endif
  {"database", 'd', "List entries for just this database (local log only)",
   (gptr*) &database, (gptr*) &database, 0, GET_STR_ALLOC, REQUIRED_ARG,
   0, 0, 0, 0, 0, 0},
  {"help", '?', "Display this help and exit",
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  {"host", 'h', "Get the binlog from server", (gptr*) &host, (gptr*) &host,
   0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  {"offset", 'o', "Skip the first N entries", (gptr*) &offset, (gptr*) &offset,
   0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  {"password", 'p', "Password to connect to remote server",
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  {"port", 'P', "Use port to connect to the remote server",
   (gptr*) &port, (gptr*) &port, 0, GET_INT, REQUIRED_ARG, MYSQL_PORT, 0, 0,
   0, 0, 0},
  {"position", 'j', "Start reading the binlog at position N",
   (gptr*) &position, (gptr*) &position, 0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0,
   0, 0},
  {"result-file", 'r', "Direct output to a given file", 0, 0, 0, GET_STR,
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  {"short-form", 's', "Just show the queries, no extra info",
   (gptr*) &short_form, (gptr*) &short_form, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
   0, 0},
  {"table", 't', "Get raw table dump using COM_TABLE_DUMB", (gptr*) &table,
   (gptr*) &table, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  {"user", 'u', "Connect to the remote server as username",
   (gptr*) &user, (gptr*) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0,
   0, 0},
  {"version", 'V', "Print version and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
   0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};


void sql_print_error(const char *format,...)
{
@@ -106,7 +125,7 @@ static void die(const char* fmt, ...)

static void print_version()
{
  printf("%s  Ver 1.9 for %s at %s\n",my_progname,SYSTEM_TYPE, MACHINE_TYPE);
  printf("%s Ver 2.0 for %s at %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE);
}


@@ -121,25 +140,9 @@ and you are welcome to modify and redistribute it under the GPL license\n");
Dumps a MySQL binary log in a format usable for viewing or for pipeing to\n\
the mysql command line client\n\n");
  printf("Usage: %s [options] log-files\n", my_progname);
  puts("Options:");
#ifndef DBUG_OFF
  printf("-#, --debug[=...]       Output debug log.  (%s)\n",
	 default_dbug_option);
#endif
  printf("\
-?, --help		Display this help and exit\n\
-s, --short-form	Just show the queries, no extra info\n\
-o, --offset=N		Skip the first N entries\n\
-d, --database=database List entries for just this database (local log only)\n\
-h, --host=server	Get the binlog from server\n\
-P, --port=port         Use port to connect to the remote server\n\
-u, --user=username     Connect to the remote server as username\n\
-p, --password=password Password to connect to remote server\n\
-r, --result-file=file  Direct output to a given file\n\
-j, --position=N	Start reading the binlog at position N\n\
-t, --table=name        Get raw table dump using COM_TABLE_DUMB\n\
-V, --version		Print version and exit.\n\
");
  my_print_help(my_long_options);
  putchar('\n');
  my_print_variables(my_long_options);
}

static void dump_remote_file(NET* net, const char* fname)
@@ -172,82 +175,61 @@ static void dump_remote_file(NET* net, const char* fname)
  fflush(result_file);
}

static int parse_args(int *argc, char*** argv)
{
  int c, opt_index = 0;

  result_file = stdout;
  while((c = getopt_long(*argc, *argv, "so:#::d:h:j:u:p:P:r:t:?V", long_options,
			 &opt_index)) != EOF)
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
	       char *argument)
{
    switch(c)
  switch(optid)
  {
#ifndef DBUG_OFF
  case '#':
      DBUG_PUSH(optarg ? optarg : default_dbug_option);
    DBUG_PUSH(argument ? argument : default_dbug_option);
    break;
#endif
  case 'd':
    one_database = 1;
      database = my_strdup(optarg, MYF(0));
      break;

    case 's':
      short_form = 1;
      break;

    case 'o':
      offset = strtoull(optarg,(char**) 0, 10);
    break;

    case 'j':
      position = strtoull(optarg,(char**) 0, 10);
      break;

  case 'h':
    use_remote = 1;
      host = my_strdup(optarg, MYF(0));
    break;

  case 'P':
    use_remote = 1;
      port = atoi(optarg);
    break;

  case 'p':
    use_remote = 1;
      pass = my_strdup(optarg, MYF(0));
    pass = my_strdup(argument, MYF(0));
    break;

  case 'r':
      if (!(result_file = my_fopen(optarg, O_WRONLY | O_BINARY, MYF(MY_WME))))
    if (!(result_file = my_fopen(argument, O_WRONLY | O_BINARY, MYF(MY_WME))))
      exit(1);
    break;

  case 'u':
    use_remote = 1;
      user = my_strdup(optarg, MYF(0));
    break;

    case 't':
      table = my_strdup(optarg, MYF(0));
      break;

  case 'V':
    print_version();
    exit(0);

  case '?':
  default:
    usage();
    exit(0);

  }
  return 0;
}

  (*argc)-=optind;
  (*argv)+=optind;

static int parse_args(int *argc, char*** argv)
{
  int ho_error;

  result_file = stdout;
  if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
  {
    printf("%s: handle_options() failed with error %d\n", my_progname,
	   ho_error);
    exit(1);
  }
  return 0;
}

+41 −33
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#define MANAGER_PWGEN_VERSION "1.0"
#define MANAGER_PWGEN_VERSION "1.1"

#include <my_global.h>
#include <m_ctype.h>
@@ -22,18 +22,23 @@
#include <m_string.h>
#include <mysql_version.h>
#include <errno.h>
#include <getopt.h>
#include <my_getopt.h>
#include <md5.h>

const char* outfile=0,*user="root";

struct option long_options[] =
static struct my_option my_long_options[] =
{
  {"output-file",required_argument,0,'o'},
  {"user",required_argument,0,'u'},
  {"help",no_argument,0,'?'},
  {"version",no_argument,0,'V'},
  {0,0,0,0}
  {"output-file", 'o', "Write the output to the file with the given name",
   (gptr*) &outfile, (gptr*) &outfile, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0,
   0, 0},
  {"user", 'u', "Put given user in the password file", (gptr*) &user,
   (gptr*) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  {"help", '?', "Display this message and exit", 0, 0, 0, GET_NO_ARG, NO_ARG,
   0, 0, 0, 0, 0, 0},
  {"version", 'V', "Display version info", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
   0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};

static void die(const char* fmt, ...)
@@ -66,26 +71,16 @@ void usage()
  printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
  printf("Generates a password file to be used by mysqltest.\n\n");
  printf("Usage: %s [OPTIONS]\n", my_progname);
  printf("-?,--help     Display this message and exit\n\
-V,--version    Display version info\n\
-u,--user=      Put given user in the password file\n\
-o,--output-file= Write the output to the file with the given name\n");
  my_print_help(my_long_options);
  putchar('\n');
  my_print_variables(my_long_options);
}

int parse_args(int argc, char** argv)
{
  int c,option_index=0;
  while ((c=getopt_long(argc,argv,"?Vu:o:",long_options,&option_index))
	 != EOF)
  {
    switch (c)
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
	       char *argument __attribute__((unused)))
{
    case 'o':
      outfile=optarg;
      break;
    case 'u':
      user=optarg;
      break;
  switch (optid) {
  case '?':
    usage();
    exit(0);
@@ -96,6 +91,19 @@ int parse_args(int argc, char** argv)
    usage();
    exit(1);
  }
  return 0;
}


int parse_args(int argc, char** argv)
{
  int ho_error;

  if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
  {
    printf("%s: handle_options() failed with error %d\n", my_progname,
	   ho_error);
    exit(1);
  }
  return 0;
}
+61 −65
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#define MANAGER_CLIENT_VERSION "1.1"
#define MANAGER_CLIENT_VERSION "1.2"

#include <my_global.h>
#include <mysql.h>
@@ -22,7 +22,7 @@
#include <mysqld_error.h>
#include <my_sys.h>
#include <m_string.h>
#include <getopt.h>
#include <my_getopt.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -35,23 +35,31 @@ static void die(const char* fmt, ...);

const char* user="root",*host="localhost";
char* pass=0;
int quiet=0;
my_bool quiet=0;
uint port=MYSQL_MANAGER_PORT;
static const char *load_default_groups[]= { "mysqlmanagerc",0 };
char** default_argv;
MYSQL_MANAGER *manager;
FILE* fp, *fp_out;

struct option long_options[] =
static struct my_option my_long_options[] =
{
  {"host",required_argument,0,'h'},
  {"user",required_argument,0,'u'},
  {"password",optional_argument,0,'p',},
  {"port",required_argument,0,'P'},
  {"help",no_argument,0,'?'},
  {"version",no_argument,0,'V'},
  {"quiet",no_argument,0,'q'},
  {0,0,0,0}
  {"host", 'h', "Connect to host.", (gptr*) &host, (gptr*) &host, 0,
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  {"user", 'u', "User for login.", (gptr*) &user, (gptr*) &user, 0,
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  {"password", 'p', "Password to use when connecting to server.",
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
  {"port", 'P', "Port number to use for connection.", (gptr*) &port,
   (gptr*) &port, 0, GET_UINT, REQUIRED_ARG, MYSQL_MANAGER_PORT, 0, 0, 0, 0,
   0},
  {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
   0, 0, 0, 0, 0, 0},
  {"version", 'V', "Output version information and exit.",  0, 0, 0,
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
  {"quiet", 'q', "Suppress all normal output.", (gptr*) &quiet, (gptr*) &quiet,
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};

static void die(const char* fmt, ...)
@@ -84,63 +92,51 @@ void usage()
  printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
  printf("Command-line client for MySQL manager daemon.\n\n");
  printf("Usage: %s [OPTIONS] < command_file\n", my_progname);
  printf("\n\
  -?, --help               Display this help and exit.\n");
  printf("\
  -h, --host=...           Connect to host.\n\
  -u, --user=...           User for login.\n\
  -p[password], --password[=...]\n\
                           Password to use when connecting to server.\n\
  -P, --port=...           Port number to use for connection.\n\
  -q, --quiet, --silent    Suppress all normal output.\n\
  -V, --version            Output version information and exit.\n\
  --no-defaults            Don't read default options from any options file.\n\n");
  my_print_help(my_long_options);
  printf("  --no-defaults         Don't read default options from any options file.\n\n");
  my_print_variables(my_long_options);
}
int parse_args(int argc, char **argv)
{
  int c, option_index = 0;
  my_bool tty_password=0;

  load_defaults("my",load_default_groups,&argc,&argv);
  default_argv= argv;

  while ((c = getopt_long(argc, argv, "h:p::u:P:?Vq",
			 long_options, &option_index)) != EOF)
    {
      switch (c)
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
	       char *argument)
{
      case 'h':
	host=optarg;
	break;
      case 'u':
	user=optarg;
	break;
  my_bool tty_password=0;
  
  switch (optid) {
  case 'p':
	if (optarg)
    if (argument)
    {
      my_free(pass, MYF(MY_ALLOW_ZERO_PTR));
	  pass=my_strdup(optarg,MYF(MY_FAE));
	  while (*optarg) *optarg++= 'x';		/* Destroy argument */
      pass= my_strdup(argument, MYF(MY_FAE));
      while (*argument) *argument++= 'x';	/* Destroy argument */
    }
    else
      tty_password=1;
    break;
      case 'P':
	port=atoi(optarg);
	break;
      case 'q':
	quiet=1;
	break;
  case 'V':
    print_version();
    exit(0);
  case '?':
    usage();
    exit(0);				
      default:
	usage();
	exit(1);
  }
  return 0;
}


int parse_args(int argc, char **argv)
{
  int ho_error;

  load_defaults("my",load_default_groups,&argc,&argv);
  default_argv= argv;
  if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
  {
    printf("%s: handle_options() failed with error %d\n", my_progname,
	   ho_error);
    exit(1);
  }
  return 0;
}
+158 −186

File changed.

Preview size limit exceeded, changes collapsed.

Loading