Skip to content

Commit

Permalink
Add support for shapefiles with uppercase extension on Linux (#4712)
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jul 17, 2013
1 parent b44f170 commit d72848e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
17 changes: 15 additions & 2 deletions mapshape.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions maptree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 11 additions & 4 deletions mapxbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand All @@ -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 );

Expand Down

0 comments on commit d72848e

Please sign in to comment.