summaryrefslogtreecommitdiffabout
path: root/gram.y
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 /gram.y
parent860ec4960ff61cf3b2e98e0d020e7f8a93a56008 (diff)
downloadalck-a75760ff7d9bedcb1377fc3441f5e38178da1d6a.tar.gz
alck-a75760ff7d9bedcb1377fc3441f5e38178da1d6a.tar.bz2
Switch to a "right" style.
Diffstat (limited to 'gram.y') (more/less context) (ignore whitespace changes)
-rw-r--r--gram.y330
1 files changed, 161 insertions, 169 deletions
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}

Return to:

Send suggestions and report system problems to the System administrator.