#!/bin/sh
# =============================================================================
# 
# @(#) strsetup,v openss7-0_9_2_F(0.9.2.10) 2007/06/17 01:57:19
#
# -----------------------------------------------------------------------------
#
# Copyright (c) 2001-2005  OpenSS7 Corporation <http://www.openss7.com>
# Copyright (c) 1997-2000  Brian F. G. Bidulock <bidulock@openss7.org>
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 675 Mass
# Ave, Cambridge, MA 02139, USA.
#
# -----------------------------------------------------------------------------
#
# U.S. GOVERNMENT RESTRICTED RIGHTS.  If you are licensing this Software on
# behalf of the U.S. Government ("Government"), the following provisions apply
# to you.  If the Software is supplied by the Department of Defense ("DoD"), it
# is classified as "Commercial Computer Software" under paragraph 252.227-7014
# of the DoD Supplement to the Federal Acquisition Regulations ("DFARS") (or any
# successor regulations) and the Government is acquiring only the license rights
# granted herein (the license rights customarily provided to non-Government
# users).  If the Software is supplied to any unit or agency of the Government
# other than DoD, it is classified as "Restricted Computer Software" and the
# Government's rights in the Software are defined in paragraph 52.227-19 of the
# Federal Acquisition Regulations ("FAR") (or any successor regulations) or, in
# the cases of NASA, in paragraph 18.52.227-86 of the NASA Supplement to the FAR
# (or any successor regulations).
#
# -----------------------------------------------------------------------------
#
# Commercial licensing and support of this software is available from OpenSS7
# Corporation at a fee.  See http://www.openss7.com/
#
# -----------------------------------------------------------------------------
#
# Last Modified 2007/06/17 01:57:19 by brian
#
# =============================================================================

ECHO='echo'
SHELL='/bin/sh'
SED='sed'

# Check that we have a woring $ECHO.
if test "X$1" = X--no-reexec ; then
    # Discard the --no-reexec flag, and continue
    shift
elif test "X`(echo '\t') 2>/dev/null`" = 'X\t' ; then
    :
else
    exec $SHELL "$0" --no-reexec ${1+"$@"}
fi

if test "X$1" = X--fallback-echo ; then
    shift
    cat <<EOF
$*
EOF
    exit 0
fi

program=`$ECHO "$0" | $SED -e 's%^.*/%%'`
modename="$program"

ident='strsetup,v openss7-0_9_2_F(0.9.2.10) 2007/06/17 01:57:19'

HELP="Try \`$program --help' for more information."

MKDIR='mkdir'
MV='/bin/mv -f'
RM='/bin/rm -f'

# Sed substitution that helps us do robust quoting.  It backslashifies
# metacharacters that are still active within double-quoted strings.
Xsed="$SED"' -e 1s/^X//'
sed_quote_subst='s/\([\\`\\"$\\\\]\)/\\\1/g'
# test EBCDIC or ASCII
case `$ECHO A | od -x` in
    *[Cc]1*) # EBCDIC based system
	SP2NL="tr '\100' '\n'"
	NL2SP="tr '\r\n' '\100\100'"
	;;
    *) # Assume ASCII based system
	SP2NL="tr '\040' '\012'"
	NL2SP="tr '\015\012' '\040\040'"
	;;
esac

# NLS nuisances.
# Only set LANG and LC_ALL to C if already set.
# These must not be set unconditionally because not all systems understand
# e.g. LANG=C (notably SCO).
# We save the old values to restore during execute mode.
if test "${LC_ALL+set}" = set ; then
    save_LC_ALL="$LC_ALL"; LC_ALL=C; export LC_ALL
fi
if test "${LANG+set}" = set ; then
    save_LANG="$LANG"; LANG=C; export LANG
fi

# Make sure IFS has a sensible default
: ${IFS=" 	"}

strsetup_letters='abcdefghijklmnopqrstuvwxyz'
strsetup_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
strsetup_Letters=$strsetup_letters$strsetup_LETTERS
strsetup_numbers='0123456789'
strsetup_alphano=$strsetup_Letters$strsetup_numbers
strsetup_uppercase="$SED y%*$strsetup_letters%P$strsetup_LETTERS%;s%[^_$strsetup_alphano]%_%g"
strsetup_tokenize="$SED s%[^a-zA-Z0-9]%_%g"

# Defaults

