OSDN Git Service

* CreateFile: test_libedittext_lineedit.c
[drdeamon64/drdeamon64.git] / libedittext / drd64_libedittext_linectrl.c
1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
2
3                          D r . D e a m o n  6 4
4                         for INTEL64(R), AMD64(R)
5         
6    Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
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.
16
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.
28
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
30
31 /* File Info -----------------------------------------------------------
32 File: drd64_.c
33 Function: 
34 Comment: 
35 ----------------------------------------------------------------------*/
36
37 #define DRD64_SRC_LIBEDITTEXT_LINECTRL
38 #include"drd64_libedittext.h"
39
40
41 /*----------------------------------------------------------------------
42 ----------------------------------------------------------------------*/
43 LIBEDITTEXT_LINECTRL_EXTERN
44 int
45         LibEditText_LineCtrl_AppendLine(
46                 LibEditText_TextInfo            *p_tinfo,
47                 Byte    *pstr_text,
48                 DWord   dw_length,
49                 Byte    b_mode )
50 {
51         int                                             i_result;
52         DWord                                   dw_buflength;
53         Byte                                            str_lf[2]       = { '\n', '\0'};
54         Byte                                            *pb_tmp;
55         LibEditText_LineInfo            *p_line;
56         LibEditText_LineInfo            *p_before;
57
58         assert( NULL != p_tinfo );
59         p_before        = LINFO(p_tinfo, p_tinfo->dw_line_end);
60
61         if( NULL == p_before )
62                 { goto goto_LibEditText_LineCtrl_AppendLine_prechecked; }
63
64         if( 0 < p_before->dw_strlen )   {
65                 pb_tmp  = p_tinfo->pb_text + ((p_before->dw_start) + (p_before->dw_strlen) - 1);
66                 if( '\n' == *pb_tmp )
67                         { goto goto_LibEditText_LineCtrl_AppendLine_prechecked; }
68         }
69
70         i_result        = LibEditText_LineEdit_InsertString(
71                                                         p_tinfo, p_before, p_before->dw_strlen, str_lf, 1);
72
73 goto_LibEditText_LineCtrl_AppendLine_prechecked:
74
75         dw_buflength    = dw_length + DRD64_LIBEDITTEXT_DEFAULT_RESERVEBUF_INLINE;
76         p_line  = LibEditText_LineInfo_GetEmptyLineInfo( p_tinfo, dw_buflength );
77         if( NULL == p_line )    { return -0x11; }
78
79         /* ReSet p_before for if expand LineInfo memory in GetEmptyLineInfo() func.. */
80         p_before        = LINFO(p_tinfo, p_tinfo->dw_line_end);
81         
82         /* p_line->dw_start      */
83         if( NULL != p_before )
84                 { p_before->dw_next     = p_line->dw_id; }
85         else
86                 { p_tinfo->dw_line_start        = p_line->dw_id; }
87
88         p_line->dw_before       = (NULL==p_before ? INVALID_LINE : p_before->dw_id);
89         p_line->dw_strlen       = dw_length;
90
91         i_result    = LibEditText_LineInfo_AddSortChain( p_tinfo, p_line );
92         if( 0x00 != i_result )  {
93                 return -0x12;
94         }
95
96         memcpy( p_tinfo->pb_text + p_line->dw_start, pstr_text, dw_length );
97
98         /* Normal Append Mode is b_mode=0x00. */
99         if( 0x00 == b_mode )    {
100                 i_result        = LibEditText_Section_AppendLine( p_tinfo, p_line );
101                 p_tinfo->dw_maxline++;
102         }
103
104         p_tinfo->dw_line_end    = p_line->dw_id;
105
106         return 0x00;
107 }
108
109
110 /*----------------------------------------------------------------------
111 ----------------------------------------------------------------------*/
112 LIBEDITTEXT_API_LINECTRL
113 int
114         LibEditText_AppendLine(
115                 int             i_tinfoid,
116                 char    *pstr_text,
117                 DWord   dw_length )
118 {
119         int                                             i_result;
120         LibEditText_TextInfo    *p_tinfo;
121
122         if( 0 > i_tinfoid )             { return -0x01; }
123         p_tinfo = LibEditText_System_GetTextInfo( i_tinfoid );
124         if( NULL == p_tinfo )   { return -0x02; }
125
126         if( NULL == pstr_text ) { return -0x03; }
127         
128         i_result        = LibEditText_LineCtrl_AppendLine( p_tinfo, (Byte *)pstr_text, dw_length, 0x00 );
129         
130         return i_result;
131 }
132
133
134 /* EOF of drd64_.c ----------------------------------- */