gimp r26921 - in trunk: . plug-ins/script-fu plug-ins/script-fu/re
- From: mitch svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp r26921 - in trunk: . plug-ins/script-fu plug-ins/script-fu/re
- Date: Wed, 10 Sep 2008 23:10:15 +0000 (UTC)
Author: mitch
Date: Wed Sep 10 23:10:15 2008
New Revision: 26921
URL: http://svn.gnome.org/viewvc/gimp?rev=26921&view=rev
Log:
2008-09-11 Michael Natterer <mitch gimp org>
* plug-ins/script-fu/Makefile.am
* plug-ins/script-fu/re/*: removed....
* plug-ins/script-fu/script-fu-regex.[ch]: and replaced with a
few-liner using GRegex. Seems to have some issues that need to be
sorted out.
* plug-ins/script-fu/scheme-wrapper.c: changed accordingly.
Added:
trunk/plug-ins/script-fu/script-fu-regex.c (contents, props changed)
- copied, changed from r26918, /trunk/plug-ins/script-fu/re/re.c
trunk/plug-ins/script-fu/script-fu-regex.h (props changed)
- copied unchanged from r26918, /trunk/plug-ins/script-fu/re/re.h
Removed:
trunk/plug-ins/script-fu/re/
Modified:
trunk/ChangeLog
trunk/plug-ins/script-fu/Makefile.am
trunk/plug-ins/script-fu/scheme-wrapper.c
Modified: trunk/plug-ins/script-fu/Makefile.am
==============================================================================
--- trunk/plug-ins/script-fu/Makefile.am (original)
+++ trunk/plug-ins/script-fu/Makefile.am Wed Sep 10 23:10:15 2008
@@ -10,7 +10,6 @@
libtinyscheme=tinyscheme/libtinyscheme.a
libftx=ftx/libftx.a
-libre=re/libre.a
if OS_WIN32
mwindows = -mwindows
@@ -27,7 +26,7 @@
AM_LDFLAGS = $(mwindows)
-SUBDIRS = tinyscheme ftx re scripts
+SUBDIRS = tinyscheme ftx scripts
libexecdir = $(gimpplugindir)/plug-ins
@@ -45,6 +44,8 @@
script-fu-text-console.h \
script-fu-text-console.c \
script-fu-intl.h \
+ script-fu-regex.c \
+ script-fu-regex.h \
script-fu-scripts.c \
script-fu-scripts.h \
script-fu-server.c \
@@ -64,7 +65,6 @@
$(libgimpbase) \
$(libtinyscheme) \
$(libftx) \
- $(libre) \
$(GTK_LIBS) \
$(SOCKET_LIBS) \
$(WINSOCK_LIBS) \
Modified: trunk/plug-ins/script-fu/scheme-wrapper.c
==============================================================================
--- trunk/plug-ins/script-fu/scheme-wrapper.c (original)
+++ trunk/plug-ins/script-fu/scheme-wrapper.c Wed Sep 10 23:10:15 2008
@@ -36,12 +36,12 @@
#include "tinyscheme/dynload.h"
#endif
#include "ftx/ftx.h"
-#include "re/re.h"
#include "script-fu-types.h"
#include "script-fu-console.h"
#include "script-fu-interface.h"
+#include "script-fu-regex.h"
#include "script-fu-scripts.h"
#include "script-fu-server.h"
Copied: trunk/plug-ins/script-fu/script-fu-regex.c (from r26918, /trunk/plug-ins/script-fu/re/re.c)
==============================================================================
--- /trunk/plug-ins/script-fu/re/re.c (original)
+++ trunk/plug-ins/script-fu/script-fu-regex.c Wed Sep 10 23:10:15 2008
@@ -2,93 +2,20 @@
/* Henry Spencer's implementation of Regular Expressions,
used for TinyScheme */
/* Refurbished by Stephen Gildea */
-#include "regex.h"
-#include "tinyscheme/scheme-private.h"
-
-#if defined(_WIN32)
-#define EXPORT __declspec( dllexport )
-#else
-#define EXPORT
-#endif
-
-/* Since not exported */
-#define T_STRING 1
+/* Ported to GRegex by Michael Natterer */
-pointer foreign_re_match(scheme *sc, pointer args);
-EXPORT void init_re(scheme *sc);
-
-
-static void set_vector_elem(pointer vec, int ielem, pointer newel) {
- int n=ielem/2;
- if(ielem%2==0) {
- vec[1+n]._object._cons._car=newel;
- } else {
- vec[1+n]._object._cons._cdr=newel;
- }
-}
+#include "config.h"
-pointer foreign_re_match(scheme *sc, pointer args) {
- pointer retval=sc->F;
- int retcode;
- regex_t rt;
- pointer first_arg, second_arg;
- pointer third_arg=sc->NIL;
- char *string;
- char *pattern;
- int num=0;
-
- if(!((args != sc->NIL) && sc->vptr->is_string((first_arg = sc->vptr->pair_car(args)))
- && (args=sc->vptr->pair_cdr(args))
- && sc->vptr->is_pair(args) && sc->vptr->is_string((second_arg = sc->vptr->pair_car(args))))) {
- return sc->F;
- }
- pattern = sc->vptr->string_value(first_arg);
- string = sc->vptr->string_value(second_arg);
-
- args=sc->vptr->pair_cdr(args);
- if(args!=sc->NIL) {
- if(!(sc->vptr->is_pair(args) && sc->vptr->is_vector((third_arg = sc->vptr->pair_car(args))))) {
- return sc->F;
- } else {
- num=third_arg->_object._number.value.ivalue;
- }
- }
-
-
- if(regcomp(&rt,pattern,REG_EXTENDED)!=0) {
- return sc->F;
- }
-
- if(num==0) {
- retcode=regexec(&rt,string,0,0,0);
- } else {
- regmatch_t *pmatch=malloc((num+1)*sizeof(regmatch_t));
- if(pmatch!=0) {
- retcode=regexec(&rt,string,num+1,pmatch,0);
- if(retcode==0) {
- int i;
- for(i=0; i<num; i++) {
-#undef cons
- set_vector_elem(third_arg, i,
- sc->vptr->cons(sc, sc->vptr->mk_integer(sc, pmatch[i].rm_so),
- sc->vptr->mk_integer(sc, pmatch[i].rm_eo)));
- }
- }
- free(pmatch);
- } else {
- sc->no_memory=1;
- retcode=-1;
- }
- }
+#include "tinyscheme/scheme-private.h"
+#include "script-fu-regex.h"
- if(retcode==0) {
- retval=sc->T;
- }
- regfree(&rt);
+static pointer foreign_re_match (scheme *sc,
+ pointer args);
+static void set_vector_elem (pointer vec,
+ int ielem,
+ pointer newel);
- return(retval);
-}
#if 0
static char* utilities=";; return the substring of STRING matched in MATCH-VECTOR, \n"
@@ -106,7 +33,111 @@
" (string-length string))))\n";
#endif
-void init_re(scheme *sc) {
- sc->vptr->scheme_define(sc,sc->global_env,sc->vptr->mk_symbol(sc,"re-match"),sc->vptr->mk_foreign_func(sc, foreign_re_match));
- /* sc->vptr->load_string(sc,utilities);*/
+void
+init_re (scheme *sc)
+{
+ sc->vptr->scheme_define (sc,
+ sc->global_env,
+ sc->vptr->mk_symbol(sc,"re-match"),
+ sc->vptr->mk_foreign_func(sc, foreign_re_match));
+
+#if 0
+ sc->vptr->load_string (sc,utilities);
+#endif
+}
+
+static pointer
+foreign_re_match (scheme *sc,
+ pointer args)
+{
+ pointer retval = sc->F;
+ gboolean success;
+ GRegex *regex;
+ pointer first_arg, second_arg;
+ pointer third_arg = sc->NIL;
+ char *string;
+ char *pattern;
+ int num = 0;
+
+ if (!((args != sc->NIL)
+ && sc->vptr->is_string ((first_arg = sc->vptr->pair_car (args)))
+ && (args = sc->vptr->pair_cdr (args))
+ && sc->vptr->is_pair (args)
+ && sc->vptr->is_string ((second_arg = sc->vptr->pair_car (args)))))
+ {
+ return sc->F;
+ }
+
+ pattern = sc->vptr->string_value (first_arg);
+ string = sc->vptr->string_value (second_arg);
+
+ args = sc->vptr->pair_cdr (args);
+
+ if (args != sc->NIL)
+ {
+ if (!(sc->vptr->is_pair (args)
+ && sc->vptr->is_vector ((third_arg = sc->vptr->pair_car (args)))))
+ {
+ return sc->F;
+ }
+ else
+ {
+ num = third_arg->_object._number.value.ivalue;
+ }
+ }
+
+ regex = g_regex_new (pattern, G_REGEX_EXTENDED, 0, NULL);
+ if (! regex)
+ return sc->F;
+
+ if (! num)
+ {
+ success = g_regex_match (regex, string, 0, NULL);
+ }
+ else
+ {
+ GMatchInfo *match_info;
+ gint i;
+
+ success = g_regex_match (regex, string, 0, &match_info);
+
+ for (i = 0; i < num; i++)
+ {
+ gint start, end;
+
+ g_match_info_fetch_pos (match_info, i, &start, &end);
+
+#undef cons
+ set_vector_elem (third_arg, i,
+ sc->vptr->cons(sc,
+ sc->vptr->mk_integer(sc, start),
+ sc->vptr->mk_integer(sc, end)));
+ }
+
+ g_match_info_free (match_info);
+ }
+
+ if (success)
+ retval = sc->T;
+
+ g_regex_unref (regex);
+
+ return retval;
+}
+
+static void
+set_vector_elem (pointer vec,
+ int ielem,
+ pointer newel)
+{
+ int n = ielem / 2;
+
+ if (ielem % 2 == 0)
+ {
+ vec[1 + n]._object._cons._car = newel;
+ }
+ else
+ {
+ vec[1 + n]._object._cons._cdr = newel;
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]