OSDN Git Service

* Tested: DeleteLine_toLine ( if delete-line is the end of file.)
authorKoine Yuusuke(koinec) <koinec@users.sourceforge.jp>
Sun, 17 May 2015 20:52:14 +0000 (05:52 +0900)
committerKoine Yuusuke(koinec) <koinec@users.sourceforge.jp>
Sun, 17 May 2015 20:52:14 +0000 (05:52 +0900)
    TODO: testing delete-line in the imtermidiate line of file.

libedittext/drd64_libedittext_linectrl.c
libedittext/drd64_libedittext_lineinfo.c
libedittext/drd64_libedittext_section.c
libedittext/drd64_libedittext_section.h
libedittext/test_libedittext_linectrl.c

index 1f67313..8d413f6 100644 (file)
@@ -55,7 +55,7 @@ int
        assert( NULL != p_tinfo );
        assert( NULL != p_line );
 
-       if( 1 == p_tinfo->dw_maxline )  { return 0x00; }
+       if( 1 == p_tinfo->dw_maxline )  { return 0x00; }
 
        // Check & Remove Section ---
        LibEditText_Section_DeleteLine( p_tinfo, dw_line );
@@ -281,6 +281,7 @@ goto_LibEditText_LineCtrl_AppendLine_prechecked:
                i_result        = LibEditText_Section_AddSection( p_tinfo );
                if( 0x00 > i_result )           { return i_result; }
                else if( 0x00 < i_result )      { i_result      = 0x00; }
+
                p_tinfo->dw_maxline++;
        }
 
index fb05365..7d58fa6 100644 (file)
@@ -381,9 +381,10 @@ int
 
        /* Follow if-block is memory-garbage collect proc if this is in last buffer */
        if( p_tinfo->dw_lastsize == p_line->dw_start + p_line->dw_linelen )     {
-               p_line->dw_linelen      = 0;
-               p_line->dw_strlen       = 0;
-               p_line->dw_start        = 0;
+               p_tinfo->dw_lastsize    -= p_line->dw_linelen;
+               p_line->dw_linelen              = 0;
+               p_line->dw_strlen               = 0;
+               p_line->dw_start                = 0;
        }
 
        i_element       = LibEditText_LineInfo_CalcSortChainElement( p_line->dw_linelen );
@@ -454,7 +455,7 @@ int
        int             i_element;
        LibEditText_LineInfo            *p_sort;
        LibEditText_LineInfo            *p_before;
-       
+       DWord dw_cnt=0;
        assert( 0 != p_line->dw_linelen);
 
        i_element       = LibEditText_LineInfo_CalcSortChainElement( p_line->dw_linelen );
@@ -467,6 +468,7 @@ int
        while(( NULL != p_sort ) && ( p_line != p_sort ))               {
                p_before        = p_sort;
                p_sort          = LINFO(p_tinfo, p_before->dw_sortnext);
+               dw_cnt++;
        }
 
        if( NULL == p_sort )    { return -0x02; }
@@ -474,7 +476,8 @@ int
 
        if( NULL != p_before)
                { p_before->dw_sortnext = p_sort->dw_sortnext; }
-       else
+
+       if( p_tinfo->dw_linesort[i_element] == p_sort->dw_id )
                { p_tinfo->dw_linesort[i_element]       = p_sort->dw_sortnext; }
 
        p_sort->dw_sortnext             = INVALID_LINE;
index 45cb91e..c0c97b6 100644 (file)
@@ -372,10 +372,10 @@ void
 
        assert( NULL != p_tinfo );
        assert( 0 < p_tinfo->dw_sections );
-
+/*
        if( 0 != (p_tinfo->dw_maxline % p_tinfo->dw_sect_steps) )
                { return; }
-
+*/
        p_sbefore       = SECINFO(p_tinfo, dw_secid);
        dw_secid++;
        for( ; dw_secid < p_tinfo->dw_sections; dw_secid++ )    {
@@ -406,10 +406,10 @@ void
 
        assert( NULL != p_tinfo );
        assert( 0 < p_tinfo->dw_sections );
-
+/*
        if( 0 != (p_tinfo->dw_maxline % p_tinfo->dw_sect_steps) )
                { return; }
-
+*/
        p_section                               = p_tinfo->p_section + (p_tinfo->dw_sections - 1);
        p_section->dw_line              = 0;
        p_section->dw_linfoid   = INVALID_LINE;
@@ -435,20 +435,20 @@ int
        p_line  = LINFO(p_tinfo, p_tinfo->dw_line_end );
        assert( NULL != p_line );
 
-       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 0x01; }
        
        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 0x01; }
        }
 
        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++;
 
@@ -490,6 +490,9 @@ void
                        { p_section->dw_line--; }
        }
 
