commit 729969a6adb83150601dbe6941e0ef2594500d7a
parent 0c29f1c9ed52ac60b5bc5f74a7840d1f23b96b71
Author: Frederic Cambus <fred@statdns.com>
Date: Tue, 18 Dec 2018 14:04:25 +0100
Use function pointers to call the appropriate loader, this will make error handling easier
Diffstat:
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/main.c b/src/main.c
@@ -235,27 +235,31 @@ main(int argc, char *argv[])
ctx.length -= 129 - (saucerec->comments > 0 ? 5 + 64 * saucerec->comments : 0);
}
+ int (*loader)(struct ansilove_ctx *, struct ansilove_options *);
+
/* create the output PNG data by invoking the appropiate function */
if (!strcmp(fext, ".pcb")) {
- ansilove_pcboard(&ctx, &options);
+ loader = ansilove_pcboard;
fileIsPCBoard = true;
} else if (!strcmp(fext, ".bin")) {
- ansilove_binary(&ctx, &options);
+ loader = ansilove_binary;
fileIsBinary = true;
} else if (!strcmp(fext, ".adf")) {
- ansilove_artworx(&ctx, &options);
+ loader = ansilove_artworx;
} else if (!strcmp(fext, ".idf")) {
- ansilove_icedraw(&ctx, &options);
+ loader = ansilove_icedraw;
} else if (!strcmp(fext, ".tnd")) {
- ansilove_tundra(&ctx, &options);
+ loader = ansilove_tundra;
fileIsTundra = true;
} else if (!strcmp(fext, ".xb")) {
- ansilove_xbin(&ctx, &options);
+ loader = ansilove_xbin;
} else {
- ansilove_ansi(&ctx, &options);
+ loader = ansilove_ansi;
fileIsANSi = true;
}
+ loader(&ctx, &options);
+
/* create the output file */
if (ansilove_savefile(&ctx, fileName) == -1) {
fprintf(stderr, "\n%s\n", ansilove_error(&ctx));