ansilove

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

commit cb3f18f71a296f721b11294a91ed3869bd6f32c2
parent c688793286c41a395c3572fbae43919b0196f5ef
Author: Frederic Cambus <fcambus@users.sourceforge.net>
Date:   Tue, 28 Jul 2015 20:16:26 +0200

Merge branch 'getopt'

Diffstat:
MCMakeLists.txt | 2+-
Msrc/ansilove.c | 64++++++++++++++++++----------------------------------------------
Msrc/ansilove.h | 14+++++++-------
Msrc/main.c | 489+++++++++++++++++++++++++++++++------------------------------------------------
4 files changed, 216 insertions(+), 353 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -4,7 +4,7 @@ project (ansilove C) find_library(LIB_GD NAMES gd REQUIRED) include_directories(/usr/local/include) -add_definitions(-Wall -std=c99 -pedantic) +add_definitions(-Wall -Wextra -std=c99 -pedantic) add_executable(ansilove src/main.c src/albinfonts.c src/ansilove.c src/explode.c src/filesize.c src/strtolower.c src/substr.c) diff --git a/src/ansilove.c b/src/ansilove.c @@ -38,7 +38,7 @@ void alDrawChar(gdImagePtr im, const unsigned char *font_data, int32_t int_bits, } // ANSi -void alAnsiLoader(char *input, char output[], char retinaout[], char font[], char bits[], char icecolors[], char *fext, bool createRetinaRep) +void alAnsiLoader(char *input, char *output, char *retinaout, char *font, int32_t int_bits, char *mode, char *icecolors, char *fext, bool createRetinaRep) { const unsigned char *font_data; @@ -196,25 +196,20 @@ void alAnsiLoader(char *input, char output[], char retinaout[], char font[], cha } // to deal with the bits flag, we declared handy bool types - if (strcmp(bits, "ced") == 0) { + if (strcmp(mode, "ced") == 0) { ced = true; } - else if (strcmp(bits, "transparent") == 0) { + else if (strcmp(mode, "transparent") == 0) { transparent = true; } - else if (strcmp(bits, "workbench") == 0) { + else if (strcmp(mode, "workbench") == 0) { workbench = true; } - else if (strcmp(bits, "workbench-transparent") == 0) { + else if (strcmp(mode, "workbench-transparent") == 0) { workbench = true; transparent = true; } - // force defaults... exactly now! - if (strcmp(bits, "8") != 0 && strcmp(bits, "9") != 0) { - sprintf(bits, "%s", "8"); - } - // load input file FILE *input_file = fopen(input, "r"); if (input_file == NULL) { @@ -227,7 +222,7 @@ void alAnsiLoader(char *input, char output[], char retinaout[], char font[], cha // next up is loading our file into a dynamically allocated memory buffer unsigned char *input_file_buffer; - size_t result; + int32_t result; // allocate memory to contain the whole file input_file_buffer = (unsigned char *) malloc(sizeof(unsigned char)*input_file_size); @@ -278,7 +273,6 @@ void alAnsiLoader(char *input, char output[], char retinaout[], char font[], cha gdImageColorTransparent(im_Font, 20); // convert numeric command line flags to integer values - int32_t int_bits = atoi(bits); int32_t int_icecolors = atoi(icecolors); // ANSi processing loops @@ -1018,7 +1012,7 @@ void alAnsiLoader(char *input, char output[], char retinaout[], char font[], cha } // PCB -void alPcBoardLoader(char *input, char *output, char *retinaout, char *font, char *bits, bool createRetinaRep) +void alPcBoardLoader(char *input, char *output, char *retinaout, char *font, int32_t int_bits, bool createRetinaRep) { // some type declarations int32_t font_size_x; @@ -1159,11 +1153,6 @@ void alPcBoardLoader(char *input, char *output, char *retinaout, char *font, cha font_size_y = 16; } - // now set bits to 8 if not already value 8 or 9 - if (strcmp(bits, "8") != 0 && strcmp(bits, "9") != 0) { - sprintf(bits, "%s", "8"); - } - // load input file FILE *input_file = fopen(input, "r"); if (input_file == NULL) { @@ -1176,7 +1165,7 @@ void alPcBoardLoader(char *input, char *output, char *retinaout, char *font, cha // next up is loading our file into a dynamically allocated memory buffer unsigned char *input_file_buffer; - size_t result; + int32_t result; // allocate memory to contain the whole file input_file_buffer = (unsigned char *) malloc(sizeof(unsigned char)*input_file_size); @@ -1197,9 +1186,6 @@ void alPcBoardLoader(char *input, char *output, char *retinaout, char *font, cha // libgd image pointers gdImagePtr im_PCB; - // convert numeric command line flags to integer values - int32_t int_bits = atoi(bits); - // defines for stripping PCBoard codes char *stripped_file_buffer; char **pcbStripCodes; @@ -1412,7 +1398,7 @@ void alPcBoardLoader(char *input, char *output, char *retinaout, char *font, cha } // BINARY -void alBinaryLoader(char *input, char output[], char retinaout[], char columns[], char font[], char bits[], char icecolors[], bool createRetinaRep) +void alBinaryLoader(char *input, char *output, char *retinaout, char *columns, char *font, int32_t int_bits, char *icecolors, bool createRetinaRep) { // some type declarations int32_t font_size_x; @@ -1552,11 +1538,6 @@ void alBinaryLoader(char *input, char output[], char retinaout[], char columns[] font_size_y = 16; } - // now set bits to 8 if not already value 8 or 9 - if (strcmp(bits, "8") != 0 && strcmp(bits, "9") != 0) { - sprintf(bits, "%s", "8"); - } - // load input file FILE *input_file = fopen(input, "r"); if (input_file == NULL) { @@ -1569,7 +1550,7 @@ void alBinaryLoader(char *input, char output[], char retinaout[], char columns[] // next up is loading our file into a dynamically allocated memory buffer unsigned char *input_file_buffer; - size_t result; + int32_t result; // allocate memory to contain the whole file input_file_buffer = (unsigned char *) malloc(sizeof(unsigned char)*input_file_size); @@ -1592,7 +1573,6 @@ void alBinaryLoader(char *input, char output[], char retinaout[], char columns[] // convert numeric command line flags to integer values int32_t int_columns = atoi(columns); - int32_t int_bits = atoi(bits); int32_t int_icecolors = atoi(icecolors); // allocate buffer image memory @@ -1687,7 +1667,7 @@ void alBinaryLoader(char *input, char output[], char retinaout[], char columns[] } // ADF -void alArtworxLoader(char *input, char output[], char retinaout[], char bits[], bool createRetinaRep) +void alArtworxLoader(char *input, char *output, char *retinaout, bool createRetinaRep) { const unsigned char *font_data; unsigned char *font_data_adf; @@ -1704,7 +1684,7 @@ void alArtworxLoader(char *input, char output[], char retinaout[], char bits[], // next up is loading our file into a dynamically allocated memory buffer unsigned char *input_file_buffer; - size_t result; + int32_t result; // allocate memory to contain the whole file input_file_buffer = (unsigned char *) malloc(sizeof(unsigned char)*input_file_size); @@ -1815,7 +1795,7 @@ void alArtworxLoader(char *input, char output[], char retinaout[], char bits[], } // IDF -void alIcedrawLoader(char *input, char output[], char retinaout[], char bits[], bool fileHasSAUCE, bool createRetinaRep) +void alIcedrawLoader(char *input, char *output, char *retinaout, bool fileHasSAUCE, bool createRetinaRep) { const unsigned char *font_data; unsigned char *font_data_idf; @@ -1832,7 +1812,7 @@ void alIcedrawLoader(char *input, char output[], char retinaout[], char bits[], // next up is loading our file into a dynamically allocated memory buffer unsigned char *input_file_buffer; - size_t result; + int32_t result; // allocate memory to contain the whole file input_file_buffer = (unsigned char *) malloc(sizeof(unsigned char)*input_file_size); @@ -2008,7 +1988,7 @@ void alIcedrawLoader(char *input, char output[], char retinaout[], char bits[], } // TUNDRA -void alTundraLoader(char *input, char output[], char retinaout[], char font[], char bits[], bool fileHasSAUCE, bool createRetinaRep) +void alTundraLoader(char *input, char *output, char *retinaout, char *font, int32_t int_bits, bool fileHasSAUCE, bool createRetinaRep) { int32_t columns = 80; int32_t font_size_x; @@ -2150,11 +2130,6 @@ void alTundraLoader(char *input, char output[], char retinaout[], char font[], c font_size_y = 16; } - // now set bits to 8 if not already value 8 or 9 - if (strcmp(bits, "8") != 0 && strcmp(bits, "9") != 0) { - sprintf(bits, "%s", "8"); - } - // load input file FILE *input_file = fopen(input, "r"); if (input_file == NULL) { @@ -2167,7 +2142,7 @@ void alTundraLoader(char *input, char output[], char retinaout[], char font[], c // next up is loading our file into a dynamically allocated memory buffer unsigned char *input_file_buffer; - size_t result; + int32_t result; // allocate memory to contain the whole file input_file_buffer = (unsigned char *) malloc(sizeof(unsigned char)*input_file_size); @@ -2196,9 +2171,6 @@ void alTundraLoader(char *input, char output[], char retinaout[], char font[], c // libgd image pointers gdImagePtr im_Tundra; - // convert numeric command line flags to integer values - int32_t int_bits = atoi(bits); - // extract tundra header tundra_version = input_file_buffer[0]; memcpy(&tundra_header,input_file_buffer+1,8); @@ -2381,7 +2353,7 @@ void alTundraLoader(char *input, char output[], char retinaout[], char font[], c } // XBIN -void alXbinLoader(char *input, char output[], char retinaout[], char bits[], bool createRetinaRep) +void alXbinLoader(char *input, char *output, char *retinaout, bool createRetinaRep) { const unsigned char *font_data; unsigned char *font_data_xbin; @@ -2398,7 +2370,7 @@ void alXbinLoader(char *input, char output[], char retinaout[], char bits[], boo // next up is loading our file into a dynamically allocated memory buffer unsigned char *input_file_buffer; - size_t result; + int32_t result; // allocate memory to contain the whole file input_file_buffer = (unsigned char *) malloc(sizeof(unsigned char)*input_file_size); diff --git a/src/ansilove.h b/src/ansilove.h @@ -30,13 +30,13 @@ void alDrawChar(gdImagePtr im, const unsigned char *font_data, int32_t int_bits, int32_t font_size_x, int32_t font_size_y, int32_t position_x, int32_t position_y, int32_t color_background, int32_t color_foreground, unsigned char character); -void alAnsiLoader(char *input, char output[], char retinaout[], char font[], char bits[], char icecolors[], char *fext, bool createRetinaRep); -void alPcBoardLoader(char *input, char output[], char retinaout[], char font[], char bits[], bool createRetinaRep); -void alBinaryLoader(char *input, char output[], char retinaout[], char columns[], char font[], char bits[], char icecolors[], bool createRetinaRep); -void alArtworxLoader(char *input, char output[], char retinaout[], char bits[], bool createRetinaRep); -void alIcedrawLoader(char *input, char output[], char retinaout[], char bits[], bool fileHasSAUCE, bool createRetinaRep); -void alTundraLoader(char *input, char output[], char retinaout[], char font[], char bits[], bool fileHasSAUCE, bool createRetinaRep); -void alXbinLoader(char *input, char output[], char retinaout[], char bits[], bool createRetinaRep); +void alAnsiLoader(char *input, char *output, char *retinaout, char *font, int32_t int_bits, char *mode, char *icecolors, char *fext, bool createRetinaRep); +void alPcBoardLoader(char *input, char *output, char *retinaout, char *font, int32_t int_bits, bool createRetinaRep); +void alBinaryLoader(char *input, char *output, char *retinaout, char *columns, char *font, int32_t int_bits, char *icecolors, bool createRetinaRep); +void alArtworxLoader(char *input, char *output, char *retinaout, bool createRetinaRep); +void alIcedrawLoader(char *input, char *output, char *retinaout, bool fileHasSAUCE, bool createRetinaRep); +void alTundraLoader(char *input, char *output, char *retinaout, char *font, int32_t int_bits, bool fileHasSAUCE, bool createRetinaRep); +void alXbinLoader(char *input, char *output, char *retinaout, bool createRetinaRep); // helper functions char *str_replace(const char *string, const char *substr, const char *replacement); diff --git a/src/main.c b/src/main.c @@ -13,6 +13,7 @@ #include <stdlib.h> #include <string.h> #include <stdbool.h> +#include <getopt.h> #include "alconfig.h" #include "strtolower.h" #include "substr.h" @@ -103,7 +104,6 @@ int main(int argc, char *argv[]) bool createRetinaRep = false; // analyze options and do what has to be done - bool outputIdentical = false; bool fileIsBinary = false; bool fileIsANSi = false; bool fileIsPCBoard = false; @@ -113,322 +113,213 @@ int main(int argc, char *argv[]) synopsis(); return EXIT_SUCCESS; } - if ((strcmp(argv[1], "-v") == 0) || (strcmp(argv[1], "--version") == 0)) { - versionInfo(); - return EXIT_SUCCESS; + + int getoptFlag; + char *bits = NULL; + char *mode = NULL; + char *columns = NULL; + char *font = NULL; + char *icecolors = NULL; + + char *input = NULL, *output = NULL; + char *retinaout = NULL; + + while ((getoptFlag = getopt(argc, argv, "b:c:ef:hi:m:o:rsv")) != -1) { + switch(getoptFlag) { + case 'b': + bits = optarg; + break; + case 'c': + columns = optarg; + break; + case 'e': + listExamples(); + return EXIT_SUCCESS; + case 'f': + font = optarg; + break; + case 'h': + showHelp(); + return EXIT_SUCCESS; + case 'i': + input = optarg; + break; + case 'm': + mode = optarg; + break; + case 'o': + output = optarg; + break; + case 'r': + createRetinaRep = true; + break; + case 's': + justDisplaySAUCE = true; + break; + case 'v': + versionInfo(); + return EXIT_SUCCESS; + } } - if ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0)) { - showHelp(); - return EXIT_SUCCESS; + + argc -= optind; + argv += optind; + + // let's check the file for a valid SAUCE record + sauce *record = sauceReadFileName(input); + + // record == NULL also means there is no file, we can stop here + if (record == NULL) { + printf("\nFile %s not found.\n\n", input); + return EXIT_FAILURE; } - if (strcmp(argv[1], "-e") == 0) { - listExamples(); - return EXIT_SUCCESS; + else { + // if we find a SAUCE record, update bool flag + if (strcmp(record->ID, SAUCE_ID) == 0) { + fileHasSAUCE = true; + } } - if ((argv[2] && (strcmp(argv[2], "-s") == 0)) || - (argv[2] && (strcmp(argv[2], "-i") == 0)) || - (argv[2] && (strcmp(argv[2], "-ir") == 0)) || - (argv[2] && (strcmp(argv[2], "-o") == 0)) || - (argv[2] && (strcmp(argv[2], "-or") == 0))) + + if (justDisplaySAUCE == false) { - if (strcmp(argv[2], "-s") == 0) { - justDisplaySAUCE = true; + // create output file name if output is not specified + if (!output) { + int outputLen = strlen(input) + 5; + output = malloc(outputLen); + snprintf(output, outputLen, "%s%s", input, ".png"); } - - if (strcmp(argv[2], "-ir") == 0 || strcmp(argv[2], "-or") == 0) { - createRetinaRep = true; + + if (createRetinaRep) { + int retinaLen = strlen(input) + 8; + retinaout = malloc(retinaLen); + snprintf(retinaout, retinaLen, "%s%s", input, "@2x.png"); } - - // let's check the file for a valid SAUCE record - sauce *record = sauceReadFileName(argv[1]); - - // record == NULL also means there is no file, we can stop here - if (record == NULL) { - printf("\nFile %s not found.\n\n", argv[1]); - return EXIT_FAILURE; + + // default to 8 if bits option is not specified + if (!bits) { + bits = "8"; } - else { - // if we find a SAUCE record, update bool flag - if (strcmp(record->ID, SAUCE_ID) == 0) { - fileHasSAUCE = true; - } + + // default to empty string if mode option is not specified + if (!mode) { + mode = ""; } - - // this should be self-explanatory - if (justDisplaySAUCE == false) - { - // declaration of types we pass to ansilove.c - char *input = argv[1]; - char output[1000] = { 0 }; - char retinaout[1000] = { 0 }; - char columns[1000] = { 0 }; - char font[1000] = { 0 }; - char bits[1000] = { 0 }; - char icecolors[1000] = { 0 }; - // get file extension - char *fext = strrchr(input, '.'); - fext = fext ? strtolower(fext) : "none"; + // convert numeric command line flags to integer values + int32_t int_bits = atoi(bits); - // in case we got arguments for input and the '-i' or '-ir' flag is set - if (strcmp(argv[2], "-i") == 0) { - // append .png suffix to file name - sprintf(output, "%s.png", input); - sprintf(retinaout, "placeholder_%s.png", input); - outputIdentical = true; - } - - if (strcmp(argv[2], "-ir") == 0) { - // again, append .png and also add @2x for retina output - sprintf(output, "%s.png", input); - sprintf(retinaout, "%s@2x.png", input); - outputIdentical = true; - } - - if ((strcmp(argv[2], "-o") == 0) && argv[3]) { - // so the user provided an alternate path / file name - sprintf(output, "%s.png", argv[3]); - sprintf(retinaout, "placeholder_%s.png", input); - } - - if ((strcmp(argv[2], "-or") == 0) && argv[3]) { - // alternate path and retina? damn you! even more work. - sprintf(output, "%s.png", argv[3]); - sprintf(retinaout, "%s@2x.png", argv[3]); - } - - if ((strcmp(argv[2], "-o") == 0) && !argv[3]) { - // arrr... matey! setting the option -o without output file argument, eh? - printf("\nOption -o is invalid without output file argument.\n\n"); - return EXIT_FAILURE; - } - - if ((strcmp(argv[2], "-or") == 0) && !argv[3]) { - // y u no enter output file argument? - printf("\nOption -or is invalid without output file argument.\n\n"); - return EXIT_FAILURE; - } - - // check for operands and apply them based on the file extension - if ((strcmp(fext, ".bin") == 0) && outputIdentical == true) - { - // set binary bool value - fileIsBinary = true; - - // font - if (argc >= 4) { - sprintf(font, "%s", argv[3]); - } - else { - sprintf(font, "%s", "80x25"); - } - // bits - if (argc >= 5) { - sprintf(bits, "%s", argv[4]); - } - else { - sprintf(bits, "%s", "8"); - - } - // iCE colors - if (argc >= 6) { - sprintf(icecolors, "%s", argv[5]); - } - else { - sprintf(icecolors, "%s", "0"); - } - // columns - if (argc >= 7) { - sprintf(columns, "%s", argv[6]); - } - else { - sprintf(columns, "%s", "160"); - } - } - else if ((strcmp(fext, ".bin") == 0) && outputIdentical == false) - { - // font - if (argc >= 5) { - sprintf(font, "%s", argv[4]); - } - else { - sprintf(font, "%s", "80x25"); - } - // bits - if (argc >= 6) { - sprintf(bits, "%s", argv[5]); - } - else { - sprintf(bits, "%s", "8"); - - } - // iCE colors - if (argc >= 7) { - sprintf(icecolors, "%s", argv[6]); - } - else { - sprintf(icecolors, "%s", "0"); - } - // columns - if (argc >= 8) { - sprintf(columns, "%s", argv[7]); - } - else { - sprintf(columns, "%s", "160"); - } - } - else { - if (outputIdentical == true) { - // font - if (argc >= 4) { - sprintf(font, "%s", argv[3]); - } - else { - sprintf(font, "%s", "80x25"); - } - // bits - if (argc >= 5) { - sprintf(bits, "%s", argv[4]); - } - else { - sprintf(bits, "%s", "8"); - } - // iCE colors - if (argc >= 6) { - sprintf(icecolors, "%s", argv[5]); - } - else { - sprintf(icecolors, "%s", "0"); - } - } - else { - // font - if (argc >= 5) { - sprintf(font, "%s", argv[4]); - } - else { - sprintf(font, "%s", "80x25"); - } - // bits - if (argc >= 6) { - sprintf(bits, "%s", argv[5]); - } - else { - sprintf(bits, "%s", "8"); - } - // iCE colors - if (argc >= 7) { - sprintf(icecolors, "%s", argv[6]); - } - else { - sprintf(icecolors, "%s", "0"); - } - } - } - - // create the output file by invoking the appropiate function - if (strcmp(fext, ".pcb") == 0) { - // params: input, output, font, bits, icecolors - alPcBoardLoader(input, output, retinaout, font, bits, createRetinaRep); - fileIsPCBoard = true; - } - else if (strcmp(fext, ".bin") == 0) { - // params: input, output, columns, font, bits, icecolors - alBinaryLoader(input, output, retinaout, columns, font, bits, icecolors, createRetinaRep); - fileIsBinary = true; - } - else if (strcmp(fext, ".adf") == 0) { - // params: input, output, bits - alArtworxLoader(input, output, retinaout, bits, createRetinaRep); - } - else if (strcmp(fext, ".idf") == 0) { - // params: input, output, bits - alIcedrawLoader(input, output, retinaout, bits, fileHasSAUCE, createRetinaRep); - } - else if (strcmp(fext, ".tnd") == 0) { - alTundraLoader(input, output, retinaout, font, bits, fileHasSAUCE, createRetinaRep); - fileIsTundra = true; - } - else if (strcmp(fext, ".xb") == 0) { - // params: input, output, bits - alXbinLoader(input, output, retinaout, bits, createRetinaRep); - } - else { - // params: input, output, font, bits, icecolors, fext - alAnsiLoader(input, output, retinaout, font, bits, icecolors, fext, createRetinaRep); - fileIsANSi = true; - } - - // gather information and report to the command line - printf("\nInput File: %s\n", input); - printf("Output File: %s\n", output); - if (createRetinaRep == true) { - printf("Retina Output File: %s\n", retinaout); - } - if (fileIsANSi == true || fileIsBinary == true || - fileIsPCBoard == true || fileIsTundra == true) { - printf("Font: %s\n", font); - } - if (fileIsANSi == true || fileIsBinary == true || - fileIsPCBoard == true || fileIsTundra == true) { - printf("Bits: %s\n", bits); - } - if (fileIsANSi == true || fileIsBinary == true || fileIsPCBoard == true) { - printf("iCE Colors: %s\n", icecolors); - } - if (fileIsBinary == true) { - printf("Columns: %s\n", columns); - } + // now set bits to 8 if not already value 8 or 9 + if (int_bits != 8 && int_bits != 9) { + int_bits = 8; } - - // either display SAUCE or tell us if there is no record - if (fileHasSAUCE == false) { - printf("\nFile %s does not have a SAUCE record.\n", argv[1]); + + // default to 160 if columns option is not specified + if (!columns) { + columns = "160"; } - else { - printf( "\n%s: %s v%s\n", "Id", record->ID, record->version); - printf( "%s: %s\n", "Title", record->title ); - printf( "%s: %s\n", "Author", record->author); - printf( "%s: %s\n", "Group", record->group); - printf( "%s: %s\n", "Date", record->date); - printf( "%s: %d\n", "Datatype", record->dataType); - printf( "%s: %d\n", "Filetype", record->fileType); - if (record->flags != 0) { - printf( "%s: %d\n", "Flags", record->flags); - } - if (record->tinfo1 != 0) { - printf( "%s: %d\n", "Tinfo1", record->tinfo1); - } - if (record->tinfo2 != 0) { - printf( "%s: %d\n", "Tinfo2", record->tinfo2); - } - if (record->tinfo3 != 0) { - printf( "%s: %d\n", "Tinfo3", record->tinfo3); - } - if (record->tinfo4 != 0) { - printf( "%s: %d\n", "Tinfo4", record->tinfo4); - } - if (record->comments > 0) { - int32_t i; - printf( "Comments: "); - for(i = 0; i < record->comments; i++) { - printf( "%s\n", record->comment_lines[i] ); - } - } + + // default to 80x25 font if font option is not specified + if (!font) { + font = "80x25"; + } + + // enabling iCE colors by default (For now) + icecolors = "1"; + + // get file extension + char *fext = strrchr(input, '.'); + fext = fext ? strtolower(fext) : "none"; + + // create the output file by invoking the appropiate function + if (strcmp(fext, ".pcb") == 0) { + // params: input, output, font, bits, icecolors + alPcBoardLoader(input, output, retinaout, font, int_bits, createRetinaRep); + fileIsPCBoard = true; + } + else if (strcmp(fext, ".bin") == 0) { + // params: input, output, columns, font, bits, icecolors + alBinaryLoader(input, output, retinaout, columns, font, int_bits, icecolors, createRetinaRep); + fileIsBinary = true; + } + else if (strcmp(fext, ".adf") == 0) { + // params: input, output, bits + alArtworxLoader(input, output, retinaout, createRetinaRep); + } + else if (strcmp(fext, ".idf") == 0) { + // params: input, output, bits + alIcedrawLoader(input, output, retinaout, fileHasSAUCE, createRetinaRep); } - - // post a message when the output file is created (in case we created output) - if (justDisplaySAUCE == false) { - printf("\nSuccessfully created output file.\n\n"); + else if (strcmp(fext, ".tnd") == 0) { + alTundraLoader(input, output, retinaout, font, int_bits, fileHasSAUCE, createRetinaRep); + fileIsTundra = true; + } + else if (strcmp(fext, ".xb") == 0) { + // params: input, output, bits + alXbinLoader(input, output, retinaout, createRetinaRep); } else { - printf("\n"); + // params: input, output, font, bits, icecolors, fext + alAnsiLoader(input, output, retinaout, font, int_bits, mode, icecolors, fext, createRetinaRep); + fileIsANSi = true; + } + + // gather information and report to the command line + printf("\nInput File: %s\n", input); + printf("Output File: %s\n", output); + if (createRetinaRep == true) { + printf("Retina Output File: %s\n", retinaout); + } + if (fileIsANSi == true || fileIsBinary == true || + fileIsPCBoard == true || fileIsTundra == true) { + printf("Font: %s\n", font); + } + if (fileIsANSi == true || fileIsBinary == true || + fileIsPCBoard == true || fileIsTundra == true) { + printf("Bits: %d\n", int_bits); + } + if (fileIsANSi == true || fileIsBinary == true || fileIsPCBoard == true) { + printf("iCE Colors: %s\n", icecolors); + } + if (fileIsBinary == true) { + printf("Columns: %s\n", columns); } } + + // either display SAUCE or tell us if there is no record + if (fileHasSAUCE == false) { + printf("\nFile %s does not have a SAUCE record.\n", input); + } else { - // in any other case the synopsis will be just fine - synopsis(); - return EXIT_SUCCESS; + printf( "\n%s: %s v%s\n", "Id", record->ID, record->version); + printf( "%s: %s\n", "Title", record->title ); + printf( "%s: %s\n", "Author", record->author); + printf( "%s: %s\n", "Group", record->group); + printf( "%s: %s\n", "Date", record->date); + printf( "%s: %d\n", "Datatype", record->dataType); + printf( "%s: %d\n", "Filetype", record->fileType); + if (record->flags != 0) { + printf( "%s: %d\n", "Flags", record->flags); + } + if (record->tinfo1 != 0) { + printf( "%s: %d\n", "Tinfo1", record->tinfo1); + } + if (record->tinfo2 != 0) { + printf( "%s: %d\n", "Tinfo2", record->tinfo2); + } + if (record->tinfo3 != 0) { + printf( "%s: %d\n", "Tinfo3", record->tinfo3); + } + if (record->tinfo4 != 0) { + printf( "%s: %d\n", "Tinfo4", record->tinfo4); + } + if (record->comments > 0) { + int32_t i; + printf( "Comments: "); + for(i = 0; i < record->comments; i++) { + printf( "%s\n", record->comment_lines[i] ); + } + } } + return EXIT_SUCCESS; }