#define DRD64_SRC_LIBEDITTEXT_LINECTRL
#include"drd64_libedittext.h"
+#define DRD64_SRC_LIBEDITTEXT_LINECTRL_SRCID 0x04
+#define LOCATION(n) DRD64_ERR_LOCATION( \
+ DRD64_ERROR_MODULE_LIBEDITTEXT, DRD64_ERROR_ARCH_NODEPEND, \
+ DRD64_SRC_LIBEDITTEXT_LINECTRL_SRCID, (n))
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+#define FUNCID_LibEditText_LineCtrl_DeleteLine 0x01
+LIBEDITTEXT_LINECTRL_EXTERN
+int
+ LibEditText_LineCtrl_DeleteLine(
+ LibEditText_TextInfo *p_tinfo,
+ LibEditText_LineInfo *p_line,
+ DWord dw_line )
+{
+ int i_result;
+ Byte *pb_data;
+ LibEditText_LineInfo *p_lbefore;
+ LibEditText_LineInfo *p_lnext;
+
+ assert( NULL != p_tinfo );
+ assert( NULL != p_line );
+
+ if( 1 == p_tinfo->dw_maxline ) { return 0x00; }
+
+ // Check & Remove Section ---
+ LibEditText_Section_DeleteLine( p_tinfo, dw_line );
+
+ // Data Clear ---
+ pb_data = p_tinfo->pb_text + p_line->dw_start;
+ memset( pb_data, 0x00, p_line->dw_linelen );
+ p_line->dw_strlen = 0;
+
+ // Remove Link LineInfo ---
+ p_lbefore = LINFO(p_tinfo, p_line->dw_before);
+ p_lnext = LINFO(p_tinfo, p_line->dw_next);
+
+ if( NULL != p_lbefore )
+ { p_lbefore->dw_next = p_line->dw_next; }
+ if( NULL != p_lnext )
+ { p_lnext->dw_before = p_line->dw_before; }
+ if( p_tinfo->dw_line_start == p_line->dw_id )
+ { p_tinfo->dw_line_start = p_line->dw_next; }
+ if( p_tinfo->dw_line_end == p_line->dw_id )
+ { p_tinfo->dw_line_end = p_line->dw_before; }
+
+ p_line->dw_before = INVALID_LINE;
+ p_line->dw_next = INVALID_LINE;
+
+ // Remove SortChain ---
+ i_result = LibEditText_LineInfo_RemoveSortChain( p_tinfo, p_line );
+ if( 0x00 != i_result ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_CALLFUNC, 0x01, 0x01 ),
+ LOCATION( FUNCID_LibEditText_LineCtrl_DeleteLine ),
+ errno, (QWord)i_result, (QWord)0x00, __LINE__ );
+
+ return i_result;
+ }
+
+ // Add EmptyChain ---
+ i_result = LibEditText_LineInfo_SetEmptyLineChain( p_tinfo, p_line );
+ if( 0x00 != i_result ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_CALLFUNC, 0x01, 0x02 ),
+ LOCATION( FUNCID_LibEditText_LineCtrl_DeleteLine ),
+ errno, (QWord)i_result, (QWord)0x00, __LINE__ );
+
+ return i_result;
+ }
+
+ p_tinfo->dw_maxline--;
+
+ return 0x00;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+#define FUNCID_LibEditText_DeleteLine_toLine 0x02
+LIBEDITTEXT_API_LINECTRL
+int
+ LibEditText_DeleteLine_toLine(
+ int i_tinfoid,
+ DWord dw_line )
+{
+ int i_result = 0x00;
+ LibEditText_TextInfo *p_tinfo;
+ LibEditText_LineInfo *p_line;
+
+ if( 0 > i_tinfoid ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_FAILED_ARG, 0x01, 0x01 ),
+ LOCATION( FUNCID_LibEditText_DeleteLine_toLine ),
+ errno, (QWord)i_tinfoid, (QWord)dw_line, __LINE__ );
+
+ return -0x01; }
+ p_tinfo = LibEditText_System_GetTextInfo( i_tinfoid );
+ if( NULL == p_tinfo ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_NULLPTR, 0x01, 0x02 ),
+ LOCATION( FUNCID_LibEditText_DeleteLine_toLine ),
+ errno, (QWord)i_tinfoid, (QWord)dw_line, __LINE__ );
+
+ return -0x02;
+ }
+
+ p_line = LibEditText_Section_SearchLine( p_tinfo, dw_line );
+ assert( NULL != p_line );
+
+ i_result = LibEditText_LineCtrl_DeleteLine( p_tinfo, p_line, dw_line );
+
+ return i_result;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+#define FUNCID_LibEditText_LineCtrl_JoinLine 0x03
+LIBEDITTEXT_LINECTRL_EXTERN
+int
+ LibEditText_LineCtrl_JoinLine(
+ LibEditText_TextInfo *p_tinfo,
+ LibEditText_LineInfo *p_ldest,
+ DWord dw_line )
+{
+ int i_result;
+ Byte *pb_dest;
+ Byte *pb_src;
+ LibEditText_LineInfo *p_lsrc;
+
+ // Check
+ assert( NULL != p_tinfo );
+ assert( NULL != p_ldest );
+
+ if(( 1 >= p_tinfo->dw_maxline ) && ( 0 == dw_line )) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_WARNING( DRD64_ERROR_PTN_FAILED_ARG, 0x00, 0x01 ),
+ LOCATION( FUNCID_LibEditText_LineCtrl_JoinLine ),
+ errno, (QWord)p_tinfo->dw_maxline, (QWord)dw_line, __LINE__ );
+
+ return 0x01;
+ }
+ if( p_tinfo->dw_line_end == p_ldest->dw_id ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_WARNING( DRD64_ERROR_PTN_FAILED_ARG, 0x00, 0x02 ),
+ LOCATION( FUNCID_LibEditText_LineCtrl_JoinLine ),
+ errno, (QWord)p_tinfo->dw_line_end, (QWord)p_ldest->dw_id, __LINE__ );
+
+ return 0x02;
+ }
+
+ p_lsrc = LINFO(p_tinfo, p_ldest->dw_next);
+ assert( NULL != p_lsrc );
+
+ // Merge Memory data
+ if((p_ldest->dw_strlen + p_lsrc->dw_strlen + 5) > p_ldest->dw_linelen ) {
+ i_result = LibEditText_LineInfo_ExpandLineBuffer(
+ p_tinfo, p_ldest, p_lsrc->dw_linelen );
+ if( 0x00 != i_result ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_CALLFUNC, 0x01, 0x03 ),
+ LOCATION( FUNCID_LibEditText_LineCtrl_JoinLine ),
+ errno, (QWord)i_result, (QWord)0x00, __LINE__ );
+
+ return -0x03;
+ }
+ }
+
+ pb_src = p_tinfo->pb_text + p_lsrc->dw_start;
+ pb_dest = p_tinfo->pb_text + p_ldest->dw_start + p_ldest->dw_strlen;
+ if( '\n' == *(pb_dest - 1) ) {
+ p_ldest->dw_strlen--;
+ pb_dest--;
+ }
+
+ memcpy( pb_dest, pb_src, p_lsrc->dw_strlen );
+ *(pb_dest + p_lsrc->dw_strlen) = '\0';
+
+ p_ldest->dw_strlen += p_lsrc->dw_strlen;
+
+ // delete line
+ i_result = LibEditText_LineCtrl_DeleteLine( p_tinfo, p_lsrc, dw_line + 1 );
+ if( 0x00 != i_result ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_CALLFUNC, 0x01, 0x04 ),
+ LOCATION( FUNCID_LibEditText_LineCtrl_JoinLine ),
+ errno, (QWord)i_result, (QWord)0x00, __LINE__ );
+
+ return -0x04;
+ }
+
+ return 0x00;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+#define FUNCID_LibEditText_JoinLine_toLine 0x04
+LIBEDITTEXT_API_LINECTRL
+int
+ LibEditText_JoinLine_toLine(
+ int i_tinfoid,
+ DWord dw_line )
+{
+ int i_result;
+ LibEditText_TextInfo *p_tinfo;
+ LibEditText_LineInfo *p_line;
+
+ if( 0 > i_tinfoid ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_FAILED_ARG, 0x01, 0x01 ),
+ LOCATION( FUNCID_LibEditText_JoinLine_toLine ),
+ errno, (QWord)i_tinfoid, (QWord)0x00, __LINE__ );
+
+ return -0x01;
+ }
+ p_tinfo = LibEditText_System_GetTextInfo( i_tinfoid );
+ if( NULL == p_tinfo ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_NULLPTR, 0x01, 0x02 ),
+ LOCATION( FUNCID_LibEditText_JoinLine_toLine ),
+ errno, (QWord)i_tinfoid, (QWord)0x00, __LINE__ );
+
+ return -0x02;
+ }
+
+ p_line = LibEditText_Section_SearchLine( p_tinfo, dw_line );
+ assert( NULL != p_line );
+
+ i_result = LibEditText_LineCtrl_JoinLine( p_tinfo, p_line, dw_line );
+
+ return i_result;
+}
+
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
+#define FUNCID_LibEditText_LineCtrl_InsertLine 0x05
+LIBEDITTEXT_LINECTRL_EXTERN
+int
+ LibEditText_LineCtrl_InsertLine(
+ LibEditText_TextInfo *p_tinfo,
+ DWord dw_line,
+ Byte *pb_text,
+ DWord dw_length )
+{
+ int i_result;
+ DWord dw_buflength;
+ DWord dw_strlen;
+ LibEditText_LineInfo *p_lbefore;
+ LibEditText_LineInfo *p_line;
+ LibEditText_LineInfo *p_lnext;
+
+ assert( NULL != p_tinfo );
+
+ // PreProccess
+ dw_strlen = dw_length;
+ if(( 0 == dw_length ) || ( '\n' != *(pb_text + dw_length - 1) ))
+ { 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 ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_CALLFUNC, 0x01, 0x11 ),
+ LOCATION( FUNCID_LibEditText_LineCtrl_InsertLine ),
+ errno, (QWord)dw_buflength, (QWord)0x00, __LINE__ );
+
+ return -0x11;
+ }
+
+ p_lnext = LibEditText_Section_SearchLine( p_tinfo, dw_line );
+ assert( NULL != p_lnext );
+
+ p_lbefore = LINFO(p_tinfo, p_lnext->dw_before);
+
+ // 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 ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_CALLFUNC, 0x01, 0x12 ),
+ LOCATION( FUNCID_LibEditText_LineCtrl_InsertLine ),
+ errno, (QWord)i_result, (QWord)0x00, __LINE__ );
+
+ 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'; }
+
+ // Adjust LineSection
+ i_result = LibEditText_Section_InsertLine( p_tinfo, dw_line );
+ if( 0x00 != i_result ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_CALLFUNC, 0x01, 0x13 ),
+ LOCATION( FUNCID_LibEditText_LineCtrl_InsertLine ),
+ errno, (QWord)i_result, (QWord)0x00, __LINE__ );
+
+ return -0x13;
+ }
+
+ p_tinfo->dw_maxline++;
+
+ return 0x00;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+#define FUNCID_LibEditText_InsertLine_toLine 0x06
+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;
+
+ if( NULL == pstr_text ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_FAILED_ARG, 0x01, 0x03 ),
+ LOCATION( FUNCID_LibEditText_InsertLine_toLine ),
+ errno, (QWord)0x00, (QWord)0x00, __LINE__ );
+
+ return -0x01;
+ }
+
+ if( 0 > i_tinfoid ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_FAILED_ARG, 0x01, 0x02 ),
+ LOCATION( FUNCID_LibEditText_InsertLine_toLine ),
+ errno, (QWord)i_tinfoid, (QWord)0x00, __LINE__ );
+
+ return -0x02;
+ }
+ p_tinfo = LibEditText_System_GetTextInfo( i_tinfoid );
+ if( NULL == p_tinfo ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_FAILED_ARG, 0x01, 0x03 ),
+ LOCATION( FUNCID_LibEditText_InsertLine_toLine ),
+ errno, (QWord)i_tinfoid, (QWord)0x00, __LINE__ );
+
+ return -0x03;
+ }
+
+ if( p_tinfo->dw_maxline < (dw_line + 1) ) {
+ i_result = LibEditText_LineCtrl_AppendLine(
+ p_tinfo, (Byte *)pstr_text, dw_length, 0x00 );
+ }
+ else {
+ i_result = LibEditText_LineCtrl_InsertLine(
+ p_tinfo, dw_line, (Byte *)pstr_text, dw_length );
+ }
+
+ return i_result;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+#define FUNCID_LibEditText_LineCtrl_AppendLine 0x07
LIBEDITTEXT_LINECTRL_EXTERN
int
LibEditText_LineCtrl_AppendLine(
{
int i_result;
DWord dw_buflength;
+ Byte str_lf[2] = { '\n', '\0'};
+ Byte *pb_tmp;
LibEditText_LineInfo *p_line;
LibEditText_LineInfo *p_before;
assert( NULL != p_tinfo );
p_before = LINFO(p_tinfo, p_tinfo->dw_line_end);
+ if( NULL == p_before )
+ { goto goto_LibEditText_LineCtrl_AppendLine_prechecked; }
+
+ if( 0 < p_before->dw_strlen ) {
+ pb_tmp = p_tinfo->pb_text + ((p_before->dw_start) + (p_before->dw_strlen) - 1);
+ if( '\n' == *pb_tmp )
+ { goto goto_LibEditText_LineCtrl_AppendLine_prechecked; }
+ }
+
+ i_result = LibEditText_LineEdit_InsertString(
+ p_tinfo, p_before, p_before->dw_strlen, str_lf, 1);
+
+goto_LibEditText_LineCtrl_AppendLine_prechecked:
+
dw_buflength = dw_length + DRD64_LIBEDITTEXT_DEFAULT_RESERVEBUF_INLINE;
p_line = LibEditText_LineInfo_GetEmptyLineInfo( p_tinfo, dw_buflength );
- if( NULL == p_line ) { return -0x11; }
+ if( NULL == p_line ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_CALLFUNC, 0x01, 0x11 ),
+ LOCATION( FUNCID_LibEditText_LineCtrl_AppendLine ),
+ errno, (QWord)dw_buflength, (QWord)0x00, __LINE__ );
+
+ return -0x11;
+ }
+
+ /* ReSet p_before for if expand LineInfo memory in GetEmptyLineInfo() func.. */
+ p_before = LINFO(p_tinfo, p_tinfo->dw_line_end);
/* p_line->dw_start */
if( NULL != p_before )
else
{ p_tinfo->dw_line_start = p_line->dw_id; }
- p_line->dw_strlen = dw_length;
p_line->dw_before = (NULL==p_before ? INVALID_LINE : p_before->dw_id);
+ p_line->dw_strlen = dw_length;
i_result = LibEditText_LineInfo_AddSortChain( p_tinfo, p_line );
if( 0x00 != i_result ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_CALLFUNC, 0x01, 0x12 ),
+ LOCATION( FUNCID_LibEditText_LineCtrl_AppendLine ),
+ errno, (QWord)i_result, (QWord)0x00, __LINE__ );
+
return -0x12;
}
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 );
+ i_result = LibEditText_Section_AddSection( p_tinfo );
+ if( 0x00 > i_result ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_CALLFUNC, 0x01, 0x20 ),
+ LOCATION( FUNCID_LibEditText_LineCtrl_AppendLine ),
+ errno, (QWord)i_result, (QWord)0x00, __LINE__ );
+
+ return i_result;
+ }
+ else if( 0x00 < i_result ) { i_result = 0x00; }
+
p_tinfo->dw_maxline++;
}
- p_tinfo->dw_line_end = p_line->dw_id;
-
return 0x00;
}
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
+#define FUNCID_LibEditText_AppendLine 0x08
LIBEDITTEXT_API_LINECTRL
int
LibEditText_AppendLine(
int i_tinfoid,
- Byte *pstr_text,
+ char *pstr_text,
DWord dw_length )
{
int i_result;
LibEditText_TextInfo *p_tinfo;
- if( 0 > i_tinfoid ) { return -0x01; }
- p_tinfo = LibEditText_System_GetTextInfo( i_tinfoid );
- if( NULL == p_tinfo ) { return -0x02; }
+ if( NULL == pstr_text ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_FAILED_ARG, 0x01, 0x01 ),
+ LOCATION( FUNCID_LibEditText_AppendLine ),
+ errno, (QWord)0x00, (QWord)0x00, __LINE__ );
- if( NULL == pstr_text ) { return -0x03; }
+ return -0x01;
+ }
- i_result = LibEditText_LineCtrl_AppendLine( p_tinfo, pstr_text, dw_length, 0x00 );
+ if( 0 > i_tinfoid ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_FAILED_ARG, 0x01, 0x02 ),
+ LOCATION( FUNCID_LibEditText_AppendLine ),
+ errno, (QWord)i_tinfoid, (QWord)0x00, __LINE__ );
+
+ return -0x02;
+ }
+ p_tinfo = LibEditText_System_GetTextInfo( i_tinfoid );
+ if( NULL == p_tinfo ) {
+ LibBrownie_Error_SetErrorInfo(
+ DRD64_ERROR( DRD64_ERROR_PTN_NULLPTR, 0x01, 0x03 ),
+ LOCATION( FUNCID_LibEditText_AppendLine ),
+ errno, (QWord)i_tinfoid, (QWord)0x00, __LINE__ );
+
+ return -0x03;
+ }
+
+ i_result = LibEditText_LineCtrl_AppendLine( p_tinfo, (Byte *)pstr_text, dw_length, 0x00 );
return i_result;
}