aboutsummaryrefslogtreecommitdiff
path: root/gram.y
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-03-04 21:44:25 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2013-03-04 21:44:25 +0200
commita75760ff7d9bedcb1377fc3441f5e38178da1d6a (patch)
tree39413a06ee259848dfc2cb585a357ddac5d2d4ca /gram.y
parent860ec4960ff61cf3b2e98e0d020e7f8a93a56008 (diff)
downloadalck-a75760ff7d9bedcb1377fc3441f5e38178da1d6a.tar.gz
alck-a75760ff7d9bedcb1377fc3441f5e38178da1d6a.tar.bz2
Switch to a "right" style.
Diffstat (limited to 'gram.y')
-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]);