EbookFramework.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:303k
源码类别:

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*******************************************************************************
  36.  * Filename:
  37.  * ---------
  38.  * EbookFramework.c
  39.  *
  40.  * Project:
  41.  * --------MMI_CARD_DRV
  42.  *   MAUI
  43.  *
  44.  * Description:
  45.  * ------------
  46.  *   
  47.  *
  48.  * Author:
  49.  * -------
  50.  * -------
  51.  *
  52.  *==============================================================================
  53.  *             HISTORY
  54.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
  55.  *------------------------------------------------------------------------------
  56.  * removed!
  57.  *
  58.  *------------------------------------------------------------------------------
  59.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
  60.  *============================================================================== 
  61.  *******************************************************************************/
  62. /**
  63.  * Copyright Notice
  64.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  65.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  66.  *  (It is illegal to remove this copyright notice from this software or any
  67.  *  portion of it)
  68.  */
  69. /***************** Ebook Application implementation *********************/
  70. /**************************************************************
  71.    FILENAME : EbookFramework.c
  72.    PURPOSE     : Framework Application Functions
  73.    REMARKS     : nil
  74.    AUTHOR      : Rajat Kumar
  75.    DATE     : 
  76. **************************************************************/
  77. #include "StdC.h"
  78. #include "L4Dr1.h"
  79. #include "L4Dr.h"
  80. #include "MMI_features.h"
  81. #include "Conversions.h"      //KP Jerry add for can use "g_chset_text_encoding" on 2007-3-7
  82. #ifdef __MMI_EBOOK_READER__
  83. #include "gpioInc.h"
  84. #include "TimerEvents.h"
  85. #include "EbookDefs.h"
  86. #include "NVRAMType.h"
  87. #include "NVRAMProt.h"
  88. #include "NVRAMEnum.h"
  89. #include "CommonScreens.h"
  90. #include "FileMgr.h"
  91. #include "EbookManager.h"
  92. #include "EbookProt.h"
  93. #include "FileManagerDef.h"
  94. #include "Conversions.h"
  95. #include "FileManagerGProt.h"
  96. #include "fmt_struct.h"
  97. #include "PhoneSetupGprots.h"
  98. #include "hf_rules.h"
  99. g_current_book_context g_curr_bk_cntx;
  100. g_current_book_context *g_curr_book_cntx_p = &g_curr_bk_cntx;
  101. S8 *HW_itoa(S32 value, S8 *s, S32 radix);
  102. S32 HW_atoi(const S8 *s);
  103. #define MAX_FAILURE_RETRIES     5
  104. #define MAX_RECORD_CONVERT_EACH_RECURSION    8
  105. #define WHITE_SPACE 0x20
  106. /*****************************************************************************
  107.  * FUNCTION
  108.  *  ebr_frm_open_book_create_nfo_file_pdb
  109.  * DESCRIPTION
  110.  *  Create Nfo File for PDB
  111.  * PARAMETERS
  112.  *  filename        [IN]        
  113.  * RETURNS
  114.  *  void
  115.  *****************************************************************************/
  116. ebr_frm_nfo_create_type_errors_enum ebr_frm_open_book_create_nfo_file_pdb(U8 *filename)
  117. {
  118.     /*----------------------------------------------------------------*/
  119.     /* Local Variables                                                */
  120.     /*----------------------------------------------------------------*/
  121.     U32 size;
  122.     FILE_HANDLE file_hnd, nfo_hnd;
  123.     S32 write_result;
  124.     U8 ebook_file_name[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH] = {0};
  125.     ebr_frm_database_hdr_type file_header;
  126.     S32 local_nfo_id, compare_type = 0, isValidNfo = 0;
  127.     S32 offset;
  128.     S32 create_nfo_file = 0;
  129.     ebr_frm_nfo_create_type_errors_enum return_value = EBR_FRM_NFO_CREATE_SUCCESS;
  130.     doc_record0 rec0;
  131.     S32 attr = 0;
  132.     U32 nfo_file_size;
  133. pBOOL is_read_only = FALSE;
  134.     /*----------------------------------------------------------------*/
  135.     /* Code Body                                                      */
  136.     /*----------------------------------------------------------------*/
  137.     pfnUnicodeStrcpy(
  138.         (S8*) ebook_file_name,
  139.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  140.     pfnUnicodeStrcat((PS8) ebook_file_name, (PS8) filename);
  141.     attr = FS_GetAttributes((const WCHAR*)ebook_file_name);
  142.     if (attr & FS_ATTR_READ_ONLY)
  143.     {
  144.         is_read_only = TRUE;
  145.         FS_SetAttributes((const WCHAR*)ebook_file_name, (U8) (attr & ~(FS_ATTR_READ_ONLY)));
  146.     }
  147.     file_hnd = FS_Open((const WCHAR*)ebook_file_name, FS_READ_WRITE);
  148.     if (!file_hnd)
  149.     {
  150.         return EBR_FRM_NFO_CREATE_FAILURE;
  151.     }
  152.     if (FS_Read(file_hnd, &file_header, EBR_FRM_DATABASE_HEADER_SIZE, &size) == FS_NO_ERROR)
  153.     {
  154.         if (file_header.modification_date > 32768)
  155.         {
  156.             create_nfo_file = 1;
  157.         }
  158.         else
  159.         {   /* Check that the cerrseponding nfo file exists or not if not then change the header information */
  160.             nfo_hnd = FS_Open((const WCHAR*)ebr_frm_get_nfo_file_name((S32) file_header.modification_date), FS_READ_ONLY);
  161.             if (nfo_hnd <= 0)
  162.             {
  163.                 create_nfo_file = 1;
  164.             }
  165.             else
  166.             {
  167.                 FS_Read(
  168.                     nfo_hnd,
  169.                     &g_curr_book_cntx_p->g_nfo_book_struct,
  170.                     sizeof(g_curr_book_cntx_p->g_nfo_book_struct),
  171.                     &size);
  172.                 FS_GetFileSize(nfo_hnd, &nfo_file_size);
  173.                 isValidNfo = strncmp(
  174.                                 (const S8*)g_curr_book_cntx_p->g_nfo_book_struct.checksum,
  175.                                 (const S8*)EBR_TXT_FOOTER_START,
  176.                                 TXT_FOOTER_START_SIZE);
  177.                 compare_type = pfnUnicodeStrcmp(
  178.                                 (const S8*)g_curr_book_cntx_p->g_nfo_book_struct.e_book_name,
  179.                                 (const S8*)g_curr_book_cntx_p->nfo_name);
  180.                 if ((compare_type != 0) || (isValidNfo != 0) ||
  181.                     (nfo_file_size != sizeof(g_curr_book_cntx_p->g_nfo_book_struct)))
  182.                 {
  183.                     create_nfo_file = 1;
  184.                 }
  185.                 FS_Close(nfo_hnd);
  186.             }
  187.         }
  188.     }
  189.     if (create_nfo_file)
  190.     {
  191.         if (memcmp(file_header.type, DOC_TYPE, strlen((PS8) DOC_TYPE)) == 0)
  192.         {
  193.             if (FS_Read(file_hnd, &offset, 4, &size) == FS_NO_ERROR)
  194.             {
  195.                 offset = ntohl(offset);
  196.             }
  197.             FS_Seek(file_hnd, offset, FS_FILE_BEGIN);
  198.             if (FS_Read(file_hnd, &rec0, sizeof rec0, &size) == FS_NO_ERROR)
  199.             {
  200.                 g_curr_book_cntx_p->num_records = ntohs(rec0.num_records);
  201.                 g_curr_book_cntx_p->g_nfo_book_struct.book_size = ntohl(rec0.doc_size);
  202.                 if (ebr_frm_is_empty_file(file_hnd, EBR_FRM_FILE_TYPE_PDB))
  203.                 {
  204.                     create_nfo_file = 1;
  205.                     return_value = EBR_FRM_EMPTY_BOOK;
  206.                     memset(g_curr_book_cntx_p->nfo_path, 0, sizeof(g_curr_book_cntx_p->nfo_path));
  207.                     FS_Close(file_hnd);
  208.                     return return_value;
  209.                 }
  210.             }
  211.             pfnUnicodeStrcpy(
  212.                 (S8*) ebook_file_name,
  213.                 (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  214.             local_nfo_id = ebr_frm_create_nfo_file(file_header.name, ebook_file_name, filename);
  215.             if (local_nfo_id >= 0)
  216.             {
  217.                 file_header.modification_date = local_nfo_id;
  218.                 if (g_curr_book_cntx_p->src_application == EBR_FRM_SRC_APP_FMGR)
  219.                 {   /* Means it is from file manager */
  220.                     ebr_frm_fmgr_set_nfo_id(local_nfo_id);
  221.                 }
  222.                 FS_Seek(file_hnd, 0, FS_FILE_BEGIN);
  223.                 write_result = FS_Write(file_hnd, &file_header, EBR_FRM_DATABASE_HEADER_SIZE, (U32*) & size);
  224.                 return_value = EBR_FRM_NFO_CREATE_SUCCESS;
  225.             }
  226.             else
  227.             {
  228.                 return_value = EBR_FRM_NFO_CREATE_FAILURE;
  229.             }
  230.         }
  231.         else
  232.         {
  233.             return_value = EBR_FRM_NFO_CREATE_FILE_TYPE_NOT_SUPPORTED;
  234.         }
  235.     }
  236.     FS_Close(file_hnd);
  237.     pfnUnicodeStrcpy(
  238.         (S8*) ebook_file_name,
  239.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  240.     pfnUnicodeStrcat((PS8) ebook_file_name, (PS8) filename);
  241.     attr = FS_GetAttributes((const WCHAR*)ebook_file_name);
  242. if(is_read_only)
  243. {
  244. FS_SetAttributes((const WCHAR*)ebook_file_name, (U8) (attr | (FS_ATTR_READ_ONLY)));
  245. }
  246.     return return_value;
  247. }
  248. /*****************************************************************************
  249.  * FUNCTION
  250.  *  ebr_frm_open_book_create_nfo_file_txt
  251.  * DESCRIPTION
  252.  *  Create Nfo File for TXT
  253.  * PARAMETERS
  254.  *  filename        [IN]        
  255.  * RETURNS
  256.  *  void
  257.  *****************************************************************************/
  258. ebr_frm_nfo_create_type_errors_enum ebr_frm_open_book_create_nfo_file_txt(U8 *filename)
  259. {
  260.     /*----------------------------------------------------------------*/
  261.     /* Local Variables                                                */
  262.     /*----------------------------------------------------------------*/
  263.     U32 size;
  264.     FILE_HANDLE file_hnd, nfo_hnd;
  265.     S8 tmp_str[MAX_EBOOK_NAME_LENGTH];
  266.     U8 ebook_file_name[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH] = {0};
  267.     U8 display_name[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH] = {0};
  268.     S32 create_nfo_file = 0, compare_type = 0, isValidNfo = 0;
  269.     S32 local_nfo_id;
  270.     U32 strlength = 0;
  271.     ebr_frm_nfo_create_type_errors_enum return_value = EBR_FRM_NFO_CREATE_SUCCESS;
  272.     S32 attr = 0;
  273.     U32 nfo_file_size;
  274. pBOOL is_read_only = FALSE;
  275.     /*----------------------------------------------------------------*/
  276.     /* Code Body                                                      */
  277.     /*----------------------------------------------------------------*/
  278.     pfnUnicodeStrcpy(
  279.         (S8*) ebook_file_name,
  280.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  281.     pfnUnicodeStrcat((S8*) ebook_file_name, (S8*) filename);
  282.     attr = FS_GetAttributes((const WCHAR*)ebook_file_name);
  283.     if (attr & FS_ATTR_READ_ONLY)
  284.     {
  285.         is_read_only = TRUE;
  286.         FS_SetAttributes((const WCHAR*)ebook_file_name, (U8) (attr & ~(FS_ATTR_READ_ONLY)));
  287.     }
  288.     file_hnd = FS_Open((const WCHAR*)ebook_file_name, FS_READ_WRITE);
  289.     if (file_hnd > 0)
  290.     {
  291.         FS_GetFileSize(file_hnd, &g_curr_book_cntx_p->g_nfo_book_struct.book_size);
  292.         /* g_curr_book_cntx_p->g_nfo_book_struct.book_size=g_curr_book_cntx_p->g_nfo_book_struct.book_size-TXT_FOOTER_END_SIZE-MAX_EBOOK_NAME_LENGTH-TXT_FOOTER_START_SIZE; */
  293.         if (ebr_frm_is_empty_file(file_hnd, EBR_FRM_FILE_TYPE_TXT))
  294.         {
  295.             create_nfo_file = 1;
  296.             return_value = EBR_FRM_EMPTY_BOOK;
  297.             memset(g_curr_book_cntx_p->nfo_path, 0, sizeof(g_curr_book_cntx_p->nfo_path));
  298.             goto end;
  299.         }
  300.             FS_Close(file_hnd);
  301.             local_nfo_id = ebr_fmgr_get_nfo_id_for_txt_file(g_curr_book_cntx_p->memory_type_selected, (PS8) filename);
  302.         file_hnd = FS_Open((const WCHAR*)ebook_file_name, FS_READ_WRITE);
  303.         if (local_nfo_id != 0)
  304.         {
  305.             nfo_hnd = FS_Open((const WCHAR*)ebr_frm_get_nfo_file_name((S32) local_nfo_id), FS_READ_ONLY);
  306.             if (nfo_hnd <= 0)
  307.             {
  308.                 create_nfo_file = 1;
  309.                 FS_Seek(file_hnd, -TXT_FOOTER_START_SIZE - TXT_FOOTER_END_SIZE - MAX_EBOOK_NAME_LENGTH, FS_FILE_END);
  310.                 g_curr_book_cntx_p->g_nfo_book_struct.book_size =
  311.                             g_curr_book_cntx_p->g_nfo_book_struct.book_size + (-TXT_FOOTER_START_SIZE -
  312.                                                                        TXT_FOOTER_END_SIZE - MAX_EBOOK_NAME_LENGTH);
  313.                 FS_Truncate(file_hnd);
  314.             }
  315.             else
  316.             {
  317.                 FS_Read(
  318.                     nfo_hnd,
  319.                     &g_curr_book_cntx_p->g_nfo_book_struct,
  320.                     sizeof(g_curr_book_cntx_p->g_nfo_book_struct),
  321.                     &size);
  322.                 FS_GetFileSize(nfo_hnd, &nfo_file_size);
  323.                 isValidNfo = strncmp(
  324.                                 (const S8*)g_curr_book_cntx_p->g_nfo_book_struct.checksum,
  325.                                 (const S8*)EBR_TXT_FOOTER_START,
  326.                                 TXT_FOOTER_START_SIZE);
  327.                 compare_type = pfnUnicodeStrcmp(
  328.                                 (const S8*)g_curr_book_cntx_p->g_nfo_book_struct.e_book_name,
  329.                                 (const S8*)g_curr_book_cntx_p->nfo_name);
  330.                 if ((compare_type != 0) || (isValidNfo != 0) ||
  331.                     (nfo_file_size != sizeof(g_curr_book_cntx_p->g_nfo_book_struct)))
  332.                 {
  333.                     create_nfo_file = 1;
  334.     if (FS_Seek(
  335.                         file_hnd,
  336.                         -TXT_FOOTER_START_SIZE - TXT_FOOTER_END_SIZE - MAX_EBOOK_NAME_LENGTH,
  337.                         FS_FILE_END))
  338.                     {
  339. g_curr_book_cntx_p->g_nfo_book_struct.book_size =
  340. g_curr_book_cntx_p->g_nfo_book_struct.book_size + (-TXT_FOOTER_START_SIZE -
  341.                             TXT_FOOTER_END_SIZE - MAX_EBOOK_NAME_LENGTH);
  342.                     }
  343.                     FS_Truncate(file_hnd);
  344.                 }
  345.                 else
  346.                 {
  347.                     return_value = EBR_FRM_NFO_CREATE_SUCCESS;
  348.                 }
  349.                 FS_Close(nfo_hnd);
  350.             }
  351.         }
  352.         else
  353.         {
  354.             create_nfo_file = 1;
  355.         }
  356.     }
  357.     else
  358.     {
  359.         return_value = EBR_FRM_NFO_CREATE_FAILURE;
  360.     }
  361.     if (create_nfo_file)
  362.     {
  363.         strlength = pfnUnicodeStrlen((const S8*)filename);
  364.         pfnUnicodeStrncpy((S8*) display_name, (S8*) filename, strlength - EBR_EXTENSION_NAME_LENGTH - 1);
  365.         local_nfo_id = ebr_frm_create_nfo_file(display_name, ebook_file_name, filename);
  366.         if (local_nfo_id >= 0)
  367.         {
  368.             memset(tmp_str, 0, MAX_EBOOK_NAME_LENGTH);
  369.             if (g_curr_book_cntx_p->src_application == EBR_FRM_SRC_APP_FMGR)
  370.             {   /* Means it is from file manager */
  371.                 ebr_frm_fmgr_set_nfo_id(local_nfo_id);
  372.             }
  373.             HW_itoa(g_curr_book_cntx_p->g_last_nfo_id_allocated, (S8*) tmp_str, 10);
  374.             FS_Seek(file_hnd, 0, FS_FILE_END);
  375.             FS_Write(file_hnd, EBR_TXT_FOOTER_START, TXT_FOOTER_START_SIZE, &size);
  376.             FS_Write(file_hnd, tmp_str, MAX_EBOOK_NAME_LENGTH, &size);
  377.             FS_Write(file_hnd, EBR_TXT_FOOTER_END, TXT_FOOTER_END_SIZE, &size);
  378.             return_value = EBR_FRM_NFO_CREATE_SUCCESS;
  379.         }
  380.         else
  381.         {
  382.             return_value = EBR_FRM_NFO_CREATE_FAILURE;
  383.         }
  384.     }
  385.   end:
  386.     pfnUnicodeStrcpy((PS8) g_curr_book_cntx_p->book_name_path, (PS8) ebook_file_name);
  387.     FS_Close(file_hnd);
  388. attr = FS_GetAttributes((const WCHAR*)ebook_file_name);
  389. if(is_read_only)
  390. {
  391. FS_SetAttributes((const WCHAR*)ebook_file_name, (U8) (attr | (FS_ATTR_READ_ONLY)));
  392. }
  393.     return return_value;
  394. }
  395. /*****************************************************************************
  396.  * FUNCTION
  397.  *  ebr_frm_is_empty_file
  398.  * DESCRIPTION
  399.  *  Check if it is an empty file
  400.  * PARAMETERS
  401.  *  filename        [IN]        
  402.  * RETURNS
  403.  *  void
  404.  *****************************************************************************/
  405. MMI_BOOL ebr_frm_is_empty_file(FILE_HANDLE file_hnd, ebr_frm_filetype_enum type)
  406. {
  407.     U32 filesize, size, offset;
  408.     S8 file_header[10];
  409.     S8 UCS2empty[2] = {0xFF, 0xFE};
  410.     S8 UCS2BEempty[2] = {0xFE, 0xFF};
  411.     S8 UTF8empty[3] = {0xEF, 0xBB, 0xBF};   
  412.     memset(&file_header, 0, 10);
  413.     
  414.     if (type == EBR_FRM_FILE_TYPE_TXT)
  415.     {               
  416.         FS_GetFileSize(file_hnd, &filesize);
  417.         FS_Read(file_hnd, &file_header, 10, &size);
  418.         
  419.         /* g_curr_book_cntx_p->g_nfo_book_struct.book_size=g_curr_book_cntx_p->g_nfo_book_struct.book_size-TXT_FOOTER_END_SIZE-MAX_EBOOK_NAME_LENGTH-TXT_FOOTER_START_SIZE; */
  420.         if (filesize == 0)
  421.         {
  422.             return MMI_TRUE;
  423.         }
  424.         //else if (mmiEncoding == MMI_CHSET_UCS2 && (strncmp(file_header, UCS2empty, 2) == 0 || strncmp(file_header, UCS2BEempty, 2) == 0))
  425.         else if (pfnUnicodeStrlen(file_header) == 1 && (strncmp(file_header, UCS2empty, 2) == 0 || strncmp(file_header, UCS2BEempty, 2) == 0))
  426.         {
  427.             return MMI_TRUE;
  428.         }
  429.         else if (strlen(file_header) == 3 && strncmp(file_header, UTF8empty, 3) == 0)
  430.         {
  431.             return MMI_TRUE;
  432.         }
  433.         return MMI_FALSE;
  434.     }
  435.     else
  436.     {
  437.         SEEK_REC_ENTRY(file_hnd, 1);
  438.         if (FS_Read(file_hnd, &offset, 4, (U32*) & size) == FS_NO_ERROR)
  439.         {
  440.             offset = ntohl(offset);
  441.         }        
  442.         if (g_curr_book_cntx_p->g_nfo_book_struct.book_size == 1)
  443.         {
  444.             if (FS_Seek(file_hnd, offset, FS_FILE_BEGIN) != FS_INVALID_FILE_POS)
  445.             {
  446.                 FS_Read(file_hnd, file_header, 10, (U32*) &size);
  447.             }
  448.             if (file_header[0] == 0x20)
  449.             {
  450.                 return TRUE;
  451.             }
  452.         }
  453.         return FALSE;
  454.     }
  455.     
  456. }
  457. /*****************************************************************************
  458.  * FUNCTION
  459.  *  ebr_frm_get_nfo_file_name
  460.  * DESCRIPTION
  461.  *  Get Nfo File Name.
  462.  * PARAMETERS
  463.  *  local_nfo_id        [IN]        
  464.  * RETURNS
  465.  *  void
  466.  *****************************************************************************/
  467. U8 *ebr_frm_get_nfo_file_name(S32 local_nfo_id)
  468. {
  469.     /*----------------------------------------------------------------*/
  470.     /* Local Variables                                                */
  471.     /*----------------------------------------------------------------*/
  472.     static U8 nfo_file_name[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH] = {0};
  473.     static S32 prev_local_nfo_id = -1;
  474.     S8 nfo_file_name_prefix_ascii[MAX_EBOOK_NAME_LENGTH - 3];   /* Extension length subtracted */
  475.     S8 nfo_file_name_prefix_ucs2[(MAX_EBOOK_NAME_LENGTH - 3) * ENCODING_LENGTH];
  476.     UI_string_type temp_str[MAX_EBOOK_NAME_LENGTH];
  477.     /*----------------------------------------------------------------*/
  478.     /* Code Body                                                      */
  479.     /*----------------------------------------------------------------*/
  480.     if (prev_local_nfo_id == local_nfo_id)
  481.     {
  482.         return nfo_file_name;
  483.     }
  484.     pfnUnicodeStrcpy(
  485.         (S8*) nfo_file_name,
  486.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  487.     sprintf(nfo_file_name_prefix_ascii, "%08d", local_nfo_id);
  488.     AnsiiToUnicodeString((PS8) nfo_file_name_prefix_ucs2, (PS8) nfo_file_name_prefix_ascii);
  489.     pfnUnicodeStrcat((PS8) nfo_file_name, nfo_file_name_prefix_ucs2);
  490.     AnsiiToUnicodeString((PS8) temp_str, (PS8) EBR_EBOOK_NFO_FILE_EXT);
  491.     pfnUnicodeStrcat((PS8) nfo_file_name, (PS8) temp_str);
  492.     prev_local_nfo_id = local_nfo_id;
  493.     return nfo_file_name;
  494. }
  495. /*****************************************************************************
  496.  * FUNCTION
  497.  *  ebr_frm_create_nfo_file
  498.  * DESCRIPTION
  499.  *  Create Nfo File for TXT and PDB
  500.  * PARAMETERS
  501.  *  display_name                    [IN]        
  502.  *  ebook_file_name_with_path       [IN]        
  503.  *  ebook_file_name                 [IN]        
  504.  * RETURNS
  505.  *  void
  506.  *****************************************************************************/
  507. S32 ebr_frm_create_nfo_file(U8 *display_name, U8 *ebook_file_name_with_path, U8 *ebook_file_name)
  508. {
  509.     /*----------------------------------------------------------------*/
  510.     /* Local Variables                                                */
  511.     /*----------------------------------------------------------------*/
  512.     FILE_HANDLE file_hnd;
  513.     S32 return_val;
  514.     /*----------------------------------------------------------------*/
  515.     /* Code Body                                                      */
  516.     /*----------------------------------------------------------------*/
  517.     ebr_frm_find_next_nfo_id();
  518.     file_hnd = FS_Open(
  519.                 (const WCHAR*)ebr_frm_get_nfo_file_name(++g_curr_book_cntx_p->g_last_nfo_id_allocated),
  520.                 FS_CREATE | FS_ATTR_HIDDEN);
  521.     if (file_hnd != 0)
  522.     {
  523.         return_val = ebr_frm_fill_nfo_file(file_hnd, display_name, (U8*) ebook_file_name);
  524.         FS_Close(file_hnd);
  525.         if (return_val == 0)
  526.         {
  527.             FS_Delete((const WCHAR*)
  528.                       ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  529.             return -1;
  530.         }
  531.         else
  532.         {
  533.             return g_curr_book_cntx_p->g_last_nfo_id_allocated;
  534.         }
  535.     }
  536.     else
  537.     {
  538.         return -1;
  539.     }
  540. }
  541. /*****************************************************************************
  542.  * FUNCTION
  543.  *  ebr_frm_fill_nfo_file
  544.  * DESCRIPTION
  545.  *  Fill the NFO file
  546.  * PARAMETERS
  547.  *  file_hnd            [IN]        
  548.  *  display_name        [IN]        
  549.  *  ebook_file_name     [IN]        
  550.  * RETURNS
  551.  *  void
  552.  *****************************************************************************/
  553. S16 ebr_frm_fill_nfo_file(FILE_HANDLE file_hnd, U8 *display_name, U8 *ebook_file_name)
  554. {
  555.     /*----------------------------------------------------------------*/
  556.     /* Local Variables                                                */
  557.     /*----------------------------------------------------------------*/
  558.     ebr_frm_book_struct book_struct;
  559.     ebr_frm_setting_struct g_setting;
  560.     ebr_frm_setting_struct *g_setting_list = &g_setting;
  561.     U8 i;
  562.     U32 size;
  563.     S16 error;
  564.     S32 write_result;
  565.     /*----------------------------------------------------------------*/
  566.     /* Code Body                                                      */
  567.     /*----------------------------------------------------------------*/
  568.     pfnUnicodeStrcpy((PS8) book_struct.e_book_name, (PS8) ebook_file_name);
  569.     pfnUnicodeStrcpy((PS8) book_struct.display_name, (PS8) display_name);
  570.     book_struct.book_size = g_curr_book_cntx_p->g_nfo_book_struct.book_size;
  571.     book_struct.temp_book_size = 0;
  572.     book_struct.temp_encoding_file_format = '';
  573.     book_struct.current_page_id = 0;
  574.     book_struct.offset = 0;
  575.     book_struct.jump_offset = 0;
  576.     book_struct.last_showed_percentage = 0;
  577.     book_struct.last_text_offset_y = 0;
  578.     for (i = 0; i < EBR_FRM_MAX_NO_OF_BOOKMARKS; i++)
  579.     {
  580.         book_struct.book_marks[i].offset = 0;
  581.         book_struct.book_marks[i].page_id = 0;
  582.         pfnUnicodeStrcpy((PS8) book_struct.book_marks[i].bookmark_name, (PS8) NULL);
  583.         book_struct.book_marks[i].percentage_associated_with_book_mark = 0;
  584.     }
  585.     ReadRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
  586. #ifndef MMI_ON_HARDWARE_P
  587.     if (g_setting_list->common_settings.encoding_format == 0xff)
  588.     {
  589.         g_setting_list->common_settings.encoding_format = EBOOK_WESTERN_WINDOWS;
  590.         g_setting_list->common_settings.font_size = EBR_FONT_SIZE_MEDIUM;
  591.         g_setting_list->common_settings.font_style = EBR_FONT_STYLE_NORMAL;
  592.         g_setting_list->memory_type = (S8)MMI_PUBLIC_DRV;
  593.         g_setting_list->common_settings.screen_mode = EBR_FULL_SCREEN_OFF;
  594.         g_setting_list->common_settings.auto_scroll_settings.scroll_flag = EBR_SCROLL_OFF;
  595.         g_setting_list->common_settings.auto_scroll_settings.scroll_speed = EBR_AUTO_SCROLL_SPEED_1;
  596.         g_setting_list->common_settings.auto_scroll_settings.scroll_type = EBR_SCROLL_BY_PAGE;
  597.         WriteRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
  598.         WriteRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
  599.     }
  600. #endif /* MMI_ON_HARDWARE_P */ 
  601.     book_struct.settings = g_setting_list->common_settings;
  602.     strcpy((char*)book_struct.checksum, (const char*)EBR_TXT_FOOTER_START);
  603.     if ((write_result = FS_Write(file_hnd, &book_struct, sizeof(ebr_frm_book_struct), (U32*) & size)) == FS_NO_ERROR)
  604.     {
  605.         return 1;
  606.     }
  607.     else
  608.     {
  609.         return 0;
  610.     }
  611. }
  612. /*****************************************************************************
  613.  * FUNCTION
  614.  *  ebr_frm_get_nfo_id_from_file_name
  615.  * DESCRIPTION
  616.  *  Get the next NFO from File
  617.  * PARAMETERS
  618.  *  file_name_without_path      [IN]        
  619.  * RETURNS
  620.  *  void
  621.  *****************************************************************************/
  622. S32 ebr_frm_get_nfo_id_from_file_name(U8 *file_name_without_path)
  623. {
  624.     /*----------------------------------------------------------------*/
  625.     /* Local Variables                                                */
  626.     /*----------------------------------------------------------------*/
  627.     U8 previous_file_name[MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH];
  628.     S32 i = 0;
  629.     /*----------------------------------------------------------------*/
  630.     /* Code Body                                                      */
  631.     /*----------------------------------------------------------------*/
  632.     while (file_name_without_path[i * 2] != '.')
  633.     {
  634.         previous_file_name[i] = file_name_without_path[i * 2];
  635.         i++;
  636.     }
  637.     previous_file_name[i] = 0;
  638.     return HW_atoi((const S8*)previous_file_name);
  639. }
  640. /*****************************************************************************
  641.  * FUNCTION
  642.  *  ebr_frm_find_next_nfo_id
  643.  * DESCRIPTION
  644.  *  Get the next NFO id
  645.  * PARAMETERS
  646.  *  void
  647.  * RETURNS
  648.  *  void
  649.  *****************************************************************************/
  650. void ebr_frm_find_next_nfo_id(void)
  651. {
  652.     /*----------------------------------------------------------------*/
  653.     /* Local Variables                                                */
  654.     /*----------------------------------------------------------------*/
  655.     S8 nfo_search_query[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
  656.     FS_HANDLE fh_cur;
  657.     FS_DOSDirEntry file_info;
  658.     S32 count = 0;
  659.     S32 file_id = 0;
  660.     U8 file_name_without_path[MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH];
  661.     S16 nfo_id_from_middle = 0;
  662.     /*----------------------------------------------------------------*/
  663.     /* Code Body                                                      */
  664.     /*----------------------------------------------------------------*/
  665.     pfnUnicodeStrcpy(
  666.         (S8*) nfo_search_query,
  667.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_NFO));
  668.     if ((fh_cur = FS_FindFirst(
  669.                     (const WCHAR*)nfo_search_query,
  670.                     0,
  671.                     0,
  672.                     &file_info,
  673.                     (WCHAR*) file_name_without_path,
  674.                     MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH)) >= 0)
  675.     {
  676.         do
  677.         {
  678.             count++;
  679.             if (!(file_info.Attributes & FS_ATTR_DIR))
  680.             {
  681.                 file_id = ebr_frm_get_nfo_id_from_file_name(file_name_without_path);
  682.             }
  683.             if (count < file_id)
  684.             {
  685.                 nfo_id_from_middle = 1;
  686.                 break;
  687.             }
  688.         } while ((FS_FindNext
  689.                   (fh_cur, &file_info, (U16*) file_name_without_path,
  690.                    MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH) == FS_NO_ERROR));
  691.         FS_FindClose(fh_cur);
  692.     }
  693.     if (count > 0)
  694.     {
  695.         if (nfo_id_from_middle != 1)
  696.         {
  697.             g_curr_book_cntx_p->g_last_nfo_id_allocated = file_id;
  698.         }
  699.         else
  700.         {
  701.             g_curr_book_cntx_p->g_last_nfo_id_allocated = --count;
  702.         }
  703.     }
  704.     else
  705.     {
  706.         g_curr_book_cntx_p->g_last_nfo_id_allocated = 0;
  707.     }
  708. }
  709. /*****************************************************************************
  710.  * FUNCTION
  711.  *  ebr_frm_delete_unused_nfo_file
  712.  * DESCRIPTION
  713.  *  Delete invalid NFO files.
  714.  * PARAMETERS
  715.  *  void
  716.  * RETURNS
  717.  *  void
  718.  *****************************************************************************/
  719. void ebr_frm_delete_unused_nfo_file(void)
  720. {
  721.     /*----------------------------------------------------------------*/
  722.     /* Local Variables                                                */
  723.     /*----------------------------------------------------------------*/
  724.     FS_HANDLE fh_cur;
  725.     FS_DOSDirEntry file_info;
  726.     S8 path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
  727.     U8 filename[MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH];
  728.     /*----------------------------------------------------------------*/
  729.     /* Code Body                                                      */
  730.     /*----------------------------------------------------------------*/
  731.     pfnUnicodeStrcpy(
  732.         (S8*) path,
  733.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_NFO));
  734.     if ((fh_cur = FS_FindFirst(
  735.                     (const WCHAR*)path,
  736.                     0,
  737.                     0,
  738.                     &file_info,
  739.                     (U16*) filename,
  740.                     MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH)) >= 0)
  741.     {
  742.         do
  743.         {
  744.             if (!(file_info.Attributes & FS_ATTR_DIR))
  745.             {
  746.                 ebr_frm_open_nfo_file_and_delete_unused_nfo(filename);
  747.             }
  748.         } while ((FS_FindNext(fh_cur, &file_info, (U16*) filename, MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH) ==
  749.                   FS_NO_ERROR));
  750.         FS_FindClose(fh_cur);
  751.     }
  752. }
  753. /*****************************************************************************
  754.  * FUNCTION
  755.  *  ebr_frm_open_nfo_file_and_delete_unused_nfo
  756.  * DESCRIPTION
  757.  *  Delete invalid NFO files.
  758.  * PARAMETERS
  759.  *  filename        [IN]        
  760.  * RETURNS
  761.  *  void
  762.  *****************************************************************************/
  763. void ebr_frm_open_nfo_file_and_delete_unused_nfo(U8 *filename)
  764. {
  765.     /*----------------------------------------------------------------*/
  766.     /* Local Variables                                                */
  767.     /*----------------------------------------------------------------*/
  768.     S8 nfo_path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH + ENCODING_LENGTH];
  769.     S8 file_path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH + ENCODING_LENGTH];
  770.     FILE_HANDLE nfo_hnd, file_hnd;
  771.     U32 size, nfo_file_size;
  772.     S32 nfo_id, strlen_file_name;
  773.     pBOOL isValidNfo = FALSE;
  774.     S32 local_nfo_id;
  775.     S8 nfo_file_name[NFO_FILE_NAME_LENGTH] = {0};
  776.     S8 nfo_file[NFO_FILE_NAME_VALUE] = {0};
  777.     /*----------------------------------------------------------------*/
  778.     /* Code Body                                                      */
  779.     /*----------------------------------------------------------------*/
  780.     UnicodeToAnsii((S8*) nfo_file_name, (S8*) filename);
  781.     strncpy((S8*) nfo_file, (S8*) nfo_file_name, NFO_FILE_NAME_VALUE - 1);
  782.     nfo_file[NFO_FILE_NAME_VALUE-1] = '';
  783.     local_nfo_id = HW_atoi((const S8*)nfo_file);
  784.     pfnUnicodeStrcpy(
  785.         (S8*) nfo_path,
  786.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  787.     pfnUnicodeStrcat((S8*) nfo_path, (S8*) filename);
  788.     nfo_hnd = FS_Open((const WCHAR*)nfo_path, FS_READ_ONLY);
  789.     FS_Read(nfo_hnd, &g_curr_book_cntx_p->g_nfo_book_struct, sizeof(g_curr_book_cntx_p->g_nfo_book_struct), &size);
  790.     FS_GetFileSize(nfo_hnd, &nfo_file_size);
  791.     if ((!strncmp
  792.          ((const S8*)g_curr_book_cntx_p->g_nfo_book_struct.checksum, (const S8*)EBR_TXT_FOOTER_START,
  793.           TXT_FOOTER_START_SIZE)) && (nfo_file_size == sizeof(g_curr_book_cntx_p->g_nfo_book_struct)))
  794.     {
  795.         isValidNfo = TRUE;
  796.     }
  797.     else
  798.     {
  799.         isValidNfo = FALSE;
  800.     }
  801.     FS_Close(nfo_hnd);
  802.     if (isValidNfo)
  803.     {
  804.     strlen_file_name = pfnUnicodeStrlen((const S8*)g_curr_book_cntx_p->g_nfo_book_struct.e_book_name);
  805.     if ((g_curr_book_cntx_p->g_nfo_book_struct.e_book_name[strlen_file_name * 2 - 6] == 'p') ||
  806.         (g_curr_book_cntx_p->g_nfo_book_struct.e_book_name[strlen_file_name * 2 - 6] == 'P'))
  807.     {
  808.         g_curr_book_cntx_p->gbook_type = EBR_FRM_FILE_TYPE_PDB;
  809.     }
  810.     else
  811.     {
  812.         g_curr_book_cntx_p->gbook_type = EBR_FRM_FILE_TYPE_TXT;
  813.     }
  814.         pfnUnicodeStrncpy(
  815.             (S8*) file_path,
  816.             (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT),
  817.             MAX_DWNL_EBK_PATH_LEN);
  818.         pfnUnicodeStrncat(
  819.         (S8*) file_path,
  820.             (S8*) g_curr_book_cntx_p->g_nfo_book_struct.e_book_name,
  821.             MAX_DWNL_EBK_PATH_LEN - pfnUnicodeStrlen((S8*) file_path));
  822.     file_hnd = FS_Open((const WCHAR*)file_path, FS_READ_ONLY);
  823.     if (file_hnd <= 0)
  824.     {
  825.             pfnUnicodeStrncpy(
  826.                 (S8*) file_path,
  827.                 (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT),
  828.                 MAX_DWNL_EBK_PATH_LEN);
  829.             pfnUnicodeStrncat(
  830.             (S8*) file_path,
  831.                 (S8*) g_curr_book_cntx_p->g_nfo_book_struct.temp_file_name,
  832.                 MAX_DWNL_EBK_PATH_LEN - pfnUnicodeStrlen((S8*) file_path));
  833.         file_hnd = FS_Open((const WCHAR*)file_path, FS_READ_ONLY);
  834.         if (file_hnd >= 0)
  835.         {
  836.             FS_Close(file_hnd);
  837.             FS_Delete((const WCHAR*)file_path);
  838.         }
  839.         FS_Delete((const WCHAR*)nfo_path);
  840.     }
  841.     else
  842.     {
  843.         FS_Close(file_hnd);
  844.         if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_TXT)
  845.         {
  846.             nfo_id = ebr_fmgr_get_nfo_id_for_txt_file(
  847.                         g_curr_book_cntx_p->memory_type_selected,
  848.                         (S8*) g_curr_book_cntx_p->g_nfo_book_struct.e_book_name);
  849.         }
  850.         else
  851.         {
  852.             nfo_id = ebr_fmgr_get_nfo_id_for_pdb_file(
  853.                         g_curr_book_cntx_p->memory_type_selected,
  854.                         (S8*) g_curr_book_cntx_p->g_nfo_book_struct.e_book_name);
  855.         }
  856.             if (nfo_id <= 0 || (nfo_id != local_nfo_id))
  857.         {
  858.             FS_Delete((const WCHAR*)nfo_path);
  859.         }
  860.     }
  861.     }
  862.     else
  863.     {
  864.         FS_Delete((const WCHAR*)nfo_path);
  865.     }
  866. }
  867. /*****************************************************************************
  868.  * FUNCTION
  869.  *  ebr_frm_entry_refresh_book_shelf
  870.  * DESCRIPTION
  871.  *  Refresh the book Shelf
  872.  * PARAMETERS
  873.  *  void
  874.  * RETURNS
  875.  *  void
  876.  *****************************************************************************/
  877. void ebr_frm_entry_refresh_book_shelf(void)
  878. {
  879.     /*----------------------------------------------------------------*/
  880.     /* Local Variables                                                */
  881.     /*----------------------------------------------------------------*/
  882.     /*----------------------------------------------------------------*/
  883.     /* Code Body                                                      */
  884.     /*----------------------------------------------------------------*/
  885.     ebr_frm_delete_unused_nfo_file();
  886.     g_curr_book_cntx_p->ebr_frm_end_book_flag = 1;
  887.     g_curr_book_cntx_p->ebr_search_strlen = 0;
  888.     g_curr_book_cntx_p->highlight_string_flag = 0;
  889. }
  890. /*****************************************************************************
  891.  * FUNCTION
  892.  *  ebr_frm_get_total_countof_nfo_file
  893.  * DESCRIPTION
  894.  *  Get the total count for nfo files
  895.  * PARAMETERS
  896.  *  void
  897.  * RETURNS
  898.  *  S32 count
  899.  *****************************************************************************/
  900. S32 ebr_frm_get_total_countof_nfo_file()
  901. {
  902.     /*----------------------------------------------------------------*/
  903.     /* Local Variables                                                */
  904.     /*----------------------------------------------------------------*/
  905.     FS_HANDLE fh_cur;
  906.     FS_DOSDirEntry file_info;
  907.     UI_character_type filename[MAX_EBOOK_NAME_LENGTH];
  908.     U8 count = 0;
  909.     S8 path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
  910.     /*----------------------------------------------------------------*/
  911.     /* Code Body                                                      */
  912.     /*----------------------------------------------------------------*/
  913.     pfnUnicodeStrcpy(
  914.         (S8*) path,
  915.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_PDB));
  916.     if ((fh_cur = FS_FindFirst(
  917.                     (const WCHAR*)path,
  918.                     0,
  919.                     0,
  920.                     &file_info,
  921.                     (U16*) filename,
  922.                     MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH)) >= 0)
  923.     {
  924.         do
  925.         {
  926.             if (!(file_info.Attributes & FS_ATTR_DIR))
  927.             {
  928.                 count++;
  929.                 break;
  930.             }
  931.         } while ((FS_FindNext(fh_cur, &file_info, (U16*) filename, MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH) ==
  932.                   FS_NO_ERROR));
  933.         FS_FindClose(fh_cur);
  934.     }
  935.     if (count > 0)
  936.     {
  937.         return count;
  938.     }
  939.     else
  940.     {
  941.         pfnUnicodeStrcpy(
  942.             (S8*) path,
  943.             (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_TXT));
  944.         if ((fh_cur = FS_FindFirst(
  945.                         (const WCHAR*)path,
  946.                         0,
  947.                         0,
  948.                         &file_info,
  949.                         (U16*) filename,
  950.                         MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH)) >= 0)
  951.         {
  952.             do
  953.             {
  954.                 if (!(file_info.Attributes & FS_ATTR_DIR))
  955.                 {
  956.                     count++;
  957.                     break;
  958.                 }
  959.             } while ((FS_FindNext(fh_cur, &file_info, (U16*) filename, MAX_EBOOK_NAME_LENGTH * ENCODING_LENGTH) ==
  960.                       FS_NO_ERROR));
  961.             FS_FindClose(fh_cur);
  962.         }
  963.     }
  964.     return count;
  965. }
  966. /*****************************************************************************
  967.  * FUNCTION
  968.  *  ebr_frm_get_file_path
  969.  * DESCRIPTION
  970.  *  Get the file path
  971.  * PARAMETERS
  972.  *  memory_type_selected        [IN]        
  973.  *  search_type_path            [IN]        
  974.  * RETURNS
  975.  *  S32 count
  976.  *****************************************************************************/
  977. S8 *ebr_frm_get_file_path(S8 memory_type_selected, ebr_frm_search_type_enum search_type_path)
  978. {
  979.     /*----------------------------------------------------------------*/
  980.     /* Local Variables                                                */
  981.     /*----------------------------------------------------------------*/
  982.     S8 file_path_in_ascii[MAX_DWNL_EBK_PATH_LEN];
  983.     static S8 file_path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH];
  984.     static ebr_frm_search_type_enum prev_search_type_path = EBR_FRM_SEARCH_MAX;    
  985.     static S8 prev_memory_type_selected = 0;
  986.     /*----------------------------------------------------------------*/
  987.     /* Code Body                                                      */
  988.     /*----------------------------------------------------------------*/
  989.     if (prev_memory_type_selected == memory_type_selected && prev_search_type_path == search_type_path)
  990.     {
  991.         return file_path;
  992.     }
  993.     switch (search_type_path)
  994.     {
  995.         case EBR_FRM_SEARCH_NFO:
  996.             sprintf((char*)file_path_in_ascii, "%c%s%s", memory_type_selected, EBR_DOWNLOADED_EBOOK_PATH, EBR_EBOOK_SEARCH_NFO_STR);
  997.             break;
  998.         case EBR_FRM_SEARCH_PDB:
  999.             sprintf((char*)file_path_in_ascii, "%c%s%s", memory_type_selected, EBR_DOWNLOADED_EBOOK_PATH, EBR_EBOOK_SEARCH_PDB_STR);
  1000.             break;
  1001.         case EBR_FRM_SEARCH_TXT:
  1002.             sprintf((char*)file_path_in_ascii, "%c%s%s", memory_type_selected, EBR_DOWNLOADED_EBOOK_PATH, EBR_EBOOK_SEARCH_TXT_STR);
  1003.             break;
  1004.         case EBR_FRM_SEARCH_TXZ:
  1005.             sprintf((char*)file_path_in_ascii, "%c%s%s", memory_type_selected, EBR_DOWNLOADED_EBOOK_PATH, EBR_EBOOK_SEARCH_TXZ_STR);
  1006.             break;
  1007.         case EBR_FRM_SEARCH_PBZ:
  1008.             sprintf((char*)file_path_in_ascii, "%c%s%s", memory_type_selected, EBR_DOWNLOADED_EBOOK_PATH, EBR_EBOOK_SEARCH_PBZ_STR);
  1009.             break;
  1010.         default:
  1011.             sprintf((char*)file_path_in_ascii, "%c%s", memory_type_selected, EBR_DOWNLOADED_EBOOK_PATH);
  1012.             break;
  1013.     }
  1014.     AnsiiToUnicodeString((PS8) file_path, file_path_in_ascii);
  1015.     prev_memory_type_selected = memory_type_selected;
  1016.     prev_search_type_path = search_type_path;
  1017.     return file_path;
  1018. }
  1019. /*****************************************************************************
  1020.  * FUNCTION
  1021.  *  ebr_frm_get_path_for_bookshelf
  1022.  * DESCRIPTION
  1023.  *  Get the book shelf path
  1024.  * PARAMETERS
  1025.  *  void
  1026.  * RETURNS
  1027.  *  S32 count
  1028.  *****************************************************************************/
  1029. S8 *ebr_frm_get_path_for_bookshelf(void)
  1030. {
  1031.     /*----------------------------------------------------------------*/
  1032.     /* Local Variables                                                */
  1033.     /*----------------------------------------------------------------*/
  1034.     /*----------------------------------------------------------------*/
  1035.     /* Code Body                                                      */
  1036.     /*----------------------------------------------------------------*/
  1037.     return ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT);
  1038. }
  1039. /*****************************************************************************
  1040.  * FUNCTION
  1041.  *  ebr_frm_set_number_of_records
  1042.  * DESCRIPTION
  1043.  *  Set number of records
  1044.  * PARAMETERS
  1045.  *  void
  1046.  * RETURNS
  1047.  *  void
  1048.  *****************************************************************************/
  1049. void ebr_frm_set_number_of_records(void)
  1050. {
  1051.     /*----------------------------------------------------------------*/
  1052.     /* Local Variables                                                */
  1053.     /*----------------------------------------------------------------*/
  1054.     /*----------------------------------------------------------------*/
  1055.     /* Code Body                                                      */
  1056.     /*----------------------------------------------------------------*/
  1057.     if (g_curr_book_cntx_p->g_nfo_book_struct.book_size % EBR_RECORD_SIZE_MAX == 0)
  1058.     {
  1059.         g_curr_book_cntx_p->num_records = g_curr_book_cntx_p->g_nfo_book_struct.book_size / EBR_RECORD_SIZE_MAX;
  1060.     }
  1061.     else
  1062.     {
  1063.         g_curr_book_cntx_p->num_records = g_curr_book_cntx_p->g_nfo_book_struct.book_size / EBR_RECORD_SIZE_MAX + 1;
  1064.     }
  1065. }
  1066. /*****************************************************************************
  1067.  * FUNCTION
  1068.  *  ebr_frm_set_temp_number_of_records
  1069.  * DESCRIPTION
  1070.  *  
  1071.  * PARAMETERS
  1072.  *  void
  1073.  * RETURNS
  1074.  *  void
  1075.  *****************************************************************************/
  1076. void ebr_frm_set_temp_number_of_records(void)
  1077. {
  1078.     /*----------------------------------------------------------------*/
  1079.     /* Local Variables                                                */
  1080.     /*----------------------------------------------------------------*/
  1081.     /*----------------------------------------------------------------*/
  1082.     /* Code Body                                                      */
  1083.     /*----------------------------------------------------------------*/
  1084.     if (g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size % EBR_RECORD_SIZE_MAX == 0)
  1085.     {
  1086.         g_curr_book_cntx_p->num_records = g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size / EBR_RECORD_SIZE_MAX;
  1087.     }
  1088.     else
  1089.     {
  1090.         g_curr_book_cntx_p->num_records =
  1091.             g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size / EBR_RECORD_SIZE_MAX + 1;
  1092.     }
  1093. }
  1094. /*****************************************************************************
  1095.  * FUNCTION
  1096.  *  copy_record_in_passed_buffer
  1097.  * DESCRIPTION
  1098.  *  Copy the data in previous buffer
  1099.  * PARAMETERS
  1100.  *  file_hnd            [IN]        
  1101.  *  record_id           [IN]        
  1102.  *  output_buffer       [IN]        
  1103.  *  input_buffer        [IN]        
  1104.  *  size                [IN]        
  1105.  * RETURNS
  1106.  *  void
  1107.  *****************************************************************************/
  1108. void copy_record_in_passed_buffer(FS_HANDLE file_hnd, S32 record_id, U8 *output_buffer, U8 *input_buffer, U32 *size)
  1109. {
  1110.     /*----------------------------------------------------------------*/
  1111.     /* Local Variables                                                */
  1112.     /*----------------------------------------------------------------*/
  1113.     S32 rec_size;
  1114.     S32 offset;
  1115.     /*----------------------------------------------------------------*/
  1116.     /* Code Body                                                      */
  1117.     /*----------------------------------------------------------------*/
  1118.     if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_TXT || g_curr_book_cntx_p->book_is_in_other_encoding_format)
  1119.     {
  1120.         rec_size = ebr_frm_get_record_size_txt(record_id);
  1121.         if (record_id >= 1) /* first record */
  1122.         {
  1123.             record_id -= 1;
  1124.         }
  1125.         FS_Seek(file_hnd, (record_id) * EBR_RECORD_SIZE_MAX, FS_FILE_BEGIN);
  1126.         FS_Read(file_hnd, g_curr_book_cntx_p->buffer, rec_size, size);
  1127.     }
  1128.     else
  1129.     {
  1130.         SEEK_REC_ENTRY(file_hnd, record_id);
  1131.         if (FS_Read(file_hnd, &offset, 4, size) == FS_NO_ERROR)
  1132.         {
  1133.             offset = ntohl(offset);
  1134.         }
  1135.         rec_size = ebr_frm_get_record_size_pdb(file_hnd, offset, record_id);
  1136.         FS_Seek(file_hnd, offset, FS_FILE_BEGIN);
  1137.         FS_Read(file_hnd, input_buffer, rec_size, size);
  1138.         ebr_frm_start_decompression(output_buffer, input_buffer, size);
  1139.     }
  1140. }
  1141. /*****************************************************************************
  1142.  * FUNCTION
  1143.  *  copy_record_in_buffer
  1144.  * DESCRIPTION
  1145.  *  Copy the data in current buffer
  1146.  * PARAMETERS
  1147.  *  file_hnd        [IN]        
  1148.  *  record_id       [IN]        
  1149.  *  copy_type       [IN]        
  1150.  * RETURNS
  1151.  *  void
  1152.  *****************************************************************************/
  1153. void copy_record_in_buffer(FS_HANDLE file_hnd, S32 record_id, ebr_frm_copy_type_enum copy_type)
  1154. {
  1155.     /*----------------------------------------------------------------*/
  1156.     /* Local Variables                                                */
  1157.     /*----------------------------------------------------------------*/
  1158.     S32 rec_size;
  1159.     S32 offset;
  1160.     S32 size;
  1161.     /*----------------------------------------------------------------*/
  1162.     /* Code Body                                                      */
  1163.     /*----------------------------------------------------------------*/
  1164.     if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_TXT || g_curr_book_cntx_p->pdb_converted_to_text)
  1165.     {
  1166.         switch (copy_type)
  1167.         {
  1168.             case EBR_FRM_COPY_TYPE_FIRST:
  1169.                 memset(g_curr_book_cntx_p->start, 0, EBR_RECORD_SIZE_MAX * 2);
  1170.                 offset = 0;
  1171.                 break;
  1172.             case EBR_FRM_COPY_TYPE_SECOND:
  1173.                 memset(g_curr_book_cntx_p->start + EBR_RECORD_SIZE_MAX, 0, EBR_RECORD_SIZE_MAX);
  1174.                 offset = EBR_RECORD_SIZE_MAX;
  1175.                 break;
  1176.             case EBR_FRM_COPY_TYPE_NEXT:
  1177.                 memcpy(g_curr_book_cntx_p->start, g_curr_book_cntx_p->start + EBR_RECORD_SIZE_MAX, EBR_RECORD_SIZE_MAX);
  1178.                 /* pfnUnicodeStrcpy((PS8)g_curr_book_cntx_p->start,(PS8)g_curr_book_cntx_p->start+EBR_RECORD_SIZE_MAX); */
  1179.                 memset(g_curr_book_cntx_p->start + EBR_RECORD_SIZE_MAX, 0, EBR_RECORD_SIZE_MAX);
  1180.                 offset = EBR_RECORD_SIZE_MAX;
  1181.                 break;
  1182.             case EBR_FRM_COPY_TYPE_PREVIOUS:
  1183.                 memcpy(g_curr_book_cntx_p->start + EBR_RECORD_SIZE_MAX, g_curr_book_cntx_p->start, EBR_RECORD_SIZE_MAX);
  1184.                 memset(g_curr_book_cntx_p->start, 0, EBR_RECORD_SIZE_MAX);
  1185.                 offset = 0;
  1186.                 break;
  1187.         }
  1188.         rec_size = ebr_frm_get_record_size_txt(record_id);
  1189.         FS_Seek(file_hnd, (record_id - 1) * EBR_RECORD_SIZE_MAX, FS_FILE_BEGIN);
  1190.         FS_Read(file_hnd, g_curr_book_cntx_p->start + offset, rec_size, (U32*) & size);
  1191.     }
  1192.     else
  1193.     {
  1194.         SEEK_REC_ENTRY(file_hnd, record_id);
  1195.         if (FS_Read(file_hnd, &offset, 4, (U32*) & size) == FS_NO_ERROR)
  1196.         {
  1197.             offset = ntohl(offset);
  1198.         }
  1199.         rec_size = ebr_frm_get_record_size_pdb(file_hnd, offset, record_id);
  1200.         if (rec_size < 0 || (rec_size > EBR_RECORD_SIZE_MAX))
  1201.         {
  1202.             g_curr_book_cntx_p->is_in_valid = TRUE;
  1203.         }
  1204.         else
  1205.         {
  1206.             if (FS_Seek(file_hnd, offset, FS_FILE_BEGIN) != FS_INVALID_FILE_POS)
  1207.             {
  1208.         FS_Read(file_hnd, &g_curr_book_cntx_p->buffer, rec_size, (U32*) & size);
  1209.         ebr_frm_decompress_pdb((U8*) g_curr_book_cntx_p->buffer, (U32*) & size, copy_type);
  1210.     }
  1211.             else
  1212.             {
  1213.                 g_curr_book_cntx_p->is_in_valid = TRUE;
  1214.                 g_curr_book_cntx_p->gcurrent_record_id = g_curr_book_cntx_p->num_records;
  1215.             }
  1216.         }
  1217.     }
  1218. }
  1219. #ifdef __MMI_TOUCH_SCREEN__
  1220. /*****************************************************************************
  1221.  * FUNCTION
  1222.  *  ebr_frm_get_data_during_scrolling
  1223.  * DESCRIPTION
  1224.  *  Copy the data in buffer_local during scrolling
  1225.  * PARAMETERS
  1226.  *  page_id             [IN]        
  1227.  *  buffer_local        [IN]        
  1228.  * RETURNS
  1229.  *  void
  1230.  *****************************************************************************/
  1231. void ebr_frm_get_data_during_scrolling(S32 percentage_val,PU8 buffer_local)
  1232. {
  1233. S8 display_name[(MAX_EBOOK_NAME_LENGTH + 1) * ENCODING_LENGTH];
  1234. gui_page_info_app ebook_frm_setting;
  1235. if(percentage_val==100)
  1236. {
  1237. ebr_frm_jump_to_record(0,EBR_JUMP_END); 
  1238. /* Here 0 is being passed as percentage value reason being ,Ebook application consider jump to end case 
  1239.  when percentage value is 0 : During dragging of scrollbar to reach to end of the book,it is being added*/
  1240. }
  1241. else
  1242. {
  1243. ebr_frm_jump_to_record(percentage_val,EBR_JUMP_PERCENTAGE);
  1244. }
  1245. ebr_frm_get_data_to_open_book(&ebook_frm_setting,buffer_local, display_name);
  1246. wgui_paging_set_page_info(&ebook_frm_setting);
  1247. }
  1248. #endif /* __MMI_TOUCH_SCREEN__ */ 
  1249. /*****************************************************************************
  1250.  * FUNCTION
  1251.  *  ebr_frm_decode_header
  1252.  * DESCRIPTION
  1253.  *  Get the File Header for PDB and Footer for TXT file
  1254.  * PARAMETERS
  1255.  *  ebook_file_name     [IN]        
  1256.  * RETURNS
  1257.  *  S16 error_type
  1258.  *****************************************************************************/
  1259. S16 ebr_frm_decode_header(U8 *ebook_file_name)
  1260. {
  1261.     /*----------------------------------------------------------------*/
  1262.     /* Local Variables                                                */
  1263.     /*----------------------------------------------------------------*/
  1264.     FILE_HANDLE file_hnd;
  1265.     S16 ebr_page_size;
  1266.     S32 book_size = 0;
  1267.     //      FS_DiskInfo disk_info;
  1268.     //      S32 fs_ret;
  1269.     S8 file_path_in_ascii[5];
  1270.     S8 file_path[10];
  1271.     /*----------------------------------------------------------------*/
  1272.     /* Code Body                                                      */
  1273.     /*----------------------------------------------------------------*/
  1274.     //      U64 disk_free_space;
  1275.     //  U64 disk_total_space;
  1276.     if (g_curr_book_cntx_p->is_book_in_unicode || g_curr_book_cntx_p->book_is_in_other_encoding_format)
  1277.     {
  1278.         ebr_page_size = EBR_PAGE_SIZE * 2;
  1279.     }
  1280.     else
  1281.     {
  1282.         ebr_page_size = EBR_PAGE_SIZE;
  1283.     }
  1284.     file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->book_name_path, FS_READ_ONLY);
  1285.     if (file_hnd <= 0)
  1286.     {
  1287.         return -1;
  1288.     }
  1289.     if (g_curr_book_cntx_p->book_is_in_other_encoding_format)
  1290.     {
  1291.         /* Create a new file in Unicode and change the book_size */
  1292.         S32 status;
  1293.         sprintf((char*)file_path_in_ascii, "%c", g_curr_book_cntx_p->memory_type_selected);
  1294.         strcat((char*)file_path_in_ascii, ":\");
  1295.         AnsiiToUnicodeString((PS8) file_path, file_path_in_ascii);
  1296.         status = ebr_frm_create_temp_file_in_ucs2(file_hnd);
  1297.         if (status == 0)
  1298.         {
  1299.             FS_Close(file_hnd);
  1300.             return 0;
  1301.         }
  1302.         else if (status == 1)
  1303.         {
  1304.             return 1;
  1305.         }
  1306.         else if (status == 2)
  1307.         {
  1308.             ebr_frm_set_temp_number_of_records();
  1309.             FS_Close(file_hnd);
  1310.             file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path, FS_READ_ONLY);
  1311. book_size = g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size;
  1312.         }
  1313.     }
  1314.     else
  1315.     {
  1316.         ebr_frm_set_number_of_records();
  1317.         ebr_frm_delete_temp_file();
  1318. book_size = g_curr_book_cntx_p->g_nfo_book_struct.book_size;
  1319.     }
  1320.     if (!g_curr_book_cntx_p->ebr_frm_end_book_flag ||
  1321.         (g_curr_book_cntx_p->g_nfo_book_struct.current_page_id + 4) * ebr_page_size >= (U32) book_size)
  1322.     {
  1323.         if (book_size > EBR_RECORD_SIZE_MAX)
  1324.         {
  1325.             g_curr_book_cntx_p->gcurrent_record_id = g_curr_book_cntx_p->num_records - 1;
  1326.             g_curr_book_cntx_p->gnext_record_id = g_curr_book_cntx_p->gcurrent_record_id + 1;
  1327.         }
  1328.         else
  1329.         {
  1330.             g_curr_book_cntx_p->gcurrent_record_id =
  1331.                 g_curr_book_cntx_p->g_start_id / (EBR_RECORD_SIZE_MAX / ebr_page_size) + 1;
  1332.             g_curr_book_cntx_p->gnext_record_id = g_curr_book_cntx_p->gcurrent_record_id + 1;
  1333.         }
  1334.     }
  1335.     else
  1336.     {
  1337.         g_curr_book_cntx_p->gcurrent_record_id =
  1338.             g_curr_book_cntx_p->g_start_id / (EBR_RECORD_SIZE_MAX / ebr_page_size) + 1;
  1339.         g_curr_book_cntx_p->gnext_record_id = g_curr_book_cntx_p->gcurrent_record_id + 1;
  1340.     }
  1341.     copy_record_in_buffer(file_hnd, g_curr_book_cntx_p->gcurrent_record_id, EBR_FRM_COPY_TYPE_FIRST);
  1342. if(g_curr_book_cntx_p->book_is_in_other_encoding_format)
  1343. {
  1344. if(g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size>EBR_RECORD_SIZE_MAX)
  1345. {
  1346. copy_record_in_buffer(file_hnd, g_curr_book_cntx_p->gnext_record_id, EBR_FRM_COPY_TYPE_SECOND);
  1347. }
  1348. }
  1349. else
  1350. {
  1351. if(g_curr_book_cntx_p->g_nfo_book_struct.book_size>EBR_RECORD_SIZE_MAX)
  1352. {
  1353.     copy_record_in_buffer(file_hnd, g_curr_book_cntx_p->gnext_record_id, EBR_FRM_COPY_TYPE_SECOND);
  1354. }
  1355. }
  1356.     FS_Close(file_hnd);
  1357.     if (g_curr_book_cntx_p->is_in_valid)
  1358.     {
  1359.         g_curr_book_cntx_p->is_in_valid = FALSE;
  1360.         return 2;
  1361.     }
  1362.     return 1;
  1363. }
  1364. /*****************************************************************************
  1365.  * FUNCTION
  1366.  *  ebr_frm_delete_temp_file
  1367.  * DESCRIPTION
  1368.  *  Get the record size for text file.
  1369.  * PARAMETERS
  1370.  *  void
  1371.  * RETURNS
  1372.  *  void
  1373.  *****************************************************************************/
  1374. void ebr_frm_delete_temp_file(void)
  1375. {
  1376.     /*----------------------------------------------------------------*/
  1377.     /* Local Variables                                                */
  1378.     /*----------------------------------------------------------------*/
  1379.     pBOOL is_temp_file_present;
  1380.     /*----------------------------------------------------------------*/
  1381.     /* Code Body                                                      */
  1382.     /*----------------------------------------------------------------*/
  1383.     ebr_frm_create_temp_file_path();
  1384.     is_temp_file_present = ebr_frm_check_if_file_exists_or_not();
  1385.     if (is_temp_file_present)
  1386.     {
  1387.         FS_Delete((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path);
  1388.     }
  1389. }
  1390. /*****************************************************************************
  1391.  * FUNCTION
  1392.  *  ebr_frm_get_current_recursive_conversion_state
  1393.  * DESCRIPTION
  1394.  *  Get the current conversion state.
  1395.  * PARAMETERS
  1396.  *  void
  1397.  * RETURNS
  1398.  *  void
  1399.  *****************************************************************************/
  1400. S32 ebr_frm_get_current_recursive_conversion_state(void)
  1401. {
  1402.     /*----------------------------------------------------------------*/
  1403.     /* Local Variables                                                */
  1404.     /*----------------------------------------------------------------*/
  1405.     /*----------------------------------------------------------------*/
  1406.     /* Code Body                                                      */
  1407.     /*----------------------------------------------------------------*/
  1408.     return g_curr_book_cntx_p->state_recursive_conversion;
  1409. }
  1410. /*****************************************************************************
  1411.  * FUNCTION
  1412.  *  ebr_frm_set_current_recursive_conversion_state
  1413.  * DESCRIPTION
  1414.  *  Set the current conversion state.
  1415.  * PARAMETERS
  1416.  *  state       [IN]        
  1417.  * RETURNS
  1418.  *  void
  1419.  *****************************************************************************/
  1420. void ebr_frm_set_current_recursive_conversion_state(S32 state)
  1421. {
  1422.     /*----------------------------------------------------------------*/
  1423.     /* Local Variables                                                */
  1424.     /*----------------------------------------------------------------*/
  1425.     /*----------------------------------------------------------------*/
  1426.     /* Code Body                                                      */
  1427.     /*----------------------------------------------------------------*/
  1428.     g_curr_book_cntx_p->state_recursive_conversion = state;
  1429. }
  1430. /*****************************************************************************
  1431.  * FUNCTION
  1432.  *  ebr_frm_register_recursive_callback_fn
  1433.  * DESCRIPTION
  1434.  *  Reister Function for Recursive callback
  1435.  * PARAMETERS
  1436.  *  fn      [IN]        
  1437.  *  void (*fn)(?)
  1438.  * RETURNS
  1439.  *  void
  1440.  *****************************************************************************/
  1441. void ebr_frm_register_recursive_callback_fn(void (*fn) (void))
  1442. {
  1443.     /*----------------------------------------------------------------*/
  1444.     /* Local Variables                                                */
  1445.     /*----------------------------------------------------------------*/
  1446.     /*----------------------------------------------------------------*/
  1447.     /* Code Body                                                      */
  1448.     /*----------------------------------------------------------------*/
  1449.     g_curr_book_cntx_p->g_recursive_callback_fn = fn;
  1450. }
  1451. /*****************************************************************************
  1452.  * FUNCTION
  1453.  *  ebr_frm_stop_recursion
  1454.  * DESCRIPTION
  1455.  *  Stop the timer for Recursive callback
  1456.  * PARAMETERS
  1457.  *  void
  1458.  * RETURNS
  1459.  *  void
  1460.  *****************************************************************************/
  1461. void ebr_frm_stop_recursion(void)
  1462. {
  1463.     /*----------------------------------------------------------------*/
  1464.     /* Local Variables                                                */
  1465.     /*----------------------------------------------------------------*/
  1466.     /*----------------------------------------------------------------*/
  1467.     /* Code Body                                                      */
  1468.     /*----------------------------------------------------------------*/
  1469.     StopTimer(EBOOK_RECURSIVE_TIMER);
  1470. }
  1471. /*****************************************************************************
  1472.  * FUNCTION
  1473.  *  ebr_frm_convert_record
  1474.  * DESCRIPTION
  1475.  *  Convert the record and write in temp file
  1476.  * PARAMETERS
  1477.  *  file_hnd            [IN]        
  1478.  *  new_file_hnd        [IN]        
  1479.  *  record_id           [IN]        
  1480.  * RETURNS
  1481.  *  void
  1482.  *****************************************************************************/
  1483. void ebr_frm_convert_record(FILE_HANDLE file_hnd, FILE_HANDLE new_file_hnd, S32 record_id)
  1484. {
  1485.     /*----------------------------------------------------------------*/
  1486.     /* Local Variables                                                */
  1487.     /*----------------------------------------------------------------*/
  1488.     S32 rec_size = 0;
  1489.     S32 total_bytes_converted = 0;
  1490.     S32 offset = 0;
  1491.     S32 size = 0;
  1492.     U32 static over_the_record_border = 0;
  1493.     S32 converted_str_len;
  1494.     U8 mmiEncoding = mmi_ebook_util_get_chset(g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format);
  1495.     /*----------------------------------------------------------------*/
  1496.     /* Code Body                                                      */
  1497.     /*----------------------------------------------------------------*/
  1498.     if (record_id == 1)
  1499.     {
  1500.         over_the_record_border = 0;
  1501.     }
  1502.     if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_TXT)
  1503.     {
  1504.         rec_size = ebr_frm_create_temp_file_txt(record_id) - over_the_record_border;
  1505.         if (rec_size > EBR_RECORD_SIZE_MAX)
  1506.         {
  1507.             rec_size = EBR_RECORD_SIZE_MAX;
  1508.             over_the_record_border = 0;
  1509.         }
  1510.         memset(g_curr_book_cntx_p->buffer, 0, sizeof(g_curr_book_cntx_p->buffer));
  1511.         FS_Read(file_hnd, g_curr_book_cntx_p->buffer, rec_size, (U32*) & size);
  1512.         memset(g_curr_book_cntx_p->start, 0, sizeof(g_curr_book_cntx_p->start));
  1513.         mmi_chset_use_space_for_unknown_character();
  1514.         switch (mmiEncoding)
  1515.         {
  1516.         #if defined(MMI_ON_HARDWARE_P) && defined(__MMI_CHSET_BIG5__)
  1517.             case MMI_CHSET_BIG5:
  1518.                 total_bytes_converted = ebr_frm_mmi_chset_text_to_ucs2_str(
  1519.                                             file_hnd,
  1520.                                             (U8*) g_curr_book_cntx_p->start,
  1521.                                             EBR_RECORD_SIZE_MAX * 2 + 10,
  1522.                                             (U8*) g_curr_book_cntx_p->buffer,
  1523.                                             (S16) size,
  1524.                                             BIG_5_ENCODING_TYPE,
  1525.                                             &over_the_record_border);
  1526.                 break;
  1527.         #endif /* defined(MMI_ON_HARDWARE_P) && defined(__MMI_CHSET_BIG5__) */ 
  1528.         #if defined(MMI_ON_HARDWARE_P) && defined(__MMI_CHSET_GB2312__)
  1529.             case MMI_CHSET_GB2312:
  1530.                 total_bytes_converted = ebr_frm_mmi_chset_text_to_ucs2_str(
  1531.                                             file_hnd,
  1532.                                             (U8*) g_curr_book_cntx_p->start,
  1533.                                             EBR_RECORD_SIZE_MAX * 2 + 10,
  1534.                                             (U8*) g_curr_book_cntx_p->buffer,
  1535.                                             (S16) size,
  1536.                                             GB2312_ENCODING_TYPE,
  1537.                                             &over_the_record_border);
  1538.                 break;
  1539.         #endif /* defined(MMI_ON_HARDWARE_P) && defined(__MMI_CHSET_GB2312__) */ 
  1540.         #if defined(MMI_ON_HARDWARE_P)
  1541.             case MMI_CHSET_UTF8:
  1542.                 total_bytes_converted = ebr_frm_mmi_chset_utf8_to_ucs2_string(
  1543.                                             file_hnd,
  1544.                                             (U8*) g_curr_book_cntx_p->start,
  1545.                                             EBR_RECORD_SIZE_MAX * 2 + 10,
  1546.                                             (U8*) g_curr_book_cntx_p->buffer,
  1547.                                             (S16) size,
  1548.                                             &over_the_record_border);
  1549.                 break;
  1550.         #endif /* defined(MMI_ON_HARDWARE_P) */ 
  1551.             default:
  1552.                 total_bytes_converted = mmi_chset_convert(
  1553.                                             (mmi_chset_enum) mmiEncoding,
  1554.                                             MMI_CHSET_UCS2,
  1555.                                             (S8*) g_curr_book_cntx_p->buffer,
  1556.                                             (S8*) g_curr_book_cntx_p->start,
  1557.                                             EBR_RECORD_SIZE_MAX * 2 + 10);
  1558.                 break;
  1559.         }
  1560.         mmi_chset_do_not_use_space_for_unknown_character();
  1561.         converted_str_len = pfnUnicodeStrlen((S8*) g_curr_book_cntx_p->start);
  1562.         if (converted_str_len != (total_bytes_converted - 2) / 2)
  1563.         {
  1564.             g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
  1565.             FS_Write(new_file_hnd, g_curr_book_cntx_p->start, (converted_str_len * 2) + 2, (U32*) & size);
  1566.         }
  1567.         else if (mmiEncoding == MMI_CHSET_UTF8 && (total_bytes_converted - 2) < (size / 2))
  1568.         {
  1569.             g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
  1570.             FS_Write(new_file_hnd, g_curr_book_cntx_p->start, (converted_str_len * 2) + 2, (U32*) & size);
  1571.         }
  1572.     #ifdef __MMI_CHSET_BIG5__
  1573.         else if (mmiEncoding == MMI_CHSET_BIG5 && (total_bytes_converted - 2) < (size))
  1574.         {
  1575.             g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
  1576.             FS_Write(new_file_hnd, g_curr_book_cntx_p->start, (converted_str_len * 2) + 2, (U32*) & size);
  1577.         }
  1578.     #endif /* __MMI_CHSET_BIG5__ */ 
  1579.     #ifdef __MMI_CHSET_GB2312__
  1580.         else if (mmiEncoding == MMI_CHSET_GB2312 && (total_bytes_converted - 2) < (size))
  1581.         {
  1582.             g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
  1583.             FS_Write(new_file_hnd, g_curr_book_cntx_p->start, (converted_str_len * 2) + 2, (U32*) & size);
  1584.         }
  1585.     #endif /* __MMI_CHSET_GB2312__ */ 
  1586.         else if (record_id == g_curr_book_cntx_p->num_records)
  1587.         {
  1588.             FS_Write(new_file_hnd, g_curr_book_cntx_p->start, total_bytes_converted, (U32*) & size);
  1589.         }
  1590.         else
  1591.         {
  1592.             FS_Write(new_file_hnd, g_curr_book_cntx_p->start, total_bytes_converted - 2, (U32*) & size);
  1593.         }
  1594.     }
  1595.     else
  1596.     {
  1597.         memset(g_curr_book_cntx_p->start, 0, sizeof(g_curr_book_cntx_p->start));
  1598.         g_curr_book_cntx_p->pdb_converted_to_text = TRUE;
  1599.         SEEK_REC_ENTRY(file_hnd, record_id);
  1600.         if (FS_Read(file_hnd, &offset, 4, (U32*) & size) == FS_NO_ERROR)
  1601.         {
  1602.             offset = ntohl(offset);
  1603.         }
  1604.         rec_size = ebr_frm_get_record_size_pdb(file_hnd, offset, record_id);
  1605.         if (rec_size < 0 || (rec_size > EBR_RECORD_SIZE_MAX))
  1606.         {
  1607.             g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
  1608.             return;
  1609.         }
  1610.         if (FS_Seek(file_hnd, offset, FS_FILE_BEGIN) != FS_INVALID_FILE_POS)
  1611.         {
  1612.         FS_Read(file_hnd, g_curr_book_cntx_p->for_unicode_buffer, rec_size, (U32*) & size);
  1613.         }
  1614.         else
  1615.         {
  1616.             g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
  1617.             return;
  1618.         }
  1619.         if (size <= 0)
  1620.         {
  1621.             g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
  1622.             return;
  1623.         }
  1624.         ebr_frm_start_decompression(g_curr_book_cntx_p->buffer, g_curr_book_cntx_p->for_unicode_buffer, (U32*) & size);
  1625.         mmi_chset_use_space_for_unknown_character();
  1626.         total_bytes_converted = mmi_chset_convert(
  1627.                                     (mmi_chset_enum) mmiEncoding,
  1628.                                     MMI_CHSET_UCS2,
  1629.                                     (char*)g_curr_book_cntx_p->buffer,
  1630.                                     (char*)g_curr_book_cntx_p->start,
  1631.                                     EBR_RECORD_SIZE_MAX * 2 + 10);
  1632.         mmi_chset_do_not_use_space_for_unknown_character();
  1633.         converted_str_len = pfnUnicodeStrlen((S8*) g_curr_book_cntx_p->start);
  1634.         if (converted_str_len != (total_bytes_converted - 2) / 2)
  1635.         {
  1636.             g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
  1637.             FS_Write(new_file_hnd, g_curr_book_cntx_p->start, (converted_str_len * 2) + 2, (U32*) & size);
  1638.         }
  1639.         else if (mmiEncoding == MMI_CHSET_UTF8 && (total_bytes_converted - 2) < (size / 2))
  1640.         {
  1641.             g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
  1642.             FS_Write(new_file_hnd, g_curr_book_cntx_p->start, (converted_str_len * 2) + 2, (U32*) & size);
  1643.         }
  1644.     #ifdef __MMI_CHSET_BIG5__
  1645.         else if (mmiEncoding == MMI_CHSET_BIG5 && (total_bytes_converted - 2) < (size))
  1646.         {
  1647.             g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
  1648.             FS_Write(new_file_hnd, g_curr_book_cntx_p->start, (converted_str_len * 2) + 2, (U32*) & size);
  1649.         }
  1650.     #endif /* __MMI_CHSET_BIG5__ */ 
  1651.     #ifdef __MMI_CHSET_GB2312__
  1652.         else if (mmiEncoding == MMI_CHSET_GB2312 && (total_bytes_converted - 2) < (size))
  1653.         {
  1654.             g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
  1655.             FS_Write(new_file_hnd, g_curr_book_cntx_p->start, (converted_str_len * 2) + 2, (U32*) & size);
  1656.         }
  1657.     #endif /* __MMI_CHSET_GB2312__ */ 
  1658.         if (record_id == g_curr_book_cntx_p->num_records)
  1659.         {
  1660.             FS_Write(new_file_hnd, g_curr_book_cntx_p->start, total_bytes_converted, (U32*) & size);
  1661.         }
  1662.         else
  1663.         {
  1664.             memset(g_curr_book_cntx_p->buffer, 0, sizeof(g_curr_book_cntx_p->buffer));
  1665.             FS_Write(new_file_hnd, g_curr_book_cntx_p->start, total_bytes_converted - 2, (U32*) & size);
  1666.         }
  1667.     }
  1668. }
  1669. /*****************************************************************************
  1670.  * FUNCTION
  1671.  *  ebr_frm_convert_record_record_recursively
  1672.  * DESCRIPTION
  1673.  *  Convert record recursively
  1674.  * PARAMETERS
  1675.  *  void
  1676.  * RETURNS
  1677.  *  void
  1678.  *****************************************************************************/
  1679. void ebr_frm_convert_record_record_recursively(void)
  1680. {
  1681.     /*----------------------------------------------------------------*/
  1682.     /* Local Variables                                                */
  1683.     /*----------------------------------------------------------------*/
  1684.     U32 size;
  1685.     static U32 failure_count = 0;
  1686.     /*----------------------------------------------------------------*/
  1687.     /* Code Body                                                      */
  1688.     /*----------------------------------------------------------------*/
  1689.     StopTimer(EBOOK_RECURSIVE_TIMER);
  1690.     if (g_curr_book_cntx_p->g_record_id <= g_curr_book_cntx_p->num_records)
  1691.     {
  1692.         FILE_HANDLE file_hnd, new_file_hnd;
  1693.         file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->book_name_path, FS_READ_ONLY);
  1694.         if (g_curr_book_cntx_p->g_record_id == 1)
  1695.         {
  1696.             new_file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path, FS_CREATE_ALWAYS | FS_ATTR_HIDDEN);
  1697.             failure_count = 0;
  1698.         }
  1699.         else
  1700.         {
  1701.             new_file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path, FS_READ_WRITE);
  1702.             if (file_hnd > 0)
  1703.             {
  1704.                 FS_Seek(file_hnd, g_curr_book_cntx_p->g_file_hnd_offset, FS_FILE_BEGIN);
  1705.             }
  1706.             if (new_file_hnd > 0)
  1707.             {
  1708.                 FS_Seek(new_file_hnd, 0, FS_FILE_END);
  1709.             }
  1710.         }
  1711.         if (new_file_hnd > 0 && file_hnd > 0)
  1712.         {
  1713.             S32 count = 0;
  1714.             while (count < MAX_RECORD_CONVERT_EACH_RECURSION)
  1715.             {
  1716.                 ebr_frm_convert_record(file_hnd, new_file_hnd, g_curr_book_cntx_p->g_record_id);
  1717.                 g_curr_book_cntx_p->g_record_id++;
  1718.                 count++;
  1719.                 if (g_curr_book_cntx_p->g_record_id > g_curr_book_cntx_p->num_records)
  1720.                 {
  1721.                     break;
  1722.                 }
  1723.             }
  1724.             g_curr_book_cntx_p->g_file_hnd_offset = FS_Seek(file_hnd, 0, FS_FILE_CURRENT);
  1725.             failure_count = 0;
  1726.         }
  1727.         else
  1728.         {
  1729.             failure_count++;
  1730.             if (failure_count == MAX_FAILURE_RETRIES)
  1731.             {
  1732.                 g_curr_book_cntx_p->g_record_id = g_curr_book_cntx_p->num_records;
  1733.             }
  1734.         }
  1735.         if (file_hnd > 0)
  1736.         {
  1737.             FS_Close(file_hnd);
  1738.         }
  1739.         if (new_file_hnd > 0)
  1740.         {
  1741.             FS_Close(new_file_hnd);
  1742.         }
  1743. if(file_hnd>0)
  1744. {
  1745.         if (g_curr_book_cntx_p->g_record_id > g_curr_book_cntx_p->num_records)
  1746.         {
  1747.             StartTimer(EBOOK_RECURSIVE_TIMER, 10, ebr_frm_convert_record_record_recursively);
  1748.         }
  1749.         else
  1750.         {
  1751.             StartTimer(EBOOK_RECURSIVE_TIMER, 10, ebr_frm_convert_record_record_recursively);
  1752.         }
  1753.     }
  1754.     else
  1755.     {
  1756. g_curr_book_cntx_p->state_recursive_conversion = EBR_FRM_NFO_CONVERSION_COMPLETED;
  1757. g_curr_book_cntx_p->g_recursive_callback_fn();
  1758. }
  1759.     }
  1760.     else
  1761.     {
  1762.         FILE_HANDLE nfo_handle, new_file_hnd = 0;
  1763.         U8 nfo_extension_name[MAX_EBOOK_NAME_LENGTH];
  1764.         new_file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path, FS_READ_WRITE);
  1765.         FS_Seek(new_file_hnd, 0, FS_FILE_END);
  1766.         nfo_handle = ebr_frm_get_nfo_handle();
  1767.         FS_Seek(nfo_handle, 0, FS_FILE_BEGIN);
  1768.         g_curr_book_cntx_p->g_nfo_book_struct.temp_encoding_file_format = mmi_ebook_util_get_chset(g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format);
  1769.         memset(g_curr_book_cntx_p->g_nfo_book_struct.temp_file_name, 0, MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH);
  1770.         pfnUnicodeStrncat(
  1771.             (PS8) g_curr_book_cntx_p->g_nfo_book_struct.temp_file_name,
  1772.             (const S8*)g_curr_book_cntx_p->g_nfo_book_struct.e_book_name,
  1773.             pfnUnicodeStrlen((const S8*)g_curr_book_cntx_p->g_nfo_book_struct.e_book_name) - 4);
  1774.         if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_TXT)
  1775.         {
  1776.             AnsiiToUnicodeString((S8*) nfo_extension_name, (S8*) TXT_TEMP_EXT_STR);
  1777.         }
  1778.         else
  1779.         {
  1780.             AnsiiToUnicodeString((S8*) nfo_extension_name, (S8*) PDB_TEMP_EXT_STR);
  1781.         }
  1782.         pfnUnicodeStrcat((PS8) g_curr_book_cntx_p->g_nfo_book_struct.temp_file_name, (PS8) nfo_extension_name);
  1783.         FS_GetFileSize(new_file_hnd, &g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size);
  1784.         FS_Write(
  1785.             nfo_handle,
  1786.             &g_curr_book_cntx_p->g_nfo_book_struct,
  1787.             sizeof(g_curr_book_cntx_p->g_nfo_book_struct),
  1788.             &size);
  1789.         FS_Close(nfo_handle);
  1790.         FS_Close(new_file_hnd);
  1791.         ebr_frm_set_temp_number_of_records();
  1792.         g_curr_book_cntx_p->state_recursive_conversion = EBR_FRM_NFO_CONVERSION_COMPLETED;
  1793. if (GetExitScrnID() == SCR_ID_EBOOK_WAITSCREEN)
  1794.         {
  1795.             g_curr_book_cntx_p->g_recursive_callback_fn();
  1796.         }
  1797.         else
  1798.         {
  1799.             return;
  1800.         }        
  1801.     }
  1802. }
  1803. /*****************************************************************************
  1804.  * FUNCTION
  1805.  *  ebr_frm_create_temp_file_in_ucs2
  1806.  * DESCRIPTION
  1807.  *  Get the record size for text file.
  1808.  * PARAMETERS
  1809.  *  file_hnd        [IN]        
  1810.  * RETURNS
  1811.  *  S16 error_type
  1812.  *****************************************************************************/
  1813. S32 ebr_frm_create_temp_file_in_ucs2(FILE_HANDLE file_hnd)
  1814. {
  1815.     /*----------------------------------------------------------------*/
  1816.     /* Local Variables                                                */
  1817.     /*----------------------------------------------------------------*/
  1818.     pBOOL is_temp_file_present = FALSE;
  1819.     FS_DiskInfo disk_info;
  1820.     U64 disk_free_space;
  1821.     U64 disk_total_space;
  1822.     S32 fs_ret;
  1823.     S8 file_path_in_ascii[5];
  1824.     S8 file_path[10];
  1825.     /*----------------------------------------------------------------*/
  1826.     /* Code Body                                                      */
  1827.     /*----------------------------------------------------------------*/
  1828.     ebr_frm_create_temp_file_path();
  1829.     /* NEERAJ START */
  1830.     FS_Seek(file_hnd, 0, FS_FILE_BEGIN);
  1831.     /* Check wether the file with this encoding exists before or not. */
  1832.     is_temp_file_present = ebr_frm_check_if_file_exists_or_not();
  1833.     if (!is_temp_file_present)
  1834.     {
  1835.         sprintf((char*)file_path_in_ascii, "%c", g_curr_book_cntx_p->memory_type_selected);
  1836.         strcat((char*)file_path_in_ascii, ":\");
  1837.         AnsiiToUnicodeString((PS8) file_path, file_path_in_ascii);
  1838.         fs_ret = FS_GetDiskInfo((PU16) file_path, &disk_info, FS_DI_BASIC_INFO | FS_DI_FREE_SPACE);
  1839.         disk_free_space = 0;
  1840.         disk_total_space = 0;
  1841.         if (fs_ret >= 0)
  1842.         {
  1843.             disk_free_space = disk_info.FreeClusters * disk_info.SectorsPerCluster * disk_info.BytesPerSector;
  1844.             disk_total_space = disk_info.TotalClusters * disk_info.SectorsPerCluster * disk_info.BytesPerSector;
  1845.             if (disk_free_space <= g_curr_book_cntx_p->g_nfo_book_struct.book_size * 2)
  1846.             {
  1847.                 //     ebr_app_dispaly_less_memory_pop_up();
  1848.                 //     FS_Close(file_hnd);
  1849.                 return 0;
  1850.             }
  1851.         }
  1852.         FS_Close(file_hnd);
  1853.         g_curr_book_cntx_p->g_record_id = 1;
  1854.         g_curr_book_cntx_p->state_recursive_conversion = EBR_FRM_CONVERSION_UNDERWAY;
  1855.         ebr_frm_convert_record_record_recursively();
  1856.     }
  1857.     else
  1858.     {
  1859.         if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_PDB)
  1860.         {
  1861.             g_curr_book_cntx_p->pdb_converted_to_text = TRUE;
  1862.         }
  1863.         return 2;
  1864.     }
  1865.     return 1;
  1866. }
  1867. /*****************************************************************************
  1868.  * FUNCTION
  1869.  *  ebr_frm_check_if_file_exists_or_not
  1870.  * DESCRIPTION
  1871.  *  Get the record size for text file.
  1872.  * PARAMETERS
  1873.  *  void
  1874.  * RETURNS
  1875.  *  S16 error_type
  1876.  *****************************************************************************/
  1877. pBOOL ebr_frm_check_if_file_exists_or_not(void)
  1878. {
  1879.     /*----------------------------------------------------------------*/
  1880.     /* Local Variables                                                */
  1881.     /*----------------------------------------------------------------*/
  1882.     U8 mmiEncoding;
  1883.     FS_HANDLE fh_cur;
  1884.     /*----------------------------------------------------------------*/
  1885.     /* Code Body                                                      */
  1886.     /*----------------------------------------------------------------*/
  1887.     mmiEncoding = mmi_ebook_util_get_chset(g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format);
  1888.     if (mmiEncoding == g_curr_book_cntx_p->g_nfo_book_struct.temp_encoding_file_format)
  1889.     {
  1890.         fh_cur = FS_Open((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path, FS_READ_ONLY);
  1891.         if (fh_cur == 0 || fh_cur < 0)
  1892.         {
  1893.             FS_Close(fh_cur);
  1894.             return FALSE;
  1895.         }
  1896.         else
  1897.         {
  1898.             FS_Close(fh_cur);
  1899.             return TRUE;
  1900.         }
  1901.     }
  1902.     else
  1903.     {
  1904.         FS_Delete((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path);
  1905.         return FALSE;
  1906.     }
  1907. }
  1908. /*****************************************************************************
  1909.  * FUNCTION
  1910.  *  ebr_frm_create_temp_file_path
  1911.  * DESCRIPTION
  1912.  *  Get the record size for text file.
  1913.  * PARAMETERS
  1914.  *  void
  1915.  * RETURNS
  1916.  *  void
  1917.  *****************************************************************************/
  1918. void ebr_frm_create_temp_file_path(void)
  1919. {
  1920.     /*----------------------------------------------------------------*/
  1921.     /* Local Variables                                                */
  1922.     /*----------------------------------------------------------------*/
  1923.     U8 nfo_extension_name[MAX_EBOOK_NAME_LENGTH];
  1924.     /*----------------------------------------------------------------*/
  1925.     /* Code Body                                                      */
  1926.     /*----------------------------------------------------------------*/
  1927.     pfnUnicodeStrcpy(
  1928.         (S8*) g_curr_book_cntx_p->temp_book_name_path,
  1929.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  1930.     pfnUnicodeStrncat(
  1931.         (PS8) g_curr_book_cntx_p->temp_book_name_path,
  1932.         (PS8) g_curr_book_cntx_p->g_nfo_book_struct.e_book_name,
  1933.         pfnUnicodeStrlen((const S8*)g_curr_book_cntx_p->g_nfo_book_struct.e_book_name) - 4);
  1934.     if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_TXT)
  1935.     {
  1936.         AnsiiToUnicodeString((S8*) nfo_extension_name, (S8*) TXT_TEMP_EXT_STR);
  1937.     }
  1938.     else
  1939.     {
  1940.         AnsiiToUnicodeString((S8*) nfo_extension_name, (S8*) PDB_TEMP_EXT_STR);
  1941.     }
  1942.     pfnUnicodeStrcat((PS8) g_curr_book_cntx_p->temp_book_name_path, (PS8) nfo_extension_name);
  1943. }
  1944. /*****************************************************************************
  1945.  * FUNCTION
  1946.  *  ebr_frm_create_temp_file_txt
  1947.  * DESCRIPTION
  1948.  *  Get the record size for text file.
  1949.  * PARAMETERS
  1950.  *  rec_num     [IN]        
  1951.  * RETURNS
  1952.  *  S16 error_type
  1953.  *****************************************************************************/
  1954. S32 ebr_frm_create_temp_file_txt(S32 rec_num)
  1955. {
  1956.     /*----------------------------------------------------------------*/
  1957.     /* Local Variables                                                */
  1958.     /*----------------------------------------------------------------*/
  1959.     S32 rec_size;
  1960.     /*----------------------------------------------------------------*/
  1961.     /* Code Body                                                      */
  1962.     /*----------------------------------------------------------------*/
  1963.     if (rec_num < g_curr_book_cntx_p->num_records)
  1964.     {
  1965.         rec_size = EBR_RECORD_SIZE_MAX;
  1966.     }
  1967.     else
  1968.     {
  1969.         rec_size = g_curr_book_cntx_p->g_nfo_book_struct.book_size % EBR_RECORD_SIZE_MAX;
  1970.     }
  1971.     return rec_size;
  1972. }
  1973. /*****************************************************************************
  1974.  * FUNCTION
  1975.  *  ebr_frm_get_record_size_txt
  1976.  * DESCRIPTION
  1977.  *  
  1978.  * PARAMETERS
  1979.  *  rec_num     [IN]        
  1980.  * RETURNS
  1981.  *  
  1982.  *****************************************************************************/
  1983. S32 ebr_frm_get_record_size_txt(S32 rec_num)
  1984. {
  1985.     /*----------------------------------------------------------------*/
  1986.     /* Local Variables                                                */
  1987.     /*----------------------------------------------------------------*/
  1988.     S32 rec_size;
  1989.     /*----------------------------------------------------------------*/
  1990.     /* Code Body                                                      */
  1991.     /*----------------------------------------------------------------*/
  1992.     if (rec_num < g_curr_book_cntx_p->num_records)
  1993.     {
  1994.         rec_size = EBR_RECORD_SIZE_MAX;
  1995.     }
  1996.     else
  1997.     {
  1998.         if (g_curr_book_cntx_p->book_is_in_other_encoding_format)
  1999.         {
  2000.             rec_size = g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size % EBR_RECORD_SIZE_MAX;
  2001.         }
  2002.         else
  2003.         {
  2004.             rec_size = g_curr_book_cntx_p->g_nfo_book_struct.book_size % EBR_RECORD_SIZE_MAX;
  2005.         }
  2006.     }
  2007.     return rec_size;
  2008. }
  2009. /*****************************************************************************
  2010.  * FUNCTION
  2011.  *  ebr_frm_get_record_size_pdb
  2012.  * DESCRIPTION
  2013.  *  Get the offset for the current record to be displayed
  2014.  * PARAMETERS
  2015.  *  file_hnd        [IN]        
  2016.  *  offset          [IN]        
  2017.  *  rec_num         [IN]        
  2018.  * RETURNS
  2019.  *  S32
  2020.  *****************************************************************************/
  2021. S32 ebr_frm_get_record_size_pdb(FILE_HANDLE file_hnd, S32 offset, S32 rec_num)
  2022. {
  2023.     /*----------------------------------------------------------------*/
  2024.     /* Local Variables                                                */
  2025.     /*----------------------------------------------------------------*/
  2026.     S32 size, rec_size;
  2027.     U32 next_offset;
  2028.     /*----------------------------------------------------------------*/
  2029.     /* Code Body                                                      */
  2030.     /*----------------------------------------------------------------*/
  2031.     if (rec_num < g_curr_book_cntx_p->num_records)
  2032.     {
  2033.         SEEK_REC_ENTRY(file_hnd, rec_num + 1);
  2034.         if (FS_Read(file_hnd, &next_offset, 4, (U32*) & size) == FS_NO_ERROR)
  2035.         {
  2036.             next_offset = ntohl(next_offset);
  2037.         }
  2038.         rec_size = next_offset - offset;
  2039.     }
  2040.     else
  2041.     {
  2042.         rec_size = EBR_RECORD_SIZE_MAX;
  2043.     }
  2044.     return rec_size;
  2045. }
  2046. /*****************************************************************************
  2047.  * FUNCTION
  2048.  *  ebr_frm_start_decompression
  2049.  * DESCRIPTION
  2050.  *  Start decompression
  2051.  * PARAMETERS
  2052.  *  decompressed_buffer     [IN]        
  2053.  *  compressed_buffer       [IN]        
  2054.  *  size                    [IN]        
  2055.  * RETURNS
  2056.  *  void
  2057.  *****************************************************************************/
  2058. void ebr_frm_start_decompression(U8 *decompressed_buffer, U8 *compressed_buffer, U32 *size)
  2059. {
  2060.     /*----------------------------------------------------------------*/
  2061.     /* Local Variables                                                */
  2062.     /*----------------------------------------------------------------*/
  2063.     U32 i, j = 0;
  2064.     /*----------------------------------------------------------------*/
  2065.     /* Code Body                                                      */
  2066.     /*----------------------------------------------------------------*/
  2067.     for (i = 0; i < *size;)
  2068.     {
  2069.         unsigned c = compressed_buffer[i++];
  2070.         if (c >= 1 && c <= 8)
  2071.             while (c--)
  2072.                 /* copy 'c' bytes */
  2073.             {
  2074.                 if (j >= EBR_RECORD_SIZE_MAX)
  2075.                 {
  2076.                     goto end;
  2077.                 }
  2078.                 decompressed_buffer[j++] = compressed_buffer[i++];
  2079.             }
  2080.         else if (c <= 0x7F)
  2081.             /* 0,09-7F = self */
  2082.         {
  2083.             if (j >= EBR_RECORD_SIZE_MAX)
  2084.             {
  2085.                 goto end;
  2086.             }
  2087.             decompressed_buffer[j++] = c;
  2088.         }
  2089.         else if (c >= 0xC0) /* space + ASCII char */
  2090.         {
  2091.             if (j >= EBR_RECORD_SIZE_MAX - 1)
  2092.             {
  2093.                 goto end;
  2094.             }
  2095.             decompressed_buffer[j++] = ' ', decompressed_buffer[j++] = c ^ 0x80;
  2096.         }
  2097.         else
  2098.         {   /* 80-BF = sequences */
  2099.             S32 di, n;
  2100.             c = (c << 8) + compressed_buffer[i++];
  2101.             di = (c & 0x3FFF) >> COUNT_BITS;
  2102.             for (n = (c & ((1 << COUNT_BITS) - 1)) + 3; n--; ++j)
  2103.             {
  2104.                 if (j >= EBR_RECORD_SIZE_MAX)
  2105.                 {
  2106.                     goto end;
  2107.                 }
  2108.                 decompressed_buffer[j] = decompressed_buffer[j - di];
  2109.             }
  2110.         }
  2111.     }
  2112.   end:
  2113.     *size = j;
  2114. }
  2115. /*****************************************************************************
  2116.  * FUNCTION
  2117.  *  ebr_frm_decompress_pdb
  2118.  * DESCRIPTION
  2119.  *  Decompress the PDB record
  2120.  * PARAMETERS
  2121.  *  b               [IN]        
  2122.  *  size            [IN]        
  2123.  *  copy_type       [IN]        
  2124.  * RETURNS
  2125.  *  void
  2126.  *****************************************************************************/
  2127. void ebr_frm_decompress_pdb(U8 *b, U32 *size, ebr_frm_copy_type_enum copy_type)
  2128. {
  2129.     /*----------------------------------------------------------------*/
  2130.     /* Local Variables                                                */
  2131.     /*----------------------------------------------------------------*/
  2132.     U32 offset = 0;
  2133.     /*----------------------------------------------------------------*/
  2134.     /* Code Body                                                      */
  2135.     /*----------------------------------------------------------------*/
  2136.     switch (copy_type)
  2137.     {
  2138.         case EBR_FRM_COPY_TYPE_FIRST:
  2139.             memset(g_curr_book_cntx_p->start, 0, EBR_RECORD_SIZE_MAX * 2);
  2140.             offset = 0;
  2141.             break;
  2142.         case EBR_FRM_COPY_TYPE_SECOND:
  2143.             memset(g_curr_book_cntx_p->start + EBR_RECORD_SIZE_MAX, 0, EBR_RECORD_SIZE_MAX);
  2144.             offset = EBR_RECORD_SIZE_MAX;
  2145.             break;
  2146.         case EBR_FRM_COPY_TYPE_NEXT:
  2147.             memcpy(g_curr_book_cntx_p->start, g_curr_book_cntx_p->start + EBR_RECORD_SIZE_MAX, EBR_RECORD_SIZE_MAX);
  2148.             memset(g_curr_book_cntx_p->start + EBR_RECORD_SIZE_MAX, 0, EBR_RECORD_SIZE_MAX);
  2149.             offset = EBR_RECORD_SIZE_MAX;
  2150.             break;
  2151.         case EBR_FRM_COPY_TYPE_PREVIOUS:
  2152.             memcpy(g_curr_book_cntx_p->start + EBR_RECORD_SIZE_MAX, g_curr_book_cntx_p->start, EBR_RECORD_SIZE_MAX);
  2153.             memset(g_curr_book_cntx_p->start, 0, EBR_RECORD_SIZE_MAX);
  2154.             offset = 0;
  2155.             break;
  2156.     }
  2157.     ebr_frm_start_decompression(g_curr_book_cntx_p->start + offset, b, size);
  2158. }
  2159. /*****************************************************************************
  2160.  * FUNCTION
  2161.  *  ebr_frm_get_data_to_open_book
  2162.  * DESCRIPTION
  2163.  *  Get the g_curr_book_cntx_p->buffer
  2164.  * PARAMETERS
  2165.  *  ebook_frm_setting       [IN]        
  2166.  *  buffer_data             [IN]        
  2167.  *  book_display_name       [IN]        
  2168.  * RETURNS
  2169.  *  U8*
  2170.  *****************************************************************************/
  2171. S16 ebr_frm_get_data_to_open_book(gui_page_info_app *ebook_frm_setting, U8 *buffer_data, S8 *book_display_name)
  2172. {
  2173.     /*----------------------------------------------------------------*/
  2174.     /* Local Variables                                                */
  2175.     /*----------------------------------------------------------------*/
  2176.     FILE_HANDLE nfo_hnd_local;
  2177.     S32 start_id, end_id;
  2178.     U8 mmiEncoding = 0;
  2179.     S16 returnval;
  2180.     S32 buffer_length, book_size = 0;
  2181.     S16 ebr_page_size;
  2182.     U32 strlength = 0;
  2183.     U8* buffer_start;
  2184.     U8 UCS2headerle[] = {0xFF,0xFE};
  2185.     U8 UCS2headerbe[] = {0xFE,0xFF};
  2186.     /*----------------------------------------------------------------*/
  2187.     /* Code Body                                                      */
  2188.     /*----------------------------------------------------------------*/
  2189.     /* Check here if the call is from file manager or not */
  2190.     memset(ebook_frm_setting, 0, sizeof(ebook_frm_setting));
  2191.     /* g_curr_book_cntx_p->g_nfo_book_struct.book_size = 0; */
  2192.     nfo_hnd_local = ebr_frm_get_nfo_handle();
  2193.     if (nfo_hnd_local <= 0)
  2194.     {
  2195.         return -1;
  2196.     }
  2197.     FS_Close(nfo_hnd_local);
  2198.     ebr_frm_get_book_encoding_type();
  2199.     memset(g_curr_book_cntx_p->start, 0, sizeof(g_curr_book_cntx_p->start));
  2200.     memset(g_curr_book_cntx_p->buffer, 0, sizeof(g_curr_book_cntx_p->buffer));
  2201.     if (g_curr_book_cntx_p->book_is_in_other_encoding_format)
  2202.     {
  2203.         book_size = g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size;
  2204.         if (book_size < 0)
  2205.         {
  2206.             return 3;
  2207.         }
  2208.     }
  2209.     else
  2210.     {
  2211.         book_size = g_curr_book_cntx_p->g_nfo_book_struct.book_size;
  2212.         if (book_size < 0)
  2213.         {
  2214.             return 3;
  2215.         }
  2216.         ebr_frm_set_number_of_records();
  2217.     }
  2218.     if (g_curr_book_cntx_p->is_book_in_unicode || g_curr_book_cntx_p->book_is_in_other_encoding_format ||
  2219.         g_curr_book_cntx_p->book_is_in_other_encoding_format)
  2220.     {
  2221.         ebr_page_size = EBR_PAGE_SIZE * 2;
  2222.     }
  2223.     else
  2224.     {
  2225.         ebr_page_size = EBR_PAGE_SIZE;
  2226. ebr_frm_set_number_of_records();
  2227.     }
  2228. if(g_curr_book_cntx_p->book_is_in_other_encoding_format)
  2229. {
  2230. ebr_frm_create_temp_file_path();
  2231. if(ebr_frm_check_if_file_exists_or_not())
  2232. {
  2233. ebr_frm_set_temp_number_of_records();
  2234. }
  2235. else
  2236. {
  2237. ebr_frm_set_number_of_records();
  2238. }
  2239. }
  2240.     g_curr_book_cntx_p->g_start_id = g_curr_book_cntx_p->g_nfo_book_struct.current_page_id;
  2241.     g_curr_book_cntx_p->prev_end_id = g_curr_book_cntx_p->g_start_id;
  2242.     g_curr_book_cntx_p->g_offset = g_curr_book_cntx_p->g_nfo_book_struct.offset;
  2243.     if (g_curr_book_cntx_p->num_records == 0)
  2244.     {
  2245.         return 2;
  2246.     }
  2247.     if (g_curr_book_cntx_p->g_start_id != 0)
  2248.     {
  2249.         if (!g_curr_book_cntx_p->ebr_frm_end_book_flag ||
  2250.             ((g_curr_book_cntx_p->g_nfo_book_struct.current_page_id + 4) * ebr_page_size >= (U32) book_size ||
  2251.              (g_curr_book_cntx_p->g_nfo_book_struct.offset > (U32) ebr_page_size * 3 ||
  2252.               g_curr_book_cntx_p->g_nfo_book_struct.jump_offset > (U32) ebr_page_size * 3)) &&
  2253.             (!g_curr_book_cntx_p->search_flag_is_on))
  2254.         {
  2255.             start_id = (g_curr_book_cntx_p->g_start_id) % (EBR_RECORD_SIZE_MAX / ebr_page_size);
  2256.             if ((start_id + EBR_RECORD_SIZE_MAX / ebr_page_size + 3) <= (EBR_RECORD_SIZE_MAX / ebr_page_size) * 2 - 1)
  2257.             {
  2258.                 start_id += EBR_RECORD_SIZE_MAX / ebr_page_size;
  2259.             }
  2260.             else if (g_curr_book_cntx_p->g_start_id / (EBR_RECORD_SIZE_MAX / ebr_page_size) == g_curr_book_cntx_p->num_records - 1)
  2261.             {
  2262.                 start_id += (EBR_RECORD_SIZE_MAX / ebr_page_size - start_id);    
  2263.             }
  2264.             if (book_size < EBR_RECORD_SIZE_MAX)
  2265.             {
  2266.                 start_id = g_curr_book_cntx_p->g_start_id;
  2267.             }
  2268.         }
  2269.         else
  2270.         {
  2271.             start_id = g_curr_book_cntx_p->g_start_id % (EBR_RECORD_SIZE_MAX / ebr_page_size);
  2272.             /* This check si required when the end page id to jump at is the last page id and it may come in
  2273.                first record */
  2274.             if (g_curr_book_cntx_p->g_start_id / (EBR_RECORD_SIZE_MAX / ebr_page_size) + 2 >
  2275.                 g_curr_book_cntx_p->num_records)
  2276.             {
  2277.                 start_id -= EBR_RECORD_SIZE_MAX / ebr_page_size;
  2278.             }
  2279.             if (book_size < EBR_RECORD_SIZE_MAX)
  2280.             {
  2281.                 start_id = g_curr_book_cntx_p->g_start_id;
  2282.             }
  2283.         }
  2284.     }
  2285.     else
  2286.     {
  2287.         start_id = 0;
  2288.     }
  2289.     if (start_id < 0)
  2290.     {
  2291.         g_curr_book_cntx_p->g_start_id =
  2292.             g_curr_book_cntx_p->g_nfo_book_struct.current_page_id - EBR_RECORD_SIZE_MAX / ebr_page_size;
  2293.         if (g_curr_book_cntx_p->g_start_id < 0)
  2294.         {
  2295.             g_curr_book_cntx_p->g_start_id = 0;
  2296.         }
  2297.     }
  2298.     g_curr_book_cntx_p->g_end_id = g_curr_book_cntx_p->g_nfo_book_struct.current_page_id + 3;
  2299.     returnval = ebr_frm_decode_header((U8*) g_curr_book_cntx_p->g_nfo_book_struct.e_book_name);
  2300.     if (returnval == 0)
  2301.     {
  2302.         return 0;
  2303.     }
  2304.     if (returnval == 2)
  2305.     {
  2306.         return 3;
  2307.     }
  2308.     if (g_curr_book_cntx_p->state_recursive_conversion == EBR_FRM_CONVERSION_UNDERWAY)
  2309.     {
  2310.         return 1;
  2311.     }
  2312.     if (start_id < 0)
  2313.     {
  2314.         if (start_id == -1)
  2315.         {
  2316.             start_id += EBR_RECORD_SIZE_MAX / ebr_page_size;
  2317.         }
  2318.         else
  2319.         {
  2320.             start_id += (EBR_RECORD_SIZE_MAX / ebr_page_size * 2);
  2321.         }
  2322.         if (g_curr_book_cntx_p->is_book_in_unicode)
  2323.         {
  2324.             if (start_id > 5)
  2325.             {
  2326.                 start_id = 5;
  2327.             }
  2328.         }
  2329.         if (g_curr_book_cntx_p->book_is_in_other_encoding_format)
  2330.         {
  2331. if (start_id >= 4 && (g_curr_book_cntx_p->g_nfo_book_struct.current_page_id >4))
  2332.             {
  2333. if(g_curr_book_cntx_p->search_flag_is_on)
  2334. {
  2335. }
  2336. else
  2337. {
  2338.                 start_id = 4;
  2339.             }
  2340.             }
  2341. else
  2342. {
  2343. if(g_curr_book_cntx_p->g_nfo_book_struct.current_page_id<=4)
  2344.                     {
  2345. start_id = g_curr_book_cntx_p->g_nfo_book_struct.current_page_id;
  2346.                     }
  2347. }
  2348.         }
  2349.     }
  2350.     end_id = start_id + 3;
  2351.     memset(g_curr_book_cntx_p->buffer, 0, ebr_page_size * 4);
  2352.     memcpy(g_curr_book_cntx_p->buffer, g_curr_book_cntx_p->start + ebr_page_size * start_id, ebr_page_size * 4);
  2353.     buffer_length = pfnUnicodeStrlen((const S8*)g_curr_book_cntx_p->buffer);
  2354.     mmiEncoding = mmi_ebook_util_get_chset(g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format);
  2355.     if ((mmiEncoding == MMI_CHSET_UCS2 || g_curr_book_cntx_p->book_is_in_other_encoding_format) && g_curr_book_cntx_p->g_start_id == 0)    
  2356.     {
  2357.         buffer_start = g_curr_book_cntx_p->buffer;
  2358.         
  2359.         while (!pfnUnicodeStrncmp((S8*)buffer_start, (S8*)UCS2headerle,1))
  2360.         {
  2361.             buffer_start[0] = WHITE_SPACE;
  2362.             buffer_start[1] = 0;
  2363.             buffer_start += 2;
  2364.         }
  2365.         while (!pfnUnicodeStrncmp((S8*)buffer_start, (S8*)UCS2headerbe,1))
  2366.         {
  2367.             buffer_start[0] = WHITE_SPACE;
  2368.             buffer_start[1] = 0;
  2369.             buffer_start += 2;
  2370.         }
  2371.     }
  2372.     
  2373.     switch (mmiEncoding)
  2374.     {
  2375.         case MMI_CHSET_UCS2:
  2376.             pfnUnicodeStrncpy(
  2377.                 (PS8) buffer_data,
  2378.                 (PS8) g_curr_book_cntx_p->buffer,
  2379.                 (EBR_RECORD_SIZE_MAX + GUI_SHARED_BYTES) / 2);
  2380.             break;
  2381.         case MMI_CHSET_WESTERN_WIN:
  2382.             returnval = AnsiiNToUnicodeString(
  2383.                             (PS8) buffer_data,
  2384.                             (PS8) g_curr_book_cntx_p->buffer,
  2385.                             (EBR_RECORD_SIZE_MAX + GUI_SHARED_BYTES) / 2);
  2386.             break;
  2387.         default:
  2388.             pfnUnicodeStrncpy(
  2389.                 (PS8) buffer_data,
  2390.                 (PS8) g_curr_book_cntx_p->buffer,
  2391.                 (EBR_RECORD_SIZE_MAX + GUI_SHARED_BYTES) / 2);
  2392.             break;
  2393.     }
  2394.     if (g_curr_book_cntx_p->is_book_in_unicode)
  2395.     {
  2396.         ebook_frm_setting->doc_size = g_curr_book_cntx_p->g_nfo_book_struct.book_size / 2;
  2397.     }
  2398.     else
  2399.     {
  2400.         if (g_curr_book_cntx_p->book_is_in_other_encoding_format)
  2401.         {
  2402.             ebook_frm_setting->doc_size = g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size / 2;
  2403.         }
  2404.         else
  2405.         {
  2406.             ebook_frm_setting->doc_size = g_curr_book_cntx_p->g_nfo_book_struct.book_size;
  2407.         }
  2408.     }
  2409.     if (ebook_frm_setting->doc_size < EBR_PAGE_SIZE * 4)
  2410.     {
  2411.         ebook_frm_setting->end_id = ebook_frm_setting->doc_size / EBR_PAGE_SIZE - 1;
  2412.         if (ebook_frm_setting->doc_size % EBR_PAGE_SIZE != 0)
  2413.         {
  2414.             ebook_frm_setting->end_id = ebook_frm_setting->end_id + 1;
  2415.         }
  2416.         if (ebook_frm_setting->doc_size <= EBR_PAGE_SIZE)
  2417.         {
  2418.             ebook_frm_setting->end_id = 1;
  2419.         ebook_frm_setting->start_id = 0;
  2420.     }
  2421.     else
  2422.     {
  2423.             ebook_frm_setting->start_id = g_curr_book_cntx_p->g_nfo_book_struct.current_page_id;
  2424.         }
  2425.     }
  2426.     else
  2427.     {
  2428.         ebook_frm_setting->start_id = g_curr_book_cntx_p->g_nfo_book_struct.current_page_id;    /* -reduce_start_id_by; */
  2429.         if ((book_size - g_curr_book_cntx_p->g_nfo_book_struct.current_page_id * EBR_PAGE_SIZE) < EBR_RECORD_SIZE_MAX)
  2430.         {
  2431.             if (book_size - g_curr_book_cntx_p->g_nfo_book_struct.current_page_id * EBR_PAGE_SIZE > EBR_PAGE_SIZE * 3)
  2432.             {
  2433.                 ebook_frm_setting->end_id = g_curr_book_cntx_p->g_nfo_book_struct.current_page_id + 3;
  2434.             }
  2435.             else
  2436.             {
  2437.                 ebook_frm_setting->end_id = g_curr_book_cntx_p->g_nfo_book_struct.current_page_id + 2;
  2438.             }
  2439.         }
  2440.         else
  2441.         {
  2442.             ebook_frm_setting->end_id = g_curr_book_cntx_p->g_nfo_book_struct.current_page_id + 3;
  2443.         }
  2444.     }
  2445.     ebook_frm_setting->font_style = g_curr_book_cntx_p->g_nfo_book_struct.settings.font_style;
  2446.     ebook_frm_setting->font_size = g_curr_book_cntx_p->g_nfo_book_struct.settings.font_size;
  2447.     ebook_frm_setting->scroll_speed =
  2448.         g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_speed + 1;
  2449.     ebook_frm_setting->scroll_type = g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_type;
  2450.     ebook_frm_setting->text_offset = g_curr_book_cntx_p->g_nfo_book_struct.offset;
  2451.     ebook_frm_setting->jump_offset_from_app = g_curr_book_cntx_p->g_nfo_book_struct.jump_offset;
  2452.     ebook_frm_setting->scroll_flag = g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_flag;
  2453.     ebook_frm_setting->jump_to_end = g_curr_book_cntx_p->ebr_frm_end_book_flag;
  2454.     ebook_frm_setting->search_str_len = g_curr_book_cntx_p->ebr_search_strlen;
  2455.     ebook_frm_setting->highlight_string = g_curr_book_cntx_p->highlight_string_flag;
  2456.     ebook_frm_setting->search_flag_is_on = g_curr_book_cntx_p->search_flag_is_on;
  2457.     ebook_frm_setting->last_text_offset_y = g_curr_book_cntx_p->g_nfo_book_struct.last_text_offset_y;
  2458. #ifdef __MMI_TOUCH_SCREEN__
  2459.     ebook_frm_setting->get_data_during_scrolling = ebr_frm_get_data_during_scrolling;
  2460. #endif 
  2461.     if (g_curr_book_cntx_p->search_flag_is_on == 0)
  2462.     {
  2463.         ebook_frm_setting->last_showed_percentage = g_curr_book_cntx_p->g_nfo_book_struct.last_showed_percentage;
  2464.     }
  2465.     else
  2466.     {
  2467.         ebook_frm_setting->last_showed_percentage = 0;
  2468.     }
  2469.     g_curr_book_cntx_p->highlight_string_flag = 0;
  2470.     g_curr_book_cntx_p->search_flag_is_on = 0;
  2471.     g_curr_book_cntx_p->ebr_frm_end_book_flag = 1;
  2472.         strlength = pfnUnicodeStrlen((const S8*)g_curr_book_cntx_p->g_nfo_book_struct.e_book_name);
  2473.         pfnUnicodeStrncpy(
  2474.             (S8*) book_display_name,
  2475.             (S8*) g_curr_book_cntx_p->g_nfo_book_struct.e_book_name,
  2476.             strlength - EBR_EXTENSION_NAME_LENGTH - 1);
  2477.         return 1;
  2478. }
  2479. /*****************************************************************************
  2480.  * FUNCTION
  2481.  *  ebr_frm_get_book_encoding_type
  2482.  * DESCRIPTION
  2483.  *  Get encoding type
  2484.  * PARAMETERS
  2485.  *  void
  2486.  * RETURNS
  2487.  *  void
  2488.  *****************************************************************************/
  2489. void ebr_frm_get_book_encoding_type(void)
  2490. {
  2491.     /*----------------------------------------------------------------*/
  2492.     /* Local Variables                                                */
  2493.     /*----------------------------------------------------------------*/
  2494.     U8 mmiEncoding = 0;
  2495.     /*----------------------------------------------------------------*/
  2496.     /* Code Body                                                      */
  2497.     /*----------------------------------------------------------------*/
  2498.     mmiEncoding = mmi_ebook_util_get_chset(g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format);
  2499.     if (mmiEncoding != MMI_CHSET_WESTERN_WIN)
  2500.     {
  2501.         if ((mmiEncoding == MMI_CHSET_UCS2))
  2502.         {
  2503.             g_curr_book_cntx_p->is_book_in_unicode = TRUE;
  2504.             g_curr_book_cntx_p->book_is_in_other_encoding_format = FALSE;
  2505.         }
  2506.         else
  2507.         {
  2508.             g_curr_book_cntx_p->is_book_in_unicode = FALSE;
  2509.             g_curr_book_cntx_p->book_is_in_other_encoding_format = TRUE;
  2510.         }
  2511.     }
  2512.     else
  2513.     {
  2514.         g_curr_book_cntx_p->is_book_in_unicode = FALSE;
  2515.         g_curr_book_cntx_p->book_is_in_other_encoding_format = FALSE;
  2516.     }
  2517. }
  2518. /*****************************************************************************
  2519.  * FUNCTION
  2520.  *  ebr_frm_get_encoded_data
  2521.  * DESCRIPTION