Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/etc Add hexprint(); display the given number as hex.



details:   https://anonhg.NetBSD.org/src/rev/585fd89afd9e
branches:  trunk
changeset: 580635:585fd89afd9e
user:      lukem <lukem%NetBSD.org@localhost>
date:      Mon May 02 00:46:46 2005 +0000

description:
Add hexprint(); display the given number as hex.
Add a comment to document zeropad()'s purpose.

diffstat:

 etc/MAKEDEV.tmpl |  25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)

diffs (47 lines):

diff -r 9a1312c51d4f -r 585fd89afd9e etc/MAKEDEV.tmpl
--- a/etc/MAKEDEV.tmpl  Mon May 02 00:45:08 2005 +0000
+++ b/etc/MAKEDEV.tmpl  Mon May 02 00:46:46 2005 +0000
@@ -1,5 +1,5 @@
 #!/bin/sh -
-#      $NetBSD: MAKEDEV.tmpl,v 1.42 2005/04/30 16:26:06 augustss Exp $
+#      $NetBSD: MAKEDEV.tmpl,v 1.43 2005/05/02 00:46:46 lukem Exp $
 #
 # Copyright (c) 2003 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -296,7 +296,11 @@
        exit 1
 }
 
-zeropad() {
+# zeropad width number
+#      display number with a zero (`0') padding of width digits.
+#
+zeropad()
+{
        case $(($1 - ${#2})) in
        5)      echo 00000$2;;
        4)      echo 0000$2;;
@@ -308,6 +312,23 @@
        esac
 }
 
+# hexprint number
+#      display (base10) number as hexadecimal
+#
+hexprint()
+{
+       case $1 in
+       [0-9])  echo $1 ;;
+       10)     echo a ;;
+       11)     echo b ;;
+       12)     echo c ;;
+       13)     echo d ;;
+       14)     echo e ;;
+       15)     echo f ;;
+       *)      echo $(hexprint $(($1 / 16)))$(hexprint $(($1 % 16))) ;;
+       esac
+}
+
 do_force=false
 do_specfile=false
 while getopts fm:s ch; do



Home | Main Index | Thread Index | Old Index