diff options
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | ckaliases.c | 82 | ||||
-rw-r--r-- | ckaliases.h | 30 | ||||
-rw-r--r-- | gram.y | 100 | ||||
-rw-r--r-- | lex.l | 47 |
5 files changed, 138 insertions, 124 deletions
diff --git a/Makefile.am b/Makefile.am index c43b7a3..12f531c 100644 --- a/Makefile.am +++ b/Makefile.am | |||
@@ -14,9 +14,10 @@ | |||
14 | # You should have received a copy of the GNU General Public License | 14 | # You should have received a copy of the GNU General Public License |
15 | # along with GSC. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with GSC. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | ||
17 | AM_INSTALLCHECK_STD_OPTIONS_EXEMPT=ckaliases | ||
18 | AM_YFLAGS=-vtd | 17 | AM_YFLAGS=-vtd |
19 | AM_LFLAGS=-d | 18 | AM_LFLAGS=-d |
20 | sbin_PROGRAMS=ckaliases | 19 | sbin_PROGRAMS=ckaliases |
21 | noinst_HEADERS=gram.h | 20 | noinst_HEADERS=gram.h |
22 | ckaliases_SOURCES=gram.y lex.l ckaliases.c ckaliases.h | 21 | ckaliases_SOURCES=gram.y lex.l ckaliases.c ckaliases.h |
22 | LDADD=../lib/libgsc.a ../gnu/libgnu.a | ||
23 | INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gnu -I../gnu | ||
diff --git a/ckaliases.c b/ckaliases.c index 343a52f..d77e62d 100644 --- a/ckaliases.c +++ b/ckaliases.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* ckaliases - verify syntax of sendmail-style alias files | 1 | /* ckaliases - verify syntax of sendmail-style alias files |
2 | Copyright (C) 2005 Sergey Poznyakoff | 2 | Copyright (C) 2005, 2007 Sergey Poznyakoff |
3 | 3 | ||
4 | This program is free software; you can redistribute it and/or modify it | 4 | This program is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU General Public License as published by the | 5 | under the terms of the GNU General Public License as published by the |
@@ -14,28 +14,8 @@ | |||
14 | You should have received a copy of the GNU General Public License along | 14 | You should have received a copy of the GNU General Public License along |
15 | with this program. If not, see <http://www.gnu.org/licenses/>. */ | 15 | with this program. If not, see <http://www.gnu.org/licenses/>. */ |
16 | 16 | ||
17 | #ifdef HAVE_CONFIG_H | ||
18 | # include <config.h> | ||
19 | #endif | ||
20 | #include <stdio.h> | ||
21 | #include <stdlib.h> | ||
22 | #define obstack_chunk_alloc malloc | ||
23 | #define obstack_chunk_free free | ||
24 | #include <obstack.h> | ||
25 | #include "ckaliases.h" | 17 | #include "ckaliases.h" |
26 | 18 | ||
27 | void * | ||
28 | xmalloc(size_t size) | ||
29 | { | ||
30 | void *p = malloc(size); | ||
31 | if (!p) { | ||
32 | fprintf(stderr, "not enough memory\n"); | ||
33 | exit(1); | ||
34 | } | ||
35 | return p; | ||
36 | } | ||
37 | |||
38 | |||
39 | #ifndef CHAR_BIT | 19 | #ifndef CHAR_BIT |
40 | # define CHAR_BIT 8 | 20 | # define CHAR_BIT 8 |
41 | #endif | 21 | #endif |
@@ -70,18 +50,23 @@ TC(unsigned *R, int n) | |||
70 | cword = R; | 50 | cword = R; |
71 | mask = 1; | 51 | mask = 1; |
72 | rowi = R; | 52 | rowi = R; |
73 | while (rowi < relend) { | 53 | while (rowi < relend) |
54 | { | ||
74 | ccol = cword; | 55 | ccol = cword; |
75 | rowj = R; | 56 | rowj = R; |
76 | 57 | ||
77 | while (rowj < relend) { | 58 | while (rowj < relend) |
78 | if (*ccol & mask) { | 59 | { |
60 | if (*ccol & mask) | ||
61 | { | ||
79 | rp = rowi; | 62 | rp = rowi; |
80 | rend = (unsigned *) ((char *) rowj + rowsize); | 63 | rend = (unsigned *) ((char *) rowj + rowsize); |
81 | 64 | ||
82 | while (rowj < rend) | 65 | while (rowj < rend) |
83 | *rowj++ |= *rp++; | 66 | *rowj++ |= *rp++; |
84 | } else { | 67 | } |
68 | else | ||
69 | { | ||
85 | rowj = (unsigned *) ((char *) rowj + rowsize); | 70 | rowj = (unsigned *) ((char *) rowj + rowsize); |
86 | } | 71 | } |
87 | 72 | ||
@@ -89,7 +74,8 @@ TC(unsigned *R, int n) | |||
89 | } | 74 | } |
90 | 75 | ||
91 | mask <<= 1; | 76 | mask <<= 1; |
92 | if (mask == 0) { | 77 | if (mask == 0) |
78 | { | ||
93 | mask = 1; | 79 | mask = 1; |
94 | cword++; | 80 | cword++; |
95 | } | 81 | } |
@@ -98,7 +84,6 @@ TC(unsigned *R, int n) | |||
98 | } | 84 | } |
99 | 85 | ||
100 | 86 | ||
101 | |||
102 | void | 87 | void |
103 | slist_add (SLIST **plist, char *str) | 88 | slist_add (SLIST **plist, char *str) |
104 | { | 89 | { |
@@ -106,15 +91,19 @@ slist_add(SLIST **plist, char *str) | |||
106 | p->str = str; | 91 | p->str = str; |
107 | p->next = NULL; | 92 | p->next = NULL; |
108 | 93 | ||
109 | if (!*plist) { | 94 | if (!*plist) |
95 | { | ||
110 | *plist = xmalloc (sizeof (**plist)); | 96 | *plist = xmalloc (sizeof (**plist)); |
111 | (*plist)->head = NULL; | 97 | (*plist)->head = NULL; |
112 | } | 98 | } |
113 | 99 | ||
114 | if ((*plist)->head == NULL) { | 100 | if ((*plist)->head == NULL) |
101 | { | ||
115 | (*plist)->head = p; | 102 | (*plist)->head = p; |
116 | (*plist)->count = 0; | 103 | (*plist)->count = 0; |
117 | } else { | 104 | } |
105 | else | ||
106 | { | ||
118 | (*plist)->tail->next = p; | 107 | (*plist)->tail->next = p; |
119 | (*plist)->count++; | 108 | (*plist)->count++; |
120 | } | 109 | } |
@@ -126,7 +115,8 @@ slist_append(SLIST **pdst, SLIST *src) | |||
126 | { | 115 | { |
127 | struct string_list *tail; | 116 | struct string_list *tail; |
128 | 117 | ||
129 | if (!*pdst) { | 118 | if (!*pdst) |
119 | { | ||
130 | *pdst = xmalloc (sizeof (**pdst)); | 120 | *pdst = xmalloc (sizeof (**pdst)); |
131 | (*pdst)->head = NULL; | 121 | (*pdst)->head = NULL; |
132 | (*pdst)->count = 0; | 122 | (*pdst)->count = 0; |
@@ -161,7 +151,8 @@ slist_destroy(SLIST **plist) | |||
161 | if (!plist || !*plist) | 151 | if (!plist || !*plist) |
162 | return; | 152 | return; |
163 | p = (*plist)->head; | 153 | p = (*plist)->head; |
164 | while (p) { | 154 | while (p) |
155 | { | ||
165 | struct string_list *next = p->next; | 156 | struct string_list *next = p->next; |
166 | free (p); | 157 | free (p); |
167 | p = next; | 158 | p = next; |
@@ -171,9 +162,8 @@ slist_destroy(SLIST **plist) | |||
171 | } | 162 | } |
172 | 163 | ||
173 | 164 | ||
174 | 165 | typedef struct | |
175 | 166 | { | |
176 | typedef struct { | ||
177 | char *name; | 167 | char *name; |
178 | SLIST *exp; | 168 | SLIST *exp; |
179 | } ALIAS; | 169 | } ALIAS; |
@@ -238,7 +228,10 @@ end_aliases() | |||
238 | qsort (aliases, alias_count, sizeof aliases[0], alias_cmp); | 228 | qsort (aliases, alias_count, sizeof aliases[0], alias_cmp); |
239 | for (i = 1; i < alias_count; i++) | 229 | for (i = 1; i < alias_count; i++) |
240 | if (alias_cmp (aliases + i - 1, aliases + i) == 0) | 230 | if (alias_cmp (aliases + i - 1, aliases + i) == 0) |
241 | error("alias `%s' multiply defined", aliases[i].name); | 231 | { |
232 | error (0, 0, "alias `%s' multiply defined", aliases[i].name); | ||
233 | error_count++; | ||
234 | } | ||
242 | } | 235 | } |
243 | 236 | ||
244 | 237 | ||
@@ -273,10 +266,13 @@ mark_connected(unsigned *r, unsigned size) | |||
273 | { | 266 | { |
274 | int i; | 267 | int i; |
275 | 268 | ||
276 | for (i = 0; i < alias_count; i++) { | 269 | for (i = 0; i < alias_count; i++) |
277 | if (aliases[i].exp) { | 270 | { |
271 | if (aliases[i].exp) | ||
272 | { | ||
278 | struct string_list *p; | 273 | struct string_list *p; |
279 | for (p = aliases[i].exp->head; p; p = p->next) { | 274 | for (p = aliases[i].exp->head; p; p = p->next) |
275 | { | ||
280 | int n = find_alias (p->str); | 276 | int n = find_alias (p->str); |
281 | if (n >= 0) | 277 | if (n >= 0) |
282 | alias_setbit (r, size, i, n); | 278 | alias_setbit (r, size, i, n); |
@@ -290,9 +286,13 @@ check_circular_deps(unsigned *r, unsigned size) | |||
290 | { | 286 | { |
291 | int i; | 287 | int i; |
292 | 288 | ||
293 | for (i = 0; i < alias_count; i++) { | 289 | for (i = 0; i < alias_count; i++) |
290 | { | ||
294 | if (alias_bitisset (r, size, i, i)) | 291 | if (alias_bitisset (r, size, i, i)) |
295 | error("%s: circular dependency", aliases[i].name); | 292 | { |
293 | error (0, 0, "%s: circular dependency", aliases[i].name); | ||
294 | error_count++; | ||
295 | } | ||
296 | } | 296 | } |
297 | } | 297 | } |
298 | 298 | ||
diff --git a/ckaliases.h b/ckaliases.h index 8d6546d..d3e053c 100644 --- a/ckaliases.h +++ b/ckaliases.h | |||
@@ -14,20 +14,44 @@ | |||
14 | You should have received a copy of the GNU General Public License along | 14 | You should have received a copy of the GNU General Public License along |
15 | with this program. If not, see <http://www.gnu.org/licenses/>. */ | 15 | with this program. If not, see <http://www.gnu.org/licenses/>. */ |
16 | 16 | ||
17 | #ifdef HAVE_CONFIG_H | ||
18 | # include <config.h> | ||
19 | #endif | ||
20 | #include <stdio.h> | ||
21 | #include <stdlib.h> | ||
22 | #define obstack_chunk_alloc malloc | ||
23 | #define obstack_chunk_free free | ||
24 | #include <obstack.h> | ||
25 | #include <stdio.h> | ||
26 | #include <stdlib.h> | ||
27 | #include <stdarg.h> | ||
28 | #include <unistd.h> | ||
29 | #include <sys/file.h> | ||
30 | #include <sys/stat.h> | ||
31 | #include <errno.h> | ||
32 | #include <string.h> | ||
33 | #include "getopt.h" | ||