Commit 21c1e5be authored by unknown's avatar unknown

- Added new type GET_STRALC to my_getopt.

- Fixed some bugs, wrongly freed pointers, in some clients.
- Removed unneccessary code.
- Fixed some other minor bugs and added some options into
  variables category, which had accidently been left out earlier.


client/mysql.cc:
  Fixed some wrong freed pointers. Removed unneccessary code.
  Changed some types from GET_STR to GET_STRALC.
client/mysqladmin.c:
  Fixed some wrong freed pointers. Removed unneccessary code.
  Changed some types from GET_STR to GET_STRALC.
client/mysqlcheck.c:
  Fixed some wrong freed pointers. Removed unneccessary code.
  Changed some types from GET_STR to GET_STRALC.
client/mysqldump.c:
  Fixed some wrong freed pointers. Removed unneccessary code.
  Changed some types from GET_STR to GET_STRALC.
client/mysqlimport.c:
  Removed unneccessary code.
  Fixed a bug in option --ignore-lines
client/mysqlshow.c:
  Removed unneccessary code.
include/my_getopt.h:
  Added new type, GET_STRALC. The name stands for GET STRING ALLOC,
  which means that the struct member value and u_max_value are
  strings that must be alloced and freed when used.
  The normal GET_STR works similarly otherwise, except that it's
  arguments are just pointers to strings, not alloced ones.
mysys/my_getopt.c:
  Added support for GET_STRALC
