1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
4 for INTEL64(R), AMD64(R)
6 Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
11 1. Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
31 /* File Info -----------------------------------------------------------
35 ----------------------------------------------------------------------*/
37 #define DRD64_SRC_LIBEDITTEXT_LINEEDIT
38 #include"drd64_libedittext.h"
40 #define LOCATION(n) DRD64_ERR_LOCATION( \
41 DRD64_ERROR_MODULE_LIBEDITTEXT, DRD64_ERROR_ARCH_NODEPEND, \
42 DRD64_SRC_LIBEDITTEXT_LINEEDIT_SRCID, (n))
45 /*----------------------------------------------------------------------
46 ----------------------------------------------------------------------*/
47 #define FUNCID_LibEditText_LineEdit_ClearLine 0x01
48 LIBEDITTEXT_LINEEDIT_EXTERN
50 LibEditText_LineEdit_ClearLine(
51 LibEditText_TextInfo *p_tinfo,
52 LibEditText_LineInfo *p_line )
56 assert( NULL != p_tinfo );
57 assert( NULL != p_line );
59 if(( INVALID_LINE == p_line->dw_before ) && ( INVALID_LINE == p_line->dw_next ))
60 { dw_len = p_line->dw_strlen; }
62 if( 1 == p_line->dw_strlen ) { return 0x00; }
63 dw_len = p_line->dw_strlen - 1;
66 memset( (p_tinfo->pb_text + p_line->dw_start), 0x00, dw_len );
67 p_line->dw_strlen -= dw_len;
73 /*----------------------------------------------------------------------
74 ----------------------------------------------------------------------*/
75 #define FUNCID_LibEditText_LineEdit_DeleteString 0x02
76 LIBEDITTEXT_LINEEDIT_EXTERN
78 LibEditText_LineEdit_DeleteString(
79 LibEditText_TextInfo *p_tinfo,
80 LibEditText_LineInfo *p_line,
88 assert( NULL != p_tinfo );
89 assert( NULL != p_line );
90 assert( p_line->dw_strlen >= (dw_pos + dw_len) );
92 if(( 0 == dw_pos ) && ( dw_len == p_line->dw_strlen )) {
94 i_result = LibEditText_LineCtrl_DeleteLine( p_tinfo, p_line, dw_line );
95 goto goto_LibEditText_LineEdit_DeleteString_post;
98 // Move StringData ---
99 pb_data = p_tinfo->pb_text + p_line->dw_start;
100 memmove( (pb_data + dw_pos), (pb_data + dw_pos + dw_len),
101 (p_line->dw_strlen - dw_pos - dw_len));
102 memset( (pb_data + p_line->dw_strlen - dw_len), 0x00, dw_len );
103 p_line->dw_strlen -= dw_len;
105 assert( 0 < p_line->dw_strlen );
107 if( p_tinfo->dw_line_end == p_line->dw_id )
108 { goto goto_LibEditText_LineEdit_DeleteString_post; }
109 if( '\n' == *(pb_data + p_line->dw_strlen - 1) )
110 { goto goto_LibEditText_LineEdit_DeleteString_post; }
113 i_result = LibEditText_LineCtrl_JoinLine( p_tinfo, p_line, dw_line );
115 goto_LibEditText_LineEdit_DeleteString_post:
120 /*----------------------------------------------------------------------
121 ----------------------------------------------------------------------*/
122 #define FUNCID_LibEditText_LineEdit_InsertString 0x03
123 LIBEDITTEXT_LINEEDIT_EXTERN
125 LibEditText_LineEdit_InsertString(
126 LibEditText_TextInfo *p_tinfo,
127 LibEditText_LineInfo *p_line,
136 assert( NULL != p_tinfo );
137 assert( NULL != p_line );
139 if( 0 == dw_srclen ) {
140 LibBrownie_Error_SetErrorInfo(
141 DRD64_WARNING( DRD64_ERROR_PTN_FAILED_ARG, 0x00, 0x01 ),
142 LOCATION( FUNCID_LibEditText_LineEdit_InsertString ),
143 errno, (QWord)0x00, (QWord)dw_srclen, __LINE__ );
148 /* Check Line Remain-Length & Swap line-buffer ---*/
149 if( p_line->dw_strlen + dw_srclen + 1 > p_line->dw_linelen ) {
150 i_result = LibEditText_LineInfo_ExpandLineBuffer(
152 dw_srclen + DRD64_LIBEDITTEXT_DEFAULT_RESERVEBUF_INLINE);
153 if( 0x00 != i_result ) {
154 LibBrownie_Error_SetErrorInfo(
155 DRD64_ERROR( DRD64_ERROR_PTN_CALLFUNC, 0x01, 0x02 ),
156 LOCATION( FUNCID_LibEditText_LineEdit_InsertString ),
157 errno, (QWord)i_result, (QWord)dw_srclen, __LINE__ );
163 if( p_line->dw_strlen < dw_pos )
164 { dw_pos = p_line->dw_strlen; }
166 pb_pos = p_tinfo->pb_text + p_line->dw_start + dw_pos;
167 assert( NULL != pb_pos );
169 if(( '\n' == *(pb_src + dw_srclen - 1)) && ( 0 < p_line->dw_strlen )) {
170 if( '\n' == *(pb_pos + p_line->dw_strlen - 1)) {
175 if( p_line->dw_strlen > dw_pos ) {
176 dw_length = p_line->dw_strlen - dw_pos + 1;
177 memmove( pb_pos + dw_srclen, pb_pos, dw_length );
180 memcpy( pb_pos, pb_src, dw_srclen );
181 p_line->dw_strlen += dw_srclen;
187 /* EOF of drd64_.c ----------------------------------- */