Skip to content

Commit

Permalink
Merge pull request #1550 from masatake/output-option-in-json-output-mode
Browse files Browse the repository at this point in the history
Output option in json output mode
  • Loading branch information
masatake committed Sep 11, 2017
2 parents 19df62a + 4b7a154 commit 2a35ca6
Show file tree
Hide file tree
Showing 36 changed files with 358 additions and 107 deletions.
100 changes: 50 additions & 50 deletions Tmain/extras-long.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
# resetting
- subword no NONE Include tags for subwords generated by splitting the original tag (only for ctags development)
F fileScope no NONE Include tags of file scope
f inputFile no NONE Include an entry for the base file name of every input file
g guest no NONE Include tags generated by guest parsers
p pseudo no NONE Include pseudo tags
q qualified no NONE Include an extra class-qualified tag entry for each tag
r reference no NONE Include reference tags
s subparser yes NONE Include tags generated by subparsers
- funcmap yes QemuHX Include mapping SQMP to C function name
- whitespaceSwapped yes Robot Include tags swapping whitespace and underscore chars
- subword no NONE no Include tags for subwords generated by splitting the original tag (only for ctags development)
F fileScope no NONE no Include tags of file scope
f inputFile no NONE no Include an entry for the base file name of every input file
g guest no NONE no Include tags generated by guest parsers
p pseudo no NONE no Include pseudo tags
q qualified no NONE no Include an extra class-qualified tag entry for each tag
r reference no NONE no Include reference tags
s subparser yes NONE no Include tags generated by subparsers
- funcmap yes QemuHX no Include mapping SQMP to C function name
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
# enabling 1
- subword no NONE Include tags for subwords generated by splitting the original tag (only for ctags development)
F fileScope yes NONE Include tags of file scope
f inputFile no NONE Include an entry for the base file name of every input file
g guest no NONE Include tags generated by guest parsers
p pseudo yes NONE Include pseudo tags
q qualified no NONE Include an extra class-qualified tag entry for each tag
r reference no NONE Include reference tags
s subparser yes NONE Include tags generated by subparsers
- funcmap yes QemuHX Include mapping SQMP to C function name
- whitespaceSwapped yes Robot Include tags swapping whitespace and underscore chars
- subword no NONE no Include tags for subwords generated by splitting the original tag (only for ctags development)
F fileScope yes NONE no Include tags of file scope
f inputFile no NONE no Include an entry for the base file name of every input file
g guest no NONE no Include tags generated by guest parsers
p pseudo yes NONE no Include pseudo tags
q qualified no NONE no Include an extra class-qualified tag entry for each tag
r reference no NONE no Include reference tags
s subparser yes NONE no Include tags generated by subparsers
- funcmap yes QemuHX no Include mapping SQMP to C function name
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
# disabling 1
- subword no NONE Include tags for subwords generated by splitting the original tag (only for ctags development)
F fileScope no NONE Include tags of file scope
f inputFile no NONE Include an entry for the base file name of every input file
g guest no NONE Include tags generated by guest parsers
p pseudo no NONE Include pseudo tags
q qualified no NONE Include an extra class-qualified tag entry for each tag
r reference no NONE Include reference tags
s subparser yes NONE Include tags generated by subparsers
- funcmap yes QemuHX Include mapping SQMP to C function name
- whitespaceSwapped yes Robot Include tags swapping whitespace and underscore chars
- subword no NONE no Include tags for subwords generated by splitting the original tag (only for ctags development)
F fileScope no NONE no Include tags of file scope
f inputFile no NONE no Include an entry for the base file name of every input file
g guest no NONE no Include tags generated by guest parsers
p pseudo yes NONE no Include pseudo tags
q qualified no NONE no Include an extra class-qualified tag entry for each tag
r reference no NONE no Include reference tags
s subparser yes NONE no Include tags generated by subparsers
- funcmap yes QemuHX no Include mapping SQMP to C function name
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
# combination
- subword no NONE Include tags for subwords generated by splitting the original tag (only for ctags development)
F fileScope no NONE Include tags of file scope
f inputFile yes NONE Include an entry for the base file name of every input file
g guest no NONE Include tags generated by guest parsers
p pseudo no NONE Include pseudo tags
q qualified no NONE Include an extra class-qualified tag entry for each tag
r reference yes NONE Include reference tags
s subparser yes NONE Include tags generated by subparsers
- funcmap yes QemuHX Include mapping SQMP to C function name
- whitespaceSwapped yes Robot Include tags swapping whitespace and underscore chars
- subword no NONE no Include tags for subwords generated by splitting the original tag (only for ctags development)
F fileScope no NONE no Include tags of file scope
f inputFile yes NONE no Include an entry for the base file name of every input file
g guest no NONE no Include tags generated by guest parsers
p pseudo yes NONE no Include pseudo tags
q qualified no NONE no Include an extra class-qualified tag entry for each tag
r reference yes NONE no Include reference tags
s subparser yes NONE no Include tags generated by subparsers
- funcmap yes QemuHX no Include mapping SQMP to C function name
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
# combination with letters
- subword no NONE Include tags for subwords generated by splitting the original tag (only for ctags development)
F fileScope no NONE Include tags of file scope
f inputFile no NONE Include an entry for the base file name of every input file
g guest no NONE Include tags generated by guest parsers
p pseudo yes NONE Include pseudo tags
q qualified yes NONE Include an extra class-qualified tag entry for each tag
r reference yes NONE Include reference tags
s subparser yes NONE Include tags generated by subparsers
- funcmap yes QemuHX Include mapping SQMP to C function name
- whitespaceSwapped yes Robot Include tags swapping whitespace and underscore chars
- subword no NONE no Include tags for subwords generated by splitting the original tag (only for ctags development)
F fileScope no NONE no Include tags of file scope
f inputFile no NONE no Include an entry for the base file name of every input file
g guest no NONE no Include tags generated by guest parsers
p pseudo yes NONE no Include pseudo tags
q qualified yes NONE no Include an extra class-qualified tag entry for each tag
r reference yes NONE no Include reference tags
s subparser yes NONE no Include tags generated by subparsers
- funcmap yes QemuHX no Include mapping SQMP to C function name
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
1 change: 1 addition & 0 deletions Tmain/filter-option-write-to-file.d/input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int main(void) { return 0; }
10 changes: 10 additions & 0 deletions Tmain/filter-option-write-to-file.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
# Copyright: 2017 Masatake YAMATO
# License: GPL-2

