cvs commit: ALFS/nALFS/src init.c options.c

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Tue Nov 4 19:21:58 PST 2003


kpfleming    03/11/04 20:21:58

  Modified:    nALFS/src init.c options.c
  Log:
  reverse sense of validate_boolean_input test to be consistent with other option types
  add validate_number_input function and move strtol() code there; add check for errno!=0 after strtol() call
  remove "option has invalid value" message from init.c, as set_yet_unknown_option will generate messages for any validation failures that it finds
  
  Revision  Changes    Path
  1.6       +0 -4      ALFS/nALFS/src/init.c
  
  Index: init.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/init.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- init.c	3 Nov 2003 22:12:18 -0000	1.5
  +++ init.c	5 Nov 2003 03:21:58 -0000	1.6
  @@ -118,10 +118,6 @@
   			break;
   
   		case OPTION_INVALID_VALUE:
  -			fprintf(stderr,
  -				"Option \"%s\" has invalid value \"%s\".\n",
  -				opt,
  -				val);
   			ret = -1;
   			break;
   	}
  
  
  
  1.15      +31 -9     ALFS/nALFS/src/options.c
  
  Index: options.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/options.c,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- options.c	4 Nov 2003 18:48:48 -0000	1.14
  +++ options.c	5 Nov 2003 03:21:58 -0000	1.15
  @@ -23,6 +23,8 @@
   
   
   #include <string.h>
  +#include <stdlib.h>
  +#include <errno.h>
   
   #ifdef HAVE_CONFIG_H
   #include <config.h>
  @@ -276,12 +278,34 @@
   	return status;
   }
   
  +static int validate_number_input(const struct option_s *option,
  +				 const char *input, NUMBER *val)
  +{
  +	char *tmp;
  +	int status = 1;
  +
  +	*val = (NUMBER) strtol(input, &tmp, 10);
  +			
  +	if (tmp != NULL && *tmp) {
  +		option_invalid(option,
  +			       "%s\n\textraneous characters found (%s).",
  +			       input, tmp);
  +		status = 0;
  +	} else if (errno) {
  +		option_invalid(option,
  +			       "%s\n\tnumeric conversion failure.",
  +			       input);
  +		status = 0;
  +	}
  +
  +	return status;
  +			
  +}
  +
   set_opt_e set_yet_unknown_option(const char *opt, const char *val)
   {
   	int i;
  -	long num;
  -	char *s = NULL;
  -
  +	NUMBER num;
   
   	for (i = 0; options[i]; i++) {
   		if (strcmp(options[i]->name, opt) != 0) {
  @@ -290,16 +314,14 @@
   
   		switch (options[i]->type) {
   		case O_BOOL:
  -			if (validate_boolean_input(options[i], val,
  +			if (!validate_boolean_input(options[i], val,
   						   &options[i]->val.bool.value))
  -				return OPTION_SET;
  +				return OPTION_INVALID_VALUE;
   			
  -			return OPTION_INVALID_VALUE;
  +			return OPTION_SET;
   			
   		case O_NUMBER:
  -			num = strtol(val, &s, 10);
  -			
  -			if (s != NULL && *s)
  +			if (!validate_number_input(options[i], val, &num))
   				return OPTION_INVALID_VALUE;
   			
   			if (options[i]->val.num.validate &&
  
  
  



More information about the alfs-log mailing list