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

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Tue Nov 4 20:22:41 PST 2003


kpfleming    03/11/04 21:22:41

  Modified:    nALFS/src bufsize.h init.c nalfs.c options.c
  Log:
  modify nprint_text to support sending output to stderr when message type is T_ERR (was a TODO)
  modify init.c to use Nprint_err for some messages instead of direct fprintf
  modify option_invalid to use Nprint_err instead of direct fprintf
  add MAX_ERROR_MSG_LEN constant to bufsize.h for option_invalid to use when formatting error message from validation function
  set errno=0 before calling strtol() in validate_number_input
  
  Revision  Changes    Path
  1.2       +1 -0      ALFS/nALFS/src/bufsize.h
  
  Index: bufsize.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/bufsize.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- bufsize.h	21 Oct 2003 15:52:44 -0000	1.1
  +++ bufsize.h	5 Nov 2003 04:22:41 -0000	1.2
  @@ -27,6 +27,7 @@
   /*
    * Maximum lengths of some strings.
    */
  +#define MAX_ERROR_MSG_LEN		1024
   #define MAX_DATA_MSG_LEN		1024
   #define MAX_CTRL_MSG_LEN		1024
   #define MAX_COMMAND_LEN			1024
  
  
  
  1.8       +11 -14    ALFS/nALFS/src/init.c
  
  Index: init.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/init.c,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- init.c	5 Nov 2003 03:30:20 -0000	1.7
  +++ init.c	5 Nov 2003 04:22:41 -0000	1.8
  @@ -39,6 +39,7 @@
   #include "options.h"
   #include "utility.h"
   #include "logging.h"
  +#include "win.h"
   
   #include "init.h"
   
  @@ -113,7 +114,7 @@
   			break;
   
   		case OPTION_UNKNOWN:
  -			fprintf(stderr, "Option \"%s\" is unknown.\n", opt);
  +			Nprint_err("Option \"%s\" is unknown.\n", opt);
   			ret = -1;
   			break;
   
  @@ -202,7 +203,7 @@
   		return handle_set_line(opt, val);
   	}
   
  -	fprintf(stderr, "Unknown command (%s).\n", command);
  +	Nprint_err("Unknown command (%s).\n", command);
   
   	return -1;
   }
  @@ -218,14 +219,11 @@
   	/* Open it. */
   	if ((fp = fopen(rcfile, "r")) == NULL) {
   		if (errno == ENOENT) {
  -			fprintf(stderr,
  -				"No configuration file to read (%s).\n",
  -				rcfile);
  +			Nprint_err("No configuration file to read (%s).",
  +				   rcfile);
   		} else {
  -			fprintf(stderr,
  -				"Unable to open rc file (%s): %s\n",
  -				rcfile,
  -				strerror(errno));
  +			Nprint_err("Unable to open rc file (%s): %s",
  +				   rcfile, strerror(errno));
   		}
   		return 0; /* Just don't read it then. */
   	}
  @@ -239,15 +237,14 @@
   			while ((c = getc(fp)) != EOF && c != '\n')
   				/* Skip in circle. */;
   
  -			fprintf(stderr, "File %s:\nLine %d too long, won't read it.\n",
  -				rcfile, line_num);
  +			Nprint_err("File %s, line %d too long, won't read it.",
  +				   rcfile, line_num);
   		}
   
   		if (parse_rc_line(line) != 0) {
   			ret = 1;
  -			fprintf(stderr, 
  -				"File %s:\nError at line %d: %s\n",
  -				rcfile, line_num, line);
  +			Nprint_err("File %s, error at line %d: %s",
  +				   rcfile, line_num, line);
   		}
   	}
   
  
  
  
  1.34      +8 -5      ALFS/nALFS/src/nalfs.c
  
  Index: nalfs.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/nalfs.c,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- nalfs.c	4 Nov 2003 04:06:53 -0000	1.33
  +++ nalfs.c	5 Nov 2003 04:22:41 -0000	1.34
  @@ -4581,11 +4581,11 @@
   	xfree(file);
   }
   
  -/* TODO: Check for T_ERR and print those messages to stderr. */
   static void nprint_text(msg_id_e mid, const char *format,...)
   {
   	char *file = alloc_real_status_logfile_name();
   	FILE *fp = NULL;
  +	FILE *console = stdout;
   	va_list ap;
           va_list ap2;
   
  @@ -4599,16 +4599,19 @@
   	va_start(ap, format);
           __va_copy(ap2, ap);
   
  +	if (mid == T_ERR)
  +		console = stderr;
  +
   	if (mid != T_RAW) {
  -		printf("\n%c: ", msg_character(mid));
  +		fprintf(console, "\n%c: ", msg_character(mid));
   
   		if (*opt_log_status_window && fp) {
   			fprintf(fp, "\n%c: ", msg_character(mid));
   		}
   	}
   
  -	vprintf(format, ap);
  -	fflush(stdout);
  +	vfprintf(console, format, ap);
  +	fflush(console);
   
   	if (*opt_log_status_window && fp) {
   		vfprintf(fp, format, ap2);
  @@ -4645,7 +4648,7 @@
   	read_env_variables();
   
   	if (read_rc_file() != 0) {
  -		fprintf(stderr, "Reading RC file failed.\n");
  +		Nprint_err("Reading RC file failed.\n");
   		return EXIT_FAILURE;
   	}
   
  
  
  
  1.16      +8 -4      ALFS/nALFS/src/options.c
  
  Index: options.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/options.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- options.c	5 Nov 2003 03:21:58 -0000	1.15
  +++ options.c	5 Nov 2003 04:22:41 -0000	1.16
  @@ -25,6 +25,7 @@
   #include <string.h>
   #include <stdlib.h>
   #include <errno.h>
  +#include <stdarg.h>
   
   #ifdef HAVE_CONFIG_H
   #include <config.h>
  @@ -34,6 +35,8 @@
   #include "nalfs-core.h"
   #include "logging.h"
   #include "utility.h"
  +#include "win.h"
  +#include "bufsize.h"
   
   /* These macro definitions will cause the options in options.h to actually
      be allocated storage in this module.
  @@ -187,13 +190,13 @@
   			   const char *format, ...)
   {
   	va_list ap;
  +	char buffer[MAX_ERROR_MSG_LEN];
   
   	va_start(ap, format);
  -	fprintf(stderr, "Option \"%s\" has an invalid value: ",
  -		option->name);
  -	vfprintf(stderr, format, ap);
  -	fprintf(stderr, "\n");
  +	vsnprintf(buffer, sizeof buffer, format, ap);
   	va_end(ap);
  +	Nprint_err("Option \"%s\" invalid value: %s",
  +		   option->name, buffer);
   }
   
   static int validate_number_minmax(const struct option_s *option,
  @@ -284,6 +287,7 @@
   	char *tmp;
   	int status = 1;
   
  +	errno = 0;
   	*val = (NUMBER) strtol(input, &tmp, 10);
   			
   	if (tmp != NULL && *tmp) {
  
  
  



More information about the alfs-log mailing list