Re: __initfunc - very clever and nice, but...

Pete Wyckoff (pw@dancer.ca.sandia.gov)
Thu, 9 Jul 1998 08:55:23 -0700


The following script lives in /usr/src/linux/scripts/dotags, and acts as a
wrapper to ctags, which I run once every major upgrade. It's a hack.
Notice the exclusion of trees which I claim not to be interested in; this
looks different on my alpha machines, of course. You may choose not to
be so drastic in your pruning.

The interesting part is the parsing of __initfunc. It seems to work on
all cases today, but looks very tender to me. I'd appreciate it if someone
would rewrite this in a real programming languange (no offense to the awk
fanatics).

-- Pete

#!/bin/sh
#
# Make my favorite tags file, without non-i386 architecture specific stuff,
# and replacing __initfunc with the function name it encloses. Not sorting
# in ctags since stripping the __initfunc will produce previously unsorted
# tags. Sort afterward.
#
# Someday do __initdata too.
#
# Written by Pete Wyckoff <wyckoff@ca.sandia.gov>, 1997.
#
find . -name '*.[chS]' -print |\
egrep -v '^\.\/(arch\/|include\/asm-)(alpha|arm|m68k|mips|ppc|sparc)' |\
egrep -v '^\.\/drivers\/(acorn|ap1000|fc4|isdn|macintosh|nubus|pnp|sbus|sgi|video)\/' |\
ctags -L - -f - --totals=yes --sort=no | awk -F\\011 '
/^__initfunc/ {
# strip initfunc off regexp
re = $3
sub("__initfunc[ \t]*[(][ \t]*", "", re)
# rindex to remove last ), seems awk has only index()
for (i=length(re); i>=0; i--) {
if (substr(re, i, 1) == ")") {
re = substr(re, 1, i-1) substr(re, i+1)
break
}
}
# find func name
split(re, arr, "[ \t]")
for (i=1; i<100; i++) { # so it will terminate sometime
if ((j = index(arr[i], "(")) > 0) {
if (j == 1) # space after func name and befor paren
fnc = arr[i-1]
else
fnc = substr(arr[i], 1, j-1)
break
}
}
# take off the "*" in case the func returns a pointer to something
if (index(fnc, "\*") > 0)
fnc = substr(fnc, 2)
printf "%s\t%s\t%s\n", fnc, $2, $3;
next
}
{ print }
' | sort > tags
exit 0
-----------------------------------------------------
Pete Wyckoff | wyckoff@ca.sandia.gov
Sandia National Laboratories | 925 294 3503 (voice)
MS 9011, P.O. Box 969 | 925 294 1225 (fax)
Livermore, CA 94551 |

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu