libansilove

Library for converting ANSI, ASCII, and other formats to PNG
Log | Files | Refs | README | LICENSE

commit acbcd877c37523a7ead6b685d073b158fadee884
parent fa43fecd6d3a4f30c710090823b1e744d8cf6273
Author: Frederic Cambus <fred@statdns.com>
Date:   Fri, 19 Oct 2018 14:08:56 +0200

Add an ansilove_error() function to return an error string

Diffstat:
MCMakeLists.txt | 2+-
Minclude/ansilove.h | 2+-
Asrc/error.c | 42++++++++++++++++++++++++++++++++++++++++++
3 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -21,7 +21,7 @@ find_path(GD_INCLUDE_DIRS gd.h) find_library(GD_LIBRARIES NAMES gd REQUIRED) include_directories(${GD_INCLUDE_DIRS}) -set(SRC src/drawchar.c src/fonts.c src/loadfile.c src/init.c src/output.c src/savefile.c) +set(SRC src/drawchar.c src/fonts.c src/error.c src/loadfile.c src/init.c src/output.c src/savefile.c) set(LOADERS src/loaders/ansi.c src/loaders/artworx.c src/loaders/binary.c src/loaders/icedraw.c src/loaders/pcboard.c src/loaders/tundra.c src/loaders/xbin.c) if(NOT HAVE_STRTONUM) diff --git a/include/ansilove.h b/include/ansilove.h @@ -82,7 +82,7 @@ struct ansilove_options { }; int ansilove_init(struct ansilove_ctx *, struct ansilove_options *); - +char* ansilove_error(struct ansilove_ctx *); int ansilove_loadfile(struct ansilove_ctx *, char *); int ansilove_savefile(struct ansilove_ctx *, char *); diff --git a/src/error.c b/src/error.c @@ -0,0 +1,42 @@ +// +// error.c +// AnsiLove/C +// +// Copyright (c) 2011-2018 Stefan Vogt, Brian Cassidy, and Frederic Cambus. +// All rights reserved. +// +// This source code is licensed under the BSD 2-Clause License. +// See the LICENSE file for details. +// + +#include <fcntl.h> +#include <unistd.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include "ansilove.h" + +char* +ansilove_error(struct ansilove_ctx *ctx) { + if (ctx == NULL) + return NULL; + + switch (ctx->error) { + case ANSILOVE_INVALID_PARAM: + return "Invalid parameter."; + break; + case ANSILOVE_FORMAT_ERROR: + return "File format error."; + break; + case ANSILOVE_MEMORY_ERROR: + return "Memory allocation error."; + break; + case ANSILOVE_FILE_ERROR: + return "File error."; + break; + case ANSILOVE_GD_ERROR: + return "GD error."; + break; + default: + return NULL; + } +}