Multi line (or ignore line) search

jalaram

Lifer
Aug 14, 2000
12,920
2
81
I'm trying to find all calls of a macro which have a specific option in one of its parameters. This is C++ and the macro calls can be spread over multiple lines.

VS 2008 allows one to search over multiple lines of text as long as you know how many newlines exist between tags. E.g. "ExampleCommand.*\n.*optICareAbout". Is there a way (in or out of VS) to search over multiple lines where one doesn't know the exact numbers of newlines?
 

jalaram

Lifer
Aug 14, 2000
12,920
2
81
I don't know why the code didn't format correctly. Imagine that the various calls spread over multiple lines. :)
 

jalaram

Lifer
Aug 14, 2000
12,920
2
81
Originally posted by: Dhaval00
You could try a regex search?

Is there a free program that handles the /s option on a regex search? WinGrep and PrGrep don't seem to.
 

imported_Dhaval00

Senior member
Jul 23, 2004
573
0
0
I meant the regex search from within Visual Studio. In the "Find" window, you have the option to specify a regex, and Visual Studio will do the searching for you.
 

jalaram

Lifer
Aug 14, 2000
12,920
2
81
Originally posted by: Dhaval00
I meant the regex search from within Visual Studio. In the "Find" window, you have the option to specify a regex, and Visual Studio will do the searching for you.

Yes, but the only way to search multiple lines is with the \n tag and that matches one newline. There may be 1, 2, or 3 newlines between the two terms.

I wish my included code formatted better to illustrate my difficulty.
 

imported_Dhaval00

Senior member
Jul 23, 2004
573
0
0
I guess you just need to come up with the proper regex - you can specify the min/max occurrences in a regex using the {n, m} construct - n being the min, m being the max.
 

QuixoticOne

Golden Member
Nov 4, 2005
1,855
0
0
If "optICareAbout" isn't a common string, just search for it and manually filter out the ones that don't correspond to macro calls of the right sort.

Otherwise use a proper regexp processing system. AWK, PERL, PYTHON, RUBY, even a good GREP could do that for you.

IDK if SourceNavigator is better than VS08 in terms of search, but I wouldn't be surprised if it was.
http://sourcenav.sourceforge.net/

Actually if you're a cracker jack programmer and you're using a VS2008 other than express edition, why don't you just WRITE a proper regexp search plug in for VS2008 in C# or whatever your favorite language is -- it couldn't take more than a hand-full of lines of code to do, the regexp libraries are all there in great abundance, and they're always bragging about the extensibility of VS2008, the SDK for it can't be that hard to use...


 

QuixoticOne

Golden Member
Nov 4, 2005
1,855
0
0
PS -- if you're looking for real REGEXP command line utilities for Windows, look at CYGWIN for a real awk / grep / sed / et. al.

Of course there are stand-alone windows PERL, RUBY, et. al. ports.

If you want something Windows oriented from Microsoft, install PowerShell V2 CTP from Microsoft's download page and call the regexp function from .NET via a script.

The way to 'cheat' and do it is to run the program through the C preprocessor or a code formatting program (think indent or whatever) that'll just UNDO the line breaks for you and leave you with more parsable code out... I suppose you'd have to see if there was an CPP option to NOT cook the macros but which would undo unnecessary white-space on the input.

Personally I'd us
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Lucky for you ExampleFunction() is a macro:

#define ExampleFunction(blah, blah, blah, optICareAbout, blah, blah ) {
if( optICareAbout == thingImLookingFor ) {
printf("%s:%i\n",__FILE__,__LINE__);
}
... /* More macro here... */
}
 

QuixoticOne

Golden Member
Nov 4, 2005
1,855
0
0
That only works if he has complete code COVERAGE to EXECUTE that code in every line it appears in. I suppose it could work if there were 100% code coverage unit tests available but.....

Now if he got really kinky with the macro and stringizing and whatever the compiler / preprocessor supported he might just be able to get a #warning out of each of the matching instances.. or at least generate a hard compile error that would stop on that line and then let him incrementally fix / note the occurrences...