]> granicus.if.org Git - postgis/commitdiff
Added a copy of GNU vsprintf.c file and compiled in.
authorSandro Santilli <strk@keybit.net>
Tue, 2 Nov 2004 16:48:54 +0000 (16:48 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 2 Nov 2004 16:48:54 +0000 (16:48 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@1077 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/Makefile
lwgeom/compat.h [new file with mode: 0644]
lwgeom/liblwgeom.c
lwgeom/liblwgeom.h
lwgeom/lwgeom_pg.c
lwgeom/vsprintf.c [new file with mode: 0644]

index 33622121dce1884bc81e944151ef7aacc7d070b1..21e7c02e506819a8cd31087e6190240242339258 100644 (file)
@@ -73,7 +73,7 @@ ifeq ($(USE_STATS),1)
        override CFLAGS += -DUSE_STATS
 endif
  
-SA_OBJS=misures.o box2d.o ptarray.o lwgeom_api.o lwgeom.o lwpoint.o lwline.o lwpoly.o lwmpoint.o lwmline.o lwmpoly.o lwcollection.o $(GEOS_WRAPPER) wktunparse.o lwgparse.o wktparse.tab.o lex.yy.o
+SA_OBJS=misures.o box2d.o ptarray.o lwgeom_api.o lwgeom.o lwpoint.o lwline.o lwpoly.o lwmpoint.o lwmline.o lwmpoly.o lwcollection.o $(GEOS_WRAPPER) wktunparse.o lwgparse.o wktparse.tab.o lex.yy.o vsprintf.o
 OBJS=$(SA_OBJS) liblwgeom.o lwgeom_pg.o lwgeom_debug.o lwgeom_spheroid.o lwgeom_ogc.o lwgeom_functions_analytic.o lwgeom_geos.o lwgeom_inout.o lwgeom_estimate.o lwgeom_functions_basic.o lwgeom_gist.o lwgeom_btree.o lwgeom_transform.o stringBuffer.o lwgeom_box.o lwgeom_box3d.o lwgeom_box2dfloat4.o lwgeom_chip.o lwgeom_svg.o lwgeom_gml.o 
 
 OTHERS=y.output lex.yy.c wktparse.tab.c wktparse.tab.h lwpostgis.sql
diff --git a/lwgeom/compat.h b/lwgeom/compat.h
new file mode 100644 (file)
index 0000000..1eda4a5
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef _COMPAT_H
+#define _COMPAT_H 1
+
+#include <stdarg.h>
+
+int  vasprintf(char  **strp,  const  char *format, va_list ap);
+#endif // _COMPAT_H
index 84436ddf4311e0cc09cd2ca0efafdfba05ae2fef..e9a4f361140ff04dac863abf128f299e49b45e3e 100644 (file)
@@ -71,9 +71,9 @@ default_noticereporter(const char *fmt, ...)
        va_start (ap, fmt);
 
        /*
-       * This is a GNU extension.
-       * Dunno how to handle errors here.
-       */
+        * This is a GNU extension.
+        * Dunno how to handle errors here.
+        */
        if (!vasprintf (&msg, fmt, ap))
        {
                va_end (ap);
@@ -93,9 +93,9 @@ default_errorreporter(const char *fmt, ...)
        va_start (ap, fmt);
 
        /*
-       * This is a GNU extension.
-       * Dunno how to handle errors here.
-       */
+        * This is a GNU extension.
+        * Dunno how to handle errors here.
+        */
        if (!vasprintf (&msg, fmt, ap))
        {
                va_end (ap);
index 26644b46ad7ed7a899bfdba5e2d135e3e1848c62..961cc3c5dc00e0024b8cc08f3d21f64334d5ebf8 100644 (file)
@@ -2,6 +2,7 @@
 #define _LIBLWGEOM_H 1
 
 #include <stdio.h>
+#include <compat.h>
 
 #define INTEGRITY_CHECKS 1
 //#define DEBUG_ALLOCS 1
index 90439d511603b04e553a53128cf13a9e6f66c3d8..b010db69a2cc8aa22fe3a11de7007664b05328e5 100644 (file)
@@ -55,9 +55,9 @@ pg_error(const char *fmt, ...)
        va_start (ap, fmt);
 
        /*
-       * This is a GNU extension.
-       * Dunno how to handle errors here.
-       */
+        * This is a GNU extension.
+        * Dunno how to handle errors here.
+        */
        if (!vasprintf (&msg, fmt, ap))
        {
                va_end (ap);
@@ -77,9 +77,9 @@ pg_notice(const char *fmt, ...)
        va_start (ap, fmt);
 
        /*
-       * This is a GNU extension.
-       * Dunno how to handle errors here.
-       */
+        * This is a GNU extension.
+        * Dunno how to handle errors here.
+        */
        if (!vasprintf (&msg, fmt, ap))
        {
                va_end (ap);
diff --git a/lwgeom/vsprintf.c b/lwgeom/vsprintf.c
new file mode 100644 (file)
index 0000000..ded8214
--- /dev/null
@@ -0,0 +1,162 @@
+/* Like vsprintf but provides a pointer to malloc'd storage, which must
+   be freed by the caller.
+   Copyright (C) 1994, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#if __STDC__
+# include <stdarg.h>
+#else
+# include <varargs.h>
+#endif
+
+#include <math.h>
+
+#ifdef TEST
+int global_total_width;
+#endif
+
+static int
+int_vasprintf (result, format, args)
+     char **result;
+     const char *format;
+     va_list *args;
+{
+  const char *p = format;
+  /* Add one to make sure that it is never zero, which might cause malloc
+     to return NULL.  */
+  int total_width = strlen (format) + 1;
+  va_list ap;
+
+  memcpy (&ap, args, sizeof (va_list));
+
+  while (*p != '\0')
+    {
+      if (*p++ == '%')
+       {
+         while (strchr ("-+ #0", *p))
+           ++p;
+         if (*p == '*')
+           {
+             ++p;
+             total_width += abs (va_arg (ap, int));
+           }
+         else
+           total_width += strtoul (p, (char **) &p, 10);
+         if (*p == '.')
+           {
+             ++p;
+             if (*p == '*')
+               {
+                 ++p;
+                 total_width += abs (va_arg (ap, int));
+               }
+             else
+               total_width += strtoul (p, (char **) &p, 10);
+           }
+         while (strchr ("hlLjtz", *p))
+           ++p;
+         /* Should be big enough for any format specifier except %s
+            and floats.  */
+         total_width += 30;
+         switch (*p)
+           {
+           case 'd':
+           case 'i':
+           case 'o':
+           case 'u':
+           case 'x':
+           case 'X':
+           case 'c':
+             (void) va_arg (ap, int);
+             break;
+           case 'f':
+             {
+               double arg = va_arg (ap, double);
+               if (arg >= 1.0 || arg <= -1.0)
+                 /* Since an ieee double can have an exponent of 307, we'll
+                    make the buffer wide enough to cover the gross case. */
+                 total_width += 307;
+             }
+             break;
+           case 'e':
+           case 'E':
+           case 'g':
+           case 'G':
+             (void) va_arg (ap, double);
+             break;
+           case 's':
+             total_width += strlen (va_arg (ap, char *));
+             break;
+           case 'p':
+           case 'n':
+             (void) va_arg (ap, char *);
+             break;
+           }
+         p++;
+       }
+    }
+#ifdef TEST
+  global_total_width = total_width;
+#endif
+  *result = malloc (total_width);
+  if (*result != NULL)
+    return vsprintf (*result, format, *args);
+  else
+    return 0;
+}
+
+int
+vasprintf (result, format, args)
+     char **result;
+     const char *format;
+     va_list args;
+{
+  return int_vasprintf (result, format, &args);
+}
+
+int
+asprintf
+#if __STDC__
+     (char **result, const char *format, ...)
+#else
+     (result, va_alist)
+     char **result;
+     va_dcl
+#endif
+{
+  va_list args;
+  int done;
+
+#if __STDC__
+  va_start (args, format);
+#else
+  char *format;
+  va_start (args);
+  format = va_arg (args, char *);
+#endif
+  done = vasprintf (result, format, args);
+  va_end (args);
+
+  return done;
+}