1 /* agt.c Treaty of Babel module for AGX-encapsulated AGT 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.ifarchive.org/indexes/if-archiveXprogrammingXagt"
\r
12 #define FORMAT_EXT ".agx"
\r
16 #include "treaty_builder.h"
\r
21 static char AGX_MAGIC[4] = { 0x58, 0xC7, 0xC1, 0x51 };
\r
23 /* Helper functions to unencode integers from AGT source */
\r
24 static int32 read_agt_short(unsigned char *sf)
\r
26 return sf[0] | (int32) sf[1]<<8;
\r
28 static int32 read_agt_int(unsigned char *sf)
\r
30 return (read_agt_short(sf+2) << 16) | read_agt_short(sf);
\r
34 static int32 get_story_file_IFID(void *story_file, int32 extent, char *output, int32 output_extent)
\r
36 int32 l, game_version, game_sig;
\r
37 unsigned char *sf=(unsigned char *)story_file;
\r
39 /* Read the position of the game desciption block */
\r
40 l=read_agt_int(sf+32);
\r
41 if (extent<l+6) return INVALID_STORY_FILE_RV;
\r
42 game_version = read_agt_short(sf+l);
\r
43 game_sig=read_agt_int(sf+l+2);
\r
44 ASSERT_OUTPUT_SIZE(19);
\r
45 sprintf(output,"AGT-%05d-%08X",game_version,game_sig);
\r
49 /* The claim algorithm for AGT is to check for the magic word
\r
52 static int32 claim_story_file(void *story_file, int32 extent)
\r
56 if (extent<36 || memcmp(story_file,AGX_MAGIC,4)) return INVALID_STORY_FILE_RV;
\r
57 return VALID_STORY_FILE_RV;
\r