From 805229c3b5a9b5078a273d175140b42445fd501a Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 26 Apr 2005 07:53:37 +0000 Subject: Made variable argument pushError method --- src/error.cc | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) (limited to 'src/error.cc') diff --git a/src/error.cc b/src/error.cc index 4e3f045..34c8e33 100644 --- a/src/error.cc +++ b/src/error.cc @@ -22,42 +22,30 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - #include #include "error.h" +#include +#include + Error::Error() { // Initialize lastError = NULL; - pthread_mutex_init (&mutex, NULL); } + Error::~Error() { } -/* - pthread_mutex_lock(&mutex); - // ... do something - pthread_mutex_unlock(&mutex); - - */ bool Error::hasError() { return lastError != NULL; } -/* // Perhaps! -string Error::popAllErrorStrings() -{ - string le = lastError; - removeError(); - return le; -} -*/ string Error::popErrorString() { @@ -72,30 +60,30 @@ string Error::popErrorString() return le; } -void Error::pushError(char* errstr) + +void Error::pushError(char *fmt, ...) { - pthread_mutex_lock(&mutex); - printf("New Error: [%s]\n", errstr); + char buf[1024]; - _err_entry *err = new _err_entry; + pthread_mutex_lock(&mutex); - err->errstr = errstr; - err->prev = lastError; - lastError = err; - pthread_mutex_unlock(&mutex); -} + va_list argp; + va_start(argp, fmt); + fprintf(stderr, "New Error: ["); + vfprintf(stderr, fmt, argp); + fprintf(stderr, "]\n"); fflush(stderr); + vsprintf(buf, fmt, argp); + va_end(argp); -void Error::pushError(string &errstr) -{ - pthread_mutex_lock(&mutex); _err_entry *err = new _err_entry; - err->errstr = errstr; + err->errstr = string(buf); err->prev = lastError; lastError = err; pthread_mutex_unlock(&mutex); } + void Error::removeAllErrors() { while(lastError) popErrorString(); -- cgit v1.2.3