Results 1 to 5 of 5
I have a C++ project , some of the source files have function calls like this:
WarningMsg("Something is here");
My job is to come up with a way to find ...
- 04-16-2009 #1Just Joined!
- Join Date
- Apr 2009
- Posts
- 1
Find all warning messages in code
I have a C++ project , some of the source files have function calls like this:
WarningMsg("Something is here");
My job is to come up with a way to find all such instances in all files. And output the entire WarningMsg("Something is here") to a text file. I tried using grep, it worked but I found out WarningMsg could be spread across more than one line, eg:
if( ... ) WarningMsg(
"A warning
message");
What is the best way to solve this problem? Please give me some tips.
- 04-17-2009 #2Just Joined!
- Join Date
- Apr 2009
- Posts
- 14
It certainly won't match every possible case of function call in C++ but if You are sure that WarinngMsg() is called only with a constant "in-place" char *, then my code should work:
Code:grep -P 'WarningMsg(?s).*?\)'
- 04-17-2009 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
This is one of those situations where a short C or C++ program might be a better solution, especially if you want to filter out any of these that might be buried inside comments or are only conditionally compiled into the code. It's one of those tasks that seem like they should be simple on the surface of it, but end up being more complex and difficult to accomplish than anticipated.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 04-17-2009 #4Linux Guru
- Join Date
- Nov 2004
- Posts
- 6,110
I'm not sure how much use it will be, but just to throw it in there....the strings command is very useful for outputting text strings in binaries. I'm not sure how useful it'll be for the filter you need, but thought it may be useful.
- 04-18-2009 #5Just Joined!
- Join Date
- Apr 2009
- Posts
- 14
You're right. There's no way regular expressions will work in all situations, i.e. if You use another function inside of WarningMsg. Regular expressions are not powerful enough to parse a(ny) language, so to fully achieve the goal You need to construct Your own grammar. If You want, You can use a lex/yacc pair to do it easily.


Reply With Quote
