diff options
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | ckaliases.c | 416 | ||||
-rw-r--r-- | ckaliases.h | 62 | ||||
-rw-r--r-- | gram.y | 336 | ||||
-rw-r--r-- | lex.l | 213 |
5 files changed, 522 insertions, 508 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 |
@@ -51,131 +31,141 @@ xmalloc(size_t size) | |||
51 | to be the transitive closure of what was given. */ | 31 | to be the transitive closure of what was given. */ |
52 | 32 | ||
53 | void | 33 | void |
54 | TC(unsigned *R, int n) | 34 | TC (unsigned *R, int n) |
55 | { | 35 | { |
56 | register int rowsize; | 36 | register int rowsize; |
57 | register unsigned mask; | 37 | register unsigned mask; |
58 | register unsigned *rowj; | 38 | register unsigned *rowj; |
59 | register unsigned *rp; | 39 | register unsigned *rp; |
60 | register unsigned *rend; | 40 | register unsigned *rend; |
61 | register unsigned *ccol; | 41 | register unsigned *ccol; |
62 | 42 | ||
63 | unsigned *relend; | 43 | unsigned *relend; |
64 | unsigned *cword; | 44 | unsigned *cword; |
65 | unsigned *rowi; | 45 | unsigned *rowi; |
66 | 46 | ||
67 | rowsize = WORDSIZE(n) * sizeof(unsigned); | 47 | rowsize = WORDSIZE (n) * sizeof (unsigned); |
68 | relend = (unsigned *) ((char *) R + (n * rowsize)); | 48 | relend = (unsigned *) ((char *) R + (n * rowsize)); |
69 | 49 | ||
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) |
74 | ccol = cword; | 54 | { |
75 | rowj = R; | 55 | ccol = cword; |
76 | 56 | rowj = R; | |
77 | while (rowj < relend) { | 57 | |
78 | if (*ccol & mask) { | 58 | while (rowj < relend) |
79 | rp = rowi; | 59 | { |
80 | rend = (unsigned *) ((char *) rowj + rowsize); | 60 | if (*ccol & mask) |
81 | 61 | { | |
82 | while (rowj < rend) | 62 | rp = rowi; |
83 | *rowj++ |= *rp++; | 63 | rend = (unsigned *) ((char *) rowj + rowsize); |
84 | } else { | 64 | |
85 | rowj = (unsigned *) ((char *) rowj + rowsize); | 65 | while (rowj < rend) |
86 | } | 66 | *rowj++ |= *rp++; |
87 | 67 | } | |
88 | ccol = (unsigned *) ((char *) ccol + rowsize); | 68 | else |
89 | } | 69 | { |
90 | 70 | rowj = (unsigned *) ((char *) rowj + rowsize); | |
91 | mask <<= 1; | 71 | } |
92 | if (mask == 0) { | 72 | |
93 | mask = 1; | 73 | ccol = (unsigned *) ((char *) ccol + rowsize); |
94 | cword++; | 74 | } |
95 | } | ||
96 | rowi = (unsigned *) ((char *) rowi + rowsize); | ||
97 | } | ||
98 | } | ||
99 | 75 | ||
76 | mask <<= 1; | ||
77 | if (mask == 0) | ||
78 | { | ||
79 | mask = 1; | ||
80 | cword++; | ||
81 | } | ||
82 | rowi = (unsigned *) ((char *) rowi + rowsize); | ||
83 | } | ||
84 | } | ||
100 | 85 | ||
101 | 86 | ||
102 | void | 87 | void |
103 | slist_add(SLIST **plist, char *str) | 88 | slist_add (SLIST **plist, char *str) |
104 | { | 89 | { |
105 | struct string_list *p = xmalloc(sizeof(*p)); | 90 | struct string_list *p = xmalloc (sizeof (*p)); |
106 | p->str = str; | 91 | p->str = str; |
107 | p->next = NULL; | 92 | p->next = NULL; |
108 | 93 | ||
109 | if (!*plist) { | 94 | if (!*plist) |
110 | *plist = xmalloc(sizeof(**plist)); | 95 | { |
111 | (*plist)->head = NULL; | 96 | *plist = xmalloc (sizeof (**plist)); |
112 | } | 97 | (*plist)->head = NULL; |
113 | 98 | } | |
114 | if ((*plist)->head == NULL) { | 99 | |
115 | (*plist)->head = p; | 100 | if ((*plist)->head == NULL) |
116 | (*plist)->count = 0; | 101 | { |
117 | } else { | 102 | (*plist)->head = p; |
118 | (*plist)->tail->next = p; | 103 | (*plist)->count = 0; |
119 | (*plist)->count++; | 104 | } |
120 | } | 105 | else |
121 | (*plist)->tail = p; | 106 | { |
107 | (*plist)->tail->next = p; | ||
108 | (*plist)->count++; | ||
109 | } | ||
110 | (*plist)->tail = p; | ||
122 | } | 111 | } |
123 | 112 | ||
124 | void | 113 | void |
125 | slist_append(SLIST **pdst, SLIST *src) | 114 | 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) |
130 | *pdst = xmalloc(sizeof(**pdst)); | 119 | { |
131 | (*pdst)->head = NULL; | 120 | *pdst = xmalloc (sizeof (**pdst)); |
132 | (*pdst)->count = 0; | 121 | (*pdst)->head = NULL; |
133 | } | 122 | (*pdst)->count = 0; |
123 | } | ||
124 | |||
125 | if ((*pdst)->head = NULL) | ||
126 | (*pdst)->head = src->head; | ||
127 | |||
128 | for (tail = src->tail; tail->next; tail = tail->next) | ||
129 | ; | ||
134 | 130 | ||
135 | if ((*pdst)->head = NULL) | 131 | (*pdst)->tail = tail; |
136 | (*pdst)->head = src->head; | 132 | (*pdst)->count += src->count; |
137 | |||
138 | for (tail = src->tail; tail->next; tail = tail->next) | ||
139 | ; | ||
140 | |||
141 | (*pdst)->tail = tail; | ||
142 | (*pdst)->count += src->count; | ||
143 | } | 133 | } |
144 | 134 | ||
145 | char * | 135 | char * |
146 | slist_member(SLIST *plist, char *name) | 136 | slist_member (SLIST *plist, char *name) |
147 | { | 137 | { |
148 | struct string_list *p; | 138 | struct string_list *p; |
149 | 139 | ||
150 | if (plist) | 140 | if (plist) |
151 | for (p = plist->head; p; p = p->next) | 141 | for (p = plist->head; p; p = p->next) |
152 | if (p->str && strcmp(p->str, name) == 0) | 142 | if (p->str && strcmp (p->str, name) == 0) |
153 | return p->str; | 143 | return p->str; |
154 | return NULL; | 144 | return NULL; |
155 | } | 145 | } |
156 | 146 | ||
157 | void | 147 | void |
158 | slist_destroy(SLIST **plist) | 148 | slist_destroy (SLIST **plist) |
159 | { | 149 | { |
160 | struct string_list *p; | 150 | struct string_list *p; |
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) |
165 | struct string_list *next = p->next; | 155 | { |
166 | free(p); |