ansilove

ANSI and ASCII art to PNG converter in C
Log | Files | Refs | README | LICENSE

commit 75c3cb766f7b5fa5cd88a9db937e20b37099823f
parent 32d5d8c61ffbace91db0b9001424cfc153d798ca
Author: Frederic Cambus <fred@statdns.com>
Date:   Fri, 14 Feb 2020 17:27:11 +0100

Add a new '-t' which will allow overriding file type detection.

Diffstat:
Msrc/ansilove.c | 60++++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 38 insertions(+), 22 deletions(-)

diff --git a/src/ansilove.c b/src/ansilove.c @@ -77,6 +77,7 @@ main(int argc, char *argv[]) char *input = NULL, *output = NULL; char *fileName = NULL; char *font = NULL; + char *type = NULL; static struct ansilove_ctx ctx; static struct ansilove_options options; @@ -101,7 +102,7 @@ main(int argc, char *argv[]) if (ansilove_init(&ctx, &options) == -1) errx(EXIT_FAILURE, "%s", ansilove_error(&ctx)); - while ((getoptFlag = getopt(argc, argv, "b:c:df:him:o:qrR:sv")) != -1) { + while ((getoptFlag = getopt(argc, argv, "b:c:df:him:o:qrR:st:v")) != -1) { switch (getoptFlag) { case 'b': /* convert numeric command line flags to integer values */ @@ -166,6 +167,9 @@ main(int argc, char *argv[]) case 's': justDisplaySAUCE = true; break; + case 't': + type = optarg; + break; case 'v': version(); return EXIT_SUCCESS; @@ -232,27 +236,39 @@ main(int argc, char *argv[]) if (fileHasSAUCE && (record->flags & 1)) options.icecolors = true; - int (*loader)(struct ansilove_ctx *, struct ansilove_options *); - - /* create the output PNG data by invoking the appropriate function */ - if (!strcmp(fext, "pcb")) { - loader = ansilove_pcboard; - fileIsPCBoard = true; - } else if (!strcmp(fext, "bin")) { - loader = ansilove_binary; - fileIsBinary = true; - } else if (!strcmp(fext, "adf")) { - loader = ansilove_artworx; - } else if (!strcmp(fext, "idf")) { - loader = ansilove_icedraw; - } else if (!strcmp(fext, "tnd")) { - loader = ansilove_tundra; - fileIsTundra = true; - } else if (!strcmp(fext, "xb")) { - loader = ansilove_xbin; - } else { - loader = ansilove_ansi; - fileIsANSi = true; + int (*loader)(struct ansilove_ctx *, struct ansilove_options *) = NULL; + + /* if type was specified, attempt to find a loader */ + if (type) { + for (size_t loop = 0; loop < 7; loop++) { + if (!strncmp(types[loop], type, strlen(type))) { + loader = loaders[loop]; + break; + } + } + } + + /* fall back on extension if no loader was found */ + if (!loader) { + if (!strcmp(fext, "pcb")) { + loader = ansilove_pcboard; + fileIsPCBoard = true; + } else if (!strcmp(fext, "bin")) { + loader = ansilove_binary; + fileIsBinary = true; + } else if (!strcmp(fext, "adf")) { + loader = ansilove_artworx; + } else if (!strcmp(fext, "idf")) { + loader = ansilove_icedraw; + } else if (!strcmp(fext, "tnd")) { + loader = ansilove_tundra; + fileIsTundra = true; + } else if (!strcmp(fext, "xb")) { + loader = ansilove_xbin; + } else { + loader = ansilove_ansi; + fileIsANSi = true; + } } if (loader(&ctx, &options) == -1)