summaryrefslogtreecommitdiff
path: root/isam
diff options
context:
space:
mode:
authorunknown <monty@hundin.mysql.fi>2002-06-03 12:59:31 +0300
committerunknown <monty@hundin.mysql.fi>2002-06-03 12:59:31 +0300
commitf0409fa920c7908f2f9ef03919583a32bf84eaad (patch)
treebe04186411dc657ef6bbcbe01267d30f2675c914 /isam
parentebbcb0f391d7df364e0ccc6bca706456e9aadbf7 (diff)
parent7cb2e2d1dce2c7466388f4a6ade0614564be82fc (diff)
downloadmariadb-git-f0409fa920c7908f2f9ef03919583a32bf84eaad.tar.gz
merge with 4.0
BitKeeper/etc/ignore: auto-union BitKeeper/etc/logging_ok: auto-union BUILD/SETUP.sh: Auto merged BUILD/compile-pentium-debug: Auto merged BitKeeper/triggers/post-commit: Auto merged configure.in: Auto merged Docs/manual.texi: Auto merged client/mysql.cc: Auto merged client/mysqldump.c: Auto merged client/mysqltest.c: Auto merged extra/mysql_install.c: Auto merged extra/resolve_stack_dump.c: Auto merged extra/resolveip.c: Auto merged include/my_sys.h: Auto merged include/mysqld_error.h: Auto merged isam/pack_isam.c: Auto merged libmysql/Makefile.shared: Auto merged libmysql/libmysql.c: Auto merged myisam/ft_dump.c: Auto merged myisam/ft_test1.c: Auto merged myisam/ftdefs.h: Auto merged myisam/mi_check.c: Auto merged myisam/mi_test1.c: Auto merged myisam/mi_write.c: Auto merged myisam/myisamchk.c: Auto merged myisam/myisampack.c: Auto merged mysql-test/mysql-test-run.sh: Auto merged mysql-test/r/select_found.result: Auto merged mysql-test/t/select_found.test: Auto merged mysys/charset.c: Auto merged mysys/default.c: Auto merged mysys/hash.c: Auto merged sql/field.cc: Auto merged sql/gen_lex_hash.cc: Auto merged sql/ha_innodb.cc: Auto merged sql/hostname.cc: Auto merged sql/item_cmpfunc.h: Auto merged sql/item_strfunc.cc: Auto merged sql/item_timefunc.h: Auto merged sql/lex.h: Auto merged sql/log.cc: Auto merged sql/mysql_priv.h: Auto merged sql/repl_failsafe.cc: Auto merged sql/slave.cc: Auto merged sql/sql_acl.cc: Auto merged sql/sql_base.cc: Auto merged sql/sql_cache.cc: Auto merged sql/sql_class.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_db.cc: Auto merged sql/sql_parse.cc: Auto merged sql/sql_select.cc: Auto merged sql/sql_string.cc: Auto merged sql/sql_table.cc: Auto merged sql/sql_union.cc: Auto merged sql/share/czech/errmsg.txt: Auto merged sql/share/danish/errmsg.txt: Auto merged sql/share/dutch/errmsg.txt: Auto merged sql/share/english/errmsg.txt: Auto merged sql/share/estonian/errmsg.txt: Auto merged sql/share/german/errmsg.txt: Auto merged sql/share/greek/errmsg.txt: Auto merged sql/share/hungarian/errmsg.txt: Auto merged sql/share/italian/errmsg.txt: Auto merged sql/share/japanese/errmsg.txt: Auto merged sql/share/korean/errmsg.txt: Auto merged sql/share/norwegian-ny/errmsg.txt: Auto merged sql/share/norwegian/errmsg.txt: Auto merged sql/sql_update.cc: Auto merged sql/structs.h: Auto merged sql/share/polish/errmsg.txt: Auto merged sql/share/portuguese/errmsg.txt: Auto merged sql/share/romanian/errmsg.txt: Auto merged sql/share/russian/errmsg.txt: Auto merged sql/share/slovak/errmsg.txt: Auto merged sql/share/spanish/errmsg.txt: Auto merged sql/share/swedish/errmsg.txt: Auto merged sql/share/ukrainian/errmsg.txt: Auto merged strings/Makefile.am: Auto merged strings/ctype-ujis.c: Auto merged tools/mysqlmanager.c: Auto merged
Diffstat (limited to 'isam')
-rw-r--r--isam/isamchk.c378
-rw-r--r--isam/pack_isam.c216
2 files changed, 291 insertions, 303 deletions
diff --git a/isam/isamchk.c b/isam/isamchk.c
index c09b1cd3324..23bded29f79 100644
--- a/isam/isamchk.c
+++ b/isam/isamchk.c
@@ -20,7 +20,7 @@
#include <m_ctype.h>
#include <stdarg.h>
-#include <getopt.h>
+#include <my_getopt.h>
#ifdef HAVE_SYS_VADVICE_H
#include <sys/vadvise.h>
#endif
@@ -94,12 +94,16 @@ typedef struct st_isam_sort_info {
N_KEYSEG *keyseg;
} ISAM_SORT_INFO;
-enum ic_options {OPT_CHARSETS_DIR_IC=256};
+enum ic_options {OPT_CHARSETS_DIR_IC=256, OPT_KEY_BUFFER_SIZE,
+ OPT_READ_BUFFER_SIZE, OPT_WRITE_BUFFER_SIZE,
+ OPT_SORT_BUFFER_SIZE, OPT_SORT_KEY_BLOCKS,
+ OPT_DECODE_BITS};
static ulong use_buffers=0,read_buffer_length=0,write_buffer_length=0,
sort_buffer_length=0,sort_key_blocks=0,crc=0,unique_count=0;
static uint testflag=0,out_flag=0,warning_printed=0,error_printed=0,
- rep_quick=0,verbose=0,opt_follow_links=1;
+ verbose=0,opt_follow_links=1;
+static my_bool rep_quick= 0;
static uint opt_sort_key=0,total_files=0,max_level=0,max_key=N_MAXKEY;
static ulong keydata=0,totaldata=0,key_blocks=0;
static ulong new_file_pos=0,record_checksum=0,key_file_blocks=0,decode_bits;
@@ -234,118 +238,118 @@ int main( int argc, char **argv)
} /* main */
-static CHANGEABLE_VAR changeable_vars[] = {
- { "key_buffer_size",(long*) &use_buffers,(long) USE_BUFFER_INIT,
- (long) MALLOC_OVERHEAD, (long) ~0L,(long) MALLOC_OVERHEAD,(long) IO_SIZE },
- { "read_buffer_size", (long*) &read_buffer_length,(long) READ_BUFFER_INIT,
- (long) MALLOC_OVERHEAD,(long) ~0L,(long) MALLOC_OVERHEAD,(long) 1L },
- { "write_buffer_size", (long*) &write_buffer_length,(long) READ_BUFFER_INIT,
- (long) MALLOC_OVERHEAD,(long) ~0L,(long) MALLOC_OVERHEAD,(long) 1L },
- { "sort_buffer_size",(long*) &sort_buffer_length,(long) SORT_BUFFER_INIT,
- (long) (MIN_SORT_BUFFER+MALLOC_OVERHEAD),(long) ~0L,
- (long) MALLOC_OVERHEAD,(long) 1L },
- { "sort_key_blocks",(long*) &sort_key_blocks,BUFFERS_WHEN_SORTING,4L,100L,0L,
- 1L },
- { "decode_bits",(long*) &decode_bits,9L,4L,17L,0L,1L },
- { NullS,(long*) 0,0L,0L,0L,0L,0L,} };
-
-
-static struct option long_options[] =
+static struct my_option my_long_options[] =
{
- {"analyze", no_argument, 0, 'a'},
- {"character-sets-dir", required_argument, 0, OPT_CHARSETS_DIR_IC},
+ {"analyze", 'a',
+ "Analyze distribution of keys. Will make some joins in MySQL faster.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"character-sets-dir", OPT_CHARSETS_DIR_IC,
+ "Directory where character sets are", (gptr*) &charsets_dir,
+ (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#ifndef DBUG_OFF
- {"debug", required_argument, 0, '#'},
+ {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'",
+ 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#endif
- {"default-character-set", required_argument, 0, 'C'},
- {"description", no_argument, 0, 'd'},
- {"extend-check", no_argument, 0, 'e'},
- {"information", no_argument, 0, 'i'},
- {"force", no_argument, 0, 'f'},
- {"help", no_argument, 0, '?'},
- {"keys-used", required_argument, 0, 'k'},
- {"no-symlinks", no_argument, 0, 'l'},
- {"quick", no_argument, 0, 'q'},
- {"recover", no_argument, 0, 'r'},
- {"safe-recover", no_argument, 0, 'o'},
- {"block-search", required_argument, 0, 'b'},
- {"set-variable", required_argument, 0, 'O'},
- {"silent", no_argument, 0, 's'},
- {"sort-index", no_argument, 0, 'S'},
- {"sort-records", required_argument, 0, 'R'},
- {"unpack", no_argument, 0, 'u'},
- {"verbose", no_argument, 0, 'v'},
- {"version", no_argument, 0, 'V'},
- {"wait", no_argument, 0, 'w'},
- {0, 0, 0, 0}
+ {"default-character-set", 'C', "Set the default character set",
+ (gptr*) &default_charset, (gptr*) &default_charset, 0, GET_STR,
+ REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"description", 'd', "Prints some information about table.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"extend-check", 'e',
+ "Check the table VERY thoroughly. One need to use this only in extreme cases, because isamchk should normally find all errors even without this switch.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"information", 'i', "Print statistics information about the table",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"force", 'f',
+ "Overwrite old temporary files. If one uses -f when checking tables (running isamchk without -r), isamchk will automatically restart with -r on any wrong table.",
+ 0, 0, 0, GET_NO_ARG, NO_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},
+ {"keys-used", 'k',
+ "Used with '-r'. Tell ISAM to update only the first # keys. This can be used to get faster inserts!",
+ (gptr*) &max_key, (gptr*) &max_key, 0, GET_UINT, REQUIRED_ARG, N_MAXKEY, 0,
+ 0, 0, 0, 0},
+ {"no-symlinks", 'l',
+ "Do not follow symbolic links when repairing. Normally isamchk repairs the table a symlink points at.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"quick", 'q',
+ "Used with -r to get a faster repair. (The data file isn't touched.) One can give a second '-q' to force isamchk to modify the original datafile.",
+ (gptr*) &rep_quick, (gptr*) &rep_quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
+ 0},
+ {"recover", 'r',
+ "Can fix almost anything except unique keys that aren't unique.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"safe-recover", 'o',
+ "Uses old recovery method; slower than '-r' but can handle a couple of cases that '-r' cannot handle.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"set-variable", 'O',
+ "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
+ 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"block-search", 'b', "For debugging.", (gptr*) &search_after_block,
+ (gptr*) &search_after_block, 0, GET_ULONG, REQUIRED_ARG, NI_POS_ERROR, 0,
+ 0, 0, 0, 0},
+ {"silent", 's',
+ "Only print errors. One can use two -s to make isamchk very silent.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"sort-index", 'S',
+ "Sort index blocks. This speeds up 'read-next' in applications.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"sort-records", 'R',
+ "Sort records according to an index. This makes your data much more localized and may speed up things (It may be VERY slow to do a sort the first time!)",
+ (gptr*) &opt_sort_key, (gptr*) &opt_sort_key, 0, GET_UINT, REQUIRED_ARG,
+ 0, 0, (N_MAXKEY - 1), 1, 0, 0},
+ {"unpack", 'u', "Unpack file packed with pack_isam.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"verbose", 'v',
+ "Print more information. This can be used with -d and -e. Use many -v for more verbosity!",
+ 0, 0, 0, GET_NO_ARG, NO_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},
+ {"wait", 'w', "Wait if table is locked.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"key_buffer_size", OPT_KEY_BUFFER_SIZE, "", (gptr*) &use_buffers,
+ (gptr*) &use_buffers, 0, GET_ULONG, REQUIRED_ARG, (long) USE_BUFFER_INIT,
+ (long) MALLOC_OVERHEAD, (long) ~0L, (long) MALLOC_OVERHEAD, (long) IO_SIZE,
+ 0},
+ {"read_buffer_size", OPT_READ_BUFFER_SIZE, "",
+ (gptr*) &read_buffer_length, (gptr*) &read_buffer_length, 0, GET_ULONG,
+ REQUIRED_ARG, (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
+ (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
+ {"write_buffer_size", OPT_WRITE_BUFFER_SIZE, "",
+ (gptr*) &write_buffer_length, (gptr*) &write_buffer_length, 0, GET_ULONG,
+ REQUIRED_ARG, (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD, (long) ~0L,
+ (long) MALLOC_OVERHEAD, (long) 1L, 0},
+ {"sort_buffer_size", OPT_SORT_BUFFER_SIZE, "",
+ (gptr*) &sort_buffer_length, (gptr*) &sort_buffer_length, 0, GET_ULONG,
+ REQUIRED_ARG, (long) SORT_BUFFER_INIT,
+ (long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD), (long) ~0L,
+ (long) MALLOC_OVERHEAD, (long) 1L, 0},
+ {"sort_key_blocks", OPT_SORT_KEY_BLOCKS, "",
+ (gptr*) &sort_key_blocks, (gptr*) &sort_key_blocks, 0, GET_ULONG,
+ REQUIRED_ARG, BUFFERS_WHEN_SORTING, 4L, 100L, 0L, 1L, 0},
+ {"decode_bits", OPT_DECODE_BITS, "",
+ (gptr*) &decode_bits, (gptr*) &decode_bits, 0, GET_ULONG, REQUIRED_ARG,
+ 9L, 4L, 17L, 0L, 1L, 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 5.17 for %s at %s\n",my_progname,SYSTEM_TYPE,
+ printf("%s Ver 6.01 for %s at %s\n", my_progname, SYSTEM_TYPE,
MACHINE_TYPE);
}
static void usage(void)
{
- uint i;
print_version();
- puts("TCX Datakonsult AB, by Monty, for your professional use");
+ puts("MySQL AB, by Monty, for your professional use");
puts("This software comes with NO WARRANTY: see the PUBLIC for details.\n");
puts("Description, check and repair of ISAM tables.");
puts("Used without options all tables on the command will be checked for errors");
printf("Usage: %s [OPTIONS] tables[.ISM]\n", my_progname);
- puts("\n\
- -a, --analyze Analyze distribution of keys. Will make some joins in\n\
- MySQL faster.\n\
- -#, --debug=... Output debug log. Often this is 'd:t:o,filename`\n\
- --character-sets-dir=...\n\
- Directory where character sets are\n\
- -C, --default-character-set=...\n\
- Set the default character set\n\
- -d, --description Prints some information about table.\n\
- -e, --extend-check Check the table VERY thoroughly. One need use this\n\
- only in extreme cases as isamchk should normally find\n\
- all errors even without this switch\n\
- -f, --force Overwrite old temporary files.\n\
- If one uses -f when checking tables (running isamchk\n\
- without -r), isamchk will automatically restart with\n\
- -r on any wrong table.\n\
- -?, --help Display this help and exit.\n\
- -i, --information Print statistics information about the table\n\
- -k, --keys-used=# Used with '-r'. Tell ISAM to update only the first\n\
- # keys. This can be used to get faster inserts!\n\
- -l, --no-symlinks Do not follow symbolic links when repairing. Normally\n\
- isamchk repairs the table a symlink points at.\n\
- -q, --quick Used with -r to get a faster repair. (The data file\n\
- isn't touched.) One can give a second '-q' to force\n\
- isamchk to modify the original datafile.");
- puts("\
- -r, --recover Can fix almost anything except unique keys that aren't\n\
- unique.\n\
- -o, --safe-recover Uses old recovery method; slower than '-r' but can\n\
- handle a couple of cases that '-r' cannot handle.\n\
- -O, --set-variable var=option\n\
- Change the value of a variable.\n\
- -s, --silent Only print errors. One can use two -s to make isamchk\n\
- very silent\n\
- -S, --sort-index Sort index blocks. This speeds up 'read-next' in\n\
- applications\n\
- -R, --sort-records=#\n\
- Sort records according to an index. This makes your\n\
- data much more localized and may speed up things\n\
- (It may be VERY slow to do a sort the first time!)\n\
- -u, --unpack Unpack file packed with pack_isam.\n\
- -v, --verbose Print more information. This can be used with\n\
- -d and -e. Use many -v for more verbosity!\n\
- -V, --version Print version and exit.\n\
- -w, --wait Wait if table is locked.");
- print_defaults("my",load_default_groups);
- printf("\nPossible variables for option --set-variable (-O) are:\n");
- for (i=0; changeable_vars[i].name ; i++)
- printf("%-20s current value: %lu\n",
- changeable_vars[i].name,
- *changeable_vars[i].varptr);
+ my_print_help(my_long_options);
+ print_defaults("my", load_default_groups);
+ my_print_variables(my_long_options);
}
/* Check table */
@@ -575,112 +579,94 @@ end2:
} /* nisamchk */
+static my_bool
+get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
+ char *argument)
+
+{
+ switch(optid) {
+ case 'a':
+ testflag|= T_STATISTICS;
+ break;
+ case 's': /* silent */
+ if (testflag & T_SILENT)
+ testflag|=T_VERY_SILENT;
+ testflag|= T_SILENT;
+ testflag&= ~T_WRITE_LOOP;
+ break;
+ case 'w':
+ testflag|= T_WAIT_FOREVER;
+ break;
+ case 'd': /* description if isam-file */
+ testflag|= T_DESCRIPT;
+ break;
+ case 'e': /* extend check */
+ testflag|= T_EXTEND;
+ break;
+ case 'i':
+ testflag|= T_INFO;
+ break;
+ case 'f':
+ tmpfile_createflag= O_RDWR | O_TRUNC;
+ testflag|=T_FORCE_CREATE;
+ break;
+ case 'l':
+ opt_follow_links=0;
+ break;
+ case 'r': /* Repair table */
+ testflag= (testflag & ~T_REP) | T_REP_BY_SORT;
+ break;
+ case 'o':
+ testflag= (testflag & ~T_REP_BY_SORT) | T_REP;
+ my_disable_async_io=1; /* More safety */
+ break;
+ case 'u':
+ testflag|= T_UNPACK | T_REP_BY_SORT;
+ break;
+ case 'v': /* Verbose */
+ testflag|= T_VERBOSE;
+ verbose++;
+ break;
+ case 'R': /* Sort records */
+ testflag|= T_SORT_RECORDS;
+ if (opt_sort_key >= N_MAXKEY)
+ {
+ fprintf(stderr,
+ "The value of the sort key is bigger than max key: %d.\n",
+ N_MAXKEY);
+ exit(1);
+ }
+ break;
+ case 'S': /* Sort index */
+ testflag|= T_SORT_INDEX;
+ break;
+ case '#':
+ DBUG_PUSH(argument ? argument : "d:t:o,/tmp/isamchk.trace");
+ break;
+ case 'V':
+ print_version();
+ exit(0);
+ case '?':
+ usage();
+ exit(0);
+ }
+ return 0;
+}
+
/* Read options */
-static void get_options(register int *argc,register char ***argv)
+static void get_options(register int *argc, register char ***argv)
{
- int c,option_index=0;
+ int ho_error;
load_defaults("my",load_default_groups,argc,argv);
defaults_alloc= *argv;
- set_all_changeable_vars(changeable_vars);
if (isatty(fileno(stdout)))
testflag|=T_WRITE_LOOP;
- while ((c=getopt_long(*argc,*argv,"adeif?lqrosSuvVw#:b:k:O:R:C:",
- long_options, &option_index)) != EOF)
- {
- switch(c) {
- case 'a':
- testflag|= T_STATISTICS;
- break;
- case 'C':
- default_charset=optarg;
- break;
- case OPT_CHARSETS_DIR_IC:
- charsets_dir = optarg;
- break;
- case 'b':
- search_after_block=strtoul(optarg,NULL,10);
- break;
- case 's': /* silent */
- if (testflag & T_SILENT)
- testflag|=T_VERY_SILENT;
- testflag|= T_SILENT;
- testflag&= ~T_WRITE_LOOP;
- break;
- case 'w':
- testflag|= T_WAIT_FOREVER;
- break;
- case 'd': /* description if isam-file */
- testflag|= T_DESCRIPT;
- break;
- case 'e': /* extend check */
- testflag|= T_EXTEND;
- break;
- case 'i':
- testflag|= T_INFO;
- break;
- case 'f':
- tmpfile_createflag= O_RDWR | O_TRUNC;
- testflag|=T_FORCE_CREATE;
- break;
- case 'k':
- max_key= (uint) atoi(optarg);
- break;
- case 'l':
- opt_follow_links=0;
- break;
- case 'r': /* Repair table */
- testflag= (testflag & ~T_REP) | T_REP_BY_SORT;
- break;
- case 'o':
- testflag= (testflag & ~T_REP_BY_SORT) | T_REP;
- my_disable_async_io=1; /* More safety */
- break;
- case 'q':
- rep_quick++;
- break;
- case 'u':
- testflag|= T_UNPACK | T_REP_BY_SORT;
- break;
- case 'v': /* Verbose */
- testflag|= T_VERBOSE;
- verbose++;
- break;
- case 'O':
- if (set_changeable_var(optarg, changeable_vars))
- {
- usage();
- exit(1);
- }
- break;
- case 'R': /* Sort records */
- testflag|= T_SORT_RECORDS;
- opt_sort_key=(uint) atoi(optarg)-1;
- if (opt_sort_key >= N_MAXKEY)
- {
- fprintf(stderr,
- "The value of the sort key is bigger than max key: %d.\n",
- N_MAXKEY);
- exit(1);
- }
- break;
- case 'S': /* Sort index */
- testflag|= T_SORT_INDEX;
- break;
- case '#':
- DBUG_PUSH(optarg ? optarg : "d:t:o,/tmp/isamchk.trace");
- break;
- case 'V':
- print_version();
- exit(0);
- case '?':
- usage();
- exit(0);
- }
- }
- (*argc)-=optind;
- (*argv)+=optind;
+
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ exit(ho_error);
+
if (*argc == 0)
{
usage();
diff --git a/isam/pack_isam.c b/isam/pack_isam.c
index 6122a4e6024..0f36c3cb2aa 100644
--- a/isam/pack_isam.c
+++ b/isam/pack_isam.c
@@ -1,17 +1,20 @@
-/* Copyright (C) 1979-1999 TcX AB & Monty Program KB & Detron HB
-
- This software is distributed with NO WARRANTY OF ANY KIND. No author or
- distributor accepts any responsibility for the consequences of using it, or
- for whether it serves any particular purpose or works at all, unless he or
- she says so in writing. Refer to the Free Public License (the "License")
- for full details.
- Every copy of this file must include a copy of the License, normally in a
- plain ASCII text file named PUBLIC. The License grants you the right to
- copy, modify and redistribute this file, but only under certain conditions
- described in the License. Among other things, the License requires that
- the copyright notice and this notice be preserved on all copies. */
-
-/* Pack isam file*/
+/* Copyright (C) 1979-2002 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/* Pack isam file */
#ifndef USE_MY_FUNC
#define USE_MY_FUNC /* We nead at least my_malloc */
@@ -27,7 +30,7 @@
#ifndef __GNU_LIBRARY__
#define __GNU_LIBRARY__ /* Skipp warnings in getopt.h */
#endif
-#include <getopt.h>
+#include <my_getopt.h>
#if INT_MAX > 32767
#define BITS_SAVED 32
@@ -179,8 +182,9 @@ static int mrg_rrnd(MRG_INFO *info,byte *buf);
static void mrg_reset(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 my_bool backup, opt_wait;
static int tmpfile_createflag=O_RDWR | O_TRUNC | O_EXCL;
static uint tree_buff_length=8196-MALLOC_OVERHEAD,force_pack_ref_length;
static char tmp_dir[FN_REFLEN]={0},*join_table;
@@ -237,26 +241,44 @@ int main(int argc, char **argv)
}
-static struct option long_options[] =
+static struct my_option my_long_options[] =
{
- {"backup", no_argument, 0, 'b'},
- {"debug", optional_argument, 0, '#'},
- {"force", no_argument, 0, 'f'},
- {"join", required_argument, 0, 'j'},
- {"help", no_argument, 0, '?'},
- {"packlength",required_argument, 0, 'p'},
- {"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},
+ {"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's gets bigger or 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 the identical layout.",
+ (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},
+ {"packlength", 'p', "Force storage size of recordlength (1, 2 or 3)",
+ (gptr*) &force_pack_ref_length, (gptr*) &force_pack_ref_length, 0,
+ GET_UINT, REQUIRED_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",
+ (gptr*) &tmp_dir, (gptr*) &tmp_dir, 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 5.8 for %s on %s\n",my_progname,SYSTEM_TYPE,MACHINE_TYPE);
+ printf("%s Ver 5.10 for %s on %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE);
}
static void usage(void)
@@ -271,92 +293,72 @@ static void usage(void)
puts("You should give the .ISM 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's gets bigger or\n\
- tempfile exists.\n\
- -j, --join='new_table_name'\n\
- Join all given tables into 'new_table_name'.\n\
- All tables MUST have the identical layout.\n\
- -p, --packlength=# Force storage size of recordlength (1,2 or 3)\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\n");
- 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 'p':
+ if (force_pack_ref_length > 3)
+ force_pack_ref_length= 0;
+ 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 */
/* Initiates DEBUG - but no debugging here ! */
-static void get_options(int *argc,char ***argv)
+static void get_options(int *argc, char ***argv)
{
- int c,option_index=0;
- uint length;
+ int ho_error;
+
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ exit(ho_error);
my_progname= argv[0][0];
if (isatty(fileno(stdout)))
write_loop=1;
- while ((c=getopt_long(*argc,*argv,"bfj:p:stvwT:#::?V",long_options,
- &option_index)) != EOF)
- {
- 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 'p':
- force_pack_ref_length=(uint) atoi(optarg);
- if (force_pack_ref_length > 3)
- force_pack_ref_length=0;
- 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 '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);
- }
- }
- (*argc)-=optind;
- (*argv)+=optind;
if (!*argc)
{
usage();