[Thuban-commits] r2798 - in branches/WIP-pyshapelib-Unicode/thuban/libraries: pyshapelib shapelib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Dec 18 19:51:33 CET 2007


Author: bramz
Date: 2007-12-18 19:51:33 +0100 (Tue, 18 Dec 2007)
New Revision: 2798

Modified:
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/ChangeLog
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflibmodule.c
   branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/dbfopen.c
   branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/safileio.c
   branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/shapefil.h
Log:
shapelib now has a hook to set your own atof function.
Before opening or creating a DBF file, atof is now set to PyOS_ascii_atof
See libaries/pyshapelib/ChangeLog

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/ChangeLog
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/ChangeLog	2007-12-15 20:40:22 UTC (rev 2797)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/ChangeLog	2007-12-18 18:51:33 UTC (rev 2798)
@@ -1,5 +1,13 @@
-2007-12-15  Bram de Greve <bram.degreve at bramz.net>
+2007-12-18	Bram de Greve <bram.degreve at bramz.net>
 
+	* dbflibmodule.c: shapelib now has a hook to set your own atof function.
+	See http://bugzilla.maptools.org/show_bug.cgi?id=1615#c3
+	- Before opening or creating a DBF file, atof is now set to PyOS_ascii_atof.
+	- corresponding revisions of shapelib on cvs.maptools.org: shapefil.h v1.42,
+	dbfopen.c v1.78, safileio.c v1.3
+
+2007-12-15	Bram de Greve <bram.degreve at bramz.net>
+
 	* dbflibmodule.c: Unicode support mark II.  Ditched are the language_driver
 	members and functions, as it is not sufficient to indicate code pages 
 	specified by .CPG files.  

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflibmodule.c
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflibmodule.c	2007-12-15 20:40:22 UTC (rev 2797)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflibmodule.c	2007-12-18 18:51:33 UTC (rev 2798)
@@ -107,6 +107,7 @@
 */
 static int dbffile_init(DBFFileObject* self, PyObject* args, PyObject* kwds)
 {
+	SAHooks hooks;
 	char* file = NULL;
 	char* mode = "rb";
 	PyObject* return_unicode = 0;
@@ -159,7 +160,9 @@
 		if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|sO:DBFFile", kwlist, 
 			Py_FileSystemDefaultEncoding, &file, &mode, &return_unicode)) return -1;	
 #endif
-		self->handle = DBFOpen(file, mode);
+		SASetupDefaultHooks(&hooks);
+		hooks.Atof = PyOS_ascii_atof;
+		self->handle = DBFOpenLL(file, mode, &hooks);
 
 		if (!self->handle)
 		{
@@ -737,14 +740,17 @@
 	
 	if (!handle)
 	{
+		SAHooks hooks;
+		SASetupDefaultHooks(&hooks);
+		hooks.Atof = PyOS_ascii_atof;
 #if HAVE_CODE_PAGE
 		if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|sOO:create", kwlist, Py_FileSystemDefaultEncoding, 
 				&file, &code_page, &return_unicode, &codecs_map)) return NULL;
-		handle = DBFCreateEx(file, code_page);
+		handle = DBFCreateLL(file, code_page, &hooks);
 #else
 		if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|O:create", kwlist, Py_FileSystemDefaultEncoding, 
 				&file, &return_unicode)) return NULL;
