commit 54c4fd5683572e8c2d1b3ce586cfd4657ecfd490
parent abe6d12bff94f352ca283d69c9fe20709c048d42
Author: Brian Cassidy <bricas@cpan.org>
Date: Thu, 16 Feb 2012 16:09:35 -0400
minor bit of work to xbin code
Diffstat:
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/ansilove/ansilove.c b/ansilove/ansilove.c
@@ -2174,7 +2174,43 @@ void alArtworxLoader(char *input, char output[], char bits[])
// XBin
void alXbinLoader(char *input, char output[], char bits[])
-{ }
+{
+ // 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;
+ size_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
+ rewind(input_file);
+ fclose(input_file);
+
+ if (strcmp(strndup((char *)input_file_buffer, 4), "XBIN") != 0) {
+ fputs("\nNot an XBin.\n\n", stderr); exit (4);
+ }
+
+ fputs("\nXBin OK!\n\n", stderr); exit (0);
+}
// check_libraries();
//