diff options
author | unknown <monty@hundin.mysql.fi> | 2002-06-03 12:59:31 +0300 |
---|---|---|
committer | unknown <monty@hundin.mysql.fi> | 2002-06-03 12:59:31 +0300 |
commit | 702256ebaa12ca37724f68da2bd5f5d2959b1e8f (patch) | |
tree | be04186411dc657ef6bbcbe01267d30f2675c914 /mysys | |
parent | 775d09780fb32c101c4e5da2807817c1d1231ce9 (diff) | |
parent | 7daf5a5d0ee7b52508943c7095a2cc150abcf616 (diff) | |
download | mariadb-git-702256ebaa12ca37724f68da2bd5f5d2959b1e8f.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 'mysys')
-rw-r--r-- | mysys/Makefile.am | 9 | ||||
-rw-r--r-- | mysys/array.c | 2 | ||||
-rw-r--r-- | mysys/charset.c | 4 | ||||
-rw-r--r-- | mysys/default.c | 2 | ||||
-rw-r--r-- | mysys/getopt.c | 750 | ||||
-rw-r--r-- | mysys/getopt1.c | 170 | ||||
-rw-r--r-- | mysys/hash.c | 2 | ||||
-rw-r--r-- | mysys/mf_strip.c (renamed from mysys/mf_stripp.c) | 6 | ||||
-rw-r--r-- | mysys/my_alloc.c | 16 | ||||
-rw-r--r-- | mysys/my_gethostbyname.c | 119 | ||||
-rw-r--r-- | mysys/my_getopt.c | 484 | ||||
-rw-r--r-- | mysys/my_pthread.c | 60 | ||||
-rw-r--r-- | mysys/my_thr_init.c | 29 | ||||
-rw-r--r-- | mysys/raid.cc | 2 | ||||
-rw-r--r-- | mysys/raid2.c | 31 | ||||
-rw-r--r-- | mysys/testhash.c | 18 |
16 files changed, 525 insertions, 1179 deletions
diff --git a/mysys/Makefile.am b/mysys/Makefile.am index a32740e2168..ec8a6b33224 100644 --- a/mysys/Makefile.am +++ b/mysys/Makefile.am @@ -35,7 +35,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c\ my_error.c errors.c my_div.c my_messnc.c \ mf_format.c mf_same.c mf_dirname.c mf_fn_ext.c \ my_symlink.c my_symlink2.c \ - mf_pack.c mf_unixpath.c mf_stripp.c \ + mf_pack.c mf_unixpath.c mf_strip.c \ mf_casecnv.c mf_soundex.c mf_wcomp.c mf_wfile.c \ mf_qsort.c mf_qsort2.c mf_sort.c \ ptr_cmp.c mf_radix.c queues.c \ @@ -44,10 +44,11 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c\ my_delete.c my_rename.c my_redel.c my_tempnam.c \ my_chsize.c my_lread.c my_lwrite.c my_clock.c \ my_quick.c my_lockmem.c my_static.c \ - getopt.c getopt1.c my_getopt.c getvar.c my_mkdir.c \ - default.c my_compress.c checksum.c raid.cc my_net.c \ + my_getopt.c getvar.c my_mkdir.c \ + default.c my_compress.c checksum.c raid.cc \ + my_net.c \ my_vsnprintf.c charset.c my_bitmap.c my_bit.c md5.c \ - my_handler.c + my_gethostbyname.c my_handler.c EXTRA_DIST = thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \ thr_mutex.c thr_rwlock.c libmysys_a_LIBADD = @THREAD_LOBJECTS@ diff --git a/mysys/array.c b/mysys/array.c index 2420213d454..2a0723fbd69 100644 --- a/mysys/array.c +++ b/mysys/array.c @@ -28,7 +28,7 @@ even if space allocation failed */ -my_bool _init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, +my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, uint init_alloc, uint alloc_increment CALLER_INFO_PROTO) { diff --git a/mysys/charset.c b/mysys/charset.c index de6ccbf7ea9..b021945a5dc 100644 --- a/mysys/charset.c +++ b/mysys/charset.c @@ -122,7 +122,7 @@ static my_bool read_charset_index(CS_ID ***charsets, myf myflags) fb.buf[0] = '\0'; fb.p = fb.buf; - if (init_dynamic_array(&cs, sizeof(CS_ID *), 32, 32)) + if (my_init_dynamic_array(&cs, sizeof(CS_ID *), 32, 32)) return TRUE; while (!get_word(&fb, buf) && !get_word(&fb, num_buf)) @@ -180,7 +180,7 @@ static my_bool init_available_charsets(myf myflags) pthread_mutex_lock(&THR_LOCK_charset); if (!cs_info_table.buffer) /* If not initialized */ { - init_dynamic_array(&cs_info_table, sizeof(CHARSET_INFO*), 16, 8); + my_init_dynamic_array(&cs_info_table, sizeof(CHARSET_INFO*), 16, 8); error = read_charset_index(&available_charsets, myflags); } charset_initialized=1; diff --git a/mysys/default.c b/mysys/default.c index ad34d4b949d..d270aa8673a 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -123,7 +123,7 @@ void load_defaults(const char *conf_file, const char **groups, for (; *groups ; groups++) group.count++; - if (init_dynamic_array(&args, sizeof(char*),*argc, 32)) + if (my_init_dynamic_array(&args, sizeof(char*),*argc, 32)) goto err; if (forced_default_file) { diff --git a/mysys/getopt.c b/mysys/getopt.c deleted file mode 100644 index 7b96e10c85c..00000000000 --- a/mysys/getopt.c +++ /dev/null @@ -1,750 +0,0 @@ -/* Getopt for GNU. - NOTE: getopt is now part of the C library, so if you don't know what - "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu - before changing it! - - Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94 - Free Software Foundation, Inc. - -Changes by monty: -- Added include of string.h when nessessary. -- Removed two warnings from gcc. - -This file is part of the GNU C Library. Its master source is NOT part of -the C library, however. The master source lives in /gd/gnu/lib. - -The GNU C Library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -The GNU C Library 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 -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with the GNU C Library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. - Ditto for AIX 3.2 and <stdlib.h>. */ -#ifndef _NO_PROTO -#define _NO_PROTO -#endif - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#if (!defined (__STDC__) || !__STDC__) && !defined(MSDOS) && !defined(OS2) -/* This is a separate conditional since some stdc systems - reject `defined (const)'. */ -#ifndef const -#define const -#endif -#endif - -#include <my_global.h> /* Changes for mysys */ -#include <m_string.h> - -/* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ - -#if defined (_LIBC) || !defined (__GNU_LIBRARY__) - - -/* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ -/* Don't include stdlib.h for non-GNU C libraries because some of them - contain conflicting prototypes for getopt. */ -#include <stdlib.h> -#endif /* GNU C library. */ - -/* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. - - Setting the environment variable POSIXLY_CORRECT disables permutation. - Then the behavior is completely standard. - - GNU application programs can use a third alternative mode in which - they can distinguish the relative order of options and other arguments. */ - -#include "getopt.h" - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -char *optarg = NULL; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns EOF, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -/* XXX 1003.2 says this must be 1 before any call. */ -int optind = 1; - -/* The next char to be scanned in the option-element - in which the last option character we returned was found. - This allows us to pick up the scan where we left off. - - If this is zero, or a null string, it means resume the scan - by advancing to the next ARGV-element. */ - -static char *nextchar; - -/* Callers store zero here to inhibit the error message - for unrecognized options. */ - -int opterr = 1; - -/* Set to an option character which was unrecognized. - This must be initialized on some systems to avoid linking in the - system's own getopt implementation. */ - -int optopt = '?'; - -/* Describe how to deal with options that follow non-option ARGV-elements. - - If the caller did not specify anything, - the default is REQUIRE_ORDER if the environment variable - POSIXLY_CORRECT is defined, PERMUTE otherwise. - - REQUIRE_ORDER means don't recognize them as options; - stop option processing when the first non-option is seen. - This is what Unix does. - This mode of operation is selected by either setting the environment - variable POSIXLY_CORRECT, or using `+' as the first character - of the list of option characters. - - PERMUTE is the default. We permute the contents of ARGV as we scan, - so that eventually all the non-options are at the end. This allows options - to be given in any order, even with programs that were not written to - expect this. - - RETURN_IN_ORDER is an option available to programs that were written - to expect options and other ARGV-elements in any order and that care about - the ordering of the two. We describe each non-option ARGV-element - as if it were the argument of an option with character code 1. - Using `-' as the first character of the list of option characters - selects this mode of operation. - - The special argument `--' forces an end of option-scanning regardless - of the value of `ordering'. In the case of RETURN_IN_ORDER, only - `--' can cause `getopt' to return EOF with `optind' != ARGC. */ - -static enum -{ - REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER -} ordering; - -/* Value of POSIXLY_CORRECT environment variable. */ -static char *posixly_correct; - -#ifdef __GNU_LIBRARY__ -/* We want to avoid inclusion of string.h with non-GNU libraries - because there are many ways it can cause trouble. - On some systems, it contains special magic macros that don't work - in GCC. */ -#include <string.h> -#define my_index strchr -#else - -/* Avoid depending on library functions or files - whose names are inconsistent. */ - -#ifndef OS2 -char *getenv (const char *); -#endif - -static char * -my_index (const char *str, int chr) -{ - while (*str) - { - if (*str == chr) - return (char *) str; - str++; - } - return 0; -} - -/* If using GCC, we can safely declare strlen this way. - If not using GCC, it is ok not to declare it. */ -#ifdef __GNUC__ -/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. - That was relevant to code that was here before. */ -#if !defined (__STDC__) || !__STDC__ -/* gcc with -traditional declares the built-in strlen to return int, - and has done so at least since version 2.4.5. -- rms. */ -extern int strlen (const char *); -#endif /* not __STDC__ */ -#endif /* __GNUC__ */ - -#endif /* not __GNU_LIBRARY__ */ - -/* Handle permutation of arguments. */ - -/* Describe the part of ARGV that contains non-options that have - been skipped. `first_nonopt' is the index in ARGV of the first of them; - `last_nonopt' is the index after the last of them. */ - -static int first_nonopt; -static int last_nonopt; - -/* Exchange two adjacent subsequences of ARGV. - One subsequence is elements [first_nonopt,last_nonopt) - which contains all the non-options that have been skipped so far. - The other is elements [last_nonopt,optind), which contains all - the options processed since those non-options were skipped. - - `first_nonopt' and `last_nonopt' are relocated so that they describe - the new indices of the non-options in ARGV after they are moved. */ - -static void -exchange (char **argv) -{ - int bottom = first_nonopt; - int middle = last_nonopt; - int top = optind; - char *tem; - - /* Exchange the shorter segment with the far end of the longer segment. - That puts the shorter segment into the right place. - It leaves the longer segment in the right place overall, - but it consists of two parts that need to be swapped next. */ - - while (top > middle && middle > bottom) - { - if (top - middle > middle - bottom) - { - /* Bottom segment is the short one. */ - int len = middle - bottom; - register int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } - else - { - /* Top segment is the short one. */ - int len = top - middle; - register int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - - /* Update records for the slots the non-options now occupy. */ - - first_nonopt += (optind - last_nonopt); - last_nonopt = optind; -} - -/* Initialize the internal data when the first call is made. */ - -static const char * -_getopt_initialize (const char *optstring) -{ - /* Start processing options with ARGV-element 1 (since ARGV-element 0 - is the program name); the sequence of previously skipped - non-option ARGV-elements is empty. */ - - first_nonopt = last_nonopt = optind = 1; - - nextchar = NULL; - - posixly_correct = getenv ("POSIXLY_CORRECT"); - - /* Determine how to handle the ordering of options and nonoptions. */ - - if (optstring[0] == '-') - { - ordering = RETURN_IN_ORDER; - ++optstring; - } - else if (optstring[0] == '+') - { - ordering = REQUIRE_ORDER; - ++optstring; - } - else if (posixly_correct != NULL) - ordering = REQUIRE_ORDER; - else - ordering = PERMUTE; - - return optstring; -} - -/* Scan elements of ARGV (whose length is ARGC) for option characters - given in OPTSTRING. - - If an element of ARGV starts with '-', and is not exactly "-" or "--", - then it is an option element. The characters of this element - (aside from the initial '-') are option characters. If `getopt' - is called repeatedly, it returns successively each of the option characters - from each of the option elements. - - If `getopt' finds another option character, it returns that character, - updating `optind' and `nextchar' so that the next call to `getopt' can - resume the scan with the following option character or ARGV-element. - - If there are no more option characters, `getopt' returns `EOF'. - Then `optind' is the index in ARGV of the first ARGV-element - that is not an option. (The ARGV-elements have been permuted - so that those that are not options now come last.) - - OPTSTRING is a string containing the legitimate option characters. - If an option character is seen that is not listed in OPTSTRING, - return '?' after printing an error message. If you set `opterr' to - zero, the error message is suppressed but we still return '?'. - - If a char in OPTSTRING is followed by a colon, that means it wants an arg, - so the following text in the same ARGV-element, or the text of the following - ARGV-element, is returned in `optarg'. Two colons mean an option that - wants an optional arg; if there is text in the current ARGV-element, - it is returned in `optarg', otherwise `optarg' is set to zero. - - If OPTSTRING starts with `-' or `+', it requests different methods of - handling the non-option ARGV-elements. - See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - - Long-named options begin with `--' instead of `-'. - Their names may be abbreviated as long as the abbreviation is unique - or is an exact match for some defined option. If they have an - argument, it follows the option name in the same ARGV-element, separated - from the option name by a `=', or else the in next ARGV-element. - When `getopt' finds a long-named option, it returns 0 if that option's - `flag' field is nonzero, the value of the option's `val' field - if the `flag' field is zero. - - The elements of ARGV aren't really const, because we permute them. - But we pretend they're const in the prototype to be compatible - with other systems. - - LONGOPTS is a vector of `struct option' terminated by an - element containing a name which is zero. - - LONGIND returns the index in LONGOPT of the long-named option found. - It is only valid when a long-named option has been found by the most - recent call. - - If LONG_ONLY is nonzero, '-' as well as '--' can introduce - long-named options. */ - -int -_getopt_internal (int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longind, int long_only) -{ - optarg = NULL; - - if (optind == 0) - optstring = _getopt_initialize (optstring); - - if (nextchar == NULL || *nextchar == '\0') - { - /* Advance to the next ARGV-element. */ - - if (ordering == PERMUTE) - { - /* If we have just processed some options following some non-options, - exchange them so that the options come first. */ - - if (first_nonopt != last_nonopt && last_nonopt != optind) - exchange ((char **) argv); - else if (last_nonopt != optind) - first_nonopt = optind; - - /* Skip any additional non-options - and extend the range of non-options previously skipped. */ - - while (optind < argc - && (argv[optind][0] != '-' || argv[optind][1] == '\0')) - optind++; - last_nonopt = optind; - } - - /* The special ARGV-element `--' means premature end of options. - Skip it like a null option, - then exchange with previous non-options as if it were an option, - then skip everything else like a non-option. */ - - if (optind != argc && !strcmp (argv[optind], "--")) - { - optind++; - - if (first_nonopt != last_nonopt && last_nonopt != optind) - exchange ((char **) argv); - else if (first_nonopt == last_nonopt) - first_nonopt = optind; - last_nonopt = argc; - - optind = argc; - } - - /* If we have done all the ARGV-elements, stop the scan - and back over any non-options that we skipped and permuted. */ - - if (optind == argc) - { - /* Set the next-arg-index to point at the non-options - that we previously skipped, so the caller will digest them. */ - if (first_nonopt != last_nonopt) - optind = first_nonopt; - return EOF; - } - - /* If we have come to a non-option and did not permute it, - either stop the scan or describe it to the caller and pass it by. */ - - if ((argv[optind][0] != '-' || argv[optind][1] == '\0')) - { - if (ordering == REQUIRE_ORDER) - return EOF; - optarg = argv[optind++]; - return 1; - } - - /* We have found another option-ARGV-element. - Skip the initial punctuation. */ - - nextchar = (argv[optind] + 1 - + (longopts != NULL && argv[optind][1] == '-')); - } - - /* Decode the current option-ARGV-element. */ - - /* Check whether the ARGV-element is a long option. - - If long_only and the ARGV-element has the form "-f", where f is - a valid short option, don't consider it an abbreviated form of - a long option that starts with f. Otherwise there would be no - way to give the -f short option. - - On the other hand, if there's a long option "fubar" and - the ARGV-element is "-fu", do consider that an abbreviation of - the long option, just like "--fu", and not "-f" with arg "u". - - This distinction seems to be the most useful approach. */ - - if (longopts != NULL - && (argv[optind][1] == '-' - || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) - { - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound=0; /* Keep gcc happy */ - int option_index; - - for (nameend = nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match - or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, nextchar, nameend - nextchar)) - { - if ((size_t) (nameend - nextchar) == (size_t) strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second or later nonexact match found. */ - ambig = 1; - } - - if (ambig && !exact) - { - if (opterr) - fprintf (stderr, "%s: option `%s' is ambiguous\n", - argv[0], argv[optind]); - nextchar += strlen (nextchar); - optind++; - return '?'; - } - - if (pfound != NULL) - { - option_index = indfound; - optind++; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - optarg = nameend + 1; - else - { - if (opterr) - { - if (argv[optind - 1][1] == '-') - /* --option */ - fprintf (stderr, - "%s: option `--%s' doesn't allow an argument\n", - argv[0], pfound->name); - else - /* +option or -option */ - fprintf (stderr, - "%s: option `%c%s' doesn't allow an argument\n", - argv[0], argv[optind - 1][0], pfound->name); - } - nextchar += strlen (nextchar); - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (optind < argc) - optarg = argv[optind++]; - else - { - if (opterr) - fprintf (stderr, "%s: option `%s' requires an argument\n", - argv[0], argv[optind - 1]); - nextchar += strlen (nextchar); - return optstring[0] == ':' ? ':' : '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - - /* Can't find it as a long option. If this is not getopt_long_only, - or the option starts with '--' or is not a valid short - option, then it's an error. - Otherwise interpret it as a short option. */ - if (!long_only || argv[optind][1] == '-' - || my_index (optstring, *nextchar) == NULL) - { - if (opterr) - { - if (argv[optind][1] == '-') - /* --option */ - fprintf (stderr, "%s: unrecognized option `--%s'\n", - argv[0], nextchar); - else - /* +option or -option */ - fprintf (stderr, "%s: unrecognized option `%c%s'\n", - argv[0], argv[optind][0], nextchar); - } - nextchar = (char *) ""; - optind++; - return '?'; - } - } - - /* Look at and handle the next short option-character. */ - - { - char c = *nextchar++; - char *temp = my_index (optstring, c); - - /* Increment `optind' when we start to process its last character. */ - if (*nextchar == '\0') - ++optind; - - if (temp == NULL || c == ':') - { - if (opterr) - { - if (posixly_correct) - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c); - else - fprintf (stderr, "%s: invalid option -- %c\n", argv[0], c); - } - optopt = c; - return '?'; - } - if (temp[1] == ':') - { - if (temp[2] == ':') - { - /* This is an option that accepts an argument optionally. */ - if (*nextchar != '\0') - { - optarg = nextchar; - optind++; - } - else - optarg = NULL; - nextchar = NULL; - } - else - { - /* This is an option that requires an argument. */ - if (*nextchar != '\0') - { - optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - optind++; - } - else if (optind == argc) - { - if (opterr) - { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, "%s: option requires an argument -- %c\n", - argv[0], c); - } - optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } - else - /* We already incremented `optind' once; - increment it again when taking next ARGV-elt as argument. */ - optarg = argv[optind++]; - nextchar = NULL; - } - } - return c; - } -} - -#ifdef __EMX__ -int getopt (int argc, char **argv, __const__ char *optstring) -#else -int -getopt (int argc, char *const *argv, const char *optstring) -#endif -{ - return _getopt_internal (argc, argv, optstring, - (const struct option *) 0, - (int *) 0, - 0); -} - -#endif /* _LIBC or not __GNU_LIBRARY__. */ - -#ifdef TEST - -/* Compile with -DTEST to make an executable for use in testing - the above definition of `getopt'. */ - -int -main (argc, argv) - int argc; - char **argv; -{ - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = optind ? optind : 1; - - c = getopt (argc, argv, "abc:d:0123456789"); - if (c == EOF) - break; - - switch (c) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (optind < argc) - { - printf ("non-option ARGV-elements: "); - while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } - - exit (0); -} - -#endif /* TEST */ diff --git a/mysys/getopt1.c b/mysys/getopt1.c deleted file mode 100644 index 15f3c8f544b..00000000000 --- a/mysys/getopt1.c +++ /dev/null @@ -1,170 +0,0 @@ -/* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987, 88, 89, 90, 91, 92, 1993, 1994 - Free Software Foundation, Inc. - -This file is part of the GNU C Library. Its master source is NOT part of -the C library, however. The master source lives in /gd/gnu/lib. - -The GNU C Library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -The GNU C Library 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 -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with the GNU C Library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <my_global.h> -#include "getopt.h" - -#if (!defined (__STDC__) || !__STDC__) && !defined(MSDOS) && !defined(OS2) -/* This is a separate conditional since some stdc systems - reject `defined (const)'. */ -#ifndef const -#define const -#endif -#endif - -#include <stdio.h> - -/* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ - -#if defined (_LIBC) || !defined (__GNU_LIBRARY__) - -#ifndef __WIN__ -#include <stdlib.h> -#endif /* __WIN__ */ - -#ifndef NULL -#define NULL 0 -#endif - -int -getopt_long (int argc, char *const *argv, const char *options, const struct option *long_options, int *opt_index) -{ - return _getopt_internal (argc, argv, options, long_options, opt_index, 0); -} - -/* Like getopt_long, but '-' as well as '--' can indicate a long option. - If an option that starts with '-' (not '--') doesn't match a long option, - but does match a short option, it is parsed as a short option - instead. */ - -int -getopt_long_only (int argc, char *const *argv, const char *options, const struct option *long_options, int *opt_index) -{ - return _getopt_internal (argc, argv, options, long_options, opt_index, 1); -} - - -#endif /* _LIBC or not __GNU_LIBRARY__. */ - -#ifdef TEST - -#include <stdio.h> - -int -main (argc, argv) - int argc; - char **argv; -{ - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = optind ? optind : 1; - int option_index = 0; - static struct option long_options[] = - { - {"add", 1, 0, 0}, - {"append", 0, 0, 0}, - {"delete", 1, 0, 0}, - {"verbose", 0, 0, 0}, - {"create", 0, 0, 0}, - {"file", 1, 0, 0}, - {0, 0, 0, 0} - }; - - c = getopt_long (argc, argv, "abc:d:0123456789", - long_options, &option_index); - if (c == EOF) - break; - - switch (c) - { - case 0: - printf ("option %s", long_options[option_index].name); - if (optarg) - printf (" with arg %s", optarg); - printf ("\n"); - break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case 'd': - printf ("option d with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (optind < argc) - { - printf ("non-option ARGV-elements: "); - while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } - - exit (0); -} - -#endif /* TEST */ diff --git a/mysys/hash.c b/mysys/hash.c index 770bd396d06..0cbd14607f6 100644 --- a/mysys/hash.c +++ b/mysys/hash.c @@ -45,7 +45,7 @@ _hash_init(HASH *hash,CHARSET_INFO *charset, DBUG_PRINT("enter",("hash: %lx size: %d",hash,size)); hash->records=0; - if (init_dynamic_array_ci(&hash->array,sizeof(HASH_LINK),size,0)) + if (my_init_dynamic_array_ci(&hash->array,sizeof(HASH_LINK),size,0)) { hash->free=0; /* Allow call to hash_free */ DBUG_RETURN(TRUE); diff --git a/mysys/mf_stripp.c b/mysys/mf_strip.c index d2fd171ec8c..ef2aab2c0a3 100644 --- a/mysys/mf_stripp.c +++ b/mysys/mf_strip.c @@ -19,11 +19,11 @@ #include "mysys_priv.h" /* - stripp_sp(my_string str) + strip_sp(my_string str) Strips end-space from string and returns new length. */ -size_s stripp_sp(register my_string str) +size_s strip_sp(register my_string str) { reg2 my_string found; reg3 my_string start; @@ -43,4 +43,4 @@ size_s stripp_sp(register my_string str) } *found= '\0'; /* Stripp at first space */ return (size_s) (found-start); -} /* stripp_sp */ +} /* strip_sp */ diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c index 789e64526a3..5a6afe2fac9 100644 --- a/mysys/my_alloc.c +++ b/mysys/my_alloc.c @@ -29,6 +29,7 @@ void init_alloc_root(MEM_ROOT *mem_root, uint block_size, mem_root->min_malloc=32; mem_root->block_size=block_size-MALLOC_OVERHEAD-sizeof(USED_MEM)-8; mem_root->error_handler=0; + mem_root->block_num= 0; #if !(defined(HAVE_purify) && defined(EXTRA_DEBUG)) if (pre_alloc_size) { @@ -61,25 +62,20 @@ gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size) mem_root->used=next; return (gptr) (((char*) next)+ALIGN_SIZE(sizeof(USED_MEM))); #else - uint get_size,max_left; + uint get_size, block_size; gptr point; reg1 USED_MEM *next; reg2 USED_MEM **prev; Size= ALIGN_SIZE(Size); prev= &mem_root->free; - max_left=0; for (next= *prev ; next && next->left < Size ; next= next->next) - { - if (next->left > max_left) - max_left=next->left; prev= &next->next; - } if (! next) { /* Time to alloc new block */ + block_size= mem_root->block_size*((mem_root->block_num>>2)+1); get_size= Size+ALIGN_SIZE(sizeof(USED_MEM)); - if (max_left*4 < mem_root->block_size && get_size < mem_root->block_size) - get_size=mem_root->block_size; /* Normal alloc */ + get_size= max(get_size, block_size); if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME)))) { @@ -87,6 +83,7 @@ gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size) (*mem_root->error_handler)(); return((gptr) 0); /* purecov: inspected */ } + mem_root->block_num++; next->next= *prev; next->size= get_size; next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM)); @@ -165,7 +162,10 @@ void free_root(MEM_ROOT *root, myf MyFlags) root->free=root->pre_alloc; root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(USED_MEM)); root->free->next=0; + root->block_num= 1; } + else + root->block_num= 0; DBUG_VOID_RETURN; } diff --git a/mysys/my_gethostbyname.c b/mysys/my_gethostbyname.c new file mode 100644 index 00000000000..898ca694121 --- /dev/null +++ b/mysys/my_gethostbyname.c @@ -0,0 +1,119 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +/* Thread safe version of gethostbyname_r() */ + +#include "mysys_priv.h" +#include "my_pthread.h" +#include <assert.h> +#if !defined(MSDOS) && !defined(__WIN__) +#include <netdb.h> +#endif +#include <my_net.h> + +/* This file is not needed if my_gethostbyname_r is a macro */ +#if !defined(my_gethostbyname_r) + +#ifndef THREAD +#define pthread_mutex_lock(A) +#define pthread_mutex_unlock(A) +#endif + +/* + Emulate SOLARIS style calls, not because it's better, but just to make the + usage of getbostbyname_r simpler. +*/ + +#if defined(HAVE_GETHOSTBYNAME_R) + +#if defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE) + +struct hostent *my_gethostbyname_r(const char *name, + struct hostent *result, char *buffer, + int buflen, int *h_errnop) +{ + struct hostent *hp; + DBUG_ASSERT((size_t) buflen >= sizeof(*result)); + if (gethostbyname_r(name,result, buffer, (size_t) buflen, &hp, h_errnop)) + return 0; + return hp; +} + +#elif defined(HAVE_GETHOSTBYNAME_R_RETURN_INT) + +struct hostent *my_gethostbyname_r(const char *name, + struct hostent *result, char *buffer, + int buflen, int *h_errnop) +{ + DBUG_ASSERT(buflen >= sizeof(struct hostent_data)); + if (gethostbyname_r(name,result,(struct hostent_data *) buffer) == -1) + { + *h_errnop= errno; + return 0; + } + return result; +} + +#else + +/* gethostbyname_r with similar interface as gethostbyname() */ + +struct hostent *my_gethostbyname_r(const char *name, + struct hostent *result, char *buffer, + int buflen, int *h_errnop) +{ + struct hostent *hp; + DBUG_ASSERT(buflen >= sizeof(struct hostent_data)); + hp= gethostbyname_r(name,result,(struct hostent_data *) buffer); + *h_errnop= errno; + return hp; +} +#endif /* GLIBC2_STYLE_GETHOSTBYNAME_R */ + +#else /* !HAVE_GETHOSTBYNAME_R */ + +#ifdef THREAD +extern pthread_mutex_t LOCK_gethostbyname_r; +#endif + +/* + No gethostbyname_r() function exists. + In this case we have to keep a mutex over the call to ensure that no + other thread is going to reuse the internal memory. + + The user is responsible to call my_gethostbyname_r_free() when he + is finished with the structure. +*/ + +struct hostent *my_gethostbyname_r(const char *name, + struct hostent *result, char *buffer, + int buflen, int *h_errnop) +{ + struct hostent *hp; + pthread_mutex_lock(&LOCK_gethostbyname_r); + hp= gethostbyname(name); + *h_errnop= h_errno; + return hp; +} + +void my_gethostbyname_r_free() +{ + pthread_mutex_unlock(&LOCK_gethostbyname_r); +} + +#endif /* !HAVE_GETHOSTBYNAME_R */ +#endif /* !my_gethostbyname_r */ diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index b17d1463121..76cdbede78d 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -19,6 +19,8 @@ #include <stdlib.h> #include <my_getopt.h> #include <assert.h> +#include <my_sys.h> +#include <mysys_err.h> static int findopt (char *optpat, uint length, const struct my_option **opt_res, @@ -26,27 +28,26 @@ static int findopt (char *optpat, uint length, static my_bool compare_strings (register const char *s, register const char *t, uint length); static longlong getopt_ll (char *arg, const struct my_option *optp, int *err); +static ulonglong getopt_ull (char *arg, const struct my_option *optp, + int *err); static void init_variables(const struct my_option *options); +static int setval (const struct my_option *opts, char *argument, + my_bool set_maximum_value); +#define DISABLE_OPTION_COUNT 2 /* currently 'skip' and 'disable' below */ -#define DISABLE_OPTION_COUNT 2 - +/* 'disable'-option prefixes must be in the beginning, DISABLE_OPTION_COUNT + is the number of disabling prefixes */ static const char *special_opt_prefix[]= -{"skip", "disable", "enable", "maximum", 0}; +{"skip", "disable", "enable", "maximum", "loose", 0}; char *disabled_my_option= (char*) "0"; -/* Return error values from handle_options */ +/* This is a flag that can be set in client programs. 0 means that + my_getopt will not print error messages, but the client should do + it by itself */ -#define ERR_UNKNOWN_OPTION 1 -#define ERR_AMBIGUOUS_OPTION 2 -#define ERR_NO_ARGUMENT_ALLOWED 3 -#define ERR_ARGUMENT_REQUIRED 4 -#define ERR_VAR_PREFIX_NOT_UNIQUE 5 -#define ERR_UNKNOWN_VARIABLE 6 -#define ERR_MUST_BE_VARIABLE 7 -#define ERR_UNKNOWN_SUFFIX 8 -#define ERR_NO_PTR_TO_VARIABLE 9 +my_bool my_getopt_print_errors= 1; /* @@ -66,15 +67,17 @@ int handle_options(int *argc, char ***argv, char *)) { uint opt_found, argvpos= 0, length, spec_len, i; - int err= 0; - my_bool end_of_options= 0, must_be_var, set_maximum_value, special_used; + my_bool end_of_options= 0, must_be_var, set_maximum_value, special_used, + option_is_loose; char *progname= *(*argv), **pos, *optend, *prev_found; const struct my_option *optp; + int error; LINT_INIT(opt_found); (*argc)--; /* Skip the program name */ (*argv)++; /* --- || ---- */ init_variables(longopts); + for (pos= *argv; *pos; pos++) { char *cur_arg= *pos; @@ -84,45 +87,48 @@ int handle_options(int *argc, char ***argv, must_be_var= 0; set_maximum_value= 0; special_used= 0; + option_is_loose= 0; cur_arg++; /* skip '-' */ - if (*cur_arg == 'O') - { - must_be_var= 1; - - if (!(*++cur_arg)) /* If not -Ovar=# */ + if (*cur_arg == '-' || *cur_arg == 'O') /* check for long option, */ + { /* --set-variable, or -O */ + if (*cur_arg == 'O') { - /* the argument must be in next argv */ - if (!*++pos) + must_be_var= 1; + + if (!(*++cur_arg)) /* If not -Ovar=# */ { - fprintf(stderr, "%s: Option '-O' requires an argument\n", - progname); - return ERR_ARGUMENT_REQUIRED; + /* the argument must be in next argv */ + if (!*++pos) + { + if (my_getopt_print_errors) + fprintf(stderr, "%s: Option '-O' requires an argument\n", + progname); + return EXIT_ARGUMENT_REQUIRED; + } + cur_arg= *pos; + (*argc)--; } - cur_arg= *pos; - (*argc)--; } - /* Sasha: quick dirty fix of a bug that coredumps mysqladmin while - running the test suite. The bug is actually pretty serious - - even in cases when we do not coredump, -O var=val will not set - the variable, and the previous option would be treated upredictably. - */ - goto found_var; - } - else if (*cur_arg == '-') /* check for long option, or --set-variable */ - { - if (!compare_strings(cur_arg, "-set-variable", 13)) + else if (!compare_strings(cur_arg, "-set-variable", 13) || + !compare_strings(cur_arg, "-loose-set-variable", 19)) { must_be_var= 1; + if (cur_arg[1] == 'l') + { + option_is_loose= 1; + cur_arg+= 6; + } if (cur_arg[13] == '=') { cur_arg+= 14; if (!*cur_arg) { - fprintf(stderr, - "%s: Option '--set-variable' requires an argument\n", - progname); - return ERR_ARGUMENT_REQUIRED; + if (my_getopt_print_errors) + fprintf(stderr, + "%s: Option '--set-variable' requires an argument\n", + progname); + return EXIT_ARGUMENT_REQUIRED; } } else if (cur_arg[14]) /* garbage, or another option. break out */ @@ -132,10 +138,11 @@ int handle_options(int *argc, char ***argv, /* the argument must be in next argv */ if (!*++pos) { - fprintf(stderr, - "%s: Option '--set-variable' requires an argument\n", - progname); - return ERR_ARGUMENT_REQUIRED; + if (my_getopt_print_errors) + fprintf(stderr, + "%s: Option '--set-variable' requires an argument\n", + progname); + return EXIT_ARGUMENT_REQUIRED; } cur_arg= *pos; (*argc)--; @@ -151,7 +158,6 @@ int handle_options(int *argc, char ***argv, continue; } } - found_var: optend= strcend(cur_arg, '='); length= optend - cur_arg; if (*optend == '=') @@ -173,7 +179,7 @@ int handle_options(int *argc, char ***argv, if (!must_be_var) { if (optend) - must_be_var= 1; + must_be_var= 1; /* option is followed by an argument */ for (i= 0; special_opt_prefix[i]; i++) { spec_len= strlen(special_opt_prefix[i]); @@ -185,16 +191,19 @@ int handle_options(int *argc, char ***argv, */ special_used= 1; cur_arg+= (spec_len + 1); + if (!compare_strings(special_opt_prefix[i], "loose", 5)) + option_is_loose= 1; if ((opt_found= findopt(cur_arg, length - (spec_len + 1), &optp, &prev_found))) { if (opt_found > 1) { - fprintf(stderr, - "%s: ambiguous option '--%s-%s' (--%s-%s)\n", - progname, special_opt_prefix[i], cur_arg, - special_opt_prefix[i], prev_found); - return ERR_AMBIGUOUS_OPTION; + if (my_getopt_print_errors) + fprintf(stderr, + "%s: ambiguous option '--%s-%s' (--%s-%s)\n", + progname, special_opt_prefix[i], cur_arg, + special_opt_prefix[i], prev_found); + return EXIT_AMBIGUOUS_OPTION; } if (i < DISABLE_OPTION_COUNT) optend= disabled_my_option; @@ -214,15 +223,26 @@ int handle_options(int *argc, char ***argv, { if (must_be_var) { - fprintf(stderr, - "%s: unknown variable '%s'\n", progname, cur_arg); - return ERR_UNKNOWN_VARIABLE; + if (my_getopt_print_errors) + fprintf(stderr, + "%s: %s: unknown variable '%s'\n", progname, + option_is_loose ? "WARNING" : "ERROR", cur_arg); + if (!option_is_loose) + return EXIT_UNKNOWN_VARIABLE; } else { - fprintf(stderr, - "%s: unknown option '--%s'\n", progname, cur_arg); - return ERR_UNKNOWN_OPTION; + if (my_getopt_print_errors) + fprintf(stderr, + "%s: %s: unknown option '--%s'\n", progname, + option_is_loose ? "WARNING" : "ERROR", cur_arg); + if (!option_is_loose) + return EXIT_UNKNOWN_OPTION; + } + if (option_is_loose) + { + (*argc)--; + continue; } } } @@ -230,30 +250,34 @@ int handle_options(int *argc, char ***argv, { if (must_be_var) { - fprintf(stderr, "%s: variable prefix '%s' is not unique\n", - progname, cur_arg); - return ERR_VAR_PREFIX_NOT_UNIQUE; + if (my_getopt_print_errors) + fprintf(stderr, "%s: variable prefix '%s' is not unique\n", + progname, cur_arg); + return EXIT_VAR_PREFIX_NOT_UNIQUE; } else { - fprintf(stderr, "%s: ambiguous option '--%s' (%s, %s)\n", - progname, cur_arg, prev_found, optp->name); - return ERR_AMBIGUOUS_OPTION; + if (my_getopt_print_errors) + fprintf(stderr, "%s: ambiguous option '--%s' (%s, %s)\n", + progname, cur_arg, prev_found, optp->name); + return EXIT_AMBIGUOUS_OPTION; } } - if (must_be_var && !optp->value) + if (must_be_var && (!optp->value || optp->var_type == GET_BOOL)) { - fprintf(stderr, "%s: argument '%s' is not a variable\n", - progname, *pos); - return ERR_MUST_BE_VARIABLE; + if (my_getopt_print_errors) + fprintf(stderr, "%s: option '%s' cannot take an argument\n", + progname, optp->name); + return EXIT_NO_ARGUMENT_ALLOWED; } if (optp->arg_type == NO_ARG) { if (optend && !special_used) { - fprintf(stderr, "%s: option '--%s' cannot take an argument\n", - progname, optp->name); - return ERR_NO_ARGUMENT_ALLOWED; + if (my_getopt_print_errors) + fprintf(stderr, "%s: option '--%s' cannot take an argument\n", + progname, optp->name); + return EXIT_NO_ARGUMENT_ALLOWED; } if (optp->var_type == GET_BOOL) { @@ -261,10 +285,10 @@ int handle_options(int *argc, char ***argv, Set bool to 1 if no argument or if the user has used --enable-'option-name'. *optend was set to '0' if one used --disable-option - */ + */ *((my_bool*) optp->value)= (my_bool) (!optend || *optend == '1'); (*argc)--; - continue; + continue; // For GET_BOOL get_one_option() shouldn't be called } argument= optend; } @@ -287,9 +311,10 @@ int handle_options(int *argc, char ***argv, /* Check if there are more arguments after this one */ if (!*++pos) { - fprintf(stderr, "%s: option '--%s' requires an argument\n", - progname, optp->name); - return ERR_ARGUMENT_REQUIRED; + if (my_getopt_print_errors) + fprintf(stderr, "%s: option '--%s' requires an argument\n", + progname, optp->name); + return EXIT_ARGUMENT_REQUIRED; } argument= *pos; (*argc)--; @@ -299,8 +324,9 @@ int handle_options(int *argc, char ***argv, } else /* must be short option */ { - for (optend= cur_arg; *optend; optend++, opt_found= 0) + for (optend= cur_arg; *optend; optend++) { + opt_found= 0; for (optp= longopts; optp->id; optp++) { if (optp->id == (int) (uchar) *optend) @@ -311,7 +337,7 @@ int handle_options(int *argc, char ***argv, { *((my_bool*) optp->value)= (my_bool) 1; (*argc)--; - continue; + continue; // For GET_BOOL get_one_option() shouldn't be called } else if (optp->arg_type == REQUIRED_ARG || optp->arg_type == OPT_ARG) @@ -328,48 +354,45 @@ int handle_options(int *argc, char ***argv, /* Check if there are more arguments after this one */ if (!*++pos) { - fprintf(stderr, "%s: option '-%c' requires an argument\n", - progname, optp->id); - return ERR_ARGUMENT_REQUIRED; + if (my_getopt_print_errors) + fprintf(stderr, + "%s: option '-%c' requires an argument\n", + progname, optp->id); + return EXIT_ARGUMENT_REQUIRED; } argument= *pos; (*argc)--; /* the other loop will break, because *optend + 1 == 0 */ } } + if ((error= setval(optp, argument, set_maximum_value))) + { + fprintf(stderr, + "%s: Error while setting value '%s' to '%s'\n", + progname, argument, optp->name); + return error; + } get_one_option(optp->id, optp, argument); break; } } if (!opt_found) { - fprintf(stderr, - "%s: unknown option '-%c'\n", progname, *cur_arg); - return ERR_UNKNOWN_OPTION; + if (my_getopt_print_errors) + fprintf(stderr, + "%s: unknown option '-%c'\n", progname, *optend); + return EXIT_UNKNOWN_OPTION; } } (*argc)--; /* option handled (short), decrease argument count */ continue; } - if (optp->value) + if ((error= setval(optp, argument, set_maximum_value))) { - gptr *result_pos= (set_maximum_value) ? - optp->u_max_value : optp->value; - - if (!result_pos) - { - fprintf(stderr, - "%s: Can't set a value for %s\n", progname, optp->name); - return ERR_NO_PTR_TO_VARIABLE; - } - if (optp->var_type == GET_LONG) - *((long*) result_pos)= (long) getopt_ll(argument, optp, &err); - else if (optp->var_type == GET_LL) - *((longlong*) result_pos)= getopt_ll(argument, optp, &err); - else if (optp->var_type == GET_STR) - *((char**) result_pos)= argument; - if (err) - return ERR_UNKNOWN_SUFFIX; + fprintf(stderr, + "%s: Error while setting value '%s' to '%s'\n", + progname, argument, optp->name); + return error; } get_one_option(optp->id, optp, argument); @@ -381,6 +404,59 @@ int handle_options(int *argc, char ***argv, return 0; } +/* + function: setval + + Arguments: opts, argument + Will set the option value to given value +*/ + +static int setval (const struct my_option *opts, char *argument, + my_bool set_maximum_value) +{ + int err= 0; + + if (opts->value && argument) + { + gptr *result_pos= (set_maximum_value) ? + opts->u_max_value : opts->value; + + if (!result_pos) + return EXIT_NO_PTR_TO_VARIABLE; + + switch (opts->var_type) { + case GET_INT: + case GET_UINT: /* fall through */ + *((int*) result_pos)= (int) getopt_ll(argument, opts, &err); + break; + case GET_LONG: + case GET_ULONG: /* fall through */ + *((long*) result_pos)= (long) getopt_ll(argument, opts, &err); + break; + case GET_LL: + *((longlong*) result_pos)= getopt_ll(argument, opts, &err); + break; + case GET_ULL: + *((ulonglong*) result_pos)= getopt_ull(argument, opts, &err); + break; + case GET_STR: + *((char**) result_pos)= argument; + break; + case GET_STR_ALLOC: + if ((*((char**) result_pos))) + my_free((*(char**) result_pos), + MYF(MY_WME | MY_FAE)); + if (!(*((char**) result_pos)= my_strdup(argument, MYF(MY_WME)))) + return EXIT_OUT_OF_MEMORY; + break; + default: /* dummy default to avoid compiler warnings */ + break; + } + if (err) + return EXIT_UNKNOWN_SUFFIX; + } + return 0; +} /* function: findopt @@ -436,25 +512,20 @@ static my_bool compare_strings(register const char *s, register const char *t, return 0; } +/* + function: eval_num_suffix -/* - function: getopt_ll - - Evaluates and returns the value that user gave as an argument - to a variable. Recognizes (case insensitive) K as KILO, M as MEGA - and G as GIGA bytes. Some values must be in certain blocks, as - defined in the given my_option struct, this function will check - that those values are honored. - In case of an error, set error value in *err. + Transforms a number with a suffix to real number. Suffix can + be k|K for kilo, m|M for mega or g|G for giga. */ -static longlong getopt_ll (char *arg, const struct my_option *optp, int *err) +static longlong eval_num_suffix (char *argument, int *error, char *option_name) { char *endchar; longlong num; - *err= 0; - num= strtoll(arg, &endchar, 10); + *error= 0; + num= strtoll(argument, &endchar, 10); if (*endchar == 'k' || *endchar == 'K') num*= 1024L; else if (*endchar == 'm' || *endchar == 'M') @@ -465,9 +536,29 @@ static longlong getopt_ll (char *arg, const struct my_option *optp, int *err) { fprintf(stderr, "Unknown suffix '%c' used for variable '%s' (value '%s')\n", - *endchar, optp->name, arg); - *err= 1; + *endchar, option_name, argument); + *error= 1; + return 0; } + return num; +} + +/* + function: getopt_ll + + Evaluates and returns the value that user gave as an argument + to a variable. Recognizes (case insensitive) K as KILO, M as MEGA + and G as GIGA bytes. Some values must be in certain blocks, as + defined in the given my_option struct, this function will check + that those values are honored. + In case of an error, set error value in *err. +*/ + +static longlong getopt_ll (char *arg, const struct my_option *optp, int *err) +{ + longlong num; + + num= eval_num_suffix(arg, err, (char*) optp->name); if (num < (longlong) optp->min_value) num= (longlong) optp->min_value; else if (num > 0 && (ulonglong) num > (ulonglong) (ulong) optp->max_value @@ -480,6 +571,29 @@ static longlong getopt_ll (char *arg, const struct my_option *optp, int *err) 1L)); } +/* + function: getopt_ull + + This is the same as getopt_ll, but is meant for unsigned long long + values. +*/ + +static ulonglong getopt_ull (char *arg, const struct my_option *optp, int *err) +{ + ulonglong num; + + num= eval_num_suffix(arg, err, (char*) optp->name); + if (num < (ulonglong) optp->min_value) + num= (ulonglong) optp->min_value; + else if (num > 0 && (ulonglong) num > (ulonglong) (ulong) optp->max_value + && optp->max_value) // if max value is not set -> no upper limit + num= (ulonglong) (ulong) optp->max_value; + num= ((num - (ulonglong) optp->sub_size) / (optp->block_size ? + (ulonglong) optp->block_size : + 1L)); + return (ulonglong) (num * (optp->block_size ? (ulonglong) optp->block_size : + 1L)); +} /* function: init_variables @@ -493,12 +607,38 @@ static void init_variables(const struct my_option *options) { if (options->value) { - if (options->var_type == GET_LONG) + switch (options->var_type) { + case GET_BOOL: + *((my_bool*) options->u_max_value)= *((my_bool*) options->value)= + (my_bool) options->def_value; + break; + case GET_INT: + *((int*) options->u_max_value)= *((int*) options->value)= + (int) options->def_value; + break; + case GET_UINT: + *((uint*) options->u_max_value)= *((uint*) options->value)= + (uint) options->def_value; + break; + case GET_LONG: *((long*) options->u_max_value)= *((long*) options->value)= (long) options->def_value; - else if (options->var_type == GET_LL) + break; + case GET_ULONG: + *((ulong*) options->u_max_value)= *((ulong*) options->value)= + (ulong) options->def_value; + break; + case GET_LL: *((longlong*) options->u_max_value)= *((longlong*) options->value)= - options->def_value; + (longlong) options->def_value; + break; + case GET_ULL: + *((ulonglong*) options->u_max_value)= *((ulonglong*) options->value)= + (ulonglong) options->def_value; + break; + default: /* dummy default to avoid compiler warnings */ + break; + } } } } @@ -520,7 +660,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 @@ -528,29 +668,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) - { - 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) + if (strlen(optp->name)) { - 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(' '); @@ -587,36 +730,47 @@ void my_print_variables(const struct my_option *options) char buff[255]; const struct my_option *optp; - printf("Variables (--variable-name=value) Default value\n"); - printf("--------------------------------- -------------\n"); + printf("\nVariables (--variable-name=value)\n"); + printf("and boolean options {FALSE|TRUE} Value (after reading options)\n"); + printf("--------------------------------- -----------------------------\n"); for (optp= options; optp->id; optp++) { - if (optp->value && optp->var_type != GET_BOOL) + if (optp->value) { printf("%s", optp->name); length= strlen(optp->name); for (; length < name_space; length++) putchar(' '); - if (optp->var_type == GET_STR) - { - if (*((char**) optp->value)) - printf("%s\n", *((char**) optp->value)); - else - printf("(No default value)\n"); - } - else if (optp->var_type == GET_LONG) - { - if (!optp->def_value && !*((long*) optp->value)) - printf("(No default value)\n"); - else - printf("%lu\n", *((long*) optp->value)); - } - else - { - if (!optp->def_value && !*((longlong*) optp->value)) - printf("(No default value)\n"); - else - printf("%s\n", llstr(*((longlong*) optp->value), buff)); + switch (optp->var_type) { + case GET_STR: + case GET_STR_ALLOC: /* fall through */ + printf("%s\n", *((char**) optp->value) ? *((char**) optp->value) : + "(No default value)"); + break; + case GET_BOOL: + printf("%s\n", *((my_bool*) optp->value) ? "TRUE" : "FALSE"); + break; + case GET_INT: + printf("%d\n", *((int*) optp->value)); + break; + case GET_UINT: + printf("%d\n", *((uint*) optp->value)); + break; + case GET_LONG: + printf("%lu\n", *((long*) optp->value)); + break; + case GET_ULONG: + printf("%lu\n", *((ulong*) optp->value)); + break; + case GET_LL: + printf("%s\n", llstr(*((longlong*) optp->value), buff)); + break; + case GET_ULL: + longlong2str(*((ulonglong*) optp->value), buff, 10); + printf("%s\n", buff); + break; + default: /* dummy default to avoid compiler warnings */ + break; } } } diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c index 37c18a32451..e1345b96627 100644 --- a/mysys/my_pthread.c +++ b/mysys/my_pthread.c @@ -23,9 +23,6 @@ #include <m_string.h> #include <thr_alarm.h> #include <assert.h> -#if !defined(MSDOS) && !defined(__WIN__) -#include <netdb.h> -#endif #if (defined(__BSD__) || defined(_BSDI_VERSION)) && !defined(HAVE_mit_thread) #define SCHED_POLICY SCHED_RR @@ -410,56 +407,6 @@ int my_pthread_cond_init(pthread_cond_t *mp, const pthread_condattr_t *attr) #endif -/* -** Emulate SOLARIS style calls, not because it's better, but just to make the -** usage of getbostbyname_r simpler. -*/ - -#if !defined(my_gethostbyname_r) && defined(HAVE_GETHOSTBYNAME_R) - -#if defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE) - -struct hostent *my_gethostbyname_r(const char *name, - struct hostent *result, char *buffer, - int buflen, int *h_errnop) -{ - struct hostent *hp; - DBUG_ASSERT((size_t) buflen >= sizeof(*result)); - if (gethostbyname_r(name,result, buffer, (size_t) buflen, &hp, h_errnop)) - return 0; - return hp; -} - -#elif defined(HAVE_GETHOSTBYNAME_R_RETURN_INT) - -struct hostent *my_gethostbyname_r(const char *name, - struct hostent *result, char *buffer, - int buflen, int *h_errnop) -{ - DBUG_ASSERT(buflen >= sizeof(struct hostent_data)); - if (gethostbyname_r(name,result,(struct hostent_data *) buffer) == -1) - { - *h_errnop= errno; - return 0; - } - return result; -} - -#else - -struct hostent *my_gethostbyname_r(const char *name, - struct hostent *result, char *buffer, - int buflen, int *h_errnop) -{ - struct hostent *hp; - DBUG_ASSERT(buflen >= sizeof(struct hostent_data)); - hp= gethostbyname_r(name,result,(struct hostent_data *) buffer); - *h_errnop= errno; - return hp; -} - -#endif /* GLIBC2_STYLE_GETHOSTBYNAME_R */ -#endif /***************************************************************************** Patches for HPUX @@ -469,9 +416,10 @@ struct hostent *my_gethostbyname_r(const char *name, Note that currently we only remap pthread_ functions used by MySQL. If we are depending on the value for some other pthread_xxx functions, this has to be added here. -*****************************************************************************/ +****************************************************************************/ -#ifdef HPUX +#if defined(HPUX) || defined(HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT) +#undef pthread_cond_timedwait int my_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, struct timespec *abstime) @@ -483,8 +431,10 @@ int my_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, error=ETIMEDOUT; return error; } +#endif +#ifdef HPUX int my_pthread_mutex_trylock(pthread_mutex_t *mutex) { int error=pthread_mutex_trylock(mutex); diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index 5b137df20f8..f62b8d5cb1a 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -34,6 +34,9 @@ pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open,THR_LOCK_keycache, #ifndef HAVE_LOCALTIME_R pthread_mutex_t LOCK_localtime_r; #endif +#ifndef HAVE_GETHOSTBYNAME_R +pthread_mutex_t LOCK_gethostbyname_r; +#endif #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP pthread_mutexattr_t my_fast_mutexattr; #endif @@ -77,6 +80,9 @@ my_bool my_thread_global_init(void) #ifndef HAVE_LOCALTIME_R pthread_mutex_init(&LOCK_localtime_r,MY_MUTEX_INIT_SLOW); #endif +#ifndef HAVE_GETHOSTBYNAME_R + pthread_mutex_init(&LOCK_gethostbyname_r,MY_MUTEX_INIT_SLOW); +#endif return my_thread_init(); } @@ -91,6 +97,9 @@ void my_thread_global_end(void) #ifdef PPTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP pthread_mutexattr_destroy(&my_errchk_mutexattr); #endif +#ifndef HAVE_GETHOSTBYNAME_R + pthread_mutex_destroy(&LOCK_gethostbyname_r); +#endif } static long thread_id=0; @@ -105,7 +114,9 @@ static long thread_id=0; my_bool my_thread_init(void) { struct st_my_thread_var *tmp; -#ifdef EXTRA_DEBUG + my_bool error=0; + +#ifdef EXTRA_DEBUG_THREADS fprintf(stderr,"my_thread_init(): thread_id=%ld\n",pthread_self()); #endif #if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX) @@ -117,16 +128,14 @@ my_bool my_thread_init(void) { #ifdef EXTRA_DEBUG fprintf(stderr,"my_thread_init() called more than once in thread %ld\n", - pthread_self()); + pthread_self()); #endif - pthread_mutex_unlock(&THR_LOCK_lock); - return 0; /* Safequard */ + goto end; } - if (!(tmp=(struct st_my_thread_var *) - calloc(1, sizeof(struct st_my_thread_var)))) + if (!(tmp= (struct st_my_thread_var *) calloc(1, sizeof(*tmp)))) { - pthread_mutex_unlock(&THR_LOCK_lock); - return 1; + error= 1; + goto end; } pthread_setspecific(THR_KEY_mysys,tmp); @@ -146,13 +155,13 @@ end: #if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX) pthread_mutex_unlock(&THR_LOCK_lock); #endif - return 0; + return error; } void my_thread_end(void) { struct st_my_thread_var *tmp=my_thread_var; -#ifdef EXTRA_DEBUG +#ifdef EXTRA_DEBUG_THREADS fprintf(stderr,"my_thread_end(): tmp=%p,thread_id=%ld\n", tmp,pthread_self()); #endif diff --git a/mysys/raid.cc b/mysys/raid.cc index 72d3b2074be..6196e1f1aa6 100644 --- a/mysys/raid.cc +++ b/mysys/raid.cc @@ -94,7 +94,7 @@ extern "C" { void init_raid(void) { /* Allocate memory for global file to raid map */ - init_dynamic_array(&RaidFd::_raid_map, sizeof(RaidFd*), 4096, 1024); + my_init_dynamic_array(&RaidFd::_raid_map, sizeof(RaidFd*), 4096, 1024); } void end_raid(void) { diff --git a/mysys/raid2.c b/mysys/raid2.c new file mode 100644 index 00000000000..94b085b0074 --- /dev/null +++ b/mysys/raid2.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2002 MySQL AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +/* + RAID support for MySQL. For full comments, check raid.cc + This is in a separate file to not cause problems on OS that can't + put C++ files in archives. +*/ + +#include "mysys_priv.h" + +const char *raid_type_string[]={"none","striped"}; + +const char *my_raid_type(int raid_type) +{ + return raid_type_string[raid_type]; +} diff --git a/mysys/testhash.c b/mysys/testhash.c index 461f1d8be5e..a1d14dc225d 100644 --- a/mysys/testhash.c +++ b/mysys/testhash.c @@ -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 */ -/* Test av hash libarary: stor test */ +/* Test of hash library: big test */ #include <my_global.h> #include <my_sys.h> @@ -36,6 +36,7 @@ static uint16 key1[1000]; #else my_bool hash_check(HASH *hash); #endif + void free_record(void *record); static byte *hash2_key(const byte *rec,uint *length, @@ -45,7 +46,7 @@ static byte *hash2_key(const byte *rec,uint *length, return (byte*) rec; } - /* Huvudprogrammet */ +/* main program */ int main(int argc,char *argv[]) { @@ -75,7 +76,7 @@ static int do_test() printf("- Creating hash\n"); if (hash_init(&hash,recant/2,0,6,0,free_record,0)) goto err; - printf("- Writing records:s\n"); + printf("- Writing records:\n"); for (i=0 ; i < recant ; i++) { @@ -242,8 +243,8 @@ err: } /* main */ - /* l{ser optioner */ - /* OBS! intierar endast DEBUG - ingen debuggning h{r ! */ +/* read options */ +/* NOTE! DBUG not initialised - no debugging here! */ static int get_options(int argc, char **argv) { @@ -264,7 +265,7 @@ static int get_options(int argc, char **argv) case 'I': case '?': printf("%s Ver 1.0 for %s at %s\n",progname,SYSTEM_TYPE,MACHINE_TYPE); - puts("TCX Datakonsult AB, by Monty, for your professional use\n"); + printf("MySQL AB, by Monty\n\n"); printf("Usage: %s [-?ABIKLWv] [-m#] [-t#]\n",progname); exit(0); case '#': @@ -274,9 +275,10 @@ static int get_options(int argc, char **argv) } } return 0; -} /* get options */ +} /* get_options */ + - /* Ge ett randomv{rde inom ett intervall 0 <=x <= n */ +/* Get a random number in the interval 0 <= x <= n */ static int rnd(int max_value) { |