libansilove

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

commit c64a1949775d4fde74884adbdb120b20f688f1b6
parent 3ecc01f1401dbd2b727e78f1ee506955d8b2e808
Author: Frederic Cambus <fred@statdns.com>
Date:   Sun, 15 Jul 2018 22:50:08 +0200

Get rid of explode, we now use standard C functions to parse ANSI sequences

Diffstat:
MCMakeLists.txt | 2+-
MTODO | 1-
Msrc/ansilove.h | 1-
Dsrc/explode.c | 40----------------------------------------
Dsrc/explode.h | 27---------------------------
5 files changed, 1 insertion(+), 70 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/explode.c src/output.c) +set(SRC src/drawchar.c src/fonts.c src/output.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/TODO b/TODO @@ -1,4 +1,3 @@ -- Use standard C functions to parse ANSI sequences and get rid of explode - Increment ansi_buffer by more than one element at a time when using realloc in order to avoid wasting memory. Switch to OpenBSD reallocarray? - Use include-what-you-use to remove unnecessary headers diff --git a/src/ansilove.h b/src/ansilove.h @@ -12,7 +12,6 @@ #include "../include/ansilove.h" #include "config.h" #include "drawchar.h" -#include "explode.h" #include "fonts.h" #include "output.h" #include <gd.h> diff --git a/src/explode.c b/src/explode.c @@ -1,40 +0,0 @@ -// -// explode.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 "explode.h" - -int32_t explode(char ***arr_ptr, char delimiter, char *str) { - char *src = str, *end, *dst; - char **arr; - int32_t size = 1, i; - - while ((end = strchr(src, delimiter)) != NULL) { - ++size; - src = end + 1; - } - - arr = malloc(size * sizeof (char *) + (strlen(str) + 1) * sizeof (char)); - - src = str; - dst = (char *)arr + size * sizeof (char *); - for (i = 0; i < size; ++i) { - if ((end = strchr(src, delimiter)) == NULL) - end = src + strlen(src); - arr[i] = dst; - strncpy(dst, src, end - src); - dst[end - src] = '\0'; - dst += end - src + 1; - src = end + 1; - } - *arr_ptr = arr; - - return size; -} diff --git a/src/explode.h b/src/explode.h @@ -1,27 +0,0 @@ -// -// explode.h -// 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 <stdint.h> -#include <stdlib.h> -#include <string.h> - -#ifndef explode_h -#define explode_h - -// Converts a delimited string into a string array. Other than PHP's -// explode() function it will return an integer of strings found. I -// consider this as much better approach as you can access the strings -// via array pointer and you don't have to determine how many string -// instances were stored overall as this is what you're getting. - -int32_t explode(char ***arr_ptr, char delimiter, char *str); - -#endif