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_LINECTRL
38 #include"drd64_libedittext.h"
41 /*----------------------------------------------------------------------
42 ----------------------------------------------------------------------*/
43 LIBEDITTEXT_LINECTRL_EXTERN
45 LibEditText_LineCtrl_DeleteLine(
46 LibEditText_TextInfo *p_tinfo,
47 LibEditText_LineInfo *p_line,
52 LibEditText_LineInfo *p_lbefore;
53 LibEditText_LineInfo *p_lnext;
55 assert( NULL != p_tinfo );
56 assert( NULL != p_line );
58 if( 1 == p_tinfo->dw_maxline ) { return 0x00; }
60 // Check & Remove Section ---
61 LibEditText_Section_DeleteLine( p_tinfo, dw_line );
64 pb_data = p_tinfo->pb_text + p_line->dw_start;
65 memset( pb_data, 0x00, p_line->dw_linelen );
66 p_line->dw_strlen = 0;
68 // Remove Link LineInfo ---
69 p_lbefore = LINFO(p_tinfo, p_line->dw_before);
70 p_lnext = LINFO(p_tinfo, p_line->dw_next);
72 if( NULL != p_lbefore )
73 { p_lbefore->dw_next = p_line->dw_next; }
75 { p_lnext->dw_before = p_line->dw_before; }
76 if( p_tinfo->dw_line_start == p_line->dw_id )
77 { p_tinfo->dw_line_start = p_line->dw_next; }
78 if( p_tinfo->dw_line_end == p_line->dw_id )
79 { p_tinfo->dw_line_end = p_line->dw_before; }
81 p_line->dw_before = INVALID_LINE;
82 p_line->dw_next = INVALID_LINE;
84 // Remove SortChain ---
85 i_result = LibEditText_LineInfo_RemoveSortChain( p_tinfo, p_line );
86 if( 0x00 != i_result ) { return i_result; }
89 i_result = LibEditText_LineInfo_SetEmptyLineChain( p_tinfo, p_line );
90 if( 0x00 != i_result ) { return i_result; }
92 p_tinfo->dw_maxline--;
98 /*----------------------------------------------------------------------
99 ----------------------------------------------------------------------*/
100 LIBEDITTEXT_API_LINECTRL
102 LibEditText_DeleteLine_toLine(
107 LibEditText_TextInfo *p_tinfo;
108 LibEditText_LineInfo *p_line;
110 if( 0 > i_tinfoid ) { return -0x01; }
111 p_tinfo = LibEditText_System_GetTextInfo( i_tinfoid );
112 if( NULL == p_tinfo ) { return -0x02; }
114 p_line = LibEditText_Section_SearchLine( p_tinfo, dw_line );
115 assert( NULL != p_line );
117 i_result = LibEditText_LineCtrl_DeleteLine( p_tinfo, p_line, dw_line );
123 /*----------------------------------------------------------------------
124 ----------------------------------------------------------------------*/
125 LIBEDITTEXT_LINECTRL_EXTERN
127 LibEditText_LineCtrl_InsertLine(
128 LibEditText_TextInfo *p_tinfo,
136 LibEditText_LineInfo *p_lbefore;
137 LibEditText_LineInfo *p_line;
138 LibEditText_LineInfo *p_lnext;
140 assert( NULL != p_tinfo );
142 p_lnext = LibEditText_Section_SearchLine( p_tinfo, dw_line );
143 assert( NULL != p_lnext );
146 p_lbefore = LINFO(p_tinfo, p_lnext->dw_before);
148 dw_strlen = dw_length;
149 if(( 0 == dw_length ) || ( '\n' != *(pb_text + dw_length - 1) ))
152 // Get LineInfo struct
153 dw_buflength = dw_strlen + DRD64_LIBEDITTEXT_DEFAULT_RESERVEBUF_INLINE;
154 p_line = LibEditText_LineInfo_GetEmptyLineInfo( p_tinfo, dw_buflength );
155 if( NULL == p_line ) { return -0x11; }
157 // Link Before & After LineInfo
158 if( NULL != p_lbefore ) {
159 p_lbefore->dw_next = p_line->dw_id;
160 p_line->dw_before = p_lbefore->dw_id;
163 { p_tinfo->dw_line_start = p_line->dw_id; }
165 p_lnext->dw_before = p_line->dw_id;
166 p_line->dw_next = p_lnext->dw_id;
168 // Set LineInfo to SortChain
169 i_result = LibEditText_LineInfo_AddSortChain( p_tinfo, p_line );
170 if( 0x00 != i_result ) { return -0x12; }
172 // Set Init. TextData
173 p_line->dw_strlen = dw_strlen;
174 memcpy( p_tinfo->pb_text + p_line->dw_start, pb_text, dw_length );
175 if( dw_length != dw_strlen )
176 { *(p_tinfo->pb_text + p_line->dw_start + dw_length) = '\n'; }
178 // Adjust LineSection
179 i_result = LibEditText_Section_InsertLine( p_tinfo, dw_line );
180 if( 0x00 != i_result ) { return -0x13; }
182 p_tinfo->dw_maxline++;
188 /*----------------------------------------------------------------------
189 ----------------------------------------------------------------------*/
190 LIBEDITTEXT_API_LINECTRL
192 LibEditText_InsertLine_toLine(
199 LibEditText_TextInfo *p_tinfo;
201 if( 0 > i_tinfoid ) { return -0x01; }
202 p_tinfo = LibEditText_System_GetTextInfo( i_tinfoid );
203 if( NULL == p_tinfo ) { return -0x02; }
205 if( NULL == pstr_text ) { return -0x03; }
207 if( p_tinfo->dw_maxline < (dw_line + 1) ) {
208 i_result = LibEditText_LineCtrl_AppendLine(
209 p_tinfo, (Byte *)pstr_text, dw_length, 0x00 );
212 i_result = LibEditText_LineCtrl_InsertLine(
213 p_tinfo, dw_line, (Byte *)pstr_text, dw_length );
220 /*----------------------------------------------------------------------
221 ----------------------------------------------------------------------*/
222 LIBEDITTEXT_LINECTRL_EXTERN
224 LibEditText_LineCtrl_AppendLine(
225 LibEditText_TextInfo *p_tinfo,
232 Byte str_lf[2] = { '\n', '\0'};
234 LibEditText_LineInfo *p_line;
235 LibEditText_LineInfo *p_before;
237 assert( NULL != p_tinfo );
238 p_before = LINFO(p_tinfo, p_tinfo->dw_line_end);
240 if( NULL == p_before )
241 { goto goto_LibEditText_LineCtrl_AppendLine_prechecked; }
243 if( 0 < p_before->dw_strlen ) {
244 pb_tmp = p_tinfo->pb_text + ((p_before->dw_start) + (p_before->dw_strlen) - 1);
245 if( '\n' == *pb_tmp )
246 { goto goto_LibEditText_LineCtrl_AppendLine_prechecked; }
249 i_result = LibEditText_LineEdit_InsertString(
250 p_tinfo, p_before, p_before->dw_strlen, str_lf, 1);
252 goto_LibEditText_LineCtrl_AppendLine_prechecked:
254 dw_buflength = dw_length + DRD64_LIBEDITTEXT_DEFAULT_RESERVEBUF_INLINE;
255 p_line = LibEditText_LineInfo_GetEmptyLineInfo( p_tinfo, dw_buflength );
256 if( NULL == p_line ) { return -0x11; }
258 /* ReSet p_before for if expand LineInfo memory in GetEmptyLineInfo() func.. */
259 p_before = LINFO(p_tinfo, p_tinfo->dw_line_end);
261 /* p_line->dw_start */
262 if( NULL != p_before )
263 { p_before->dw_next = p_line->dw_id; }
265 { p_tinfo->dw_line_start = p_line->dw_id; }
267 p_line->dw_before = (NULL==p_before ? INVALID_LINE : p_before->dw_id);
268 p_line->dw_strlen = dw_length;
270 i_result = LibEditText_LineInfo_AddSortChain( p_tinfo, p_line );
271 if( 0x00 != i_result ) {
275 memcpy( p_tinfo->pb_text + p_line->dw_start, pstr_text, dw_length );
277 p_tinfo->dw_line_end = p_line->dw_id;
279 /* Normal Append Mode is b_mode=0x00. */
280 if( 0x00 == b_mode ) {
281 i_result = LibEditText_Section_AddSection( p_tinfo );
282 if( 0x00 > i_result ) { return i_result; }
283 else if( 0x00 < i_result ) { i_result = 0x00; }
285 p_tinfo->dw_maxline++;
292 /*----------------------------------------------------------------------
293 ----------------------------------------------------------------------*/
294 LIBEDITTEXT_API_LINECTRL
296 LibEditText_AppendLine(
302 LibEditText_TextInfo *p_tinfo;
304 if( 0 > i_tinfoid ) { return -0x01; }
305 p_tinfo = LibEditText_System_GetTextInfo( i_tinfoid );
306 if( NULL == p_tinfo ) { return -0x02; }
308 if( NULL == pstr_text ) { return -0x03; }
310 i_result = LibEditText_LineCtrl_AppendLine( p_tinfo, (Byte *)pstr_text, dw_length, 0x00 );
316 /* EOF of drd64_.c ----------------------------------- */