Kill filetypes_find(), rename static function
It's not worth abstracting finding through filetypes_array, it's not bug prone, and it may even cause bugs with non-type-safe predicate signature. It was only used once anyway.
This commit is contained in:
parent
868da11715
commit
0082fb2a99
@ -463,26 +463,8 @@ void filetypes_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Find a filetype that predicate returns TRUE for, otherwise return NULL. */
|
static gboolean match_basename(const GeanyFiletype *ft, const gchar *base_filename)
|
||||||
GeanyFiletype *filetypes_find(GCompareFunc predicate, gpointer user_data)
|
|
||||||
{
|
{
|
||||||
guint i;
|
|
||||||
|
|
||||||
for (i = 0; i < filetypes_array->len; i++)
|
|
||||||
{
|
|
||||||
GeanyFiletype *ft = filetypes[i];
|
|
||||||
|
|
||||||
if (predicate(ft, user_data))
|
|
||||||
return ft;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static gboolean match_basename(gconstpointer pft, gconstpointer user_data)
|
|
||||||
{
|
|
||||||
const GeanyFiletype *ft = pft;
|
|
||||||
const gchar *base_filename = user_data;
|
|
||||||
gint j;
|
gint j;
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
@ -505,7 +487,7 @@ static gboolean match_basename(gconstpointer pft, gconstpointer user_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static GeanyFiletype *check_builtin_filenames(const gchar *utf8_filename)
|
static GeanyFiletype *detect_filetype_conf_file(const gchar *utf8_filename)
|
||||||
{
|
{
|
||||||
gchar *lfn = NULL;
|
gchar *lfn = NULL;
|
||||||
gchar *path;
|
gchar *path;
|
||||||
@ -540,7 +522,7 @@ GeanyFiletype *filetypes_detect_from_extension(const gchar *utf8_filename)
|
|||||||
gchar *base_filename;
|
gchar *base_filename;
|
||||||
GeanyFiletype *ft;
|
GeanyFiletype *ft;
|
||||||
|
|
||||||
ft = check_builtin_filenames(utf8_filename);
|
ft = detect_filetype_conf_file(utf8_filename);
|
||||||
if (ft)
|
if (ft)
|
||||||
return ft;
|
return ft;
|
||||||
|
|
||||||
@ -551,7 +533,14 @@ GeanyFiletype *filetypes_detect_from_extension(const gchar *utf8_filename)
|
|||||||
SETPTR(base_filename, g_utf8_strdown(base_filename, -1));
|
SETPTR(base_filename, g_utf8_strdown(base_filename, -1));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ft = filetypes_find(match_basename, base_filename);
|
for (guint i = 0; i < filetypes_array->len; i++)
|
||||||
|
{
|
||||||
|
if (match_basename(filetypes[i], base_filename))
|
||||||
|
{
|
||||||
|
ft = filetypes[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (ft == NULL)
|
if (ft == NULL)
|
||||||
ft = filetypes[GEANY_FILETYPES_NONE];
|
ft = filetypes[GEANY_FILETYPES_NONE];
|
||||||
|
|
||||||
|
@ -196,9 +196,6 @@ extern GPtrArray *filetypes_array;
|
|||||||
extern GSList *filetypes_by_title;
|
extern GSList *filetypes_by_title;
|
||||||
|
|
||||||
|
|
||||||
GeanyFiletype *filetypes_find(GCompareFunc predicate, gpointer user_data);
|
|
||||||
|
|
||||||
|
|
||||||
void filetypes_init(void);
|
void filetypes_init(void);
|
||||||
|
|
||||||
void filetypes_init_types(void);
|
void filetypes_init_types(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user