1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
dnl $OpenBSD: MAKEDEV.sub,v 1.9 2004/01/12 22:18:24 todd Exp $
dnl
dnl Copyright (c) 2001,2002,2003 Todd T. Fries <todd@OpenBSD.org>
dnl
dnl Permission to use, copy, modify, and distribute this software for any
dnl purpose with or without fee is hereby granted, provided that the above
dnl copyright notice and this permission notice appear in all copies.
dnl
dnl THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
dnl WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
dnl MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
dnl ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
dnl WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
dnl ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
dnl OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
dnl
dnl
dnl This file is an m4 file
dnl
dnl Conventions:
dnl
dnl o First, a change of quote to make shell statements like: `command`
dnl possible
dnl
changequote(`{-', `-}')dnl
dnl
dnl o version info must be stripped of $ so we can say 'generated from' below
dnl
dnl If we just use the version string how are we going to know what arch
dnl 'MAKEDEV.md,v' came from?
dnl
dnl Thus, I have used the below to create a version string looking like
dnl 'OpenBSD: etc.sparc/MAKEDEV.inc,v...' which works, although requires
dnl some attention if ported to another Id string setup.
dnl
dnl
dnl Initialize the stacks stored in _m4_*
dnl
undefine({-_m4_cvs_ver-})dnl
pushdef({-_m4_cvs_ver-}, {-done-})dnl
dnl
undefine({-_m4_devs-})dnl
pushdef({-_m4_devs-}, {-done-})dnl
dnl
undefine({-_m4_disks-})dnl
undefine({-_m4_disks2-})dnl
pushdef({-_m4_disks-}, {-done-})dnl
pushdef({-_m4_disks2-}, {-done-})dnl
dnl
dnl define stack 'add to' functions, only unique names queued
dnl
define({-ver_q-}, {-ifelse(index($1_ver, y), 0, ,
{-pushdef({-_m4_cvs_ver-}, {-$2-})define({-$1_ver-}, {-y-})-})-})dnl ver_q
dnl
define({-dev_q-}, {-ifelse(index(_q_$1_dev, :), 0,
{-errprint({-duplicated dev id: $1 at -}__file__{-:-}__line__ originally at _q_$1_dev)-},
{-pushdef({-_m4_devs-}, {-$1-})dnl
define({-_q_$1_dev-}, {-:-}__file__{-:-}__line__)-})-})dnl dev_q
dnl
define({-disk_q-}, {-ifelse(index(_q_$1_disk, :), 0,
{-errprint({-duplicated disk id: $1 at -}__file__{-:-}__line__ originally at _q_$1_disk)-}, {-pushdef({-_m4_disks-}, {-$1-})dnl
pushdef({-_m4_disks2-}, {-$1-})dnl
define({-_q_$1_disks-}, {-:-}__file__{-:-}__line__)-})-})dnl disk_q
dnl
dnl store a version string for 'this' file
dnl
dnl vers ( uniqueidstring, versionstring, subdir )
dnl
dnl example1: vers(__file__, {-$OpenBSD: MAKEDEV.sub,v 1.9 2004/01/12 22:18:24 todd Exp $-})
dnl example2: vers(__file__, {-$OpenBSD: MAKEDEV.sub,v 1.9 2004/01/12 22:18:24 todd Exp $-}, etc.MACHINE)
dnl
dnl if subdir is defined, prepend it to the filename in the version string
dnl
define({-vers-},
{-ifelse({-$3-}, {--},
{-ver_q(hstcl({-$1-}), {-translit({-{-$2-}-}, {-$-}, {--})-})-},
{-ver_q(hstcl({-$1-}), {-_addsubdir({-{-$2-}-}, $3)-})-})-})dnl
dnl
dnl Version info for this file:
dnl
vers(__file__, {-$OpenBSD: MAKEDEV.sub,v 1.9 2004/01/12 22:18:24 todd Exp $-})dnl
dnl
dnl
define({-_addsubdir-},
{-patsubst({-$1-}, {-\$(OpenBSD:) ([^\$]*)\$-}, {-\1 $2/\2-})-})dnl
dnl
dnl do the 'showing' of the version info
dnl
define({-do_vers-}, {-# $1-})dnl
dnl
dnl show version function, to be called at the place when all versions are
dnl queued, and it is time to show all of them
dnl
define({-show_vers-},
{-ifelse(_m4_cvs_ver, {-done-}, {--},
{-do_vers(_m4_cvs_ver)
popdef({-_m4_cvs_ver-})dnl
show_vers()dnl
-})-})dnl
dnl
dnl show the routines to generate devices
define({-show_devs-},
{-ifelse(_m4_devs, {-done-}, {--},
{-_MKDEV(_m4_devs){--}dnl
popdef({-_m4_devs-})dnl
show_devs()dnl
-})-})dnl
dnl
dnl routines to generate disks
define({-show_disks-},
{-ifelse(_m4_disks, {-done-}, {--},
{-ifcase(_m4_disks, _m4_disks{--}*)dnl
popdef({-_m4_disks-})dnl
show_disks()dnl
-})-})dnl
dnl
define({-show_disks2-},
{-ifelse(_m4_disks2, {-done-}, {--},
{-CasE(_m4_disks2)dnl
popdef({-_m4_disks2-})dnl
show_disks2()dnl
-})-})dnl
dnl
dnl
dnl Some m4 math functions:
dnl
dnl Add(a, b) - displays the result of a+b
dnl Mult(a, b) - displays the result of a*b
dnl trunc a b - displays the string a minus b removed from the RHS
dnl hex a - displays the hex equivalent of 0-15
dnl unt a - s/[a-z]*([0-9]*).*/\1/ aka sd0a -> 0
dnl
dnl Functions:
dnl
dnl --> Addition
dnl
define({-Add-}, {-$({-(-}$1+$2{-)-})-})dnl
dnl
dnl --> Multiplication
dnl
define({-Mult-}, {-$({-(-}$1*$2{-)-})-})dnl
dnl
dnl
dnl TRUNC
dnl
define({-expr_trunc-}, {-$1trunc()
$1{
$1 case {-$-}3 in
$1 l) {-expr-} {-$-}1 : '\(.*\)'{-$-}2 ;;
$1 r|*) {-expr-} ${--}1 : ${--}2'\(.*\)' ;;
$1 esac
$1}-})dnl
dnl
dnl
define({-_SHELL-}, {-sh-})dnl
define({-_this-}, {-{-$-}T-})dnl
dnl define({-_recurse-}, {-_SHELL _this-})dnl
define({-_recurse-}, {-R-})dnl
dnl
dnl _devitem(pattern, description)
dnl
define({-_devitem-},
{-{-#-} $1 {-$2-}-})dnl
dnl
dnl _devtitle(description)
dnl
define({-_devtitle-}, {-{-#-} $1:-})dnl
dnl
dnl _DEV(name, [character major], [block major])
dnl
define({-_DEV-}, {-$1_dev{--}dnl
dnl
dnl _DEV 'ifelse' .. $2 - major_$1_c
dnl
ifelse($2, , , {-define(major_$1_c, $2)-})dnl
dnl
dnl _DEV 'ifelse' .. $3 - major_$1_b
dnl
ifelse($3, , , {-define(major_$1_b, $3)-})dnl
dnl
dnl _DEV 'ifelse' .. $4 - step_$1
dnl
ifelse($4, , , {-define(step_$1, {-$4-})-})dnl
dnl
dnl Some magic here, defining a devitem also defines another
dnl string so that later we can check if a particular devitem was
dnl defined, and thus determine if the devices themselves are to
dnl be built
dnl
define({-$1__DEV-}, {-Y-})dnl
dnl
dnl More magic, put device string name into a queue of script segments to
dnl be shown later if it has been defined as a device in MAKEDEV.mi
dnl
ifdef({-$1_mkdev-}, {-__mkdev({-$1-})-})dnl
dnl
dnl
-})dnl _DEV
dnl
dnl
define({-ifdev-}, {-ifelse($1__DEV, Y, {-$2-})-})dnl
dnl
define({-_MKDEV-}, {-$1_mkdev-})dnl
define({-_TITLE-}, {-$1_title-})dnl
define({-__devitem-}, {-define($1_dev, {-_devitem($2, $3)-})$4-})dnl
define({-__devtitle-}, {-define($1_title, {-_devtitle($2)-})-})dnl
dnl
dnl Beginning and ending of case entries, just incase we change in the
dnl future, save chasing things down again
dnl
define({-_end-}, {-
;;
-})dnl
define({-_beg-}, {-{-)-}
-})dnl
dnl
dnl create the script segment for making devices
dnl $1 $2 $3
dnl _mkdev(shortname, devpatt, action)dnl
define({-_mkdev-}, {-define($1_mkdev, {-$2{--}_beg{--}$3{--}_end-})-})dnl
dnl
dnl define a major character device
dnl $1 $2 $3 $4
dnl _mcdev(shortname, devpatt, devbase, devmajor [, group [ owner ] ])dnl
dnl
define({-_mcdev-}, {-define($1_mkdev, {-{-$2-}_beg{--}M $3$U c $4 $U{--}dnl
ifelse($6, , ifelse($5, , , {- -}$5), {- -}ifelse($5, , 600, $5){- -}$6){--}_end-})-})dnl
dnl
dnl $1 $2 $3 $4 $5 $6
dnl _cdev(shortname, devpatt, devmajor, devminor[, devmod, devgrp])dnl
define({-_cdev-},
{-dnl
define($1_mkdev, {-$2{--}_beg{--}M $2 c $3 $4 $5 $6{--}_end-}){--}-})dnl
dnl
dnl
define({-__mkdev-}, {-dev_q($1)-})dnl
dnl
dnl for showing disks
dnl
define({-CasE-},
{-ifdev({-$1-},
{- $1*) dodisk $1 $U major_$1_b major_$1_c $U 0{--}ifstep($1);;
-})-})dnl
dnl
dnl
define({-ifcase-}, {-dnl
ifelse(C_ase, Y, ifdev({-$1-}, {-|$2-}),
{-ifdev({-$1-}, {-$2define({-C_ase-}, Y)-})-})-})dnl
dnl
dnl
dnl device list .. list devices 'iff' they are defined
dnl
dnl input:
dnl
dnl _dl({-usb-}, {-usb0 usb1-}, {-urio-}, {-urio-}, ...)
dnl
dnl output:
dnl
dnl {-<tab>_recurse usb0 usb1 urio
dnl <tab>_recurse uhid0 uhid2 uhid3-}
dnl
dnl wrap if more than 60 chars wide
dnl
dnl .. wrap it all up in an 'ifelse({-$1-}, , {- ... -})' for neatness ??
dnl
define({-_dl-}, {-dnl
ifdef({-_dt-}, , {-define({-_dt-})-})dnl
ifdef({-_do-}, , {-_dt{--}_recurse{--}define({-_do-}, 0)dnl
define({-_dt-}, {- -})-})dnl
ifdef({-$1__DEV-},
{-define({-_di-}, {-$2-})-},
{-define({-_di-})-})dnl
ifelse(eval(len(_di)+_do<60), 1,
{-ifelse(eval(len(_di)>0), 1,
{- _di{--}define({-_do-}, eval(1+_do+len(_di)))-})-},
{-
_dt{--}_recurse _di{--}dnl
define({-_do-}, len(_di))-})dnl
ifelse({-$3-}, {--},
{-undefine({-_dt-}, {-_do-})-}, dnl <--- The END
{-_dl(shift(shift($@)))-})-})dnl
dnl
dnl
define({-_show_target-}, {-dnl
ifdef({-$1__DEV-}, {-disp_dev({-$2-})-})dnl
ifelse({-$3-}, {--},
{-_disp_dev_end()-}, dnl <--- The END
{-_show_target(shift(shift($@)))-})-})dnl
dnl
define({-disp_dev-}, {-dnl
ifdef({-_disp_dev_tab-}, , {-define({-_disp_dev_tab-})-})dnl
ifdef({-_disp_dev_len-}, , {-dnl
define({-_disp_dev_len-}, 0)dnl
_disp_dev_tab{--}_recurse{--}dnl
define({-_disp_dev_tab-}, {- -})-})dnl
ifelse(eval(len($1)+_disp_dev_len<60), 1,
{- $1{--}define({-_disp_dev_len-}, eval(1+_disp_dev_len+len($1)))-}, {-
_disp_dev_tab{--}_recurse $1{--}dnl
define({-_disp_dev_len-}, len($1))-})dnl
-})dnl
define({-_disp_dev_end-}, {-undefine({-_disp_dev_tab-}, {-_disp_dev_len-})-})dnl
dnl
dnl A word about the above:
dnl
dnl _dt -> 'tab' .. at first, defined to nothing, as the tab is already there
dnl then define it to a tab every time through
dnl undefine it at the end
dnl
dnl _do -> 'old' count .. stores the length of the old string already displayed
dnl it is initialized to 0, added to the length plus 1 of '_di' each
dnl iteration the line is less than 60 chars long
dnl undefined at the end
dnl _di -> 'iteration' string .. the string used in this iteration, is empty if
dnl the device does not exist
dnl
dnl
dnl ifstep(devstr)
dnl .. if stepping is defined for the particular device, emit ' step', else
dnl nothing
define({-ifstep-}, {-ifdef({-step_$1-}, {- -}step_$1{--})-})dnl
dnl
dnl
define({-target-}, {-twrget({-$1-}, {-$2-}, {-$2-}, shift(shift($@)))-})dnl
dnl
dnl twrget(target, devname, prefix, str1, str2, str3)
dnl $1 $2 $3 $4 $5 $6
dnl
define({-twrget-}, {-dnl
dnl
ifdef({-$1_target-}, , {-pushdef({-$1_target-}, {-done-})-})dnl
dnl
ifelse({-$4-}, , , {-dnl
ifelse({-$4-}, {-_done-}, , {-dnl
ifelse({-$5-}, , , {-dnl
dnl errprint({-recurse: $1, $2, $3, $4, $5, $6, ...-})dnl
twrget({-$1-}, {-$2-}, {-$3-}, shift(shift(shift(shift($@)))))dnl
-})-})-})dnl
dnl
ifelse({-$4-}, {-_done-}, , {-dnl
dnl errprint({-recurse: $1_$2_dev, $3$4, $3$4, _done-})dnl
twrget({-$1_$2_dev-}, {-$3$4-}, {-$3$4-}, {-_done-})dnl
-})dnl
dnl
ifdef({-$1$2target-}, , {-dnl
pushdef({-$1_target-}, {-$2-})define({-$1$2target-})dnl
-})dnl
dnl
-})dnl
dnl
dnl
define({-show_target-}, {-dnl
ifelse($1_target, {-done-}, {-_disp_dev_end()-},
{-dnl $1_target:
show_dev($1, -}$1_target{-)dnl
popdef({-$1_target-})dnl
show_target({-$1-})dnl
-})-})dnl
dnl
define({-show_dev-}, {-dnl
ifdef({-$2__DEV-}, {-dnl
ifelse($1_$2_dev_target, {-done-}, , {-dnl
disp_dev({-$1_$2_dev_target-})dnl
popdef({-$1_$2_dev_target-})dnl
show_dev({-$1-}, {-$2-})-})dnl
-})dnl
-})dnl
dnl
|