/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
void
+ LibEditText_LineInfo_ClearLineInfo(
+ LibEditText_LineInfo *p_line,
+ DWord dw_linfoid )
+{
+ assert( NULL != p_line );
+
+ p_line->dw_id = dw_linfoid;
+ p_line->dw_start = 0;
+ p_line->dw_strlen = 0;
+ p_line->dw_linelen = 0;
+ p_line->dw_before = INVALID_LINE;
+ p_line->dw_next = INVALID_LINE;
+ p_line->dw_sortnext = INVALID_LINE;
+
+ return;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+void
LibEditText_LineInfo_MemCopy(
Byte *pb_dest,
Byte *pb_src,
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
+LibEditText_LineInfo *
+ LibEditText_LineInfo_SearchChain(
+ LibEditText_TextInfo *p_tinfo,
+ DWord dw_sort[],
+ int i_element,
+ DWord dw_linelen,
+ LibEditText_LineInfo **pp_lbefore )
+{
+ LibEditText_LineInfo *p_lnow;
+ LibEditText_LineInfo *p_lbefore;
+
+ p_lbefore = NULL;
+ p_lnow = LINFO( p_tinfo, dw_sort[i_element] );
+
+ while( NULL != p_lnow ) {
+ if( dw_linelen >= p_lnow->dw_linelen ) { break; }
+ p_lbefore = p_lnow;
+ p_lnow = LINFO(p_tinfo, p_lbefore->dw_sortnext);
+ }
+
+ if( NULL != pp_lbefore ) { *pp_lbefore = p_lbefore; }
+ return p_lnow;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBEDITTEXT_LINEINFO_EXTERN
+LibEditText_LineInfo *
+ LibEditText_LineInfo_DeliveryLineInfo(
+ LibEditText_TextInfo *p_tinfo,
+ DWord dw_linelen )
+{
+ int i_result;
+ DWord dw_expandsize;
+ LibEditText_LineInfo *p_line = NULL;
+
+ assert( NULL != p_tinfo );
+
+ /* Check Remain Text-Buffer --- */
+ if( p_tinfo->dw_lastsize + dw_linelen >= p_tinfo->dw_bufsize ) {
+ dw_expandsize = (DWord)(p_tinfo->dw_bufsize
+ * DRD64_LIBEDITTEXT_DEFAULT_BUFSIZE_EXPANDFACTOR);
+ i_result = LibEditText_System_ExpandTextBuffer(
+ p_tinfo, dw_expandsize );
+ if( 0x00 != i_result ) {
+ return NULL;
+ }
+ }
+
+ i_result = LibEditText_LineInfo_ExpandLineInfo( p_tinfo, 0 );
+ if( 0x00 != i_result ) { return NULL; }
+
+ p_line = LINFO(p_tinfo, p_tinfo->dw_empty[0]);
+ if( NULL == p_line ) {
+ return NULL;
+ }
+
+ p_line->dw_start = p_tinfo->dw_lastsize;
+ p_tinfo->dw_lastsize += dw_linelen;
+ p_line->dw_linelen = dw_linelen;
+
+ p_tinfo->dw_empty[0] = p_line->dw_sortnext;
+ p_line->dw_sortnext = INVALID_LINE;
+ p_line->dw_strlen = 0;
+
+ p_tinfo->dw_bufline--;
+
+ return p_line;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
LIBEDITTEXT_LINEINFO_EXTERN
int
LibEditText_LineInfo_ExpandLineBuffer(
i_element = LibEditText_LineInfo_CalcSortChainElement( dw_linesize );
- /* Search Empty Chain ---*/
- p_lbefore = NULL;
- p_lnow = LINFO( p_tinfo, p_tinfo->dw_empty[i_element] );
- while( NULL != p_lnow ) {
- if( dw_linesize >= p_lnow->dw_linelen ) { break; }
- p_lbefore = p_lnow;
- p_lnow = LINFO(p_tinfo, p_lbefore->dw_sortnext);
- }
-
+ /* Search Other Line Chain ---*/
+ p_lnow = LibEditText_LineInfo_SearchChain(
+ p_tinfo, p_tinfo->dw_linesort, i_element, dw_linesize, &p_lbefore );
if( NULL != p_lnow ) {
- LibEditText_LineInfo_MoveLineBuffer( p_tinfo, p_lnow, p_line );
+ LibEditText_LineInfo_SwapLineBuffer( p_tinfo, p_lnow, p_line );
goto goto_LibEditText_LineInfo_ExpandLineBuffer_post;
}
- /* Search Other Line Chain ---*/
- p_lbefore = NULL;
- p_lnow = LINFO( p_tinfo, p_tinfo->dw_linesort[i_element] );
- while( NULL != p_lnow ) {
- if( dw_linesize >= p_lnow->dw_linelen ) { break; }
- p_lbefore = p_lnow;
- p_lnow = LINFO(p_tinfo, p_lbefore->dw_sortnext);
- }
-
- if( NULL != p_lnow ) {
- LibEditText_LineInfo_SwapLineBuffer( p_tinfo, p_lnow, p_line );
+ p_lnow = LibEditText_LineInfo_GetEmptyLineInfo( p_tinfo, dw_linesize );
+ if( NULL == p_lnow ) {
goto goto_LibEditText_LineInfo_ExpandLineBuffer_post;
+ i_result = -0x01;
}
- i_result = -0x01;
goto_LibEditText_LineInfo_ExpandLineBuffer_post:
{
int i_result;
int i_element;
+ LibEditText_LineInfo *p_line;
+ LibEditText_LineInfo *p_lbefore;
+
+ assert( NULL != p_tinfo );
+
+ i_element = LibEditText_LineInfo_CalcSortChainElement( dw_linelen );
+
+ // Search EmptyChain in Indicate LineLength Chain ---
+ p_lbefore = NULL;
+ p_line = LibEditText_LineInfo_SearchChain(
+ p_tinfo, p_tinfo->dw_empty, i_element, dw_linelen, &p_lbefore );
+
+ if( NULL != p_line ) {
+ if( NULL != p_lbefore )
+ { p_lbefore->dw_sortnext = p_line->dw_sortnext; }
+ else
+ { p_tinfo->dw_empty[i_element] = p_line->dw_sortnext; }
+ p_line->dw_strlen = 0;
+ p_line->dw_sortnext = INVALID_LINE;
+
+ p_tinfo->dw_bufline--;
+ goto goto_LibEditText_LineInfo_GetEmptyLineInfo_post;
+ }
+
+ p_line = LibEditText_LineInfo_DeliveryLineInfo( p_tinfo, dw_linelen );
+
+goto_LibEditText_LineInfo_GetEmptyLineInfo_post:
+
+ return p_line;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+/*LIBEDITTEXT_LINEINFO_EXTERN
+LibEditText_LineInfo *
+ LibEditText_LineInfo_GetEmptyLineInfo(
+ LibEditText_TextInfo *p_tinfo,
+ DWord dw_linelen )
+{
+ int i_result;
+ int i_element;
DWord dw_expandsize;
LibEditText_LineInfo *p_line;
LibEditText_LineInfo *p_lbefore;
assert( NULL != p_tinfo );
- /* Check Remain Text-Buffer --- */
+ i_element = LibEditText_LineInfo_CalcSortChainElement( dw_linelen );
+
+ // Search EmptyChain in Indicate LineLength Chain ---
+ p_lbefore = NULL;
+ p_line = LibEditText_LineInfo_SearchChain(
+ p_tinfo, p_tinfo->dw_empty, i_element, dw_linelen, &p_lbefore );
+
+ if( NULL != p_line )
+ { goto goto_LibEditText_LineInfo_GetEmptyLineInfo_setresult; }
+
+ // Check Remain Text-Buffer ---
if( p_tinfo->dw_lastsize + dw_linelen >= p_tinfo->dw_bufsize ) {
dw_expandsize = (DWord)(p_tinfo->dw_bufsize
* DRD64_LIBEDITTEXT_DEFAULT_BUFSIZE_EXPANDFACTOR);
i_result = LibEditText_LineInfo_ExpandLineInfo( p_tinfo, 0 );
if( 0x00 != i_result ) { return NULL; }
- i_element = LibEditText_LineInfo_CalcSortChainElement( dw_linelen );
-
- /* Search EmptyChain in Indicate LineLength Chain ---*/
- p_lbefore = NULL;
- p_line = LINFO(p_tinfo, p_tinfo->dw_empty[i_element]);
- if( NULL != p_line ) {
- do {
- if( dw_linelen >= p_line->dw_linelen ) { break; }
- p_lbefore = p_line;
- p_line = LINFO(p_tinfo, p_lbefore->dw_sortnext);
- }while( p_line != NULL );
- }
-
- if( NULL != p_line )
- { goto goto_LibEditText_LineInfo_GetEmptyLineInfo_setresult; }
-
- /* Search EmptyChain in Empty LineLength Chain ---*/
+ // Search EmptyChain in Empty LineLength Chain ---
i_element = 0;
p_lbefore = NULL;
p_line = LINFO(p_tinfo, p_tinfo->dw_empty[i_element]);
p_line->dw_start = p_tinfo->dw_lastsize;
p_tinfo->dw_lastsize += dw_linelen;
+ p_line->dw_linelen = dw_linelen;
goto_LibEditText_LineInfo_GetEmptyLineInfo_setresult:
else
{ p_tinfo->dw_empty[i_element] = p_line->dw_sortnext; }
p_line->dw_strlen = 0;
- p_line->dw_linelen = dw_linelen;
- p_line->dw_before = INVALID_LINE;
- p_line->dw_next = INVALID_LINE;
+// p_line->dw_linelen = dw_linelen;
+ //p_line->dw_before = INVALID_LINE;
+ //p_line->dw_next = INVALID_LINE;
p_line->dw_sortnext = INVALID_LINE;
p_tinfo->dw_bufline--;
goto_LibEditText_LineInfo_GetEmptyLineInfo_post:
return p_line;
-}
+}*/
/*----------------------------------------------------------------------
/* Init LineInfo Data --- */
p_lnow = p_line + p_tinfo->dw_maxline;
for( dw_cnt = p_tinfo->dw_maxline; dw_cnt < dw_newlines; dw_cnt++ ) {
- p_lnow->dw_id = dw_cnt;
- p_lnow->dw_start = 0;
- p_lnow->dw_strlen = 0;
- p_lnow->dw_linelen = 0;
- p_lnow->dw_next = INVALID_LINE;
- p_lnow->dw_before = INVALID_LINE;
- p_lnow->dw_sortnext = INVALID_LINE;
+ LibEditText_LineInfo_ClearLineInfo( p_lnow, dw_cnt );
+ //p_lnow->dw_id = dw_cnt;
+ //p_lnow->dw_start = 0;
+ //p_lnow->dw_strlen = 0;
+ //p_lnow->dw_linelen = 0;
+ //p_lnow->dw_next = INVALID_LINE;
+ //p_lnow->dw_before = INVALID_LINE;
+ //p_lnow->dw_sortnext = INVALID_LINE;
i_result = LibEditText_LineInfo_SetEmptyLineChain( p_tinfo, p_lnow );
p_lnow++;
}
----------------------------------------------------------------------*/
LIBEDITTEXT_SYSTEM_EXTERN
LibEditText_LineInfo *
- LibEditText_LineInfo_InitLineInfo(
+ LibEditText_LineInfo_Init(
LibEditText_TextInfo *p_tinfo,
DWord dw_line )
{
/* Init LineInfo Data --- */
p_lnow = p_line;
for( dw_cnt = 0; dw_cnt < dw_line; dw_cnt++ ) {
- p_lnow->dw_id = dw_cnt;
- p_lnow->dw_next = INVALID_LINE;
- p_lnow->dw_before = INVALID_LINE;
- p_lnow->dw_sortnext = INVALID_LINE;
+ LibEditText_LineInfo_ClearLineInfo( p_lnow, dw_cnt );
+ //p_lnow->dw_id = dw_cnt;
+ //p_lnow->dw_next = INVALID_LINE;
+ //p_lnow->dw_before = INVALID_LINE;
+ //p_lnow->dw_sortnext = INVALID_LINE;
i_result = LibEditText_LineInfo_SetEmptyLineChain( p_tinfo, p_lnow );
p_lnow++;
}
#include"drd64_libedittext.h"
/*----------------------------------------------------------------------
- * Search Line
* Insert Line
* Delete Line
* Expand SectionArea
return dw_sectionid;
}
+#define CALC_LINE2SECTION(m,n) (((n)+1)/(m)->dw_sect_steps)
+#define SECINFO(m,n) ((m)->p_section+(n))
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+DWord
+ LibEditText_Section_BackwardSections_toNearTargetLine(
+ LibEditText_TextInfo *p_tinfo,
+ DWord dw_secid,
+ DWord dw_targetline )
+{
+ LibEditText_LineSection *p_snow;
+ LibEditText_LineSection *p_sbefore;
+
+ assert( NULL != p_tinfo );
+ assert( p_tinfo->dw_sections > dw_secid );
+
+ if( 0 == dw_secid ) { return dw_secid; }
+
+ p_sbefore = SECINFO(p_tinfo, dw_secid);
+
+ do{
+ dw_secid--;
+ p_snow = SECINFO(p_tinfo, dw_secid);
+
+ if(( dw_targetline > p_snow->dw_line )
+ && ( dw_targetline < p_sbefore->dw_line ))
+ { return dw_secid + 1; }
+
+ p_sbefore = p_snow;
+ }while( 0 < dw_secid );
+
+ return 0;
+}
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+DWord
+ LibEditText_Section_ForwardSections_toNearTargetLine(
+ LibEditText_TextInfo *p_tinfo,
+ DWord dw_secid,
+ DWord dw_targetline )
+{
+ LibEditText_LineSection *p_snow;
+ LibEditText_LineSection *p_sbefore;
+
+ assert( NULL != p_tinfo );
+ assert( p_tinfo->dw_sections > dw_secid );
+
+ if( p_tinfo->dw_sections == dw_secid + 1 ) { return dw_secid; }
+
+ p_sbefore = SECINFO(p_tinfo, dw_secid);
+
+ do{
+ dw_secid++;
+ p_snow = SECINFO(p_tinfo, dw_secid);
+
+ if(( dw_targetline < p_snow->dw_line )
+ && ( dw_targetline > p_sbefore->dw_line ))
+ { return dw_secid - 1; }
+
+ p_sbefore = p_snow;
+ }while( p_tinfo->dw_sections > dw_secid );
+
+ return p_tinfo->dw_sections - 1;
+}
+
+/*----------------------------------------------------------------------
+ //dw_line = (p_tinfo->dw_maxline * dw_cnt) / p_tinfo->dw_sections;
+ //dw_nowsec = (p_tinfo->dw_maxline + 1) / p_tinfo->dw_sect_steps;
+----------------------------------------------------------------------*/
+LIBEDITTEXT_SECTION_EXTERN
+LibEditText_LineInfo *
+ LibEditText_Section_SearchLine(
+ LibEditText_TextInfo *p_tinfo,
+ DWord dw_targline )
+{
+ int i_move = 0;
+ DWord dw_secid;
+ DWord dw_line;
+ LibEditText_LineInfo *p_line;
+ LibEditText_LineSection *p_sec;
+
+ dw_secid = CALC_LINE2SECTION(p_tinfo, dw_targline);
+ p_sec = SECINFO(p_tinfo, dw_secid);
+
+ if( dw_targline < p_sec->dw_line ) {
+ i_move = -1;
+ dw_secid = LibEditText_Section_BackwardSections_toNearTargetLine(
+ p_tinfo, dw_secid, dw_targline );
+ }
+ else if( dw_targline > p_sec->dw_line ) {
+ i_move = 1;
+ dw_secid = LibEditText_Section_ForwardSections_toNearTargetLine(
+ p_tinfo, dw_secid, dw_targline );
+ }
+ else {
+ p_line = LINFO(p_tinfo, p_sec->dw_linfoid);
+ goto goto_LibEditText_Section_SearchLine_post;
+ }
+
+ p_sec = SECINFO(p_tinfo, dw_secid);
+ dw_line = p_sec->dw_line;
+ p_line = LINFO(p_tinfo, p_sec->dw_linfoid);
+
+ while( NULL != p_line ) {
+ if( dw_targline == dw_line ) { break; }
+
+ if( -1 == i_move ) {
+ p_line = LINFO(p_tinfo, p_line->dw_before);
+ dw_line--;
+ }
+ else if( 1 == i_move ) {
+ p_line = LINFO(p_tinfo, p_line->dw_next);
+ dw_line++;
+ }
+ }
+
+goto_LibEditText_Section_SearchLine_post:
+ return p_line;
+}
+
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/