]> granicus.if.org Git - postgis/commitdiff
Remove dependency on regex library by implementing the same functionality using stand...
authorMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Tue, 22 Sep 2009 11:13:33 +0000 (11:13 +0000)
committerMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Tue, 22 Sep 2009 11:13:33 +0000 (11:13 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@4520 b70326c6-7e19-0410-871a-916f4a2858ee

configure.ac
liblwgeom/cunit/Makefile.in
liblwgeom/g_util.c
postgis/Makefile.in

index be1e796ec4ba13d7fe632a0d33b698b3ac117203..c2370b5c7e9a1e23b467db83feb84b0c69ab5fbe 100644 (file)
@@ -536,11 +536,8 @@ CPPFLAGS="$PGSQL_CPPFLAGS $GEOS_CPPFLAGS $PROJ_CPPFLAGS"
 dnl AC_MSG_RESULT([CPPFLAGS: $CPPFLAGS])
 
 SHLIB_LINK="$PGSQL_LDFLAGS $GEOS_LDFLAGS $PROJ_LDFLAGS -lgeos_c -lproj"
-AC_CHECK_FUNCS(regexec, REGEX_LIBS= , [AC_CHECK_LIB(regex, regexec, REGEX_LIBS="$REGEX_LIBS -lregex")])
-
 AC_SUBST([SHLIB_LINK])
 dnl AC_MSG_RESULT([SHLIB_LINK: $SHLIB_LINK])
-AC_SUBST([REGEX_LIBS])
 
 dnl Output the relevant files
 AC_OUTPUT([liblwgeom/Makefile liblwgeom/cunit/Makefile postgis/Makefile postgis/sqldefines.h loader/Makefile topology/Makefile regress/Makefile doc/Makefile doc/html/image_src/Makefile])
index 93a6343a1600a6605a9d4e0e40a5d9e7db003774..0a052019111d0c4be15369984142425180930528 100644 (file)
@@ -13,7 +13,7 @@
 CC=@CC@
 CFLAGS=@CFLAGS@ @WARNFLAGS@
 
-CUNIT_LDFLAGS=@CUNIT_LDFLAGS@ @REGEX_LIBS@
+CUNIT_LDFLAGS=@CUNIT_LDFLAGS@
 CUNIT_CPPFLAGS=@CUNIT_CPPFLAGS@ -I..
 
 OBJS=  \
index 85043e005837ac751c315a838d2f7cdc7ab90306..6dfd16965a7262c1ca99a366bdbf1a19cc66c9ef 100644 (file)
@@ -9,8 +9,57 @@
  *
  **********************************************************************/
 
+#include <ctype.h>
+
 #include "libgeom.h"
 
+/* Structure for the type array */
+struct geomtype_struct
+{
+       char *typename;
+       int type;
+       int z;
+       int m;
+};
+
+/* Type array. Note that the order of this array is important in
+   that any typename in the list must *NOT* occur within an entry
+   before it. Otherwise if we search for "POINT" at the top of the
+   list we would also match MULTIPOINT, for example. */
+
+struct geomtype_struct geomtype_struct_array[28] = 
+{
+       { "GEOMETRYCOLLECTIONZM", COLLECTIONTYPE, 1, 1 },
+       { "GEOMETRYCOLLECTIONZ", COLLECTIONTYPE, 1, 0 },
+       { "GEOMETRYCOLLECTIONM", COLLECTIONTYPE, 0, 1 },
+       { "GEOMETRYCOLLECTION", COLLECTIONTYPE, 0, 0 },
+       { "MULTILINESTRINGZM", MULTILINETYPE, 1, 1 },
+       { "MULTILINESTRINGZ", MULTILINETYPE, 1, 0 },
+       { "MULTILINESTRINGM", MULTILINETYPE, 0, 1 },
+       { "MULTILINESTRING", MULTILINETYPE, 0, 0 },
+       { "MULTIPOLYGONZM", MULTIPOLYGONTYPE, 1, 1 },
+       { "MULTIPOLYGONZ", MULTIPOLYGONTYPE, 1, 0 },
+       { "MULTIPOLYGONM", MULTIPOLYGONTYPE, 0, 1 },
+       { "MULTIPOLYGON", MULTIPOLYGONTYPE, 0, 0 },
+       { "MULTIPOINTZM", MULTIPOINTTYPE, 1, 1 },
+       { "MULTIPOINTZ", MULTIPOINTTYPE, 1, 0 },
+       { "MULTIPOINTM", MULTIPOINTTYPE, 0, 1 },
+       { "MULTIPOINT", MULTIPOINTTYPE, 0, 0 },
+       { "LINESTRINGZM", LINETYPE, 1, 1 },
+       { "LINESTRINGZ", LINETYPE, 1, 0 },
+       { "LINESTRINGM", LINETYPE, 0, 1 },
+       { "LINESTRING", LINETYPE, 0, 0 },
+       { "POLYGONZM", POLYGONTYPE, 1, 1 },
+       { "POLYGONZ", POLYGONTYPE, 1, 0 },
+       { "POLYGONM", POLYGONTYPE, 0, 1 },
+       { "POLYGON", POLYGONTYPE, 0, 0 },
+       { "POINTZM", POINTTYPE, 1, 1 },
+       { "POINTZ", POINTTYPE, 1, 0 },
+       { "POINTM", POINTTYPE, 0, 1 },
+       { "POINT", POINTTYPE, 0, 0 }
+};
+
+
 uchar gflags(int hasz, int hasm, int geodetic)
 {
        unsigned char flags = 0;
@@ -31,13 +80,9 @@ uchar gflags(int hasz, int hasm, int geodetic)
 */
 int geometry_type_from_string(char *str, int *type, int *z, int *m)
 {
-       regex_t rx_point;
-       regex_t rx_linestring;
-       regex_t rx_polygon;
-       regex_t rx_geometrycollection;
-       regex_t rx_geometry;
-       size_t rx_nmatch = 5;
-       regmatch_t rx_matchptr[5];
+       char *tmpstr;
+       int tmpstartpos, tmpendpos;
+       int i;
 
        assert(str);
        assert(type);
@@ -49,81 +94,54 @@ int geometry_type_from_string(char *str, int *type, int *z, int *m)
        *z = 0;
        *m = 0;
 
-       regcomp(&rx_point, "^ *(st_)?(multi)?point(z)?(m)? *$", REG_ICASE | REG_EXTENDED);
-       regcomp(&rx_linestring, "^ *(st_)?(multi)?linestring(z)?(m)? *$", REG_ICASE | REG_EXTENDED);
-       regcomp(&rx_polygon, "^ *(st_)?(multi)?polygon(z)?(m)? *$", REG_ICASE | REG_EXTENDED);
-       regcomp(&rx_geometrycollection, "^ *(st_)?geometrycollection(z)?(m)? *$", REG_ICASE | REG_EXTENDED);
-       regcomp(&rx_geometry, "^ *(st_)?geometry(z)?(m)? *$", REG_ICASE | REG_EXTENDED);
-
-       if( ! regexec(&rx_point, str, rx_nmatch, rx_matchptr, 0) )
-       {
-               *type = POINTTYPE;
-               if(rx_matchptr[2].rm_so != -1) /* MULTI */
-                       *type = MULTIPOINTTYPE;
-                       
-               if(rx_matchptr[3].rm_so != -1) /* Z */
-                       *z = 1;
-                       
-               if(rx_matchptr[4].rm_so != -1) /* M */
-                       *m = 1;
-
-               return G_SUCCESS;
-       }
-       if( ! regexec(&rx_linestring, str, rx_nmatch, rx_matchptr, 0) )
+       /* Locate any leading/trailing spaces */
+       tmpstartpos = 0;
+       for (i = 0; i < strlen(str); i++)
        {
-               *type = LINETYPE;
-               if(rx_matchptr[2].rm_so != -1) /* MULTI */
-                       *type = MULTILINETYPE;
-                       
-               if(rx_matchptr[3].rm_so != -1) /* Z */
-                       *z = 1;
-                       
-               if(rx_matchptr[4].rm_so != -1) /* M */
-                       *m = 1;
-
-               return G_SUCCESS;
-       }
-       if( ! regexec(&rx_polygon, str, rx_nmatch, rx_matchptr, 0) )
+               if (str[i] != ' ')
+               {
+                       tmpstartpos = i;
+                       break;          
+               }
+       }       
+
+       tmpendpos = strlen(str) - 1;
+       for (i = strlen(str) - 1; i >= 0; i--)
        {
-               *type = POLYGONTYPE;
-               if(rx_matchptr[2].rm_so != -1) /* MULTI */
-                       *type = MULTIPOLYGONTYPE;
-                       
-               if(rx_matchptr[3].rm_so != -1) /* Z */
-                       *z = 1;
-                       
-               if(rx_matchptr[4].rm_so != -1) /* M */
-                       *m = 1;
-
-               return G_SUCCESS;
-       }
-       if( ! regexec(&rx_geometrycollection, str, rx_nmatch, rx_matchptr, 0) )
+               if (str[i] != ' ')
+               {
+                       tmpendpos = i;
+                       break;          
+               }
+       }       
+
+       /* Copy and convert to upper case for comparison */
+       tmpstr = lwalloc(tmpendpos - tmpstartpos + 2);
+       for (i = tmpstartpos; i <= tmpendpos; i++)
+               tmpstr[i - tmpstartpos] = toupper(str[i]);
+
+       /* Add NULL to terminate */
+       tmpstr[i - tmpstartpos] = '\0';
+
+       /* Now check for the type */
+       for (i = 0; i < 28; i++)
        {
-               *type = COLLECTIONTYPE;
+               if (!strcmp(tmpstr, geomtype_struct_array[i].typename))
+               {
+                       *type = geomtype_struct_array[i].type;
+                       *z = geomtype_struct_array[i].z;
+                       *m = geomtype_struct_array[i].m;
 
-               if(rx_matchptr[2].rm_so != -1) /* Z */
-                       *z = 1;
-                       
-               if(rx_matchptr[3].rm_so != -1) /* M */
-                       *m = 1;
+                       lwfree(tmpstr);
 
-               return G_SUCCESS;
-       }
-       if( ! regexec(&rx_geometry, str, rx_nmatch, rx_matchptr, 0) )
-       {
-               *type = 0; /* Generic geometry type. */
+                       return G_SUCCESS;
+               }
+       } 
 
-               if(rx_matchptr[2].rm_so != -1) /* Z */
-                       *z = 1;
-                       
-               if(rx_matchptr[3].rm_so != -1) /* M */
-                       *m = 1;
+       lwfree(tmpstr);
 
-               return G_SUCCESS;
-       }
-       
        return G_FAILURE;
-
 }
 
 
index 75fec41f13d4d0643d0efa453aabe9bc6f0deeb7..fc66cbdd4259f1a8633b279232d13b60a327fb57 100644 (file)
@@ -62,7 +62,7 @@ OBJS=$(PG_OBJS)
 # older version of PostGIS, rather than with the static liblwgeom.a 
 # supplied with newer versions of PostGIS
 PG_CPPFLAGS+=@CPPFLAGS@ -I../liblwgeom
-SHLIB_LINK+=@SHLIB_LINK@ ../liblwgeom/liblwgeom.a @REGEX_LIBS@
+SHLIB_LINK+=@SHLIB_LINK@ ../liblwgeom/liblwgeom.a
 
 # Extra files to remove during 'make clean'
 EXTRA_CLEAN=$(SQL_OBJS)