diff options
author | unknown <jani@rhols221.arenanet.fi> | 2002-05-24 14:06:58 +0300 |
---|---|---|
committer | unknown <jani@rhols221.arenanet.fi> | 2002-05-24 14:06:58 +0300 |
commit | 072e605cdc5f8803d90f88877c7abe1b4efaa551 (patch) | |
tree | dde3a16d80cc4857063e077d484ded67a7697cb5 | |
parent | 701d369d1844f19853223860c8610e40b802f428 (diff) | |
download | mariadb-git-072e605cdc5f8803d90f88877c7abe1b4efaa551.tar.gz |
Changed ft_dump, ft_eval, ft_test1, mi_test1, myisampack, gen_lex_hash,
mysqlmanager from using GNU getopt to use my_getopt.
Changed some files that just included old getopt.h to include
my_getopt.h now.
Fixed a bug in my_print_help() in my_getopt.c.
Made better documentation for option -G in mysql client.
client/mysql.cc:
Documented --named-commands better.
myisam/ft_dump.c:
Changed getopt to my_getopt.
myisam/ft_eval.c:
Changed getopt to my_getopt.
myisam/ft_test1.c:
Changed getopt to my_getopt.
myisam/mi_check.c:
getopt.h -> my_getopt.h
myisam/mi_test1.c:
Changed getopt to my_getopt.
myisam/myisampack.c:
Changed getopt to my_getopt.
mysys/my_getopt.c:
Fixed a bug when printing help for option that didn't have a
description.
sql/gen_lex_hash.cc:
Changed getopt to my_getopt.
tools/mysqlmanager.c:
Changed getopt to my_getopt.
vio/test-ssl.c:
getopt.h -> my_getopt.h
vio/test-sslclient.c:
getopt.h -> my_getopt.h
vio/test-sslserver.c:
getopt.h -> my_getopt.h
vio/viotest-ssl.c:
getopt.h -> my_getopt.h
BitKeeper/etc/logging_ok:
Logging to logging@openlogging.org accepted
-rw-r--r-- | BitKeeper/etc/logging_ok | 1 | ||||
-rw-r--r-- | client/mysql.cc | 7 | ||||
-rw-r--r-- | myisam/ft_dump.c | 103 | ||||
-rw-r--r-- | myisam/ft_eval.c | 128 | ||||
-rw-r--r-- | myisam/ft_test1.c | 88 | ||||
-rw-r--r-- | myisam/mi_check.c | 2 | ||||
-rw-r--r-- | myisam/mi_test1.c | 278 | ||||
-rw-r--r-- | myisam/myisampack.c | 176 | ||||
-rw-r--r-- | mysys/my_getopt.c | 49 | ||||
-rw-r--r-- | sql/gen_lex_hash.cc | 126 | ||||
-rw-r--r-- | tools/mysqlmanager.c | 164 | ||||
-rw-r--r-- | vio/test-ssl.c | 4 | ||||
-rw-r--r-- | vio/test-sslclient.c | 4 | ||||
-rw-r--r-- | vio/test-sslserver.c | 4 | ||||
-rw-r--r-- | vio/viotest-ssl.c | 4 |
15 files changed, 630 insertions, 508 deletions
diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index a25e9320284..d3baff14852 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -62,3 +62,4 @@ venu@work.mysql.com zak@balfor.local zak@linux.local jani@hynda.(none) +jani@rhols221.arenanet.fi diff --git a/client/mysql.cc b/client/mysql.cc index 41d7caf4b08..105711bd6a0 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -40,7 +40,7 @@ #include <signal.h> #include <violite.h> -const char *VER= "12.6"; +const char *VER= "12.7"; /* Don't try to make a nice table if the data is too big */ #define MAX_COLUMN_LENGTH 1024 @@ -467,10 +467,11 @@ static struct my_option my_long_options[] = {"force", 'f', "Continue even if we get an sql error.", (gptr*) &ignore_errors, (gptr*) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"no-named-commands", 'g', "Named commands are disabled. Use \\* form only, or use named commands only in the beginning of a line ending with a semicolon (;) Since version 10.9 the client now starts with this option ENABLED by default! Disable with '-G'. Long format commands still work from the first line. WARNING: option depricated; use --disable-named-commands instead.", + {"no-named-commands", 'g', + "Named commands are disabled. Use \\* form only, or use named commands only in the beginning of a line ending with a semicolon (;) Since version 10.9 the client now starts with this option ENABLED by default! Disable with '-G'. Long format commands still work from the first line. WARNING: option depricated; use --disable-named-commands instead.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"named-commands", 'G', - "Enable named commands. Disable with --disable-named-commands. This option is disabled by default.", + "Enable named commands. Named commands mean this program's internal commands; see mysql> help . When enabled, the named commands can be used from any line of the query, otherwise only from the first line, before an enter. Disable with --disable-named-commands. This option is disabled by default.", (gptr*) &named_cmds, (gptr*) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"ignore-space", 'i', "Ignore space after function names.", 0, 0, 0, diff --git a/myisam/ft_dump.c b/myisam/ft_dump.c index 6308694b58e..619e59efc3e 100644 --- a/myisam/ft_dump.c +++ b/myisam/ft_dump.c @@ -14,22 +14,46 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* Written by Sergei A. Golubchik, who has a shared copyright to this code */ +/* Written by Sergei A. Golubchik, who has a shared copyright to this code + added support for long options (my_getopt) 22.5.2002 by Jani Tolonen */ #include "ftdefs.h" -#include <getopt.h> +#include <my_getopt.h> static void get_options(int argc,char *argv[]); -static void usage(char *argv[]); +static void usage(); static void complain(int val); -static int count=0, stats=0, dump=0, verbose=0, lstats=0; +static int count=0, stats=0, dump=0, lstats=0; +static my_bool verbose; static char *query=NULL; static uint lengths[256]; #define MAX_LEN (HA_FT_MAXLEN+10) #define HOW_OFTEN_TO_WRITE 10000 +static struct my_option my_long_options[] = +{ + {"dump", 'd', "Dump index (incl. data offsets and word weights)", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"stats", 's', "Report global stats", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"verbose", 'v', "Be verbose", + (gptr*) &verbose, (gptr*) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"count", 'c', "Calculate per-word stats (counts and global weights)", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"length", 'l', "Report length distribution", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"execute", 'e', "Execute given query", (gptr*) &query, (gptr*) &query, 0, + GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"help", 'h', "Display help and exit", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"help", '?', "Synonym for -h", + 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} +}; + + int main(int argc,char *argv[]) { int error=0; @@ -52,7 +76,7 @@ int main(int argc,char *argv[]) setbuf(stdout,NULL); if (argc-optind < 2) - usage(argv); + usage(); if (!(info=mi_open(argv[optind],2,HA_OPEN_ABORT_IF_LOCKED))) goto err; @@ -184,45 +208,60 @@ err: return 0; } -const char *options="dslcvh"; + +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument __attribute__((unused))) +{ + switch(optid) { + case 'd': + dump=1; + complain(count || query); + break; + case 's': + stats=1; + complain(query!=0); + break; + case 'c': + count= 1; + complain(dump || query); + break; + case 'l': + lstats=1; + complain(query!=0); + break; + case 'e': + complain(dump || count || stats); + break; + case '?': + case 'h': + usage(); + } + return 0; +} static void get_options(int argc, char *argv[]) { - int c; + int ho_error; - while ((c=getopt(argc,argv,options)) != -1) + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) { - switch(c) { - case 'd': dump=1; complain(count || query); break; - case 's': stats=1; complain(query!=0); break; - case 'v': verbose=1; break; - case 'c': count=1; complain(dump || query); break; - case 'l': lstats=1; complain(query!=0); break; - case 'e': query=my_strdup(optarg,MYF(MY_FAE)); complain(dump || count || stats); break; - case '?': - case 'h': - default: - usage(argv); - } + printf("%s: handle_options() failed with error %d\n", my_progname, + ho_error); + exit(1); } - return; } /* get options */ -static void usage(char *argv[]) + +static void usage() { - printf("\n\ -Use: %s [-%s] <table_name> <index_no>\n\ -\n\ --d Dump index (incl. data offsets and word weights)\n\ --s Report global stats\n\ --c Calculate per-word stats (counts and global weights)\n\ --l Report length distribution\n\ --v Be verbose\n\ --h This text\n\ -", *argv, options); + printf("Use: ft_dump <table_name> <index_no>\n"); + my_print_help(my_long_options); + my_print_variables(my_long_options); exit(1); } + static void complain(int val) /* Kinda assert :-) */ { if (val) diff --git a/myisam/ft_eval.c b/myisam/ft_eval.c index c498725daab..1b40209563d 100644 --- a/myisam/ft_eval.c +++ b/myisam/ft_eval.c @@ -11,18 +11,32 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* Written by Sergei A. Golubchik, who has a shared copyright to this code */ +/* Written by Sergei A. Golubchik, who has a shared copyright to this code + added support for long options (my_getopt) 22.5.2002 by Jani Tolonen */ #include "ftdefs.h" #include "ft_eval.h" #include <stdarg.h> -#include <getopt.h> +#include <my_getopt.h> static void print_error(int exit_code, const char *fmt,...); static void get_options(int argc, char *argv[]); static int create_record(char *pos, FILE *file); +static void usage(); -int main(int argc,char *argv[]) +static struct my_option my_long_options[] = +{ + {"", 's', "", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"", 'q', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"", 'S', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"", '#', "", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"", 'V', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"", '?', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"", 'h', "", 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} +}; + +int main(int argc, char *argv[]) { MI_INFO *file; int i,j; @@ -81,7 +95,9 @@ int main(int argc,char *argv[]) if (!silent) printf("- Reading rows with key\n"); for(i=1;create_record(record,qf);i++) { - FT_DOCLIST *result; double w; int t,err; + FT_DOCLIST *result; + double w; + int t, err; result=ft_nlq_init_search(file,0,blob_record,(uint) strlen(blob_record),1); if(!result) { @@ -94,7 +110,7 @@ int main(int argc,char *argv[]) t=uint2korr(read_record); w=ft_nlq_get_relevance(result); printf("%d %.*s %f\n",i,t,read_record+2,w); - } + } if(err != HA_ERR_END_OF_FILE) { printf("ft_read_next %d failed with errno %3d\n",j,my_errno); goto err; @@ -106,57 +122,67 @@ int main(int argc,char *argv[]) my_end(MY_CHECK_ERROR); return (0); -err: + + err: printf("got error: %3d when using myisam-database\n",my_errno); - return 1; /* skipp warning */ + return 1; /* skip warning */ } -static void get_options(int argc,char *argv[]) -{ - int c; - char *options=(char*) "Vh#:qSs:"; - while ((c=getopt(argc,argv,options)) != -1) - { - switch(c) { - case 's': - if(stopwordlist && stopwordlist!=ft_precompiled_stopwords) break; - { - FILE *f; char s[HA_FT_MAXLEN]; int i=0,n=SWL_INIT; - - if(!(stopwordlist=(const char**) malloc(n*sizeof(char *)))) - print_error(1,"malloc(%d)",n*sizeof(char *)); - if(!(f=fopen(optarg,"r"))) - print_error(1,"fopen(%s)",optarg); - while(!feof(f)) { - if(!(fgets(s,HA_FT_MAXLEN,f))) - print_error(1,"fgets(s,%d,%s)",HA_FT_MAXLEN,optarg); - if(!(stopwordlist[i++]=strdup(s))) - print_error(1,"strdup(%s)",s); - if(i>=n) { - n+=SWL_PLUS; - if(!(stopwordlist=(const char**) realloc((char*) stopwordlist,n*sizeof(char *)))) - print_error(1,"realloc(%d)",n*sizeof(char *)); - } +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + switch(optid) { + case 's': + if(stopwordlist && stopwordlist!=ft_precompiled_stopwords) break; + { + FILE *f; char s[HA_FT_MAXLEN]; int i=0,n=SWL_INIT; + + if(!(stopwordlist=(const char**) malloc(n*sizeof(char *)))) + print_error(1,"malloc(%d)",n*sizeof(char *)); + if(!(f=fopen(argument,"r"))) + print_error(1,"fopen(%s)",argument); + while(!feof(f)) { + if(!(fgets(s,HA_FT_MAXLEN,f))) + print_error(1,"fgets(s,%d,%s)",HA_FT_MAXLEN,argument); + if(!(stopwordlist[i++]=strdup(s))) + print_error(1,"strdup(%s)",s); + if(i>=n) { + n+=SWL_PLUS; + if(!(stopwordlist=(const char**) realloc((char*) stopwordlist,n*sizeof(char *)))) + print_error(1,"realloc(%d)",n*sizeof(char *)); } - fclose(f); - stopwordlist[i]=NULL; - break; } - case 'q': silent=1; break; - case 'S': if(stopwordlist==ft_precompiled_stopwords) stopwordlist=NULL; break; - case '#': - DEBUGGER_ON; - DBUG_PUSH (optarg); + fclose(f); + stopwordlist[i]=NULL; break; - case 'V': - case '?': - case 'h': - default: - printf("%s -[%s] <d_file> <q_file>\n", argv[0], options); - exit(0); } + case 'q': silent=1; break; + case 'S': if(stopwordlist==ft_precompiled_stopwords) stopwordlist=NULL; break; + case '#': + DEBUGGER_ON; + DBUG_PUSH (argument); + break; + case 'V': + case '?': + case 'h': + usage(); + exit(1); + } + return 0; +} + +static void get_options(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); } if(!(d_file=argv[optind])) print_error(1,"No d_file"); if(!(df=fopen(d_file,"r"))) @@ -206,3 +232,11 @@ static void print_error(int exit_code, const char *fmt,...) va_end(args); exit(exit_code); } + + +static void usage() +{ + printf("%s [options]\n", my_progname); + my_print_help(my_long_options); + my_print_variables(my_long_options); +} diff --git a/myisam/ft_test1.c b/myisam/ft_test1.c index e1a47ff87c3..728ea4cd047 100644 --- a/myisam/ft_test1.c +++ b/myisam/ft_test1.c @@ -14,11 +14,12 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* Written by Sergei A. Golubchik, who has a shared copyright to this code */ +/* Written by Sergei A. Golubchik, who has a shared copyright to this code + added support for long options (my_getopt) 22.5.2002 by Jani Tolonen */ #include "ftdefs.h" #include "ft_test1.h" -#include <getopt.h> +#include <my_getopt.h> static int key_field=FIELD_VARCHAR,extra_field=FIELD_SKIP_ENDSPACE; static uint key_length=200,extra_length=50; @@ -33,8 +34,26 @@ static char record[MAX_REC_LENGTH],read_record[MAX_REC_LENGTH]; static int run_test(const char *filename); static void get_options(int argc, char *argv[]); static void create_record(char *, int); +static void usage(); -int main(int argc,char *argv[]) +static struct my_option my_long_options[] = +{ + {"", 'v', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"", '?', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"", 'h', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"", 'V', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"", 'v', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"", 's', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"", 'N', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"", 'S', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"", 'K', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"", 'F', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"", 'U', "", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"", '#', "", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, + { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} +}; + +int main(int argc, char *argv[]) { MY_INIT(argv[0]); @@ -173,7 +192,7 @@ static int run_test(const char *filename) return (0); err: printf("got error: %3d when using myisam-database\n",my_errno); - return 1; /* skipp warning */ + return 1; /* skip warning */ } static char blob_key[MAX_REC_LENGTH]; @@ -232,34 +251,51 @@ void create_record(char *pos, int n) } } + +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + switch(optid) { + case 'v': verbose=1; break; + case 's': silent=1; break; + case 'F': no_fulltext=1; no_search=1; + case 'U': skip_update=1; break; + case 'K': no_keys=no_search=1; break; + case 'N': no_search=1; break; + case 'S': no_stopwords=1; break; + case '#': + DEBUGGER_ON; + DBUG_PUSH (argument); + break; + case 'V': + case '?': + case 'h': + usage(); + exit(1); + } + return 0; +} + /* Read options */ static void get_options(int argc,char *argv[]) { - int c; - const char *options="hVvsNSKFU#:"; + int ho_error; - while ((c=getopt(argc,argv,options)) != -1) + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) { - switch(c) { - case 'v': verbose=1; break; - case 's': silent=1; break; - case 'F': no_fulltext=1; no_search=1; - case 'U': skip_update=1; break; - case 'K': no_keys=no_search=1; break; - case 'N': no_search=1; break; - case 'S': no_stopwords=1; break; - case '#': - DEBUGGER_ON; - DBUG_PUSH (optarg); - break; - case 'V': - case '?': - case 'h': - default: - printf("%s -[%s]\n", argv[0], options); - exit(0); - } + printf("%s: handle_options() failed with error %d\n", my_progname, + ho_error); + exit(1); } return; } /* get options */ + + +static void usage() +{ + printf("%s [options]\n", my_progname); + my_print_help(my_long_options); + my_print_variables(my_long_options); +} diff --git a/myisam/mi_check.c b/myisam/mi_check.c index da7848d3214..71e22c1f56c 100644 --- a/myisam/mi_check.c +++ b/myisam/mi_check.c @@ -19,7 +19,7 @@ #include "ftdefs.h" #include <m_ctype.h> #include <stdarg.h> -#include <getopt.h> +#include <my_getopt.h> #include <assert.h> #ifdef HAVE_SYS_VADVISE_H #include <sys/vadvise.h> diff --git a/myisam/mi_test1.c b/myisam/mi_test1.c index bb32860b575..84810cb25ea 100644 --- a/myisam/mi_test1.c +++ b/myisam/mi_test1.c @@ -17,20 +17,23 @@ /* Testing of the basic functions of a MyISAM table */ #include "myisam.h" -#include <getopt.h> +#include <my_getopt.h> #include <m_string.h> #define MAX_REC_LENGTH 1024 -static int rec_pointer_size=0,verbose=0,flags[50]; +static void usage(); + +static int rec_pointer_size=0, flags[50]; static int key_field=FIELD_SKIP_PRESPACE,extra_field=FIELD_SKIP_ENDSPACE; static int key_type=HA_KEYTYPE_NUM; static int create_flag=0; -static uint insert_count= 1000,update_count=1000,remove_count=1000; -static uint pack_keys=0,pack_seg=0,null_fields=0,key_length=6,skip_update=0; -static uint unique_key=HA_NOSAME,key_cacheing=0,opt_unique=0; -static uint silent; +static uint insert_count, update_count, remove_count; +static uint pack_keys=0, pack_seg=0, key_length; +static uint unique_key=HA_NOSAME; +static my_bool key_cacheing, null_fields, silent, skip_update, opt_unique, + verbose; static MI_COLUMNDEF recinfo[4]; static MI_KEYDEF keyinfo[10]; static MI_KEYSEG keyseg[10]; @@ -501,139 +504,158 @@ static void update_record(char *record) } -static struct option long_options[] = +static struct my_option my_long_options[] = { - {"checksum", no_argument, 0, 'c'}, + {"checksum", 'c', "Undocumented", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #ifndef DBUG_OFF - {"debug", required_argument, 0, '#'}, + {"debug", '#', "Undocumented", + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #endif - {"delete_rows", required_argument, 0, 'd'}, - {"help", no_argument, 0, '?'}, - {"insert_rows", required_argument, 0, 'i'}, - {"key_alpha", no_argument, 0, 'a'}, - {"key_binary_pack", no_argument, 0, 'B'}, - {"key_blob", required_argument, 0, 'b'}, - {"key_cache", no_argument, 0, 'K'}, - {"key_length", required_argument, 0, 'k'}, - {"key_multiple", no_argument, 0, 'm'}, - {"key_prefix_pack", no_argument, 0, 'P'}, - {"key_space_pack", no_argument, 0, 'p'}, - {"key_varchar", no_argument, 0, 'w'}, - {"null_fields", no_argument, 0, 'N'}, - {"row_fixed_size", no_argument, 0, 'S'}, - {"row_pointer_size", required_argument, 0, 'R'}, - {"silent", no_argument, 0, 's'}, - {"skip_update", no_argument, 0, 'U'}, - {"unique", no_argument, 0, 'C'}, - {"update_rows", required_argument, 0, 'u'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {0, 0, 0, 0} + {"delete_rows", 'd', "Undocumented", (gptr*) &remove_count, + (gptr*) &remove_count, 0, GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0}, + {"help", '?', "Display help and exit", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"insert_rows", 'i', "Undocumented", (gptr*) &insert_count, + (gptr*) &insert_count, 0, GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0}, + {"key_alpha", 'a', "Undocumented", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"key_binary_pack", 'B', "Undocumented", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"key_blob", 'b', "Undocumented", + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"key_cache", 'K', "Undocumented", (gptr*) &key_cacheing, + (gptr*) &key_cacheing, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"key_length", 'k', "Undocumented", (gptr*) &key_length, (gptr*) &key_length, + 0, GET_UINT, REQUIRED_ARG, 6, 0, 0, 0, 0, 0}, + {"key_multiple", 'm', "Undocumented", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"key_prefix_pack", 'P', "Undocumented", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"key_space_pack", 'p', "Undocumented", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"key_varchar", 'w', "Undocumented", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"null_fields", 'N', "Undocumented", + (gptr*) &null_fields, (gptr*) &null_fields, 0, GET_BOOL, NO_ARG, + 0, 0, 0, 0, 0, 0}, + {"row_fixed_size", 'S', "Undocumented", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"row_pointer_size", 'R', "Undocumented", (gptr*) &rec_pointer_size, + (gptr*) &rec_pointer_size, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"silent", 's', "Undocumented", + (gptr*) &silent, (gptr*) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"skip_update", 'U', "Undocumented", (gptr*) &skip_update, + (gptr*) &skip_update, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"unique", 'C', "Undocumented", (gptr*) &opt_unique, (gptr*) &opt_unique, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"update_rows", 'u', "Undocumented", (gptr*) &update_count, + (gptr*) &update_count, 0, GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0}, + {"verbose", 'v', "Be more verbose", (gptr*) &verbose, (gptr*) &verbose, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"version", 'V', "Print version number 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} }; +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + switch(optid) { + case 'a': + key_type= HA_KEYTYPE_TEXT; + break; + case 'c': + create_flag|= HA_CREATE_CHECKSUM; + break; + case 'R': /* Length of record pointer */ + if (rec_pointer_size > 3) + rec_pointer_size=0; + break; + case 'P': + pack_keys= HA_PACK_KEY; /* Use prefix compression */ + break; + case 'B': + pack_keys= HA_BINARY_PACK_KEY; /* Use binary compression */ + break; + case 'S': + if (key_field == FIELD_VARCHAR) + { + create_flag=0; /* Static sized varchar */ + } + else if (key_field != FIELD_BLOB) + { + key_field=FIELD_NORMAL; /* static-size record */ + extra_field=FIELD_NORMAL; + } + break; + case 'p': + pack_keys=HA_PACK_KEY; /* Use prefix + space packing */ + pack_seg=HA_SPACE_PACK; + key_type=HA_KEYTYPE_TEXT; + break; + case 'm': + unique_key=0; + break; + case 'b': + key_field=FIELD_BLOB; /* blob key */ + extra_field= FIELD_BLOB; + pack_seg|= HA_BLOB_PART; + key_type= HA_KEYTYPE_VARTEXT; + break; + case 'k': + if (key_length < 4 || key_length > MI_MAX_KEY_LENGTH) + { + fprintf(stderr,"Wrong key length\n"); + exit(1); + } + break; + case 'w': + key_field=FIELD_VARCHAR; /* varchar keys */ + extra_field= FIELD_VARCHAR; + key_type= HA_KEYTYPE_VARTEXT; + pack_seg|= HA_VAR_LENGTH; + create_flag|= HA_PACK_RECORD; + break; + case 'K': /* Use key cacheing */ + key_cacheing=1; + break; + case 'V': + printf("test1 Ver 1.1 \n"); + exit(0); + case '#': + DEBUGGER_ON; + DBUG_PUSH (argument); + break; + case '?': + usage(); + exit(1); + } + return 0; +} + + /* Read options */ -static void get_options(int argc,char *argv[]) +static void get_options(int argc, char *argv[]) { - int c,option_index=0; + int ho_error; - while ((c=getopt_long(argc,argv,"abBcCd:i:k:KmPR:SspNu:UvVw#:", - long_options, &option_index)) != EOF) + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) { - switch(c) { - case 'a': - key_type= HA_KEYTYPE_TEXT; - break; - case 'c': - create_flag|= HA_CREATE_CHECKSUM; - break; - case 'C': - opt_unique=1; - break; - case 'R': /* Length of record pointer */ - rec_pointer_size=atoi(optarg); - if (rec_pointer_size > 3) - rec_pointer_size=0; - break; - case 'P': - pack_keys= HA_PACK_KEY; /* Use prefix compression */ - break; - case 'B': - pack_keys= HA_BINARY_PACK_KEY; /* Use binary compression */ - break; - case 'S': - if (key_field == FIELD_VARCHAR) - { - create_flag=0; /* Static sized varchar */ - } - else if (key_field != FIELD_BLOB) - { - key_field=FIELD_NORMAL; /* static-size record */ - extra_field=FIELD_NORMAL; - } - break; - case 'p': - pack_keys=HA_PACK_KEY; /* Use prefix + space packing */ - pack_seg=HA_SPACE_PACK; - key_type=HA_KEYTYPE_TEXT; - break; - case 'N': - null_fields=1; /* First key part may be null */ - break; - case 'v': /* verbose */ - verbose=1; - break; - case 'd': - remove_count=atoi(optarg); - break; - case 'i': - insert_count=atoi(optarg); - break; - case 'u': - update_count=atoi(optarg); - break; - case 'U': - skip_update=1; - break; - case 'm': - unique_key=0; - break; - case 'b': - key_field=FIELD_BLOB; /* blob key */ - extra_field= FIELD_BLOB; - pack_seg|= HA_BLOB_PART; - key_type= HA_KEYTYPE_VARTEXT; - break; - case 'k': - key_length=atoi(optarg); - if (key_length < 4 || key_length > MI_MAX_KEY_LENGTH) - { - fprintf(stderr,"Wrong key length\n"); - exit(1); - } - break; - case 's': - silent=1; - break; - case 'w': - key_field=FIELD_VARCHAR; /* varchar keys */ - extra_field= FIELD_VARCHAR; - key_type= HA_KEYTYPE_VARTEXT; - pack_seg|= HA_VAR_LENGTH; - create_flag|= HA_PACK_RECORD; - break; - case 'K': /* Use key cacheing */ - key_cacheing=1; - break; - case 'V': - printf("test1 Ver 1.0 \n"); - exit(0); - case '#': - DEBUGGER_ON; - DBUG_PUSH (optarg); - break; - } + printf("%s: handle_options() failed with error %d\n", my_progname, + ho_error); + exit(1); } return; } /* get options */ + + +static void usage() +{ + printf("Usage: %s [options]\n\n", my_progname); + my_print_help(my_long_options); + my_print_variables(my_long_options); +} diff --git a/myisam/myisampack.c b/myisam/myisampack.c index 0fbbbb0bbf1..2cadeaae72a 100644 --- a/myisam/myisampack.c +++ b/myisam/myisampack.c @@ -30,7 +30,7 @@ #ifndef __GNU_LIBRARY__ #define __GNU_LIBRARY__ /* Skip warnings in getopt.h */ #endif -#include <getopt.h> +#include <my_getopt.h> #if INT_MAX > 32767 #define BITS_SAVED 32 @@ -169,9 +169,10 @@ static int mrg_rrnd(PACK_MRG_INFO *info,byte *buf); static void mrg_reset(PACK_MRG_INFO *mrg); -static int backup=0,error_on_write=0,test_only=0,verbose=0,silent=0, - write_loop=0,force_pack=0,opt_wait=0,isamchk_neaded=0; +static int error_on_write=0,test_only=0,verbose=0,silent=0, + write_loop=0,force_pack=0, isamchk_neaded=0; static int tmpfile_createflag=O_RDWR | O_TRUNC | O_EXCL; +static my_bool backup, opt_wait; static uint tree_buff_length=8196-MALLOC_OVERHEAD; static char tmp_dir[FN_REFLEN]={0},*join_table; static my_off_t intervall_length; @@ -232,26 +233,43 @@ int main(int argc, char **argv) enum options_mp {OPT_CHARSETS_DIR_MP=256}; -static struct option long_options[] = +static struct my_option my_long_options[] = { - {"backup", no_argument, 0, 'b'}, - {"character-sets-dir",required_argument,0, OPT_CHARSETS_DIR_MP}, - {"debug", optional_argument, 0, '#'}, - {"force", no_argument, 0, 'f'}, - {"join", required_argument, 0, 'j'}, - {"help", no_argument, 0, '?'}, - {"silent", no_argument, 0, 's'}, - {"tmpdir", required_argument, 0, 'T'}, - {"test", no_argument, 0, 't'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {"wait", no_argument, 0, 'w'}, - {0, 0, 0, 0} + {"backup", 'b', "Make a backup of the table as table_name.OLD", + (gptr*) &backup, (gptr*) &backup, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"character-sets-dir", OPT_CHARSETS_DIR_MP, + "Directory where character sets are.", (gptr*) &charsets_dir, + (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'", + 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, + {"force", 'f', + "Force packing of table even if it gets bigger or if tempfile exists.", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"join", 'j', + "Join all given tables into 'new_table_name'. All tables MUST have identical layouts.", + (gptr*) &join_table, (gptr*) &join_table, 0, GET_STR, 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}, + {"silent", 's', "Be more silent.", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"tmpdir", 'T', "Use temporary directory to store temporary table.", + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"test", 't', "Don't pack table, only test packing it.", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"verbose", 'v', "Write info about progress and packing result.", + 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}, + {"wait", 'w', "Wait and retry if table is in use.", (gptr*) &opt_wait, + (gptr*) &opt_wait, 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 print_version(void) { - printf("%s Ver 1.13 for %s on %s\n",my_progname,SYSTEM_TYPE,MACHINE_TYPE); + printf("%s Ver 1.20 for %s on %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE); } static void usage(void) @@ -267,22 +285,54 @@ static void usage(void) puts("You should give the .MSI file as the filename argument."); printf("\nUsage: %s [OPTIONS] filename...\n", my_progname); - puts("\n\ - -b, --backup Make a backup of the table as table_name.OLD\n\ - -f, --force Force packing of table even if it gets bigger or if\n\ - tempfile exists.\n\ - -j, --join='new_table_name'\n\ - Join all given tables into 'new_table_name'.\n\ - All tables MUST have identical layouts.\n\ - -s, --silent Be more silent.\n\ - -t, --test Don't pack table, only test packing it.\n\ - -v, --verbose Write info about progress and packing result.\n\ - -w, --wait Wait and retry if table is in use.\n\ - -T, --tmpdir=... Use temporary directory to store temporary table.\n\ - -#, --debug=... Output debug log. Often this is 'd:t:o,filename`\n\ - -?, --help Display this help and exit.\n\ - -V, --version Output version information and exit."); - print_defaults("my",load_default_groups); + my_print_help(my_long_options); + print_defaults("my", load_default_groups); + my_print_variables(my_long_options); +} + + +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + uint length; + + switch(optid) { + case 'f': + force_pack= 1; + tmpfile_createflag= O_RDWR | O_TRUNC; + break; + case 's': + write_loop= verbose= 0; + silent= 1; + break; + case 't': + test_only= verbose= 1; + break; + case 'T': + length= (uint) (strmov(tmp_dir, argument) - tmp_dir); + if (length != dirname_length(tmp_dir)) + { + tmp_dir[length]=FN_LIBCHAR; + tmp_dir[length+1]=0; + } + break; + case 'v': + verbose= 1; + silent= 0; + break; + case '#': + DBUG_PUSH(argument ? argument : "d:t:o"); + break; + case 'V': + print_version(); + exit(0); + case 'I': + case '?': + usage(); + exit(0); + } + return 0; } /* reads options */ @@ -290,66 +340,18 @@ static void usage(void) static void get_options(int *argc,char ***argv) { - int c,option_index=0; - uint length; + int ho_error; my_progname= argv[0][0]; if (isatty(fileno(stdout))) write_loop=1; - while ((c=getopt_long(*argc,*argv,"bfj:stvwT:#::?V",long_options, - &option_index)) != EOF) + if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option))) { - switch(c) { - case 'b': - backup=1; - break; - case 'f': - force_pack=1; - tmpfile_createflag=O_RDWR | O_TRUNC; - break; - case 'j': - join_table=optarg; - break; - case 's': - write_loop=verbose=0; silent=1; - break; - case 't': - test_only=verbose=1; - break; - case 'T': - length=(uint) (strmov(tmp_dir,optarg)-tmp_dir); - if (length != dirname_length(tmp_dir)) - { - tmp_dir[length]=FN_LIBCHAR; - tmp_dir[length+1]=0; - } - break; - case 'v': - verbose=1; silent=0; - break; - case 'w': - opt_wait=1; - break; - case '#': - DBUG_PUSH(optarg ? optarg : "d:t:o"); - break; - case OPT_CHARSETS_DIR_MP: - charsets_dir = optarg; - break; - case 'V': print_version(); exit(0); - case 'I': - case '?': - usage(); - exit(0); - default: - fprintf(stderr,"%s: Illegal option: -%c\n",my_progname,opterr); - usage(); - exit(1); - } + printf("%s: handle_options() failed with error %d\n", my_progname, + ho_error); + exit(1); } - (*argc)-=optind; - (*argv)+=optind; if (!*argc) { usage(); diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 11b60c8da36..80904fb46f6 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -650,7 +650,7 @@ void my_print_help(const struct my_option *options) { if (optp->id < 256) { - printf(" -%c, ", optp->id); + printf(" -%c%s", optp->id, strlen(optp->name) ? ", " : " "); col= 6; } else @@ -658,29 +658,32 @@ void my_print_help(const struct my_option *options) printf(" "); col= 2; } - printf("--%s", optp->name); - col+= 2 + strlen(optp->name); - if (optp->var_type == GET_STR || optp->var_type == GET_STR_ALLOC) + if (strlen(optp->name)) { - printf("%s=name%s ", optp->arg_type == OPT_ARG ? "[" : "", - optp->arg_type == OPT_ARG ? "]" : ""); - col+= (optp->arg_type == OPT_ARG) ? 8 : 6; - } - else if (optp->var_type == GET_NO_ARG || optp->var_type == GET_BOOL) - { - putchar(' '); - col++; - } - else - { - printf("%s=#%s ", optp->arg_type == OPT_ARG ? "[" : "", - optp->arg_type == OPT_ARG ? "]" : ""); - col+= (optp->arg_type == OPT_ARG) ? 5 : 3; - } - if (col > name_space && optp->comment && *optp->comment) - { - putchar('\n'); - col= 0; + printf("--%s", optp->name); + col+= 2 + strlen(optp->name); + if (optp->var_type == GET_STR || optp->var_type == GET_STR_ALLOC) + { + printf("%s=name%s ", optp->arg_type == OPT_ARG ? "[" : "", + optp->arg_type == OPT_ARG ? "]" : ""); + col+= (optp->arg_type == OPT_ARG) ? 8 : 6; + } + else if (optp->var_type == GET_NO_ARG || optp->var_type == GET_BOOL) + { + putchar(' '); + col++; + } + else + { + printf("%s=#%s ", optp->arg_type == OPT_ARG ? "[" : "", + optp->arg_type == OPT_ARG ? "]" : ""); + col+= (optp->arg_type == OPT_ARG) ? 5 : 3; + } + if (col > name_space && optp->comment && *optp->comment) + { + putchar('\n'); + col= 0; + } } for (; col < name_space; col++) putchar(' '); diff --git a/sql/gen_lex_hash.cc b/sql/gen_lex_hash.cc index 7ebdbcd8ba8..ba1d27f2bf6 100644 --- a/sql/gen_lex_hash.cc +++ b/sql/gen_lex_hash.cc @@ -22,13 +22,13 @@ #ifndef __GNU_LIBRARY__ #define __GNU_LIBRARY__ // Skip warnings in getopt.h #endif -#include <getopt.h> +#include <my_getopt.h> #include "mysql_version.h" #include "lex.h" -bool opt_search=0; -int opt_verbose=0; -ulong opt_count=100000; +my_bool opt_search; +int opt_verbose; +ulong opt_count; #define max_allowed_array 8000 // Don't generate bigger arrays than this #define max_symbol 32767 // Use this for 'not found' @@ -55,6 +55,35 @@ static uchar bits[how_much_and/8+1]; static uint primes[max_allowed_array+1]; static ulong hash_results[type_count][how_much_for_plus+1][total_symbols]; static ulong start_value=0; +static uint best_type; +static ulong best_t1,best_t2, best_start_value; + +static struct my_option my_long_options[] = +{ + {"help", '?', "Display help and exit", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"count", 'c', "Try count times to find a optimal hash table", + (gptr*) &opt_count, (gptr*) &opt_count, 0, GET_ULONG, REQUIRED_ARG, + 100000, 0, 0, 0, 0, 0}, + {"search", 'S', "Search after good rnd1 and rnd2 values", + (gptr*) &opt_search, (gptr*) &opt_search, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, + 0, 0}, + {"verbose", 'v', "Write some information while the program executes", + (gptr*) &opt_verbose, (gptr*) &opt_verbose, 0, GET_INT, 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}, + {"rnd1", 'r', "Set 1 part of rnd value for hash generator", + (gptr*) &best_t1, (gptr*) &best_t1, 0, GET_ULONG, REQUIRED_ARG, 6657025L, + 0, 0, 0, 0, 0}, + {"rnd2", 'R', "Set 2 part of rnd value for hash generator", + (gptr*) &best_t2, (gptr*) &best_t2, 0, GET_ULONG, REQUIRED_ARG, 6114496L, + 0, 0, 0, 0, 0}, + {"type", 't', "Set type of char table to generate", + (gptr*) &best_type, (gptr*) &best_type, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, + 0, 0, 0}, + { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} +}; struct rand_struct { unsigned long seed1,seed2,max_value; @@ -325,82 +354,51 @@ void print_arrays() } -static struct option long_options[] = -{ - {"count", required_argument, 0, 'c'}, - {"search", no_argument, 0, 'S'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {"rnd1", required_argument, 0, 'r'}, - {"rnd2", required_argument, 0, 'R'}, - {"type", required_argument, 0, 't'}, - {0, 0, 0, 0} -}; - - static void usage(int version) { - printf("%s Ver 3.3 Distrib %s, for %s (%s)\n", + printf("%s Ver 3.4 Distrib %s, for %s (%s)\n", my_progname, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE); if (version) return; puts("Copyright (C) 2001 MySQL AB, by Sinisa and Monty"); 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"); puts("This program generates a perfect hashing function for the sql_lex.cc"); - printf("Usage: %s [OPTIONS]\n", my_progname); - printf("\n\ --c, --count=# Try count times to find a optimal hash table\n\ --r, --rnd1=# Set 1 part of rnd value for hash generator\n\ --R, --rnd2=# Set 2 part of rnd value for hash generator\n\ --t, --type=# Set type of char table to generate\n\ --S, --search Search after good rnd1 and rnd2 values\n\ --v, --verbose Write some information while the program executes\n\ --V, --version Output version information and exit\n"); + printf("Usage: %s [OPTIONS]\n\n", my_progname); + my_print_help(my_long_options); + my_print_variables(my_long_options); +} + +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument __attribute__((unused))) +{ + switch(optid) { + case 'v': + opt_verbose++; + break; + case 'V': + usage(1); + exit(0); + case 'I': + case '?': + usage(0); + exit(0); + } + return 0; } -static uint best_type; -static ulong best_t1,best_t2, best_start_value; static int get_options(int argc, char **argv) { - int c,option_index=0; + int ho_error; - while ((c=getopt_long(argc,argv,"?SvVc:r:R:t:", - long_options, &option_index)) != EOF) + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) { - switch(c) { - case 'c': - opt_count=atol(optarg); - break; - case 'r': - best_t1=atol(optarg); - break; - case 'R': - best_t2=atol(optarg); - break; - case 't': - best_type=atoi(optarg); - break; - case 'S': - opt_search=1; - break; - case 'v': - opt_verbose++; - break; - case 'V': usage(1); exit(0); - case 'I': - case '?': - usage(0); - exit(0); - default: - fprintf(stderr,"illegal option: -%c\n",opterr); - usage(0); - exit(1); - } + printf("%s: handle_options() failed with error %d\n", my_progname, + ho_error); + exit(1); } - argc-=optind; - argv+=optind; if (argc >= 1) { usage(0); @@ -483,7 +481,7 @@ int main(int argc,char **argv) MY_INIT(argv[0]); - start_value=1109118L; best_t1=6657025L; best_t2=6114496L; best_type=1; /* mode=4903 add=3 type: 0 */ + start_value=1109118L; /* mode=4903 add=3 type: 0 */ if (get_options(argc,(char **) argv)) exit(1); diff --git a/tools/mysqlmanager.c b/tools/mysqlmanager.c index 4f166b2f4df..c8abb996794 100644 --- a/tools/mysqlmanager.c +++ b/tools/mysqlmanager.c @@ -30,7 +30,7 @@ #include <m_string.h> #include <m_ctype.h> #include <hash.h> -#include <getopt.h> +#include <my_getopt.h> #include <stdarg.h> #include <sys/stat.h> #include <errno.h> @@ -41,7 +41,7 @@ #include <sys/wait.h> #endif -#define MANAGER_VERSION "1.0" +#define MANAGER_VERSION "1.1" #define MANAGER_GREETING "MySQL Server Management Daemon v. 1.0" #define LOG_ERR 1 @@ -99,7 +99,7 @@ #define DO_STACKTRACE 1 #endif -uint manager_port = MANAGER_PORT; +uint manager_port; FILE* errfp; const char* manager_log_file = MANAGER_LOG_FILE; pthread_mutex_t lock_log,lock_shutdown,lock_exec_hash,lock_launch_thd; @@ -108,14 +108,14 @@ pthread_t loop_th,launch_msg_th; int manager_sock = -1; uchar* stack_bottom=0; struct sockaddr_in manager_addr; -ulong manager_bind_addr = INADDR_ANY; -int manager_back_log = MANAGER_BACK_LOG; +ulong manager_bind_addr; +int manager_back_log; int in_shutdown = 0, shutdown_requested=0; -int manager_connect_retries=MANAGER_CONNECT_RETRIES; +int manager_connect_retries; const char* manager_greeting = MANAGER_GREETING; -uint manager_max_cmd_len = MANAGER_MAX_CMD_LEN; +uint manager_max_cmd_len; const char* manager_pw_file=MANAGER_PW_FILE; -int one_thread = 0; /* for debugging */ +my_bool one_thread; /* for debugging */ typedef enum {PARAM_STDOUT,PARAM_STDERR} PARAM_TYPE; @@ -272,22 +272,44 @@ struct manager_cmd commands[] = {0,0,0,0} }; -struct option long_options[] = -{ - {"debug", optional_argument, 0, '#'}, - {"help", no_argument, 0, 'h'}, - {"port", required_argument, 0, 'P'}, - {"log", required_argument, 0, 'l'}, - {"bind-address", required_argument, 0, 'b'}, - {"tcp-backlog", required_argument, 0, 'B'}, - {"greeting", required_argument, 0, 'g'}, - {"max-command-len",required_argument,0,'m'}, - {"one-thread",no_argument,0,'d'}, - {"connect-retries",required_argument,0,'C'}, - {"password-file",required_argument,0,'p'}, - {"pid-file",required_argument,0,'f'}, - {"version", no_argument, 0, 'V'}, - {0, 0, 0, 0} + +static struct my_option my_long_options[] = +{ +#ifndef DBUG_OFF + {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'", + 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, +#endif + {"help", '?', "Display this help and exit.", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"port", 'P', "Port number to listen on.", (gptr*) &manager_port, + (gptr*) &manager_port, 0, GET_UINT, REQUIRED_ARG, MANAGER_PORT, 0, 0, 0, + 0, 0}, + {"log", 'l', "Path to log file.", (gptr*) &manager_log_file, + (gptr*) &manager_log_file, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"bind-address", 'b', "Address to listen on.", (gptr*) &manager_bind_addr, + (gptr*) &manager_bind_addr, 0, GET_ULONG, REQUIRED_ARG, INADDR_ANY, 0, + 0, 0, 0, 0}, + {"tcp-backlog", 'B', "Size of TCP/IP listen queue.", + (gptr*) &manager_back_log, (gptr*) &manager_back_log, 0, GET_INT, + REQUIRED_ARG, MANAGER_BACK_LOG, 0, 0, 0, 0, 0}, + {"greeting", 'g', "Set greeting on connect", (gptr*) &manager_greeting, + (gptr*) &manager_greeting, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"max-command-len", 'm', "Maximum command length", + (gptr*) &manager_max_cmd_len, (gptr*) &manager_max_cmd_len, 0, GET_UINT, + REQUIRED_ARG, MANAGER_MAX_CMD_LEN, 0, 0, 0, 0, 0}, + {"one-thread", 'd', "Use one thread ( for debugging)", (gptr*) &one_thread, + (gptr*) &one_thread, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"connect-retries", 'C', "Number of attempts to establish MySQL connection", + (gptr*) &manager_connect_retries, (gptr*) &manager_connect_retries, 0, + GET_INT, REQUIRED_ARG, MANAGER_CONNECT_RETRIES, 0, 0, 0, 0, 0}, + {"password-file", 'p', "Password file for manager", + (gptr*) &manager_pw_file, (gptr*) &manager_pw_file, 0, GET_STR, + REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"pid-file", 'f', "Pid file to use", (gptr*) &pid_file, (gptr*) &pid_file, + 0, GET_STR, REQUIRED_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}, + { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; static void die(const char* fmt,...); @@ -1280,76 +1302,40 @@ static void usage() printf("MySQL AB, by Sasha\n"); printf("This software comes with ABSOLUTELY NO WARRANTY\n\n"); printf("Manages instances of MySQL server.\n\n"); - printf("Usage: %s [OPTIONS]", my_progname); - printf("\n\ - -?, --help Display this help and exit.\n"); -#ifndef DBUG_OFF - puts("\ - -#, --debug=[...] Output debug log. Often this is 'd:t:o,filename`"); -#endif - printf("\ - -P, --port=... Port number to listen on.\n\ - -l, --log=... Path to log file.\n\ - -b, --bind-address=... Address to listen on.\n\ - -B, --tcp-backlog==... Size of TCP/IP listen queue.\n\ - -g, --greeting= Set greeting on connect \n\ - -m, --max-command-len Maximum command length \n\ - -d, --one-thread Use one thread ( for debugging) \n\ - -C, --connect-retries Number of attempts to establish MySQL connection \n\ - -m, --max-command-len Maximum command length \n\ - -V, --version Output version information and exit.\n\n"); + printf("Usage: %s [OPTIONS]\n\n", my_progname); + my_print_help(my_long_options); + my_print_variables(my_long_options); +} + + +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + switch (optid) { + case '#': + DBUG_PUSH(argument ? argument : "d:t:O,/tmp/mysqlmgrd.trace"); + break; + case 'V': + print_version(); + exit(0); + case '?': + usage(); + exit(0); + } + return 0; } + static int parse_args(int argc, char **argv) { - int c, option_index = 0; - while ((c=getopt_long(argc,argv,"P:?#:Vl:b:B:g:m:dC:p:f:", - long_options,&option_index)) != EOF) + int ho_error; + + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) { - switch (c) - { - case '#': - DBUG_PUSH(optarg ? optarg : "d:t:O,/tmp/mysqlmgrd.trace"); - break; - case 'd': - one_thread=1; - break; - case 'p': - manager_pw_file=optarg; - break; - case 'f': - pid_file=optarg; - break; - case 'C': - manager_connect_retries=atoi(optarg); - break; - case 'P': - manager_port=atoi(optarg); - break; - case 'm': - manager_max_cmd_len=atoi(optarg); - break; - case 'g': - manager_greeting=optarg; - case 'b': - manager_bind_addr = inet_addr(optarg); - break; - case 'B': - manager_back_log = atoi(optarg); - break; - case 'l': - manager_log_file=optarg; - break; - case 'V': - print_version(); - exit(0); - case '?': - usage(); - exit(0); - default: - usage(); - exit(1); - } + printf("%s: handle_options() failed with error %d\n", my_progname, + ho_error); + exit(1); } return 0; } diff --git a/vio/test-ssl.c b/vio/test-ssl.c index 09dae7ad5cf..9fdab86e9b9 100644 --- a/vio/test-ssl.c +++ b/vio/test-ssl.c @@ -25,11 +25,11 @@ #ifndef __GNU_LIBRARY__ #define __GNU_LIBRARY__ // Skip warnings in getopt.h #endif -#include <getopt.h> +#include <my_getopt.h> #include <signal.h> #include <violite.h> -const char *VER="0.1"; +const char *VER="0.2"; #ifndef DBUG_OFF diff --git a/vio/test-sslclient.c b/vio/test-sslclient.c index 51a78485642..84853e45485 100644 --- a/vio/test-sslclient.c +++ b/vio/test-sslclient.c @@ -25,11 +25,11 @@ #ifndef __GNU_LIBRARY__ #define __GNU_LIBRARY__ // Skip warnings in getopt.h #endif -#include <getopt.h> +#include <my_getopt.h> #include <signal.h> #include <violite.h> -const char *VER="0.1"; +const char *VER="0.2"; #ifndef DBUG_OFF diff --git a/vio/test-sslserver.c b/vio/test-sslserver.c index 988019a012b..a9e28ac7a58 100644 --- a/vio/test-sslserver.c +++ b/vio/test-sslserver.c @@ -25,11 +25,11 @@ #ifndef __GNU_LIBRARY__ #define __GNU_LIBRARY__ // Skip warnings in getopt.h #endif -#include <getopt.h> +#include <my_getopt.h> #include <signal.h> #include <violite.h> -const char *VER="0.1"; +const char *VER="0.2"; #ifndef DBUG_OFF diff --git a/vio/viotest-ssl.c b/vio/viotest-ssl.c index 8c549ae1d38..1a766a3fc97 100644 --- a/vio/viotest-ssl.c +++ b/vio/viotest-ssl.c @@ -25,12 +25,12 @@ #ifndef __GNU_LIBRARY__ #define __GNU_LIBRARY__ // Skip warnings in getopt.h #endif -#include <getopt.h> +#include <my_getopt.h> //#include "my_readline.h" #include <signal.h> #include <violite.h> -const char *VER="0.1"; +const char *VER="0.2"; #ifndef DBUG_OFF |