OSDN Git Service

* WorkBackup: 2015/05/10(Sun) (Implemented & Non-Tested > API_InsertLine() )
authorKoine Yuusuke(koinec) <koinec@users.sourceforge.jp>
Sun, 10 May 2015 02:08:01 +0000 (11:08 +0900)
committerKoine Yuusuke(koinec) <koinec@users.sourceforge.jp>
Sun, 10 May 2015 02:08:01 +0000 (11:08 +0900)
* Optimized for Section_ReviewSection()

include/libedittext.h
libedittext/drd64_libedittext_config.h
libedittext/drd64_libedittext_linectrl.c
libedittext/drd64_libedittext_linectrl.h
libedittext/drd64_libedittext_section.c
libedittext/drd64_libedittext_section.h

index e366651..9482db2 100644 (file)
@@ -70,9 +70,10 @@ LIBEDITTEXT_API_FILE
        #define LIBEDITTEXT_API_LINECTRL        extern
 #endif
 LIBEDITTEXT_API_LINECTRL
+       int LibEditText_InsertLine_toLine( int i_tinfoid, DWord dw_line, char *pstr_text, DWord dw_length );
+LIBEDITTEXT_API_LINECTRL
        int LibEditText_AppendLine( int i_tinfoid, char *pstr_text, DWord dw_length );
 
-
 #ifdef DRD64_SRC_LIBEDITTEXT_LINEEDIT
        #define LIBEDITTEXT_API_LINEEDIT
 #else
index 0d03e75..c2b9612 100644 (file)
@@ -37,7 +37,7 @@ Comment:
 #ifndef DRD64_HEADER_LIBEDITTEXT_CONFIG
 #define DRD64_HEADER_LIBEDITTEXT_CONFIG
 
-#define DEBUG_TEXTINFO_OUTPUT                                          0x02
+#define DEBUG_TEXTINFO_OUTPUT                                          0x00
        /* Output TextData for Console if this value isn't 0x00 when run test_drcc program.*/
 
 
index b229b04..6534e7b 100644 (file)
@@ -37,6 +37,100 @@ Comment:
 #define        DRD64_SRC_LIBEDITTEXT_LINECTRL
 #include"drd64_libedittext.h"
 
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBEDITTEXT_LINECTRL_EXTERN
+int
+       LibEditText_LineCtrl_InsertLine(
+               LibEditText_TextInfo    *p_tinfo,
+               LibEditText_LineInfo    *p_lnext,
+               Byte    *pb_text,
+               DWord   dw_length )
+{
+       int                                             i_result;
+       DWord                                   dw_buflength;
+       DWord                                   dw_strlen;
+       LibEditText_LineInfo    *p_lbefore;
+       LibEditText_LineInfo    *p_line;
+       
+       assert( NULL != p_tinfo );
+       assert( NULL != p_lnext );
+
+       // PreProccess
+       p_lbefore       = LINFO(p_tinfo, p_lnext->dw_before);
+       
+       dw_strlen       = dw_length;
+       if( '\n' != *(pb_text + dw_length) )    { dw_strlen++; }
+
+       // Get LineInfo struct
+       dw_buflength    = dw_strlen + DRD64_LIBEDITTEXT_DEFAULT_RESERVEBUF_INLINE;
+       p_line  = LibEditText_LineInfo_GetEmptyLineInfo( p_tinfo, dw_buflength );
+       if( NULL == p_line )    { return -0x11; }
+       
+       // Link Before & After LineInfo
+       if( NULL != p_lbefore )         {
+               p_lbefore->dw_next      = p_line->dw_id;
+               p_line->dw_before       = p_lbefore->dw_id;
+       }
+       else
+               { p_tinfo->dw_line_start        = p_line->dw_id; }
+
+       p_lnext->dw_before      = p_line->dw_id;
+       p_line->dw_next         = p_lnext->dw_id;
+
+       // Set LineInfo to SortChain
+       i_result    = LibEditText_LineInfo_AddSortChain( p_tinfo, p_line );
+       if( 0x00 != i_result )  { return -0x12; }
+
+       // Set Init. TextData
+       p_line->dw_strlen       = dw_strlen;
+       memcpy( p_tinfo->pb_text + p_line->dw_start, pb_text, dw_length );
+       if( dw_length != dw_strlen )
+               { *(p_tinfo->pb_text + p_line->dw_start + dw_length) = '\n'; }  
+
+       p_tinfo->dw_maxline++;
+
+       // Adjust LineSection
+       i_result        = LibEditText_Section_AddSection( p_tinfo );
+       if( 0x00 != i_result )  { return -0x13; }
+
+       return 0x00;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBEDITTEXT_API_LINECTRL
+int
+       LibEditText_InsertLine_toLine(
+               int             i_tinfoid,
+               DWord   dw_line,
+               char    *pstr_text,
+               DWord   dw_length )
+{
+       int                                             i_result;
+       LibEditText_TextInfo    *p_tinfo;
+       LibEditText_LineInfo    *p_line;
+
+       if( 0 > i_tinfoid )             { return -0x01; }
+       p_tinfo = LibEditText_System_GetTextInfo( i_tinfoid );
+       if( NULL == p_tinfo )   { return -0x02; }
+
+       if( NULL == pstr_text ) { return -0x03; }
+
+       if( p_tinfo->dw_maxline <= (dw_line + 1) )      {
+               i_result        = LibEditText_LineCtrl_AppendLine(
+                                               p_tinfo, (Byte *)pstr_text, dw_length, 0x00 );
+       }
+       else    {
+               p_line  = LibEditText_Section_SearchLine( p_tinfo, dw_line );
+               i_result        = LibEditText_LineCtrl_InsertLine(
+                                               p_tinfo, p_line, (Byte *)pstr_text, dw_length );
+       }
+       
+       return i_result;
+}
+
 
 /*----------------------------------------------------------------------
 ----------------------------------------------------------------------*/
@@ -95,14 +189,14 @@ goto_LibEditText_LineCtrl_AppendLine_prechecked:
 
        memcpy( p_tinfo->pb_text + p_line->dw_start, pstr_text, dw_length );
 
+       p_tinfo->dw_line_end    = p_line->dw_id;
+
        /* Normal Append Mode is b_mode=0x00. */
        if( 0x00 == b_mode )    {
-               i_result        = LibEditText_Section_AppendLine( p_tinfo, p_line );
                p_tinfo->dw_maxline++;
+               i_result        = LibEditText_Section_AddSection( p_tinfo );
        }
 
-       p_tinfo->dw_line_end    = p_line->dw_id;
-
        return 0x00;
 }
 