CTAGS=$1
O=/tmp/ctags-tmain-$$.txt

echo ./input.c | $CTAGS --filter -o $O

rm -f ${O}
1 change: 1 addition & 0 deletions Tmain/filter-option-write-to-file.d/stderr-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ctags: Warning: filter mode ignores output tag file name
1 change: 1 addition & 0 deletions Tmain/filter-option-write-to-file.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main ./input.c /^int main(void) { return 0; }$/;" f typeref:typename:int
1 change: 1 addition & 0 deletions Tmain/filter-option.d/input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int main(void) { return 0; }
8 changes: 8 additions & 0 deletions Tmain/filter-option.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
# Copyright: 2017 Masatake YAMATO
# License: GPL-2

CTAGS=$1

echo ./input.c | $CTAGS --filter
echo ./input.c | $CTAGS --filter --output-format=xref
2 changes: 2 additions & 0 deletions Tmain/filter-option.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
main ./input.c /^int main(void) { return 0; }$/;" f typeref:typename:int
main function 1 ./input.c int main(void) { return 0; }
21 changes: 21 additions & 0 deletions Tmain/interactive-option-write-to-file.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
# Copyright: 2017 Masatake YAMATO
# Copyright: 2016 Aman Gupta
# License: GPL-2

CTAGS=$1
. ../utils.sh

is_feature_available ${CTAGS} interactive

# It seems that the output format is slightly different between libjansson versions
s()
{
sed -e s/':"'/': "'/g
}

O=/tmp/ctags-tmain-$$.txt

echo '{"command":"generate-tags", "filename":"test.rb"}' | ${CTAGS} --_interactive -o ${O} |s

rm -f ${O}
Empty file.
5 changes: 5 additions & 0 deletions Tmain/interactive-option-write-to-file.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{"_type": "program", "name": "Universal Ctags", "version": "0.0.0"}
{"_type": "tag", "name": "Test", "path": "test.rb", "pattern": "/^class Test$/", "kind": "class"}
{"_type": "tag", "name": "foobar", "path": "test.rb", "pattern": "/^ def foobar$/", "kind": "method", "scope": "Test", "scopeKind": "class"}
{"_type": "tag", "name": "baz", "path": "test.rb", "pattern": "/^ def baz(a=1)$/", "kind": "method", "scope": "Test", "scopeKind": "class"}
{"_type": "completed", "command": "generate-tags"}
7 changes: 7 additions & 0 deletions Tmain/interactive-option-write-to-file.d/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Test
def foobar
end

