Upload files to "/"

This commit is contained in:
8nl 2024-01-12 16:55:46 +00:00
parent 8aeef44559
commit 188f3acc54
2 changed files with 29 additions and 9 deletions

View File

@ -2,4 +2,4 @@ CC?=cc
CFLAGS?=-Os -s
all:
$(CC) $(CFLAGS) cutecat.c -o cutecat
$(CC) $(CFLAGS) cutecat.c -o cutecat -lm

View File

@ -5,15 +5,18 @@
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <math.h>
#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;
}
}