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

MTK

开发平台:

C/C++

  1.  *  Get the encoding format
  2.  * PARAMETERS
  3.  *  inBuffer        [IN]        
  4.  *  outBuffer       [IN]        
  5.  * RETURNS
  6.  *  void
  7.  *****************************************************************************/
  8. void ebr_frm_get_encoded_data(S8 *inBuffer, S8 *outBuffer)
  9. {
  10.     /*----------------------------------------------------------------*/
  11.     /* Local Variables                                                */
  12.     /*----------------------------------------------------------------*/
  13.     U8 mmiEncoding = 0;
  14.     S16 length = pfnUnicodeStrlen((const S8*)outBuffer);
  15.     /*----------------------------------------------------------------*/
  16.     /* Code Body                                                      */
  17.     /*----------------------------------------------------------------*/
  18.     mmiEncoding = mmi_ebook_util_get_chset(g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format);
  19.     switch (mmiEncoding)
  20.     {
  21.         case MMI_CHSET_UCS2:
  22.             pfnUnicodeStrncpy((PS8) inBuffer, (PS8) outBuffer, (length) * 2);
  23.             break;
  24.         case MMI_CHSET_WESTERN_WIN:
  25.             AnsiiNToUnicodeString((PS8) inBuffer, (PS8) outBuffer, (length) * 2);
  26.             break;
  27.         default:
  28.             mmi_chset_convert(
  29.                 (mmi_chset_enum) mmiEncoding,
  30.                 MMI_CHSET_UCS2,
  31.                 (char*)outBuffer,
  32.                 (char*)inBuffer,
  33.                 length * 2);
  34.             break;
  35.     }
  36. }
  37. /*****************************************************************************
  38.  * FUNCTION
  39.  *  ebr_frm_get_record
  40.  * DESCRIPTION
  41.  *  Get the record data
  42.  * PARAMETERS
  43.  *  end_id      [IN]        
  44.  * RETURNS
  45.  *  void
  46.  *****************************************************************************/
  47. void ebr_frm_get_record(S32 end_id)
  48. {
  49.     /*----------------------------------------------------------------*/
  50.     /* Local Variables                                                */
  51.     /*----------------------------------------------------------------*/
  52.     S32 record_id_to_be_fetched;
  53.     /* U8 nfo_path[MAX_DWNL_EBK_PATH_LEN*ENCODING_LENGTH]={0}; */
  54.     FILE_HANDLE file_hnd;
  55.     S16 ebr_page_size;
  56.     /*----------------------------------------------------------------*/
  57.     /* Code Body                                                      */
  58.     /*----------------------------------------------------------------*/
  59.     //      pfnUnicodeStrcpy((S8*)nfo_path  ,(S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected,EBR_FRM_SEARCH_DEFAULT));
  60.     //      pfnUnicodeStrcat((PS8)nfo_path, (PS8)g_curr_book_cntx_p->g_nfo_book_struct.e_book_name);
  61.     if (g_curr_book_cntx_p->book_is_in_other_encoding_format)
  62.     {
  63.         file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path, FS_READ_ONLY);
  64.     }
  65.     else
  66.     {
  67.         file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->book_name_path, FS_READ_ONLY);
  68.     }
  69.     if (g_curr_book_cntx_p->is_book_in_unicode || g_curr_book_cntx_p->book_is_in_other_encoding_format)
  70.     {
  71.         ebr_page_size = EBR_PAGE_SIZE * 2;
  72.     }
  73.     else
  74.     {
  75.         ebr_page_size = EBR_PAGE_SIZE;
  76.     }
  77.     if (g_curr_book_cntx_p->prev_end_id >= end_id)
  78.     {
  79.         record_id_to_be_fetched = (end_id - 2) / (EBR_RECORD_SIZE_MAX / ebr_page_size) + 1;
  80.         if (record_id_to_be_fetched <= g_curr_book_cntx_p->num_records)
  81.         {
  82.             if ((record_id_to_be_fetched != g_curr_book_cntx_p->gcurrent_record_id) &&
  83.                 (record_id_to_be_fetched != g_curr_book_cntx_p->gnext_record_id))
  84.             {
  85.                 copy_record_in_buffer(file_hnd, record_id_to_be_fetched, EBR_FRM_COPY_TYPE_PREVIOUS);
  86.                 g_curr_book_cntx_p->gcurrent_record_id = record_id_to_be_fetched;
  87.                 g_curr_book_cntx_p->gnext_record_id = record_id_to_be_fetched + 1;
  88.             }
  89.         }
  90.     }
  91.     else
  92.     {
  93.         record_id_to_be_fetched = (end_id + 2) / (EBR_RECORD_SIZE_MAX / ebr_page_size) + 1;
  94.         if (record_id_to_be_fetched <= g_curr_book_cntx_p->num_records)
  95.         {
  96.             if ((record_id_to_be_fetched != g_curr_book_cntx_p->gcurrent_record_id) &&
  97.                 (record_id_to_be_fetched != g_curr_book_cntx_p->gnext_record_id))
  98.             {
  99.                 copy_record_in_buffer(file_hnd, record_id_to_be_fetched, EBR_FRM_COPY_TYPE_NEXT);
  100.                 g_curr_book_cntx_p->gcurrent_record_id = record_id_to_be_fetched - 1;
  101.                 g_curr_book_cntx_p->gnext_record_id = g_curr_book_cntx_p->gcurrent_record_id + 1;
  102.             }
  103.         }
  104.     }
  105.     g_curr_book_cntx_p->prev_end_id = end_id;
  106.     FS_Close(file_hnd);
  107. }
  108. /*****************************************************************************
  109.  * FUNCTION
  110.  *  ebr_frm_jump_to_record
  111.  * DESCRIPTION
  112.  *  Jump to a record
  113.  * PARAMETERS
  114.  *  percantage_val      [IN]        
  115.  *  jump_type           [IN]        
  116.  * RETURNS
  117.  *  void
  118.  *****************************************************************************/
  119. void ebr_frm_jump_to_record(U32 percantage_val, ebr_jump_type_enum jump_type)
  120. {
  121.     /*----------------------------------------------------------------*/
  122.     /* Local Variables                                                */
  123.     /*----------------------------------------------------------------*/
  124.     S16 ebr_page_size;
  125.     S32 book_size = 0;
  126.     /*----------------------------------------------------------------*/
  127.     /* Code Body                                                      */
  128.     /*----------------------------------------------------------------*/
  129.     g_curr_book_cntx_p->g_jump_offset = 0;
  130.     //      if(g_curr_book_cntx_p->is_book_in_unicode||g_curr_book_cntx_p->book_is_in_other_encoding_format)
  131.     //              ebr_page_size  = EBR_PAGE_SIZE*2;
  132.     //      else
  133.     ebr_page_size = EBR_PAGE_SIZE;
  134.     if (g_curr_book_cntx_p->book_is_in_other_encoding_format)
  135.     {
  136.         book_size = g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size;
  137.     }
  138.     else
  139.     {
  140.         book_size = g_curr_book_cntx_p->g_nfo_book_struct.book_size;
  141.     }
  142.     if (g_curr_book_cntx_p->is_book_in_unicode || g_curr_book_cntx_p->book_is_in_other_encoding_format)
  143.     {
  144.         book_size /= 2;
  145.     }
  146.     if (jump_type == EBR_JUMP_MIDDLE && percantage_val == 0)
  147.     {
  148.         percantage_val = 50;
  149.     }
  150.     if (percantage_val == 1)
  151.     {
  152.         jump_type = EBR_JUMP_BEGIN;
  153.         percantage_val = 0;
  154.     }
  155.     if (percantage_val == 100)
  156.     {
  157.         int num_of_pages = 0;
  158.         if (book_size % ebr_page_size == 0)
  159.         {
  160.             num_of_pages = book_size / ebr_page_size - 1;
  161.         }
  162.         else
  163.         {
  164.             num_of_pages = book_size / ebr_page_size;
  165.         }
  166.         if (num_of_pages < 4)
  167.         {
  168.             percantage_val = 0;
  169.             jump_type = EBR_JUMP_END;
  170.         }
  171.     }
  172.     if (percantage_val == 0)
  173.     {
  174.         switch (jump_type)
  175.         {
  176.             case EBR_JUMP_BEGIN:
  177.                 g_curr_book_cntx_p->g_start_id = 0;
  178.                 g_curr_book_cntx_p->g_end_id = 3;
  179.                 g_curr_book_cntx_p->g_jump_offset = 0;
  180.                 g_curr_book_cntx_p->gcurrent_record_id = 1;
  181.                 g_curr_book_cntx_p->gnext_record_id = 2;
  182.                 break;
  183.             case EBR_JUMP_END:
  184.                 g_curr_book_cntx_p->ebr_frm_end_book_flag = 0;
  185.                 if (book_size % ebr_page_size == 0)
  186.                 {
  187.                     g_curr_book_cntx_p->g_end_id = book_size / ebr_page_size - 1;
  188.                 }
  189.                 else
  190.                 {
  191.                     if (book_size < ebr_page_size * 8)
  192.                     {
  193.                         if (book_size < ebr_page_size * 4)
  194.                         {
  195.                             g_curr_book_cntx_p->g_start_id = 0;
  196.                             g_curr_book_cntx_p->g_end_id = 3;
  197.                         }
  198.                         else
  199.                         {
  200.                             g_curr_book_cntx_p->g_start_id = 0;
  201.                             g_curr_book_cntx_p->g_end_id = book_size / ebr_page_size - 1;
  202.                             g_curr_book_cntx_p->g_start_id = g_curr_book_cntx_p->g_end_id - 3;
  203.                         }
  204.                     }
  205.                     else
  206.                     {
  207.                         g_curr_book_cntx_p->g_end_id = book_size / ebr_page_size;
  208.                     }
  209.                 }
  210.                 g_curr_book_cntx_p->g_start_id = g_curr_book_cntx_p->g_end_id - 3;
  211.                 break;
  212.         }
  213.     }
  214.     else
  215.     {
  216.         float num;
  217.         int size_offset;
  218.         float actual_size_offset;
  219.         float actual_jump_offset;
  220.         int jump_offset = 0;
  221.         num = percantage_val / (float)100.0;
  222.         actual_size_offset = book_size * num;
  223.         if (percantage_val == 100)
  224.         {
  225.             /* percantage_val--; */
  226.             num = (percantage_val - 1) / (float)100.0;
  227.             num = (float)(num + 0.008);
  228.             size_offset = (int)(book_size * num);
  229.             actual_size_offset = ((float)book_size) * num;
  230.         }
  231.         else
  232.         {
  233.             size_offset = (int)(book_size * num);
  234.         }
  235.         if (actual_size_offset - (float)size_offset > 0)
  236.         {
  237.             size_offset++;
  238.         }
  239.         if ((book_size - size_offset) <= EBR_PAGE_SIZE)
  240.         {
  241.             if (book_size % ebr_page_size == 0)
  242.             {
  243.                 g_curr_book_cntx_p->g_end_id = book_size / ebr_page_size - 1;
  244.                 g_curr_book_cntx_p->g_start_id = g_curr_book_cntx_p->g_end_id - 3;
  245.             }
  246.             else
  247.             {
  248.                 if (book_size < ebr_page_size * 4)
  249.                 {
  250.                     actual_jump_offset = (float)(book_size) * (float)((float)(percantage_val) / (float)100.0);
  251.                     g_curr_book_cntx_p->g_jump_offset = (U16) actual_jump_offset;
  252.                     if (actual_jump_offset - (float)g_curr_book_cntx_p->g_jump_offset > 0.5)
  253.                     {
  254.                         g_curr_book_cntx_p->g_jump_offset++;
  255.                     }
  256.                     if (g_curr_book_cntx_p->g_jump_offset == book_size)
  257.                     {
  258.                         g_curr_book_cntx_p->g_jump_offset--;
  259.                     }
  260.                     g_curr_book_cntx_p->g_start_id = 0;
  261.                     g_curr_book_cntx_p->g_end_id = g_curr_book_cntx_p->g_start_id + 3;
  262.                 }
  263.                 else
  264.                 {
  265.                     if (book_size < EBR_RECORD_SIZE_MAX)
  266.                     {
  267.                         actual_jump_offset = (float)(book_size) * (float)((float)(percantage_val) / (float)100.0);
  268.                         g_curr_book_cntx_p->g_jump_offset = (U16) actual_jump_offset;
  269.                         if (actual_jump_offset - (float)g_curr_book_cntx_p->g_jump_offset > 0.5)
  270.                         {
  271.                             g_curr_book_cntx_p->g_jump_offset++;
  272.                         }
  273.                         if (g_curr_book_cntx_p->g_jump_offset == book_size)
  274.                         {
  275.                             g_curr_book_cntx_p->g_jump_offset--;
  276.                         }
  277.                         jump_offset = (int)g_curr_book_cntx_p->g_jump_offset;
  278.                         /* while(jump_offset>0)
  279.                            jump_offset = jump_offset - EBR_PAGE_SIZE; */
  280.                         /* g_curr_book_cntx_p->g_jump_offset = jump_offset + EBR_PAGE_SIZE+EBR_PAGE_SIZE; */
  281.                         g_curr_book_cntx_p->g_end_id = size_offset / ebr_page_size;
  282.                         if (g_curr_book_cntx_p->g_start_id < 0)
  283.                         {
  284.                             g_curr_book_cntx_p->g_start_id = 0;
  285.                         }
  286.                         g_curr_book_cntx_p->g_start_id = g_curr_book_cntx_p->g_end_id - 3;
  287.                         g_curr_book_cntx_p->g_jump_offset =
  288.                             g_curr_book_cntx_p->g_jump_offset - g_curr_book_cntx_p->g_start_id * EBR_PAGE_SIZE;
  289.                     }
  290.                     else
  291.                     {
  292.                         g_curr_book_cntx_p->g_jump_offset = size_offset % EBR_PAGE_SIZE + EBR_PAGE_SIZE;
  293.                         g_curr_book_cntx_p->g_start_id = (size_offset / ebr_page_size) - 1;
  294.                         g_curr_book_cntx_p->g_end_id = g_curr_book_cntx_p->g_start_id + 3;
  295.                     }
  296.                 }
  297.             }
  298.         }
  299.         else
  300.         {
  301.             if (book_size < EBR_PAGE_SIZE * 4)
  302.             {
  303.                 g_curr_book_cntx_p->g_start_id = 0;
  304.                 g_curr_book_cntx_p->g_end_id = g_curr_book_cntx_p->g_start_id + 3;
  305.                 g_curr_book_cntx_p->g_jump_offset =
  306.                     (U32) (((float)book_size) * (float)((float)(percantage_val) / (float)100.0));
  307.             }
  308.             else
  309.             {
  310.                 if (book_size < EBR_RECORD_SIZE_MAX)
  311.                 {
  312.                     actual_jump_offset = (float)(book_size) * (float)((float)(percantage_val) / (float)100.0);
  313.                     g_curr_book_cntx_p->g_jump_offset = (U16) actual_jump_offset;
  314.                     if (actual_jump_offset - (float)g_curr_book_cntx_p->g_jump_offset > 0.5)
  315.                     {
  316.                         g_curr_book_cntx_p->g_jump_offset++;
  317.                     }
  318.                     if (g_curr_book_cntx_p->g_jump_offset == book_size)
  319.                     {
  320.                         g_curr_book_cntx_p->g_jump_offset--;
  321.                     }
  322.                     jump_offset = (int)g_curr_book_cntx_p->g_jump_offset;
  323.                     while (jump_offset > 0)
  324.                     {
  325.                         jump_offset = jump_offset - EBR_PAGE_SIZE;
  326.                     }
  327.                     g_curr_book_cntx_p->g_jump_offset = jump_offset + EBR_PAGE_SIZE;
  328.                     g_curr_book_cntx_p->g_start_id = size_offset / ebr_page_size;
  329.                     if (g_curr_book_cntx_p->g_start_id < 0)
  330.                     {
  331.                         g_curr_book_cntx_p->g_start_id = 0;
  332.                     }
  333.                     g_curr_book_cntx_p->g_end_id = g_curr_book_cntx_p->g_start_id + 3;
  334.                 }
  335.                 else
  336.                 {
  337.                     g_curr_book_cntx_p->g_jump_offset = size_offset % EBR_PAGE_SIZE + EBR_PAGE_SIZE;
  338.                     if (percantage_val == 100)
  339.                     {
  340.                         g_curr_book_cntx_p->g_start_id = (size_offset / ebr_page_size);
  341.                     }
  342.                     else
  343.                     {
  344.                         g_curr_book_cntx_p->g_start_id = (size_offset / ebr_page_size) - 1;
  345.                     }
  346.                     g_curr_book_cntx_p->g_end_id = g_curr_book_cntx_p->g_start_id + 3;
  347.                 }
  348.             }
  349.         }
  350.     }
  351.     if (percantage_val != g_curr_book_cntx_p->g_nfo_book_struct.last_showed_percentage)
  352.     {
  353.         g_curr_book_cntx_p->g_nfo_book_struct.last_showed_percentage = 0;
  354.     }
  355.     g_curr_book_cntx_p->g_nfo_book_struct.current_page_id = g_curr_book_cntx_p->g_start_id;
  356.     g_curr_book_cntx_p->g_nfo_book_struct.offset = 0;
  357.     g_curr_book_cntx_p->g_nfo_book_struct.jump_offset = g_curr_book_cntx_p->g_jump_offset;
  358.     ebr_frm_save_settings_in_nfo_file();
  359.     g_curr_book_cntx_p->ebr_last_offset_string = -1;
  360. }
  361. /*****************************************************************************
  362.  * FUNCTION
  363.  *  ebr_frm_remove_bookmark
  364.  * DESCRIPTION
  365.  *  Create the linked list
  366.  * PARAMETERS
  367.  *  bookmark_index      [IN]        
  368.  * RETURNS
  369.  *  void
  370.  *****************************************************************************/
  371. void ebr_frm_remove_bookmark(U32 bookmark_index)
  372. {
  373.     /*----------------------------------------------------------------*/
  374.     /* Local Variables                                                */
  375.     /*----------------------------------------------------------------*/
  376.     S32 count = 0;
  377.     U32 size;
  378.     S32 retval;
  379.     FILE_HANDLE nfo_hnd;
  380.     /*----------------------------------------------------------------*/
  381.     /* Code Body                                                      */
  382.     /*----------------------------------------------------------------*/
  383.     pfnUnicodeStrcpy((PS8) g_curr_book_cntx_p->g_nfo_book_struct.book_marks[bookmark_index].bookmark_name, (PS8) NULL);
  384.     if (g_curr_book_cntx_p->g_nfo_book_struct.book_marks[bookmark_index + 1].bookmark_name[0] != 0)
  385.     {
  386.         count = bookmark_index + 1;
  387.         while (g_curr_book_cntx_p->g_nfo_book_struct.book_marks[count].bookmark_name[0] != 0 && count < EBR_FRM_MAX_NO_OF_BOOKMARKS)
  388.         {
  389.             pfnUnicodeStrcpy(
  390.                 (PS8) g_curr_book_cntx_p->g_nfo_book_struct.book_marks[count - 1].bookmark_name,
  391.                 (PS8) g_curr_book_cntx_p->g_nfo_book_struct.book_marks[count].bookmark_name);
  392.             count++;
  393.         }
  394.         count--;
  395.         pfnUnicodeStrcpy((PS8) g_curr_book_cntx_p->g_nfo_book_struct.book_marks[count].bookmark_name, (PS8) NULL);
  396.     }
  397.     nfo_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->nfo_path, FS_READ_WRITE);
  398.     FS_Seek(nfo_hnd, 0, FS_FILE_BEGIN);
  399.     retval = FS_Write(nfo_hnd, &g_curr_book_cntx_p->g_nfo_book_struct, sizeof(g_curr_book_cntx_p->g_nfo_book_struct), &size);
  400.     FS_Close(nfo_hnd);
  401. }
  402. /*****************************************************************************
  403.  * FUNCTION
  404.  *  ebr_frm_add_book_mark_pre_entry
  405.  * DESCRIPTION
  406.  *  Pre entry Screen for Add book mark
  407.  * PARAMETERS
  408.  *  void
  409.  * RETURNS
  410.  *  void
  411.  *****************************************************************************/
  412. void ebr_frm_add_book_mark_pre_entry()
  413. {
  414.     /*----------------------------------------------------------------*/
  415.     /* Local Variables                                                */
  416.     /*----------------------------------------------------------------*/
  417.     S32 i = 0, duplicate = 0;
  418.     U8 bookMarkName[EBR_FRM_MAX_BOOKMARK_NAME_SIZE * ENCODING_LENGTH] = {0};
  419.     /*----------------------------------------------------------------*/
  420.     /* Code Body                                                      */
  421.     /*----------------------------------------------------------------*/
  422.     pfnUnicodeStrcpy((S8*) bookMarkName, (S8*) ebr_get_book_mark_name());
  423.     while (g_curr_book_cntx_p->g_nfo_book_struct.book_marks[i].bookmark_name[0] != 0)
  424.     {
  425.         if (!pfnUnicodeStrcmp
  426.             ((const S8*)g_curr_book_cntx_p->g_nfo_book_struct.book_marks[i].bookmark_name, (const S8*)bookMarkName))
  427.         {
  428.             duplicate = 1;
  429.             entry_duplicate_book_mark_pop_up();
  430.         }
  431.         i++;
  432.     }
  433.     if (duplicate == 0)
  434.     {
  435.         ebr_frm_add_book_mark();
  436.     }
  437. }
  438. /*****************************************************************************
  439.  * FUNCTION
  440.  *  ebr_frm_add_book_mark
  441.  * DESCRIPTION
  442.  *  Entry function for Add book mark
  443.  * PARAMETERS
  444.  *  void
  445.  * RETURNS
  446.  *  void
  447.  *****************************************************************************/
  448. void ebr_frm_add_book_mark()
  449. {
  450.     /*----------------------------------------------------------------*/
  451.     /* Local Variables                                                */
  452.     /*----------------------------------------------------------------*/
  453.     S32 i = 0;
  454.     U8 bookMarkName[EBR_FRM_MAX_BOOKMARK_NAME_SIZE * ENCODING_LENGTH] = {0};
  455.     U32 size;
  456.     S32 retval, count = 0, k = 1, offset, text_offset_local = 0;
  457.     FILE_HANDLE nfo_hnd;
  458.     U32 page_id;
  459.     S32 text_offset;
  460.     U8 shared_bytes;
  461.     U8 last_showed_percentage;
  462.     S32 page_id_local, last_text_offset_y;
  463.     S8 *book_mark_name;
  464.     S16 ebr_page_size;
  465.     /*----------------------------------------------------------------*/
  466.     /* Code Body                                                      */
  467.     /*----------------------------------------------------------------*/
  468.     if (g_curr_book_cntx_p->is_book_in_unicode || g_curr_book_cntx_p->book_is_in_other_encoding_format)
  469.     {
  470.         ebr_page_size = EBR_PAGE_SIZE * 2;
  471.     }
  472.     else
  473.     {
  474.         ebr_page_size = EBR_PAGE_SIZE;
  475.     }
  476.     wgui_paging_multiline_get_current_page(
  477.         &page_id,
  478.         &text_offset,
  479.         &shared_bytes,
  480.         &last_showed_percentage,
  481.         &last_text_offset_y);
  482.     text_offset_local = text_offset;
  483.     count = 0;
  484.     while ((text_offset) >= 0)
  485.     {
  486.         text_offset = text_offset - ebr_page_size;
  487.         count++;
  488.     }
  489.     text_offset = text_offset + ebr_page_size;
  490.     page_id_local = page_id;
  491.     if (page_id_local > (EBR_RECORD_SIZE_MAX / ebr_page_size) * 2)
  492.     {
  493.         page_id_local =
  494.             page_id_local - (EBR_RECORD_SIZE_MAX / ebr_page_size) * (g_curr_book_cntx_p->gcurrent_record_id - 1);
  495.     }
  496.     while (k != (page_id_local + count))
  497.     {
  498.         k++;
  499.     }
  500.     k = 0;
  501.     offset = text_offset - 2 * (shared_bytes) + (page_id_local + count - 1) * ebr_page_size;
  502.     book_mark_name = ebr_get_book_mark_name();
  503.     pfnUnicodeStrcpy((S8*) bookMarkName, (S8*) book_mark_name);
  504.     if (!book_mark_name[0])
  505.     {
  506.         ebr_app_display_pop_up_book_mark_name_empty();
  507.         return;
  508.     }
  509.     i = 0;
  510.     while (g_curr_book_cntx_p->g_nfo_book_struct.book_marks[i].bookmark_name[0] != 0)
  511.     {
  512.         if (!pfnUnicodeStrcmp
  513.             ((const S8*)g_curr_book_cntx_p->g_nfo_book_struct.book_marks[i].bookmark_name, (const S8*)bookMarkName))
  514.         {
  515.             break;
  516.         }
  517.         i++;
  518.     }
  519.     if (i == EBR_FRM_MAX_NO_OF_BOOKMARKS)
  520.     {
  521.         /* Display Pop up that no more BookMarks can be added */
  522.         ebr_app_display_pop_up_maximum_book_marks();
  523.     }
  524.     else
  525.     {
  526.         pfnUnicodeStrcpy((PS8) g_curr_book_cntx_p->g_nfo_book_struct.book_marks[i].bookmark_name, (PS8) bookMarkName);
  527.         g_curr_book_cntx_p->g_nfo_book_struct.book_marks[i].page_id = page_id;
  528.         g_curr_book_cntx_p->g_nfo_book_struct.book_marks[i].offset = text_offset_local;
  529.         g_curr_book_cntx_p->g_nfo_book_struct.book_marks[i].shared_bytes = shared_bytes;
  530.         g_curr_book_cntx_p->g_nfo_book_struct.book_marks[i].percentage_associated_with_book_mark =
  531.             last_showed_percentage;
  532.         nfo_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->nfo_path, FS_READ_WRITE);
  533.         FS_Seek(nfo_hnd, 0, FS_FILE_BEGIN);
  534.         retval = FS_Write(
  535.                     nfo_hnd,
  536.                     &g_curr_book_cntx_p->g_nfo_book_struct,
  537.                     sizeof(g_curr_book_cntx_p->g_nfo_book_struct),
  538.                     &size);
  539.         FS_Close(nfo_hnd);
  540.         ebr_app_display_pop_up_book_mark_sucessfully_added();
  541.     }
  542. }
  543. /*****************************************************************************
  544.  * FUNCTION
  545.  *  ebr_frm_get_record_for_bookmark
  546.  * DESCRIPTION
  547.  *  Get record for BookMArk
  548.  * PARAMETERS
  549.  *  selected_index      [IN]        
  550.  * RETURNS
  551.  *  void
  552.  *****************************************************************************/
  553. void ebr_frm_get_record_for_bookmark(U32 selected_index)
  554. {
  555.     /*----------------------------------------------------------------*/
  556.     /* Local Variables                                                */
  557.     /*----------------------------------------------------------------*/
  558.     U32 filesize;
  559.     S32 page_id = 0, offset = 0, record_id = 0, shared_bytes = 0, book_size;
  560.     S16 ebr_page_size;
  561.     /*----------------------------------------------------------------*/
  562.     /* Code Body                                                      */
  563.     /*----------------------------------------------------------------*/
  564.     if (g_curr_book_cntx_p->book_is_in_other_encoding_format)
  565.     {
  566.         book_size = g_curr_book_cntx_p->g_nfo_book_struct.temp_book_size;
  567.     }
  568.     else
  569.     {
  570.         book_size = g_curr_book_cntx_p->g_nfo_book_struct.book_size;
  571.     }
  572.     if (g_curr_book_cntx_p->is_book_in_unicode || g_curr_book_cntx_p->book_is_in_other_encoding_format)
  573.     {
  574.         ebr_page_size = EBR_PAGE_SIZE * 2;
  575.     }
  576.     else
  577.     {
  578.         ebr_page_size = EBR_PAGE_SIZE;
  579.     }
  580.     filesize = book_size;
  581.     page_id = g_curr_book_cntx_p->g_nfo_book_struct.book_marks[selected_index].page_id;
  582.     offset = g_curr_book_cntx_p->g_nfo_book_struct.book_marks[selected_index].offset;
  583.     shared_bytes = g_curr_book_cntx_p->g_nfo_book_struct.book_marks[selected_index].shared_bytes;
  584.     record_id = (ebr_page_size * page_id) / EBR_RECORD_SIZE_MAX;
  585.     record_id++;
  586.     if ((page_id % (EBR_RECORD_SIZE_MAX / ebr_page_size) > 2) &&
  587.         page_id % (EBR_RECORD_SIZE_MAX / ebr_page_size) <= (EBR_RECORD_SIZE_MAX / ebr_page_size) - 2)
  588.     {
  589.         if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_PDB)
  590.         {
  591.             if ((g_curr_book_cntx_p->num_records == record_id - 1) || (g_curr_book_cntx_p->num_records == record_id))
  592.             {
  593.                 g_curr_book_cntx_p->gcurrent_record_id = g_curr_book_cntx_p->num_records - 1;
  594.                 g_curr_book_cntx_p->gnext_record_id = g_curr_book_cntx_p->gcurrent_record_id + 1;
  595.             }
  596.             else
  597.             {
  598.                 g_curr_book_cntx_p->gcurrent_record_id = record_id;
  599.                 g_curr_book_cntx_p->gnext_record_id = g_curr_book_cntx_p->gcurrent_record_id + 1;
  600.             }
  601.         }
  602.         else
  603.         {
  604.             g_curr_book_cntx_p->gcurrent_record_id = record_id;
  605.             if (page_id * ebr_page_size + EBR_RECORD_SIZE_MAX > (S32) (book_size))
  606.             {
  607.                 g_curr_book_cntx_p->gcurrent_record_id--;
  608.             }
  609.             g_curr_book_cntx_p->gnext_record_id = g_curr_book_cntx_p->gcurrent_record_id + 1;
  610.         }
  611.     }
  612.     else
  613.     {
  614.     }
  615.     if (page_id == 0)
  616.     {
  617.         g_curr_book_cntx_p->gcurrent_record_id = 1;
  618.         g_curr_book_cntx_p->gnext_record_id = 2;
  619.     }
  620.     g_curr_book_cntx_p->g_start_id = page_id;
  621.     g_curr_book_cntx_p->g_end_id = g_curr_book_cntx_p->g_start_id + 3;
  622.     g_curr_book_cntx_p->g_nfo_book_struct.current_page_id = g_curr_book_cntx_p->g_start_id;
  623. g_curr_book_cntx_p->g_nfo_book_struct.offset = 0;
  624.     g_curr_book_cntx_p->g_nfo_book_struct.jump_offset = g_curr_book_cntx_p->g_nfo_book_struct.book_marks[selected_index].offset;        
  625.     g_curr_book_cntx_p->g_nfo_book_struct.last_showed_percentage =
  626.         g_curr_book_cntx_p->g_nfo_book_struct.book_marks[selected_index].percentage_associated_with_book_mark;
  627.     ebr_frm_save_settings_in_nfo_file();
  628. }
  629. /*****************************************************************************
  630.  * FUNCTION
  631.  *  ebr_frm_convert_page_id_to_record_id
  632.  * DESCRIPTION
  633.  *  Get the record number on basis of page id
  634.  * PARAMETERS
  635.  *  page_id             [IN]        
  636.  *  text_offset         [IN]        
  637.  *  shared_bytes        [IN]        
  638.  *  record_id           [IN]        
  639.  *  record_offset       [IN]        
  640.  * RETURNS
  641.  *  void
  642.  *****************************************************************************/
  643. void ebr_frm_convert_page_id_to_record_id(
  644.         S32 page_id,
  645.         S32 text_offset,
  646.         S32 shared_bytes,
  647.         S32 *record_id,
  648.         S32 *record_offset)
  649. {
  650.     /*----------------------------------------------------------------*/
  651.     /* Local Variables                                                */
  652.     /*----------------------------------------------------------------*/
  653.     S16 ebr_page_size;
  654.     /*----------------------------------------------------------------*/
  655.     /* Code Body                                                      */
  656.     /*----------------------------------------------------------------*/
  657.     if (g_curr_book_cntx_p->is_book_in_unicode || g_curr_book_cntx_p->book_is_in_other_encoding_format)
  658.     {
  659.         ebr_page_size = EBR_PAGE_SIZE * 2;
  660.     }
  661.     else
  662.     {
  663.         ebr_page_size = EBR_PAGE_SIZE;
  664.     }
  665.     text_offset = text_offset - shared_bytes;
  666.     *record_id = (page_id / (EBR_RECORD_SIZE_MAX / ebr_page_size)) + 1;
  667.     *record_offset =
  668.         ((page_id - ((*record_id - 1) * EBR_RECORD_SIZE_MAX / ebr_page_size)) * EBR_PAGE_SIZE + text_offset) - 1;
  669.     if (*record_offset > EBR_RECORD_SIZE_MAX / 2 && *record_id < g_curr_book_cntx_p->num_records)
  670.     {
  671.         ++(*record_id);
  672.         *record_offset = *record_offset % (EBR_RECORD_SIZE_MAX / 2);
  673.     }
  674. }
  675. /*****************************************************************************
  676.  * FUNCTION
  677.  *  ebr_frm_start_search_timer
  678.  * DESCRIPTION
  679.  *  Timer handler to continue searching
  680.  * PARAMETERS
  681.  *  search_type                 [IN]        
  682.  *  ebr_search_string_input     [IN]        
  683.  * RETURNS
  684.  *  void
  685.  *****************************************************************************/
  686. void ebr_frm_start_search_timer(void)
  687. {
  688.     MMI_BOOL status;
  689.     StopTimer(EBR_SEARCH_BLOCK_TIMER);
  690.     /* if Ebook application is exited */
  691.     if (!IsScreenPresent(EBOOK_OPEN_SCREENID))
  692.     {
  693.         return;
  694.     }
  695.     status = ebr_frm_search_string_algo(
  696.                         (ebr_app_search_type_enum) g_curr_book_cntx_p->ebr_last_search_type,
  697.                         (S8*) g_curr_book_cntx_p->ebr_last_search_string_input,
  698.                         MMI_TRUE);
  699.     /* search not complete */
  700.     if (status == 0xFF)
  701.     {
  702.         return;
  703.     }
  704.     /* string has been found */    
  705.     else if (status == 1)
  706.     {
  707.         if (!ebr_frm_get_auto_scroll_status())
  708.         {
  709.             gui_paging_reset_auto_scroll();
  710.         }
  711.         ebr_app_search_result_successful(g_curr_book_cntx_p->ebr_last_search_type);
  712.         ebr_app_delete_upto_open_book_screen_id();
  713.         GoBackHistory();
  714.         ebr_frm_set_data_for_display();
  715.     }
  716.     /* string has been  */
  717.     else
  718.     {
  719. if(status==2)
  720. {
  721. ebr_app_search_result_invalid();
  722. }
  723. else
  724. {
  725.                    ebr_app_search_result_unsucessfull();
  726.               }
  727.     }
  728. }
  729. /*****************************************************************************
  730.  * FUNCTION
  731.  *  ebr_frm_search_string_algo
  732.  * DESCRIPTION
  733.  *  String search algo
  734.  * PARAMETERS
  735.  *  search_type                 [IN]        
  736.  *  ebr_search_string_input     [IN]        
  737.  * RETURNS
  738.  *  void
  739.  *****************************************************************************/
  740. pBOOL ebr_frm_search_string_algo(ebr_app_search_type_enum search_type, S8 *ebr_search_string_input, MMI_BOOL timeout)
  741. {
  742.     /*----------------------------------------------------------------*/
  743.     /* Local Variables                                                */
  744.     /*----------------------------------------------------------------*/
  745.     FILE_HANDLE nfo_hnd_local;
  746.     FILE_HANDLE file_hnd;
  747.     S32 ebr_search_from_offset = -1;
  748.     S32 search_record_id = -1,search_from_record_id;
  749.     U8 mmiEncoding = 0;
  750.     U32 page_id;
  751.     S32 text_offset, last_text_offset_y;
  752.     S8 search_string_input[(EBR_MAX_STR_SEARCH_LENGTH + 1) * ENCODING_LENGTH], string_length = pfnUnicodeStrlen((const S8*)ebr_search_string_input);
  753.     U8 shared_bytes;
  754.     U8 last_showed_percentage;
  755.     pBOOL search_status = 0;
  756.     U32 size, count = 0;
  757.     S16 ebr_page_size;
  758.     /*----------------------------------------------------------------*/
  759.     /* Code Body                                                      */
  760.     /*----------------------------------------------------------------*/
  761.     if (g_curr_book_cntx_p->is_book_in_unicode || g_curr_book_cntx_p->book_is_in_other_encoding_format)
  762.     {
  763.         ebr_page_size = EBR_PAGE_SIZE * 2;
  764.     }
  765.     else
  766.     {
  767.         ebr_page_size = EBR_PAGE_SIZE;
  768.     }
  769.     /* Need the file handle over here to open the boook and search in it */
  770.     memset((void*)g_curr_book_cntx_p->start, 0, EBR_RECORD_SIZE_MAX * 2);
  771.     pfnUnicodeStrcpy(search_string_input, ebr_search_string_input);
  772.     wgui_paging_multiline_get_current_page(
  773.         &page_id,
  774.         &text_offset,
  775.         &shared_bytes,
  776.         &last_showed_percentage,
  777.         &last_text_offset_y);
  778.     /* continue searching for previous stop */
  779.     if (timeout == MMI_TRUE)
  780.     {
  781.         search_record_id = g_curr_book_cntx_p->ebr_last_search_record_id;
  782.         ebr_search_from_offset = g_curr_book_cntx_p->ebr_last_offset_string;
  783.     }
  784.     else if (g_curr_book_cntx_p->ebr_last_offset_string == -1)
  785.     {
  786.         ebr_frm_convert_page_id_to_record_id(
  787.             page_id,
  788.             text_offset,
  789.             shared_bytes,
  790.             &search_record_id,
  791.             &ebr_search_from_offset);
  792.     }
  793.     else if (pfnUnicodeStrcmp(ebr_search_string_input, g_curr_book_cntx_p->ebr_last_search_string_input) != 0 ||
  794.              g_curr_book_cntx_p->ebr_last_search_type != search_type)
  795.     {
  796.         ebr_frm_convert_page_id_to_record_id(
  797.             page_id,
  798.             text_offset,
  799.             shared_bytes,
  800.             &search_record_id,
  801.             &ebr_search_from_offset);
  802.         g_curr_book_cntx_p->find_next_first_flag = 0;
  803.         g_curr_book_cntx_p->search_found_flag = 0;
  804.         g_curr_book_cntx_p->search_string_count = 0;
  805.     }
  806.     else if (page_id != g_curr_book_cntx_p->ebr_last_page_id || g_curr_book_cntx_p->ebr_last_text_offset != text_offset)
  807.     {
  808.         ebr_frm_convert_page_id_to_record_id(
  809.             page_id,
  810.             text_offset,
  811.             shared_bytes,
  812.             &search_record_id,
  813.             &ebr_search_from_offset);
  814.     }
  815.     else
  816.     {
  817.         search_record_id = g_curr_book_cntx_p->ebr_last_search_record_id;
  818.         ebr_search_from_offset = g_curr_book_cntx_p->ebr_last_offset_string;
  819.     }
  820.     if (g_curr_book_cntx_p->find_next_first_flag == 0)
  821.     {
  822.         g_curr_book_cntx_p->find_next_first_flag = 1;
  823.         g_curr_book_cntx_p->search_record_id_first = search_record_id;
  824.         g_curr_book_cntx_p->ebr_search_from_offset_first = ebr_search_from_offset;
  825.     }
  826.     nfo_hnd_local = ebr_frm_get_nfo_handle();
  827.     if (g_curr_book_cntx_p->book_is_in_other_encoding_format)
  828.     {
  829.         file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->temp_book_name_path, FS_READ_ONLY);
  830.     }
  831.     else
  832.     {
  833.         file_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->book_name_path, FS_READ_ONLY);
  834.     }
  835. search_from_record_id = search_record_id;
  836.     while (search_record_id <= g_curr_book_cntx_p->num_records)
  837.     {
  838.         /* Since MMI will be hung on Ebook searching process if the file size is too large, we search for some records and start a timer to continue. */
  839.         count++;
  840.         if (count > EBR_FRM_SEARCH_BLOCK)
  841.         {
  842.             g_curr_book_cntx_p->ebr_last_offset_string = -1;
  843.             g_curr_book_cntx_p->ebr_last_search_record_id = search_record_id;
  844.             g_curr_book_cntx_p->ebr_last_search_type = search_type;
  845.             g_curr_book_cntx_p->ebr_search_from_offset_first = ebr_search_from_offset;
  846.             pfnUnicodeStrcpy(g_curr_book_cntx_p->ebr_last_search_string_input, ebr_search_string_input);
  847. FS_Close(nfo_hnd_local);
  848. FS_Close(file_hnd);
  849.             
  850.             StartTimer(EBR_SEARCH_BLOCK_TIMER, EBR_FRM_SEARCH_BREAK_TIMER, ebr_frm_start_search_timer);
  851.             /* Search not complete */
  852.             return 0xFF;
  853.         }
  854.         
  855.         if (string_length == 0)
  856.         {
  857.             search_status = 0;
  858.             break;
  859.         }
  860.         memset((void*)g_curr_book_cntx_p->start, 0, EBR_RECORD_SIZE_MAX * 2);
  861.         memset((void*)g_curr_book_cntx_p->buffer, 0, EBR_RECORD_SIZE_MAX);
  862.         copy_record_in_passed_buffer(
  863.             file_hnd,
  864.             search_record_id,
  865.             (U8*) g_curr_book_cntx_p->buffer,
  866.             (U8*) g_curr_book_cntx_p->start,
  867.             &size);
  868.         mmiEncoding = mmi_ebook_util_get_chset(g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format);
  869.         switch (mmiEncoding)
  870.         {
  871.             case MMI_CHSET_UCS2:
  872.                 pfnUnicodeStrncpy(
  873.                     (PS8) g_curr_book_cntx_p->start,
  874.                     (PS8) g_curr_book_cntx_p->buffer,
  875.                     EBR_RECORD_SIZE_MAX);
  876.                 break;
  877.             case MMI_CHSET_WESTERN_WIN:
  878.                 AnsiiNToUnicodeString(
  879.                     (PS8) g_curr_book_cntx_p->start,
  880.                     (PS8) g_curr_book_cntx_p->buffer,
  881.                     EBR_RECORD_SIZE_MAX);
  882.                 break;
  883.             default:
  884.                 pfnUnicodeStrncpy(
  885.                     (PS8) g_curr_book_cntx_p->start,
  886.                     (PS8) g_curr_book_cntx_p->buffer,
  887.                     EBR_RECORD_SIZE_MAX);
  888.                 /* mmi_chset_convert ((mmi_chset_enum)mmiEncoding,MMI_CHSET_UCS2, (char*)g_curr_book_cntx_p->start, (char*)g_curr_book_cntx_p->buffer, EBR_RECORD_SIZE_MAX); */
  889.                 break;
  890.         }
  891.         if (search_type == EBR_APP_CASE_IN_SENSITIVE)
  892.         {
  893.             ebr_frm_convert_to_upper((S16*) g_curr_book_cntx_p->start);
  894.             ebr_frm_convert_to_upper((S16*) search_string_input);
  895.         }
  896.         //   if(ebr_search_from_offset==0)
  897.         //        ebr_search_from_offset=-1;
  898.         search_status = ebr_frm_bm_search((S16*) g_curr_book_cntx_p->start, (S16*) search_string_input, &ebr_search_from_offset,size);
  899. if(search_status==2)
  900. {
  901. FS_Close(nfo_hnd_local);
  902. FS_Close(file_hnd);
  903.             break;
  904. }
  905.         if (search_status == 0)
  906.         {
  907.             if (g_curr_book_cntx_p->search_record_id_first == search_record_id &&
  908.                 g_curr_book_cntx_p->last_record_flag == 1 && g_curr_book_cntx_p->search_found_flag == 0)
  909.             {
  910.                 g_curr_book_cntx_p->last_record_flag = 0;
  911.                 /* g_curr_book_cntx_p->find_next_first_flag=0; */
  912.                 break;
  913.             }
  914.             search_record_id++;
  915.             ebr_search_from_offset = 0;
  916. /* When the total record of the file is 1, and search offset is not 0, we should still search from beginning of first record. */
  917. if((search_from_record_id==1) && (search_record_id == g_curr_book_cntx_p->num_records + 1) && (g_curr_book_cntx_p->num_records != 1))
  918. {
  919. g_curr_book_cntx_p->last_record_flag = 0;
  920. break;
  921. }
  922.             if (search_record_id == g_curr_book_cntx_p->num_records + 1)
  923.             {
  924.                 search_record_id = 1;
  925. search_from_record_id = search_record_id;
  926.                 g_curr_book_cntx_p->last_record_flag = 1;
  927. ebr_search_from_offset = -1;
  928.             }
  929.         }
  930.         else
  931.         {
  932.             g_curr_book_cntx_p->search_found_flag = 1;
  933.             if (g_curr_book_cntx_p->ebr_last_search_record_id == search_record_id &&
  934.                 g_curr_book_cntx_p->ebr_last_offset_string == ebr_search_from_offset &&
  935.                 g_curr_book_cntx_p->ebr_last_search_type == search_type &&
  936.                 string_length == g_curr_book_cntx_p->ebr_search_strlen &&
  937.                 page_id == g_curr_book_cntx_p->ebr_last_page_id &&
  938.                 g_curr_book_cntx_p->ebr_last_text_offset == text_offset)
  939.             {
  940.                 search_status = 0;
  941.                 g_curr_book_cntx_p->last_record_flag = 0;
  942.                 g_curr_book_cntx_p->search_found_flag = 0;
  943.                 g_curr_book_cntx_p->search_string_count = 0;
  944.             }
  945.             else
  946.             {
  947.                 g_curr_book_cntx_p->search_string_count++;
  948.                 /* if(g_curr_book_cntx_p->search_record_id_first==search_record_id && g_curr_book_cntx_p->last_record_flag==1 && ebr_search_from_offset > g_curr_book_cntx_p->ebr_search_from_offset_first)
  949.                    {
  950.                    g_curr_book_cntx_p->search_string_count=1;
  951.                    g_curr_book_cntx_p->last_record_flag=0;
  952.                    } */
  953.             }
  954.             break;
  955.         }
  956.     }
  957.     if (search_status == 1)
  958.     {
  959.         g_curr_book_cntx_p->g_nfo_book_struct.current_page_id =
  960.             (search_record_id - 1) * EBR_RECORD_SIZE_MAX / ebr_page_size + ((ebr_search_from_offset) / EBR_PAGE_SIZE);
  961.         if (g_curr_book_cntx_p->g_nfo_book_struct.current_page_id == 0)
  962.         {
  963.             g_curr_book_cntx_p->g_nfo_book_struct.jump_offset = ebr_search_from_offset;
  964.         }
  965.         else
  966.         {
  967.             g_curr_book_cntx_p->g_nfo_book_struct.current_page_id--;
  968.             g_curr_book_cntx_p->g_nfo_book_struct.jump_offset =
  969.                 (ebr_search_from_offset) % EBR_PAGE_SIZE + EBR_PAGE_SIZE;
  970.         }
  971.         g_curr_book_cntx_p->g_nfo_book_struct.offset = 0;
  972.         FS_Seek(nfo_hnd_local, 0, FS_FILE_BEGIN);
  973.         FS_Write(
  974.             nfo_hnd_local,
  975.             &g_curr_book_cntx_p->g_nfo_book_struct,
  976.             sizeof(g_curr_book_cntx_p->g_nfo_book_struct),
  977.             &size);
  978.         g_curr_book_cntx_p->ebr_search_strlen = pfnUnicodeStrlen((const S8*)ebr_search_string_input);
  979.         g_curr_book_cntx_p->highlight_string_flag = 1;
  980.         g_curr_book_cntx_p->ebr_last_search_record_id = search_record_id;
  981.         g_curr_book_cntx_p->ebr_last_search_type = search_type;
  982.         g_curr_book_cntx_p->ebr_last_offset_string = ebr_search_from_offset;
  983.         g_curr_book_cntx_p->ebr_last_page_id = page_id;
  984.         g_curr_book_cntx_p->ebr_last_text_offset = text_offset;
  985.         pfnUnicodeStrcpy(g_curr_book_cntx_p->ebr_last_search_string_input, ebr_search_string_input);
  986.         g_curr_book_cntx_p->search_flag_is_on = 1;
  987.         /* g_curr_book_cntx_p->search_found_flag=0; */
  988.     }
  989.     else
  990.     {
  991.         g_curr_book_cntx_p->ebr_last_offset_string = -1;
  992.         /* g_curr_book_cntx_p->ebr_last_offset_string=ebr_search_from_offset; */
  993.         g_curr_book_cntx_p->ebr_last_page_id = page_id;
  994.         g_curr_book_cntx_p->ebr_last_text_offset = text_offset;
  995.         g_curr_book_cntx_p->ebr_last_search_type = search_type;
  996.         pfnUnicodeStrcpy(g_curr_book_cntx_p->ebr_last_search_string_input, ebr_search_string_input);
  997.         g_curr_book_cntx_p->search_flag_is_on = 0;
  998.         /* g_curr_book_cntx_p->search_found_flag=0; */
  999.     }
  1000.     FS_Close(nfo_hnd_local);
  1001.     FS_Close(file_hnd);
  1002.     return search_status;
  1003. }
  1004. /*****************************************************************************
  1005.  * FUNCTION
  1006.  *  ebr_frm_search_string_algo_find_next
  1007.  * DESCRIPTION
  1008.  *  String search algo for find next
  1009.  * PARAMETERS
  1010.  *  void
  1011.  * RETURNS
  1012.  *  void
  1013.  *****************************************************************************/
  1014. pBOOL ebr_frm_search_string_algo_find_next(void)
  1015. {
  1016.     /*----------------------------------------------------------------*/
  1017.     /* Local Variables                                                */
  1018.     /*----------------------------------------------------------------*/
  1019.     pBOOL search_status;
  1020.     /*----------------------------------------------------------------*/
  1021.     /* Code Body                                                      */
  1022.     /*----------------------------------------------------------------*/
  1023.     g_curr_book_cntx_p->find_next_flag = TRUE;
  1024.     search_status = ebr_frm_search_string_algo(
  1025.                         (ebr_app_search_type_enum) g_curr_book_cntx_p->ebr_last_search_type,
  1026.                         (S8*) g_curr_book_cntx_p->ebr_last_search_string_input,
  1027.                         MMI_FALSE);
  1028.     g_curr_book_cntx_p->find_next_flag = FALSE;
  1029.     return search_status;
  1030. }
  1031. /*****************************************************************************
  1032.  * FUNCTION
  1033.  *  ebr_frm_set_data_for_display
  1034.  * DESCRIPTION
  1035.  *  get the current position from GUI
  1036.  * PARAMETERS
  1037.  *  void
  1038.  * RETURNS
  1039.  *  void
  1040.  *****************************************************************************/
  1041. void ebr_frm_set_data_for_display(void)
  1042. {
  1043.     /*----------------------------------------------------------------*/
  1044.     /* Local Variables                                                */
  1045.     /*----------------------------------------------------------------*/
  1046.     U8 shared_bytes;
  1047.     S32 last_text_offset_y;
  1048.     /*----------------------------------------------------------------*/
  1049.     /* Code Body                                                      */
  1050.     /*----------------------------------------------------------------*/
  1051.     wgui_paging_multiline_get_current_page(
  1052.         &g_curr_book_cntx_p->last_displayed_page_id,
  1053.         &g_curr_book_cntx_p->last_displayed_offset,
  1054.         &shared_bytes,
  1055.         &g_curr_book_cntx_p->g_nfo_book_struct.last_showed_percentage,
  1056.         &last_text_offset_y);
  1057. }
  1058. /*****************************************************************************
  1059.  * FUNCTION
  1060.  *  ebr_frm_reset_for_new_book
  1061.  * DESCRIPTION
  1062.  *  Reset the values for a new file.
  1063.  * PARAMETERS
  1064.  *  void
  1065.  * RETURNS
  1066.  *  void
  1067.  *****************************************************************************/
  1068. ebr_frm_nfo_create_type_errors_enum ebr_frm_reset_for_new_book(void)
  1069. {
  1070.     /*----------------------------------------------------------------*/
  1071.     /* Local Variables                                                */
  1072.     /*----------------------------------------------------------------*/
  1073.     ebr_frm_nfo_create_type_errors_enum error_type = EBR_FRM_NFO_CREATE_SUCCESS;
  1074.     /*----------------------------------------------------------------*/
  1075.     /* Code Body                                                      */
  1076.     /*----------------------------------------------------------------*/
  1077.     g_curr_book_cntx_p->ebr_frm_end_book_flag = 1;
  1078.     g_curr_book_cntx_p->is_book_in_unicode = FALSE;
  1079.     g_curr_book_cntx_p->book_is_in_other_encoding_format = FALSE;
  1080.     g_curr_book_cntx_p->pdb_converted_to_text = FALSE;
  1081.     ebr_frm_reset_find_next_data();
  1082.     ebr_frm_set_file_type();
  1083.     if (!g_curr_book_cntx_p->src_application)
  1084.     {
  1085.         if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_PDB)
  1086.         {
  1087.             error_type = ebr_frm_open_book_create_nfo_file_pdb(g_curr_book_cntx_p->nfo_name);
  1088.         }
  1089.         else
  1090.         {
  1091.             error_type = ebr_frm_open_book_create_nfo_file_txt(g_curr_book_cntx_p->nfo_name);
  1092.         }
  1093.         g_curr_book_cntx_p->src_application = EBR_FRM_SRC_APP_EBOOK;
  1094.     }
  1095.     return error_type;
  1096. }
  1097. /*****************************************************************************
  1098.  * FUNCTION
  1099.  *  ebr_frm_set_file_type
  1100.  * DESCRIPTION
  1101.  *  
  1102.  * PARAMETERS
  1103.  *  void
  1104.  * RETURNS
  1105.  *  void
  1106.  *****************************************************************************/
  1107. void ebr_frm_set_file_type(void)
  1108. {
  1109.     /*----------------------------------------------------------------*/
  1110.     /* Local Variables                                                */
  1111.     /*----------------------------------------------------------------*/
  1112.     S16 strlen_file_name = 0;
  1113.     /*----------------------------------------------------------------*/
  1114.     /* Code Body                                                      */
  1115.     /*----------------------------------------------------------------*/
  1116.     strlen_file_name = pfnUnicodeStrlen((const S8*)g_curr_book_cntx_p->nfo_name);
  1117.     if ((g_curr_book_cntx_p->nfo_name[strlen_file_name * 2 - 6] == 't') ||
  1118.         (g_curr_book_cntx_p->nfo_name[strlen_file_name * 2 - 6] == 'T'))
  1119.     {
  1120.         g_curr_book_cntx_p->gbook_type = EBR_FRM_FILE_TYPE_TXT;
  1121.     }
  1122.     else
  1123.     {
  1124.         g_curr_book_cntx_p->gbook_type = EBR_FRM_FILE_TYPE_PDB;
  1125.     }
  1126. }
  1127. /*****************************************************************************
  1128.  * FUNCTION
  1129.  *  ebr_frm_convert_to_upper
  1130.  * DESCRIPTION
  1131.  *  CCase Conversion
  1132.  * PARAMETERS
  1133.  *  decoded_buffer      [IN]        
  1134.  * RETURNS
  1135.  *  void
  1136.  *****************************************************************************/
  1137. void ebr_frm_convert_to_upper(S16 *decoded_buffer)
  1138. {
  1139.     /*----------------------------------------------------------------*/
  1140.     /* Local Variables                                                */
  1141.     /*----------------------------------------------------------------*/
  1142.     S32 length, i;
  1143.     /*----------------------------------------------------------------*/
  1144.     /* Code Body                                                      */
  1145.     /*----------------------------------------------------------------*/
  1146.     length = pfnUnicodeStrlen((const S8*)decoded_buffer);
  1147.     for (i = 0; i < length; i++)
  1148.     {
  1149.         if ((decoded_buffer[i] >= 97) && (decoded_buffer[i] <= 122))
  1150.         {
  1151.             decoded_buffer[i] = decoded_buffer[i] - 32;
  1152.         }
  1153.     }
  1154. }
  1155. /*****************************************************************************
  1156.  * FUNCTION
  1157.  *  ebr_frm_bm_search
  1158.  * DESCRIPTION
  1159.  *  Search Algo
  1160.  * PARAMETERS
  1161.  *  text_in_UCS2        [IN]        
  1162.  *  pat                 [IN]        
  1163.  *  start_pos           [IN]        
  1164.  * RETURNS
  1165.  *  void
  1166.  *****************************************************************************/
  1167. S16 ebr_frm_bm_search(S16 *text_in_UCS2, S16 *pat, S32 *start_pos,U32 size)
  1168. {
  1169.     /*----------------------------------------------------------------*/
  1170.     /* Local Variables                                                */
  1171.     /*----------------------------------------------------------------*/
  1172.     S16 i;
  1173.     S32 len = pfnUnicodeStrlen((const S8*)pat);
  1174.     S32 temp, temp1, temp2, buffer_length = pfnUnicodeStrlen((const S8*)text_in_UCS2);
  1175.     S32 start = len - 1 + (*start_pos + 1);
  1176.     S16 pos_array[32] = {0};
  1177.     S16 char_position_in_UCS2, char_position_in_ascii;
  1178.     S32 clus_len = 1;
  1179. S32 s_size = size;
  1180.     /*----------------------------------------------------------------*/
  1181.     /* Code Body                                                      */
  1182.     /*----------------------------------------------------------------*/
  1183. /* Remove '' */
  1184.     for(s_size = s_size/2 - 1; s_size >= 0; s_size--)
  1185.     {
  1186.         if (text_in_UCS2[s_size] != 0)
  1187.         {
  1188.             break;
  1189.         }
  1190.     }
  1191. /* Set length of text */
  1192.     s_size++;
  1193.     if (s_size-6 > 0)
  1194.     {
  1195.         if(buffer_length < (s_size-6) ) /* txt file with end with "00 00 00 00 00 00 00 00 F2 F2 F2 F2"*/
  1196.         {
  1197.      return 2;
  1198.         }
  1199.     }
  1200.     for (i = 0; i < len; i++)
  1201.     {
  1202.         pos_array[i] = len - ((i) + 1);
  1203.     }
  1204.     temp = len - 1; /* it is taken to remove the need of table */
  1205.     temp2 = temp1 = len - 2;
  1206.     while (temp >= 0)
  1207.     {
  1208.         while (temp1 >= 0)
  1209.         {
  1210.             if (pat[temp] != pat[temp1])
  1211.             {
  1212.                 temp1--;
  1213.             }
  1214.             else
  1215.             {
  1216.                 pos_array[temp1] = pos_array[temp];
  1217.                 temp1--;
  1218.             }
  1219.         }
  1220.         temp1 = temp2 - 1;
  1221.         temp--;
  1222.     }
  1223.     while (start < buffer_length)
  1224.     {
  1225.         S32 count = 0, prev_start = 0;
  1226.         while (count < len)
  1227.         {
  1228.             if (text_in_UCS2[start - count] != pat[(len - 1) - count])
  1229.             {
  1230.                 break;
  1231.             }
  1232.             else
  1233.             {
  1234.                 count++;
  1235.             }
  1236.         }
  1237.     #ifdef __MMI_LANG_HINDI__
  1238.         if (count == len)
  1239.         {
  1240.             U16 cluster_buffer[EBR_MAX_STR_SEARCH_LENGTH];  /* just to fill the cluster for the purpose of getting its length */
  1241.             clus_len = 0;
  1242.             init_cluster_start_p((PU8) (text_in_UCS2 + start));
  1243.             init_cluster_end_p((PU8) (text_in_UCS2 + (EBR_MAX_STR_SEARCH_LENGTH / 2)));
  1244.             clus_len = hf_get_cluster(cluster_buffer);
  1245.         }
  1246.     #endif /* __MMI_LANG_HINDI__ */ 
  1247.         if (count == len && clus_len == 1)
  1248.         {
  1249.             *start_pos = (start - count + 1);
  1250.             break;
  1251.         }
  1252.         else
  1253.         {
  1254.             char_position_in_UCS2 = 0;
  1255.             char_position_in_ascii = 0;
  1256.             prev_start = start;
  1257.             while (char_position_in_ascii < len && text_in_UCS2[start - count] != pat[char_position_in_UCS2])
  1258.             {
  1259.                 char_position_in_UCS2++;
  1260.                 char_position_in_ascii++;
  1261.             }
  1262.             if (text_in_UCS2[start - count] == pat[char_position_in_UCS2])
  1263.             {
  1264.                 if (pos_array[char_position_in_ascii] - count < 0)
  1265.                 {
  1266.                     start += len;
  1267.                 }
  1268.                 else
  1269.                 {
  1270.                     start += (pos_array[char_position_in_ascii] - count);
  1271.                 }
  1272.             }
  1273.             else
  1274.             {
  1275. start += (len - count);
  1276.             }
  1277.             if (prev_start == start)
  1278.             {
  1279.                 start += len;
  1280.             }
  1281.         }
  1282.     }
  1283.     if (start >= buffer_length)
  1284.     {
  1285.         return 0;
  1286.     }
  1287.     else
  1288.     {
  1289.         return 1;
  1290.     }
  1291. }
  1292. /*****************************************************************************
  1293.  * FUNCTION
  1294.  *  gui_paging_multiline_input_box_get_page
  1295.  * DESCRIPTION
  1296.  *  Create the linked list
  1297.  * PARAMETERS
  1298.  *  start_id            [IN]        
  1299.  *  end_id              [IN]        
  1300.  *  buffer_local        [IN]        
  1301.  * RETURNS
  1302.  *  void
  1303.  *****************************************************************************/
  1304. void gui_paging_multiline_input_box_get_page(U32 start_id, U32 end_id, PU8 buffer_local)
  1305. {
  1306.     /*----------------------------------------------------------------*/
  1307.     /* Local Variables                                                */
  1308.     /*----------------------------------------------------------------*/
  1309.     /* Code Implementation to get the next page */
  1310.     U8 mmiEncoding = 0;
  1311.     S32 buffer_length;
  1312.     S16 ebr_page_size;
  1313.     U8* buffer_start;
  1314. U8 UCS2headerle[] = {0xFF,0xFE};
  1315.     U8 UCS2headerbe[] = {0xFE,0xFF};
  1316.     /*----------------------------------------------------------------*/
  1317.     /* Code Body                                                      */
  1318.     /*----------------------------------------------------------------*/
  1319.     g_curr_book_cntx_p->g_start_id = start_id;
  1320.     g_curr_book_cntx_p->g_end_id = end_id;
  1321.     ebr_frm_get_record(end_id);
  1322.     if (g_curr_book_cntx_p->is_book_in_unicode || g_curr_book_cntx_p->book_is_in_other_encoding_format)
  1323.     {
  1324.         ebr_page_size = EBR_PAGE_SIZE * 2;
  1325.     }
  1326.     else
  1327.     {
  1328.         ebr_page_size = EBR_PAGE_SIZE;
  1329.     }
  1330.     end_id -= (EBR_RECORD_SIZE_MAX / (ebr_page_size)) * (g_curr_book_cntx_p->gcurrent_record_id - 1);
  1331.     memset(g_curr_book_cntx_p->buffer, 0, EBR_RECORD_SIZE_MAX);
  1332.     memcpy(g_curr_book_cntx_p->buffer, g_curr_book_cntx_p->start + ebr_page_size * (end_id), ebr_page_size);
  1333.     mmiEncoding = mmi_ebook_util_get_chset(g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format);
  1334.     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)    
  1335.     {
  1336.         buffer_start = g_curr_book_cntx_p->buffer;
  1337.         
  1338.         while (!pfnUnicodeStrncmp((S8*)buffer_start, (S8*)UCS2headerle,1))
  1339.         {
  1340.             buffer_start[0] = WHITE_SPACE;
  1341.             buffer_start[1] = 0;
  1342.             buffer_start += 2;
  1343.         }
  1344.         while (!pfnUnicodeStrncmp((S8*)buffer_start, (S8*)UCS2headerbe,1))
  1345.         {
  1346.             buffer_start[0] = WHITE_SPACE;
  1347.             buffer_start[1] = 0;
  1348.             buffer_start += 2;
  1349.         }
  1350.     }
  1351.     memset(buffer_local, 0, EBR_PAGE_SIZE * 2);
  1352.     switch (mmiEncoding)
  1353.     {
  1354.         case MMI_CHSET_UCS2:
  1355.             if (g_curr_book_cntx_p->is_book_in_unicode)
  1356.             {
  1357.                 memcpy(buffer_local, g_curr_book_cntx_p->buffer, ebr_page_size);
  1358.             }
  1359.             else
  1360.             {
  1361.                 pfnUnicodeStrncpy((PS8) buffer_local, (PS8) g_curr_book_cntx_p->buffer, ebr_page_size);
  1362.             }
  1363.             break;
  1364.         case MMI_CHSET_WESTERN_WIN:
  1365.             AnsiiNToUnicodeString((PS8) buffer_local, (PS8) g_curr_book_cntx_p->buffer, ebr_page_size);
  1366.             break;
  1367.         default:
  1368.             if (g_curr_book_cntx_p->is_book_in_unicode)
  1369.             {
  1370.                 /* memset(g_curr_book_cntx_p->page_buffer,0,EBR_PAGE_SIZE*2); */
  1371.                 buffer_length = mmi_chset_convert(
  1372.                                     (mmi_chset_enum) mmiEncoding,
  1373.                                     MMI_CHSET_UCS2,
  1374.                                     (char*)g_curr_book_cntx_p->buffer,
  1375.                                     (char*)buffer_local,
  1376.                                     ebr_page_size);
  1377.                 /* memcpy(buffer_local,g_curr_book_cntx_p->page_buffer,buffer_length); */
  1378.             }
  1379.             else
  1380.                 //AnsiiNToUnicodeString((PS8)buffer_local,(PS8)g_curr_book_cntx_p->buffer,ebr_page_size);
  1381.                 //pfnUnicodeStrncpy((PS8)buffer_local,(PS8)g_curr_book_cntx_p->buffer,ebr_page_size);
  1382.             {
  1383.                 memcpy(buffer_local, g_curr_book_cntx_p->buffer, ebr_page_size);
  1384.                 /* pfnUnicodeStrncpy((PS8) buffer_local, (PS8) g_curr_book_cntx_p->buffer, ebr_page_size); */
  1385.             }
  1386.             break;
  1387.     }
  1388.     buffer_length = pfnUnicodeStrlen((const S8*)buffer_local);
  1389. }
  1390. /*****************************************************************************
  1391.  * FUNCTION
  1392.  *  mmi_ebook_util_get_chset
  1393.  * DESCRIPTION
  1394.  *  Get the encoding scheme
  1395.  * PARAMETERS
  1396.  *  src_chset       [IN]        
  1397.  * RETURNS
  1398.  *  U8
  1399.  *****************************************************************************/
  1400. U8 mmi_ebook_util_get_chset(U8 src_chset)
  1401. {
  1402.     /*----------------------------------------------------------------*/
  1403.     /* Local Variables                                                */
  1404.     /*----------------------------------------------------------------*/
  1405.     /*----------------------------------------------------------------*/
  1406.     /* Code Body                                                      */
  1407.     /*----------------------------------------------------------------*/
  1408.     switch (src_chset)
  1409.     {
  1410.         case EBOOK_UCS:
  1411.             return MMI_CHSET_UCS2;
  1412.         case EBOOK_UTF8:
  1413.             return MMI_CHSET_UTF8;
  1414.     #ifdef __MMI_CHSET_BIG5__
  1415.         case EBOOK_BIG5:
  1416.             return MMI_CHSET_BIG5;
  1417.     #endif /* __MMI_CHSET_BIG5__ */ 
  1418.     #ifdef __MMI_CHSET_GB2312__
  1419.         case EBOOK_GB2312:
  1420.             return MMI_CHSET_GB2312;
  1421.     #endif /* __MMI_CHSET_GB2312__ */ 
  1422.     #ifdef __MMI_CHSET_ARABIC_ISO__
  1423.         case EBOOK_ARABIC_ISO:
  1424.             return MMI_CHSET_ARABIC_ISO;
  1425.     #endif /* __MMI_CHSET_ARABIC_ISO__ */ 
  1426.     #ifdef __MMI_CHSET_ARABIC_WIN__
  1427.         case EBOOK_ARABIC_WINDOWS:
  1428.             return MMI_CHSET_ARABIC_WIN;
  1429.     #endif /* __MMI_CHSET_ARABIC_WIN__ */ 
  1430.     #ifdef __MMI_CHSET_BALTIC_ISO__
  1431.         case EBOOK_BALTIC_ISO:
  1432.             return MMI_CHSET_BALTIC_ISO;
  1433.     #endif /* __MMI_CHSET_BALTIC_ISO__ */ 
  1434.     #ifdef __MMI_CHSET_BALTIC_WIN__
  1435.         case EBOOK_BALTIC_WINDOWS:
  1436.             return MMI_CHSET_BALTIC_WIN;
  1437.     #endif /* __MMI_CHSET_BALTIC_WIN__ */ 
  1438.     #ifdef __MMI_CHSET_CEURO_ISO__
  1439.         case EBOOK_CENTRAL_EUROPEAN_ISO:
  1440.             return MMI_CHSET_CEURO_ISO;
  1441.     #endif /* __MMI_CHSET_CEURO_ISO__ */ 
  1442.     #ifdef __MMI_CHSET_CEURO_WIN__
  1443.         case EBOOK_CENTRAL_EUROPEAN_WINDOWS:
  1444.             return MMI_CHSET_CEURO_WIN;
  1445.     #endif /* __MMI_CHSET_CEURO_WIN__ */ 
  1446.     #ifdef __MMI_CHSET_GREEK_ISO__
  1447.         case EBOOK_GREEK_ISO:
  1448.             return MMI_CHSET_GREEK_ISO;
  1449.     #endif /* __MMI_CHSET_GREEK_ISO__ */ 
  1450.     #ifdef __MMI_CHSET_GREEK_WIN__
  1451.         case EBOOK_GREEK_WINDOWS:
  1452.             return MMI_CHSET_GREEK_WIN;
  1453.     #endif /* __MMI_CHSET_GREEK_WIN__ */ 
  1454.     #ifdef __MMI_CHSET_HEBREW_ISO__
  1455.         case EBOOK_HEBREW_ISO:
  1456.             return MMI_CHSET_HEBREW_ISO;
  1457.     #endif /* __MMI_CHSET_HEBREW_ISO__ */ 
  1458.     #ifdef __MMI_CHSET_HEBREW_WIN__
  1459.         case EBOOK_HEBREW_WINDOWS:
  1460.             return MMI_CHSET_HEBREW_WIN;
  1461.     #endif /* __MMI_CHSET_HEBREW_WIN__ */ 
  1462.     #ifdef __MMI_CHSET_LATIN_ISO__
  1463.         case EBOOK_LATIN_ISO:
  1464.             return MMI_CHSET_LATIN_ISO;
  1465.     #endif /* __MMI_CHSET_LATIN_ISO__ */ 
  1466.     #ifdef __MMI_CHSET_NORDIC_ISO__
  1467.         case EBOOK_NORDIC_ISO:
  1468.             return MMI_CHSET_NORDIC_ISO;
  1469.     #endif /* __MMI_CHSET_NORDIC_ISO__ */ 
  1470.     #ifdef __MMI_CHSET_SEURO_ISO__
  1471.         case EBOOK_SOURTH_EUROPEAN_ISO:
  1472.             return MMI_CHSET_SEURO_ISO;
  1473.     #endif /* __MMI_CHSET_SEURO_ISO__ */ 
  1474.     #ifdef __MMI_CHSET_TURKISH_ISO__
  1475.         case EBOOK_TURKISH_ISO:
  1476.             return MMI_CHSET_TURKISH_ISO;
  1477.     #endif /* __MMI_CHSET_TURKISH_ISO__ */ 
  1478.     #ifdef __MMI_CHSET_TURKISH_WIN__
  1479.         case EBOOK_TURKISH_WINDOWS:
  1480.             return MMI_CHSET_TURKISH_WIN;
  1481.     #endif /* __MMI_CHSET_TURKISH_WIN__ */ 
  1482.     #ifdef __MMI_CHSET_WESTERN_ISO__
  1483.         case EBOOK_WESTERN_ISO:
  1484.             return MMI_CHSET_WESTERN_ISO;
  1485.     #endif /* __MMI_CHSET_WESTERN_ISO__ */ 
  1486.     #ifdef __MMI_CHSET_WESTERN_WIN__
  1487.         case EBOOK_WESTERN_WINDOWS:
  1488.             return MMI_CHSET_WESTERN_WIN;
  1489.     #endif /* __MMI_CHSET_WESTERN_WIN__ */ 
  1490.     #ifdef __MMI_CHSET_GB18030__
  1491.         case EBOOK_GB:
  1492.             return MMI_CHSET_GB18030;
  1493.     #endif /* __MMI_CHSET_GB18030__ */ 
  1494.         default:
  1495.             return MMI_CHSET_TOTAL; /* unsupported charset */
  1496.     }
  1497. }
  1498. /*****************************************************************************
  1499.  * FUNCTION
  1500.  *  ebr_frm_delete_ebook
  1501.  * DESCRIPTION
  1502.  *  Delete the book.
  1503.  * PARAMETERS
  1504.  *  void
  1505.  * RETURNS
  1506.  *  void
  1507.  *****************************************************************************/
  1508. S32 ebr_frm_delete_ebook()
  1509. {
  1510.     /*----------------------------------------------------------------*/
  1511.     /* Local Variables                                                */
  1512.     /*----------------------------------------------------------------*/
  1513.     U8 nfo_path[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH] = {0};
  1514.     S32 retval_book,retval_nfo = 0;
  1515.     S32 local_nfo_id;
  1516.     /*----------------------------------------------------------------*/
  1517.     /* Code Body                                                      */
  1518.     /*----------------------------------------------------------------*/
  1519.     /* Delete PDB/TXT File */
  1520.     if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_PDB)
  1521.     {
  1522.         local_nfo_id = ebr_fmgr_get_nfo_id_for_pdb_file(
  1523.                         g_curr_book_cntx_p->memory_type_selected,
  1524.                         (PS8) g_curr_book_cntx_p->nfo_name);
  1525.     }
  1526.     else
  1527.     {
  1528.         local_nfo_id = ebr_fmgr_get_nfo_id_for_txt_file(
  1529.                         g_curr_book_cntx_p->memory_type_selected,
  1530.                         (PS8) g_curr_book_cntx_p->nfo_name);
  1531.     }
  1532.     if (local_nfo_id > 0)
  1533.     {
  1534.         pfnUnicodeStrcpy((S8*) nfo_path, (PS8) ebr_frm_get_nfo_file_name(local_nfo_id));
  1535.     }
  1536.     retval_nfo = FS_Delete((const WCHAR*)nfo_path);
  1537.     pfnUnicodeStrcpy(
  1538.         (S8*) nfo_path,
  1539.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  1540.     pfnUnicodeStrcat((PS8) nfo_path, (PS8) g_curr_book_cntx_p->nfo_name);
  1541.     retval_book = FS_Delete((const WCHAR*)nfo_path);
  1542. return retval_book;
  1543. }
  1544. /*****************************************************************************
  1545.  * FUNCTION
  1546.  *  ebr_frm_save_settings_in_nfo_file
  1547.  * DESCRIPTION
  1548.  *  Save settings in Nfo file.
  1549.  * PARAMETERS
  1550.  *  void
  1551.  * RETURNS
  1552.  *  void
  1553.  *****************************************************************************/
  1554. void ebr_frm_save_settings_in_nfo_file()
  1555. {
  1556.     /*----------------------------------------------------------------*/
  1557.     /* Local Variables                                                */
  1558.     /*----------------------------------------------------------------*/
  1559.     U32 size;
  1560.     S32 retval;
  1561.     FILE_HANDLE nfo_hnd;
  1562.     /*----------------------------------------------------------------*/
  1563.     /* Code Body                                                      */
  1564.     /*----------------------------------------------------------------*/
  1565.     nfo_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->nfo_path, FS_READ_WRITE);
  1566.     FS_Seek(nfo_hnd, 0, FS_FILE_BEGIN);
  1567.     retval = FS_Write(nfo_hnd, &g_curr_book_cntx_p->g_nfo_book_struct, sizeof(g_curr_book_cntx_p->g_nfo_book_struct), &size);
  1568.     FS_Close(nfo_hnd);
  1569. }
  1570. /*****************************************************************************
  1571.  * FUNCTION
  1572.  *  ebr_frm_close_the_ebook
  1573.  * DESCRIPTION
  1574.  *  Variable set before closing the book
  1575.  * PARAMETERS
  1576.  *  void
  1577.  * RETURNS
  1578.  *  void
  1579.  *****************************************************************************/
  1580. U8 ebr_frm_close_ebook = 0;
  1581. void ebr_frm_close_the_ebook(void)
  1582. {
  1583.     /*----------------------------------------------------------------*/
  1584.     /* Local Variables                                                */
  1585.     /*----------------------------------------------------------------*/
  1586.     /*----------------------------------------------------------------*/
  1587.     /* Code Body                                                      */
  1588.     /*----------------------------------------------------------------*/
  1589.     ebr_frm_close_ebook = 1;
  1590. }
  1591. /*****************************************************************************
  1592.  * FUNCTION
  1593.  *  ebr_frm_ebook_exit
  1594.  * DESCRIPTION
  1595.  *  Close the book and exit
  1596.  * PARAMETERS
  1597.  *  void
  1598.  * RETURNS
  1599.  *  void
  1600.  *****************************************************************************/
  1601. pBOOL ebr_frm_ebook_exit(void)
  1602. {
  1603.     /*----------------------------------------------------------------*/
  1604.     /* Local Variables                                                */
  1605.     /*----------------------------------------------------------------*/
  1606.     S16 local_nfo_id;
  1607.     S16 highlight_id;
  1608.     U32 size;
  1609.     U32 page_id;
  1610.     S32 text_offset;
  1611.     U8 shared_bytes;
  1612.     U8 last_showed_percentage;
  1613.     S32 last_text_offset_y;
  1614.     S32 retval;
  1615.     FILE_HANDLE nfo_hnd;
  1616.     S16 error;
  1617.     static pBOOL is_src_app_file_manager = FALSE;
  1618.     S16 ebr_page_size, auto_scroll_staus;
  1619.     /*----------------------------------------------------------------*/
  1620.     /* Code Body                                                      */
  1621.     /*----------------------------------------------------------------*/
  1622.     is_src_app_file_manager = FALSE;
  1623.     if (g_curr_book_cntx_p->state_recursive_conversion != EBR_FRM_NFO_CONVERSION_COMPLETED)
  1624.     {
  1625.         auto_scroll_staus = ebr_frm_get_auto_scroll_flag_status();
  1626.         if (auto_scroll_staus)
  1627.         {
  1628.             TurnOffBacklight();
  1629.         }
  1630.         if (g_curr_book_cntx_p->is_book_in_unicode || g_curr_book_cntx_p->book_is_in_other_encoding_format)
  1631.         {
  1632.             ebr_page_size = EBR_PAGE_SIZE * 2;
  1633.         }
  1634.         else
  1635.         {
  1636.             ebr_page_size = EBR_PAGE_SIZE;
  1637.         }
  1638.         if (g_curr_book_cntx_p->state_recursive_conversion != EBR_FRM_CONVERSION_UNDERWAY)
  1639.         {
  1640.         wgui_paging_multiline_get_current_page(
  1641.             &page_id,
  1642.             &text_offset,
  1643.             &shared_bytes,
  1644.             &last_showed_percentage,
  1645.             &last_text_offset_y);
  1646.         g_curr_book_cntx_p->g_nfo_book_struct.offset = text_offset;
  1647.         g_curr_book_cntx_p->g_nfo_book_struct.current_page_id = page_id;
  1648.         g_curr_book_cntx_p->g_nfo_book_struct.last_showed_percentage = last_showed_percentage;
  1649.         g_curr_book_cntx_p->g_nfo_book_struct.jump_offset = 0;
  1650.             g_curr_book_cntx_p->g_nfo_book_struct.last_text_offset_y = last_text_offset_y;
  1651.         }
  1652.         else
  1653.         {
  1654.             g_curr_book_cntx_p->g_nfo_book_struct.offset = 0;
  1655.             g_curr_book_cntx_p->g_nfo_book_struct.current_page_id = 0;
  1656.             g_curr_book_cntx_p->g_nfo_book_struct.last_showed_percentage = 0;
  1657.             g_curr_book_cntx_p->g_nfo_book_struct.jump_offset = 0;
  1658.             g_curr_book_cntx_p->g_nfo_book_struct.last_text_offset_y = 0;
  1659.         }
  1660.         g_curr_book_cntx_p->src_application = ebr_frm_fmgr_get_application_type();
  1661.         if (g_curr_book_cntx_p->src_application != EBR_FRM_SRC_APP_FMGR)
  1662.         {
  1663.             g_curr_book_cntx_p->g_last_nfo_id_allocated = 0;
  1664.             ReadValue(NVRAM_EBOOK_NFO_LID, (void*)&local_nfo_id, DS_SHORT, &error);
  1665.             if (local_nfo_id > 0)
  1666.             {
  1667.                 if (ebr_frm_close_ebook)
  1668.                 {
  1669.                     local_nfo_id = 0;
  1670.                     highlight_id = 0;
  1671.                     WriteValue(NVRAM_EBOOK_NFO_LID, (void*)&local_nfo_id, DS_SHORT, &error);
  1672.                     WriteValue(
  1673.                         NVRAM_EBOOK_LAST_HIGHLIGHT_ID,
  1674.                         (void*)&g_curr_book_cntx_p->current_highlight_book_id,
  1675.                         DS_SHORT,
  1676.                         &error);
  1677.                     ebr_frm_close_ebook = 0;
  1678.                 }
  1679.                 else
  1680.                 {
  1681.                     WriteValue(
  1682.                         NVRAM_EBOOK_LAST_HIGHLIGHT_ID,
  1683.                         (void*)&g_curr_book_cntx_p->current_highlight_book_id,
  1684.                         DS_SHORT,
  1685.                         &error);
  1686.                 }
  1687.             }
  1688.             else
  1689.             {
  1690.                 local_nfo_id = 0;
  1691.                 WriteValue(NVRAM_EBOOK_NFO_LID, (void*)&local_nfo_id, DS_SHORT, &error);
  1692.             }
  1693.         }
  1694.         else
  1695.         {
  1696.             is_src_app_file_manager = TRUE;
  1697.         }
  1698.         nfo_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->nfo_path, FS_READ_WRITE);
  1699.         if (nfo_hnd > 0)
  1700.         {
  1701.         FS_Seek(nfo_hnd, 0, FS_FILE_BEGIN);
  1702.         retval = FS_Write(
  1703.                     nfo_hnd,
  1704.                     &g_curr_book_cntx_p->g_nfo_book_struct,
  1705.                     sizeof(g_curr_book_cntx_p->g_nfo_book_struct),
  1706.                     &size);
  1707.         FS_Close(nfo_hnd);
  1708.     }
  1709.     }
  1710.     else
  1711.     {
  1712.         if (g_curr_book_cntx_p->src_application != EBR_FRM_SRC_APP_FMGR)
  1713.         {
  1714.             is_src_app_file_manager = FALSE;
  1715.         }
  1716.         else
  1717.         {
  1718.             is_src_app_file_manager = TRUE;
  1719.         }
  1720.     }
  1721.     return is_src_app_file_manager;
  1722. }
  1723. /*****************************************************************************
  1724.  * FUNCTION
  1725.  *  ebr_frm_set_find_next_flag
  1726.  * DESCRIPTION
  1727.  *  Clears flags for find next on scrolling
  1728.  * PARAMETERS
  1729.  *  void
  1730.  * RETURNS
  1731.  *  void
  1732.  *****************************************************************************/
  1733. void ebr_frm_set_find_next_flag(void)
  1734. {
  1735.     /*----------------------------------------------------------------*/
  1736.     /* Local Variables                                                */
  1737.     /*----------------------------------------------------------------*/
  1738.     /*----------------------------------------------------------------*/
  1739.     /* Code Body                                                      */
  1740.     /*----------------------------------------------------------------*/
  1741.     g_curr_book_cntx_p->status_for_resetting_find_next_data = TRUE;
  1742. }
  1743. /*****************************************************************************
  1744.  * FUNCTION
  1745.  *  ebr_frm_get_book_type
  1746.  * DESCRIPTION
  1747.  *  Gets the type of the book
  1748.  * PARAMETERS
  1749.  *  void
  1750.  * RETURNS
  1751.  *  void
  1752.  *****************************************************************************/
  1753. U8 *ebr_frm_get_book_type(void)
  1754. {
  1755.     /*----------------------------------------------------------------*/
  1756.     /* Local Variables                                                */
  1757.     /*----------------------------------------------------------------*/
  1758.     static U8 type[EBR_DISPLAY_INFO_DATA * ENCODING_LENGTH];
  1759.     S32 strlen_file_name;
  1760.     /*----------------------------------------------------------------*/
  1761.     /* Code Body                                                      */
  1762.     /*----------------------------------------------------------------*/
  1763.     strlen_file_name = pfnUnicodeStrlen((const S8*)g_curr_book_cntx_p->nfo_name);
  1764.     if (g_curr_book_cntx_p->nfo_name[strlen_file_name * 2 - 6] == 'p' ||
  1765.         g_curr_book_cntx_p->nfo_name[strlen_file_name * 2 - 6] == 'P')
  1766.     {
  1767.         g_curr_book_cntx_p->gbook_type = EBR_FRM_FILE_TYPE_PDB;
  1768.     }
  1769.     else
  1770.     {
  1771.         g_curr_book_cntx_p->gbook_type = EBR_FRM_FILE_TYPE_TXT;
  1772.     }
  1773.     if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_PDB)
  1774.     {
  1775.         strcpy((char*)type, (const char*)"PDB");
  1776.     }
  1777.     else
  1778.     {
  1779.         strcpy((char*)type, (const char*)"TXT");
  1780.     }
  1781.     return type;
  1782. }
  1783. /*****************************************************************************
  1784.  * FUNCTION
  1785.  *  ebr_frm_read_from_nvram
  1786.  * DESCRIPTION
  1787.  *  Get the default value from NVRAM
  1788.  * PARAMETERS
  1789.  *  void
  1790.  * RETURNS
  1791.  *  S32
  1792.  *****************************************************************************/
  1793. S32 ebr_frm_read_from_nvram()
  1794. {
  1795.     /*----------------------------------------------------------------*/
  1796.     /* Local Variables                                                */
  1797.     /*----------------------------------------------------------------*/
  1798.     S16 local_nfo_id;
  1799.     S16 error;
  1800.     MMI_BOOL status;
  1801.     FILE_HANDLE nfo_hnd_local;
  1802.     ebr_frm_setting_struct g_setting;
  1803.     ebr_frm_setting_struct *g_setting_list = &g_setting;
  1804.     /*----------------------------------------------------------------*/
  1805.     /* Code Body                                                      */
  1806.     /*----------------------------------------------------------------*/
  1807.     ReadValue(NVRAM_EBOOK_NFO_LID, (void*)&local_nfo_id, DS_SHORT, &error);
  1808.     ReadRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
  1809.     status = mmi_fmgr_is_drive_letter_valid(g_setting_list->memory_type);
  1810.     if (status && FS_GetDevStatus((UINT)g_setting_list->memory_type, FS_MOUNT_STATE_ENUM) != FS_NO_ERROR)
  1811.     {
  1812.         status = MMI_FALSE;
  1813.     }
  1814.     if (status == MMI_TRUE)
  1815.     {
  1816.         g_curr_book_cntx_p->memory_type_selected = g_setting_list->memory_type;
  1817.     }
  1818.     else
  1819.     {
  1820.        g_curr_book_cntx_p->memory_type_selected = (U8)MMI_PUBLIC_DRV; 
  1821.     }
  1822.     pfnUnicodeStrcpy((S8*) g_curr_book_cntx_p->nfo_path, (PS8) ebr_frm_get_nfo_file_name(local_nfo_id));
  1823.     nfo_hnd_local = FS_Open((const WCHAR*)g_curr_book_cntx_p->nfo_path, FS_READ_WRITE);
  1824.     if (nfo_hnd_local < 0)
  1825.     {
  1826.         local_nfo_id = 0;
  1827.         WriteValue(NVRAM_EBOOK_NFO_LID, (void*)&local_nfo_id, DS_SHORT, &error);
  1828.     }
  1829.     FS_Close(nfo_hnd_local);
  1830.     return local_nfo_id;
  1831. }
  1832. /*****************************************************************************
  1833.  * FUNCTION
  1834.  *  ebr_frm_rwrite_into_nvram
  1835.  * DESCRIPTION
  1836.  *  Write Nfo id in NVRAM
  1837.  * PARAMETERS
  1838.  *  local_nfo_id        [IN]        
  1839.  * RETURNS
  1840.  *  void
  1841.  *****************************************************************************/
  1842. void ebr_frm_rwrite_into_nvram(S16 local_nfo_id)
  1843. {
  1844.     /*----------------------------------------------------------------*/
  1845.     /* Local Variables                                                */
  1846.     /*----------------------------------------------------------------*/
  1847.     S16 error;
  1848.     /*----------------------------------------------------------------*/
  1849.     /* Code Body                                                      */
  1850.     /*----------------------------------------------------------------*/
  1851.     WriteValue(NVRAM_EBOOK_NFO_LID, (void*)&local_nfo_id, DS_SHORT, &error);
  1852. }
  1853. /*****************************************************************************
  1854.  * FUNCTION
  1855.  *  ebr_frm_write_settings_in_nvram
  1856.  * DESCRIPTION
  1857.  *  Write settings in NVRAM
  1858.  * PARAMETERS
  1859.  *  void
  1860.  * RETURNS
  1861.  *  void
  1862.  *****************************************************************************/
  1863. void ebr_frm_write_settings_in_nvram()
  1864. {
  1865.     /*----------------------------------------------------------------*/
  1866.     /* Local Variables                                                */
  1867.     /*----------------------------------------------------------------*/
  1868.     S16 error;
  1869.     ebr_frm_setting_struct g_setting;
  1870.     ebr_frm_setting_struct *g_setting_list = &g_setting;
  1871.     /*----------------------------------------------------------------*/
  1872.     /* Code Body                                                      */
  1873.     /*----------------------------------------------------------------*/
  1874.     g_setting_list->common_settings = g_curr_book_cntx_p->g_nfo_book_struct.settings;
  1875.     g_setting_list->memory_type = g_curr_book_cntx_p->g_nfo_book_struct.memory_type;
  1876.     WriteRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
  1877. }
  1878. /*****************************************************************************
  1879.  * FUNCTION
  1880.  *  ebr_frm_get_default_settings_value
  1881.  * DESCRIPTION
  1882.  *  get the default settings value
  1883.  * PARAMETERS
  1884.  *  g_ebookset_cntx_p               [IN]        
  1885.  *  ebr_set_local_setting_flag      [IN]        
  1886.  * RETURNS
  1887.  *  void
  1888.  *****************************************************************************/
  1889. void ebr_frm_get_default_settings_value(EBOOKSET_CNTX *g_ebookset_cntx_p, S16 ebr_set_local_setting_flag)
  1890. {
  1891.     /*----------------------------------------------------------------*/
  1892.     /* Local Variables                                                */
  1893.     /*----------------------------------------------------------------*/
  1894.     S16 error;
  1895.     MMI_BOOL status;
  1896.     /*----------------------------------------------------------------*/
  1897.     /* Code Body                                                      */
  1898.     /*----------------------------------------------------------------*/
  1899.     if (ebr_set_local_setting_flag == 1)
  1900.     {
  1901.         g_ebookset_cntx_p->inlineHighligtItemFontStyle = g_curr_book_cntx_p->g_nfo_book_struct.settings.font_style;
  1902.         g_ebookset_cntx_p->inlineHighligtItemFontSize = g_curr_book_cntx_p->g_nfo_book_struct.settings.font_size;
  1903.         g_ebookset_cntx_p->inlineHighligtItemScrollBy =
  1904.             g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_type;
  1905.         g_ebookset_cntx_p->inlineHighligtItemAutoScroll =
  1906.             g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_flag;
  1907.         g_ebookset_cntx_p->inlineHighligtItemScrollSpeed =
  1908.             g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_speed;
  1909.         g_ebookset_cntx_p->inlineHighligtItemFulScreenMode = g_curr_book_cntx_p->g_nfo_book_struct.settings.screen_mode;
  1910.         g_ebookset_cntx_p->inlineHighligtItemEncodingFormat =
  1911.             g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format;
  1912.     }
  1913.     else
  1914.     {
  1915.         ebr_frm_setting_struct g_setting;
  1916.         ebr_frm_setting_struct *g_setting_list = &g_setting;
  1917.         ReadRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
  1918.         g_ebookset_cntx_p->inlineHighligtItemEncodingFormat = g_setting_list->common_settings.encoding_format;
  1919.         g_ebookset_cntx_p->inlineHighligtItemFontSize = g_setting_list->common_settings.font_size;
  1920.         g_ebookset_cntx_p->inlineHighligtItemFontStyle = g_setting_list->common_settings.font_style;
  1921.          
  1922.         g_ebookset_cntx_p->inlineHighligtItemFulScreenMode = g_setting_list->common_settings.screen_mode;
  1923.         g_ebookset_cntx_p->inlineHighligtItemAutoScroll =
  1924.             g_setting_list->common_settings.auto_scroll_settings.scroll_flag;
  1925.         g_ebookset_cntx_p->inlineHighligtItemScrollSpeed =
  1926.             g_setting_list->common_settings.auto_scroll_settings.scroll_speed;
  1927.         g_ebookset_cntx_p->inlineHighligtItemScrollBy =
  1928.             g_setting_list->common_settings.auto_scroll_settings.scroll_type;
  1929. /* memory type */
  1930. status = mmi_fmgr_is_drive_letter_valid(g_setting_list->memory_type);
  1931.         if (status && FS_GetDevStatus((UINT)g_setting_list->memory_type, FS_MOUNT_STATE_ENUM) != FS_NO_ERROR)
  1932.         {
  1933.             status = MMI_FALSE;
  1934.         }
  1935.         if (status == MMI_TRUE)
  1936.         {
  1937.             g_ebookset_cntx_p->inlineHighligtItemSelectMemory = g_setting_list->memory_type;
  1938.         }
  1939.         else
  1940.         {
  1941.            g_ebookset_cntx_p->inlineHighligtItemSelectMemory = (U8)MMI_PUBLIC_DRV; 
  1942.         }       
  1943.     }
  1944. }
  1945. /*****************************************************************************
  1946.  * FUNCTION
  1947.  *  ebr_frm_save_settings_screen_mode
  1948.  * DESCRIPTION
  1949.  *  save the screen mode in NFO
  1950.  * PARAMETERS
  1951.  *  void
  1952.  * RETURNS
  1953.  *  void
  1954.  *****************************************************************************/
  1955. S32 ebr_frm_save_settings_screen_mode(void)
  1956. {
  1957.     /*----------------------------------------------------------------*/
  1958.     /* Local Variables                                                */
  1959.     /*----------------------------------------------------------------*/
  1960.     U32 size;
  1961.     S32 retval;
  1962.     FILE_HANDLE nfo_hnd;
  1963.     /*----------------------------------------------------------------*/
  1964.     /* Code Body                                                      */
  1965.     /*----------------------------------------------------------------*/
  1966.     if (g_curr_book_cntx_p->g_nfo_book_struct.settings.screen_mode == 0)
  1967.     {
  1968.         g_curr_book_cntx_p->g_nfo_book_struct.settings.screen_mode = 1;
  1969.     }
  1970.     else
  1971.     {
  1972.         g_curr_book_cntx_p->g_nfo_book_struct.settings.screen_mode = 0;
  1973.     }
  1974.     nfo_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->nfo_path, FS_READ_WRITE);
  1975.     FS_Seek(nfo_hnd, 0, FS_FILE_BEGIN);
  1976.     retval = FS_Write(nfo_hnd, &g_curr_book_cntx_p->g_nfo_book_struct, sizeof(g_curr_book_cntx_p->g_nfo_book_struct), &size);
  1977.     FS_Close(nfo_hnd);
  1978.     return g_curr_book_cntx_p->g_nfo_book_struct.settings.screen_mode;
  1979. }
  1980. /*****************************************************************************
  1981.  * FUNCTION
  1982.  *  ebr_frm_save_settings_scroll
  1983.  * DESCRIPTION
  1984.  *  save the scroll settings in NFO
  1985.  * PARAMETERS
  1986.  *  void
  1987.  * RETURNS
  1988.  *  void
  1989.  *****************************************************************************/
  1990. S32 ebr_frm_save_settings_scroll(void)
  1991. {
  1992.     /*----------------------------------------------------------------*/
  1993.     /* Local Variables                                                */
  1994.     /*----------------------------------------------------------------*/
  1995.     U32 size;
  1996.     S32 retval;
  1997.     FILE_HANDLE nfo_hnd;
  1998.     /*----------------------------------------------------------------*/
  1999.     /* Code Body                                                      */
  2000.     /*----------------------------------------------------------------*/
  2001.     if (g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_flag == 0)
  2002.     {
  2003.         g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_flag = 1;
  2004.     }
  2005.     else
  2006.     {
  2007.         g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_flag = 0;
  2008.     }
  2009.     nfo_hnd = FS_Open((const WCHAR*)g_curr_book_cntx_p->nfo_path, FS_READ_WRITE);
  2010.     FS_Seek(nfo_hnd, 0, FS_FILE_BEGIN);
  2011.     retval = FS_Write(nfo_hnd, &g_curr_book_cntx_p->g_nfo_book_struct, sizeof(g_curr_book_cntx_p->g_nfo_book_struct), &size);
  2012.     FS_Close(nfo_hnd);
  2013.     return g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_flag;
  2014. }
  2015. /*****************************************************************************
  2016.  * FUNCTION
  2017.  *  ebr_fmgr_get_nfo_id_for_txt_file
  2018.  * DESCRIPTION
  2019.  *  Ge the nfo id for Text File
  2020.  * PARAMETERS
  2021.  *  drive_type      [IN]        
  2022.  *  file_name       [IN]        
  2023.  * RETURNS
  2024.  *  S32
  2025.  *****************************************************************************/
  2026. S32 ebr_fmgr_get_nfo_id_for_txt_file(S8 drive_type, PS8 file_name)
  2027. {
  2028.     /*----------------------------------------------------------------*/
  2029.     /* Local Variables                                                */
  2030.     /*----------------------------------------------------------------*/
  2031.     FILE_HANDLE file_hnd;
  2032.     U32 size;
  2033.     U8 ebook_file_name[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH] = {0};
  2034.     U8 tmp_str[MAX_EBOOK_NAME_LENGTH] = {0};
  2035.     U8 end_footer_buffer[TXT_FOOTER_END_SIZE];
  2036.     U8 start_footer_buffer[TXT_FOOTER_START_SIZE];
  2037.     S32 local_nfo_id = 0;
  2038.     S32 file_size;
  2039.     /*----------------------------------------------------------------*/
  2040.     /* Code Body                                                      */
  2041.     /*----------------------------------------------------------------*/
  2042.     g_curr_book_cntx_p->memory_type_selected = drive_type;
  2043.     pfnUnicodeStrcpy((S8*) ebook_file_name, (S8*) ebr_frm_get_file_path(drive_type, EBR_FRM_SEARCH_DEFAULT));
  2044.     pfnUnicodeStrcat((PS8) ebook_file_name, (PS8) file_name);
  2045.     file_hnd = FS_Open((const WCHAR*)ebook_file_name, FS_READ_ONLY);
  2046.     FS_GetFileSize(file_hnd, (U32*) & file_size);
  2047.     if (file_hnd > 0)
  2048.     {
  2049.         if (FS_Seek(file_hnd, -TXT_FOOTER_END_SIZE, FS_FILE_END) != FS_INVALID_FILE_POS)
  2050.         {
  2051.         FS_Read(file_hnd, end_footer_buffer, TXT_FOOTER_END_SIZE, &size);
  2052.         }
  2053.         else
  2054.         {
  2055.             memset(end_footer_buffer, 0, sizeof(end_footer_buffer));
  2056.         }
  2057.         if (FS_Seek(file_hnd, -TXT_FOOTER_START_SIZE - TXT_FOOTER_END_SIZE - MAX_EBOOK_NAME_LENGTH, FS_FILE_END) !=
  2058.             FS_INVALID_FILE_POS)
  2059.             {
  2060.             FS_Read(file_hnd, start_footer_buffer, TXT_FOOTER_START_SIZE, &size);
  2061.             }
  2062.             else
  2063.             {
  2064.             memset(start_footer_buffer, 0, sizeof(start_footer_buffer));
  2065.             }
  2066.         if (strncmp((PS8) end_footer_buffer, (PS8) EBR_TXT_FOOTER_END, TXT_FOOTER_END_SIZE) == 0 &&
  2067.             strncmp((PS8) start_footer_buffer, (PS8) EBR_TXT_FOOTER_START, TXT_FOOTER_START_SIZE) == 0)
  2068.             {
  2069.             FS_Read(file_hnd, tmp_str, MAX_EBOOK_NAME_LENGTH, &size);
  2070.             local_nfo_id = atoi((const char*)tmp_str);
  2071.         }
  2072.         FS_Close(file_hnd);
  2073.         return local_nfo_id;
  2074.     }
  2075.     return 0;
  2076. }
  2077. /*****************************************************************************
  2078.  * FUNCTION
  2079.  *  ebr_fmgr_get_nfo_id_for_pdb_file
  2080.  * DESCRIPTION
  2081.  *  Ge the nfo id for PDB File
  2082.  * PARAMETERS
  2083.  *  drive_type      [IN]        
  2084.  *  file_name       [IN]        
  2085.  * RETURNS
  2086.  *  S32
  2087.  *****************************************************************************/
  2088. S32 ebr_fmgr_get_nfo_id_for_pdb_file(S8 drive_type, PS8 file_name)
  2089. {
  2090.     /*----------------------------------------------------------------*/
  2091.     /* Local Variables                                                */
  2092.     /*----------------------------------------------------------------*/
  2093.     FILE_HANDLE file_hnd;
  2094.     U32 size;
  2095.     ebr_frm_database_hdr_type file_header;
  2096.     U8 ebook_file_name[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH] = {0};
  2097.     /*----------------------------------------------------------------*/
  2098.     /* Code Body                                                      */
  2099.     /*----------------------------------------------------------------*/
  2100.     g_curr_book_cntx_p->memory_type_selected = drive_type;
  2101.     pfnUnicodeStrcpy((S8*) ebook_file_name, (S8*) ebr_frm_get_file_path(drive_type, EBR_FRM_SEARCH_DEFAULT));
  2102.     pfnUnicodeStrcat((PS8) ebook_file_name, (PS8) file_name);
  2103.     file_hnd = FS_Open((const WCHAR*)ebook_file_name, FS_READ_ONLY);
  2104.     if (file_hnd > 0)
  2105.     {
  2106.         if (FS_Read(file_hnd, &file_header, EBR_FRM_DATABASE_HEADER_SIZE, &size) == FS_NO_ERROR)
  2107.         {
  2108.             FS_Close(file_hnd);
  2109.             if (file_header.modification_date > 32768)
  2110.             {
  2111.                 return 0;
  2112.             }
  2113.             else
  2114.             {
  2115.                 return file_header.modification_date;
  2116.             }
  2117.         }
  2118.     }
  2119.     return 0;
  2120. }
  2121. /*****************************************************************************
  2122.  * FUNCTION
  2123.  *  ebr_frm_remove_nfo_id_info_from_file
  2124.  * DESCRIPTION
  2125.  *  Remove the nfo id info from the file
  2126.  * PARAMETERS
  2127.  *  drive_type                      [IN]        
  2128.  *  full_path_with_file_name        [IN]        
  2129.  *  book_type                       [IN]        
  2130.  * RETURNS
  2131.  *  void
  2132.  *****************************************************************************/
  2133. void ebr_frm_remove_nfo_id_info_from_file(S32 drive_type, PS8 full_path_with_file_name, ebr_frm_filetype_enum book_type)
  2134. {
  2135.     /*----------------------------------------------------------------*/
  2136.     /* Local Variables                                                */
  2137.     /*----------------------------------------------------------------*/
  2138.     FILE_HANDLE file_hnd;
  2139.     U32 size;
  2140.     ebr_frm_database_hdr_type file_header;
  2141.     S32 offset = 0;
  2142.     doc_record0 rec0;
  2143.     /*----------------------------------------------------------------*/
  2144.     /* Code Body                                                      */
  2145.     /*----------------------------------------------------------------*/
  2146.     g_curr_book_cntx_p->memory_type_selected = drive_type;
  2147.     //      pfnUnicodeStrcpy((S8*)ebook_file_name ,(S8*) ebr_frm_get_file_path(drive_type,EBR_FRM_SEARCH_DEFAULT));
  2148.     //      pfnUnicodeStrcat((PS8)ebook_file_name, (PS8)file_name);
  2149.     file_hnd = FS_Open((const WCHAR*)full_path_with_file_name, FS_READ_WRITE);
  2150.     if (file_hnd > 0)
  2151.     {
  2152.         if (book_type == EBR_FRM_FILE_TYPE_TXT)
  2153.         {
  2154.             FS_Seek(file_hnd, -TXT_FOOTER_START_SIZE - TXT_FOOTER_END_SIZE - MAX_EBOOK_NAME_LENGTH, FS_FILE_END);
  2155.             FS_Truncate(file_hnd);
  2156.         }
  2157.         else
  2158.         {
  2159.             if (FS_Read(file_hnd, &file_header, EBR_FRM_DATABASE_HEADER_SIZE, &size) == FS_NO_ERROR)
  2160.             {
  2161.                 SEEK_REC_ENTRY(file_hnd, 0);
  2162.                 if (FS_Read(file_hnd, &offset, 4, &size) == FS_NO_ERROR)
  2163.                 {
  2164.                     offset = ntohl(offset);
  2165.                 }
  2166.                 FS_Seek(file_hnd, offset, FS_FILE_BEGIN);
  2167.                 FS_Read(file_hnd, &rec0, sizeof rec0, &size);
  2168.                 file_header.modification_date = 32769;
  2169.                 FS_Seek(file_hnd, 0, FS_FILE_BEGIN);
  2170.                 FS_Write(file_hnd, &file_header, sizeof(ebr_frm_database_hdr_type), &size);
  2171.             }
  2172.         }
  2173.         FS_Close(file_hnd);
  2174.     }
  2175. }
  2176. /*****************************************************************************
  2177.  * FUNCTION
  2178.  *  ebr_frm_add_to_book_shelf
  2179.  * DESCRIPTION
  2180.  *  Add file to bookshelf.
  2181.  * PARAMETERS
  2182.  *  void
  2183.  * RETURNS
  2184.  *  void
  2185.  *****************************************************************************/
  2186. ebr_frm_nfo_create_type_errors_enum ebr_frm_add_to_book_shelf()
  2187. {
  2188.     /*----------------------------------------------------------------*/
  2189.     /* Local Variables                                                */
  2190.     /*----------------------------------------------------------------*/
  2191.     ebr_frm_nfo_create_type_errors_enum nfo_create_type_error = EBR_FRM_NFO_CREATE_SUCCESS;
  2192.     /*----------------------------------------------------------------*/
  2193.     /* Code Body                                                      */
  2194.     /*----------------------------------------------------------------*/
  2195.     g_curr_book_cntx_p->src_application = ebr_frm_fmgr_get_application_type();
  2196.     if (g_curr_book_cntx_p->g_fmgr_book_type == EBR_FRM_FILE_TYPE_PDB)  /* Means PDB file */
  2197.     {
  2198.         nfo_create_type_error = ebr_frm_open_book_create_nfo_file_pdb(g_curr_book_cntx_p->nfo_name);
  2199.     }
  2200.     else
  2201.     {
  2202.         nfo_create_type_error = ebr_frm_open_book_create_nfo_file_txt(g_curr_book_cntx_p->nfo_name);
  2203.     }
  2204.     return nfo_create_type_error;
  2205. }
  2206. /*****************************************************************************
  2207.  * FUNCTION
  2208.  *  ebr_fmgr_delete_from_ebook
  2209.  * DESCRIPTION
  2210.  *  Delete file from File manager
  2211.  * PARAMETERS
  2212.  *  drive_type      [IN]        
  2213.  *  file_name       [IN]        
  2214.  *  book_type       [IN]        
  2215.  * RETURNS
  2216.  *  void
  2217.  *****************************************************************************/
  2218. S16 ebr_fmgr_delete_from_ebook(S16 drive_type, S8 *file_name, ebr_frm_filetype_enum book_type)
  2219. {
  2220.     /*----------------------------------------------------------------*/
  2221.     /* Local Variables                                                */
  2222.     /*----------------------------------------------------------------*/
  2223.     U8 ebook_file_name[MAX_DWNL_EBK_PATH_LEN * ENCODING_LENGTH] = {0};
  2224.     S32 retval = -1;
  2225.     S16 local_nfo_id;
  2226.     ebr_frm_database_hdr_type file_header;
  2227.     FILE_HANDLE file_hnd;
  2228.     U32 size;
  2229.     /*----------------------------------------------------------------*/
  2230.     /* Code Body                                                      */
  2231.     /*----------------------------------------------------------------*/
  2232.     /* Check for the type of file .. delete the cerrseponding NFO file also. */
  2233.     pfnUnicodeStrcpy(
  2234.         (S8*) ebook_file_name,
  2235.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  2236.     pfnUnicodeStrcat((PS8) ebook_file_name, (PS8) file_name);
  2237.     file_hnd = FS_Open((const WCHAR*)ebook_file_name, FS_READ_ONLY);
  2238.     g_curr_book_cntx_p->g_fmgr_book_type = book_type;
  2239.     if (g_curr_book_cntx_p->g_fmgr_book_type == EBR_FRM_FILE_TYPE_PDB)  /* Means PDB file */
  2240.     {
  2241.         if (FS_Read(file_hnd, &file_header, EBR_FRM_DATABASE_HEADER_SIZE, &size) == FS_NO_ERROR)
  2242.         {
  2243.             if (file_header.modification_date > 32768)  /* Means no nfo file has been created. */
  2244.             {
  2245.                 FS_Close(file_hnd);
  2246.                 retval = FS_Delete((const WCHAR*)ebook_file_name);
  2247.                 return retval;
  2248.             }
  2249.             else
  2250.             {
  2251.                 local_nfo_id = (S16) file_header.modification_date;
  2252.                 FS_Close(file_hnd);
  2253.                 retval = FS_Delete((const WCHAR*)ebook_file_name);
  2254.                 FS_Delete((const WCHAR*)ebr_frm_get_nfo_file_name(local_nfo_id));
  2255.                 return retval;
  2256.             }
  2257.         }
  2258.     }
  2259.     else
  2260.     {   /* this is a text file. Delete the text as well as the cerresponding nfo file if it exists */
  2261.         FS_Close(file_hnd);
  2262.         local_nfo_id = ebr_fmgr_get_nfo_id_for_txt_file((S8)drive_type, file_name);
  2263.         if (local_nfo_id <= 0)
  2264.         {
  2265.             /* Nfo file doenot exist . delete the file only. */
  2266.             retval = FS_Delete((const WCHAR*)ebook_file_name);
  2267.             return retval;
  2268.         }
  2269.         else
  2270.         {
  2271.             FS_Close(file_hnd);
  2272.             retval = FS_Delete((const WCHAR*)ebook_file_name);
  2273.             retval = FS_Delete((const WCHAR*)ebr_frm_get_nfo_file_name(local_nfo_id));
  2274.             return retval;
  2275.         }
  2276.     }
  2277.     return retval;
  2278. }
  2279. /*****************************************************************************
  2280.  * FUNCTION
  2281.  *  ebr_frm_fmgr_set_drive_type
  2282.  * DESCRIPTION
  2283.  *  Get the drive type
  2284.  * PARAMETERS
  2285.  *  drive_type      [IN]        
  2286.  * RETURNS
  2287.  *  void
  2288.  *****************************************************************************/
  2289. void ebr_frm_fmgr_set_drive_type(ebr_memory_type_enum drive_type)
  2290. {
  2291.     /*----------------------------------------------------------------*/
  2292.     /* Local Variables                                                */
  2293.     /*----------------------------------------------------------------*/
  2294.     /*----------------------------------------------------------------*/
  2295.     /* Code Body                                                      */
  2296.     /*----------------------------------------------------------------*/
  2297.     g_curr_book_cntx_p->memory_type_selected = drive_type;
  2298. }
  2299. /*****************************************************************************
  2300.  * FUNCTION
  2301.  *  ebr_frm_get_nfo_handle
  2302.  * DESCRIPTION
  2303.  *  Get the NFO handle
  2304.  * PARAMETERS
  2305.  *  void
  2306.  * RETURNS
  2307.  *  FILE_HANDLE
  2308.  *****************************************************************************/
  2309. FILE_HANDLE ebr_frm_get_nfo_handle(void)
  2310. {
  2311.     /*----------------------------------------------------------------*/
  2312.     /* Local Variables                                                */
  2313.     /*----------------------------------------------------------------*/
  2314.     S16 error;
  2315.     FILE_HANDLE nfo_hnd_local;
  2316.     S16 local_nfo_id = 0;
  2317.     U32 size;
  2318.     /*----------------------------------------------------------------*/
  2319.     /* Code Body                                                      */
  2320.     /*----------------------------------------------------------------*/
  2321.     g_curr_book_cntx_p->src_application = ebr_frm_fmgr_get_application_type();
  2322.     if (g_curr_book_cntx_p->src_application == EBR_FRM_SRC_APP_FMGR)
  2323.     {   /* Means it is from file manager */
  2324.         local_nfo_id = ebr_frm_fmgr_get_nfo_id();
  2325.     }
  2326.     else
  2327.     {
  2328.         /* Write the nfo name in NVRAM */
  2329.         ReadValue(NVRAM_EBOOK_NFO_LID, (void*)&local_nfo_id, DS_SHORT, &error);
  2330.         if (local_nfo_id == 0)
  2331.         {
  2332.             if (g_curr_book_cntx_p->gbook_type == EBR_FRM_FILE_TYPE_PDB)
  2333.             {
  2334.                 local_nfo_id = ebr_fmgr_get_nfo_id_for_pdb_file(
  2335.                                 g_curr_book_cntx_p->memory_type_selected,
  2336.                                 (PS8) g_curr_book_cntx_p->nfo_name);
  2337.             }
  2338.             else
  2339.             {
  2340.                 local_nfo_id = ebr_fmgr_get_nfo_id_for_txt_file(
  2341.                                 g_curr_book_cntx_p->memory_type_selected,
  2342.                                 (PS8) g_curr_book_cntx_p->nfo_name);
  2343.             }
  2344.             WriteValue(NVRAM_EBOOK_NFO_LID, (void*)&local_nfo_id, DS_SHORT, &error);
  2345.         }
  2346.     }
  2347.     pfnUnicodeStrcpy((S8*) g_curr_book_cntx_p->nfo_path, (PS8) ebr_frm_get_nfo_file_name(local_nfo_id));
  2348.     nfo_hnd_local = FS_Open((const WCHAR*)g_curr_book_cntx_p->nfo_path, FS_READ_WRITE);
  2349.     if (nfo_hnd_local < 0)
  2350.     {
  2351.         return nfo_hnd_local;
  2352.     }
  2353.     FS_Seek(nfo_hnd_local, 0, FS_FILE_BEGIN);
  2354.     FS_Read(nfo_hnd_local, &g_curr_book_cntx_p->g_nfo_book_struct, sizeof(ebr_frm_book_struct), &size);
  2355.     pfnUnicodeStrcpy(
  2356.         (S8*) g_curr_book_cntx_p->book_name_path,
  2357.         (S8*) ebr_frm_get_file_path(g_curr_book_cntx_p->memory_type_selected, EBR_FRM_SEARCH_DEFAULT));
  2358.     pfnUnicodeStrcat((PS8) g_curr_book_cntx_p->book_name_path, (PS8) g_curr_book_cntx_p->g_nfo_book_struct.e_book_name);
  2359.     return nfo_hnd_local;
  2360. }
  2361. /*****************************************************************************
  2362.  * FUNCTION
  2363.  *  ebr_get_drive_type
  2364.  * DESCRIPTION
  2365.  *  Get the drive type selected
  2366.  * PARAMETERS
  2367.  *  void
  2368.  * RETURNS
  2369.  *  S16
  2370.  *****************************************************************************/
  2371. S16 ebr_get_drive_type(void)
  2372. {
  2373.     /*----------------------------------------------------------------*/
  2374.     /* Local Variables                                                */
  2375.     /*----------------------------------------------------------------*/
  2376.     /*----------------------------------------------------------------*/
  2377.     /* Code Body                                                      */
  2378.     /*----------------------------------------------------------------*/
  2379.     return g_curr_book_cntx_p->memory_type_selected;
  2380. }
  2381. /*****************************************************************************
  2382.  * FUNCTION
  2383.  *  ebr_frm_set_settings_and_save
  2384.  * DESCRIPTION
  2385.  *  Save the settings in nfo file
  2386.  * PARAMETERS
  2387.  *  g_ebookset_cntx_p       [IN]        
  2388.  * RETURNS
  2389.  *  void
  2390.  *****************************************************************************/
  2391. void ebr_frm_set_settings_and_save(EBOOKSET_CNTX *g_ebookset_cntx_p)
  2392. {
  2393.     /*----------------------------------------------------------------*/
  2394.     /* Local Variables                                                */
  2395.     /*----------------------------------------------------------------*/
  2396.     ebr_frm_setting_struct g_setting;
  2397.     S16 error;
  2398.     S16 i;
  2399.     ebr_frm_setting_struct *g_setting_list = &g_setting;
  2400.     /*----------------------------------------------------------------*/
  2401.     /* Code Body                                                      */
  2402.     /*----------------------------------------------------------------*/
  2403.     g_curr_book_cntx_p->pdb_converted_to_text = FALSE;
  2404.     ReadRecord(NVRAM_EF_EBOOK_SETTINGS_LID, 1, (void*)(g_setting_list), NVRAM_EF_EBOOK_SETTING_SIZE, &error);
  2405. if(g_curr_book_cntx_p->g_nfo_book_struct.settings.font_size!=g_ebookset_cntx_p->inlineHighligtItemFontSize)
  2406. {
  2407. g_curr_book_cntx_p->g_nfo_book_struct.jump_offset = g_curr_book_cntx_p->g_nfo_book_struct.offset;
  2408. g_curr_book_cntx_p->g_nfo_book_struct.offset = 0;
  2409. }
  2410.     g_curr_book_cntx_p->g_nfo_book_struct.settings.font_size = g_ebookset_cntx_p->inlineHighligtItemFontSize;
  2411.     g_curr_book_cntx_p->g_nfo_book_struct.settings.font_style = g_ebookset_cntx_p->inlineHighligtItemFontStyle;
  2412.     g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_flag =
  2413.         g_ebookset_cntx_p->inlineHighligtItemAutoScroll;
  2414.     g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_speed =
  2415.         g_ebookset_cntx_p->inlineHighligtItemScrollSpeed;
  2416.     g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_type =
  2417.         g_ebookset_cntx_p->inlineHighligtItemScrollBy;
  2418.     if (g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format ==
  2419.         g_ebookset_cntx_p->inlineHighligtItemEncodingFormat)
  2420.     {
  2421.         g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format =
  2422.             g_ebookset_cntx_p->inlineHighligtItemEncodingFormat;
  2423.     }
  2424.     else
  2425.     {
  2426.         g_curr_book_cntx_p->g_nfo_book_struct.temp_encoding_file_format = '';
  2427.         for (i = 0; i < EBR_FRM_MAX_NO_OF_BOOKMARKS; i++)
  2428.         {
  2429.             g_curr_book_cntx_p->g_nfo_book_struct.book_marks[i].offset = 0;
  2430.             g_curr_book_cntx_p->g_nfo_book_struct.book_marks[i].page_id = 0;
  2431.             pfnUnicodeStrcpy((PS8) g_curr_book_cntx_p->g_nfo_book_struct.book_marks[i].bookmark_name, (PS8) NULL);
  2432.             g_curr_book_cntx_p->g_nfo_book_struct.book_marks[i].percentage_associated_with_book_mark = 0;
  2433.         }
  2434.         g_curr_book_cntx_p->g_nfo_book_struct.current_page_id = 0;
  2435.         g_curr_book_cntx_p->g_nfo_book_struct.offset = 0;
  2436.         g_curr_book_cntx_p->g_nfo_book_struct.jump_offset = 0;
  2437.         g_curr_book_cntx_p->g_nfo_book_struct.last_showed_percentage = 0;
  2438.         /* g_curr_book_cntx_p->g_nfo_book_struct.settings = g_setting_list->common_settings; */
  2439.         g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format =
  2440.             g_ebookset_cntx_p->inlineHighligtItemEncodingFormat;
  2441. g_curr_book_cntx_p->g_nfo_book_struct.last_text_offset_y = 0;
  2442.     }
  2443.     g_curr_book_cntx_p->g_nfo_book_struct.settings.screen_mode = g_ebookset_cntx_p->inlineHighligtItemFulScreenMode;
  2444.     ebr_frm_save_settings_in_nfo_file();
  2445. }
  2446. /*****************************************************************************
  2447.  * FUNCTION
  2448.  *  ebr_frm_set_settings_and_save_in_nvram
  2449.  * DESCRIPTION
  2450.  *  Save the settings in NVRAM
  2451.  * PARAMETERS
  2452.  *  g_ebookset_cntx_p       [IN]        
  2453.  * RETURNS
  2454.  *  void
  2455.  *****************************************************************************/
  2456. void ebr_frm_set_settings_and_save_in_nvram(EBOOKSET_CNTX *g_ebookset_cntx_p)
  2457. {
  2458.     /*----------------------------------------------------------------*/
  2459.     /* Local Variables                                                */
  2460.     /*----------------------------------------------------------------*/
  2461.     /*----------------------------------------------------------------*/
  2462.     /* Code Body                                                      */
  2463.     /*----------------------------------------------------------------*/
  2464.     g_curr_book_cntx_p->g_nfo_book_struct.settings.font_size = g_ebookset_cntx_p->inlineHighligtItemFontSize;
  2465.     g_curr_book_cntx_p->g_nfo_book_struct.settings.font_style = g_ebookset_cntx_p->inlineHighligtItemFontStyle;
  2466.     g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_flag =
  2467.         g_ebookset_cntx_p->inlineHighligtItemAutoScroll;
  2468.     g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_speed =
  2469.         g_ebookset_cntx_p->inlineHighligtItemScrollSpeed;
  2470.     g_curr_book_cntx_p->g_nfo_book_struct.settings.auto_scroll_settings.scroll_type =
  2471.         g_ebookset_cntx_p->inlineHighligtItemScrollBy;
  2472.     g_curr_book_cntx_p->g_nfo_book_struct.settings.encoding_format =
  2473.         g_ebookset_cntx_p->inlineHighligtItemEncodingFormat;
  2474.     g_curr_book_cntx_p->g_nfo_book_struct.settings.screen_mode = g_ebookset_cntx_p->inlineHighligtItemFulScreenMode;
  2475.     g_curr_book_cntx_p->g_nfo_book_struct.memory_type = g_ebookset_cntx_p->inlineHighligtItemSelectMemory;
  2476.     ebr_frm_write_settings_in_nvram();
  2477. }
  2478. /*****************************************************************************
  2479.  * FUNCTION
  2480.  *  ebr_get_book_mark_name_list
  2481.  * DESCRIPTION
  2482.  *  Call back to get the book mark names
  2483.  * PARAMETERS
  2484.  *  item_index          [IN]        
  2485.  *  str_buff            [IN]