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 17, 2022
1 parent 6cd0af4 commit 28d363d
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
!_PTAG value\ /comment/;"
!_TAG_OUTPUT_MODE u-ctags //;"
!_TAG_OUTPUT_FILESEP slash //
regular_tag /path/to/file /^pattern$/;" kind:
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
!_PTAG value\\ /comment/;"
!_TAG_OUTPUT_FILESEP slash //;"
!_TAG_OUTPUT_MODE u-ctags //;"
regular_tag /path/to/file /^pattern$/;" kind:
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
!_PTAG value\t /comment/;"
!_TAG_OUTPUT_MODE u-ctags //;"
!_TAG_OUTPUT_FILESEP slash //
regular_tag /path/to/file /^pattern$/;" kind:
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
!_PTAG value /comment/;"
!_TAG_OUTPUT_FILESEP slash //;"
!_TAG_OUTPUT_MODE u-ctags //;"
regular_tag /path/to/file\ /^pattern$/;" kind:
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
!_PTAG value /comment/;"
!_TAG_OUTPUT_MODE u-ctags //;"
!_TAG_OUTPUT_FILESEP slash //
regular_tag /path/to/file\\ /^pattern$/;" kind:
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
!_PTAG value /comment/;"
!_COMMENT _ /intentionally remote semicolon double quotes char in the next line/;"
!_TAG_OUTPUT_MODE u-ctags //
!_TAG_OUTPUT_FILESEP slash //;"
regular_tag /path/to/file\t /^pattern$/;" kind:
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
!_PTAG value /comment/;"
!_COMMENT _ /intentionally remote semicolon double quotes char in the next line/;"
!_TAG_OUTPUT_MODE u-ctags //
!_TAG_OUTPUT_FILESEP backslash //;"
regular_tag /path/to/file\t /^pattern$/;" kind:
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
!_PTAG value /comment/;"
!_COMMENT _ /intentionally remote semicolon double quotes char in the next line/;"
!_TAG_OUTPUT_MODE u-ctags //
regular_tag /path/to/file\t /^pattern$/;" kind:
44 changes: 44 additions & 0 deletions Tmain/readtags-ptags-escaping.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ for t in INIT \
regular-input-b_.tags \
regular-input-bb.tags \
regular-input-bt.tags \
regular-input-b_-u-ctags-mode.tags \
regular-input-bb-u-ctags-mode.tags \
regular-input-bt-u-ctags-mode.tags \
regular-kind-b_.tags \
regular-kind-bb.tags \
pseudo-name-b_.tags \
Expand All @@ -29,6 +32,11 @@ for t in INIT \
pseudo-input-b_.tags \
pseudo-input-bb.tags \
pseudo-input-bt.tags \
pseudo-input-b_-u-ctags-mode.tags \
pseudo-input-bb-u-ctags-mode.tags \
pseudo-input-bt-u-ctags-mode.tags \
regular-input-bt-u-filesep-backslash.tags \
regular-input-bt-u-no-filesep.tags \
; do
case $t in
INIT)
Expand All @@ -49,3 +57,39 @@ for t in INIT \
;;
esac
done

for t in INIT \
regular-input-b_.tags \
regular-input-bb.tags \
regular-input-bt.tags \
regular-input-b_-u-ctags-mode.tags \
regular-input-bb-u-ctags-mode.tags \
regular-input-bt-u-ctags-mode.tags \
pseudo-input-b_.tags \
pseudo-input-bb.tags \
pseudo-input-bt.tags \
pseudo-input-b_-u-ctags-mode.tags \
pseudo-input-bb-u-ctags-mode.tags \
pseudo-input-bt-u-ctags-mode.tags \
regular-input-bt-u-filesep-backslash.tags \
regular-input-bt-u-no-filesep.tags \
; do
case $t in
INIT)
;;
regular-*)
echo "# <no unescaping> $t"
${V} ${READTAGS} -e -t $t -l || exit 1
echo
;;
pseudo-*)
echo "# <no unescaping> $t"
${V} ${READTAGS} -e -t $t -D || exit 1
echo
;;
*)
echo "INTERNAL BUG"
exit 1
;;
esac
done
90 changes: 84 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,22 @@ 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-input-b_-u-ctags-mode.tags
regular_tag /path/to/file\\ /^pattern$/

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

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

# regular-kind-b_.tags
regular_tag /path/to/file /^pattern$/;" kind:\\
Expand All @@ -32,11 +41,80 @@ 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/

# pseudo-input-b_-u-ctags-mode.tags
!_PTAG value\\ /comment/
!_TAG_OUTPUT_MODE u-ctags //
!_TAG_OUTPUT_FILESEP slash //

