summaryrefslogtreecommitdiffstats
path: root/sys/kern/genassym.sh
diff options
context:
space:
mode:
authorjulian <julian@FreeBSD.org>2008-01-18 17:02:14 +0000
committerjulian <julian@FreeBSD.org>2008-01-18 17:02:14 +0000
commitd6aa139aefaddfda946f56f88c4e08544becbe38 (patch)
tree430f5556705f2432bc98d3782088c918df6e5f0a /sys/kern/genassym.sh
parent7847e23eaf9f8130047c2510a17215d528080c14 (diff)
downloadFreeBSD-src-d6aa139aefaddfda946f56f88c4e08544becbe38.zip
FreeBSD-src-d6aa139aefaddfda946f56f88c4e08544becbe38.tar.gz
refactor code so it can run in a chroot without having to have /dev/mounted
MFC After: 1 week
Diffstat (limited to 'sys/kern/genassym.sh')
-rw-r--r--sys/kern/genassym.sh81
1 files changed, 48 insertions, 33 deletions
diff --git a/sys/kern/genassym.sh b/sys/kern/genassym.sh
index 70ad69e..1cbc32b 100644
--- a/sys/kern/genassym.sh
+++ b/sys/kern/genassym.sh
@@ -1,19 +1,56 @@
#!/bin/sh
# $FreeBSD$
-# Grrr, this should use stdin and stdout, but is encrufted for compatibility.
-
usage()
{
echo "usage: genassym [-o outfile] objfile"
exit 1
}
-outfile=/dev/stdout
+
+work()
+{
+ ${NM:='nm'} "$1" | ${AWK:='awk'} '
+ / C .*sign$/ {
+ sign = substr($1, length($1) - 3, 4)
+ sub("^0*", "", sign)
+ if (sign != "")
+ sign = "-"
+ }
+ / C .*w0$/ {
+ w0 = substr($1, length($1) - 3, 4)
+ }
+ / C .*w1$/ {
+ w1 = substr($1, length($1) - 3, 4)
+ }
+ / C .*w2$/ {
+ w2 = substr($1, length($1) - 3, 4)
+ }
+ / C .*w3$/ {
+ w3 = substr($1, length($1) - 3, 4)
+ w = w3 w2 w1 w0
+ sub("^0*", "", w)
+ if (w == "")
+ w = "0"
+ sub("w3$", "", $3)
+ # This still has minor problems representing INT_MIN, etc.
+ # E.g.,
+ # with 32-bit 2''s complement ints, this prints -0x80000000,
+ # which has the wrong type (unsigned int).
+ printf("#define\t%s\t%s0x%s\n", $3, sign, w)
+ } '
+}
+
+
+#
+#MAIN PROGGRAM
+#
+use_outfile="no"
while getopts "o:" option
do
case "$option" in
- o) outfile="$OPTARG";;
+ o) outfile="$OPTARG"
+ use_outfile="yes";;
*) usage;;
esac
done
@@ -23,32 +60,10 @@ case $# in
*) usage;;
esac
-${NM:='nm'} "$1" | ${AWK:='awk'} '
-/ C .*sign$/ {
- sign = substr($1, length($1) - 3, 4)
- sub("^0*", "", sign)
- if (sign != "")
- sign = "-"
-}
-/ C .*w0$/ {
- w0 = substr($1, length($1) - 3, 4)
-}
-/ C .*w1$/ {
- w1 = substr($1, length($1) - 3, 4)
-}
-/ C .*w2$/ {
- w2 = substr($1, length($1) - 3, 4)
-}
-/ C .*w3$/ {
- w3 = substr($1, length($1) - 3, 4)
- w = w3 w2 w1 w0
- sub("^0*", "", w)
- if (w == "")
- w = "0"
- sub("w3$", "", $3)
- # This still has minor problems representing INT_MIN, etc. E.g.,
- # with 32-bit 2''s complement ints, this prints -0x80000000, which
- # has the wrong type (unsigned int).
- printf("#define\t%s\t%s0x%s\n", $3, sign, w)
-}
-' 3>"$outfile" >&3 3>&-
+if [ "$use_outfile" = "yes" ]
+then
+ work $1 3>"$outfile" >&3 3>&-
+else
+ work $1
+fi
+
OpenPOWER on IntegriCloud