Skip to content

Commit

Permalink
Add a new --undef command-line option
Browse files Browse the repository at this point in the history
This option allows to disable the generation of macro tags from #undef
directives, see PR #221 for the rationale. The default behaviour is
unchanged, i.e. a tag is still generated.

The help and man have been updated accordingly, and I added a small unit
to check that --undef=no disables the generation of a tag. The
directives.c unit already checks that a tag is generated when no option
is passed (which is equivalent to --undef=yes).
  • Loading branch information
Kevin Brodsky committed Feb 9, 2015
1 parent 7e3402c commit 275d65b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions Units/option-disable-undef.c.t/args.ctags
@@ -0,0 +1 @@
--undef=no
1 change: 1 addition & 0 deletions Units/option-disable-undef.c.t/expected.tags
@@ -0,0 +1 @@
MACRO_TO_SEE input.c /^#define MACRO_TO_SEE$/;" d file:
2 changes: 2 additions & 0 deletions Units/option-disable-undef.c.t/input.c
@@ -0,0 +1,2 @@
#define MACRO_TO_SEE
#undef MACRO_NOT_TO_SEE
6 changes: 6 additions & 0 deletions ctags.1
Expand Up @@ -790,6 +790,12 @@ Prints statistics about the source files read and the tag file written during
the current invocation of \fBctags\fP. This option is off by default.
This option must appear before the first file name.

.TP 5
\fB\-\-undef\fP[=\fIyes\fP|\fIno\fP]
Specifies whether a macro tag should be generated from an #undef CPP directive
(in a C/C++ file), as if it were a #define directive. This option is enabled by
default.

.TP 5
\fB\-\-verbose\fP[=\fIyes\fP|\fIno\fP]
Enable verbose mode. This prints out information on option processing and a
Expand Down
14 changes: 13 additions & 1 deletion get.c
Expand Up @@ -328,6 +328,18 @@ static void directiveDefine (const int c)
Cpp.directive.state = DRCTV_NONE;
}

static void directiveUndef (const int c)
{
if (Option.undef)
{
directiveDefine (c);
}
else
{
Cpp.directive.state = DRCTV_NONE;
}
}

static void directivePragma (int c)
{
if (isident1 (c))
Expand Down Expand Up @@ -412,7 +424,7 @@ static boolean handleDirective (const int c)
case DRCTV_HASH: ignore = directiveHash (c); break;
case DRCTV_IF: ignore = directiveIf (c); break;
case DRCTV_PRAGMA: directivePragma (c); break;
case DRCTV_UNDEF: directiveDefine (c); break;
case DRCTV_UNDEF: directiveUndef (c); break;
}
return ignore;
}
Expand Down
6 changes: 5 additions & 1 deletion options.c
Expand Up @@ -158,6 +158,7 @@ optionValues Option = {
NULL, /* --etags-include */
DEFAULT_FILE_FORMAT,/* --format */
FALSE, /* --if0 */
TRUE, /* --undef */
FALSE, /* --kind-long */
LANG_AUTO, /* --lang */
TRUE, /* --links */
Expand Down Expand Up @@ -259,7 +260,7 @@ static optionDescription LongOptionDescription [] = {
{1," --help"},
{1," Print this option summary."},
{1," --if0=[yes|no]"},
{1," Should C code within #if 0 conditional branches be parsed [no]?"},
{1," Should code within #if 0 conditional branches be parsed [no]?"},
{1," --<LANG>-alias=[+|-]aliasPattern"},
{1," Add a pattern detecting a name can be used as an alternative name for LANG."},
{1," --<LANG>-corpus=spec:corpusFile"},
Expand Down Expand Up @@ -328,6 +329,8 @@ static optionDescription LongOptionDescription [] = {
{0," Should paths be relative to location of tag file [no; yes when -e]?"},
{1," --totals=[yes|no]"},
{1," Print statistics about source and tag files [no]."},
{1," --undef=[yes|no]"},
{1," Should #undef directives generate a macro tag [yes]?"},
{1," --verbose=[yes|no]"},
{1," Enable verbose messages describing actions on each source file."},
{1," --version"},
Expand Down Expand Up @@ -2031,6 +2034,7 @@ static booleanOption BooleanOptions [] = {
#endif
{ "tag-relative", &Option.tagRelative, TRUE },
{ "totals", &Option.printTotals, TRUE },
{ "undef", &Option.undef, FALSE },
{ "verbose", &Option.verbose, FALSE },
};

Expand Down
1 change: 1 addition & 0 deletions options.h
Expand Up @@ -101,6 +101,7 @@ typedef struct sOptionValues {
stringList* etagsInclude;/* --etags-include list of TAGS files to include*/
unsigned int tagFileFormat;/* --format tag file format (level) */
boolean if0; /* --if0 examine code within "#if 0" branch */
boolean undef; /* --undef generate a tag from #undef'd macros */
boolean kindLong; /* --kind-long */
langType language; /* --lang specified language override */
boolean followLinks; /* --link follow symbolic links? */
Expand Down

0 comments on commit 275d65b

Please sign in to comment.