ascii-gen

simple ascii image converter
git clone git://git.jakekoroman.com/ascii-gen
Log | Files | Refs | README

commit 0cd317758c4d173d04789a15364cd074ec893d7a
parent 551440fd1dd49aea04e3f8c38d7cf8156d07124a
Author: Jake Koroman <jakekoroman@gmail.com>
Date:   Tue,  8 Oct 2024 14:18:12 -0400

ascii_gen.c: updated formatting and added inverted option.

Diffstat:
Mascii_gen.c | 147++++++++++++++++++++++++++++++++++++++++++-------------------------------------
1 file changed, 79 insertions(+), 68 deletions(-)

diff --git a/ascii_gen.c b/ascii_gen.c @@ -20,6 +20,7 @@ typedef uint8_t uint8; #define SET_LONG "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\\|()1{}[]?-_+~<>i!lI;:,\"^`'. " #define SET_SIZE_LONG 70 #define SET_SHORT "@%#*+=-:. " +#define SET_SHORT_INVERTED " .:-=+*#%@" #define SET_SIZE_SHORT 10 typedef enum { @@ -36,6 +37,7 @@ typedef struct { int set_size; int scale; bool debug; + bool inverted; } Options; internal inline int @@ -54,6 +56,7 @@ print_docs(const char *fname) printf(" -S: The character set that will be used to generate the output, defaults to the builtin 'short' character set\n"); printf(" -l: Uses the builtin 'long' character set for generating the output\n"); printf(" -t: Uses the builtin 'short' character set for generating the output\n"); + printf(" -i: Uses the builtin 'short' character set but inverted\n"); printf(" -v: Shows debug info\n"); } @@ -65,82 +68,90 @@ parse_args(int argc, char **argv, Options *options) int opt; options->scale = 1; - while ((opt = getopt(argc, argv, ":o:hls:S:vc")) != -1) + while ((opt = getopt(argc, argv, ":o:hls:S:vic")) != -1) { switch (opt) { - case 'o': - { - strncpy(options->out_file, optarg, BUF_CAP); - } break; - - case 'h': - { - print_docs(argv[0]); - exit(0); - } break; - - case 's': - { - options->scale = atoi(optarg); - if (options->scale == 0) { - fprintf(stderr, "Invalid scale '%s'\n", optarg); - exit(69); - } - } break; - - case 'v': - { - options->debug = true; - } break; - - case 'l': - { - options->set_type = SET_TYPE_LONG; - options->set_size = SET_SIZE_LONG; - strncpy(options->set, SET_LONG, BUF_CAP); - } break; - - case 't': // 't' for tiny I guess? wanted to keep 's' for scale - { - // Redundant because it will default to short but sometimes - // it's nice to request it even though its default. - options->set_type = SET_TYPE_SHORT; - } break; - - case 'S': - { - int size = strnlen(optarg, BUF_CAP); - - options->set_size = size; - options->set_type = SET_TYPE_CUSTOM; - strncpy(options->set, optarg, size); - printf("sizeof input: %d\n", size); - } break; - - case '?': - { - printf("Unknown Option: %c\n", optopt); - exit(69); - } break; - - case ':': - { - printf("Missing arg for %c\n", optopt); - exit(69); - } break; - - default: - { - printf("Something broke\n"); - break; - } + case 'o': + { + strncpy(options->out_file, optarg, BUF_CAP); + } break; + + case 'h': + { + print_docs(argv[0]); + exit(0); + } break; + + case 's': + { + options->scale = atoi(optarg); + if (options->scale == 0) { + fprintf(stderr, "Invalid scale '%s'\n", optarg); + exit(69); + } + } break; + + case 'v': + { + options->debug = true; + } break; + + case 'l': + { + options->set_type = SET_TYPE_LONG; + options->set_size = SET_SIZE_LONG; + strncpy(options->set, SET_LONG, BUF_CAP); + } break; + + case 't': // 't' for tiny I guess? wanted to keep 's' for scale + { + // Redundant because it will default to short but sometimes + // it's nice to request it even though its default. + options->set_type = SET_TYPE_SHORT; + } break; + + case 'i': + { + options->inverted = true; + } break; + + case 'S': + { + int size = strnlen(optarg, BUF_CAP); + + options->set_size = size; + options->set_type = SET_TYPE_CUSTOM; + strncpy(options->set, optarg, size); + printf("sizeof input: %d\n", size); + } break; + + case '?': + { + printf("Unknown Option: %c\n", optopt); + exit(69); + } break; + + case ':': + { + printf("Missing arg for %c\n", optopt); + exit(69); + } break; + + default: + { + printf("Something broke\n"); + break; + } } } if (options->set_type == SET_TYPE_SHORT) { options->set_size = SET_SIZE_SHORT; - strncpy(options->set, SET_SHORT, BUF_CAP); + if (options->inverted) + strncpy(options->set, SET_SHORT_INVERTED, BUF_CAP); + else + strncpy(options->set, SET_SHORT, BUF_CAP); } if (optind < argc) {