+       if( 0 != ((p_tinfo->dw_maxline - 1) % p_tinfo->dw_sect_steps) )
+               { goto  goto_LibEditText_Section_DeleteLine_post; }
+
        // Delete Section Info ---
        p_section       = SECINFO(p_tinfo, dw_secid);
        if( 0 < dw_secid )      {
index 1150006..ba5b86f 100644 (file)
@@ -51,9 +51,8 @@ Comment:
        #define LIBEDITTEXT_SECTION_INTERNALFUNC        extern
 #endif
 
-#define CALC_LINE2SECTION(m,n) (((n)+1)/(m)->dw_sect_steps)
-#define        CALC_SECTION2LINE(m,n)  ((1 >= (m)->dw_sections) ? 0 : ((((m)->dw_maxline)*(n))/((m)->dw_sections - 1)))
-//#define      CALC_SECTION2LINE(m,n)  ((((m)->dw_maxline)*(n))/((m)->dw_sections))
+#define CALC_LINE2SECTION(m,n) ((n)/(m)->dw_sect_steps)
+#define        CALC_SECTION2LINE(m,n)  (((m)->dw_sect_steps)*(n))
 #define SECINFO(m,n)                   ((m)->p_section+(n))
 
 
index 5009d8e..934bcb7 100644 (file)
@@ -61,6 +61,14 @@ void Test_LibEditText_API_AppendLine_test00_001(void)
                CU_ASSERT( 0x00 == i_result );
        }
 
+       i_result        = LibEditText_Debug_DebugTextInfo( i_tinfoid, 0x02);
+       CU_ASSERT( 0x00 == i_result );
+
+       for( i_cnt = 65536; i_cnt > 2; i_cnt-- )        {
+               i_result        = LibEditText_DeleteLine_toLine( i_tinfoid, i_cnt );
+               CU_ASSERT( 0x00 == i_result );
+       }
+
        i_result        = LibEditText_Debug_DebugTextInfo( i_tinfoid, DEBUG_TEXTINFO_OUTPUT );
        CU_ASSERT( 0x00 == i_result );
 
@@ -77,9 +85,6 @@ void Test_LibEditText_API_InsertLine_test00_001(void)
 {
        int     i_result;
        int             i_tinfoid;
-       int             i_len;
-       int             i_cnt;
-       char    str_testdata[256];
 
        i_result        = LibEditText_Init();
        CU_ASSERT( 0x00 == i_result );
@@ -93,7 +98,7 @@ void Test_LibEditText_API_InsertLine_test00_001(void)
        i_result        = LibEditText_InsertLine_toLine( i_tinfoid, 0, " 0: InsertLine Test00_001\n", 26);
        CU_ASSERT( 0x00 == i_result );
 
-       i_result        = LibEditText_InsertLine_toLine( i_tinfoid, 3, " 2: InsertLine Test00_001", 25);
+       i_result        = LibEditText_InsertLine_toLine( i_tinfoid, 2, " 2: InsertLine Test00_001", 25);
        CU_ASSERT( 0x00 == i_result );
 
        i_result        = LibEditText_Debug_DebugTextInfo( i_tinfoid, DEBUG_TEXTINFO_OUTPUT );
@@ -124,14 +129,11 @@ void Test_LibEditText_API_InsertLine_test00_002(void)
        CU_ASSERT( 0x00 == i_result );
 
        for( i_cnt = 1022; i_cnt > 0; i_cnt-- ) {
-               i_len   = snprintf( str_testdata, 255, "%6d Dr.deamon64 libeditext testdata---\n", i_cnt);
+               i_len   = snprintf( str_testdata, 255, "%6d Dr.deamon64 libeditext InsertLine2---\n", i_cnt);
                i_result        = LibEditText_InsertLine_toLine( i_tinfoid, 1, str_testdata, i_len);
                CU_ASSERT( 0x00 == i_result );
        }
-/*
-       i_result        = LibEditText_InsertLine_toLine( i_tinfoid, 1022, "Section TestData", 16);
-       CU_ASSERT( 0x00 == i_result );
-*/
+
        i_result        = LibEditText_Debug_DebugTextInfo( i_tinfoid, DEBUG_TEXTINFO_OUTPUT );
        CU_ASSERT( 0x00 == i_result );
 
@@ -155,12 +157,10 @@ int
 
        CU_add_test( pt_edittext, "EditText_API_AppendLine_test00_001",
                                                                Test_LibEditText_API_AppendLine_test00_001 );
-
        CU_add_test( pt_edittext, "EditText_API_InsertLine_test00_001",
                                                                Test_LibEditText_API_InsertLine_test00_001 );
        CU_add_test( pt_edittext, "EditText_API_InsertLine_test00_002",
                                                                Test_LibEditText_API_InsertLine_test00_002 );
-
        return 0x00;
 }