summaryrefslogtreecommitdiff
path: root/mysys/my_getopt.c
diff options
context:
space:
mode:
authorunknown <antony@pcg5ppc.xiphis.org>2007-10-19 13:06:37 -0700
committerunknown <antony@pcg5ppc.xiphis.org>2007-10-19 13:06:37 -0700
commit62fd471647d920482eb4a8bd61d33a6cad1064ec (patch)
treec11732a55bd249a146cc63db1188fd4f7c10cd0c /mysys/my_getopt.c
parentb0488a32038ca9abf8e9ec8ec2482598aca133ab (diff)
parent8d923eb55973643d171f83616f21466defc89137 (diff)
downloadmariadb-git-62fd471647d920482eb4a8bd61d33a6cad1064ec.tar.gz
Merge anubis.xiphis.org:/usr/home/antony/work/mysql-5.1-engines
into anubis.xiphis.org:/usr/home/antony/work/mysql-5.1-engines.merge configure.in: Auto merged mysql-test/r/heap_btree.result: Auto merged mysql-test/r/log_tables.result: Auto merged mysql-test/r/partition.result: Auto merged mysql-test/r/system_mysql_db.result: Auto merged mysql-test/t/heap_btree.test: Auto merged mysql-test/t/log_tables.test: Auto merged mysql-test/t/partition.test: Auto merged mysys/my_getopt.c: Auto merged scripts/mysql_system_tables.sql: Auto merged sql/sql_base.cc: Auto merged
Diffstat (limited to 'mysys/my_getopt.c')
-rw-r--r--mysys/my_getopt.c46
1 files changed, 43 insertions, 3 deletions
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index 5b5c0881314..3aad6152dfd 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -21,6 +21,9 @@
#include <my_getopt.h>
#include <errno.h>
+typedef void (*init_func_p)(const struct my_option *option, uchar* *variable,
+ longlong value);
+
static void default_reporter(enum loglevel level, const char *format, ...);
my_error_reporter my_getopt_error_reporter= &default_reporter;
@@ -34,7 +37,12 @@ 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 double getopt_double(char *arg, const struct my_option *optp, int *err);
-static void init_variables(const struct my_option *options);
+static void init_variables(const struct my_option *options,
+ init_func_p init_one_value);
+static void init_one_value(const struct my_option *option, uchar* *variable,
+ longlong value);
+static void fini_one_value(const struct my_option *option, uchar* *variable,
+ longlong value);
static int setval(const struct my_option *opts, uchar* *value, char *argument,
my_bool set_maximum_value);
static char *check_struct_option(char *cur_arg, char *key_name);
@@ -118,7 +126,7 @@ int handle_options(int *argc, char ***argv,
DBUG_ASSERT(argv && *argv);
(*argc)--; /* Skip the program name */
(*argv)++; /* --- || ---- */
- init_variables(longopts);
+ init_variables(longopts, init_one_value);
for (pos= *argv, pos_end=pos+ *argc; pos != pos_end ; pos++)
{
@@ -922,6 +930,37 @@ static void init_one_value(const struct my_option *option, uchar* *variable,
}
+/*
+ Init one value to it's default values
+
+ SYNOPSIS
+ init_one_value()
+ option Option to initialize
+ value Pointer to variable
+*/
+
+static void fini_one_value(const struct my_option *option, uchar* *variable,
+ longlong value __attribute__ ((unused)))
+{
+ DBUG_ENTER("fini_one_value");
+ switch ((option->var_type & GET_TYPE_MASK)) {
+ case GET_STR_ALLOC:
+ my_free((*(char**) variable), MYF(MY_ALLOW_ZERO_PTR));
+ *((char**) variable)= NULL;
+ break;
+ default: /* dummy default to avoid compiler warnings */
+ break;
+ }
+ DBUG_VOID_RETURN;
+}
+
+
+void my_cleanup_options(const struct my_option *options)
+{
+ init_variables(options, fini_one_value);
+}
+
+
/*
initialize all variables to their default values
@@ -935,7 +974,8 @@ static void init_one_value(const struct my_option *option, uchar* *variable,
for a value and initialize.
*/
-static void init_variables(const struct my_option *options)
+static void init_variables(const struct my_option *options,
+ init_func_p init_one_value)
{
DBUG_ENTER("init_variables");
for (; options->name; options++)