commit deec12bf56d20837c6e07ac85d20d6bce26a88bc
parent c1abe12eca1e11dd88c317ad87b3de353e195a0c
Author: ByteProject <stefan.vogt@byteproject.net>
Date: Sun, 19 Feb 2012 12:07:39 +0100
bool type 'fileHasSAUCE' implementation
This type has been added as workaround for known issues occurring when
IDF files contain SAUCE records. Now only invoking libsauce when
fileHasSAUCE == true.
Diffstat:
3 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/ansilove/ansilove.c b/ansilove/ansilove.c
@@ -1627,7 +1627,7 @@ void alArtworxLoader(char *input, char output[], char bits[])
}
// IDF
-void alIcedrawLoader(char *input, char output[], char bits[])
+void alIcedrawLoader(char *input, char output[], char bits[], bool fileHasSAUCE)
{
// load input file
FILE *input_file = fopen(input, "r");
@@ -1655,18 +1655,18 @@ void alIcedrawLoader(char *input, char output[], char bits[])
fputs ("\nReading error.\n\n", stderr); exit (3);
} // whole file is now loaded into input_file_buffer
+ // just like a tape, you know?
rewind(input_file);
- sauce *saucerec = sauceReadFile(input_file);
-
- // close input file, we don't need it anymore
- rewind(input_file);
- fclose(input_file);
-
- // in case the file contains a Sauce record, we need to adjust the file size
- if( saucerec != NULL ) {
+ // IDF related: file contains a SAUCE record? adjust the file size
+ if(fileHasSAUCE == true) {
+ sauce *saucerec = sauceReadFile(input_file);
input_file_size -= 128 - ( saucerec->comments > 0 ? 5 + 64 * saucerec->comments : 0);
+ rewind(input_file);
}
+
+ // close input file, we don't need it anymore
+ fclose(input_file);
// extract IDF header, four 16-bit little endian unsigned shorts
int32_t x1 = (input_file_buffer[5] << 8) + input_file_buffer[4];
diff --git a/ansilove/ansilove.h b/ansilove/ansilove.h
@@ -36,7 +36,7 @@ void alAnsiLoader(char *input, char output[], char font[], char bits[], char ice
void alBinaryLoader(char *input, char output[], char columns[], char font[], char bits[], char icecolors[]);
void alArtworxLoader(char *input, char output[], char bits[]);
void alXbinLoader(char *input, char output[], char bits[]);
-void alIcedrawLoader(char *input, char output[], char bits[]);
+void alIcedrawLoader(char *input, char output[], char bits[], bool fileHasSAUCE);
// sauce records
#define RECORD_SIZE 128
diff --git a/ansilove/main.c b/ansilove/main.c
@@ -80,8 +80,9 @@ int main(int argc, char *argv[])
return EXIT_SUCCESS;
}
- // indicates whether AnsiLove/C should just display SAUCE or not
+ // SAUCE record related bool types
bool justDisplaySAUCE = false;
+ bool fileHasSAUCE = false;
// in case the SAUCE flag is set we set our bool type to 'true'
if (strcmp(argv[2], "-r") == 0) {
@@ -91,11 +92,17 @@ int main(int argc, char *argv[])
// let's check the file for a valid SAUCE record
sauce *record = sauceReadFileName(argv[1]);
- // record == NULL means there is no file, we can stop here
+ // 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;
}
+ else {
+ // if we find a SAUCE record, update bool flag
+ if (strcmp(record->ID, SAUCE_ID) == 0) {
+ fileHasSAUCE = true;
+ }
+ }
// this should be self-explanatory
if (justDisplaySAUCE == false)
@@ -125,7 +132,7 @@ int main(int argc, char *argv[])
fext = "none";
}
- // in case we got arguments for input, output and the '-s' flag is set
+ // in case we got arguments for input, output, and the '-s' flag is set
if (strcmp(argv[2], "-s") == 0)
{
// append .png suffix to file name
@@ -215,7 +222,7 @@ int main(int argc, char *argv[])
}
else if (strcmp(fext, ".idf") == 0) {
// params: input, output, bits
- alIcedrawLoader(input, output, bits);
+ alIcedrawLoader(input, output, bits, fileHasSAUCE);
}
else if (strcmp(fext, ".tnd") == 0) {
loadTundra();
@@ -231,8 +238,8 @@ int main(int argc, char *argv[])
}
// either display SAUCE or tell us if there is no record
- if (strcmp( record->ID, SAUCE_ID ) != 0) {
- printf("\nFile does not have a SAUCE record.\n");
+ if (fileHasSAUCE == false) {
+ printf("\nFile %s does not have a SAUCE record.\n", argv[1]);
}
else {
printf( "\n%s: %s v%s\n", "Id", record->ID, record->version);