Skip to content

Commit

Permalink
main: introduce portable scandir implementation
Browse files Browse the repository at this point in the history
option-directory feature was not available on platforms
where scandir is not available.

Following items are suggested by @k-takata:

* use eMalloc/eRealloc/eFree, and
* refer _MSC_VER instead of _MSVC
  • Loading branch information
masatake committed Aug 3, 2017
1 parent daa85cb commit c9fa895
Show file tree
Hide file tree
Showing 8 changed files with 668 additions and 8 deletions.
6 changes: 5 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,11 @@ have_regcomp=no])
AC_SUBST([REGCOMP_CPPFLAGS])
AM_CONDITIONAL([HAVE_REGCOMP], [test "xyes" = "x$have_regcomp"])

AC_CHECK_FUNCS(scandir)
have_scandir=no
AC_CHECK_FUNCS(scandir,have_scandir=yes)

have_dirent_h=no
AC_CHECK_HEADERS(dirent.h,have_dirent_h=yes)

AC_ARG_ENABLE([xml],
[AS_HELP_STRING([--disable-xml],
Expand Down
16 changes: 9 additions & 7 deletions main/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
#include <stdio.h>
#include <ctype.h> /* to declare isspace () */

#if defined(HAVE_SCANDIR)
#include <dirent.h>
#endif

#include "ctags.h"
#include "debug.h"
#include "field.h"
Expand Down Expand Up @@ -511,7 +507,7 @@ static struct Feature {
#ifdef DEBUG
{"debug", "TO BE WRITTEN"},
#endif
#ifdef HAVE_SCANDIR
#if defined(HAVE_SCANDIR) || defined (HAVE_DIRENT_H) || defined (_MSC_VER)
{"option-directory", "TO BE WRITTEN"},
#endif
#ifdef HAVE_LIBXML
Expand Down Expand Up @@ -3341,7 +3337,7 @@ static void parseConfigurationFileOptionsInDirectory (const char* directory)
#endif
}

#if defined(HAVE_SCANDIR)
#if defined(HAVE_SCANDIR) || defined (HAVE_DIRENT_H) || defined (_MSC_VER)
static int ignore_dot_file(const struct dirent* dent)
{
/* Ignore a file which name is started from dot. */
Expand Down Expand Up @@ -3383,13 +3379,19 @@ static int accept_only_dot_ctags(const struct dirent* dent)
return 0;
}

static int local_insenstive_alphasort(const struct dirent ** a,
const struct dirent ** b)
{
return strcmp ((*a)->d_name, (*b)->d_name);
}

static bool parseAllConfigurationFilesOptionsInDirectory (const char* const dirName,
stringList* const already_loaded_files)
{
struct dirent **dents;
int i, n;

n = scandir (dirName, &dents, ignore_dot_file, alphasort);
n = scanDirectory (dirName, &dents, ignore_dot_file, local_insenstive_alphasort);
if (n < 0)
return false;

Expand Down
Loading

0 comments on commit c9fa895

Please sign in to comment.