dnl $OpenBSD: MAKEDEV.sub,v 1.4 2002/01/07 06:54:10 todd Exp $ dnl dnl Copyright (c) 2001 Todd T. Fries dnl All rights reserved. dnl dnl Redistribution and use in source and binary forms, with or without dnl modification, are permitted provided that the following conditions dnl are met: dnl 1. Redistributions of source code must retain the above copyright dnl notice, this list of conditions and the following disclaimer. dnl 2. The name of the author may not be used to endorse or promote products dnl derived from this software without specific prior written permission. dnl dnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY dnl AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL dnl THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; dnl OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, dnl WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR dnl OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF dnl ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 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.4 2002/01/07 06:54:10 todd Exp $-}) dnl example2: vers(__file__,{-$OpenBSD: MAKEDEV.sub,v 1.4 2002/01/07 06:54:10 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.4 2002/01/07 06:54:10 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)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 {-_recurse usb0 usb1 urio dnl _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 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