-		handle = DBFCreate(file);
+		handle = DBFCreateLL(file, &hooks);
 #endif
 		if (!handle)
 		{

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/dbfopen.c
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/dbfopen.c	2007-12-15 20:40:22 UTC (rev 2797)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/dbfopen.c	2007-12-18 18:51:33 UTC (rev 2798)
@@ -34,8 +34,16 @@
  ******************************************************************************
  *
  * $Log: dbfopen.c,v $
+ * Revision 1.78  2007/12/18 18:28:07  bram
+ * - create hook for client specific atof (bugzilla ticket 1615)
+ * - check for NULL handle before closing cpCPG file, and close after reading.
+ *
  * Revision 1.77  2007/12/15 20:25:21  bram
- * dbfopen.c now reads the Code Page information from the DBF file, and exports this information as a string through the DBFGetCodePage function.  This is either the number from the LDID header field ("LDID/<number>") or as the content of an accompanying .CPG file.  When creating a DBF file, the code can be set using DBFCreateEx.
+ * dbfopen.c now reads the Code Page information from the DBF file, and exports
+ * this information as a string through the DBFGetCodePage function.  This is 
+ * either the number from the LDID header field ("LDID/<number>") or as the 
+ * content of an accompanying .CPG file.  When creating a DBF file, the code can
+ * be set using DBFCreateEx.
  *
  * Revision 1.76  2007/12/12 22:21:32  bram
  * DBFClose: check for NULL psDBF handle before trying to close it.
@@ -414,7 +422,7 @@
     if( psDBF->fp == NULL )
     {
         free( psDBF );
-        psHooks->FClose( pfCPG );
+        if( pfCPG ) psHooks->FClose( pfCPG );
         return( NULL );
     }
 
@@ -429,7 +437,7 @@
     if( psDBF->sHooks.FRead( pabyBuf, 32, 1, psDBF->fp ) != 1 )
     {
         psDBF->sHooks.FClose( psDBF->fp );
-        psDBF->sHooks.FClose( pfCPG );
+        if( pfCPG ) psDBF->sHooks.FClose( pfCPG );
         free( pabyBuf );
         free( psDBF );
         return NULL;
@@ -464,6 +472,7 @@
             psDBF->pszCodePage = (char *) malloc(n + 1);
             memcpy( psDBF->pszCodePage, pabyBuf, n + 1 );
         }
+		psDBF->sHooks.FClose( pfCPG );
     }
     if( psDBF->pszCodePage == NULL && pabyBuf[29] != 0 )
     {
@@ -896,7 +905,7 @@
 /* -------------------------------------------------------------------- */
     if( chReqType == 'N' )
     {
-        psDBF->dfDoubleField = atof(psDBF->pszWorkField);
+        psDBF->dfDoubleField = psDBF->sHooks.Atof(psDBF->pszWorkField);
 
 	pReturnField = &(psDBF->dfDoubleField);
     }

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/safileio.c
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/safileio.c	2007-12-15 20:40:22 UTC (rev 2797)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/safileio.c	2007-12-18 18:51:33 UTC (rev 2798)
@@ -1,5 +1,5 @@
 /******************************************************************************
- * $Id: safileio.c,v 1.2 2007/12/15 20:25:30 bram Exp $
+ * $Id: safileio.c,v 1.3 2007/12/18 18:28:11 bram Exp $
  *
  * Project:  Shapelib
  * Purpose:  Default implementation of file io based on stdio.
@@ -34,8 +34,16 @@
  ******************************************************************************
  *
  * $Log: safileio.c,v $
+ * Revision 1.3  2007/12/18 18:28:11  bram
+ * - create hook for client specific atof (bugzilla ticket 1615)
+ * - check for NULL handle before closing cpCPG file, and close after reading.
+ *
  * Revision 1.2  2007/12/15 20:25:30  bram
- * dbfopen.c now reads the Code Page information from the DBF file, and exports this information as a string through the DBFGetCodePage function.  This is either the number from the LDID header field ("LDID/<number>") or as the content of an accompanying .CPG file.  When creating a DBF file, the code can be set using DBFCreateEx.
+ * dbfopen.c now reads the Code Page information from the DBF file, and exports
+ * this information as a string through the DBFGetCodePage function.  This is 
+ * either the number from the LDID header field ("LDID/<number>") or as the 
+ * content of an accompanying .CPG file.  When creating a DBF file, the code can
+ * be set using DBFCreateEx.
  *
  * Revision 1.1  2007/12/06 06:56:41  fwarmerdam
  * new
@@ -51,7 +59,7 @@
 #include <string.h>
 #include <stdio.h>
 
-SHP_CVSID("$Id: safileio.c,v 1.2 2007/12/15 20:25:30 bram Exp $");
+SHP_CVSID("$Id: safileio.c,v 1.3 2007/12/18 18:28:11 bram Exp $");
 
 /************************************************************************/
 /*                              SADFOpen()                              */
@@ -122,8 +130,6 @@
 int SADFClose( SAFile file )
 
 {
-    if( file == NULL )
-        return;
     return fclose( (FILE *) file );
 }
 
@@ -164,4 +170,5 @@
     psHooks->Remove  = SADRemove;
 
     psHooks->Error   = SADError;
+    psHooks->Atof    = atof;
 }

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/shapefil.h
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/shapefil.h	2007-12-15 20:40:22 UTC (rev 2797)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/shapefil.h	2007-12-18 18:51:33 UTC (rev 2798)
@@ -37,8 +37,16 @@
  ******************************************************************************
  *
  * $Log: shapefil.h,v $
+ * Revision 1.42  2007/12/18 18:28:14  bram
+ * - create hook for client specific atof (bugzilla ticket 1615)
+ * - check for NULL handle before closing cpCPG file, and close after reading.
+ *
  * Revision 1.41  2007/12/15 20:25:32  bram
- * dbfopen.c now reads the Code Page information from the DBF file, and exports this information as a string through the DBFGetCodePage function.  This is either the number from the LDID header field ("LDID/<number>") or as the content of an accompanying .CPG file.  When creating a DBF file, the code can be set using DBFCreateEx.
+ * dbfopen.c now reads the Code Page information from the DBF file, and exports
+ * this information as a string through the DBFGetCodePage function.  This is 
+ * either the number from the LDID header field ("LDID/<number>") or as the 
+ * content of an accompanying .CPG file.  When creating a DBF file, the code can
+ * be set using DBFCreateEx.
  *
  * Revision 1.40  2007/12/06 07:00:25  fwarmerdam
  * dbfopen now using SAHooks for fileio
@@ -208,6 +216,7 @@
     int        (*Remove) ( const char *filename );
 
     void       (*Error) ( const char *message );
+    double     (*Atof)  ( const char *str );
 } SAHooks;
 
 void SHPAPI_CALL SASetupDefaultHooks( SAHooks *psHooks );



More information about the Thuban-commits mailing list