#/bin/bash
# Written as an excercise for sed, but actually does something useful.
# It is very slow, but who cares anyway.
# On my Celery 300MHz Notebook it takes about 50sec to complete, so
# be patient
#
# (c) 2000 Tilmann Bitterberg
# Mon Nov 20 02:51:52 CET 2000
########## CONFIGURE ############
PROCROOT="/proc" # e.g /home/tibit/test/proc
#PROCROOT="/home/tibit/kernel/proc" # e.g /home/tibit/test/proc
HEXPRINT="xxd" # e.g /usr/bin/hexdump
GSED="sed"
########## END CONFIGURE ############
# all dirs
function getdirs () {
x=`echo $1|$GSED 's,.*/,,'` # strip fullpathname
y=`echo $1|$GSED 's/..//;s,/,|,g'`
echo "
"
echo "Node $x"| $GSED 's/Node \./Root Node/g'
echo " |
"
SEDDIR='s,..,,;s,/,|,g;s|.*|& &
|'
SEDFIXUP='s:\([^>]*>\)[^<]*|\([^<]*\):\1\2:'
# Note: Puts name at the beginning for sorting, gets deleted afterwards
# !!
SEDSYM='s|\(\([^ ]*/\)*[^:]*\):.*to \(.*\)$|\1 \1 -\> \3|;s,/,|,g;s|$|
|'
(
find $1 -maxdepth 1 -type l | $GSED 's,\./,,' | xargs file 2>/dev/null | \
$GSED -e "$SEDSYM" -e "$SEDFIXUP" 2>/dev/null
find $1 -maxdepth 1 -type d 2>/dev/null|
$GSED -e "$SEDDIR" -e "$SEDFIXUP"
) | sort | $GSED 's|^[^ ]* ||'
}
function getproperty () {
cd $1
a=0;
x=`echo $1|$GSED 's,\./,,'`
echo "
"
echo ""
for i in `find . -maxdepth 1 -type f | $GSED 's,\./,,;s, ,|,g'`; do
if [ `expr $a % 2` = 0 ]; then
echo ""
else
echo "
"
fi
echo "\"`echo $i|sed 's,|, ,g'`\""
$HEXPRINT "`echo $i|$GSED 's,|, ,g'`"| $GSED '$s|$| |
|'
a=`expr $a + 1`
done
echo "
"
cd -
}
function getrest () {
cd $1
for i in `find . -type d`; do
getdirs $i | $GSED '4d'
getproperty $i
done
cd -
}
function getindex () {
cd $1
echo ""
echo "Root Node"
find . -type d | $GSED 'ss..ss;/^$/d;/^.$/d;s/^\.$//' | $GSED '
h; # save for later use
s,/,|,g
x
:t;\|/|s|\( *\)*[^/]*/|\1 |;tt
\|^ |!s|^|/|
G
s,\( *\)\([^\n]*\)\n\(.*\),\1\2,
'
echo "
"
cd -
}
function getappendix () {
cd $1
echo "Appendix
Root Node"
find . | $GSED 'ss..ss;/^$/d;/^.$/d;s/^\.$//' | $GSED '
:t;\|/|s|\( *\)*[^/]*/|\1 |;tt
\|^ |!s|^|/|
'
echo "
"
cd -
}
# MAIN
olddir=`pwd -P`
cd $PROCROOT
NAME=`cat device-tree/name`
echo "Device Tree $NAME"
echo "Device Tree $NAME
generated on `date`Index
"
getindex device-tree
getrest device-tree
cd $PROCROOT
# getappendix device-tree
echo ""
cd $olddir