masqmail

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 diff
     1.1 --- a/src/tables.c	Mon Oct 27 16:21:27 2008 +0100
     1.2 +++ b/src/tables.c	Mon Oct 27 16:23:10 2008 +0100
     1.3 @@ -19,120 +19,128 @@
     1.4  #include "masqmail.h"
     1.5  #include <fnmatch.h>
     1.6  
     1.7 -table_pair *create_pair(gchar *key, gpointer value)
     1.8 +table_pair*
     1.9 +create_pair(gchar * key, gpointer value)
    1.10  {
    1.11 -  table_pair *pair;
    1.12 -  
    1.13 -  pair = g_malloc(sizeof(table_pair));
    1.14 -  pair->key = g_strdup(key);
    1.15 -  pair->value = value;
    1.16 +	table_pair *pair;
    1.17  
    1.18 -  return pair;
    1.19 +	pair = g_malloc(sizeof(table_pair));
    1.20 +	pair->key = g_strdup(key);
    1.21 +	pair->value = value;
    1.22 +
    1.23 +	return pair;
    1.24  }
    1.25  
    1.26 -table_pair *create_pair_string(gchar *key, gpointer value)
    1.27 +table_pair*
    1.28 +create_pair_string(gchar * key, gpointer value)
    1.29  {
    1.30 -  table_pair *pair;
    1.31 -  
    1.32 -  pair = g_malloc(sizeof(table_pair));
    1.33 -  pair->key = g_strdup(key);
    1.34 -  pair->value = (gpointer)(g_strdup(value));
    1.35 +	table_pair *pair;
    1.36  
    1.37 -  return pair;
    1.38 +	pair = g_malloc(sizeof(table_pair));
    1.39 +	pair->key = g_strdup(key);
    1.40 +	pair->value = (gpointer) (g_strdup(value));
    1.41 +
    1.42 +	return pair;
    1.43  }
    1.44  
    1.45 -table_pair *parse_table_pair(gchar *line, char delim)
    1.46 +table_pair*
    1.47 +parse_table_pair(gchar * line, char delim)
    1.48  {
    1.49 -  gchar buf[256];
    1.50 -  gchar *p, *q;
    1.51 -  table_pair *pair;
    1.52 +	gchar buf[256];
    1.53 +	gchar *p, *q;
    1.54 +	table_pair *pair;
    1.55  
    1.56 -  p = line;
    1.57 -  q = buf;
    1.58 -  while((*p != 0) && (*p != delim) && q < buf+255)
    1.59 -    *(q++) = *(p++);
    1.60 -  *q = 0;
    1.61 +	p = line;
    1.62 +	q = buf;
    1.63 +	while ((*p != 0) && (*p != delim) && q < buf + 255)
    1.64 +		*(q++) = *(p++);
    1.65 +	*q = 0;
    1.66  
    1.67 -  pair = g_malloc(sizeof(table_pair));
    1.68 -  pair->key = g_strdup(g_strstrip(buf));
    1.69 +	pair = g_malloc(sizeof(table_pair));
    1.70 +	pair->key = g_strdup(g_strstrip(buf));
    1.71  
    1.72 -  if(*p){
    1.73 -    p++;
    1.74 -    /*    while(isspace(*p)) p++; */
    1.75 -    pair->value = (gpointer *)(g_strdup(g_strstrip(p)));
    1.76 -  }else
    1.77 -    pair->value = (gpointer *)g_strdup("");
    1.78 +	if (*p) {
    1.79 +		p++;
    1.80 +		/*    while(isspace(*p)) p++; */
    1.81 +		pair->value = (gpointer *) (g_strdup(g_strstrip(p)));
    1.82 +	} else
    1.83 +		pair->value = (gpointer *) g_strdup("");
    1.84  
    1.85 -  return pair;
    1.86 +	return pair;
    1.87  }
    1.88  
    1.89 -gpointer *table_find_func(GList *table_list, gchar *key, int (*cmp_func)(const char *, const char *))
    1.90 +gpointer*
    1.91 +table_find_func(GList * table_list, gchar * key, int (*cmp_func) (const char *, const char *))
    1.92  {
    1.93 -  GList *node;
    1.94 +	GList *node;
    1.95  
    1.96 -  foreach(table_list, node){
    1.97 -    table_pair *pair = (table_pair *)(node->data);
    1.98 -    if(cmp_func(pair->key, key) == 0)
    1.99 -      return pair->value;
   1.100 -  }
   1.101 -  return NULL;
   1.102 +	foreach(table_list, node) {
   1.103 +		table_pair *pair = (table_pair *) (node->data);
   1.104 +		if (cmp_func(pair->key, key) == 0)
   1.105 +			return pair->value;
   1.106 +	}
   1.107 +	return NULL;
   1.108  }
   1.109  
   1.110 -gpointer *table_find(GList *table_list, gchar *key)
   1.111 +gpointer*
   1.112 +table_find(GList * table_list, gchar * key)
   1.113  {
   1.114 -  return table_find_func(table_list, key, strcmp);
   1.115 +	return table_find_func(table_list, key, strcmp);
   1.116  }
   1.117  
   1.118 -gpointer *table_find_case(GList *table_list, gchar *key)
   1.119 +gpointer*
   1.120 +table_find_case(GList * table_list, gchar * key)
   1.121  {
   1.122 -  return table_find_func(table_list, key, strcasecmp);
   1.123 +	return table_find_func(table_list, key, strcasecmp);
   1.124  }
   1.125  
   1.126 -static
   1.127 -int fnmatch0(const char *pattern, const char *string)
   1.128 +static int
   1.129 +fnmatch0(const char *pattern, const char *string)
   1.130  {
   1.131 -  return fnmatch(pattern, string, 0);
   1.132 +	return fnmatch(pattern, string, 0);
   1.133  }
   1.134  
   1.135 -gpointer *table_find_fnmatch(GList *table_list, gchar *key)
   1.136 +gpointer*
   1.137 +table_find_fnmatch(GList * table_list, gchar * key)
   1.138  {
   1.139 -  return table_find_func(table_list, key, fnmatch0);
   1.140 +	return table_find_func(table_list, key, fnmatch0);
   1.141  }
   1.142  
   1.143 -GList *table_read(gchar *fname, gchar delim)
   1.144 +GList*
   1.145 +table_read(gchar * fname, gchar delim)
   1.146  {
   1.147 -  GList *list = NULL;
   1.148 -  FILE *fptr;
   1.149 +	GList *list = NULL;
   1.150 +	FILE *fptr;
   1.151  
   1.152 -  if((fptr = fopen(fname, "rt"))){
   1.153 -    gchar buf[256];
   1.154 +	if ((fptr = fopen(fname, "rt"))) {
   1.155 +		gchar buf[256];
   1.156  
   1.157 -    while(fgets(buf, 255, fptr)){
   1.158 -      if(buf[0] && (buf[0] != '#') && (buf[0] != '\n')){
   1.159 -	table_pair *pair;
   1.160 -	g_strchomp(buf);
   1.161 -	pair = parse_table_pair(buf, delim);
   1.162 -	list = g_list_append(list, pair);
   1.163 -      }
   1.164 -    }
   1.165 -    fclose(fptr);
   1.166 -    return list;
   1.167 -  }
   1.168 -  logwrite(LOG_ALERT, "could not open table file %s: %s\n", fname, strerror(errno));
   1.169 +		while (fgets(buf, 255, fptr)) {
   1.170 +			if (buf[0] && (buf[0] != '#') && (buf[0] != '\n')) {
   1.171 +				table_pair *pair;
   1.172 +				g_strchomp(buf);
   1.173 +				pair = parse_table_pair(buf, delim);
   1.174 +				list = g_list_append(list, pair);
   1.175 +			}
   1.176 +		}
   1.177 +		fclose(fptr);
   1.178 +		return list;
   1.179 +	}
   1.180 +	logwrite(LOG_ALERT, "could not open table file %s: %s\n", fname, strerror(errno));
   1.181  
   1.182 -  return NULL;
   1.183 +	return NULL;
   1.184  }
   1.185  
   1.186 -void destroy_table(GList *table)
   1.187 +void
   1.188 +destroy_table(GList * table)
   1.189  {
   1.190 -  GList *node;
   1.191 +	GList *node;
   1.192  
   1.193 -  foreach(table, node){
   1.194 -    table_pair *p = (table_pair *)(node->data);
   1.195 -    g_free(p->key);
   1.196 -    g_free(p->value);
   1.197 -    g_free(p);
   1.198 -  }
   1.199 -  g_list_free(table);
   1.200 +	foreach(table, node) {
   1.201 +		table_pair *p = (table_pair *) (node->data);
   1.202 +		g_free(p->key);
   1.203 +		g_free(p->value);
   1.204 +		g_free(p);
   1.205 +	}
   1.206 +	g_list_free(table);
   1.207  }
   1.208 -