diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Exceptions.cc | 34 | ||||
-rw-r--r-- | lib/String.cc | 12 |
2 files changed, 43 insertions, 3 deletions
diff --git a/lib/Exceptions.cc b/lib/Exceptions.cc index fe3aecc..85b4429 100644 --- a/lib/Exceptions.cc +++ b/lib/Exceptions.cc @@ -5,9 +5,6 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#ifdef HAVE_GLIB -#include <glib.h> -#endif #ifdef DEBUG #include <iostream> #endif @@ -21,6 +18,8 @@ char GeneralException::t[BUFSIZ]; +std::vector<String> Base::context; + GeneralException::GeneralException(String emsg) : msg(emsg.strdup()) { #ifdef DEBUG printm(M_BARE, String(_("Generating a General Exception error: '")) + msg + "'.\n"); @@ -179,6 +178,10 @@ void xexit(int status) throw (GeneralException) { throw Exit(status); } +void xexception(const String & err) throw (GeneralException) { + throw GeneralException(err); +} + char * Base::strdup(const char * s) { return xstrdup(s); } @@ -239,3 +242,28 @@ pid_t Base::fork() { void Base::exit(int status) { xexit(status); } + +void Base::flushcontext() { + context.clear(); +} + +void Base::pushcontext(const String & c) { + context.push_back(c); +} + +void Base::popcontext() { + context.pop_back(); +} + +void Base::exception(const String & err) { + int c; + std::vector<String>::iterator i; + printm(M_ERROR, "Error detected, showing context.\n"); + for (i = context.begin(), c = 0; i != context.end(); i++, c++) { + printm(M_ERROR, " (%i) - " + *i + "\n", c); + } + + printm(M_ERROR, " Error description: " + err); + + xexception(err); +} diff --git a/lib/String.cc b/lib/String.cc index bd265a0..75d9d15 100644 --- a/lib/String.cc +++ b/lib/String.cc @@ -331,6 +331,18 @@ char String::operator[](size_t i) const { } } +char & String::operator[](size_t i) { + static char zero; + + zero = 0; + + if (i >= siz) { + return zero; + } else { + return str[i]; + } +} + ssize_t String::strchr(char c, size_t from) const { for (size_t i = from; i < siz; i++) { if (str[i] == c) return i; |