849 char *pszBasename = NULL, *pszFullname = NULL;
851 SAFile fpSHP = NULL, fpSHX = NULL;
852 uchar abyHeader[100];
860 if( *((
uchar *) &i) == 1 )
869 pszBasename = (
char *)
malloc(strlen(pszLayer)+5);
870 strcpy( pszBasename, pszLayer );
871 for( i = strlen(pszBasename)-1;
872 i > 0 && pszBasename[i] !=
'.' && pszBasename[i] !=
'/'
873 && pszBasename[i] !=
'\\';
876 if( pszBasename[i] ==
'.' )
877 pszBasename[i] =
'\0';
882 pszFullname = (
char *)
malloc(strlen(pszBasename) + 5);
883 sprintf( pszFullname,
"%s.shp", pszBasename );
884 fpSHP = psHooks->
FOpen(pszFullname,
"wb" );
887 psHooks->
Error(
"Failed to create file .shp file." );
891 sprintf( pszFullname,
"%s.shx", pszBasename );
892 fpSHX = psHooks->
FOpen(pszFullname,
"wb" );
895 psHooks->
Error(
"Failed to create file .shx file." );
899 free( pszFullname ); pszFullname = NULL;
900 free( pszBasename ); pszBasename = NULL;
905 for( i = 0; i < 100; i++ )
924 ByteCopy( &dValue, abyHeader+36, 8 );
925 ByteCopy( &dValue, abyHeader+44, 8 );
926 ByteCopy( &dValue, abyHeader+52, 8 );
927 ByteCopy( &dValue, abyHeader+60, 8 );
932 if( psHooks->
FWrite( abyHeader, 100, 1, fpSHP ) != 1 )
934 psHooks->
Error(
"Failed to write .shp header." );
945 if( psHooks->
FWrite( abyHeader, 100, 1, fpSHX ) != 1 )
947 psHooks->
Error(
"Failed to write .shx header." );
957 return(
SHPOpenLL( pszLayer,
"r+b", psHooks ) );
960 if (pszFullname)
free(pszFullname);
961 if (pszBasename)
free(pszBasename);
962 if (fpSHP) psHooks->
FClose( fpSHP );
963 if (fpSHX) psHooks->
FClose( fpSHX );
SHPHandle SHPAPI_CALL SHPOpenLL(const char *pszLayer, const char *pszAccess, SAHooks *psHooks)
static void SwapWord(int length, void *wordP)
#define ByteCopy(a, b, c)
void(* Error)(const char *message)
SAFile(* FOpen)(const char *filename, const char *access)
SAOffset(* FWrite)(void *p, SAOffset size, SAOffset nmemb, SAFile file)
int(* FClose)(SAFile file)