SF.net SVN: geany:[4704] branches/gnu-regex
ntrel at users.sourceforge.net
ntrel at xxxxx
Wed Feb 24 15:27:12 UTC 2010
Revision: 4704
http://geany.svn.sourceforge.net/geany/?rev=4704&view=rev
Author: ntrel
Date: 2010-02-24 15:27:12 +0000 (Wed, 24 Feb 2010)
Log Message:
-----------
Make Find dialog Next button use GNU/system regex instead of
Scintilla engine.
Modified Paths:
--------------
branches/gnu-regex/ChangeLog
branches/gnu-regex/src/document.c
Modified: branches/gnu-regex/ChangeLog
===================================================================
--- branches/gnu-regex/ChangeLog 2010-02-24 15:22:39 UTC (rev 4703)
+++ branches/gnu-regex/ChangeLog 2010-02-24 15:27:12 UTC (rev 4704)
@@ -3,6 +3,9 @@
* src/keybindings.c, doc/geany.txt, doc/geany.html:
Make Switch to Editor keybinding reshow the document statistics
line, so user doesn't have to move the cursor.
+ * src/document.c:
+ Make Find dialog Next button use GNU/system regex instead of
+ Scintilla engine.
2010-02-22 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: branches/gnu-regex/src/document.c
===================================================================
--- branches/gnu-regex/src/document.c 2010-02-24 15:22:39 UTC (rev 4703)
+++ branches/gnu-regex/src/document.c 2010-02-24 15:27:12 UTC (rev 4704)
@@ -1924,6 +1924,72 @@
}
+/* TODO: fix building when HAVE_REGCOMP is not defined? */
+# ifdef HAVE_REGEX_H
+# include <regex.h>
+# else
+# include "gnuregex.h"
+# endif
+
+static gboolean compile_regex(regex_t *regex, const gchar *str, gint sflags)
+{
+ gint err;
+ gint rflags = REG_EXTENDED | REG_NEWLINE;
+
+ if (~sflags & SCFIND_MATCHCASE)
+ rflags |= REG_ICASE;
+
+ err = regcomp(regex, str, rflags);
+ if (err != 0)
+ {
+ gchar buf[256];
+
+ regerror(err, regex, buf, sizeof buf);
+ ui_set_statusbar(FALSE, _("Bad regex: %s"), buf);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+
+static gint find_regex(ScintillaObject *sci, guint pos, regex_t *regex, regmatch_t *match)
+{
+ const gchar *text;
+
+ g_return_val_if_fail(pos <= (guint)sci_get_length(sci), FALSE);
+
+ text = (void*)scintilla_send_message(sci, SCI_GETCHARACTERPOINTER, 0, 0);
+ text += pos;
+ if (regexec(regex, text, 1, match, 0) == 0)
+ return match->rm_so + pos;
+
+ return -1;
+}
+
+
+static gint geany_search_next(ScintillaObject *sci, const gchar *str, gint flags)
+{
+ regmatch_t match;
+ regex_t regex;
+ gint ret = -1;
+ gint pos;
+
+ if (~flags & SCFIND_REGEXP)
+ return sci_search_next(sci, flags, str);
+
+ if (!compile_regex(®ex, str, flags))
+ return -1;
+
+ pos = sci_get_current_position(sci);
+ ret = find_regex(sci, pos, ®ex, &match);
+ if (ret >= 0)
+ sci_set_selection(sci, ret, match.rm_eo + pos);
+
+ regfree(®ex);
+ return ret;
+}
+
+
/* General search function, used from the find dialog.
* Returns -1 on failure or the start position of the matching text.
* Will skip past any selection, ignoring it. */
@@ -1954,7 +2020,7 @@
if (search_backwards)
search_pos = sci_search_prev(doc->editor->sci, flags, text);
else
- search_pos = sci_search_next(doc->editor->sci, flags, text);
+ search_pos = geany_search_next(doc->editor->sci, text, flags);
if (search_pos != -1)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list