Skip to content

Commit

Permalink
Remove built in globbing support when generating tag files
Browse files Browse the repository at this point in the history
We can rely on shell to expand wildcards for us and the current detection
of whether globbing should be enabled based on \" presence is questionable,
undocumented and probably unused.
  • Loading branch information
techee committed May 17, 2022
1 parent 37d20a8 commit 41d771c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 66 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -45,7 +45,7 @@ fi
# autoscan start

# Checks for header files.
AC_CHECK_HEADERS([fcntl.h glob.h stdlib.h sys/time.h errno.h limits.h])
AC_CHECK_HEADERS([fcntl.h stdlib.h sys/time.h errno.h limits.h])

# Checks for dependencies needed by ctags
AC_CHECK_HEADERS([dirent.h fnmatch.h direct.h io.h sys/dir.h])
Expand Down
1 change: 0 additions & 1 deletion meson.build
Expand Up @@ -46,7 +46,6 @@ check_headers = [
'errno.h',
'fcntl.h',
'fnmatch.h',
'glob.h',
'inttypes.h',
'io.h',
'langinfo.h',
Expand Down
69 changes: 5 additions & 64 deletions src/tagmanager/tm_workspace.c
Expand Up @@ -24,9 +24,6 @@
#include <sys/types.h>
#include <string.h>
#include <sys/stat.h>
#ifdef HAVE_GLOB_H
# include <glob.h>
#endif
#include <glib/gstdio.h>

#include "tm_workspace.h"
Expand Down Expand Up @@ -443,73 +440,17 @@ static GList *lookup_includes(const gchar **includes, gint includes_count)
GList *includes_files = NULL;
GHashTable *table; /* used for deduping */
gint i;
#ifdef HAVE_GLOB_H
glob_t globbuf;
size_t idx_glob;
#endif

table = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);

#ifdef HAVE_GLOB_H
globbuf.gl_offs = 0;

if (includes[0][0] == '"') /* leading \" char for glob matching */
{
for (i = 0; i < includes_count; i++)
{
size_t dirty_len = strlen(includes[i]);
gchar *clean_path;

if (dirty_len < 2)
continue;

clean_path = g_malloc(dirty_len - 1);

strncpy(clean_path, includes[i] + 1, dirty_len - 1);
clean_path[dirty_len - 2] = 0;

#ifdef TM_DEBUG
g_message ("[o][%s]\n", clean_path);
#endif
glob(clean_path, 0, NULL, &globbuf);

#ifdef TM_DEBUG
g_message ("matches: %d\n", globbuf.gl_pathc);
#endif

for (idx_glob = 0; idx_glob < globbuf.gl_pathc; idx_glob++)
{
#ifdef TM_DEBUG
g_message (">>> %s\n", globbuf.gl_pathv[idx_glob]);
#endif
if (!g_hash_table_lookup(table, globbuf.gl_pathv[idx_glob]))
{
gchar *file_name_copy = g_strdup(globbuf.gl_pathv[idx_glob]);

includes_files = g_list_prepend(includes_files, file_name_copy);
g_hash_table_insert(table, file_name_copy, file_name_copy);
#ifdef TM_DEBUG
g_message ("Added ...\n");
#endif
}
}
globfree(&globbuf);
g_free(clean_path);
}
}
else
#endif /* HAVE_GLOB_H */
for (i = 0; i < includes_count; i++)
{
/* no glob support or globbing not wanted */
for (i = 0; i < includes_count; i++)
if (!g_hash_table_lookup(table, includes[i]))
{
if (!g_hash_table_lookup(table, includes[i]))
{
gchar* file_name_copy = g_strdup(includes[i]);
gchar* file_name_copy = g_strdup(includes[i]);

includes_files = g_list_prepend(includes_files, file_name_copy);
g_hash_table_insert(table, file_name_copy, file_name_copy);
}
includes_files = g_list_prepend(includes_files, file_name_copy);
g_hash_table_insert(table, file_name_copy, file_name_copy);
}
}

Expand Down

0 comments on commit 41d771c

Please sign in to comment.