index 7856fdd..c01b51b 100644 (file)
@@ -49,7 +49,10 @@ Comment:
        #define LIBEDITTEXT_LINECTRL_INTERNALFUNC
 #endif
 
-
+LIBEDITTEXT_LINECTRL_EXTERN
+       int LibEditText_LineCtrl_InsertLine(
+                       LibEditText_TextInfo *p_tinfo, LibEditText_LineInfo *p_lnext,
+                       Byte *pb_text, DWord dw_length );
 LIBEDITTEXT_LINECTRL_EXTERN
        int LibEditText_LineCtrl_AppendLine(
                        LibEditText_TextInfo *p_tinfo, Byte *pstr_text, DWord dw_length, Byte b_mode );
index 0593f48..eb48401 100644 (file)
@@ -45,23 +45,6 @@ Comment:
 
 /*----------------------------------------------------------------------
 ----------------------------------------------------------------------*/
-LIBEDITTEXT_SECTION_EXTERN
-DWord inline
-       LibEditText_Section_CalcSectionID(
-                       LibEditText_TextInfo    *p_tinfo,
-                       DWord   dw_line )
-{
-       DWord   dw_sectionid;
-
-       assert( NULL != p_tinfo );
-       dw_sectionid    = (dw_line * p_tinfo->dw_sections) / p_tinfo->dw_maxline;
-
-       return dw_sectionid;
-}
-
-
-/*----------------------------------------------------------------------
-----------------------------------------------------------------------*/
 DWord
        LibEditText_Section_BackwardSections_toNearTargetLine(
                LibEditText_TextInfo    *p_tinfo, 
@@ -134,26 +117,26 @@ void
        p_sec_min       = SECINFO(p_tinfo, dw_secid_min);
        p_sec_high      = SECINFO(p_tinfo, dw_secid_high);
 
-       for( dw_cnt = 0; dw_cnt < p_tinfo->dw_sections - 1; dw_cnt++ )  {
-               if( dw_cnt < dw_secid_min )     {
+       if( 0 < dw_secid_min )  {
+               for( dw_cnt = dw_secid_min - 1; dw_cnt < dw_secid_min; dw_cnt--)        {
                        p_sec_now       = SECINFO(p_tinfo, dw_cnt);
 
                        if( p_sec_min->dw_line < p_sec_now->dw_line )   {
                                p_sec_now->dw_line              = p_sec_min->dw_line;
                                p_sec_now->dw_linfoid   = p_sec_min->dw_linfoid;
                        }
+                       else    { break; }
                }
-               else if( dw_cnt > dw_secid_high )       {
-                       p_sec_now       = SECINFO(p_tinfo, dw_cnt);
+       }
 
-                       if( p_sec_high->dw_line > p_sec_now->dw_line )  {
-                               p_sec_now->dw_line              = p_sec_high->dw_line;
-                               p_sec_now->dw_linfoid   = p_sec_high->dw_linfoid;
-                       }
-                       else
-                               { return; }
-               }
+       for( dw_cnt = dw_secid_high; dw_cnt < p_tinfo->dw_sections - 1; dw_cnt++ )      {
+               p_sec_now       = SECINFO(p_tinfo, dw_cnt);
 
+               if( p_sec_high->dw_line > p_sec_now->dw_line )  {
+                       p_sec_now->dw_line              = p_sec_high->dw_line;
+                       p_sec_now->dw_linfoid   = p_sec_high->dw_linfoid;
+               }
+               else { return; }
        }
 
        return;
@@ -341,28 +324,31 @@ int
 ----------------------------------------------------------------------*/
 LIBEDITTEXT_SECTION_EXTERN
 int
-       LibEditText_Section_AppendLine(
-                       LibEditText_TextInfo    *p_tinfo,
-                       LibEditText_LineInfo    *p_line )
+       LibEditText_Section_AddSection(
+                       LibEditText_TextInfo    *p_tinfo )
 {
        int                                                     i_result;
        DWord                                           dw_nowsec;
+       LibEditText_LineInfo            *p_line;
        LibEditText_LineSection         *p_section;
 
-       dw_nowsec       = (p_tinfo->dw_maxline + 1) / p_tinfo->dw_sect_steps;
+       p_line  = LINFO(p_tinfo, p_tinfo->dw_line_end );
+       assert( NULL != p_line );
+
+       dw_nowsec       = p_tinfo->dw_maxline / p_tinfo->dw_sect_steps;
        if( p_tinfo->dw_sections > dw_nowsec )          { return 0x00; }
        
        if( p_tinfo->dw_bufsections == dw_nowsec )      {
                i_result        = LibEditText_Section_ExpandSectionInfo( p_tinfo );
                if( 0x00 != i_result )  { return i_result; }
-               dw_nowsec       = (p_tinfo->dw_maxline + 1) / p_tinfo->dw_sect_steps;
+               dw_nowsec       = p_tinfo->dw_maxline / p_tinfo->dw_sect_steps;
                if( p_tinfo->dw_sections > dw_nowsec )          { return 0x00; }
        }
 
        p_section       = p_tinfo->p_section + dw_nowsec;
        assert( NULL != p_section );
 
-       p_section->dw_line              = p_tinfo->dw_maxline + 1;
+       p_section->dw_line              = p_tinfo->dw_maxline;
        p_section->dw_linfoid   = p_line->dw_id;
        p_tinfo->dw_sections++;
 
index 8f06369..d3ac469 100644 (file)
@@ -58,16 +58,14 @@ Comment:
 
 LIBEDITTEXT_SECTION_EXTERN
        LibEditText_LineInfo    *
-               LibEditText_Section_SearchLine( LibEditText_TextInfo *p_tinfo, DWord dw_targline );
-LIBEDITTEXT_SECTION_EXTERN
-       DWord inline LibEditText_CalcSectionID(
-                       LibEditText_TextInfo *p_tinfo, DWord dw_line );
+               LibEditText_Section_SearchLine(
+                       LibEditText_TextInfo *p_tinfo, DWord dw_targline );
 LIBEDITTEXT_SECTION_EXTERN
        int LibEditText_Section_ConstractSection(
                        LibEditText_TextInfo *p_tinfo );
 LIBEDITTEXT_SECTION_EXTERN
-       int LibEditText_Section_AppendLine(
-                       LibEditText_TextInfo *p_tinfo, LibEditText_LineInfo *p_line );
+       int LibEditText_Section_AddSection(
+                       LibEditText_TextInfo *p_tinfo );
 LIBEDITTEXT_SECTION_EXTERN
        int LibEditText_Section_TermSection(
                        LibEditText_TextInfo *p_tinfo );
@@ -80,6 +78,8 @@ DWord LibEditText_Section_BackwardSections_toNearTargetLine(
        LibEditText_TextInfo *p_tinfo, DWord dw_secid, DWord dw_targetline );
 DWord LibEditText_Section_ForwardSections_toNearTargetLine(
        LibEditText_TextInfo *p_tinfo, DWord dw_secid, DWord dw_targetline );
+void LibEditText_Section_ReviewSection(
+       LibEditText_TextInfo *p_tinfo, DWord dw_secid_min, DWord dw_secid_high );
 DWord LibEditText_Section_SearchLine_OldSectionInfo(
        LibEditText_LineSection *p_section, LibEditText_TextInfo *p_tinfo,
                DWord dw_secid, DWord dw_line );