ansilove

ANSI and ASCII art to PNG converter in C
Log | Files | Refs | README | LICENSE

commit f84f95ee61500411fc7c9802759429680aee15d9
parent a940469c3e6db10762aafff0b81ef82819c4deaf
Author: Frederic Cambus <fred@statdns.com>
Date:   Sat, 15 Apr 2017 00:22:51 +0200

Remove the custom substr function, and call strndup directly

Diffstat:
MCMakeLists.txt | 2+-
Msrc/ansilove.h | 1-
Msrc/loaders/ansi.c | 18+++++++++++-------
Dsrc/substr.c | 22----------------------
Dsrc/substr.h | 19-------------------
5 files changed, 12 insertions(+), 50 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -18,7 +18,7 @@ find_path(GD_INCLUDE_DIRS gd.h) find_library(GD_LIBRARIES NAMES gd REQUIRED) include_directories(${GD_INCLUDE_DIRS}) -set(SRC src/main.c src/fonts.c src/ansilove.c src/explode.c src/strtolower.c src/substr.c src/sauce.c) +set(SRC src/main.c src/fonts.c src/ansilove.c src/explode.c src/strtolower.c src/sauce.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) diff --git a/src/ansilove.h b/src/ansilove.h @@ -18,7 +18,6 @@ #include <gd.h> #include "config.h" #include "fonts.h" -#include "substr.h" #include "explode.h" #include "sauce.h" diff --git a/src/loaders/ansi.c b/src/loaders/ansi.c @@ -9,6 +9,10 @@ // See the file LICENSE for details. // +#define _XOPEN_SOURCE 700 +#define _NETBSD_SOURCE +#include <string.h> + #include "ansi.h" void ansi(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, char *retinaout, char *font, int32_t bits, char *mode, bool icecolors, char *fext, bool createRetinaRep) @@ -125,7 +129,7 @@ void ansi(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, c if (ansi_sequence_character == 'H' || ansi_sequence_character == 'f') { // create substring from the sequence's content - seqGrab = substr((char *)inputFileBuffer, loop+2, ansi_sequence_loop); + seqGrab = strndup((char *)inputFileBuffer + loop + 2, ansi_sequence_loop); // create sequence content array seqArrayCount = explode(&seqArray, ';', seqGrab); @@ -152,7 +156,7 @@ void ansi(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, c if (ansi_sequence_character=='A') { // create substring from the sequence's content - seqGrab = substr((char *)inputFileBuffer, loop+2, ansi_sequence_loop); + seqGrab = strndup((char *)inputFileBuffer + loop + 2, ansi_sequence_loop); // now get escape sequence's position value int32_t seq_line = strtonum(seqGrab, 0, INT32_MAX, &errstr); @@ -171,7 +175,7 @@ void ansi(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, c if (ansi_sequence_character=='B') { // create substring from the sequence's content - seqGrab = substr((char *)inputFileBuffer, loop+2, ansi_sequence_loop); + seqGrab = strndup((char *)inputFileBuffer + loop + 2, ansi_sequence_loop); // now get escape sequence's position value int32_t seq_line = strtonum(seqGrab, 0, INT32_MAX, &errstr); @@ -190,7 +194,7 @@ void ansi(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, c if (ansi_sequence_character=='C') { // create substring from the sequence's content - seqGrab = substr((char *)inputFileBuffer, loop+2, ansi_sequence_loop); + seqGrab = strndup((char *)inputFileBuffer + loop + 2, ansi_sequence_loop); // now get escape sequence's position value int32_t seq_column = strtonum(seqGrab, 0, INT32_MAX, &errstr); @@ -214,7 +218,7 @@ void ansi(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, c if (ansi_sequence_character=='D') { // create substring from the sequence's content - seqGrab = substr((char *)inputFileBuffer, loop+2, ansi_sequence_loop); + seqGrab = strndup((char *)inputFileBuffer + loop + 2, ansi_sequence_loop); // now get escape sequence's content length int32_t seq_column = strtonum(seqGrab, 0, INT32_MAX, &errstr); @@ -258,7 +262,7 @@ void ansi(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, c if (ansi_sequence_character=='J') { // create substring from the sequence's content - seqGrab = substr((char *)inputFileBuffer, loop+2, ansi_sequence_loop); + seqGrab = strndup((char *)inputFileBuffer + loop + 2, ansi_sequence_loop); // convert grab to an integer int32_t eraseDisplayInt = strtonum(seqGrab, 0, INT32_MAX, &errstr); @@ -284,7 +288,7 @@ void ansi(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, c if (ansi_sequence_character=='m') { // create substring from the sequence's content - seqGrab = substr((char *)inputFileBuffer, loop+2, ansi_sequence_loop); + seqGrab = strndup((char *)inputFileBuffer + loop + 2, ansi_sequence_loop); // create sequence content array seqArrayCount = explode(&seqArray, ';', seqGrab); diff --git a/src/substr.c b/src/substr.c @@ -1,22 +0,0 @@ -// -// substr.c -// AnsiLove/C -// -// Copyright (C) 2011-2017 Stefan Vogt, Brian Cassidy, and Frederic Cambus. -// All rights reserved. -// -// This source code is licensed under the BSD 2-Clause License. -// See the file LICENSE for details. -// - -#define _XOPEN_SOURCE 700 -#define _NETBSD_SOURCE -#include <string.h> - -char *substr(char *str, size_t begin, size_t len) -{ - if (str == 0 || strlen(str) == 0) - return 0; - - return strndup(str + begin, len); -} diff --git a/src/substr.h b/src/substr.h @@ -1,19 +0,0 @@ -// -// substr.h -// AnsiLove/C -// -// Copyright (C) 2011-2017 Stefan Vogt, Brian Cassidy, and Frederic Cambus. -// All rights reserved. -// -// This source code is licensed under the BSD 2-Clause License. -// See the file LICENSE for details. -// - -#ifndef substr_h -#define substr_h - -// Returns portion of a string specified by start and length parameters. - -char *substr(char *str, size_t begin, size_t len); - -#endif