coding style/indent.

SVN revision: 42193
This commit is contained in:
Gustavo Sverzut Barbieri 2009-09-02 22:39:41 +00:00
parent d00a91f70d
commit c1e2a300e4
1 changed files with 202 additions and 202 deletions

View File

@ -78,68 +78,68 @@ void *alloca (size_t);
struct _Eina_Module struct _Eina_Module
{ {
char *file; char *file;
void *handle; void *handle;
int ref; int ref;
}; };
typedef struct _Dir_List_Get_Cb_Data typedef struct _Dir_List_Get_Cb_Data
{ {
Eina_Module_Cb cb; Eina_Module_Cb cb;
void *data; void *data;
Eina_Array *array; Eina_Array *array;
} Dir_List_Get_Cb_Data; } Dir_List_Get_Cb_Data;
typedef struct _Dir_List_Cb_Data typedef struct _Dir_List_Cb_Data
{ {
Eina_Module_Cb cb; Eina_Module_Cb cb;
void *data; void *data;
} Dir_List_Cb_Data; } Dir_List_Cb_Data;
static Eina_Bool _dir_list_get_cb(Eina_Module *m, void *data) static Eina_Bool _dir_list_get_cb(Eina_Module *m, void *data)
{ {
Dir_List_Get_Cb_Data *cb_data = data; Dir_List_Get_Cb_Data *cb_data = data;
Eina_Bool ret = EINA_TRUE; Eina_Bool ret = EINA_TRUE;
if (cb_data->cb) if (cb_data->cb)
{ {
ret = cb_data->cb(m, cb_data->data); ret = cb_data->cb(m, cb_data->data);
} }
if (ret) if (ret)
{ {
eina_array_push(cb_data->array, m); eina_array_push(cb_data->array, m);
} }
return ret; return ret;
} }
static void _dir_list_cb(const char *name, const char *path, void *data) static void _dir_list_cb(const char *name, const char *path, void *data)
{ {
Dir_List_Cb_Data *cb_data = 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; size_t length;
length = strlen(name); length = strlen(path) + strlen(name) + 2;
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 ;
file = alloca(sizeof (char) * length); snprintf(file, length, "%s/%s", path, name);
if (!file) return ; m = eina_module_new(file);
if (!m)
snprintf(file, length, "%s/%s", path, name); return;
m = eina_module_new(file); /* call the user provided cb on this module */
if (!m) if (!cb_data->cb(m, cb_data->data))
return; eina_module_free(m);
/* call the user provided cb on this module */ }
if (!cb_data->cb(m, cb_data->data))
eina_module_free(m);
}
} }
static int _eina_module_count = 0; static int _eina_module_count = 0;
@ -198,22 +198,22 @@ EAPI Eina_Error EINA_ERROR_MODULE_INIT_FAILED = 0;
EAPI int EAPI int
eina_module_init(void) eina_module_init(void)
{ {
_eina_module_count++; _eina_module_count++;
if (_eina_module_count != 1) if (_eina_module_count != 1)
goto end_init; goto end_init;
if (!eina_error_init()) if (!eina_error_init())
{ {
fprintf(stderr, "Could not initialize eina error module.\n"); fprintf(stderr, "Could not initialize eina error module.\n");
return 0; return 0;
} }
EINA_ERROR_WRONG_MODULE = eina_error_msg_register("Wrong file format or no file module found"); EINA_ERROR_WRONG_MODULE = eina_error_msg_register("Wrong file format or no file module found");
EINA_ERROR_MODULE_INIT_FAILED = eina_error_msg_register("Module initialisation function failed"); EINA_ERROR_MODULE_INIT_FAILED = eina_error_msg_register("Module initialisation function failed");
end_init: end_init:
return _eina_module_count; return _eina_module_count;
} }
/** /**
@ -233,18 +233,18 @@ end_init:
EAPI int EAPI int
eina_module_shutdown(void) eina_module_shutdown(void)
{ {
_eina_module_count--; _eina_module_count--;
if (_eina_module_count != 0) if (_eina_module_count != 0)
goto end_shutdown; goto end_shutdown;
eina_error_shutdown(); eina_error_shutdown();
/* TODO should we store every module when "new" is called and /* TODO should we store every module when "new" is called and
* delete the list of modules here * delete the list of modules here
*/ */
end_shutdown: end_shutdown:
return _eina_module_count; return _eina_module_count;
} }
/** /**
@ -264,18 +264,18 @@ end_shutdown:
*/ */
EAPI Eina_Module *eina_module_new(const char *file) EAPI Eina_Module *eina_module_new(const char *file)
{ {
Eina_Module *m; Eina_Module *m;
EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL); EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
/* TODO check that the file exists. Update doc too */ /* TODO check that the file exists. Update doc too */
m = malloc(sizeof(Eina_Module)); m = malloc(sizeof(Eina_Module));
/* TODO add the magic */ /* TODO add the magic */
m->file = strdup(file); m->file = strdup(file);
m->ref = 0; m->ref = 0;
m->handle = NULL; m->handle = NULL;
return m; return m;
} }
/** /**
@ -291,16 +291,16 @@ EAPI Eina_Module *eina_module_new(const char *file)
*/ */
EAPI Eina_Bool eina_module_free(Eina_Module *m) EAPI Eina_Bool eina_module_free(Eina_Module *m)
{ {
EINA_SAFETY_ON_NULL_RETURN_VAL(m, EINA_FALSE); EINA_SAFETY_ON_NULL_RETURN_VAL(m, EINA_FALSE);
if (m->handle) if (m->handle)
{ {
if (eina_module_unload(m) == EINA_FALSE) if (eina_module_unload(m) == EINA_FALSE)
return EINA_FALSE; return EINA_FALSE;
} }
free(m->file); free(m->file);
free(m); free(m);
return EINA_TRUE; return EINA_TRUE;
} }
/** /**
@ -325,38 +325,38 @@ EAPI Eina_Bool eina_module_free(Eina_Module *m)
*/ */
EAPI Eina_Bool eina_module_load(Eina_Module *m) EAPI Eina_Bool eina_module_load(Eina_Module *m)
{ {
void *dl_handle; void *dl_handle;
Eina_Module_Init *initcall; Eina_Module_Init *initcall;
EINA_SAFETY_ON_NULL_RETURN_VAL(m, EINA_FALSE); EINA_SAFETY_ON_NULL_RETURN_VAL(m, EINA_FALSE);
if (m->handle) goto loaded; if (m->handle) goto loaded;
dl_handle = dlopen(m->file, RTLD_NOW); dl_handle = dlopen(m->file, RTLD_NOW);
if (!dl_handle) if (!dl_handle)
{ {
EINA_ERROR_PDBG("could not dlopen(\"%s\", RTLD_NOW): %s\n", EINA_ERROR_PDBG("could not dlopen(\"%s\", RTLD_NOW): %s\n",
m->file, dlerror()); m->file, dlerror());
eina_error_set(EINA_ERROR_WRONG_MODULE); eina_error_set(EINA_ERROR_WRONG_MODULE);
return EINA_FALSE;
}
initcall = dlsym(dl_handle, EINA_MODULE_SYMBOL_INIT);
if ((!initcall) || (!(*initcall)))
goto ok;
if ((*initcall)() == EINA_TRUE)
goto ok;
eina_error_set(EINA_ERROR_MODULE_INIT_FAILED);
dlclose(dl_handle);
return EINA_FALSE; return EINA_FALSE;
ok: }
m->handle = dl_handle;
loaded:
m->ref++;
eina_error_set(0); initcall = dlsym(dl_handle, EINA_MODULE_SYMBOL_INIT);
return EINA_TRUE; if ((!initcall) || (!(*initcall)))
goto ok;
if ((*initcall)() == EINA_TRUE)
goto ok;
eina_error_set(EINA_ERROR_MODULE_INIT_FAILED);
dlclose(dl_handle);
return EINA_FALSE;
ok:
m->handle = dl_handle;
loaded:
m->ref++;
eina_error_set(0);
return EINA_TRUE;
} }
/** /**
@ -375,20 +375,20 @@ loaded:
*/ */
EAPI Eina_Bool eina_module_unload(Eina_Module *m) EAPI Eina_Bool eina_module_unload(Eina_Module *m)
{ {
Eina_Module_Shutdown *shut; Eina_Module_Shutdown *shut;
EINA_SAFETY_ON_NULL_RETURN_VAL(m, EINA_FALSE); EINA_SAFETY_ON_NULL_RETURN_VAL(m, EINA_FALSE);
m->ref--; m->ref--;
if (!m->ref) if (!m->ref)
{ {
shut = dlsym(m->handle, EINA_MODULE_SYMBOL_SHUTDOWN); shut = dlsym(m->handle, EINA_MODULE_SYMBOL_SHUTDOWN);
if ((shut) && (*shut)) if ((shut) && (*shut))
(*shut)(); (*shut)();
dlclose(m->handle); dlclose(m->handle);
m->handle = NULL; m->handle = NULL;
return EINA_TRUE; return EINA_TRUE;
} }
return EINA_FALSE; return EINA_FALSE;
} }
/** /**
@ -405,9 +405,9 @@ EAPI Eina_Bool eina_module_unload(Eina_Module *m)
*/ */
EAPI void * eina_module_symbol_get(Eina_Module *m, const char *symbol) EAPI void * eina_module_symbol_get(Eina_Module *m, const char *symbol)
{ {
EINA_SAFETY_ON_NULL_RETURN_VAL(m, NULL); EINA_SAFETY_ON_NULL_RETURN_VAL(m, NULL);
EINA_SAFETY_ON_NULL_RETURN_VAL(m->handle, NULL); EINA_SAFETY_ON_NULL_RETURN_VAL(m->handle, NULL);
return dlsym(m->handle, symbol); return dlsym(m->handle, symbol);
} }
/** /**
@ -422,76 +422,76 @@ EAPI void * eina_module_symbol_get(Eina_Module *m, const char *symbol)
*/ */
EAPI const char * eina_module_file_get(Eina_Module *m) EAPI const char * eina_module_file_get(Eina_Module *m)
{ {
EINA_SAFETY_ON_NULL_RETURN_VAL(m, NULL); EINA_SAFETY_ON_NULL_RETURN_VAL(m, NULL);
return m->file; return m->file;
} }
EAPI char *eina_module_symbol_path_get(const void *symbol, const char *sub_dir) EAPI char *eina_module_symbol_path_get(const void *symbol, const char *sub_dir)
{ {
EINA_SAFETY_ON_NULL_RETURN_VAL(symbol, NULL); EINA_SAFETY_ON_NULL_RETURN_VAL(symbol, NULL);
#ifdef HAVE_DLADDR #ifdef HAVE_DLADDR
Dl_info eina_dl; Dl_info eina_dl;
if (dladdr(symbol, &eina_dl)) if (dladdr(symbol, &eina_dl))
{ {
if (strrchr(eina_dl.dli_fname, '/')) if (strrchr(eina_dl.dli_fname, '/'))
{ {
char *path; char *path;
int l0; int l0;
int l1; int l1;
int l2 = 0; int l2 = 0;
l0 = strlen(eina_dl.dli_fname); l0 = strlen(eina_dl.dli_fname);
l1 = strlen(strrchr(eina_dl.dli_fname, '/')); l1 = strlen(strrchr(eina_dl.dli_fname, '/'));
if (sub_dir && (*sub_dir != '\0')) if (sub_dir && (*sub_dir != '\0'))
l2 = strlen(sub_dir); l2 = strlen(sub_dir);
path = malloc(l0 - l1 + l2 + 1); path = malloc(l0 - l1 + l2 + 1);
if (path) if (path)
{ {
memcpy(path, eina_dl.dli_fname, l0 - l1); memcpy(path, eina_dl.dli_fname, l0 - l1);
if (sub_dir && (*sub_dir != '\0')) if (sub_dir && (*sub_dir != '\0'))
memcpy(path + l0 - l1, sub_dir, l2); memcpy(path + l0 - l1, sub_dir, l2);
path[l0 - l1 + l2] = '\0'; path[l0 - l1 + l2] = '\0';
return path; return path;
} }
} }
} }
#endif /* ! HAVE_DLADDR */ #endif /* ! HAVE_DLADDR */
return NULL; return NULL;
} }
EAPI char *eina_module_environment_path_get(const char *env, const char *sub_dir) EAPI char *eina_module_environment_path_get(const char *env, const char *sub_dir)
{ {
const char *env_dir; const char *env_dir;
EINA_SAFETY_ON_NULL_RETURN_VAL(env, NULL); EINA_SAFETY_ON_NULL_RETURN_VAL(env, NULL);
env_dir = getenv(env); env_dir = getenv(env);
if (env_dir) if (env_dir)
{ {
char *path; char *path;
size_t l1; size_t l1;
size_t l2 = 0; size_t l2 = 0;
l1 = strlen(env_dir); l1 = strlen(env_dir);
if (sub_dir && (*sub_dir != '\0')) if (sub_dir && (*sub_dir != '\0'))
l2 = strlen(sub_dir); l2 = strlen(sub_dir);
path = (char *)malloc(l1 + l2 + 1); path = (char *)malloc(l1 + l2 + 1);
if (path) if (path)
{ {
memcpy(path, env_dir, l1); memcpy(path, env_dir, l1);
if (sub_dir && (*sub_dir != '\0')) if (sub_dir && (*sub_dir != '\0'))
memcpy(path + l1, sub_dir, l2); memcpy(path + l1, sub_dir, l2);
path[l1 + l2] = '\0'; path[l1 + l2] = '\0';
return path; return path;
} }
} }
return NULL; return NULL;
} }
/** /**
@ -506,21 +506,21 @@ EAPI char *eina_module_environment_path_get(const char *env, const char *sub_dir
*/ */
EAPI Eina_Array * eina_module_list_get(Eina_Array *array, const char *path, unsigned int recursive, Eina_Module_Cb cb, void *data) EAPI Eina_Array * eina_module_list_get(Eina_Array *array, const char *path, unsigned int recursive, Eina_Module_Cb cb, void *data)
{ {
Dir_List_Get_Cb_Data list_get_cb_data; Dir_List_Get_Cb_Data list_get_cb_data;
Dir_List_Cb_Data list_cb_data; Dir_List_Cb_Data list_cb_data;
if (!path) return array; if (!path) return array;
list_get_cb_data.array = array ? array : eina_array_new(4); list_get_cb_data.array = array ? array : eina_array_new(4);
list_get_cb_data.cb = cb; list_get_cb_data.cb = cb;
list_get_cb_data.data = data; list_get_cb_data.data = data;
list_cb_data.cb = &_dir_list_get_cb; list_cb_data.cb = &_dir_list_get_cb;
list_cb_data.data = &list_get_cb_data; list_cb_data.data = &list_get_cb_data;
eina_file_dir_list(path, recursive, &_dir_list_cb, &list_cb_data); eina_file_dir_list(path, recursive, &_dir_list_cb, &list_cb_data);
return list_get_cb_data.array; return list_get_cb_data.array;
} }
/** /**
@ -529,14 +529,14 @@ EAPI Eina_Array * eina_module_list_get(Eina_Array *array, const char *path, unsi
*/ */
EAPI void eina_module_list_load(Eina_Array *array) EAPI void eina_module_list_load(Eina_Array *array)
{ {
Eina_Array_Iterator iterator; Eina_Array_Iterator iterator;
Eina_Module *m; Eina_Module *m;
unsigned int i; unsigned int i;
EINA_SAFETY_ON_NULL_RETURN(array); EINA_SAFETY_ON_NULL_RETURN(array);
EINA_ARRAY_ITER_NEXT(array, i, m, iterator) EINA_ARRAY_ITER_NEXT(array, i, m, iterator)
eina_module_load(m); eina_module_load(m);
} }
/** /**
@ -545,14 +545,14 @@ EAPI void eina_module_list_load(Eina_Array *array)
*/ */
EAPI void eina_module_list_unload(Eina_Array *array) EAPI void eina_module_list_unload(Eina_Array *array)
{ {
Eina_Array_Iterator iterator; Eina_Array_Iterator iterator;
Eina_Module *m; Eina_Module *m;
unsigned int i; unsigned int i;
EINA_SAFETY_ON_NULL_RETURN(array); EINA_SAFETY_ON_NULL_RETURN(array);
EINA_ARRAY_ITER_NEXT(array, i, m, iterator) EINA_ARRAY_ITER_NEXT(array, i, m, iterator)
eina_module_unload(m); eina_module_unload(m);
} }
/** /**
@ -561,16 +561,16 @@ EAPI void eina_module_list_unload(Eina_Array *array)
*/ */
EAPI void eina_module_list_flush(Eina_Array *array) EAPI void eina_module_list_flush(Eina_Array *array)
{ {
Eina_Array_Iterator iterator; Eina_Array_Iterator iterator;
Eina_Module *m; Eina_Module *m;
unsigned int i; unsigned int i;
EINA_SAFETY_ON_NULL_RETURN(array); EINA_SAFETY_ON_NULL_RETURN(array);
EINA_ARRAY_ITER_NEXT(array, i, m, iterator) EINA_ARRAY_ITER_NEXT(array, i, m, iterator)
eina_module_free(m); eina_module_free(m);
eina_array_flush(array); eina_array_flush(array);
} }
/** /**