diff options
Diffstat (limited to 'src/map/npc_chat.c')
-rw-r--r-- | src/map/npc_chat.c | 66 |
1 files changed, 44 insertions, 22 deletions
diff --git a/src/map/npc_chat.c b/src/map/npc_chat.c index 6726c65a9..0ca84cff4 100644 --- a/src/map/npc_chat.c +++ b/src/map/npc_chat.c @@ -2,8 +2,8 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team - * Copyright (C) Athena Dev Teams + * Copyright (C) 2012-2020 Hercules Dev Team + * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,8 +40,8 @@ /** * interface sources **/ -struct npc_chat_interface npc_chat_s; -struct pcre_interface libpcre_s; +static struct npc_chat_interface npc_chat_s; +static struct pcre_interface libpcre_s; struct npc_chat_interface *npc_chat; struct pcre_interface *libpcre; @@ -98,8 +98,9 @@ struct pcre_interface *libpcre; * * This does NOT do the list management */ -void finalize_pcrematch_entry(struct pcrematch_entry* e) +static void finalize_pcrematch_entry(struct pcrematch_entry *e) { + nullpo_retv(e); libpcre->free(e->pcre_); libpcre->free(e->pcre_extra_); aFree(e->pattern); @@ -109,9 +110,13 @@ void finalize_pcrematch_entry(struct pcrematch_entry* e) /** * Lookup (and possibly create) a new set of patterns by the set id */ -struct pcrematch_set* lookup_pcreset(struct npc_data* nd, int setid) { +static struct pcrematch_set *lookup_pcreset(struct npc_data *nd, int setid) +{ struct pcrematch_set *pcreset; - struct npc_parse *npcParse = nd->chatdb; + struct npc_parse *npcParse; + + nullpo_retr(NULL, nd); + npcParse = nd->chatdb; if (npcParse == NULL) nd->chatdb = npcParse = (struct npc_parse *)aCalloc(sizeof(struct npc_parse), 1); @@ -148,10 +153,12 @@ struct pcrematch_set* lookup_pcreset(struct npc_data* nd, int setid) { * * if the setid does not exist, this will silently return */ -void activate_pcreset(struct npc_data* nd, int setid) +static void activate_pcreset(struct npc_data *nd, int setid) { struct pcrematch_set *pcreset; - struct npc_parse *npcParse = nd->chatdb; + struct npc_parse *npcParse; + nullpo_retv(nd); + npcParse = nd->chatdb; if (npcParse == NULL) return; // Nothing to activate... pcreset = npcParse->inactive; @@ -181,10 +188,12 @@ void activate_pcreset(struct npc_data* nd, int setid) * * if the setid does not exist, this will silently return */ -void deactivate_pcreset(struct npc_data* nd, int setid) +static void deactivate_pcreset(struct npc_data *nd, int setid) { struct pcrematch_set *pcreset; - struct npc_parse *npcParse = nd->chatdb; + struct npc_parse *npcParse; + nullpo_retv(nd); + npcParse = nd->chatdb; if (npcParse == NULL) return; // Nothing to deactivate... if (setid == -1) { @@ -217,11 +226,13 @@ void deactivate_pcreset(struct npc_data* nd, int setid) /** * delete a set of patterns. */ -void delete_pcreset(struct npc_data* nd, int setid) +static void delete_pcreset(struct npc_data *nd, int setid) { int active = 1; struct pcrematch_set *pcreset; - struct npc_parse *npcParse = nd->chatdb; + struct npc_parse *npcParse; + nullpo_retv(nd); + npcParse = nd->chatdb; if (npcParse == NULL) return; // Nothing to deactivate... pcreset = npcParse->active; @@ -267,10 +278,14 @@ void delete_pcreset(struct npc_data* nd, int setid) /** * create a new pattern entry */ -struct pcrematch_entry* create_pcrematch_entry(struct pcrematch_set* set) +static struct pcrematch_entry *create_pcrematch_entry(struct pcrematch_set *set) { - struct pcrematch_entry * e = (struct pcrematch_entry *) aCalloc(sizeof(struct pcrematch_entry), 1); - struct pcrematch_entry * last = set->head; + struct pcrematch_entry *e; + struct pcrematch_entry *last; + + nullpo_retr(NULL, set); + e = (struct pcrematch_entry *)aCalloc(sizeof(struct pcrematch_entry), 1); + last = set->head; // Normally we would have just stuck it at the end of the list but // this doesn't sink up with peoples usage pattern. They wanted @@ -296,13 +311,14 @@ struct pcrematch_entry* create_pcrematch_entry(struct pcrematch_set* set) /** * define/compile a new pattern */ -void npc_chat_def_pattern(struct npc_data* nd, int setid, const char* pattern, const char* label) +static void npc_chat_def_pattern(struct npc_data *nd, int setid, const char *pattern, const char *label) { const char *err; int erroff; struct pcrematch_set * s = npc_chat->lookup_pcreset(nd, setid); struct pcrematch_entry *e = npc_chat->create_pcrematch_entry(s); + nullpo_retv(e); e->pattern = aStrdup(pattern); e->label = aStrdup(label); e->pcre_ = libpcre->compile(pattern, PCRE_CASELESS, &err, &erroff, NULL); @@ -315,9 +331,12 @@ void npc_chat_def_pattern(struct npc_data* nd, int setid, const char* pattern, c * * this could be more efficient but.. how often do you do this? */ -void npc_chat_finalize(struct npc_data* nd) +static void npc_chat_finalize(struct npc_data *nd) { - struct npc_parse *npcParse = nd->chatdb; + struct npc_parse *npcParse; + + nullpo_retv(nd); + npcParse = nd->chatdb; if (npcParse == NULL) return; @@ -334,7 +353,7 @@ void npc_chat_finalize(struct npc_data* nd) /** * Handler called whenever a global message is spoken in a NPC's area */ -int npc_chat_sub(struct block_list* bl, va_list ap) +static int npc_chat_sub(struct block_list *bl, va_list ap) { struct npc_data *nd = NULL; struct npc_parse *npcParse = NULL; @@ -358,6 +377,8 @@ int npc_chat_sub(struct block_list* bl, va_list ap) len = va_arg(ap,int); sd = va_arg(ap,struct map_session_data *); + nullpo_ret(sd); + // iterate across all active sets for (pcreset = npcParse->active; pcreset != NULL; pcreset = pcreset->next) { @@ -373,7 +394,7 @@ int npc_chat_sub(struct block_list* bl, va_list ap) // save out the matched strings for (i = 0; i < r; i++) { - char var[6], val[255]; + char var[15], val[255]; snprintf(var, sizeof(var), "$@p%i$", i); libpcre->copy_substring(msg, offsets, r, i, val, sizeof(val)); script->set_var(sd, var, val); @@ -443,7 +464,8 @@ BUILDIN(deletepset) return true; } -void npc_chat_defaults(void) { +void npc_chat_defaults(void) +{ npc_chat = &npc_chat_s; npc_chat->sub = npc_chat_sub; |