Reputation: 14893
Let's say we have a project (e.g. a library) consisting of 100 files, each contains about 1000 lines of code. You want to find the function awesome_foo(...) How do you do it? Honestly, I find grepping it creepy and ineffective...
EDIT: I'm looking mainly for the function definition
Upvotes: 3
Views: 1013
Reputation: 1651
another possibility is astro grep which is a windows aplication which gives you a gui to form your grep statements, taking the 'sting' out and making the process of forming complicated searches very simple.
"features: - Regular expressions (Uses the standard Microsoft .Net Regular Expressions: Quick Reference) - Concurrent multiple file types - Recursive directory searching - A "context" feature that selects the lines above and below your search expression - Most Recently Used list for search paths - Somewhat versatile printing options - Double click to open file with editor of your choice - Store Most Recently Used file names and search expressions - Match Whole Word Only - Syntax highlighing - Free of charge and Open Source"
Upvotes: 1
Reputation: 27242
The ctags/etags programs are useful under linux and cygwin environments. They have bindings for editors like vim and emacs as well as other tools. It lets you select functions and can then move back and forth between declarations and implementations, among other things.
Upvotes: 1
Reputation: 72299
Integrated development environments parse your code and generate an index that allows you to navigate to each symbol's declaration (or usages) by ctrl+clicking on it, or using some keyboard shortcut. That's how people often work on large codebases.
If you aren't using an IDE, you still have some options.
CTags is an indexer that read source files and generates "index files" which contain symbol information for your program. It can be hooked up into an editor (such as Vim) or just generate a human-readable symbol reference.
This is the output of ctags -x
for an example program:
DrawGLScene 37 lesson5.c void DrawGLScene()
InitGL 15 lesson5.c void InitGL(int Width, int Height) // We call this right after our OpenGL window is created.
ReSizeGLScene 24 lesson5.c void ReSizeGLScene(int Width, int Height)
keyPressed 62 lesson5.c void keyPressed(unsigned char key, int x, int y)
main 78 lesson5.c int main(int argc, char **argv)
It looks like "name, line and file, signature" and can be easily used as an index manually.
−x
Print a tabular, human-readable cross reference (xref) file to standard output instead of generating a tag file. The information contained in the output includes: the tag name; the kind of tag; the line number, file name, and source line (with extra white space condensed) of the file which defines the tag. No tag file is written and all options affecting tag file output will be ignored. Example applications for this feature are generating a listing of all functions located in a source file (e.g. ctags −x −−c−kinds=f file), or generating a list of all externally visible global variables located in a source file (e.g. ctags −x −−c−kinds=v −−file−scope=no file). This option must appear before the first file name.
Upvotes: 4
Reputation: 9494
grep -irnw "awesome_foo" *
definitly will give you result.
The parameters are:
-i, --ignore-case
Ignore case distinctions in both the PATTERN and the input files.
-n, --line-number
Prefix each line of output with the line number within its input file.
-R, -r, --recursive
Read all files under each directory, recursively; this is equivalent to the -d recurse option.
-w, --word-regexp
Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word con- stituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word- constituent characters are letters, digits, and the underscore.
Upvotes: 5
Reputation: 2329
Use eclipse
IDE. You can track functions in navigator. CodeInsight
is also fine. Just add a project to add keep track of your code. Believe me it will save your time.
Upvotes: 1
Reputation: 1651
if you can use something like notepadd++ that has a great find in files tool that will return all instances of a direct text search or even a regex. i use this a lot and its very helpful.
Upvotes: 4