Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main,win32: introduce an option replacing backslashes in input file names with slashes #2199

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Tmain/input-encoding-option.d/tags-expected.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
!_TAG_FILE_ENCODING UTF-8 //
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_PROGRAM_AUTHOR Universal Ctags Team //
!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
Expand Down
2 changes: 1 addition & 1 deletion Tmain/json-output-format.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ if is_feature_available "${CTAGS}" json; then
run_with_format json --languages=+man
run_with_format json --languages=+man --fields="*"
run_with_format json --languages=+man --fields="*" --extras='*'-{subword}
} | grep -v TAG_PROGRAM_VERSION
} | grep -v TAG_PROGRAM_VERSION | grep -v TAG_OUTPUT_FILESEP
fi
1 change: 1 addition & 0 deletions Tmain/list-pseudo-tags.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ TAG_FILE_FORMAT on the version of tags file format
TAG_FILE_SORTED on how tags are sorted
TAG_KIND_DESCRIPTION off the letters, names and descriptions of kinds in a parser
TAG_KIND_SEPARATOR off the separators used in kinds
TAG_OUTPUT_FILESEP on the separator used in file name (slash or backslash)
TAG_OUTPUT_MODE on the output mode: u-ctags or e-ctags
TAG_PROGRAM_AUTHOR on the author of this ctags implementation
TAG_PROGRAM_NAME on the name of this ctags implementation
Expand Down
9 changes: 2 additions & 7 deletions Tmain/maxdepth.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@

CTAGS=$1

convsep ()
{
sed -e 's#\\\\#/#g'
}

echo '# DEPTH=1'
${CTAGS} --quiet --options=NONE --maxdepth=1 -R -o - ./src | convsep
${CTAGS} --quiet --options=NONE --maxdepth=1 -R -o - ./src
echo '# DEPTH=2'
${CTAGS} --quiet --options=NONE --maxdepth=2 -R -o - ./src | convsep
${CTAGS} --quiet --options=NONE --maxdepth=2 -R -o - ./src
exit $?
40 changes: 40 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,40 @@
# 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 '#u-ctags ptag output'
{
$CTAGS --quiet --options=NONE --extras=p -o - 'src\input.c'
$CTAGS --quiet --options=NONE --extras=p -o - $OPT 'src\input.c'
$CTAGS --quiet --options=NONE --extras=p -o - ${OPT}=no 'src\input.c'
} | grep TAG_OUTPUT_FILESEP

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 '#e-ctags ptag output'
{
$CTAGS --quiet --options=NONE --extras=p --output-format=e-ctags -o - 'src\input.c'
$CTAGS --quiet --options=NONE --extras=p --output-format=e-ctags -o - $OPT 'src\input.c'
$CTAGS --quiet --options=NONE --extras=p --output-format=e-ctags -o - ${OPT}=no 'src\input.c'
} | grep TAG_OUTPUT_FILESEP

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;
20 changes: 20 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,20 @@
#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
#u-ctags ptag output
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_OUTPUT_FILESEP backslash /slash or backslash/
#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
#e-ctags ptag output
!_TAG_OUTPUT_FILESEP backslash /slash or backslash/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_OUTPUT_FILESEP backslash /slash or backslash/
#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;
1 change: 1 addition & 0 deletions Tmain/output-encoding-option.d/tags-expected.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
!_TAG_FILE_ENCODING cp932 //
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_PROGRAM_AUTHOR Universal Ctags Team //
!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
Expand Down
2 changes: 2 additions & 0 deletions Tmain/ptag-kind-desc.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
!_TAG_KIND_DESCRIPTION!Sh f,function /functions/
!_TAG_KIND_DESCRIPTION!Sh h,heredoc /label for here document/
!_TAG_KIND_DESCRIPTION!Sh s,script /script files/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_PROGRAM_AUTHOR Universal Ctags Team //
!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
Expand All @@ -13,6 +14,7 @@
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_KIND_DESCRIPTION!foo k,kind /kinds/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_PROGRAM_AUTHOR Universal Ctags Team //
!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
Expand Down
1 change: 1 addition & 0 deletions Tmain/tags-pseudo-tags.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
!_TAG_KIND_SEPARATOR!PHP \\ /nn/
!_TAG_KIND_SEPARATOR!PHP \\ /nt/
!_TAG_KIND_SEPARATOR!PHP \\ /nv/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_PROGRAM_AUTHOR Universal Ctags Team //
!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
Expand Down
4 changes: 2 additions & 2 deletions Tmain/w32-slash-in-exclude-option.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
capture_me_0 input.d\\input.c /^int capture_me_0(void)$/;" f typeref:typename:int
capture_me_1 input.d\\capture_me\\input.c /^int capture_me_1(void)$/;" f typeref:typename:int
capture_me_0 input.d/input.c /^int capture_me_0(void)$/;" f typeref:typename:int
capture_me_1 input.d/capture_me/input.c /^int capture_me_1(void)$/;" f typeref:typename:int
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
name: Install build tools
# TODO: enable spell checker
command: |
yum -y install gcc automake autoconf pkgconfig make libxml2-devel jansson-devel libyaml-devel findutils
yum -y --enablerepo=PowerTools install gcc automake autoconf pkgconfig make libxml2-devel jansson-devel libyaml-devel findutils diffutils
- run:
name: Build
command: |
Expand Down
16 changes: 15 additions & 1 deletion main/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static void addCommonPseudoTags (void)
for (int i = 0; i < PTAG_COUNT; i++)
{
if (isPtagCommonInParsers (i))
makePtagIfEnabled (i, NULL);
makePtagIfEnabled (i, &Option);
}
}

