Add back some $Id tags and files missing in TWKB commit
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 13 May 2015 18:29:52 +0000 (18:29 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 13 May 2015 18:29:52 +0000 (18:29 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13497 b70326c6-7e19-0410-871a-916f4a2858ee

14 files changed:
liblwgeom/bytebuffer.c [new file with mode: 0644]
liblwgeom/bytebuffer.h [new file with mode: 0644]
liblwgeom/cunit/cu_bytebuffer.c [new file with mode: 0644]
liblwgeom/cunit/cu_in_wkt.c
liblwgeom/cunit/cu_out_twkb.c
liblwgeom/liblwgeom.h.in
liblwgeom/liblwgeom_internal.h
loader/dbfopen.c
loader/pgsql2shp-core.h
loader/safileio.c
loader/shp2pgsql-core.h
loader/shpopen.c
raster/loader/raster2pgsql.h
utils/read_scripts_version.pl

diff --git a/liblwgeom/bytebuffer.c b/liblwgeom/bytebuffer.c
new file mode 100644 (file)
index 0000000..b3a2129
--- /dev/null
@@ -0,0 +1,356 @@
+/**********************************************************************
+ * $Id: bytebuffer.c 11218 2013-03-28 13:32:44Z robe $
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * Copyright 2015 Nicklas Avén <nicklas.aven@jordogskog.no>
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ **********************************************************************/
+
+
+#include "liblwgeom_internal.h"
+#include "bytebuffer.h"
+
+/**
+* Allocate a new bytebuffer_t. Use bytebuffer_destroy to free.
+*/
+bytebuffer_t* 
+bytebuffer_create(void)
+{
+       LWDEBUG(2,"Entered bytebuffer_create");
+       return bytebuffer_create_with_size(BYTEBUFFER_STARTSIZE);
+}
+
+/**
+* Allocate a new bytebuffer_t. Use bytebuffer_destroy to free.
+*/
+bytebuffer_t* 
+bytebuffer_create_with_size(size_t size)
+{
+       LWDEBUGF(2,"Entered bytebuffer_create_with_size %d", size);
+       bytebuffer_t *s;
+
+       s = lwalloc(sizeof(bytebuffer_t));
+       s->buf_start = lwalloc(size);
+       s->readcursor = s->writecursor = s->buf_start;
+       s->capacity = size;
+       memset(s->buf_start,0,size);
+       LWDEBUGF(4,"We create a buffer on %p of %d bytes", s->buf_start, size);
+       return s;
+}
+
+/**
+* Free the bytebuffer_t and all memory managed within it.
+*/
+void 
+bytebuffer_destroy(bytebuffer_t *s)
+{
+       LWDEBUG(2,"Entered bytebuffer_destroy");
+       LWDEBUGF(4,"The buffer has used %d bytes",bytebuffer_getlength(s));
+       
+       if ( s->buf_start ) 
+       {
+               LWDEBUGF(4,"let's free buf_start %p",s->buf_start);
+               lwfree(s->buf_start);
+               LWDEBUG(4,"buf_start is freed");
+       }
+       if ( s ) 
+       {
+               lwfree(s);              
+               LWDEBUG(4,"bytebuffer_t is freed");
+       }
+       return;
+}
+
+/**
+* Set the read cursor to the beginning
+*/
+void 
+bytebuffer_reset_reading(bytebuffer_t *s)
+{
+       s->readcursor = s->buf_start;
+}
+
+/**
+* Reset the bytebuffer_t. Useful for starting a fresh string
+* without the expense of freeing and re-allocating a new
+* bytebuffer_t.
+*/
+void 
+bytebuffer_clear(bytebuffer_t *s)
+{
+       s->readcursor = s->writecursor = s->buf_start;
+}
+
+/**
+* If necessary, expand the bytebuffer_t internal buffer to accomodate the
+* specified additional size.
+*/
+static inline void 
+bytebuffer_makeroom(bytebuffer_t *s, size_t size_to_add)
+{
+       LWDEBUGF(2,"Entered bytebuffer_makeroom with space need of %d", size_to_add);
+       size_t current_write_size = (s->writecursor - s->buf_start);
+       size_t capacity = s->capacity;
+       size_t required_size = current_write_size + size_to_add;
+
+       LWDEBUGF(2,"capacity = %d and required size = %d",capacity ,required_size);
+       while (capacity < required_size)
+               capacity *= 2;
+
+       if ( capacity > s->capacity )
+       {
+               LWDEBUGF(4,"We need to realloc more memory. New capacity is %d", capacity);
+               s->buf_start = lwrealloc(s->buf_start, capacity);
+               s->capacity = capacity;
+               s->writecursor = s->buf_start + current_write_size;
+               s->readcursor = s->buf_start + (s->readcursor - s->buf_start);
+       }
+       return;
+}
+
+/**
+* Writes a uint8_t value to the buffer
+*/
+void 
+bytebuffer_append_byte(bytebuffer_t *s, const uint8_t val)
+{      
+       LWDEBUGF(2,"Entered bytebuffer_append_byte with value %d", val);        
+       bytebuffer_makeroom(s, 1);
+       *(s->writecursor)=val;
+       s->writecursor += 1;
+       return;
+}
+
+
+/**
+* Writes a uint8_t value to the buffer
+*/
+void 
+bytebuffer_append_bulk(bytebuffer_t *s, void * start, size_t size)
+{      
+       LWDEBUGF(2,"bytebuffer_append_bulk with size %d",size); 
+       bytebuffer_makeroom(s, size);
+       memcpy(s->writecursor, start, size);
+       s->writecursor += size;
+       return;
+}
+
+/**
+* Writes a uint8_t value to the buffer
+*/
+void 
+bytebuffer_append_bytebuffer(bytebuffer_t *write_to,bytebuffer_t *write_from )
+{      
+       LWDEBUG(2,"bytebuffer_append_bytebuffer");      
+       size_t size = bytebuffer_getlength(write_from);
+       bytebuffer_makeroom(write_to, size);
+       memcpy(write_to->writecursor, write_from->buf_start, size);
+       write_to->writecursor += size;
+       return;
+}
+
+
+/**
+* Writes a signed varInt to the buffer
+*/
+void 
+bytebuffer_append_varint(bytebuffer_t *b, const int64_t val)
+{      
+       size_t size;
+       bytebuffer_makeroom(b, 8);
+       size = varint_s64_encode_buf(val, b->writecursor);
+       b->writecursor += size;
+       return;
+}
+
+/**
+* Writes a unsigned varInt to the buffer
+*/
+void 
+bytebuffer_append_uvarint(bytebuffer_t *b, const uint64_t val)
+{      
+       size_t size;
+       bytebuffer_makeroom(b, 8);
+       size = varint_u64_encode_buf(val, b->writecursor);
+       b->writecursor += size;
+       return;
+}
+
+
+/*
+* Writes Integer to the buffer
+*/
+void
+bytebuffer_append_int(bytebuffer_t *buf, const int val, int swap)
+{
+       LWDEBUGF(2,"Entered bytebuffer_append_int with value %d, swap = %d", val, swap);        
+       
+       LWDEBUGF(4,"buf_start = %p and write_cursor=%p", buf->buf_start,buf->writecursor);
+       char *iptr = (char*)(&val);
+       int i = 0;
+
+       if ( sizeof(int) != WKB_INT_SIZE )
+       {
+               lwerror("Machine int size is not %d bytes!", WKB_INT_SIZE);
+       }
+       
+       bytebuffer_makeroom(buf, WKB_INT_SIZE);
+       /* Machine/request arch mismatch, so flip byte order */
+       if ( swap)
+       {
+               LWDEBUG(4,"Ok, let's do the swaping thing");    
+               for ( i = 0; i < WKB_INT_SIZE; i++ )
+               {
+                       *(buf->writecursor) = iptr[WKB_INT_SIZE - 1 - i];
+                       buf->writecursor += 1;
+               }
+       }
+       /* If machine arch and requested arch match, don't flip byte order */
+       else
+       {
+               LWDEBUG(4,"Ok, let's do the memcopying thing");         
+               memcpy(buf->writecursor, iptr, WKB_INT_SIZE);
+               buf->writecursor += WKB_INT_SIZE;
+       }
+       
+       LWDEBUGF(4,"buf_start = %p and write_cursor=%p", buf->buf_start,buf->writecursor);
+       return;
+
+}
+
+
+
+
+
+/**
+* Writes a float64 to the buffer
+*/
+void
+bytebuffer_append_double(bytebuffer_t *buf, const double val, int swap)
+{
+       LWDEBUGF(2,"Entered bytebuffer_append_double with value %lf swap = %d", val, swap);     
+       
+       LWDEBUGF(4,"buf_start = %p and write_cursor=%p", buf->buf_start,buf->writecursor);
+       char *dptr = (char*)(&val);
+       int i = 0;
+
+       if ( sizeof(double) != WKB_DOUBLE_SIZE )
+       {
+               lwerror("Machine double size is not %d bytes!", WKB_DOUBLE_SIZE);
+       }
+
+       bytebuffer_makeroom(buf, WKB_DOUBLE_SIZE);
+       
+       /* Machine/request arch mismatch, so flip byte order */
+       if ( swap )
+       {
+               LWDEBUG(4,"Ok, let's do the swapping thing");           
+               for ( i = 0; i < WKB_DOUBLE_SIZE; i++ )
+               {
+                       *(buf->writecursor) = dptr[WKB_DOUBLE_SIZE - 1 - i];
+                       buf->writecursor += 1;
+               }
+       }
+       /* If machine arch and requested arch match, don't flip byte order */
+       else
+       {
+               LWDEBUG(4,"Ok, let's do the memcopying thing");                 
+               memcpy(buf->writecursor, dptr, WKB_DOUBLE_SIZE);
+               buf->writecursor += WKB_DOUBLE_SIZE;
+       }
+       
+       LWDEBUG(4,"Return from bytebuffer_append_double");              
+       return;
+
+}
+
+/**
+* Reads a signed varInt from the buffer
+*/
+int64_t 
+bytebuffer_read_varint(bytebuffer_t *b)
+{
+       size_t size;
+       int64_t val = varint_s64_decode(b->readcursor, b->buf_start + b->capacity, &size);
+       b->readcursor += size;
+       return val;
+}
+
+/**
+* Reads a unsigned varInt from the buffer
+*/
+uint64_t 
+bytebuffer_read_uvarint(bytebuffer_t *b)
+{      
+       size_t size;
+       uint64_t val = varint_u64_decode(b->readcursor, b->buf_start + b->capacity, &size);
+       b->readcursor += size;
+       return val;
+}
+
+/**
+* Returns the length of the current buffer
+*/
+size_t 
+bytebuffer_getlength(bytebuffer_t *s)
+{
+       return (size_t) (s->writecursor - s->buf_start);
+}
+
+
+/**
+* Returns a new bytebuffer were both ingoing bytebuffers is merged.
+* Caller is responsible for freeing both incoming bytefyffers and resulting bytebuffer
+*/
+bytebuffer_t*
+bytebuffer_merge(bytebuffer_t **buff_array, int nbuffers)
+{
+       size_t total_size = 0, current_size, acc_size = 0;
+       int i;
+       for ( i = 0; i < nbuffers; i++ )
+       {
+               total_size += bytebuffer_getlength(buff_array[i]);
+       }
+               
+       bytebuffer_t *res = bytebuffer_create_with_size(total_size);
+       for ( i = 0; i < nbuffers; i++)
+       {
+               current_size = bytebuffer_getlength(buff_array[i]);
+               memcpy(res->buf_start+acc_size, buff_array[i]->buf_start, current_size);
+               acc_size += current_size;
+       }
+       res->writecursor = res->buf_start + total_size;
+       res->readcursor = res->buf_start;
+       return res;
+}
+
+
diff --git a/liblwgeom/bytebuffer.h b/liblwgeom/bytebuffer.h
new file mode 100644 (file)
index 0000000..bbb13de
--- /dev/null
@@ -0,0 +1,75 @@
+/**********************************************************************
+ * $Id: bytebuffer.h 12198 2014-01-29 17:49:35Z pramsey $
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * Copyright 2015 Nicklas Avén <nicklas.aven@jordogskog.no>
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ **********************************************************************/
+
+#ifndef _BYTEBUFFER_H
+#define _BYTEBUFFER_H 1
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include "varint.h"
+
+#include "lwgeom_log.h"
+#define BYTEBUFFER_STARTSIZE 128
+
+typedef struct
+{
+       size_t capacity;
+       uint8_t *buf_start;
+       uint8_t *writecursor;   
+       uint8_t *readcursor;    
+}
+bytebuffer_t;
+
+bytebuffer_t *bytebuffer_create_with_size(size_t size);
+bytebuffer_t *bytebuffer_create(void);
+void bytebuffer_destroy(bytebuffer_t *s);
+void bytebuffer_clear(bytebuffer_t *s);
+void bytebuffer_append_byte(bytebuffer_t *s, const uint8_t val);
+void bytebuffer_append_varint(bytebuffer_t *s, const int64_t val);
+void bytebuffer_append_uvarint(bytebuffer_t *s, const uint64_t val);
+uint64_t bytebuffer_read_uvarint(bytebuffer_t *s);
+int64_t bytebuffer_read_varint(bytebuffer_t *s);
+size_t bytebuffer_getlength(bytebuffer_t *s);
+bytebuffer_t* bytebuffer_merge(bytebuffer_t **buff_array, int nbuffers);
+void bytebuffer_reset_reading(bytebuffer_t *s);
+
+void bytebuffer_append_bytebuffer(bytebuffer_t *write_to,bytebuffer_t *write_from);
+void bytebuffer_append_bulk(bytebuffer_t *s, void * start, size_t size);
+void bytebuffer_append_int(bytebuffer_t *buf, const int val, int swap);
+void bytebuffer_append_double(bytebuffer_t *buf, const double val, int swap);
+#endif /* _BYTEBUFFER_H */
diff --git a/liblwgeom/cunit/cu_bytebuffer.c b/liblwgeom/cunit/cu_bytebuffer.c
new file mode 100644 (file)
index 0000000..0ee5426
--- /dev/null
@@ -0,0 +1,58 @@
+/**********************************************************************
+ * $Id$
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.net
+ *
+ * Copyright 2012 Sandro Santilli <strk@keybit.net>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU General Public Licence. See the COPYING file.
+ *
+ **********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "CUnit/Basic.h"
+
+#include "bytebuffer.h"
+#include "cu_tester.h"
+
+#if 0
+
+static void test_bytebuffer_append(void)
+{
+       bytebuffer_t *bb1;
+       int64_t res;
+       bb1 = bytebuffer_create_with_size(2);
+       
+       bytebuffer_append_varint(bb1,(int64_t) -12345);
+
+       
+       bytebuffer_reset_reading(bb1);
+       
+       res= bytebuffer_read_varint(bb1);
+
+       CU_ASSERT_EQUAL(res, -12345);
+
+       bytebuffer_destroy(bb1);
+}
+
+
+/* TODO: add more... */
+
+
+
+/*
+** Used by the test harness to register the tests in this file.
+*/
+void bytebuffer_suite_setup(void);
+void bytebuffer_suite_setup(void)
+{
+       PG_TEST(test_bytebuffer_append),
+       CU_TEST_INFO_NULL
+};
+CU_SuiteInfo bytebuffer_suite = {"bytebuffer", NULL, NULL, bytebuffer_tests };
+
+#endif
index aa6e55c27fee6b962c3a84c9481b3a17f3237e25..04e41c6b0fdf6360735a54912baed845186e028e 100644 (file)
@@ -337,7 +337,7 @@ static void test_wkt_in_errlocation(void)
        lwgeom_parser_result_init(&p);
        rv = lwgeom_parse_wkt(&p, wkt, LW_PARSER_CHECK_ALL);
        CU_ASSERT_EQUAL( rv, LW_FAILURE );
-       CU_ASSERT(fabs(12 - p.errlocation) < 1.5);
+       CU_ASSERT((12 - p.errlocation) < 1.5);
 
 //     printf("errlocation %d\n", p.errlocation);
 //     printf("message %s\n", p.message);
index b4a23a19e013cdeda76267ef4cdb51730d01e315..910d8d19fd17895a9ecf233a847cce3aa8875aa3 100644 (file)
@@ -69,7 +69,7 @@ static void cu_twkb(char *wkt, int8_t prec_xy, int8_t prec_z, int8_t prec_m, uin
 /*
 ** Creating an input TWKB from a wkt string
 */
-static void cu_twkb_idlist(char *wkt, uint64_t *idlist, int8_t prec_xy, int8_t prec_z, int8_t prec_m, uint8_t variant)
+static void cu_twkb_idlist(char *wkt, int64_t *idlist, int8_t prec_xy, int8_t prec_z, int8_t prec_m, uint8_t variant)
 {
        LWGEOM *g = lwgeom_from_wkt(wkt, LW_PARSER_CHECK_NONE);
        LWGEOM *g_b;
@@ -199,7 +199,7 @@ static void test_twkb_out_collection(void)
 
 static void test_twkb_out_idlist(void)
 {
-       uint64_t idlist[2];
+       int64_t idlist[2];
 
        idlist[0] = 2;
        idlist[1] = 4;
index e1f8705f2fb34333cb4bfbbd30515b1785bb0806..214c27e432c1070f6c8ba78702a8c9cd7b06bb0d 100644 (file)
@@ -19,7 +19,6 @@
 #include <stdio.h>
 #include <stdint.h>
 #include "proj_api.h"
-#include "bytebuffer.h"
 
 /**
 * @file liblwgeom.h
index f97f4ccee5b9acee0051b4ae5c1c759610a2d1c9..6096af8a27c6c9c87b4f4040593f84e2513d52dd 100644 (file)
@@ -30,6 +30,8 @@
 
 #include <float.h>
 
+#include "bytebuffer.h"
+
 #include "liblwgeom.h"
 
 
index cf4df559a570fac087d7301cada176a5b0af9831..bc0e0a299a63300856a3ac7352d47cc3b722bfd8 100644 (file)
 #include <ctype.h>
 #include <string.h>
 
+SHP_CVSID("$Id$")
 
 #ifndef FALSE
 #  define FALSE                0
index 418c5e817ac648531c0d07b8aa1d2e859a18cab4..a6ba456033d854042e71b4bbcce18b313be1c253 100644 (file)
@@ -28,7 +28,7 @@
 #include "shpcommon.h"
 #include "getopt.h"
 
-
+#define P2S_RCSID "$Id$"
 
 /*
  * Error message handling
index dd2afab70413979fef01db2080b78e94dc12d43b..c7f7a2a232f77fb8779de8c27ab80a24d58c72c0 100644 (file)
@@ -64,6 +64,7 @@
 #include <string.h>
 #include <stdio.h>
 
+SHP_CVSID("$Id$")
 
 #ifdef SHPAPI_UTF8_HOOKS
 #   ifdef SHPAPI_WINDOWS
index 5ad00c884ad59a876de49183986fe481e4084a0f..dabb7bfda4fe4d12cf95149812bbbf790df75f7d 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "../liblwgeom/stringbuffer.h"
 
-
+#define S2P_RCSID "$Id$"
 
 /* Number of digits of precision in WKT produced. */
 #define WKT_PRECISION 15
index ee4c3fa160b2459598720931dd260dca69265d4b..444c07bc3b79ed7799970f6987dd24c2e92b391e 100644 (file)
 #include <string.h>
 #include <stdio.h>
 
+SHP_CVSID("$Id$")
 
 typedef unsigned char uchar;
 
index f9fa5314c3968157357eaf08ac7d030246dd51b0..fc1002ea00f8beb19258705623ce0c20e2fbf674 100644 (file)
@@ -67,6 +67,7 @@
 */
 #define MAXTILESIZE 1073741824
 
+#define RCSID "$Id$"
 
 typedef struct raster_loader_config {
        /* raster filename */
index 550f7f88f14231befa0e6c63b67199929c00014d..dced639359496c6603f23885c0c8bbf397550e91 100755 (executable)
@@ -19,6 +19,7 @@ foreach $f (@files)
                open(F, $file);
                while(<F>)
                {
+            $r = $1 if /\$Id: \S+ (\d+) /;
                }
                print "$f got revision $r\n" if $debug && $r;
                $rev = $r if $r > $rev;