Commit c4f1ced9 authored by unknown's avatar unknown

New functionality to my_getopt. myisamchk now uses my_getopt

only.


include/my_getopt.h:
  Added u_max_value as for user definable maximum value for
  a variable in my_getopt.
myisam/myisamchk.c:
  myisamchk now uses my_getopt struct for variables also.
  Variables can be set with -O var=val, --set-variable=var=val and
  --variable=val now.
mysys/getvar.c:
  my_set_changeable_var moved to my_getopt.c
mysys/my_getopt.c:
  Added special prefix --maximum[-variable-name=...] for user
  definable maximum values for variables, among other things.
parent 5b968bb8
......@@ -23,14 +23,15 @@ struct my_optarg
};
enum get_opt_var_type { GET_NO_ARG, GET_INT, GET_LL, GET_STR };
enum get_opt_var_type { GET_NO_ARG, GET_LONG, GET_LL, GET_STR };
enum get_opt_arg_type { NO_ARG, OPT_ARG, REQUIRED_ARG };
struct my_option
{
const char *name; /* Name of the option */
const char *comment; /* option comment, for autom. --help */
char *value; /* The variable value */
gptr *value; /* The variable value */
gptr *u_max_value; /* The user def. max variable value */
const char **str_values; /* Pointer to possible values */
enum get_opt_var_type var_type;
enum get_opt_arg_type arg_type;
......@@ -41,6 +42,6 @@ struct my_option
longlong sub_size; /* Subtract this from given value */
long block_size; /* Value should be a mult. of this */
int app_type; /* To be used by an application */
my_bool changeable_var; /* If true, the option is a variable */
my_bool opt_is_var; /* If true, the option is a variable */
};
This diff is collapsed.
......@@ -109,78 +109,3 @@ my_bool set_changeable_var(my_string str,CHANGEABLE_VAR *vars)
}
DBUG_RETURN(1);
}
my_bool my_set_changeable_var(my_string str, const struct my_option *vars)
{
char endchar;
my_string end;
DBUG_ENTER("my_set_changeable_var");
DBUG_PRINT("enter",("%s",str));
if (str)
{
if (!(end=strchr(str,'=')))
fprintf(stderr,"Can't find '=' in expression '%s' to option -O\n",str);
else
{
uint length,found_count=0;
const struct my_option *var, *found;
my_string var_end;
const char *name;
longlong num;
/* Skip end space from variable */
for (var_end=end ; end > str && isspace(var_end[-1]) ; var_end--) ;
length=(uint) (var_end-str);
/* Skip start space from argument */
for (end++ ; isspace(*end) ; end++) ;
for (var= vars, found= 0; (name= var->name); var++)
{
if (var->changeable_var)
{
if (!my_casecmp(name, str, length))
{
found= var; found_count++;
if (!name[length])
{
found_count=1;
break;
}
}
}
}
if (found_count == 0)
{
fprintf(stderr,"No variable match for: -O '%s'\n",str);
DBUG_RETURN(1);
}
if (found_count > 1)
{
fprintf(stderr,"Variable prefix '%*s' is not unique\n",length,str);
DBUG_RETURN(1);
}
num=strtoll(end, (char **)NULL, 10); endchar=strend(end)[-1];
if (endchar == 'k' || endchar == 'K')
num*=1024;
else if (endchar == 'm' || endchar == 'M')
num*=1024L*1024L;
else if (endchar == 'g' || endchar == 'G')
num*=1024L*1024L*1024L;
else if (!isdigit(endchar))
{
fprintf(stderr,"Unknown prefix used for variable value '%s'\n",str);
DBUG_RETURN(1);
}
if (num < (longlong) found->min_value)
num=(longlong) found->min_value;
else if (num > 0 && (ulonglong) num > (ulonglong) (ulong) found->max_value)
num=(longlong) (ulong) found->max_value;
num=((num- (longlong) found->sub_size) / (ulonglong) found->block_size);
/* (*found->varptr)= (long) (num*(ulonglong) found->block_size);*/
DBUG_RETURN(0);
}
}
DBUG_RETURN(1);
}
This diff is collapsed.
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