<commit_before>/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */
#include "e.h"

/* TODO List:
 * 
 * * add module types/classes
 * * add list of exclusions that a module cant work with
 * 
 */

typedef struct _Module_Menu_Data Module_Menu_Data;

struct _Module_Menu_Data
{
   Evas_List *submenus;
};

/* local subsystem functions */
static void _e_module_free(E_Module *m);
static E_Menu *_e_module_control_menu_new(E_Module *mod);
static void _e_module_menu_free(void *obj);
static void _e_module_control_menu_about(void *data, E_Menu *m, E_Menu_Item *mi);
static void _e_module_control_menu_enabled(void *data, E_Menu *m, E_Menu_Item *mi);

/* local subsystem globals */
static Evas_List *_e_modules = NULL;

static E_Module_Api _e_module_api =
{
   E_MODULE_API_VERSION
};

/* externally accessible functions */
int
e_module_init(void)
{
   Evas_List *pl = NULL, *l;
   
   for (l = e_config->modules; l;)
     {
	E_Config_Module *em;
	E_Module *m;
	
	em = l->data;
	pl = l;
	l = l->next;
	m = e_module_new(em->name);
	if (m)
	  {
	     if (em->enabled) e_module_enable(m);
	  }
	else
	  {
	     IF_FREE(em->name);
	     IF_FREE(em);
	     e_config->modules = evas_list_remove_list(e_config->modules, pl);
	     e_config_save_queue();
	  }
     }
   
   return 1;
}

int
e_module_shutdown(void)
{
   Evas_List *l, *tmp;
   for (l = _e_modules; l;)
     {
	tmp = l;
	l = l->next;
	e_object_del(E_OBJECT(tmp->data));
     }
   return 1;
}

