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.

1525 lines
40 KiB

  1. /*++
  2. Copyright (c) 1991-1999, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. alloc.c
  5. Abstract:
  6. This file contains functions that will allocate the necessary memory
  7. blocks.
  8. External Routines in this file:
  9. AllocateMB
  10. AllocateGlyph
  11. AllocateTopDBCS
  12. AllocateDBCS
  13. AllocateWCTable
  14. Allocate8
  15. Insert844
  16. Insert844Map
  17. AllocateTemp844
  18. AllocateCTMap
  19. AllocateGrid
  20. AllocateLangException
  21. AllocateLangExceptionNodes
  22. AllocateSortDefault
  23. AllocateReverseDW
  24. AllocateDoubleCompression
  25. AllocateIdeographLcid
  26. AllocateExpansion
  27. AllocateCompression
  28. AllocateCompression2Nodes
  29. AllocateCompression3Nodes
  30. AllocateException
  31. AllocateExceptionNodes
  32. AllocateMultipleWeights
  33. AllocateIdeographExceptions
  34. Free844
  35. FreeCTMap
  36. Revision History:
  37. 07-30-91 JulieB Created.
  38. 03-10-00 lguindon Add explicit typecast to remove build errors
  39. --*/
  40. //
  41. // Include Files.
  42. //
  43. #include "nlstrans.h"
  44. //
  45. // Forward Declarations.
  46. //
  47. CT_MAP_VALUE
  48. MapTrioToByte(
  49. PCT_MAP pMap,
  50. WORD Value1,
  51. WORD Value2,
  52. WORD Value3);
  53. //-------------------------------------------------------------------------//
  54. // EXTERNAL ROUTINES //
  55. //-------------------------------------------------------------------------//
  56. ////////////////////////////////////////////////////////////////////////////
  57. //
  58. // AllocateMB
  59. //
  60. // This routine allocates all structures needed for the MB table.
  61. // If an error is encountered while allocating, an error is returned.
  62. //
  63. // 07-30-91 JulieB Created.
  64. // 12-10-91 JulieB Modified for new table format.
  65. ////////////////////////////////////////////////////////////////////////////
  66. int AllocateMB(
  67. PCODEPAGE pCP)
  68. {
  69. //
  70. // Allocate MB Table buffer.
  71. // Set all entries in MB Table to zero.
  72. //
  73. if ((pCP->pMB = (PMB_TBL)malloc(MB_TABLE_SIZE * sizeof(WORD))) == NULL)
  74. {
  75. printf("Error: Can't allocate buffer.\n");
  76. return (1);
  77. }
  78. memset(pCP->pMB, 0, MB_TABLE_SIZE * sizeof(WORD));
  79. //
  80. // Return success.
  81. //
  82. return (0);
  83. }
  84. ////////////////////////////////////////////////////////////////////////////
  85. //
  86. // AllocateGlyph
  87. //
  88. // This routine allocates all structures needed for the Glyph table.
  89. // If an error is encountered while allocating, an error is returned.
  90. // All entries in the glyph table are set equal to the entries in the
  91. // MB table. If the MB table has not been read in yet, then an error
  92. // is returned.
  93. //
  94. // 06-02-92 JulieB Created.
  95. ////////////////////////////////////////////////////////////////////////////
  96. int AllocateGlyph(
  97. PCODEPAGE pCP)
  98. {
  99. int ctr; // loop counter
  100. //
  101. // Allocate Glyph Table buffer.
  102. //
  103. if ((pCP->pGlyph = (PGLYPH_TBL)malloc( GLYPH_TABLE_SIZE *
  104. sizeof(WORD) )) == NULL)
  105. {
  106. printf("Error: Can't allocate buffer.\n");
  107. return (1);
  108. }
  109. //
  110. // Make sure the MB table has already been read in at this point.
  111. //
  112. if ((!(pCP->WriteFlags & F_MB)) || (pCP->pMB == NULL))
  113. {
  114. printf("Parse Error: MBTABLE must be BEFORE GLYPHTABLE in file.\n");
  115. return (1);
  116. }
  117. //
  118. // Set all entries in the Glyph Table to the MB Table entries.
  119. // All new glyph values will overwrite the appropriate MB entries
  120. // in the glyph table.
  121. //
  122. for (ctr = 0; ((ctr < GLYPH_TABLE_SIZE) && (ctr < MB_TABLE_SIZE)); ctr++)
  123. {
  124. (pCP->pGlyph)[ctr] = (pCP->pMB)[ctr];
  125. }
  126. //
  127. // Return success.
  128. //
  129. return (0);
  130. }
  131. ////////////////////////////////////////////////////////////////////////////
  132. //
  133. // AllocateTopDBCS
  134. //
  135. // This routine allocates the initial DBCS array structure. If an error
  136. // is encountered while allocating, an error is returned.
  137. //
  138. // 07-30-91 JulieB Created.
  139. // 12-10-91 JulieB Modified for new table format.
  140. ////////////////////////////////////////////////////////////////////////////
  141. int AllocateTopDBCS(
  142. PCODEPAGE pCP,
  143. int Size)
  144. {
  145. //
  146. // Allocate initial DBCS array structure.
  147. //
  148. if ((pCP->pDBCS = (PDBCS_ARRAY)malloc( Size *
  149. sizeof(PDBCS_RANGE) )) == NULL)
  150. {
  151. printf("Error: Can't allocate buffer.\n");
  152. return (1);
  153. }
  154. memset(pCP->pDBCS, 0, Size * sizeof(PDBCS_RANGE));
  155. //
  156. // Allocate offset area.
  157. //
  158. if ((pCP->pDBCSOff = (PDBCS_OFFSETS)malloc( DBCS_OFFSET_SIZE *
  159. sizeof(WORD) )) == NULL)
  160. {
  161. printf("Error: Can't allocate buffer.\n");
  162. return (1);
  163. }
  164. memset(pCP->pDBCSOff, 0, DBCS_OFFSET_SIZE * sizeof(WORD));
  165. //
  166. // Return success.
  167. //
  168. return (0);
  169. }
  170. ////////////////////////////////////////////////////////////////////////////
  171. //
  172. // AllocateDBCS
  173. //
  174. // This routine allocates all structures needed for the DBCS tables and
  175. // ranges. If an error is encountered while allocating, an error is
  176. // returned.
  177. //
  178. // 07-30-91 JulieB Created.
  179. // 12-10-91 JulieB Modified for new table format.
  180. ////////////////////////////////////////////////////////////////////////////
  181. int AllocateDBCS(
  182. PCODEPAGE pCP,
  183. int Low,
  184. int High,
  185. int Index)
  186. {
  187. PDBCS_RANGE pRange; // ptr to DBCS range
  188. PDBCS_TBL_ARRAY pTblArray; // ptr to DBCS table array
  189. int Ctr, Ctr2; // loop counters
  190. int NumTables = High - Low + 1; // number of tables for range
  191. WORD *pWordPtr; // ptr to dbcs buffer
  192. //
  193. // Allocate Range Structure.
  194. //
  195. if ((pRange = (PDBCS_RANGE)malloc(sizeof(DBCS_RANGE))) == NULL)
  196. {
  197. printf("Error: Can't allocate buffer.\n");
  198. return (1);
  199. }
  200. memset(pRange, 0, sizeof(DBCS_RANGE));
  201. //
  202. // Allocate Table Array.
  203. //
  204. if ((pTblArray = (PDBCS_TBL_ARRAY)malloc( NumTables *
  205. sizeof(PDBCS_TBL) )) == NULL)
  206. {
  207. printf("Error: Can't allocate buffer.\n");
  208. return (1);
  209. }
  210. memset(pTblArray, 0, NumTables * sizeof(PDBCS_TBL));
  211. //
  212. // Allocate All Tables.
  213. //
  214. for (Ctr = 0; Ctr < NumTables; Ctr++)
  215. {
  216. //
  217. // Allocate table.
  218. //
  219. if ((pTblArray[Ctr] = (PDBCS_TBL)malloc( DBCS_TABLE_SIZE *
  220. sizeof(WORD) )) == NULL)
  221. {
  222. printf("Error: Can't allocate buffer.\n");
  223. return (1);
  224. }
  225. //
  226. // Set all entries to the Unicode default character.
  227. //
  228. pWordPtr = (WORD *)(pTblArray[Ctr]);
  229. for (Ctr2 = 0; Ctr2 < DBCS_TABLE_SIZE; Ctr2++)
  230. {
  231. pWordPtr[Ctr2] = (WORD)(pCP->UniDefaultChar);
  232. }
  233. }
  234. //
  235. // Attach the tables to each other.
  236. //
  237. pRange->pDBCSTbls = pTblArray;
  238. (pCP->pDBCS)[Index] = pRange;
  239. //
  240. // Return success.
  241. //
  242. return (0);
  243. }
  244. ////////////////////////////////////////////////////////////////////////////
  245. //
  246. // AllocateWCTable
  247. //
  248. // This routine allocates the buffer for the Unicode to ANSI translation
  249. // table. The buffer is (64K // Size) bytes in length.
  250. //
  251. // 05-28-92 JulieB Created.
  252. ////////////////////////////////////////////////////////////////////////////
  253. int AllocateWCTable(
  254. PCODEPAGE pCP,
  255. int Size)
  256. {
  257. int Ctr; // loop counter
  258. WORD *pWordPtr; // ptr to wide character buffer
  259. //
  260. // Allocate translation table buffer.
  261. //
  262. if ((pCP->pWC = (PWC_ARRAY)malloc(WC_TABLE_SIZE * Size)) == NULL)
  263. {
  264. printf("Error: Can't allocate buffer.\n");
  265. return (1);
  266. }
  267. //
  268. // Set all entries to the default character.
  269. //
  270. if (Size == sizeof(BYTE))
  271. {
  272. memset(pCP->pWC, (BYTE)(pCP->DefaultChar), WC_TABLE_SIZE);
  273. }
  274. else if (Size == sizeof(WORD))
  275. {
  276. pWordPtr = pCP->pWC;
  277. for (Ctr = 0; Ctr < WC_TABLE_SIZE; Ctr++)
  278. {
  279. pWordPtr[Ctr] = pCP->DefaultChar;
  280. }
  281. }
  282. else
  283. {
  284. printf("Code Error: Bad 'Size' parameter for AllocateWCTable.\n");
  285. return (1);
  286. }
  287. //
  288. // Return success.
  289. //
  290. return (0);
  291. }
  292. ////////////////////////////////////////////////////////////////////////////
  293. //
  294. // Allocate8
  295. //
  296. // This routine allocates the top buffer for the 8:4:4 table.
  297. //
  298. // 07-30-91 JulieB Created.
  299. ////////////////////////////////////////////////////////////////////////////
  300. int Allocate8(
  301. P844_ARRAY *pArr)
  302. {
  303. //
  304. // Allocate top buffer for 8:4:4 table - 256 pointers.
  305. //
  306. if ((*pArr = (P844_ARRAY)malloc( TABLE_SIZE_8 *
  307. sizeof(P844_ARRAY) )) == NULL)
  308. {
  309. printf("Error: Can't allocate top 8:4:4 buffer.\n");
  310. return (1);
  311. }
  312. memset(*pArr, 0, TABLE_SIZE_8 * sizeof(P844_ARRAY));
  313. //
  314. // Return success.
  315. //
  316. return (0);
  317. }
  318. ////////////////////////////////////////////////////////////////////////////
  319. //
  320. // Insert844
  321. //
  322. // This routine inserts a WORD or DWORD value into an 8:4:4 table based on
  323. // the Size parameter. It does so by allocating the appropriate buffers
  324. // and filling in the third buffers with the appropriate WORD or DWORD value.
  325. //
  326. // 07-30-91 JulieB Created.
  327. ////////////////////////////////////////////////////////////////////////////
  328. int Insert844(
  329. P844_ARRAY pArr,
  330. WORD WChar,
  331. DWORD Value,
  332. int *cbBuf2,
  333. int *cbBuf3,
  334. int Size)
  335. {
  336. register int Index; // index into array
  337. P844_ARRAY pTbl2; // pointer to second array
  338. P844_ARRAY pTbl3; // pointer to third array
  339. //
  340. // Use the "8" index to get to the second table.
  341. // Allocate it if necessary.
  342. //
  343. Index = GET8(WChar);
  344. if ((pTbl2 = (P844_ARRAY)(pArr[Index])) == NULL)
  345. {
  346. //
  347. // Allocate second table - 16 pointers.
  348. //
  349. if ((pTbl2 = (P844_ARRAY)malloc( TABLE_SIZE_4 *
  350. sizeof(P844_ARRAY) )) == NULL)
  351. {
  352. printf("Error: Can't allocate second 8:4:4 buffer.\n");
  353. return (1);
  354. }
  355. memset(pTbl2, 0, TABLE_SIZE_4 * sizeof(P844_ARRAY));
  356. pArr[Index] = pTbl2;
  357. //
  358. // Keep track of how many "second buffer" allocations were made.
  359. //
  360. (*cbBuf2)++;
  361. }
  362. //
  363. // Use the "high 4" index to get to the third table.
  364. // Allocate it if necessary.
  365. //
  366. Index = GETHI4(WChar);
  367. if ((pTbl3 = pTbl2[Index]) == NULL)
  368. {
  369. //
  370. // Allocate third table - 16 words.
  371. //
  372. if ((pTbl3 = (P844_ARRAY)malloc(TABLE_SIZE_4 * Size)) == NULL)
  373. {
  374. printf("Error: Can't allocate third 8:4:4 buffer.\n");
  375. return (1);
  376. }
  377. memset(pTbl3, 0, TABLE_SIZE_4 * Size);
  378. pTbl2[Index] = pTbl3;
  379. //
  380. // Keep track of how many "third buffer" allocations were made.
  381. //
  382. (*cbBuf3)++;
  383. }
  384. //
  385. // Use the "low 4" value to index into the third table.
  386. // Save the value at this spot.
  387. //
  388. Index = GETLO4(WChar);
  389. if (Size == sizeof(WORD))
  390. {
  391. ((WORD *)pTbl3)[Index] = (WORD)Value;
  392. }
  393. else if (Size == sizeof(DWORD))
  394. {
  395. ((DWORD *)pTbl3)[Index] = (DWORD)Value;
  396. }
  397. else
  398. {
  399. printf("Code Error: Bad 'Size' parameter for Insert844 Table.\n");
  400. return (1);
  401. }
  402. //
  403. // Return success.
  404. //
  405. return (0);
  406. }
  407. ////////////////////////////////////////////////////////////////////////////
  408. //
  409. // Insert844Map
  410. //
  411. // This routine inserts 3 WORD values into an 8:4:4 table. It does so by
  412. // allocating the appropriate buffers and filling in the third buffers
  413. // with a 1 BYTE value that is the mapping of the given 3 WORD trio.
  414. //
  415. // 10-29-93 JulieB Created.
  416. ////////////////////////////////////////////////////////////////////////////
  417. int Insert844Map(
  418. P844_ARRAY pArr,
  419. PCT_MAP pMap,
  420. WORD WChar,
  421. WORD Value1,
  422. WORD Value2,
  423. WORD Value3,
  424. int *cbBuf2,
  425. int *cbBuf3)
  426. {
  427. register int Index; // index into array
  428. P844_ARRAY pTbl2; // pointer to second array
  429. PCT_MAP_VALUE pTbl3; // pointer to third array
  430. //
  431. // Use the "8" index to get to the second table.
  432. // Allocate it if necessary.
  433. //
  434. Index = GET8(WChar);
  435. if ((pTbl2 = (P844_ARRAY)(pArr[Index])) == NULL)
  436. {
  437. //
  438. // Allocate second table - 16 pointers + 1 word.
  439. // The additional 1 word will be used when writing this table
  440. // to avoid duplicates of the same table.
  441. //
  442. if ((pTbl2 = (P844_ARRAY)malloc( (TABLE_SIZE_4 + 1) *
  443. sizeof(P844_ARRAY) )) == NULL)
  444. {
  445. printf("Error: Can't allocate second 8:4:4 buffer.\n");
  446. return (1);
  447. }
  448. memset(pTbl2, 0, (TABLE_SIZE_4 + 1) * sizeof(P844_ARRAY));
  449. pArr[Index] = pTbl2;
  450. //
  451. // Keep track of how many "second buffer" allocations were made.
  452. //
  453. (*cbBuf2)++;
  454. }
  455. //
  456. // Use the "high 4" index to get to the third table.
  457. // Allocate it if necessary.
  458. //
  459. Index = GETHI4(WChar);
  460. if ((pTbl3 = pTbl2[Index]) == NULL)
  461. {
  462. //
  463. // Allocate third table - 16 + 2 bytes.
  464. // The 2 extra bytes will be used when writing the table.
  465. //
  466. if ((pTbl3 = (PCT_MAP_VALUE)malloc( (TABLE_SIZE_4 + 2) *
  467. (sizeof(CT_MAP_VALUE)) )) == NULL)
  468. {
  469. printf("Error: Can't allocate third 8:4:4 buffer.\n");
  470. return (1);
  471. }
  472. //
  473. // The last field of the third table is used when writing to the
  474. // data file to ensure that each table is written only ONCE
  475. // (with muliple pointers to it). This field takes 1 WORD
  476. // (2 bytes) and is initialized to 0.
  477. //
  478. memset(pTbl3, 0, (TABLE_SIZE_4 + 2) * (sizeof(CT_MAP_VALUE)));
  479. pTbl2[Index] = pTbl3;
  480. //
  481. // Keep track of how many "third buffer" allocations were made.
  482. //
  483. (*cbBuf3)++;
  484. }
  485. //
  486. // Use the "low 4" value to index into the third table.
  487. // Save the values at this spot.
  488. //
  489. Index = GETLO4(WChar);
  490. //
  491. // Map 3 WORD CType trio to 1 BYTE value.
  492. //
  493. pTbl3[Index] = MapTrioToByte( pMap,
  494. Value1,
  495. Value2,
  496. Value3 );
  497. //
  498. // Make sure the number of entries in the mapping table is
  499. // not greater than MAX_CT_MAP_TBL_SIZE.
  500. //
  501. if (pMap->Length >= MAX_CT_MAP_TBL_SIZE)
  502. {
  503. printf("Error: CTYPE Mapping Table Too Large.\n");
  504. return (1);
  505. }
  506. //
  507. // Return success.
  508. //
  509. return (0);
  510. }
  511. ////////////////////////////////////////////////////////////////////////////
  512. //
  513. // AllocateTemp844
  514. //
  515. // This routine allocates the temporary storage buffer for the 8:4:4
  516. // table. This temporary buffer is used when writing to the output file.
  517. // The size of the buffer is (TblSize * Size) bytes in length.
  518. //
  519. // 07-30-91 JulieB Created.
  520. ////////////////////////////////////////////////////////////////////////////
  521. int AllocateTemp844(
  522. PVOID *ppArr,
  523. int TblSize,
  524. int Size)
  525. {
  526. //
  527. // Allocate buffer of size TblSize.
  528. //
  529. if ((*ppArr = (PVOID)malloc(TblSize * Size)) == NULL)
  530. {
  531. printf("Error: Can't allocate temp 8:4:4 buffer.\n");
  532. return (1);
  533. }
  534. memset(*ppArr, 0, TblSize * Size);
  535. //
  536. // Return success.
  537. //
  538. return (0);
  539. }
  540. ////////////////////////////////////////////////////////////////////////////
  541. //
  542. // AllocateCTMap
  543. //
  544. // This routine allocates all structures needed for the ctype mapping table.
  545. // If an error is encountered while allocating, an error is returned.
  546. //
  547. ////////////////////////////////////////////////////////////////////////////
  548. int AllocateCTMap(
  549. PCT_MAP *pMap)
  550. {
  551. //
  552. // Allocate buffer mapping table.
  553. //
  554. if ((*pMap = (PCT_MAP)malloc(sizeof(CT_MAP))) == NULL)
  555. {
  556. printf("Error: Can't allocate buffer for CType Mapping table.\n");
  557. return (1);
  558. }
  559. memset(*pMap, 0, sizeof(CT_MAP));
  560. //
  561. // Allocate mapping table entries.
  562. //
  563. if (((*pMap)->pCTValues = (PCT_VALUES)malloc( MAX_CT_MAP_TBL_SIZE *
  564. sizeof(CT_VALUES) )) == NULL)
  565. {
  566. printf("Error: Can't allocate CType mapping table with %d entries.\n",
  567. MAX_CT_MAP_TBL_SIZE);
  568. return (1);
  569. }
  570. //
  571. // Set the first entry to 0 so that any third level table that maps
  572. // to 0 will be C1 = 0, C2 = 0, and C3 = 0.
  573. //
  574. memset((*pMap)->pCTValues, 0, sizeof(CT_VALUES));
  575. (*pMap)->Length = 1;
  576. //
  577. // Return success.
  578. //
  579. return (0);
  580. }
  581. ////////////////////////////////////////////////////////////////////////////
  582. //
  583. // AllocateGrid
  584. //
  585. // This routine allocates the 2D grid for the composite table.
  586. // The size passed in is the number of precomposed entries that need to
  587. // go into the table. Since the exact size of the array is not known yet,
  588. // the maximum possible size is allocated (size squared).
  589. //
  590. // 07-30-91 JulieB Created.
  591. ////////////////////////////////////////////////////////////////////////////
  592. int AllocateGrid(
  593. PCOMP_GRID *pCompGrid,
  594. int TblSize)
  595. {
  596. //
  597. // Allocate 2D grid.
  598. // The size of the grid is the TblSize squared plus one to save the
  599. // size of the grid.
  600. //
  601. if ((*pCompGrid = (PCOMP_GRID)malloc( (TblSize * TblSize + 1) *
  602. sizeof(WORD) )) == NULL)
  603. {
  604. printf("Error: Can't allocate buffer.\n");
  605. return (1);
  606. }
  607. memset(*pCompGrid, 0, (TblSize * TblSize + 1) * sizeof(WORD));
  608. //
  609. // Save the size of the grid in the first spot.
  610. //
  611. (*pCompGrid)[0] = (WORD)TblSize;
  612. //
  613. // Return success.
  614. //
  615. return (0);
  616. }
  617. ////////////////////////////////////////////////////////////////////////////
  618. //
  619. // AllocateLangException
  620. //
  621. // This routine allocates the exception header and the exception table.
  622. // The size of the table is determined by the TblSize parameter. The
  623. // pointer to the header and the table are stored in the language
  624. // structure.
  625. //
  626. // 08-30-95 JulieB Created.
  627. ////////////////////////////////////////////////////////////////////////////
  628. int AllocateLangException(
  629. PLANG_EXCEPT pLangExcept,
  630. int TblSize)
  631. {
  632. //
  633. // Set the number of Exception entries in table.
  634. //
  635. pLangExcept->NumException = TblSize;
  636. //
  637. // Allocate buffer of size TblSize for Exception header.
  638. //
  639. if ((pLangExcept->pExceptHdr =
  640. (PL_EXCEPT_HDR)malloc(TblSize * sizeof(L_EXCEPT_HDR))) == NULL)
  641. {
  642. printf("Error: Can't allocate buffer for Exception Header.\n");
  643. return (1);
  644. }
  645. memset(pLangExcept->pExceptHdr, 0, TblSize * sizeof(L_EXCEPT_HDR));
  646. //
  647. // Allocate buffer of size TblSize for Exception table.
  648. //
  649. if ((pLangExcept->pExceptTbl =
  650. (PL_EXCEPT_TBL)malloc(TblSize * sizeof(PL_EXCEPT_NODE))) == NULL)
  651. {
  652. printf("Error: Can't allocate buffer for Exception table.\n");
  653. return (1);
  654. }
  655. memset(pLangExcept->pExceptTbl, 0, TblSize * sizeof(PL_EXCEPT_NODE));
  656. //
  657. // Return success.
  658. //
  659. return (0);
  660. }
  661. ////////////////////////////////////////////////////////////////////////////
  662. //
  663. // AllocateLangExceptionNodes
  664. //
  665. // This routine allocates the exception nodes for the exception table.
  666. // The size of the table is determined by the TblSize parameter. The
  667. // pointer to the nodes is stored in the exception table at the Index
  668. // given.
  669. //
  670. // 08-30-95 JulieB Created.
  671. ////////////////////////////////////////////////////////////////////////////
  672. int AllocateLangExceptionNodes(
  673. PLANG_EXCEPT pLangExcept,
  674. int TblSize,
  675. int Index)
  676. {
  677. PL_EXCEPT_NODE pExcNode; // ptr to exception node
  678. //
  679. // Allocate buffer of size TblSize for Exception nodes.
  680. //
  681. if ((pExcNode = (PL_EXCEPT_NODE)malloc( TblSize *
  682. sizeof(L_EXCEPT_NODE) )) == NULL)
  683. {
  684. printf("Error: Can't allocate buffer for Exception Nodes.\n");
  685. return (1);
  686. }
  687. memset(pExcNode, 0, TblSize * sizeof(L_EXCEPT_NODE));
  688. //
  689. // Set pointer in exception table.
  690. //
  691. (pLangExcept->pExceptTbl)[Index] = pExcNode;
  692. //
  693. // Return success.
  694. //
  695. return (0);
  696. }
  697. ////////////////////////////////////////////////////////////////////////////
  698. //
  699. // AllocateSortDefault
  700. //
  701. // This routine allocates the sort default table - 64K DWORDS. The pointer
  702. // to the new table is stored in the sortkey structure.
  703. //
  704. // 11-04-92 JulieB Created.
  705. ////////////////////////////////////////////////////////////////////////////
  706. int AllocateSortDefault(
  707. PSORTKEY pSKey)
  708. {
  709. //
  710. // Allocate buffer of size 64K DWORDS for sort default table.
  711. //
  712. if ((pSKey->pDefault = (PSKEY)malloc( SKEY_TBL_SIZE *
  713. sizeof(SKEY) )) == NULL)
  714. {
  715. printf("Error: Can't allocate buffer for sortkey default table.\n");
  716. return (1);
  717. }
  718. memset(pSKey->pDefault, 0, SKEY_TBL_SIZE * sizeof(SKEY));
  719. //
  720. // Return success.
  721. //
  722. return (0);
  723. }
  724. ////////////////////////////////////////////////////////////////////////////
  725. //
  726. // AllocateReverseDW
  727. //
  728. // This routine allocates the reverse diacritic weight table. The size of
  729. // the table is determined by the TblSize parameter. The pointer to the
  730. // new table is stored in the sorttables structure.
  731. //
  732. // 11-04-92 JulieB Created.
  733. ////////////////////////////////////////////////////////////////////////////
  734. int AllocateReverseDW(
  735. PSORT_TABLES pSTbl,
  736. int TblSize)
  737. {
  738. //
  739. // Allocate buffer of size TblSize for RevrseDW table.
  740. //
  741. if ((pSTbl->pReverseDW = (PREV_DW)malloc( TblSize *
  742. sizeof(REV_DW) )) == NULL)
  743. {
  744. printf("Error: Can't allocate buffer for Reverse DW table.\n");
  745. return (1);
  746. }
  747. memset(pSTbl->pReverseDW, 0, TblSize * sizeof(REV_DW));
  748. //
  749. // Set the number of ReverseDW entries in table.
  750. //
  751. pSTbl->NumReverseDW = TblSize;
  752. //
  753. // Return success.
  754. //
  755. return (0);
  756. }
  757. ////////////////////////////////////////////////////////////////////////////
  758. //
  759. // AllocateDoubleCompression
  760. //
  761. // This routine allocates the double compression table. The size of
  762. // the table is determined by the TblSize parameter. The pointer to the
  763. // new table is stored in the sorttables structure.
  764. //
  765. // 11-04-92 JulieB Created.
  766. ////////////////////////////////////////////////////////////////////////////
  767. int AllocateDoubleCompression(
  768. PSORT_TABLES pSTbl,
  769. int TblSize)
  770. {
  771. //
  772. // Allocate buffer of size TblSize for Double Compression table.
  773. //
  774. if ((pSTbl->pDblCompression =
  775. (PDBL_COMPRESS)malloc(TblSize * sizeof(DBL_COMPRESS))) == NULL)
  776. {
  777. printf("Error: Can't allocate buffer for Double Compression table.\n");
  778. return (1);
  779. }
  780. memset(pSTbl->pDblCompression, 0, TblSize * sizeof(DBL_COMPRESS));
  781. //
  782. // Set the number of Double Compression entries in table.
  783. //
  784. pSTbl->NumDblCompression = TblSize;
  785. //
  786. // Return success.
  787. //
  788. return (0);
  789. }
  790. ////////////////////////////////////////////////////////////////////////////
  791. //
  792. // AllocateIdeographLcid
  793. //
  794. // This routine allocates the ideograph lcid table. The size of
  795. // the table is determined by the TblSize parameter. The pointer to the
  796. // new table is stored in the sorttables structure.
  797. //
  798. // 09-01-93 JulieB Created.
  799. ////////////////////////////////////////////////////////////////////////////
  800. int AllocateIdeographLcid(
  801. PSORT_TABLES pSTbl,
  802. int TblSize)
  803. {
  804. //
  805. // Allocate buffer of size TblSize for IdeographLcid table.
  806. //
  807. if ((pSTbl->pIdeographLcid =
  808. (PIDEOGRAPH_LCID)malloc(TblSize * sizeof(IDEOGRAPH_LCID))) == NULL)
  809. {
  810. printf("Error: Can't allocate buffer for Ideograph Lcid table.\n");
  811. return (1);
  812. }
  813. memset(pSTbl->pIdeographLcid, 0, TblSize * sizeof(IDEOGRAPH_LCID));
  814. //
  815. // Set the number of Ideograph Lcid entries in table.
  816. //
  817. pSTbl->NumIdeographLcid = TblSize;
  818. //
  819. // Return success.
  820. //
  821. return (0);
  822. }
  823. ////////////////////////////////////////////////////////////////////////////
  824. //
  825. // AllocateExpansion
  826. //
  827. // This routine allocates the expansion table. The size of
  828. // the table is determined by the TblSize parameter. The pointer to the
  829. // new table is stored in the sorttables structure.
  830. //
  831. // 11-04-92 JulieB Created.
  832. ////////////////////////////////////////////////////////////////////////////
  833. int AllocateExpansion(
  834. PSORT_TABLES pSTbl,
  835. int TblSize)
  836. {
  837. //
  838. // Allocate buffer of size TblSize for Expansion table.
  839. //
  840. if ((pSTbl->pExpansion = (PEXPAND)malloc( TblSize *
  841. sizeof(EXPAND) )) == NULL)
  842. {
  843. printf("Error: Can't allocate buffer for Expansion table.\n");
  844. return (1);
  845. }
  846. memset(pSTbl->pExpansion, 0, TblSize * sizeof(EXPAND));
  847. //
  848. // Set the number of Expansion entries in table.
  849. //
  850. pSTbl->NumExpansion = TblSize;
  851. //
  852. // Return success.
  853. //
  854. return (0);
  855. }
  856. ////////////////////////////////////////////////////////////////////////////
  857. //
  858. // AllocateCompression
  859. //
  860. // This routine allocates the compression header and the compression table.
  861. // The size of the table is determined by the TblSize parameter. The
  862. // pointer to the header and the table are stored in the sorttables
  863. // structure.
  864. //
  865. // 11-04-92 JulieB Created.
  866. ////////////////////////////////////////////////////////////////////////////
  867. int AllocateCompression(
  868. PSORT_TABLES pSTbl,
  869. int TblSize)
  870. {
  871. //
  872. // Set the number of Compression entries in table.
  873. //
  874. pSTbl->NumCompression = TblSize;
  875. //
  876. // Allocate buffer of size TblSize for Compression header.
  877. //
  878. if ((pSTbl->pCompressHdr =
  879. (PCOMPRESS_HDR)malloc(TblSize * sizeof(COMPRESS_HDR))) == NULL)
  880. {
  881. printf("Error: Can't allocate buffer for Compression Header.\n");
  882. return (1);
  883. }
  884. memset(pSTbl->pCompressHdr, 0, TblSize * sizeof(COMPRESS_HDR));
  885. //
  886. // Allocate buffer of size TblSize for Compression 2 table.
  887. //
  888. if ((pSTbl->pCompress2Tbl =
  889. (PCOMPRESS_2_TBL)malloc( TblSize *
  890. sizeof(PCOMPRESS_2_NODE) )) == NULL)
  891. {
  892. printf("Error: Can't allocate buffer for Compression 2 table.\n");
  893. return (1);
  894. }
  895. memset(pSTbl->pCompress2Tbl, 0, TblSize * sizeof(PCOMPRESS_2_NODE));
  896. //
  897. // Allocate buffer of size TblSize for Compression 3 table.
  898. //
  899. if ((pSTbl->pCompress3Tbl =
  900. (PCOMPRESS_3_TBL)malloc( TblSize *
  901. sizeof(PCOMPRESS_3_NODE) )) == NULL)
  902. {
  903. printf("Error: Can't allocate buffer for Compression 3 table.\n");
  904. return (1);
  905. }
  906. memset(pSTbl->pCompress3Tbl, 0, TblSize * sizeof(PCOMPRESS_3_NODE));
  907. //
  908. // Return success.
  909. //
  910. return (0);
  911. }
  912. ////////////////////////////////////////////////////////////////////////////
  913. //
  914. // AllocateCompression2Nodes
  915. //
  916. // This routine allocates the compression 2 nodes for the compression table.
  917. // The size of the table is determined by the TblSize parameter. The
  918. // pointer to the nodes is stored in the compression table at the Index
  919. // given.
  920. //
  921. // 11-04-92 JulieB Created.
  922. ////////////////////////////////////////////////////////////////////////////
  923. int AllocateCompression2Nodes(
  924. PSORT_TABLES pSTbl,
  925. int TblSize,
  926. int Index)
  927. {
  928. PCOMPRESS_2_NODE pCompNode; // ptr to compression 2 node
  929. //
  930. // Allocate buffer of size TblSize for Compression nodes.
  931. //
  932. if ((pCompNode =
  933. (PCOMPRESS_2_NODE)malloc( TblSize *
  934. sizeof(COMPRESS_2_NODE) )) == NULL)
  935. {
  936. printf("Error: Can't allocate buffer for Compression 2 Nodes.\n");
  937. return (1);
  938. }
  939. memset(pCompNode, 0, TblSize * sizeof(COMPRESS_2_NODE));
  940. //
  941. // Set pointer in compression 2 table.
  942. //
  943. (pSTbl->pCompress2Tbl)[Index] = pCompNode;
  944. //
  945. // Return success.
  946. //
  947. return (0);
  948. }
  949. ////////////////////////////////////////////////////////////////////////////
  950. //
  951. // AllocateCompression3Nodes
  952. //
  953. // This routine allocates the compression 3 nodes for the compression table.
  954. // The size of the table is determined by the TblSize parameter. The
  955. // pointer to the nodes is stored in the compression table at the Index
  956. // given.
  957. //
  958. // 11-04-92 JulieB Created.
  959. ////////////////////////////////////////////////////////////////////////////
  960. int AllocateCompression3Nodes(
  961. PSORT_TABLES pSTbl,
  962. int TblSize,
  963. int Index)
  964. {
  965. PCOMPRESS_3_NODE pCompNode; // ptr to compression 3 node
  966. //
  967. // Allocate buffer of size TblSize for Compression nodes.
  968. //
  969. if ((pCompNode =
  970. (PCOMPRESS_3_NODE)malloc( TblSize *
  971. sizeof(COMPRESS_3_NODE) )) == NULL)
  972. {
  973. printf("Error: Can't allocate buffer for Compression 3 Nodes.\n");
  974. return (1);
  975. }
  976. memset(pCompNode, 0, TblSize * sizeof(COMPRESS_3_NODE));
  977. //
  978. // Set pointer in compression 3 table.
  979. //
  980. (pSTbl->pCompress3Tbl)[Index] = pCompNode;
  981. //
  982. // Return success.
  983. //
  984. return (0);
  985. }
  986. ////////////////////////////////////////////////////////////////////////////
  987. //
  988. // AllocateException
  989. //
  990. // This routine allocates the exception header and the exception table.
  991. // The size of the table is determined by the TblSize parameter. The
  992. // pointer to the header and the table are stored in the sorttables
  993. // structure.
  994. //
  995. // 11-04-92 JulieB Created.
  996. ////////////////////////////////////////////////////////////////////////////
  997. int AllocateException(
  998. PSORT_TABLES pSTbl,
  999. int TblSize)
  1000. {
  1001. //
  1002. // Set the number of Exception entries in table.
  1003. //
  1004. pSTbl->NumException = TblSize;
  1005. //
  1006. // Allocate buffer of size TblSize for Exception header.
  1007. //
  1008. if ((pSTbl->pExceptHdr =
  1009. (PEXCEPT_HDR)malloc(TblSize * sizeof(EXCEPT_HDR))) == NULL)
  1010. {
  1011. printf("Error: Can't allocate buffer for Exception Header.\n");
  1012. return (1);
  1013. }
  1014. memset(pSTbl->pExceptHdr, 0, TblSize * sizeof(EXCEPT_HDR));
  1015. //
  1016. // Allocate buffer of size TblSize for Exception table.
  1017. //
  1018. if ((pSTbl->pExceptTbl =
  1019. (PEXCEPT_TBL)malloc(TblSize * sizeof(PEXCEPT_NODE))) == NULL)
  1020. {
  1021. printf("Error: Can't allocate buffer for Exception table.\n");
  1022. return (1);
  1023. }
  1024. memset(pSTbl->pExceptTbl, 0, TblSize * sizeof(PEXCEPT_NODE));
  1025. //
  1026. // Return success.
  1027. //
  1028. return (0);
  1029. }
  1030. ////////////////////////////////////////////////////////////////////////////
  1031. //
  1032. // AllocateException
  1033. //
  1034. // This routine allocates the Jamo Table and Jamo Composition table.
  1035. // The size of the table is determined by the TblSize parameter. The
  1036. // pointer to the tables are stored in the sorttables
  1037. // structure.
  1038. //
  1039. // 06-26-2000 YSLin Created.
  1040. ////////////////////////////////////////////////////////////////////////////
  1041. int AllocateJamoTables(
  1042. PSORT_TABLES pSTbl,
  1043. int TblSize)
  1044. {
  1045. //
  1046. // Set the number of Jamo Index entries in table
  1047. //
  1048. pSTbl->NumJamoIndex = JAMO_INDEX_SIZE;
  1049. //
  1050. // Allocate buffer for Jamo Index table.
  1051. //
  1052. if ((pSTbl->pJamoIndexTbl =
  1053. (PJAMO_TABLE)malloc(JAMO_INDEX_SIZE * sizeof(JAMO_TABLE))) == NULL)
  1054. {
  1055. printf("Error: Can't allocate buffer for Jamo Index.\n");
  1056. return (1);
  1057. }
  1058. memset(pSTbl->pJamoIndexTbl, 0, JAMO_INDEX_SIZE * sizeof(WORD));
  1059. //
  1060. // Set the number of Jamo Composition entries in table.
  1061. // Add one for the dummy entry.
  1062. //
  1063. pSTbl->NumJamoComposition = TblSize - JAMO_INDEX_SIZE + 1;
  1064. //
  1065. // Allocate buffer for Jamo Composition table.
  1066. //
  1067. if ((pSTbl->pJamoComposeTbl =
  1068. (PJAMO_COMPOSE_STATE)malloc(pSTbl->NumJamoComposition * sizeof(JAMO_COMPOSE_STATE))) == NULL)
  1069. {
  1070. printf("Error: Can't allocate buffer for Jamo Composition.\n");
  1071. return (1);
  1072. }
  1073. memset(pSTbl->pJamoComposeTbl, 0, pSTbl->NumJamoComposition * sizeof(JAMO_COMPOSE_STATE));
  1074. //
  1075. // Return success.
  1076. //
  1077. return (0);
  1078. }
  1079. ////////////////////////////////////////////////////////////////////////////
  1080. //
  1081. // AllocateExceptionNodes
  1082. //
  1083. // This routine allocates the exception nodes for the exception table.
  1084. // The size of the table is determined by the TblSize parameter. The
  1085. // pointer to the nodes is stored in the exception table at the Index
  1086. // given.
  1087. //
  1088. // 11-04-92 JulieB Created.
  1089. ////////////////////////////////////////////////////////////////////////////
  1090. int AllocateExceptionNodes(
  1091. PSORT_TABLES pSTbl,
  1092. int TblSize,
  1093. int Index)
  1094. {
  1095. PEXCEPT_NODE pExcNode; // ptr to exception node
  1096. //
  1097. // Allocate buffer of size TblSize for Exception nodes.
  1098. //
  1099. if ((pExcNode = (PEXCEPT_NODE)malloc( TblSize *
  1100. sizeof(EXCEPT_NODE) )) == NULL)
  1101. {
  1102. printf("Error: Can't allocate buffer for Exception Nodes.\n");
  1103. return (1);
  1104. }
  1105. memset(pExcNode, 0, TblSize * sizeof(EXCEPT_NODE));
  1106. //
  1107. // Set pointer in exception table.
  1108. //
  1109. (pSTbl->pExceptTbl)[Index] = pExcNode;
  1110. //
  1111. // Return success.
  1112. //
  1113. return (0);
  1114. }
  1115. ////////////////////////////////////////////////////////////////////////////
  1116. //
  1117. // AllocateMultipleWeights
  1118. //
  1119. // This routine allocates the multiple weights table. The size of
  1120. // the table is determined by the TblSize parameter. The pointer to the
  1121. // new table is stored in the sorttables structure.
  1122. //
  1123. // 11-04-92 JulieB Created.
  1124. ////////////////////////////////////////////////////////////////////////////
  1125. int AllocateMultipleWeights(
  1126. PSORT_TABLES pSTbl,
  1127. int TblSize)
  1128. {
  1129. //
  1130. // Allocate buffer of size TblSize for Multiple Weights table.
  1131. //
  1132. if ((pSTbl->pMultiWeight = (PMULTI_WT)malloc( TblSize *
  1133. sizeof(MULTI_WT) )) == NULL)
  1134. {
  1135. printf("Error: Can't allocate buffer for Multiple Weight table.\n");
  1136. return (1);
  1137. }
  1138. memset(pSTbl->pMultiWeight, 0, TblSize * sizeof(MULTI_WT));
  1139. //
  1140. // Set the number of Multiple Weight entries in table.
  1141. //
  1142. pSTbl->NumMultiWeight = TblSize;
  1143. //
  1144. // Return success.
  1145. //
  1146. return (0);
  1147. }
  1148. ////////////////////////////////////////////////////////////////////////////
  1149. //
  1150. // AllocateIdeographExceptions
  1151. //
  1152. // This routine allocates the ideograph exception table. The size of
  1153. // the table is determined by the TblSize parameter. The pointer to the
  1154. // new table is stored in the ideograph exception structure.
  1155. //
  1156. // 09-01-93 JulieB Created.
  1157. ////////////////////////////////////////////////////////////////////////////
  1158. int AllocateIdeographExceptions(
  1159. PIDEOGRAPH_EXCEPT pIdeograph,
  1160. int TblSize,
  1161. int NumColumns)
  1162. {
  1163. //
  1164. // Allocate buffer of size TblSize for Ideograph Exception table.
  1165. //
  1166. if (NumColumns == 2)
  1167. {
  1168. if ((pIdeograph->pExcept =
  1169. (PIDEOGRAPH_NODE)malloc( TblSize *
  1170. sizeof(IDEOGRAPH_NODE) )) == NULL)
  1171. {
  1172. printf("Error: Can't allocate buffer for Ideograph Exception table.\n");
  1173. return (1);
  1174. }
  1175. memset(pIdeograph->pExcept, 0, TblSize * sizeof(IDEOGRAPH_NODE));
  1176. pIdeograph->pExceptEx = NULL;
  1177. }
  1178. else if (NumColumns == 4)
  1179. {
  1180. if ((pIdeograph->pExceptEx =
  1181. (PIDEOGRAPH_NODE_EX)malloc( TblSize *
  1182. sizeof(IDEOGRAPH_NODE_EX) )) == NULL)
  1183. {
  1184. printf("Error: Can't allocate buffer for Ideograph Exception table.\n");
  1185. return (1);
  1186. }
  1187. memset(pIdeograph->pExceptEx, 0, TblSize * sizeof(IDEOGRAPH_NODE_EX));
  1188. pIdeograph->pExcept = NULL;
  1189. }
  1190. else
  1191. {
  1192. printf("Parse Error: The Number of Columns must be either 2 or 4.\n");
  1193. return (1);
  1194. }
  1195. //
  1196. // Set the number of ideograph exception entries in table.
  1197. //
  1198. pIdeograph->NumEntries = TblSize;
  1199. pIdeograph->NumColumns = NumColumns;
  1200. //
  1201. // Return success.
  1202. //
  1203. return (0);
  1204. }
  1205. ////////////////////////////////////////////////////////////////////////////
  1206. //
  1207. // Free844
  1208. //
  1209. // This routine frees the memory used by an 8:4:4 table pointed to by pArr.
  1210. //
  1211. // 07-30-91 JulieB Created.
  1212. ////////////////////////////////////////////////////////////////////////////
  1213. void Free844(
  1214. P844_ARRAY pArr)
  1215. {
  1216. int Ctr1, Ctr2; // loop counters
  1217. P844_ARRAY pArr2; // ptr to second arrays
  1218. if (pArr != NULL)
  1219. {
  1220. for (Ctr1 = 0; Ctr1 < TABLE_SIZE_8; Ctr1++)
  1221. {
  1222. if ((pArr2 = (P844_ARRAY)(pArr[Ctr1])) != NULL)
  1223. {
  1224. for (Ctr2 = 0; Ctr2 < TABLE_SIZE_4; Ctr2++)
  1225. {
  1226. if (pArr2[Ctr2] != NULL)
  1227. {
  1228. free(pArr2[Ctr2]);
  1229. }
  1230. }
  1231. free(pArr2);
  1232. }
  1233. }
  1234. free(pArr);
  1235. }
  1236. }
  1237. ////////////////////////////////////////////////////////////////////////////
  1238. //
  1239. // FreeCTMap
  1240. //
  1241. // This routine frees the memory used by the ctype mapping table pointed
  1242. // to by pMap.
  1243. //
  1244. ////////////////////////////////////////////////////////////////////////////
  1245. void FreeCTMap(
  1246. PCT_MAP pMap)
  1247. {
  1248. if (pMap != NULL)
  1249. {
  1250. free(pMap->pCTValues);
  1251. free(pMap);
  1252. }
  1253. }
  1254. //-------------------------------------------------------------------------//
  1255. // INTERNAL ROUTINES //
  1256. //-------------------------------------------------------------------------//
  1257. ////////////////////////////////////////////////////////////////////////////
  1258. //
  1259. // MapTrioToByte
  1260. //
  1261. // This routine searches through the mapping table for the given CType trio.
  1262. // If it already exists, the entry value is returned. Otherwise, it adds
  1263. // the new trio to the mapping table and returns the new entry value.
  1264. //
  1265. ////////////////////////////////////////////////////////////////////////////
  1266. CT_MAP_VALUE MapTrioToByte(
  1267. PCT_MAP pMap,
  1268. WORD Value1,
  1269. WORD Value2,
  1270. WORD Value3)
  1271. {
  1272. PCT_VALUES pEntry; // ptr to entry
  1273. CT_MAP_VALUE EntryNum; // entry number
  1274. int Ctr; // loop counter
  1275. //
  1276. // Search through the current entries to see if the ctype trio
  1277. // already exists.
  1278. //
  1279. for (Ctr = 0; Ctr < pMap->Length; Ctr++)
  1280. {
  1281. //
  1282. // Check the entry.
  1283. //
  1284. if ( ((pMap->pCTValues[Ctr]).CType1 == Value1) &&
  1285. ((pMap->pCTValues[Ctr]).CType2 == Value2) &&
  1286. ((pMap->pCTValues[Ctr]).CType3 == Value3) )
  1287. {
  1288. //
  1289. // Entry already exists. Return the entry number.
  1290. //
  1291. if (Verbose)
  1292. printf("Mapping Entry %d:\tCT1 = %x\tCT2 = %x\tCT3 = %x\n",
  1293. Ctr, Value1, Value2, Value3);
  1294. return ((BYTE)Ctr);
  1295. }
  1296. }
  1297. //
  1298. // The given CType trio does not yet exist in the table.
  1299. // Add the new trio entry to the table and increment the
  1300. // total number of entries.
  1301. //
  1302. pEntry = &(pMap->pCTValues[pMap->Length]);
  1303. pEntry->CType1 = Value1;
  1304. pEntry->CType2 = Value2;
  1305. pEntry->CType3 = Value3;
  1306. EntryNum = (CT_MAP_VALUE)(pMap->Length);
  1307. pMap->Length++;
  1308. if (Verbose)
  1309. printf("Mapping New Entry %d:\tCT1 = %x\tCT2 = %x\tCT3 = %x\n",
  1310. EntryNum, Value1, Value2, Value3);
  1311. //
  1312. // Return the new entry number.
  1313. //
  1314. return (EntryNum);
  1315. }