1 /* hugo.c Treaty of Babel module for hugo 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
11 #define HOME_PAGE "http://www.generalcoffee.com"
\r
12 #define FORMAT_EXT ".hex"
\r
16 #include "treaty_builder.h"
\r
20 static int32 get_story_file_IFID(void *s_file, int32 extent, char *output, int32 output_extent)
\r
26 char *story_file = (char *) s_file;
\r
29 if (extent<0x0B) return INVALID_STORY_FILE_RV;
\r
31 for(i=0;i<extent;i++) if (memcmp((char *)story_file+i,"UUID://",7)==0) break;
\r
32 if (i<extent) /* Found explicit IFID */
\r
34 for(j=i+7;j<extent && ((char *)story_file)[j]!='/';j++);
\r
38 ASSERT_OUTPUT_SIZE(j-i);
\r
39 memcpy(output,(char *)story_file+i,j-i);
\r
45 memcpy(ser, (char *) story_file+0x03, 8);
\r
49 if (!isalnum(ser[j])) ser[j]='-';
\r
52 sprintf(buffer,"HUGO-%d-%02X-%02X-%s",story_file[0],story_file[1], story_file[2],ser);
\r
54 ASSERT_OUTPUT_SIZE((signed) strlen(buffer)+1);
\r
55 strcpy((char *)output,buffer);
\r
59 static int32 read_hugo_addx(unsigned char *from)
\r
61 return ((unsigned int) from[0])| ((unsigned int)from[1] << 8);
\r
64 static int32 claim_story_file(void *story_file, int32 extent)
\r
66 unsigned char *sf=(unsigned char *)story_file;
\r
70 if (!story_file || extent < 0x28) return INVALID_STORY_FILE_RV;
\r
72 if (sf[0]<34) scale=4;
\r
74 for(i=3;i<0x0B;i++) if (sf[i]<0x20 || sf[i]>0x7e) return INVALID_STORY_FILE_RV;
\r
75 for(i=0x0b;i<0x18;i+=2)
\r
76 if (read_hugo_addx(sf+i) * scale > extent) return INVALID_STORY_FILE_RV;
\r
78 return VALID_STORY_FILE_RV;
\r