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

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Tue Nov 4 10:48:49 PST 2003


kpfleming    03/11/04 11:48:49

  Modified:    nALFS    bootstrap
               nALFS/src options.c options.h
  Added:       nALFS    bootstrap.option-array
               nALFS/src option_struct.h
  Removed:     nALFS    bootstrap.option-list
  Log:
  rename src/option-list.h to src/option-array.h to better reflect its purpose
  split src/options.h into two pieces so that src/options.c can include them separately and provide macro definitions and prototypes for validation functions
  
  Revision  Changes    Path
  1.15      +1 -1      ALFS/nALFS/bootstrap
  
  Index: bootstrap
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/bootstrap,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- bootstrap	3 Nov 2003 21:45:03 -0000	1.14
  +++ bootstrap	4 Nov 2003 18:48:48 -0000	1.15
  @@ -34,7 +34,7 @@
   done
   all_syntaxes=`echo ${all_syntaxes} | ${SP2NL} | sort -u`
   
  -. ./bootstrap.option-list > src/option-list.h
  +. ./bootstrap.option-array > src/option-array.h
   
   . ./bootstrap.Makefile > Makefile.am
   
  
  
  
  1.1                  ALFS/nALFS/bootstrap.option-array
  
  Index: bootstrap.option-array
  ===================================================================
  #!/bin/bash
  
  cat <<"EOF"
  /*
   *  option-list.h - Program's options.
   *
   *  Copyright (C) 2003
   *
   *  Neven Has <haski at sezampro.yu>
   *  Kevin P. Fleming <kpfleming at linuxfromscratch.org>
   *
   *  This program is free software; you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation; either version 2 of the License, or
   *  (at your option) any later version.
   *
   *  This program is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details.
   *
   *  You should have received a copy of the GNU General Public License
   *  along with this program; if not, write to the Free Software
   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
  
  static struct option_s *options[] = {
  EOF
  
  grep -e "^STRING_OPTION" src/options.h | sed "s/STRING_OPTION(/\&real_opt_/" | sed "s/,.*$/,/"
  grep -e "^BOOL_OPTION" src/options.h | sed "s/BOOL_OPTION(/\&real_opt_/" | sed "s/,.*$/,/"
  grep -e "^NUMBER_OPTION" src/options.h | sed "s/NUMBER_OPTION(/\&real_opt_/" | sed "s/,.*$/,/"
  
  cat <<"EOF"
  NULL
  };
  EOF
  
  
  
  1.14      +5 -1      ALFS/nALFS/src/options.c
  
  Index: options.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/options.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- options.c	4 Nov 2003 17:06:18 -0000	1.13
  +++ options.c	4 Nov 2003 18:48:48 -0000	1.14
  @@ -62,9 +62,13 @@
   		}; \
   		NUMBER * const opt_##opt_name = &real_opt_##opt_name .val.num.value
   
  +#include "option_struct.h"
  +
  +static int validate_command(const struct option_s *option, const STRING value);
  +static int validate_number_minmax(const struct option_s *option, const NUMBER value);
   
   #include "options.h"
  -#include "option-list.h"
  +#include "option-array.h"
   
   
   void set_string_option(STRING * const var, const char *value)
  
  
  
  1.13      +2 -114    ALFS/nALFS/src/options.h
  
  Index: options.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/options.h,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- options.h	4 Nov 2003 04:06:53 -0000	1.12
  +++ options.h	4 Nov 2003 18:48:48 -0000	1.13
  @@ -22,102 +22,12 @@
    */
   
   
  +#include "option_struct.h"
  +
   #ifndef H_OPTIONS_
   #define H_OPTIONS_
   
   
  -/*
  - * Types of some options.
  - */
  -
  -typedef enum timer_type {
  -	TIMER_NONE = 0,
  -	TIMER_TOTAL,
  -	TIMER_CURRENT
  -} timer_type_t;
  -
  -typedef enum jump_location {
  -	JUMP_TO_FAILED = 0,
  -	JUMP_TO_RUNNING,
  -	JUMP_TO_DONE,
  -	JUMP_TO_PACKAGE
  -} jump_location_t;
  -
  -/* We're looping through this enum (toggling) - 0 markes the first value. */
  -typedef enum logging_method {
  -	LOG_OFF = 0,
  -	LOG_USING_ONE_FIND,
  -} logging_method_t;
  -
  -#define LAST_LOGGING_METHOD LOG_USING_ONE_FIND
  -
  -
  -/*
  - * Options themselves.
  - */
  -
  -#define BOOL 	int
  -#define NUMBER 	int
  -#define STRING 	char *
  -
  -enum option_type {
  -	O_BOOL,
  -	O_NUMBER,
  -	O_STRING
  -};
  -
  -struct option_s {
  -	char *name;
  -
  -	enum option_type type;
  -
  -	union {
  -		struct {
  -			STRING value;
  -			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;
  -			NUMBER const def_value;
  -			NUMBER const min_value;
  -			NUMBER const max_value;
  -			int (*validate)(const struct option_s *option,
  -					const NUMBER value);
  -			int (*post_validate)(const struct option_s *option);
  -		} num;
  -	} val;
  -};
  -
  -#ifndef STRING_OPTION
  -#define STRING_OPTION(opt_name, opt_def_value, opt_other...) \
  -		extern STRING * const opt_##opt_name
  -#endif /* STRING_OPTION */
  -
  -#ifndef BOOL_OPTION
  -#define BOOL_OPTION(opt_name, opt_def_value, opt_other...) \
  -		extern BOOL * const opt_##opt_name
  -#endif /* BOOL_OPTION */
  -
  -#ifndef NUMBER_OPTION
  -#define NUMBER_OPTION(opt_name, opt_def_value, opt_other...) \
  -		extern NUMBER * const opt_##opt_name
  -#endif /* NUMBER_OPTION */
  -
  -
  -static int validate_command(const struct option_s *option, const STRING value);
  -static int validate_number_minmax(const struct option_s *option, const NUMBER value);
  -
  -
   STRING_OPTION(alfs_directory, "");
   BOOL_OPTION(start_immediately, 0);
   STRING_OPTION(packages_directory, "packages");
  @@ -170,28 +80,6 @@
   STRING_OPTION(unpax_command, "pax -rv", validate_command);
   STRING_OPTION(uncpio_command, "cpio -idv", validate_command);
   STRING_OPTION(unzip_command, "unzip %s", validate_command);
  -
  -
  -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);
  -char *alloc_real_stamp_directory_name(void);
  -
  -/*
  - * Setting option from RC file parser.
  - */
  -
  -typedef enum set_opt_e {
  -	OPTION_SET,
  -	OPTION_UNKNOWN,
  -	OPTION_INVALID_VALUE
  -} set_opt_e;
  -
  -set_opt_e set_yet_unknown_option(const char *opt, const char *val);
   
   
   #endif /* H_OPTIONS_ */
  
  
  
  1.1                  ALFS/nALFS/src/option_struct.h
  
  Index: option_struct.h
  ===================================================================
  /*
   *  option_struct.h - Structures and enums used to process program options.
   *
   *  Copyright (C) 2002
   *
   *  Neven Has <haski at sezampro.yu>
   *  Kevin P. Fleming <kpfleming at linuxfromscratch.org>
   *
   *  This program is free software; you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation; either version 2 of the License, or
   *  (at your option) any later version.
   *
   *  This program is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details.
   *
   *  You should have received a copy of the GNU General Public License
   *  along with this program; if not, write to the Free Software
   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
  
  
  #ifndef H_OPTION_STRUCT_
  #define H_OPTION_STRUCT_
  
  
  /*
   * Types of some options.
   */
  
  typedef enum timer_type {
  	TIMER_NONE = 0,
  	TIMER_TOTAL,
  	TIMER_CURRENT
  } timer_type_t;
  
  typedef enum jump_location {
  	JUMP_TO_FAILED = 0,
  	JUMP_TO_RUNNING,
  	JUMP_TO_DONE,
  	JUMP_TO_PACKAGE
  } jump_location_t;
  
  /* We're looping through this enum (toggling) - 0 markes the first value. */
  typedef enum logging_method {
  	LOG_OFF = 0,
  	LOG_USING_ONE_FIND,
  } logging_method_t;
  
  #define LAST_LOGGING_METHOD LOG_USING_ONE_FIND
  
  
  /*
   * Options themselves.
   */
  
  #define BOOL 	int
  #define NUMBER 	int
  #define STRING 	char *
  
  enum option_type {
  	O_BOOL,
  	O_NUMBER,
  	O_STRING
  };
  
  struct option_s {
  	char *name;
  
  	enum option_type type;
  
  	union {
  		struct {
  			STRING value;
  			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;
  			NUMBER const def_value;
  			NUMBER const min_value;
  			NUMBER const max_value;
  			int (*validate)(const struct option_s *option,
  					const NUMBER value);
  			int (*post_validate)(const struct option_s *option);
  		} num;
  	} val;
  };
  
  #ifndef STRING_OPTION
  #define STRING_OPTION(opt_name, opt_def_value, opt_other...) \
  		extern STRING * const opt_##opt_name
  #endif /* STRING_OPTION */
  
  #ifndef BOOL_OPTION
  #define BOOL_OPTION(opt_name, opt_def_value, opt_other...) \
  		extern BOOL * const opt_##opt_name
  #endif /* BOOL_OPTION */
  
  #ifndef NUMBER_OPTION
  #define NUMBER_OPTION(opt_name, opt_def_value, opt_other...) \
  		extern NUMBER * const opt_##opt_name
  #endif /* NUMBER_OPTION */
  
  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);
  char *alloc_real_stamp_directory_name(void);
  
  /*
   * Setting option from RC file parser.
   */
  
  typedef enum set_opt_e {
  	OPTION_SET,
  	OPTION_UNKNOWN,
  	OPTION_INVALID_VALUE
  } set_opt_e;
  
  set_opt_e set_yet_unknown_option(const char *opt, const char *val);
  
  
  #endif /* H_OPTION_STRUCT_ */
  
  
  



More information about the alfs-log mailing list