# pseudo-input-bb-u-ctags-mode.tags
!_PTAG value\\ /comment/
!_TAG_OUTPUT_FILESEP slash //
!_TAG_OUTPUT_MODE u-ctags //

# pseudo-input-bt-u-ctags-mode.tags
!_PTAG value\t /comment/
!_TAG_OUTPUT_MODE u-ctags //
!_TAG_OUTPUT_FILESEP slash //

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

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

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

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

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

# <no unescaping> regular-input-b_-u-ctags-mode.tags
regular_tag /path/to/file\ /^pattern$/

# <no unescaping> regular-input-bb-u-ctags-mode.tags
regular_tag /path/to/file\ /^pattern$/

# <no unescaping> regular-input-bt-u-ctags-mode.tags
regular_tag /path/to/file /^pattern$/

# <no unescaping> pseudo-input-b_.tags
!_PTAG value\ /comment/

# <no unescaping> pseudo-input-bb.tags
!_PTAG value\\ /comment/

# <no unescaping> pseudo-input-bt.tags
!_PTAG value\t /comment/

# <no unescaping> pseudo-input-b_-u-ctags-mode.tags
!_PTAG value\ /comment/
!_TAG_OUTPUT_MODE u-ctags //
!_TAG_OUTPUT_FILESEP slash //

# <no unescaping> pseudo-input-bb-u-ctags-mode.tags
!_PTAG value\ /comment/
!_TAG_OUTPUT_FILESEP slash //
!_TAG_OUTPUT_MODE u-ctags //

# <no unescaping> pseudo-input-bt-u-ctags-mode.tags
!_PTAG value /comment/
!_TAG_OUTPUT_MODE u-ctags //
!_TAG_OUTPUT_FILESEP slash //

# <no unescaping> regular-input-bt-u-filesep-backslash.tags
regular_tag /path/to/file\t /^pattern$/

# <no unescaping> regular-input-bt-u-no-filesep.tags
regular_tag /path/to/file\t /^pattern$/

14 changes: 12 additions & 2 deletions 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 printingFileInUniversalCtagsMode,
int pseudoTag,
int (* print_str) (const char *, void *),
int (* print_char) (int, void *),
Expand Down Expand Up @@ -142,8 +143,15 @@ static void tagsPrintTag (const tagEntry *entry,
print_str, print_char, outfp);

print_char ('\t', outfp);
printValue (entry->file, printingWithEscaping,
print_str, print_char, outfp);
{
/* Universal Ctags on Windows converts \ , the file name separator
* on the platform, to /; we can reliably expect \ characters in
* entry->file is for escaping. So we can do unescape here.
*/
int esc = printingWithEscaping && printingFileInUniversalCtagsMode;
printValue (entry->file, esc,
print_str, print_char, outfp);
}
print_char ('\t', outfp);
print_str (entry->address.pattern, outfp);

Expand Down Expand Up @@ -201,6 +209,7 @@ extern int tagsPrint (const tagEntry *entry,
opt->extensionFields,
opt->lineNumber,
opt->escaping,
opt->outputMode == universalOutputMode,
0,
procs->printStr,
procs->printChar,
Expand All @@ -218,6 +227,7 @@ extern int tagsPrintPseudoTag (const tagEntry *entry,
opt->extensionFields,
opt->lineNumber,
opt->escaping,
opt->outputMode == universalOutputMode,
1,
procs->printStr,
procs->printChar,
Expand Down
8 changes: 6 additions & 2 deletions extra-cmds/printtags.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ typedef struct {
int (* printChar) (int, void *);
} tagPrintProcs;

typedef enum eTagPrintOutputMode {
exuberantOutputMode,
universalOutputMode
} tagPrintOutputMode;

typedef struct {
/* TODO: int version; */
int extensionFields;
int lineNumber;
int escaping;
/* version 1 */
tagPrintOutputMode outputMode;
} tagPrintOptions;

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

static tagPrintOutputMode getTagOutputMode (tagFile *const file)
{
tagEntry entry;

if ((tagsFindPseudoTag (file, &entry,
"!_TAG_OUTPUT_MODE", TAG_FULLMATCH) == TagSuccess)
&& (strcmp(entry.file, "u-ctags") == 0)
&& (tagsFindPseudoTag (file, &entry,
"!_TAG_OUTPUT_FILESEP", TAG_FULLMATCH) == TagSuccess)
&& (strcmp(entry.file, "slash") == 0))
return universalOutputMode;
return exuberantOutputMode;
}

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

printOpts->outputMode = getTagOutputMode (file);

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

printOpts->outputMode = getTagOutputMode (file);

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

0 comments on commit 28d363d

Please sign in to comment.