Undoing C syntax mangling macros to make exctags able to create prototype tags
Clash 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?
header-file macro ctags
add a comment |Â
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?
header-file macro ctags
add a comment |Â
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?
header-file macro ctags
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?
header-file macro ctags
asked May 18 at 12:43
Jens
9921027
9921027
add a comment |Â
add a comment |Â
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
That's a beautifully concise solution! Thanks a bunch!
â Jens
May 22 at 7:58
add a comment |Â
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:
Preprocessing is a very interesting idea! Thanks and +1!
â Jens
May 22 at 7:59
add a comment |Â
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
That's a beautifully concise solution! Thanks a bunch!
â Jens
May 22 at 7:58
add a comment |Â
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
That's a beautifully concise solution! Thanks a bunch!
â Jens
May 22 at 7:58
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
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:
Preprocessing is a very interesting idea! Thanks and +1!
â Jens
May 22 at 7:59
add a comment |Â
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:
Preprocessing is a very interesting idea! Thanks and +1!
â Jens
May 22 at 7:59
add a comment |Â
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:
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:
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password