changeset 385:01769f722a18

Refactoring in tables.c.
author markus schnalke <meillo@marmaro.de>
date Thu, 16 Feb 2012 13:34:44 +0100
parents 4848c16ed1c1
children 13c9e0969054
files src/tables.c
diffstat 1 files changed, 30 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/tables.c	Thu Feb 16 11:22:31 2012 +0100
+++ b/src/tables.c	Thu Feb 16 13:34:44 2012 +0100
@@ -19,8 +19,8 @@
 */
 
 #include <fnmatch.h>
+#include "masqmail.h"
 
-#include "masqmail.h"
 
 table_pair*
 create_pair(gchar *key, gpointer value)
@@ -55,8 +55,9 @@
 
 	p = line;
 	q = buf;
-	while ((*p != '\0') && (*p != delim) && q < buf + 255)
+	while (*p && (*p != delim) && q < buf + 255) {
 		*(q++) = *(p++);
+	}
 	*q = '\0';
 
 	pair = g_malloc(sizeof(table_pair));
@@ -64,24 +65,26 @@
 
 	if (*p) {
 		p++;
-		/*    while(isspace(*p)) p++; */
+		/* while(isspace(*p)) p++; */
 		pair->value = (gpointer *) (g_strdup(g_strstrip(p)));
-	} else
+	} else {
 		pair->value = (gpointer *) g_strdup("");
+	}
 
 	return pair;
 }
 
 gpointer*
-table_find_func(GList *table_list, gchar *key, int (*cmp_func) (const char *,
-		const char *))
+table_find_func(GList *table_list, gchar *key,
+		int (*cmp_func) (const char *, const char *))
 {
 	GList *node;
 
 	foreach(table_list, node) {
 		table_pair *pair = (table_pair *) (node->data);
-		if (cmp_func(pair->key, key) == 0)
+		if (cmp_func(pair->key, key) == 0) {
 			return pair->value;
+		}
 	}
 	return NULL;
 }
@@ -115,27 +118,30 @@
 {
 	GList *list = NULL;
 	FILE *fptr;
+	gchar buf[256];
 
-	if ((fptr = fopen(fname, "rt"))) {
-		gchar buf[256];
+	if (!(fptr = fopen(fname, "rt"))) {
+		logwrite(LOG_ALERT, "could not open table file %s: %s. Thus "
+				"no aliasing will be done\n",
+				fname, strerror(errno));
+		return NULL;
+	}
 
-		while (fgets(buf, 255, fptr)) {
-			if (buf[0] && (buf[0] != '#') && (buf[0] != '\n')) {
-				table_pair *pair;
-				g_strchomp(buf);
-				pair = parse_table_pair(buf, delim);
-				list = g_list_append(list, pair);
-			}
+	while (fgets(buf, sizeof buf, fptr)) {
+		if (!*buf || *buf == '#' || *buf == '\n') {
+			continue;
 		}
-		fclose(fptr);
-		if (!list)
-			logwrite(LOG_NOTICE, "table file %s contained no entries\n", fname);
-		return list;
+		table_pair *pair;
+		g_strchomp(buf);
+		pair = parse_table_pair(buf, delim);
+		list = g_list_append(list, pair);
 	}
-	logwrite(LOG_ALERT, "could not open table file %s: %s."
-	                    " Thus no aliasing will be done\n", fname, strerror(errno));
-
-	return NULL;
+	fclose(fptr);
+	if (!list) {
+		logwrite(LOG_NOTICE, "table file %s contained no entries\n",
+				fname);
+	}
+	return list;
 }
 
 void