cvs commit: ALFS/nALFS/src options.c

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Tue Nov 4 09:06:18 PST 2003


kpfleming    03/11/04 10:06:18

  Modified:    nALFS/src options.c
  Log:
  clean up formatting of validate_command
  create option_invalid function for displaying option validation errors and use it where appropriate
  
  Revision  Changes    Path
  1.13      +35 -25    ALFS/nALFS/src/options.c
  
  Index: options.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/options.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- options.c	4 Nov 2003 16:45:14 -0000	1.12
  +++ options.c	4 Nov 2003 17:06:18 -0000	1.13
  @@ -177,6 +177,19 @@
   	return s;
   }
   
  +static void option_invalid(const struct option_s *option,
  +			   const char *format, ...)
  +{
  +	va_list ap;
  +
  +	va_start(ap, format);
  +	fprintf(stderr, "Option \"%s\" has an invalid value: ",
  +		option->name);
  +	vfprintf(stderr, format, ap);
  +	fprintf(stderr, "\n");
  +	va_end(ap);
  +}
  +
   static int validate_number_minmax(const struct option_s *option,
   				  const NUMBER value)
   {
  @@ -186,11 +199,10 @@
   		 value <= option->val.num.max_value);
   
   	if (!valid)
  -		fprintf(stderr,
  -			"Option \"%s\" outside valid range, must be between"
  -			" %d and %d.\n", option->name,
  -			option->val.num.min_value,
  -			option->val.num.max_value);
  +		option_invalid(option, "%d\n\tmust be between %d and %d",
  +			       value,
  +			       option->val.num.min_value,
  +			       option->val.num.max_value);
   
   	return valid;
   }
  @@ -201,25 +213,23 @@
   	int string_count = 0;
   
   	for (tmp = value; *tmp; ++tmp) {
  -		if (*tmp == '%') {
  -			switch (*(++tmp)) {
  -			case '%':
  -				break;
  -			case 's':
  -				if (string_count++) {
  -					fprintf(stderr, "Option \"%s\" contains"
  -						" more than one string"
  -						" substitution.\n",
  -						option->name);
  -					return 0;
  -				}
  -				break;
  -			default:
  -				fprintf(stderr, "Option \"%s\" contains an"
  -					" invalid substitution specifier.\n",
  -					option->name);
  +		if (*tmp != '%')
  +			continue;
  +		switch (*(++tmp)) {
  +		case '%':
  +			break;
  +		case 's':
  +			if (string_count++) {
  +				option_invalid(option,
  +					       "%s\n\tonly one string substitution allowed", value);
   				return 0;
   			}
  +			break;
  +		default:
  +			option_invalid(option,
  +				       "%s\n\tinvalid substitution specified",
  +				       value);
  +			return 0;
   		}
   	}
   
  @@ -252,9 +262,9 @@
   	else if (!strcmp(tmp, "false"))
   		*val = 0;
   	else {
  -		fprintf(stderr, "Option \"%s\" does not contain a valid"
  -			" boolean value,\nchoices are yes/y/true and"
  -			" no/n/false.\n", option->name);
  +		option_invalid(option,
  +			       "%s\n\tvalid choices are yes/y/true or no/n/false.",
  +			       input);
   		status = 0;
   	}
   
  
  
  



More information about the alfs-log mailing list