summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2013-03-04 19:44:25 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-03-04 19:44:25 (GMT)
commita75760ff7d9bedcb1377fc3441f5e38178da1d6a (patch) (unidiff)
tree39413a06ee259848dfc2cb585a357ddac5d2d4ca
parent860ec4960ff61cf3b2e98e0d020e7f8a93a56008 (diff)
downloadalck-a75760ff7d9bedcb1377fc3441f5e38178da1d6a.tar.gz
alck-a75760ff7d9bedcb1377fc3441f5e38178da1d6a.tar.bz2
Switch to a "right" style.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ckaliases.c385
-rw-r--r--gram.y330
-rw-r--r--lex.l188
3 files changed, 436 insertions, 467 deletions
diff --git a/ckaliases.c b/ckaliases.c
index d77e62d..da0a5c1 100644
--- a/ckaliases.c
+++ b/ckaliases.c
@@ -31,141 +31,128 @@
31 to be the transitive closure of what was given. */ 31 to be the transitive closure of what was given. */
32 32
33void 33void
34TC (unsigned *R, int n) 34TC(unsigned *R, int n)
35{ 35{
36 register int rowsize; 36 register int rowsize;
37 register unsigned mask; 37 register unsigned mask;
38 register unsigned *rowj; 38 register unsigned *rowj;
39 register unsigned *rp; 39 register unsigned *rp;
40 register unsigned *rend; 40 register unsigned *rend;
41 register unsigned *ccol; 41 register unsigned *ccol;
42 42
43 unsigned *relend; 43 unsigned *relend;
44 unsigned *cword; 44 unsigned *cword;
45 unsigned *rowi; 45 unsigned *rowi;
46 46
47 rowsize = WORDSIZE (n) * sizeof (unsigned); 47 rowsize = WORDSIZE(n) * sizeof(unsigned);
48 relend = (unsigned *) ((char *) R + (n * rowsize)); 48 relend = (unsigned *) ((char *) R + (n * rowsize));
49 49
50 cword = R; 50 cword = R;
51 mask = 1; 51 mask = 1;
52 rowi = R; 52 rowi = R;
53 while (rowi < relend) 53 while (rowi < relend) {
54 { 54 ccol = cword;
55 ccol = cword; 55 rowj = R;
56 rowj = R; 56
57 57 while (rowj < relend) {
58 while (rowj < relend) 58 if (*ccol & mask) {
59 { 59 rp = rowi;
60 if (*ccol & mask) 60 rend = (unsigned *) ((char *) rowj + rowsize);
61 { 61
62 rp = rowi; 62 while (rowj < rend)
63 rend = (unsigned *) ((char *) rowj + rowsize); 63 *rowj++ |= *rp++;
64 64 } else {
65 while (rowj < rend) 65 rowj = (unsigned *) ((char *) rowj + rowsize);
66 *rowj++ |= *rp++; 66 }
67 } 67
68 else 68 ccol = (unsigned *) ((char *) ccol + rowsize);
69 { 69 }
70 rowj = (unsigned *) ((char *) rowj + rowsize); 70
71 } 71 mask <<= 1;
72 72 if (mask == 0) {
73 ccol = (unsigned *) ((char *) ccol + rowsize); 73 mask = 1;
74 cword++;
75 }
76 rowi = (unsigned *) ((char *) rowi + rowsize);
74 } 77 }
75
76 mask <<= 1;
77 if (mask == 0)
78 {
79 mask = 1;
80 cword++;
81 }
82 rowi = (unsigned *) ((char *) rowi + rowsize);
83 }
84} 78}
85 79
86 80
87void 81void
88slist_add (SLIST **plist, char *str) 82slist_add(SLIST **plist, char *str)
89{ 83{
90 struct string_list *p = xmalloc (sizeof (*p)); 84 struct string_list *p = xmalloc(sizeof(*p));
91 p->str = str; 85 p->str = str;
92 p->next = NULL; 86 p->next = NULL;
93 87
94 if (!*plist) 88 if (!*plist) {
95 { 89 *plist = xmalloc(sizeof(**plist));
96 *plist = xmalloc (sizeof (**plist)); 90 (*plist)->head = NULL;
97 (*plist)->head = NULL; 91 }
98 } 92
99 93 if ((*plist)->head == NULL) {
100 if ((*plist)->head == NULL) 94 (*plist)->head = p;
101 { 95 (*plist)->count = 0;
102 (*plist)->head = p; 96 } else {
103 (*plist)->count = 0; 97 (*plist)->tail->next = p;
104 } 98 (*plist)->count++;
105 else 99 }
106 { 100 (*plist)->tail = p;
107 (*plist)->tail->next = p;
108 (*plist)->count++;
109 }
110 (*plist)->tail = p;
111} 101}
112 102
113void 103void
114slist_append (SLIST **pdst, SLIST *src) 104slist_append(SLIST **pdst, SLIST *src)
115{ 105{
116 struct string_list *tail; 106 struct string_list *tail;
117 107
118 if (!*pdst) 108 if (!*pdst) {
119 { 109 *pdst = xmalloc(sizeof(**pdst));
120 *pdst = xmalloc (sizeof (**pdst)); 110 (*pdst)->head = NULL;
121 (*pdst)->head = NULL; 111 (*pdst)->count = 0;
122 (*pdst)->count = 0; 112 }
123 }
124 113
125 if ((*pdst)->head = NULL) 114 if ((*pdst)->head = NULL)
126 (*pdst)->head = src->head; 115 (*pdst)->head = src->head;
127 116
128 for (tail = src->tail; tail->next; tail = tail->next) 117 for (tail = src->tail; tail->next; tail = tail->next)
129 ; 118 ;
130 119
131 (*pdst)->tail = tail; 120 (*pdst)->tail = tail;
132 (*pdst)->count += src->count; 121 (*pdst)->count += src->count;
133} 122}
134 123
135char * 124char *
136slist_member (SLIST *plist, char *name) 125slist_member(SLIST *plist, char *name)
137{ 126{
138 struct string_list *p; 127 struct string_list *p;
139 128
140 if (plist) 129 if (plist)
141 for (p = plist->head; p; p = p->next) 130 for (p = plist->head; p; p = p->next)
142 if (p->str && strcmp (p->str, name) == 0) 131 if (p->str && strcmp(p->str, name) == 0)
143 return p->str; 132 return p->str;
144 return NULL; 133 return NULL;
145} 134}
146 135
147void 136void
148slist_destroy (SLIST **plist) 137slist_destroy(SLIST **plist)
149{ 138{
150 struct string_list *p; 139 struct string_list *p;
151 if (!plist || !*plist) 140 if (!plist || !*plist)
152 return; 141 return;
153 p = (*plist)->head; 142 p = (*plist)->head;
154 while (p) 143 while (p) {
155 { 144 struct string_list *next = p->next;
156 struct string_list *next = p->next; 145 free(p);
157 free (p); 146 p = next;
158 p = next; 147 }
159 } 148 free(*plist);
160 free (*plist); 149 *plist = NULL;
161 *plist = NULL;
162} 150}
163 151
164 152
165typedef struct 153typedef struct {
166{ 154 char *name;
167 char *name; 155 SLIST *exp;
168 SLIST *exp;
169} ALIAS; 156} ALIAS;
170 157
171struct obstack alias_stk; 158struct obstack alias_stk;
@@ -173,149 +160,143 @@ unsigned alias_count;
173ALIAS *aliases; 160ALIAS *aliases;
174 161
175void 162void
176regalias (char *name, SLIST *exp) 163regalias(char *name, SLIST *exp)
177{ 164{
178 ALIAS a; 165 ALIAS a;
179 a.name = name; 166 a.name = name;
180 a.exp = exp; 167 a.exp = exp;
181 obstack_grow (&alias_stk, &a, sizeof a); 168 obstack_grow(&alias_stk, &a, sizeof a);
182 alias_count++; 169 alias_count++;
183} 170}
184 171
185void 172void
186begin_aliases () 173begin_aliases()
187{ 174{
188 obstack_init (&alias_stk); 175 obstack_init(&alias_stk);
189} 176}
190 177
191static int 178static int
192alias_cmp (const void *a, const void *b) 179alias_cmp(const void *a, const void *b)
193{ 180{
194 return strcmp (((ALIAS *) a)->name, ((ALIAS *) b)->name); 181 return strcmp(((ALIAS *) a)->name, ((ALIAS *) b)->name);
195} 182}
196 183
197static int 184static int
198alias_cmp2 (const void *a, const void *b) 185alias_cmp2(const void *a, const void *b)
199{ 186{
200 char *aname = ((ALIAS *) a)->name; 187 char *aname = ((ALIAS *) a)->name;
201 char *bname = ((ALIAS *) b)->name; 188 char *bname = ((ALIAS *) b)->name;
202 int rc; 189 int rc;
203 int alen; 190 int alen;
204 int blen; 191 int blen;
205 char *p; 192 char *p;
206 193
207 if ((p = strchr (aname, '@')) && slist_member (cw_list, p + 1)) 194 if ((p = strchr(aname, '@')) && slist_member(cw_list, p + 1))
208 alen = p - aname; 195 alen = p - aname;
209 else 196 else
210 alen = strlen (aname); 197 alen = strlen(aname);
211 198
212 if ((p = strchr (bname, '@')) && slist_member (cw_list, p + 1)) 199 if ((p = strchr(bname, '@')) && slist_member(cw_list, p + 1))
213 blen = p - bname; 200 blen = p - bname;
214 else 201 else
215 blen = strlen (bname); 202 blen = strlen(bname);
216 203
217 if (alen == blen) 204 if (alen == blen)
218 return memcmp (aname, bname, alen); 205 return memcmp(aname, bname, alen);
219 206
220 return strcmp (aname, bname); 207 return strcmp(aname, bname);
221} 208}
222 209
223void 210void
224end_aliases () 211end_aliases()
225{ 212{
226 int i; 213 int i;
227 aliases = obstack_finish (&alias_stk); 214 aliases = obstack_finish(&alias_stk);
228 qsort (aliases, alias_count, sizeof aliases[0], alias_cmp); 215 qsort(aliases, alias_count, sizeof aliases[0], alias_cmp);
229 for (i = 1; i < alias_count; i++) 216 for (i = 1; i < alias_count; i++)
230 if (alias_cmp (aliases + i - 1, aliases + i) == 0) 217 if (alias_cmp(aliases + i - 1, aliases + i) == 0) {
231 { 218 error(0, 0, "alias `%s' multiply defined", aliases[i].name);
232 error (0, 0, "alias `%s' multiply defined", aliases[i].name); 219 error_count++;
233 error_count++; 220 }
234 }
235} 221}
236 222
237 223
238int 224int
239find_alias (char *name) 225find_alias(char *name)
240{ 226{
241 ALIAS a, *p; 227 ALIAS a, *p;
242 228
243 if (!name) 229 if (!name)
244 return -1; 230 return -1;
245 a.name = name; 231 a.name = name;
246 p = bsearch (&a, aliases, alias_count, sizeof aliases[0], alias_cmp2); 232 p = bsearch(&a, aliases, alias_count, sizeof aliases[0], alias_cmp2);
247 return p ? p - aliases : -1; 233 return p ? p - aliases : -1;
248} 234}
249 235
250 236
251static void 237static void
252alias_setbit (unsigned *r, unsigned rowsize, unsigned row, unsigned col) 238alias_setbit(unsigned *r, unsigned rowsize, unsigned row, unsigned col)
253{ 239{
254 SETBIT (r + rowsize * row, col); 240 SETBIT(r + rowsize * row, col);
255} 241}
256 242
257static int 243static int
258alias_bitisset (unsigned *r, unsigned rowsize, unsigned row, unsigned col) 244alias_bitisset(unsigned *r, unsigned rowsize, unsigned row, unsigned col)
259{ 245{
260 return BITISSET (r + rowsize * row, col); 246 return BITISSET(r + rowsize * row, col);
261} 247}
262 248
263 249
264void 250void
265mark_connected (unsigned *r, unsigned size) 251mark_connected(unsigned *r, unsigned size)
266{ 252{
267 int i; 253 int i;
268 254
269 for (i = 0; i < alias_count; i++) 255 for (i = 0; i < alias_count; i++) {
270 { 256 if (aliases[i].exp) {
271 if (aliases[i].exp) 257 struct string_list *p;
272 { 258 for (p = aliases[i].exp->head; p; p = p->next) {
273 struct string_list *p; 259 int n = find_alias(p->str);
274 for (p = aliases[i].exp->head; p; p = p->next) 260 if (n >= 0)
275 { 261 alias_setbit(r, size, i, n);
276 int n = find_alias (p->str); 262 }
277 if (n >= 0) 263 }
278 alias_setbit (r, size, i, n);
279 }
280 } 264 }
281 }
282} 265}
283 266
284void 267void
285check_circular_deps (unsigned *r, unsigned size) 268check_circular_deps(unsigned *r, unsigned size)
286{ 269{
287 int i; 270 int i;
288 271
289 for (i = 0; i < alias_count; i++) 272 for (i = 0; i < alias_count; i++) {
290 { 273 if (alias_bitisset(r, size, i, i)) {
291 if (alias_bitisset (r, size, i, i)) 274 error(0, 0, "%s: circular dependency", aliases[i].name);
292 { 275 error_count++;
293 error (0, 0, "%s: circular dependency", aliases[i].name); 276 }
294 error_count++;
295 } 277 }
296 }
297} 278}
298 279
299void 280void
300check_aliases () 281check_aliases()
301{ 282{
302 size_t size; 283 size_t size;
303 unsigned *r; 284 unsigned *r;
304 285
305 /* Allocate matrix */ 286 /* Allocate matrix */
306 size = (alias_count + BITS_PER_WORD - 1) / BITS_PER_WORD; 287 size = (alias_count + BITS_PER_WORD - 1) / BITS_PER_WORD;
307 r = xmalloc (alias_count * size * sizeof (*r)); 288 r = xmalloc(alias_count * size * sizeof(*r));
308 memset (r, 0, alias_count * size * sizeof (*r)); 289 memset(r, 0, alias_count * size * sizeof(*r));
309 290
310 /* First pass: mark directly connected entries */ 291 /* First pass: mark directly connected entries */
311 mark_connected (r, size); 292 mark_connected(r, size);
312 293
313 /* Compute transitive closure of the matrix r */ 294 /* Compute transitive closure of the matrix r */
314 TC (r, alias_count); 295 TC(r, alias_count);
315 296
316 /* Third pass: check for circular deps */ 297 /* Third pass: check for circular deps */
317 check_circular_deps (r, size); 298 check_circular_deps(r, size);
318 299
319 if (verbose) 300 if (verbose)
320 printf ("%lu aliases\n", alias_count); 301 printf("%lu aliases\n", alias_count);
321} 302}
diff --git a/gram.y b/gram.y
index dd323be..34d46e2 100644
--- a/gram.y
+++ b/gram.y
@@ -25,8 +25,8 @@ int error_count; /* Number of errors detected so far */
25%} 25%}
26 26
27%union { 27%union {
28 char *string; 28 char *string;
29 SLIST *slist; 29 SLIST *slist;
30}; 30};
31 31
32%token <string> IDENT EMAIL STRING LHS 32%token <string> IDENT EMAIL STRING LHS
@@ -46,15 +46,15 @@ list : alias
46 | list EOL alias 46 | list EOL alias
47 | list error EOL 47 | list error EOL
48 { 48 {
49 yyclearin; 49 yyclearin;
50 yyerrok; 50 yyerrok;
51 } 51 }
52 ; 52 ;
53 53
54alias : /* empty */ 54alias : /* empty */
55 | lhs rhs 55 | lhs rhs
56 { 56 {
57 regalias ($1, $2); 57 regalias($1, $2);
58 } 58 }
59 ; 59 ;
60 60
@@ -64,43 +64,41 @@ lhs : LHS ':'
64rhs : emails 64rhs : emails
65 | rhs CONT emails 65 | rhs CONT emails
66 { 66 {
67 slist_append (&$1, $3); 67 slist_append(&$1, $3);
68 $$ = $1; 68 $$ = $1;
69 } 69 }
70 ; 70 ;
71 71
72emails: email 72emails: email
73 | emails ',' email 73 | emails ',' email
74 { 74 {
75 slist_append (&$1, $3); 75 slist_append(&$1, $3);
76 $$ = $1; 76 $$ = $1;
77 } 77 }
78 ; 78 ;
79 79
80email : string 80email : string
81 { 81 {
82 if (restricted && ($1[0] == '|' || $1[0] == '/')) 82 if (restricted && ($1[0] == '|' || $1[0] == '/')) {
83 { 83 yyerror("Construct not allowed");
84 yyerror ("Construct not allowed"); 84 YYERROR;
85 YYERROR; 85 }
86 } 86 $$ = NULL;
87 $$ = NULL; 87 slist_add(&$$, $1);
88 slist_add (&$$, $1);
89 } 88 }
90 | EMAIL 89 | EMAIL
91 { 90 {
92 $$ = NULL; 91 $$ = NULL;
93 slist_add (&$$, $1); 92 slist_add(&$$, $1);
94 } 93 }
95 | INCLUDE string 94 | INCLUDE string
96 { 95 {
97 if (restricted) 96 if (restricted) {
98 { 97 yyerror("Include statement is not allowed");
99 yyerror ("Include statement is not allowed"); 98 YYERROR;
100 YYERROR; 99 }
101 } 100 $$ = NULL;
102 $$ = NULL; 101 read_include(&$$, $2);
103 read_include (&$$, $2);
104 } 102 }
105 ; 103 ;
106 104
@@ -113,169 +111,163 @@ string: IDENT
113int 111int
114yyerror (char *s) 112yyerror (char *s)
115{ 113{
116 error_at_line (0, 0, file_name, line_num, "%s", s); 114 error_at_line(0, 0, file_name, line_num, "%s", s);
117 error_count++; 115 error_count++;
118} 116}
119 117
120 118
121void 119void
122usage () 120usage()
123{ 121{
124 printf ("usage: ckaliases [OPTIONS] [FILES...]\n"); 122 printf("usage: ckaliases [OPTIONS] [FILES...]\n");
125 printf ("OPTIONS and FILES may be interspered.\n"); 123 printf("OPTIONS and FILES may be interspered.\n");
126 printf ("Valid options are:\n"); 124 printf("Valid options are:\n");
127 printf (" -d,--debug=SPEC Set debug level. SPEC consists of the following\n"); 125 printf(" -d,--debug=SPEC Set debug level. SPEC consists of the following\n");
128 printf (" letters:\n"); 126 printf(" letters:\n");
129 printf (" y enable parser debugging\n"); 127 printf(" y enable parser debugging\n");
130 printf (" l enable lexical analizer debugging\n"); 128 printf(" l enable lexical analizer debugging\n");
131 printf (" Upper-case variants are also accepted. Prepending\n"); 129 printf(" Upper-case variants are also accepted. Prepending\n");
132 printf (" a letter with '-' reverts its sense\n"); 130 printf(" a letter with '-' reverts its sense\n");
133 printf (" -f, --files-from=FILE\n"); 131 printf(" -f, --files-from=FILE\n");
134 printf (" Read names of alias files from FILE\n"); 132 printf(" Read names of alias files from FILE\n");
135 printf (" -h, --help Display this help list\n"); 133 printf(" -h, --help Display this help list\n");
136 printf (" -r, --restrict Restrict alias file syntax to aliases only (i.e.\n"); 134 printf(" -r, --restrict Restrict alias file syntax to aliases only (i.e.\n");
137 printf (" prohibit use of pipes and file redirections\n"); 135 printf(" prohibit use of pipes and file redirections\n");
138 printf (" -u, --unrestrict Revert the effect of the previous -r option\n"); 136 printf(" -u, --unrestrict Revert the effect of the previous -r option\n");
139 printf (" -v, --verbose Verbose mode\n"); 137 printf(" -v, --verbose Verbose mode\n");
140 printf (" -V, --version print program version and exit\n"); 138 printf(" -V, --version print program version and exit\n");
141 printf (" -w FILE Read contents of Sendmail `w' class from the given\n"); 139 printf(" -w FILE Read contents of Sendmail `w' class from the given\n");
142 printf (" file.\n"); 140 printf(" file.\n");
143 printf ("\n"); 141 printf("\n");
144 printf ("Report bugs to <%s>\n", PACKAGE_BUGREPORT); 142 printf("Report bugs to <%s>\n", PACKAGE_BUGREPORT);
145} 143}
146 144
147struct option options[] = { 145struct option options[] = {
148 { "debug", required_argument, NULL, 'd' }, 146 { "debug", required_argument, NULL, 'd' },
149 { "help", no_argument, NULL, 'h' }, 147 { "help", no_argument, NULL, 'h' },
150 { "version", no_argument, NULL, 'V' }, 148 { "version", no_argument, NULL, 'V' },
151 { "restrict", no_argument, NULL, 'r' }, 149 { "restrict", no_argument, NULL, 'r' },
152 { "unrestrict", no_argument, NULL, 'u' }, 150 { "unrestrict", no_argument, NULL, 'u' },
153 { "verbose", no_argument, NULL, 'v' }, 151 { "verbose", no_argument, NULL, 'v' },
154 { "files-from", required_argument, NULL, 'f' }, 152 { "files-from", required_argument, NULL, 'f' },
155 { NULL } 153 { NULL }
156}; 154};
157 155
158int 156int
159main (int argc, char **argv) 157main(int argc, char **argv)
160{ 158{
161 char *p; 159 char *p;
162 int c; 160 int c;
163 int file_count = 0; 161 int file_count = 0;
164 int true = 1; 162 int true = 1;
165 char *cwfile = "/etc/mail/sendmail.cw"; 163 char *cwfile = "/etc/mail/sendmail.cw";
166 SLIST *file_list; /* List of files to be read */ 164 SLIST *file_list; /* List of files to be read */
167 struct string_list *s; 165 struct string_list *s;
168 166
169 begin_aliases (); 167 begin_aliases();
170 init_lex (); 168 init_lex ();
171 program_name = argv[0]; 169 program_name = argv[0];
172 while ((c = getopt_long (argc, argv, "-d:f:hp:ruvw:", options, NULL)) != EOF) 170 while ((c = getopt_long(argc, argv, "-d:f:hp:ruvw:",
173 { 171 options, NULL)) != EOF) {
174 switch (c) 172 switch (c) {
175 { 173 case 1:
176 case 1: 174 if (!cw_list)
177 if (!cw_list) 175 read_include(&cw_list, cwfile);
178 read_include (&cw_list, cwfile); 176 openaliases(optarg);
179 openaliases (optarg); 177 yyparse();
180 yyparse (); 178 file_count++;
181 file_count++; 179 break;
182 break;
183 180
184 case 'd': 181 case 'd':
185 for (p = optarg; *p; p++) 182 for (p = optarg; *p; p++) {
186 { 183 switch (*p) {
187 switch (*p) 184 case '-':
188 { 185 true = 0;
189 case '-': 186 break;
190 true = 0; 187
191 break; 188 case 'y':
192 189 case 'Y':
193 case 'y': 190 yydebug = true;
194 case 'Y': 191 true = 1;
195 yydebug = true; 192 break;
196 true = 1; 193
197 break; 194 case 'l':
198 195 case 'L':
199 case 'l': 196 lex_debug(true);
200 case 'L': 197 true = 1;
201 lex_debug (true); 198 break;
202 true = 1; 199
203 break; 200 default:
204 201 error(1, 0, "%s: unknown debug option %c", argv[0]);
205 default: 202 }
206 error (1, 0, "%s: unknown debug option %c", argv[0]); 203 }
207 } 204 break;
208 } 205
209 break; 206 case 'f':
210 207 if (!cw_list)
211 case 'f': 208 read_include(&cw_list, cwfile);
212 if (!cw_list) 209 file_list = NULL;
213 read_include (&cw_list, cwfile); 210 read_include(&file_list, optarg);
214 file_list = NULL; 211 if (file_list) {
215 read_include (&file_list, optarg); 212 for (s = file_list->head; s; s = s->next) {
216 if (file_list) 213 openaliases_prefix(optarg, s->str);
217 { 214 yyparse();
218 for (s = file_list->head; s; s = s->next) 215 file_count++;
219 { 216 }
220 openaliases_prefix (optarg, s->str); 217 slist_destroy(&file_list);
221 yyparse (); 218 }
222 file_count++; 219 break;
223 }
224 slist_destroy (&file_list);
225 }
226 break;
227 220
228 case 'h': 221 case 'h':
229 usage (); 222 usage();
230 exit (0); 223 exit(0);
231 224
232 case 'r': 225 case 'r':
233 restricted = 1; 226 restricted = 1;
234 break; 227 break;
235 228
236 case 'u': 229 case 'u':
237 restricted = 0; 230 restricted = 0;
238 break; 231 break;
239 232
240 case 'v': 233 case 'v':
241 verbose++; 234 verbose++;
242 break; 235 break;
243 236
244 case 'V': 237 case 'V':
245 gsc_version ("ckaliases"); 238 gsc_version ("ckaliases");
246 exit (0); 239 exit (0);
247
248 case 'w':
249 if (file_count)
250 error (1, 0, "-w must be used before first non-option argument");
251 cwfile = optarg;
252 break;
253 240
254 default: 241 case 'w':
255 exit (1); 242 if (file_count)
243 error(1, 0, "-w must be used before first non-option argument");
244 cwfile = optarg;
245 break;
246
247 default:
248 exit (1);
249 }
250 }
251
252 argc -= optind;
253 argv += optind;
254
255 if (!cw_list)
256 read_include(&cw_list, cwfile);
257 while (argc--) {
258 openaliases(*argv++);
259 yyparse();
260 file_count++;
256 } 261 }
257 }
258
259 argc -= optind;
260 argv += optind;
261
262 if (!cw_list)
263 read_include (&cw_list, cwfile);
264 while (argc--)
265 {
266 openaliases (*argv++);
267 yyparse ();
268 file_count++;
269 }
270 262
271 if (!file_count) 263 if (!file_count)
272 error (1, 0, "no files specified"); 264 error(1, 0, "no files specified");
273 265
274 if (verbose) 266 if (verbose)
275 printf ("%d files\n", file_count); 267 printf("%d files\n", file_count);
276 end_aliases (); 268 end_aliases();
277 check_aliases (); 269 check_aliases();
278 if (verbose) 270 if (verbose)
279 printf ("%lu errors\n", error_count); 271 printf("%lu errors\n", error_count);
280 exit (error_count!=0); 272 exit(error_count!=0);
281} 273}
diff --git a/lex.l b/lex.l
index ba48a9c..c71d4b9 100644
--- a/lex.l
+++ b/lex.l
@@ -44,32 +44,32 @@ SPEC [:@\\]
44 /* Names and emails */ 44 /* Names and emails */
45:include: return INCLUDE; 45:include: return INCLUDE;
46^{IDENT} { 46^{IDENT} {
47 line_begin (); 47 line_begin();
48 line_add (yytext, yyleng); 48 line_add(yytext, yyleng);
49 line_finish (); 49 line_finish ();
50 return LHS; } 50 return LHS; }
51{IDENT}@{IDENT} { 51{IDENT}@{IDENT} {
52 line_begin (); 52 line_begin();
53 line_add (yytext, yyleng); 53 line_add(yytext, yyleng);
54 line_finish (); 54 line_finish();
55 return EMAIL; } 55 return EMAIL; }
56{IDENT} { line_begin (); 56{IDENT} { line_begin();
57 line_add (yytext, yyleng); 57 line_add(yytext, yyleng);
58 line_finish (); 58 line_finish();
59 return IDENT; } 59 return IDENT; }
60 /* Quoted strings */ 60 /* Quoted strings */
61\"[^\\"\n]*\" { line_begin (); 61\"[^\\"\n]*\" { line_begin();
62 line_add (yytext, yyleng); 62 line_add(yytext, yyleng);
63 line_finish (); 63 line_finish();
64 return STRING; } 64 return STRING; }
65\"[^\\"\n]*\\. { BEGIN (STR); 65\"[^\\"\n]*\\. { BEGIN(STR);
66 line_begin (); 66 line_begin();
67 line_add_unescape (yytext + 1, yyleng - 1); } 67 line_add_unescape(yytext + 1, yyleng - 1); }
68<STR>[^\\"\n]*\\. { line_add_unescape (yytext, yyleng); } 68<STR>[^\\"\n]*\\. { line_add_unescape(yytext, yyleng); }
69<STR>[^\\"\n]*\" { BEGIN (INITIAL); 69<STR>[^\\"\n]*\" { BEGIN(INITIAL);
70 if (yyleng > 1) 70 if (yyleng > 1)
71 line_add (yytext, yyleng - 1); 71 line_add(yytext, yyleng - 1);
72 line_finish (); 72 line_finish();
73 return STRING; } 73 return STRING; }
74 /* Other characters */ 74 /* Other characters */
75{SPEC} return yytext[0]; 75{SPEC} return yytext[0];
@@ -77,135 +77,131 @@ SPEC [:@\\]
77\n{WS}+/[^ \t\n] { line_num++; return CONT; } 77\n{WS}+/[^ \t\n] { line_num++; return CONT; }
78\n { line_num++; return EOL; } 78\n { line_num++; return EOL; }
79 ,return yytext[0]; 79 ,return yytext[0];
80. { error_at_line (0, 0, file_name, line_num, 80. { error_at_line(0, 0, file_name, line_num,
81 "Stray character %03o in alias file", yytext[0]); 81 "Stray character %03o in alias file", yytext[0]);
82 error_count++; } 82 error_count++; }
83%% 83%%
84 84
85int 85int
86yywrap () 86yywrap()
87{ 87{
88 fclose (yyin); 88 fclose(yyin);
89 return 1; 89 return 1;
90} 90}
91 91
92static char escape_transtab[] = "\\\\a\ab\bf\fn\nr\rt\t"; 92static char escape_transtab[] = "\\\\a\ab\bf\fn\nr\rt\t";
93 93
94int 94int
95unescape_char (int c) 95unescape_char(int c)
96{ 96{
97 char *p; 97 char *p;
98 98
99 for (p = escape_transtab; *p; p += 2) 99 for (p = escape_transtab; *p; p += 2) {
100 { 100 if (*p == c)
101 if (*p == c) 101 return p[1];
102 return p[1]; 102 }
103 } 103 return c;
104 return c;
105} 104}
106 105
107void 106void
108line_add (char *text, size_t len) 107line_add(char *text, size_t len)
109{ 108{
110 obstack_grow (&string_stk, text, len); 109 obstack_grow(&string_stk, text, len);
111} 110}
112 111
113void 112void
114line_add_unescape (char *text, size_t len) 113line_add_unescape(char *text, size_t len)
115{ 114{
116 char c; 115 char c;
117 obstack_grow (&string_stk, text, len - 2); 116 obstack_grow(&string_stk, text, len - 2);
118 c = unescape_char (text[len - 1]); 117 c = unescape_char(text[len - 1]);
119 obstack_1grow (&string_stk, c); 118 obstack_1grow(&string_stk, c);
120} 119}
121 120
122void 121void
123line_begin () 122line_begin()
124{ 123{
125} 124}
126 125
127void 126void
128line_finish () 127line_finish ()
129{ 128{
130 obstack_1grow (&string_stk, 0); 129 obstack_1grow(&string_stk, 0);
131 yylval.string = obstack_finish (&string_stk); 130 yylval.string = obstack_finish(&string_stk);
132} 131}
133 132
134void 133void
135openaliases (char *name) 134openaliases(char *name)
136{ 135{
137 yyin = fopen (name, "r"); 136 yyin = fopen (name, "r");
138 if (!yyin) 137 if (!yyin)
139 error (1, errno, "cannot open file `%s'", name); 138 error(1, errno, "cannot open file `%s'", name);
140 file_name = name; 139 file_name = name;
141 line_num = 0; 140 line_num = 0;
142} 141}
143 142
144void 143void
145openaliases_prefix (char *prefix, char *name) 144openaliases_prefix(char *prefix, char *name)
146{ 145{
147 char *fullname = NULL; 146 char *fullname = NULL;
148 struct stat st; 147 struct stat st;
149 148
150 if (stat (prefix, &st)) 149 if (stat(prefix, &st))
151 error (1, errno, "cannot stat `%s'", prefix); 150 error(1, errno, "cannot stat `%s'", prefix);
152 151
153 if (!S_ISDIR (st.st_mode)) 152 if (!S_ISDIR(st.st_mode)) {
154 { 153 char *p = strrchr(prefix, '/');
155 char *p = strrchr (prefix, '/'); 154 if (p)
156 if (p) 155 *p = 0;
157 *p = 0; 156 else
158 else 157 prefix = ".";
159 prefix = "."; 158 }
160 } 159 asprintf(&fullname, "%s/%s", prefix, name);
161 asprintf (&fullname, "%s/%s", prefix, name); 160 openaliases(fullname);
162 openaliases (fullname); 161 free(fullname);
163 free (fullname);
164} 162}
165 163
166void 164void
167init_lex () 165init_lex()
168{ 166{
169 obstack_init (&string_stk); 167 obstack_init(&string_stk);
170 yy_flex_debug = 0; 168 yy_flex_debug = 0;
171} 169}
172 170
173void 171void
174lex_debug (int debug) 172lex_debug(int debug)
175{ 173{
176 yy_flex_debug = debug; 174 yy_flex_debug = debug;
177} 175}
178 176
179void 177void
180read_include (SLIST **plist, char *name) 178read_include(SLIST **plist, char *name)
181{ 179{
182 char *p; 180 char *p;
183 char buffer[256]; 181 char buffer[256];
184 FILE *fp = fopen (name, "r"); 182 FILE *fp = fopen(name, "r");
185 183
186 if (!fp) 184 if (!fp) {
187 { 185 error_at_line(0, 0, file_name, line_num,
188 error_at_line (0, 0, file_name, line_num, 186 "cannot open include file `%s': %s",
189 "cannot open include file `%s': %s", 187 name, strerror(errno));
190 name, strerror (errno)); 188 error_count++;
191 error_count++; 189 return;
192 return; 190 }
193 } 191
194 192 while (p = fgets(buffer, sizeof buffer, fp)) {
195 while (p = fgets (buffer, sizeof buffer, fp)) 193 char *q;
196 {
197 char *q;
198 194
199 while (*p && isspace (*p)) 195 while (*p && isspace(*p))
200 p++; 196 p++;
201 if (*p == '#') 197 if (*p == '#')
202 continue; 198 continue;
203 for (q = p + strlen (p) - 1; q > p && isspace (*q); q--) 199 for (q = p + strlen(p) - 1; q > p && isspace(*q); q--)
204 ; 200 ;
205 q[1] = 0; 201 q[1] = 0;
206 if (*p) 202 if (*p)
207 slist_add (plist, strdup (p)); 203 slist_add(plist, strdup(p));
208 } 204 }
209 fclose (fp); 205 fclose(fp);
210} 206}
211 207

Return to:

Send suggestions and report system problems to the System administrator.