Merge branch 'master' into browser
[projects/chimara/chimara.git] / babel / executable.c
diff --git a/babel/executable.c b/babel/executable.c
new file mode 100644 (file)
index 0000000..ac0c403
--- /dev/null
@@ -0,0 +1,62 @@
+/* executable.c  Treaty of Babel module for Z-code 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 executable\r
+#define HOME_PAGE "http://http://en.wikipedia.org/wiki/Executable"\r
+#define FORMAT_EXT ".exe"\r
+#define NO_METADATA\r
+#define NO_COVER\r
+\r
+#include "treaty_builder.h"\r
+#include <ctype.h>\r
+#include <stdio.h>\r
+\r
+static char elfmagic[] = { 0x7f, 0x45, 0x4c, 0x46, 0 };\r
+static char javamagic[] = { 0xCA, 0xFE, 0xBA, 0xBE, 0 };\r
+static char amigamagic[] = { 0, 0, 3, 0xe7, 0 };\r
+static char machomagic[] = { 0xFE, 0xED, 0xFA, 0xCE, 0};\r
+struct exetype\r
+{\r
+ char *magic;\r
+ char *name;\r
+ int len;\r
+};\r
+static struct exetype magic[]= { { "MZ", "MZ", 2 },\r
+                                 { elfmagic, "ELF", 4 },\r
+                                 { javamagic, "JAVA", 4 },\r
+                                 { amigamagic, "AMIGA", 4 },\r
+                                 { "#! ", "SCRIPT", 3 },\r
+                                 { machomagic, "MACHO",4 },\r
+                                 { "APPL", "MAC",4 },\r
+                                 { NULL, NULL, 0 } };\r
+\r
+static char *deduce_magic(void *sf, int32 extent)\r
+{\r
+ int i;\r
+ for(i=0;magic[i].magic;i++)\r
+ if (extent >= magic[i].len && memcmp(magic[i].magic,sf,magic[i].len)==0)\r
+  return magic[i].name;\r
+ return NULL;\r
+}\r
+                                 \r
+static int32 claim_story_file(void *sf, int32 extent)\r
+{\r
+ if (deduce_magic(sf,extent)) return VALID_STORY_FILE_RV;\r
+ return NO_REPLY_RV;\r
+}\r
+static int32 get_story_file_IFID(void *sf, int32 extent, char *output, int32 output_extent)\r
+{\r
+ char *o;\r
+ o=deduce_magic(sf,extent);\r
+ if (!o) return 0;\r
+ ASSERT_OUTPUT_SIZE((signed) strlen(o)+2);\r
+ strcpy(output,o);\r
+ strcat(output,"-");\r
+ return INCOMPLETE_REPLY_RV;\r
+}\r