/* tiger -- Tiger print standard input to standard output.
Copyright (C) 2022 Remington Furman
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include
#include
#include
#include
#include
#include "tiger.h"
#include "leopard.h"
void usage(char *name) {
printf("usage: cat file | %s [-i] [-h] \n", name);
printf(" -i invert pattern\n");
printf(" -h print this help\n");
}
int main(int argc, char **argv) {
int width = tiger_width;
int height = tiger_height;
unsigned char *image = tiger_bits;
int opt_invert = 0;
if (strstr(argv[0], "tiger") != NULL) {
width = tiger_width;
height = tiger_height;
image = tiger_bits;
}
else if (strstr(argv[0], "leopard") != NULL) {
width = leopard_width;
height = leopard_height;
image = leopard_bits;
}
int opt;
while ((opt = getopt(argc, argv, "ih")) != -1) {
switch (opt) {
case 'i':
opt_invert = 0x1;
break;
case 'h':
usage(argv[0]);
exit(EXIT_SUCCESS);
break;
default:
usage(argv[0]);
exit(EXIT_FAILURE);
}
}
int x = 0;
int y = 0;
char c;
while ((c = getc(stdin)) != EOF) {
if (c == '\n') {
x = 0;
y = (y+1) % height;
}
else if (c == '\t') {
x = (x+8) % width;
}
else if (isgraph(c)) {
x = (x+1) % width;
unsigned char byte = image[y*width + x>>3];
unsigned char pixel = (byte >> (x&7)) & 1;
pixel ^= opt_invert;
c = pixel ? c : ' ';
}
putchar(c);
}
}