Skip to content
Permalink
Browse files

Add support for shapefiles with uppercase extension on Linux (#4712)

  • Loading branch information...
rouault committed Jul 17, 2013
1 parent b44f170 commit d72848eebd51ba2bba41b730db3e0dcf69b4b34b
Showing with 30 additions and 6 deletions.
  1. +15 −2 mapshape.c
  2. +4 −0 maptree.c
  3. +11 −4 mapxbase.c
@@ -249,6 +249,10 @@ SHPHandle msSHPOpen( const char * pszLayer, const char * pszAccess )
pszFullname = (char *) msSmallMalloc(strlen(pszBasename) + 5);
sprintf( pszFullname, "%s.shp", pszBasename );
psSHP->fpSHP = fopen(pszFullname, pszAccess );
if( psSHP->fpSHP == NULL ) {
sprintf( pszFullname, "%s.SHP", pszBasename );
psSHP->fpSHP = fopen(pszFullname, pszAccess );
}
if( psSHP->fpSHP == NULL ) {
msFree(pszBasename);
msFree(pszFullname);
@@ -258,6 +262,10 @@ SHPHandle msSHPOpen( const char * pszLayer, const char * pszAccess )

sprintf( pszFullname, "%s.shx", pszBasename );
psSHP->fpSHX = fopen(pszFullname, pszAccess );
if( psSHP->fpSHX == NULL ) {
sprintf( pszFullname, "%s.SHX", pszBasename );
psSHP->fpSHX = fopen(pszFullname, pszAccess );
}
if( psSHP->fpSHX == NULL ) {
msFree(pszBasename);
msFree(pszFullname);
@@ -1753,9 +1761,14 @@ int msShapefileWhichShapes(shapefileObj *shpfile, rectObj rect, int debug)

/* deal with case where sourcename is of the form 'file.shp' */
sourcename = msStrdup(shpfile->source);
/* TODO: need to add case-insensitive handling! */
s = strstr(sourcename, ".shp");
if( s ) *s = '\0';
if( s )
*s = '\0';
else {
s = strstr(sourcename, ".SHP");
if( s )
*s = '\0';
}

filename = (char *)malloc(strlen(sourcename)+strlen(MS_INDEX_EXTENSION)+1);
MS_CHECK_ALLOC(filename, strlen(sourcename)+strlen(MS_INDEX_EXTENSION)+1, MS_FAILURE);
@@ -126,6 +126,10 @@ SHPTreeHandle msSHPDiskTreeOpen(const char * pszTree, int debug)
pszFullname = (char *) msSmallMalloc(strlen(pszBasename) + 5);
sprintf( pszFullname, "%s%s", pszBasename, MS_INDEX_EXTENSION);
psTree->fp = fopen(pszFullname, "rb" );
if( psTree->fp == NULL ) {
sprintf( pszFullname, "%s.QIX", pszBasename);
psTree->fp = fopen(pszFullname, "rb" );
}

msFree(pszBasename); /* don't need these any more */
msFree(pszFullname);
@@ -162,11 +162,11 @@ DBFHandle msDBFOpen( const char * pszFilename, const char * pszAccess )
pszDBFFilename = (char *) msSmallMalloc(strlen(pszFilename)+1);
strcpy( pszDBFFilename, pszFilename );

if( strcmp(pszFilename+strlen(pszFilename)-4,".shp")
|| strcmp(pszFilename+strlen(pszFilename)-4,".shx") ) {
if( strcmp(pszFilename+strlen(pszFilename)-4,".shp") == 0
|| strcmp(pszFilename+strlen(pszFilename)-4,".shx") == 0 ) {
strcpy( pszDBFFilename+strlen(pszDBFFilename)-4, ".dbf");
} else if( strcmp(pszFilename+strlen(pszFilename)-4,".SHP")
|| strcmp(pszFilename+strlen(pszFilename)-4,".SHX") ) {
} else if( strcmp(pszFilename+strlen(pszFilename)-4,".SHP") == 0
|| strcmp(pszFilename+strlen(pszFilename)-4,".SHX") == 0 ) {
strcpy( pszDBFFilename+strlen(pszDBFFilename)-4, ".DBF");
}

@@ -176,6 +176,13 @@ DBFHandle msDBFOpen( const char * pszFilename, const char * pszAccess )
psDBF = (DBFHandle) calloc( 1, sizeof(DBFInfo) );
MS_CHECK_ALLOC(psDBF, sizeof(DBFInfo), NULL);
psDBF->fp = fopen( pszDBFFilename, pszAccess );
if( psDBF->fp == NULL )
{
if( strcmp(pszDBFFilename+strlen(pszDBFFilename)-4,".dbf") == 0 ) {
strcpy( pszDBFFilename+strlen(pszDBFFilename)-4, ".DBF");
psDBF->fp = fopen( pszDBFFilename, pszAccess );
}
}
if( psDBF->fp == NULL )
return( NULL );

0 comments on commit d72848e

Please sign in to comment.
You can’t perform that action at this time.