1 /* glulx.c Treaty of Babel module for Glulx files
\r
2 * 2006 By L. Ross Raszewski
\r
4 * This file depends on treaty_builder.h
\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
10 #define FORMAT glulx
\r
11 #define HOME_PAGE "http://eblong.com/zarf/glulx"
\r
12 #define FORMAT_EXT ".ulx"
\r
16 #include "treaty_builder.h"
\r
20 static int32 read_int(unsigned char *mem)
\r
26 return i1 | (i2<<8) | (i3<<16) | (i4<<24);
\r
31 static int32 get_story_file_IFID(void *story_file, int32 extent, char *output, int32 output_extent)
\r
38 if (extent<256) return INVALID_STORY_FILE_RV;
\r
39 for(i=0;i<extent;i++) if (memcmp((char *)story_file+i,"UUID://",7)==0) break;
\r
40 if (i<extent) /* Found explicit IFID */
\r
42 for(j=i+7;j<extent && ((char *)story_file)[j]!='/';j++);
\r
46 ASSERT_OUTPUT_SIZE(j-i);
\r
47 memcpy(output,(char *)story_file+i,j-i);
\r
53 /* Did not find intact IFID. Build one */
\r
55 j=read_int((unsigned char *)story_file+32);
\r
56 k=read_int((unsigned char *)story_file+12);
\r
57 if (memcmp((char *)story_file+36,"Info",4)==0)
\r
58 { /* Inform generated */
\r
59 char *bb=(char *)story_file+52;
\r
60 k= (int) bb[0]<<8 | (int) bb[1];
\r
63 for(i=0;i<6;i++) if (!isalnum(ser[i])) ser[i]='-';
\r
64 sprintf(buffer,"GLULX-%u-%s-%04X",k,ser,j);
\r
67 sprintf(buffer,"GLULX-%08X-%08X",k,j);
\r
69 ASSERT_OUTPUT_SIZE((signed) strlen(buffer)+1);
\r
70 strcpy((char *)output,buffer);
\r
75 static int32 claim_story_file(void *story_file, int32 extent)
\r
78 memcmp(story_file,"Glul",4)
\r
79 ) return INVALID_STORY_FILE_RV;
\r
80 return VALID_STORY_FILE_RV;
\r