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

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Tue Nov 4 22:05:36 PST 2003


kpfleming    03/11/04 23:05:36

  Modified:    nALFS/src init.c init.h nalfs.c
  Log:
  read /etc/nALFSrc (if it exists) before user's .nALFSrc
  support --rcfile parameter (overrides default rc files)
  minor error messages formatting changes
  
  Revision  Changes    Path
  1.9       +36 -3     ALFS/nALFS/src/init.c
  
  Index: init.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/init.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- init.c	5 Nov 2003 04:22:41 -0000	1.8
  +++ init.c	5 Nov 2003 06:05:36 -0000	1.9
  @@ -237,13 +237,13 @@
   			while ((c = getc(fp)) != EOF && c != '\n')
   				/* Skip in circle. */;
   
  -			Nprint_err("File %s, line %d too long, won't read it.",
  +			Nprint_err("File %s, line %d too long, won't read it.\n",
   				   rcfile, line_num);
   		}
   
   		if (parse_rc_line(line) != 0) {
   			ret = 1;
  -			Nprint_err("File %s, error at line %d: %s",
  +			Nprint_err("File %s, error at line %d: %s\n",
   				   rcfile, line_num, line);
   		}
   	}
  @@ -254,9 +254,24 @@
   }
   
   /*
  + * Read the "system" configuration file, /etc/nALFSrc.
  + */
  +
  +int 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;
  +}
  +
  +/*
    * Constructs a full name of configuration file and calls a parser.
    */
  -int read_rc_file(void)
  +int read_user_rc_file(void)
   {
   	int ret;
   	char *home_dir;
  @@ -299,6 +314,7 @@
   	LONG_OPTION_VERSION,
   	LONG_OPTION_HELP,
   	LONG_OPTION_GENERATE_STAMP,
  +	LONG_OPTION_RCFILE,
   };
   
   
  @@ -352,6 +368,7 @@
   "    -p, --prune <dirs>            Ignore <dirs> (separated with spaces) when\n"
   "                                  logging files.\n"
   "    -S, --generate-stamp          Toggle stamp mode.\n"
  +"    --rcfile <file>               Use <file> as configuration file.\n"
   "    -v, --verbose                 Toggle verbosity (%s).\n"
   "    --version                     Display program's version.\n"
   "    --help                        Display this help.\n"
  @@ -381,6 +398,15 @@
   	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;
  @@ -411,6 +437,8 @@
   
   	{"generate-stamp", no_argument, NULL, LONG_OPTION_GENERATE_STAMP},
   
  +	{"rcfile", required_argument, NULL, LONG_OPTION_RCFILE},
  +
   	{NULL, no_argument, NULL, 0}
   
   	};
  @@ -480,6 +508,11 @@
   			case 'S':
   			case LONG_OPTION_GENERATE_STAMP:
   				Toggle(*opt_stamp_packages);
  +				break;
  +
  +			case LONG_OPTION_RCFILE:
  +				if (parse_rc_file(optarg) != 0)
  +					exit(EXIT_FAILURE);
   				break;
   
   			case LONG_OPTION_HELP:
  
  
  
  1.4       +3 -1      ALFS/nALFS/src/init.h
  
  Index: init.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/init.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- init.h	21 Oct 2003 15:52:44 -0000	1.3
  +++ init.h	5 Nov 2003 06:05:36 -0000	1.4
  @@ -33,8 +33,10 @@
   
   void read_env_variables(void);
   
  -int read_rc_file(void);
  +int read_system_rc_file(void);
  +int 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.35      +5 -3      ALFS/nALFS/src/nalfs.c
  
  Index: nalfs.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/nalfs.c,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- nalfs.c	5 Nov 2003 04:22:41 -0000	1.34
  +++ nalfs.c	5 Nov 2003 06:05:36 -0000	1.35
  @@ -4647,9 +4647,11 @@
   
   	read_env_variables();
   
  -	if (read_rc_file() != 0) {
  -		Nprint_err("Reading RC file failed.\n");
  -		return EXIT_FAILURE;
  +	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_command_line_options(&argc, &argv);
  
  
  



More information about the alfs-log mailing list