chiark / gitweb /
@@ -7,6 +7,7 @@
[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,1999 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',eval(`0x1'))
36 define(`cautotokt',eval(`0x1000'))
37
38 define(`autovalistype',`hasvalistype(`$1',format(``0x%08x'',cautotoki),`$2')`'define(`cautotoki',incr(cautotoki))')
39
40 define(`autovaldeftype',`pushdef(`odiv',divnum)divert(4)dnl
41   format(``%-25s'',`tokt_$1=')format(``0x%08x'',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'`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(`builtinservice')
70 autovaldeftype(`misc')
71 autovaldeftype(`internal')
72
73 dnl simple isdirectives
74 define(`isdirectivefn',`dnl
75 wordtypelexexec(`$1',`tokt_directive$3',`lr_dir= $2; $4')dnl
76 pushdef(`odiv',divnum)
77 divert(odiv)popdef(`odiv')')
78 define(`isdirective',`isdirectivefn(`$1',`df_'makename(`$1'),`$2')')
79 define(`isdirectiveinternal',`isdirectivefn(`$1',`dfi_'makename(`$1'),
80                                             `|tokt_internal$2')')
81 define(`isexecmode',`isdirective(`$1',`|tokt_execmode')')
82 define(`isehandlemode',`isdirective(`$1',`|tokt_ehandlemode')')
83 define(`isfdwant',`isdirectivefn(`$1',`dfg_fdwant',`',
84                       `lr_fdwant_readwrite=$2; ')')
85 define(`isflagpair',`isdirectivefn(`$1',`dfg_setflag',`',
86                       `lr_flag= &'makename(`$1')`; lr_flagval= 1; ')
87                      isdirectivefn(`no-$1',`dfg_setflag',`',
88                       `lr_flag= &'makename(`$1')`; lr_flagval= 0; ')')
89 dnl `reset' is also a builtin service
90 isexecmode(`reject')
91 dnl `execute' is also a builtin service
92 isexecmode(`execute-from-directory')
93 isexecmode(`execute-from-path')
94 isexecmode(`execute-builtin')
95 isehandlemode(`errors-to-stderr')
96 isehandlemode(`errors-to-syslog')
97 isehandlemode(`errors-to-file')
98 isfdwant(`require-fd',`1')
99 isfdwant(`allow-fd',`0')
100 isfdwant(`null-fd',`0')
101 isfdwant(`reject-fd',`-1')
102 isfdwant(`ignore-fd',`-1')
103 isflagpair(`set-environment')
104 isflagpair(`suppress-args')
105 isflagpair(`disconnect-hup')
106 isdirective(`cd')
107 isdirective(`user-rcfile')
108 isdirective(`include')
109 isdirectivefn(`include-ifexist',`df_include')
110 isdirective(`include-lookup')
111 isdirectivefn(`include-lookup-all',`df_includelookup')
112 isdirective(`include-directory')
113 isdirective(`message')
114 isdirectivefn(`_include-sysconfig',`df_include',`|tokt_internal')
115 isdirectiveinternal(`_include-user-rcfile')
116 isdirectiveinternal(`_include-client-config')
117
118 dnl quit and eof are each a directive _and_ an exception
119 dnl as separate tokens.  A true end of file is returned by yylex
120 dnl as the exception.  The directive (word) tokens are
121 dnl tokv_word_{eof,quit}; the exceptions are tokv_{eof,quit}.
122 isdirective(`quit')
123 isdirective(`eof')
124
125 dnl control construct starters
126 define(`iscontrolstart',
127 `isdirective(`$1',`|tokt_controlstart')')
128 iscontrolstart(`if')
129 iscontrolstart(`catch-quit')
130 iscontrolstart(`errors-push')
131
132 dnl control construct enders
133 define(`iscontrolend',
134 `wordtypelexexec(`$1',`tokt_controlend$3',
135                  `lr_controlend= tokv_word_'makename(`$2')`; ')')
136 iscontrolend(`elif',   `if', `|tokt_controlstart')
137 iscontrolend(`else',   `if', `|tokt_controlstart')
138 iscontrolend(`fi',     `if')
139 iscontrolend(`hctac',  `catch-quit')
140 iscontrolend(`srorre', `errors-push')
141
142 dnl conditions
143 define(`isparmcondition',`wordtypelexexec(`$1',`tokt_parmcondition',
144                            `lr_parmcond= pcf_'makename(`$1')`; ')')
145 isparmcondition(`glob')
146 isparmcondition(`range')
147 isparmcondition(`grep')
148
149
150 define(`builtininlist',`
151 pushdef(`odiv',divnum)divert(5)dnl
152   `"$1$2"',
153 divert(odiv)popdef(`odiv')')
154
155 dnl builtin services
156 define(`isbuiltinservice',
157  `wordtypelexexec(`$1',`tokt_builtinservice$3',
158     `lr_bispa= bispa_'makename(`$2')`; lr_bisexec= bisexec_'makename(`$1')`; $5')
159   builtininlist(`$1',`$4')')
160 isbuiltinservice(`environment',`none')
161 isbuiltinservice(`parameter',`parameter',`',` <parameter>')
162 isbuiltinservice(`version',`none')
163 isbuiltinservice(`toplevel',`none')
164 isbuiltinservice(`override',`none')
165 isbuiltinservice(`shutdown',`none')
166
167 dnl builtin services that are also directive names
168 define(`isdirectivebuiltinservice',
169    `isbuiltinservice(`$1',`$2',`|tokt_directive$3',`$4',
170                      `lr_dir= df_'makename(`$1')`; ')')
171 isdirectivebuiltinservice(`reset',`none')
172 isdirectivebuiltinservice(`execute',`none',`|tokt_execmode')
173
174 isbuiltinservice(`help',`none')
175
176 dnl parameters
177 define(`isparameter',`wordtypelexexec(`$1',`tokt_parameter',
178                         `lr_parameter= pf_'makename(`$1')`; ')')
179 isparameter(`service')
180 isparameter(`calling-user')
181 isparameter(`calling-group')
182 isparameter(`calling-user-shell')
183 isparameter(`service-user')
184 isparameter(`service-group')
185 isparameter(`service-user-shell')
186
187 dnl syslog levels
188 define(`isloglevellexpat',
189 `nametypelexpatexec(`syslog_$1',`tokt_loglevel|tokr_word',`$2',
190                     `lr_loglevel= LOG_'translit(``$1'',`a-z',`A-Z')`; ')')
191 define(`isloglevel',`isloglevellexpat(`$1',`$1')')
192 isloglevel(`debug')
193 isloglevel(`info')
194 isloglevel(`notice')
195 isloglevellexpat(`warning',`warn(ing)?')
196 isloglevel(`err')dnl also the word error, which has dual meaning (below)
197 isloglevel(`crit')
198 isloglevel(`alert')
199 isloglevellexpat(`emerg',`emerg|panic')
200
201 dnl syslog facilities
202 define(`islogfacilitylexpat',
203 `nametypelexpatexec(`syslog_$1',`tokt_logfacility|tokr_word',`$2',
204                     `lr_logfacility= LOG_'translit(``$1'',`a-z',`A-Z')`; ')')
205 define(`islogfacility',`islogfacilitylexpat(`$1',`$1')')
206 islogfacilitylexpat(`authpriv',`auth(priv)?|security')
207 islogfacility(`cron')
208 islogfacility(`daemon')
209 islogfacilitylexpat(`kern',`kern(el)?')
210 islogfacility(`lpr')
211 islogfacility(`mail')
212 islogfacility(`news')
213 islogfacility(`syslog')
214 islogfacility(`user')
215 islogfacility(`uucp')
216 islogfacility(`local0')
217 islogfacility(`local1')
218 islogfacility(`local2')
219 islogfacility(`local3')
220 islogfacility(`local4')
221 islogfacility(`local5')
222 islogfacility(`local6')
223 islogfacility(`local7')
224
225 dnl misc. word-like things
226 wordtypelexexec(`read',`tokt_readwrite',`')
227 wordtypelexexec(`write',`tokt_readwrite',`')
228
229 dnl small nonnegative integers and fd ranges
230 dnl some of these have two tokt_ bits set, because they can be several things.
231 autovalistype(`ordinal',        `tokt_number|tokt_fdrange|tokr_word')
232 autovalistype(`fdrange',        `tokt_fdrange|tokr_punct')
233 autovalistype(`fdstoend',       `tokt_fdrange|tokr_punct')
234 nametypelexpatexec(`dollar',`tokt_misc|tokr_punct',`\$',`')
235
236 dnl non-word things
237 autovalistype(`lwsp',            `tokt_misc|tokr_nonstring')
238 autovalistype(`newline',         `tokt_misc|tokr_nonstring')
239 autovalistype(`barestring',      `tokt_string|tokr_string')
240 autovalistype(`quotedstring',    `tokt_string|tokr_string')
241
242 dnl exceptions - NB that there are also tokv_word_{eof,quit}
243 dnl - see above, near the directives.
244 autovalistype(`eof',             `tokt_exception|tokr_nonstring')
245 autovalistype(`quit',            `tokt_exception|tokr_nonstring')
246 autovalistype(`error',           `tokt_exception|tokr_nonstring')
247
248 define(`iscondop',`nametypelexpatexec(`$2',`tokt_condop|tokr_punct',`$1',`')')
249 iscondop(`\(',`openparen')
250 iscondop(`\)',`closeparen')
251 iscondop(`\!',`not')
252 iscondop(`\&',`and')
253 iscondop(`\|',`or')
254
255 dnl words that could be two things
256 wordtypelexexec(`error',`tokt_directive|tokt_loglevel',
257                `lr_dir= df_error; lr_loglevel= LOG_ERR; ')
258
259 divert