Debian Codegraph @

support/babel/glulx.c

raw symbols SCIP
1 /* glulx.c Treaty of Babel module for Glulx files
2 * 2006 By L. Ross Raszewski
3 *
4 * This file depends on treaty_builder.h
5 *
6 * This file is public domain, but note that any changes to this file
7 * may render it noncompliant with the Treaty of Babel
8 */
9
10 #define FORMAT glulx
11 #define HOME_PAGE "http://eblong.com/zarf/glulx"
12 #define FORMAT_EXT ".ulx"
13 #define NO_METADATA
14 #define NO_COVER
15
16 #include "treaty_builder.h"
17 #include "ifiction.h"
18 #include <ctype.h>
19 #include <stdio.h>
20
21 static uint32 read_int(unsigned char *mem)
22 {
23 uint32 i4 = mem[0],
24 i3 = mem[1],
25 i2 = mem[2],
26 i1 = mem[3];
27 return i1 | (i2<<8) | (i3<<16) | (i4<<24);
28 }
29
30
31
32 static int32 get_story_file_IFID(void *story_file, int32 extent, char *output, int32 output_extent)
33 {
34 int32 i,j, k;
35 char ser[7];
36 char buffer[32];
37
38 if (extent<256) return INVALID_STORY_FILE_RV;
39
40 i = find_uuid_ifid_marker(story_file, extent, output, output_extent);
41 if (i == VALID_STORY_FILE_RV || i == INVALID_USAGE_RV)
42 return i;
43
44 /* Did not find intact IFID. Build one */
45
46 j=read_int((unsigned char *)story_file+32);
47 k=read_int((unsigned char *)story_file+12);
48 if (memcmp((char *)story_file+36,"Info",4)==0)
49 { /* Inform generated */
50 char *bb=(char *)story_file+52;
51 k= (int) bb[0]<<8 | (int) bb[1];
52 memcpy(ser,bb+2,6);
53 ser[6]=0;
54 for(i=0;i<6;i++) if (!isalnum(ser[i])) ser[i]='-';
55 sprintf(buffer,"GLULX-%u-%s-%04X",k,ser,j);
56 }
57 else
58 sprintf(buffer,"GLULX-%08X-%08X",k,j);
59
60 ASSERT_OUTPUT_SIZE((signed) strlen(buffer)+1);
61 strcpy((char *)output,buffer);
62 return 1;
63
64 }
65
66 static int32 claim_story_file(void *story_file, int32 extent)
67 {
68 if (extent<256 ||
69 memcmp(story_file,"Glul",4)
70 ) return INVALID_STORY_FILE_RV;
71 return VALID_STORY_FILE_RV;
72 }