Expand Down Expand Up @@ -1236,6 +1236,20 @@ static void writeTagEntry (const tagEntryInfo *const tag, bool checkingNeeded)

DebugStatement ( debugEntry (tag); )

#ifdef WIN32
if (getFilenameSeparator(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
14 changes: 12 additions & 2 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 [yes] for u-ctags output format."},
#endif
{1," --verbose=[yes|no]"},
{1," Enable verbose messages describing actions on each input file."},
{1," --version"},
Expand Down Expand Up @@ -526,7 +533,7 @@ static struct Feature {
#ifdef CUSTOM_CONFIGURATION_FILE
{"custom-conf", "read \"" CUSTOM_CONFIGURATION_FILE "\" as config file"},
#endif
#if defined (WIN32) && defined (UNIX_PATH_SEPARATOR)
#if defined (WIN32)
{"unix-path-separator", "can use '/' as file name separator"},
#endif
#ifdef HAVE_ICONV
Expand Down Expand Up @@ -1146,7 +1153,7 @@ static void processExcludeOption (
{
vString *const item = vStringNewInit (parameter);
#if defined (WIN32)
vStringTranslate(item, '\\', '/');
vStringTranslate(item, PATH_SEPARATOR, OUTPUT_PATH_SEPARATOR);
#endif
if (Excluded == NULL)
Excluded = stringListNew ();
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_NO_REPLACE = false,
FILENAME_SEP_USE_SLASH = true,
FILENAME_SEP_UNSET,
} useSlashAsFilenameSeparator; /* --use-slash-as-filename-separator */
#endif
#ifdef DEBUG
unsigned long breakLine;/* -b input line at which to call lineBreak() */
#endif
Expand Down
28 changes: 16 additions & 12 deletions main/ptag.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <string.h>


static bool ptagMakeFormat (ptagDesc *desc, void *data CTAGS_ATTR_UNUSED)
static bool ptagMakeFormat (ptagDesc *desc, const void *data CTAGS_ATTR_UNUSED)
{
char format [11];
const char *formatComment = "unknown format";
Expand All @@ -38,7 +38,7 @@ static bool ptagMakeFormat (ptagDesc *desc, void *data CTAGS_ATTR_UNUSED)
return writePseudoTag (desc, format, formatComment, NULL);
}

static bool ptagMakeHowSorted (ptagDesc *desc, void *data CTAGS_ATTR_UNUSED)
static bool ptagMakeHowSorted (ptagDesc *desc, const void *data CTAGS_ATTR_UNUSED)
{
return writePseudoTag (desc,
Option.sorted == SO_FOLDSORTED ? "2" :
Expand All @@ -47,32 +47,32 @@ static bool ptagMakeHowSorted (ptagDesc *desc, void *data CTAGS_ATTR_UNUSED)
NULL);
}

static bool ptagMakeAuthor (ptagDesc *desc, void *data CTAGS_ATTR_UNUSED)
static bool ptagMakeAuthor (ptagDesc *desc, const void *data CTAGS_ATTR_UNUSED)
{
return writePseudoTag (desc,
AUTHOR_NAME, "", NULL);
}

static bool ptagMakeProgName (ptagDesc *desc, void *data CTAGS_ATTR_UNUSED)
static bool ptagMakeProgName (ptagDesc *desc, const void *data CTAGS_ATTR_UNUSED)
{
return writePseudoTag (desc,
PROGRAM_NAME, "Derived from Exuberant Ctags", NULL);
}

static bool ptagMakeProgURL (ptagDesc *desc, void *data CTAGS_ATTR_UNUSED)
static bool ptagMakeProgURL (ptagDesc *desc, const void *data CTAGS_ATTR_UNUSED)
{
return writePseudoTag (desc,
PROGRAM_URL, "official site", NULL);
}

static bool ptagMakeProgVersion (ptagDesc *desc, void *data CTAGS_ATTR_UNUSED)
static bool ptagMakeProgVersion (ptagDesc *desc, const void *data CTAGS_ATTR_UNUSED)
{
const char* repoinfo = ctags_repoinfo? ctags_repoinfo: "";
return writePseudoTag (desc, PROGRAM_VERSION, repoinfo, NULL);
}

#ifdef HAVE_ICONV
static bool ptagMakeFileEncoding (ptagDesc *desc, void *data CTAGS_ATTR_UNUSED)
static bool ptagMakeFileEncoding (ptagDesc *desc, const void *data CTAGS_ATTR_UNUSED)
{
if (! Option.outputEncoding)
return false;
Expand All @@ -81,16 +81,16 @@ static bool ptagMakeFileEncoding (ptagDesc *desc, void *data CTAGS_ATTR_UNUSED)
}
#endif

static bool ptagMakeKindSeparators (ptagDesc *desc, void *data)
static bool ptagMakeKindSeparators (ptagDesc *desc, const void *data)
{
langType *language = data;
const langType *language = data;

return makeKindSeparatorsPseudoTags (*language, desc);
}

static bool ptagMakeKindDescriptions (ptagDesc *desc, void *data)
static bool ptagMakeKindDescriptions (ptagDesc *desc, const void *data)
{
langType *language = data;
const langType *language = data;
return makeKindDescriptionsPseudoTags (*language, desc);
}

Expand Down Expand Up @@ -144,9 +144,13 @@ static ptagDesc ptagDescs [] = {
"the output mode: u-ctags or e-ctags",
ptagMakeCtagsOutputMode,
true },
{ true, "TAG_OUTPUT_FILESEP",
"the separator used in file name (slash or backslash)",
ptagMakeCtagsOutputFilesep,
true },
};

extern bool makePtagIfEnabled (ptagType type, void *data)
extern bool makePtagIfEnabled (ptagType type, const void *data)
{
ptagDesc *desc;

Expand Down
11 changes: 9 additions & 2 deletions main/ptag_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,25 @@ typedef enum ePtagType { /* pseudo tag content control */
PTAG_KIND_SEPARATOR,
PTAG_KIND_DESCRIPTION,
PTAG_OUTPUT_MODE,
PTAG_OUTPUT_FILESEP,
PTAG_COUNT
} ptagType;

struct sPtagDesc {
bool enabled;
const char* name;
const char* description; /* displayed in --list-pseudo-tags output */
bool (* makeTag) (ptagDesc *, void *);

/* For the common ptags, the pointer for optionValues type value
* is passed as the second argument.
* For parser specific ptags, the pointer for parserObject
* of the parser is passed as the second argument.
*/
bool (* makeTag) (ptagDesc *, const void *);
bool commonInParsers;
};

extern bool makePtagIfEnabled (ptagType type, void *data);
extern bool makePtagIfEnabled (ptagType type, const void *data);
extern ptagDesc* getPtagDesc (ptagType type);
extern ptagType getPtagTypeForName (const char *name);
extern void printPtags (bool withListHeader, bool machinable, FILE *fp);
Expand Down
2 changes: 1 addition & 1 deletion main/routines_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# endif
#endif

#if defined (MSDOS_STYLE_PATH) && defined (UNIX_PATH_SEPARATOR)
#if defined (MSDOS_STYLE_PATH)
# define OUTPUT_PATH_SEPARATOR '/'
#else
# define OUTPUT_PATH_SEPARATOR PATH_SEPARATOR
Expand Down
4 changes: 2 additions & 2 deletions main/strlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ extern vString* stringListFileFinds (

#if defined (WIN32)
vString *tmp = vStringNewInit (fileName);
vStringTranslate (tmp, '\\', '/');
vStringTranslate (tmp, PATH_SEPARATOR, OUTPUT_PATH_SEPARATOR);
normalized = vStringValue (tmp);
#endif

Expand All @@ -257,7 +257,7 @@ extern vString* stringListFileFinds (
matched = fileNameMatched (vstr, normalized);
}

#if defined (WIN32) && defined (UNIX_PATH_SEPARATOR)
#if defined (WIN32)
vStringDelete (tmp);
#endif

Expand Down
1 change: 1 addition & 0 deletions main/strlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
#include "general.h" /* must always come first */

#include "routines_p.h"
#include "vstring.h"
#include "ptrarray.h"

Expand Down
Loading