Mercurial > masqmail-0.2
diff src/tables.c @ 10:26e34ae9a3e3
changed indention and line wrapping to a more consistent style
author | meillo@marmaro.de |
---|---|
date | Mon, 27 Oct 2008 16:23:10 +0100 |
parents | 08114f7dcc23 |
children | f671821d8222 |
line wrap: on
line diff
--- a/src/tables.c Mon Oct 27 16:21:27 2008 +0100 +++ b/src/tables.c Mon Oct 27 16:23:10 2008 +0100 @@ -19,120 +19,128 @@ #include "masqmail.h" #include <fnmatch.h> -table_pair *create_pair(gchar *key, gpointer value) +table_pair* +create_pair(gchar * key, gpointer value) { - table_pair *pair; - - pair = g_malloc(sizeof(table_pair)); - pair->key = g_strdup(key); - pair->value = value; + table_pair *pair; - return pair; + pair = g_malloc(sizeof(table_pair)); + pair->key = g_strdup(key); + pair->value = value; + + return pair; } -table_pair *create_pair_string(gchar *key, gpointer value) +table_pair* +create_pair_string(gchar * key, gpointer value) { - table_pair *pair; - - pair = g_malloc(sizeof(table_pair)); - pair->key = g_strdup(key); - pair->value = (gpointer)(g_strdup(value)); + table_pair *pair; - return pair; + pair = g_malloc(sizeof(table_pair)); + pair->key = g_strdup(key); + pair->value = (gpointer) (g_strdup(value)); + + return pair; } -table_pair *parse_table_pair(gchar *line, char delim) +table_pair* +parse_table_pair(gchar * line, char delim) { - gchar buf[256]; - gchar *p, *q; - table_pair *pair; - - p = line; - q = buf; - while((*p != 0) && (*p != delim) && q < buf+255) - *(q++) = *(p++); - *q = 0; + gchar buf[256]; + gchar *p, *q; + table_pair *pair; - pair = g_malloc(sizeof(table_pair)); - pair->key = g_strdup(g_strstrip(buf)); + p = line; + q = buf; + while ((*p != 0) && (*p != delim) && q < buf + 255) + *(q++) = *(p++); + *q = 0; + + pair = g_malloc(sizeof(table_pair)); + pair->key = g_strdup(g_strstrip(buf)); - if(*p){ - p++; - /* while(isspace(*p)) p++; */ - pair->value = (gpointer *)(g_strdup(g_strstrip(p))); - }else - pair->value = (gpointer *)g_strdup(""); + if (*p) { + p++; + /* while(isspace(*p)) p++; */ + pair->value = (gpointer *) (g_strdup(g_strstrip(p))); + } else + pair->value = (gpointer *) g_strdup(""); - return pair; + return pair; } -gpointer *table_find_func(GList *table_list, gchar *key, int (*cmp_func)(const char *, const char *)) +gpointer* +table_find_func(GList * table_list, gchar * key, int (*cmp_func) (const char *, const char *)) { - GList *node; + GList *node; - foreach(table_list, node){ - table_pair *pair = (table_pair *)(node->data); - if(cmp_func(pair->key, key) == 0) - return pair->value; - } - return NULL; + foreach(table_list, node) { + table_pair *pair = (table_pair *) (node->data); + if (cmp_func(pair->key, key) == 0) + return pair->value; + } + return NULL; } -gpointer *table_find(GList *table_list, gchar *key) +gpointer* +table_find(GList * table_list, gchar * key) { - return table_find_func(table_list, key, strcmp); -} - -gpointer *table_find_case(GList *table_list, gchar *key) -{ - return table_find_func(table_list, key, strcasecmp); + return table_find_func(table_list, key, strcmp); } -static -int fnmatch0(const char *pattern, const char *string) +gpointer* +table_find_case(GList * table_list, gchar * key) { - return fnmatch(pattern, string, 0); + return table_find_func(table_list, key, strcasecmp); } -gpointer *table_find_fnmatch(GList *table_list, gchar *key) +static int +fnmatch0(const char *pattern, const char *string) { - return table_find_func(table_list, key, fnmatch0); + return fnmatch(pattern, string, 0); +} + +gpointer* +table_find_fnmatch(GList * table_list, gchar * key) +{ + return table_find_func(table_list, key, fnmatch0); } -GList *table_read(gchar *fname, gchar delim) +GList* +table_read(gchar * fname, gchar delim) { - GList *list = NULL; - FILE *fptr; + GList *list = NULL; + FILE *fptr; - if((fptr = fopen(fname, "rt"))){ - gchar buf[256]; + if ((fptr = fopen(fname, "rt"))) { + gchar buf[256]; - 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); - } - } - fclose(fptr); - return list; - } - logwrite(LOG_ALERT, "could not open table file %s: %s\n", fname, strerror(errno)); + 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); + } + } + fclose(fptr); + return list; + } + logwrite(LOG_ALERT, "could not open table file %s: %s\n", fname, strerror(errno)); - return NULL; + return NULL; } -void destroy_table(GList *table) +void +destroy_table(GList * table) { - GList *node; + GList *node; - foreach(table, node){ - table_pair *p = (table_pair *)(node->data); - g_free(p->key); - g_free(p->value); - g_free(p); - } - g_list_free(table); + foreach(table, node) { + table_pair *p = (table_pair *) (node->data); + g_free(p->key); + g_free(p->value); + g_free(p); + } + g_list_free(table); } -