|
tesseract 3.04.01
|
00001 /* I don't expect anyone to run this program, ever again. It is 00002 * included primarily as documentation for how the GlyphLessFont was 00003 * created. 00004 */ 00005 00006 #include <stdio.h> 00007 #include <stdlib.h> 00008 #include <string.h> 00009 #include "GlyphLessFont.h" 00010 00011 #define LITTLE_ENDIAN 00012 00013 Offset_Table Offsets = { 00014 #ifdef LITTLE_ENDIAN 00015 0x00000100, /* sfnt_version */ 00016 0x0A00, /* numTables (10) */ 00017 0x8000, /* searchRange = Max power of 2 <= numTables*16 (128) */ 00018 0x0300, /* entrySelector Log2(searchRange) (3) */ 00019 0x2000, /* rangeShift = numTables*16 - searchRange (160 - 128 = 32) */ 00020 #else 00021 0x00010000, /* sfnt_version */ 00022 0x000A, /* numTables (10) */ 00023 0x0080, /* searchRange = Max power of 2 <= numTables*16 (128) */ 00024 0x0003, /* entrySelector Log2(searchRange) (3) */ 00025 0x0020, /* rangeShift = numTables*16 - searchRange (160 - 128 = 32) */ 00026 #endif 00027 }; 00028 00029 head_table head = { 00030 #ifdef LITTLE_ENDIAN 00031 0x00000100, /* sfnt_version */ 00032 0x00000100, /* font_version */ 00033 0, /* checksum adjustment */ 00034 0xF53C0F5F, /* Magic number */ 00035 0x0704, /* flags: 00036 * Bit 0 - 1 - baseline of font at y = 0 00037 * Bit 1 - 1 - Left sidebearing at x = 0 00038 * Bit 2 - 0 - instructions not dependent on font size 00039 * Bit 3 - 1 - force integer ppem 00040 * Bit 4 - 0 - instructions may not alter advance width 00041 * Bit 5 - 0 - Not laid out vertically 00042 * Bit 6 - 0 - required to be 0 00043 * Bit 7 - 0 - Does not require layout for rendering 00044 * Bit 8 - 0 - Not an AAT font with metamorphosis 00045 * Bit 9 - 0 - Not strongly right to left 00046 * Bit 10 - 0 - Does not require indic-style rearrangements 00047 * Bit 11 - 0 - Font data is not 'lossless' 00048 * Bit 12 - 0 - Font not 'covnerted' 00049 * Bit 13 - 0 - Not optimised for ClearType 00050 * Bit 14 - 1 - This is a 'last resort' font 00051 * Bit 15 - 0 - Reserved, must be 0 00052 */ 00053 0x0001, /* 16 units per em */ 00054 0x0,0x6EFC9ACF,/* Creation time */ 00055 0x0,0x6EFC9ACF,/* Modified time */ 00056 0, /* xMin */ 00057 0x0080, /* yMin */ 00058 0, /* xMax */ 00059 0x0100, /* yMax */ 00060 0x0000, /* macStyle (none) */ 00061 0x1000, /* Lowest readable size (16 pixels) */ 00062 0x0200, /* font direction (deprecated, should be 2) */ 00063 0, /* index to LOCA format (shorts) */ 00064 0 /* glyph data format (must be 0) */ 00065 #else 00066 0x00010000, /* afnt version */ 00067 0x00010000, /* font version */ 00068 0, /* checksum adjustment */ 00069 0x5F0F3CF5, /* Magic number */ 00070 0x0407, /* flags: 00071 * Bit 0 - 1 - baseline of font at y = 0 00072 * Bit 1 - 1 - Left sidebearing at x = 0 00073 * Bit 2 - 0 - instructions not dependent on font size 00074 * Bit 3 - 1 - force integer ppem 00075 * Bit 4 - 0 - instructions may not alter advance width 00076 * Bit 5 - 0 - Not laid out vertically 00077 * Bit 6 - 0 - required to be 0 00078 * Bit 7 - 0 - Does not require layout for rendering 00079 * Bit 8 - 0 - Not an AAT font with metamorphosis 00080 * Bit 9 - 0 - Not strongly right to left 00081 * Bit 10 - 0 - Does not require indic-style rearrangements 00082 * Bit 11 - 0 - Font data is not 'lossless' 00083 * Bit 12 - 0 - Font not 'covnerted' 00084 * Bit 13 - 0 - Not optimised for ClearType 00085 * Bit 14 - 1 - This is a 'last resort' font 00086 * Bit 15 - 0 - Reserved, must be 0 00087 */ 00088 0x0100, /* 16 units per em */ 00089 0x0,0xCF9AFC6E,/* Creation time */ 00090 0x0,0xCF9AFC6E,/* Modified time */ 00091 0, /* xMin */ 00092 0xFFFF, /* yMin */ 00093 0, /* xMax */ 00094 0x001, /* yMax */ 00095 0, /* macStyle (none) */ 00096 0x0010, /* Lowest readable size (16 pixels) */ 00097 0x0002, /* font direction (deprecated, should be 2) */ 00098 0, /* index to LOCA format (shorts) */ 00099 0 /* glyph data format (must be 0) */ 00100 #endif 00101 }; 00102 00103 hhea_table hhea = { 00104 #ifdef LITTLE_ENDIAN 00105 0x00000100, /* table version */ 00106 0x0100, /* Ascender */ 00107 #else 00108 0x00001000, /* table version */ 00109 0x0001, /* Ascender */ 00110 #endif 00111 0xFFFF, /* Descender */ 00112 0x0000, /* LineGap */ 00113 0x0000, /* AdvanceWidthMax */ 00114 0x0000, /* MinLeftSideBearing */ 00115 0x0000, /* MinRightSideBearing */ 00116 0x0000, /* xMaxExtent */ 00117 #ifdef LITTLE_ENDIAN 00118 0x0100, /* caretSlopeRise (1 = vertical) */ 00119 #else 00120 0x0001, /* caretSlopeRise (1 = vertical) */ 00121 #endif 00122 0x0000, /* caretslopeRun (0 = vertical) */ 00123 0x0000, /* caretOffset */ 00124 0x0000, /* Reserved1 */ 00125 0x0000, /* Reserved2 */ 00126 0x0000, /* Reserved3 */ 00127 0x0000, /* Reserved4 */ 00128 0x0000, /* merticDataFormat (must be 0) */ 00129 #ifdef LITTLE_ENDIAN 00130 0x0200, /* number of hMetric entries in hmtx */ 00131 #else 00132 0x0002, /* number of hMetric entries in hmtx */ 00133 #endif 00134 }; 00135 00136 maxp_table maxp = { 00137 #ifdef LITTLE_ENDIAN 00138 0x00000100, /* table version */ 00139 0x0200, /* numGlyphs */ 00140 0x00000000, /* maxPoints */ 00141 0x00000000, /* maxContours */ 00142 0x00000000, /* maxCompositePoints */ 00143 0x00000000, /* maxCompositeContours */ 00144 0x00000100, /* maxZones */ 00145 0x00000000, /* maxTwilightPoints */ 00146 0x00000000, /* maxStorage */ 00147 0x00000000, /* maxFunctionDefs */ 00148 0x00000000, /* maxInstructionDefs */ 00149 0x00000000, /* maxStackElements */ 00150 0x00000000, /* maxSizeOfInstructions */ 00151 0x00000000, /* maxComponentElements */ 00152 0x00000000, /* maxComponentDepth */ 00153 #else 00154 0x00001000, /* table version */ 00155 0x0002, /* numGlyphs */ 00156 0x00000000, /* maxPoints */ 00157 0x00000000, /* maxContours */ 00158 0x00000000, /* maxCompositePoints */ 00159 0x00000000, /* maxCompositeContours */ 00160 0x00000001, /* maxZones */ 00161 0x00000000, /* maxTwilightPoints */ 00162 0x00000000, /* maxStorage */ 00163 0x00000000, /* maxFunctionDefs */ 00164 0x00000000, /* maxInstructionDefs */ 00165 0x00000000, /* maxStackElements */ 00166 0x00000000, /* maxSizeOfInstructions */ 00167 0x00000000, /* maxComponentElements */ 00168 0x00000000, /* maxComponentDepth */ 00169 #endif 00170 }; 00171 00172 OS2_table OS2 = { 00173 #ifdef LITTLE_ENDIAN 00174 0x0300, /* table version */ 00175 0x0000, /* xAvgCharWidth */ 00176 0x9001, /* usWeight Class (400 = FW_NORMAL) */ 00177 0x0500, /* usWidthClass (5 = FWIDTH_NORMAL) */ 00178 0x0000, /* fsType (0 = no embedding restrictions) */ 00179 0x0000, /* ySubscriptXSize */ 00180 0x0000, /* ySubscriptYSize */ 00181 0x0000, /* ySubscriptXOffset */ 00182 0x0000, /* ySubscriptYOffset */ 00183 0x0000, /* ySuperscriptXSize */ 00184 0x0000, /* ySuperscriptYSize */ 00185 0x0000, /* ySuperscriptXOffset */ 00186 0x0000, /* ySuperscriptYOffset */ 00187 0x0000, /* yStikeoutPosition */ 00188 0x0000, /* sFamilyClass (0 = no classification) */ 00189 0,5,0,1,0,1,0,0,0,0,0, /* PANOSE */ 00190 0x00000000, /* ulUnicodeRanges1 */ 00191 0x00000000, /* ulUnicodeRanges2 */ 00192 0x00000000, /* ulUnicodeRanges3 */ 00193 0x00000000, /* ulUnicodeRanges4 */ 00194 'G', 'O', 'O', 'G', /* achVendID (GOOG = Google) */ 00195 0x4000, /* fsSelection (bit 6 set = regular font) */ 00196 0xFFFF, /* fsFirstCharIndex */ 00197 0x0000, /* fsLastCharIndex */ 00198 0x0100, /* sTypoAscender */ 00199 0xFFFF, /* StypoDescender */ 00200 0x0000, /* STypoLineGap */ 00201 0x0100, /* usWinAscent */ 00202 0x0100, /* usWinDescent */ 00203 0x00000080,/* ulCodePageRange1 */ 00204 0x00000000,/* ulCodePageRange2 */ 00205 0x0000, /* sxHeight */ 00206 0x0000, /* sCapHeight */ 00207 0x0000, /* usDefaultChar */ 00208 0x0100, /* usBreakChar */ 00209 0x0000, /* usMaxContent */ 00210 #else 00211 0x0003, /* table version */ 00212 0x0000, /* xAvgCharWidth */ 00213 0x0190, /* usWeight Class (400 = FW_NORMAL) */ 00214 0x0005, /* usWidthClass (5 = FWIDTH_NORMAL) */ 00215 0x0000, /* fsType (0 = no embedding restrictions) */ 00216 0x0000, /* ySubscriptXSize */ 00217 0x0000, /* ySubscriptYSize */ 00218 0x0000, /* ySubscriptXOffset */ 00219 0x0000, /* ySubscriptYOffset */ 00220 0x0000, /* ySuperscriptXSize */ 00221 0x0000, /* ySuperscriptYSize */ 00222 0x0000, /* ySuperscriptXOffset */ 00223 0x0000, /* ySuperscriptYOffset */ 00224 0x0000, /* yStikeoutPosition */ 00225 0x0000, /* sFamilyClass (0 = no classification) */ 00226 0,5,0,1,0,1,0,0,0,0,0, /* PANOSE */ 00227 0x00000000,/* ulUnicodeRanges1 */ 00228 0x00000000,/* ulUnicodeRanges2 */ 00229 0x00000000,/* ulUnicodeRanges3 */ 00230 0x00000000,/* ulUnicodeRanges4 */ 00231 'G', 'O', 'O', 'G', /* achVendID (GOOG = Google) */ 00232 0x0040, /* fsSelection (bit 6 set = regular font) */ 00233 0xFFFF, /* fsFirstCharIndex */ 00234 0x0000, /* fsLastCharIndex */ 00235 0x0001, /* sTypoAscender */ 00236 0xFFFF, /* StypoDescender */ 00237 0x0000, /* STypoLineGap */ 00238 0x0001, /* usWinAscent */ 00239 0x0001, /* usWinDescent */ 00240 0x80000000,/* ulCodePageRange1 */ 00241 0x00000000,/* ulCodePageRange2 */ 00242 0x0000, /* sxHeight */ 00243 0x0000, /* sCapHeight */ 00244 0x0000, /* usDefaultChar */ 00245 0x0001, /* usBreakChar */ 00246 0x0000, /* usMaxContent */ 00247 #endif 00248 }; 00249 00250 hmtx_table hmtx = { 00251 0x0000, 0x0000, 00252 0x0000, 0x0000 00253 }; 00254 00255 cmap_table cmap = { 00256 0x0000, /* Cmap version (0) */ 00257 #ifdef LITTLE_ENDIAN 00258 0x0200, /* numTables (2) */ 00259 0x0100, /* Start of first subtable record, platformID = 1 */ 00260 0x0000, /* encodingID = 0 */ 00261 0x14000000, /* Offset of data */ 00262 0x0300, /* Start of second subtable record, platformID = 3 */ 00263 0x0000, /* encodingID = 0 */ 00264 0x20000000, /* Offset of data */ 00265 0x0600, /* STart of Apple table (format 6) */ 00266 0x0C00, /* length of table (12) */ 00267 0x0000, /* Language must be 0 for non-Apple or 00268 non-specific language */ 00269 0x0000, /* firstCode = 0 */ 00270 0x0100, /* number of codes is 1 */ 00271 0x0000, /* GID is 0 */ 00272 0x0600, /* Start of MS Table (format 4) */ 00273 0x0C00, /* length of table (12) */ 00274 0x0000, /* Language must be 0 for non-Apple or 00275 non-specific language */ 00276 0x0000, /* firstCode = 0 */ 00277 0x0100, /* number of codes is 1 */ 00278 0x0000, /* GID is 0 */ 00279 #else 00280 0x0002, /* numTables (2) */ 00281 0x0001, 00282 0x0000, 00283 0x00000014, 00284 0x0003, 00285 0x0000, 00286 0x00000020, 00287 0x0006, 00288 0x000C, 00289 0x0000, 00290 0x0000, 00291 0x0001, 00292 0x0000, 00293 0x0006, 00294 0x000C, 00295 0x0000, 00296 0x0000, 00297 0x0001, 00298 0x0000, 00299 #endif 00300 }; 00301 00302 /* Changing these strings requires you to change the offset and lengths 00303 in the name table below */ 00304 char Macnamestring[] = {'V', 'e', 'r', 's', 'i', 'o', 'n', ' ', '1', '.', '0'}; 00305 char Unamestring[] = {0x00, 'V', 0x00, 'e', 0x00, 'r', 0x00, 's', 0x00, 'i', 00306 0x00, 'o', 0x00, 'n', 0x00, ' ', 0x00, '1', 0x00, '.', 00307 0x00, '0', 0x00, 0x00, 0x00}; 00308 name_table name = { 00309 0x0000, /* format 0 */ 00310 #ifdef LITTLE_ENDIAN 00311 0x0300, /* 3 records */ 00312 0x2A00, /* Offset of string storage */ 00313 00314 0x0000, /* Start of 1st name record, platform = 0 (Unicode) */ 00315 0x0300, /* Platform-specific ID = 0 */ 00316 0x0000, /* Language ID (0 = none) */ 00317 0x0500, /* name ID (5 = version string) */ 00318 0x1600, /* String length */ 00319 0x0B00, /* Offset from start of storage */ 00320 00321 0x0100, /* Start of 2nd name record, platform = 1 (Mac) */ 00322 0x0000, 00323 0x0000, 00324 0x0500, /* name ID (5 = version string) */ 00325 0x0B00, /* String length */ 00326 0x0000, /* Offset from start of storage */ 00327 00328 0x0300, /* Start of 3rd name record, platform = 3 */ 00329 0x0100, /* Platform-specific ID = 1 */ 00330 0x0904, /* Language ID (0x409 = US English) */ 00331 0x0500, /* name ID (5 = version string) */ 00332 0x1600, /* String length */ 00333 0x0B00, /* Offset from start of storage */ 00334 #else 00335 0x0003, /* 3 record2 */ 00336 0x002A, /* Offset of string storage */ 00337 00338 0x0000, /* Start of 1st name record, platform = 0 (Unicode) */ 00339 0x0003, /* Platform-specific ID = 0 */ 00340 0x0000, /* Language ID (0 = none) */ 00341 0x0005, /* name ID (5 = version string) */ 00342 0x0016, /* String length */ 00343 0x000B, /* Offset from start of storage */ 00344 00345 0x0001, /* Start of 2nd name record, platform = 1 (Mac) */ 00346 0x0000, 00347 0x0000, 00348 0x0500, /* name ID (5 = version string) */ 00349 0x000B, /* String length */ 00350 0x0000, /* Offset from start of storage */ 00351 00352 0x0003, /* Start of 3rd name record, platform = 3 */ 00353 0x0001, /* Platform-specific ID = 0 */ 00354 0x0409, /* Language ID (0 = none) */ 00355 0x0005, /* name ID (5 = version string) */ 00356 0x0016, /* String length */ 00357 0x000B, /* Offset from start of storage */ 00358 #endif 00359 }; 00360 00361 post_table post = { 00362 #ifdef LITTLE_ENDIAN 00363 0x0100, /* Version (2) */ 00364 #else 00365 0x0001, /* Version (2) */ 00366 #endif 00367 0x00000000, /* italicAngle */ 00368 0x0000, /* underlinePosition */ 00369 0x0000, /* underlineThickness */ 00370 #ifdef LITTLE_ENDIAN 00371 0x01000000, /* isFixedPitch */ 00372 #else 00373 0x00000001, /* isFixedPitch */ 00374 #endif 00375 0x00000000, /* minMemType42 */ 00376 0x00000000, /* maxMemType42 */ 00377 0x00000000, /* minMemType1 */ 00378 0x00000000, /* maxMemType1 */ 00379 }; 00380 00381 int main (int argc, char **argv) 00382 { 00383 FILE *OutputFile; 00384 TableRecord Table[10]; 00385 unsigned long offset = 00386 sizeof(Offset_Table) + (sizeof(TableRecord) * 10), 00387 length = 0, checksum = 0, HeadTableOffset, Working; 00388 short fword = -1; 00389 short loca = 0; 00390 long glyf = 0; 00391 unsigned int NameLength, i, FileLength; 00392 00393 printf("Ken's Glyph-free font creator\n"); 00394 if (argc != 2) { 00395 fprintf (stderr, "Usage: GlyphLessFont <output filename>\n"); 00396 exit (1); 00397 } 00398 00399 OutputFile = fopen (argv[1], "wb+"); 00400 if (OutputFile == 0) { 00401 fprintf (stderr, "Couldn't open file %s for writing\n", argv[1]); 00402 exit (1); 00403 } 00404 00405 fwrite (&Offsets, sizeof(Offset_Table), 1, OutputFile); 00406 memset(&Table, 0x00, sizeof(TableRecord) + 10); 00407 fwrite (&Table, sizeof (TableRecord), 10, OutputFile); 00408 offset = ftell(OutputFile); 00409 Table[3].offset = HeadTableOffset = offset; 00410 00411 /* The whole business of writing a TrueType file is complicated by 00412 * the way its laid out Firstly there is the fact that it wants 00413 * the tables to be laid out in alphabetical order, but it wants 00414 * the actual table data (which the table record points to) to be 00415 * in quite a different order. Then there's the requirement to 00416 * have all the table offsets be a multiple of 4 bytes. Finally 00417 * we have to calculate a checksum for each table as well, which 00418 * we cna't realistically do until we have written the table data, 00419 * but which gets stored in the table record at the start of the 00420 * file. 00421 * 00422 * So we start by writing a dumm set of table records, we'll fill 00423 * in the array as we go and once we've written all the data and 00424 * worked out the offsets and checksums of all the tables, we'll 00425 * come back and write the table records into the area we left 00426 * reserved. 00427 */ 00428 fwrite (&head, sizeof(head_table), 1, OutputFile); 00429 offset = ftell(OutputFile); 00430 Table[4].offset = offset; 00431 00432 fwrite (&hhea, sizeof(hhea_table), 1, OutputFile); 00433 offset = ftell(OutputFile); 00434 Table[7].offset = offset; 00435 00436 fwrite (&maxp, sizeof(maxp_table), 1, OutputFile); 00437 offset = ftell(OutputFile); 00438 Table[0].offset = offset; 00439 00440 fwrite (&OS2, sizeof(OS2_table), 1, OutputFile); 00441 offset = ftell(OutputFile); 00442 Table[5].offset = offset; 00443 00444 fwrite (&hmtx, sizeof(hmtx_table), 1, OutputFile); 00445 offset = ftell(OutputFile); 00446 Table[1].offset = offset; 00447 00448 fwrite (&cmap, sizeof(cmap_table), 1, OutputFile); 00449 offset = ftell(OutputFile); 00450 Table[6].offset = offset; 00451 00452 fwrite (&loca, sizeof(short), 1, OutputFile); 00453 fwrite (&loca, sizeof(short), 1, OutputFile); 00454 fwrite (&loca, sizeof(short), 1, OutputFile); 00455 fwrite (&loca, sizeof(short), 1, OutputFile); 00456 offset = ftell(OutputFile); 00457 Table[2].offset = offset; 00458 00459 fwrite (&glyf, sizeof(long), 1, OutputFile); 00460 offset = ftell(OutputFile); 00461 Table[8].offset = offset; 00462 00463 length = (sizeof(name_table) + sizeof(Macnamestring) + 00464 sizeof(Unamestring) + 3) / 4; 00465 length *= 4; 00466 NameLength = length; 00467 fwrite (&name, sizeof(name_table), 1, OutputFile); 00468 fwrite (&Macnamestring, sizeof(Macnamestring), 1, OutputFile); 00469 fwrite (&Unamestring, NameLength - 00470 (sizeof(name_table) + sizeof(Macnamestring)), 1, OutputFile); 00471 offset = ftell(OutputFile); 00472 Table[9].offset = offset; 00473 00474 fwrite (&post, sizeof(post_table), 1, OutputFile); 00475 FileLength = ftell(OutputFile); 00476 00477 Table[3].tag[0] = 'h'; 00478 Table[3].tag[1] = 'e'; 00479 Table[3].tag[2] = 'a'; 00480 Table[3].tag[3] = 'd'; 00481 Table[3].checkSum = 0; 00482 Table[3].length = sizeof(head_table) - 2; /* Don't count size 00483 of padding bytes in table */ 00484 00485 Table[4].tag[0] = 'h'; 00486 Table[4].tag[1] = 'h'; 00487 Table[4].tag[2] = 'e'; 00488 Table[4].tag[3] = 'a'; 00489 Table[4].checkSum = 0; 00490 Table[4].length = sizeof(hhea_table); 00491 00492 Table[7].tag[0] = 'm'; 00493 Table[7].tag[1] = 'a'; 00494 Table[7].tag[2] = 'x'; 00495 Table[7].tag[3] = 'p'; 00496 Table[7].checkSum = 0; 00497 Table[7].length = sizeof(maxp_table); 00498 00499 Table[0].tag[0] = 'O'; 00500 Table[0].tag[1] = 'S'; 00501 Table[0].tag[2] = '/'; 00502 Table[0].tag[3] = '2'; 00503 Table[0].checkSum = 0; 00504 Table[0].length = sizeof(OS2_table); 00505 00506 Table[5].tag[0] = 'h'; 00507 Table[5].tag[1] = 'm'; 00508 Table[5].tag[2] = 't'; 00509 Table[5].tag[3] = 'x'; 00510 Table[5].checkSum = 0; 00511 Table[5].length = sizeof(hmtx_table); 00512 00513 Table[1].tag[0] = 'c'; 00514 Table[1].tag[1] = 'm'; 00515 Table[1].tag[2] = 'a'; 00516 Table[1].tag[3] = 'p'; 00517 Table[1].checkSum = 0; 00518 Table[1].length = sizeof(cmap_table); 00519 00520 Table[6].tag[0] = 'l'; 00521 Table[6].tag[1] = 'o'; 00522 Table[6].tag[2] = 'c'; 00523 Table[6].tag[3] = 'a'; 00524 Table[6].checkSum = 0; 00525 Table[6].length = sizeof(USHORT) * 3; 00526 00527 Table[2].tag[0] = 'g'; 00528 Table[2].tag[1] = 'l'; 00529 Table[2].tag[2] = 'y'; 00530 Table[2].tag[3] = 'f'; 00531 Table[2].checkSum = 0; 00532 Table[2].length = 1; 00533 00534 Table[8].tag[0] = 'n'; 00535 Table[8].tag[1] = 'a'; 00536 Table[8].tag[2] = 'm'; 00537 Table[8].tag[3] = 'e'; 00538 Table[8].checkSum = 0; 00539 Table[8].length = (sizeof(name_table) + 00540 sizeof(Macnamestring) + 00541 sizeof(Unamestring) + 3) / 4; 00542 Table[8].length *= 4; 00543 NameLength = Table[8].length; 00544 00545 Table[9].tag[0] = 'p'; 00546 Table[9].tag[1] = 'o'; 00547 Table[9].tag[2] = 's'; 00548 Table[9].tag[3] = 't'; 00549 Table[9].checkSum = 0; 00550 Table[9].length = sizeof(post_table); 00551 00552 for (i=0;i<10;i++) { 00553 ULONG LENGTH, Sum = 0L; 00554 ULONG *EndPtr, *Data, *Current; 00555 00556 offset = Table[i].offset; 00557 length = Table[i].length; 00558 LENGTH = (length + 3 & ~3); 00559 Data = (ULONG *)malloc(LENGTH); 00560 memset(Data, 0x00, LENGTH); 00561 fseek(OutputFile, offset, SEEK_SET); 00562 fread(Data, length, 1, OutputFile); 00563 00564 Current = Data; 00565 EndPtr = Data + (LENGTH / sizeof(ULONG)); 00566 while(Current < EndPtr){ 00567 #ifdef LITTLE_ENDIAN 00568 Working = *Current++; 00569 Sum += ((Working & 0xff) << 24) + 00570 ((Working & 0xff00) << 8) + 00571 ((Working & 0xff0000) >> 8) + 00572 (Working >> 24); 00573 #else 00574 Sum += *Current++; 00575 #endif 00576 } 00577 free(Data); 00578 00579 #ifdef LITTLE_ENDIAN 00580 Table[i].offset = 00581 ((offset & 0xff) << 24) + 00582 ((offset & 0xff00) << 8) + 00583 ((offset & 0xff0000) >> 8) + 00584 (offset >> 24); 00585 Table[i].length = 00586 ((length & 0xff) << 24) + 00587 ((length & 0xff00) << 8) + 00588 ((length & 0xff0000) >> 8) + 00589 (length >> 24); 00590 Table[i].checkSum = 00591 ((Sum & 0xff) << 24) + 00592 ((Sum & 0xff00) << 8) + 00593 ((Sum & 0xff0000) >> 8) + 00594 (Sum >> 24); 00595 #else 00596 Table[i].checkSum = Sum; 00597 #endif 00598 } 00599 00600 fseek(OutputFile, sizeof(Offset_Table), SEEK_SET); 00601 fwrite (&Table, sizeof(TableRecord), 10, OutputFile); 00602 00603 fseek(OutputFile, 0, SEEK_SET); 00604 00605 for (i=0;i < FileLength / sizeof(long);i++) { 00606 fread(&Working, sizeof(long), 1, OutputFile); 00607 #ifdef LITTLE_ENDIAN 00608 checksum += ((Working & 0xff) << 24) + 00609 ((Working & 0xff00) << 8) + 00610 ((Working & 0xff0000) >> 8) + 00611 (Working >> 24); 00612 #else 00613 checksum += Working; 00614 #endif 00615 } 00616 checksum = 0xB1B0AFBA - checksum; 00617 #ifdef LITTLE_ENDIAN 00618 head.checkSumAdjustment = 00619 ((checksum & 0xff) << 24) + 00620 ((checksum & 0xff00) << 8) + 00621 ((checksum & 0xff0000) >> 8) + 00622 (checksum >> 24); 00623 #else 00624 head.checkSumAdjustment = checksum; 00625 #endif 00626 fseek(OutputFile, HeadTableOffset, SEEK_SET); 00627 fwrite (&head, sizeof(head_table), 1, OutputFile); 00628 fclose(OutputFile); 00629 00630 return 0; 00631 }