diff options
Diffstat (limited to 'Source/Swig/error.c')
-rw-r--r-- | Source/Swig/error.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Source/Swig/error.c b/Source/Swig/error.c index fa82ad8d9..5dfcf605b 100644 --- a/Source/Swig/error.c +++ b/Source/Swig/error.c @@ -285,6 +285,41 @@ static String *format_filename(const_String_or_char_ptr filename) { } /* ----------------------------------------------------------------------------- + * Swig_stringify_with_location() + * + * Return a string representation of any DOH object with line and file location + * information in the appropriate error message format. The string representation + * is enclosed within [] brackets after the line and file information. + * ----------------------------------------------------------------------------- */ + +String *Swig_stringify_with_location(DOH *object) { + String *str = NewStringEmpty(); + + if (!init_fmt) + Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT); + + if (object) { + int line = Getline(object); + String *formatted_filename = format_filename(Getfile(object)); + if (line > 0) { + Printf(str, diag_line_fmt, formatted_filename, line); + } else { + Printf(str, diag_eof_fmt, formatted_filename); + } + if (Len(object) == 0) { + Printf(str, "[EMPTY]"); + } else { + Printf(str, "[%s]", object); + } + Delete(formatted_filename); + } else { + Printf(str, "[NULL]"); + } + + return str; +} + +/* ----------------------------------------------------------------------------- * Swig_diagnostic() * * Issue a diagnostic message on stdout. |