cvs commit: ALFS/nALFS/src nalfs.c options.c options.h

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Mon Nov 3 20:06:53 PST 2003


kpfleming    03/11/03 21:06:53

  Modified:    nALFS/src nalfs.c options.c options.h
  Log:
  add framework to support post-validating options (validation after all options have been read from both rc files and command line)
  
  Revision  Changes    Path
  1.33      +3 -0      ALFS/nALFS/src/nalfs.c
  
  Index: nalfs.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/nalfs.c,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- nalfs.c	3 Nov 2003 22:12:18 -0000	1.32
  +++ nalfs.c	4 Nov 2003 04:06:53 -0000	1.33
  @@ -4651,6 +4651,9 @@
   
   	read_command_line_options(&argc, &argv);
   
  +	if (!post_validate_options())
  +		return EXIT_FAILURE;
  +
   	init_needed_directories();
   
   
  
  
  
  1.11      +29 -0     ALFS/nALFS/src/options.c
  
  Index: options.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/options.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- options.c	4 Nov 2003 03:45:27 -0000	1.10
  +++ options.c	4 Nov 2003 04:06:53 -0000	1.11
  @@ -321,3 +321,32 @@
   
   	return OPTION_UNKNOWN;
   }
  +
  +/*
  + * Executes all "post-validation" functions for options.
  + */
  +int post_validate_options(void)
  +{
  +	int i;
  +	int all_ok = 1;
  +
  +	for (i = 0; options[i]; i++) {
  +		switch (options[i]->type) {
  +		case O_BOOL:
  +			if (options[i]->val.bool.post_validate)
  +				all_ok &= options[i]->val.bool.post_validate(options[i]);
  +			break;
  +		case O_NUMBER:
  +			if (options[i]->val.num.post_validate)
  +				all_ok &= options[i]->val.num.post_validate(options[i]);
  +			break;
  +		case O_STRING:
  +			if (options[i]->val.str.post_validate)
  +				all_ok &= options[i]->val.str.post_validate(options[i]);
  +			break;
  +		}
  +	}
  +
  +	return all_ok;
  +}
  +
  
  
  
  1.12      +4 -0      ALFS/nALFS/src/options.h
  
  Index: options.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/options.h,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- options.h	4 Nov 2003 03:51:25 -0000	1.11
  +++ options.h	4 Nov 2003 04:06:53 -0000	1.12
  @@ -77,12 +77,14 @@
   			STRING const def_value;
   			int (*validate)(const struct option_s *option,
   					const STRING value);
  +			int (*post_validate)(const struct option_s *option);
   		} str;
   		struct {
   			BOOL value;
   			BOOL const def_value;
   			int (*validate)(const struct option_s *option,
   					const BOOL value);
  +			int (*post_validate)(const struct option_s *option);
   		} bool;
   		struct {
   			NUMBER value;
  @@ -91,6 +93,7 @@
   			NUMBER const max_value;
   			int (*validate)(const struct option_s *option,
   					const NUMBER value);
  +			int (*post_validate)(const struct option_s *option);
   		} num;
   	} val;
   };
  @@ -172,6 +175,7 @@
   void set_string_option(STRING * const var, const STRING value);
   void append_string_option(STRING * const var, const STRING value);
   void set_options_to_defaults(void);
  +int post_validate_options(void);
   
   char *alloc_real_status_logfile_name(void);
   char *alloc_real_packages_directory_name(void);
  
  
  



More information about the alfs-log mailing list