From 409083e69d4bb9d8b1eb492b3474c86e093f2de8 Mon Sep 17 00:00:00 2001 From: xHire Date: Tue, 26 May 2009 00:44:42 +0200 Subject: Rewritten messages/comments in code of base Rectified the coding style in code of base --- src/base/modules.c | 96 +++++++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 44 deletions(-) (limited to 'src/base/modules.c') diff --git a/src/base/modules.c b/src/base/modules.c index 7b0b7c2..5e4e32e 100644 --- a/src/base/modules.c +++ b/src/base/modules.c @@ -1,10 +1,9 @@ - #include #include #include #ifndef __WIN32__ -# include -#endif +#include +#endif /* __WIN32__ */ #include #include "main.h" @@ -18,17 +17,17 @@ #include "shareFunction.h" #ifndef PUBLIC_SERVER -# include "interface.h" -# include "image.h" -# include "layer.h" -# include "configFile.h" -#endif +#include "interface.h" +#include "image.h" +#include "layer.h" +#include "configFile.h" +#endif /* PUBLIC_SERVER */ static export_fce_t export_fce = { #ifndef PUBLIC_SERVER .fce_addLayer = addLayer, .fce_image_get = image_get, -#endif +#endif /* PUBLIC_SERVER */ .fce_module_load_dep = module_load_dep, .fce_share_function_add = share_function_add, .fce_share_function_get = share_function_get, @@ -49,14 +48,14 @@ static export_fce_t export_fce = { .fce_proto_send_module_server = proto_send_module_server, #ifndef PUBLIC_SERVER .fce_proto_send_module_client = proto_send_module_client, -#endif +#endif /* PUBLIC_SERVER */ .fce_shot_destroy = shot_destroy, .fce_shot_bound_bombBall = shot_bound_bombBall, .fce_shot_transform_lasser = shot_transform_lasser }; static list_t *listModule; -static void *getFce(module_t * p, char *s) +static void *getFce(module_t *p, char *s) { #ifndef __WIN32__ void *ret; @@ -67,15 +66,16 @@ static void *getFce(module_t * p, char *s) ret = dlsym(p->image, s); if ((error = dlerror()) != NULL) { - fprintf(stderr, _("Error %s occured when using getFce function!\n"), error); + fprintf(stderr, _("[Error] Use of getFce function failed: %s\n"), error); return NULL; } -#else +#else /* __WIN32__ */ FARPROC ret = GetProcAddress((HMODULE) p->image, (LPCSTR) s); if (!ret) { - fprintf(stderr, _("Error %s occured when using getFce function!\n"), s); + fprintf(stderr, _("[Error] Use of getFce function failed: %s\n"), s); } -#endif +#endif /* __WIN32__ */ + return (void *) ret; } @@ -89,26 +89,26 @@ static void *mapImage(char *name) fputs(dlerror(), stderr); return NULL; } -#else +#else /* __WIN32__ */ HINSTANCE image; image = LoadLibrary((LPCSTR) name); if (!image) { LPVOID msg; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) & msg, 0, NULL); + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) & msg, 0, NULL); fputs(msg, stderr); free(msg); FreeLibrary(image); return NULL; } - //FreeLibrary(image); //never ever untag this -#endif + /*FreeLibrary(image);*/ /* never ever uncomment this */ +#endif /* __WIN32__ */ return image; } @@ -116,20 +116,20 @@ static void unmapImage(void *image) { #ifndef __WIN32__ dlclose(image); -#else +#else /* __WIN32__ */ FreeLibrary(image); -#endif +#endif /* __WIN32__ */ } static void setModulePath(char *name, char *path) { - sprintf(path, PATH_MODULES "%s" MODULE_TYPE_UNIX, name); // linux + sprintf(path, PATH_MODULES "%s" MODULE_TYPE_UNIX, name); /* GNU/Linux */ #ifdef __WIN32__ - sprintf(path, PATH_MODULES "%s" MODULE_TYPE_WIN, name); // windows -#endif + sprintf(path, PATH_MODULES "%s" MODULE_TYPE_WIN, name); /* MS Windows */ +#endif /* __WIN32__ */ #ifdef APPLE - sprintf(path, PATH_MODULES "%s" MODULE_TYPE_APPLE, name); // apple -#endif + sprintf(path, PATH_MODULES "%s" MODULE_TYPE_APPLE, name); /* Apple */ +#endif /* APPLE */ } static module_t *newModule(char *name) @@ -143,7 +143,7 @@ static module_t *newModule(char *name) image = mapImage(path); if (image == NULL) { - fprintf(stderr, _("Unable to map file %s!\n"), name); + fprintf(stderr, _("[Error] Unable to map image of new module [%s]\n"), name); return NULL; } @@ -153,17 +153,17 @@ static module_t *newModule(char *name) ret->fce_init = getFce(ret, "init"); #ifndef PUBLIC_SERVER ret->fce_draw = getFce(ret, "draw"); -#endif +#endif /* PUBLIC_SERVER */ ret->fce_event = getFce(ret, "event"); ret->fce_destroy = getFce(ret, "destroy"); ret->fce_isConflict = getFce(ret, "isConflict"); ret->fce_cmd = getFce(ret, "cmdArena"); ret->fce_recvMsg = getFce(ret, "recvMsg"); - DEBUG_MSG(_("Loading module: \"%s\"\n"), name); + DEBUG_MSG(_("[Debug] Loading module [%s]\n"), name); if (ret->fce_init(&export_fce) != 0) { - fprintf(stderr, _("Failed initialization of module \"%s\""), name); + fprintf(stderr, _("[Error] Unable to load module [%s]\n"), name); unmapImage(image); free(ret->name); free(ret); @@ -173,16 +173,17 @@ static module_t *newModule(char *name) return ret; } -static int destroyModule(module_t * p) +static int destroyModule(module_t *p) { assert(p != NULL); + + DEBUG_MSG(_("[Debug] Unloading module [%s]\n"), p->name); + p->fce_destroy(); unmapImage(p->image); free(p->name); free(p); - DEBUG_MSG(_("Destroing module...\n")); - return 0; } @@ -201,9 +202,11 @@ int isModuleLoaded(char *name) this = (module_t *) listModule->list[i]; - if (strcmp(this->name, name) == 0) + if (strcmp(this->name, name) == 0) { return 1; + } } + return 0; } @@ -212,25 +215,27 @@ int module_load(char *name) module_t *module; if (isModuleLoaded(name)) { - fprintf(stderr, ("I've done this once, dont want to mess memory with module %s again!\n"), name); + fprintf(stderr, ("[Error] Unable to load already loaded module [%s]\n"), name); return -1; } module = newModule(name); if (module == NULL) { - fprintf(stderr, _("Loading module %s failed!\n"), name); + fprintf(stderr, _("[Error] Unable to load module [%s]\n"), name); return -1; } list_add(listModule, module); + return 0; } int module_load_dep(char *name) { - if (isModuleLoaded(name)) + if (isModuleLoaded(name)) { return 0; + } return module_load(name); } @@ -259,7 +264,7 @@ void module_draw(int x, int y, int w, int h) this->fce_draw(x, y, w, h); } } -#endif +#endif /* PUBLIC_SERVER */ void module_event() { @@ -282,9 +287,11 @@ int module_is_conflict(int x, int y, int w, int h) this = (module_t *) listModule->list[i]; - if (this->fce_isConflict(x, y, w, h) == 1) + if (this->fce_isConflict(x, y, w, h) == 1) { return 1; + } } + return 0; } @@ -298,6 +305,7 @@ int module_recv_msg(char *msg) this = (module_t *) listModule->list[i]; this->fce_recvMsg(msg); } + return 0; } -- cgit v1.2.3