Skip to content

Commit b3579ab

Browse files
committed
Fix build of dxf2shp plugin with GDAL 2.2
Up to know the plugin relied on the fact that GDAL exported the symbols of its internal shapelib. Since GDAL 2.2 this is no longer the case. So build the internal copy of shapelib in the plugin, but to avoid symbol name clashes, prefix the shapelib symbols with qgis_. And also use GDAL VSI large API for I/O so that on Windows on particular non ASCII filenames are properly handled.
1 parent eb7c98f commit b3579ab

File tree

4 files changed

+137
-74
lines changed

4 files changed

+137
-74
lines changed

src/plugins/dxf2shp_converter/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ SET (dxf2shpconverter_SRCS
88
builder.cpp
99
dxflib/src/dl_dxf.cpp
1010
dxflib/src/dl_writer_ascii.cpp
11+
shapelib-1.2.10/dbfopen.c
12+
shapelib-1.2.10/shpopen.c
1113
)
1214

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

3335
INCLUDE_DIRECTORIES(
3436
${CMAKE_CURRENT_BINARY_DIR}
37+
${GDAL_INCLUDE_DIR}
3538
../../core
3639
../../core/geometry
3740
../../core/raster

src/plugins/dxf2shp_converter/shapelib-1.2.10/dbfopen.c

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,10 @@
182182
* Added header.
183183
*/
184184

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

188190
#include "shapefil.h"
189191

@@ -256,9 +258,9 @@ static void DBFWriteHeader( DBFHandle psDBF )
256258
/* Write the initial 32 byte file header, and all the field */
257259
/* descriptions. */
258260
/* -------------------------------------------------------------------- */
259-
fseek( psDBF->fp, 0, 0 );
260-
fwrite( abyHeader, XBASE_FLDHDR_SZ, 1, psDBF->fp );
261-
fwrite( psDBF->pszHeader, XBASE_FLDHDR_SZ, psDBF->nFields, psDBF->fp );
261+
VSIFSeekL( psDBF->fp, 0, 0 );
262+
VSIFWriteL( abyHeader, XBASE_FLDHDR_SZ, 1, psDBF->fp );
263+
VSIFWriteL( psDBF->pszHeader, XBASE_FLDHDR_SZ, psDBF->nFields, psDBF->fp );
262264

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

270272
cNewline = 0x0d;
271-
fwrite( &cNewline, 1, 1, psDBF->fp );
273+
VSIFWriteL( &cNewline, 1, 1, psDBF->fp );
272274
}
273275
}
274276

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

293-
fseek( psDBF->fp, nRecordOffset, 0 );
294-
fwrite( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
295+
VSIFSeekL( psDBF->fp, nRecordOffset, 0 );
296+
VSIFWriteL( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
295297
}
296298
}
297299

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

344346
psDBF = ( DBFHandle ) calloc( 1, sizeof( DBFInfo ) );
345-
psDBF->fp = fopen( pszFullname, pszAccess );
347+
psDBF->fp = VSIFOpenL( pszFullname, pszAccess );
346348

347349
if ( psDBF->fp == NULL )
348350
{
349351
sprintf( pszFullname, "%s.DBF", pszBasename );
350-
psDBF->fp = fopen( pszFullname, pszAccess );
352+
psDBF->fp = VSIFOpenL( pszFullname, pszAccess );
351353
}
352354

353355
free( pszBasename );
@@ -367,9 +369,9 @@ DBFOpen( const char * pszFilename, const char * pszAccess )
367369
/* Read Table Header info */
368370
/* -------------------------------------------------------------------- */
369371
pabyBuf = ( unsigned char * ) malloc( 500 );
370-
if ( fread( pabyBuf, 32, 1, psDBF->fp ) != 1 )
372+
if ( VSIFReadL( pabyBuf, 32, 1, psDBF->fp ) != 1 )
371373
{
372-
fclose( psDBF->fp );
374+
VSIFCloseL( psDBF->fp );
373375
free( pabyBuf );
374376
free( psDBF );
375377
return NULL;
@@ -389,12 +391,13 @@ DBFOpen( const char * pszFilename, const char * pszAccess )
389391
/* Read in Field Definitions */
390392
/* -------------------------------------------------------------------- */
391393

392-
pabyBuf = psDBF->pszHeader = ( unsigned char * ) SfRealloc( pabyBuf, nHeadLen );
394+
psDBF->pszHeader = ( char * ) SfRealloc( pabyBuf, nHeadLen );
395+
pabyBuf = ( unsigned char* )psDBF->pszHeader;
393396

394-
fseek( psDBF->fp, 32, 0 );
395-
if ( fread( pabyBuf, nHeadLen - 32, 1, psDBF->fp ) != 1 )
397+
VSIFSeekL( psDBF->fp, 32, 0 );
398+
if ( VSIFReadL( pabyBuf, nHeadLen - 32, 1, psDBF->fp ) != 1 )
396399
{
397-
fclose( psDBF->fp );
400+
VSIFCloseL( psDBF->fp );
398401
free( pabyBuf );
399402
free( psDBF );
400403
return NULL;
@@ -456,8 +459,8 @@ DBFClose( DBFHandle psDBF )
456459
{
457460
unsigned char abyFileHeader[32];
458461

459-
fseek( psDBF->fp, 0, 0 );
460-
fread( abyFileHeader, 32, 1, psDBF->fp );
462+
VSIFSeekL( psDBF->fp, 0, 0 );
463+
VSIFReadL( abyFileHeader, 32, 1, psDBF->fp );
461464

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

471-
fseek( psDBF->fp, 0, 0 );
472-
fwrite( abyFileHeader, 32, 1, psDBF->fp );
474+
VSIFSeekL( psDBF->fp, 0, 0 );
475+
VSIFWriteL( abyFileHeader, 32, 1, psDBF->fp );
473476
}
474477

475478
/* -------------------------------------------------------------------- */
476479
/* Close, and free resources. */
477480
/* -------------------------------------------------------------------- */
478-
fclose( psDBF->fp );
481+
VSIFCloseL( psDBF->fp );
479482

480483
if ( psDBF->panFieldOffset != NULL )
481484
{
@@ -509,7 +512,7 @@ DBFCreate( const char *pszFilename )
509512

510513
{
511514
DBFHandle psDBF;
512-
FILE *fp;
515+
VSILFILE *fp;
513516
char *pszFullname, *pszBasename;
514517
int i;
515518

@@ -534,17 +537,20 @@ DBFCreate( const char *pszFilename )
534537
/* -------------------------------------------------------------------- */
535538
/* Create the file. */
536539
/* -------------------------------------------------------------------- */
537-
fp = fopen( pszFullname, "wb" );
540+
fp = VSIFOpenL( pszFullname, "wb" );
538541
if ( fp == NULL )
539542
{
540543
free( pszFullname );
541544
return( NULL );
542545
}
543546

544-
fputc( 0, fp );
545-
fclose( fp );
547+
{
548+
char ch = 0;
549+
VSIFWriteL( &ch, 1, 1, fp );
550+
}
551+
VSIFCloseL( fp );
546552

547-
fp = fopen( pszFullname, "rb+" );
553+
fp = VSIFOpenL( pszFullname, "rb+" );
548554
if ( fp == NULL )
549555
{
550556
free( pszFullname );
@@ -716,17 +722,17 @@ static void *DBFReadAttribute( DBFHandle psDBF, int hEntity, int iField,
716722

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

719-
if ( fseek( psDBF->fp, nRecordOffset, 0 ) != 0 )
725+
if ( VSIFSeekL( psDBF->fp, nRecordOffset, 0 ) != 0 )
720726
{
721727
fprintf( stderr, "fseek(%d) failed on DBF file.\n",
722728
nRecordOffset );
723729
return NULL;
724730
}
725731

726-
if ( fread( psDBF->pszCurrentRecord, psDBF->nRecordLength,
727-
1, psDBF->fp ) != 1 )
732+
if ( VSIFReadL( psDBF->pszCurrentRecord, psDBF->nRecordLength,
733+
1, psDBF->fp ) != 1 )
728734
{
729-
fprintf( stderr, "fread(%d) failed on DBF file.\n",
735+
fprintf( stderr, "VSIFReadL(%d) failed on DBF file.\n",
730736
psDBF->nRecordLength );
731737
return NULL;
732738
}
@@ -790,7 +796,7 @@ static void *DBFReadAttribute( DBFHandle psDBF, int hEntity, int iField,
790796
}
791797

792798
/************************************************************************/
793-
/* DBFReadIntAttribute() */
799+
/* DBFReadIntegerAttribute() */
794800
/* */
795801
/* Read an integer attribute. */
796802
/************************************************************************/
@@ -1013,8 +1019,8 @@ static int DBFWriteAttribute( DBFHandle psDBF, int hEntity, int iField,
10131019

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

1016-
fseek( psDBF->fp, nRecordOffset, 0 );
1017-
fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
1022+
VSIFSeekL( psDBF->fp, nRecordOffset, 0 );
1023+
VSIFReadL( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
10181024

10191025
psDBF->nCurrentRecord = hEntity;
10201026
}
@@ -1073,7 +1079,7 @@ static int DBFWriteAttribute( DBFHandle psDBF, int hEntity, int iField,
10731079
{
10741080
int nWidth = psDBF->panFieldSize[iField];
10751081

1076-
if ( sizeof( szSField ) - 2 < nWidth )
1082+
if (( int )sizeof( szSField ) - 2 < nWidth )
10771083
nWidth = sizeof( szSField ) - 2;
10781084

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

1094-
if ( sizeof( szSField ) - 2 < nWidth )
1100+
if (( int )sizeof( szSField ) - 2 < nWidth )
10951101
nWidth = sizeof( szSField ) - 2;
10961102

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

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

1185-
fseek( psDBF->fp, nRecordOffset, 0 );
1186-
fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
1191+
VSIFSeekL( psDBF->fp, nRecordOffset, 0 );
1192+
VSIFReadL( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
11871193

11881194
psDBF->nCurrentRecord = hEntity;
11891195
}
@@ -1328,8 +1334,8 @@ DBFWriteTuple( DBFHandle psDBF, int hEntity, void * pRawTuple )
13281334

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

1331-
fseek( psDBF->fp, nRecordOffset, 0 );
1332-
fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
1337+
VSIFSeekL( psDBF->fp, nRecordOffset, 0 );
1338+
VSIFReadL( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
13331339

13341340
psDBF->nCurrentRecord = hEntity;
13351341
}
@@ -1372,8 +1378,8 @@ DBFReadTuple( DBFHandle psDBF, int hEntity )
13721378

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

1375-
fseek( psDBF->fp, nRecordOffset, 0 );
1376-
fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
1381+
VSIFSeekL( psDBF->fp, nRecordOffset, 0 );
1382+
VSIFReadL( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
13771383

13781384
psDBF->nCurrentRecord = hEntity;
13791385
}

src/plugins/dxf2shp_converter/shapelib-1.2.10/shapefil.h

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,61 @@
116116

117117
#include <stdio.h>
118118

119+
#include "cpl_vsi.h"
120+
119121
#ifdef USE_DBMALLOC
120122
#include <dbmalloc.h>
121123
#endif
122124

125+
#define SHPOpen qgis_SHPOpen
126+
#define SHPCreate qgis_SHPCreate
127+
#define SHPGetInfo qgis_SHPGetInfo
128+
#define SHPReadObject qgis_SHPReadObject
129+
#define SHPWriteObject qgis_SHPWriteObject
130+
#define SHPDestroyObject qgis_SHPDestroyObject
131+
#define SHPComputeExtents qgis_SHPComputeExtents
132+
#define SHPCreateObject qgis_SHPCreateObject
133+
#define SHPCreateSimpleObject qgis_SHPCreateSimpleObject
134+
#define SHPRewindObject qgis_SHPRewindObject
135+
#define SHPClose qgis_SHPClose
136+
#define SHPTypeName qgis_SHPTypeName
137+
#define SHPPartTypeName qgis_SHPPartTypeName
138+
#define SHPCreateTree qgis_SHPCreateTree
139+
#define SHPDestroyTree qgis_SHPDestroyTree
140+
#define SHPWriteTree qgis_SHPWriteTree
141+
#define SHPReadTree qgis_SHPReadTree
142+
#define SHPTreeAddObject qgis_SHPTreeAddObject
143+
#define SHPTreeAddShapeId qgis_SHPTreeAddShapeId
144+
#define SHPTreeRemoveShapeId qgis_SHPTreeRemoveShapeId
145+
#define SHPTreeTrimExtraNodes qgis_SHPTreeTrimExtraNodes
146+
#define SHPTreeFindLikelyShapes qgis_SHPTreeFindLikelyShapes
147+
#define SHPCheckBoundsOverlap qgis_SHPCheckBoundsOverlap
148+
#define DBFOpen qgis_DBFOpen
149+
#define DBFCreate qgis_DBFCreate
150+
#define DBFGetFieldCount qgis_DBFGetFieldCount
151+
#define DBFGetRecordCount qgis_DBFGetRecordCount
152+
#define DBFAddField qgis_DBFAddField
153+
#define DBFFieldType qgis_DBFFieldType
154+
#define DBFGetFieldInfo qgis_DBFGetFieldInfo
155+
#define DBFGetFieldIndex qgis_DBFGetFieldIndex
156+
#define DBFReadIntegerAttribute qgis_DBFReadIntegerAttribute
157+
#define DBFReadDoubleAttribute qgis_DBFReadDoubleAttribute
158+
#define DBFReadStringAttribute qgis_DBFReadStringAttribute
159+
#define DBFReadLogicalAttribute qgis_DBFReadLogicalAttribute
160+
#define DBFIsAttributeNULL qgis_DBFIsAttributeNULL
161+
#define DBFWriteIntegerAttribute qgis_DBFWriteIntegerAttribute
162+
#define DBFWriteDoubleAttribute qgis_DBFWriteDoubleAttribute
163+
#define DBFWriteStringAttribute qgis_DBFWriteStringAttribute
164+
#define DBFWriteNULLAttribute qgis_DBFWriteNULLAttribute
165+
#define DBFWriteLogicalAttribute qgis_DBFWriteLogicalAttribute
166+
#define DBFWriteAttributeDirectly qgis_DBFWriteAttributeDirectly
167+
#define DBFReadTuple qgis_DBFReadTuple
168+
#define DBFWriteTuple qgis_DBFWriteTuple
169+
#define DBFCloneEmpty qgis_DBFCloneEmpty
170+
#define DBFClose qgis_DBFClose
171+
#define DBFGetNativeFieldType qgis_DBFGetNativeFieldType
172+
173+
123174
#ifdef __cplusplus
124175
extern "C"
125176
{
@@ -189,8 +240,8 @@ extern "C"
189240
/************************************************************************/
190241
typedef struct
191242
{
192-
FILE *fpSHP;
193-
FILE *fpSHX;
243+
VSILFILE *fpSHP;
244+
VSILFILE *fpSHX;
194245

195246
int nShapeType; /* SHPT_* */
196247

@@ -382,7 +433,7 @@ extern "C"
382433
/************************************************************************/
383434
typedef struct
384435
{
385-
FILE *fp;
436+
VSILFILE *fp;
386437

387438
int nRecords;
388439

0 commit comments

Comments
 (0)