Monday, November 15, 2004

Search4Code - Simple Source-Code Search Tool

I wrote this simple source-code search tool. It can be used to search the internet for source-code files in the specified language, containing the specified text in them. You may find the tool very useful to learn new APIs.

Text:  Language:   


How does it work?
Search4Code uses Google Search behind the scenes. It uses the filetype search parameter of Google to restrict a search within files having the well-known file-extension of the language being searched for. The tool currently supports C, C++, C#, VB etc. and support for more languages can be easily added in the future.

Koders (currently in beta) offers a similar service but they appear to have a dedicated search-engine of their own. Search4Code on the other hand is a meta-search engine (a search-engine that uses another search-engine behind the scenes). My ultimate aim with Search4Code is to also allow for the searching of package/class/method/variable declarations and references.

[Update on 16-Nov-2004] Thanks to Bheema for his suggestions in the comments. He suggested to include header files (.h) when searching in C program files (.c) and C++ program files (.cpp or .cc). Google does not understand the logical OR operator in its as_filetype parameter but offers filetype keyword in the search query. Thus the solution is to simply do some processing on the search query text before submitting the form if the search language happens to be C or C++. I chose to write my first manual JavaScript for this and hook onto the onSubmit event of the form.

Unfortunately, while updating this post, I found that Blogger.com does not allow <script> tags in the posts :-(

So I guess, its time to have a dedicated webpage for Search4Code! I shall try to get one up ASAP and update this post with info about the same.

Check back for more updates!