Skip to content

Commit

Permalink
main,win32: introduce an option replacing backslashes in input file n…
Browse files Browse the repository at this point in the history
…ames with slashes

(TODO: documentation, more log should be here)

Suggested by @k-takata in universal-ctags#1325.
  • Loading branch information
masatake committed Sep 19, 2019
1 parent de3bac3 commit 3efaed1
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 1 deletion.
26 changes: 26 additions & 0 deletions Tmain/option-use-slash-as-filename-separator.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright: 2019 Masatake YAMATO
# License: GPL-2

CTAGS=$1
OPT=--use-slash-as-filename-separator

. ../utils.sh

exit_unless_win32 $CTAGS

echo '#u-ctags output'
$CTAGS --quiet --options=NONE -o - 'src\input.c'
$CTAGS --quiet --options=NONE -o - $OPT 'src\input.c'
$CTAGS --quiet --options=NONE -o - ${OPT}=no 'src\input.c'

echo '#e-ctags output'
$CTAGS --quiet --options=NONE --output-format=e-ctags -o - 'src\input.c'
$CTAGS --quiet --options=NONE --output-format=e-ctags -o - $OPT 'src\input.c'
$CTAGS --quiet --options=NONE --output-format=e-ctags -o - ${OPT}=no 'src\input.c'

echo '#xref output'
$CTAGS --quiet --options=NONE --output-format=xref -o - 'src\input.c'
$CTAGS --quiet --options=NONE --output-format=xref -o - $OPT 'src\input.c'
$CTAGS --quiet --options=NONE --output-format=xref -o - ${OPT}=no 'src\input.c'

# TODO: json output
1 change: 1 addition & 0 deletions Tmain/option-use-slash-as-filename-separator.d/src/input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int n;
12 changes: 12 additions & 0 deletions Tmain/option-use-slash-as-filename-separator.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#u-ctags output
n src/input.c /^int n;$/;" v typeref:typename:int
n src/input.c /^int n;$/;" v typeref:typename:int
n src\\input.c /^int n;$/;" v typeref:typename:int
#e-ctags output
n src\input.c /^int n;$/;" v typeref:typename:int
n src/input.c /^int n;$/;" v typeref:typename:int
n src\input.c /^int n;$/;" v typeref:typename:int
#xref output
n variable 1 src\\input.c int n;
n variable 1 src/input.c int n;
n variable 1 src\\input.c int n;
14 changes: 14 additions & 0 deletions main/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,20 @@ static void writeTagEntry (const tagEntryInfo *const tag, bool checkingNeeded)

DebugStatement ( debugEntry (tag); )

#ifdef WIN32
if (Option.useSlashAsFilenameSeparator == FILENAME_SEP_USE_SLASH)
{
Assert (((const tagEntryInfo *)tag)->inputFileName);
char *c = (char *)(((tagEntryInfo *const)tag)->inputFileName);
while (*c)
{
if (*c == PATH_SEPARATOR)
*c = OUTPUT_PATH_SEPARATOR;
c++;
}
}
#endif

if (includeExtensionFlags ()
&& isXtagEnabled (XTAG_QUALIFIED_TAGS)
&& doesInputLanguageRequestAutomaticFQTag ()
Expand Down
10 changes: 10 additions & 0 deletions main/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ optionValues Option = {
.putFieldPrefix = false,
.maxRecursionDepth = 0xffffffff,
.interactive = false,
#ifdef WIN32
.useSlashAsFilenameSeparator = FILENAME_SEP_UNSET,
#endif
#ifdef DEBUG
.breakLine = 0,
#endif
Expand Down Expand Up @@ -416,6 +419,10 @@ static optionDescription LongOptionDescription [] = {
{0," never: be absolute even if input files are passed in with relative paths" },
{1," --totals=[yes|no|extra]"},
{1," Print statistics about input and tag files [no]."},
#ifdef WIN32
{1," --use-slash-as-filename-separator"},
{1," Use slash as filename separator [no]."},
#endif
{1," --verbose=[yes|no]"},
{1," Enable verbose messages describing actions on each input file."},
{1," --version"},
Expand Down Expand Up @@ -2786,6 +2793,9 @@ static booleanOption BooleanOptions [] = {
{ "recurse", &Option.recurse, false, STAGE_ANY },
#endif
{ "verbose", &ctags_verbose, false, STAGE_ANY },
#ifdef WIN32
{ "use-slash-as-filename-separator", (bool *)&Option.useSlashAsFilenameSeparator, false, STAGE_ANY },
#endif
{ "with-list-header", &localOption.withListHeader, true, STAGE_ANY },
{ "_fatal-warnings",&Option.fatalWarnings, false, STAGE_ANY },
};
Expand Down
6 changes: 6 additions & 0 deletions main/options_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ typedef struct sOptionValues {
enum interactiveMode { INTERACTIVE_NONE = 0,
INTERACTIVE_DEFAULT,
INTERACTIVE_SANDBOX, } interactive; /* --interactive */
#ifdef WIN32
enum filenameSepOp { FILENAME_SEP_UNSET = -1,
FILENAME_SEP_NO_REPLACE = false,
FILENAME_SEP_USE_SLASH = true,
} useSlashAsFilenameSeparator; /* --use-slash-as-filename-separator */
#endif
#ifdef DEBUG
unsigned long breakLine;/* -b input line at which to call lineBreak() */
#endif
Expand Down
12 changes: 11 additions & 1 deletion main/writer-ctags.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,20 @@ struct rejection {
bool rejectionInThisInput;
};

static void *beginUCtagsFile (tagWriter *writer CTAGS_ATTR_UNUSED, MIO * mio CTAGS_ATTR_UNUSED,
void *clientData CTAGS_ATTR_UNUSED)
{
#ifdef WIN32
if (Option.useSlashAsFilenameSeparator == FILENAME_SEP_UNSET)
Option.useSlashAsFilenameSeparator = FILENAME_SEP_USE_SLASH;
#endif
return NULL;
}

tagWriter uCtagsWriter = {
.writeEntry = writeCtagsEntry,
.writePtagEntry = writeCtagsPtagEntry,
.preWriteEntry = NULL,
.preWriteEntry = beginUCtagsFile,
.postWriteEntry = NULL,
.rescanFailedEntry = NULL,
.treatFieldAsFixed = treatFieldAsFixed,
Expand Down

0 comments on commit 3efaed1

Please sign in to comment.