| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
#ifndef TREATY_BUILDER |
| 58 |
#define TREATY_BUILDER |
| 59 |
|
| 60 |
#include "treaty.h" |
| 61 |
#include <string.h> |
| 62 |
|
| 63 |
#define ASSERT_OUTPUT_SIZE(x) do { if (output_extent < (x)) return INVALID_USAGE_RV; } while (0) |
| 64 |
|
| 65 |
#ifndef NO_METADATA |
| 66 |
static int32 get_story_file_metadata_extent(void *, int32); |
| 67 |
static int32 get_story_file_metadata(void *, int32, char *, int32); |
| 68 |
#endif |
| 69 |
#ifndef NO_COVER |
| 70 |
static int32 get_story_file_cover_extent(void *, int32); |
| 71 |
static int32 get_story_file_cover_format(void *, int32); |
| 72 |
static int32 get_story_file_cover(void *, int32, void *, int32); |
| 73 |
#endif |
| 74 |
static int32 get_story_file_IFID(void *, int32, char *, int32); |
| 75 |
static int32 claim_story_file(void *, int32); |
| 76 |
#ifdef CONTAINER_FORMAT |
| 77 |
static int32 get_story_file(void *, int32, void *, int32); |
| 78 |
static int32 get_story_format(void *, int32, char *, int32); |
| 79 |
static int32 get_story_extent(void *, int32); |
| 80 |
#endif |
| 81 |
#ifdef CUSTOM_EXTENSION |
| 82 |
static int32 get_story_file_extension(void *, int32, char *, int32); |
| 83 |
#else |
| 84 |
#include <stdio.h> |
| 85 |
static int32 get_story_file_extension(void *sf, int32 extent, char *out, int32 output_extent) |
| 86 |
{ |
| 87 |
int i; |
| 88 |
|
| 89 |
if (!sf || !extent) return INVALID_STORY_FILE_RV; |
| 90 |
|
| 91 |
for(i=0;FORMAT_EXT[i] && FORMAT_EXT[i]!=',';i++); |
| 92 |
ASSERT_OUTPUT_SIZE(i+1); |
| 93 |
memcpy(out,FORMAT_EXT,i); |
| 94 |
out[i]=0; |
| 95 |
return strlen(out); |
| 96 |
} |
| 97 |
|
| 98 |
#endif |
| 99 |
|
| 100 |
#define TREATY_FUNCTION(X) DEEP_TREATY_FUNCTION(X) |
| 101 |
#define DEEP_TREATY_FUNCTION(X) X ## _treaty |
| 102 |
#define dSTRFRY(X) #X |
| 103 |
#define STRFRY(X) dSTRFRY(X) |
| 104 |
|
| 105 |
int32 TREATY_FUNCTION(FORMAT)(int32 selector, |
| 106 |
void *story_file, int32 extent, |
| 107 |
void *output, int32 output_extent) |
| 108 |
{ |
| 109 |
int32 ll, csf; |
| 110 |
if ((TREATY_SELECTOR_INPUT & selector) && |
| 111 |
(csf=claim_story_file(story_file, extent))<NO_REPLY_RV) |
| 112 |
return INVALID_STORY_FILE_RV; |
| 113 |
|
| 114 |
|
| 115 |
if ((TREATY_SELECTOR_OUTPUT & selector) && |
| 116 |
(output_extent ==0 || |
| 117 |
output==NULL)) |
| 118 |
return INVALID_USAGE_RV; |
| 119 |
switch(selector) |
| 120 |
{ |
| 121 |
case GET_HOME_PAGE_SEL: |
| 122 |
ASSERT_OUTPUT_SIZE((signed) strlen(HOME_PAGE)+1); |
| 123 |
strcpy((char *) output,HOME_PAGE); |
| 124 |
return NO_REPLY_RV; |
| 125 |
case GET_FORMAT_NAME_SEL: |
| 126 |
ASSERT_OUTPUT_SIZE(512); |
| 127 |
strncpy((char *) output,STRFRY(FORMAT),output_extent-1); |
| 128 |
return NO_REPLY_RV; |
| 129 |
case GET_FILE_EXTENSIONS_SEL: |
| 130 |
ll=(strlen(FORMAT_EXT)+1) < 512 ? (strlen(FORMAT_EXT)+1):512; |
| 131 |
ASSERT_OUTPUT_SIZE(ll); |
| 132 |
strncpy((char *) output, FORMAT_EXT, output_extent); |
| 133 |
return NO_REPLY_RV; |
| 134 |
case CLAIM_STORY_FILE_SEL: |
| 135 |
return csf; |
| 136 |
case GET_STORY_FILE_METADATA_EXTENT_SEL: |
| 137 |
#ifndef NO_METADATA |
| 138 |
return get_story_file_metadata_extent(story_file, extent); |
| 139 |
#endif |
| 140 |
case GET_STORY_FILE_METADATA_SEL: |
| 141 |
#ifndef NO_METADATA |
| 142 |
return get_story_file_metadata(story_file, extent, (char *)output, output_extent); |
| 143 |
#else |
| 144 |
return NO_REPLY_RV; |
| 145 |
#endif |
| 146 |
case GET_STORY_FILE_COVER_EXTENT_SEL: |
| 147 |
#ifndef NO_COVER |
| 148 |
return get_story_file_cover_extent(story_file, extent); |
| 149 |
#endif |
| 150 |
case GET_STORY_FILE_COVER_FORMAT_SEL: |
| 151 |
#ifndef NO_COVER |
| 152 |
return get_story_file_cover_format(story_file, extent); |
| 153 |
#endif |
| 154 |
case GET_STORY_FILE_COVER_SEL: |
| 155 |
#ifndef NO_COVER |
| 156 |
return get_story_file_cover(story_file, extent, output, output_extent); |
| 157 |
#else |
| 158 |
return NO_REPLY_RV; |
| 159 |
#endif |
| 160 |
case GET_STORY_FILE_IFID_SEL: |
| 161 |
return get_story_file_IFID(story_file, extent, (char *)output, output_extent); |
| 162 |
case GET_STORY_FILE_EXTENSION_SEL: |
| 163 |
return get_story_file_extension(story_file, extent, (char *)output, output_extent); |
| 164 |
#ifdef CONTAINER_FORMAT |
| 165 |
case CONTAINER_GET_STORY_FORMAT_SEL: |
| 166 |
return get_story_format(story_file, extent, (char *)output, output_extent); |
| 167 |
case CONTAINER_GET_STORY_EXTENT_SEL: |
| 168 |
return get_story_extent(story_file, extent); |
| 169 |
case CONTAINER_GET_STORY_FILE_SEL: |
| 170 |
return get_story_file(story_file, extent, output, output_extent); |
| 171 |
#endif |
| 172 |
|
| 173 |
} |
| 174 |
return UNAVAILABLE_RV; |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
#else |
| 179 |
#error "treaty_builder should be used as most once in any source file"; |
| 180 |
#endif |