masqmail

changeset 394:c8e3d1a79313

Refactoring in conf.c: read_rval().
author markus schnalke <meillo@marmaro.de>
date Sat, 18 Feb 2012 19:32:40 +0100
parents 5e728dd64c1b
children 5f0829f8e6c7
files src/conf.c
diffstat 1 files changed, 32 insertions(+), 38 deletions(-) [+]
line diff
     1.1 --- a/src/conf.c	Sat Feb 18 18:48:19 2012 +0100
     1.2 +++ b/src/conf.c	Sat Feb 18 19:32:40 2012 +0100
     1.3 @@ -256,22 +256,6 @@
     1.4  	return FALSE;
     1.5  }
     1.6  
     1.7 -/*
     1.8 -** after parsing, eat trailing characters until and including the Newline
     1.9 -*/
    1.10 -static gboolean
    1.11 -eat_line_trailing(FILE *in)
    1.12 -{
    1.13 -	gint c;
    1.14 -
    1.15 -	while ((c = fgetc(in)) != EOF) {
    1.16 -		if (c == '\n') {
    1.17 -			return TRUE;
    1.18 -		}
    1.19 -	}
    1.20 -	return FALSE;
    1.21 -}
    1.22 -
    1.23  static gboolean
    1.24  eat_spaces(FILE *in)
    1.25  {
    1.26 @@ -332,38 +316,48 @@
    1.27  	}
    1.28  
    1.29  	c = fgetc(in);
    1.30 -	if (c != '\"') {
    1.31 -		while ((isalnum(c) || c == '_' || c == '-' || c == '.'
    1.32 -		        || c == '/' || c == '@' || c == ';' || c == ':')
    1.33 -		       && (ptr < buf + size - 1)
    1.34 -		       && (c != EOF)) {
    1.35 -			*ptr = c;
    1.36 -			ptr++;
    1.37 -			c = fgetc(in);
    1.38 +	if (c != '"') {
    1.39 +		/* unquoted rval */
    1.40 +		ungetc(c, in);
    1.41 +		while ((c = fgetc(in)) != EOF) {
    1.42 +			if (ptr >= buf+size-1) {
    1.43 +				/* rval too long */
    1.44 +				break;
    1.45 +			}
    1.46 +			if (!isalnum(c) && c != '_' && c != '-' &&
    1.47 +					c != '.' && c != '/' && c != '@' &&
    1.48 +					c != ';' && c != ':') {
    1.49 +				break;
    1.50 +			}
    1.51 +			*ptr++ = c;
    1.52  		}
    1.53  		*ptr = '\0';
    1.54  		ungetc(c, in);
    1.55  	} else {
    1.56 +		/* quoted rval */
    1.57  		gboolean escape = FALSE;
    1.58 -		c = fgetc(in);
    1.59 -		while (((c != '\"') || escape) && (ptr < buf + size - 1)) {
    1.60 -			if (c != '\n') {  /* ignore line breaks */
    1.61 -				if ((c == '\\') && (!escape)) {
    1.62 -					escape = TRUE;
    1.63 -				} else {
    1.64 -					*ptr = c;
    1.65 -					ptr++;
    1.66 -					escape = FALSE;
    1.67 -				}
    1.68 +		while ((c = fgetc(in)) != EOF) {
    1.69 +			if (ptr >= buf+size-1) {
    1.70 +				/* rval too long */
    1.71 +				break;
    1.72  			}
    1.73 -			c = fgetc(in);
    1.74 +			if (!escape && c == '"') {
    1.75 +				break;
    1.76 +			}
    1.77 +			if (!escape && c == '\\') {
    1.78 +				escape = TRUE;
    1.79 +				continue;
    1.80 +			}
    1.81 +			*ptr++ = c;
    1.82 +			escape = FALSE;
    1.83  		}
    1.84  		*ptr = '\0';
    1.85  	}
    1.86 -
    1.87 -	eat_line_trailing(in);
    1.88 -
    1.89  	DEBUG(9) fprintf(stderr, "rval = %s\n", buf);
    1.90 +	/* eat trailing of line */
    1.91 +	while ((c = fgetc(in)) != EOF && c != '\n') {
    1.92 +		continue;
    1.93 +	}
    1.94  
    1.95  	return TRUE;
    1.96  }