From c607661ffaed980ddf4881462014799f97b17281 Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 24 Oct 2014 11:12:03 +0200 Subject: Initial commit --- .gitignore | 3 +++ Makefile | 5 ++++ lolcat.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 lolcat.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a2a2fbd --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +lolcat +.*.swo +.*.swp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..40dbecd --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ + +all: lolcat + +lolcat: lolcat.c + gcc -std=c99 -Wall -o lolcat lolcat.c diff --git a/lolcat.c b/lolcat.c new file mode 100644 index 0000000..f136ffd --- /dev/null +++ b/lolcat.c @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +#include +#include + +#define ARRAY_SIZE(foo) (sizeof(foo)/sizeof(foo[0])) +char codes[] = {39,38,44,43,49,48,84,83,119,118,154,148,184,178,214,208,209,203,204,198,199,163,164,128,129,93,99,63,69,33}; + +void usage(){ + printf("Usage: lolcat [-h horizontal_speed] [-v vertical_speed] [--] [FILES...]\n"); + exit(1); +} + +int main(int argc, char **argv){ + int c, cc=-1, i, l=0; + double freq_h = 0.23, freq_v = 0.1; + + for(i=1;i 0){ + if(c == '\n'){ + l++; + i = 0; + }else if(isprint(c)){ + int ncc = (int)((i++)*freq_h + l*freq_v); + if(ncc != cc) + printf("\033[38;5;%hhum", codes[(cc = ncc) % ARRAY_SIZE(codes)]); + } + printf("%lc", c); + } + if(c != WEOF){ + fprintf(stderr, "Error reading input file \"%s\": %s (%d)\n", *filename, strerror(errno), errno); + return 2; + } + + fclose(f); + } +} -- cgit