/* gutenfetch - a small utility to list and fetch books available through project gutenberg Copyright (C) 2001, 2002, 2003 Russell Francis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc. 59 Temple Place, Suite 330 Boston, MA 02111-1307 USA Last updated on $Date: 2004/03/21 05:14:13 $ by $Author: johntabularasa $. */ #include "stddefs.h" #include "libgutenfetch_error.h" #ifdef HAVE_STRING_H # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_STDIO_H # include #endif #ifdef HAVE_ERRNO_H # include #endif #ifdef HAVE_STDLIB_H # include #endif static char *error_messages[NUM_OF_ERRORS]; /** * Initialize internal variables of the error code. * * This function builds a table of error strings, to be * used later if something bad should happen. */ void gutenfetch_error_init(void) { error_messages[GUTENFETCH_OK] = (char*)_("The operation was successful."); error_messages[GUTENFETCH_UNRECOGNIZED_ERROR] = (char*)_("The error code is unrecognized."); error_messages[GUTENFETCH_SEE_ERRNO] = (char*)""; error_messages[GUTENFETCH_NOMEM] = (char*)_("Memory allocation failure."); error_messages[GUTENFETCH_CURL_GLOBAL_INIT_FAILED] = (char*)_("The global initialization of CURL failed."); error_messages[GUTENFETCH_CURL_PERFORM_FAILED] = (char*)_("CURL was unable to perform the requested file transfer."); error_messages[GUTENFETCH_CURL_GET_HANDLE_FAILED] = (char*)_("An attempt to get a CURL handle has failed."); error_messages[GUTENFETCH_BAD_PARAM] = (char*)_("A bad parameter has been passed to an internal function."); error_messages[GUTENFETCH_NO_ACTIVE_SERVER] = (char*)_("There is no currently active gutenfetch server."); error_messages[GUTENFETCH_UNABLE_TO_DETAIL_LISTING] = (char*)_("Unable to detail the ebook listings."); error_messages[GUTENFETCH_UNABLE_TO_INIT_CACHE] = (char *)_("Unable to initialize the cache directory."); } /** * Release the resources used by the error code. */ void gutenfetch_error_shutdown(void) { } /** * Convert a gutenfetch_error_t code into a human readable string. * * @param error_code The numeric representation of the error. * @return A NULL-terminated human-readable error string. */ const char * gutenfetch_error_to_string(gutenfetch_error_t error_code) { char *errmsg = NULL; switch (error_code) { case GUTENFETCH_SEE_ERRNO: errmsg = strerror(errno); break; case GUTENFETCH_BAD_PARAM: case GUTENFETCH_NOMEM: case GUTENFETCH_CURL_GLOBAL_INIT_FAILED: case GUTENFETCH_CURL_GET_HANDLE_FAILED: case GUTENFETCH_CURL_PERFORM_FAILED: case GUTENFETCH_NO_ACTIVE_SERVER: case GUTENFETCH_UNABLE_TO_DETAIL_LISTING: case GUTENFETCH_UNABLE_TO_INIT_CACHE: case GUTENFETCH_OK: errmsg = error_messages[error_code]; break; case GUTENFETCH_UNRECOGNIZED_ERROR: default: errmsg = error_messages[GUTENFETCH_UNRECOGNIZED_ERROR]; break; } return errmsg; }