def baz(a=1)
end
end
12 changes: 12 additions & 0 deletions Tmain/json-output-to-file.d/input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>

static int foo (void)
{
return 1;
}

int
main(void)
{
return foo();
}
17 changes: 17 additions & 0 deletions Tmain/json-output-to-file.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright: 2017 Masatake YAMATO
# License: GPL-2

CTAGS=$1

. ../utils.sh

O=/tmp/ctags-tmain-$$.json

is_feature_available "${CTAGS}" json

$CTAGS --extras=-p --output-format=json -f ${O} input.c > /dev/null && cat ${O}
s=$?

rm -f ${O}

exit $s
2 changes: 2 additions & 0 deletions Tmain/json-output-to-file.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"_type": "tag", "name": "foo", "path": "input.c", "pattern": "/^static int foo (void)$/", "file": true, "typeref": "int", "kind": "function"}
{"_type": "tag", "name": "main", "path": "input.c", "pattern": "/^main(void)$/", "typeref": "int", "kind": "function"}
22 changes: 22 additions & 0 deletions Tmain/json-ptag-in-list-extras.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright: 2017 Masatake YAMATO
# License: GPL-2

CTAGS=$1


. ../utils.sh

is_feature_available ${CTAGS} json

O=/tmp/ctags-tmain-$$

echo '#' json regular file
"${CTAGS}" --quiet --options=NONE --output-format=json -o $O --list-extras | grep pseudo

echo '#' json -
"${CTAGS}" --quiet --options=NONE --output-format=json -o - --list-extras | grep pseudo

echo '#' json NOTHING
"${CTAGS}" --quiet --options=NONE --output-format=json --list-extras | grep pseudo

rm -f $O
Empty file.
6 changes: 6 additions & 0 deletions Tmain/json-ptag-in-list-extras.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# json regular file
p pseudo yes NONE no Include pseudo tags
# json -
p pseudo no NONE no Include pseudo tags
# json NOTHING
p pseudo no NONE no Include pseudo tags
44 changes: 22 additions & 22 deletions Tmain/list-extras.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#LETTER NAME ENABLED LANGUAGE DESCRIPTION
- subword yes NONE Include tags for subwords generated by splitting the original tag (only for ctags development)
F fileScope yes NONE Include tags of file scope
f inputFile yes NONE Include an entry for the base file name of every input file
g guest yes NONE Include tags generated by guest parsers
p pseudo yes NONE Include pseudo tags
q qualified yes NONE Include an extra class-qualified tag entry for each tag
r reference yes NONE Include reference tags
s subparser yes NONE Include tags generated by subparsers
- funcmap yes QemuHX Include mapping SQMP to C function name
- whitespaceSwapped yes Robot Include tags swapping whitespace and underscore chars
#LETTER NAME ENABLED LANGUAGE DESCRIPTION
- subword yes NONE Include tags for subwords generated by splitting the original tag (only for ctags development)
F fileScope yes NONE Include tags of file scope
f inputFile yes NONE Include an entry for the base file name of every input file
g guest yes NONE Include tags generated by guest parsers
p pseudo yes NONE Include pseudo tags
q qualified yes NONE Include an extra class-qualified tag entry for each tag
r reference yes NONE Include reference tags
s subparser yes NONE Include tags generated by subparsers
- funcmap yes QemuHX Include mapping SQMP to C function name
- whitespaceSwapped yes Robot Include tags swapping whitespace and underscore chars
#LETTER NAME ENABLED LANGUAGE FIXED DESCRIPTION
- subword yes NONE no Include tags for subwords generated by splitting the original tag (only for ctags development)
F fileScope yes NONE no Include tags of file scope
f inputFile yes NONE no Include an entry for the base file name of every input file
g guest yes NONE no Include tags generated by guest parsers
p pseudo yes NONE no Include pseudo tags
q qualified yes NONE no Include an extra class-qualified tag entry for each tag
r reference yes NONE no Include reference tags
s subparser yes NONE no Include tags generated by subparsers
- funcmap yes QemuHX no Include mapping SQMP to C function name
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
#LETTER NAME ENABLED LANGUAGE FIXED DESCRIPTION
- subword yes NONE no Include tags for subwords generated by splitting the original tag (only for ctags development)
F fileScope yes NONE no Include tags of file scope
f inputFile yes NONE no Include an entry for the base file name of every input file
g guest yes NONE no Include tags generated by guest parsers
p pseudo yes NONE no Include pseudo tags
q qualified yes NONE no Include an extra class-qualified tag entry for each tag
r reference yes NONE no Include reference tags
s subparser yes NONE no Include tags generated by subparsers
- funcmap yes QemuHX no Include mapping SQMP to C function name
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
16 changes: 8 additions & 8 deletions Tmain/parser-own-extras.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#LETTER NAME ENABLED LANGUAGE DESCRIPTION
- whitespaceSwapped yes Robot Include tags swapping whitespace and underscore chars
- whitespaceSwapped no Robot Include tags swapping whitespace and underscore chars
- whitespaceSwapped yes Robot Include tags swapping whitespace and underscore chars
- whitespaceSwapped no Robot Include tags swapping whitespace and underscore chars
- whitespaceSwapped yes Robot Include tags swapping whitespace and underscore chars
- whitespaceSwapped yes Robot Include tags swapping whitespace and underscore chars
- whitespaceSwapped yes Robot Include tags swapping whitespace and underscore chars
#LETTER NAME ENABLED LANGUAGE FIXED DESCRIPTION
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
- whitespaceSwapped no Robot no Include tags swapping whitespace and underscore chars
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
- whitespaceSwapped no Robot no Include tags swapping whitespace and underscore chars
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
12 changes: 12 additions & 0 deletions Tmain/xref-output-to-file.d/input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>

