From 0a1ad13e6d89ceeb90b89a22b5577559c7c97366 Mon Sep 17 00:00:00 2001 From: pixel Date: Sun, 5 Oct 2003 19:14:04 +0000 Subject: Changes of the month --- lib/Exceptions.cc | 34 +++++++++++++++++++++++++++++++--- lib/String.cc | 12 ++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) (limited to 'lib') 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 -#endif #ifdef DEBUG #include #endif @@ -21,6 +18,8 @@ char GeneralException::t[BUFSIZ]; +std::vector 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::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; -- cgit v1.2.3