Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #4413 from rouault/fix_dxf2shp_gdal2.2
Browse files Browse the repository at this point in the history
Fix build of dxf2shp plugin with GDAL 2.2
  • Loading branch information
rouault committed Apr 25, 2017
2 parents 7af8c49 + 486aa81 commit 46186f1
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 74 deletions.
3 changes: 3 additions & 0 deletions src/plugins/dxf2shp_converter/CMakeLists.txt
Expand Up @@ -8,6 +8,8 @@ SET (dxf2shpconverter_SRCS
builder.cpp
dxflib/src/dl_dxf.cpp
dxflib/src/dl_writer_ascii.cpp
shapelib-1.2.10/dbfopen.c
shapelib-1.2.10/shpopen.c
)

SET (dxf2shpconverter_UIS dxf2shpconvertergui.ui)
Expand All @@ -32,6 +34,7 @@ ADD_LIBRARY (dxf2shpconverterplugin MODULE ${dxf2shpconverter_SRCS} ${dxf2shpcon

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${GDAL_INCLUDE_DIR}
../../core
../../core/geometry
../../core/raster
Expand Down
84 changes: 45 additions & 39 deletions src/plugins/dxf2shp_converter/shapelib-1.2.10/dbfopen.c
Expand Up @@ -182,8 +182,10 @@
* Added header.
*/

#if 0
static char rcsid[] =
"$Id: dbfopen.c,v 1.48 2003/03/10 14:51:27 warmerda Exp $";
#endif

#include "shapefil.h"

Expand Down Expand Up @@ -256,9 +258,9 @@ static void DBFWriteHeader( DBFHandle psDBF )
/* Write the initial 32 byte file header, and all the field */
/* descriptions. */
/* -------------------------------------------------------------------- */
fseek( psDBF->fp, 0, 0 );
fwrite( abyHeader, XBASE_FLDHDR_SZ, 1, psDBF->fp );
fwrite( psDBF->pszHeader, XBASE_FLDHDR_SZ, psDBF->nFields, psDBF->fp );
VSIFSeekL( psDBF->fp, 0, 0 );
VSIFWriteL( abyHeader, XBASE_FLDHDR_SZ, 1, psDBF->fp );
VSIFWriteL( psDBF->pszHeader, XBASE_FLDHDR_SZ, psDBF->nFields, psDBF->fp );

/* -------------------------------------------------------------------- */
/* Write out the newline character if there is room for it. */
Expand All @@ -268,7 +270,7 @@ static void DBFWriteHeader( DBFHandle psDBF )
char cNewline;

cNewline = 0x0d;
fwrite( &cNewline, 1, 1, psDBF->fp );
VSIFWriteL( &cNewline, 1, 1, psDBF->fp );
}
}

Expand All @@ -290,8 +292,8 @@ static void DBFFlushRecord( DBFHandle psDBF )
nRecordOffset = psDBF->nRecordLength * psDBF->nCurrentRecord
+ psDBF->nHeaderLength;

fseek( psDBF->fp, nRecordOffset, 0 );
fwrite( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
VSIFSeekL( psDBF->fp, nRecordOffset, 0 );
VSIFWriteL( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
}
}

Expand Down Expand Up @@ -342,12 +344,12 @@ DBFOpen( const char * pszFilename, const char * pszAccess )
sprintf( pszFullname, "%s.dbf", pszBasename );

psDBF = ( DBFHandle ) calloc( 1, sizeof( DBFInfo ) );
psDBF->fp = fopen( pszFullname, pszAccess );
psDBF->fp = VSIFOpenL( pszFullname, pszAccess );

if ( psDBF->fp == NULL )
{
sprintf( pszFullname, "%s.DBF", pszBasename );
psDBF->fp = fopen( pszFullname, pszAccess );
psDBF->fp = VSIFOpenL( pszFullname, pszAccess );
}

