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

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Mon Nov 3 14:12:19 PST 2003


kpfleming    03/11/03 15:12:19

  Modified:    nALFS/src init.c nalfs.c options.c options.h
  Log:
  ensure that opt_* pointers to variables within real_opt_ structures are not modified (const)
  add append_string_option function, and use it where set_string_option was special-casing opt_find_prunes
  make opt_find_base/opt_find_prunes editing in nalfs.c use a temporary variable, since string options should only be modified via set/append_string_option
  
  Revision  Changes    Path
  1.5       +1 -1      ALFS/nALFS/src/init.c
  
  Index: init.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/init.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- init.c	3 Nov 2003 21:45:04 -0000	1.4
  +++ init.c	3 Nov 2003 22:12:18 -0000	1.5
  @@ -472,7 +472,7 @@
   				set_string_option(opt_find_base, optarg);
   				break;
   			case 'p':
  -				set_string_option(opt_find_prunes, optarg);
  +				append_string_option(opt_find_prunes, optarg);
   				break;
   
   			case 'v':
  
  
  
  1.32      +11 -3     ALFS/nALFS/src/nalfs.c
  
  Index: nalfs.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/nalfs.c,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- nalfs.c	3 Nov 2003 21:45:04 -0000	1.31
  +++ nalfs.c	3 Nov 2003 22:12:18 -0000	1.32
  @@ -2025,15 +2025,23 @@
   
   static INLINE void change_find_options(void)
   {
  +	char *tmp;
  +
   	if (Backend_exists) {
   		Nprint_warn("Can't change find options while running.");
   		return;
   	}
   
  -	get_string_from_bottom("Root directory:", opt_find_base);
  +	tmp = xstrdup(*opt_find_base);
  +	get_string_from_bottom("Root directory:", &tmp);
  +	set_string_option(opt_find_base, tmp);
  +	xfree(tmp);
   	Nprint("Root directory: %s", *opt_find_base ? *opt_find_base : "/");
   
  -	get_string_from_bottom("Prune directories:", opt_find_prunes);
  +	tmp = xstrdup(*opt_find_prunes);
  +	get_string_from_bottom("Prune directories:", &tmp);
  +	set_string_option(opt_find_prunes, tmp);
  +	xfree(tmp);
   	if (*opt_find_prunes) {
   		Nprint("Prune directories: %s", *opt_find_prunes);
   	} else {
  @@ -4500,7 +4508,7 @@
   		
   		fclose(fp);
   
  -		set_string_option(opt_find_prunes, new_dirs);
  +		append_string_option(opt_find_prunes, new_dirs);
   
   		xfree(new_dirs);
   	}
  
  
  
  1.6       +16 -22    ALFS/nALFS/src/options.c
  
  Index: options.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/options.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- options.c	3 Nov 2003 21:45:04 -0000	1.5
  +++ options.c	3 Nov 2003 22:12:18 -0000	1.6
  @@ -70,37 +70,31 @@
   #include "option-list.h"
   
   
  -void set_string_option(STRING *var, const char *value)
  +void set_string_option(STRING * const var, const char *value)
   {
  -
   	ASSERT(var != NULL);
   	ASSERT(value != NULL);
   
  -	/*
  -	 * Some options need special treatment when they are set.
  -	 */
  -
  -	if (var == opt_find_prunes) {
  -		/* Append the value, instead of overwriting the existing. */
  -
  -		char *new_value = NULL;
  +	xfree(*var);
  +	*var = xstrdup(value);
  +}
   
  -		if (*var && strlen(*var) > 0) {
  -			append_str(&new_value, *var);
  -			append_str(&new_value, " ");
  -		}
  -
  -		append_str(&new_value, value);
  +void append_string_option(STRING * const var, const char *value)
  +{
  +	char *new_value = NULL;
   
  -		xfree(*var);
  +	ASSERT(var != NULL);
  +	ASSERT(value != NULL);
   
  -		*var = new_value;
  +	if (*var && strlen(*var) > 0) {
  +		append_str(&new_value, *var);
  +		append_str(&new_value, " ");
  +	}
   
  -	} else {
  -		xfree(*var);
  +	append_str(&new_value, value);
   
  -		*var = xstrdup(value);
  -	}
  +	xfree(*var);
  +	*var = new_value;
   }
   
   /*
  
  
  
  1.7       +6 -5      ALFS/nALFS/src/options.h
  
  Index: options.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/options.h,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- options.h	3 Nov 2003 21:45:04 -0000	1.6
  +++ options.h	3 Nov 2003 22:12:18 -0000	1.7
  @@ -84,22 +84,22 @@
   
   #ifndef STRING_OPTION
   #define STRING_OPTION(opt_name, opt_def_value) \
  -		extern STRING *opt_##opt_name;
  +		extern STRING * const opt_##opt_name;
   #endif /* STRING_OPTION */
   
   #ifndef BOOL_OPTION
   #define BOOL_OPTION(opt_name, opt_def_value) \
  -		extern BOOL *opt_##opt_name;
  +		extern BOOL * const opt_##opt_name;
   #endif /* BOOL_OPTION */
   
   #ifndef NUMBER_OPTION
   #define NUMBER_OPTION(opt_name, opt_def_value) \
  -		extern NUMBER *opt_##opt_name;
  +		extern NUMBER * const opt_##opt_name;
   #endif /* NUMBER_OPTION */
   
   #ifndef COMMAND_OPTION
   #define COMMAND_OPTION(opt_name, opt_def_value) \
  -		extern const STRING *opt_##opt_name;
  +		extern STRING * const opt_##opt_name;
   #endif /* COMMAND_OPTION */
   
   
  @@ -151,7 +151,8 @@
   COMMAND_OPTION(unzip_command,"unzip %s")
   
   
  -void set_string_option(STRING *var, const STRING value);
  +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);
   
   char *alloc_real_status_logfile_name(void);
  
  
  



More information about the alfs-log mailing list