OSDN Git Service

* CreateFile: drd64_libedittext_cursorfind.[ch]
authorKoine Yuusuke(koinec) <koinec@users.sourceforge.jp>
Sun, 9 Aug 2015 05:22:49 +0000 (14:22 +0900)
committerKoine Yuusuke(koinec) <koinec@users.sourceforge.jp>
Sun, 9 Aug 2015 05:22:49 +0000 (14:22 +0900)
* Implement: Find String from Cursor-postion Function (Non-Tested)

include/libedittext.h
libedittext/Makefile
libedittext/drd64_libedittext.h
libedittext/drd64_libedittext_config.h
libedittext/drd64_libedittext_cursorfind.c [new file with mode: 0644]
libedittext/drd64_libedittext_cursorfind.h [new file with mode: 0644]
libedittext/drd64_libedittext_cursorinfo.c
libedittext/drd64_libedittext_cursorinfo.h
libedittext/drd64_libedittext_types.h

index a86801e..c954e57 100644 (file)
@@ -42,6 +42,14 @@ Comment:
 #include"../include/drd64_error.h"
 #include"../include/drd64_conf.h"
 
+#define        LIBEDITTEXT_FLAGFIND_NORMAL                     0x00
+#define        LIBEDITTEXT_FLAGFIND_IGNOREICASE        0x01
+
+#define        LIBEDITTEXT_RET_FINDMATCH                       0x00
+#define        LIBEDITTEXT_RET_FINDMATCH_ROUND         0x01
+#define        LIBEDITTEXT_RET_FINDNOMATCH                     0x02
+
+
 #ifdef DRD64_SRC_LIBEDITTEXT_SYSTEM
        #define LIBEDITTEXT_API_SYSTEM
 #else
index 66c742c..286b982 100644 (file)
@@ -61,6 +61,7 @@ OBJS = \
                drd64_libedittext_cursorinfo.o \
                drd64_libedittext_cursorctrl.o \
                drd64_libedittext_cursormove.o \
+               drd64_libedittext_cursorfind.o \
                drd64_libedittext_cursorapi_info.o \
                drd64_libedittext_cursorapi_edit.o \
                drd64_libedittext_cursorapi_move.o \
@@ -78,6 +79,7 @@ HEADER = \
                drd64_libedittext_cursorinfo.h \
                drd64_libedittext_cursorctrl.h \
                drd64_libedittext_cursormove.h \
+               drd64_libedittext_cursorfind.h \
                drd64_libedittext_undoinfo.h \
                drd64_libedittext_undoedit.h \
                drd64_libedittext_system.h \
@@ -137,6 +139,9 @@ drd64_libedittext_cursorctrl.o: drd64_libedittext_cursorctrl.c $(HEADER)
 drd64_libedittext_cursormove.o: drd64_libedittext_cursormove.c $(HEADER)
        $(CC) -c -o drd64_libedittext_cursormove.o $(FLAGS_DEBUG) $(FLAGS_COMPILE) \
                                drd64_libedittext_cursormove.c
+drd64_libedittext_cursorfind.o: drd64_libedittext_cursorfind.c $(HEADER)
+       $(CC) -c -o drd64_libedittext_cursorfind.o $(FLAGS_DEBUG) $(FLAGS_COMPILE) \
+                               drd64_libedittext_cursorfind.c
 drd64_libedittext_cursorapi_info.o: drd64_libedittext_cursorapi_info.c $(HEADER)
        $(CC) -c -o drd64_libedittext_cursorapi_info.o $(FLAGS_DEBUG) $(FLAGS_COMPILE) \
                                drd64_libedittext_cursorapi_info.c
index f6cb0a1..234eca9 100644 (file)
@@ -44,6 +44,7 @@ Comment:
 #include<string.h>
 #include<fcntl.h>
 #include<errno.h>
+#include<regex.h>
 #include<sys/types.h>
 #include<sys/stat.h>
 
@@ -66,6 +67,7 @@ Comment:
 #include"drd64_libedittext_cursorinfo.h"
 #include"drd64_libedittext_cursorctrl.h"
 #include"drd64_libedittext_cursormove.h"
+#include"drd64_libedittext_cursorfind.h"
 #include"drd64_libedittext_undoinfo.h"
 #include"drd64_libedittext_undoedit.h"
 #include"drd64_libedittext_debug.h"
