From fd1d0eec77fb7eb2c27afdd866782662ee441c13 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Sun, 8 Mar 2020 15:36:35 +0900 Subject: [PATCH] main: allow to use {...} notation when enabling/disabling a pseudo tag Signed-off-by: Masatake YAMATO --- Tmain/option-pseudo-tags.d/input.c | 1 + Tmain/option-pseudo-tags.d/run.sh | 63 ++++++++++++++ .../option-pseudo-tags.d/stdout-expected.txt | 18 ++++ docs/news.rst | 7 ++ main/options.c | 83 ++++++++++++------- 5 files changed, 144 insertions(+), 28 deletions(-) create mode 100644 Tmain/option-pseudo-tags.d/input.c create mode 100644 Tmain/option-pseudo-tags.d/run.sh create mode 100644 Tmain/option-pseudo-tags.d/stdout-expected.txt diff --git a/Tmain/option-pseudo-tags.d/input.c b/Tmain/option-pseudo-tags.d/input.c new file mode 100644 index 0000000000..936ffd8809 --- /dev/null +++ b/Tmain/option-pseudo-tags.d/input.c @@ -0,0 +1 @@ +/* EMPTY */ diff --git a/Tmain/option-pseudo-tags.d/run.sh b/Tmain/option-pseudo-tags.d/run.sh new file mode 100644 index 0000000000..635df4d13a --- /dev/null +++ b/Tmain/option-pseudo-tags.d/run.sh @@ -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 diff --git a/Tmain/option-pseudo-tags.d/stdout-expected.txt b/Tmain/option-pseudo-tags.d/stdout-expected.txt new file mode 100644 index 0000000000..b7cc432a3b --- /dev/null +++ b/Tmain/option-pseudo-tags.d/stdout-expected.txt @@ -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/ diff --git a/docs/news.rst b/docs/news.rst index 4bf028d611..a0254adf44 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/main/options.c b/main/options.c index 1f325da742..37adff9017 100644 --- a/main/options.c +++ b/main/options.c @@ -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 (