diff options
author | monty@hundin.mysql.fi <> | 2002-01-26 01:24:38 +0200 |
---|---|---|
committer | monty@hundin.mysql.fi <> | 2002-01-26 01:24:38 +0200 |
commit | 20530c307b3deb5261c502f3e60f6da3c5ae02fc (patch) | |
tree | b651f8314c59f530a2ad12e2f9c83630cb92c89a /myisam | |
parent | b9d3a55238c02baf8f4b088530e924934ecbf74c (diff) | |
parent | 40fcae6d4b7c02e6cd18b98d8d3b8c525e51aeae (diff) | |
download | mariadb-git-20530c307b3deb5261c502f3e60f6da3c5ae02fc.tar.gz |
merge
Diffstat (limited to 'myisam')
-rw-r--r-- | myisam/myisamchk.c | 404 |
1 files changed, 220 insertions, 184 deletions
diff --git a/myisam/myisamchk.c b/myisam/myisamchk.c index 1ed23ffe4f6..eedbb6af940 100644 --- a/myisam/myisamchk.c +++ b/myisam/myisamchk.c @@ -20,7 +20,7 @@ #include <m_ctype.h> #include <stdarg.h> -#include <getopt.h> +#include <my_getopt.h> #include <assert.h> #ifdef HAVE_SYS_VADVICE_H #include <sys/vadvise.h> @@ -169,58 +169,75 @@ static CHANGEABLE_VAR changeable_vars[] = { enum options { OPT_CHARSETS_DIR=256, OPT_SET_CHARSET,OPT_START_CHECK_POS, - OPT_CORRECT_CHECKSUM + OPT_CORRECT_CHECKSUM, OPT_KEY_BUFFER_SIZE, OPT_MYISAM_BLOCK_SIZE, + OPT_READ_BUFFER_SIZE, OPT_WRITE_BUFFER_SIZE, OPT_SORT_BUFFER_SIZE, + OPT_SORT_KEY_BLOCKS, OPT_DECODE_BITS, OPT_FT_MIN_WORD_LEN, + OPT_FT_MAX_WORD_LEN, OPT_FT_MAX_WORD_LEN_FOR_SORT }; - -static struct option long_options[] = +static struct my_option my_long_options[] = { - {"analyze", no_argument, 0, 'a'}, - {"block-search", required_argument,0, 'b'}, - {"backup", no_argument, 0, 'B'}, - {"character-sets-dir",required_argument,0, OPT_CHARSETS_DIR}, - {"check", no_argument, 0, 'c'}, - {"check-only-changed",no_argument, 0, 'C'}, - {"correct-checksum", no_argument, 0, OPT_CORRECT_CHECKSUM}, + {"analyze", "", 0, 0, GET_NO_ARG, NO_ARG, 'a', 0, 0, 0, 0, 0, 0, 0}, + {"block-search", "", 0, 0, GET_LL, REQUIRED_ARG, 'b', 0, 0, 0, 0, 0, 0, 0}, + {"backup", "", 0, 0, GET_NO_ARG, NO_ARG, 'B', 0, 0, 0, 0, 0, 0, 0}, + {"character-sets-dir", "", 0, 0, GET_STR, REQUIRED_ARG, OPT_CHARSETS_DIR, 0, 0, 0, 0, 0, 0, 0}, + + {"check", "", 0, 0, GET_NO_ARG, NO_ARG, 'c', 0, 0, 0, 0, 0, 0, 0}, + {"check-only-changed", "", 0, 0, GET_NO_ARG, NO_ARG, 'C', 0, 0, 0, 0, 0, 0, 0}, + + {"correct-checksum", "", 0, 0, GET_NO_ARG, NO_ARG, OPT_CORRECT_CHECKSUM, 0, 0, 0, 0, 0, 0, 0}, #ifndef DBUG_OFF - {"debug", optional_argument, 0, '#'}, + {"debug", "", 0, 0, GET_STR, OPT_ARG, '#', 0, 0, 0, 0, 0, 0, 0}, #endif - {"description", no_argument, 0, 'd'}, - {"data-file-length", required_argument, 0, 'D'}, - {"extend-check", no_argument, 0, 'e'}, - {"fast", no_argument, 0, 'F'}, - {"force", no_argument, 0, 'f'}, - {"help", no_argument, 0, '?'}, - {"information", no_argument, 0, 'i'}, - {"keys-used", required_argument, 0, 'k'}, - {"medium-check", no_argument, 0, 'm'}, - {"quick", no_argument, 0, 'q'}, - {"read-only", no_argument, 0, 'T'}, - {"recover", no_argument, 0, 'r'}, - {"safe-recover", no_argument, 0, 'o'}, - {"start-check-pos", required_argument, 0, OPT_START_CHECK_POS}, - {"set-auto-increment",optional_argument, 0, 'A'}, - {"set-character-set",required_argument,0,OPT_SET_CHARSET}, - {"set-variable", required_argument, 0, 'O'}, - {"silent", no_argument, 0, 's'}, - {"sort-index", no_argument, 0, 'S'}, - {"sort-records", required_argument, 0, 'R'}, - {"sort-recover", no_argument, 0, 'n'}, - {"tmpdir", required_argument, 0, 't'}, - {"update-state", no_argument, 0, 'U'}, - {"unpack", no_argument, 0, 'u'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {"wait", no_argument, 0, 'w'}, - {0, 0, 0, 0} + {"description", "", 0, 0, GET_NO_ARG, NO_ARG, 'd', 0, 0, 0, 0, 0, 0, 0}, + {"data-file-length", "", 0, 0, GET_LL, REQUIRED_ARG, 'D', 0, 0, 0, 0, 0, 0, 0}, + {"extend-check", "", 0, 0, GET_NO_ARG, NO_ARG, 'e', 0, 0, 0, 0, 0, 0, 0}, + {"fast", "", 0, 0, GET_NO_ARG, NO_ARG, 'F', 0, 0, 0, 0, 0, 0, 0}, + {"force", "", 0, 0, GET_NO_ARG, NO_ARG, 'f', 0, 0, 0, 0, 0, 0, 0}, + {"help", "", 0, 0, GET_NO_ARG, NO_ARG, '?', 0, 0, 0, 0, 0, 0, 0}, + {"information", "", 0, 0, GET_NO_ARG, NO_ARG, 'i', 0, 0, 0, 0, 0, 0, 0}, + {"keys-used", "", 0, 0, GET_LL, REQUIRED_ARG, 'k', 0, 0, 0, 0, 0, 0, 0}, + {"medium-check", "", 0, 0, GET_NO_ARG, NO_ARG, 'm', 0, 0, 0, 0, 0, 0, 0}, + {"quick", "", 0, 0, GET_NO_ARG, NO_ARG, 'q', 0, 0, 0, 0, 0, 0, 0}, + {"read-only", "", 0, 0, GET_NO_ARG, NO_ARG, 'T', 0, 0, 0, 0, 0, 0, 0}, + {"recover", "", 0, 0, GET_NO_ARG, NO_ARG, 'r', 0, 0, 0, 0, 0, 0, 0}, + {"safe-recover", "", 0, 0, GET_NO_ARG, NO_ARG, 'o', 0, 0, 0, 0, 0, 0, 0}, + {"start-check-pos", "", 0, 0, GET_LL, REQUIRED_ARG, OPT_START_CHECK_POS, 0, 0, 0, 0, 0, 0, 0}, + {"set-auto-increment", "", 0, 0, GET_LL, OPT_ARG, 'A', 0, 0, 0, 0, 0, 0, 0}, + {"set-character-set", "", 0, 0, GET_STR, REQUIRED_ARG, OPT_SET_CHARSET, 0, 0, 0, 0, 0, 0, 0}, + {"set-variable", "", 0, 0, GET_STR, REQUIRED_ARG, 'O', 0, 0, 0, 0, 0, 0, 0}, + {"silent", "", 0, 0, GET_NO_ARG, NO_ARG, 's', 0, 0, 0, 0, 0, 0, 0}, + {"sort-index", "", 0, 0, GET_NO_ARG, NO_ARG, 'S', 0, 0, 0, 0, 0, 0, 0}, + {"sort-records", "", 0, 0, GET_INT, REQUIRED_ARG, 'R', 0, 0, 0, 0, 0, 0, 0}, + {"sort-recover", "", 0, 0, GET_NO_ARG, NO_ARG, 'n', 0, 0, 0, 0, 0, 0, 0}, + {"tmpdir", "", 0, 0, GET_STR, REQUIRED_ARG, 't', 0, 0, 0, 0, 0, 0, 0}, + {"update-state", "", 0, 0, GET_NO_ARG, NO_ARG, 'U', 0, 0, 0, 0, 0, 0, 0}, + {"unpack", "", 0, 0, GET_NO_ARG, NO_ARG, 'u', 0, 0, 0, 0, 0, 0, 0}, + {"verbose", "", 0, 0, GET_NO_ARG, NO_ARG, 'v', 0, 0, 0, 0, 0, 0, 0}, + {"version", "", 0, 0, GET_NO_ARG, NO_ARG, 'V', 0, 0, 0, 0, 0, 0, 0}, + {"wait", "", 0, 0, GET_NO_ARG, NO_ARG, 'w', 0, 0, 0, 0, 0, 0, 0}, + /* variables begin here */ + { "key_buffer_size", "", 0, 0, GET_LL, REQUIRED_ARG, OPT_KEY_BUFFER_SIZE, 0, 0, 0, 0, 0, 0, 1}, + { "myisam_block_size", "", 0, 0, GET_LL, REQUIRED_ARG, OPT_MYISAM_BLOCK_SIZE, 0, 0, 0, 0, 0, 0, 1}, + { "read_buffer_size", "", 0, 0, GET_LL, REQUIRED_ARG, OPT_READ_BUFFER_SIZE, 0, 0, 0, 0, 0, 0, 1}, + { "write_buffer_size", "", 0, 0, GET_LL, REQUIRED_ARG, OPT_WRITE_BUFFER_SIZE, 0, 0, 0, 0, 0, 0, 1}, + { "sort_buffer_size", "", 0, 0, GET_LL, REQUIRED_ARG, OPT_SORT_BUFFER_SIZE, 0, 0, 0, 0, 0, 0, 1}, + { "sort_key_blocks", "", 0, 0, GET_LL, REQUIRED_ARG, OPT_SORT_KEY_BLOCKS, 0, 0, 0, 0, 0, 0, 1}, + { "decode_bits", "", 0, 0, GET_LL, REQUIRED_ARG, OPT_DECODE_BITS, 0, 0, 0, 0, 0, 0, 1}, + { "ft_min_word_len", "", 0, 0, GET_LL, REQUIRED_ARG, OPT_FT_MIN_WORD_LEN, 0, 0, 0, 0, 0, 0, 1}, + { "ft_max_word_len", "", 0, 0, GET_LL, REQUIRED_ARG, OPT_FT_MAX_WORD_LEN, 0, 0, 0, 0, 0, 0, 1}, + { "ft_max_word_len_for_sort", "", 0, 0, GET_LL, REQUIRED_ARG, OPT_FT_MAX_WORD_LEN_FOR_SORT, 0, 0, 0, 0, 0, 0, 1}, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; + static void print_version(void) { - printf("%s Ver 2.0 for %s at %s\n",my_progname,SYSTEM_TYPE, + printf("%s Ver 2.1 for %s at %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE); } + static void usage(void) { uint i; @@ -315,163 +332,182 @@ static void usage(void) /* Read options */ +static my_bool get_one_option(int optid, const struct my_option *opt, + char *argument) +{ + uint old_testflag; + char buff[255], *end; + + switch(optid) { + case 'a': + check_param.testflag|= T_STATISTICS; + break; + case 'A': + if (argument) + check_param.auto_increment_value=strtoull(argument, NULL, 0); + else + check_param.auto_increment_value=0; /* Set to max used value */ + check_param.testflag|= T_AUTO_INC; + break; + case 'b': + check_param.search_after_block=strtoul(argument, NULL, 10); + break; + case 'B': + check_param.testflag|= T_BACKUP_DATA; + break; + case 'c': + check_param.testflag|= T_CHECK; + break; + case 'C': + check_param.testflag|= T_CHECK | T_CHECK_ONLY_CHANGED; + break; + case 'D': + check_param.max_data_file_length=strtoll(argument, NULL, 10); + break; + case 's': /* silent */ + if (check_param.testflag & T_SILENT) + check_param.testflag|=T_VERY_SILENT; + check_param.testflag|= T_SILENT; + check_param.testflag&= ~T_WRITE_LOOP; + break; + case 'w': + check_param.testflag|= T_WAIT_FOREVER; + break; + case 'd': /* description if isam-file */ + check_param.testflag|= T_DESCRIPT; + break; + case 'e': /* extend check */ + check_param.testflag|= T_EXTEND; + break; + case 'i': + check_param.testflag|= T_INFO; + break; + case 'f': + check_param.tmpfile_createflag= O_RDWR | O_TRUNC; + check_param.testflag|= T_FORCE_CREATE | T_UPDATE_STATE; + break; + case 'F': + check_param.testflag|=T_FAST; + break; + case 'k': + check_param.keys_in_use= (ulonglong) strtoll(argument, NULL, 10); + break; + case 'm': + check_param.testflag|= T_MEDIUM; /* Medium check */ + break; + case 'r': /* Repair table */ + check_param.testflag= (check_param.testflag & ~T_REP) | T_REP_BY_SORT; + break; + case 'o': + check_param.testflag= (check_param.testflag & ~T_REP_BY_SORT) | T_REP; + check_param.force_sort=0; + my_disable_async_io=1; /* More safety */ + break; + case 'n': + check_param.testflag= (check_param.testflag & ~T_REP) | T_REP_BY_SORT; + check_param.force_sort=1; + break; + case 'q': + check_param.opt_rep_quick++; + break; + case 'u': + check_param.testflag|= T_UNPACK | T_REP_BY_SORT; + break; + case 'v': /* Verbose */ + check_param.testflag|= T_VERBOSE; + check_param.verbose++; + break; + case 'O': + /* this is a temporary fix for variables to work until my_getopt */ + /* can my_set_changeable_vars */ + case OPT_KEY_BUFFER_SIZE: + case OPT_MYISAM_BLOCK_SIZE: + case OPT_READ_BUFFER_SIZE: + case OPT_WRITE_BUFFER_SIZE: + case OPT_SORT_BUFFER_SIZE: + case OPT_SORT_KEY_BLOCKS: + case OPT_DECODE_BITS: + case OPT_FT_MIN_WORD_LEN: + case OPT_FT_MAX_WORD_LEN: + case OPT_FT_MAX_WORD_LEN_FOR_SORT: + end= buff; + end= strmov(strmov(strmov(end, opt->name), "="), argument); + if (set_changeable_var(buff, changeable_vars)) + { + usage(); + exit(1); + } + break; + case 'R': /* Sort records */ + old_testflag=check_param.testflag; + check_param.testflag|= T_SORT_RECORDS; + check_param.opt_sort_key=(uint) atoi(argument) - 1; + if (check_param.opt_sort_key >= MI_MAX_KEY) + { + fprintf(stderr, + "The value of the sort key is bigger than max key: %d.\n", + MI_MAX_KEY); + exit(1); + } + break; + case 'S': /* Sort index */ + old_testflag=check_param.testflag; + check_param.testflag|= T_SORT_INDEX; + break; + case 't': + check_param.tmpdir=argument; + break; + case 'T': + check_param.testflag|= T_READONLY; + break; + case 'U': + check_param.testflag|= T_UPDATE_STATE; + break; + case '#': + DBUG_PUSH(argument ? argument : "d:t:o,/tmp/myisamchk.trace"); + break; + case 'V': + print_version(); + exit(0); + case OPT_CORRECT_CHECKSUM: + check_param.testflag|=T_CALC_CHECKSUM; + break; + case OPT_CHARSETS_DIR: + charsets_dir= argument; + break; + case OPT_SET_CHARSET: + set_charset_name= argument; + break; +#ifdef DEBUG /* Only useful if debugging */ + case OPT_START_CHECK_POS: + check_param.start_check_pos=strtoull(argument, NULL, 0); + break; +#endif + case '?': + usage(); + exit(0); + } +} + + static void get_options(register int *argc,register char ***argv) { int c,option_index=0; - uint old_testflag; load_defaults("my",load_default_groups,argc,argv); default_argv= *argv; set_all_changeable_vars(changeable_vars); if (isatty(fileno(stdout))) check_param.testflag|=T_WRITE_LOOP; - while ((c=getopt_long(*argc,*argv, - "aBcCdeifF?lqrmnosSTuUvVw#:b:D:k:O:R:A::t:", - long_options, &option_index)) != EOF) - { - switch(c) { - case 'a': - check_param.testflag|= T_STATISTICS; - break; - case 'A': - if (optarg) - check_param.auto_increment_value=strtoull(optarg,NULL,0); - else - check_param.auto_increment_value=0; /* Set to max used value */ - check_param.testflag|= T_AUTO_INC; - break; - case 'b': - check_param.search_after_block=strtoul(optarg,NULL,10); - break; - case 'B': - check_param.testflag|= T_BACKUP_DATA; - break; - case 'c': - check_param.testflag|= T_CHECK; - break; - case 'C': - check_param.testflag|= T_CHECK | T_CHECK_ONLY_CHANGED; - break; - case 'D': - check_param.max_data_file_length=strtoll(optarg,NULL,10); - break; - case 's': /* silent */ - if (check_param.testflag & T_SILENT) - check_param.testflag|=T_VERY_SILENT; - check_param.testflag|= T_SILENT; - check_param.testflag&= ~T_WRITE_LOOP; - break; - case 'w': - check_param.testflag|= T_WAIT_FOREVER; - break; - case 'd': /* description if isam-file */ - check_param.testflag|= T_DESCRIPT; - break; - case 'e': /* extend check */ - check_param.testflag|= T_EXTEND; - break; - case 'i': - check_param.testflag|= T_INFO; - break; - case 'f': - check_param.tmpfile_createflag= O_RDWR | O_TRUNC; - check_param.testflag|= T_FORCE_CREATE | T_UPDATE_STATE; - break; - case 'F': - check_param.testflag|=T_FAST; - break; - case 'k': - check_param.keys_in_use= (ulonglong) strtoll(optarg,NULL,10); - break; - case 'm': - check_param.testflag|= T_MEDIUM; /* Medium check */ - break; - case 'r': /* Repair table */ - check_param.testflag= (check_param.testflag & ~T_REP) | T_REP_BY_SORT; - break; - case 'o': - check_param.testflag= (check_param.testflag & ~T_REP_BY_SORT) | T_REP; - check_param.force_sort=0; - my_disable_async_io=1; /* More safety */ - break; - case 'n': - check_param.testflag= (check_param.testflag & ~T_REP) | T_REP_BY_SORT; - check_param.force_sort=1; - break; - case 'q': - check_param.opt_rep_quick++; - break; - case 'u': - check_param.testflag|= T_UNPACK | T_REP_BY_SORT; - break; - case 'v': /* Verbose */ - check_param.testflag|= T_VERBOSE; - check_param.verbose++; - break; - case 'O': - if (set_changeable_var(optarg, changeable_vars)) - { - usage(); - exit(1); - } - break; - case 'R': /* Sort records */ - old_testflag=check_param.testflag; - check_param.testflag|= T_SORT_RECORDS; - check_param.opt_sort_key=(uint) atoi(optarg)-1; - if (check_param.opt_sort_key >= MI_MAX_KEY) - { - fprintf(stderr, - "The value of the sort key is bigger than max key: %d.\n", - MI_MAX_KEY); - exit(1); - } - break; - case 'S': /* Sort index */ - old_testflag=check_param.testflag; - check_param.testflag|= T_SORT_INDEX; - break; - case 't': - check_param.tmpdir=optarg; - break; - case 'T': - check_param.testflag|= T_READONLY; - break; - case 'U': - check_param.testflag|= T_UPDATE_STATE; - break; - case '#': - DBUG_PUSH(optarg ? optarg : "d:t:o,/tmp/myisamchk.trace"); - break; - case 'V': - print_version(); - exit(0); - case OPT_CORRECT_CHECKSUM: - check_param.testflag|=T_CALC_CHECKSUM; - break; - case OPT_CHARSETS_DIR: - charsets_dir = optarg; - break; - case OPT_SET_CHARSET: - set_charset_name=optarg; - break; -#ifdef DEBUG /* Only useful if debugging */ - case OPT_START_CHECK_POS: - check_param.start_check_pos=strtoull(optarg,NULL,0); - break; -#endif - case '?': - usage(); - exit(0); - } - } + + if (handle_options(argc, argv, my_long_options, get_one_option)) + exit(1); + /* If using repair, then update checksum if one uses --update-state */ if ((check_param.testflag & T_UPDATE_STATE) && (check_param.testflag & (T_REP | T_REP_BY_SORT))) check_param.testflag|= T_CALC_CHECKSUM; - (*argc)-=optind; - (*argv)+=optind; if (*argc == 0) { usage(); |