@@ -82,6 +84,7 @@ Comment:
 #define        DRD64_SRC_LIBEDITTEXT_CURSORINFO_SRCID          0x31
 #define        DRD64_SRC_LIBEDITTEXT_CURSORCTRL_SRCID          0x32
 #define        DRD64_SRC_LIBEDITTEXT_CURSORMOVE_SRCID          0x33
+#define        DRD64_SRC_LIBEDITTEXT_CURSORFIND_SRCID          0x34
 #define        DRD64_SRC_LIBEDITTEXT_CURSORAPI_INFO_SRCID      0x37
 #define        DRD64_SRC_LIBEDITTEXT_CURSORAPI_EDIT_SRCID      0x38
 #define        DRD64_SRC_LIBEDITTEXT_CURSORAPI_MOVE_SRCID      0x39
index dfcf8f9..2264611 100644 (file)
@@ -65,6 +65,8 @@ Comment:
 
 #define        DRD64_LIBEDITTEXT_DEFAULT_UNDOINFO_BUFSIZE                      65536
 
+#define        DRD64_LIBEDITTEXT_DEFAULT_REGSTR_SIZE                           256
+
 #endif /* DRD64_HEADER_XXX */
 
 /* EOF of drd64_.h ----------------------------------- */
diff --git a/libedittext/drd64_libedittext_cursorfind.c b/libedittext/drd64_libedittext_cursorfind.c
new file mode 100644 (file)
index 0000000..48cd7d5
--- /dev/null
@@ -0,0 +1,249 @@
+/*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
+
+                         D r . D e a m o n  6 4
+                        for INTEL64(R), AMD64(R)
+       
+   Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+    this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+
+DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
+
+/* File Info -----------------------------------------------------------
+File: drd64_.c
+Function: 
+Comment: 
+----------------------------------------------------------------------*/
+
+#define        DRD64_SRC_LIBEDITTEXT_CURSORFIND
+#include"drd64_libedittext.h"
+
+#define        LOCATION(n)     DRD64_ERR_LOCATION( \
+                                               DRD64_ERROR_MODULE_LIBEDITTEXT, DRD64_ERROR_ARCH_NODEPEND, \
+                                               DRD64_SRC_LIBEDITTEXT_CURSORFIND_SRCID, (n))
+
+
+/*----------------------------------------------------------------------
+FindString
+FindNext
+BackFindString
+BackFindNext
+----------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+int
+       LibEditText_CursorFind_SetRegexString(
+               LibEditText_Cursor      *p_cursor,
+               char                            *pstr_regex,
+               DWord                           dw_regexlen )
+{
+       char    *pstr_now;
+       DWord   dw_cnt;
+
+       assert( NULL != p_cursor );
+       assert( NULL != pstr_regex );
+
+       // Check regex length & NULL terminator ---
+       if( DRD64_LIBEDITTEXT_DEFAULT_REGSTR_SIZE <= dw_regexlen )      {
+               return -0x01;
+       }
+
+       pstr_now        = (pstr_regex + dw_regexlen);
+       for( dw_cnt = dw_regexlen; dw_cnt > 0; dw_cnt-- )       {
+               if( *pstr_now == '\0' )         { break; }
+               pstr_now--;
+       }
+
+       if( 0 == dw_cnt )       {
+               return -0x02;
+       }
+
+       // Set regex string to CursorInfo ---
+       strncpy( p_cursor->str_regstr, pstr_regex, (dw_cnt + 1) );
+
+       return 0x00;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+DWord
+       LibEditText_CursorFind_GetFindingPostion(
+               LibEditText_Cursor      *p_cursor )
+{
+       DWord   dw_pos;
+
+       dw_pos  = p_cursor->dw_pos;
+       
+       if( 0 < p_cursor->dw_find_prevpos_len ) {
+               if( p_cursor->dw_lineid != p_cursor->dw_find_prevlineid )
+                       { goto  goto_LibEditText_CursorFind_GetFindingPostion_post; }
+
+               if( p_cursor->dw_pos < p_cursor->dw_find_prevpos_start )
+                       { goto  goto_LibEditText_CursorFind_GetFindingPostion_post; }
+
+               if( p_cursor->dw_pos >=
+                               (p_cursor->dw_find_prevpos_start + p_cursor->dw_find_prevpos_len ) )
+                       { goto  goto_LibEditText_CursorFind_GetFindingPostion_post; }
+
+               dw_pos  = p_cursor->dw_find_prevpos_start + p_cursor->dw_find_prevpos_len;
+       }
+
+goto_LibEditText_CursorFind_GetFindingPostion_post:
+       return dw_pos;
+}
+               
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBEDITTEXT_CURSORFIND_EXTERN
+int
+       LibEditText_CursorFind_FindString(
+               LibEditText_TextInfo    *p_tinfo, 
+               LibEditText_Cursor              *p_cursor,
+               char                                    *pstr_regex,
+               DWord                                   dw_regexlen,
+               Byte                                    b_flagfind )
+{
+       int             i_result;
+       int             i_flag;
+       int             i_round;
+       Byte    *pb_start;
+       DWord   dw_pstart;
+       DWord   dw_lnow;
+       DWord   dw_len;
+       DWord   dw_lidbase;
+       LibEditText_LineInfo    *p_line;
+       regmatch_t      t_match;
+
+       assert( NULL != p_tinfo );
+       assert( NULL != p_cursor );
+       assert( NULL != pstr_regex );
+
+       // Check & Set regex String ---
+       i_result        = LibEditText_CursorFind_SetRegexString( p_cursor, pstr_regex, dw_regexlen );
+       if( 0x00 != i_result )  {
+               return i_result;
+       }
+
+       // Clear Before Find Data ---
+       if( NULL != p_cursor->pt_findreg )      {
+               regfree( p_cursor->pt_findreg );
+               p_cursor->pt_findreg    = NULL;
+       }
+       
+       // Compile regex string ---
+       i_flag  = REG_EXTENDED;
+       if( LIBEDITTEXT_FLAGFIND_IGNOREICASE & b_flagfind ) { i_flag    |= REG_ICASE; }
+
+       i_result        = regcomp( p_cursor->pt_findreg, p_cursor->str_regstr, i_flag );
+       if( 0x00 != i_result )  {
+
+               return i_result;
+       }
+
+       // Exec Find ---
+       p_line  = LINFO(p_tinfo, p_cursor->dw_lineid);
+       assert( NULL != p_line );
+
+       dw_lidbase      = p_line->dw_id;
+       dw_lnow         = p_cursor->dw_line;
+       dw_pstart       = LibEditText_CursorFind_GetFindingPostion( p_cursor );
+       pb_start        = p_tinfo->pb_text + p_line->dw_start + dw_pstart;
+       i_round         = 0x00;
+
+       if( 0 < dw_pstart )     { i_flag        = REG_NOTBOL; }
+       else                            { i_flag        = 0x00; }
+
+       do      {
+
+               i_result        = regexec( p_cursor->pt_findreg, (const char *)pb_start,
+                                                               1, &t_match, i_flag );
+               if( 0x00 == i_result )  { break; }
+               else if( REG_NOMATCH != i_result )      {
+                       return -0x10;
+               }
+
+               // Going to Next-Line ---
+               i_flag  = 0x00;
+               p_line  = LINFO(p_tinfo, p_line->dw_next);
+               dw_lnow++;
+               if( NULL == p_line )    {
+                       p_line  = LINFO(p_tinfo, p_tinfo->dw_line_start);
+                       dw_lnow = 0;
+                       i_round = 0x01;
+               }
+               assert( NULL != p_line );
+               dw_pstart       = 0;
+               pb_start        = p_tinfo->pb_text + p_line->dw_start;
+
+       }while( p_line->dw_id != dw_lidbase );
+       
+       if( p_line->dw_id == dw_lidbase )
+               { return LIBEDITTEXT_RET_FINDNOMATCH; } // NO match string in Text. 
+
+       dw_pstart       += (DWord)t_match.rm_so;                                        // Find String Pos.
+       dw_len          = (DWord)(t_match.rm_eo - t_match.rm_so);       // Find String Len.
+       // Find String Line is dw_lnow.
+
+       assert( dw_lnow < p_tinfo->dw_maxline );
+       assert( dw_pstart < p_line->dw_strlen );
+
+       i_result        = LibEditText_CursorInfo_LocateCursor( p_tinfo, p_cursor, p_line, dw_lnow );
+       if( 0x00 != i_result )  {
+               return -0x20;
+       }
+
+       i_result        = LibEditText_CursorMove_SetPosition( p_tinfo, p_cursor, dw_pstart );
+       if( 0x00 != i_result )  {
+               return -0x21;
+       }
+       
+       p_cursor->dw_find_prevpos_start = dw_pstart;
+       p_cursor->dw_find_prevpos_len   = dw_len;
+       p_cursor->dw_find_prevlineid    = p_line->dw_id;
+
+       i_result        = LIBEDITTEXT_RET_FINDMATCH;
+       if( 0x00 != i_round )   { i_result      = LIBEDITTEXT_RET_FINDMATCH_ROUND; }
+
+       return i_result;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+/*LIBEDITTEXT_CURSORFIND_EXTERN
+int
+       LibEditText_CursorCtrl_AdjustCursorPosition_DeleteString(
+                       LibEditText_TextInfo    *p_tinfo,
+                       LibEditText_LineInfo    *p_line, 
+                       DWord   dw_start,
+                       DWord   dw_len )
+{
+       
+       return 0x00;
+}*/
+
+
+/* EOF of drd64_.c ----------------------------------- */
diff --git a/libedittext/drd64_libedittext_cursorfind.h b/libedittext/drd64_libedittext_cursorfind.h
new file mode 100644 (file)
index 0000000..8543a20
--- /dev/null
@@ -0,0 +1,59 @@
+/*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
+
+                         D r . D e a m o n  6 4
+                        for INTEL64(R), AMD64(R)
+       
+   Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+    this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+
+DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
+
+/* File Info -----------------------------------------------------------
+File: drd64_.h
+Function: Header 
+Comment: 
+----------------------------------------------------------------------*/
+
+#ifndef DRD64_HEADER_LIBEDITTEXT_CURSORFIND
+#define DRD64_HEADER_LIBEDITTEXT_CURSORFIND
+
+#ifdef DRD64_SRC_LIBEDITTEXT_CURSORFIND
+       #define LIBEDITTEXT_CURSORFIND_EXTERN
+#else
+       #define LIBEDITTEXT_CURSORFIND_EXTERN   extern
+#endif
+
+#if defined DRD64_SRC_LIBEDITTEXT_CURSORFIND
+       #define LIBEDITTEXT_CURSORFIND_INTERNALFUNC
+#elif defined DRD64_SRC_TEST_LIBEDITTEXT_CURSORFIND
+       #define LIBEDITTEXT_CURSORFIND_INTERNALFUNC
+#endif
+
+
+
+#ifdef LIBEDITTEXT_CURSORFIND_INTERNALFUNC
+#endif
+
+#endif /* DRD64_HEADER_XXX */
+
+/* EOF of drd64_.h ----------------------------------- */
index eed98c1..d032dfc 100644 (file)
@@ -202,6 +202,7 @@ void
 
 /*----------------------------------------------------------------------
 ----------------------------------------------------------------------*/
