nyancat

Unnamed repository; edit this file 'description' to name the repository.
git clone https://git.inz.fi/nyancat
Log | Files | Refs | README

commit 27ed7c32a15c28ff85a91f55190972b00d1fbcac
parent 3bc3ad41085ae6947f39912b0744a3eaf48bf4a3
Author: Santtu Lakkala <inz@inz.fi>
Date:   Mon, 20 Jul 2020 10:47:17 +0300

Type juggling

Diffstat:
Mnyancat.c | 46++++++++++++++++++++++++----------------------
1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/nyancat.c b/nyancat.c @@ -16,6 +16,8 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <stdbool.h> +#include <stdint.h> #include <math.h> @@ -38,14 +40,14 @@ struct lolcat { int h; int sx; int sy; - int fg; - int bg; - char bold; - char reverse; - char underline; - char was_bold; - char was_reverse; - char was_underline; + uint32_t fg; + uint32_t bg; + bool bold; + bool reverse; + bool underline; + bool was_bold; + bool was_reverse; + bool was_underline; void (*write)(const char *buffer, size_t buflen, void *data); void *write_data; @@ -148,22 +150,22 @@ static int _lc_arg_m(int arg, void *data) switch (arg) { case 0: - lc->bold = 0; - lc->reverse = 0; + lc->bold = false; + lc->reverse = false; lc->fg = 0xc0c0c0; lc->bg = 0x000000; break; case 1: - lc->bold = 1; + lc->bold = true; break; case 4: - lc->underline = 1; + lc->underline = true; break; case 7: - lc->reverse = 1; + lc->reverse = true; break; case 24: - lc->underline = 0; + lc->underline = false; break; case 30: case 31: @@ -234,9 +236,9 @@ static void _lc_colorize(struct lolcat *lc, const char *u8_char, size_t len) if ((lc->was_bold && !lc->bold) || (lc->was_reverse && !lc->reverse)) { - lc->was_underline = 0; - lc->was_bold = 0; - lc->was_reverse = 0; + lc->was_underline = false; + lc->was_bold = false; + lc->was_reverse = false; *bw++ = '0'; *bw++ = ';'; } @@ -250,12 +252,12 @@ static void _lc_colorize(struct lolcat *lc, const char *u8_char, size_t len) if (lc->bold && !lc->was_bold) { *bw++ = '1'; *bw++ = ';'; - lc->was_bold = 1; + lc->was_bold = true; } if (lc->reverse && !lc->was_reverse) { *bw++ = '7'; *bw++ = ';'; - lc->was_reverse = 1; + lc->was_reverse = true; } if (lc->bold) @@ -296,10 +298,10 @@ static int strnsplit_int(const char *str, size_t len, char delim, int n, ...) return n - data.n; } -ssize_t lc_process(struct lolcat *lc, const char *buffer, int32_t len) +ssize_t lc_process(struct lolcat *lc, const char *buffer, size_t len) { - int32_t i = 0; - int32_t ip = 0; + size_t i = 0; + size_t ip = 0; while (i < len) { UChar32 c; int eaw;