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

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Thu Nov 6 10:18:11 PST 2003


kpfleming    03/11/06 11:18:11

  Modified:    nALFS/src init.c init.h nalfs.c option-struct.h options.c
  Log:
  begin converting init process functions to new model: don't return errors from functions, or exit the program; instead use Nprint_err to report errors, and nalfs.c/main() will exit the program after all initialization functions have been called if any errors occurred
  
  Revision  Changes    Path
  1.11      +9 -28     ALFS/nALFS/src/init.c
  
  Index: init.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/init.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- init.c	6 Nov 2003 16:57:41 -0000	1.10
  +++ init.c	6 Nov 2003 18:18:11 -0000	1.11
  @@ -208,9 +208,8 @@
   	return -1;
   }
   
  -static INLINE int parse_rc_file(const char *rcfile)
  +static INLINE void parse_rc_file(const char *rcfile)
   {
  -	int ret = 0;
   	int line_num = 0;
   	char line[MAX_RC_LINE_LEN];
   	FILE *fp;
  @@ -225,7 +224,7 @@
   			Nprint_err("Unable to open rc file (%s): %s",
   				   rcfile, strerror(errno));
   		}
  -		return 0; /* Just don't read it then. */
  +		return; /* Just don't read it then. */
   	}
   
   	while (fgets(line, sizeof line, fp)) {
  @@ -242,38 +241,32 @@
   		}
   
   		if (parse_rc_line(line) != 0) {
  -			ret = 1;
   			Nprint_err("File %s, error at line %d: %s\n",
   				   rcfile, line_num, line);
   		}
   	}
   
   	fclose(fp);
  -
  -	return ret;
   }
   
   /*
    * Read the "system" configuration file, /etc/nALFSrc.
    */
   
  -int read_system_rc_file(void)
  +void read_system_rc_file(void)
   {
   	char system_rc_file[] = "/etc/nALFSrc";
   	struct stat st;
   
   	if (!stat(system_rc_file, &st))
  -		return parse_rc_file("/etc/nALFSrc");
  -	else
  -		return 0;
  +		parse_rc_file(system_rc_file);
   }
   
   /*
    * Constructs a full name of configuration file and calls a parser.
    */
  -int read_user_rc_file(void)
  +void read_user_rc_file(void)
   {
  -	int ret;
   	char *home_dir;
   	char *rcfile;
   
  @@ -281,19 +274,17 @@
   	home_dir = get_home_directory();
   
   	if (Empty_string(home_dir)) {
  -		fprintf(stderr, "Can't find your home directory.\n");
  -		exit(EXIT_FAILURE);
  +		Nprint_warn("Can't find your home directory.\n");
  +		return;
   	}
   
   	rcfile = xstrdup(home_dir);
   	append_str(&rcfile, "/");
   	append_str(&rcfile, RC_FILE_NAME);
   
  -	ret = parse_rc_file(rcfile);
  +	parse_rc_file(rcfile);
   
   	xfree(rcfile);
  -
  -	return ret;
   }
   
   /*
  @@ -398,15 +389,6 @@
   	exit(EXIT_FAILURE);
   }
   
  -int have_command_line_rc_file(int argc, char **argv)
  -{
  -	while(--argc) {
  -		if (strcmp(argv[argc], "--rcfile") == 0)
  -			return 1;
  -	}
  -	return 0;
  -}
  -
   void read_command_line_options(int *argc, char ***argv)
   {
   	int i;
  @@ -511,8 +493,7 @@
   				break;
   
   			case LONG_OPTION_RCFILE:
  -				if (parse_rc_file(optarg) != 0)
  -					exit(EXIT_FAILURE);
  +				parse_rc_file(optarg);
   				break;
   
   			case LONG_OPTION_HELP:
  
  
  
  1.5       +2 -3      ALFS/nALFS/src/init.h
  
  Index: init.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/init.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- init.h	5 Nov 2003 06:05:36 -0000	1.4
  +++ init.h	6 Nov 2003 18:18:11 -0000	1.5
  @@ -33,10 +33,9 @@
   
   void read_env_variables(void);
   
  -int read_system_rc_file(void);
  -int read_user_rc_file(void);
  +void read_system_rc_file(void);
  +void read_user_rc_file(void);
   
  -int have_command_line_rc_file(int argc, char **argv);
   void read_command_line_options(int *argc, char ***argv);
   
   void init_needed_directories(void);
  
  
  
  1.38      +6 -7      ALFS/nALFS/src/nalfs.c
  
  Index: nalfs.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/nalfs.c,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- nalfs.c	6 Nov 2003 16:57:41 -0000	1.37
  +++ nalfs.c	6 Nov 2003 18:18:11 -0000	1.38
  @@ -4677,16 +4677,15 @@
   
   	read_env_variables();
   
  -	if (!have_command_line_rc_file(argc, argv)) {
  -		if (read_system_rc_file() != 0)
  -			return EXIT_FAILURE;
  -		if (read_user_rc_file() != 0)
  -			return EXIT_FAILURE;
  -	}
  +	read_system_rc_file();
  +
  +	read_user_rc_file();
   
   	read_command_line_options(&argc, &argv);
   
  -	if (!post_validate_options())
  +	post_validate_options();
  +
  +	if (init_errors)
   		return EXIT_FAILURE;
   
   	nprint = nprint_text;
  
  
  
  1.2       +4 -4      ALFS/nALFS/src/option-struct.h
  
  Index: option-struct.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/option-struct.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- option-struct.h	6 Nov 2003 06:22:48 -0000	1.1
  +++ option-struct.h	6 Nov 2003 18:18:11 -0000	1.2
  @@ -77,14 +77,14 @@
   			STRING const def_value;
   			int (*validate)(const struct option_s *option,
   					const STRING value);
  -			int (*post_validate)(const struct option_s *option);
  +			void (*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);
  +			void (*post_validate)(const struct option_s *option);
   		} bool;
   		struct {
   			NUMBER value;
  @@ -93,7 +93,7 @@
   			NUMBER const max_value;
   			int (*validate)(const struct option_s *option,
   					const NUMBER value);
  -			int (*post_validate)(const struct option_s *option);
  +			void (*post_validate)(const struct option_s *option);
   		} num;
   	} val;
   };
  @@ -116,7 +116,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);
  +void post_validate_options(void);
   
   char *alloc_real_status_logfile_name(void);
   char *alloc_real_packages_directory_name(void);
  
  
  
  1.21      +4 -7      ALFS/nALFS/src/options.c
  
  Index: options.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/options.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- options.c	6 Nov 2003 16:57:41 -0000	1.20
  +++ options.c	6 Nov 2003 18:18:11 -0000	1.21
  @@ -372,28 +372,25 @@
   /*
    * Executes all "post-validation" functions for options.
    */
  -int post_validate_options(void)
  +void 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]);
  +				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]);
  +				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]);
  +				options[i]->val.str.post_validate(options[i]);
   			break;
   		}
   	}
  -
  -	return all_ok;
   }
   
  
  
  



More information about the alfs-log mailing list