parent f20dda3e
......@@ -41,7 +41,7 @@
#include <signal.h>
#include <violite.h>
const char *VER= "12.4";
const char *VER= "12.5";
/* Don't try to make a nice table if the data is too big */
#define MAX_COLUMN_LENGTH 1024
......@@ -458,8 +458,8 @@ static struct my_option my_long_options[] =
{"debug", '#', "Output debug log.", (gptr*) &default_dbug_option,
(gptr*) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
#endif
{"database", 'D', "Database to use.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0,
0, 0, 0, 0},
{"database", 'D', "Database to use.", (gptr*) &current_db,
(gptr*) &current_db, 0, GET_STRALC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"execute", 'e', "Execute command and quit. (Output like with --batch).", 0,
0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"vertical", 'E', "Print the output of a query (rows) vertically.",
......@@ -478,10 +478,10 @@ static struct my_option my_long_options[] =
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"local-infile", OPT_LOCAL_INFILE, "Enable/disable LOAD DATA LOCAL INFILE.",
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"no-beep", 'b', "Turn off beep on error.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
0, 0, 0, 0, 0},
{"no-beep", 'b', "Turn off beep on error.", (gptr*) &opt_nobeep,
(gptr*) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"host", 'h', "Connect to host.", (gptr*) &current_host,
(gptr*) &current_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
(gptr*) &current_host, 0, GET_STRALC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"html", 'H', "Produce HTML output.", (gptr*) &opt_html, (gptr*) &opt_html,
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"xml", 'X', "Produce XML output", (gptr*) &opt_xml, (gptr*) &opt_xml, 0,
......@@ -527,8 +527,9 @@ static struct my_option my_long_options[] =
{"port", 'P', "Port number to use for connection.", (gptr*) &opt_mysql_port,
(gptr*) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0,
0},
{"prompt", OPT_PROMPT, "Set the mysql prompt to this value.", 0, 0, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"prompt", OPT_PROMPT, "Set the mysql prompt to this value.",
(gptr*) &current_prompt, (gptr*) &current_prompt, 0, GET_STRALC,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"quick", 'q',
"Don't cache result, print it row by row. This may slow down the server if the output is suspended. Doesn't use history file. ",
(gptr*) &quick, (gptr*) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
......@@ -538,7 +539,8 @@ static struct my_option my_long_options[] =
{"silent", 's', "Be more silent.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0,
0, 0},
{"socket", 'S', "Socket file to use for connection.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
(gptr*) &opt_mysql_unix_port, (gptr*) &opt_mysql_unix_port, 0, GET_STRALC,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#include "sslopt-longopts.h"
{"table", 't', "Output in table format.", (gptr*) &output_tables,
(gptr*) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
......@@ -549,7 +551,7 @@ static struct my_option my_long_options[] =
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#ifndef DONT_ALLOW_USER_CHANGE
{"user", 'u', "User for login if not current user.", (gptr*) &current_user,
(gptr*) &current_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
(gptr*) &current_user, 0, GET_STRALC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#endif
{"safe-updates", 'U', "Only allow UPDATE and DELETE that uses keys.",
(gptr*) &safe_updates, (gptr*) &safe_updates, 0, GET_BOOL, OPT_ARG, 0, 0,
......@@ -602,16 +604,13 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch(optid) {
case OPT_DEFAULT_CHARSET:
default_charset= argument;
break;
case OPT_CHARSETS_DIR:
strmov(mysql_charsets_dir, argument);
charsets_dir = mysql_charsets_dir;
break;
case OPT_LOCAL_INFILE:
using_opt_local_infile=1;
opt_local_infile= test(!optarg || atoi(optarg)>0);
opt_local_infile= test(!argument || atoi(argument)>0);
break;
case OPT_TEE:
if (argument == disabled_my_option)
......@@ -646,20 +645,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
printf("WARNING: option depricated; use --disable-pager instead.\n");
opt_nopager= 1;
break;
case OPT_PROMPT:
my_free(current_prompt,MYF(MY_ALLOW_ZERO_PTR));
current_prompt=my_strdup(optarg,MYF(MY_FAE));
break;
case 'A':
rehash= 0;
break;
case 'b':
opt_nobeep = 1;
break;
case 'D':
my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
current_db= my_strdup(argument, MYF(MY_WME));
break;
case 'e':
status.batch= 1;
status.add_to_history= 0;
......@@ -668,16 +656,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
return 1;
ignore_errors= 0;
break;
case 'h':
my_free(current_host, MYF(MY_ALLOW_ZERO_PTR));
current_host= my_strdup(argument, MYF(MY_WME));
break;
#ifndef DONT_ALLOW_USER_CHANGE
case 'u':
my_free(current_user, MYF(MY_ALLOW_ZERO_PTR));
current_user= my_strdup(argument, MYF(MY_WME));
break;
#endif
case 'o':
if (argument == disabled_my_option)
one_database= 0;
......@@ -726,13 +704,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
opt_silent++; // more silent
}
break;
case 'P':
opt_mysql_port= (unsigned int) atoi(argument);
break;
case 'S':
my_free(opt_mysql_unix_port, MYF(MY_ALLOW_ZERO_PTR));
opt_mysql_unix_port= my_strdup(argument, MYF(0));
break;
case 'W':
#ifdef __WIN__
opt_mysql_unix_port= my_strdup(MYSQL_NAMEDPIPE, MYF(0));
......
......@@ -24,7 +24,7 @@
#include <my_pthread.h> /* because of signal() */
#endif
#define ADMIN_VERSION "8.31"
#define ADMIN_VERSION "8.32"
#define MAX_MYSQL_VAR 64
#define SHUTDOWN_DEF_TIMEOUT 3600 /* Wait for shutdown */
#define MAX_TRUNC_LENGTH 3
......@@ -136,14 +136,15 @@ static struct my_option my_long_options[] =
{"silent", 's', "Silently exit if one can't connect to server",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"socket", 'S', "Socket file to use for connection.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
(gptr*) &unix_port, (gptr*) &unix_port, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
0, 0, 0},
{"sleep", 'i', "Execute commands again and again with a sleep between.",
(gptr*) &interval, (gptr*) &interval, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0,
0, 0},
#include "sslopt-longopts.h"
#ifndef DONT_ALLOW_USER_CHANGE
{"user", 'u', "User for login if not current user.", (gptr*) &user,
(gptr*) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
(gptr*) &user, 0, GET_STRALC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#endif
{"verbose", 'v', "Write more information.", (gptr*) &opt_verbose,
(gptr*) &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
......@@ -174,10 +175,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
int error = 0;
switch(optid) {
case 'h':
host = argument;
break;
case 'q': /* Allow old 'q' option */
case 'p':
if (argument)
{
......@@ -191,23 +188,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
else
tty_password=1;
break;
#ifndef DONT_ALLOW_USER_CHANGE
case 'u':
user= my_strdup(argument,MYF(0));
break;
#endif
case 'i':
interval=atoi(argument);
break;
case 'P':
tcp_port= (unsigned int) atoi(argument);
break;
case 's':
option_silent++;
break;
case 'S':
unix_port= argument;
break;
case 'W':
#ifdef __WIN__
unix_port=MYSQL_NAMEDPIPE;
......
......@@ -16,7 +16,7 @@
/* By Jani Tolonen, 2001-04-20, MySQL Development Team */
#define CHECK_VERSION "2.1"
#define CHECK_VERSION "2.2"
#include "client_priv.h"
#include <my_getopt.h>
......@@ -94,7 +94,7 @@ static struct my_option my_long_options[] =
{"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"host",'h', "Connect to host.", (gptr*) &current_host,
(gptr*) &current_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
(gptr*) &current_host, 0, GET_STRALC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"medium-check", 'm',
"Faster than extended-check, but only finds 99.99 percent of all errors. Should be good enough for most cases.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
......@@ -199,12 +199,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case 'a':
what_to_do = DO_ANALYZE;
break;
case OPT_DEFAULT_CHARSET:
default_charset = argument;
break;
case OPT_CHARSETS_DIR:
charsets_dir = argument;
break;
case 'c':
what_to_do = DO_CHECK;
break;
......@@ -216,10 +210,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case '?':
usage();
exit(0);
case 'h':
my_free(current_host, MYF(MY_ALLOW_ZERO_PTR));
current_host = my_strdup(argument, MYF(MY_WME));
break;
case 'm':
what_to_do = DO_CHECK;
opt_medium_check = 1;
......@@ -227,11 +217,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case 'o':
what_to_do = DO_OPTIMIZE;
break;
#ifndef DONT_ALLOW_USER_CHANGE
case 'u':
current_user = argument;
break;
#endif
case 'p':
if (argument)
{
......@@ -245,15 +230,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
else
tty_password = 1;
break;
case 'P':
opt_mysql_port = (unsigned int) atoi(argument);
break;
case 'r':
what_to_do = DO_REPAIR;
break;
case 'S':
opt_mysql_unix_port = argument;
break;
case 'W':
#ifdef __WIN__
opt_mysql_unix_port = MYSQL_NAMEDPIPE;
......
......@@ -35,7 +35,7 @@
** and adapted to mysqldump 05/11/01 by Jani Tolonen
*/
#define DUMP_VERSION "9.03"
#define DUMP_VERSION "9.04"
#include <my_global.h>
#include <my_sys.h>
......@@ -97,8 +97,9 @@ static struct my_option my_long_options[] =
"Dump all the databases. This will be same as --databases with all databases selected.",
(gptr*) &opt_alldbs, (gptr*) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
0, 0},
{"all", 'a', "Include all MySQL specific create options.", 0, 0, 0,
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"all", 'a', "Include all MySQL specific create options.",
(gptr*) &create_options, (gptr*) &create_options, 0, GET_BOOL, NO_ARG, 0,
0, 0, 0, 0, 0},
{"add-drop-table", OPT_DROP, "Add a 'drop table' before each create.",
(gptr*) &opt_drop, (gptr*) &opt_drop, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
0},
......@@ -111,8 +112,8 @@ static struct my_option my_long_options[] =
{"character-sets-dir", OPT_CHARSETS_DIR,
"Directory where character sets are", (gptr*) &charsets_dir,
(gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"complete-insert", 'c', "Use complete insert statements.", 0, 0, 0,
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"complete-insert", 'c', "Use complete insert statements.", (gptr*) &cFlag,
(gptr*) &cFlag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"compress", 'C', "Use compression in server/client protocol.",
(gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
0, 0, 0},
......@@ -158,7 +159,7 @@ static struct my_option my_long_options[] =
{"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"host", 'h', "Connect to host.", (gptr*) &current_host,
(gptr*) &current_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
(gptr*) &current_host, 0, GET_STRALC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
(gptr*) &lines_terminated, (gptr*) &lines_terminated, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
......@@ -176,9 +177,9 @@ static struct my_option my_long_options[] =
(gptr*) &opt_create_db, (gptr*) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
0, 0, 0, 0},
{"no-create-info", 't', "Don't write table creation info.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"no-data", 'd', "No row information.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
0, 0, 0, 0},
(gptr*) &tFlag, (gptr*) &tFlag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"no-data", 'd', "No row information.", (gptr*) &dFlag, (gptr*) &dFlag, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"set-variable", 'O',
"Change the value of a variable. Please note that this option is depricated; you can set variables directly with --variable-name=value.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
......@@ -301,24 +302,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
opt_master_data=1;
opt_first_slave=1;
break;
case 'a':
create_options=1;
break;
case OPT_DEFAULT_CHARSET:
default_charset= argument;
break;
case OPT_CHARSETS_DIR:
charsets_dir= argument;
break;
case 'h':
my_free(current_host,MYF(MY_ALLOW_ZERO_PTR));
current_host=my_strdup(argument,MYF(MY_WME));
break;
#ifndef DONT_ALLOW_USER_CHANGE
case 'u':
current_user=argument;
break;
#endif
case 'p':
if (argument)
{
......@@ -332,36 +315,23 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
else
tty_password=1;
break;
case 'P':
opt_mysql_port= (unsigned int) atoi(argument);
break;
case 'r':
if (!(md_result_file = my_fopen(argument, O_WRONLY | O_BINARY,
MYF(MY_WME))))
exit(1);
break;
case 'S':
opt_mysql_unix_port= argument;
break;
case 'W':
#ifdef __WIN__
opt_mysql_unix_port=MYSQL_NAMEDPIPE;
#endif
break;
case 'T':
path= argument;
opt_disable_keys=0;
break;
case '#':
DBUG_PUSH(argument ? argument : "d:t:o");
break;
case 'c': cFlag=1; break;
case 'd': dFlag=1; break;
case 't': tFlag=1; break;
case 'V': print_version(); exit(0);
case 'w':
where=argument;
break;
case 'X':
opt_xml = 1;
opt_disable_keys=0;
......@@ -370,21 +340,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case '?':
usage();
exit(0);
case (int) OPT_FTB:
fields_terminated= argument;
break;
case (int) OPT_LTB:
lines_terminated= argument;
break;
case (int) OPT_ENC:
enclosed= argument;
break;
case (int) OPT_O_ENC:
opt_enclosed= argument;
break;
case (int) OPT_ESC:
escaped= argument;
break;
case (int) OPT_OPTIMIZE:
extended_insert=opt_drop=opt_lock=lock_tables=quick=create_options=
opt_disable_keys=1;
......
......@@ -25,7 +25,7 @@
** * *
** *************************
*/
#define IMPORT_VERSION "3.1"
#define IMPORT_VERSION "3.2"
#include "client_priv.h"
#include "mysql_version.h"
......@@ -90,8 +90,9 @@ static struct my_option my_long_options[] =
(gptr*) &current_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"ignore", 'i', "If duplicate unique key was found, keep old row.",
(gptr*) &ignore, (gptr*) &ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"ignore-lines", OPT_IGN_LINES, "Ignore first n lines of data infile.", 0, 0,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"ignore-lines", OPT_IGN_LINES, "Ignore first n lines of data infile.",
(gptr*) &opt_ignore_lines, (gptr*) &opt_ignore_lines, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
(gptr*) &lines_terminated, (gptr*) &lines_terminated, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
......@@ -166,23 +167,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch(optid) {
case 'c':
opt_columns= argument;
break;
case OPT_DEFAULT_CHARSET:
default_charset= argument;
break;
case OPT_CHARSETS_DIR:
charsets_dir= argument;
break;
case 'h':
current_host= argument;
break;
#ifndef DONT_ALLOW_USER_CHANGE
case 'u':
current_user= argument;
break;
#endif
case 'p':
if (argument)
{
......@@ -196,12 +180,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
else
tty_password= 1;
break;
case 'P':
opt_mysql_port= (unsigned int) atoi(argument);
break;
case 'S':
opt_mysql_unix_port= argument;
break;
#ifdef __WIN__
case 'W':
opt_mysql_unix_port=MYSQL_NAMEDPIPE;
......@@ -216,24 +194,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case '?':
usage();
exit(0);
case (int) OPT_FTB:
fields_terminated= argument;
break;
case (int) OPT_LTB:
lines_terminated= argument;
break;
case (int) OPT_ENC:
enclosed= argument;
break;
case (int) OPT_O_ENC:
opt_enclosed= argument;
break;
case (int) OPT_ESC:
escaped= argument;
break;
case (int) OPT_IGN_LINES:
opt_ignore_lines= argument;
break;
#include "sslopt-case.h"
}
return 0;
......
......@@ -16,7 +16,7 @@
/* Show databases, tables or columns */
#define SHOW_VERSION "9.1"
#define SHOW_VERSION "9.2"
#include <my_global.h>
#include "client_priv.h"
......@@ -198,15 +198,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
switch(optid) {
case 'c':
charsets_dir= argument;
break;
case 'v':
opt_verbose++;
break;
case 'h':
host = argument;
break;
case 'p':
if (argument)
{
......@@ -220,17 +214,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
else
tty_password=1;
break;
#ifndef DONT_ALLOW_USER_CHANGE
case 'u':
user=argument;
break;
#endif
case 'P':
opt_mysql_port= (unsigned int) atoi(argument);
break;
case 'S':
opt_mysql_unix_port= argument;
break;
case 'W':
#ifdef __WIN__
opt_mysql_unix_port=MYSQL_NAMEDPIPE;
......
......@@ -17,7 +17,7 @@
C_MODE_START
enum get_opt_var_type { GET_NO_ARG, GET_BOOL, GET_INT, GET_UINT, GET_LONG,
GET_ULONG, GET_LL, GET_ULL, GET_STR };
GET_ULONG, GET_LL, GET_ULL, GET_STR, GET_STRALC };
enum get_opt_arg_type { NO_ARG, OPT_ARG, REQUIRED_ARG };
struct my_option
......
......@@ -19,6 +19,7 @@
#include <stdlib.h>
#include <my_getopt.h>
#include <assert.h>
#include <my_sys.h>
static int findopt (char *optpat, uint length,
const struct my_option **opt_res,
......@@ -423,6 +424,12 @@ static int setval (const struct my_option *opts, char *argument,
*((ulonglong*) result_pos)= getopt_ull(argument, opts, &err);
else if (opts->var_type == GET_STR)
*((char**) result_pos)= argument;
else if (opts->var_type == GET_STRALC)
{
if ((*((char**) result_pos)))
my_free((*(char**) result_pos), MYF(MY_ALLOW_ZERO_PTR));
*((char**) result_pos)= my_strdup(argument, MYF(MY_WME));
}
if (err)
return ERR_UNKNOWN_SUFFIX;
}
......@@ -627,7 +634,7 @@ void my_print_help(const struct my_option *options)
}
printf("--%s", optp->name);
col+= 2 + strlen(optp->name);
if (optp->var_type == GET_STR)
if (optp->var_type == GET_STR || optp->var_type == GET_STRALC)
{
printf("%s=name%s ", optp->arg_type == OPT_ARG ? "[" : "",
optp->arg_type == OPT_ARG ? "]" : "");
......@@ -694,7 +701,7 @@ void my_print_variables(const struct my_option *options)
length= strlen(optp->name);
for (; length < name_space; length++)
putchar(' ');
if (optp->var_type == GET_STR)
if (optp->var_type == GET_STR || optp->var_type == GET_STRALC)
{
if (*((char**) optp->value))
printf("%s\n", *((char**) optp->value));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment