Mercurial > masqmail
comparison src/tables.c @ 366:41958685480d
Switched to `type *name' style
Andrew Koenig's ``C Traps and Pitfalls'' (Ch.2.1) convinced
me that it is best to go with the way C had been designed.
The ``declaration reflects use'' concept conflicts with a
``type* name'' notation. Hence I switched.
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Thu, 22 Sep 2011 15:07:40 +0200 |
parents | ec28ce798b79 |
children | b27f66555ba8 |
comparison
equal
deleted
inserted
replaced
365:934a223e4ee8 | 366:41958685480d |
---|---|
20 #include <fnmatch.h> | 20 #include <fnmatch.h> |
21 | 21 |
22 #include "masqmail.h" | 22 #include "masqmail.h" |
23 | 23 |
24 table_pair* | 24 table_pair* |
25 create_pair(gchar * key, gpointer value) | 25 create_pair(gchar *key, gpointer value) |
26 { | 26 { |
27 table_pair *pair; | 27 table_pair *pair; |
28 | 28 |
29 pair = g_malloc(sizeof(table_pair)); | 29 pair = g_malloc(sizeof(table_pair)); |
30 pair->key = g_strdup(key); | 30 pair->key = g_strdup(key); |
32 | 32 |
33 return pair; | 33 return pair; |
34 } | 34 } |
35 | 35 |
36 table_pair* | 36 table_pair* |
37 create_pair_string(gchar * key, gpointer value) | 37 create_pair_string(gchar *key, gpointer value) |
38 { | 38 { |
39 table_pair *pair; | 39 table_pair *pair; |
40 | 40 |
41 pair = g_malloc(sizeof(table_pair)); | 41 pair = g_malloc(sizeof(table_pair)); |
42 pair->key = g_strdup(key); | 42 pair->key = g_strdup(key); |
44 | 44 |
45 return pair; | 45 return pair; |
46 } | 46 } |
47 | 47 |
48 table_pair* | 48 table_pair* |
49 parse_table_pair(gchar * line, char delim) | 49 parse_table_pair(gchar *line, char delim) |
50 { | 50 { |
51 gchar buf[256]; | 51 gchar buf[256]; |
52 gchar *p, *q; | 52 gchar *p, *q; |
53 table_pair *pair; | 53 table_pair *pair; |
54 | 54 |
70 | 70 |
71 return pair; | 71 return pair; |
72 } | 72 } |
73 | 73 |
74 gpointer* | 74 gpointer* |
75 table_find_func(GList * table_list, gchar * key, int (*cmp_func) (const char *, const char *)) | 75 table_find_func(GList *table_list, gchar *key, int (*cmp_func) (const char *, const char *)) |
76 { | 76 { |
77 GList *node; | 77 GList *node; |
78 | 78 |
79 foreach(table_list, node) { | 79 foreach(table_list, node) { |
80 table_pair *pair = (table_pair *) (node->data); | 80 table_pair *pair = (table_pair *) (node->data); |
83 } | 83 } |
84 return NULL; | 84 return NULL; |
85 } | 85 } |
86 | 86 |
87 gpointer* | 87 gpointer* |
88 table_find(GList * table_list, gchar * key) | 88 table_find(GList *table_list, gchar *key) |
89 { | 89 { |
90 return table_find_func(table_list, key, strcmp); | 90 return table_find_func(table_list, key, strcmp); |
91 } | 91 } |
92 | 92 |
93 gpointer* | 93 gpointer* |
94 table_find_case(GList * table_list, gchar * key) | 94 table_find_case(GList *table_list, gchar *key) |
95 { | 95 { |
96 return table_find_func(table_list, key, strcasecmp); | 96 return table_find_func(table_list, key, strcasecmp); |
97 } | 97 } |
98 | 98 |
99 static int | 99 static int |
101 { | 101 { |
102 return fnmatch(pattern, string, 0); | 102 return fnmatch(pattern, string, 0); |
103 } | 103 } |
104 | 104 |
105 gpointer* | 105 gpointer* |
106 table_find_fnmatch(GList * table_list, gchar * key) | 106 table_find_fnmatch(GList *table_list, gchar *key) |
107 { | 107 { |
108 return table_find_func(table_list, key, fnmatch0); | 108 return table_find_func(table_list, key, fnmatch0); |
109 } | 109 } |
110 | 110 |
111 GList* | 111 GList* |
112 table_read(gchar * fname, gchar delim) | 112 table_read(gchar *fname, gchar delim) |
113 { | 113 { |
114 GList *list = NULL; | 114 GList *list = NULL; |
115 FILE *fptr; | 115 FILE *fptr; |
116 | 116 |
117 if ((fptr = fopen(fname, "rt"))) { | 117 if ((fptr = fopen(fname, "rt"))) { |
135 | 135 |
136 return NULL; | 136 return NULL; |
137 } | 137 } |
138 | 138 |
139 void | 139 void |
140 destroy_table(GList * table) | 140 destroy_table(GList *table) |
141 { | 141 { |
142 GList *node; | 142 GList *node; |
143 | 143 |
144 foreach(table, node) { | 144 foreach(table, node) { |
145 table_pair *p = (table_pair *) (node->data); | 145 table_pair *p = (table_pair *) (node->data); |