/* alan.c Treaty of Babel module for ALAN files * 2006 By L. Ross Raszewski * * This file depends on treaty_builder.h * * This file is public domain, but note that any changes to this file * may render it noncompliant with the Treaty of Babel */ #define FORMAT alan #define HOME_PAGE "http://www.alanif.se/" #define FORMAT_EXT ".acd,.a3c" #define NO_METADATA #define NO_COVER #include "treaty_builder.h" #include #include #include typedef unsigned char byte; static uint32 read_alan_int_at(byte *from) { return ((uint32) from[3])| ((uint32)from[2] << 8) | ((uint32) from[1]<<16)| ((uint32)from[0] << 24); } static bool magic_word_found(byte *story_file) { if(story_file == NULL) return false; return memcmp(story_file,"ALAN",4) == 0; } static int32 get_story_file_IFID(void *story_file, int32 extent, char *output, int32 output_extent) { if (story_file || extent) { } if (!magic_word_found(story_file)) { ASSERT_OUTPUT_SIZE(5); strcpy(output,"ALAN-"); return INCOMPLETE_REPLY_RV; } else { /* Alan v3 stores IFIDs in the story file in a format that might differ between versions. So just scan for "UUID://". Alan files seem to have lower-case hex in the "UUID://" string, which is not what we want, but we accept it for historic reasons. We therefore don't call find_uuid_ifid_marker(). */ int32 i, j, k; for(i=0;i extent_in_bytes/4) return INVALID_STORY_FILE_RV; for (i=24;i<81;i+=4) if (read_alan_int_at(sf+i) > extent_in_bytes/4) return INVALID_STORY_FILE_RV; for (i=160;i<(size_in_awords*4);i++) crc+=sf[i]; if (crc!=read_alan_int_at(sf+152)) return INVALID_STORY_FILE_RV; return VALID_STORY_FILE_RV; } else { /* Identify Alan 3 */ size_in_awords=read_alan_int_at(sf+3*4); /* hdr.size @ 3 */ if (!crc_is_correct(sf, size_in_awords)) { switch (read_alan_int_at(sf+46*4)) { case 1427594: /* Enter The Dark */ case 8683866: /* Waldo’s Pie */ return VALID_STORY_FILE_RV; default: return INVALID_STORY_FILE_RV; } } return VALID_STORY_FILE_RV; } }