ansilove

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

commit d68f2bd933c070765842c10e1b6b9aad31a78501
parent 9f75259f4a686f3c98a1f2659575ab46fee983bc
Author: Frederic Cambus <fred@statdns.com>
Date:   Fri, 22 Jul 2016 12:14:56 +0200

Move input file loader from the ANSI loader to main

Diffstat:
Msrc/loaders/ansi.c | 29-----------------------------
Msrc/main.c | 29+++++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/src/loaders/ansi.c b/src/loaders/ansi.c @@ -39,35 +39,6 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi workbench = true; } - // load input file - FILE *input_file = fopen(input, "r"); - if (input_file == NULL) { - fputs("\nFile error.\n\n", stderr); exit (1); - } - - // get the file size (bytes) - size_t get_file_size = filesize(input); - int32_t input_file_size = (int32_t)get_file_size; - - // next up is loading our file into a dynamically allocated memory buffer - unsigned char *input_file_buffer; - int32_t result; - - // allocate memory to contain the whole file - input_file_buffer = (unsigned char *) malloc(sizeof(unsigned char)*input_file_size); - if (input_file_buffer == NULL) { - fputs ("\nMemory error.\n\n", stderr); exit (2); - } - - // copy the file into the buffer - result = fread(input_file_buffer, 1, input_file_size, input_file); - if (result != input_file_size) { - fputs ("\nReading error.\n\n", stderr); exit (3); - } // whole file is now loaded into input_file_buffer - - // close input file, we don't need it anymore - fclose(input_file); - // check if current file has a .diz extension if (!strcmp(fext, ".diz")) { isDizFile = true; diff --git a/src/main.c b/src/main.c @@ -283,6 +283,35 @@ int main(int argc, char *argv[]) { char *fext = strrchr(input, '.'); fext = fext ? strtolower(strdup(fext)) : ""; + // load input file + FILE *input_file = fopen(input, "r"); + if (input_file == NULL) { + fputs("\nFile error.\n\n", stderr); exit (1); + } + + // get the file size (bytes) + size_t get_file_size = filesize(input); + int32_t input_file_size = (int32_t)get_file_size; + + // next up is loading our file into a dynamically allocated memory buffer + unsigned char *input_file_buffer; + int32_t result; + + // allocate memory to contain the whole file + input_file_buffer = (unsigned char *) malloc(sizeof(unsigned char)*input_file_size); + if (input_file_buffer == NULL) { + fputs ("\nMemory error.\n\n", stderr); exit (2); + } + + // copy the file into the buffer + result = fread(input_file_buffer, 1, input_file_size, input_file); + if (result != input_file_size) { + fputs ("\nReading error.\n\n", stderr); exit (3); + } // whole file is now loaded into input_file_buffer + + // close input file, we don't need it anymore + fclose(input_file); + // create the output file by invoking the appropiate function if (!strcmp(fext, ".pcb")) { // params: input, output, font, bits, icecolors