From: Rick L Bird Date: Tue, 10 May 2011 10:17:02 +0000 (-0400) Subject: Ran indent on modules.c X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=c44a2035157adeb98f7e67eddaf09dd653944b14;p=cobramush.git Ran indent on modules.c --- diff --git a/hdrs/modules.h b/hdrs/modules.h index f678af3..d6715dd 100644 --- a/hdrs/modules.h +++ b/hdrs/modules.h @@ -89,8 +89,8 @@ void CHooks_Init (); /* Initialize the Core Hook interface */ struct core_hook_t *CHook_Create (const char *key, int flags); /* Create a CHook */ struct core_entry_t *CHook_Insert (const char *key, char priority, int flags, void *data); /* inserts an individual piece of data in hook table */ int CHook_Delete(struct core_entry_t *entry); -int CHook_Run (struct core_entry_t *entry, char *format, ...); /* Given a chook entry executes it however it suppose to be executed.. */ -int CHook_SC(struct core_entry_t *entry, char *format, va_list args); /* Execution function to run SC associated with a hook */ +int CHook_Run (struct core_entry_t *entry, const char *format, ...); /* Given a chook entry executes it however it suppose to be executed.. */ +int CHook_SC(struct core_entry_t *entry, const char *format, va_list args); /* Execution function to run SC associated with a hook */ int CHook_Insert_Module(char *key, char priority, struct module_hook *hook); /* Insert a module hook */ /* Iterate through Module List */ diff --git a/src/modules.c b/src/modules.c index 6a0581f..529a4f1 100644 --- a/src/modules.c +++ b/src/modules.c @@ -25,20 +25,20 @@ struct module_entry_t *module_list = NULL; HASHTAB chook_htab; -HASHTAB chook_mevents; /* MUSH Events aliased to Hooks */ +HASHTAB chook_mevents; /* MUSH Events aliased to Hooks */ extern sig_atomic_t cpu_time_limit_hit; /**< Have we used too much CPU? */ struct chook_table_t chook_tab[] = { /* Key, MUSH Event Name(or NULL if not), flags */ - {"DUMP_5MIN.AROUND", "DUMP_5MIN", MODHOOK_AROUND}, /* Overrides the default 5min message */ - {"DUMP_1MIN.AROUND", "DUMP_1MIN", MODHOOK_AROUND}, /* Overrides teh default 1min message */ + {"DUMP_5MIN.AROUND", "DUMP_5MIN", MODHOOK_AROUND}, /* Overrides the default 5min message */ + {"DUMP_1MIN.AROUND", "DUMP_1MIN", MODHOOK_AROUND}, /* Overrides teh default 1min message */ {"PCREATE.AROUND", NULL, MODHOOK_AROUND}, {"PCREATE.BEFORE", NULL, MODHOOK_BEFORE}, {"PCREATE.AFTER", "PCREATE", MODHOOK_AFTER}, - {"LOG_ALL.AFTER", "LOG_ALL", MODHOOK_AFTER}, + {"LOG_ALL.AFTER", "LOG_ALL", MODHOOK_AFTER}, {"OBJECT_CREATE.AROUND", NULL, MODHOOK_AROUND | MODHOOK_INTRET}, - {"OBJECT_CREATE.BEFORE", NULL, MODHOOK_BEFORE | MODHOOK_INTRET }, + {"OBJECT_CREATE.BEFORE", NULL, MODHOOK_BEFORE | MODHOOK_INTRET}, {"OBJECT_CREATE.AFTER", "OBJECT_CREATE", MODHOOK_AFTER | MODHOOK_NONE}, {"OBJECT_DESTROY.AFTER", "OBJECT_DESTROY", MODHOOK_AFTER | MODHOOK_NONE}, {"OBJECT_MOVE.BEFORE", NULL, MODHOOK_BEFORE | MODHOOK_INTRET}, @@ -48,7 +48,7 @@ struct chook_table_t chook_tab[] = { {"PLAYER_DISCONNECT.AROUND", NULL, MODHOOK_AROUND}, {"PLAYER_DISCONNECT.BEFORE", NULL, MODHOOK_BEFORE | MODHOOK_INTRET}, {"PLAYER_DISCONNECT.AFTER", "PLAYER_DISCONNECT", MODHOOK_AFTER}, - {"PLAYER_IDLEOUT", "PLAYER_IDLEOUT", MODHOOK_AFTER}, /* Run after a player idles out */ + {"PLAYER_IDLEOUT", "PLAYER_IDLEOUT", MODHOOK_AFTER}, /* Run after a player idles out */ {"SOCKET_CONNECT.AFTER", "SOCKET_CONNECT", MODHOOK_AFTER}, {"SOCKET_DISCONNECT.AFTER", "SOCKET_DISCONNECT", MODHOOK_AFTER}, {"SOCKET_LOGINFAIL.AFTER", "SOCKET_LOGINFAIL", MODHOOK_AFTER}, @@ -57,114 +57,128 @@ struct chook_table_t chook_tab[] = { {NULL, NULL, MODHOOK_NONE} }; -void CHooks_Init() { +void +CHooks_Init() +{ int i, sz; /* Figure out size */ - for(i = 0 ;chook_tab[i].key != NULL; i++) - ; + for (i = 0; chook_tab[i].key != NULL; i++); hashinit(&chook_htab, i); /* Initialize Chook Hashtab */ - for(i = 0; chook_tab[i].key != NULL; i++) + for (i = 0; chook_tab[i].key != NULL; i++) CHook_Create(chook_tab[i].key, chook_tab[i].flags); /* Setup the MUSH Event aliases to our actual Hooks */ - for(sz = i = 0 ;chook_tab[i].key != NULL; i++) - if(chook_tab[i].mush_key != NULL) + for (sz = i = 0; chook_tab[i].key != NULL; i++) + if (chook_tab[i].mush_key != NULL) sz++; hashinit(&chook_mevents, sz); - for(sz = i = 0 ;chook_tab[i].key != NULL; i++) - if(chook_tab[i].mush_key != NULL) - hashadd( chook_tab[i].mush_key, (void *)chook_tab[i].key, &chook_mevents); + for (sz = i = 0; chook_tab[i].key != NULL; i++) + if (chook_tab[i].mush_key != NULL) + hashadd(chook_tab[i].mush_key, (void *) chook_tab[i].key, + &chook_mevents); } -struct core_hook_t *CHook_Create(const char *key, int flags) { +struct core_hook_t * +CHook_Create(const char *key, int flags) +{ struct core_hook_t *chook; /* check to see if we need to create it */ - if((chook = (struct core_hook_t *) hashfind(key, &chook_htab))) { + if ((chook = (struct core_hook_t *) hashfind(key, &chook_htab))) { /* It already exists.. just return this one */ return chook; - } - + } + /* First Create our struct */ - chook = mush_malloc(sizeof(struct core_hook_t), "CORE_HOOK.PARENT"); - - if(!chook) + chook = mush_malloc(sizeof(struct core_hook_t), "CORE_HOOK.PARENT"); + + if (!chook) mush_panic("Out of memory!"); /* Initialize data */ chook->key = mush_strdup(strupper(key), "CORE_HOOK.KEY"); chook->flags = flags; - chook->hooks = NULL; /* Initialized as having no children */ + chook->hooks = NULL; /* Initialized as having no children */ /* Add to the hashtab */ hashadd(key, chook, &chook_htab); return chook; } -struct core_entry_t *CHook_Insert (const char *key, char priority, int flags, void *data) { - struct core_hook_t *parent; - struct core_entry_t *new_child, *cur_child; - - /* Ok first look for the htab entry */ - parent = hashfind(key, &chook_htab); - - if(!parent) /* It doesn't exist, return NULL */ - return NULL; - - /* It does exist lets allocate some information for this entry */ - new_child = mush_malloc(sizeof(struct core_entry_t), "CORE_HOOK.CHILD"); - - if(!new_child) - mush_panic("Out of memory!"); - /* Now go ahead, give it priority, flags & data */ - new_child->priority = priority; - new_child->flags = flags; - new_child->data = data; - new_child->up = parent; - new_child->next = NULL; - new_child->prev = NULL; - - /* Find a place before it within the parent */ - if(parent->hooks == NULL) { /* simple. set it and return */ - parent->hooks = new_child; - return new_child; - } - - for(cur_child = parent->hooks ; cur_child != NULL; cur_child = cur_child->next) - if(cur_child->priority < priority) - break; - else if(cur_child->next == NULL) { - /* We're going at the end of the list */ - new_child->prev = cur_child; - cur_child->next = new_child; - return new_child; - } - - /* Place us in prev */ - cur_child->prev->next = new_child; - new_child->next = cur_child; - new_child->prev = cur_child->prev; - cur_child->prev = new_child; - return new_child; +struct core_entry_t * +CHook_Insert(const char *key, char priority, int flags, void *data) +{ + struct core_hook_t *parent; + struct core_entry_t *new_child, *cur_child; + + /* Ok first look for the htab entry */ + parent = hashfind(key, &chook_htab); + + if (!parent) /* It doesn't exist, return NULL */ + return NULL; + + /* It does exist lets allocate some information for this entry */ + new_child = mush_malloc(sizeof(struct core_entry_t), "CORE_HOOK.CHILD"); + + if (!new_child) + mush_panic("Out of memory!"); + /* Now go ahead, give it priority, flags & data */ + new_child->priority = priority; + new_child->flags = flags; + new_child->data = data; + new_child->up = parent; + new_child->next = NULL; + new_child->prev = NULL; + + /* Find a place before it within the parent */ + if (parent->hooks == NULL) { /* simple. set it and return */ + parent->hooks = new_child; + return new_child; } + for (cur_child = parent->hooks; cur_child != NULL; + cur_child = cur_child->next) + if (cur_child->priority < priority) + break; + else if (cur_child->next == NULL) { + /* We're going at the end of the list */ + new_child->prev = cur_child; + cur_child->next = new_child; + return new_child; + } + + /* Place us in prev */ + cur_child->prev->next = new_child; + new_child->next = cur_child; + new_child->prev = cur_child->prev; + cur_child->prev = new_child; + return new_child; +} + /* Create SC event associated with 'key' */ -int CHook_Insert_SC(char *key, dbref object, char *attribute) { +int +CHook_Insert_SC(char *key, dbref object, char *attribute) +{ struct core_entry_t *entry; struct softcode_hook *softcode_block; - if(!GoodObject(object)) + if (!GoodObject(object)) return 0; - softcode_block = (struct softcode_hook *) mush_malloc(sizeof(struct softcode_hook), "CHOOK.SOFTCODE_BLOCK"); + softcode_block = + (struct softcode_hook *) mush_malloc(sizeof(struct softcode_hook), + "CHOOK.SOFTCODE_BLOCK"); softcode_block->obj = object; memset(softcode_block->attribute, '\0', ATTRIBUTE_NAME_LIMIT); - strncpy(softcode_block->attribute, strupper(attribute), ATTRIBUTE_NAME_LIMIT-1); + strncpy(softcode_block->attribute, strupper(attribute), + ATTRIBUTE_NAME_LIMIT - 1); - entry = CHook_Insert(key, MODHOOK_PRI_SC, MODHOOK_SOFTCODE, (void *) softcode_block); - if(!entry) { + entry = + CHook_Insert(key, MODHOOK_PRI_SC, MODHOOK_SOFTCODE, + (void *) softcode_block); + if (!entry) { /* Free the softcode block we created */ mush_free(softcode_block, "CHOOK.SOFTCODE_BLOCK"); return 0; @@ -174,14 +188,19 @@ int CHook_Insert_SC(char *key, dbref object, char *attribute) { } /* Insert a hook for a module for the key */ -int CHook_Insert_Module(char *key __attribute__ ((__unused__)), char priority __attribute__ ((__unused__)), struct module_hook *hook __attribute__ ((__unused__))) { +int +CHook_Insert_Module(char *key __attribute__ ((__unused__)), char priority + __attribute__ ((__unused__)), struct module_hook *hook + __attribute__ ((__unused__))) +{ return 0; } /* arg_left -> key * arg_right -> obj/attribute */ -COMMAND(cmd_event) { +COMMAND(cmd_event) +{ dbref thing; char *key; char *s; @@ -189,44 +208,46 @@ COMMAND(cmd_event) { s = strchr(arg_right, '/'); *s++ = '\0'; - if(!s) { + if (!s) { notify(player, "Bad Event format"); return; } thing = match_thing(player, arg_right); - if(!GoodObject(thing)) + if (!GoodObject(thing)) return; /* Look for event */ - if(!(key = (char *) hashfind(arg_left, &chook_mevents))) { + if (!(key = (char *) hashfind(arg_left, &chook_mevents))) { notify(player, "No such event."); return; } - if(!CHook_Insert_SC(key, thing, s)) { + if (!CHook_Insert_SC(key, thing, s)) { /* This shouldn't happen.. */ notify(player, "ERROR: Could not add event."); return; } notify(player, "Event added."); - + } /* Give a hook parent, delete the child from its linked list */ -int CHook_Delete(struct core_entry_t *entry) { +int +CHook_Delete(struct core_entry_t *entry) +{ - if(!entry) + if (!entry) return 0; /* Detach from list */ - if(entry->next == NULL && entry->up->hooks == entry) { + if (entry->next == NULL && entry->up->hooks == entry) { /* Quick one */ entry->up->hooks = NULL; goto free_chook_child; - } else if(entry->prev) + } else if (entry->prev) entry->prev->next = entry->next; - else if(entry->up) /* We're rooted from the parent.. deal with that situation */ + else if (entry->up) /* We're rooted from the parent.. deal with that situation */ entry->up->hooks = entry->next; - if(entry->next) + if (entry->next) entry->next->prev = entry->prev; free_chook_child: /* Free entry */ @@ -235,17 +256,19 @@ free_chook_child: return 1; } -int CHook_Run(struct core_entry_t *entry, char *format, ...) { +int +CHook_Run(struct core_entry_t *entry, const char *format, ...) +{ va_list argp; int rval; - int (*module_func)(struct core_entry_t *entry, va_list argp); + int (*module_func) (struct core_entry_t * entry, va_list argp); - module_func = NULL; /* Just for initialization purposes */ + module_func = NULL; /* Just for initialization purposes */ va_start(argp, format); - if(entry->flags & MODHOOK_SOFTCODE) { - rval = CHook_SC(entry, format, argp); - va_end(argp); - } else if(entry->flags & MODHOOK_MODULE) { + if (entry->flags & MODHOOK_SOFTCODE) { + rval = CHook_SC(entry, format, argp); + va_end(argp); + } else if (entry->flags & MODHOOK_MODULE) { /* We'll do this code later */ va_end(argp); return -1; @@ -259,7 +282,9 @@ int CHook_Run(struct core_entry_t *entry, char *format, ...) { } -int CHook_SC(struct core_entry_t *entry, char *format, va_list arguments) { +int +CHook_SC(struct core_entry_t *entry, const char *format, va_list arguments) +{ /* Register Saving */ char *preserve_wnxt[10], *preserve_rnxt[NUMQ]; char *val_wnxt[10], *val_rnxt[NUMQ]; @@ -267,78 +292,81 @@ int CHook_SC(struct core_entry_t *entry, char *format, va_list arguments) { HASHTAB preserve_namedregs; /* */ struct softcode_hook *sc_hook; - const char *s; + const char *s, *fptr; char cmd_buf[BUFFER_LEN], tbuf[BUFFER_LEN]; - char *fptr, *r; + char *r; char next = 0; ATTR *atr; - dbref enactor, cause,executor; + dbref enactor, cause, executor; dbref local_ooref; int break_count, spot = 0; - + sc_hook = (struct softcode_hook *) entry->data; /* Before we bother with va_list .. Make sure A) Its a good object, B) Its a good attribute */ - if(!GoodObject(sc_hook->obj)) + if (!GoodObject(sc_hook->obj)) return -1; atr = atr_get(sc_hook->obj, sc_hook->attribute); - if(!atr) + if (!atr) return -1; /* Save Environment */ - save_global_nxt("chook_sc_save", preserve_wnxt, preserve_rnxt, val_wnxt, val_rnxt); + save_global_nxt("chook_sc_save", preserve_wnxt, preserve_rnxt, val_wnxt, + val_rnxt); save_global_regs("chook_sc_save", preserveq); save_global_env("chook_sc_save", preserves); init_namedregs(&preserve_namedregs); copy_namedregs(&preserve_namedregs, &global_eval_context.namedregs); clear_namedregs(&global_eval_context.namedregs); - enactor = executor = cause = sc_hook->obj; + enactor = executor = cause = sc_hook->obj; - /* Ok.. Now that we haev all the info we need we need to build a parse_que with 0-10 being the args passed */ - for(fptr = format; fptr && *fptr ; fptr++) { + /* Ok.. Now that we haev all the info we need we need to build a parse_que with 0-10 being the args passed */ + for (fptr = format; fptr && *fptr; fptr++) { /* Look for the '%' symbol.. Thats are argument starting processor */ - if(*fptr != '%' && !next) + if (*fptr != '%' && !next) continue; - if(!next) { /* we caught % */ + if (!next) { /* we caught % */ next = 1; continue; } - switch(*fptr) { - case '@': /* The cause */ - cause = (dbref) va_arg(arguments, dbref); - next = 0; - break; - case '#': /* This should set the enactor */ - enactor = (dbref) va_arg(arguments, dbref); - next = 0; - break; - case 'D': - case 'd': - global_eval_context.wenv[spot++] = unparse_integer(va_arg(arguments, intmax_t)); - next = 0; - break; - case 'S': - case 's': - global_eval_context.wenv[spot++] = va_arg(arguments, char *); - next = 0; - break; - case ' ': /* this shouldn't happen.. but just in case */ - break; - default: - /* Bad Format.. don't run & return an error */ - do_rawlog(LT_ERR, "%s:%d -> Unexpected format character '%c' in format \"%s\"", __FILE__, __LINE__, *fptr, format); - /* Restore Environment */ - copy_namedregs(&global_eval_context.namedregs, &preserve_namedregs); - free_namedregs(&preserve_namedregs); - restore_global_regs("chook_sc_save", preserveq); - restore_global_env("chook_sc_save", preserves); - restore_global_nxt("chook_sc_save", preserve_wnxt, preserve_rnxt, - val_wnxt, val_rnxt); - - return -2; + switch (*fptr) { + case '@': /* The cause */ + cause = (dbref) va_arg(arguments, dbref); + next = 0; + break; + case '#': /* This should set the enactor */ + enactor = (dbref) va_arg(arguments, dbref); + next = 0; + break; + case 'D': + case 'd': + global_eval_context.wenv[spot++] = + unparse_integer(va_arg(arguments, intmax_t)); + next = 0; + break; + case 'S': + case 's': + global_eval_context.wenv[spot++] = va_arg(arguments, char *); + next = 0; + break; + case ' ': /* this shouldn't happen.. but just in case */ + break; + default: + /* Bad Format.. don't run & return an error */ + do_rawlog(LT_ERR, + "%s:%d -> Unexpected format character '%c' in format \"%s\"", + __FILE__, __LINE__, *fptr, format); + /* Restore Environment */ + copy_namedregs(&global_eval_context.namedregs, &preserve_namedregs); + free_namedregs(&preserve_namedregs); + restore_global_regs("chook_sc_save", preserveq); + restore_global_env("chook_sc_save", preserves); + restore_global_nxt("chook_sc_save", preserve_wnxt, preserve_rnxt, + val_wnxt, val_rnxt); + + return -2; } } - strncpy(cmd_buf, atr_value(atr), BUFFER_LEN-1); - /* FIXME: Make immediate parse execution.. And alter the cause/enactor appropriately.. parse_que doesn't give us that flexibility */ + strncpy(cmd_buf, atr_value(atr), BUFFER_LEN - 1); s = cmd_buf; global_eval_context.process_command_port = 0; *(global_eval_context.break_replace) = '\0'; @@ -346,35 +374,33 @@ int CHook_SC(struct core_entry_t *entry, char *format, va_list arguments) { break_count = 100; start_cpu_timer(); while (!cpu_time_limit_hit && *s) { - r = cmd_buf; - local_ooref = ooref; - ooref = atr->creator; - process_expression(cmd_buf, &r, &s, - executor, enactor, cause, PE_NOTHING, PT_SEMI, - NULL); - *r = '\0'; - if (*s == ';') - s++; - strcpy(tbuf, cmd_buf); - process_command(executor, tbuf, enactor, - cause, 0); - if (global_eval_context.break_called) { - global_eval_context.break_called = 0; - s = global_eval_context.break_replace; - if (!*global_eval_context.break_replace) { - ooref = local_ooref; - break; - } - break_count--; - if (!break_count) { - notify(global_eval_context.cplr, - T("@break recursion exceeded.")); - ooref = local_ooref; - break; - } - } - ooref = local_ooref; - } + r = cmd_buf; + local_ooref = ooref; + ooref = atr->creator; + process_expression(cmd_buf, &r, &s, + executor, enactor, cause, PE_NOTHING, PT_SEMI, + NULL); + *r = '\0'; + if (*s == ';') + s++; + strcpy(tbuf, cmd_buf); + process_command(executor, tbuf, enactor, cause, 0); + if (global_eval_context.break_called) { + global_eval_context.break_called = 0; + s = global_eval_context.break_replace; + if (!*global_eval_context.break_replace) { + ooref = local_ooref; + break; + } + break_count--; + if (!break_count) { + notify(global_eval_context.cplr, T("@break recursion exceeded.")); + ooref = local_ooref; + break; + } + } + ooref = local_ooref; + } reset_cpu_timer(); /* Restore Environment */ copy_namedregs(&global_eval_context.namedregs, &preserve_namedregs); @@ -382,7 +408,7 @@ int CHook_SC(struct core_entry_t *entry, char *format, va_list arguments) { restore_global_regs("chook_sc_save", preserveq); restore_global_env("chook_sc_save", preserves); restore_global_nxt("chook_sc_save", preserve_wnxt, preserve_rnxt, - val_wnxt, val_rnxt); + val_wnxt, val_rnxt); return 1; } @@ -392,12 +418,16 @@ int CHook_SC(struct core_entry_t *entry, char *format, va_list arguments) { /* Ads a module entry and returns */ -struct module_entry_t *module_entry_add(char *name) { +struct module_entry_t * +module_entry_add(char *name) +{ struct module_entry_t *entry; - entry = (struct module_entry_t *) mush_malloc(sizeof(struct module_entry_t), "MODULE_ENTRY"); + entry = + (struct module_entry_t *) mush_malloc(sizeof(struct module_entry_t), + "MODULE_ENTRY"); - if(!entry) + if (!entry) mush_panic("Could not allocate MODULE_ENTRY"); entry->name = mush_strdup(name, "MODULE_ENTRY.NAME"); @@ -411,24 +441,27 @@ struct module_entry_t *module_entry_add(char *name) { } /* removes a module entry from the list */ -int module_entry_del(struct module_entry_t *entry) { +int +module_entry_del(struct module_entry_t *entry) +{ struct module_entry_t *m, *e = NULL; - if(module_list == entry) { + if (module_list == entry) { e = module_list; module_list = NULL; } - else MODULE_ITER(m) - if(m->next != NULL && m->next == entry) { - e = m; - m->next = m->next->next; - break; - } + else + MODULE_ITER(m) + if (m->next != NULL && m->next == entry) { + e = m; + m->next = m->next->next; + break; + } - if(e == NULL) + if (e == NULL) return 0; - + MODULE_CAF(e->name, "MODULE_ENTRY.NAME"); MODULE_CAF(e->info, "MODULE_ENTRY.INFO"); MODULE_CAF(e, "MODULE_ENTRY"); @@ -437,14 +470,18 @@ int module_entry_del(struct module_entry_t *entry) { } /* Initialize Module Interface */ -int modules_init() { - return lt_dlinit(); /* Initialize libltdl. 0 is good */ +int +modules_init() +{ + return lt_dlinit(); /* Initialize libltdl. 0 is good */ } /* Load Module name */ -int module_open(char *path, char *name) { +int +module_open(char *path, char *name) +{ char file[BUFFER_LEN]; - int (*module_loader)(struct module_entry_t *); + int (*module_loader) (struct module_entry_t *); struct module_entry_t *module; void *handle; @@ -453,52 +490,59 @@ int module_open(char *path, char *name) { handle = lt_dlopen(file); - if(!handle) { - do_rawlog(LT_ERR, "Error Loading Module: %s | %s ", file, lt_dlerror()); + if (!handle) { + do_rawlog(LT_ERR, "Error Loading Module: %s | %s ", file, + lt_dlerror()); return 0; } /* Some OSes may need symbols to be prefixed with _.. Will need to look into autoconfig code for this */ MODULE_FUNCPTR(module_loader, handle, "module_load"); - if(!module_loader) { - do_rawlog(LT_ERR, "Error Loading Module: Could not call module_load | %s", file); + if (!module_loader) { + do_rawlog(LT_ERR, + "Error Loading Module: Could not call module_load | %s", + file); return 0; } /* Add the module to the linked list */ module = module_entry_add(name); - if(module == NULL) { + if (module == NULL) { return 0; } module->handle = handle; module->load = module_loader; MODULE_FUNCPTR(module->unload, handle, "module_unload"); - + /* Grab info and version from module & put it in */ /* Success.. Call the module */ return module_loader(module); } /* Unload one Module */ -int module_close(struct module_entry_t *m) { +int +module_close(struct module_entry_t *m) +{ int ret; - ret = m->unload(m); /* first run requierd unload code */ - - if(!ret) + ret = m->unload(m); /* first run requierd unload code */ + + if (!ret) return 0; /* next unload the modules for real */ ret = lt_dlclose(m->handle); - if(ret != 0) { - do_rawlog(LT_ERR, "Could not unload module: %s/%d | %s", __FILE__, __LINE__, lt_dlerror()); + if (ret != 0) { + do_rawlog(LT_ERR, "Could not unload module: %s/%d | %s", __FILE__, + __LINE__, lt_dlerror()); return 0; } - if(!module_entry_del(m)) { - do_rawlog(LT_ERR, "Could not unload module: %s/%d ", __FILE__, __LINE__); + if (!module_entry_del(m)) { + do_rawlog(LT_ERR, "Could not unload module: %s/%d ", __FILE__, + __LINE__); return 0; } @@ -506,60 +550,61 @@ int module_close(struct module_entry_t *m) { } /* Unload all modules */ -int modules_shutdown() { +int +modules_shutdown() +{ struct module_entry_t *m; MODULE_ITER(m) - m->unload(m); + m->unload(m); - return lt_dlexit(); /* 0 is good */ + return lt_dlexit(); /* 0 is good */ } /* MUSH Module Interface Portion... Much of this section will probably actually move to a module itself and become a resident module */ /* command will be restricted to Director player in nature from the command file */ -COMMAND(cmd_module) { +COMMAND(cmd_module) +{ struct module_entry_t *m; char tbuf1[BUFFER_LEN]; int ret; - if(SW_ISSET(sw, SWITCH_LOAD)) { - if(!arg_left) { + if (SW_ISSET(sw, SWITCH_LOAD)) { + if (!arg_left) { notify(player, "Requires at least one argument."); return; } /* Load a Module By name in arg_left */ (void) getcwd(tbuf1, BUFFER_LEN); ret = module_open(tbuf1, arg_left); - if(ret) + if (ret) notify(player, "module successfully loaded."); else notify(player, "module could not load."); - } else if(module_list == NULL) { + } else if (module_list == NULL) { notify_format(player, "Search-path: %s", lt_dlgetsearchpath()); notify(player, "No modules loaded."); return; - } else if(SW_ISSET(sw, SWITCH_UNLOAD)) { + } else if (SW_ISSET(sw, SWITCH_UNLOAD)) { /* This is after the no modules loaded one.. because you have to modules loaded in order to unload something */ - if(!arg_left) { + if (!arg_left) { notify(player, "Reqiures at least one argument."); return; } MODULE_ITER(m) - if(!strcasecmp(arg_left, m->name)) { - if(module_close(m)) - notify(player, "unloaded module"); - else - notify(player, "could not unload module"); - return; - } + if (!strcasecmp(arg_left, m->name)) { + if (module_close(m)) + notify(player, "unloaded module"); + else + notify(player, "could not unload module"); + return; + } } else { - /* No Switches.. Just view modules loaded */ - MODULE_ITER(m) { - notify_format(player, "Module-Name: %s", m->name); - } + /* No Switches.. Just view modules loaded */ + MODULE_ITER(m) { + notify_format(player, "Module-Name: %s", m->name); + } } } - -