E_Module *
e_module_new(char *name)
{
   E_Module *m;
   char buf[4096];
   char *modpath, *s;
   Evas_List *l;
   int in_list = 0;

   if (!name) return NULL;
   m = E_OBJECT_ALLOC(E_Module, E_MODULE_TYPE, _e_module_free);
   m->api = &_e_module_api;
   if (name[0] != '/')
     {
	snprintf(buf, sizeof(buf), "%s/%s/module.so", name, MODULE_ARCH);
	modpath = e_path_find(path_modules, buf);
     }
   else
     modpath = strdup(name);
   if (!modpath)
     {
	e_error_dialog_show(_("Error loading Module"),
			    _("There was an error loading module named: %s\n"
			      "No module named %s could be found in the\n"
			      "module search directories\n"),
			    name, buf);
	free(m);
	return NULL;
     }
   m->handle = dlopen(modpath, RTLD_NOW | RTLD_GLOBAL);
   if (!m->handle)
     {
	e_error_dialog_show(_("Error loading Module"),
			    _("There was an error loading module named: %s\n"
			      "The full path to this module is:\n"
			      "%s\n"
			      "The error reported was:\n"
			      "dlopen: %s"),
			    name, buf, dlerror());
	free(m);
	return NULL;
     }
   m->func.init = dlsym(m->handle, "e_modapi_init");
   m->func.shutdown = dlsym(m->handle, "e_modapi_shutdown");
   m->func.save = dlsym(m->handle, "e_modapi_save");
   m->func.info = dlsym(m->handle, "e_modapi_info");
   m->func.about = dlsym(m->handle, "e_modapi_about");
   if ((!m->func.init) ||
       (!m->func.shutdown) ||
       (!m->func.save) ||
       (!m->func.info) ||
       (!m->func.about)
       )
     {
	e_error_dialog_show(_("Error loading Module"),
			    _("There was an error loading module named: %s\n"
			      "The full path to this module is:\n"
			      "%s\n"
			      "The error reported was:\n"
			      "dlsym: %s"),
			    name, buf, dlerror());
	dlclose(m->handle);
	free(m);
	return NULL;
     }
   _e_modules = evas_list_append(_e_modules, m);
   m->name = strdup(name);
   s = ecore_file_get_dir(modpath);
   if (s)
     {
	m->dir = ecore_file_get_dir(s);<commit_msg>Remove debug comment.<commit_after>/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */
#include "e.h"

/* TODO List:
 * 
 * * add module types/classes
 * * add list of exclusions that a module cant work with
 * 
 */

typedef struct _Module_Menu_Data Module_Menu_Data;

struct _Module_Menu_Data
{
   Evas_List *submenus;
};

/* local subsystem functions */
static void _e_module_free(E_Module *m);
static E_Menu *_e_module_control_menu_new(E_Module *mod);
static void _e_module_menu_free(void *obj);
static void _e_module_control_menu_about(void *data, E_Menu *m, E_Menu_Item *mi);
static void _e_module_control_menu_enabled(void *data, E_Menu *m, E_Menu_Item *mi);

/* local subsystem globals */
static Evas_List *_e_modules = NULL;

static E_Module_Api _e_module_api =
{
   E_MODULE_API_VERSION
};

/* externally accessible functions */
int
e_module_init(void)
{
   Evas_List *pl = NULL, *l;
   
   for (l = e_config->modules; l;)
     {
	E_Config_Module *em;
	E_Module *m;
	
	em = l->data;
	pl = l;
	l = l->next;
	m = e_module_new(em->name);
	if (m)
	  {
	     if (em->enabled) e_module_enable(m);
	  }
	else
	  {
	     IF_FREE(em->name);
	     IF_FREE(em);
	     e_config->modules = evas_list_remove_list(e_config->modules, pl);
	     e_config_save_queue();
	  }
     }
   
   return 1;
}

int
e_module_shutdown(void)
{
   Evas_List *l, *tmp;
   for (l = _e_modules; l;)
     {
	tmp = l;
	l = l->next;
	e_object_del(E_OBJECT(tmp->data));
     }
   return 1;
}

E_Module *
e_module_new(char *name)
{
   E_Module *m;
   char buf[4096];
   char *modpath, *s;
   Evas_List *l;
   int in_list = 0;

   if (!name) return NULL;
   m = E_OBJECT_ALLOC(E_Module, E_MODULE_TYPE, _e_module_free);
   m->api = &_e_module_api;
   if (name[0] != '/')
     {
	snprintf(buf, sizeof(buf), "%s/%s/module.so", name, MODULE_ARCH);
	modpath = e_path_find(path_modules, buf);
     }
   else
     modpath = strdup(name);
   if (!modpath)
     {
	e_error_dialog_show(_("Error loading Module"),
			    _("There was an error loading module named: %s\n"
			      "No module named %s could be found in the\n"
			      "module search directories\n"),
			    name, buf);
	free(m);
	return NULL;
     }
   m->handle = dlopen(modpath, RTLD_NOW | RTLD_GLOBAL);
   if (!m->handle)
     {
	e_error_dialog_show(_("Error loading Module"),
			    _("There was an error loading module named: %s\n"
			      "The full path to this module is:\n"
			      "%s\n"
			      "The error reported was:\n"
			      "%s"),
			    name, buf, dlerror());
	free(m);
	return NULL;
     }
   m->func.init = dlsym(m->handle, "e_modapi_init");
   m->func.shutdown = dlsym(m->handle, "e_modapi_shutdown");
   m->func.save = dlsym(m->handle, "e_modapi_save");
   m->func.info = dlsym(m->handle, "e_modapi_info");
   m->func.about = dlsym(m->handle, "e_modapi_about");
   if ((!m->func.init) ||
       (!m->func.shutdown) ||
       (!m->func.save) ||
       (!m->func.info) ||
       (!m->func.about)
       )
     {
	e_error_dialog_show(_("Error loading Module"),
			    _("There was an error loading module named: %s\n"
			      "The full path to this module is:\n"
			      "%s\n"
			      "The error reported was:\n"
			      "%s"),
			    name, buf, dlerror());
	dlclose(m->handle);
	free(m);
	return NULL;
     }
   _e_modules = evas_list_append(_e_modules, m);
   m->name = strdup(name);
   s = ecore_file_get_dir(modpath);
   if (s)
     {
	m->dir = ecore_file_get_dir(s);
{'fraction_non_alphanumeric': 0.15155044402387538, 'fraction_numerical': 0.004658611151550444, 'mean_word_length': 2.966512702078522, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2713012', 'n_tokens_mistral': 2854, 'n_tokens_neox': 2707, 'n_words': 585}