Skip to content

Commit

Permalink
readtags: unescape input field (a.k.a {tagfile}) only if TAG_OUTPUT_M…
Browse files Browse the repository at this point in the history
…ODE is u-ctags and TAG_OUTPUT_FILESEP is slash

Close universal-ctags#3577.
Close universal-ctags#3559 except documentation.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Dec 30, 2022
1 parent 52ad100 commit 82e18e5
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 7 deletions.
12 changes: 6 additions & 6 deletions Tmain/readtags-ptags-escaping.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ regular_tag\\ /path/to/file /^pattern$/
regular_tag\t /path/to/file /^pattern$/

# regular-input-b_.tags
regular_tag /path/to/file\\ /^pattern$/
regular_tag /path/to/file\ /^pattern$/

# regular-input-bb.tags
regular_tag /path/to/file\\\\ /^pattern$/
regular_tag /path/to/file\\ /^pattern$/

# regular-input-bt.tags
regular_tag /path/to/file\\t /^pattern$/
regular_tag /path/to/file\t /^pattern$/

# regular-kind-b_.tags
regular_tag /path/to/file /^pattern$/;" kind:\\
Expand All @@ -32,11 +32,11 @@ regular_tag /path/to/file /^pattern$/;" kind:\\
!_PTAG\t value /comment/

# pseudo-input-b_.tags
!_PTAG value\\ /comment/
!_PTAG value\ /comment/

# pseudo-input-bb.tags
!_PTAG value\\\\ /comment/
!_PTAG value\\ /comment/

# pseudo-input-bt.tags
!_PTAG value\\t /comment/
!_PTAG value\t /comment/

1 change: 1 addition & 0 deletions Tmain/readtags-ptags-escaping2.d/example-_-_.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!_TAG_PROC_CWD /home/a\tb //
2 changes: 2 additions & 0 deletions Tmain/readtags-ptags-escaping2.d/example-_-b.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!_TAG_OUTPUT_FILESEP backslash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //
2 changes: 2 additions & 0 deletions Tmain/readtags-ptags-escaping2.d/example-_-s.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //
2 changes: 2 additions & 0 deletions Tmain/readtags-ptags-escaping2.d/example-e-_.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!_TAG_OUTPUT_MODE e-ctags /u-ctags or e-ctags/
!_TAG_PROC_CWD /home/a\tb //
3 changes: 3 additions & 0 deletions Tmain/readtags-ptags-escaping2.d/example-e-b.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!_TAG_OUTPUT_MODE e-ctags /u-ctags or e-ctags/
!_TAG_OUTPUT_FILESEP backslash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //
3 changes: 3 additions & 0 deletions Tmain/readtags-ptags-escaping2.d/example-e-s.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!_TAG_OUTPUT_MODE e-ctags /u-ctags or e-ctags/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //
2 changes: 2 additions & 0 deletions Tmain/readtags-ptags-escaping2.d/example-u-_.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_PROC_CWD /home/a\tb //
3 changes: 3 additions & 0 deletions Tmain/readtags-ptags-escaping2.d/example-u-b.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_OUTPUT_FILESEP backslash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //
3 changes: 3 additions & 0 deletions Tmain/readtags-ptags-escaping2.d/example-u-s.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //
24 changes: 24 additions & 0 deletions Tmain/readtags-ptags-escaping2.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

# Copyright: 2022 Masatake YAMATO
# License: GPL-2

READTAGS=$3
#V="valgrind --leak-check=full --track-origins=yes -v"
V=

. ../utils.sh

if ! [ -x "${READTAGS}" ]; then
skip "no readtags"
fi

