e0e1cf8a565ffb1e1598bed71046cd7281741555
[projects/chimara/chimara.git] / babel / advsys.c
1 /* advsys.c  Treaty of Babel module for AdvSys files\r
2  * 2006 By L. Ross Raszewski\r
3  *\r
4  * This file depends on treaty_builder.h\r
5  *\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
8  */\r
9 \r
10 #define FORMAT advsys\r
11 #define HOME_PAGE "http://www.ifarchive.org/if-archive/programming/advsys/"\r
12 #define FORMAT_EXT ".dat"\r
13 #define NO_METADATA\r
14 #define NO_COVER\r
15 \r
16 #include "treaty_builder.h"\r
17 #include <ctype.h>\r
18 #include <stdio.h>\r
19 \r
20 /* IFIDs for AdvSys are formed by prepending ADVSYS- to the default\r
21    MD5 ifid\r
22 */\r
23 static int32 get_story_file_IFID(void *story_file, int32 extent, char *output, int32 output_extent)\r
24 {\r
25  /* This line suppresses a warning from the borland compiler */\r
26  if (story_file || extent) { }\r
27  ASSERT_OUTPUT_SIZE(8);\r
28  strcpy(output,"ADVSYS-");\r
29  return INCOMPLETE_REPLY_RV;\r
30 \r
31 }\r
32 \r
33 /* The Advsys claim algorithm: bytes 2-8 of the file contain the\r
34    text "ADVSYS", unobfuscated in the following way:\r
35      30 is added to each byte, then the bits are reversed\r
36 */\r
37 static int32 claim_story_file(void *story_file, int32 extent)\r
38 {\r
39  char buf[7];\r
40  int i;\r
41  if (extent >=8)\r
42  { \r
43    for(i=0;i<6;i++)\r
44     buf[i]=~(((char *)story_file)[i+2]+30);\r
45    buf[6]=0;\r
46    if (strcmp(buf,"ADVSYS")==0) return VALID_STORY_FILE_RV;\r
47  }\r
48  return INVALID_STORY_FILE_RV;\r
49 }\r