static int foo (void)
{
return 1;
}

int
main(void)
{
return foo();
}
14 changes: 14 additions & 0 deletions Tmain/xref-output-to-file.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright: 2017 Masatake YAMATO
# License: GPL-2

CTAGS=$1

. ../utils.sh

O=/tmp/ctags-tmain-$$.xref
$CTAGS --output-format=xref -f ${O} input.c > /dev/null && cat ${O}
s=$?

rm -f ${O}

exit $s
2 changes: 2 additions & 0 deletions Tmain/xref-output-to-file.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo function 3 input.c static int foo (void)
main function 9 input.c main(void)
26 changes: 26 additions & 0 deletions Tmain/xref-ptag-in-list-extras.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright: 2017 Masatake YAMATO
# License: GPL-2

CTAGS=$1

O=/tmp/ctags-tmain-$$

echo '#' tags regular file
"${CTAGS}" --options=NONE --output-format=u-ctags -o $O --list-extras | grep pseudo

echo '#' tags -
"${CTAGS}" --options=NONE --output-format=u-ctags -o - --list-extras | grep pseudo

echo '#' tags NOTHING
"${CTAGS}" --options=NONE --output-format=u-ctags --list-extras | grep pseudo

echo '#' xref regular file
"${CTAGS}" --options=NONE --output-format=xref -o $O --list-extras | grep pseudo

echo '#' xref -
"${CTAGS}" --options=NONE --output-format=xref -o - --list-extras | grep pseudo

echo '#' xref NOTHING
"${CTAGS}" --options=NONE --output-format=xref --list-extras | grep pseudo

rm -f $O
12 changes: 12 additions & 0 deletions Tmain/xref-ptag-in-list-extras.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# tags regular file
p pseudo yes NONE no Include pseudo tags
# tags -
p pseudo no NONE no Include pseudo tags
# tags NOTHING
p pseudo yes NONE no Include pseudo tags
# xref regular file
p pseudo no NONE yes Include pseudo tags
# xref -
p pseudo no NONE yes Include pseudo tags
# xref NOTHING
p pseudo no NONE yes Include pseudo tags
5 changes: 4 additions & 1 deletion main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,14 @@ extern bool isDestinationStdout (void)
{
bool toStdout = false;

if (outputFormatUsedStdoutByDefault() || Option.filter || Option.interactive ||
if (Option.filter || Option.interactive ||
(Option.tagFileName != NULL && (strcmp (Option.tagFileName, "-") == 0
|| strcmp (Option.tagFileName, "/dev/stdout") == 0
)))
toStdout = true;
else if (Option.tagFileName == NULL && NULL == outputDefaultFileName ())
toStdout = true;

return toStdout;
}

Expand Down
Loading

0 comments on commit 2a35ca6

Please sign in to comment.