Subject: Re: MAKEDEV is not portable
To: Charles M. Hannum <root@ihack.net>
From: Paul Kranenburg <pk@cs.few.eur.nl>
List: port-sparc
Date: 01/06/1999 22:13:49
> So, the reason for that change was quite well documented: the old
> version ran about 10x slower.  I even proposed a more general
> solution, which none of the people who bitched about it at the time
> bothered to implement: move the mknods into shell functions, and
> provide two implementations of those functions, one using shell
> arithmetic and one using expr.

I did just that last weekend but was appalled to find that the result
ran 5x slower again (though still 2x faster than the wholy expr based
script).  Anyone with more shell script skills care to look for
something more efficient?

This is what I did (I'll gladly send the whole MAKEDEV file
(for sparc) on request):

USE_EXTENSIONS=0
shellfeatures() {
        eval i=`(temp="xxx42"; echo ${temp#xxx}) 2> /dev/null`
        if [ "$i" = 42 ]; then
                USE_EXTENSIONS=1
        fi
}

arith() {
        if [ $USE_EXTENSIONS = 1 ]; then
                eval echo '$((' "$@" '))'
        else
                echo `expr "$@"`
        fi
}

rspp() {
        if [ $USE_EXTENSIONS = 1 ]; then
                echo ${1#$2}
        else
                echo `expr $1 : '^'$2'\(.*\)'`
        fi
}
...

then use as in

	i=tty[abcd]
	unit=`rspp $i tty`


and

	minor=`arith $unit \* 8 + 0`


etc..