• Login
Community
  • Login

search in C-files and give me the name of the C-function

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 3 Posters 870 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K
    Klaus Konzept
    last edited by Aug 16, 2022, 11:02 AM

    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

    A 2 Replies Last reply Aug 16, 2022, 12:22 PM Reply Quote 0
    • A
      Alan Kilborn @Klaus Konzept
      last edited by Alan Kilborn Aug 16, 2022, 12:23 PM Aug 16, 2022, 12:22 PM

      @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 expression

      In 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:

      ae5a0839-65a8-464d-bd49-8318df82c8eb-image.png

      Again, having “strongly patterned” data is key to success here…or writing even more complex regular expressions than the sample one.

      1 Reply Last reply Reply Quote 1
      • A
        Alan Kilborn @Klaus Konzept
        last edited by Alan Kilborn Aug 16, 2022, 12:34 PM Aug 16, 2022, 12:34 PM

        @Klaus-Konzept

        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.

        1 Reply Last reply Reply Quote 1
        • K
          Klaus Konzept
          last edited by Aug 16, 2022, 1:55 PM

          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

          V 1 Reply Last reply Aug 17, 2022, 6:53 PM Reply Quote 1
          • V
            Vitalii Dovgan @Klaus Konzept
            last edited by Aug 17, 2022, 6:53 PM

            Probably these two plugins can help? –
            https://github.com/vinsworldcom/nppTagLEET
            https://github.com/d0vgan/TagsView

            K 1 Reply Last reply Aug 19, 2022, 5:20 AM Reply Quote 0
            • K
              Klaus Konzept @Vitalii Dovgan
              last edited by Aug 19, 2022, 5:20 AM

              Hi Vitalii,

              cool things are out there, thanks you for your hints.
              I even didn’t know ctags.

              Klaus

              1 Reply Last reply Reply Quote 0
              6 out of 6
              • First post
                6/6
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors