summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2013-08-26 20:35:13 +0200
committerHaru <haru@dotalux.com>2013-08-26 20:49:39 +0200
commit86602bbb645987b8b59588d1d2c74679589f6a7b (patch)
treef02367148f1dc1b13ad5a2c9662153f53dc203d7 /src/map
parent835188124a6e590b406d81803b8d47f07884a9ea (diff)
downloadhercules-86602bbb645987b8b59588d1d2c74679589f6a7b.tar.gz
hercules-86602bbb645987b8b59588d1d2c74679589f6a7b.tar.bz2
hercules-86602bbb645987b8b59588d1d2c74679589f6a7b.tar.xz
hercules-86602bbb645987b8b59588d1d2c74679589f6a7b.zip
Added support for non-fatal error messages from the script parser
- Changed overflow errors to be non-fatal. The value will now be capped to INT_MAX or INT_MIN. - Follow-up to 8351881 Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map')
-rw-r--r--src/map/script.c61
-rw-r--r--src/map/script.h1
2 files changed, 47 insertions, 15 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 754cf6dd5..1a3bb92b9 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -109,6 +109,10 @@ static jmp_buf error_jump;
static char* error_msg;
static const char* error_pos;
static int error_report; // if the error should produce output
+// Used by disp_warning_message
+static const char* parser_current_src;
+static const char* parser_current_file;
+static int parser_current_line;
// for advanced scripting support ( nested if, switch, while, for, do-while, function, etc )
// [Eoe / jA 1080, 1081, 1094, 1164]
@@ -429,6 +433,10 @@ static void disp_error_message2(const char *mes,const char *pos,int report)
}
#define disp_error_message(mes,pos) disp_error_message2(mes,pos,1)
+static void disp_warning_message(const char *mes, const char *pos) {
+ script->warning(parser_current_src,parser_current_file,parser_current_line,mes,pos);
+}
+
/// Checks event parameter validity
static void check_event(struct script_state *st, const char *evt)
{
@@ -677,8 +685,10 @@ const char* script_skip_space(const char* p)
p += 2;
for(;;)
{
- if( *p == '\0' )
- return p;//disp_error_message("script:script->skip_space: end of file while parsing block comment. expected "CL_BOLD"*/"CL_NORM, p);
+ if( *p == '\0' ) {
+ disp_warning_message("script:script->skip_space: end of file while parsing block comment. expected "CL_BOLD"*/"CL_NORM, p);
+ return p;
+ }
if( *p == '*' && p[1] == '/' )
{// end of block comment
p += 2;
@@ -1034,10 +1044,10 @@ const char* parse_simpleexpr(const char *p)
i=strtoll(p,&np,0);
if( i < INT_MIN ) {
i = INT_MIN;
- disp_error_message("parse_simpleexpr: underflow detected, capping value to INT_MIN",p);
+ disp_warning_message("parse_simpleexpr: underflow detected, capping value to INT_MIN",p);
} else if( i > INT_MAX ) {
i = INT_MAX;
- disp_error_message("parse_simpleexpr: overflow detected, capping value to INT_MAX",p);
+ disp_warning_message("parse_simpleexpr: overflow detected, capping value to INT_MAX",p);
}
add_scripti(i);
p=np;
@@ -2028,14 +2038,12 @@ static const char* script_print_line(StringBuf* buf, const char* p, const char*
return p+i+(p[i] == '\n' ? 1 : 0);
}
-void script_error(const char* src, const char* file, int start_line, const char* error_msg, const char* error_pos)
-{
+void script_errorwarning_sub(StringBuf *buf, const char* src, const char* file, int start_line, const char* error_msg, const char* error_pos) {
// Find the line where the error occurred
int j;
int line = start_line;
const char *p;
const char *linestart[5] = { NULL, NULL, NULL, NULL, NULL };
- StringBuf buf;
for(p=src;p && *p;line++){
const char *lineend=strchr(p,'\n');
@@ -2049,25 +2057,44 @@ void script_error(const char* src, const char* file, int start_line, const char*
p=lineend+1;
}
- StrBuf->Init(&buf);
- StrBuf->AppendStr(&buf, "\a\n");
if( line >= 0 )
- StrBuf->Printf(&buf, "script error on %s line %d\n", file, line);
+ StrBuf->Printf(buf, "script error on %s line %d\n", file, line);
else
- StrBuf->Printf(&buf, "script error on %s item ID %d\n", file, -line);
+ StrBuf->Printf(buf, "script error on %s item ID %d\n", file, -line);
- StrBuf->Printf(&buf, " %s\n", error_msg);
+ StrBuf->Printf(buf, " %s\n", error_msg);
for(j = 0; j < 5; j++ ) {
- script_print_line(&buf, linestart[j], NULL, line + j - 5);
+ script_print_line(buf, linestart[j], NULL, line + j - 5);
}
- p = script_print_line(&buf, p, error_pos, -line);
+ p = script_print_line(buf, p, error_pos, -line);
for(j = 0; j < 5; j++) {
- p = script_print_line(&buf, p, NULL, line + j + 1 );
+ p = script_print_line(buf, p, NULL, line + j + 1 );
}
+}
+
+void script_error(const char* src, const char* file, int start_line, const char* error_msg, const char* error_pos) {
+ StringBuf buf;
+
+ StrBuf->Init(&buf);
+ StrBuf->AppendStr(&buf, "\a\n");
+
+ script_errorwarning_sub(&buf, src, file, start_line, error_msg, error_pos);
+
ShowError("%s", StrBuf->Value(&buf));
StrBuf->Destroy(&buf);
}
+void script_warning(const char* src, const char* file, int start_line, const char* error_msg, const char* error_pos) {
+ StringBuf buf;
+
+ StrBuf->Init(&buf);
+
+ script_errorwarning_sub(&buf, src, file, start_line, error_msg, error_pos);
+
+ ShowWarning("%s", StrBuf->Value(&buf));
+ StrBuf->Destroy(&buf);
+}
+
/*==========================================
* Analysis of the script
*------------------------------------------*/
@@ -2078,6 +2105,9 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
struct script_code* code = NULL;
char end;
bool unresolved_names = false;
+ parser_current_src = src;
+ parser_current_file = file;
+ parser_current_line = line;
if( src == NULL )
return NULL;// empty script
@@ -18192,6 +18222,7 @@ void script_defaults(void) {
script->parse_builtin = script_parse_builtin;
script->skip_space = script_skip_space;
script->error = script_error;
+ script->warning = script_warning;
script->parse_subexpr = script_parse_subexpr;
script->addScript = script_hp_add;
diff --git a/src/map/script.h b/src/map/script.h
index 774101eb3..bcdd1fdaf 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -362,6 +362,7 @@ struct script_interface {
const char* (*parse_subexpr) (const char* p,int limit);
const char* (*skip_space) (const char* p);
void (*error) (const char* src, const char* file, int start_line, const char* error_msg, const char* error_pos);
+ void (*warning) (const char* src, const char* file, int start_line, const char* error_msg, const char* error_pos);
/* */
bool (*addScript) (char *name, char *args, bool (*func)(struct script_state *st));
int (*conv_num) (struct script_state *st,struct script_data *data);