libansilove

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

commit 855e94d96f138b3712f1035a49d16f5f3506db01
parent 48698a2e6a2edeb72e4ec93021eb34db0dffdfa7
Author: Frederic Cambus <fred@statdns.com>
Date:   Sun, 21 Oct 2018 18:19:30 +0200

Switch back to using int32_t for columns and rows variables, using uint32_t complicated things and introduced bugs

Diffstat:
Minclude/ansilove.h | 2+-
Msrc/loaders/ansi.c | 18+++++++++---------
Msrc/loaders/binary.c | 3++-
Msrc/loaders/tundra.c | 5+++--
4 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/include/ansilove.h b/include/ansilove.h @@ -72,7 +72,7 @@ struct ansilove_ctx { struct ansilove_options { int font; uint32_t bits; - uint32_t columns; + int32_t columns; int mode; bool diz; bool icecolors; diff --git a/src/loaders/ansi.c b/src/loaders/ansi.c @@ -17,8 +17,8 @@ // Character structure struct ansiChar { - uint32_t column; - uint32_t row; + int32_t column; + int32_t row; uint32_t background; uint32_t foreground; uint32_t current_character; @@ -42,7 +42,7 @@ int ansilove_ansi(struct ansilove_ctx *ctx, struct ansilove_options *options) // Default to 80 columns if columns option wasn't set options->columns = options->columns ? options->columns : 80; - uint32_t columns = options->columns; + int32_t columns = options->columns; bool ced = false; bool transparent = false; @@ -84,8 +84,8 @@ int ansilove_ansi(struct ansilove_ctx *ctx, struct ansilove_options *options) bool bold = false, underline = false, italics = false, blink = false, invert = false; // positions - uint32_t column = 0, row = 0, columnMax = 0, rowMax = 0; - uint32_t saved_row = 0, saved_column = 0; + int32_t column = 0, row = 0, columnMax = 0, rowMax = 0; + int32_t saved_row = 0, saved_column = 0; // sequence parsing variables uint32_t seqValue, seq_line, seq_column; @@ -225,10 +225,10 @@ int ansilove_ansi(struct ansilove_ctx *ctx, struct ansilove_options *options) uint32_t seq_column = strtonum(seqGrab, 0, UINT32_MAX, &errstr); free(seqGrab); - if (seq_column && column >= seq_column) - column -= seq_column; - else if (column > 0) - column--; + column -= seq_column ? seq_column : 1; + + if (column < 0) + column = 0; loop += ansi_sequence_loop+2; break; diff --git a/src/loaders/binary.c b/src/loaders/binary.c @@ -55,7 +55,8 @@ int ansilove_binary(struct ansilove_ctx *ctx, struct ansilove_options *options) // process binary uint32_t character, attribute, background, foreground; - uint32_t loop = 0, column = 0, row = 0; + uint32_t loop = 0; + int32_t column = 0, row = 0; while (loop < ctx->length) { if (column == options->columns) { diff --git a/src/loaders/tundra.c b/src/loaders/tundra.c @@ -32,7 +32,7 @@ int ansilove_tundra(struct ansilove_ctx *ctx, struct ansilove_options *options) char tundra_version; options->columns = options->columns ? options->columns : 80; - uint32_t columns = options->columns; + int32_t columns = options->columns; // font selection alSelectFont(&fontData, options->font); @@ -51,7 +51,8 @@ int ansilove_tundra(struct ansilove_ctx *ctx, struct ansilove_options *options) // read tundra file a first time to find the image size uint32_t cursor, character, background = 0, foreground = 0; - uint32_t loop = 9, column = 0, row = 1; + uint32_t loop = 9; + int32_t column = 0, row = 1; while (loop < ctx->length) { if (column == columns) {