initial commit uwu

main
anna 2 years ago
commit 6f259485b2
Signed by: fef
GPG Key ID: EC22E476DC2D3D84

1
.gitignore vendored

@ -0,0 +1 @@
gaycat

@ -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
```

@ -0,0 +1,61 @@
.\" Copyright (C) 2021 fef <owo@fef.moe>. 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.

@ -0,0 +1,74 @@
/*
* Copyright (C) 2021 fef <owo@fef.moe>. 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 <errno.h>
#include <stdio.h>
#include <string.h>
#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;
}
}
}
}
Loading…
Cancel
Save