Merge branch 'master' into browser
[projects/chimara/chimara.git] / babel / agt.c
diff --git a/babel/agt.c b/babel/agt.c
new file mode 100644 (file)
index 0000000..66b6575
--- /dev/null
@@ -0,0 +1,59 @@
+/* agt.c  Treaty of Babel module for AGX-encapsulated AGT files\r
+ * 2006 By L. Ross Raszewski\r
+ *\r
+ * This file depends on treaty_builder.h\r
+ *\r
+ * This file is public domain, but note that any changes to this file\r
+ * may render it noncompliant with the Treaty of Babel\r
+ */\r
+\r
+#define FORMAT agt\r
+#define HOME_PAGE "http://www.ifarchive.org/indexes/if-archiveXprogrammingXagt"\r
+#define FORMAT_EXT ".agx"\r
+#define NO_METADATA\r
+#define NO_COVER\r
+\r
+#include "treaty_builder.h"\r
+#include <ctype.h>\r
+#include <stdio.h>\r
+\r
+\r
+static char AGX_MAGIC[4] = { 0x58, 0xC7, 0xC1, 0x51 };\r
+\r
+/* Helper functions to unencode integers from AGT source */\r
+static int32 read_agt_short(unsigned char *sf)\r
+{\r
+ return sf[0] | (int32) sf[1]<<8;\r
+}\r
+static int32 read_agt_int(unsigned char *sf)\r
+{\r
+ return (read_agt_short(sf+2) << 16) | read_agt_short(sf);\r
+\r
+}\r
+\r
+static int32 get_story_file_IFID(void *story_file, int32 extent, char *output, int32 output_extent)\r
+{\r
+ int32 l, game_version, game_sig;\r
+ unsigned char *sf=(unsigned char *)story_file;\r
+\r
+ /* Read the position of the game desciption block */\r
+ l=read_agt_int(sf+32);\r
+ if (extent<l+6) return INVALID_STORY_FILE_RV;\r
+ game_version = read_agt_short(sf+l);\r
+ game_sig=read_agt_int(sf+l+2);\r
+ ASSERT_OUTPUT_SIZE(19);\r
+ sprintf(output,"AGT-%05d-%08X",game_version,game_sig);\r
+ return 1;\r
+}\r
+\r
+/* The claim algorithm for AGT is to check for the magic word\r
+   defined above\r
+*/\r
+static int32 claim_story_file(void *story_file, int32 extent)\r
+{\r
+\r
+\r
+ if (extent<36 || memcmp(story_file,AGX_MAGIC,4)) return INVALID_STORY_FILE_RV;\r
+ return VALID_STORY_FILE_RV;\r
+\r
+}\r