Merge branch 'master' into browser
[projects/chimara/chimara.git] / babel / advsys.c
diff --git a/babel/advsys.c b/babel/advsys.c
new file mode 100644 (file)
index 0000000..e0e1cf8
--- /dev/null
@@ -0,0 +1,49 @@
+/* advsys.c  Treaty of Babel module for AdvSys 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 advsys\r
+#define HOME_PAGE "http://www.ifarchive.org/if-archive/programming/advsys/"\r
+#define FORMAT_EXT ".dat"\r
+#define NO_METADATA\r
+#define NO_COVER\r
+\r
+#include "treaty_builder.h"\r
+#include <ctype.h>\r
+#include <stdio.h>\r
+\r
+/* IFIDs for AdvSys are formed by prepending ADVSYS- to the default\r
+   MD5 ifid\r
+*/\r
+static int32 get_story_file_IFID(void *story_file, int32 extent, char *output, int32 output_extent)\r
+{\r
+ /* This line suppresses a warning from the borland compiler */\r
+ if (story_file || extent) { }\r
+ ASSERT_OUTPUT_SIZE(8);\r
+ strcpy(output,"ADVSYS-");\r
+ return INCOMPLETE_REPLY_RV;\r
+\r
+}\r
+\r
+/* The Advsys claim algorithm: bytes 2-8 of the file contain the\r
+   text "ADVSYS", unobfuscated in the following way:\r
+     30 is added to each byte, then the bits are reversed\r
+*/\r
+static int32 claim_story_file(void *story_file, int32 extent)\r
+{\r
+ char buf[7];\r
+ int i;\r
+ if (extent >=8)\r
+ { \r
+   for(i=0;i<6;i++)\r
+    buf[i]=~(((char *)story_file)[i+2]+30);\r
+   buf[6]=0;\r
+   if (strcmp(buf,"ADVSYS")==0) return VALID_STORY_FILE_RV;\r
+ }\r
+ return INVALID_STORY_FILE_RV;\r
+}\r