chiark / gitweb /
8d4088caa94105c09713c0689a6993c51e0b84d8
[userv.git] / language.i4
1 dnl  userv - language.i4
2 dnl  definition of the configuration language, used for tokens.h and lexer.l
3 dnl
4 dnl  Copyright (C)1996-1997 Ian Jackson
5 dnl
6 dnl  This is free software; you can redistribute it and/or modify it
7 dnl  under the terms of the GNU General Public License as published by
8 dnl  the Free Software Foundation; either version 2 of the License, or
9 dnl  (at your option) any later version.
10 dnl
11 dnl  This program is distributed in the hope that it will be useful, but
12 dnl  WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 dnl  General Public License for more details.
15 dnl
16 dnl  You should have received a copy of the GNU General Public License
17 dnl  along with userv; if not, write to the Free Software
18 dnl  Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 dnl  Diversions are
21 dnl   1,2,4: sections of token enum list
22 dnl   3:     flex rules
23
24 divert(-1)
25
26 define(`makename',`translit(``$1'',`-_')')
27
28 define(`hasvalistype',`pushdef(`odiv',divnum)dnl
29 divert(1)dnl
30   format(``%-50s'',`toki_$1=')`$2',
31 divert(2)dnl
32   format(``%-30s'',`tokv_$1=')`$3|toki_$1',
33 divert(odiv)popdef(`odiv')')
34
35 define(`cautotoki',`01')
36 define(`cautotokt',eval(`010000'))
37
38 define(`autovalistype',`hasvalistype(`$1',format(``0%03o'',cautotoki),`$2')`'define(`cautotoki',incr(cautotoki))')
39
40 define(`autovaldeftype',`pushdef(`odiv',divnum)divert(4)dnl
41   format(``%-25s'',`tokt_$1=')format(``0%011o'',cautotokt),
42 divert(odiv)popdef(`odiv')define(`cautotokt',eval(cautotokt`*2'))')
43
44 define(`nametypelexpatexec',`
45 autovalistype(`$1',`$2')
46 pushdef(`odiv',divnum)divert(3)dnl
47 `$3 { $4'`atnewline= 0; return tokv_$1; }'
48 divert(odiv)popdef(`odiv')')
49
50 define(`wordtypelexexec',
51 `nametypelexpatexec(`word_'makename(`$1'),`$2|tokr_word',`$1',`$3')')
52
53 dnl types
54 autovaldeftype(`directive')
55 autovaldeftype(`controlstart')
56 autovaldeftype(`controlend')
57 autovaldeftype(`exception')
58 autovaldeftype(`parmcondition')
59 autovaldeftype(`condop')
60 autovaldeftype(`parameter')
61 autovaldeftype(`number')
62 autovaldeftype(`fdrange')
63 autovaldeftype(`logfacility')
64 autovaldeftype(`loglevel')
65 autovaldeftype(`readwrite')
66 autovaldeftype(`string')
67 autovaldeftype(`execmode')
68 autovaldeftype(`ehandlemode')
69 autovaldeftype(`misc')
70
71 dnl simple isdirectives
72 define(`isdirectivefn',`dnl
73 wordtypelexexec(`$1',`tokt_directive$3',`lr_dir= $2; $4')dnl
74 pushdef(`odiv',divnum)
75 divert(odiv)popdef(`odiv')')
76 define(`isdirective',`isdirectivefn(`$1',`df_'makename(`$1'),`$2')')
77 define(`isdirectiveinternal',`isdirectivefn(`$1',`dfi_'makename(`$1'),`$2')')
78 define(`isexecmode',`isdirective(`$1',`|tokt_execmode')')
79 define(`isehandlemode',`isdirective(`$1',`|tokt_ehandlemode')')
80 define(`isfdwant',`isdirectivefn(`$1',`dfg_fdwant',`',
81                       `lr_fdwant_readwrite=$2; ')')
82 define(`isflagpair',`isdirectivefn(`$1',`dfg_setflag',`',
83                       `lr_flag= &'makename(`$1')`; lr_flagval= 1; ')
84                      isdirectivefn(`no-$1',`dfg_setflag',`',
85                       `lr_flag= &'makename(`$1')`; lr_flagval= 0; ')')
86 isexecmode(`reject')
87 isexecmode(`execute')
88 isexecmode(`execute-from-directory')
89 isexecmode(`execute-from-path')
90 isehandlemode(`errors-to-stderr')
91 isehandlemode(`errors-to-syslog')
92 isehandlemode(`errors-to-file')
93 isfdwant(`require-fd',`1')
94 isfdwant(`allow-fd',`0')
95 isfdwant(`null-fd',`0')
96 isfdwant(`reject-fd',`-1')
97 isfdwant(`ignore-fd',`-1')
98 isflagpair(`set-environment')
99 isflagpair(`suppress-args')
100 isflagpair(`disconnect-hup')
101 isdirective(`cd')
102 isdirective(`reset')
103 isdirective(`user-rcfile')
104 isdirective(`include')
105 isdirectivefn(`include-ifexist',`df_include')
106 isdirective(`include-lookup')
107 isdirectivefn(`include-lookup-all',`df_includelookup')
108 isdirective(`include-directory')
109 isdirective(`message')
110 isdirectivefn(`_include-sysconfig',`df_include')
111 isdirectiveinternal(`_include-user-rcfile')
112 isdirectiveinternal(`_include-client-config')
113
114 dnl quit and eof are each a directive _and_ an exception
115 dnl as separate tokens.  A true end of file is returned by yylex
116 dnl as the exception.  The directive (word) tokens are
117 dnl tokv_word_{eof,quit}; the exceptions are tokv_{eof,quit}.
118 isdirective(`quit')
119 isdirective(`eof')
120
121 dnl control construct starters
122 define(`iscontrolstart',
123 `isdirective(`$1',`|tokt_controlstart')')
124 iscontrolstart(`if')
125 iscontrolstart(`catch-quit')
126 iscontrolstart(`errors-push')
127
128 dnl control construct enders
129 define(`iscontrolend',
130 `wordtypelexexec(`$1',`tokt_controlend$3',
131                  `lr_controlend= tokv_word_'makename(`$2')`; ')')
132 iscontrolend(`elif',   `if', `|tokt_controlstart')
133 iscontrolend(`else',   `if', `|tokt_controlstart')
134 iscontrolend(`fi',     `if')
135 iscontrolend(`hctac',  `catch-quit')
136 iscontrolend(`srorre', `errors-push')
137
138 dnl conditions
139 define(`isparmcondition',`wordtypelexexec(`$1',`tokt_parmcondition',
140                            `lr_parmcond= pcf_'makename(`$1')`; ')')
141 isparmcondition(`glob')
142 isparmcondition(`range')
143 isparmcondition(`grep')
144
145 dnl parameters
146 define(`isparameter',`wordtypelexexec(`$1',`tokt_parameter',
147                         `lr_parameter= pf_'makename(`$1')`; ')')
148 isparameter(`service')
149 isparameter(`calling-user')
150 isparameter(`calling-group')
151 isparameter(`calling-user-shell')
152 isparameter(`service-user')
153 isparameter(`service-group')
154 isparameter(`service-user-shell')
155
156 dnl syslog levels
157 define(`isloglevellexpat',
158 `nametypelexpatexec(`syslog_$1',`tokt_loglevel|tokr_word',`$2',
159                     `lr_loglevel= LOG_'translit(``$1'',`a-z',`A-Z')`; ')')
160 define(`isloglevel',`isloglevellexpat(`$1',`$1')')
161 isloglevel(`debug')
162 isloglevel(`info')
163 isloglevel(`notice')
164 isloglevellexpat(`warning',`warn(ing)?')
165 isloglevel(`err')dnl also the word error, which has dual meaning (below)
166 isloglevel(`crit')
167 isloglevel(`alert')
168 isloglevelexpat(`emerg',`emerg|panic')
169
170 dnl syslog facilities
171 define(`islogfacilitylexpat',
172 `nametypelexpatexec(`syslog_$1',`tokt_logfacility|tokr_word',`$2',
173                     `lr_logfacility= LOG_'translit(``$1'',`a-z',`A-Z')`; ')')
174 define(`islogfacility',`islogfacilitylexpat(`$1',`$1')')
175 islogfacilitylexpat(`authpriv',`auth(priv)?|security')
176 islogfacility(`cron')
177 islogfacility(`daemon')
178 islogfacilitylexpat(`kern',`kern(el)?')
179 islogfacility(`lpr')
180 islogfacility(`mail')
181 islogfacility(`news')
182 islogfacility(`syslog')
183 islogfacility(`user')
184 islogfacility(`uucp')
185 islogfacility(`local0')
186 islogfacility(`local1')
187 islogfacility(`local2')
188 islogfacility(`local3')
189 islogfacility(`local4')
190 islogfacility(`local5')
191 islogfacility(`local6')
192 islogfacility(`local7')
193
194 dnl misc. word-like things
195 wordtypelexexec(`read',`tokt_readwrite',`')
196 wordtypelexexec(`write',`tokt_readwrite',`')
197
198 dnl small nonnegative integers and fd ranges
199 dnl some of these have two tokt_ bits set, because they can be several
200 dnl things.
201 nametypelexpatexec(`ordinal',`tokt_number|tokt_fdrange|tokr_word',`[0-9]{1,8}',
202 `{ char *ep;
203    lr_min=lr_max= (int)strtoul(yytext,&ep,10);
204    assert(!*ep); }; ')
205 nametypelexpatexec(`fdrange',`tokt_fdrange|tokr_punct',`[0-9]{1,8}-[0-9]{1,8}',
206 `{ char *ep;
207    lr_min=(int)strtoul(yytext,&ep,10);
208    assert(*ep == HYPHEN); assert(*++ep);
209    lr_max=(int)strtoul(ep,&ep,10);
210    if (lr_max < lr_min) {
211      atnewline= 0; parseerrprint("fd range has min > max"); return tokv_error;
212    }
213    assert(!*ep); }; ')
214 nametypelexpatexec(`fdstoend',`tokt_fdrange|tokr_punct',`[0-9]{1,8}-',
215 `{ char *ep;
216    lr_min= (int)strtoul(yytext,&ep,10); lr_max=-1;
217    assert(*ep == HYPHEN); assert(!*++ep); }; ')
218 nametypelexpatexec(`dollar',`tokt_misc|tokr_punct',`\$',`')
219
220 dnl non-word things
221 autovalistype(`lwsp',            `tokt_misc|tokr_nonstring')
222 autovalistype(`newline',         `tokt_misc|tokr_nonstring')
223 autovalistype(`barestring',      `tokt_string|tokr_string')
224 autovalistype(`quotedstring',    `tokt_string|tokr_string')
225
226 dnl exceptions - NB that there are also tokv_word_{eof,quit}
227 dnl - see above, near the directives.
228 autovalistype(`eof',             `tokt_exception|tokr_nonstring')
229 autovalistype(`quit',            `tokt_exception|tokr_nonstring')
230 autovalistype(`error',           `tokt_exception|tokr_nonstring')
231
232 define(`iscondop',`nametypelexpatexec(`$2',`tokt_condop|tokr_punct',`$1',`')')
233 iscondop(`\(',`openparen')
234 iscondop(`\)',`closeparen')
235 iscondop(`\!',`not')
236 iscondop(`\&',`and')
237 iscondop(`\|',`or')
238
239 dnl words that could be two things
240 wordtypelexexec(`error',`tokt_directive|tokt_loglevel',
241                `lr_dir= df_error; lr_loglevel= LOG_ERR; ')
242
243 divert