default_command="config"
default_filesrch="/etc/strsetup.conf:/etc/sysconfig/streams/strsetup.conf:$HOME/strsetup.conf:./strsetup.conf"
default_filename="/etc/strsetup.conf"

command=
filename=
debug=0
verbose=1

function version()
{
    if test ${show:-yes} = no ; then
	return
    fi
    cat <<EOF
$ident
Copyright (c) 2001-2005  OpenSS7 Corporation.  All Rights Reserved.
Distributed under GPL Version 2, included here by reference.
See \`$program --copying' for copying permissions.
EOF
}

function usage()
{
    if test ${show:-yes} = no ; then
	return
    fi
    cat <<EOF
Usage:
    $program [options] [{-c|--config}]
    $program [options] [{-i|--install}] [{-f|--filename} FILENAME]
    $program [options] {-d|--delete} [{-f|--filename} FILENAME]
    $program {-h|--help}
    $program {-V|--version}
    $program {-C|--copying}
EOF
}

function help()
{
    if test ${show:-yes} = no ; then
	return
    fi
    usage
    cat <<EOF
Options:
    -c, --config
        show current configuration, this is the default when no command
	options are specified
    -i, --install
        install devices from configuration file, this is the default when a
	filename is specified
    -d, --delete
        remove devices from configuration file
    -f, --filename FILENAME
        specify configuration file [default: '$default_filename']
    -q, --quiet
        suppress normal output
    -D, --debug [LEVEL]
        increase or set debugging verbosity
    -v, --verbose [LEVEL]
        increase or set output verbosity
    -h, --help
        prints this usage information and exits
    -V, --version
        prints the version and exits
    -C, --copying
        prints copying permissions and exits
EOF
}

function copying()
{
    if test ${show:-yes} = no ; then
	return
    fi
    cat <<EOF
--------------------------------------------------------------------------------
$ident
--------------------------------------------------------------------------------
Copyright (c) 2001-2005  OpenSS7 Corporation <http://www.openss7.com>
Copyright (c) 1997-2000  Brian F. G. Bidulock <bidulock@openss7.org>

All Rights Reserved.
--------------------------------------------------------------------------------
This program is free software; you can  redistribute  it and/or modify  it under
the terms  of the GNU General Public License  as  published by the Free Software
Foundation; version 2 of the License.

This program is distributed in the hope that it will  be useful, but WITHOUT ANY
WARRANTY; without even  the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should  have received a copy of the GNU  General  Public License  along with
this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA.
--------------------------------------------------------------------------------
U.S. GOVERNMENT RESTRICTED RIGHTS.  If you are licensing this Software on behalf
of the U.S. Government ("Government"), the following provisions apply to you. If
the Software is supplied by the  Department of Defense ("DoD"), it is classified
as "Commercial  Computer  Software"  under  paragraph  252.227-7014  of the  DoD
Supplement  to the  Federal Acquisition Regulations  ("DFARS") (or any successor
regulations) and the  Government  is acquiring  only the  license rights granted
herein (the license rights customarily provided to non-Government users). If the
Software is supplied to any unit or agency of the Government  other than DoD, it
is  classified as  "Restricted Computer Software" and the Government's rights in
the Software  are defined  in  paragraph 52.227-19  of the  Federal  Acquisition
Regulations ("FAR")  (or any successor regulations) or, in the cases of NASA, in
paragraph  18.52.227-86 of  the  NASA  Supplement  to the FAR (or any  successor
regulations).
--------------------------------------------------------------------------------
Commercial  licensing  and  support of this  software is  available from OpenSS7
Corporation at a fee.  See http://www.openss7.com/
--------------------------------------------------------------------------------
EOF
}

function option_unrec()
{
    if test ${verbose:-0} -gt 0 ; then
	opt=`$ECHO -n "X$1" | $Xsed -e 's|=.*||'`
	$ECHO "$program: syntax error -- \`$opt' unrecognized" >&2
	( usage ) >&2
    fi
    exit 2
}

function option_noarg()
{
    if test ${verbose:-0} -gt 0 ; then
	opt=`$ECHO -n "X$1" | $Xsed -e 's|=.*||'`
	$ECHO "$program: syntax error -- \`$opt' does not accept an argument" >&2
	( usage ) >&2
    fi
    exit 2
}

function option_needarg()
{
    if test ${verbose:-0} -gt 0 ; then
	$ECHO "$program: syntax error -- \`$1' requires an argument" >&2
	( usage ) >&2
    fi
    exit 2
}

function option_after()
{
    if test ${verbose:-0} -gt 0 ; then
	$ECHO "$program: syntax error -- \`$1' cannot occur after \`$2'" >&2
	( usage ) >&2
    fi
    exit 2
}

function option_with()
{
    if test ${verbose:-0} -gt 0 ; then
	$ECHO "$program: syntax error -- \`$1' cannot occur with \`$2'" >&2
	( usage ) >&2
    fi
    exit 2
}

# Parse our command line options once, thoroughly.
while test "$#" -gt 0 -o ":$more" != ":"
do
    if test ":$more" != ":" ; then
	arg="-$more"
	more=
    else
	arg="$1"
	shift
    fi
    if test x"$more_options" = xno ; then
	nonopt="$arg"
	break
    fi
    # check for attached option argument
    case $arg in
	--filename=* | --filenam=* | --filena=* | --filen=* | --file=* | --fil=* | --fi=* | --f=*)
	    optarg=`$ECHO "X$arg" | $Xsed -e 's/[-_a-zA-Z0-9]*=//'`
	    ;;
	--*=*)
	    option_noarg $arg ;;
	-[cdinqDvhVC])
	    optarg= ;;
	-[cdinqDvhVC]*)
	    optarg=
	    more=`$ECHO "X$arg" | $Xsed -e 's|-[cdinqDvhVC]||'`
	    eval "arg=\`$ECHO \"X$arg\" | $Xsed -e 's|$more||'\`"
	    ;;
	-f)
	    optarg= ;;
	-f*)
	    optarg=`$ECHO "X$arg" | $Xsed -e 's|-f||'` ;;
	*)
	    optarg= ;;
    esac
    # check for optional or required option argument
    if test -n "$prev" ; then
	case $arg in
	    -*) # optional arguments not forthcoming
		case $prev in
		    debug | verbose) eval "(($prev++))" ;;
		    # these have required arguments
		    filename)
			option_needarg $prevopt ;;
		esac
		prev= ; prevopt=
		;;
	    *) # if the previous option needs an argument, assign it.
		eval "$prev=\"\$arg\""
		prev= ; prevopt=
		continue
		;;
	esac
    fi
    # Have we seen a non-optional argument yet?
    case $arg in
	--help | --h | --Help | --H | -h | -H | -\? | --\?)
	    show_help=yes
	    if test ":$command" = ":" ; then command=none ; fi
	    ;;
	--version | --versio | --versi | --vers | -V)
	    show_version=yes
	    if test ":$command" = ":" ; then command=none ; fi
	    ;;
	--copying | --copyin | --copyi | --copy | --cop | --co | --c | -C)
	    show_copying=yes
	    if test ":$command" = ":" ; then command=none ; fi
	    ;;
	--verbose | --verbos | --verbo | --verb)
	    prevopt="$arg"
	    prev=verbose
	    ;;
	-v)
	    ((verbose++))
	    ;;
	--verbose=* | --verbos=* | --verbo=* | --verb=*)
	    verbose="$optarg"
	    ;;
	--debug | --debu | --deb)
	    prevopt="$arg"
	    prev=debug
	    ;;
	-D)
	    $ECHO "$program: enabling shell trace mode" 1>&2
	    set -x
	    ;;
	--debug=* | --debu=* | --deb=*)
	    debug="$optarg"
	    ;;
	--dry-run | --dryrun | --n | -n)
	    run=no
	    ;;
	--quiet | --silent | -q)
	    show=no
	    verbose=0
	    debug=0
	    ;;
	--filename | --filenam | --filena | --filen | --file | --fis | --fi | --f | -f)
	    if test ":$command" = ":config" ; then option_with --filename --config ; fi
	    if test ":$command" = ":" ; then command=filename ; fi
	    prevopt="$arg"
	    prev=filename
	    ;;
	--filename=* | --filenam=* | --filena=* | --filen=* | --file=* | --fil=* | --fi=* | --f=* | -f*)
	    filename="$optarg"
	    if test ":$command" = ":config" ; then option_with --filename --config ; fi
	    if test ":$command" = ":" ; then command=filename ; fi
	    ;;
	--config | --confi | --conf | --con | --co | --c | -c)
	    if test ":$command" != ":" -a ":$command" != ":config" ; then option_after $arg --$command ; fi
	    command=config
	    ;;
	--install | --instal | --insta | --inst | --ins | --in | --i | -i)
	    if test ":$command" != ":" -a ":$command" != ":install" ; then option_after $arg --$command ; fi
	    command=install
	    ;;
	--delete | --delet | --dele | --del | --de | --d | -d)
	    if test ":$command" != ":" -a ":$command" != ":delete" ; then option_after $arg --$command ; fi
	    command=delete
	    ;;
	--)
	    # end of options
	    more_options=no
	    ;;
	-*)
	    option_unrec $arg
	    ;;
	*)
	    nonopt="${nonopt}${nonopt:+ }'$arg'"
	    ;;
    esac
done

# hit end of list wanting an argument
case $prev in
    # these have optional arguments
    debug | verbose) eval "(($prev++))" ;;
    # the rest have required arguments
    filename)
	option_needarg $prevopt ;;
esac

if test x"$nonopt${nonopt:+ }${1+$@}" != "x" ; then
    eval "files=($nonopt${nonopt:+ }${1+$@})"
else
    files=
fi

# assign all defaults
if test ":$command" = ":" ; then
    command=config
fi
if test ":$filename" = ":" ; then
    for file in `$ECHO -n "$default_filesrch" | $SED -e 's|:| |g'` ; do
	if test -f $file ; then
	    default_filename="$file"
	    break
	fi
    done
    filename="$default_filename"
fi

function parse_file()
{
    lineno=0
    while read -a tokens
    do
	((lineno++))
	numb=${#tokens[*]}
	case ":${tokens[0]}" in
	    :#*) # comment
		continue
		;;
	    :) # blank line
		continue
		;;
	esac
	# check for too few tokens
	if test $numb -lt 4 ; then
	    if test ${verbose:-0} -gt 0 ; then
		$ECHO "$program: error: \`$filename' at line $lineno: too few tokens, $numb instead of 4" >&2
	    fi
	    continue
	fi
	# check for excess tokens
	if test $numb -gt 4 ; then
	    case ":${tokens[4]}" in
		:# | :#*) # comment
		    ;;
		:*)
		    if test ${verbose:-0} -gt 0 ; then
			$ECHO "$program: warning: \`$filename' at line $lineno: too many tokens" >&2
		    fi
		    ;;
		:) # blank tokens
		    ;;
	    esac
	fi
	driver="${tokens[0]}"
	device="${tokens[1]}"
	access="${tokens[2]}"
	minors="${tokens[3]}"
	case "::${tokens[0]}::${tokens[1]}::${tokens[2]}::${tokens[3]}::" in
	    *::#*) # one token is comment
		if test ${verbose:-0} -gt 0 ; then
		    $ECHO "$program: error: \`$filename at line $lineno: too few tokens" >&2
		fi
		continue
		;;
	esac
	# token 0 is the driver name
	token=`$ECHO -n "$driver$lineno" | $strsetup_tokenize`
	# token 1 is the device name spec
	case ":$device" in
	    :/*)
		;;
	    :*)
		if test ${verbose:-0} -gt 0 ; then
		    $ECHO "$program: error: \`$filename' at line $lineno token 2: expecting absolute path, got \`$device'" >&2
		fi
		continue
		;;
	esac
	dir=`$ECHO -n "$device" | $SED -e 's|/[^/]*$||'`
	dir="${dir:-/}"
	if test ! -e $dir ; then
	    if test ${verbose:-0} -gt 0 ; then
		$ECHO "$program: warning: \`$filename' at line $lineno token 2: \`$dir' does not exist" 2>&1
	    fi
	elif test ! -d $dir ; then
	    if test ${verbose:-0} -gt 0 ; then
		$ECHO "$program: warning: \`$filename' at line $lineno token 2: \`$dir' is not a directory" 2>&1
	    fi
	fi
	# token 2 is the (octal) file mode
	case ":$access" in
	    :0[0-7][0-7][0-7])
		;;
	    :*)
		if test ${verbose:-0} -gt 0 ; then
		    $ECHO "$program: error: \`$filename' at line $lineno token 3: expecting octal mode, got \`$access'" >&2
		fi
		continue
		;;
	esac
	# token 3 is "clone" or a minor device number or a minor device number range
	case ":$minors" in
	    :[0-9] | :[0-9][0-9] | :[0-9][0-9][0-9] | :[0-9]-[0-9] | \
	    :[0-9]-[0-9][0-9] | :[0-9]-[0-9][0-9][0-9] | :[0-9][0-9]-[0-9] | \
	    :[0-9][0-9]-[0-9][0-9] | :[0-9][0-9]-[0-9][0-9][0-9] | \
	    :[0-9][0-9][0-9]-[0-9] | :[0-9][0-9][0-9]-[0-9][0-9] | \
	    :[0-9][0-9][0-9]-[0-9][0-9][0-9] | :clone)
		;;
	    :*)
		if test ${verbose:-0} -gt 0 ; then
		    $ECHO "$program: error: \`$filename' at line $lineno token 4: N or N-N or clone, got \`$minors'" >&2
		fi
		continue
		;;
	esac
	fminor=`$ECHO -n $minors | $SED -e 's|-.*||' -e 's|clone||'`
	lminor=`$ECHO -n $minors | $SED -e 's|.*-||' -e 's|clone||'`
	# driver name assignment
	entries="$entries${entries:+ }$token"
	eval "lineno_$token=\"$lineno\""
	eval "driver_$token=\"$driver\""
	# device name spec assignment
	eval "device_$token=\"$device\""
	# mode assignment
	eval "access_$token=\"$access\""
	# minor device assignment
	eval "minors_$token=\"$minors\""
	eval "fminor_$token=\"$fminor\""
	eval "lminor_$token=\"$lminor\""
    done
}

function none_command()
{
    if test -n "$show_version$show_help$show_copying" ; then
	if test ${verbose:-0} -gt 1 ; then
	    $ECHO "Displaying information"
	fi
	if test ":$show_version" != ":" ; then
	    version
	fi
	if test ":$show_help" != ":" ; then
	    help
	fi
	if test ":$show_copying" != ":" ; then
	    copying
	fi
    fi
}

function config_command()
{
    if test ${verbose:-0} -gt 1 ; then
	$ECHO "Displaying configuration"
    fi
}

function test_input_file()
{
    if test ! -e $filename ; then
	if test ${verbose:-0} -gt 0 ; then
	    $ECHO "$program: error: file \`$filename' does not exist"
	fi
	exit 1
    fi
    if test ! -f $filename ; then
	if test ${verbose:-0} -gt 0 ; then
	    $ECHO "$program: error: file \`$filename' is not a regular file"
	fi
	exit 1
    fi
    if test ! -r $filename ; then
	if test ${verbose:-0} -gt 0 ; then
	    $ECHO "$program: error: file \`$filename' cannot be read"
	fi
	exit 1
    fi
}

function install_command()
{
    if test ${verbose:-0} -gt 1 ; then
	$ECHO "Installing devices using \`$filename'"
    fi
    files=
    for entry in $entries ; do
	eval "driver=\"\$driver_$entry\""
	eval "device=\"\$device_$entry\""
	eval "access=\"\$access_$entry\""
	eval "minors=\"\$minors_$entry\""
	eval "fminor=\"\$fminor_$entry\""
	eval "lminor=\"\$lminor_$entry\""
	if test ":$minors" = ":clone" ; then
	    files="$files${files:+ }$device"
	else
	    minor="$fminor"
	    while test $minor -le $lminor ; do
		devname="$device"
		decimal=`printf '%d' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%d|$decimal|g'\`"
		lchexad=`printf '%x' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%x|$lchexad|g'\`"
		uchexad=`printf '%X' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%X|$uchexad|g'\`"
		octalno=`printf '%o' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%o|$octalno|g'\`"
		unsignd=`printf '%u' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%u|$unsignd|g'\`"
		integno=`printf '%i' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%i|$integno|g'\`"
		files="$files${files:+ }$devname"
		((minor++))
	    done
	fi
    done
# create all directories
    for file in $files ; do
	# strip filename
	comps=`$ECHO ":$file" | $SED -ne 's|^:/|#|;s|^:||;s|/| |g;s|^#|/|;p'`
	eval "components=($comps)"
	count=0
	pathcomp=
	numb=${#components[*]}
	((numb--))
	while test $count -lt $numb ; do
	    eval "pathcomp=\"$pathcomp\${components[$count]}\""
	    ((count++))
	    case $pathcomp in
		-*) pathcomp=./$pathcomp ;;
	    esac
	    if test ! -d "$pathcomp" ; then
		if test -e "$pathcomp" ; then
		    if test ${verbose:-0} -gt 1 ; then $ECHO "$RM \"$pathcomp\"" ; fi
		    if test ":${run:-yes}" != ":no" ; then $RM "$pathcomp" ; fi
		fi
		if test ${verbose:-0} -gt 1 ; then $ECHO "mkdir \"$pathcomp\" || lasterr=$?" ; fi
		if test ":${run:-yes}" != ":no" ; then
		    mkdir "$pathcomp" || lasterr=$?
		    if test ! -d "$pathcomp" ; then
			errstatus=$lasterr
		    elif test ! -z "$permission" ; then
			lasterr=
			chmod 0777 "$pathcomp" || lasterr=$?
			if test ! -z "$lasterr" ; then
			    errstatus=$lasterr
			fi
		    fi
		fi
	    fi
	    pathcomp="$pathcomp/"
	done
    done
    for entry in $entries ; do
	eval "driver=\"\$driver_$entry\""
	eval "device=\"\$device_$entry\""
	eval "access=\"\$access_$entry\""
	eval "minors=\"\$minors_$entry\""
	eval "fminor=\"\$fminor_$entry\""
	eval "lminor=\"\$lminor_$entry\""
	if test ":$minors" = ":clone" ; then
	    if test ${verbose:-0} -gt 1 ; then $ECHO "mknod -m $access $device c $minors $driver" ; fi
	    if test ":${run:-yes}" != ":no" ; then mknod -m $access $device c $minors $driver ; fi
	else
	    minor="$fminor"
	    while test $minor -le $lminor ; do
		devname="$device"
		decimal=`printf '%d' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%d|$decimal|g'\`"
		lchexad=`printf '%x' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%x|$lchexad|g'\`"
		uchexad=`printf '%X' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%X|$uchexad|g'\`"
		octalno=`printf '%o' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%o|$octalno|g'\`"
		unsignd=`printf '%u' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%u|$unsignd|g'\`"
		integno=`printf '%i' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%i|$integno|g'\`"
		if test ${verbose:-0} -gt 1 ; then $ECHO "mknod -m $access $devname c $driver $minor" ; fi
		if test ":$run" != ":no" ;  then mknod -m $access $devname c $driver $minor ; fi
		((minor++))
	    done
	fi
    done
}

function delete_command()
{
    if test ${verbose:-0} -gt 1 ; then
	$ECHO "Deleting devices using \`$filename'"
    fi
    for entry in $entries ; do
	eval "device=\"\$device_$entry\""
	eval "minors=\"\$minors_$entry\""
	eval "fminor=\"\$fminor_$entry\""
	eval "lminor=\"\$lminor_$entry\""
	if test ":$minors" = ":clone" ; then
	    if test ${verbose:-0} -gt 1 ; then $ECHO "$RM $device" ; fi
	    if test ":${run:-yes}" != ":no" ; then $RM $device ; fi
	else
	    minor="$fminor"
	    while test $minor -le $lminor ; do
		devname="$device"
		decimal=`printf '%d' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%d|$decimal|g'\`"
		lchexad=`printf '%x' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%x|$lchexad|g'\`"
		uchexad=`printf '%X' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%X|$uchexad|g'\`"
		octalno=`printf '%o' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%o|$octalno|g'\`"
		unsignd=`printf '%u' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%u|$unsignd|g'\`"
		integno=`printf '%i' $minor`
		eval "devname=\`$ECHO \"$devname\" | $SED -e 's|%i|$integno|g'\`"
		if test ${verbose:-0} -gt 1 ; then $ECHO "$RM $devname" ; fi
		if test ":${run:-yes}" != ":no" ; then $RM $devname ; fi
		((minor++))
	    done
	fi
    done
}

case "$command" in
    none)
	none_command
	;;
    config)
	none_command
	config_command
	;;
    install | filename)
	none_command
	test_input_file
	parse_file <$filename
	delete_command
	install_command
	;;
    delete)
	none_command
	test_input_file
	parse_file <$filename
	delete_command
	;;
    *)
	( usage ) >&2
	exit 1
	;;
esac

exit 0

# vim: ft=sh sw=4
