<commit_before>/* EINA - EFL data type library
 * Copyright (C) 2007-2008 <NAME>, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library;
 * if not, see <http://www.gnu.org/licenses/>.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#ifdef HAVE_DLADDR
#define _GNU_SOURCE
#endif

#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <string.h>

#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#elif defined __GNUC__
# define alloca __builtin_alloca
#elif defined _AIX
# define alloca __alloca
#elif defined _MSC_VER
# include <malloc.h>
# define alloca _alloca
#else
# include <stddef.h>
# ifdef  __cplusplus
extern "C"
# endif
void *alloca (size_t);
#endif

#include <dlfcn.h>

#ifdef HAVE_EVIL
# include <Evil.h>
#endif

#include "eina_error.h"
#include "eina_module.h"
#include "eina_file.h"
#include "eina_private.h"
#include "eina_safety_checks.h"

/*============================================================================*
 *                                  Local                                     *
 *============================================================================*/

/**
 * @cond LOCAL
 */

#ifdef _WIN32
# define MODULE_EXTENSION ".dll"
#else
# define MODULE_EXTENSION ".so"
#endif /* ! _WIN32 */

#define EINA_MODULE_SYMBOL_INIT "__eina_module_init"
#define EINA_MODULE_SYMBOL_SHUTDOWN "__eina_module_shutdown"

EAPI Eina_Error EINA_ERROR_WRONG_MODULE = 0;
EAPI Eina_Error EINA_ERROR_MODULE_INIT_FAILED = 0;

struct _Eina_Module
{
	char *file;
	void *handle;
	int ref;
};

typedef struct _Dir_List_Get_Cb_Data
{
	Eina_Module_Cb cb;
	void *data;
	Eina_Array *array;
} Dir_List_Get_Cb_Data;

typedef struct _Dir_List_Cb_Data
{
	Eina_Module_Cb cb;
	void *data;
} Dir_List_Cb_Data;

static Eina_Bool _dir_list_get_cb(Eina_Module *m, void *data)
{
	Dir_List_Get_Cb_Data *cb_data = data;
	Eina_Bool ret = EINA_TRUE;

	if (cb_data->cb)
	{
		ret = cb_data->cb(m, cb_data->data);
	}
	if (ret)
	{
		eina_array_push(cb_data->array, m);
	}
	return ret;
}

static void _dir_list_cb(const char *name, const char *path, void *data)
{
	Dir_List_Cb_Data *cb_data = data;
	size_t length;

	length = strlen(name);
	if (length < strlen(MODULE_EXTENSION) + 1) /* x.so */
		return;
	if (!strcmp(name + length - strlen(MODULE_EXTENSION),
			MODULE_EXTENSION))
	{
		char *file;
		Eina_Module *m;
		size_t length;

		length = strlen(path) + strlen(name) + 2;

		file = alloca(sizeof (char) * length);
		if (!file) return ;

		snprintf(file, length, "%s/%s", path, name);
		m = eina_module_new(file);
		if (!m)
			return;
		/* call the user provided cb on this module */
		cb_data->cb(m, cb_data->data);
	}
}
static int _eina_module_count = 0;

/**
 * @endcond
 */

/*============================================================================*
 *                                 Global                                     *
 *============================================================================*/

/*============================================================================*
 *                                   API                                      *
 *============================================================================*/

/**
 * To be documented
 * FIXME: To be fixed<commit_msg>do not leak module if user do not want it.<commit_after>/* EINA - EFL data type library
 * Copyright (C) 2007-2008 <NAME>, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library;
 * if not, see <http://www.gnu.org/licenses/>.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#ifdef HAVE_DLADDR
#define _GNU_SOURCE
#endif

#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <string.h>

#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#elif defined __GNUC__
# define alloca __builtin_alloca
#elif defined _AIX
# define alloca __alloca
#elif defined _MSC_VER
# include <malloc.h>
# define alloca _alloca
#else
# include <stddef.h>
# ifdef  __cplusplus
extern "C"
# endif
void *alloca (size_t);
#endif

#include <dlfcn.h>

#ifdef HAVE_EVIL
# include <Evil.h>
#endif

#include "eina_error.h"
#include "eina_module.h"
#include "eina_file.h"
#include "eina_private.h"
#include "eina_safety_checks.h"

/*============================================================================*
 *                                  Local                                     *
 *============================================================================*/

/**
 * @cond LOCAL
 */

#ifdef _WIN32
# define MODULE_EXTENSION ".dll"
#else
# define MODULE_EXTENSION ".so"
#endif /* ! _WIN32 */

#define EINA_MODULE_SYMBOL_INIT "__eina_module_init"
#define EINA_MODULE_SYMBOL_SHUTDOWN "__eina_module_shutdown"

EAPI Eina_Error EINA_ERROR_WRONG_MODULE = 0;
EAPI Eina_Error EINA_ERROR_MODULE_INIT_FAILED = 0;

struct _Eina_Module
{
	char *file;
	void *handle;
	int ref;
};

typedef struct _Dir_List_Get_Cb_Data
{
	Eina_Module_Cb cb;
	void *data;
	Eina_Array *array;
} Dir_List_Get_Cb_Data;

typedef struct _Dir_List_Cb_Data
{
	Eina_Module_Cb cb;
	void *data;
} Dir_List_Cb_Data;

static Eina_Bool _dir_list_get_cb(Eina_Module *m, void *data)
{
	Dir_List_Get_Cb_Data *cb_data = data;
	Eina_Bool ret = EINA_TRUE;

	if (cb_data->cb)
	{
		ret = cb_data->cb(m, cb_data->data);
	}
	if (ret)
	{
		eina_array_push(cb_data->array, m);
	}
	return ret;
}

static void _dir_list_cb(const char *name, const char *path, void *data)
{
	Dir_List_Cb_Data *cb_data = data;
	size_t length;

	length = strlen(name);
	if (length < strlen(MODULE_EXTENSION) + 1) /* x.so */
		return;
	if (!strcmp(name + length - strlen(MODULE_EXTENSION),
			MODULE_EXTENSION))
	{
		char *file;
		Eina_Module *m;
		size_t length;

		length = strlen(path) + strlen(name) + 2;

		file = alloca(sizeof (char) * length);
		if (!file) return ;

		snprintf(file, length, "%s/%s", path, name);
		m = eina_module_new(file);
		if (!m)
			return;
		/* call the user provided cb on this module */
		if (!cb_data->cb(m, cb_data->data))
		  eina_module_delete(m);
	}
}
static int _eina_module_count = 0;

/**
 * @endcond
 */

/*============================================================================*
 *                                 Global                                     *
 *============================================================================*/

/*============================================================================*
 *                                   API                                      *
 *============================================================================*/

/**
 * To be documented
 * FIXME: To be fixed
{'fraction_non_alphanumeric': 0.2156530798281026, 'fraction_numerical': 0.004948561010548249, 'mean_word_length': 3.6743761412051126, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1165380', 'n_tokens_mistral': 2607, 'n_tokens_neox': 2456, 'n_words': 690}