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 829 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.
    • Klaus KonzeptK
      Klaus Konzept
      last edited by

      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

      Alan KilbornA 2 Replies Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Klaus Konzept
        last edited by Alan Kilborn

        @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
        • Alan KilbornA
          Alan Kilborn @Klaus Konzept
          last edited by Alan Kilborn

          @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
          • Klaus KonzeptK
            Klaus Konzept
            last edited by

            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

            Vitalii DovganV 1 Reply Last reply Reply Quote 1
            • Vitalii DovganV
              Vitalii Dovgan @Klaus Konzept
              last edited by

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

              Klaus KonzeptK 1 Reply Last reply Reply Quote 0
              • Klaus KonzeptK
                Klaus Konzept @Vitalii Dovgan
                last edited by

                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
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors