+++ /dev/null
-/* glulx.c Treaty of Babel module for Glulx 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 glulx\r
-#define HOME_PAGE "http://eblong.com/zarf/glulx"\r
-#define FORMAT_EXT ".ulx"\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 int32 read_int(unsigned char *mem)\r
-{\r
- int32 i4 = mem[0],\r
- i3 = mem[1],\r
- i2 = mem[2],\r
- i1 = mem[3];\r
- return i1 | (i2<<8) | (i3<<16) | (i4<<24);\r
-}\r
-\r
-\r
-\r
-static int32 get_story_file_IFID(void *story_file, int32 extent, char *output, int32 output_extent)\r
-{\r
- int32 i,j, k;\r
- char ser[7];\r
- char buffer[32];\r
-\r
-\r
- if (extent<256) return INVALID_STORY_FILE_RV;\r
- for(i=0;i<extent;i++) if (memcmp((char *)story_file+i,"UUID://",7)==0) break;\r
- if (i<extent) /* Found explicit IFID */\r
- {\r
- for(j=i+7;j<extent && ((char *)story_file)[j]!='/';j++);\r
- if (j<extent)\r
- {\r
- i+=7;\r
- ASSERT_OUTPUT_SIZE(j-i);\r
- memcpy(output,(char *)story_file+i,j-i);\r
- output[j-i]=0;\r
- return 1;\r
- }\r
- }\r
-\r
- /* Did not find intact IFID. Build one */\r
-\r
- j=read_int((unsigned char *)story_file+32);\r
- k=read_int((unsigned char *)story_file+12);\r
- if (memcmp((char *)story_file+36,"Info",4)==0)\r
- { /* Inform generated */\r
- char *bb=(char *)story_file+52;\r
- k= (int) bb[0]<<8 | (int) bb[1];\r
- memcpy(ser,bb+2,6);\r
- ser[6]=0;\r
- for(i=0;i<6;i++) if (!isalnum(ser[i])) ser[i]='-';\r
- sprintf(buffer,"GLULX-%u-%s-%04X",k,ser,j);\r
- }\r
- else\r
- sprintf(buffer,"GLULX-%08X-%08X",k,j);\r
-\r
- ASSERT_OUTPUT_SIZE((signed) strlen(buffer)+1);\r
- strcpy((char *)output,buffer);\r
- return 1;\r
-\r
-}\r
-\r
-static int32 claim_story_file(void *story_file, int32 extent)\r
-{\r
- if (extent<256 ||\r
- memcmp(story_file,"Glul",4)\r
- ) return INVALID_STORY_FILE_RV;\r
- return VALID_STORY_FILE_RV;\r
-}\r