Leaked source code of windows server 2003
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.

825 lines
24 KiB

  1. #ifdef _WINDOWS
  2. #include <windows.h>
  3. #endif
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include "ccdef.h"
  7. #include "compcert.h"
  8. #include "gmem.h"
  9. #define FIXED_MODEL 1
  10. #define ADAPTATIVE_MODEL 2
  11. #define Code_value_bits 16
  12. #define No_of_chars 256
  13. #define Max_frequency 16383
  14. #define EOF_symbol (No_of_chars+1)
  15. #define No_of_symbols (No_of_chars+1)
  16. #define Top_value (( (long) 1 << Code_value_bits) - 1)
  17. #define First_qtr (Top_value / 4 + 1)
  18. #define Half (2 * First_qtr)
  19. #define Third_qtr (3 * First_qtr)
  20. typedef long code_value;
  21. static code_value value_dc;
  22. static code_value low_dc, high_dc;
  23. static code_value low_enc, high_enc;
  24. static long bits_to_follow;
  25. static unsigned int buffer_in;
  26. static unsigned int bits_to_go_in;
  27. static unsigned int garbage_bits_in;
  28. static unsigned int buffer_out;
  29. static unsigned int bits_to_go_out;
  30. static int Error;
  31. unsigned int char_to_index[No_of_chars];
  32. unsigned char index_to_char[No_of_symbols+1];
  33. unsigned int cum_freq[No_of_symbols+1];
  34. unsigned char *Memory;
  35. static unsigned MemoSize;
  36. unsigned int FixedFreqA[No_of_symbols+1] =
  37. {
  38. 0,
  39. 63, 260, 180, 216, 254, 63, 268, 95, 43, 62, 33, 28, 14, 6, 45, 38,
  40. 33, 35, 13, 303, 41, 37, 41, 8, 15, 81, 25, 2, 15, 88, 20, 6,
  41. /* ! = # $ % & ' ( ) * + , - . / */
  42. 662, 3, 35, 18, 12, 3, 11, 3, 16, 12, 2, 34, 42, 32, 56, 31,
  43. /* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? */
  44. 300, 118, 42, 40, 21, 37, 63, 46, 10, 90, 33, 3, 1, 9, 15, 3,
  45. /* @ A B C D E F G H I J K L M N O */
  46. 27, 158, 73, 122, 82, 31, 20, 14, 26, 56, 1, 2, 27, 20, 12, 31,
  47. /* P Q R S T U V W X Y Z [ \ ] ^ _ */
  48. 64, 4, 65, 114, 106, 195, 10, 27, 3, 18, 25, 2, 3, 1, 2, 12,
  49. /* ` a b c d e f g h i j k l m n o */
  50. 24, 271, 44, 171, 158, 439, 44, 50, 71, 308, 2, 5, 60, 73, 234, 280,
  51. /* p q r s t u v w x y z { | } ~ */
  52. 76, 44, 274, 273, 358, 100, 36, 43, 12, 79, 2, 1, 1, 1, 1, 1,
  53. 48, 48, 30, 1, 1, 5, 100, 5, 1, 3, 1, 1, 1, 50, 1, 1,
  54. 1, 4, 2, 14, 1, 5, 12, 1, 4, 1, 1, 1, 1, 1, 1, 1,
  55. 6, 14, 1, 1, 24, 1, 1, 4, 1, 11, 1, 2, 23, 1, 1, 4,
  56. 1, 1, 1, 1, 5, 1, 1, 12, 1, 1, 1, 1, 1, 1, 1, 1,
  57. 1, 1, 1, 2, 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1,
  58. 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, 4, 1,
  59. 1, 1, 1, 13, 12, 1, 1, 1, 1, 1, 1, 2, 1, 13, 1, 1,
  60. 5, 1, 2, 1, 12, 1, 1, 1, 24, 2, 1, 1, 1, 4, 1, 308,
  61. 250
  62. };
  63. unsigned int AdaptativeFreqA[No_of_symbols+1] =
  64. {
  65. 0,
  66. 12, 24, 19, 18, 19, 6, 20, 7, 4, 5, 3, 3, 2, 2, 4, 4,
  67. 3, 4, 2, 23, 4, 4, 4, 2, 2, 7, 3, 1, 2, 7, 3, 1,
  68. /* ! = # $ % & ' ( ) * + , - . / */
  69. 49, 1, 3, 2, 2, 2, 2, 1, 2, 2, 1, 3, 4, 3, 5, 3,
  70. /* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? */
  71. 25, 9, 3, 3, 2, 3, 5, 4, 2, 7, 3, 1, 1, 1, 2, 1,
  72. /* @ A B C D E F G H I J K L M N O */
  73. 3, 14, 6, 10, 7, 3, 3, 2, 3, 5, 1, 1, 3, 2, 1, 3,
  74. /* P Q R S T U V W X Y Z [ \ ] ^ _ */
  75. 5, 2, 6, 9, 9, 15, 2, 3, 1, 2, 3, 2, 1, 1, 1, 2,
  76. /* ` a b c d e f g h i j k l m n o */
  77. 2, 20, 4, 13, 12, 32, 4, 5, 6, 24, 1, 1, 5, 7, 18, 21,
  78. /* p q r s t u v w x y z { | } ~ */
  79. 6, 4, 20, 21, 27, 8, 3, 4, 2, 7, 1, 1, 1, 1, 1, 1,
  80. 4, 9, 3, 1, 1, 1, 8, 1, 1, 3, 1, 1, 1, 5, 1, 1,
  81. 1, 2, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82. 1, 2, 1, 1, 3, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1,
  83. 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1,
  84. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  85. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  86. 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2,
  87. 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 24,
  88. 25
  89. };
  90. unsigned int freq[No_of_symbols+1];
  91. /******************************************************************************/
  92. void start_model(int ModelType)
  93. {
  94. int i;
  95. for (i = 0; i < No_of_chars; i++)
  96. {
  97. char_to_index[i] = i+1;
  98. index_to_char[i+1] = (BYTE)i;
  99. }
  100. if (ModelType == FIXED_MODEL)
  101. {
  102. for (i = 0; i <= No_of_symbols; i++)
  103. {
  104. freq[i] = FixedFreqA[i];
  105. }
  106. cum_freq[No_of_symbols] = 0;
  107. for(i = No_of_symbols; i > 0; i--)
  108. {
  109. cum_freq[i-1] = cum_freq[i] + freq[i];
  110. }
  111. }
  112. if (ModelType == ADAPTATIVE_MODEL)
  113. {
  114. for (i = 0; i <= No_of_symbols; i++)
  115. {
  116. freq[i] = AdaptativeFreqA[i];
  117. }
  118. cum_freq[No_of_symbols] = 0;
  119. for(i = No_of_symbols; i > 0; i--)
  120. {
  121. cum_freq[i-1] = cum_freq[i] + freq[i];
  122. }
  123. }
  124. }
  125. /******************************************************************************/
  126. void update_model(int ModelType, unsigned int symbol)
  127. {
  128. unsigned int i;
  129. unsigned int cum;
  130. unsigned int ch_i;
  131. unsigned int ch_symbol;
  132. if (ModelType == ADAPTATIVE_MODEL)
  133. {
  134. if (cum_freq[0] == Max_frequency)
  135. {
  136. cum = 0;
  137. for (i = No_of_symbols + 1; i != 0; /**/)
  138. {
  139. --i;
  140. freq[i] = (freq[i] + 1) / 2;
  141. cum_freq[i] = cum;
  142. cum += freq[i];
  143. }
  144. }
  145. for (i = symbol; freq[i] == freq[i-1]; i--)
  146. {
  147. }
  148. if (i < symbol)
  149. {
  150. ch_i = index_to_char[i];
  151. ch_symbol = index_to_char[symbol];
  152. index_to_char[i] = (BYTE)ch_symbol;
  153. index_to_char[symbol] = (BYTE)ch_i;
  154. char_to_index[ch_i] = symbol;
  155. char_to_index[ch_symbol] = i;
  156. }
  157. freq[i] += 1;
  158. while (i > 0)
  159. {
  160. i -= 1;
  161. cum_freq[i] += 1;
  162. }
  163. }
  164. }
  165. /******************************************************************************/
  166. void start_outputing_bits(void)
  167. {
  168. buffer_out = 0;
  169. bits_to_go_out = 8;
  170. }
  171. /******************************************************************************/
  172. int output_bit(unsigned short int *pOutCount, unsigned int bit)
  173. {
  174. buffer_out >>= 1;
  175. if (bit)
  176. {
  177. buffer_out |= 0x80;
  178. }
  179. bits_to_go_out -= 1;
  180. if (bits_to_go_out == 0)
  181. {
  182. if (*pOutCount == MemoSize)
  183. {
  184. return RV_COMPRESSION_FAILED;
  185. }
  186. Memory[(*pOutCount)++] = (BYTE)buffer_out;
  187. bits_to_go_out = 8;
  188. }
  189. return RV_SUCCESS;
  190. }
  191. /******************************************************************************/
  192. int done_outputing_bits(unsigned short int *pOutCount)
  193. {
  194. if (*pOutCount == MemoSize)
  195. {
  196. return RV_COMPRESSION_FAILED;
  197. }
  198. Memory[(*pOutCount)++] = buffer_out>>bits_to_go_out;
  199. return RV_SUCCESS;
  200. }
  201. /******************************************************************************/
  202. void start_inputing_bits(void)
  203. {
  204. bits_to_go_in = 0;
  205. garbage_bits_in = 0;
  206. Error = RV_SUCCESS;
  207. }
  208. /******************************************************************************/
  209. unsigned int input_bit(BLOC InBloc, unsigned short int *pusInCount)
  210. {
  211. unsigned int t;
  212. if (bits_to_go_in == 0)
  213. {
  214. if (*pusInCount < InBloc.usLen)
  215. {
  216. buffer_in = InBloc.pData[(*pusInCount)++];
  217. }
  218. else
  219. {
  220. buffer_in = 0x00;
  221. }
  222. if (*pusInCount == InBloc.usLen)
  223. {
  224. garbage_bits_in += 1;
  225. if (garbage_bits_in > Code_value_bits - 2)
  226. {
  227. Error = RV_INVALID_DATA;
  228. }
  229. }
  230. bits_to_go_in = 8;
  231. }
  232. t = buffer_in & 1;
  233. buffer_in >>= 1;
  234. bits_to_go_in -= 1;
  235. return (t);
  236. }
  237. /******************************************************************************/
  238. int bit_plus_follow(unsigned short int *pOutCount, unsigned int bit)
  239. {
  240. if (output_bit(pOutCount, bit) != RV_SUCCESS)
  241. {
  242. return RV_COMPRESSION_FAILED;
  243. }
  244. while (bits_to_follow > 0)
  245. {
  246. if (output_bit(pOutCount, !bit) != RV_SUCCESS)
  247. {
  248. return RV_COMPRESSION_FAILED;
  249. }
  250. bits_to_follow -= 1;
  251. }
  252. return RV_SUCCESS;
  253. }
  254. /******************************************************************************/
  255. void start_encoding(void)
  256. {
  257. low_enc = 0;
  258. high_enc = Top_value;
  259. bits_to_follow = 0;
  260. }
  261. /******************************************************************************/
  262. int encode_symbol(unsigned short int *pOutCount,
  263. unsigned int symbol,
  264. unsigned int cum_freq[]
  265. )
  266. {
  267. long range;
  268. range = (long) (high_enc-low_enc) + 1;
  269. high_enc = low_enc + (range * cum_freq[symbol-1]) / cum_freq[0] - 1;
  270. low_enc = low_enc + (range * cum_freq[symbol]) / cum_freq[0];
  271. for ( ; ; )
  272. {
  273. if (high_enc < Half)
  274. {
  275. if (bit_plus_follow(pOutCount, 0) != RV_SUCCESS)
  276. {
  277. return RV_COMPRESSION_FAILED;
  278. }
  279. }
  280. else if (low_enc >= Half)
  281. {
  282. if (bit_plus_follow(pOutCount, 1) != RV_SUCCESS)
  283. {
  284. return RV_COMPRESSION_FAILED;
  285. }
  286. low_enc -= Half;
  287. high_enc -= Half;
  288. }
  289. else if ((low_enc >= First_qtr) && (high_enc < Third_qtr))
  290. {
  291. bits_to_follow += 1;
  292. low_enc -= First_qtr;
  293. high_enc -= First_qtr;
  294. }
  295. else
  296. {
  297. break;
  298. }
  299. low_enc = 2 * low_enc;
  300. high_enc = 2 * high_enc + 1;
  301. }
  302. return RV_SUCCESS;
  303. }
  304. /******************************************************************************/
  305. int done_encoding(unsigned short int *pOutCount)
  306. {
  307. bits_to_follow += 1;
  308. if (low_enc < First_qtr)
  309. {
  310. if (bit_plus_follow(pOutCount, 0) != RV_SUCCESS)
  311. {
  312. return RV_COMPRESSION_FAILED;
  313. }
  314. }
  315. else
  316. {
  317. if (bit_plus_follow(pOutCount, 1) != RV_SUCCESS)
  318. {
  319. return RV_COMPRESSION_FAILED;
  320. }
  321. }
  322. return RV_SUCCESS;
  323. }
  324. /******************************************************************************/
  325. void start_decoding(BLOC InBloc, unsigned short int *pusInCount)
  326. {
  327. unsigned int i;
  328. value_dc = 0;
  329. for (i = 1; i <= Code_value_bits; i++)
  330. {
  331. value_dc = 2 * value_dc + input_bit(InBloc, pusInCount);
  332. if (Error != RV_SUCCESS)
  333. {
  334. break;
  335. }
  336. }
  337. low_dc = 0;
  338. high_dc = Top_value;
  339. }
  340. /******************************************************************************/
  341. unsigned int decode_symbol(BLOC InBloc,
  342. unsigned short int *pusInCount,
  343. unsigned int cum_freq[]
  344. )
  345. {
  346. long range;
  347. unsigned int cum;
  348. unsigned int symbol;
  349. range = (long) (high_dc-low_dc) + 1;
  350. cum = (((long) (value_dc-low_dc) + 1) * cum_freq[0] - 1) / range;
  351. for (symbol = 1; cum_freq[symbol] > cum; symbol++)
  352. {
  353. }
  354. high_dc = low_dc + (range * cum_freq[symbol-1]) / cum_freq[0] - 1;
  355. low_dc = low_dc + (range * cum_freq[symbol]) / cum_freq[0];
  356. for ( ; ; )
  357. {
  358. if (high_dc < Half)
  359. {
  360. }
  361. else if (low_dc >= Half)
  362. {
  363. value_dc -= Half;
  364. low_dc -= Half;
  365. high_dc -= Half;
  366. }
  367. else if ((low_dc >= First_qtr) && (high_dc < Third_qtr))
  368. {
  369. value_dc -= First_qtr;
  370. low_dc -= First_qtr;
  371. high_dc -= First_qtr;
  372. }
  373. else
  374. {
  375. break;
  376. }
  377. low_dc = 2 * low_dc;
  378. high_dc = 2 * high_dc + 1;
  379. value_dc = 2 * value_dc + input_bit(InBloc, pusInCount);
  380. if (Error != RV_SUCCESS)
  381. {
  382. break;
  383. }
  384. }
  385. return (symbol);
  386. }
  387. /******************************************************************************/
  388. int AcAd8_Encode(BLOC *pInBloc, BLOC *pOutBloc)
  389. {
  390. int i, ch;
  391. unsigned int symbol;
  392. unsigned short int usInCount = 0;
  393. unsigned short int usOutCount = 0;
  394. MemoSize = pInBloc->usLen;
  395. Memory = GMEM_Alloc (MemoSize);
  396. if (Memory == NULL)
  397. {
  398. return (RV_MALLOC_FAILED);
  399. }
  400. start_model(ADAPTATIVE_MODEL);
  401. start_outputing_bits();
  402. start_encoding();
  403. for (usInCount = 0; usInCount < pInBloc->usLen; usInCount++)
  404. {
  405. ch = pInBloc->pData[usInCount];
  406. symbol = char_to_index[ch];
  407. if (encode_symbol(&usOutCount, symbol, cum_freq) != RV_SUCCESS)
  408. {
  409. goto err;
  410. }
  411. update_model(ADAPTATIVE_MODEL, symbol);
  412. }
  413. if (encode_symbol(&usOutCount, EOF_symbol, cum_freq) != RV_SUCCESS)
  414. {
  415. goto err;
  416. }
  417. if (done_encoding(&usOutCount) != RV_SUCCESS)
  418. {
  419. goto err;
  420. }
  421. if (done_outputing_bits(&usOutCount) != RV_SUCCESS)
  422. {
  423. goto err;
  424. }
  425. pOutBloc->usLen = usOutCount;
  426. pOutBloc->pData = GMEM_Alloc(pOutBloc->usLen);
  427. if (pOutBloc->pData != NULL)
  428. {
  429. for (i=0; i < pOutBloc->usLen; i++)
  430. {
  431. pOutBloc->pData[i] = Memory[i];
  432. }
  433. GMEM_Free(Memory);
  434. return (RV_SUCCESS);
  435. }
  436. else
  437. {
  438. pOutBloc->usLen = 0;
  439. pOutBloc->pData = NULL;
  440. GMEM_Free(Memory);
  441. return (RV_MALLOC_FAILED);
  442. }
  443. err:
  444. GMEM_Free(Memory);
  445. pOutBloc->usLen = pInBloc->usLen;
  446. pOutBloc->pData = GMEM_Alloc(pOutBloc->usLen);
  447. if (pOutBloc->pData != NULL)
  448. {
  449. for (i=0; i < pOutBloc->usLen; i++)
  450. {
  451. pOutBloc->pData[i] = pInBloc->pData[i];
  452. }
  453. return (RV_COMPRESSION_FAILED);
  454. }
  455. else
  456. {
  457. pOutBloc->usLen = 0;
  458. pOutBloc->pData = NULL;
  459. return (RV_MALLOC_FAILED);
  460. }
  461. }
  462. /******************************************************************************/
  463. int AcFx8_Encode(BLOC *pInBloc, BLOC *pOutBloc)
  464. {
  465. int i, ch;
  466. unsigned int symbol;
  467. unsigned short int usInCount = 0;
  468. unsigned short int usOutCount = 0;
  469. MemoSize = pInBloc->usLen;
  470. Memory = GMEM_Alloc (MemoSize);
  471. if (Memory == NULL)
  472. {
  473. return (RV_MALLOC_FAILED);
  474. }
  475. start_model(FIXED_MODEL);
  476. start_outputing_bits();
  477. start_encoding();
  478. for (usInCount = 0; usInCount < pInBloc->usLen; usInCount++)
  479. {
  480. ch = pInBloc->pData[usInCount];
  481. symbol = char_to_index[ch];
  482. if (encode_symbol(&usOutCount, symbol, cum_freq) != RV_SUCCESS)
  483. {
  484. goto err;
  485. }
  486. update_model(FIXED_MODEL, symbol);
  487. }
  488. if (encode_symbol(&usOutCount, EOF_symbol, cum_freq))
  489. {
  490. goto err;
  491. }
  492. if (done_encoding(&usOutCount) != RV_SUCCESS)
  493. {
  494. goto err;
  495. }
  496. if (done_outputing_bits(&usOutCount) != RV_SUCCESS)
  497. {
  498. goto err;
  499. }
  500. pOutBloc->usLen = usOutCount;
  501. pOutBloc->pData = GMEM_Alloc(pOutBloc->usLen);
  502. if (pOutBloc->pData != NULL)
  503. {
  504. for (i=0; i < pOutBloc->usLen; i++)
  505. {
  506. pOutBloc->pData[i] = Memory[i];
  507. }
  508. GMEM_Free(Memory);
  509. return (RV_SUCCESS);
  510. }
  511. else
  512. {
  513. pOutBloc->usLen = 0;
  514. pOutBloc->pData = NULL;
  515. GMEM_Free(Memory);
  516. return (RV_MALLOC_FAILED);
  517. }
  518. err:
  519. GMEM_Free(Memory);
  520. pOutBloc->usLen = pInBloc->usLen;
  521. pOutBloc->pData = GMEM_Alloc(pOutBloc->usLen);
  522. if (pOutBloc->pData != NULL)
  523. {
  524. for (i=0; i < pOutBloc->usLen; i++)
  525. {
  526. pOutBloc->pData[i] = pInBloc->pData[i];
  527. }
  528. return (RV_COMPRESSION_FAILED);
  529. }
  530. else
  531. {
  532. pOutBloc->usLen = 0;
  533. pOutBloc->pData = NULL;
  534. return (RV_MALLOC_FAILED);
  535. }
  536. }
  537. /******************************************************************************/
  538. int AcAd8_Decode(BLOC *pInBloc, BLOC *pOutBloc)
  539. {
  540. unsigned int ch;
  541. unsigned int symbol;
  542. unsigned short int usInCount = 0;
  543. unsigned short int usOutCount = 0;
  544. MemoSize = 2*pInBloc->usLen;
  545. Memory = GMEM_Alloc(MemoSize);
  546. if (Memory == NULL)
  547. {
  548. pOutBloc->pData = NULL;
  549. pOutBloc->usLen = 0;
  550. return (RV_MALLOC_FAILED);
  551. }
  552. start_model(ADAPTATIVE_MODEL);
  553. start_inputing_bits();
  554. start_decoding(*pInBloc, &usInCount);
  555. while(1)
  556. {
  557. symbol = decode_symbol(*pInBloc, &usInCount, cum_freq);
  558. if ((symbol == EOF_symbol) || (Error != RV_SUCCESS))
  559. {
  560. break;
  561. }
  562. ch = index_to_char[symbol];
  563. if (usOutCount >= MemoSize)
  564. {
  565. Memory = GMEM_ReAlloc (Memory, 2*MemoSize);
  566. if (Memory == NULL)
  567. {
  568. pOutBloc->pData = NULL;
  569. pOutBloc->usLen = 0;
  570. return (RV_MALLOC_FAILED);
  571. }
  572. MemoSize = MemoSize*2;
  573. }
  574. Memory[usOutCount++] = (BYTE)ch;
  575. update_model(ADAPTATIVE_MODEL, symbol);
  576. }
  577. if (Error != RV_SUCCESS)
  578. {
  579. GMEM_Free (Memory);
  580. pOutBloc->pData = NULL;
  581. pOutBloc->usLen = 0;
  582. return (Error);
  583. }
  584. pOutBloc->pData = GMEM_Alloc(usOutCount);
  585. if (pOutBloc->pData == NULL)
  586. {
  587. GMEM_Free (Memory);
  588. pOutBloc->usLen = 0;
  589. return (RV_MALLOC_FAILED);
  590. }
  591. pOutBloc->usLen = usOutCount;
  592. memcpy(pOutBloc->pData, Memory, usOutCount);
  593. GMEM_Free (Memory);
  594. return (RV_SUCCESS);
  595. }
  596. /******************************************************************************/
  597. int AcFx8_Decode(BLOC *pInBloc, BLOC *pOutBloc)
  598. {
  599. unsigned int i, ch;
  600. unsigned int symbol;
  601. unsigned short int usInCount = 0;
  602. unsigned short int usOutCount = 0;
  603. MemoSize = 2*pInBloc->usLen;
  604. Memory = GMEM_Alloc(MemoSize);
  605. if (Memory == NULL)
  606. {
  607. pOutBloc->pData = NULL;
  608. pOutBloc->usLen = 0;
  609. return (RV_MALLOC_FAILED);
  610. }
  611. start_model(FIXED_MODEL);
  612. start_inputing_bits();
  613. start_decoding(*pInBloc, &usInCount);
  614. while(1)
  615. {
  616. symbol = decode_symbol(*pInBloc, &usInCount, cum_freq);
  617. if ((symbol == EOF_symbol) || (Error != RV_SUCCESS))
  618. {
  619. break;
  620. }
  621. ch = index_to_char[symbol];
  622. if (usOutCount >= MemoSize)
  623. {
  624. Memory = GMEM_ReAlloc (Memory, 2*MemoSize);
  625. if (Memory == NULL)
  626. {
  627. pOutBloc->pData = NULL;
  628. pOutBloc->usLen = 0;
  629. return (RV_MALLOC_FAILED);
  630. }
  631. MemoSize = MemoSize*2;
  632. }
  633. Memory[usOutCount++] = (BYTE)ch;
  634. update_model(FIXED_MODEL, symbol);
  635. }
  636. if (Error != RV_SUCCESS)
  637. {
  638. GMEM_Free (Memory);
  639. pOutBloc->pData = NULL;
  640. pOutBloc->usLen = 0;
  641. return (Error);
  642. }
  643. pOutBloc->pData = GMEM_Alloc(usOutCount);
  644. if (pOutBloc->pData == NULL)
  645. {
  646. GMEM_Free (Memory);
  647. pOutBloc->usLen = 0;
  648. return (RV_MALLOC_FAILED);
  649. }
  650. pOutBloc->usLen = usOutCount;
  651. for (i=0; i<pOutBloc->usLen; i++)
  652. {
  653. pOutBloc->pData[i] = Memory[i];
  654. }
  655. GMEM_Free (Memory);
  656. return (RV_SUCCESS);
  657. }