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

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Mon Nov 3 18:35:02 PST 2003


kpfleming    03/11/03 19:35:02

  Modified:    nALFS/src options.c options.h
  Log:
  restructure option structure again, to prepare for supporting per-option validation functions
  
  Revision  Changes    Path
  1.8       +18 -18    ALFS/nALFS/src/options.c
  
  Index: options.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/options.c,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- options.c	3 Nov 2003 23:20:11 -0000	1.7
  +++ options.c	4 Nov 2003 02:35:02 -0000	1.8
  @@ -41,30 +41,30 @@
   		static struct option_s real_opt_##opt_name = { \
   			.name = #opt_name, \
   			.type = O_STRING, \
  -			.def_value.str_value = opt_def_value \
  +			.val.str = { .def_value = opt_def_value } \
   		}; \
  -		STRING * const opt_##opt_name = &real_opt_##opt_name .value.str_value;
  +		STRING * const opt_##opt_name = &real_opt_##opt_name .val.str.value;
   #define BOOL_OPTION(opt_name, opt_def_value) \
   		static struct option_s real_opt_##opt_name = { \
   			.name = #opt_name, \
   			.type = O_BOOL, \
  -			.def_value.bool_value = opt_def_value \
  +			.val.bool = { .def_value = opt_def_value } \
   		}; \
  -		BOOL * const opt_##opt_name = &real_opt_##opt_name .value.bool_value;
  +		BOOL * const opt_##opt_name = &real_opt_##opt_name .val.bool.value;
   #define NUMBER_OPTION(opt_name, opt_def_value) \
   		static struct option_s real_opt_##opt_name = { \
   			.name = #opt_name, \
   			.type = O_NUMBER, \
  -			.def_value.num_value = opt_def_value \
  +			.val.num = { .def_value= opt_def_value } \
   		}; \
  -		NUMBER * const opt_##opt_name = &real_opt_##opt_name .value.num_value;
  +		NUMBER * const opt_##opt_name = &real_opt_##opt_name .val.num.value;
   #define COMMAND_OPTION(opt_name, opt_def_value) \
   		static struct option_s real_opt_##opt_name = { \
   			.name = #opt_name, \
   			.type = O_COMMAND, \
  -			.def_value.str_value = opt_def_value \
  +			.val.str = { .def_value = opt_def_value } \
   		}; \
  -		STRING * const opt_##opt_name = &real_opt_##opt_name .value.str_value;
  +		STRING * const opt_##opt_name = &real_opt_##opt_name .val.str.value;
   
   #include "options.h"
   #include "option-list.h"
  @@ -104,18 +104,18 @@
   {
   	switch (option->type) {
   	case O_BOOL:
  -		option->value.bool_value = option->def_value.bool_value;
  +		option->val.bool.value = option->val.bool.def_value;
   		break;
   		
   	case O_NUMBER:
  -		option->value.num_value = option->def_value.num_value;
  +		option->val.num.value = option->val.num.def_value;
   		break;
   		
   	case O_STRING:
   	case O_COMMAND:
  -		if (option->value.str_value)
  -			xfree(option->value.str_value);
  -		option->value.str_value = xstrdup(option->def_value.str_value);
  +		if (option->val.str.value)
  +			xfree(option->val.str.value);
  +		option->val.str.value = xstrdup(option->val.str.def_value);
   		break;
   	}
   }
  @@ -240,11 +240,11 @@
   		switch (options[i]->type) {
   			case O_BOOL:
   				if (strcmp(val, BOOL_TRUE_VALUE) == 0) {
  -					options[i]->value.bool_value = 1;
  +					options[i]->val.bool.value = 1;
   					return OPTION_SET;
   
   				} else if (strcmp(val, BOOL_FALSE_VALUE) == 0) {
  -					options[i]->value.bool_value = 0;
  +					options[i]->val.bool.value = 0;
   					return OPTION_SET;
   				}
   
  @@ -259,12 +259,12 @@
   				if (not_correct_number(options[i], num))
   					return OPTION_INVALID_VALUE;
   
  -				options[i]->value.num_value = num;
  +				options[i]->val.num.value = num;
   
   				return OPTION_SET;
   
   			case O_STRING:
  -				set_string_option(&options[i]->value.str_value, val);
  +				set_string_option(&options[i]->val.str.value, val);
   
   				return OPTION_SET;
   
  @@ -272,7 +272,7 @@
   				if (not_valid_command(val))
   					return OPTION_INVALID_VALUE;
   
  -				set_string_option(&options[i]->value.str_value, val);
  +				set_string_option(&options[i]->val.str.value, val);
   
   				return OPTION_SET;
   		}
  
  
  
  1.8       +17 -8     ALFS/nALFS/src/options.h
  
  Index: options.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/options.h,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- options.h	3 Nov 2003 22:12:18 -0000	1.7
  +++ options.h	4 Nov 2003 02:35:02 -0000	1.8
  @@ -60,12 +60,6 @@
   #define NUMBER 	int
   #define STRING 	char *
   
  -union option_value {
  -	STRING str_value;
  -	BOOL bool_value;
  -	NUMBER num_value;
  -};
  -
   enum option_type {
   	O_BOOL,
   	O_NUMBER,
  @@ -78,8 +72,23 @@
   
   	enum option_type type;
   
  -	union option_value value;
  -	union option_value def_value;
  +	union {
  +		struct {
  +			STRING value;
  +			STRING const def_value;
  +			int (*validate)(STRING value);
  +		} str;
  +		struct {
  +			BOOL value;
  +			BOOL const def_value;
  +			int (*validate)(BOOL value);
  +		} bool;
  +		struct {
  +			NUMBER value;
  +			NUMBER const def_value;
  +			int (*validate)(NUMBER value);
  +		} num;
  +	} val;
   };
   
   #ifndef STRING_OPTION
  
  
  



More information about the alfs-log mailing list