Understanding large source code with gonzui
Posted by Steve on Tue 3 May 2005 at 15:51
When you first start examining a new project it can be hard to understand the source code, especially if it's a large project. Whilst often a simple bugfix, or tweak can be made to a project by somebody who doesn't understand the full picture it's hard to know where to start.
To solve this problem there are a range of different "source navigators", these are programs which are designed to make it simple for you to see where functions are defined, called, etc.
One of the best known of the source tools is a project called Source-Navigator. This is a tool which allows you to explore, and work with, a large codebase easily.
Another example of such a tool is the oo-browser package for Emacs, which gives you the ability to visualise hierarchys of code, and move around with ease.
Both the projects mentioned previously have one thing in common, they use their own IDE. (Although in the case of Emacs some people might be happy with that!)
Requiring you to use a particular environment to browse the code might seem like a good idea, but it can be a problem if you're used to developing in another tool or environment.
This is where gonzui comes in, it's an indexer and cross-linker of source code, which presents the code to you in your browser. (Of course because it indexes it has a drawback of its own, it doesn't update live, you must refres the index manually.)
The package is available in the Debian archive in the unstable distribution at the moment, and the testing archive shortly.
Installing gonzui is very simple, as we've come to expect from Debian packages:
apt-get install gonzui
Once the package is installed you can start using it to index your source code.
If, for example, you can have some source code installed in a directory ~/Programs you can index it like this:
gonzui-import ~/Programs
This will give you a progress bar as it completes the job of indexing the code. Once it's done you can then start the server, and point your browser at it:
gonzui-server
The server will, by default, listen upon port 46984. If you wish to change this you can either:
- Specify an alternate port on the command line "gonzui-server --port=9999".
- Copy the sample configuration file /etc/gonzuirc.sample to ~/.gonzuirc, and edit the port there.
Once the server is running open your browser and point it at the relevent port, as discussed this will default to:
http://localhost:46984/
The GUI will then present itself, allowing you to list all the importated proejcts, or search through the indexed code.
Whilst the interface is very simple and clean, it's suprisingly powerful. It allows you to see where functions are called, defined, and more. The sample screenshots will give a good idea of what it looks like.
Using the search engine from your browser isn't the only way to find code though, you also get a console-based program to search for code called gonzui-search. This works even if the server isn't running, using the raw index to find things.
Here is a small sample of searching for the function "popen" in a bunch of code:
skx@mystery:~$ gonzui-search popen
wanna-build/andrea/run_andrea-mail: p = os.popen("%s -t" % SENDMAIL, "w");
wanna-build/andrea/run_andrea-mail: p = os.popen("%s -t" % SENDMAIL, "w");
Here we see the file that matched, as wells as the text of the line itself.
[ Parent | Reply to this comment ]
(Since egrep == grep -E, and gnu's grep has no difference between extended and basic regexes?)
I'm a rgrep(1) fan myself =)
[ Parent | Reply to this comment ]
No, there is a difference between extended and basic regexps:
mas90@neptune ~ $ cat testfile fooo fo+ mas90@neptune ~ $ grep fo+ testfile fo+ mas90@neptune ~ $ grep -E fo+ testfile fooo fo+
[ Parent | Reply to this comment ]
Grep understands three different versions of regular expression syntax: "basic," "extended," and "perl." In GNU grep, there is no difference in available functionality using either of the first two syntaxes.and:
In basic regular expressions the metacharacters ?, +, {, |, (, and )
lose their special meaning; instead use the backslashed versions \?,
\+, \{, \|, \(, and \). so to replicate your second example from above I could do: grep fo\\+ testfile(note that you must escape the slash in bash)
[ Parent | Reply to this comment ]
happy hacking
/Rainer
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]