free( pszBasename );
Expand All @@ -367,9 +369,9 @@ DBFOpen( const char * pszFilename, const char * pszAccess )
/* Read Table Header info */
/* -------------------------------------------------------------------- */
pabyBuf = ( unsigned char * ) malloc( 500 );
if ( fread( pabyBuf, 32, 1, psDBF->fp ) != 1 )
if ( VSIFReadL( pabyBuf, 32, 1, psDBF->fp ) != 1 )
{
fclose( psDBF->fp );
VSIFCloseL( psDBF->fp );
free( pabyBuf );
free( psDBF );
return NULL;
Expand All @@ -389,12 +391,13 @@ DBFOpen( const char * pszFilename, const char * pszAccess )
/* Read in Field Definitions */
/* -------------------------------------------------------------------- */

pabyBuf = psDBF->pszHeader = ( unsigned char * ) SfRealloc( pabyBuf, nHeadLen );
psDBF->pszHeader = ( char * ) SfRealloc( pabyBuf, nHeadLen );
pabyBuf = ( unsigned char* )psDBF->pszHeader;

fseek( psDBF->fp, 32, 0 );
if ( fread( pabyBuf, nHeadLen - 32, 1, psDBF->fp ) != 1 )
VSIFSeekL( psDBF->fp, 32, 0 );
if ( VSIFReadL( pabyBuf, nHeadLen - 32, 1, psDBF->fp ) != 1 )
{
fclose( psDBF->fp );
VSIFCloseL( psDBF->fp );
free( pabyBuf );
free( psDBF );
return NULL;
Expand Down Expand Up @@ -456,8 +459,8 @@ DBFClose( DBFHandle psDBF )
{
unsigned char abyFileHeader[32];

fseek( psDBF->fp, 0, 0 );
fread( abyFileHeader, 32, 1, psDBF->fp );
VSIFSeekL( psDBF->fp, 0, 0 );
VSIFReadL( abyFileHeader, 32, 1, psDBF->fp );

abyFileHeader[1] = 95; /* YY */
abyFileHeader[2] = 7; /* MM */
Expand All @@ -468,14 +471,14 @@ DBFClose( DBFHandle psDBF )
abyFileHeader[6] = ( psDBF->nRecords / ( 256 * 256 ) ) % 256;
abyFileHeader[7] = ( psDBF->nRecords / ( 256 * 256 * 256 ) ) % 256;

fseek( psDBF->fp, 0, 0 );
fwrite( abyFileHeader, 32, 1, psDBF->fp );
VSIFSeekL( psDBF->fp, 0, 0 );
VSIFWriteL( abyFileHeader, 32, 1, psDBF->fp );
}

/* -------------------------------------------------------------------- */
/* Close, and free resources. */
/* -------------------------------------------------------------------- */
fclose( psDBF->fp );
VSIFCloseL( psDBF->fp );

if ( psDBF->panFieldOffset != NULL )
{
Expand Down Expand Up @@ -509,7 +512,7 @@ DBFCreate( const char *pszFilename )

{
DBFHandle psDBF;
FILE *fp;
VSILFILE *fp;
char *pszFullname, *pszBasename;
int i;

Expand All @@ -534,17 +537,20 @@ DBFCreate( const char *pszFilename )
/* -------------------------------------------------------------------- */
/* Create the file. */
/* -------------------------------------------------------------------- */
fp = fopen( pszFullname, "wb" );
fp = VSIFOpenL( pszFullname, "wb" );
if ( fp == NULL )
{
free( pszFullname );
return( NULL );
}

fputc( 0, fp );
fclose( fp );
{
char ch = 0;
VSIFWriteL( &ch, 1, 1, fp );
}
VSIFCloseL( fp );

fp = fopen( pszFullname, "rb+" );
fp = VSIFOpenL( pszFullname, "rb+" );
if ( fp == NULL )
{
free( pszFullname );
Expand Down Expand Up @@ -716,17 +722,17 @@ static void *DBFReadAttribute( DBFHandle psDBF, int hEntity, int iField,

nRecordOffset = psDBF->nRecordLength * hEntity + psDBF->nHeaderLength;

if ( fseek( psDBF->fp, nRecordOffset, 0 ) != 0 )
if ( VSIFSeekL( psDBF->fp, nRecordOffset, 0 ) != 0 )
{
fprintf( stderr, "fseek(%d) failed on DBF file.\n",
nRecordOffset );
return NULL;
}

if ( fread( psDBF->pszCurrentRecord, psDBF->nRecordLength,
1, psDBF->fp ) != 1 )
if ( VSIFReadL( psDBF->pszCurrentRecord, psDBF->nRecordLength,
1, psDBF->fp ) != 1 )
{
fprintf( stderr, "fread(%d) failed on DBF file.\n",
fprintf( stderr, "VSIFReadL(%d) failed on DBF file.\n",
psDBF->nRecordLength );
return NULL;
}
Expand Down Expand Up @@ -790,7 +796,7 @@ static void *DBFReadAttribute( DBFHandle psDBF, int hEntity, int iField,
}

/************************************************************************/
/* DBFReadIntAttribute() */
/* DBFReadIntegerAttribute() */
/* */
/* Read an integer attribute. */
/************************************************************************/
Expand Down Expand Up @@ -1013,8 +1019,8 @@ static int DBFWriteAttribute( DBFHandle psDBF, int hEntity, int iField,

nRecordOffset = psDBF->nRecordLength * hEntity + psDBF->nHeaderLength;

fseek( psDBF->fp, nRecordOffset, 0 );
fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
VSIFSeekL( psDBF->fp, nRecordOffset, 0 );
VSIFReadL( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );

psDBF->nCurrentRecord = hEntity;
}
Expand Down Expand Up @@ -1073,7 +1079,7 @@ static int DBFWriteAttribute( DBFHandle psDBF, int hEntity, int iField,
{
int nWidth = psDBF->panFieldSize[iField];

if ( sizeof( szSField ) - 2 < nWidth )
if (( int )sizeof( szSField ) - 2 < nWidth )
nWidth = sizeof( szSField ) - 2;

sprintf( szFormat, "%%%dd", nWidth );
Expand All @@ -1091,7 +1097,7 @@ static int DBFWriteAttribute( DBFHandle psDBF, int hEntity, int iField,
{
int nWidth = psDBF->panFieldSize[iField];

if ( sizeof( szSField ) - 2 < nWidth )
if (( int )sizeof( szSField ) - 2 < nWidth )
nWidth = sizeof( szSField ) - 2;

sprintf( szFormat, "%%%d.%df",
Expand Down Expand Up @@ -1182,8 +1188,8 @@ int DBFWriteAttributeDirectly( DBFHandle psDBF, int hEntity, int iField,

nRecordOffset = psDBF->nRecordLength * hEntity + psDBF->nHeaderLength;

fseek( psDBF->fp, nRecordOffset, 0 );
fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
VSIFSeekL( psDBF->fp, nRecordOffset, 0 );
VSIFReadL( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );

psDBF->nCurrentRecord = hEntity;
}
Expand Down Expand Up @@ -1328,8 +1334,8 @@ DBFWriteTuple( DBFHandle psDBF, int hEntity, void * pRawTuple )

nRecordOffset = psDBF->nRecordLength * hEntity + psDBF->nHeaderLength;

fseek( psDBF->fp, nRecordOffset, 0 );
fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
VSIFSeekL( psDBF->fp, nRecordOffset, 0 );
VSIFReadL( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );

psDBF->nCurrentRecord = hEntity;
}
Expand Down Expand Up @@ -1372,8 +1378,8 @@ DBFReadTuple( DBFHandle psDBF, int hEntity )

nRecordOffset = psDBF->nRecordLength * hEntity + psDBF->nHeaderLength;

fseek( psDBF->fp, nRecordOffset, 0 );
fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
VSIFSeekL( psDBF->fp, nRecordOffset, 0 );
VSIFReadL( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );

psDBF->nCurrentRecord = hEntity;
}
Expand Down
57 changes: 54 additions & 3 deletions src/plugins/dxf2shp_converter/shapelib-1.2.10/shapefil.h
Expand Up @@ -116,10 +116,61 @@

#include <stdio.h>

#include "cpl_vsi.h"

#ifdef USE_DBMALLOC
#include <dbmalloc.h>
#endif

#define SHPOpen qgis_SHPOpen
#define SHPCreate qgis_SHPCreate
#define SHPGetInfo qgis_SHPGetInfo
#define SHPReadObject qgis_SHPReadObject
#define SHPWriteObject qgis_SHPWriteObject
#define SHPDestroyObject qgis_SHPDestroyObject
#define SHPComputeExtents qgis_SHPComputeExtents
#define SHPCreateObject qgis_SHPCreateObject
#define SHPCreateSimpleObject qgis_SHPCreateSimpleObject
#define SHPRewindObject qgis_SHPRewindObject
#define SHPClose qgis_SHPClose
#define SHPTypeName qgis_SHPTypeName
#define SHPPartTypeName qgis_SHPPartTypeName
#define SHPCreateTree qgis_SHPCreateTree
#define SHPDestroyTree qgis_SHPDestroyTree
#define SHPWriteTree qgis_SHPWriteTree
#define SHPReadTree qgis_SHPReadTree
#define SHPTreeAddObject qgis_SHPTreeAddObject
#define SHPTreeAddShapeId qgis_SHPTreeAddShapeId
#define SHPTreeRemoveShapeId qgis_SHPTreeRemoveShapeId
#define SHPTreeTrimExtraNodes qgis_SHPTreeTrimExtraNodes
#define SHPTreeFindLikelyShapes qgis_SHPTreeFindLikelyShapes
#define SHPCheckBoundsOverlap qgis_SHPCheckBoundsOverlap
#define DBFOpen qgis_DBFOpen
#define DBFCreate qgis_DBFCreate
#define DBFGetFieldCount qgis_DBFGetFieldCount
#define DBFGetRecordCount qgis_DBFGetRecordCount
#define DBFAddField qgis_DBFAddField
#define DBFFieldType qgis_DBFFieldType
#define DBFGetFieldInfo qgis_DBFGetFieldInfo
#define DBFGetFieldIndex qgis_DBFGetFieldIndex
#define DBFReadIntegerAttribute qgis_DBFReadIntegerAttribute
#define DBFReadDoubleAttribute qgis_DBFReadDoubleAttribute
#define DBFReadStringAttribute qgis_DBFReadStringAttribute
#define DBFReadLogicalAttribute qgis_DBFReadLogicalAttribute
#define DBFIsAttributeNULL qgis_DBFIsAttributeNULL
#define DBFWriteIntegerAttribute qgis_DBFWriteIntegerAttribute
#define DBFWriteDoubleAttribute qgis_DBFWriteDoubleAttribute
#define DBFWriteStringAttribute qgis_DBFWriteStringAttribute
#define DBFWriteNULLAttribute qgis_DBFWriteNULLAttribute
#define DBFWriteLogicalAttribute qgis_DBFWriteLogicalAttribute
#define DBFWriteAttributeDirectly qgis_DBFWriteAttributeDirectly
#define DBFReadTuple qgis_DBFReadTuple
#define DBFWriteTuple qgis_DBFWriteTuple
#define DBFCloneEmpty qgis_DBFCloneEmpty
#define DBFClose qgis_DBFClose
#define DBFGetNativeFieldType qgis_DBFGetNativeFieldType


#ifdef __cplusplus
extern "C"
{
Expand Down Expand Up @@ -189,8 +240,8 @@ extern "C"
/************************************************************************/
typedef struct
{
FILE *fpSHP;
FILE *fpSHX;
VSILFILE *fpSHP;
VSILFILE *fpSHX;

int nShapeType; /* SHPT_* */

Expand Down Expand Up @@ -382,7 +433,7 @@ extern "C"
/************************************************************************/
typedef struct
{
FILE *fp;
VSILFILE *fp;

int nRecords;

Expand Down

0 comments on commit 46186f1

Please sign in to comment.