+LIBEDITTEXT_CURSORINFO_EXTERN
 int
        LibEditText_CursorInfo_LocateCursor(
                        LibEditText_TextInfo    *p_tinfo, 
index 3732652..131528a 100644 (file)
@@ -70,6 +70,10 @@ LIBEDITTEXT_CURSORINFO_EXTERN
        void LibEditText_CursorInfo_ClearCurrentCursor(
                        LibEditText_TextInfo *p_tinfo );
 LIBEDITTEXT_CURSORINFO_EXTERN
+       int LibEditText_CursorInfo_LocateCursor(
+                       LibEditText_TextInfo *p_tinfo, LibEditText_Cursor *p_cursor,
+                       LibEditText_LineInfo *p_curline, DWord dw_curlrow );
+LIBEDITTEXT_CURSORINFO_EXTERN
        int LibEditText_CursorInfo_JumpCursor(
                        LibEditText_TextInfo *p_tinfo, LibEditText_Cursor *p_cursor, DWord dw_targline );
 LIBEDITTEXT_CURSORINFO_EXTERN
index b35951c..4dfc200 100644 (file)
@@ -85,6 +85,14 @@ typedef struct       {
        DWord   dw_now_rngline;
 
        Byte    b_update;
+
+       /* Find Data --- */
+       char    str_regstr[DRD64_LIBEDITTEXT_DEFAULT_REGSTR_SIZE];
+       regex_t *pt_findreg;
+       DWord   dw_find_prevpos_start;
+       DWord   dw_find_prevpos_len;
+       DWord   dw_find_prevlineid;
+
 } LibEditText_Cursor;
 
 typedef struct {