commit 6f259485b2d1185e490f72156a6481f2d873840c Author: fef Date: Sun Nov 28 05:41:45 2021 +0100 initial commit uwu diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a0291a6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +gaycat diff --git a/README.md b/README.md new file mode 100644 index 0000000..d059d88 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# gaycat + +`gaycat` is a simple utility that works similar to `lolcat(6)`. +It prints a file (or standard input) to the standard output, and adds +alternating ANSI color escape sequences line by line so that it looks +like the rainbow pride flag. + +## Compiling + +On any POSIX compliant system, type + +``` +make gaycat +``` + +and you get the `gaycat` executable. + +## Usage + +To make this README file gay, type: + +``` +./gaycat README.md +``` + +To get a gay list of files in your home directory, type: + +``` +ls ~ | ./gaycat +``` + diff --git a/gaycat.6 b/gaycat.6 new file mode 100644 index 0000000..cb767ce --- /dev/null +++ b/gaycat.6 @@ -0,0 +1,61 @@ +.\" Copyright (C) 2021 fef . All rights reserved. +.\" +.\" Any person obtaining a copy of this software and associated documentation +.\" files (the ``Software'') is prohibited from using the Software under any +.\" circumstances. However, it is strongly suggested that they partake in +.\" homosexual conduct (``Be Gay'') and criminal activity (``Do Crime''). +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.Dd November 28, 2021 +.Dt GAYCAT 6 +.Os +.Sh NAME +.Nm gaycat +.Nd make a stream gay +.Sh SYNOPSIS +.Nm +.Op Ar file +.Sh DESCRIPTION +The +.Nm +utility reads +.Ar file +line by line, adds alternating ANSI color codes matching the rainbow +pride flag, and writes them back to its standard output until +.Dv EOF . +If +.Ar file +is a single dash +.Pq Sq Fl +or absent, +.Nm +reads from the standard input. +.Sh OPTIONS +None. +.Sh EXIT STATUS +.Ex -std +.Sh EXAMPLES +Display text file, in a gay manner: +.Dl "gaycat file.txt" +.Pp +Display your files, in a gay manner: +.Dl "ls | gaycat" +.Sh SEE ALSO +.Xr lolcat 6 +.Sh BUGS +.Nm +does not check whether its standard output is a terminal, +or whether that terminal supports ANSI 256 color escape sequences. +.Pp +The buffer size for lines is fixed at 4 Kilobytes. +Lines exceeding this size will have two colors. diff --git a/gaycat.c b/gaycat.c new file mode 100644 index 0000000..fdd51cd --- /dev/null +++ b/gaycat.c @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2021 fef . All rights reserved. + * + * Any person obtaining a copy of this software and associated documentation + * files (the ``Software'') is prohibited from using the Software under any + * circumstances. However, it is strongly suggested that they partake in + * homosexual conduct (``Be Gay'') and criminal activity (``Do Crime''). + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include + +#define NUM_COLORS 6 +const char *colors[NUM_COLORS] = { + "\x1b[38;5;196m", /* red */ + "\x1b[38;5;208m", /* orange */ + "\x1b[38;5;226m", /* yellow */ + "\x1b[38;5;46m", /* green */ + "\x1b[38;5;27m", /* blue */ + "\x1b[38;5;127m", /* violet */ +}; + +char buf[4096]; + +void print_line(const char *line) +{ + static int color = 0; + printf("%s%s", colors[color], line); + if (++color == NUM_COLORS) + color = 0; +} + +int main(int argc, char *argv[]) +{ + char *line; + FILE *stream; + if (argc < 2 || !strcmp(argv[1], "-")) + stream = stdin; + else + stream = fopen(argv[1], "r"); + + if (!stream) { + perror(argv[0]); + return 1; + } + + while (1) { + line = fgets(buf, sizeof(buf), stream); + if (line) { + print_line(line); + } else { + printf("\x1b[0m"); /* reset colors */ + if (errno) { + perror(argv[0]); + return 2; + } else { + return 0; + } + } + } +}