1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#!/bin/sh
#
# This file is part of tela the Tensor Language.
# Copyright (c) 1994 Pekka Janhunen
#
# telahelp.sh
# This script is called by the Tela kernel when help on t-function
# is requested by the user.
# Usage: telahelp.sh myfn fyle.t
# scans for the definition of function myfn in fyle.t
# trying to extract the comment immediately following the header.
# Both /* ... */ and sequential // comments are recognized.
#
# This script should work in almost any Unix system.
# It only needs /bin/sh, egrep, tail and basic old awk.
fn=$1
file=$2
if [ -f "$file" ]; then
lines=`egrep -n "^[ \t]*function[^{]*[ \=\\t]${fn}[ \\t]*\\(" "$file" | cut -f1 -d':'`
if [ -n "$lines" ]; then
for line in $lines; do
tail +`expr $line + 1` "$file" | awk '
BEGIN {incomment=0; printed=0}
/\/\*.*/ {
printed = 1
if (NR == 1) {
incomment = 1
L = length();
if ($0 ~ /\*\//) {
print substr($0,3,L-4)
incomment = 0
} else
print substr($0,3,L-2)
} else
exit
next
}
/.*\*\// {
print substr($0,1,length()-2)
exit
}
/\/\/.*/ {
printed = 1;
if (substr($0,3,1) == " ")
print substr($0,4,length()-3)
else
print substr($0,3,length()-2)
next
}
{
if (incomment) {
printed = 1
print
} else
exit
}
END {if (!printed) print "No comment string."}
'
done
else
echo "Function pattern \"${fn}\" not found in \"${file}\"."
exit 1
fi
else
echo '*** telahelp.sh: File '"$file"' not found.'
exit 1
fi
|