summaryrefslogtreecommitdiff
path: root/src/map/script.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/script.c')
-rw-r--r--src/map/script.c54
1 files changed, 23 insertions, 31 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 181ff350f..a5e45f503 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -2699,13 +2699,13 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
#endif
#ifdef SCRIPT_DEBUG_DISASM
i = 0;
- while(i < script->pos) {
- int j = i;
- c_op op = script->get_com(script->buf,&i);
+ while (i < script->pos) {
+ c_op op = script->get_com(script->buf, &i);
+ int j = i; // Note: i is modified in the line above.
ShowMessage("%06x %s", i, script->op2name(op));
- j = i;
- switch(op) {
+
+ switch (op) {
case C_INT:
ShowMessage(" %d", script->get_num(script->buf,&i));
break;
@@ -3834,7 +3834,7 @@ void op_2str(struct script_state* st, int op, const char* s1, const char* s2)
pcre *compiled_regex;
pcre_extra *extra_regex;
const char *pcre_error, *pcre_match;
- int pcre_erroroffset, offsetcount, i;
+ int pcre_erroroffset, offsetcount;
int offsets[256*3]; // (max_capturing_groups+1)*3
compiled_regex = libpcre->compile(s2, 0, &pcre_error, &pcre_erroroffset, NULL);
@@ -3875,8 +3875,9 @@ void op_2str(struct script_state* st, int op, const char* s1, const char* s2)
return;
}
- if( op == C_RE_EQ ) {
- for( i = 0; i < offsetcount; i++ ) {
+ if (op == C_RE_EQ) {
+ int i;
+ for (i = 0; i < offsetcount; i++) {
libpcre->get_substring(s1, offsets, offsetcount, i, &pcre_match);
mapreg->setregstr(reference_uid(script->add_str("$@regexmatch$"), i), pcre_match);
libpcre->free_substring(pcre_match);
@@ -4920,7 +4921,7 @@ void script_load_translations(void) {
libconfig->destroy(&translations_conf);
if( total ) {
- struct DBIterator *main_iter, *sub_iter;
+ struct DBIterator *main_iter;
struct DBMap *string_db;
struct string_translation *st = NULL;
uint32 j = 0;
@@ -4929,9 +4930,9 @@ void script_load_translations(void) {
script->translation_buf_size = total;
main_iter = db_iterator(script->translation_db);
- for( string_db = dbi_first(main_iter); dbi_exists(main_iter); string_db = dbi_next(main_iter) ) {
- sub_iter = db_iterator(string_db);
- for( st = dbi_first(sub_iter); dbi_exists(sub_iter); st = dbi_next(sub_iter) ) {
+ for (string_db = dbi_first(main_iter); dbi_exists(main_iter); string_db = dbi_next(main_iter)) {
+ struct DBIterator *sub_iter = db_iterator(string_db);
+ for (st = dbi_first(sub_iter); dbi_exists(sub_iter); st = dbi_next(sub_iter)) {
script->translation_buf[j++] = st->buf;
}
dbi_destroy(sub_iter);
@@ -4956,8 +4957,8 @@ void script_load_translations(void) {
/**
*
**/
-const char * script_get_translation_file_name(const char *file) {
- static char file_name[200];
+const char *script_get_translation_file_name(const char *file)
+{
int i, len = (int)strlen(file), last_bar = -1, last_dot = -1;
for(i = 0; i < len; i++) {
@@ -4968,6 +4969,7 @@ const char * script_get_translation_file_name(const char *file) {
}
if( last_bar != -1 || last_dot != -1 ) {
+ static char file_name[200];
if( last_bar != -1 && last_dot < last_bar )
last_dot = -1;
safestrncpy(file_name, file+(last_bar >= 0 ? last_bar+1 : 0), ( last_dot >= 0 ? ( last_bar >= 0 ? last_dot - last_bar : last_dot ) : sizeof(file_name) ));
@@ -4999,7 +5001,7 @@ void script_load_translation(const char *file, uint8 lang_id, uint32 *total) {
atcommand->expand_message_table();
while(fgets(line, sizeof(line), fp)) {
- size_t len = strlen(line), cursor = 0;
+ size_t len = strlen(line);
if( len <= 1 )
continue;
@@ -5008,6 +5010,7 @@ void script_load_translation(const char *file, uint8 lang_id, uint32 *total) {
continue;
if( strncasecmp(line,"msgctxt \"", 9) == 0 ) {
+ int cursor = 0;
msgctxt[0] = '\0';
for(i = 9; i < len - 2; i++) {
if( line[i] == '\\' && line[i+1] == '"' ) {
@@ -5015,7 +5018,7 @@ void script_load_translation(const char *file, uint8 lang_id, uint32 *total) {
i++;
} else
msgctxt[cursor] = line[i];
- if( ++cursor >= sizeof(msgctxt) - 1 )
+ if (++cursor >= (int)sizeof(msgctxt) - 1)
break;
}
msgctxt[cursor] = '\0';
@@ -18643,22 +18646,11 @@ BUILDIN(getcharip) {
return false;
}
- /* check for IP */
- if (!sockt->session[sd->fd]->client_addr) {
+ if (sd->fd == 0 || sockt->session[sd->fd] == NULL || sockt->session[sd->fd]->client_addr == 0) {
script_pushconststr(st, "");
- return true;
- }
-
- /* return the client ip_addr converted for output */
- if (sd && sd->fd && sockt->session[sd->fd])
- {
- /* initiliaze */
- const char *ip_addr = NULL;
- uint32 ip;
-
- /* set ip, ip_addr and convert to ip and push str */
- ip = sockt->session[sd->fd]->client_addr;
- ip_addr = sockt->ip2str(ip, NULL);
+ } else {
+ uint32 ip = sockt->session[sd->fd]->client_addr;
+ const char *ip_addr = sockt->ip2str(ip, NULL);
script_pushstrcopy(st, ip_addr);
}