diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-04-04 17:08:44 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-04-04 17:08:44 +0300 |
commit | 3732bd4a6b708651f6b4bcd32d6beb2b7f49c478 (patch) | |
tree | 83155915c35c72d018108231437248cc78d5060d /src/map/script.c | |
parent | 0bd30a0fac1db1b478b3173a22a81bd5249113f8 (diff) | |
parent | 9147fe9473b26ee32aafed65fd02b03f11397629 (diff) | |
download | hercules-3732bd4a6b708651f6b4bcd32d6beb2b7f49c478.tar.gz hercules-3732bd4a6b708651f6b4bcd32d6beb2b7f49c478.tar.bz2 hercules-3732bd4a6b708651f6b4bcd32d6beb2b7f49c478.tar.xz hercules-3732bd4a6b708651f6b4bcd32d6beb2b7f49c478.zip |
Merge pull request #1210 from HerculesWS/wcast_qual
Added -Wcast-qual compiler flag
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 326 |
1 files changed, 178 insertions, 148 deletions
diff --git a/src/map/script.c b/src/map/script.c index 7ad9fd141..007c6e0e1 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -56,6 +56,7 @@ #include "map/unit.h" #include "common/cbasetypes.h" #include "common/conf.h" +#include "common/db.h" #include "common/memmgr.h" #include "common/md5calc.h" #include "common/mmo.h" // NEW_CARTS @@ -63,6 +64,7 @@ #include "common/random.h" #include "common/showmsg.h" #include "common/socket.h" // usage: getcharip +#include "common/sql.h" #include "common/strlib.h" #include "common/sysinfo.h" #include "common/timer.h" @@ -2864,43 +2866,46 @@ struct script_data *get_val(struct script_state* st, struct script_data* data) { } } - if( postfix == '$' ) {// string variable + if (postfix == '$') { + // string variable + const char *str = NULL; - switch( prefix ) { + switch (prefix) { case '@': - data->u.str = pc->readregstr(sd, data->u.num); + str = pc->readregstr(sd, data->u.num); break; case '$': - data->u.str = mapreg->readregstr(data->u.num); + str = mapreg->readregstr(data->u.num); break; case '#': - if( name[1] == '#' ) - data->u.str = pc_readaccountreg2str(sd, data->u.num);// global + if (name[1] == '#') + str = pc_readaccountreg2str(sd, data->u.num);// global else - data->u.str = pc_readaccountregstr(sd, data->u.num);// local + str = pc_readaccountregstr(sd, data->u.num);// local break; case '.': if (data->ref) - data->u.str = script->get_val_ref_str(st, data->ref, data); + str = script->get_val_ref_str(st, data->ref, data); else if (name[1] == '@') - data->u.str = script->get_val_scope_str(st, &st->stack->scope, data); + str = script->get_val_scope_str(st, &st->stack->scope, data); else - data->u.str = script->get_val_npc_str(st, &st->script->local, data); + str = script->get_val_npc_str(st, &st->script->local, data); break; case '\'': - data->u.str = script->get_val_instance_str(st, name, data); + str = script->get_val_instance_str(st, name, data); break; default: - data->u.str = pc_readglobalreg_str(sd, data->u.num); + str = pc_readglobalreg_str(sd, data->u.num); break; } - if( data->u.str == NULL || data->u.str[0] == '\0' ) {// empty string + if (str == NULL || str[0] == '\0') { + // empty string data->type = C_CONSTSTR; data->u.str = ""; } else {// duplicate string data->type = C_STR; - data->u.str = aStrdup(data->u.str); + data->u.mutstr = aStrdup(str); } } else {// integer variable @@ -2957,12 +2962,16 @@ struct script_data *get_val(struct script_state* st, struct script_data* data) { * @param ref[in] the container to look up the reference into. * @return the retrieved value of the reference. */ -void* get_val2(struct script_state* st, int64 uid, struct reg_db *ref) { +const void *get_val2(struct script_state *st, int64 uid, struct reg_db *ref) +{ struct script_data* data; script->push_val(st->stack, C_NAME, uid, ref); data = script_getdatatop(st, -1); script->get_val(st, data); - return (data->type == C_INT ? (void*)h64BPTRSIZE((int32)data->u.num) : (void*)h64BPTRSIZE(data->u.str)); // u.num is int32 because it comes from script->get_val + if (data->type == C_INT) // u.num is int32 because it comes from script->get_val + return (const void *)h64BPTRSIZE((int32)data->u.num); + else + return (const void *)h64BPTRSIZE(data->u.str); } /** * Because, currently, array members with key 0 are indifferenciable from normal variables, we should ensure its actually in @@ -2979,8 +2988,8 @@ void script_array_ensure_zero(struct script_state *st, struct map_session_data * insert = true; } else { if( is_string_variable(name) ) { - char* str = (char*)script->get_val2(st, uid, ref); - if( str && *str ) + const char *str = script->get_val2(st, uid, ref); + if (str != NULL && *str != '\0') insert = true; script_removetop(st, -1, 0); } else { @@ -3044,7 +3053,8 @@ unsigned int script_array_highest_key(struct script_state *st, struct map_sessio } return 0; } -int script_free_array_db(DBKey key, DBData *data, va_list ap) { +int script_free_array_db(union DBKey key, struct DBData *data, va_list ap) +{ struct script_array *sa = DB->data2ptr(data); aFree(sa->members); ers_free(script->array_ers, sa); @@ -3351,59 +3361,59 @@ int set_var(struct map_session_data *sd, char *name, void *val) return script->set_reg(NULL, sd, reference_uid(script->add_str(name),0), name, val, NULL); } -void setd_sub(struct script_state *st, struct map_session_data *sd, const char *varname, int elem, void *value, struct reg_db *ref) +void setd_sub(struct script_state *st, struct map_session_data *sd, const char *varname, int elem, const void *value, struct reg_db *ref) { script->set_reg(st, sd, reference_uid(script->add_str(varname),elem), varname, value, ref); } /// Converts the data to a string -const char* conv_str(struct script_state* st, struct script_data* data) +const char *conv_str(struct script_state *st, struct script_data* data) { - char* p; - script->get_val(st, data); - if( data_isstring(data) ) - {// nothing to convert + if (data_isstring(data)) { + // nothing to convert + return data->u.str; } - else if( data_isint(data) ) - {// int -> string + if (data_isint(data)) { + // int -> string + char *p; CREATE(p, char, ITEM_NAME_LENGTH); snprintf(p, ITEM_NAME_LENGTH, "%"PRId64"", data->u.num); p[ITEM_NAME_LENGTH-1] = '\0'; data->type = C_STR; - data->u.str = p; + data->u.mutstr = p; + return data->u.mutstr; } - else if( data_isreference(data) ) - {// reference -> string + if (data_isreference(data)) { + // reference -> string //##TODO when does this happen (check script->get_val) [FlavioJS] data->type = C_CONSTSTR; data->u.str = reference_getname(data); - } - else - {// unsupported data type - ShowError("script:conv_str: cannot convert to string, defaulting to \"\"\n"); - script->reportdata(data); - script->reportsrc(st); - data->type = C_CONSTSTR; - data->u.str = ""; - } + return data->u.str; + } + // unsupported data type + ShowError("script:conv_str: cannot convert to string, defaulting to \"\"\n"); + script->reportdata(data); + script->reportsrc(st); + data->type = C_CONSTSTR; + data->u.str = ""; return data->u.str; } /// Converts the data to an int -int conv_num(struct script_state* st, struct script_data* data) { - char* p; +int conv_num(struct script_state *st, struct script_data *data) +{ long num; script->get_val(st, data); - if( data_isint(data) ) - {// nothing to convert + if (data_isint(data)) { + // nothing to convert + return (int)data->u.num; } - else if( data_isstring(data) ) - {// string -> int + if (data_isstring(data)) { + // string -> int // the result does not overflow or underflow, it is capped instead // ex: 999999999999 is capped to INT_MAX (2147483647) - p = data->u.str; errno = 0; num = strtol(data->u.str, NULL, 10);// change radix to 0 to support octal numbers "o377" and hex numbers "0xFF" if( errno == ERANGE @@ -3425,22 +3435,21 @@ int conv_num(struct script_state* st, struct script_data* data) { script->reportdata(data); script->reportsrc(st); } - if( data->type == C_STR ) - aFree(p); + if (data->type == C_STR) + aFree(data->u.mutstr); data->type = C_INT; data->u.num = (int)num; + return (int)data->u.num; } #if 0 + // unsupported data type // FIXME this function is being used to retrieve the position of labels and // probably other stuff [FlavioJS] - else - {// unsupported data type - ShowError("script:conv_num: cannot convert to number, defaulting to 0\n"); - script->reportdata(data); - script->reportsrc(st); - data->type = C_INT; - data->u.num = 0; - } + ShowError("script:conv_num: cannot convert to number, defaulting to 0\n"); + script->reportdata(data); + script->reportsrc(st); + data->type = C_INT; + data->u.num = 0; #endif return (int)data->u.num; } @@ -3470,11 +3479,23 @@ struct script_data* push_val(struct script_stack* stack, enum c_op type, int64 v } /// Pushes a string into the stack -struct script_data* push_str(struct script_stack* stack, enum c_op type, char* str) +struct script_data *push_str(struct script_stack *stack, char *str) { if( stack->sp >= stack->sp_max ) script->stack_expand(stack); - stack->stack_data[stack->sp].type = type; + stack->stack_data[stack->sp].type = C_STR; + stack->stack_data[stack->sp].u.mutstr = str; + stack->stack_data[stack->sp].ref = NULL; + stack->sp++; + return &stack->stack_data[stack->sp-1]; +} + +/// Pushes a constant string into the stack +struct script_data *push_conststr(struct script_stack *stack, const char *str) +{ + if( stack->sp >= stack->sp_max ) + script->stack_expand(stack); + stack->stack_data[stack->sp].type = C_CONSTSTR; stack->stack_data[stack->sp].u.str = str; stack->stack_data[stack->sp].ref = NULL; stack->sp++; @@ -3496,10 +3517,10 @@ struct script_data* push_retinfo(struct script_stack* stack, struct script_retin struct script_data* push_copy(struct script_stack* stack, int pos) { switch( stack->stack_data[pos].type ) { case C_CONSTSTR: - return script->push_str(stack, C_CONSTSTR, stack->stack_data[pos].u.str); + return script->push_conststr(stack, stack->stack_data[pos].u.str); break; case C_STR: - return script->push_str(stack, C_STR, aStrdup(stack->stack_data[pos].u.str)); + return script->push_str(stack, aStrdup(stack->stack_data[pos].u.mutstr)); break; case C_RETINFO: ShowFatalError("script:push_copy: can't create copies of C_RETINFO. Exiting...\n"); @@ -3533,8 +3554,8 @@ void pop_stack(struct script_state* st, int start, int end) { for( i = start; i < end; i++ ) { data = &stack->stack_data[i]; - if( data->type == C_STR ) - aFree(data->u.str); + if (data->type == C_STR) + aFree(data->u.mutstr); if( data->type == C_RETINFO ) { struct script_retinfo* ri = data->u.ri; @@ -3586,7 +3607,8 @@ void pop_stack(struct script_state* st, int start, int end) { /*========================================== * Release script dependent variable, dependent variable of function *------------------------------------------*/ -void script_free_vars(struct DBMap* var_storage) { +void script_free_vars(struct DBMap *var_storage) +{ if( var_storage ) { // destroy the storage construct containing the variables db_destroy(var_storage); @@ -3765,12 +3787,11 @@ void op_3(struct script_state* st, int op) data = script_getdatatop(st, -3); script->get_val(st, data); - if( data_isstring(data) ) - flag = data->u.str[0];// "" -> false - else if( data_isint(data) ) + if (data_isstring(data)) { + flag = data->u.str[0]; // "" -> false + } else if (data_isint(data)) { flag = data->u.num == 0 ? 0 : 1;// 0 -> false - else - { + } else { ShowError("script:op_3: invalid data for the ternary operator test\n"); script->reportdata(data); script->reportsrc(st); @@ -3991,10 +4012,9 @@ void op_2(struct script_state *st, int op) script->op_2str(st, op, left->u.str, right->u.str); script_removetop(st, leftref.type == C_NOP ? -3 : -2, -1);// pop the two values before the top one - if (leftref.type != C_NOP) - { + if (leftref.type != C_NOP) { if (left->type == C_STR) // don't free C_CONSTSTR - aFree(left->u.str); + aFree(left->u.mutstr); *left = leftref; } } @@ -4243,8 +4263,9 @@ void run_script(struct script_code *rootscript, int pos, int rid, int oid) { script->run_main(st); } -void script_stop_instances(struct script_code *code) { - DBIterator *iter; +void script_stop_instances(struct script_code *code) +{ + struct DBIterator *iter; struct script_state* st; if( !script->active_scripts ) @@ -4392,7 +4413,7 @@ void run_script_main(struct script_state *st) { script->push_val(stack,c,0,NULL); break; case C_STR: - script->push_str(stack,C_CONSTSTR,(char*)(st->script->script_buf+st->pos)); + script->push_conststr(stack, (const char *)(st->script->script_buf+st->pos)); while(st->script->script_buf[st->pos++]); break; case C_LSTR: @@ -4404,7 +4425,7 @@ void run_script_main(struct script_state *st) { st->pos += sizeof(int) + sizeof(uint8); if( (!st->rid || !(lsd = map->id2sd(st->rid)) || !lsd->lang_id) && !map->default_lang_id ) - script->push_str(stack,C_CONSTSTR,script->string_list+string_id); + script->push_conststr(stack, script->string_list+string_id); else { uint8 k, wlang_id = lsd ? lsd->lang_id : map->default_lang_id; int offset = st->pos; @@ -4416,8 +4437,10 @@ void run_script_main(struct script_state *st) { break; offset += sizeof(char*); } - script->push_str(stack,C_CONSTSTR, - ( k == translations ) ? script->string_list+string_id : *(char**)(&st->script->script_buf[offset]) ); + if (k == translations) + script->push_conststr(stack, script->string_list+string_id); + else + script->push_conststr(stack, *(const char**)(&st->script->script_buf[offset]) ); } st->pos += ( ( sizeof(char*) + sizeof(uint8) ) * translations ); } @@ -4576,7 +4599,7 @@ int script_config_read(char *cfgName) { /** * @see DBApply */ -int db_script_free_code_sub(DBKey key, DBData *data, va_list ap) +int db_script_free_code_sub(union DBKey key, struct DBData *data, va_list ap) { struct script_code *code = DB->data2ptr(data); if (code) @@ -4652,7 +4675,8 @@ void script_setarray_pc(struct map_session_data* sd, const char* varname, uint32 /** * Clears persistent variables from memory **/ -int script_reg_destroy(DBKey key, DBData *data, va_list ap) { +int script_reg_destroy(union DBKey key, struct DBData *data, va_list ap) +{ struct script_reg_state *src; if( data->type != DB_DATA_PTR )/* got no need for those! */ @@ -4702,9 +4726,10 @@ void script_generic_ui_array_expand (unsigned int plus) { /*========================================== * Destructor *------------------------------------------*/ -void do_final_script(void) { +void do_final_script(void) +{ int i; - DBIterator *iter; + struct DBIterator *iter; struct script_state *st; #ifdef SCRIPT_DEBUG_HASH @@ -4895,9 +4920,8 @@ void script_load_translations(void) { libconfig->destroy(&translations_conf); if( total ) { - DBIterator *main_iter; - DBIterator *sub_iter; - DBMap *string_db; + struct DBIterator *main_iter, *sub_iter; + struct DBMap *string_db; struct string_translation *st = NULL; uint32 j = 0; @@ -4960,7 +4984,7 @@ void script_load_translation(const char *file, uint8 lang_id, uint32 *total) { uint32 translations = 0; char line[1024]; char msgctxt[NAME_LENGTH*2+1] = { 0 }; - DBMap *string_db; + struct DBMap *string_db; size_t i; FILE *fp; struct script_string_buf msgid = { 0 }, msgstr = { 0 }; @@ -5111,12 +5135,13 @@ void script_clear_translations(bool reload) { /** * **/ -int script_translation_db_destroyer(DBKey key, DBData *data, va_list ap) { - DBMap *string_db = DB->data2ptr(data); +int script_translation_db_destroyer(union DBKey key, struct DBData *data, va_list ap) +{ + struct DBMap *string_db = DB->data2ptr(data); if( db_size(string_db) ) { struct string_translation *st = NULL; - DBIterator *iter = db_iterator(string_db); + struct DBIterator *iter = db_iterator(string_db); for( st = dbi_first(iter); dbi_exists(iter); st = dbi_next(iter) ) { aFree(st); @@ -5196,9 +5221,10 @@ void do_init_script(bool minimal) { script->load_translations(); } -int script_reload(void) { +int script_reload(void) +{ int i; - DBIterator *iter; + struct DBIterator *iter; struct script_state *st; #ifdef ENABLE_CASE_CHECK @@ -6337,7 +6363,7 @@ BUILDIN(jobchange) BUILDIN(jobname) { int class_=script_getnum(st,2); - script_pushconststr(st, (char*)pc->job_name(class_)); + script_pushconststr(st, pc->job_name(class_)); return true; } @@ -6386,16 +6412,13 @@ BUILDIN(input) } else { // take received text/value and store it in the designated variable sd->state.menu_or_input = 0; - if( is_string_variable(name) ) - { + if (is_string_variable(name)) { int len = (int)strlen(sd->npc_str); - script->set_reg(st, sd, uid, name, (void*)sd->npc_str, script_getref(st,2)); + script->set_reg(st, sd, uid, name, sd->npc_str, script_getref(st,2)); script_pushint(st, (len > max ? 1 : len < min ? -1 : 0)); - } - else - { + } else { int amount = sd->npc_amount; - script->set_reg(st, sd, uid, name, (void*)h64BPTRSIZE(cap_value(amount,min,max)), script_getref(st,2)); + script->set_reg(st, sd, uid, name, (const void *)h64BPTRSIZE(cap_value(amount,min,max)), script_getref(st,2)); script_pushint(st, (amount > max ? 1 : amount < min ? -1 : 0)); } st->state = RUN; @@ -6482,9 +6505,9 @@ BUILDIN(__setr) } if (is_string_variable(name)) - script->set_reg(st,sd,num,name,(void*)script_getstr(st,3),script_getref(st,2)); + script->set_reg(st, sd, num, name, script_getstr(st, 3), script_getref(st, 2)); else - script->set_reg(st,sd,num,name,(void*)h64BPTRSIZE(script_getnum(st,3)),script_getref(st,2)); + script->set_reg(st, sd, num, name, (const void *)h64BPTRSIZE(script_getnum(st, 3)), script_getref(st, 2)); return true; } @@ -6531,15 +6554,14 @@ BUILDIN(setarray) if( end > SCRIPT_MAX_ARRAYSIZE ) end = SCRIPT_MAX_ARRAYSIZE; - if( is_string_variable(name) ) - {// string array - for( i = 3; start < end; ++start, ++i ) - script->set_reg(st, sd, reference_uid(id, start), name, (void*)script_getstr(st,i), reference_getref(data)); - } - else - {// int array - for( i = 3; start < end; ++start, ++i ) - script->set_reg(st, sd, reference_uid(id, start), name, (void*)h64BPTRSIZE(script_getnum(st,i)), reference_getref(data)); + if (is_string_variable(name)) { + // string array + for (i = 3; start < end; ++start, ++i) + script->set_reg(st, sd, reference_uid(id, start), name, script_getstr(st, i), reference_getref(data)); + } else { + // int array + for (i = 3; start < end; ++start, ++i) + script->set_reg(st, sd, reference_uid(id, start), name, (const void *)h64BPTRSIZE(script_getnum(st, i)), reference_getref(data)); } return true; } @@ -6555,7 +6577,7 @@ BUILDIN(cleararray) uint32 start; uint32 end; int32 id; - void* v; + const void *v = NULL; struct map_session_data *sd = NULL; data = script_getdata(st, 2); @@ -6578,10 +6600,10 @@ BUILDIN(cleararray) return true;// no player attached } - if( is_string_variable(name) ) - v = (void*)script_getstr(st, 3); + if (is_string_variable(name)) + v = script_getstr(st, 3); else - v = (void*)h64BPTRSIZE(script_getnum(st, 3)); + v = (const void *)h64BPTRSIZE(script_getnum(st, 3)); end = start + script_getnum(st, 4); if( end > SCRIPT_MAX_ARRAYSIZE ) @@ -6606,7 +6628,6 @@ BUILDIN(copyarray) int32 idx2; int32 id1; int32 id2; - void* v; int32 i; uint32 count; struct map_session_data *sd = NULL; @@ -6654,20 +6675,25 @@ BUILDIN(copyarray) if( is_same_reference(data1, data2) && idx1 > idx2 ) { // destination might be overlapping the source - copy in reverse order for( i = count - 1; i >= 0; --i ) { - v = script->get_val2(st, reference_uid(id2, idx2 + i), reference_getref(data2)); - script->set_reg(st, sd, reference_uid(id1, idx1 + i), name1, v, reference_getref(data1)); + const void *value = script->get_val2(st, reference_uid(id2, idx2 + i), reference_getref(data2)); + script->set_reg(st, sd, reference_uid(id1, idx1 + i), name1, value, reference_getref(data1)); script_removetop(st, -1, 0); } } else { // normal copy for( i = 0; i < count; ++i ) { if( idx2 + i < SCRIPT_MAX_ARRAYSIZE ) { - v = script->get_val2(st, reference_uid(id2, idx2 + i), reference_getref(data2)); - script->set_reg(st, sd, reference_uid(id1, idx1 + i), name1, v, reference_getref(data1)); + const void *value = script->get_val2(st, reference_uid(id2, idx2 + i), reference_getref(data2)); + script->set_reg(st, sd, reference_uid(id1, idx1 + i), name1, value, reference_getref(data1)); script_removetop(st, -1, 0); } else { // out of range - assume ""/0 - script->set_reg(st, sd, reference_uid(id1, idx1 + i), name1, (is_string_variable(name1)?(void*)"":(void*)0), reference_getref(data1)); + const void *value; + if (is_string_variable(name1)) + value = ""; + else + value = (const void *)0; + script->set_reg(st, sd, reference_uid(id1, idx1 + i), name1, value, reference_getref(data1)); } } } @@ -6696,8 +6722,9 @@ BUILDIN(getarraysize) script_pushint(st, script->array_highest_key(st,st->rid ? script->rid2sd(st) : NULL,reference_getname(data),reference_getref(data))); return true; } -int script_array_index_cmp(const void *a, const void *b) { - return ( *(const unsigned int*)a - *(const unsigned int*)b ); +int script_array_index_cmp(const void *a, const void *b) +{ + return (*(const unsigned int *)a - *(const unsigned int *)b); // FIXME: Is the unsigned difference really intended here? } /// Deletes count or all the elements in an array, from the starting index. @@ -6770,7 +6797,7 @@ BUILDIN(deletearray) // Better to iterate directly on the array, no speed-up from using sa for( ; start + count < end; ++start ) { // Compact and overwrite - void* v = script->get_val2(st, reference_uid(id, start + count), reference_getref(data)); + const void *v = script->get_val2(st, reference_uid(id, start + count), reference_getref(data)); script->set_reg(st, sd, reference_uid(id, start), name, v, reference_getref(data)); script_removetop(st, -1, 0); } @@ -6794,7 +6821,7 @@ BUILDIN(deletearray) for( ; i < size && list[i] < end; i++ ) { // Move back count positions any entries between start+count to fill the gaps - void* v = script->get_val2(st, reference_uid(id, list[i]), reference_getref(data)); + const void *v = script->get_val2(st, reference_uid(id, list[i]), reference_getref(data)); script->set_reg(st, sd, reference_uid(id, list[i]-count), name, v, reference_getref(data)); script_removetop(st, -1, 0); // Clear their originals @@ -11054,9 +11081,9 @@ BUILDIN(getstatus) case 4: script_pushint(st, sd->sc.data[id]->val4); break; case 5: { - const struct TimerData* td = (const struct TimerData*)timer->get(sd->sc.data[id]->timer); + const struct TimerData *td = timer->get(sd->sc.data[id]->timer); - if( td ) { + if (td != NULL) { // return the amount of time remaining script_pushint(st, (int)(td->tick - timer->gettick())); // TODO: change this to int64 when we'll support 64 bit script values } @@ -14407,7 +14434,7 @@ BUILDIN(getmapxy) sd=script->rid2sd(st); else sd=NULL; - script->set_reg(st,sd,num,name,(void*)mapname,script_getref(st,2)); + script->set_reg(st, sd, num, name, mapname, script_getref(st, 2)); //Set MapX num=st->stack->stack_data[st->start+3].u.num; @@ -14418,7 +14445,7 @@ BUILDIN(getmapxy) sd=script->rid2sd(st); else sd=NULL; - script->set_reg(st,sd,num,name,(void*)h64BPTRSIZE(x),script_getref(st,3)); + script->set_reg(st, sd, num, name, (const void *)h64BPTRSIZE(x), script_getref(st, 3)); //Set MapY num=st->stack->stack_data[st->start+4].u.num; @@ -14429,7 +14456,7 @@ BUILDIN(getmapxy) sd=script->rid2sd(st); else sd=NULL; - script->set_reg(st,sd,num,name,(void*)h64BPTRSIZE(y),script_getref(st,4)); + script->set_reg(st, sd, num, name, (const void *)h64BPTRSIZE(y), script_getref(st, 4)); //Return Success value script_pushint(st,0); @@ -15089,7 +15116,7 @@ BUILDIN(explode) if (str[i] == delimiter && (int64)start + k < (int64)(SCRIPT_MAX_ARRAYSIZE-1)) { // FIXME[Haru]: SCRIPT_MAX_ARRAYSIZE should really be unsigned (and INT32_MAX) //break at delimiter but ignore after reaching last array index temp[j] = '\0'; - script->set_reg(st, sd, reference_uid(id, start + k), name, (void*)temp, reference_getref(data)); + script->set_reg(st, sd, reference_uid(id, start + k), name, temp, reference_getref(data)); k++; j = 0; } else { @@ -15098,7 +15125,7 @@ BUILDIN(explode) } //set last string temp[j] = '\0'; - script->set_reg(st, sd, reference_uid(id, start + k), name, (void*)temp, reference_getref(data)); + script->set_reg(st, sd, reference_uid(id, start + k), name, temp, reference_getref(data)); aFree(temp); @@ -15159,7 +15186,7 @@ BUILDIN(implode) size_t len = 0, glue_len = 0, k = 0; const char *glue = NULL, *temp; for(i = 0; i <= array_size; ++i) { - temp = (char*) script->get_val2(st, reference_uid(id, i), reference_getref(data)); + temp = script->get_val2(st, reference_uid(id, i), reference_getref(data)); len += strlen(temp); script_removetop(st, -1, 0); } @@ -15174,7 +15201,7 @@ BUILDIN(implode) //build output for(i = 0; i < array_size; ++i) { - temp = (char*) script->get_val2(st, reference_uid(id, i), reference_getref(data)); + temp = script->get_val2(st, reference_uid(id, i), reference_getref(data)); len = strlen(temp); memcpy(&output[k], temp, len); k += len; @@ -15184,7 +15211,7 @@ BUILDIN(implode) } script_removetop(st, -1, 0); } - temp = (char*) script->get_val2(st, reference_uid(id, array_size), reference_getref(data)); + temp = script->get_val2(st, reference_uid(id, array_size), reference_getref(data)); len = strlen(temp); memcpy(&output[k], temp, len); k += len; @@ -15418,12 +15445,12 @@ BUILDIN(sscanf) { if(sscanf(str, buf, ref_str)==0) { break; } - script->set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (void *)(ref_str), reference_getref(data)); + script->set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, ref_str, reference_getref(data)); } else { // Number if(sscanf(str, buf, &ref_int)==0) { break; } - script->set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (void *)h64BPTRSIZE(ref_int), reference_getref(data)); + script->set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (const void *)h64BPTRSIZE(ref_int), reference_getref(data)); } arg++; @@ -15863,8 +15890,8 @@ BUILDIN(swap) value2 = script_getstr(st,3); if (strcmpi(value1, value2)) { - script->set_reg(st, sd, uid1, varname1, (void*)(value2), script_getref(st,3)); - script->set_reg(st, sd, uid2, varname2, (void*)(value1), script_getref(st,2)); + script->set_reg(st, sd, uid1, varname1, value2, script_getref(st,3)); + script->set_reg(st, sd, uid2, varname2, value1, script_getref(st,2)); } } else { @@ -15874,8 +15901,8 @@ BUILDIN(swap) value2 = script_getnum(st,3); if (value1 != value2) { - script->set_reg(st, sd, uid1, varname1, (void*)h64BPTRSIZE(value2), script_getref(st,3)); - script->set_reg(st, sd, uid2, varname2, (void*)h64BPTRSIZE(value1), script_getref(st,2)); + script->set_reg(st, sd, uid1, varname1, (const void *)h64BPTRSIZE(value2), script_getref(st,3)); + script->set_reg(st, sd, uid2, varname2, (const void *)h64BPTRSIZE(value1), script_getref(st,2)); } } return true; @@ -15904,16 +15931,16 @@ BUILDIN(setd) } } - if( is_string_variable(varname) ) { - script->setd_sub(st, sd, varname, elem, (void *)script_getstr(st, 3), NULL); + if (is_string_variable(varname)) { + script->setd_sub(st, sd, varname, elem, script_getstr(st, 3), NULL); } else { - script->setd_sub(st, sd, varname, elem, (void *)h64BPTRSIZE(script_getnum(st, 3)), NULL); + script->setd_sub(st, sd, varname, elem, (const void *)h64BPTRSIZE(script_getnum(st, 3)), NULL); } return true; } -int buildin_query_sql_sub(struct script_state* st, Sql* handle) +int buildin_query_sql_sub(struct script_state *st, struct Sql *handle) { int i, j; struct map_session_data *sd = NULL; @@ -16529,7 +16556,7 @@ BUILDIN(searchitem) for( i = 0; i < count; ++start, ++i ) {// Set array - void* v = (void*)h64BPTRSIZE((int)items[i]->nameid); + const void *v = (const void *)h64BPTRSIZE((int)items[i]->nameid); script->set_reg(st, sd, reference_uid(id, start), name, v, reference_getref(data)); } @@ -16976,8 +17003,9 @@ BUILDIN(sleep2) { /// Awakes all the sleep timers of the target npc /// /// awake "<npc name>"; -BUILDIN(awake) { - DBIterator *iter; +BUILDIN(awake) +{ + struct DBIterator *iter; struct script_state *tst; struct npc_data* nd; @@ -19747,9 +19775,10 @@ BUILDIN(checkbound) /* bg_match_over( arena_name {, optional canceled } ) */ /* returns 0 when successful, 1 otherwise */ -BUILDIN(bg_match_over) { +BUILDIN(bg_match_over) +{ bool canceled = script_hasdata(st,3) ? true : false; - struct bg_arena *arena = bg->name2arena((const char*)script_getstr(st, 2)); + struct bg_arena *arena = bg->name2arena(script_getstr(st, 2)); if( arena ) { bg->match_over(arena,canceled); @@ -21150,6 +21179,7 @@ void script_defaults(void) { script->get_val_npc_num = get_val_npcscope_num; script->get_val_instance_num = get_val_instance_num; script->push_str = push_str; + script->push_conststr = push_conststr; script->push_copy = push_copy; script->pop_stack = pop_stack; script->set_constant = script_set_constant; |