changeset 394:c8e3d1a79313

Refactoring in conf.c: read_rval().
author markus schnalke <meillo@marmaro.de>
date Sat, 18 Feb 2012 19:32:40 +0100 (2012-02-18)
parents 5e728dd64c1b
children 5f0829f8e6c7
files src/conf.c
diffstat 1 files changed, 32 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/src/conf.c	Sat Feb 18 18:48:19 2012 +0100
+++ b/src/conf.c	Sat Feb 18 19:32:40 2012 +0100
@@ -256,22 +256,6 @@
 	return FALSE;
 }
 
-/*
-** after parsing, eat trailing characters until and including the Newline
-*/
-static gboolean
-eat_line_trailing(FILE *in)
-{
-	gint c;
-
-	while ((c = fgetc(in)) != EOF) {
-		if (c == '\n') {
-			return TRUE;
-		}
-	}
-	return FALSE;
-}
-
 static gboolean
 eat_spaces(FILE *in)
 {
@@ -332,38 +316,48 @@
 	}
 
 	c = fgetc(in);
-	if (c != '\"') {
-		while ((isalnum(c) || c == '_' || c == '-' || c == '.'
-		        || c == '/' || c == '@' || c == ';' || c == ':')
-		       && (ptr < buf + size - 1)
-		       && (c != EOF)) {
-			*ptr = c;
-			ptr++;
-			c = fgetc(in);
+	if (c != '"') {
+		/* unquoted rval */
+		ungetc(c, in);
+		while ((c = fgetc(in)) != EOF) {
+			if (ptr >= buf+size-1) {
+				/* rval too long */
+				break;
+			}
+			if (!isalnum(c) && c != '_' && c != '-' &&
+					c != '.' && c != '/' && c != '@' &&
+					c != ';' && c != ':') {
+				break;
+			}
+			*ptr++ = c;
 		}
 		*ptr = '\0';
 		ungetc(c, in);
 	} else {
+		/* quoted rval */
 		gboolean escape = FALSE;
-		c = fgetc(in);
-		while (((c != '\"') || escape) && (ptr < buf + size - 1)) {
-			if (c != '\n') {  /* ignore line breaks */
-				if ((c == '\\') && (!escape)) {
-					escape = TRUE;
-				} else {
-					*ptr = c;
-					ptr++;
-					escape = FALSE;
-				}
+		while ((c = fgetc(in)) != EOF) {
+			if (ptr >= buf+size-1) {
+				/* rval too long */
+				break;
 			}
-			c = fgetc(in);
+			if (!escape && c == '"') {
+				break;
+			}
+			if (!escape && c == '\\') {
+				escape = TRUE;
+				continue;
+			}
+			*ptr++ = c;
+			escape = FALSE;
 		}
 		*ptr = '\0';
 	}
-
-	eat_line_trailing(in);
-
 	DEBUG(9) fprintf(stderr, "rval = %s\n", buf);
+	/* eat trailing of line */
+	while ((c = fgetc(in)) != EOF && c != '\n') {
+		continue;
+	}
 
 	return TRUE;
 }