cvs commit: ALFS/nALFS/src options.c

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Tue Nov 4 08:45:15 PST 2003


kpfleming    03/11/04 09:45:15

  Modified:    nALFS/src options.c
  Log:
  simplify boolean input validation
  
  Revision  Changes    Path
  1.12      +11 -23    ALFS/nALFS/src/options.c
  
  Index: options.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/options.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- options.c	4 Nov 2003 04:06:53 -0000	1.11
  +++ options.c	4 Nov 2003 16:45:14 -0000	1.12
  @@ -226,13 +226,14 @@
   	return 1;
   }
   
  -static int convert_to_boolean(const char *input, BOOL *val)
  +static int validate_boolean_input(const struct option_s *option,
  +				  const char *input, BOOL *val)
   {
   	char *p;
  +	char *tmp;
   	int status = 1;
  -	char *tmp = xstrdup(input);
   
  -	p = tmp;
  +	p = tmp = xstrdup(input);
   	while (*p) {
   		*p = tolower(*p);
   		++p;
  @@ -250,26 +251,15 @@
   		*val = 0;
   	else if (!strcmp(tmp, "false"))
   		*val = 0;
  -	else
  -		status = 0;
  -
  -	xfree(tmp);
  -	return status;
  -}
  -
  -static int validate_boolean_input(const struct option_s *option,
  -				  const char *input)
  -{
  -	BOOL val;
  -
  -	if (!convert_to_boolean(input, &val)) {
  +	else {
   		fprintf(stderr, "Option \"%s\" does not contain a valid"
   			" boolean value,\nchoices are yes/y/true and"
   			" no/n/false.\n", option->name);
  -		return 0;
  +		status = 0;
   	}
  -	else
  -		return 1;
  +
  +	xfree(tmp);
  +	return status;
   }
   
   set_opt_e set_yet_unknown_option(const char *opt, const char *val)
  @@ -286,11 +276,9 @@
   
   		switch (options[i]->type) {
   		case O_BOOL:
  -			if (validate_boolean_input(options[i], val)) {
  -				convert_to_boolean(val,
  -						   &options[i]->val.bool.value);
  +			if (validate_boolean_input(options[i], val,
  +						   &options[i]->val.bool.value))
   				return OPTION_SET;
  -			}
   			
   			return OPTION_INVALID_VALUE;
   			
  
  
  



More information about the alfs-log mailing list