Skip to content

Commit

Permalink
main: allow to use {...} notation when enabling/disabling a pseudo tag
Browse files Browse the repository at this point in the history
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Mar 8, 2020
1 parent ae707bd commit fd1d0ee
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 28 deletions.
1 change: 1 addition & 0 deletions Tmain/option-pseudo-tags.d/input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* EMPTY */
63 changes: 63 additions & 0 deletions Tmain/option-pseudo-tags.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright: 2020 Masatake YAMATO
# License: GPL-2

CTAGS=$1
O="--quiet --options=NONE "

echo '# single with no curly bracket'
${CTAGS} $O \
--extras=+p --pseudo-tags=TAG_PROGRAM_URL \
-o - \
input.c

echo '# single with curly bracket'
${CTAGS} $O \
--extras=+p --pseudo-tags='{TAG_PROGRAM_URL}' \
-o - \
input.c

echo '# single with + no curly bracket'
${CTAGS} $O \
--extras=+p --pseudo-tags= \
--pseudo-tags=+TAG_PROGRAM_URL \
-o - \
input.c

echo '# single with + curly bracket'
${CTAGS} $O \
--extras=+p --pseudo-tags= \
--pseudo-tags=+'{TAG_PROGRAM_URL}' \
-o - \
input.c

echo '# single with +- no curly bracket'
${CTAGS} $O \
--extras=+p --pseudo-tags= \
--pseudo-tags=+TAG_PROGRAM_VERSION \
--pseudo-tags=+TAG_PROGRAM_URL \
--pseudo-tags=-TAG_PROGRAM_VERSION \
-o - \
input.c

echo '# single with +- curly bracket'
${CTAGS} $O \
--extras=+p --pseudo-tags= \
--pseudo-tags=+'{TAG_PROGRAM_VERSION}' \
--pseudo-tags=+'{TAG_PROGRAM_URL}' \
--pseudo-tags=-'{TAG_PROGRAM_VERSION}' \
-o - \
input.c

echo '# multiple specifications with +- curly bracket'
${CTAGS} $O \
--extras=+p --pseudo-tags= \
--pseudo-tags='+{TAG_PROGRAM_VERSION}{TAG_FILE_SORTED}{TAG_PROGRAM_URL}-{TAG_PROGRAM_VERSION}' \
-o - \
input.c

echo '# multiple specifications with -+- curly bracket'
${CTAGS} $O \
--extras=+p --pseudo-tags= \
--pseudo-tags='-{TAG_PROGRAM_VERSION}+{TAG_PROGRAM_VERSION}{TAG_FILE_FORMAT}{TAG_PROGRAM_URL}-{TAG_PROGRAM_VERSION}' \
-o - \
input.c
18 changes: 18 additions & 0 deletions Tmain/option-pseudo-tags.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# single with no curly bracket
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
# single with curly bracket
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
# single with + no curly bracket
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
# single with + curly bracket
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
# single with +- no curly bracket
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
# single with +- curly bracket
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
# multiple specifications with +- curly bracket
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
# multiple specifications with -+- curly bracket
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
7 changes: 7 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,13 @@ To specify only a single pseudo tag, omit the sign::

--pseudo-tags=ptag

With `{` and `}` characters, you can specify multiple pseudo tags at once::

--pseudo-tags={ptag1}{ptag2}...
--pseudo-tags=+{ptag1}{ptag2}...
--pseudo-tags=-{ptag1}{ptag2}...
--pseudo-tags=+{ptag1}{ptag2}-{ptag3}...

JSON output
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
83 changes: 55 additions & 28 deletions main/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -2389,43 +2389,70 @@ static void processPseudoTags (const char *const option CTAGS_ATTR_UNUSED,
const char *const parameter)
{
const char *p = parameter;
bool s;
bool s = true;
ptagType t;
vString *str = vStringNew();

if (*p == '*')
if (*p == '\0' || !strchr ("*+-", *p))
{
int i;
for (i = 0; i < PTAG_COUNT; i++)
enablePtag (i, true);
return;
for (unsigned int i = 0; i < PTAG_COUNT; i++)
enablePtag (i, false);
}

if (*p == '-')
while (1)
{
s= false;
p++;
}
else if (*p == '+')
{
s = true;
p++;
}
else
{
unsigned int i;

s = true;
for (i = 0; i < PTAG_COUNT; i++)
enablePtag (i, false);
if (*p == '\0')
return;
}
break;

t = getPtagTypeForName (p);
if (t == PTAG_UNKNOWN)
error (FATAL, "Unknown pseudo tag name: %s", p);
if (*p == '*')
{
int i;
for (i = 0; i < PTAG_COUNT; i++)
enablePtag (i, true);
p++;
continue;
}
else if (*p == '-')
{
s= false;
p++;
continue;
}
else if (*p == '+')
{
s = true;
p++;
continue;
}
else if (*p == '{')
{
const char *origin = p;

enablePtag (t, s);
p++;
while (*p != '\0' && *p != '}')
{
vStringPut (str, *p);
p++;
}
if (*p != '}')
error (FATAL, "curly bracket specifying a pseudo tags is unbalanced: %s",
origin);
p++;
}
else
{
vStringCopyS (str, p);
p += vStringLength (str);
}

char *name = vStringValue (str);
t = getPtagTypeForName (name);
if (t == PTAG_UNKNOWN)
error (FATAL, "Unknown pseudo tag name: %s", name);
enablePtag (t, s);
vStringClear (str);
}
vStringDelete (str);
}

static void processSortOption (
Expand Down

0 comments on commit fd1d0ee

Please sign in to comment.