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"
40 /*----------------------------------------------------------------------
41 ----------------------------------------------------------------------*/
42 LIBEDITTEXT_LINECTRL_EXTERN
44 LibEditText_LineCtrl_InsertLine(
45 LibEditText_TextInfo *p_tinfo,
53 LibEditText_LineInfo *p_lbefore;
54 LibEditText_LineInfo *p_line;
55 LibEditText_LineInfo *p_lnext;
57 assert( NULL != p_tinfo );
59 p_lnext = LibEditText_Section_SearchLine( p_tinfo, dw_line );
60 assert( NULL != p_lnext );
63 p_lbefore = LINFO(p_tinfo, p_lnext->dw_before);
65 dw_strlen = dw_length;
66 if(( 0 == dw_length ) || ( '\n' != *(pb_text + dw_length - 1) ))
69 // Get LineInfo struct
70 dw_buflength = dw_strlen + DRD64_LIBEDITTEXT_DEFAULT_RESERVEBUF_INLINE;
71 p_line = LibEditText_LineInfo_GetEmptyLineInfo( p_tinfo, dw_buflength );
72 if( NULL == p_line ) { return -0x11; }
74 // Link Before & After LineInfo
75 if( NULL != p_lbefore ) {
76 p_lbefore->dw_next = p_line->dw_id;
77 p_line->dw_before = p_lbefore->dw_id;
80 { p_tinfo->dw_line_start = p_line->dw_id; }
82 p_lnext->dw_before = p_line->dw_id;
83 p_line->dw_next = p_lnext->dw_id;
85 // Set LineInfo to SortChain
86 i_result = LibEditText_LineInfo_AddSortChain( p_tinfo, p_line );
87 if( 0x00 != i_result ) { return -0x12; }
90 p_line->dw_strlen = dw_strlen;
91 memcpy( p_tinfo->pb_text + p_line->dw_start, pb_text, dw_length );
92 if( dw_length != dw_strlen )
93 { *(p_tinfo->pb_text + p_line->dw_start + dw_length) = '\n'; }
96 i_result = LibEditText_Section_InsertLine( p_tinfo, dw_line );
97 if( 0x00 != i_result ) { return -0x13; }
99 p_tinfo->dw_maxline++;
105 /*----------------------------------------------------------------------
106 ----------------------------------------------------------------------*/
107 LIBEDITTEXT_API_LINECTRL
109 LibEditText_InsertLine_toLine(
116 LibEditText_TextInfo *p_tinfo;
118 if( 0 > i_tinfoid ) { return -0x01; }
119 p_tinfo = LibEditText_System_GetTextInfo( i_tinfoid );
120 if( NULL == p_tinfo ) { return -0x02; }
122 if( NULL == pstr_text ) { return -0x03; }
124 if( p_tinfo->dw_maxline < (dw_line + 1) ) {
125 i_result = LibEditText_LineCtrl_AppendLine(
126 p_tinfo, (Byte *)pstr_text, dw_length, 0x00 );
129 i_result = LibEditText_LineCtrl_InsertLine(
130 p_tinfo, dw_line, (Byte *)pstr_text, dw_length );
137 /*----------------------------------------------------------------------
138 ----------------------------------------------------------------------*/
139 LIBEDITTEXT_LINECTRL_EXTERN
141 LibEditText_LineCtrl_AppendLine(
142 LibEditText_TextInfo *p_tinfo,
149 Byte str_lf[2] = { '\n', '\0'};
151 LibEditText_LineInfo *p_line;
152 LibEditText_LineInfo *p_before;
154 assert( NULL != p_tinfo );
155 p_before = LINFO(p_tinfo, p_tinfo->dw_line_end);
157 if( NULL == p_before )
158 { goto goto_LibEditText_LineCtrl_AppendLine_prechecked; }
160 if( 0 < p_before->dw_strlen ) {
161 pb_tmp = p_tinfo->pb_text + ((p_before->dw_start) + (p_before->dw_strlen) - 1);
162 if( '\n' == *pb_tmp )
163 { goto goto_LibEditText_LineCtrl_AppendLine_prechecked; }
166 i_result = LibEditText_LineEdit_InsertString(
167 p_tinfo, p_before, p_before->dw_strlen, str_lf, 1);
169 goto_LibEditText_LineCtrl_AppendLine_prechecked:
171 dw_buflength = dw_length + DRD64_LIBEDITTEXT_DEFAULT_RESERVEBUF_INLINE;
172 p_line = LibEditText_LineInfo_GetEmptyLineInfo( p_tinfo, dw_buflength );
173 if( NULL == p_line ) { return -0x11; }
175 /* ReSet p_before for if expand LineInfo memory in GetEmptyLineInfo() func.. */
176 p_before = LINFO(p_tinfo, p_tinfo->dw_line_end);
178 /* p_line->dw_start */
179 if( NULL != p_before )
180 { p_before->dw_next = p_line->dw_id; }
182 { p_tinfo->dw_line_start = p_line->dw_id; }
184 p_line->dw_before = (NULL==p_before ? INVALID_LINE : p_before->dw_id);
185 p_line->dw_strlen = dw_length;
187 i_result = LibEditText_LineInfo_AddSortChain( p_tinfo, p_line );
188 if( 0x00 != i_result ) {
192 memcpy( p_tinfo->pb_text + p_line->dw_start, pstr_text, dw_length );
194 p_tinfo->dw_line_end = p_line->dw_id;
196 /* Normal Append Mode is b_mode=0x00. */
197 if( 0x00 == b_mode ) {
198 i_result = LibEditText_Section_AddSection( p_tinfo );
199 if( 0x00 > i_result ) { return i_result; }
200 else if( 0x00 < i_result ) { i_result = 0x00; }
201 p_tinfo->dw_maxline++;
208 /*----------------------------------------------------------------------
209 ----------------------------------------------------------------------*/
210 LIBEDITTEXT_API_LINECTRL
212 LibEditText_AppendLine(
218 LibEditText_TextInfo *p_tinfo;
220 if( 0 > i_tinfoid ) { return -0x01; }
221 p_tinfo = LibEditText_System_GetTextInfo( i_tinfoid );
222 if( NULL == p_tinfo ) { return -0x02; }
224 if( NULL == pstr_text ) { return -0x03; }
226 i_result = LibEditText_LineCtrl_AppendLine( p_tinfo, (Byte *)pstr_text, dw_length, 0x00 );
232 /* EOF of drd64_.c ----------------------------------- */