search in C-files and give me the name of the C-function
-
Fellow Notepad++ Users,
Could you please help me the the following search problem I am having?
I would like to find an identifier (e.g. a preprocessor define) in a bunch of .c sourcefiles.
For each result, I need to get not only the filename, but also the name of the C function, in which the identifier was found.If I use ‘Find in Files’ to search for an identifier and double-klick on one of the results, the name of the corresponding C-function is highlighted in the 'Function List" view.
Therefore I think notepad++ should be able to do what I described above, automatically.Thank you in advance!
Best Regards
Klaus -
@Klaus-Konzept said in search in C-files and give me the name of the C-function:
Therefore I think notepad++ should be able to do what I described above, automatically.
Well, there’s code behind that.
Certainly you could do your task by writing your own code as well.
But, let’s say for now you want to keep it within Notepad++…You can do it with Find in Files, but can you count on a reasonable pattern to your data?
For an example that works, if I had C files and I knew that all functions had their opening
{
in column 1 of the line following the function name, I’d do this search operation:Find:
(?-s)^.+?\K(\w+)(?=\(.*?\)\R(?s)^\{.*?HELLO.*?^\})
Search mode: Regular expressionIn this example,
HELLO
is the preprocessor define I’m seeking info on.If you run the search against this sample C code:
#define HELLO 1 void test(int arg) { if (arg == HELLO) { print(arg); } } void test2(int arg) { if (arg == HELLO) { print(arg); } } void test3(int arg) { if (arg == 2) { print(arg); } }
your results would be:
Again, having “strongly patterned” data is key to success here…or writing even more complex regular expressions than the sample one.
-
If your data isn’t as strongly patterned as in the example I gave, you could adapt a more-complicated regular expression to use from the function-list data file for C: look in
...\functionList\c.xml
on your system. -
Hi Alan,
thank you for your quick and helpful answer.
As you mentioned, the regular expression works for your example but not (yet) for my C-Code.
But you gave me a nudge in the right direction. From here I will try to find a solution.Thx again!
Klaus -
Probably these two plugins can help? –
https://github.com/vinsworldcom/nppTagLEET
https://github.com/d0vgan/TagsView -
Hi Vitalii,
cool things are out there, thanks you for your hints.
I even didn’t know ctags.Klaus