From: Sandro Santilli Date: Tue, 2 Nov 2004 16:48:54 +0000 (+0000) Subject: Added a copy of GNU vsprintf.c file and compiled in. X-Git-Tag: pgis_1_0_0RC1~216 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e72eae5a310f3ddb34242a869de882b6d1ab1d8e;p=postgis Added a copy of GNU vsprintf.c file and compiled in. git-svn-id: http://svn.osgeo.org/postgis/trunk@1077 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/lwgeom/Makefile b/lwgeom/Makefile index 33622121d..21e7c02e5 100644 --- a/lwgeom/Makefile +++ b/lwgeom/Makefile @@ -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 index 000000000..1eda4a50f --- /dev/null +++ b/lwgeom/compat.h @@ -0,0 +1,7 @@ +#ifndef _COMPAT_H +#define _COMPAT_H 1 + +#include + +int vasprintf(char **strp, const char *format, va_list ap); +#endif // _COMPAT_H diff --git a/lwgeom/liblwgeom.c b/lwgeom/liblwgeom.c index 84436ddf4..e9a4f3611 100644 --- a/lwgeom/liblwgeom.c +++ b/lwgeom/liblwgeom.c @@ -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); diff --git a/lwgeom/liblwgeom.h b/lwgeom/liblwgeom.h index 26644b46a..961cc3c5d 100644 --- a/lwgeom/liblwgeom.h +++ b/lwgeom/liblwgeom.h @@ -2,6 +2,7 @@ #define _LIBLWGEOM_H 1 #include +#include #define INTEGRITY_CHECKS 1 //#define DEBUG_ALLOCS 1 diff --git a/lwgeom/lwgeom_pg.c b/lwgeom/lwgeom_pg.c index 90439d511..b010db69a 100644 --- a/lwgeom/lwgeom_pg.c +++ b/lwgeom/lwgeom_pg.c @@ -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 index 000000000..ded821490 --- /dev/null +++ b/lwgeom/vsprintf.c @@ -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 +#endif + +#include +#include +#include + +#if __STDC__ +# include +#else +# include +#endif + +#include + +#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; +}