From 188f3acc54bc6c072acccf858bf3c97a02547292 Mon Sep 17 00:00:00 2001 From: 8nl <8nlight@disroot.org> Date: Fri, 12 Jan 2024 16:55:46 +0000 Subject: [PATCH] Upload files to "/" --- Makefile | 2 +- cutecat.c | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index b139e77..6f1ae59 100644 --- a/Makefile +++ b/Makefile @@ -2,4 +2,4 @@ CC?=cc CFLAGS?=-Os -s all: - $(CC) $(CFLAGS) cutecat.c -o cutecat + $(CC) $(CFLAGS) cutecat.c -o cutecat -lm diff --git a/cutecat.c b/cutecat.c index 982d87d..7483a43 100644 --- a/cutecat.c +++ b/cutecat.c @@ -5,15 +5,18 @@ #include #include #include +#include +#define FREQ 220 unsigned int d_flag; -char eyes[] = {'U', 'O'}; +unsigned int r_flag; void OwO(char *buf, off_t len) { if (d_flag) return; - for (int i = 0; i < len / 10; i++) { + char eyes[] = {'U', 'O'}; + for (int i = 0; i < len; i++) { size_t i = rand() % len; if (i + 3 < len && !isspace(buf[i]) && !isspace(buf[i + 1]) && !isspace(buf[i + 2])) { @@ -26,6 +29,14 @@ void OwO(char *buf, off_t len) { } } +void PrintRainbow(char c, off_t i) { + int red = sin(FREQ * i) * 127 + 128; + int blue = sin(FREQ * i + 2 * M_PI / 3) * 127 + 128; + int green = sin(FREQ * i + 4 * M_PI / 3) * 127 + 128; + + printf("\033[38;2;%d;%d;%dm%c\033[0m", red, green, blue, c); +} + int cat(const char *path) { int fd = STDIN_FILENO; @@ -37,13 +48,18 @@ int cat(const char *path) { return 1; } - char buf[513]; + char buf[1025]; off_t len = 0; + while ((len = read(fd, buf, sizeof(buf))) > 0) { OwO(buf, len); - if (write(STDOUT_FILENO, buf, len) != len) { - fprintf(stderr, "cutecat: %s\n", strerror(errno)); - return 1; + + for (off_t i = 0; i < len; i++) { + if (!isspace(buf[i]) && !r_flag) + PrintRainbow(buf[i], i); + + else + putchar(buf[i]); } } @@ -55,14 +71,18 @@ int cat(const char *path) { int main(int argc, char **argv) { int opt; - while ((opt = getopt(argc, argv, "d")) != -1) { + while ((opt = getopt(argc, argv, "dr")) != -1) { switch (opt) { case 'd': d_flag = 1; break; + case 'r': + r_flag = 1; + break; + default: - printf("cutecat [file1 file2...]\n\t[-d Default mode]\n"); + printf("cutecat [file1 file2...]\n\t[-d Default mode]\n\t[-r Print without colorise text]\n"); return 0; } }