summaryrefslogtreecommitdiffstats
path: root/etc/MAKEDEV
diff options
context:
space:
mode:
authorsheldonh <sheldonh@FreeBSD.org>2001-11-20 17:24:35 +0000
committersheldonh <sheldonh@FreeBSD.org>2001-11-20 17:24:35 +0000
commitaaeaa0d93a3f84c33ed33fba93d9716170b5c36f (patch)
treec74760428ebba8f32fdd84f4c93c8517c1813e88 /etc/MAKEDEV
parentd2f823593c6c3eae8866726d9c61f5899720287f (diff)
downloadFreeBSD-src-aaeaa0d93a3f84c33ed33fba93d9716170b5c36f.zip
FreeBSD-src-aaeaa0d93a3f84c33ed33fba93d9716170b5c36f.tar.gz
Introduce new shell functions hexdigit, hexprint and zeropad.
Use these new functions instead of printf(1), which is scheduled for removal as a shell builtin command, and which will not be available as a standalone utility if MAKEDEV is run prior to mounting /usr. Requested by: knu
Diffstat (limited to 'etc/MAKEDEV')
-rw-r--r--etc/MAKEDEV51
1 files changed, 48 insertions, 3 deletions
diff --git a/etc/MAKEDEV b/etc/MAKEDEV
index 02c0d3a..823dc75 100644
--- a/etc/MAKEDEV
+++ b/etc/MAKEDEV
@@ -196,6 +196,39 @@ dkminor()
echo $(($1 << 25 | ($2 / 32) << 21 | ($2 % 32) << 3 | $3 << 16 | $4))
}
+# Print the hexadecimal representation of a decimal value from 0 to 15
+hexdigit () {
+ if [ $1 -lt 10 ]; then
+ echo $1
+ else
+ case $1 in
+ 10) echo a ;;
+ 11) echo b ;;
+ 12) echo c ;;
+ 13) echo d ;;
+ 14) echo e ;;
+ 15) echo f ;;
+ esac
+ fi
+}
+
+# Print the hexadecimal representation of an arbitrary decimal value
+hexprint () {
+ val=$1
+ str=''
+
+ dig=`hexdigit $((${val} & 15))`
+ str=${dig}${str}
+ val=$((${val} >> 4))
+ while [ ${val} -gt 0 ]; do
+ dig=`hexdigit $((${val} & 15))`
+ str=${dig}${str}
+ val=$((${val} >> 4))
+ done
+
+ echo ${str}
+}
+
# Override mknod(2) to add extra handling to it.
mknod=/sbin/mknod
for i in `IFS=':'; echo $PATH`; do
@@ -239,6 +272,18 @@ unit2minor()
echo $(((($1 >> 8) << 16) | ($1 % 256)))
}
+# Zero-pad a value to the appropriate minimum length
+zeropad () {
+ min=$1
+ val=$2
+
+ while [ ${#val} -lt ${min} ]; do
+ val=0${val}
+ done
+
+ echo ${val}
+}
+
# Raw partition for disks
dkrawpart=2
@@ -1073,7 +1118,7 @@ vty*)
units=`expr $i : 'vty\(.*\)'`
i=0
while [ $i -lt $units ]; do
- mknod ttyv$(printf %01x $i) c $chr `unit2minor $i`
+ mknod ttyv$(hexprint $i) c $chr `unit2minor $i`
i=$(($i + 1))
done
ln -fs ttyv0 vga # XXX X still needs this pccons relic
@@ -1182,7 +1227,7 @@ ttyA*)
port=1
while [ $port -le $units ]; do
minor=$(expr $port - 1)
- name=$(printf %02d $port)
+ name=$(zeropad 2 $port)
mknod ttyA$name c $major $minor
mknod ttyiA$name c $major `expr $minor + 65536`
mknod ttylA$name c $major `expr $minor + 131072`
@@ -1199,7 +1244,7 @@ cuaA*)
port=1
while [ $port -le $units ]; do
minor=$(expr $port - 1)
- name=$(printf %02d $port)
+ name=$(zeropad 2 $port)
mknod cuaA$name c $major `expr $minor + 128` uucp:dialer
mknod cuaiA$name c $major `expr $minor + 128 + 65536` \
uucp:dialer
OpenPOWER on IntegriCloud