18 September, 2007

Etags

Imagine studying the linux kernel (for entirely sane purposes :D) with thousands of files containing thousands of functions... Around 70MB worth of text... And you are told to find a function in this haystack !! (well... don't even try grep.. it takes MONTHS to return a result.. I'd rather search manually :P)

Etags swoops in to ur rescue...
etags is basically a utility which generates tags for each function or data definition.
eg. a function declaration fun() would yeild "fun" as a tag. The corresponding file name and the offset at which the definition can be found is recorded in the file TAGS. TAGS is used by Emacs editor to simulate hyperlinks for tokens.
In simple language, if you come across a function and wonder how it is coded... just move the cursor over the function name and press M-. (M= meta key... usually ALT)... and voila!
The simplest way to browse a code !!
neat... eh!

wanna go back to where you were... no probs... M-* and there you are !!
Linux continues to amaze me!!

For kernel source code :
go to /usr/src/linux-[version]
login as su.. nd type in "make TAGS"...

For your own directory tree:
this is a bit clumsy since etags dosen't support nested directories... etags searches for specified files ONLY in the current directory... so.. the roundabout way is :
go to the root of your directory tree and type in
$ find . -name "*.[chCH]" -print | etags -
and voila!:D

what it does is... the find command returns all the filenames of .c and .h extension and this output is piped to etags command (the hyphen after etags directs etags to use standard output as its input)...

now that i see what linux editors can do... notepad suddenly appears soo lame !!:)

No comments: