Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2282 lines
54 KiB

  1. /*++
  2. Copyright (c) 1991-1999, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. unicode.c
  5. Abstract:
  6. This file contains functions necessary to parse and write the locale
  7. independent (Unicode) tables to a data file.
  8. External Routines in this file:
  9. ParseUnicode
  10. WriteUnicode
  11. Revision History:
  12. 12-10-91 JulieB Created.
  13. --*/
  14. //
  15. // Include Files.
  16. //
  17. #include "nlstrans.h"
  18. //
  19. // Forward Declarations.
  20. //
  21. int
  22. GetAsciiDigits(
  23. PUNICODE pUnic,
  24. int Size);
  25. int
  26. GetFoldCZone(
  27. PUNICODE pUnic,
  28. int Size);
  29. int
  30. GetHiragana(
  31. PUNICODE pUnic,
  32. int Size);
  33. int
  34. GetKatakana(
  35. PUNICODE pUnic,
  36. int Size);
  37. int
  38. GetHalfWidth(
  39. PUNICODE pUnic,
  40. int Size);
  41. int
  42. GetFullWidth(
  43. PUNICODE pUnic,
  44. int Size);
  45. int
  46. GetTraditional(
  47. PUNICODE pUnic,
  48. int Size);
  49. int
  50. GetSimplified(
  51. PUNICODE pUnic,
  52. int Size);
  53. int
  54. GetCompTable(
  55. PUNICODE pUnic,
  56. int Size);
  57. void
  58. Get844Value(
  59. P844_ARRAY pArr,
  60. WORD WChar,
  61. WORD *Value);
  62. void
  63. InsertCompGrid(
  64. PCOMP_GRID pCompGrid,
  65. WORD PreComp,
  66. WORD BaseOff,
  67. WORD NonSpOff);
  68. int
  69. WriteAsciiDigits(
  70. PUNICODE pUnic,
  71. FILE *pOutputFile);
  72. int
  73. WriteFoldCZone(
  74. PUNICODE pUnic,
  75. FILE *pOutputFile);
  76. int
  77. WriteHiragana(
  78. PUNICODE pUnic,
  79. FILE *pOutputFile);
  80. int
  81. WriteKatakana(
  82. PUNICODE pUnic,
  83. FILE *pOutputFile);
  84. int
  85. WriteHalfWidth(
  86. PUNICODE pUnic,
  87. FILE *pOutputFile);
  88. int
  89. WriteFullWidth(
  90. PUNICODE pUnic,
  91. FILE *pOutputFile);
  92. int
  93. WriteTraditional(
  94. PUNICODE pUnic,
  95. FILE *pOutputFile);
  96. int
  97. WriteSimplified(
  98. PUNICODE pUnic,
  99. FILE *pOutputFile);
  100. int
  101. WritePrecomposed(
  102. PUNICODE pUnic,
  103. FILE *pOutputFile);
  104. int
  105. WriteComposite(
  106. PUNICODE pUnic,
  107. FILE *pOutputFile);
  108. int
  109. WriteGrid(
  110. PUNICODE pUnic,
  111. FILE *pOutputFile);
  112. //-------------------------------------------------------------------------//
  113. // EXTERNAL ROUTINES //
  114. //-------------------------------------------------------------------------//
  115. ////////////////////////////////////////////////////////////////////////////
  116. //
  117. // ParseUnicode
  118. //
  119. // This routine parses the input file for the locale independent (Unicode)
  120. // tables. This routine is only entered when the UNICODE keyword is found.
  121. // The parsing continues until the ENDUNICODE keyword is found.
  122. //
  123. // 12-10-91 JulieB Created.
  124. ////////////////////////////////////////////////////////////////////////////
  125. int ParseUnicode(
  126. PUNICODE pUnic,
  127. PSZ pszKeyWord)
  128. {
  129. int size; // size of table to follow
  130. while (fscanf(pInputFile, "%s", pszKeyWord) == 1)
  131. {
  132. if (_stricmp(pszKeyWord, "ASCIIDIGITS") == 0)
  133. {
  134. if (Verbose)
  135. printf("\n\nFound ASCIIDIGITS keyword.\n");
  136. //
  137. // Get size parameter.
  138. //
  139. if (GetSize(&size))
  140. return (1);
  141. //
  142. // Get ASCIIDIGITS Table.
  143. //
  144. if (GetAsciiDigits(pUnic, size))
  145. return (1);
  146. //
  147. // Set WriteFlags for ASCIIDIGITS Table.
  148. //
  149. pUnic->WriteFlags |= F_ADIGIT;
  150. }
  151. else if (_stricmp(pszKeyWord, "FOLDCZONE") == 0)
  152. {
  153. if (Verbose)
  154. printf("\n\nFound FOLDCZONE keyword.\n");
  155. //
  156. // Get size parameter.
  157. //
  158. if (GetSize(&size))
  159. return (1);
  160. //
  161. // Get FOLDCZONE Table.
  162. //
  163. if (GetFoldCZone(pUnic, size))
  164. return (1);
  165. //
  166. // Set WriteFlags for FOLDCZONE Table.
  167. //
  168. pUnic->WriteFlags |= F_CZONE;
  169. }
  170. else if (_stricmp(pszKeyWord, "HIRAGANA") == 0)
  171. {
  172. if (Verbose)
  173. printf("\n\nFound HIRAGANA keyword.\n");
  174. //
  175. // Get size parameter.
  176. //
  177. if (GetSize(&size))
  178. return (1);
  179. //
  180. // Get HIRAGANA Table.
  181. //
  182. if (GetHiragana(pUnic, size))
  183. return (1);
  184. //
  185. // Set WriteFlags for HIRAGANA Table.
  186. //
  187. pUnic->WriteFlags |= F_HIRAGANA;
  188. }
  189. else if (_stricmp(pszKeyWord, "KATAKANA") == 0)
  190. {
  191. if (Verbose)
  192. printf("\n\nFound KATAKANA keyword.\n");
  193. //
  194. // Get size parameter.
  195. //
  196. if (GetSize(&size))
  197. return (1);
  198. //
  199. // Get KATAKANA Table.
  200. //
  201. if (GetKatakana(pUnic, size))
  202. return (1);
  203. //
  204. // Set WriteFlags for KATAKANA Table.
  205. //
  206. pUnic->WriteFlags |= F_KATAKANA;
  207. }
  208. else if (_stricmp(pszKeyWord, "HALFWIDTH") == 0)
  209. {
  210. if (Verbose)
  211. printf("\n\nFound HALFWIDTH keyword.\n");
  212. //
  213. // Get size parameter.
  214. //
  215. if (GetSize(&size))
  216. return (1);
  217. //
  218. // Get HALFWIDTH Table.
  219. //
  220. if (GetHalfWidth(pUnic, size))
  221. return (1);
  222. //
  223. // Set WriteFlags for HALFWIDTH Table.
  224. //
  225. pUnic->WriteFlags |= F_HALFWIDTH;
  226. }
  227. else if (_stricmp(pszKeyWord, "FULLWIDTH") == 0)
  228. {
  229. if (Verbose)
  230. printf("\n\nFound FULLWIDTH keyword.\n");
  231. //
  232. // Get size parameter.
  233. //
  234. if (GetSize(&size))
  235. return (1);
  236. //
  237. // Get FULLWIDTH Table.
  238. //
  239. if (GetFullWidth(pUnic, size))
  240. return (1);
  241. //
  242. // Set WriteFlags for FULLWIDTH Table.
  243. //
  244. pUnic->WriteFlags |= F_FULLWIDTH;
  245. }
  246. else if (_stricmp(pszKeyWord, "TRADITIONAL_CHINESE") == 0)
  247. {
  248. if (Verbose)
  249. printf("\n\nFound TRADITIONAL_CHINESE keyword.\n");
  250. //
  251. // Get size parameter.
  252. //
  253. if (GetSize(&size))
  254. return (1);
  255. //
  256. // Get TRADITIONAL_CHINESE Table.
  257. //
  258. if (GetTraditional(pUnic, size))
  259. return (1);
  260. //
  261. // Set WriteFlags for TRADITIONAL_CHINESE Table.
  262. //
  263. pUnic->WriteFlags |= F_TRADITIONAL;
  264. }
  265. else if (_stricmp(pszKeyWord, "SIMPLIFIED_CHINESE") == 0)
  266. {
  267. if (Verbose)
  268. printf("\n\nFound SIMPLIFIED_CHINESE keyword.\n");
  269. //
  270. // Get size parameter.
  271. //
  272. if (GetSize(&size))
  273. return (1);
  274. //
  275. // Get SIMPLIFIED_CHINESE Table.
  276. //
  277. if (GetSimplified(pUnic, size))
  278. return (1);
  279. //
  280. // Set WriteFlags for SIMPLIFIED_CHINESE Table.
  281. //
  282. pUnic->WriteFlags |= F_SIMPLIFIED;
  283. }
  284. else if (_stricmp(pszKeyWord, "COMP") == 0)
  285. {
  286. if (Verbose)
  287. printf("\n\nFound COMP keyword.\n");
  288. //
  289. // Get size parameter.
  290. //
  291. if (GetSize(&size))
  292. return (1);
  293. //
  294. // Get Precomposed and Composite Tables.
  295. //
  296. if (GetCompTable(pUnic, size))
  297. return (1);
  298. //
  299. // Set WriteFlags for COMP Tables.
  300. //
  301. pUnic->WriteFlags |= F_COMP;
  302. }
  303. else if (_stricmp(pszKeyWord, "ENDUNICODE") == 0)
  304. {
  305. if (Verbose)
  306. printf("\n\nFound ENDUNICODE keyword.\n");
  307. //
  308. // Return success.
  309. //
  310. return (0);
  311. }
  312. else
  313. {
  314. printf("Parse Error: Invalid Instruction '%s'.\n", pszKeyWord);
  315. return (1);
  316. }
  317. }
  318. //
  319. // If this point is reached, then the ENDUNICODE keyword was
  320. // not found. Return an error.
  321. //
  322. printf("Parse Error: Expecting ENDUNICODE keyword.\n");
  323. return (1);
  324. }
  325. ////////////////////////////////////////////////////////////////////////////
  326. //
  327. // WriteUnicode
  328. //
  329. // This routine writes the locale independent (Unicode) tables to an
  330. // output file.
  331. //
  332. // 12-10-91 JulieB Created.
  333. ////////////////////////////////////////////////////////////////////////////
  334. int WriteUnicode(
  335. PUNICODE pUnic)
  336. {
  337. FILE *pOutputFile; // ptr to output file
  338. //
  339. // Make sure all tables are present.
  340. //
  341. if (!((pUnic->WriteFlags & F_ADIGIT) &&
  342. (pUnic->WriteFlags & F_CZONE) &&
  343. (pUnic->WriteFlags & F_COMP) &&
  344. (pUnic->WriteFlags & F_HIRAGANA) &&
  345. (pUnic->WriteFlags & F_KATAKANA) &&
  346. (pUnic->WriteFlags & F_HALFWIDTH) &&
  347. (pUnic->WriteFlags & F_FULLWIDTH) &&
  348. (pUnic->WriteFlags & F_TRADITIONAL) &&
  349. (pUnic->WriteFlags & F_SIMPLIFIED)))
  350. {
  351. printf("Write Error: All tables must be present -\n");
  352. printf(" Ascii Digits, Compatibility Zone, Composite Tables,\n");
  353. printf(" Hiragana, Katakana, Half Width, Full Width,\n");
  354. printf(" Traditional Chinese, and Simplified Chinese.\n");
  355. return (1);
  356. }
  357. //
  358. // Make sure output file can be opened for writing.
  359. //
  360. if ((pOutputFile = fopen(UNICODE_FILE, "w+b")) == 0)
  361. {
  362. printf("Error opening output file %s.\n", UNICODE_FILE);
  363. return (1);
  364. }
  365. if (Verbose)
  366. printf("\n\nWriting output file %s...\n", UNICODE_FILE);
  367. //
  368. // Write Ascii Digits Table to output file.
  369. //
  370. if (WriteAsciiDigits(pUnic, pOutputFile))
  371. {
  372. fclose(pOutputFile);
  373. return (1);
  374. }
  375. //
  376. // Free Ascii Digits table structures.
  377. //
  378. Free844(pUnic->pADigit);
  379. //
  380. // Write Fold Compatibility Zone Table to output file.
  381. //
  382. if (WriteFoldCZone(pUnic, pOutputFile))
  383. {
  384. fclose(pOutputFile);
  385. return (1);
  386. }
  387. //
  388. // Free Fold Compatibility Zone table structures.
  389. //
  390. Free844(pUnic->pCZone);
  391. //
  392. // Write Hiragana Table to output file.
  393. //
  394. if (WriteHiragana(pUnic, pOutputFile))
  395. {
  396. fclose(pOutputFile);
  397. return (1);
  398. }
  399. //
  400. // Free Hiragana table structures.
  401. //
  402. Free844(pUnic->pHiragana);
  403. //
  404. // Write Katakana Table to output file.
  405. //
  406. if (WriteKatakana(pUnic, pOutputFile))
  407. {
  408. fclose(pOutputFile);
  409. return (1);
  410. }
  411. //
  412. // Free Katakana table structures.
  413. //
  414. Free844(pUnic->pKatakana);
  415. //
  416. // Write Half Width Table to output file.
  417. //
  418. if (WriteHalfWidth(pUnic, pOutputFile))
  419. {
  420. fclose(pOutputFile);
  421. return (1);
  422. }
  423. //
  424. // Free Half Width table structures.
  425. //
  426. Free844(pUnic->pHalfWidth);
  427. //
  428. // Write Full Width Table to output file.
  429. //
  430. if (WriteFullWidth(pUnic, pOutputFile))
  431. {
  432. fclose(pOutputFile);
  433. return (1);
  434. }
  435. //
  436. // Free Full Width table structures.
  437. //
  438. Free844(pUnic->pFullWidth);
  439. //
  440. // Write Traditional Chinese Table to output file.
  441. //
  442. if (WriteTraditional(pUnic, pOutputFile))
  443. {
  444. fclose(pOutputFile);
  445. return (1);
  446. }
  447. //
  448. // Free Traditional Chinese table structures.
  449. //
  450. Free844(pUnic->pTraditional);
  451. //
  452. // Write Simplified Chinese Table to output file.
  453. //
  454. if (WriteSimplified(pUnic, pOutputFile))
  455. {
  456. fclose(pOutputFile);
  457. return (1);
  458. }
  459. //
  460. // Free Simplified Chinese table structures.
  461. //
  462. Free844(pUnic->pSimplified);
  463. //
  464. // Write Precomposed Table to output file.
  465. //
  466. if (WritePrecomposed(pUnic, pOutputFile))
  467. {
  468. fclose(pOutputFile);
  469. return (1);
  470. }
  471. //
  472. // Write Composite Table to output file.
  473. //
  474. if (WriteComposite(pUnic, pOutputFile))
  475. {
  476. fclose(pOutputFile);
  477. return (1);
  478. }
  479. //
  480. // Free Comp table structures.
  481. //
  482. Free844(pUnic->pPreComp);
  483. Free844(pUnic->pBase);
  484. Free844(pUnic->pNonSp);
  485. if (pUnic->pCompGrid != NULL)
  486. {
  487. free(pUnic->pCompGrid);
  488. }
  489. //
  490. // Close the output file.
  491. //
  492. fclose(pOutputFile);
  493. //
  494. // Return success.
  495. //
  496. printf("\nSuccessfully wrote output file %s\n", UNICODE_FILE);
  497. return (0);
  498. }
  499. //-------------------------------------------------------------------------//
  500. // INTERNAL ROUTINES //
  501. //-------------------------------------------------------------------------//
  502. ////////////////////////////////////////////////////////////////////////////
  503. //
  504. // GetAsciiDigits
  505. //
  506. // This routine gets the ascii digits table from the input file. It uses
  507. // the size parameter to know when to stop reading from the file. If an
  508. // error is encountered, a message is printed and an error is returned.
  509. //
  510. // 07-30-91 JulieB Created.
  511. // 12-10-91 JulieB Modified for new table format.
  512. ////////////////////////////////////////////////////////////////////////////
  513. int GetAsciiDigits(
  514. PUNICODE pUnic,
  515. int Size)
  516. {
  517. int Digit; // digit value
  518. int Ascii; // ascii digit value
  519. register int Ctr; // loop counter
  520. int NumItems; // number of items returned from fscanf
  521. //
  522. // Allocate top buffer for 8:4:4 table - 256 pointers.
  523. //
  524. if (Allocate8(&pUnic->pADigit))
  525. {
  526. return (1);
  527. }
  528. //
  529. // For each entry in table, read in digit value and ascii digit
  530. // translation value from input file, allocate necessary 16 word
  531. // buffers based on wide character value, and store difference
  532. // to ascii digit.
  533. //
  534. for (Ctr = 0; Ctr < Size; Ctr++)
  535. {
  536. //
  537. // Read in digit and ascii digit values.
  538. //
  539. NumItems = fscanf( pInputFile,
  540. "%x %x ;%*[^\n]",
  541. &Digit,
  542. &Ascii );
  543. if (NumItems != 2)
  544. {
  545. printf("Parse Error: Error reading ASCIIDIGITS values.\n");
  546. return (1);
  547. }
  548. if (Verbose)
  549. printf(" Digit = %x\tAscii = %x\n", Digit, Ascii);
  550. //
  551. // Insert difference (Ascii - Digit) into 8:4:4 table.
  552. //
  553. if (Insert844( pUnic->pADigit,
  554. (WORD)Digit,
  555. (WORD)(Ascii - Digit),
  556. &pUnic->ADBuf2,
  557. &pUnic->ADBuf3,
  558. sizeof(WORD) ))
  559. {
  560. return (1);
  561. }
  562. }
  563. //
  564. // Return success.
  565. //
  566. return (0);
  567. }
  568. ////////////////////////////////////////////////////////////////////////////
  569. //
  570. // GetFoldCZone
  571. //
  572. // This routine gets the FOLDCZONE table from the input file. It uses
  573. // the size parameter to know when to stop reading from the file. If an
  574. // error is encountered, a message is printed and an error is returned.
  575. //
  576. // 07-30-91 JulieB Created.
  577. // 12-10-91 JulieB Modified for new table format.
  578. ////////////////////////////////////////////////////////////////////////////
  579. int GetFoldCZone(
  580. PUNICODE pUnic,
  581. int Size)
  582. {
  583. int CZone; // compatibility zone value
  584. int Ascii; // ascii value
  585. register int Ctr; // loop counter
  586. int NumItems; // number of items returned from fscanf
  587. //
  588. // Allocate top buffer for 8:4:4 table - 256 pointers.
  589. //
  590. if (Allocate8(&pUnic->pCZone))
  591. {
  592. return (1);
  593. }
  594. //
  595. // For each entry in table, read in czone value and ascii
  596. // translation value from input file, allocate necessary 16 word
  597. // buffers based on wide character value, and store difference to
  598. // ascii value.
  599. //
  600. for (Ctr = 0; Ctr < Size; Ctr++)
  601. {
  602. //
  603. // Read in CZone and Ascii values.
  604. //
  605. NumItems = fscanf( pInputFile,
  606. "%x %x ;%*[^\n]",
  607. &CZone,
  608. &Ascii );
  609. if (NumItems != 2)
  610. {
  611. printf("Parse Error: Error reading FOLDCZONE values.\n");
  612. return (1);
  613. }
  614. if (Verbose)
  615. printf(" CZone = %x\tAscii = %x\n", CZone, Ascii);
  616. //
  617. // Insert difference (Ascii - CZone) into 8:4:4 table.
  618. //
  619. if (Insert844( pUnic->pCZone,
  620. (WORD)CZone,
  621. (WORD)(Ascii - CZone),
  622. &pUnic->CZBuf2,
  623. &pUnic->CZBuf3,
  624. sizeof(WORD) ))
  625. {
  626. return (1);
  627. }
  628. }
  629. //
  630. // Return success.
  631. //
  632. return (0);
  633. }
  634. ////////////////////////////////////////////////////////////////////////////
  635. //
  636. // GetHiragana
  637. //
  638. // This routine gets the Hiragana table (Katakana to Hiragana) from the
  639. // input file. It uses the size parameter to know when to stop reading
  640. // from the file. If an error is encountered, a message is printed and
  641. // an error is returned.
  642. //
  643. // 07-14-93 JulieB Created.
  644. ////////////////////////////////////////////////////////////////////////////
  645. int GetHiragana(
  646. PUNICODE pUnic,
  647. int Size)
  648. {
  649. int Kata; // Katakana value
  650. int Hira; // Hiragana value
  651. register int Ctr; // loop counter
  652. int NumItems; // number of items returned from fscanf
  653. //
  654. // Allocate top buffer for 8:4:4 table - 256 pointers.
  655. //
  656. if (Allocate8(&pUnic->pHiragana))
  657. {
  658. return (1);
  659. }
  660. //
  661. // For each entry in table, read in katakana value and hiragana
  662. // translation value from input file, allocate necessary 16 word
  663. // buffers based on wide character value, and store difference to
  664. // hiragana value.
  665. //
  666. for (Ctr = 0; Ctr < Size; Ctr++)
  667. {
  668. //
  669. // Read in katakana and hiragana values.
  670. //
  671. NumItems = fscanf( pInputFile,
  672. "%x %x ;%*[^\n]",
  673. &Kata,
  674. &Hira );
  675. if (NumItems != 2)
  676. {
  677. printf("Parse Error: Error reading HIRAGANA values.\n");
  678. return (1);
  679. }
  680. if (Verbose)
  681. printf(" Katakana = %x\tHiragana = %x\n", Kata, Hira);
  682. //
  683. // Insert difference (Kata - Hira) into 8:4:4 table.
  684. //
  685. if (Insert844( pUnic->pHiragana,
  686. (WORD)Kata,
  687. (WORD)(Hira - Kata),
  688. &pUnic->HGBuf2,
  689. &pUnic->HGBuf3,
  690. sizeof(WORD) ))
  691. {
  692. return (1);
  693. }
  694. }
  695. //
  696. // Return success.
  697. //
  698. return (0);
  699. }
  700. ////////////////////////////////////////////////////////////////////////////
  701. //
  702. // GetKatakana
  703. //
  704. // This routine gets the Katakana table (Hiragana to Katakana) from the
  705. // input file. It uses the size parameter to know when to stop reading
  706. // from the file. If an error is encountered, a message is printed and
  707. // an error is returned.
  708. //
  709. // 07-14-93 JulieB Created.
  710. ////////////////////////////////////////////////////////////////////////////
  711. int GetKatakana(
  712. PUNICODE pUnic,
  713. int Size)
  714. {
  715. int Hira; // Hiragana value
  716. int Kata; // Katakana value
  717. register int Ctr; // loop counter
  718. int NumItems; // number of items returned from fscanf
  719. //
  720. // Allocate top buffer for 8:4:4 table - 256 pointers.
  721. //
  722. if (Allocate8(&pUnic->pKatakana))
  723. {
  724. return (1);
  725. }
  726. //
  727. // For each entry in table, read in hiragana value and katakana
  728. // translation value from input file, allocate necessary 16 word
  729. // buffers based on wide character value, and store difference to
  730. // katakana value.
  731. //
  732. for (Ctr = 0; Ctr < Size; Ctr++)
  733. {
  734. //
  735. // Read in hiragana and katakana values.
  736. //
  737. NumItems = fscanf( pInputFile,
  738. "%x %x ;%*[^\n]",
  739. &Hira,
  740. &Kata );
  741. if (NumItems != 2)
  742. {
  743. printf("Parse Error: Error reading KATAKANA values.\n");
  744. return (1);
  745. }
  746. if (Verbose)
  747. printf(" Hiragana = %x\tKatakana = %x\n", Hira, Kata);
  748. //
  749. // Insert difference (Hira - Kata) into 8:4:4 table.
  750. //
  751. if (Insert844( pUnic->pKatakana,
  752. (WORD)Hira,
  753. (WORD)(Kata - Hira),
  754. &pUnic->KKBuf2,
  755. &pUnic->KKBuf3,
  756. sizeof(WORD) ))
  757. {
  758. return (1);
  759. }
  760. }
  761. //
  762. // Return success.
  763. //
  764. return (0);
  765. }
  766. ////////////////////////////////////////////////////////////////////////////
  767. //
  768. // GetHalfWidth
  769. //
  770. // This routine gets the Half Width table (Full Width to Half Width) from
  771. // the input file. It uses the size parameter to know when to stop reading
  772. // from the file. If an error is encountered, a message is printed and
  773. // an error is returned.
  774. //
  775. // 07-14-93 JulieB Created.
  776. ////////////////////////////////////////////////////////////////////////////
  777. int GetHalfWidth(
  778. PUNICODE pUnic,
  779. int Size)
  780. {
  781. int Full; // Full Width value
  782. int Half; // Half Width value
  783. register int Ctr; // loop counter
  784. int NumItems; // number of items returned from fscanf
  785. //
  786. // Allocate top buffer for 8:4:4 table - 256 pointers.
  787. //
  788. if (Allocate8(&pUnic->pHalfWidth))
  789. {
  790. return (1);
  791. }
  792. //
  793. // For each entry in table, read in full width value and half width
  794. // translation value from input file, allocate necessary 16 word
  795. // buffers based on wide character value, and store difference to
  796. // half width value.
  797. //
  798. for (Ctr = 0; Ctr < Size; Ctr++)
  799. {
  800. //
  801. // Read in full width and half width values.
  802. //
  803. NumItems = fscanf( pInputFile,
  804. "%x %x ;%*[^\n]",
  805. &Full,
  806. &Half );
  807. if (NumItems != 2)
  808. {
  809. printf("Parse Error: Error reading HALFWIDTH values.\n");
  810. return (1);
  811. }
  812. if (Verbose)
  813. printf(" Full Width = %x\tHalf Width = %x\n", Full, Half);
  814. //
  815. // Insert difference (Full - Half) into 8:4:4 table.
  816. //
  817. if (Insert844( pUnic->pHalfWidth,
  818. (WORD)Full,
  819. (WORD)(Half - Full),
  820. &pUnic->HWBuf2,
  821. &pUnic->HWBuf3,
  822. sizeof(WORD) ))
  823. {
  824. return (1);
  825. }
  826. }
  827. //
  828. // Return success.
  829. //
  830. return (0);
  831. }
  832. ////////////////////////////////////////////////////////////////////////////
  833. //
  834. // GetFullWidth
  835. //
  836. // This routine gets the Full Width table (Half Width to Full Width) from
  837. // the input file. It uses the size parameter to know when to stop reading
  838. // from the file. If an error is encountered, a message is printed and
  839. // an error is returned.
  840. //
  841. // 07-14-93 JulieB Created.
  842. ////////////////////////////////////////////////////////////////////////////
  843. int GetFullWidth(
  844. PUNICODE pUnic,
  845. int Size)
  846. {
  847. int Half; // Half Width value
  848. int Full; // Full Width value
  849. register int Ctr; // loop counter
  850. int NumItems; // number of items returned from fscanf
  851. //
  852. // Allocate top buffer for 8:4:4 table - 256 pointers.
  853. //
  854. if (Allocate8(&pUnic->pFullWidth))
  855. {
  856. return (1);
  857. }
  858. //
  859. // For each entry in table, read in half width value and full width
  860. // translation value from input file, allocate necessary 16 word
  861. // buffers based on wide character value, and store difference to
  862. // full width value.
  863. //
  864. for (Ctr = 0; Ctr < Size; Ctr++)
  865. {
  866. //
  867. // Read in half width and full width values.
  868. //
  869. NumItems = fscanf( pInputFile,
  870. "%x %x ;%*[^\n]",
  871. &Half,
  872. &Full );
  873. if (NumItems != 2)
  874. {
  875. printf("Parse Error: Error reading FULLWIDTH values.\n");
  876. return (1);
  877. }
  878. if (Verbose)
  879. printf(" Half Width = %x\tFull Width = %x\n", Half, Full);
  880. //
  881. // Insert difference (Half - Full) into 8:4:4 table.
  882. //
  883. if (Insert844( pUnic->pFullWidth,
  884. (WORD)Half,
  885. (WORD)(Full - Half),
  886. &pUnic->FWBuf2,
  887. &pUnic->FWBuf3,
  888. sizeof(WORD) ))
  889. {
  890. return (1);
  891. }
  892. }
  893. //
  894. // Return success.
  895. //
  896. return (0);
  897. }
  898. ////////////////////////////////////////////////////////////////////////////
  899. //
  900. // GetTraditional
  901. //
  902. // This routine gets the Traditional table (Simplified to Traditional) from
  903. // the input file. It uses the size parameter to know when to stop reading
  904. // from the file. If an error is encountered, a message is printed and
  905. // an error is returned.
  906. //
  907. // 05-07-96 JulieB Created.
  908. ////////////////////////////////////////////////////////////////////////////
  909. int GetTraditional(
  910. PUNICODE pUnic,
  911. int Size)
  912. {
  913. int Simplified; // Simplified value
  914. int Traditional; // Traditional value
  915. register int Ctr; // loop counter
  916. int NumItems; // number of items returned from fscanf
  917. //
  918. // Allocate top buffer for 8:4:4 table - 256 pointers.
  919. //
  920. if (Allocate8(&pUnic->pTraditional))
  921. {
  922. return (1);
  923. }
  924. //
  925. // For each entry in table, read in simplified value and traditional
  926. // translation value from input file, allocate necessary 16 word
  927. // buffers based on wide character value, and store difference to
  928. // traditional value.
  929. //
  930. for (Ctr = 0; Ctr < Size; Ctr++)
  931. {
  932. //
  933. // Read in simplified and traditional values.
  934. //
  935. NumItems = fscanf( pInputFile,
  936. "%x %x ;%*[^\n]",
  937. &Simplified,
  938. &Traditional );
  939. if (NumItems != 2)
  940. {
  941. printf("Parse Error: Error reading TRADITIONAL_CHINESE values.\n");
  942. return (1);
  943. }
  944. if (Verbose)
  945. printf(" Simplified = %x\tTraditional = %x\n",
  946. Simplified, Traditional);
  947. //
  948. // Insert difference (Simplified - Traditional) into 8:4:4 table.
  949. //
  950. if (Insert844( pUnic->pTraditional,
  951. (WORD)Simplified,
  952. (WORD)(Traditional - Simplified),
  953. &pUnic->TRBuf2,
  954. &pUnic->TRBuf3,
  955. sizeof(WORD) ))
  956. {
  957. return (1);
  958. }
  959. }
  960. //
  961. // Return success.
  962. //
  963. return (0);
  964. }
  965. ////////////////////////////////////////////////////////////////////////////
  966. //
  967. // GetSimplified
  968. //
  969. // This routine gets the Simplified table (Traditional to Simplified) from
  970. // the input file. It uses the size parameter to know when to stop reading
  971. // from the file. If an error is encountered, a message is printed and
  972. // an error is returned.
  973. //
  974. // 05-07-96 JulieB Created.
  975. ////////////////////////////////////////////////////////////////////////////
  976. int GetSimplified(
  977. PUNICODE pUnic,
  978. int Size)
  979. {
  980. int Traditional; // Traditional value
  981. int Simplified; // Simplified value
  982. register int Ctr; // loop counter
  983. int NumItems; // number of items returned from fscanf
  984. //
  985. // Allocate top buffer for 8:4:4 table - 256 pointers.
  986. //
  987. if (Allocate8(&pUnic->pSimplified))
  988. {
  989. return (1);
  990. }
  991. //
  992. // For each entry in table, read in traditional value and simplified
  993. // translation value from input file, allocate necessary 16 word
  994. // buffers based on wide character value, and store difference to
  995. // simplified value.
  996. //
  997. for (Ctr = 0; Ctr < Size; Ctr++)
  998. {
  999. //
  1000. // Read in traditional and simplified values.
  1001. //
  1002. NumItems = fscanf( pInputFile,
  1003. "%x %x ;%*[^\n]",
  1004. &Traditional,
  1005. &Simplified );
  1006. if (NumItems != 2)
  1007. {
  1008. printf("Parse Error: Error reading SIMPLIFIED_CHINESE values.\n");
  1009. return (1);
  1010. }
  1011. if (Verbose)
  1012. printf(" Traditional = %x\tSimplified = %x\n",
  1013. Traditional, Simplified);
  1014. //
  1015. // Insert difference (Traditional - Simplified) into 8:4:4 table.
  1016. //
  1017. if (Insert844( pUnic->pSimplified,
  1018. (WORD)Traditional,
  1019. (WORD)(Simplified - Traditional),
  1020. &pUnic->SPBuf2,
  1021. &pUnic->SPBuf3,
  1022. sizeof(WORD) ))
  1023. {
  1024. return (1);
  1025. }
  1026. }
  1027. //
  1028. // Return success.
  1029. //
  1030. return (0);
  1031. }
  1032. ////////////////////////////////////////////////////////////////////////////
  1033. //
  1034. // GetCompTable
  1035. //
  1036. // This routine gets the precomposed table and the composite table from
  1037. // the input file. It uses the size parameter to know when to stop reading
  1038. // from the file. If an error is encountered, a message is printed and an
  1039. // error is returned.
  1040. //
  1041. // 07-30-91 JulieB Created.
  1042. // 12-10-91 JulieB Modified for new table format.
  1043. ////////////////////////////////////////////////////////////////////////////
  1044. int GetCompTable(
  1045. PUNICODE pUnic,
  1046. int Size)
  1047. {
  1048. int PreComp; // precomposed character
  1049. int Base; // base character
  1050. int NonSp; // nonspace character
  1051. DWORD Combo; // combined base and nonspace
  1052. register int Ctr; // loop counter
  1053. WORD BOff, NOff; // offsets for Base and NonSpace chars
  1054. int NumItems; // number of items returned from fscanf
  1055. //
  1056. // Allocate top buffers for 8:4:4 tables - 256 pointers.
  1057. //
  1058. if (Allocate8(&pUnic->pPreComp))
  1059. {
  1060. return (1);
  1061. }
  1062. if (Allocate8(&pUnic->pBase))
  1063. {
  1064. return (1);
  1065. }
  1066. if (Allocate8(&pUnic->pNonSp))
  1067. {
  1068. return (1);
  1069. }
  1070. //
  1071. // Allocate 2D grid for Composite table and save Size
  1072. // in the first position of the grid.
  1073. //
  1074. if (AllocateGrid(&pUnic->pCompGrid, Size))
  1075. {
  1076. return (1);
  1077. }
  1078. //
  1079. // For each entry in table, read in precomposed, base, and nonspace
  1080. // characters from input file and build the necessary tables.
  1081. //
  1082. for (Ctr = 0; Ctr < Size; Ctr++)
  1083. {
  1084. //
  1085. // Read in precomposed, base, and nonspace characters.
  1086. //
  1087. NumItems = fscanf( pInputFile,
  1088. "%x %x %x ;%*[^\n]",
  1089. &PreComp,
  1090. &Base,
  1091. &NonSp );
  1092. if (NumItems != 3)
  1093. {
  1094. printf("Parse Error: Error reading COMPTABLE values.\n");
  1095. return (1);
  1096. }
  1097. if (Verbose)
  1098. printf(" PreComp = %x\tBase = %x\tNonSp = %x\n",
  1099. PreComp, Base, NonSp);
  1100. //
  1101. // PRECOMPOSED TABLE:
  1102. //
  1103. // Convert Base and NonSp into one DWORD value - Combo.
  1104. // Base = high word, NonSp = low word.
  1105. //
  1106. // Insert Combo information into Precomposed 8:4:4 table.
  1107. //
  1108. Combo = MAKE_DWORD((WORD)NonSp, (WORD)Base);
  1109. if (Insert844( pUnic->pPreComp,
  1110. (WORD)PreComp,
  1111. Combo,
  1112. &pUnic->PCBuf2,
  1113. &pUnic->PCBuf3,
  1114. sizeof(DWORD) ))
  1115. {
  1116. return (1);
  1117. }
  1118. if (Verbose)
  1119. printf(" Combo = %x\n", Combo);
  1120. //
  1121. // COMPOSITE TABLE:
  1122. //
  1123. // Insert offsets into BASE and NONSPACE 8:4:4 tables.
  1124. // Insert PRECOMPOSED into 2D grid.
  1125. //
  1126. Get844Value( pUnic->pBase,
  1127. (WORD)Base,
  1128. &BOff );
  1129. Get844Value( pUnic->pNonSp,
  1130. (WORD)NonSp,
  1131. &NOff );
  1132. if (BOff == 0)
  1133. {
  1134. BOff = (WORD)(++(pUnic->NumBase));
  1135. if (Insert844( pUnic->pBase,
  1136. (WORD)Base,
  1137. BOff,
  1138. &pUnic->BSBuf2,
  1139. &pUnic->BSBuf3,
  1140. sizeof(WORD) ))
  1141. {
  1142. return (1);
  1143. }
  1144. }
  1145. if (NOff == 0)
  1146. {
  1147. NOff = (WORD)(++(pUnic->NumNonSp));
  1148. if (Insert844( pUnic->pNonSp,
  1149. (WORD)NonSp,
  1150. NOff,
  1151. &pUnic->NSBuf2,
  1152. &pUnic->NSBuf3,
  1153. sizeof(WORD) ))
  1154. {
  1155. return (1);
  1156. }
  1157. }
  1158. if (Verbose)
  1159. printf(" BOff = %x\tNOff = %x\n", BOff, NOff);
  1160. InsertCompGrid( pUnic->pCompGrid,
  1161. (WORD)PreComp,
  1162. BOff,
  1163. NOff );
  1164. }
  1165. //
  1166. // Return success.
  1167. //
  1168. return (0);
  1169. }
  1170. ////////////////////////////////////////////////////////////////////////////
  1171. //
  1172. // Get844Value
  1173. //
  1174. // This routine gets the value in the 8:4:4 table of the given wide character.
  1175. // If a value is found, it returns the value found in Value. Otherwise,
  1176. // it returns 0 in Value.
  1177. //
  1178. // 07-30-91 JulieB Created.
  1179. ////////////////////////////////////////////////////////////////////////////
  1180. void Get844Value(
  1181. P844_ARRAY pArr,
  1182. WORD WChar,
  1183. WORD *Value)
  1184. {
  1185. P844_ARRAY pMidFour;
  1186. WORD *pFour;
  1187. //
  1188. // Traverse 8:4:4 table for value.
  1189. //
  1190. if (pMidFour = (P844_ARRAY)(pArr[GET8(WChar)]))
  1191. {
  1192. if (pFour = pMidFour[GETHI4(WChar)])
  1193. {
  1194. *Value = pFour[GETLO4(WChar)];
  1195. }
  1196. else
  1197. {
  1198. *Value = 0;
  1199. }
  1200. }
  1201. else
  1202. {
  1203. *Value = 0;
  1204. }
  1205. }
  1206. ////////////////////////////////////////////////////////////////////////////
  1207. //
  1208. // InsertCompGrid
  1209. //
  1210. // This routine inserts the given precomposed character at the given
  1211. // offset in the 2D grid. The matrix size of the grid is located in
  1212. // the first spot of the grid array.
  1213. //
  1214. // The grid is set up in memory as follows:
  1215. //
  1216. // [ base 1 ][ base 2 ][ base 3 ]
  1217. //
  1218. // where the size of each is GridSize.
  1219. //
  1220. // In other words, BASE characters => ROWS
  1221. // NONSPACE characters => COLUMNS
  1222. //
  1223. // NOTE: BaseOff and NonSpOff start at 1, not 0.
  1224. //
  1225. // 07-30-91 JulieB Created.
  1226. // 12-10-91 JulieB Modified for new table format.
  1227. ////////////////////////////////////////////////////////////////////////////
  1228. void InsertCompGrid(
  1229. PCOMP_GRID pCompGrid,
  1230. WORD PreComp,
  1231. WORD BaseOff,
  1232. WORD NonSpOff)
  1233. {
  1234. int Index;
  1235. Index = ((BaseOff - 1) * pCompGrid[0] + (NonSpOff - 1)) + 1;
  1236. pCompGrid[Index] = PreComp;
  1237. if (Verbose)
  1238. printf(" Grid Spot = %d\tMax = %d\n", Index, pCompGrid[0]);
  1239. }
  1240. ////////////////////////////////////////////////////////////////////////////
  1241. //
  1242. // WriteAsciiDigits
  1243. //
  1244. // This routine writes the Ascii Digits information to the output file.
  1245. //
  1246. // 07-30-91 JulieB Created.
  1247. // 12-10-91 JulieB Modified for new table format.
  1248. ////////////////////////////////////////////////////////////////////////////
  1249. int WriteAsciiDigits(
  1250. PUNICODE pUnic,
  1251. FILE *pOutputFile)
  1252. {
  1253. int TblSize; // size of table
  1254. WORD wValue; // temp storage value
  1255. if (Verbose)
  1256. printf("\nWriting Ascii Digits Table...\n");
  1257. //
  1258. // Compute size of table.
  1259. //
  1260. TblSize = Compute844Size( pUnic->ADBuf2,
  1261. pUnic->ADBuf3,
  1262. sizeof(WORD) ) + 1;
  1263. //
  1264. // Make sure the total size of the table is not greater than 64K.
  1265. // If it is, then the WORD offsets are too small.
  1266. //
  1267. if (TblSize > MAX_844_TBL_SIZE)
  1268. {
  1269. printf("Write Error: Size of Ascii Digits table is greater than 64K.\n");
  1270. return (1);
  1271. }
  1272. //
  1273. // Write the size to the output file.
  1274. //
  1275. wValue = (WORD)TblSize;
  1276. if (FileWrite( pOutputFile,
  1277. &wValue,
  1278. sizeof(WORD),
  1279. 1,
  1280. "Ascii Digits size" ))
  1281. {
  1282. return (1);
  1283. }
  1284. //
  1285. // Write Ascii Digits 8:4:4 table to file.
  1286. //
  1287. if (Write844Table( pOutputFile,
  1288. pUnic->pADigit,
  1289. pUnic->ADBuf2,
  1290. TblSize - 1,
  1291. sizeof(WORD) ))
  1292. {
  1293. return (1);
  1294. }
  1295. //
  1296. // Return success.
  1297. //
  1298. return (0);
  1299. }
  1300. ////////////////////////////////////////////////////////////////////////////
  1301. //
  1302. // WriteFoldCZone
  1303. //
  1304. // This routine writes the Fold Compatibility Zone information to the
  1305. // output file.
  1306. //
  1307. // 07-30-91 JulieB Created.
  1308. // 12-10-91 JulieB Modified for new table format.
  1309. ////////////////////////////////////////////////////////////////////////////
  1310. int WriteFoldCZone(
  1311. PUNICODE pUnic,
  1312. FILE *pOutputFile)
  1313. {
  1314. int TblSize; // size of table
  1315. WORD wValue; // temp storage value
  1316. if (Verbose)
  1317. printf("\nWriting Fold CZone Table...\n");
  1318. //
  1319. // Compute size of table.
  1320. //
  1321. TblSize = Compute844Size( pUnic->CZBuf2,
  1322. pUnic->CZBuf3,
  1323. sizeof(WORD) ) + 1;
  1324. //
  1325. // Make sure the total size of the table is not greater than 64K.
  1326. // If it is, then the WORD offsets are too small.
  1327. //
  1328. if (TblSize > MAX_844_TBL_SIZE)
  1329. {
  1330. printf("Write Error: Size of Fold CZone table is greater than 64K.\n");
  1331. return (1);
  1332. }
  1333. //
  1334. // Write the size to the output file.
  1335. //
  1336. wValue = (WORD)TblSize;
  1337. if (FileWrite( pOutputFile,
  1338. &wValue,
  1339. sizeof(WORD),
  1340. 1,
  1341. "Fold CZone size" ))
  1342. {
  1343. return (1);
  1344. }
  1345. //
  1346. // Write Ascii Digits 8:4:4 table to file.
  1347. //
  1348. if (Write844Table( pOutputFile,
  1349. pUnic->pCZone,
  1350. pUnic->CZBuf2,
  1351. TblSize - 1,
  1352. sizeof(WORD) ))
  1353. {
  1354. return (1);
  1355. }
  1356. //
  1357. // Return success.
  1358. //
  1359. return (0);
  1360. }
  1361. ////////////////////////////////////////////////////////////////////////////
  1362. //
  1363. // WriteHiragana
  1364. //
  1365. // This routine writes the Hiragana information to the output file.
  1366. //
  1367. // 07-14-93 JulieB Created.
  1368. ////////////////////////////////////////////////////////////////////////////
  1369. int WriteHiragana(
  1370. PUNICODE pUnic,
  1371. FILE *pOutputFile)
  1372. {
  1373. int TblSize; // size of table
  1374. WORD wValue; // temp storage value
  1375. if (Verbose)
  1376. printf("\nWriting Hiragana Table...\n");
  1377. //
  1378. // Compute size of table.
  1379. //
  1380. TblSize = Compute844Size( pUnic->HGBuf2,
  1381. pUnic->HGBuf3,
  1382. sizeof(WORD) ) + 1;
  1383. //
  1384. // Make sure the total size of the table is not greater than 64K.
  1385. // If it is, then the WORD offsets are too small.
  1386. //
  1387. if (TblSize > MAX_844_TBL_SIZE)
  1388. {
  1389. printf("Write Error: Size of Hiragana table is greater than 64K.\n");
  1390. return (1);
  1391. }
  1392. //
  1393. // Write the size to the output file.
  1394. //
  1395. wValue = (WORD)TblSize;
  1396. if (FileWrite( pOutputFile,
  1397. &wValue,
  1398. sizeof(WORD),
  1399. 1,
  1400. "Hiragana size" ))
  1401. {
  1402. return (1);
  1403. }
  1404. //
  1405. // Write Hiragana 8:4:4 table to file.
  1406. //
  1407. if (Write844Table( pOutputFile,
  1408. pUnic->pHiragana,
  1409. pUnic->HGBuf2,
  1410. TblSize - 1,
  1411. sizeof(WORD) ))
  1412. {
  1413. return (1);
  1414. }
  1415. //
  1416. // Return success.
  1417. //
  1418. return (0);
  1419. }
  1420. ////////////////////////////////////////////////////////////////////////////
  1421. //
  1422. // WriteKatakana
  1423. //
  1424. // This routine writes the Katakana information to the output file.
  1425. //
  1426. // 07-14-93 JulieB Created.
  1427. ////////////////////////////////////////////////////////////////////////////
  1428. int WriteKatakana(
  1429. PUNICODE pUnic,
  1430. FILE *pOutputFile)
  1431. {
  1432. int TblSize; // size of table
  1433. WORD wValue; // temp storage value
  1434. if (Verbose)
  1435. printf("\nWriting Katakana Table...\n");
  1436. //
  1437. // Compute size of table.
  1438. //
  1439. TblSize = Compute844Size( pUnic->KKBuf2,
  1440. pUnic->KKBuf3,
  1441. sizeof(WORD) ) + 1;
  1442. //
  1443. // Make sure the total size of the table is not greater than 64K.
  1444. // If it is, then the WORD offsets are too small.
  1445. //
  1446. if (TblSize > MAX_844_TBL_SIZE)
  1447. {
  1448. printf("Write Error: Size of Katakana table is greater than 64K.\n");
  1449. return (1);
  1450. }
  1451. //
  1452. // Write the size to the output file.
  1453. //
  1454. wValue = (WORD)TblSize;
  1455. if (FileWrite( pOutputFile,
  1456. &wValue,
  1457. sizeof(WORD),
  1458. 1,
  1459. "Katakana size" ))
  1460. {
  1461. return (1);
  1462. }
  1463. //
  1464. // Write Katakana 8:4:4 table to file.
  1465. //
  1466. if (Write844Table( pOutputFile,
  1467. pUnic->pKatakana,
  1468. pUnic->KKBuf2,
  1469. TblSize - 1,
  1470. sizeof(WORD) ))
  1471. {
  1472. return (1);
  1473. }
  1474. //
  1475. // Return success.
  1476. //
  1477. return (0);
  1478. }
  1479. ////////////////////////////////////////////////////////////////////////////
  1480. //
  1481. // WriteHalfWidth
  1482. //
  1483. // This routine writes the Half Width information to the output file.
  1484. //
  1485. // 07-14-93 JulieB Created.
  1486. ////////////////////////////////////////////////////////////////////////////
  1487. int WriteHalfWidth(
  1488. PUNICODE pUnic,
  1489. FILE *pOutputFile)
  1490. {
  1491. int TblSize; // size of table
  1492. WORD wValue; // temp storage value
  1493. if (Verbose)
  1494. printf("\nWriting Half Width Table...\n");
  1495. //
  1496. // Compute size of table.
  1497. //
  1498. TblSize = Compute844Size( pUnic->HWBuf2,
  1499. pUnic->HWBuf3,
  1500. sizeof(WORD) ) + 1;
  1501. //
  1502. // Make sure the total size of the table is not greater than 64K.
  1503. // If it is, then the WORD offsets are too small.
  1504. //
  1505. if (TblSize > MAX_844_TBL_SIZE)
  1506. {
  1507. printf("Write Error: Size of Half Width table is greater than 64K.\n");
  1508. return (1);
  1509. }
  1510. //
  1511. // Write the size to the output file.
  1512. //
  1513. wValue = (WORD)TblSize;
  1514. if (FileWrite( pOutputFile,
  1515. &wValue,
  1516. sizeof(WORD),
  1517. 1,
  1518. "Half Width size" ))
  1519. {
  1520. return (1);
  1521. }
  1522. //
  1523. // Write Half Width 8:4:4 table to file.
  1524. //
  1525. if (Write844Table( pOutputFile,
  1526. pUnic->pHalfWidth,
  1527. pUnic->HWBuf2,
  1528. TblSize - 1,
  1529. sizeof(WORD) ))
  1530. {
  1531. return (1);
  1532. }
  1533. //
  1534. // Return success.
  1535. //
  1536. return (0);
  1537. }
  1538. ////////////////////////////////////////////////////////////////////////////
  1539. //
  1540. // WriteFullWidth
  1541. //
  1542. // This routine writes the Full Width information to the output file.
  1543. //
  1544. // 07-14-93 JulieB Created.
  1545. ////////////////////////////////////////////////////////////////////////////
  1546. int WriteFullWidth(
  1547. PUNICODE pUnic,
  1548. FILE *pOutputFile)
  1549. {
  1550. int TblSize; // size of table
  1551. WORD wValue; // temp storage value
  1552. if (Verbose)
  1553. printf("\nWriting Full Width Table...\n");
  1554. //
  1555. // Compute size of table.
  1556. //
  1557. TblSize = Compute844Size( pUnic->FWBuf2,
  1558. pUnic->FWBuf3,
  1559. sizeof(WORD) ) + 1;
  1560. //
  1561. // Make sure the total size of the table is not greater than 64K.
  1562. // If it is, then the WORD offsets are too small.
  1563. //
  1564. if (TblSize > MAX_844_TBL_SIZE)
  1565. {
  1566. printf("Write Error: Size of Full Width table is greater than 64K.\n");
  1567. return (1);
  1568. }
  1569. //
  1570. // Write the size to the output file.
  1571. //
  1572. wValue = (WORD)TblSize;
  1573. if (FileWrite( pOutputFile,
  1574. &wValue,
  1575. sizeof(WORD),
  1576. 1,
  1577. "Full Width size" ))
  1578. {
  1579. return (1);
  1580. }
  1581. //
  1582. // Write Full Width 8:4:4 table to file.
  1583. //
  1584. if (Write844Table( pOutputFile,
  1585. pUnic->pFullWidth,
  1586. pUnic->FWBuf2,
  1587. TblSize - 1,
  1588. sizeof(WORD) ))
  1589. {
  1590. return (1);
  1591. }
  1592. //
  1593. // Return success.
  1594. //
  1595. return (0);
  1596. }
  1597. ////////////////////////////////////////////////////////////////////////////
  1598. //
  1599. // WriteTraditional
  1600. //
  1601. // This routine writes the Traditional information to the output file.
  1602. //
  1603. // 05-07-96 JulieB Created.
  1604. ////////////////////////////////////////////////////////////////////////////
  1605. int WriteTraditional(
  1606. PUNICODE pUnic,
  1607. FILE *pOutputFile)
  1608. {
  1609. int TblSize; // size of table
  1610. WORD wValue; // temp storage value
  1611. if (Verbose)
  1612. printf("\nWriting Traditional Chinese Table...\n");
  1613. //
  1614. // Compute size of table.
  1615. //
  1616. TblSize = Compute844Size( pUnic->TRBuf2,
  1617. pUnic->TRBuf3,
  1618. sizeof(WORD) ) + 1;
  1619. //
  1620. // Make sure the total size of the table is not greater than 64K.
  1621. // If it is, then the WORD offsets are too small.
  1622. //
  1623. if (TblSize > MAX_844_TBL_SIZE)
  1624. {
  1625. printf("Write Error: Size of Traditional Chinese table is greater than 64K.\n");
  1626. return (1);
  1627. }
  1628. //
  1629. // Write the size to the output file.
  1630. //
  1631. wValue = (WORD)TblSize;
  1632. if (FileWrite( pOutputFile,
  1633. &wValue,
  1634. sizeof(WORD),
  1635. 1,
  1636. "Traditional Chinese size" ))
  1637. {
  1638. return (1);
  1639. }
  1640. //
  1641. // Write Traditional 8:4:4 table to file.
  1642. //
  1643. if (Write844Table( pOutputFile,
  1644. pUnic->pTraditional,
  1645. pUnic->TRBuf2,
  1646. TblSize - 1,
  1647. sizeof(WORD) ))
  1648. {
  1649. return (1);
  1650. }
  1651. //
  1652. // Return success.
  1653. //
  1654. return (0);
  1655. }
  1656. ////////////////////////////////////////////////////////////////////////////
  1657. //
  1658. // WriteSimplified
  1659. //
  1660. // This routine writes the Simplified information to the output file.
  1661. //
  1662. // 05-07-96 JulieB Created.
  1663. ////////////////////////////////////////////////////////////////////////////
  1664. int WriteSimplified(
  1665. PUNICODE pUnic,
  1666. FILE *pOutputFile)
  1667. {
  1668. int TblSize; // size of table
  1669. WORD wValue; // temp storage value
  1670. if (Verbose)
  1671. printf("\nWriting Simplified Chinese Table...\n");
  1672. //
  1673. // Compute size of table.
  1674. //
  1675. TblSize = Compute844Size( pUnic->SPBuf2,
  1676. pUnic->SPBuf3,
  1677. sizeof(WORD) ) + 1;
  1678. //
  1679. // Make sure the total size of the table is not greater than 64K.
  1680. // If it is, then the WORD offsets are too small.
  1681. //
  1682. if (TblSize > MAX_844_TBL_SIZE)
  1683. {
  1684. printf("Write Error: Size of Simplified Chinese table is greater than 64K.\n");
  1685. return (1);
  1686. }
  1687. //
  1688. // Write the size to the output file.
  1689. //
  1690. wValue = (WORD)TblSize;
  1691. if (FileWrite( pOutputFile,
  1692. &wValue,
  1693. sizeof(WORD),
  1694. 1,
  1695. "Simplified Chinese size" ))
  1696. {
  1697. return (1);
  1698. }
  1699. //
  1700. // Write Simplified 8:4:4 table to file.
  1701. //
  1702. if (Write844Table( pOutputFile,
  1703. pUnic->pSimplified,
  1704. pUnic->SPBuf2,
  1705. TblSize - 1,
  1706. sizeof(WORD) ))
  1707. {
  1708. return (1);
  1709. }
  1710. //
  1711. // Return success.
  1712. //
  1713. return (0);
  1714. }
  1715. ////////////////////////////////////////////////////////////////////////////
  1716. //
  1717. // WritePrecomposed
  1718. //
  1719. // This routine writes the Precomposed information to the output file.
  1720. //
  1721. // 07-30-91 JulieB Created.
  1722. // 12-10-91 JulieB Modified for new table format.
  1723. ////////////////////////////////////////////////////////////////////////////
  1724. int WritePrecomposed(
  1725. PUNICODE pUnic,
  1726. FILE *pOutputFile)
  1727. {
  1728. int TblSize; // size of table
  1729. WORD wValue; // temp storage value
  1730. if (Verbose)
  1731. printf("\nWriting PRECOMPOSED Table...\n");
  1732. //
  1733. // Compute size of table.
  1734. //
  1735. TblSize = Compute844Size( pUnic->PCBuf2,
  1736. pUnic->PCBuf3,
  1737. sizeof(DWORD) ) + 1;
  1738. //
  1739. // Make sure the total size of the table is not greater than 64K.
  1740. // If it is, then the WORD offsets are too small.
  1741. //
  1742. if (TblSize > MAX_844_TBL_SIZE)
  1743. {
  1744. printf("Write Error: Size of PRECOMPOSED table is greater than 64K.\n");
  1745. return (1);
  1746. }
  1747. //
  1748. // Write the size to the output file.
  1749. //
  1750. wValue = (WORD)TblSize;
  1751. if (FileWrite( pOutputFile,
  1752. &wValue,
  1753. sizeof(WORD),
  1754. 1,
  1755. "PRECOMPOSED size" ))
  1756. {
  1757. return (1);
  1758. }
  1759. //
  1760. // Write PRECOMPOSED 8:4:4 table to file.
  1761. //
  1762. if (Write844Table( pOutputFile,
  1763. pUnic->pPreComp,
  1764. pUnic->PCBuf2,
  1765. TblSize - 1,
  1766. sizeof(DWORD) ))
  1767. {
  1768. return (1);
  1769. }
  1770. //
  1771. // Return success.
  1772. //
  1773. return (0);
  1774. }
  1775. ////////////////////////////////////////////////////////////////////////////
  1776. //
  1777. // WriteComposite
  1778. //
  1779. // This routine writes the Composite information to the output file.
  1780. //
  1781. // 07-30-91 JulieB Created.
  1782. // 12-10-91 JulieB Modified for new table format.
  1783. ////////////////////////////////////////////////////////////////////////////
  1784. int WriteComposite(
  1785. PUNICODE pUnic,
  1786. FILE *pOutputFile)
  1787. {
  1788. int BaseSize; // size of Base table
  1789. int NonSpSize; // size of NonSpace table
  1790. WORD wValue; // temp storage value
  1791. BYTE bValue; // temp storage value
  1792. if (Verbose)
  1793. printf("\nWriting COMPOSITE Table...\n");
  1794. //
  1795. // Compute size of base table.
  1796. //
  1797. BaseSize = Compute844Size( pUnic->BSBuf2,
  1798. pUnic->BSBuf3,
  1799. sizeof(WORD) );
  1800. //
  1801. // Make sure the total size of the table is not greater than 64K.
  1802. // If it is, then the WORD offsets are too small.
  1803. //
  1804. if (BaseSize > MAX_844_TBL_SIZE)
  1805. {
  1806. printf("Write Error: Size of PRECOMPOSED table is greater than 64K.\n");
  1807. return (1);
  1808. }
  1809. //
  1810. // Write the size to the output file.
  1811. //
  1812. wValue = (WORD)BaseSize;
  1813. if (FileWrite( pOutputFile,
  1814. &wValue,
  1815. sizeof(WORD),
  1816. 1,
  1817. "COMPOSITE BASE size" ))
  1818. {
  1819. return (1);
  1820. }
  1821. //
  1822. // Compute size of nonspace table.
  1823. //
  1824. NonSpSize = Compute844Size( pUnic->NSBuf2,
  1825. pUnic->NSBuf3,
  1826. sizeof(WORD) );
  1827. //
  1828. // Make sure the total size of the table is not greater than 64K.
  1829. // If it is, then the WORD offsets are too small.
  1830. //
  1831. if (NonSpSize > MAX_844_TBL_SIZE)
  1832. {
  1833. printf("Write Error: Size of PRECOMPOSED table is greater than 64K.\n");
  1834. return (1);
  1835. }
  1836. //
  1837. // Write the size to the output file.
  1838. //
  1839. wValue = (WORD)NonSpSize;
  1840. if (FileWrite( pOutputFile,
  1841. &wValue,
  1842. sizeof(WORD),
  1843. 1,
  1844. "COMPOSITE NONSPACE size" ))
  1845. {
  1846. return (1);
  1847. }
  1848. //
  1849. // Write number of base chars to output file.
  1850. //
  1851. bValue = (BYTE)(pUnic->NumBase);
  1852. if (FileWrite( pOutputFile,
  1853. &bValue,
  1854. sizeof(BYTE),
  1855. 1,
  1856. "COMPOSITE BASE number" ))
  1857. {
  1858. return (1);
  1859. }
  1860. //
  1861. // Write number of nonspace chars to output file.
  1862. //
  1863. bValue = (BYTE)(pUnic->NumNonSp);
  1864. if (FileWrite( pOutputFile,
  1865. &bValue,
  1866. sizeof(BYTE),
  1867. 1,
  1868. "COMPOSITE NONSPACE number" ))
  1869. {
  1870. return (1);
  1871. }
  1872. //
  1873. // Write Base Character 8:4:4 table to output file.
  1874. //
  1875. if (Write844Table( pOutputFile,
  1876. pUnic->pBase,
  1877. pUnic->BSBuf2,
  1878. BaseSize,
  1879. sizeof(WORD) ))
  1880. {
  1881. return (1);
  1882. }
  1883. //
  1884. // Write NonSpace Character 8:4:4 table to output file.
  1885. //
  1886. if (Write844Table( pOutputFile,
  1887. pUnic->pNonSp,
  1888. pUnic->NSBuf2,
  1889. NonSpSize,
  1890. sizeof(WORD) ))
  1891. {
  1892. return (1);
  1893. }
  1894. //
  1895. // Write 2D Grid to output file.
  1896. //
  1897. if (WriteGrid( pUnic,
  1898. pOutputFile ))
  1899. {
  1900. return (1);
  1901. }
  1902. //
  1903. // Return success.
  1904. //
  1905. return (0);
  1906. }
  1907. ////////////////////////////////////////////////////////////////////////////
  1908. //
  1909. // WriteGrid
  1910. //
  1911. // This routine writes the Composite Table 2D Grid to the output file.
  1912. //
  1913. // 07-30-91 JulieB Created.
  1914. // 12-10-91 JulieB Modified for new table format.
  1915. ////////////////////////////////////////////////////////////////////////////
  1916. int WriteGrid(
  1917. PUNICODE pUnic,
  1918. FILE *pOutputFile)
  1919. {
  1920. int GridSize; // get matrix size of grid
  1921. register int Ctr; // loop counter
  1922. register PCOMP_GRID ptr; // temp ptr into grid
  1923. GridSize = (pUnic->pCompGrid)[0];
  1924. ptr = pUnic->pCompGrid + 1;
  1925. for (Ctr = 0; Ctr < pUnic->NumBase; Ctr++)
  1926. {
  1927. if (FileWrite( pOutputFile,
  1928. ptr,
  1929. sizeof(WORD),
  1930. pUnic->NumNonSp,
  1931. "COMPOSITE GRID" ))
  1932. {
  1933. return (1);
  1934. }
  1935. ptr += GridSize;
  1936. }
  1937. //
  1938. // Return success.
  1939. //
  1940. return (0);
  1941. }