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

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Sun Nov 2 17:25:34 PST 2003


kpfleming    03/11/02 18:25:34

  Modified:    nALFS/src options.c options.h
  Log:
  do some limited parsing of "command string" options: allow only %% and %s patterns, and only allow a single %s pattern
  
  Revision  Changes    Path
  1.4       +42 -7     ALFS/nALFS/src/options.c
  
  Index: options.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/options.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- options.c	31 Oct 2003 01:47:58 -0000	1.3
  +++ options.c	3 Nov 2003 01:25:34 -0000	1.4
  @@ -193,31 +193,31 @@
   		(option_pointer *)& opt_editor,
   		(option_pointer *)& ""
   	},{
  -		"gunzip_command", O_STRING,
  +		"gunzip_command", O_COMMAND,
   		(option_pointer *)& opt_gunzip_command,
   		(option_pointer *)& "zcat %s"
   	},{
  -		"uncompress_command", O_STRING,
  +		"uncompress_command", O_COMMAND,
   		(option_pointer *)& opt_uncompress_command,
   		(option_pointer *)& "zcat %s"
   	},{
  -		"bunzip2_command", O_STRING,
  +		"bunzip2_command", O_COMMAND,
   		(option_pointer *)& opt_bunzip2_command,
   		(option_pointer *)& "bunzip2 -dc %s"
   	},{
  -		"untar_command", O_STRING,
  +		"untar_command", O_COMMAND,
   		(option_pointer *)& opt_untar_command,
   		(option_pointer *)& "tar xv"
   	},{
  -		"unpax_command", O_STRING,
  +		"unpax_command", O_COMMAND,
   		(option_pointer *)& opt_unpax_command,
   		(option_pointer *)& "pax -rv"
   	},{
  -		"uncpio_command", O_STRING,
  +		"uncpio_command", O_COMMAND,
   		(option_pointer *)& opt_uncpio_command,
   		(option_pointer *)& "cpio -idv"
   	},{
  -		"unzip_command", O_STRING,
  +		"unzip_command", O_COMMAND,
   		(option_pointer *)& opt_unzip_command,
   		(option_pointer *)& "unzip %s"
   	},{
  @@ -293,6 +293,7 @@
   				break;
   
   			case O_STRING:
  +			case O_COMMAND:
   				set_string_option(i, string);
   				break;
   		}
  @@ -311,6 +312,7 @@
   			break;
   
   		case O_STRING:
  +		case O_COMMAND:
   			set_string_option(idx, (char *)value);
   			break;
   	}
  @@ -412,6 +414,29 @@
   	return 0;
   }
   
  +static int not_valid_command(const char *command)
  +{
  +	const char *tmp;
  +	int string_count = 0;
  +
  +	for (tmp = command; *tmp; ++tmp) {
  +		if (*tmp == '%') {
  +			switch (*(++tmp)) {
  +			case '%':
  +				break;
  +			case 's':
  +				if (string_count++)
  +					return 1;
  +				break;
  +			default:
  +				return 1;
  +			}
  +		}
  +	}
  +
  +	return 0;
  +}
  +
   set_opt_e set_yet_unknown_option(const char *opt, const char *val)
   {
   	int i;
  @@ -453,6 +478,16 @@
   				return OPTION_SET;
   
   			case O_STRING:
  +				set_string_option(i, val);
  +
  +				return OPTION_SET;
  +
  +			case O_COMMAND:
  +
  +				if (not_valid_command(val)) {
  +					return OPTION_INVALID_VALUE;
  +				}
  +
   				set_string_option(i, val);
   
   				return OPTION_SET;
  
  
  
  1.5       +2 -1      ALFS/nALFS/src/options.h
  
  Index: options.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/options.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- options.h	31 Oct 2003 01:47:58 -0000	1.4
  +++ options.h	3 Nov 2003 01:25:34 -0000	1.5
  @@ -60,7 +60,8 @@
   enum option_type {
   	O_BOOL,
   	O_NUMBER,
  -	O_STRING
  +	O_STRING,
  +	O_COMMAND
   };
   
   typedef struct option_s {
  
  
  



More information about the alfs-log mailing list