diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-08-24 20:38:54 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-08-24 20:38:54 +0000 |
commit | ab736c0b1959c6c605c210d5fd9665bfe002042e (patch) | |
tree | e23a335c9a0e81505c9c06ba089e776200e1d443 /gram.y | |
parent | ed4ec220dcfcba29a7fc8ff161999c32a98e4430 (diff) | |
download | alck-ab736c0b1959c6c605c210d5fd9665bfe002042e.tar.gz alck-ab736c0b1959c6c605c210d5fd9665bfe002042e.tar.bz2 |
* lib/version.c: New file
* lib/gsc.h (gsc_version): New function
* cvs/Makefile.am, ckaliases/Makefile.am, wydawca/Makefile.am,
lib/Makefile.am, jabberd/Makefile.am: Fix include dirs
* ckaliases/ckaliases.c, ckaliases/lex.l, ckaliases/ckaliases.h,
ckaliases/gram.y: Use long options. Implement --version
* wydawca/wydawca.c, jabberd/main.c: Use gsc_version to display
program version.
* doc/gsc.texi: Update
* bootstrap: Add vasprintf
git-svn-id: file:///svnroot/gsc/trunk@289 d2de0444-eb31-0410-8365-af798a554d48
Diffstat (limited to 'gram.y')
-rw-r--r-- | gram.y | 336 |
1 files changed, 172 insertions, 164 deletions
@@ -1,6 +1,6 @@ | |||
1 | %{ | 1 | %{ |
2 | /* ckaliases - verify syntax of sendmail-style alias files | 2 | /* ckaliases - verify syntax of sendmail-style alias files |
3 | Copyright (C) 2005 Sergey Poznyakoff | 3 | Copyright (C) 2005, 2007 Sergey Poznyakoff |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify it | 5 | This program is free software; you can redistribute it and/or modify it |
6 | under the terms of the GNU General Public License as published by the | 6 | under the terms of the GNU General Public License as published by the |
@@ -15,23 +15,18 @@ | |||
15 | You should have received a copy of the GNU General Public License along | 15 | You should have received a copy of the GNU General Public License along |
16 | with this program. If not, see <http://www.gnu.org/licenses/>. */ | 16 | with this program. If not, see <http://www.gnu.org/licenses/>. */ |
17 | 17 | ||
18 | #include <stdio.h> | ||
19 | #include <stdlib.h> | ||
20 | #include <stdarg.h> | ||
21 | #include <getopt.h> | ||
22 | #include <errno.h> | ||
23 | #include "ckaliases.h" | 18 | #include "ckaliases.h" |
24 | 19 | ||
25 | SLIST *cw_list; /* List of domain names pertaining to Sendmail 'w' class */ | 20 | SLIST *cw_list; /* List of domain names pertaining to Sendmail 'w' class */ |
26 | static int restricted; /* prohibit use of `special' aliases (pipes, file redirections | 21 | static int restricted; /* prohibit use of `special' aliases (pipes, |
27 | and includes */ | 22 | file redirections and includes */ |
28 | int verbose; /* Verbose mode */ | 23 | int verbose; /* Verbose mode */ |
29 | static int error_count; /* Number of errors detected so far */ | 24 | int error_count; /* Number of errors detected so far */ |
30 | %} | 25 | %} |
31 | 26 | ||
32 | %union { | 27 | %union { |
33 | char *string; | 28 | char *string; |
34 | SLIST *slist; | 29 | SLIST *slist; |
35 | }; | 30 | }; |
36 | 31 | ||
37 | %token <string> IDENT EMAIL STRING LHS | 32 | %token <string> IDENT EMAIL STRING LHS |
@@ -51,15 +46,15 @@ list : alias | |||
51 | | list EOL alias | 46 | | list EOL alias |
52 | | list error EOL | 47 | | list error EOL |
53 | { | 48 | { |
54 | yyclearin; | 49 | yyclearin; |
55 | yyerrok; | 50 | yyerrok; |
56 | } | 51 | } |
57 | ; | 52 | ; |
58 | 53 | ||
59 | alias : /* empty */ | 54 | alias : /* empty */ |
60 | | lhs rhs | 55 | | lhs rhs |
61 | { | 56 | { |
62 | regalias($1, $2); | 57 | regalias ($1, $2); |
63 | } | 58 | } |
64 | ; | 59 | ; |
65 | 60 | ||
@@ -69,41 +64,43 @@ lhs : LHS ':' | |||
69 | rhs : emails | 64 | rhs : emails |
70 | | rhs CONT emails | 65 | | rhs CONT emails |
71 | { | 66 | { |
72 | slist_append(&$1, $3); | 67 | slist_append (&$1, $3); |
73 | $$ = $1; | 68 | $$ = $1; |
74 | } | 69 | } |
75 | ; | 70 | ; |
76 | 71 | ||
77 | emails: email | 72 | emails: email |
78 | | emails ',' email | 73 | | emails ',' email |
79 | { | 74 | { |
80 | slist_append(&$1, $3); | 75 | slist_append (&$1, $3); |
81 | $$ = $1; | 76 | $$ = $1; |
82 | } | 77 | } |
83 | ; | 78 | ; |
84 | 79 | ||
85 | email : string | 80 | email : string |
86 | { | 81 | { |
87 | if (restricted && ($1[0] == '|' || $1[0] == '/')) { | 82 | if (restricted && ($1[0] == '|' || $1[0] == '/')) |
88 | yyerror("Construct not allowed"); | 83 | { |
89 | YYERROR; | 84 | yyerror ("Construct not allowed"); |
90 | } | 85 | YYERROR; |
91 | $$ = NULL; | 86 | } |
92 | slist_add(&$$, $1); | 87 | $$ = NULL; |
88 | slist_add (&$$, $1); | ||
93 | } | 89 | } |
94 | 90 | ||
95 | { | 91 | { |
96 | $$ = NULL; | 92 | $$ = NULL; |
97 | slist_add(&$$, $1); | 93 | slist_add (&$$, $1); |
98 | } | 94 | } |
99 | | INCLUDE string | 95 | | INCLUDE string |
100 | { | 96 | { |
101 | if (restricted) { | 97 | if (restricted) |
102 | yyerror("Include statement is not allowed"); | 98 | { |
103 | YYERROR; | 99 | yyerror ("Include statement is not allowed"); |
104 | } | 100 | YYERROR; |
105 | $$ = NULL; | 101 | } |
106 | read_include(&$$, $2); | 102 | $$ = NULL; |
103 | read_include (&$$, $2); | ||
107 | } | 104 | } |
108 | ; | 105 | ; |
109 | 106 | ||
@@ -113,156 +110,167 @@ string: IDENT | |||
113 | 110 | ||
114 | %% | 111 | %% |
115 | 112 | ||
116 | void | 113 | int |
117 | error(char *fmt, ...) | 114 | yyerror (char *s) |
118 | { | ||
119 | va_list ap; | ||
120 | va_start(ap, fmt); | ||
121 | vfprintf(stderr, fmt, ap); | ||
122 | va_end(ap); | ||
123 | fprintf(stderr, "\n"); | ||
124 | error_count++; | ||
125 | } | ||
126 | |||
127 | yyerror(char *s) | ||
128 | { | 115 | { |
129 | error("%s:%d: %s", file_name, line_num, s); | 116 | error_at_line (0, 0, file_name, line_num, "%s", s); |
117 | error_count++; | ||
130 | } | 118 | } |
131 | 119 | ||
132 | |||
133 | 120 | ||
134 | void | 121 | void |
135 | usage() | 122 | usage () |
136 | { | 123 | { |
137 | printf("usage: ckaliases [OPTIONS] [FILES...]\n"); | 124 | printf ("usage: ckaliases [OPTIONS] [FILES...]\n"); |
138 | printf("OPTIONS and FILES may be interspered.\n"); | 125 | printf ("OPTIONS and FILES may be interspered.\n"); |
139 | printf("Valid options are:\n"); | 126 | printf ("Valid options are:\n"); |
140 | printf(" -d SPEC Set debug level. SPEC consists of the following\n"); | 127 | printf (" -d,--debug=SPEC Set debug level. SPEC consists of the following\n"); |
141 | printf(" letters:\n"); | 128 | printf (" letters:\n"); |
142 | printf(" y enable parser debugging\n"); | 129 | printf (" y enable parser debugging\n"); |
143 | printf(" l enable lexical analizer debugging\n"); | 130 | printf (" l enable lexical analizer debugging\n"); |
144 | printf(" Upper-case variants are also accepted. Prepending\n"); | 131 | printf (" Upper-case variants are also accepted. Prepending\n"); |
145 | printf(" a letter with '-' reverts its sense\n"); | 132 | printf (" a letter with '-' reverts its sense\n"); |
146 | printf(" -h Display this help list\n"); | 133 | printf (" -f, --files-from=FILE\n"); |
147 | printf(" -r Restrict alias file syntax to aliases only (i.e.\n"); | 134 | printf (" Read names of alias files from FILE\n"); |
148 | printf(" prohibit use of pipes and file redirections\n"); | 135 | printf (" -h, --help Display this help list\n"); |
149 | printf(" -u Revert the effect of the previous -r option\n"); | 136 | printf (" -r, --restrict Restrict alias file syntax to aliases only (i.e.\n"); |
150 | printf(" -v Verbose mode\n"); | 137 | printf (" prohibit use of pipes and file redirections\n"); |
151 | printf(" -w FILE Read contents of Sendmail `w' class from the given\n"); | 138 | printf (" -u, --unrestrict Revert the effect of the previous -r option\n"); |
152 | printf(" file.\n"); | 139 | printf (" -v, --verbose Verbose mode\n"); |
140 | printf (" -V, --version print program version and exit\n"); | ||
141 | printf (" -w FILE Read contents of Sendmail `w' class from the given\n"); | ||
142 | printf (" file.\n"); | ||
153 | } | 143 | } |
154 | 144 | ||
145 | struct option options[] = { | ||
146 | { "debug", required_argument, NULL, 'd' }, | ||
147 | { "help", no_argument, NULL, 'h' }, | ||
148 | { "version", no_argument, NULL, 'V' }, | ||
149 | { "restrict", no_argument, NULL, 'r' }, | ||
150 | { "unrestrict", no_argument, NULL, 'u' }, | ||
151 | { "verbose", no_argument, NULL, 'v' }, | ||
152 | { "files-from", required_argument, NULL, 'f' }, | ||
153 | { NULL } | ||
154 | }; | ||
155 | 155 | ||
156 | int | 156 | int |
157 | main(int argc, char **argv) | 157 | main (int argc, char **argv) |
158 | { | 158 | { |
159 | char *p; | 159 | char *p; |
160 | int c; | 160 | int c; |
161 | int file_count = 0; | 161 | int file_count = 0; |
162 | int true = 1; | 162 | int true = 1; |
163 | char *cwfile = "/etc/mail/sendmail.cw"; | 163 | char *cwfile = "/etc/mail/sendmail.cw"; |
164 | SLIST *file_list; /* List of files to be read */ | 164 | SLIST *file_list; /* List of files to be read */ |
165 | struct string_list *s; | 165 | struct string_list *s; |
166 | 166 | ||
167 | begin_aliases(); | 167 | begin_aliases (); |
168 | init_lex(); | 168 | init_lex (); |
169 | while ((c = getopt(argc, argv, "-d:f:hp:ruvw:")) != EOF) { | 169 | program_name = argv[0]; |
170 | switch (c) { | 170 | while ((c = getopt_long (argc, argv, "-d:f:hp:ruvw:", options, NULL)) != EOF) |
171 | case 1: | 171 | { |
172 | if (!cw_list) | 172 | switch (c) |
173 | read_include(&cw_list, cwfile); | 173 | { |
174 | openaliases(optarg); | 174 | case 1: |
175 | yyparse(); | 175 | if (!cw_list) |
176 | file_count++; | 176 | read_include (&cw_list, cwfile); |
177 | break; | 177 | openaliases (optarg); |
178 | yyparse (); | ||
179 | file_count++; | ||
180 | break; | ||
178 | 181 | ||
179 | case 'd': | 182 | case 'd': |
180 | for (p = optarg; *p; p++) { | 183 | for (p = optarg; *p; p++) |
181 | switch (*p) { | 184 | { |
182 | case '-': | 185 | switch (*p) |
183 |