Undoing C syntax mangling macros to make exctags able to create prototype tags

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite












I can successfully create a tags file for vim with exctags (Exuberant Ctags).



However, creating tags allowing to jump to the prototype of a function does not work, due the system headers using a syntax-mangling macro of the form



#define _EXFUN(name, proto) name proto


and in, e.g. string.h using



char *_EXFUN(strchr,(const char *, int));


which creates a tag for _EXFUN instead of strchr:



_EXFUN /somedir/include/string.h /^char *_EXFUN(strchr,(const char *, int));$/;" p


I create tags with this command:



exctags -f tags.p --language-force=c --c-kinds=p file1 file2 ...


I've read the exctags man page up and down, tried various -I options to affect macro expansions but to no avail. Has anyone solved this?







share|improve this question























    up vote
    4
    down vote

    favorite












    I can successfully create a tags file for vim with exctags (Exuberant Ctags).



    However, creating tags allowing to jump to the prototype of a function does not work, due the system headers using a syntax-mangling macro of the form



    #define _EXFUN(name, proto) name proto


    and in, e.g. string.h using



    char *_EXFUN(strchr,(const char *, int));


    which creates a tag for _EXFUN instead of strchr:



    _EXFUN /somedir/include/string.h /^char *_EXFUN(strchr,(const char *, int));$/;" p


    I create tags with this command:



    exctags -f tags.p --language-force=c --c-kinds=p file1 file2 ...


    I've read the exctags man page up and down, tried various -I options to affect macro expansions but to no avail. Has anyone solved this?







    share|improve this question





















      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      I can successfully create a tags file for vim with exctags (Exuberant Ctags).



      However, creating tags allowing to jump to the prototype of a function does not work, due the system headers using a syntax-mangling macro of the form



      #define _EXFUN(name, proto) name proto


      and in, e.g. string.h using



      char *_EXFUN(strchr,(const char *, int));


      which creates a tag for _EXFUN instead of strchr:



      _EXFUN /somedir/include/string.h /^char *_EXFUN(strchr,(const char *, int));$/;" p


      I create tags with this command:



      exctags -f tags.p --language-force=c --c-kinds=p file1 file2 ...


      I've read the exctags man page up and down, tried various -I options to affect macro expansions but to no avail. Has anyone solved this?







      share|improve this question











      I can successfully create a tags file for vim with exctags (Exuberant Ctags).



      However, creating tags allowing to jump to the prototype of a function does not work, due the system headers using a syntax-mangling macro of the form



      #define _EXFUN(name, proto) name proto


      and in, e.g. string.h using



      char *_EXFUN(strchr,(const char *, int));


      which creates a tag for _EXFUN instead of strchr:



      _EXFUN /somedir/include/string.h /^char *_EXFUN(strchr,(const char *, int));$/;" p


      I create tags with this command:



      exctags -f tags.p --language-force=c --c-kinds=p file1 file2 ...


      I've read the exctags man page up and down, tried various -I options to affect macro expansions but to no avail. Has anyone solved this?









      share|improve this question










      share|improve this question




      share|improve this question









      asked May 18 at 12:43









      Jens

      9921027




      9921027




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          To handle that particular macro, you could use the --regex-<LANG> option:



          ctags --regex-c='/^[^#]*_EXFUN *( *([^ ,]+),.*/1/p/' ...


          Which generates a tags file with:



          _EXFUN test.c 1;" d file:
          strchr test.c /^char *_EXFUN(strchr,(const char *, int));$/;" p





          share|improve this answer























          • That's a beautifully concise solution! Thanks a bunch!
            – Jens
            May 22 at 7:58

















          up vote
          5
          down vote













          Run ectags on the preprocessed file, and ask it to look at the preprocessor's comments (--line-directives=yes) and to write line numbers into the tags file (-n or --excmd=numbers).



          cc -E prog.c >prog.p
          ectags --line-directives=yes --language-force=c --c-kinds=p -n prog.p


          Sample C file:



          #define _EXFUN(name, proto) name proto

          char *_EXFUN(strchr,(const char *, int));


          Resulting tags file:



          !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
          !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
          !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
          !_TAG_PROGRAM_NAME Exuberant Ctags //
          !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
          !_TAG_PROGRAM_VERSION 5.8 //
          strchr prog.c 3;" p file:


          As you can see, the prototype for strchr is listed as occurring on line 3 in prog.c.



          The downside with this is that you don't get any tag entries for preprocessing macros.



          You can solve that through running ectags on both the preprocessed and original files though:



          ectags --line-directives=yes --language-force=c --c-kinds=pd -n -I _EXFUN prog.p prog.c


          which produces



          [...]
          _EXFUN prog.c 1;" d file:
          strchr prog.c 3;" p file:





          share|improve this answer























          • Preprocessing is a very interesting idea! Thanks and +1!
            – Jens
            May 22 at 7:59










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f444588%2fundoing-c-syntax-mangling-macros-to-make-exctags-able-to-create-prototype-tags%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote



          accepted










          To handle that particular macro, you could use the --regex-<LANG> option:



          ctags --regex-c='/^[^#]*_EXFUN *( *([^ ,]+),.*/1/p/' ...


          Which generates a tags file with:



          _EXFUN test.c 1;" d file:
          strchr test.c /^char *_EXFUN(strchr,(const char *, int));$/;" p





          share|improve this answer























          • That's a beautifully concise solution! Thanks a bunch!
            – Jens
            May 22 at 7:58














          up vote
          4
          down vote



          accepted










          To handle that particular macro, you could use the --regex-<LANG> option:



          ctags --regex-c='/^[^#]*_EXFUN *( *([^ ,]+),.*/1/p/' ...


          Which generates a tags file with:



          _EXFUN test.c 1;" d file:
          strchr test.c /^char *_EXFUN(strchr,(const char *, int));$/;" p





          share|improve this answer























          • That's a beautifully concise solution! Thanks a bunch!
            – Jens
            May 22 at 7:58












          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted






          To handle that particular macro, you could use the --regex-<LANG> option:



          ctags --regex-c='/^[^#]*_EXFUN *( *([^ ,]+),.*/1/p/' ...


          Which generates a tags file with:



          _EXFUN test.c 1;" d file:
          strchr test.c /^char *_EXFUN(strchr,(const char *, int));$/;" p





          share|improve this answer















          To handle that particular macro, you could use the --regex-<LANG> option:



          ctags --regex-c='/^[^#]*_EXFUN *( *([^ ,]+),.*/1/p/' ...


          Which generates a tags file with:



          _EXFUN test.c 1;" d file:
          strchr test.c /^char *_EXFUN(strchr,(const char *, int));$/;" p






          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited May 22 at 8:21


























          answered May 18 at 13:17









          Stéphane Chazelas

          279k53513845




          279k53513845











          • That's a beautifully concise solution! Thanks a bunch!
            – Jens
            May 22 at 7:58
















          • That's a beautifully concise solution! Thanks a bunch!
            – Jens
            May 22 at 7:58















          That's a beautifully concise solution! Thanks a bunch!
          – Jens
          May 22 at 7:58




          That's a beautifully concise solution! Thanks a bunch!
          – Jens
          May 22 at 7:58












          up vote
          5
          down vote













          Run ectags on the preprocessed file, and ask it to look at the preprocessor's comments (--line-directives=yes) and to write line numbers into the tags file (-n or --excmd=numbers).



          cc -E prog.c >prog.p
          ectags --line-directives=yes --language-force=c --c-kinds=p -n prog.p


          Sample C file:



          #define _EXFUN(name, proto) name proto

          char *_EXFUN(strchr,(const char *, int));


          Resulting tags file:



          !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
          !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
          !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
          !_TAG_PROGRAM_NAME Exuberant Ctags //
          !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
          !_TAG_PROGRAM_VERSION 5.8 //
          strchr prog.c 3;" p file:


          As you can see, the prototype for strchr is listed as occurring on line 3 in prog.c.



          The downside with this is that you don't get any tag entries for preprocessing macros.



          You can solve that through running ectags on both the preprocessed and original files though:



          ectags --line-directives=yes --language-force=c --c-kinds=pd -n -I _EXFUN prog.p prog.c


          which produces



          [...]
          _EXFUN prog.c 1;" d file:
          strchr prog.c 3;" p file:





          share|improve this answer























          • Preprocessing is a very interesting idea! Thanks and +1!
            – Jens
            May 22 at 7:59














          up vote
          5
          down vote













          Run ectags on the preprocessed file, and ask it to look at the preprocessor's comments (--line-directives=yes) and to write line numbers into the tags file (-n or --excmd=numbers).



          cc -E prog.c >prog.p
          ectags --line-directives=yes --language-force=c --c-kinds=p -n prog.p


          Sample C file:



          #define _EXFUN(name, proto) name proto

          char *_EXFUN(strchr,(const char *, int));


          Resulting tags file:



          !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
          !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
          !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
          !_TAG_PROGRAM_NAME Exuberant Ctags //
          !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
          !_TAG_PROGRAM_VERSION 5.8 //
          strchr prog.c 3;" p file:


          As you can see, the prototype for strchr is listed as occurring on line 3 in prog.c.



          The downside with this is that you don't get any tag entries for preprocessing macros.



          You can solve that through running ectags on both the preprocessed and original files though:



          ectags --line-directives=yes --language-force=c --c-kinds=pd -n -I _EXFUN prog.p prog.c


          which produces



          [...]
          _EXFUN prog.c 1;" d file:
          strchr prog.c 3;" p file:





          share|improve this answer























          • Preprocessing is a very interesting idea! Thanks and +1!
            – Jens
            May 22 at 7:59












          up vote
          5
          down vote










          up vote
          5
          down vote









          Run ectags on the preprocessed file, and ask it to look at the preprocessor's comments (--line-directives=yes) and to write line numbers into the tags file (-n or --excmd=numbers).



          cc -E prog.c >prog.p
          ectags --line-directives=yes --language-force=c --c-kinds=p -n prog.p


          Sample C file:



          #define _EXFUN(name, proto) name proto

          char *_EXFUN(strchr,(const char *, int));


          Resulting tags file:



          !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
          !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
          !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
          !_TAG_PROGRAM_NAME Exuberant Ctags //
          !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
          !_TAG_PROGRAM_VERSION 5.8 //
          strchr prog.c 3;" p file:


          As you can see, the prototype for strchr is listed as occurring on line 3 in prog.c.



          The downside with this is that you don't get any tag entries for preprocessing macros.



          You can solve that through running ectags on both the preprocessed and original files though:



          ectags --line-directives=yes --language-force=c --c-kinds=pd -n -I _EXFUN prog.p prog.c


          which produces



          [...]
          _EXFUN prog.c 1;" d file:
          strchr prog.c 3;" p file:





          share|improve this answer















          Run ectags on the preprocessed file, and ask it to look at the preprocessor's comments (--line-directives=yes) and to write line numbers into the tags file (-n or --excmd=numbers).



          cc -E prog.c >prog.p
          ectags --line-directives=yes --language-force=c --c-kinds=p -n prog.p


          Sample C file:



          #define _EXFUN(name, proto) name proto

          char *_EXFUN(strchr,(const char *, int));


          Resulting tags file:



          !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
          !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
          !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
          !_TAG_PROGRAM_NAME Exuberant Ctags //
          !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
          !_TAG_PROGRAM_VERSION 5.8 //
          strchr prog.c 3;" p file:


          As you can see, the prototype for strchr is listed as occurring on line 3 in prog.c.



          The downside with this is that you don't get any tag entries for preprocessing macros.



          You can solve that through running ectags on both the preprocessed and original files though:



          ectags --line-directives=yes --language-force=c --c-kinds=pd -n -I _EXFUN prog.p prog.c


          which produces



          [...]
          _EXFUN prog.c 1;" d file:
          strchr prog.c 3;" p file:






          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited May 18 at 14:28


























          answered May 18 at 13:12









          Kusalananda

          102k13199314




          102k13199314











          • Preprocessing is a very interesting idea! Thanks and +1!
            – Jens
            May 22 at 7:59
















          • Preprocessing is a very interesting idea! Thanks and +1!
            – Jens
            May 22 at 7:59















          Preprocessing is a very interesting idea! Thanks and +1!
          – Jens
          May 22 at 7:59




          Preprocessing is a very interesting idea! Thanks and +1!
          – Jens
          May 22 at 7:59












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f444588%2fundoing-c-syntax-mangling-macros-to-make-exctags-able-to-create-prototype-tags%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay