1 /* alan.c Treaty of Babel module for ALAN files
\r
2 * 2006 By L. Ross Raszewski
\r
4 * This file depends on treaty_builder.h
\r
6 * This file is public domain, but note that any changes to this file
\r
7 * may render it noncompliant with the Treaty of Babel
\r
11 #define HOME_PAGE "http://www.alanif.se/"
\r
12 #define FORMAT_EXT ".acd"
\r
16 #include "treaty_builder.h"
\r
20 static int32 read_alan_int(unsigned char *from)
\r
22 return ((unsigned long int) from[3])| ((unsigned long int)from[2] << 8) |
\r
23 ((unsigned long int) from[1]<<16)| ((unsigned long int)from[0] << 24);
\r
25 static int32 get_story_file_IFID(void *story_file, int32 extent, char *output, int32 output_extent)
\r
28 if (story_file || extent) { }
\r
29 ASSERT_OUTPUT_SIZE(6);
\r
30 strcpy(output,"ALAN-");
\r
31 return INCOMPLETE_REPLY_RV;
\r
34 The claim algorithm for Alan files is:
\r
35 * For Alan 3, check for the magic word
\r
36 * load the file length in blocks
\r
37 * check that the file length is correct
\r
38 * For alan 2, each word between byte address 24 and 81 is a
\r
39 word address within the file, so check that they're all within
\r
41 * Locate the checksum and verify that it is correct
\r
43 static int32 claim_story_file(void *story_file, int32 extent)
\r
45 unsigned char *sf = (unsigned char *) story_file;
\r
47 if (extent < 160) return INVALID_STORY_FILE_RV;
\r
48 if (memcmp(sf,"ALAN",4))
\r
49 { /* Identify Alan 2.x */
\r
50 bf=read_alan_int(sf+4);
\r
51 if (bf > extent/4) return INVALID_STORY_FILE_RV;
\r
52 for (i=24;i<81;i+=4)
\r
53 if (read_alan_int(sf+i) > extent/4) return INVALID_STORY_FILE_RV;
\r
54 for (i=160;i<(bf*4);i++)
\r
56 if (crc!=read_alan_int(sf+152)) return INVALID_STORY_FILE_RV;
\r
57 return VALID_STORY_FILE_RV;
\r
60 { /* Identify Alan 3 */
\r
61 bf=read_alan_int(sf+12);
\r
62 if (bf > (extent/4)) return INVALID_STORY_FILE_RV;
\r
63 for (i=184;i<(bf*4);i++)
\r
65 if (crc!=read_alan_int(sf+176)) return INVALID_STORY_FILE_RV;
\r
68 return INVALID_STORY_FILE_RV;
\r