for m in e u _; do
for s in s b _; do
echo ${READTAGS##*/} -e -t example-$m-$s.tags -E -D:
${V} ${READTAGS} -e -t example-$m-$s.tags -E -D
echo ${READTAGS##*/} -e -t example-$m-$s.tags -D:
${V} ${READTAGS} -e -t example-$m-$s.tags -D
echo
done
done
Empty file.
69 changes: 69 additions & 0 deletions Tmain/readtags-ptags-escaping2.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
readtags -e -t example-e-s.tags -E -D:
!_TAG_OUTPUT_MODE e-ctags /u-ctags or e-ctags/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //
readtags -e -t example-e-s.tags -D:
!_TAG_OUTPUT_MODE e-ctags /u-ctags or e-ctags/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //

readtags -e -t example-e-b.tags -E -D:
!_TAG_OUTPUT_MODE e-ctags /u-ctags or e-ctags/
!_TAG_OUTPUT_FILESEP backslash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //
readtags -e -t example-e-b.tags -D:
!_TAG_OUTPUT_MODE e-ctags /u-ctags or e-ctags/
!_TAG_OUTPUT_FILESEP backslash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //

readtags -e -t example-e-_.tags -E -D:
!_TAG_OUTPUT_MODE e-ctags /u-ctags or e-ctags/
!_TAG_PROC_CWD /home/a\tb //
readtags -e -t example-e-_.tags -D:
!_TAG_OUTPUT_MODE e-ctags /u-ctags or e-ctags/
!_TAG_PROC_CWD /home/a\tb //

readtags -e -t example-u-s.tags -E -D:
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //
readtags -e -t example-u-s.tags -D:
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_PROC_CWD /home/a b //

readtags -e -t example-u-b.tags -E -D:
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_OUTPUT_FILESEP backslash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //
readtags -e -t example-u-b.tags -D:
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_OUTPUT_FILESEP backslash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //

readtags -e -t example-u-_.tags -E -D:
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_PROC_CWD /home/a\tb //
readtags -e -t example-u-_.tags -D:
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_PROC_CWD /home/a\tb //

readtags -e -t example-_-s.tags -E -D:
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //
readtags -e -t example-_-s.tags -D:
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //

readtags -e -t example-_-b.tags -E -D:
!_TAG_OUTPUT_FILESEP backslash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //
readtags -e -t example-_-b.tags -D:
!_TAG_OUTPUT_FILESEP backslash /slash or backslash/
!_TAG_PROC_CWD /home/a\tb //

readtags -e -t example-_-_.tags -E -D:
!_TAG_PROC_CWD /home/a\tb //
readtags -e -t example-_-_.tags -D:
!_TAG_PROC_CWD /home/a\tb //

5 changes: 4 additions & 1 deletion extra-cmds/printtags.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ static void tagsPrintTag (const tagEntry *entry,
int printingExtensionFields,
int printingLineNumber,
int printingWithEscaping,
int printInputFieldWithEscaping,
int pseudoTag,
int (* print_str) (const char *, void *),
int (* print_char) (int, void *),
Expand Down Expand Up @@ -142,7 +143,7 @@ static void tagsPrintTag (const tagEntry *entry,
print_str, print_char, outfp);

print_char ('\t', outfp);
printValue (entry->file, printingWithEscaping,
printValue (entry->file, printInputFieldWithEscaping,
print_str, print_char, outfp);
print_char ('\t', outfp);
print_str (entry->address.pattern, outfp);
Expand Down Expand Up @@ -201,6 +202,7 @@ extern int tagsPrint (const tagEntry *entry,
opt->extensionFields,
opt->lineNumber,
opt->escaping,
opt->escapingInputField,
0,
procs->printStr,
procs->printChar,
Expand All @@ -218,6 +220,7 @@ extern int tagsPrintPseudoTag (const tagEntry *entry,
opt->extensionFields,
opt->lineNumber,
opt->escaping,
opt->escapingInputField,
1,
procs->printStr,
procs->printChar,
Expand Down
1 change: 1 addition & 0 deletions extra-cmds/printtags.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef struct {
int extensionFields;
int lineNumber;
int escaping;
int escapingInputField;
} tagPrintOptions;

/*
Expand Down
26 changes: 26 additions & 0 deletions extra-cmds/readtags-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,16 @@ static tagFile *openTags (const char *const filePath, tagFileInfo *const info)
return tagsOpen (filePath, info);
}

static int hasPsuedoTag (tagFile *const file,
const char *const ptag, const char *const exepectedValueAsInputField)
{
tagEntry entry;

return ((tagsFindPseudoTag (file, &entry,
ptag, TAG_FULLMATCH) == TagSuccess)
&& (strcmp(entry.file, exepectedValueAsInputField) == 0));
}

static void findTag (const char *const name, readOptions *readOpts,
tagPrintOptions *printOpts)
{
Expand All @@ -343,6 +353,14 @@ static void findTag (const char *const name, readOptions *readOpts,
exit (1);
}

if (printOpts->escaping)
{
printOpts->escapingInputField = 0;
if (hasPsuedoTag (file, "!_TAG_OUTPUT_MODE", "u-ctags")
&& hasPsuedoTag (file, "!_TAG_OUTPUT_FILESEP", "slash"))
printOpts->escapingInputField = 1;
}

if (readOpts->sortOverride)
{
if (tagsSetSortType (file, readOpts->sortMethod) != TagSuccess)
Expand Down Expand Up @@ -391,6 +409,14 @@ static void listTags (int pseudoTags, tagPrintOptions *printOpts)
exit (1);
}

if (printOpts->escaping)
{
printOpts->escapingInputField = 0;
if (hasPsuedoTag (file, "!_TAG_OUTPUT_MODE", "u-ctags")
&& hasPsuedoTag (file, "!_TAG_OUTPUT_FILESEP", "slash"))
printOpts->escapingInputField = 1;
}

if (pseudoTags)
{
if (tagsFirstPseudoTag (file, &entry) == TagSuccess)
Expand Down

0 comments on commit 82e18e5

Please sign in to comment.