Read Source Code the HTML Way

Cross-reference and convert source code to HTML for easy viewing.
Configuring Apache

The Web server I used was Apache 1.3.33. The first order of business is to set the permissions for the LXR directory. You can do that by editing the httpd.conf file, normally found under /etc/apache/httpd.conf. Add the following lines:


<Directory /var/www/htdocs/lxr>

AllowOverride All

Options All

</Directory>

Simply replace the location with wherever you've installed LXR. Then, go to $INSTALLPREFIX/http/ and create and open a file named .htaccess for editing. Type the following lines:


<File ~ (search|find|source|diff|ident)?>

SetHandler cgi-script

</Files>

This tells the Web server to treat the above-mentioned files as CGI scripts. If you don't do this, the server will display only the contents of these files. Close and save .htaccess. We are now ready to browse the cross-referenced source code.

How to Use LXR

After all of the above steps are done, all you have to do is open a Web browser and go to the URL, http:///my-ip//lxr/http/source, where /my-ip/ is the IP of your Web server. When you open the Web page, you will get something like what is shown in Figure 1.

Figure 1. Source Code Navigation via the Browser

As you can see, users can select any of the source code files for browsing. At the top, I'm using the template provided by LXR. It includes links to navigate the source code, search for a particular identifier, search for any text within the source code and search for any file.

A few utilities of note:

  • Source navigation: select this option to browse the source code of your choice.

  • Identifier search: search for the definition and uses of a particular identifier. Requires the ident script.

  • Freetext search: search for any text within the source files. Requires the search script.

  • File search: search for files matching the passed string. Requires the find script.

All of these utilities also can search using regular expressions to match the strings.

Conclusion

LXR is an excellent tool. It makes life a lot easier for people who want to study source code, and it's powerful and easy to use. The fact that it uses dynamically generated Web pages to browse the source code gives users a lot of flexibility in configuring it. Also, because it can be accessed via any Web browser, it imposes no limitations on the platform, client or location of users. This interoperability is one of the reasons LXR is so powerful.

Kamran Soomro is a software engineering student at the National University of Sciences and Technology, Pakistan. He has had great interest in Linux since he first used it during his first semester. Since then, he has been avidly involved in promoting Linux in Pakistan.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

correction

Anonymous's picture

change .glimpse-* to .glimpse_*

File search is not working properly for me

Dheeraj Gautam's picture

Hi
I tried to install lxr-0.3.1. Almost all things are working fine for me, but file search is not working properly for me. I used "glimpseindex -H /home/source" command to generate the index, then during browsing, I am getting absolute path.

Any solution for this. Please help.

typos

asadouglass's picture

Nice, straightforward article. There were a few typos which I found distracting. (htdcos?). Also, since many of us are running ubuntu nowadays, a little blumb on getting it installed in apache2.conf might have been nice.

I got success install follow

Anonymous's picture

I got success install follow this doc, thx !
btw,another tiny thing: "< File ....." should be "< Files ...."

Its a great article !! But

Anonymous's picture

Its a great article !!

But the one provided on lxr's homepage is good enough too.

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState