rick@jpusa1.chi.il.us (Rick Mills) (02/23/91)
The following sh/awk script was written by a colleage
of mine to create a "tags" file for the vi editor from a list
of .4gl files.
I've found it very useful in working with Informix 4gl.
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
# 4gltags
# This archive created: Sat Feb 23 08:33:00 1991
# By: rick (JPUSA - Chicago, IL)
export PATH; PATH=/bin:/usr/bin:$PATH
echo shar: "x - '4gltags'"
if test -f '4gltags'
then
echo shar: "will not over-write existing file '4gltags'"
else
cat << \SHAR_EOF4gltags > '4gltags'
:
# 4gltags - written by Stu Heiss - 02/22/91
tmp=/tmp/$$tags
trap 'rm -f $tmp;exit' 0 1 2 3 15
usage() { echo "usage: $0 [-au] file ..."; exit 1; }
uflag=false
aflag=false
set -- `getopt ua $*` || usage
for i
do
case "$i" in
-a) aflag=true;shift;;
-u) uflag=true;shift;;
--) shift;break;;
esac
done
test $# -lt 1 && usage
files="$@"
awk '
/end[ ]*function/ {
next
}
/function/ {
save=$0
sub(/#.*$/,"") # strip trailing comments
if ((i=index($0,"function"))==0) next
s=substr($0,i+8)
i=index(s,"(") # must be followed by open paren
if(i==0) next
token=substr(s,1,i-1) # function name
sub(/^[ ]/,"",token) # strip leading/trailing blanks
sub(/[ ]$/,"",token)
line=""
while((i = index(save,"\\"))>0) {
line = line substr(save,1,i-1) "\\\\"
save = substr(save,i+1)
}
if (tokens[token]) {
if (tokens[token] == FILENAME)
printf("Duplicate function in file %s, line %d: %s\nSecond entry ignored\n",
FILENAME, FNR, token) | "cat >&2"
else
printf("Duplicate function in files %s and %s: %s (Warning only)\n",
FILENAME, tokens[token], token) | "cat >&2"
continue
}
tokens[token] = FILENAME
printf("%s\t%s\t/^%s%s$/\n", token, FILENAME, line, save)
next
}
{
next
}
' $files > $tmp
$uflag && {
for file in $files
do
mv tags OTAGS
fgrep -v " ${file} " OTAGS > tags
rm OTAGS
done
aflag=true
}
if $aflag;then
cat $tmp >> tags
else
cat $tmp > tags
fi
SHAR_EOF4gltags
chmod +x '4gltags'
fi
exit 0
# End of shell archive
--
rick