[GRASS-SVN] r32582 - grass/trunk/lib/external/shapelib

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Aug 6 15:37:35 EDT 2008


Author: neteler
Date: 2008-08-06 15:37:34 -0400 (Wed, 06 Aug 2008)
New Revision: 32582

Modified:
   grass/trunk/lib/external/shapelib/dbfopen.c
   grass/trunk/lib/external/shapelib/safileio.c
   grass/trunk/lib/external/shapelib/shapefil.h
   grass/trunk/lib/external/shapelib/shpopen.c
Log:
reverted indentation of external library

Modified: grass/trunk/lib/external/shapelib/dbfopen.c
===================================================================
--- grass/trunk/lib/external/shapelib/dbfopen.c	2008-08-06 19:30:45 UTC (rev 32581)
+++ grass/trunk/lib/external/shapelib/dbfopen.c	2008-08-06 19:37:34 UTC (rev 32582)
@@ -1,4 +1,3 @@
-
 /******************************************************************************
  * $Id$
  *
@@ -113,24 +112,26 @@
 #include <string.h>
 
 SHP_CVSID("$Id$")
+
 #ifndef FALSE
 #  define FALSE		0
 #  define TRUE		1
 #endif
 
 /************************************************************************/
-    /*                             SfRealloc()                              */
-    /*                                                                      */
-    /*      A realloc cover function that will access a NULL pointer as     */
-    /*      a valid input.                                                  */
+/*                             SfRealloc()                              */
+/*                                                                      */
+/*      A realloc cover function that will access a NULL pointer as     */
+/*      a valid input.                                                  */
+/************************************************************************/
 
-/************************************************************************/
-     static void *SfRealloc(void *pMem, int nNewSize)
+static void * SfRealloc( void * pMem, int nNewSize )
+
 {
-    if (pMem == NULL)
-	return ((void *)malloc(nNewSize));
+    if( pMem == NULL )
+        return( (void *) malloc(nNewSize) );
     else
-	return ((void *)realloc(pMem, nNewSize));
+        return( (void *) realloc(pMem,nNewSize) );
 }
 
 /************************************************************************/
@@ -140,57 +141,58 @@
 /*      descriptions before writing any actual data records.  This      */
 /*      also computes all the DBFDataSet field offset/size/decimals     */
 /*      and so forth values.                                            */
-
 /************************************************************************/
 
 static void DBFWriteHeader(DBFHandle psDBF)
+
 {
-    unsigned char abyHeader[XBASE_FLDHDR_SZ];
-    int i;
+    unsigned char	abyHeader[XBASE_FLDHDR_SZ];
+    int		i;
 
-    if (!psDBF->bNoHeader)
-	return;
+    if( !psDBF->bNoHeader )
+        return;
 
     psDBF->bNoHeader = FALSE;
 
-    /* -------------------------------------------------------------------- */
-    /*      Initialize the file header information.                         */
-    /* -------------------------------------------------------------------- */
-    for (i = 0; i < XBASE_FLDHDR_SZ; i++)
-	abyHeader[i] = 0;
+/* -------------------------------------------------------------------- */
+/*	Initialize the file header information.				*/
+/* -------------------------------------------------------------------- */
+    for( i = 0; i < XBASE_FLDHDR_SZ; i++ )
+        abyHeader[i] = 0;
 
-    abyHeader[0] = 0x03;	/* memo field? - just copying   */
+    abyHeader[0] = 0x03;		/* memo field? - just copying 	*/
 
     /* write out a dummy date */
-    abyHeader[1] = 95;		/* YY */
-    abyHeader[2] = 7;		/* MM */
-    abyHeader[3] = 26;		/* DD */
+    abyHeader[1] = 95;			/* YY */
+    abyHeader[2] = 7;			/* MM */
+    abyHeader[3] = 26;			/* DD */
 
     /* record count preset at zero */
 
-    abyHeader[8] = (unsigned char)(psDBF->nHeaderLength % 256);
-    abyHeader[9] = (unsigned char)(psDBF->nHeaderLength / 256);
+    abyHeader[8] = (unsigned char) (psDBF->nHeaderLength % 256);
+    abyHeader[9] = (unsigned char) (psDBF->nHeaderLength / 256);
+    
+    abyHeader[10] = (unsigned char) (psDBF->nRecordLength % 256);
+    abyHeader[11] = (unsigned char) (psDBF->nRecordLength / 256);
 
-    abyHeader[10] = (unsigned char)(psDBF->nRecordLength % 256);
-    abyHeader[11] = (unsigned char)(psDBF->nRecordLength / 256);
+/* -------------------------------------------------------------------- */
+/*      Write the initial 32 byte file header, and all the field        */
+/*      descriptions.                                     		*/
+/* -------------------------------------------------------------------- */
+    psDBF->sHooks.FSeek( psDBF->fp, 0, 0 );
+    psDBF->sHooks.FWrite( abyHeader, XBASE_FLDHDR_SZ, 1, psDBF->fp );
+    psDBF->sHooks.FWrite( psDBF->pszHeader, XBASE_FLDHDR_SZ, psDBF->nFields, 
+                          psDBF->fp );
 
-    /* -------------------------------------------------------------------- */
-    /*      Write the initial 32 byte file header, and all the field        */
-    /*      descriptions.                                                   */
-    /* -------------------------------------------------------------------- */
-    psDBF->sHooks.FSeek(psDBF->fp, 0, 0);
-    psDBF->sHooks.FWrite(abyHeader, XBASE_FLDHDR_SZ, 1, psDBF->fp);
-    psDBF->sHooks.FWrite(psDBF->pszHeader, XBASE_FLDHDR_SZ, psDBF->nFields,
-			 psDBF->fp);
+/* -------------------------------------------------------------------- */
+/*      Write out the newline character if there is room for it.        */
+/* -------------------------------------------------------------------- */
+    if( psDBF->nHeaderLength > 32*psDBF->nFields + 32 )
+    {
+        char	cNewline;
 
-    /* -------------------------------------------------------------------- */
-    /*      Write out the newline character if there is room for it.        */
-    /* -------------------------------------------------------------------- */
-    if (psDBF->nHeaderLength > 32 * psDBF->nFields + 32) {
-	char cNewline;
-
-	cNewline = 0x0d;
-	psDBF->sHooks.FWrite(&cNewline, 1, 1, psDBF->fp);
+        cNewline = 0x0d;
+        psDBF->sHooks.FWrite( &cNewline, 1, 1, psDBF->fp );
     }
 }
 
@@ -198,33 +200,36 @@
 /*                           DBFFlushRecord()                           */
 /*                                                                      */
 /*      Write out the current record if there is one.                   */
-
 /************************************************************************/
 
-static int DBFFlushRecord(DBFHandle psDBF)
+static int DBFFlushRecord( DBFHandle psDBF )
+
 {
-    SAOffset nRecordOffset;
+    SAOffset	nRecordOffset;
 
-    if (psDBF->bCurrentRecordModified && psDBF->nCurrentRecord > -1) {
+    if( psDBF->bCurrentRecordModified && psDBF->nCurrentRecord > -1 )
+    {
 	psDBF->bCurrentRecordModified = FALSE;
 
-	nRecordOffset =
-	    psDBF->nRecordLength * (SAOffset) psDBF->nCurrentRecord
-	    + psDBF->nHeaderLength;
+	nRecordOffset = 
+            psDBF->nRecordLength * (SAOffset) psDBF->nCurrentRecord 
+            + psDBF->nHeaderLength;
 
-	if (psDBF->sHooks.FSeek(psDBF->fp, nRecordOffset, 0) != 0
-	    || psDBF->sHooks.FWrite(psDBF->pszCurrentRecord,
-				    psDBF->nRecordLength,
-				    1, psDBF->fp) != 1) {
+	if( psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, 0 ) != 0 
+            || psDBF->sHooks.FWrite( psDBF->pszCurrentRecord, 
+                                     psDBF->nRecordLength, 
+                                     1, psDBF->fp ) != 1 )
+        {
 #ifdef USE_CPL
-	    CPLError(CE_Failure, CPLE_FileIO,
-		     "Failure writing DBF record %d.", psDBF->nCurrentRecord);
-#else
-	    fprintf(stderr, "Failure writing DBF record %d.",
-		    psDBF->nCurrentRecord);
+            CPLError( CE_Failure, CPLE_FileIO, 
+                      "Failure writing DBF record %d.", 
+                      psDBF->nCurrentRecord );
+#else           
+            fprintf( stderr, "Failure writing DBF record %d.", 
+                     psDBF->nCurrentRecord );
 #endif
-	    return FALSE;
-	}
+            return FALSE;
+        }
     }
 
     return TRUE;
@@ -232,42 +237,47 @@
 
 /************************************************************************/
 /*                           DBFLoadRecord()                            */
-
 /************************************************************************/
 
-static int DBFLoadRecord(DBFHandle psDBF, int iRecord)
+static int DBFLoadRecord( DBFHandle psDBF, int iRecord )
+
 {
-    if (psDBF->nCurrentRecord != iRecord) {
-	SAOffset nRecordOffset;
+    if( psDBF->nCurrentRecord != iRecord )
+    {
+        SAOffset nRecordOffset;
 
-	if (!DBFFlushRecord(psDBF))
-	    return FALSE;
+	if( !DBFFlushRecord( psDBF ) )
+            return FALSE;
 
-	nRecordOffset =
-	    psDBF->nRecordLength * (SAOffset) iRecord + psDBF->nHeaderLength;
+	nRecordOffset = 
+            psDBF->nRecordLength * (SAOffset) iRecord + psDBF->nHeaderLength;
 
-	if (psDBF->sHooks.FSeek(psDBF->fp, nRecordOffset, SEEK_SET) != 0) {
+	if( psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, SEEK_SET ) != 0 )
+        {
 #ifdef USE_CPL
-	    CPLError(CE_Failure, CPLE_FileIO,
-		     "fseek(%ld) failed on DBF file.\n", (long)nRecordOffset);
+            CPLError( CE_Failure, CPLE_FileIO,
+                      "fseek(%ld) failed on DBF file.\n",
+                      (long) nRecordOffset );
 #else
-	    fprintf(stderr, "fseek(%ld) failed on DBF file.\n",
-		    (long)nRecordOffset);
+            fprintf( stderr, "fseek(%ld) failed on DBF file.\n",
+                     (long) nRecordOffset );
 #endif
-	    return FALSE;
-	}
+            return FALSE;
+        }
 
-	if (psDBF->sHooks.FRead(psDBF->pszCurrentRecord,
-				psDBF->nRecordLength, 1, psDBF->fp) != 1) {
+	if( psDBF->sHooks.FRead( psDBF->pszCurrentRecord, 
+                                 psDBF->nRecordLength, 1, psDBF->fp ) != 1 )
+        {
 #ifdef USE_CPL
-	    CPLError(CE_Failure, CPLE_FileIO,
-		     "fread(%d) failed on DBF file.\n", psDBF->nRecordLength);
+            CPLError( CE_Failure, CPLE_FileIO, 
+                      "fread(%d) failed on DBF file.\n",
+                      psDBF->nRecordLength );
 #else
-	    fprintf(stderr, "fread(%d) failed on DBF file.\n",
-		    psDBF->nRecordLength);
+            fprintf( stderr, "fread(%d) failed on DBF file.\n",
+                     psDBF->nRecordLength );
 #endif
-	    return FALSE;
-	}
+            return FALSE;
+        }
 
 	psDBF->nCurrentRecord = iRecord;
     }
@@ -277,314 +287,323 @@
 
 /************************************************************************/
 /*                          DBFUpdateHeader()                           */
-
 /************************************************************************/
 
-void SHPAPI_CALL DBFUpdateHeader(DBFHandle psDBF)
+void SHPAPI_CALL
+DBFUpdateHeader( DBFHandle psDBF )
+
 {
-    unsigned char abyFileHeader[32];
+    unsigned char		abyFileHeader[32];
 
-    if (psDBF->bNoHeader)
-	DBFWriteHeader(psDBF);
+    if( psDBF->bNoHeader )
+        DBFWriteHeader( psDBF );
 
-    DBFFlushRecord(psDBF);
+    DBFFlushRecord( psDBF );
 
-    psDBF->sHooks.FSeek(psDBF->fp, 0, 0);
-    psDBF->sHooks.FRead(abyFileHeader, 32, 1, psDBF->fp);
+    psDBF->sHooks.FSeek( psDBF->fp, 0, 0 );
+    psDBF->sHooks.FRead( abyFileHeader, 32, 1, psDBF->fp );
+    
+    abyFileHeader[4] = (unsigned char) (psDBF->nRecords % 256);
+    abyFileHeader[5] = (unsigned char) ((psDBF->nRecords/256) % 256);
+    abyFileHeader[6] = (unsigned char) ((psDBF->nRecords/(256*256)) % 256);
+    abyFileHeader[7] = (unsigned char) ((psDBF->nRecords/(256*256*256)) % 256);
+    
+    psDBF->sHooks.FSeek( psDBF->fp, 0, 0 );
+    psDBF->sHooks.FWrite( abyFileHeader, 32, 1, psDBF->fp );
 
-    abyFileHeader[4] = (unsigned char)(psDBF->nRecords % 256);
-    abyFileHeader[5] = (unsigned char)((psDBF->nRecords / 256) % 256);
-    abyFileHeader[6] = (unsigned char)((psDBF->nRecords / (256 * 256)) % 256);
-    abyFileHeader[7] =
-	(unsigned char)((psDBF->nRecords / (256 * 256 * 256)) % 256);
-
-    psDBF->sHooks.FSeek(psDBF->fp, 0, 0);
-    psDBF->sHooks.FWrite(abyFileHeader, 32, 1, psDBF->fp);
-
-    psDBF->sHooks.FFlush(psDBF->fp);
+    psDBF->sHooks.FFlush( psDBF->fp );
 }
 
 /************************************************************************/
 /*                              DBFOpen()                               */
 /*                                                                      */
 /*      Open a .dbf file.                                               */
-
 /************************************************************************/
+   
+DBFHandle SHPAPI_CALL
+DBFOpen( const char * pszFilename, const char * pszAccess )
 
-DBFHandle SHPAPI_CALL DBFOpen(const char *pszFilename, const char *pszAccess)
 {
     SAHooks sHooks;
 
-    SASetupDefaultHooks(&sHooks);
+    SASetupDefaultHooks( &sHooks );
 
-    return DBFOpenLL(pszFilename, pszAccess, &sHooks);
+    return DBFOpenLL( pszFilename, pszAccess, &sHooks );
 }
 
 /************************************************************************/
 /*                              DBFOpen()                               */
 /*                                                                      */
 /*      Open a .dbf file.                                               */
-
 /************************************************************************/
+   
+DBFHandle SHPAPI_CALL
+DBFOpenLL( const char * pszFilename, const char * pszAccess, SAHooks *psHooks )
 
-DBFHandle SHPAPI_CALL
-DBFOpenLL(const char *pszFilename, const char *pszAccess, SAHooks * psHooks)
 {
-    DBFHandle psDBF;
-    unsigned char *pabyBuf;
-    int nFields, nHeadLen, iField, i;
-    char *pszBasename, *pszFullname;
+    DBFHandle		psDBF;
+    unsigned char	*pabyBuf;
+    int			nFields, nHeadLen, iField, i;
+    char		*pszBasename, *pszFullname;
 
-    /* -------------------------------------------------------------------- */
-    /*      We only allow the access strings "rb" and "r+".                  */
-    /* -------------------------------------------------------------------- */
-    if (strcmp(pszAccess, "r") != 0 && strcmp(pszAccess, "r+") != 0
-	&& strcmp(pszAccess, "rb") != 0 && strcmp(pszAccess, "rb+") != 0
-	&& strcmp(pszAccess, "r+b") != 0)
-	return (NULL);
+/* -------------------------------------------------------------------- */
+/*      We only allow the access strings "rb" and "r+".                  */
+/* -------------------------------------------------------------------- */
+    if( strcmp(pszAccess,"r") != 0 && strcmp(pszAccess,"r+") != 0 
+        && strcmp(pszAccess,"rb") != 0 && strcmp(pszAccess,"rb+") != 0
+        && strcmp(pszAccess,"r+b") != 0 )
+        return( NULL );
 
-    if (strcmp(pszAccess, "r") == 0)
-	pszAccess = "rb";
+    if( strcmp(pszAccess,"r") == 0 )
+        pszAccess = "rb";
+ 
+    if( strcmp(pszAccess,"r+") == 0 )
+        pszAccess = "rb+";
 
-    if (strcmp(pszAccess, "r+") == 0)
-	pszAccess = "rb+";
-
-    /* -------------------------------------------------------------------- */
-    /*      Compute the base (layer) name.  If there is any extension       */
-    /*      on the passed in filename we will strip it off.                 */
-    /* -------------------------------------------------------------------- */
-    pszBasename = (char *)malloc(strlen(pszFilename) + 5);
-    strcpy(pszBasename, pszFilename);
-    for (i = strlen(pszBasename) - 1;
+/* -------------------------------------------------------------------- */
+/*	Compute the base (layer) name.  If there is any extension	*/
+/*	on the passed in filename we will strip it off.			*/
+/* -------------------------------------------------------------------- */
+    pszBasename = (char *) malloc(strlen(pszFilename)+5);
+    strcpy( pszBasename, pszFilename );
+    for( i = strlen(pszBasename)-1; 
 	 i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/'
-	 && pszBasename[i] != '\\'; i--) {
-    }
+	       && pszBasename[i] != '\\';
+	 i-- ) {}
 
-    if (pszBasename[i] == '.')
-	pszBasename[i] = '\0';
+    if( pszBasename[i] == '.' )
+        pszBasename[i] = '\0';
 
-    pszFullname = (char *)malloc(strlen(pszBasename) + 5);
-    sprintf(pszFullname, "%s.dbf", pszBasename);
+    pszFullname = (char *) malloc(strlen(pszBasename) + 5);
+    sprintf( pszFullname, "%s.dbf", pszBasename );
+        
+    psDBF = (DBFHandle) calloc( 1, sizeof(DBFInfo) );
+    psDBF->fp = psHooks->FOpen( pszFullname, pszAccess );
+    memcpy( &(psDBF->sHooks), psHooks, sizeof(SAHooks) );
 
-    psDBF = (DBFHandle) calloc(1, sizeof(DBFInfo));
-    psDBF->fp = psHooks->FOpen(pszFullname, pszAccess);
-    memcpy(&(psDBF->sHooks), psHooks, sizeof(SAHooks));
-
-    if (psDBF->fp == NULL) {
-	sprintf(pszFullname, "%s.DBF", pszBasename);
-	psDBF->fp = psDBF->sHooks.FOpen(pszFullname, pszAccess);
+    if( psDBF->fp == NULL )
+    {
+        sprintf( pszFullname, "%s.DBF", pszBasename );
+        psDBF->fp = psDBF->sHooks.FOpen(pszFullname, pszAccess );
     }
-
-    free(pszBasename);
-    free(pszFullname);
-
-    if (psDBF->fp == NULL) {
-	free(psDBF);
-	return (NULL);
+    
+    free( pszBasename );
+    free( pszFullname );
+    
+    if( psDBF->fp == NULL )
+    {
+        free( psDBF );
+        return( NULL );
     }
 
     psDBF->bNoHeader = FALSE;
     psDBF->nCurrentRecord = -1;
     psDBF->bCurrentRecordModified = FALSE;
 
-    /* -------------------------------------------------------------------- */
-    /*  Read Table Header info                                              */
-    /* -------------------------------------------------------------------- */
-    pabyBuf = (unsigned char *)malloc(500);
-    if (psDBF->sHooks.FRead(pabyBuf, 32, 1, psDBF->fp) != 1) {
-	psDBF->sHooks.FClose(psDBF->fp);
-	free(pabyBuf);
-	free(psDBF);
-	return NULL;
+/* -------------------------------------------------------------------- */
+/*  Read Table Header info                                              */
+/* -------------------------------------------------------------------- */
+    pabyBuf = (unsigned char *) malloc(500);
+    if( psDBF->sHooks.FRead( pabyBuf, 32, 1, psDBF->fp ) != 1 )
+    {
+        psDBF->sHooks.FClose( psDBF->fp );
+        free( pabyBuf );
+        free( psDBF );
+        return NULL;
     }
 
-    psDBF->nRecords =
-	pabyBuf[4] + pabyBuf[5] * 256 + pabyBuf[6] * 256 * 256 +
-	pabyBuf[7] * 256 * 256 * 256;
+    psDBF->nRecords = 
+     pabyBuf[4] + pabyBuf[5]*256 + pabyBuf[6]*256*256 + pabyBuf[7]*256*256*256;
 
-    psDBF->nHeaderLength = nHeadLen = pabyBuf[8] + pabyBuf[9] * 256;
-    psDBF->nRecordLength = pabyBuf[10] + pabyBuf[11] * 256;
-
+    psDBF->nHeaderLength = nHeadLen = pabyBuf[8] + pabyBuf[9]*256;
+    psDBF->nRecordLength = pabyBuf[10] + pabyBuf[11]*256;
+    
     psDBF->nFields = nFields = (nHeadLen - 32) / 32;
 
-    psDBF->pszCurrentRecord = (char *)malloc(psDBF->nRecordLength);
+    psDBF->pszCurrentRecord = (char *) malloc(psDBF->nRecordLength);
 
-    /* -------------------------------------------------------------------- */
-    /*  Read in Field Definitions                                           */
-    /* -------------------------------------------------------------------- */
+/* -------------------------------------------------------------------- */
+/*  Read in Field Definitions                                           */
+/* -------------------------------------------------------------------- */
+    
+    pabyBuf = (unsigned char *) SfRealloc(pabyBuf,nHeadLen);
+    psDBF->pszHeader = (char *) pabyBuf;
 
-    pabyBuf = (unsigned char *)SfRealloc(pabyBuf, nHeadLen);
-    psDBF->pszHeader = (char *)pabyBuf;
-
-    psDBF->sHooks.FSeek(psDBF->fp, 32, 0);
-    if (psDBF->sHooks.FRead(pabyBuf, nHeadLen - 32, 1, psDBF->fp) != 1) {
-	psDBF->sHooks.FClose(psDBF->fp);
-	free(pabyBuf);
-	free(psDBF->pszCurrentRecord);
-	free(psDBF);
-	return NULL;
+    psDBF->sHooks.FSeek( psDBF->fp, 32, 0 );
+    if( psDBF->sHooks.FRead( pabyBuf, nHeadLen-32, 1, psDBF->fp ) != 1 )
+    {
+        psDBF->sHooks.FClose( psDBF->fp );
+        free( pabyBuf );
+        free( psDBF->pszCurrentRecord );
+        free( psDBF );
+        return NULL;
     }
 
-    psDBF->panFieldOffset = (int *)malloc(sizeof(int) * nFields);
-    psDBF->panFieldSize = (int *)malloc(sizeof(int) * nFields);
-    psDBF->panFieldDecimals = (int *)malloc(sizeof(int) * nFields);
-    psDBF->pachFieldType = (char *)malloc(sizeof(char) * nFields);
+    psDBF->panFieldOffset = (int *) malloc(sizeof(int) * nFields);
+    psDBF->panFieldSize = (int *) malloc(sizeof(int) * nFields);
+    psDBF->panFieldDecimals = (int *) malloc(sizeof(int) * nFields);
+    psDBF->pachFieldType = (char *) malloc(sizeof(char) * nFields);
 
-    for (iField = 0; iField < nFields; iField++) {
-	unsigned char *pabyFInfo;
+    for( iField = 0; iField < nFields; iField++ )
+    {
+	unsigned char		*pabyFInfo;
 
-	pabyFInfo = pabyBuf + iField * 32;
+	pabyFInfo = pabyBuf+iField*32;
 
-	if (pabyFInfo[11] == 'N' || pabyFInfo[11] == 'F') {
+	if( pabyFInfo[11] == 'N' || pabyFInfo[11] == 'F' )
+	{
 	    psDBF->panFieldSize[iField] = pabyFInfo[16];
 	    psDBF->panFieldDecimals[iField] = pabyFInfo[17];
 	}
-	else {
+	else
+	{
 	    psDBF->panFieldSize[iField] = pabyFInfo[16];
 	    psDBF->panFieldDecimals[iField] = 0;
 
-	    /*
-	     ** The following seemed to be used sometimes to handle files with long
-	     ** string fields, but in other cases (such as bug 1202) the decimals field
-	     ** just seems to indicate some sort of preferred formatting, not very
-	     ** wide fields.  So I have disabled this code.  FrankW.
-	     psDBF->panFieldSize[iField] = pabyFInfo[16] + pabyFInfo[17]*256;
-	     psDBF->panFieldDecimals[iField] = 0;
-	     */
+/*
+** The following seemed to be used sometimes to handle files with long
+** string fields, but in other cases (such as bug 1202) the decimals field
+** just seems to indicate some sort of preferred formatting, not very
+** wide fields.  So I have disabled this code.  FrankW.
+	    psDBF->panFieldSize[iField] = pabyFInfo[16] + pabyFInfo[17]*256;
+	    psDBF->panFieldDecimals[iField] = 0;
+*/
 	}
 
-	psDBF->pachFieldType[iField] = (char)pabyFInfo[11];
-	if (iField == 0)
+	psDBF->pachFieldType[iField] = (char) pabyFInfo[11];
+	if( iField == 0 )
 	    psDBF->panFieldOffset[iField] = 1;
 	else
-	    psDBF->panFieldOffset[iField] =
-		psDBF->panFieldOffset[iField - 1] +
-		psDBF->panFieldSize[iField - 1];
+	    psDBF->panFieldOffset[iField] = 
+	      psDBF->panFieldOffset[iField-1] + psDBF->panFieldSize[iField-1];
     }
 
-    return (psDBF);
+    return( psDBF );
 }
 
 /************************************************************************/
 /*                              DBFClose()                              */
-
 /************************************************************************/
 
-void SHPAPI_CALL DBFClose(DBFHandle psDBF)
+void SHPAPI_CALL
+DBFClose(DBFHandle psDBF)
 {
-    /* -------------------------------------------------------------------- */
-    /*      Write out header if not already written.                        */
-    /* -------------------------------------------------------------------- */
-    if (psDBF->bNoHeader)
-	DBFWriteHeader(psDBF);
+/* -------------------------------------------------------------------- */
+/*      Write out header if not already written.                        */
+/* -------------------------------------------------------------------- */
+    if( psDBF->bNoHeader )
+        DBFWriteHeader( psDBF );
 
-    DBFFlushRecord(psDBF);
+    DBFFlushRecord( psDBF );
 
-    /* -------------------------------------------------------------------- */
-    /*      Update last access date, and number of records if we have       */
-    /*      write access.                                                   */
-    /* -------------------------------------------------------------------- */
-    if (psDBF->bUpdated)
-	DBFUpdateHeader(psDBF);
+/* -------------------------------------------------------------------- */
+/*      Update last access date, and number of records if we have	*/
+/*	write access.                					*/
+/* -------------------------------------------------------------------- */
+    if( psDBF->bUpdated )
+        DBFUpdateHeader( psDBF );
 
-    /* -------------------------------------------------------------------- */
-    /*      Close, and free resources.                                      */
-    /* -------------------------------------------------------------------- */
-    psDBF->sHooks.FClose(psDBF->fp);
+/* -------------------------------------------------------------------- */
+/*      Close, and free resources.                                      */
+/* -------------------------------------------------------------------- */
+    psDBF->sHooks.FClose( psDBF->fp );
 
-    if (psDBF->panFieldOffset != NULL) {
-	free(psDBF->panFieldOffset);
-	free(psDBF->panFieldSize);
-	free(psDBF->panFieldDecimals);
-	free(psDBF->pachFieldType);
+    if( psDBF->panFieldOffset != NULL )
+    {
+        free( psDBF->panFieldOffset );
+        free( psDBF->panFieldSize );
+        free( psDBF->panFieldDecimals );
+        free( psDBF->pachFieldType );
     }
 
-    if (psDBF->pszWorkField != NULL)
-	free(psDBF->pszWorkField);
+    if( psDBF->pszWorkField != NULL )
+        free( psDBF->pszWorkField );
 
-    free(psDBF->pszHeader);
-    free(psDBF->pszCurrentRecord);
+    free( psDBF->pszHeader );
+    free( psDBF->pszCurrentRecord );
 
-    free(psDBF);
+    free( psDBF );
 }
 
 /************************************************************************/
 /*                             DBFCreate()                              */
 /*                                                                      */
 /*      Create a new .dbf file.                                         */
-
 /************************************************************************/
 
-DBFHandle SHPAPI_CALL DBFCreate(const char *pszFilename)
+DBFHandle SHPAPI_CALL
+DBFCreate( const char * pszFilename )
+
 {
     SAHooks sHooks;
 
-    SASetupDefaultHooks(&sHooks);
+    SASetupDefaultHooks( &sHooks );
 
-    return DBFCreateLL(pszFilename, &sHooks);
+    return DBFCreateLL( pszFilename, &sHooks );
 }
 
 /************************************************************************/
 /*                             DBFCreate()                              */
 /*                                                                      */
 /*      Create a new .dbf file.                                         */
-
 /************************************************************************/
 
-DBFHandle SHPAPI_CALL DBFCreateLL(const char *pszFilename, SAHooks * psHooks)
+DBFHandle SHPAPI_CALL
+DBFCreateLL( const char * pszFilename, SAHooks *psHooks )
+
 {
-    DBFHandle psDBF;
-    SAFile fp;
-    char *pszFullname, *pszBasename;
-    int i;
+    DBFHandle	psDBF;
+    SAFile	fp;
+    char	*pszFullname, *pszBasename;
+    int		i;
     char chZero = '\0';
 
-    /* -------------------------------------------------------------------- */
-    /*      Compute the base (layer) name.  If there is any extension       */
-    /*      on the passed in filename we will strip it off.                 */
-    /* -------------------------------------------------------------------- */
-    pszBasename = (char *)malloc(strlen(pszFilename) + 5);
-    strcpy(pszBasename, pszFilename);
-    for (i = strlen(pszBasename) - 1;
+/* -------------------------------------------------------------------- */
+/*	Compute the base (layer) name.  If there is any extension	*/
+/*	on the passed in filename we will strip it off.			*/
+/* -------------------------------------------------------------------- */
+    pszBasename = (char *) malloc(strlen(pszFilename)+5);
+    strcpy( pszBasename, pszFilename );
+    for( i = strlen(pszBasename)-1; 
 	 i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/'
-	 && pszBasename[i] != '\\'; i--) {
-    }
+	       && pszBasename[i] != '\\';
+	 i-- ) {}
 
-    if (pszBasename[i] == '.')
-	pszBasename[i] = '\0';
+    if( pszBasename[i] == '.' )
+        pszBasename[i] = '\0';
 
-    pszFullname = (char *)malloc(strlen(pszBasename) + 5);
-    sprintf(pszFullname, "%s.dbf", pszBasename);
-    free(pszBasename);
+    pszFullname = (char *) malloc(strlen(pszBasename) + 5);
+    sprintf( pszFullname, "%s.dbf", pszBasename );
+    free( pszBasename );
 
-    /* -------------------------------------------------------------------- */
-    /*      Create the file.                                                */
-    /* -------------------------------------------------------------------- */
-    fp = psHooks->FOpen(pszFullname, "wb");
-    if (fp == NULL)
-	return (NULL);
+/* -------------------------------------------------------------------- */
+/*      Create the file.                                                */
+/* -------------------------------------------------------------------- */
+    fp = psHooks->FOpen( pszFullname, "wb" );
+    if( fp == NULL )
+        return( NULL );
+    
+    psHooks->FWrite( &chZero, 1, 1, fp );
+    psHooks->FClose( fp );
 
-    psHooks->FWrite(&chZero, 1, 1, fp);
-    psHooks->FClose(fp);
+    fp = psHooks->FOpen( pszFullname, "rb+" );
+    if( fp == NULL )
+        return( NULL );
 
-    fp = psHooks->FOpen(pszFullname, "rb+");
-    if (fp == NULL)
-	return (NULL);
+    free( pszFullname );
 
-    free(pszFullname);
+/* -------------------------------------------------------------------- */
+/*	Create the info structure.					*/
+/* -------------------------------------------------------------------- */
+    psDBF = (DBFHandle) calloc(1,sizeof(DBFInfo));
 
-    /* -------------------------------------------------------------------- */
-    /*      Create the info structure.                                      */
-    /* -------------------------------------------------------------------- */
-    psDBF = (DBFHandle) calloc(1, sizeof(DBFInfo));
-
-    memcpy(&(psDBF->sHooks), psHooks, sizeof(SAHooks));
+    memcpy( &(psDBF->sHooks), psHooks, sizeof(SAHooks) );
     psDBF->fp = fp;
     psDBF->nRecords = 0;
     psDBF->nFields = 0;
     psDBF->nRecordLength = 1;
     psDBF->nHeaderLength = 33;
-
+    
     psDBF->panFieldOffset = NULL;
     psDBF->panFieldSize = NULL;
     psDBF->panFieldDecimals = NULL;
@@ -597,7 +616,7 @@
 
     psDBF->bNoHeader = TRUE;
 
-    return (psDBF);
+    return( psDBF );
 }
 
 /************************************************************************/
@@ -605,24 +624,24 @@
 /*                                                                      */
 /*      Add a field to a newly created .dbf file before any records     */
 /*      are written.                                                    */
-
 /************************************************************************/
 
 int SHPAPI_CALL
-DBFAddField(DBFHandle psDBF, const char *pszFieldName,
-	    DBFFieldType eType, int nWidth, int nDecimals)
+DBFAddField(DBFHandle psDBF, const char * pszFieldName, 
+            DBFFieldType eType, int nWidth, int nDecimals )
+
 {
     char chNativeType = 'C';
 
-    if (eType == FTLogical)
-	chNativeType = 'L';
-    else if (eType == FTString)
-	chNativeType = 'C';
+    if( eType == FTLogical )
+        chNativeType = 'L';
+    else if( eType == FTString )
+        chNativeType = 'C';
     else
-	chNativeType = 'N';
+        chNativeType = 'N';
 
-    return DBFAddNativeFieldType(psDBF, pszFieldName, chNativeType,
-				 nWidth, nDecimals);
+    return DBFAddNativeFieldType( psDBF, pszFieldName, chNativeType, 
+                                  nWidth, nDecimals );
 }
 
 /************************************************************************/
@@ -630,245 +649,249 @@
 /*                                                                      */
 /*      Add a field to a newly created .dbf file before any records     */
 /*      are written.                                                    */
-
 /************************************************************************/
 
 int SHPAPI_CALL
-DBFAddNativeFieldType(DBFHandle psDBF, const char *pszFieldName,
-		      char chType, int nWidth, int nDecimals)
+DBFAddNativeFieldType(DBFHandle psDBF, const char * pszFieldName, 
+                      char chType, int nWidth, int nDecimals )
+
 {
-    char *pszFInfo;
-    int i;
+    char	*pszFInfo;
+    int		i;
 
-    /* -------------------------------------------------------------------- */
-    /*      Do some checking to ensure we can add records to this file.     */
-    /* -------------------------------------------------------------------- */
-    if (psDBF->nRecords > 0)
-	return (-1);
+/* -------------------------------------------------------------------- */
+/*      Do some checking to ensure we can add records to this file.     */
+/* -------------------------------------------------------------------- */
+    if( psDBF->nRecords > 0 )
+        return( -1 );
 
-    if (!psDBF->bNoHeader)
-	return (-1);
+    if( !psDBF->bNoHeader )
+        return( -1 );
 
-    if (nWidth < 1)
-	return -1;
+    if( nWidth < 1 )
+        return -1;
 
-    if (nWidth > 255)
-	nWidth = 255;
+    if( nWidth > 255 )
+        nWidth = 255;
 
-    /* -------------------------------------------------------------------- */
-    /*      SfRealloc all the arrays larger to hold the additional field      */
-    /*      information.                                                    */
-    /* -------------------------------------------------------------------- */
+/* -------------------------------------------------------------------- */
+/*      SfRealloc all the arrays larger to hold the additional field      */
+/*      information.                                                    */
+/* -------------------------------------------------------------------- */
     psDBF->nFields++;
 
-    psDBF->panFieldOffset = (int *)
-	SfRealloc(psDBF->panFieldOffset, sizeof(int) * psDBF->nFields);
+    psDBF->panFieldOffset = (int *) 
+        SfRealloc( psDBF->panFieldOffset, sizeof(int) * psDBF->nFields );
 
-    psDBF->panFieldSize = (int *)
-	SfRealloc(psDBF->panFieldSize, sizeof(int) * psDBF->nFields);
+    psDBF->panFieldSize = (int *) 
+        SfRealloc( psDBF->panFieldSize, sizeof(int) * psDBF->nFields );
 
-    psDBF->panFieldDecimals = (int *)
-	SfRealloc(psDBF->panFieldDecimals, sizeof(int) * psDBF->nFields);
+    psDBF->panFieldDecimals = (int *) 
+        SfRealloc( psDBF->panFieldDecimals, sizeof(int) * psDBF->nFields );
 
-    psDBF->pachFieldType = (char *)
-	SfRealloc(psDBF->pachFieldType, sizeof(char) * psDBF->nFields);
+    psDBF->pachFieldType = (char *) 
+        SfRealloc( psDBF->pachFieldType, sizeof(char) * psDBF->nFields );
 
-    /* -------------------------------------------------------------------- */
-    /*      Assign the new field information fields.                        */
-    /* -------------------------------------------------------------------- */
-    psDBF->panFieldOffset[psDBF->nFields - 1] = psDBF->nRecordLength;
+/* -------------------------------------------------------------------- */
+/*      Assign the new field information fields.                        */
+/* -------------------------------------------------------------------- */
+    psDBF->panFieldOffset[psDBF->nFields-1] = psDBF->nRecordLength;
     psDBF->nRecordLength += nWidth;
-    psDBF->panFieldSize[psDBF->nFields - 1] = nWidth;
-    psDBF->panFieldDecimals[psDBF->nFields - 1] = nDecimals;
-    psDBF->pachFieldType[psDBF->nFields - 1] = chType;
+    psDBF->panFieldSize[psDBF->nFields-1] = nWidth;
+    psDBF->panFieldDecimals[psDBF->nFields-1] = nDecimals;
+    psDBF->pachFieldType[psDBF->nFields-1] = chType;
 
-    /* -------------------------------------------------------------------- */
-    /*      Extend the required header information.                         */
-    /* -------------------------------------------------------------------- */
+/* -------------------------------------------------------------------- */
+/*      Extend the required header information.                         */
+/* -------------------------------------------------------------------- */
     psDBF->nHeaderLength += 32;
     psDBF->bUpdated = FALSE;
 
-    psDBF->pszHeader =
-	(char *)SfRealloc(psDBF->pszHeader, psDBF->nFields * 32);
+    psDBF->pszHeader = (char *) SfRealloc(psDBF->pszHeader,psDBF->nFields*32);
 
-    pszFInfo = psDBF->pszHeader + 32 * (psDBF->nFields - 1);
+    pszFInfo = psDBF->pszHeader + 32 * (psDBF->nFields-1);
 
-    for (i = 0; i < 32; i++)
-	pszFInfo[i] = '\0';
+    for( i = 0; i < 32; i++ )
+        pszFInfo[i] = '\0';
 
-    if ((int)strlen(pszFieldName) < 10)
-	strncpy(pszFInfo, pszFieldName, strlen(pszFieldName));
+    if( (int) strlen(pszFieldName) < 10 )
+        strncpy( pszFInfo, pszFieldName, strlen(pszFieldName));
     else
-	strncpy(pszFInfo, pszFieldName, 10);
+        strncpy( pszFInfo, pszFieldName, 10);
 
-    pszFInfo[11] = psDBF->pachFieldType[psDBF->nFields - 1];
+    pszFInfo[11] = psDBF->pachFieldType[psDBF->nFields-1];
 
-    if (chType == 'C') {
-	pszFInfo[16] = (unsigned char)(nWidth % 256);
-	pszFInfo[17] = (unsigned char)(nWidth / 256);
+    if( chType == 'C' )
+    {
+        pszFInfo[16] = (unsigned char) (nWidth % 256);
+        pszFInfo[17] = (unsigned char) (nWidth / 256);
     }
-    else {
-	pszFInfo[16] = (unsigned char)nWidth;
-	pszFInfo[17] = (unsigned char)nDecimals;
+    else
+    {
+        pszFInfo[16] = (unsigned char) nWidth;
+        pszFInfo[17] = (unsigned char) nDecimals;
     }
+    
+/* -------------------------------------------------------------------- */
+/*      Make the current record buffer appropriately larger.            */
+/* -------------------------------------------------------------------- */
+    psDBF->pszCurrentRecord = (char *) SfRealloc(psDBF->pszCurrentRecord,
+                                                 psDBF->nRecordLength);
 
-    /* -------------------------------------------------------------------- */
-    /*      Make the current record buffer appropriately larger.            */
-    /* -------------------------------------------------------------------- */
-    psDBF->pszCurrentRecord = (char *)SfRealloc(psDBF->pszCurrentRecord,
-						psDBF->nRecordLength);
-
-    return (psDBF->nFields - 1);
+    return( psDBF->nFields-1 );
 }
 
 /************************************************************************/
 /*                          DBFReadAttribute()                          */
 /*                                                                      */
 /*      Read one of the attribute fields of a record.                   */
-
 /************************************************************************/
 
 static void *DBFReadAttribute(DBFHandle psDBF, int hEntity, int iField,
-			      char chReqType)
+                              char chReqType )
+
 {
-    unsigned char *pabyRec;
-    void *pReturnField = NULL;
+    unsigned char	*pabyRec;
+    void	*pReturnField = NULL;
 
-    /* -------------------------------------------------------------------- */
-    /*      Verify selection.                                               */
-    /* -------------------------------------------------------------------- */
-    if (hEntity < 0 || hEntity >= psDBF->nRecords)
-	return (NULL);
+/* -------------------------------------------------------------------- */
+/*      Verify selection.                                               */
+/* -------------------------------------------------------------------- */
+    if( hEntity < 0 || hEntity >= psDBF->nRecords )
+        return( NULL );
 
-    if (iField < 0 || iField >= psDBF->nFields)
-	return (NULL);
+    if( iField < 0 || iField >= psDBF->nFields )
+        return( NULL );
 
-    /* -------------------------------------------------------------------- */
-    /*      Have we read the record?                                        */
-    /* -------------------------------------------------------------------- */
-    if (!DBFLoadRecord(psDBF, hEntity))
-	return NULL;
+/* -------------------------------------------------------------------- */
+/*	Have we read the record?					*/
+/* -------------------------------------------------------------------- */
+    if( !DBFLoadRecord( psDBF, hEntity ) )
+        return NULL;
 
-    pabyRec = (unsigned char *)psDBF->pszCurrentRecord;
+    pabyRec = (unsigned char *) psDBF->pszCurrentRecord;
 
-    /* -------------------------------------------------------------------- */
-    /*      Ensure we have room to extract the target field.                */
-    /* -------------------------------------------------------------------- */
-    if (psDBF->panFieldSize[iField] >= psDBF->nWorkFieldLength) {
-	psDBF->nWorkFieldLength = psDBF->panFieldSize[iField] + 100;
-	if (psDBF->pszWorkField == NULL)
-	    psDBF->pszWorkField = (char *)malloc(psDBF->nWorkFieldLength);
-	else
-	    psDBF->pszWorkField = (char *)realloc(psDBF->pszWorkField,
-						  psDBF->nWorkFieldLength);
+/* -------------------------------------------------------------------- */
+/*      Ensure we have room to extract the target field.                */
+/* -------------------------------------------------------------------- */
+    if( psDBF->panFieldSize[iField] >= psDBF->nWorkFieldLength )
+    {
+        psDBF->nWorkFieldLength = psDBF->panFieldSize[iField] + 100;
+        if( psDBF->pszWorkField == NULL )
+            psDBF->pszWorkField = (char *) malloc(psDBF->nWorkFieldLength);
+        else
+            psDBF->pszWorkField = (char *) realloc(psDBF->pszWorkField,
+                                                   psDBF->nWorkFieldLength);
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Extract the requested field.                                    */
-    /* -------------------------------------------------------------------- */
-    strncpy(psDBF->pszWorkField,
-	    ((const char *)pabyRec) + psDBF->panFieldOffset[iField],
-	    psDBF->panFieldSize[iField]);
+/* -------------------------------------------------------------------- */
+/*	Extract the requested field.					*/
+/* -------------------------------------------------------------------- */
+    strncpy( psDBF->pszWorkField,
+	     ((const char *) pabyRec) + psDBF->panFieldOffset[iField],
+	     psDBF->panFieldSize[iField] );
     psDBF->pszWorkField[psDBF->panFieldSize[iField]] = '\0';
 
     pReturnField = psDBF->pszWorkField;
 
-    /* -------------------------------------------------------------------- */
-    /*      Decode the field.                                               */
-    /* -------------------------------------------------------------------- */
-    if (chReqType == 'N') {
-	psDBF->dfDoubleField = atof(psDBF->pszWorkField);
+/* -------------------------------------------------------------------- */
+/*      Decode the field.                                               */
+/* -------------------------------------------------------------------- */
+    if( chReqType == 'N' )
+    {
+        psDBF->dfDoubleField = atof(psDBF->pszWorkField);
 
 	pReturnField = &(psDBF->dfDoubleField);
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Should we trim white space off the string attribute value?      */
-    /* -------------------------------------------------------------------- */
+/* -------------------------------------------------------------------- */
+/*      Should we trim white space off the string attribute value?      */
+/* -------------------------------------------------------------------- */
 #ifdef TRIM_DBF_WHITESPACE
-    else {
-	char *pchSrc, *pchDst;
+    else
+    {
+        char	*pchSrc, *pchDst;
 
-	pchDst = pchSrc = psDBF->pszWorkField;
-	while (*pchSrc == ' ')
-	    pchSrc++;
+        pchDst = pchSrc = psDBF->pszWorkField;
+        while( *pchSrc == ' ' )
+            pchSrc++;
 
-	while (*pchSrc != '\0')
-	    *(pchDst++) = *(pchSrc++);
-	*pchDst = '\0';
+        while( *pchSrc != '\0' )
+            *(pchDst++) = *(pchSrc++);
+        *pchDst = '\0';
 
-	while (pchDst != psDBF->pszWorkField && *(--pchDst) == ' ')
-	    *pchDst = '\0';
+        while( pchDst != psDBF->pszWorkField && *(--pchDst) == ' ' )
+            *pchDst = '\0';
     }
 #endif
-
-    return (pReturnField);
+    
+    return( pReturnField );
 }
 
 /************************************************************************/
 /*                        DBFReadIntAttribute()                         */
 /*                                                                      */
 /*      Read an integer attribute.                                      */
-
 /************************************************************************/
 
 int SHPAPI_CALL
-DBFReadIntegerAttribute(DBFHandle psDBF, int iRecord, int iField)
+DBFReadIntegerAttribute( DBFHandle psDBF, int iRecord, int iField )
+
 {
-    double *pdValue;
+    double	*pdValue;
 
-    pdValue = (double *)DBFReadAttribute(psDBF, iRecord, iField, 'N');
+    pdValue = (double *) DBFReadAttribute( psDBF, iRecord, iField, 'N' );
 
-    if (pdValue == NULL)
-	return 0;
+    if( pdValue == NULL )
+        return 0;
     else
-	return ((int)*pdValue);
+        return( (int) *pdValue );
 }
 
 /************************************************************************/
 /*                        DBFReadDoubleAttribute()                      */
 /*                                                                      */
 /*      Read a double attribute.                                        */
-
 /************************************************************************/
 
 double SHPAPI_CALL
-DBFReadDoubleAttribute(DBFHandle psDBF, int iRecord, int iField)
+DBFReadDoubleAttribute( DBFHandle psDBF, int iRecord, int iField )
+
 {
-    double *pdValue;
+    double	*pdValue;
 
-    pdValue = (double *)DBFReadAttribute(psDBF, iRecord, iField, 'N');
+    pdValue = (double *) DBFReadAttribute( psDBF, iRecord, iField, 'N' );
 
-    if (pdValue == NULL)
-	return 0.0;
+    if( pdValue == NULL )
+        return 0.0;
     else
-	return (*pdValue);
+        return( *pdValue );
 }
 
 /************************************************************************/
 /*                        DBFReadStringAttribute()                      */
 /*                                                                      */
 /*      Read a string attribute.                                        */
-
 /************************************************************************/
 
 const char SHPAPI_CALL1(*)
-DBFReadStringAttribute(DBFHandle psDBF, int iRecord, int iField)
+DBFReadStringAttribute( DBFHandle psDBF, int iRecord, int iField )
+
 {
-    return ((const char *)DBFReadAttribute(psDBF, iRecord, iField, 'C'));
+    return( (const char *) DBFReadAttribute( psDBF, iRecord, iField, 'C' ) );
 }
 
 /************************************************************************/
 /*                        DBFReadLogicalAttribute()                     */
 /*                                                                      */
 /*      Read a logical attribute.                                       */
-
 /************************************************************************/
 
 const char SHPAPI_CALL1(*)
-DBFReadLogicalAttribute(DBFHandle psDBF, int iRecord, int iField)
+DBFReadLogicalAttribute( DBFHandle psDBF, int iRecord, int iField )
+
 {
-    return ((const char *)DBFReadAttribute(psDBF, iRecord, iField, 'L'));
+    return( (const char *) DBFReadAttribute( psDBF, iRecord, iField, 'L' ) );
 }
 
 /************************************************************************/
@@ -877,47 +900,50 @@
 /*      Return TRUE if value for field is NULL.                         */
 /*                                                                      */
 /*      Contributed by Jim Matthews.                                    */
-
 /************************************************************************/
 
-int SHPAPI_CALL DBFIsAttributeNULL(DBFHandle psDBF, int iRecord, int iField)
+int SHPAPI_CALL
+DBFIsAttributeNULL( DBFHandle psDBF, int iRecord, int iField )
+
 {
-    const char *pszValue;
+    const char	*pszValue;
     int i;
 
-    pszValue = DBFReadStringAttribute(psDBF, iRecord, iField);
+    pszValue = DBFReadStringAttribute( psDBF, iRecord, iField );
 
-    if (pszValue == NULL)
-	return TRUE;
+    if( pszValue == NULL )
+        return TRUE;
 
-    switch (psDBF->pachFieldType[iField]) {
-    case 'N':
-    case 'F':
-	/*
-	 ** We accept all asterisks or all blanks as NULL 
-	 ** though according to the spec I think it should be all 
-	 ** asterisks. 
-	 */
-	if (pszValue[0] == '*')
-	    return TRUE;
+    switch(psDBF->pachFieldType[iField])
+    {
+      case 'N':
+      case 'F':
+        /*
+        ** We accept all asterisks or all blanks as NULL 
+        ** though according to the spec I think it should be all 
+        ** asterisks. 
+        */
+        if( pszValue[0] == '*' )
+            return TRUE;
 
-	for (i = 0; pszValue[i] != '\0'; i++) {
-	    if (pszValue[i] != ' ')
-		return FALSE;
-	}
-	return TRUE;
+        for( i = 0; pszValue[i] != '\0'; i++ )
+        {
+            if( pszValue[i] != ' ' )
+                return FALSE;
+        }
+        return TRUE;
 
-    case 'D':
-	/* NULL date fields have value "00000000" */
-	return strncmp(pszValue, "00000000", 8) == 0;
+      case 'D':
+        /* NULL date fields have value "00000000" */
+        return strncmp(pszValue,"00000000",8) == 0;
 
-    case 'L':
-	/* NULL boolean fields have value "?" */
-	return pszValue[0] == '?';
+      case 'L':
+        /* NULL boolean fields have value "?" */ 
+        return pszValue[0] == '?';
 
-    default:
-	/* empty string fields are considered NULL */
-	return strlen(pszValue) == 0;
+      default:
+        /* empty string fields are considered NULL */
+        return strlen(pszValue) == 0;
     }
 }
 
@@ -925,219 +951,234 @@
 /*                          DBFGetFieldCount()                          */
 /*                                                                      */
 /*      Return the number of fields in this table.                      */
-
 /************************************************************************/
 
-int SHPAPI_CALL DBFGetFieldCount(DBFHandle psDBF)
+int SHPAPI_CALL
+DBFGetFieldCount( DBFHandle psDBF )
+
 {
-    return (psDBF->nFields);
+    return( psDBF->nFields );
 }
 
 /************************************************************************/
 /*                         DBFGetRecordCount()                          */
 /*                                                                      */
 /*      Return the number of records in this table.                     */
-
 /************************************************************************/
 
-int SHPAPI_CALL DBFGetRecordCount(DBFHandle psDBF)
+int SHPAPI_CALL
+DBFGetRecordCount( DBFHandle psDBF )
+
 {
-    return (psDBF->nRecords);
+    return( psDBF->nRecords );
 }
 
 /************************************************************************/
 /*                          DBFGetFieldInfo()                           */
 /*                                                                      */
 /*      Return any requested information about the field.               */
-
 /************************************************************************/
 
 DBFFieldType SHPAPI_CALL
-DBFGetFieldInfo(DBFHandle psDBF, int iField, char *pszFieldName,
-		int *pnWidth, int *pnDecimals)
+DBFGetFieldInfo( DBFHandle psDBF, int iField, char * pszFieldName,
+                 int * pnWidth, int * pnDecimals )
+
 {
-    if (iField < 0 || iField >= psDBF->nFields)
-	return (FTInvalid);
+    if( iField < 0 || iField >= psDBF->nFields )
+        return( FTInvalid );
 
-    if (pnWidth != NULL)
-	*pnWidth = psDBF->panFieldSize[iField];
+    if( pnWidth != NULL )
+        *pnWidth = psDBF->panFieldSize[iField];
 
-    if (pnDecimals != NULL)
-	*pnDecimals = psDBF->panFieldDecimals[iField];
+    if( pnDecimals != NULL )
+        *pnDecimals = psDBF->panFieldDecimals[iField];
 
-    if (pszFieldName != NULL) {
-	int i;
+    if( pszFieldName != NULL )
+    {
+	int	i;
 
-	strncpy(pszFieldName, (char *)psDBF->pszHeader + iField * 32, 11);
+	strncpy( pszFieldName, (char *) psDBF->pszHeader+iField*32, 11 );
 	pszFieldName[11] = '\0';
-	for (i = 10; i > 0 && pszFieldName[i] == ' '; i--)
+	for( i = 10; i > 0 && pszFieldName[i] == ' '; i-- )
 	    pszFieldName[i] = '\0';
     }
 
-    if (psDBF->pachFieldType[iField] == 'L')
-	return (FTLogical);
+    if ( psDBF->pachFieldType[iField] == 'L' )
+	return( FTLogical);
 
-    else if (psDBF->pachFieldType[iField] == 'N'
-	     || psDBF->pachFieldType[iField] == 'F') {
-	if (psDBF->panFieldDecimals[iField] > 0)
-	    /*            || psDBF->panFieldSize[iField] > 10 ) *//* GDAL bug #809 */
-	    return (FTDouble);
+    else if( psDBF->pachFieldType[iField] == 'N' 
+             || psDBF->pachFieldType[iField] == 'F' )
+    {
+	if( psDBF->panFieldDecimals[iField] > 0 )
+/*            || psDBF->panFieldSize[iField] > 10 ) */ /* GDAL bug #809 */
+	    return( FTDouble );
 	else
-	    return (FTInteger);
+	    return( FTInteger );
     }
-    else {
-	return (FTString);
+    else
+    {
+	return( FTString );
     }
 }
 
 /************************************************************************/
 /*                         DBFWriteAttribute()                          */
-/*                                                                      */
-/*      Write an attribute record to the file.                          */
-
+/*									*/
+/*	Write an attribute record to the file.				*/
 /************************************************************************/
 
 static int DBFWriteAttribute(DBFHandle psDBF, int hEntity, int iField,
-			     void *pValue)
+			     void * pValue )
+
 {
-    int i, j, nRetResult = TRUE;
-    unsigned char *pabyRec;
-    char szSField[400], szFormat[20];
+    int	       	i, j, nRetResult = TRUE;
+    unsigned char	*pabyRec;
+    char	szSField[400], szFormat[20];
 
-    /* -------------------------------------------------------------------- */
-    /*      Is this a valid record?                                         */
-    /* -------------------------------------------------------------------- */
-    if (hEntity < 0 || hEntity > psDBF->nRecords)
-	return (FALSE);
+/* -------------------------------------------------------------------- */
+/*	Is this a valid record?						*/
+/* -------------------------------------------------------------------- */
+    if( hEntity < 0 || hEntity > psDBF->nRecords )
+        return( FALSE );
 
-    if (psDBF->bNoHeader)
-	DBFWriteHeader(psDBF);
+    if( psDBF->bNoHeader )
+        DBFWriteHeader(psDBF);
 
-    /* -------------------------------------------------------------------- */
-    /*      Is this a brand new record?                                     */
-    /* -------------------------------------------------------------------- */
-    if (hEntity == psDBF->nRecords) {
-	if (!DBFFlushRecord(psDBF))
-	    return FALSE;
+/* -------------------------------------------------------------------- */
+/*      Is this a brand new record?                                     */
+/* -------------------------------------------------------------------- */
+    if( hEntity == psDBF->nRecords )
+    {
+	if( !DBFFlushRecord( psDBF ) )
+            return FALSE;
 
 	psDBF->nRecords++;
-	for (i = 0; i < psDBF->nRecordLength; i++)
+	for( i = 0; i < psDBF->nRecordLength; i++ )
 	    psDBF->pszCurrentRecord[i] = ' ';
 
 	psDBF->nCurrentRecord = hEntity;
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Is this an existing record, but different than the last one     */
-    /*      we accessed?                                                    */
-    /* -------------------------------------------------------------------- */
-    if (!DBFLoadRecord(psDBF, hEntity))
-	return FALSE;
+/* -------------------------------------------------------------------- */
+/*      Is this an existing record, but different than the last one     */
+/*      we accessed?                                                    */
+/* -------------------------------------------------------------------- */
+    if( !DBFLoadRecord( psDBF, hEntity ) )
+        return FALSE;
 
-    pabyRec = (unsigned char *)psDBF->pszCurrentRecord;
+    pabyRec = (unsigned char *) psDBF->pszCurrentRecord;
 
     psDBF->bCurrentRecordModified = TRUE;
     psDBF->bUpdated = TRUE;
 
-    /* -------------------------------------------------------------------- */
-    /*      Translate NULL value to valid DBF file representation.          */
-    /*                                                                      */
-    /*      Contributed by Jim Matthews.                                    */
-    /* -------------------------------------------------------------------- */
-    if (pValue == NULL) {
-	switch (psDBF->pachFieldType[iField]) {
-	case 'N':
-	case 'F':
+/* -------------------------------------------------------------------- */
+/*      Translate NULL value to valid DBF file representation.          */
+/*                                                                      */
+/*      Contributed by Jim Matthews.                                    */
+/* -------------------------------------------------------------------- */
+    if( pValue == NULL )
+    {
+        switch(psDBF->pachFieldType[iField])
+        {
+          case 'N':
+          case 'F':
 	    /* NULL numeric fields have value "****************" */
-	    memset((char *)(pabyRec + psDBF->panFieldOffset[iField]), '*',
-		   psDBF->panFieldSize[iField]);
-	    break;
+            memset( (char *) (pabyRec+psDBF->panFieldOffset[iField]), '*', 
+                    psDBF->panFieldSize[iField] );
+            break;
 
-	case 'D':
+          case 'D':
 	    /* NULL date fields have value "00000000" */
-	    memset((char *)(pabyRec + psDBF->panFieldOffset[iField]), '0',
-		   psDBF->panFieldSize[iField]);
-	    break;
+            memset( (char *) (pabyRec+psDBF->panFieldOffset[iField]), '0', 
+                    psDBF->panFieldSize[iField] );
+            break;
 
-	case 'L':
-	    /* NULL boolean fields have value "?" */
-	    memset((char *)(pabyRec + psDBF->panFieldOffset[iField]), '?',
-		   psDBF->panFieldSize[iField]);
-	    break;
+          case 'L':
+	    /* NULL boolean fields have value "?" */ 
+            memset( (char *) (pabyRec+psDBF->panFieldOffset[iField]), '?', 
+                    psDBF->panFieldSize[iField] );
+            break;
 
-	default:
-	    /* empty string fields are considered NULL */
-	    memset((char *)(pabyRec + psDBF->panFieldOffset[iField]), ' ',
-		   psDBF->panFieldSize[iField]);
-	    break;
-	}
-	return TRUE;
+          default:
+            /* empty string fields are considered NULL */
+            memset( (char *) (pabyRec+psDBF->panFieldOffset[iField]), ' ', 
+                    psDBF->panFieldSize[iField] );
+            break;
+        }
+        return TRUE;
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Assign all the record fields.                                   */
-    /* -------------------------------------------------------------------- */
-    switch (psDBF->pachFieldType[iField]) {
-    case 'D':
-    case 'N':
-    case 'F':
-	if (psDBF->panFieldDecimals[iField] == 0) {
-	    int nWidth = psDBF->panFieldSize[iField];
+/* -------------------------------------------------------------------- */
+/*      Assign all the record fields.                                   */
+/* -------------------------------------------------------------------- */
+    switch( psDBF->pachFieldType[iField] )
+    {
+      case 'D':
+      case 'N':
+      case 'F':
+	if( psDBF->panFieldDecimals[iField] == 0 )
+	{
+            int		nWidth = psDBF->panFieldSize[iField];
 
-	    if ((int)sizeof(szSField) - 2 < nWidth)
-		nWidth = sizeof(szSField) - 2;
+            if( (int) sizeof(szSField)-2 < nWidth )
+                nWidth = sizeof(szSField)-2;
 
-	    sprintf(szFormat, "%%%dd", nWidth);
-	    sprintf(szSField, szFormat, (int)*((double *)pValue));
-	    if ((int)strlen(szSField) > psDBF->panFieldSize[iField]) {
-		szSField[psDBF->panFieldSize[iField]] = '\0';
-		nRetResult = FALSE;
-	    }
+	    sprintf( szFormat, "%%%dd", nWidth );
+	    sprintf(szSField, szFormat, (int) *((double *) pValue) );
+	    if( (int)strlen(szSField) > psDBF->panFieldSize[iField] )
+            {
+	        szSField[psDBF->panFieldSize[iField]] = '\0';
+                nRetResult = FALSE;
+            }
 
-	    strncpy((char *)(pabyRec + psDBF->panFieldOffset[iField]),
-		    szSField, strlen(szSField));
+	    strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
+		    szSField, strlen(szSField) );
 	}
-	else {
-	    int nWidth = psDBF->panFieldSize[iField];
+	else
+	{
+            int		nWidth = psDBF->panFieldSize[iField];
 
-	    if ((int)sizeof(szSField) - 2 < nWidth)
-		nWidth = sizeof(szSField) - 2;
+            if( (int) sizeof(szSField)-2 < nWidth )
+                nWidth = sizeof(szSField)-2;
 
-	    sprintf(szFormat, "%%%d.%df",
-		    nWidth, psDBF->panFieldDecimals[iField]);
-	    sprintf(szSField, szFormat, *((double *)pValue));
-	    if ((int)strlen(szSField) > psDBF->panFieldSize[iField]) {
-		szSField[psDBF->panFieldSize[iField]] = '\0';
-		nRetResult = FALSE;
-	    }
-	    strncpy((char *)(pabyRec + psDBF->panFieldOffset[iField]),
-		    szSField, strlen(szSField));
+	    sprintf( szFormat, "%%%d.%df", 
+                     nWidth, psDBF->panFieldDecimals[iField] );
+	    sprintf(szSField, szFormat, *((double *) pValue) );
+	    if( (int) strlen(szSField) > psDBF->panFieldSize[iField] )
+            {
+	        szSField[psDBF->panFieldSize[iField]] = '\0';
+                nRetResult = FALSE;
+            }
+	    strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
+		    szSField, strlen(szSField) );
 	}
 	break;
 
-    case 'L':
-	if (psDBF->panFieldSize[iField] >= 1 &&
-	    (*(char *)pValue == 'F' || *(char *)pValue == 'T'))
-	    *(pabyRec + psDBF->panFieldOffset[iField]) = *(char *)pValue;
-	break;
+      case 'L':
+        if (psDBF->panFieldSize[iField] >= 1  && 
+            (*(char*)pValue == 'F' || *(char*)pValue == 'T'))
+            *(pabyRec+psDBF->panFieldOffset[iField]) = *(char*)pValue;
+        break;
 
-    default:
-	if ((int)strlen((char *)pValue) > psDBF->panFieldSize[iField]) {
+      default:
+	if( (int) strlen((char *) pValue) > psDBF->panFieldSize[iField] )
+        {
 	    j = psDBF->panFieldSize[iField];
-	    nRetResult = FALSE;
-	}
-	else {
-	    memset(pabyRec + psDBF->panFieldOffset[iField], ' ',
-		   psDBF->panFieldSize[iField]);
-	    j = strlen((char *)pValue);
-	}
+            nRetResult = FALSE;
+        }
+	else
+        {
+            memset( pabyRec+psDBF->panFieldOffset[iField], ' ',
+                    psDBF->panFieldSize[iField] );
+	    j = strlen((char *) pValue);
+        }
 
-	strncpy((char *)(pabyRec + psDBF->panFieldOffset[iField]),
-		(char *)pValue, j);
+	strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
+		(char *) pValue, j );
 	break;
     }
 
-    return (nRetResult);
+    return( nRetResult );
 }
 
 /************************************************************************/
@@ -1146,188 +1187,193 @@
 /*      Write an attribute record to the file, but without any          */
 /*      reformatting based on type.  The provided buffer is written     */
 /*      as is to the field position in the record.                      */
-
 /************************************************************************/
 
 int SHPAPI_CALL
 DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField,
-			  void *pValue)
+                              void * pValue )
+
 {
-    int i, j;
-    unsigned char *pabyRec;
+    int	       		i, j;
+    unsigned char	*pabyRec;
 
-    /* -------------------------------------------------------------------- */
-    /*      Is this a valid record?                                         */
-    /* -------------------------------------------------------------------- */
-    if (hEntity < 0 || hEntity > psDBF->nRecords)
-	return (FALSE);
+/* -------------------------------------------------------------------- */
+/*	Is this a valid record?						*/
+/* -------------------------------------------------------------------- */
+    if( hEntity < 0 || hEntity > psDBF->nRecords )
+        return( FALSE );
 
-    if (psDBF->bNoHeader)
-	DBFWriteHeader(psDBF);
+    if( psDBF->bNoHeader )
+        DBFWriteHeader(psDBF);
 
-    /* -------------------------------------------------------------------- */
-    /*      Is this a brand new record?                                     */
-    /* -------------------------------------------------------------------- */
-    if (hEntity == psDBF->nRecords) {
-	if (!DBFFlushRecord(psDBF))
-	    return FALSE;
+/* -------------------------------------------------------------------- */
+/*      Is this a brand new record?                                     */
+/* -------------------------------------------------------------------- */
+    if( hEntity == psDBF->nRecords )
+    {
+	if( !DBFFlushRecord( psDBF ) )
+            return FALSE;
 
 	psDBF->nRecords++;
-	for (i = 0; i < psDBF->nRecordLength; i++)
+	for( i = 0; i < psDBF->nRecordLength; i++ )
 	    psDBF->pszCurrentRecord[i] = ' ';
 
 	psDBF->nCurrentRecord = hEntity;
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Is this an existing record, but different than the last one     */
-    /*      we accessed?                                                    */
-    /* -------------------------------------------------------------------- */
-    if (!DBFLoadRecord(psDBF, hEntity))
-	return FALSE;
+/* -------------------------------------------------------------------- */
+/*      Is this an existing record, but different than the last one     */
+/*      we accessed?                                                    */
+/* -------------------------------------------------------------------- */
+    if( !DBFLoadRecord( psDBF, hEntity ) )
+        return FALSE;
 
-    pabyRec = (unsigned char *)psDBF->pszCurrentRecord;
+    pabyRec = (unsigned char *) psDBF->pszCurrentRecord;
 
-    /* -------------------------------------------------------------------- */
-    /*      Assign all the record fields.                                   */
-    /* -------------------------------------------------------------------- */
-    if ((int)strlen((char *)pValue) > psDBF->panFieldSize[iField])
-	j = psDBF->panFieldSize[iField];
-    else {
-	memset(pabyRec + psDBF->panFieldOffset[iField], ' ',
-	       psDBF->panFieldSize[iField]);
-	j = strlen((char *)pValue);
+/* -------------------------------------------------------------------- */
+/*      Assign all the record fields.                                   */
+/* -------------------------------------------------------------------- */
+    if( (int)strlen((char *) pValue) > psDBF->panFieldSize[iField] )
+        j = psDBF->panFieldSize[iField];
+    else
+    {
+        memset( pabyRec+psDBF->panFieldOffset[iField], ' ',
+                psDBF->panFieldSize[iField] );
+        j = strlen((char *) pValue);
     }
 
-    strncpy((char *)(pabyRec + psDBF->panFieldOffset[iField]),
-	    (char *)pValue, j);
+    strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
+            (char *) pValue, j );
 
     psDBF->bCurrentRecordModified = TRUE;
     psDBF->bUpdated = TRUE;
 
-    return (TRUE);
+    return( TRUE );
 }
 
 /************************************************************************/
 /*                      DBFWriteDoubleAttribute()                       */
 /*                                                                      */
 /*      Write a double attribute.                                       */
-
 /************************************************************************/
 
 int SHPAPI_CALL
-DBFWriteDoubleAttribute(DBFHandle psDBF, int iRecord, int iField,
-			double dValue)
+DBFWriteDoubleAttribute( DBFHandle psDBF, int iRecord, int iField,
+                         double dValue )
+
 {
-    return (DBFWriteAttribute(psDBF, iRecord, iField, (void *)&dValue));
+    return( DBFWriteAttribute( psDBF, iRecord, iField, (void *) &dValue ) );
 }
 
 /************************************************************************/
 /*                      DBFWriteIntegerAttribute()                      */
 /*                                                                      */
 /*      Write a integer attribute.                                      */
-
 /************************************************************************/
 
 int SHPAPI_CALL
-DBFWriteIntegerAttribute(DBFHandle psDBF, int iRecord, int iField, int nValue)
+DBFWriteIntegerAttribute( DBFHandle psDBF, int iRecord, int iField,
+                          int nValue )
+
 {
-    double dValue = nValue;
+    double	dValue = nValue;
 
-    return (DBFWriteAttribute(psDBF, iRecord, iField, (void *)&dValue));
+    return( DBFWriteAttribute( psDBF, iRecord, iField, (void *) &dValue ) );
 }
 
 /************************************************************************/
 /*                      DBFWriteStringAttribute()                       */
 /*                                                                      */
 /*      Write a string attribute.                                       */
-
 /************************************************************************/
 
 int SHPAPI_CALL
-DBFWriteStringAttribute(DBFHandle psDBF, int iRecord, int iField,
-			const char *pszValue)
+DBFWriteStringAttribute( DBFHandle psDBF, int iRecord, int iField,
+                         const char * pszValue )
+
 {
-    return (DBFWriteAttribute(psDBF, iRecord, iField, (void *)pszValue));
+    return( DBFWriteAttribute( psDBF, iRecord, iField, (void *) pszValue ) );
 }
 
 /************************************************************************/
 /*                      DBFWriteNULLAttribute()                         */
 /*                                                                      */
 /*      Write a string attribute.                                       */
-
 /************************************************************************/
 
 int SHPAPI_CALL
-DBFWriteNULLAttribute(DBFHandle psDBF, int iRecord, int iField)
+DBFWriteNULLAttribute( DBFHandle psDBF, int iRecord, int iField )
+
 {
-    return (DBFWriteAttribute(psDBF, iRecord, iField, NULL));
+    return( DBFWriteAttribute( psDBF, iRecord, iField, NULL ) );
 }
 
 /************************************************************************/
 /*                      DBFWriteLogicalAttribute()                      */
 /*                                                                      */
 /*      Write a logical attribute.                                      */
-
 /************************************************************************/
 
 int SHPAPI_CALL
-DBFWriteLogicalAttribute(DBFHandle psDBF, int iRecord, int iField,
-			 const char lValue)
+DBFWriteLogicalAttribute( DBFHandle psDBF, int iRecord, int iField,
+		       const char lValue)
+
 {
-    return (DBFWriteAttribute(psDBF, iRecord, iField, (void *)(&lValue)));
+    return( DBFWriteAttribute( psDBF, iRecord, iField, (void *) (&lValue) ) );
 }
 
 /************************************************************************/
 /*                         DBFWriteTuple()                              */
-/*                                                                      */
-/*      Write an attribute record to the file.                          */
-
+/*									*/
+/*	Write an attribute record to the file.				*/
 /************************************************************************/
 
-int SHPAPI_CALL DBFWriteTuple(DBFHandle psDBF, int hEntity, void *pRawTuple)
+int SHPAPI_CALL
+DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple )
+
 {
-    int i;
-    unsigned char *pabyRec;
+    int	       		i;
+    unsigned char	*pabyRec;
 
-    /* -------------------------------------------------------------------- */
-    /*      Is this a valid record?                                         */
-    /* -------------------------------------------------------------------- */
-    if (hEntity < 0 || hEntity > psDBF->nRecords)
-	return (FALSE);
+/* -------------------------------------------------------------------- */
+/*	Is this a valid record?						*/
+/* -------------------------------------------------------------------- */
+    if( hEntity < 0 || hEntity > psDBF->nRecords )
+        return( FALSE );
 
-    if (psDBF->bNoHeader)
-	DBFWriteHeader(psDBF);
+    if( psDBF->bNoHeader )
+        DBFWriteHeader(psDBF);
 
-    /* -------------------------------------------------------------------- */
-    /*      Is this a brand new record?                                     */
-    /* -------------------------------------------------------------------- */
-    if (hEntity == psDBF->nRecords) {
-	if (!DBFFlushRecord(psDBF))
-	    return FALSE;
+/* -------------------------------------------------------------------- */
+/*      Is this a brand new record?                                     */
+/* -------------------------------------------------------------------- */
+    if( hEntity == psDBF->nRecords )
+    {
+	if( !DBFFlushRecord( psDBF ) )
+            return FALSE;
 
 	psDBF->nRecords++;
-	for (i = 0; i < psDBF->nRecordLength; i++)
+	for( i = 0; i < psDBF->nRecordLength; i++ )
 	    psDBF->pszCurrentRecord[i] = ' ';
 
 	psDBF->nCurrentRecord = hEntity;
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Is this an existing record, but different than the last one     */
-    /*      we accessed?                                                    */
-    /* -------------------------------------------------------------------- */
-    if (!DBFLoadRecord(psDBF, hEntity))
-	return FALSE;
+/* -------------------------------------------------------------------- */
+/*      Is this an existing record, but different than the last one     */
+/*      we accessed?                                                    */
+/* -------------------------------------------------------------------- */
+    if( !DBFLoadRecord( psDBF, hEntity ) )
+        return FALSE;
 
-    pabyRec = (unsigned char *)psDBF->pszCurrentRecord;
+    pabyRec = (unsigned char *) psDBF->pszCurrentRecord;
 
-    memcpy(pabyRec, pRawTuple, psDBF->nRecordLength);
+    memcpy ( pabyRec, pRawTuple,  psDBF->nRecordLength );
 
     psDBF->bCurrentRecordModified = TRUE;
     psDBF->bUpdated = TRUE;
 
-    return (TRUE);
+    return( TRUE );
 }
 
 /************************************************************************/
@@ -1335,64 +1381,60 @@
 /*                                                                      */
 /*      Read a complete record.  Note that the result is only valid     */
 /*      till the next record read for any reason.                       */
-
 /************************************************************************/
 
-const char SHPAPI_CALL1(*) DBFReadTuple(DBFHandle psDBF, int hEntity)
+const char SHPAPI_CALL1(*)
+DBFReadTuple(DBFHandle psDBF, int hEntity )
+
 {
-    if (hEntity < 0 || hEntity >= psDBF->nRecords)
-	return (NULL);
+    if( hEntity < 0 || hEntity >= psDBF->nRecords )
+        return( NULL );
 
-    if (!DBFLoadRecord(psDBF, hEntity))
-	return NULL;
+    if( !DBFLoadRecord( psDBF, hEntity ) )
+        return NULL;
 
-    return (const char *)psDBF->pszCurrentRecord;
+    return (const char *) psDBF->pszCurrentRecord;
 }
 
 /************************************************************************/
 /*                          DBFCloneEmpty()                              */
 /*                                                                      */
 /*      Read one of the attribute fields of a record.                   */
-
 /************************************************************************/
 
-DBFHandle SHPAPI_CALL DBFCloneEmpty(DBFHandle psDBF, const char *pszFilename)
+DBFHandle SHPAPI_CALL
+DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename ) 
 {
-    DBFHandle newDBF;
+    DBFHandle	newDBF;
 
-    newDBF = DBFCreate(pszFilename);
-    if (newDBF == NULL)
-	return (NULL);
+   newDBF = DBFCreate ( pszFilename );
+   if ( newDBF == NULL ) return ( NULL ); 
+   
+   newDBF->nFields = psDBF->nFields;
+   newDBF->nRecordLength = psDBF->nRecordLength;
+   newDBF->nHeaderLength = psDBF->nHeaderLength;
+    
+   newDBF->pszHeader = (char *) malloc ( newDBF->nHeaderLength );
+   memcpy ( newDBF->pszHeader, psDBF->pszHeader, newDBF->nHeaderLength );
+   
+   newDBF->panFieldOffset = (int *) malloc ( sizeof(int) * psDBF->nFields ); 
+   memcpy ( newDBF->panFieldOffset, psDBF->panFieldOffset, sizeof(int) * psDBF->nFields );
+   newDBF->panFieldSize = (int *) malloc ( sizeof(int) * psDBF->nFields );
+   memcpy ( newDBF->panFieldSize, psDBF->panFieldSize, sizeof(int) * psDBF->nFields );
+   newDBF->panFieldDecimals = (int *) malloc ( sizeof(int) * psDBF->nFields );
+   memcpy ( newDBF->panFieldDecimals, psDBF->panFieldDecimals, sizeof(int) * psDBF->nFields );
+   newDBF->pachFieldType = (char *) malloc ( sizeof(char) * psDBF->nFields );
+   memcpy ( newDBF->pachFieldType, psDBF->pachFieldType, sizeof(char)*psDBF->nFields );
 
-    newDBF->nFields = psDBF->nFields;
-    newDBF->nRecordLength = psDBF->nRecordLength;
-    newDBF->nHeaderLength = psDBF->nHeaderLength;
+   newDBF->bNoHeader = TRUE;
+   newDBF->bUpdated = TRUE;
+   
+   DBFWriteHeader ( newDBF );
+   DBFClose ( newDBF );
+   
+   newDBF = DBFOpen ( pszFilename, "rb+" );
 
-    newDBF->pszHeader = (char *)malloc(newDBF->nHeaderLength);
-    memcpy(newDBF->pszHeader, psDBF->pszHeader, newDBF->nHeaderLength);
-
-    newDBF->panFieldOffset = (int *)malloc(sizeof(int) * psDBF->nFields);
-    memcpy(newDBF->panFieldOffset, psDBF->panFieldOffset,
-	   sizeof(int) * psDBF->nFields);
-    newDBF->panFieldSize = (int *)malloc(sizeof(int) * psDBF->nFields);
-    memcpy(newDBF->panFieldSize, psDBF->panFieldSize,
-	   sizeof(int) * psDBF->nFields);
-    newDBF->panFieldDecimals = (int *)malloc(sizeof(int) * psDBF->nFields);
-    memcpy(newDBF->panFieldDecimals, psDBF->panFieldDecimals,
-	   sizeof(int) * psDBF->nFields);
-    newDBF->pachFieldType = (char *)malloc(sizeof(char) * psDBF->nFields);
-    memcpy(newDBF->pachFieldType, psDBF->pachFieldType,
-	   sizeof(char) * psDBF->nFields);
-
-    newDBF->bNoHeader = TRUE;
-    newDBF->bUpdated = TRUE;
-
-    DBFWriteHeader(newDBF);
-    DBFClose(newDBF);
-
-    newDBF = DBFOpen(pszFilename, "rb+");
-
-    return (newDBF);
+   return ( newDBF );
 }
 
 /************************************************************************/
@@ -1404,32 +1446,32 @@
 /*                           'N' (Numeric, with or without decimal),    */
 /*                           'L' (Logical),                             */
 /*                           'M' (Memo: 10 digits .DBT block ptr)       */
-
 /************************************************************************/
 
-char SHPAPI_CALL DBFGetNativeFieldType(DBFHandle psDBF, int iField)
+char SHPAPI_CALL
+DBFGetNativeFieldType( DBFHandle psDBF, int iField )
+
 {
-    if (iField >= 0 && iField < psDBF->nFields)
-	return psDBF->pachFieldType[iField];
+    if( iField >=0 && iField < psDBF->nFields )
+        return psDBF->pachFieldType[iField];
 
-    return ' ';
+    return  ' ';
 }
 
 /************************************************************************/
 /*                            str_to_upper()                            */
-
 /************************************************************************/
 
-static void str_to_upper(char *string)
+static void str_to_upper (char *string)
 {
     int len;
     short i = -1;
 
-    len = strlen(string);
+    len = strlen (string);
 
     while (++i < len)
-	if (isalpha(string[i]) && islower(string[i]))
-	    string[i] = (char)toupper((int)string[i]);
+        if (isalpha(string[i]) && islower(string[i]))
+            string[i] = (char) toupper ((int)string[i]);
 }
 
 /************************************************************************/
@@ -1438,27 +1480,29 @@
 /*      Get the index number for a field in a .dbf file.                */
 /*                                                                      */
 /*      Contributed by Jim Matthews.                                    */
-
 /************************************************************************/
 
-int SHPAPI_CALL DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName)
+int SHPAPI_CALL
+DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName)
+
 {
-    char name[12], name1[12], name2[12];
-    int i;
+    char          name[12], name1[12], name2[12];
+    int           i;
 
-    strncpy(name1, pszFieldName, 11);
+    strncpy(name1, pszFieldName,11);
     name1[11] = '\0';
     str_to_upper(name1);
 
-    for (i = 0; i < DBFGetFieldCount(psDBF); i++) {
-	DBFGetFieldInfo(psDBF, i, name, NULL, NULL);
-	strncpy(name2, name, 11);
-	str_to_upper(name2);
+    for( i = 0; i < DBFGetFieldCount(psDBF); i++ )
+    {
+        DBFGetFieldInfo( psDBF, i, name, NULL, NULL );
+        strncpy(name2,name,11);
+        str_to_upper(name2);
 
-	if (!strncmp(name1, name2, 10))
-	    return (i);
+        if(!strncmp(name1,name2,10))
+            return(i);
     }
-    return (-1);
+    return(-1);
 }
 
 /************************************************************************/
@@ -1466,64 +1510,65 @@
 /*                                                                      */
 /*      Returns TRUE if the indicated record is deleted, otherwise      */
 /*      it returns FALSE.                                               */
-
 /************************************************************************/
 
-int SHPAPI_CALL DBFIsRecordDeleted(DBFHandle psDBF, int iShape)
+int SHPAPI_CALL DBFIsRecordDeleted( DBFHandle psDBF, int iShape )
+
 {
-    /* -------------------------------------------------------------------- */
-    /*      Verify selection.                                               */
-    /* -------------------------------------------------------------------- */
-    if (iShape < 0 || iShape >= psDBF->nRecords)
-	return TRUE;
+/* -------------------------------------------------------------------- */
+/*      Verify selection.                                               */
+/* -------------------------------------------------------------------- */
+    if( iShape < 0 || iShape >= psDBF->nRecords )
+        return TRUE;
 
-    /* -------------------------------------------------------------------- */
-    /*      Have we read the record?                                        */
-    /* -------------------------------------------------------------------- */
-    if (!DBFLoadRecord(psDBF, iShape))
-	return FALSE;
+/* -------------------------------------------------------------------- */
+/*	Have we read the record?					*/
+/* -------------------------------------------------------------------- */
+    if( !DBFLoadRecord( psDBF, iShape ) )
+        return FALSE;
 
-    /* -------------------------------------------------------------------- */
-    /*      '*' means deleted.                                              */
-    /* -------------------------------------------------------------------- */
+/* -------------------------------------------------------------------- */
+/*      '*' means deleted.                                              */
+/* -------------------------------------------------------------------- */
     return psDBF->pszCurrentRecord[0] == '*';
 }
 
 /************************************************************************/
 /*                        DBFMarkRecordDeleted()                        */
-
 /************************************************************************/
 
-int SHPAPI_CALL DBFMarkRecordDeleted(DBFHandle psDBF, int iShape,
-				     int bIsDeleted)
+int SHPAPI_CALL DBFMarkRecordDeleted( DBFHandle psDBF, int iShape, 
+                                      int bIsDeleted )
+
 {
     char chNewFlag;
 
-    /* -------------------------------------------------------------------- */
-    /*      Verify selection.                                               */
-    /* -------------------------------------------------------------------- */
-    if (iShape < 0 || iShape >= psDBF->nRecords)
-	return FALSE;
+/* -------------------------------------------------------------------- */
+/*      Verify selection.                                               */
+/* -------------------------------------------------------------------- */
+    if( iShape < 0 || iShape >= psDBF->nRecords )
+        return FALSE;
 
-    /* -------------------------------------------------------------------- */
-    /*      Is this an existing record, but different than the last one     */
-    /*      we accessed?                                                    */
-    /* -------------------------------------------------------------------- */
-    if (!DBFLoadRecord(psDBF, iShape))
-	return FALSE;
+/* -------------------------------------------------------------------- */
+/*      Is this an existing record, but different than the last one     */
+/*      we accessed?                                                    */
+/* -------------------------------------------------------------------- */
+    if( !DBFLoadRecord( psDBF, iShape ) )
+        return FALSE;
 
-    /* -------------------------------------------------------------------- */
-    /*      Assign value, marking record as dirty if it changes.            */
-    /* -------------------------------------------------------------------- */
-    if (bIsDeleted)
-	chNewFlag = '*';
-    else
-	chNewFlag = ' ';
+/* -------------------------------------------------------------------- */
+/*      Assign value, marking record as dirty if it changes.            */
+/* -------------------------------------------------------------------- */
+    if( bIsDeleted )
+        chNewFlag = '*';
+    else 
+        chNewFlag = ' ';
 
-    if (psDBF->pszCurrentRecord[0] != chNewFlag) {
-	psDBF->bCurrentRecordModified = TRUE;
-	psDBF->bUpdated = TRUE;
-	psDBF->pszCurrentRecord[0] = chNewFlag;
+    if( psDBF->pszCurrentRecord[0] != chNewFlag )
+    {
+        psDBF->bCurrentRecordModified = TRUE;
+        psDBF->bUpdated = TRUE;
+        psDBF->pszCurrentRecord[0] = chNewFlag;
     }
 
     return TRUE;

Modified: grass/trunk/lib/external/shapelib/safileio.c
===================================================================
--- grass/trunk/lib/external/shapelib/safileio.c	2008-08-06 19:30:45 UTC (rev 32581)
+++ grass/trunk/lib/external/shapelib/safileio.c	2008-08-06 19:37:34 UTC (rev 32582)
@@ -1,4 +1,3 @@
-
 /******************************************************************************
  * $Id: safileio.c,v 1.4 2008/01/16 20:05:14 bram Exp $
  *
@@ -79,110 +78,112 @@
 
 /************************************************************************/
 /*                              SADFOpen()                              */
-
 /************************************************************************/
 
-SAFile SADFOpen(const char *pszFilename, const char *pszAccess)
+SAFile SADFOpen( const char *pszFilename, const char *pszAccess )
+
 {
-    return (SAFile) fopen(pszFilename, pszAccess);
+    return (SAFile) fopen( pszFilename, pszAccess );
 }
 
 /************************************************************************/
 /*                              SADFRead()                              */
-
 /************************************************************************/
 
-SAOffset SADFRead(void *p, SAOffset size, SAOffset nmemb, SAFile file)
+SAOffset SADFRead( void *p, SAOffset size, SAOffset nmemb, SAFile file )
+
 {
-    return (SAOffset) fread(p, (size_t) size, (size_t) nmemb, (FILE *) file);
+    return (SAOffset) fread( p, (size_t) size, (size_t) nmemb, 
+                             (FILE *) file );
 }
 
 /************************************************************************/
 /*                             SADFWrite()                              */
-
 /************************************************************************/
 
-SAOffset SADFWrite(void *p, SAOffset size, SAOffset nmemb, SAFile file)
+SAOffset SADFWrite( void *p, SAOffset size, SAOffset nmemb, SAFile file )
+
 {
-    return (SAOffset) fwrite(p, (size_t) size, (size_t) nmemb, (FILE *) file);
+    return (SAOffset) fwrite( p, (size_t) size, (size_t) nmemb, 
+                              (FILE *) file );
 }
 
 /************************************************************************/
 /*                              SADFSeek()                              */
-
 /************************************************************************/
 
-SAOffset SADFSeek(SAFile file, SAOffset offset, int whence)
+SAOffset SADFSeek( SAFile file, SAOffset offset, int whence )
+
 {
-    return (SAOffset) fseek((FILE *) file, (long)offset, whence);
+    return (SAOffset) fseek( (FILE *) file, (long) offset, whence );
 }
 
 /************************************************************************/
 /*                              SADFTell()                              */
-
 /************************************************************************/
 
-SAOffset SADFTell(SAFile file)
+SAOffset SADFTell( SAFile file )
+
 {
-    return (SAOffset) ftell((FILE *) file);
+    return (SAOffset) ftell( (FILE *) file );
 }
 
 /************************************************************************/
 /*                             SADFFlush()                              */
-
 /************************************************************************/
 
-int SADFFlush(SAFile file)
+int SADFFlush( SAFile file )
+
 {
-    return fflush((FILE *) file);
+    return fflush( (FILE *) file );
 }
 
 /************************************************************************/
 /*                             SADFClose()                              */
-
 /************************************************************************/
 
-int SADFClose(SAFile file)
+int SADFClose( SAFile file )
+
 {
-    return fclose((FILE *) file);
+    return fclose( (FILE *) file );
 }
 
 /************************************************************************/
 /*                             SADFClose()                              */
-
 /************************************************************************/
 
-int SADRemove(const char *filename)
+int SADRemove( const char *filename )
+
 {
-    return remove(filename);
+    return remove( filename );
 }
 
 /************************************************************************/
 /*                              SADError()                              */
-
 /************************************************************************/
 
-void SADError(const char *message)
+void SADError( const char *message )
+
 {
-    fprintf(stderr, "%s\n", message);
+    fprintf( stderr, "%s\n", message );
 }
 
 /************************************************************************/
 /*                        SASetupDefaultHooks()                         */
-
 /************************************************************************/
 
-void SASetupDefaultHooks(SAHooks * psHooks)
+void SASetupDefaultHooks( SAHooks *psHooks )
+
 {
-    psHooks->FOpen = SADFOpen;
-    psHooks->FRead = SADFRead;
-    psHooks->FWrite = SADFWrite;
-    psHooks->FSeek = SADFSeek;
-    psHooks->FTell = SADFTell;
-    psHooks->FFlush = SADFFlush;
-    psHooks->FClose = SADFClose;
+    psHooks->FOpen   = SADFOpen;
+    psHooks->FRead   = SADFRead;
+    psHooks->FWrite  = SADFWrite;
+    psHooks->FSeek   = SADFSeek;
+    psHooks->FTell   = SADFTell;
+    psHooks->FFlush  = SADFFlush;
+    psHooks->FClose  = SADFClose;
 
-    psHooks->Error = SADError;
+    psHooks->Error   = SADError;
 }
 
 
@@ -192,65 +193,64 @@
 
 /************************************************************************/
 /*                          Utf8ToWideChar                              */
-
 /************************************************************************/
 
-const wchar_t *Utf8ToWideChar(const char *pszFilename)
+const wchar_t* Utf8ToWideChar( const char *pszFilename )
 {
     int nMulti, nWide;
     wchar_t *pwszFileName;
-
+    
     nMulti = strlen(pszFilename) + 1;
-    nWide = MultiByteToWideChar(CP_UTF8, 0, pszFilename, nMulti, 0, 0);
-    if (nWide == 0) {
-	return NULL;
+    nWide = MultiByteToWideChar( CP_UTF8, 0, pszFilename, nMulti, 0, 0);
+    if( nWide == 0 )
+    {
+        return NULL;
     }
-    pwszFileName = (wchar_t *) malloc(nWide * sizeof(wchar_t));
-    if (pwszFileName == NULL) {
-	return NULL;
+    pwszFileName = (wchar_t*) malloc(nWide * sizeof(wchar_t));
+    if ( pwszFileName == NULL )
+    {
+        return NULL;
     }
-    if (MultiByteToWideChar
-	(CP_UTF8, 0, pszFilename, nMulti, pwszFileName, nWide) == 0) {
-	free(pwszFileName);
-	return NULL;
+    if( MultiByteToWideChar( CP_UTF8, 0, pszFilename, nMulti, pwszFileName, nWide ) == 0 )
+    {
+        free( pwszFileName );
+        return NULL;
     }
     return pwszFileName;
 }
 
 /************************************************************************/
 /*                           SAUtf8WFOpen                               */
-
 /************************************************************************/
 
-SAFile SAUtf8WFOpen(const char *pszFilename, const char *pszAccess)
+SAFile SAUtf8WFOpen( const char *pszFilename, const char *pszAccess )
 {
     SAFile file = NULL;
     const wchar_t *pwszFileName, *pwszAccess;
-
-    pwszFileName = Utf8ToWideChar(pszFilename);
-    pwszAccess = Utf8ToWideChar(pszAccess);
-    if (pwszFileName != NULL && pwszFileName != NULL) {
-	file = (SAFile) _wfopen(pwszFileName, pwszAccess);
+    pwszFileName = Utf8ToWideChar( pszFilename );
+    pwszAccess = Utf8ToWideChar( pszAccess );
+    if( pwszFileName != NULL && pwszFileName != NULL)
+    {
+        file = (SAFile) _wfopen( pwszFileName, pwszAccess );
     }
-    free((wchar_t *) pwszFileName);
-    free((wchar_t *) pwszAccess);
+    free ((wchar_t*) pwszFileName);
+    free ((wchar_t*) pwszAccess);
     return file;
 }
 
 /************************************************************************/
 /*                             SAUtf8WRemove()                          */
-
 /************************************************************************/
 
-int SAUtf8WRemove(const char *pszFilename)
+int SAUtf8WRemove( const char *pszFilename )
 {
-    const wchar_t *pwszFileName = Utf8ToWideChar(pszFilename);
-    int rc = -1;
-
-    if (pwszFileName != NULL) {
-	rc = _wremove(pwszFileName);
+    const wchar_t *pwszFileName = Utf8ToWideChar( pszFilename );
+    int rc = -1; 
+    if( pwszFileName != NULL )
+    {
+        rc = _wremove( pwszFileName );
     }
-    free((wchar_t *) pwszFileName);
+    free ((wchar_t*) pwszFileName);
     return rc;
 }
 
@@ -260,26 +260,25 @@
 
 /************************************************************************/
 /*                          SASetupUtf8Hooks()                          */
-
 /************************************************************************/
 
-void SASetupUtf8Hooks(SAHooks * psHooks)
+void SASetupUtf8Hooks( SAHooks *psHooks )
 {
-#ifdef SHPAPI_WINDOWS
-    psHooks->FOpen = SAUtf8WFOpen;
-    psHooks->Remove = SAUtf8WRemove;
+#ifdef SHPAPI_WINDOWS    
+    psHooks->FOpen   = SAUtf8WFOpen;
+    psHooks->Remove  = SAUtf8WRemove;
 #else
 #   error "no implementations of UTF-8 hooks available for this platform"
 #endif
-    psHooks->FRead = SADFRead;
-    psHooks->FWrite = SADFWrite;
-    psHooks->FSeek = SADFSeek;
-    psHooks->FTell = SADFTell;
-    psHooks->FFlush = SADFFlush;
-    psHooks->FClose = SADFClose;
+    psHooks->FRead   = SADFRead;
+    psHooks->FWrite  = SADFWrite;
+    psHooks->FSeek   = SADFSeek;
+    psHooks->FTell   = SADFTell;
+    psHooks->FFlush  = SADFFlush;
+    psHooks->FClose  = SADFClose;
 
-    psHooks->Error = SADError;
-    psHooks->Atof = atof;
+    psHooks->Error   = SADError;
+    psHooks->Atof    = atof;
 }
 
 #endif

Modified: grass/trunk/lib/external/shapelib/shapefil.h
===================================================================
--- grass/trunk/lib/external/shapelib/shapefil.h	2008-08-06 19:30:45 UTC (rev 32581)
+++ grass/trunk/lib/external/shapelib/shapefil.h	2008-08-06 19:37:34 UTC (rev 32582)
@@ -108,57 +108,55 @@
 #endif
 
 #ifdef __cplusplus
-extern "C"
-{
+extern "C" {
 #endif
 
 /************************************************************************/
-    /*                        Configuration options.                        */
-
+/*                        Configuration options.                        */
 /************************************************************************/
 
-    /* -------------------------------------------------------------------- */
-    /*      Should the DBFReadStringAttribute() strip leading and           */
-    /*      trailing white space?                                           */
-    /* -------------------------------------------------------------------- */
+/* -------------------------------------------------------------------- */
+/*      Should the DBFReadStringAttribute() strip leading and           */
+/*      trailing white space?                                           */
+/* -------------------------------------------------------------------- */
 #define TRIM_DBF_WHITESPACE
 
-    /* -------------------------------------------------------------------- */
-    /*      Should we write measure values to the Multipatch object?        */
-    /*      Reportedly ArcView crashes if we do write it, so for now it     */
-    /*      is disabled.                                                    */
-    /* -------------------------------------------------------------------- */
+/* -------------------------------------------------------------------- */
+/*      Should we write measure values to the Multipatch object?        */
+/*      Reportedly ArcView crashes if we do write it, so for now it     */
+/*      is disabled.                                                    */
+/* -------------------------------------------------------------------- */
 #define DISABLE_MULTIPATCH_MEASURE
+    
+/* -------------------------------------------------------------------- */
+/*      SHPAPI_CALL                                                     */
+/*                                                                      */
+/*      The following two macros are present to allow forcing           */
+/*      various calling conventions on the Shapelib API.                */
+/*                                                                      */
+/*      To force __stdcall conventions (needed to call Shapelib         */
+/*      from Visual Basic and/or Dephi I believe) the makefile could    */
+/*      be modified to define:                                          */
+/*                                                                      */
+/*        /DSHPAPI_CALL=__stdcall                                       */
+/*                                                                      */
+/*      If it is desired to force export of the Shapelib API without    */
+/*      using the shapelib.def file, use the following definition.      */
+/*                                                                      */
+/*        /DSHAPELIB_DLLEXPORT                                          */
+/*                                                                      */
+/*      To get both at once it will be necessary to hack this           */
+/*      include file to define:                                         */
+/*                                                                      */
+/*        #define SHPAPI_CALL __declspec(dllexport) __stdcall           */
+/*        #define SHPAPI_CALL1 __declspec(dllexport) * __stdcall        */
+/*                                                                      */
+/*      The complexity of the situtation is partly caused by the        */
+/*      peculiar requirement of Visual C++ that __stdcall appear        */
+/*      after any "*"'s in the return value of a function while the     */
+/*      __declspec(dllexport) must appear before them.                  */
+/* -------------------------------------------------------------------- */
 
-    /* -------------------------------------------------------------------- */
-    /*      SHPAPI_CALL                                                     */
-    /*                                                                      */
-    /*      The following two macros are present to allow forcing           */
-    /*      various calling conventions on the Shapelib API.                */
-    /*                                                                      */
-    /*      To force __stdcall conventions (needed to call Shapelib         */
-    /*      from Visual Basic and/or Dephi I believe) the makefile could    */
-    /*      be modified to define:                                          */
-    /*                                                                      */
-    /*        /DSHPAPI_CALL=__stdcall                                       */
-    /*                                                                      */
-    /*      If it is desired to force export of the Shapelib API without    */
-    /*      using the shapelib.def file, use the following definition.      */
-    /*                                                                      */
-    /*        /DSHAPELIB_DLLEXPORT                                          */
-    /*                                                                      */
-    /*      To get both at once it will be necessary to hack this           */
-    /*      include file to define:                                         */
-    /*                                                                      */
-    /*        #define SHPAPI_CALL __declspec(dllexport) __stdcall           */
-    /*        #define SHPAPI_CALL1 __declspec(dllexport) * __stdcall        */
-    /*                                                                      */
-    /*      The complexity of the situtation is partly caused by the        */
-    /*      peculiar requirement of Visual C++ that __stdcall appear        */
-    /*      after any "*"'s in the return value of a function while the     */
-    /*      __declspec(dllexport) must appear before them.                  */
-    /* -------------------------------------------------------------------- */
-
 #ifdef SHAPELIB_DLLEXPORT
 #  define SHPAPI_CALL __declspec(dllexport)
 #  define SHPAPI_CALL1(x)  __declspec(dllexport) x
@@ -176,78 +174,74 @@
 #ifndef SHPAPI_CALL1
 #  define SHPAPI_CALL1(x)      x SHPAPI_CALL
 #endif
-
-    /* -------------------------------------------------------------------- */
-    /*      Macros for controlling CVSID and ensuring they don't appear     */
-    /*      as unreferenced variables resulting in lots of warnings.        */
-    /* -------------------------------------------------------------------- */
+    
+/* -------------------------------------------------------------------- */
+/*      Macros for controlling CVSID and ensuring they don't appear     */
+/*      as unreferenced variables resulting in lots of warnings.        */
+/* -------------------------------------------------------------------- */
 #ifndef DISABLE_CVSID
 #  define SHP_CVSID(string)     static char cpl_cvsid[] = string; \
 static char *cvsid_aw() { return( cvsid_aw() ? ((char *) NULL) : cpl_cvsid ); }
 #else
 #  define SHP_CVSID(string)
 #endif
+    
+/* -------------------------------------------------------------------- */
+/*      IO/Error hook functions.                                        */
+/* -------------------------------------------------------------------- */
+typedef int *SAFile;
 
-    /* -------------------------------------------------------------------- */
-    /*      IO/Error hook functions.                                        */
-    /* -------------------------------------------------------------------- */
-    typedef int *SAFile;
-
 #ifndef SAOffset
-    typedef unsigned long SAOffset;
+typedef unsigned long SAOffset;
 #endif
 
-    typedef struct
-    {
-	SAFile(*FOpen) (const char *filename, const char *path);
-	SAOffset(*FRead) (void *p, SAOffset size, SAOffset nmemb,
-			  SAFile file);
-	SAOffset(*FWrite) (void *p, SAOffset size, SAOffset nmemb,
-			   SAFile file);
-	SAOffset(*FSeek) (SAFile file, SAOffset offset, int whence);
-	SAOffset(*FTell) (SAFile file);
-	int (*FFlush) (SAFile file);
-	int (*FClose) (SAFile file);
+typedef struct {
+    SAFile     (*FOpen) ( const char *filename, const char *path);
+    SAOffset   (*FRead) ( void *p, SAOffset size, SAOffset nmemb, SAFile file);
+    SAOffset   (*FWrite)( void *p, SAOffset size, SAOffset nmemb, SAFile file);
+    SAOffset   (*FSeek) ( SAFile file, SAOffset offset, int whence );
+    SAOffset   (*FTell) ( SAFile file );
+    int        (*FFlush)( SAFile file );
+    int        (*FClose)( SAFile file );
 
-	void (*Error) (const char *message);
-    } SAHooks;
+    void       (*Error) ( const char *message );
+} SAHooks;
 
-    void SHPAPI_CALL SASetupDefaultHooks(SAHooks * psHooks);
+void SHPAPI_CALL SASetupDefaultHooks( SAHooks *psHooks );
 
 /************************************************************************/
-    /*                             SHP Support.                             */
-
+/*                             SHP Support.                             */
 /************************************************************************/
-    typedef struct
-    {
-	SAHooks sHooks;
+typedef	struct
+{
+    SAHooks sHooks;
 
-	SAFile fpSHP;
-	SAFile fpSHX;
+    SAFile      fpSHP;
+    SAFile 	fpSHX;
 
-	int nShapeType;		/* SHPT_* */
+    int		nShapeType;				/* SHPT_* */
+    
+    int		nFileSize;				/* SHP file */
 
-	int nFileSize;		/* SHP file */
+    int         nRecords;
+    int		nMaxRecords;
+    int		*panRecOffset;
+    int		*panRecSize;
 
-	int nRecords;
-	int nMaxRecords;
-	int *panRecOffset;
-	int *panRecSize;
+    double	adBoundsMin[4];
+    double	adBoundsMax[4];
 
-	double adBoundsMin[4];
-	double adBoundsMax[4];
+    int		bUpdated;
 
-	int bUpdated;
+    unsigned char *pabyRec;
+    int         nBufSize;
+} SHPInfo;
 
-	unsigned char *pabyRec;
-	int nBufSize;
-    } SHPInfo;
+typedef SHPInfo * SHPHandle;
 
-    typedef SHPInfo *SHPHandle;
-
-    /* -------------------------------------------------------------------- */
-    /*      Shape types (nSHPType)                                          */
-    /* -------------------------------------------------------------------- */
+/* -------------------------------------------------------------------- */
+/*      Shape types (nSHPType)                                          */
+/* -------------------------------------------------------------------- */
 #define SHPT_NULL	0
 #define SHPT_POINT	1
 #define SHPT_ARC	3
@@ -264,10 +258,10 @@
 #define SHPT_MULTIPATCH 31
 
 
-    /* -------------------------------------------------------------------- */
-    /*      Part types - everything but SHPT_MULTIPATCH just uses           */
-    /*      SHPP_RING.                                                      */
-    /* -------------------------------------------------------------------- */
+/* -------------------------------------------------------------------- */
+/*      Part types - everything but SHPT_MULTIPATCH just uses           */
+/*      SHPP_RING.                                                      */
+/* -------------------------------------------------------------------- */
 
 #define SHPP_TRISTRIP	0
 #define SHPP_TRIFAN	1
@@ -276,277 +270,289 @@
 #define SHPP_FIRSTRING	4
 #define SHPP_RING	5
 
-    /* -------------------------------------------------------------------- */
-    /*      SHPObject - represents on shape (without attributes) read       */
-    /*      from the .shp file.                                             */
-    /* -------------------------------------------------------------------- */
-    typedef struct
-    {
-	int nSHPType;
+/* -------------------------------------------------------------------- */
+/*      SHPObject - represents on shape (without attributes) read       */
+/*      from the .shp file.                                             */
+/* -------------------------------------------------------------------- */
+typedef struct
+{
+    int		nSHPType;
 
-	int nShapeId;		/* -1 is unknown/unassigned */
+    int		nShapeId; /* -1 is unknown/unassigned */
 
-	int nParts;
-	int *panPartStart;
-	int *panPartType;
+    int		nParts;
+    int		*panPartStart;
+    int		*panPartType;
+    
+    int		nVertices;
+    double	*padfX;
+    double	*padfY;
+    double	*padfZ;
+    double	*padfM;
 
-	int nVertices;
-	double *padfX;
-	double *padfY;
-	double *padfZ;
-	double *padfM;
+    double	dfXMin;
+    double	dfYMin;
+    double	dfZMin;
+    double	dfMMin;
 
-	double dfXMin;
-	double dfYMin;
-	double dfZMin;
-	double dfMMin;
+    double	dfXMax;
+    double	dfYMax;
+    double	dfZMax;
+    double	dfMMax;
 
-	double dfXMax;
-	double dfYMax;
-	double dfZMax;
-	double dfMMax;
+    int		bMeasureIsUsed;
+} SHPObject;
 
-	int bMeasureIsUsed;
-    } SHPObject;
+/* -------------------------------------------------------------------- */
+/*      SHP API Prototypes                                              */
+/* -------------------------------------------------------------------- */
 
-    /* -------------------------------------------------------------------- */
-    /*      SHP API Prototypes                                              */
-    /* -------------------------------------------------------------------- */
+/* If pszAccess is read-only, the fpSHX field of the returned structure */
+/* will be NULL as it is not necessary to keep the SHX file open */
+SHPHandle SHPAPI_CALL
+      SHPOpen( const char * pszShapeFile, const char * pszAccess );
+SHPHandle SHPAPI_CALL
+      SHPOpenLL( const char *pszShapeFile, const char *pszAccess, 
+                 SAHooks *psHooks );
+SHPHandle SHPAPI_CALL
+      SHPCreate( const char * pszShapeFile, int nShapeType );
+SHPHandle SHPAPI_CALL
+      SHPCreateLL( const char * pszShapeFile, int nShapeType,
+                   SAHooks *psHooks );
+void SHPAPI_CALL
+      SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType,
+                  double * padfMinBound, double * padfMaxBound );
 
-    /* If pszAccess is read-only, the fpSHX field of the returned structure */
-    /* will be NULL as it is not necessary to keep the SHX file open */
-    SHPHandle SHPAPI_CALL
-	SHPOpen(const char *pszShapeFile, const char *pszAccess);
-    SHPHandle SHPAPI_CALL
-	SHPOpenLL(const char *pszShapeFile, const char *pszAccess,
-		  SAHooks * psHooks);
-    SHPHandle SHPAPI_CALL SHPCreate(const char *pszShapeFile, int nShapeType);
-    SHPHandle SHPAPI_CALL
-	SHPCreateLL(const char *pszShapeFile, int nShapeType,
-		    SAHooks * psHooks);
-    void SHPAPI_CALL
-	SHPGetInfo(SHPHandle hSHP, int *pnEntities, int *pnShapeType,
-		   double *padfMinBound, double *padfMaxBound);
+SHPObject SHPAPI_CALL1(*)
+      SHPReadObject( SHPHandle hSHP, int iShape );
+int SHPAPI_CALL
+      SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject * psObject );
 
-    SHPObject SHPAPI_CALL1(*)
-      SHPReadObject(SHPHandle hSHP, int iShape);
-    int SHPAPI_CALL
-	SHPWriteObject(SHPHandle hSHP, int iShape, SHPObject * psObject);
+void SHPAPI_CALL
+      SHPDestroyObject( SHPObject * psObject );
+void SHPAPI_CALL
+      SHPComputeExtents( SHPObject * psObject );
+SHPObject SHPAPI_CALL1(*)
+      SHPCreateObject( int nSHPType, int nShapeId, int nParts, 
+                       const int * panPartStart, const int * panPartType,
+                       int nVertices, 
+                       const double * padfX, const double * padfY,
+                       const double * padfZ, const double * padfM );
+SHPObject SHPAPI_CALL1(*)
+      SHPCreateSimpleObject( int nSHPType, int nVertices,
+                             const double * padfX, 
+                             const double * padfY, 
+                             const double * padfZ );
 
-    void SHPAPI_CALL SHPDestroyObject(SHPObject * psObject);
-    void SHPAPI_CALL SHPComputeExtents(SHPObject * psObject);
-    SHPObject SHPAPI_CALL1(*)
-     
-	SHPCreateObject(int nSHPType, int nShapeId, int nParts,
-			const int *panPartStart, const int *panPartType,
-			int nVertices,
-			const double *padfX, const double *padfY,
-			const double *padfZ, const double *padfM);
-    SHPObject SHPAPI_CALL1(*)
-     
-	SHPCreateSimpleObject(int nSHPType, int nVertices,
-			      const double *padfX,
-			      const double *padfY, const double *padfZ);
+int SHPAPI_CALL
+      SHPRewindObject( SHPHandle hSHP, SHPObject * psObject );
 
-    int SHPAPI_CALL SHPRewindObject(SHPHandle hSHP, SHPObject * psObject);
+void SHPAPI_CALL SHPClose( SHPHandle hSHP );
+void SHPAPI_CALL SHPWriteHeader( SHPHandle hSHP );
 
-    void SHPAPI_CALL SHPClose(SHPHandle hSHP);
-    void SHPAPI_CALL SHPWriteHeader(SHPHandle hSHP);
+const char SHPAPI_CALL1(*)
+      SHPTypeName( int nSHPType );
+const char SHPAPI_CALL1(*)
+      SHPPartTypeName( int nPartType );
 
-    const char SHPAPI_CALL1(*)
-      SHPTypeName(int nSHPType);
-    const char SHPAPI_CALL1(*)
-      SHPPartTypeName(int nPartType);
+/* -------------------------------------------------------------------- */
+/*      Shape quadtree indexing API.                                    */
+/* -------------------------------------------------------------------- */
 
-    /* -------------------------------------------------------------------- */
-    /*      Shape quadtree indexing API.                                    */
-    /* -------------------------------------------------------------------- */
-
-    /* this can be two or four for binary or quad tree */
+/* this can be two or four for binary or quad tree */
 #define MAX_SUBNODE	4
 
-    /* upper limit of tree levels for automatic estimation */
+/* upper limit of tree levels for automatic estimation */
 #define MAX_DEFAULT_TREE_DEPTH 12
 
-    typedef struct shape_tree_node
-    {
-	/* region covered by this node */
-	double adfBoundsMin[4];
-	double adfBoundsMax[4];
+typedef struct shape_tree_node
+{
+    /* region covered by this node */
+    double	adfBoundsMin[4];
+    double	adfBoundsMax[4];
 
-	/* list of shapes stored at this node.  The papsShapeObj pointers
-	   or the whole list can be NULL */
-	int nShapeCount;
-	int *panShapeIds;
-	SHPObject **papsShapeObj;
+    /* list of shapes stored at this node.  The papsShapeObj pointers
+       or the whole list can be NULL */
+    int		nShapeCount;
+    int		*panShapeIds;
+    SHPObject   **papsShapeObj;
 
-	int nSubNodes;
-	struct shape_tree_node *apsSubNode[MAX_SUBNODE];
+    int		nSubNodes;
+    struct shape_tree_node *apsSubNode[MAX_SUBNODE];
+    
+} SHPTreeNode;
 
-    } SHPTreeNode;
+typedef struct
+{
+    SHPHandle   hSHP;
+    
+    int		nMaxDepth;
+    int		nDimension;
+    int         nTotalCount;
+    
+    SHPTreeNode	*psRoot;
+} SHPTree;
 
-    typedef struct
-    {
-	SHPHandle hSHP;
+SHPTree SHPAPI_CALL1(*)
+      SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth,
+                     double *padfBoundsMin, double *padfBoundsMax );
+void    SHPAPI_CALL
+      SHPDestroyTree( SHPTree * hTree );
 
-	int nMaxDepth;
-	int nDimension;
-	int nTotalCount;
+int	SHPAPI_CALL
+      SHPWriteTree( SHPTree *hTree, const char * pszFilename );
+SHPTree SHPAPI_CALL
+      SHPReadTree( const char * pszFilename );
 
-	SHPTreeNode *psRoot;
-    } SHPTree;
+int	SHPAPI_CALL
+      SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject );
+int	SHPAPI_CALL
+      SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject );
+int	SHPAPI_CALL
+      SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId );
 
-    SHPTree SHPAPI_CALL1(*)
-     
-	SHPCreateTree(SHPHandle hSHP, int nDimension, int nMaxDepth,
-		      double *padfBoundsMin, double *padfBoundsMax);
-    void SHPAPI_CALL SHPDestroyTree(SHPTree * hTree);
+void 	SHPAPI_CALL
+      SHPTreeTrimExtraNodes( SHPTree * hTree );
 
-    int SHPAPI_CALL SHPWriteTree(SHPTree * hTree, const char *pszFilename);
-    SHPTree SHPAPI_CALL SHPReadTree(const char *pszFilename);
+int    SHPAPI_CALL1(*)
+      SHPTreeFindLikelyShapes( SHPTree * hTree,
+                               double * padfBoundsMin,
+                               double * padfBoundsMax,
+                               int * );
+int     SHPAPI_CALL
+      SHPCheckBoundsOverlap( double *, double *, double *, double *, int );
 
-    int SHPAPI_CALL SHPTreeAddObject(SHPTree * hTree, SHPObject * psObject);
-    int SHPAPI_CALL SHPTreeAddShapeId(SHPTree * hTree, SHPObject * psObject);
-    int SHPAPI_CALL SHPTreeRemoveShapeId(SHPTree * hTree, int nShapeId);
+int SHPAPI_CALL1(*) 
+SHPSearchDiskTree( FILE *fp, 
+                   double *padfBoundsMin, double *padfBoundsMax,
+                   int *pnShapeCount );
 
-    void SHPAPI_CALL SHPTreeTrimExtraNodes(SHPTree * hTree);
-
-    int SHPAPI_CALL1(*)
-     
-	SHPTreeFindLikelyShapes(SHPTree * hTree,
-				double *padfBoundsMin,
-				double *padfBoundsMax, int *);
-    int SHPAPI_CALL
-	SHPCheckBoundsOverlap(double *, double *, double *, double *, int);
-
-    int SHPAPI_CALL1(*)
-     
-	SHPSearchDiskTree(FILE * fp,
-			  double *padfBoundsMin, double *padfBoundsMax,
-			  int *pnShapeCount);
-
 /************************************************************************/
-    /*                             DBF Support.                             */
-
+/*                             DBF Support.                             */
 /************************************************************************/
-    typedef struct
-    {
-	SAHooks sHooks;
+typedef	struct
+{
+    SAHooks sHooks;
 
-	SAFile fp;
+    SAFile	fp;
 
-	int nRecords;
+    int         nRecords;
 
-	int nRecordLength;
-	int nHeaderLength;
-	int nFields;
-	int *panFieldOffset;
-	int *panFieldSize;
-	int *panFieldDecimals;
-	char *pachFieldType;
+    int		nRecordLength;
+    int		nHeaderLength;
+    int		nFields;
+    int		*panFieldOffset;
+    int		*panFieldSize;
+    int		*panFieldDecimals;
+    char	*pachFieldType;
 
-	char *pszHeader;
+    char	*pszHeader;
 
-	int nCurrentRecord;
-	int bCurrentRecordModified;
-	char *pszCurrentRecord;
+    int		nCurrentRecord;
+    int		bCurrentRecordModified;
+    char	*pszCurrentRecord;
 
-	int nWorkFieldLength;
-	char *pszWorkField;
+    int         nWorkFieldLength;
+    char        *pszWorkField;
+    
+    int		bNoHeader;
+    int		bUpdated;
 
-	int bNoHeader;
-	int bUpdated;
+    double      dfDoubleField;
+} DBFInfo;
 
-	double dfDoubleField;
-    } DBFInfo;
+typedef DBFInfo * DBFHandle;
 
-    typedef DBFInfo *DBFHandle;
+typedef enum {
+  FTString,
+  FTInteger,
+  FTDouble,
+  FTLogical,
+  FTInvalid
+} DBFFieldType;
 
-    typedef enum
-    {
-	FTString,
-	FTInteger,
-	FTDouble,
-	FTLogical,
-	FTInvalid
-    } DBFFieldType;
-
 #define XBASE_FLDHDR_SZ       32
 
 
-    DBFHandle SHPAPI_CALL
-	DBFOpen(const char *pszDBFFile, const char *pszAccess);
-    DBFHandle SHPAPI_CALL
-	DBFOpenLL(const char *pszDBFFile, const char *pszAccess,
-		  SAHooks * psHooks);
-    DBFHandle SHPAPI_CALL DBFCreate(const char *pszDBFFile);
-    DBFHandle SHPAPI_CALL
-	DBFCreateLL(const char *pszDBFFile, SAHooks * psHooks);
+DBFHandle SHPAPI_CALL
+      DBFOpen( const char * pszDBFFile, const char * pszAccess );
+DBFHandle SHPAPI_CALL
+      DBFOpenLL( const char * pszDBFFile, const char * pszAccess,
+                 SAHooks *psHooks );
+DBFHandle SHPAPI_CALL
+      DBFCreate( const char * pszDBFFile );
+DBFHandle SHPAPI_CALL
+      DBFCreateLL( const char * pszDBFFile, SAHooks *psHooks );
 
-    int SHPAPI_CALL DBFGetFieldCount(DBFHandle psDBF);
-    int SHPAPI_CALL DBFGetRecordCount(DBFHandle psDBF);
-    int SHPAPI_CALL
-	DBFAddField(DBFHandle hDBF, const char *pszFieldName,
-		    DBFFieldType eType, int nWidth, int nDecimals);
+int	SHPAPI_CALL
+      DBFGetFieldCount( DBFHandle psDBF );
+int	SHPAPI_CALL
+      DBFGetRecordCount( DBFHandle psDBF );
+int	SHPAPI_CALL
+      DBFAddField( DBFHandle hDBF, const char * pszFieldName,
+                   DBFFieldType eType, int nWidth, int nDecimals );
 
-    int SHPAPI_CALL
-	DBFAddNativeFieldType(DBFHandle hDBF, const char *pszFieldName,
-			      char chType, int nWidth, int nDecimals);
+int	SHPAPI_CALL
+      DBFAddNativeFieldType( DBFHandle hDBF, const char * pszFieldName,
+                             char chType, int nWidth, int nDecimals );
 
-    DBFFieldType SHPAPI_CALL
-	DBFGetFieldInfo(DBFHandle psDBF, int iField,
-			char *pszFieldName, int *pnWidth, int *pnDecimals);
+DBFFieldType SHPAPI_CALL
+      DBFGetFieldInfo( DBFHandle psDBF, int iField, 
+                       char * pszFieldName, int * pnWidth, int * pnDecimals );
 
-    int SHPAPI_CALL
-	DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName);
+int SHPAPI_CALL
+      DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName);
 
-    int SHPAPI_CALL
-	DBFReadIntegerAttribute(DBFHandle hDBF, int iShape, int iField);
-    double SHPAPI_CALL
-	DBFReadDoubleAttribute(DBFHandle hDBF, int iShape, int iField);
-    const char SHPAPI_CALL1(*)
-      DBFReadStringAttribute(DBFHandle hDBF, int iShape, int iField);
-    const char SHPAPI_CALL1(*)
-      DBFReadLogicalAttribute(DBFHandle hDBF, int iShape, int iField);
-    int SHPAPI_CALL
-	DBFIsAttributeNULL(DBFHandle hDBF, int iShape, int iField);
+int 	SHPAPI_CALL
+      DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField );
+double 	SHPAPI_CALL
+      DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField );
+const char SHPAPI_CALL1(*)
+      DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField );
+const char SHPAPI_CALL1(*)
+      DBFReadLogicalAttribute( DBFHandle hDBF, int iShape, int iField );
+int     SHPAPI_CALL
+      DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField );
 
-    int SHPAPI_CALL
-	DBFWriteIntegerAttribute(DBFHandle hDBF, int iShape, int iField,
-				 int nFieldValue);
-    int SHPAPI_CALL
-	DBFWriteDoubleAttribute(DBFHandle hDBF, int iShape, int iField,
-				double dFieldValue);
-    int SHPAPI_CALL
-	DBFWriteStringAttribute(DBFHandle hDBF, int iShape, int iField,
-				const char *pszFieldValue);
-    int SHPAPI_CALL
-	DBFWriteNULLAttribute(DBFHandle hDBF, int iShape, int iField);
+int SHPAPI_CALL
+      DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField, 
+                                int nFieldValue );
+int SHPAPI_CALL
+      DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField,
+                               double dFieldValue );
+int SHPAPI_CALL
+      DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField,
+                               const char * pszFieldValue );
+int SHPAPI_CALL
+     DBFWriteNULLAttribute( DBFHandle hDBF, int iShape, int iField );
 
-    int SHPAPI_CALL
-	DBFWriteLogicalAttribute(DBFHandle hDBF, int iShape, int iField,
-				 const char lFieldValue);
-    int SHPAPI_CALL
-	DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField,
-				  void *pValue);
-    const char SHPAPI_CALL1(*)
-      DBFReadTuple(DBFHandle psDBF, int hEntity);
-    int SHPAPI_CALL
-	DBFWriteTuple(DBFHandle psDBF, int hEntity, void *pRawTuple);
+int SHPAPI_CALL
+     DBFWriteLogicalAttribute( DBFHandle hDBF, int iShape, int iField,
+			       const char lFieldValue);
+int SHPAPI_CALL
+     DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField,
+                               void * pValue );
+const char SHPAPI_CALL1(*)
+      DBFReadTuple(DBFHandle psDBF, int hEntity );
+int SHPAPI_CALL
+      DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple );
 
-    int SHPAPI_CALL DBFIsRecordDeleted(DBFHandle psDBF, int iShape);
-    int SHPAPI_CALL DBFMarkRecordDeleted(DBFHandle psDBF, int iShape,
-					 int bIsDeleted);
+int SHPAPI_CALL DBFIsRecordDeleted( DBFHandle psDBF, int iShape );
+int SHPAPI_CALL DBFMarkRecordDeleted( DBFHandle psDBF, int iShape, 
+                                      int bIsDeleted );
 
-    DBFHandle SHPAPI_CALL
-	DBFCloneEmpty(DBFHandle psDBF, const char *pszFilename);
+DBFHandle SHPAPI_CALL
+      DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename );
+ 
+void	SHPAPI_CALL
+      DBFClose( DBFHandle hDBF );
+void    SHPAPI_CALL
+      DBFUpdateHeader( DBFHandle hDBF );
+char    SHPAPI_CALL
+      DBFGetNativeFieldType( DBFHandle hDBF, int iField );
 
-    void SHPAPI_CALL DBFClose(DBFHandle hDBF);
-    void SHPAPI_CALL DBFUpdateHeader(DBFHandle hDBF);
-    char SHPAPI_CALL DBFGetNativeFieldType(DBFHandle hDBF, int iField);
-
 #ifdef __cplusplus
 }
 #endif
 
-#endif				/* ndef _SHAPEFILE_H_INCLUDED */
+#endif /* ndef _SHAPEFILE_H_INCLUDED */

Modified: grass/trunk/lib/external/shapelib/shpopen.c
===================================================================
--- grass/trunk/lib/external/shapelib/shpopen.c	2008-08-06 19:30:45 UTC (rev 32581)
+++ grass/trunk/lib/external/shapelib/shpopen.c	2008-08-06 19:37:34 UTC (rev 32582)
@@ -1,4 +1,3 @@
-
 /******************************************************************************
  * $Id$
  *
@@ -234,12 +233,12 @@
 
 SHP_CVSID("$Id$")
 
-     typedef unsigned char uchar;
+typedef unsigned char uchar;
 
 #if UINT_MAX == 65535
-     typedef long int32;
+typedef long	      int32;
 #else
-     typedef int int32;
+typedef int	      int32;
 #endif
 
 #ifndef FALSE
@@ -253,25 +252,26 @@
 #  define MAX(a,b)      ((a>b) ? a : b)
 #endif
 
-     static int bBigEndian;
+static int 	bBigEndian;
 
 
 /************************************************************************/
 /*                              SwapWord()                              */
 /*                                                                      */
 /*      Swap a 2, 4 or 8 byte word.                                     */
-
 /************************************************************************/
 
-     static void SwapWord(int length, void *wordP)
+static void	SwapWord( int length, void * wordP )
+
 {
-    int i;
-    uchar temp;
+    int		i;
+    uchar	temp;
 
-    for (i = 0; i < length / 2; i++) {
+    for( i=0; i < length/2; i++ )
+    {
 	temp = ((uchar *) wordP)[i];
-	((uchar *) wordP)[i] = ((uchar *) wordP)[length - i - 1];
-	((uchar *) wordP)[length - i - 1] = temp;
+	((uchar *)wordP)[i] = ((uchar *) wordP)[length-i-1];
+	((uchar *) wordP)[length-i-1] = temp;
     }
 }
 
@@ -280,166 +280,157 @@
 /*                                                                      */
 /*      A realloc cover function that will access a NULL pointer as     */
 /*      a valid input.                                                  */
-
 /************************************************************************/
 
-static void *SfRealloc(void *pMem, int nNewSize)
+static void * SfRealloc( void * pMem, int nNewSize )
+
 {
-    if (pMem == NULL)
-	return ((void *)malloc(nNewSize));
+    if( pMem == NULL )
+        return( (void *) malloc(nNewSize) );
     else
-	return ((void *)realloc(pMem, nNewSize));
+        return( (void *) realloc(pMem,nNewSize) );
 }
 
 /************************************************************************/
 /*                          SHPWriteHeader()                            */
 /*                                                                      */
-/*      Write out a header for the .shp and .shx files as well as the   */
-/*      contents of the index (.shx) file.                              */
-
+/*      Write out a header for the .shp and .shx files as well as the	*/
+/*	contents of the index (.shx) file.				*/
 /************************************************************************/
 
-void SHPWriteHeader(SHPHandle psSHP)
-{
-    uchar abyHeader[100];
-    int i;
-    int32 i32;
-    double dValue;
-    int32 *panSHX;
+void SHPWriteHeader( SHPHandle psSHP )
 
-    if (psSHP->fpSHX == NULL) {
-	psSHP->sHooks.Error("SHPWriteHeader failed : SHX file is closed");
-	return;
+{
+    uchar     	abyHeader[100];
+    int		i;
+    int32	i32;
+    double	dValue;
+    int32	*panSHX;
+    
+    if (psSHP->fpSHX == NULL)
+    {
+        psSHP->sHooks.Error( "SHPWriteHeader failed : SHX file is closed");
+        return;
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Prepare header block for .shp file.                             */
-    /* -------------------------------------------------------------------- */
-    for (i = 0; i < 100; i++)
-	abyHeader[i] = 0;
+/* -------------------------------------------------------------------- */
+/*      Prepare header block for .shp file.                             */
+/* -------------------------------------------------------------------- */
+    for( i = 0; i < 100; i++ )
+      abyHeader[i] = 0;
 
-    abyHeader[2] = 0x27;	/* magic cookie */
+    abyHeader[2] = 0x27;				/* magic cookie */
     abyHeader[3] = 0x0a;
 
-    i32 = psSHP->nFileSize / 2;	/* file size */
-    ByteCopy(&i32, abyHeader + 24, 4);
-    if (!bBigEndian)
-	SwapWord(4, abyHeader + 24);
+    i32 = psSHP->nFileSize/2;				/* file size */
+    ByteCopy( &i32, abyHeader+24, 4 );
+    if( !bBigEndian ) SwapWord( 4, abyHeader+24 );
+    
+    i32 = 1000;						/* version */
+    ByteCopy( &i32, abyHeader+28, 4 );
+    if( bBigEndian ) SwapWord( 4, abyHeader+28 );
+    
+    i32 = psSHP->nShapeType;				/* shape type */
+    ByteCopy( &i32, abyHeader+32, 4 );
+    if( bBigEndian ) SwapWord( 4, abyHeader+32 );
 
-    i32 = 1000;			/* version */
-    ByteCopy(&i32, abyHeader + 28, 4);
-    if (bBigEndian)
-	SwapWord(4, abyHeader + 28);
+    dValue = psSHP->adBoundsMin[0];			/* set bounds */
+    ByteCopy( &dValue, abyHeader+36, 8 );
+    if( bBigEndian ) SwapWord( 8, abyHeader+36 );
 
-    i32 = psSHP->nShapeType;	/* shape type */
-    ByteCopy(&i32, abyHeader + 32, 4);
-    if (bBigEndian)
-	SwapWord(4, abyHeader + 32);
-
-    dValue = psSHP->adBoundsMin[0];	/* set bounds */
-    ByteCopy(&dValue, abyHeader + 36, 8);
-    if (bBigEndian)
-	SwapWord(8, abyHeader + 36);
-
     dValue = psSHP->adBoundsMin[1];
-    ByteCopy(&dValue, abyHeader + 44, 8);
-    if (bBigEndian)
-	SwapWord(8, abyHeader + 44);
+    ByteCopy( &dValue, abyHeader+44, 8 );
+    if( bBigEndian ) SwapWord( 8, abyHeader+44 );
 
     dValue = psSHP->adBoundsMax[0];
-    ByteCopy(&dValue, abyHeader + 52, 8);
-    if (bBigEndian)
-	SwapWord(8, abyHeader + 52);
+    ByteCopy( &dValue, abyHeader+52, 8 );
+    if( bBigEndian ) SwapWord( 8, abyHeader+52 );
 
     dValue = psSHP->adBoundsMax[1];
-    ByteCopy(&dValue, abyHeader + 60, 8);
-    if (bBigEndian)
-	SwapWord(8, abyHeader + 60);
+    ByteCopy( &dValue, abyHeader+60, 8 );
+    if( bBigEndian ) SwapWord( 8, abyHeader+60 );
 
-    dValue = psSHP->adBoundsMin[2];	/* z */
-    ByteCopy(&dValue, abyHeader + 68, 8);
-    if (bBigEndian)
-	SwapWord(8, abyHeader + 68);
+    dValue = psSHP->adBoundsMin[2];			/* z */
+    ByteCopy( &dValue, abyHeader+68, 8 );
+    if( bBigEndian ) SwapWord( 8, abyHeader+68 );
 
     dValue = psSHP->adBoundsMax[2];
-    ByteCopy(&dValue, abyHeader + 76, 8);
-    if (bBigEndian)
-	SwapWord(8, abyHeader + 76);
+    ByteCopy( &dValue, abyHeader+76, 8 );
+    if( bBigEndian ) SwapWord( 8, abyHeader+76 );
 
-    dValue = psSHP->adBoundsMin[3];	/* m */
-    ByteCopy(&dValue, abyHeader + 84, 8);
-    if (bBigEndian)
-	SwapWord(8, abyHeader + 84);
+    dValue = psSHP->adBoundsMin[3];			/* m */
+    ByteCopy( &dValue, abyHeader+84, 8 );
+    if( bBigEndian ) SwapWord( 8, abyHeader+84 );
 
     dValue = psSHP->adBoundsMax[3];
-    ByteCopy(&dValue, abyHeader + 92, 8);
-    if (bBigEndian)
-	SwapWord(8, abyHeader + 92);
+    ByteCopy( &dValue, abyHeader+92, 8 );
+    if( bBigEndian ) SwapWord( 8, abyHeader+92 );
 
-    /* -------------------------------------------------------------------- */
-    /*      Write .shp file header.                                         */
-    /* -------------------------------------------------------------------- */
-    if (psSHP->sHooks.FSeek(psSHP->fpSHP, 0, 0) != 0
-	|| psSHP->sHooks.FWrite(abyHeader, 100, 1, psSHP->fpSHP) != 1) {
-	psSHP->sHooks.Error("Failure writing .shp header");
-	return;
+/* -------------------------------------------------------------------- */
+/*      Write .shp file header.                                         */
+/* -------------------------------------------------------------------- */
+    if( psSHP->sHooks.FSeek( psSHP->fpSHP, 0, 0 ) != 0 
+        || psSHP->sHooks.FWrite( abyHeader, 100, 1, psSHP->fpSHP ) != 1 )
+    {
+        psSHP->sHooks.Error( "Failure writing .shp header" );
+        return;
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Prepare, and write .shx file header.                            */
-    /* -------------------------------------------------------------------- */
-    i32 = (psSHP->nRecords * 2 * sizeof(int32) + 100) / 2;	/* file size */
-    ByteCopy(&i32, abyHeader + 24, 4);
-    if (!bBigEndian)
-	SwapWord(4, abyHeader + 24);
-
-    if (psSHP->sHooks.FSeek(psSHP->fpSHX, 0, 0) != 0
-	|| psSHP->sHooks.FWrite(abyHeader, 100, 1, psSHP->fpSHX) != 1) {
-	psSHP->sHooks.Error("Failure writing .shx header");
-	return;
+/* -------------------------------------------------------------------- */
+/*      Prepare, and write .shx file header.                            */
+/* -------------------------------------------------------------------- */
+    i32 = (psSHP->nRecords * 2 * sizeof(int32) + 100)/2;   /* file size */
+    ByteCopy( &i32, abyHeader+24, 4 );
+    if( !bBigEndian ) SwapWord( 4, abyHeader+24 );
+    
+    if( psSHP->sHooks.FSeek( psSHP->fpSHX, 0, 0 ) != 0 
+        || psSHP->sHooks.FWrite( abyHeader, 100, 1, psSHP->fpSHX ) != 1 )
+    {
+        psSHP->sHooks.Error( "Failure writing .shx header" );
+        return;
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Write out the .shx contents.                                    */
-    /* -------------------------------------------------------------------- */
+/* -------------------------------------------------------------------- */
+/*      Write out the .shx contents.                                    */
+/* -------------------------------------------------------------------- */
     panSHX = (int32 *) malloc(sizeof(int32) * 2 * psSHP->nRecords);
 
-    for (i = 0; i < psSHP->nRecords; i++) {
-	panSHX[i * 2] = psSHP->panRecOffset[i] / 2;
-	panSHX[i * 2 + 1] = psSHP->panRecSize[i] / 2;
-	if (!bBigEndian)
-	    SwapWord(4, panSHX + i * 2);
-	if (!bBigEndian)
-	    SwapWord(4, panSHX + i * 2 + 1);
+    for( i = 0; i < psSHP->nRecords; i++ )
+    {
+	panSHX[i*2  ] = psSHP->panRecOffset[i]/2;
+	panSHX[i*2+1] = psSHP->panRecSize[i]/2;
+	if( !bBigEndian ) SwapWord( 4, panSHX+i*2 );
+	if( !bBigEndian ) SwapWord( 4, panSHX+i*2+1 );
     }
 
-    if ((int)psSHP->sHooks.
-	FWrite(panSHX, sizeof(int32) * 2, psSHP->nRecords, psSHP->fpSHX)
-	!= psSHP->nRecords) {
-	psSHP->sHooks.Error("Failure writing .shx contents");
+    if( (int)psSHP->sHooks.FWrite( panSHX, sizeof(int32)*2, psSHP->nRecords, psSHP->fpSHX ) 
+        != psSHP->nRecords )
+    {
+        psSHP->sHooks.Error( "Failure writing .shx contents" );
     }
 
-    free(panSHX);
+    free( panSHX );
 
-    /* -------------------------------------------------------------------- */
-    /*      Flush to disk.                                                  */
-    /* -------------------------------------------------------------------- */
-    psSHP->sHooks.FFlush(psSHP->fpSHP);
-    psSHP->sHooks.FFlush(psSHP->fpSHX);
+/* -------------------------------------------------------------------- */
+/*      Flush to disk.                                                  */
+/* -------------------------------------------------------------------- */
+    psSHP->sHooks.FFlush( psSHP->fpSHP );
+    psSHP->sHooks.FFlush( psSHP->fpSHX );
 }
 
 /************************************************************************/
 /*                              SHPOpen()                               */
-
 /************************************************************************/
 
-SHPHandle SHPAPI_CALL SHPOpen(const char *pszLayer, const char *pszAccess)
+SHPHandle SHPAPI_CALL
+SHPOpen( const char * pszLayer, const char * pszAccess )
+
 {
     SAHooks sHooks;
 
-    SASetupDefaultHooks(&sHooks);
+    SASetupDefaultHooks( &sHooks );
 
-    return SHPOpenLL(pszLayer, pszAccess, &sHooks);
+    return SHPOpenLL( pszLayer, pszAccess, &sHooks );
 }
 
 /************************************************************************/
@@ -447,339 +438,343 @@
 /*                                                                      */
 /*      Open the .shp and .shx files based on the basename of the       */
 /*      files or either file name.                                      */
-
 /************************************************************************/
-
+   
 SHPHandle SHPAPI_CALL
-SHPOpenLL(const char *pszLayer, const char *pszAccess, SAHooks * psHooks)
-{
-    char *pszFullname, *pszBasename;
-    SHPHandle psSHP;
+SHPOpenLL( const char * pszLayer, const char * pszAccess, SAHooks *psHooks )
 
-    uchar *pabyBuf;
-    int i;
-    double dValue;
-
-    /* -------------------------------------------------------------------- */
-    /*      Ensure the access string is one of the legal ones.  We          */
-    /*      ensure the result string indicates binary to avoid common       */
-    /*      problems on Windows.                                            */
-    /* -------------------------------------------------------------------- */
-    if (strcmp(pszAccess, "rb+") == 0 || strcmp(pszAccess, "r+b") == 0
-	|| strcmp(pszAccess, "r+") == 0)
-	pszAccess = "r+b";
+{
+    char		*pszFullname, *pszBasename;
+    SHPHandle		psSHP;
+    
+    uchar		*pabyBuf;
+    int			i;
+    double		dValue;
+    
+/* -------------------------------------------------------------------- */
+/*      Ensure the access string is one of the legal ones.  We          */
+/*      ensure the result string indicates binary to avoid common       */
+/*      problems on Windows.                                            */
+/* -------------------------------------------------------------------- */
+    if( strcmp(pszAccess,"rb+") == 0 || strcmp(pszAccess,"r+b") == 0
+        || strcmp(pszAccess,"r+") == 0 )
+        pszAccess = "r+b";
     else
-	pszAccess = "rb";
-
-    /* -------------------------------------------------------------------- */
-    /*      Establish the byte order on this machine.                       */
-    /* -------------------------------------------------------------------- */
+        pszAccess = "rb";
+    
+/* -------------------------------------------------------------------- */
+/*	Establish the byte order on this machine.			*/
+/* -------------------------------------------------------------------- */
     i = 1;
-    if (*((uchar *) & i) == 1)
-	bBigEndian = FALSE;
+    if( *((uchar *) &i) == 1 )
+        bBigEndian = FALSE;
     else
-	bBigEndian = TRUE;
+        bBigEndian = TRUE;
 
-    /* -------------------------------------------------------------------- */
-    /*      Initialize the info structure.                                  */
-    /* -------------------------------------------------------------------- */
-    psSHP = (SHPHandle) calloc(sizeof(SHPInfo), 1);
+/* -------------------------------------------------------------------- */
+/*	Initialize the info structure.					*/
+/* -------------------------------------------------------------------- */
+    psSHP = (SHPHandle) calloc(sizeof(SHPInfo),1);
 
     psSHP->bUpdated = FALSE;
-    memcpy(&(psSHP->sHooks), psHooks, sizeof(SAHooks));
+    memcpy( &(psSHP->sHooks), psHooks, sizeof(SAHooks) );
 
-    /* -------------------------------------------------------------------- */
-    /*      Compute the base (layer) name.  If there is any extension       */
-    /*      on the passed in filename we will strip it off.                 */
-    /* -------------------------------------------------------------------- */
-    pszBasename = (char *)malloc(strlen(pszLayer) + 5);
-    strcpy(pszBasename, pszLayer);
-    for (i = strlen(pszBasename) - 1;
+/* -------------------------------------------------------------------- */
+/*	Compute the base (layer) name.  If there is any extension	*/
+/*	on the passed in filename we will strip it off.			*/
+/* -------------------------------------------------------------------- */
+    pszBasename = (char *) malloc(strlen(pszLayer)+5);
+    strcpy( pszBasename, pszLayer );
+    for( i = strlen(pszBasename)-1; 
 	 i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/'
-	 && pszBasename[i] != '\\'; i--) {
-    }
+	       && pszBasename[i] != '\\';
+	 i-- ) {}
 
-    if (pszBasename[i] == '.')
-	pszBasename[i] = '\0';
+    if( pszBasename[i] == '.' )
+        pszBasename[i] = '\0';
 
-    /* -------------------------------------------------------------------- */
-    /*      Open the .shp and .shx files.  Note that files pulled from      */
-    /*      a PC to Unix with upper case filenames won't work!              */
-    /* -------------------------------------------------------------------- */
-    pszFullname = (char *)malloc(strlen(pszBasename) + 5);
-    sprintf(pszFullname, "%s.shp", pszBasename);
-    psSHP->fpSHP = psSHP->sHooks.FOpen(pszFullname, pszAccess);
-    if (psSHP->fpSHP == NULL) {
-	sprintf(pszFullname, "%s.SHP", pszBasename);
-	psSHP->fpSHP = psSHP->sHooks.FOpen(pszFullname, pszAccess);
+/* -------------------------------------------------------------------- */
+/*	Open the .shp and .shx files.  Note that files pulled from	*/
+/*	a PC to Unix with upper case filenames won't work!		*/
+/* -------------------------------------------------------------------- */
+    pszFullname = (char *) malloc(strlen(pszBasename) + 5);
+    sprintf( pszFullname, "%s.shp", pszBasename ) ;
+    psSHP->fpSHP = psSHP->sHooks.FOpen(pszFullname, pszAccess );
+    if( psSHP->fpSHP == NULL )
+    {
+        sprintf( pszFullname, "%s.SHP", pszBasename );
+        psSHP->fpSHP = psSHP->sHooks.FOpen(pszFullname, pszAccess );
     }
-
-    if (psSHP->fpSHP == NULL) {
+    
+    if( psSHP->fpSHP == NULL )
+    {
 #ifdef USE_CPL
-	CPLError(CE_Failure, CPLE_OpenFailed,
-		 "Unable to open %s.shp or %s.SHP.",
-		 pszBasename, pszBasename);
+        CPLError( CE_Failure, CPLE_OpenFailed, 
+                  "Unable to open %s.shp or %s.SHP.", 
+                  pszBasename, pszBasename );
 #endif
-	free(psSHP);
-	free(pszBasename);
-	free(pszFullname);
-	return (NULL);
+        free( psSHP );
+        free( pszBasename );
+        free( pszFullname );
+        return( NULL );
     }
 
-    sprintf(pszFullname, "%s.shx", pszBasename);
-    psSHP->fpSHX = psSHP->sHooks.FOpen(pszFullname, pszAccess);
-    if (psSHP->fpSHX == NULL) {
-	sprintf(pszFullname, "%s.SHX", pszBasename);
-	psSHP->fpSHX = psSHP->sHooks.FOpen(pszFullname, pszAccess);
+    sprintf( pszFullname, "%s.shx", pszBasename );
+    psSHP->fpSHX =  psSHP->sHooks.FOpen(pszFullname, pszAccess );
+    if( psSHP->fpSHX == NULL )
+    {
+        sprintf( pszFullname, "%s.SHX", pszBasename );
+        psSHP->fpSHX = psSHP->sHooks.FOpen(pszFullname, pszAccess );
     }
-
-    if (psSHP->fpSHX == NULL) {
+    
+    if( psSHP->fpSHX == NULL )
+    {
 #ifdef USE_CPL
-	CPLError(CE_Failure, CPLE_OpenFailed,
-		 "Unable to open %s.shx or %s.SHX.",
-		 pszBasename, pszBasename);
+        CPLError( CE_Failure, CPLE_OpenFailed, 
+                  "Unable to open %s.shx or %s.SHX.", 
+                  pszBasename, pszBasename );
 #endif
-	psSHP->sHooks.FClose(psSHP->fpSHP);
-	free(psSHP);
-	free(pszBasename);
-	free(pszFullname);
-	return (NULL);
+        psSHP->sHooks.FClose( psSHP->fpSHP );
+        free( psSHP );
+        free( pszBasename );
+        free( pszFullname );
+        return( NULL );
     }
 
-    free(pszFullname);
-    free(pszBasename);
+    free( pszFullname );
+    free( pszBasename );
 
-    /* -------------------------------------------------------------------- */
-    /*  Read the file size from the SHP file.                               */
-    /* -------------------------------------------------------------------- */
+/* -------------------------------------------------------------------- */
+/*  Read the file size from the SHP file.				*/
+/* -------------------------------------------------------------------- */
     pabyBuf = (uchar *) malloc(100);
-    psSHP->sHooks.FRead(pabyBuf, 100, 1, psSHP->fpSHP);
+    psSHP->sHooks.FRead( pabyBuf, 100, 1, psSHP->fpSHP );
 
     psSHP->nFileSize = (pabyBuf[24] * 256 * 256 * 256
 			+ pabyBuf[25] * 256 * 256
-			+ pabyBuf[26] * 256 + pabyBuf[27]) * 2;
+			+ pabyBuf[26] * 256
+			+ pabyBuf[27]) * 2;
 
-    /* -------------------------------------------------------------------- */
-    /*  Read SHX file Header info                                           */
-    /* -------------------------------------------------------------------- */
-    if (psSHP->sHooks.FRead(pabyBuf, 100, 1, psSHP->fpSHX) != 1
-	|| pabyBuf[0] != 0
-	|| pabyBuf[1] != 0
-	|| pabyBuf[2] != 0x27 || (pabyBuf[3] != 0x0a && pabyBuf[3] != 0x0d)) {
-	psSHP->sHooks.Error(".shx file is unreadable, or corrupt.");
-	psSHP->sHooks.FClose(psSHP->fpSHP);
-	psSHP->sHooks.FClose(psSHP->fpSHX);
-	free(psSHP);
+/* -------------------------------------------------------------------- */
+/*  Read SHX file Header info                                           */
+/* -------------------------------------------------------------------- */
+    if( psSHP->sHooks.FRead( pabyBuf, 100, 1, psSHP->fpSHX ) != 1 
+        || pabyBuf[0] != 0 
+        || pabyBuf[1] != 0 
+        || pabyBuf[2] != 0x27 
+        || (pabyBuf[3] != 0x0a && pabyBuf[3] != 0x0d) )
+    {
+        psSHP->sHooks.Error( ".shx file is unreadable, or corrupt." );
+	psSHP->sHooks.FClose( psSHP->fpSHP );
+	psSHP->sHooks.FClose( psSHP->fpSHX );
+	free( psSHP );
 
-	return (NULL);
+	return( NULL );
     }
 
     psSHP->nRecords = pabyBuf[27] + pabyBuf[26] * 256
-	+ pabyBuf[25] * 256 * 256 + pabyBuf[24] * 256 * 256 * 256;
-    psSHP->nRecords = (psSHP->nRecords * 2 - 100) / 8;
+      + pabyBuf[25] * 256 * 256 + pabyBuf[24] * 256 * 256 * 256;
+    psSHP->nRecords = (psSHP->nRecords*2 - 100) / 8;
 
     psSHP->nShapeType = pabyBuf[32];
 
-    if (psSHP->nRecords < 0 || psSHP->nRecords > 256000000) {
-	char szError[200];
+    if( psSHP->nRecords < 0 || psSHP->nRecords > 256000000 )
+    {
+        char szError[200];
+        
+        sprintf( szError, 
+                 "Record count in .shp header is %d, which seems\n"
+                 "unreasonable.  Assuming header is corrupt.",
+                  psSHP->nRecords );
+        psSHP->sHooks.Error( szError );				       
+	psSHP->sHooks.FClose( psSHP->fpSHP );
+	psSHP->sHooks.FClose( psSHP->fpSHX );
+	free( psSHP );
+        free(pabyBuf);
 
-	sprintf(szError,
-		"Record count in .shp header is %d, which seems\n"
-		"unreasonable.  Assuming header is corrupt.",
-		psSHP->nRecords);
-	psSHP->sHooks.Error(szError);
-	psSHP->sHooks.FClose(psSHP->fpSHP);
-	psSHP->sHooks.FClose(psSHP->fpSHX);
-	free(psSHP);
-	free(pabyBuf);
-
-	return (NULL);
+	return( NULL );
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Read the bounds.                                                */
-    /* -------------------------------------------------------------------- */
-    if (bBigEndian)
-	SwapWord(8, pabyBuf + 36);
-    memcpy(&dValue, pabyBuf + 36, 8);
+/* -------------------------------------------------------------------- */
+/*      Read the bounds.                                                */
+/* -------------------------------------------------------------------- */
+    if( bBigEndian ) SwapWord( 8, pabyBuf+36 );
+    memcpy( &dValue, pabyBuf+36, 8 );
     psSHP->adBoundsMin[0] = dValue;
 
-    if (bBigEndian)
-	SwapWord(8, pabyBuf + 44);
-    memcpy(&dValue, pabyBuf + 44, 8);
+    if( bBigEndian ) SwapWord( 8, pabyBuf+44 );
+    memcpy( &dValue, pabyBuf+44, 8 );
     psSHP->adBoundsMin[1] = dValue;
 
-    if (bBigEndian)
-	SwapWord(8, pabyBuf + 52);
-    memcpy(&dValue, pabyBuf + 52, 8);
+    if( bBigEndian ) SwapWord( 8, pabyBuf+52 );
+    memcpy( &dValue, pabyBuf+52, 8 );
     psSHP->adBoundsMax[0] = dValue;
 
-    if (bBigEndian)
-	SwapWord(8, pabyBuf + 60);
-    memcpy(&dValue, pabyBuf + 60, 8);
+    if( bBigEndian ) SwapWord( 8, pabyBuf+60 );
+    memcpy( &dValue, pabyBuf+60, 8 );
     psSHP->adBoundsMax[1] = dValue;
 
-    if (bBigEndian)
-	SwapWord(8, pabyBuf + 68);	/* z */
-    memcpy(&dValue, pabyBuf + 68, 8);
+    if( bBigEndian ) SwapWord( 8, pabyBuf+68 );		/* z */
+    memcpy( &dValue, pabyBuf+68, 8 );
     psSHP->adBoundsMin[2] = dValue;
-
-    if (bBigEndian)
-	SwapWord(8, pabyBuf + 76);
-    memcpy(&dValue, pabyBuf + 76, 8);
+    
+    if( bBigEndian ) SwapWord( 8, pabyBuf+76 );
+    memcpy( &dValue, pabyBuf+76, 8 );
     psSHP->adBoundsMax[2] = dValue;
-
-    if (bBigEndian)
-	SwapWord(8, pabyBuf + 84);	/* z */
-    memcpy(&dValue, pabyBuf + 84, 8);
+    
+    if( bBigEndian ) SwapWord( 8, pabyBuf+84 );		/* z */
+    memcpy( &dValue, pabyBuf+84, 8 );
     psSHP->adBoundsMin[3] = dValue;
 
-    if (bBigEndian)
-	SwapWord(8, pabyBuf + 92);
-    memcpy(&dValue, pabyBuf + 92, 8);
+    if( bBigEndian ) SwapWord( 8, pabyBuf+92 );
+    memcpy( &dValue, pabyBuf+92, 8 );
     psSHP->adBoundsMax[3] = dValue;
 
-    free(pabyBuf);
+    free( pabyBuf );
 
-    /* -------------------------------------------------------------------- */
-    /*      Read the .shx file to get the offsets to each record in         */
-    /*      the .shp file.                                                  */
-    /* -------------------------------------------------------------------- */
+/* -------------------------------------------------------------------- */
+/*	Read the .shx file to get the offsets to each record in 	*/
+/*	the .shp file.							*/
+/* -------------------------------------------------------------------- */
     psSHP->nMaxRecords = psSHP->nRecords;
 
     psSHP->panRecOffset =
-	(int *)malloc(sizeof(int) * MAX(1, psSHP->nMaxRecords));
+        (int *) malloc(sizeof(int) * MAX(1,psSHP->nMaxRecords) );
     psSHP->panRecSize =
-	(int *)malloc(sizeof(int) * MAX(1, psSHP->nMaxRecords));
-    pabyBuf = (uchar *) malloc(8 * MAX(1, psSHP->nRecords));
+        (int *) malloc(sizeof(int) * MAX(1,psSHP->nMaxRecords) );
+    pabyBuf = (uchar *) malloc(8 * MAX(1,psSHP->nRecords) );
 
     if (psSHP->panRecOffset == NULL ||
-	psSHP->panRecSize == NULL || pabyBuf == NULL) {
-	char szError[200];
+        psSHP->panRecSize == NULL ||
+        pabyBuf == NULL)
+    {
+        char szError[200];
 
-	sprintf(szError,
-		"Not enough memory to allocate requested memory (nRecords=%d).\n"
-		"Probably broken SHP file", psSHP->nRecords);
-	psSHP->sHooks.Error(szError);
-	psSHP->sHooks.FClose(psSHP->fpSHP);
-	psSHP->sHooks.FClose(psSHP->fpSHX);
-	if (psSHP->panRecOffset)
-	    free(psSHP->panRecOffset);
-	if (psSHP->panRecSize)
-	    free(psSHP->panRecSize);
-	if (pabyBuf)
-	    free(pabyBuf);
-	free(psSHP);
-	return (NULL);
+        sprintf(szError, 
+                "Not enough memory to allocate requested memory (nRecords=%d).\n"
+                "Probably broken SHP file", 
+                psSHP->nRecords );
+        psSHP->sHooks.Error( szError );
+	psSHP->sHooks.FClose( psSHP->fpSHP );
+	psSHP->sHooks.FClose( psSHP->fpSHX );
+        if (psSHP->panRecOffset) free( psSHP->panRecOffset );
+        if (psSHP->panRecSize) free( psSHP->panRecSize );
+        if (pabyBuf) free( pabyBuf );
+        free( psSHP );
+        return( NULL );
     }
 
-    if ((int)psSHP->sHooks.FRead(pabyBuf, 8, psSHP->nRecords, psSHP->fpSHX)
-	!= psSHP->nRecords) {
-	char szError[200];
+    if( (int) psSHP->sHooks.FRead( pabyBuf, 8, psSHP->nRecords, psSHP->fpSHX ) 
+			!= psSHP->nRecords )
+    {
+        char szError[200];
 
-	sprintf(szError,
-		"Failed to read all values for %d records in .shx file.",
-		psSHP->nRecords);
-	psSHP->sHooks.Error(szError);
+        sprintf( szError, 
+                 "Failed to read all values for %d records in .shx file.",
+                 psSHP->nRecords );
+        psSHP->sHooks.Error( szError );
 
-	/* SHX is short or unreadable for some reason. */
-	psSHP->sHooks.FClose(psSHP->fpSHP);
-	psSHP->sHooks.FClose(psSHP->fpSHX);
-	free(psSHP->panRecOffset);
-	free(psSHP->panRecSize);
-	free(pabyBuf);
-	free(psSHP);
+        /* SHX is short or unreadable for some reason. */
+	psSHP->sHooks.FClose( psSHP->fpSHP );
+	psSHP->sHooks.FClose( psSHP->fpSHX );
+        free( psSHP->panRecOffset );
+        free( psSHP->panRecSize );
+        free( pabyBuf );
+	free( psSHP );
 
-	return (NULL);
+	return( NULL );
     }
-
+    
     /* In read-only mode, we can close the SHX now */
-    if (strcmp(pszAccess, "rb") == 0) {
-	psSHP->sHooks.FClose(psSHP->fpSHX);
-	psSHP->fpSHX = NULL;
+    if (strcmp(pszAccess, "rb") == 0)
+    {
+        psSHP->sHooks.FClose( psSHP->fpSHX );
+        psSHP->fpSHX = NULL;
     }
 
-    for (i = 0; i < psSHP->nRecords; i++) {
-	int32 nOffset, nLength;
+    for( i = 0; i < psSHP->nRecords; i++ )
+    {
+	int32		nOffset, nLength;
 
-	memcpy(&nOffset, pabyBuf + i * 8, 4);
-	if (!bBigEndian)
-	    SwapWord(4, &nOffset);
+	memcpy( &nOffset, pabyBuf + i * 8, 4 );
+	if( !bBigEndian ) SwapWord( 4, &nOffset );
 
-	memcpy(&nLength, pabyBuf + i * 8 + 4, 4);
-	if (!bBigEndian)
-	    SwapWord(4, &nLength);
+	memcpy( &nLength, pabyBuf + i * 8 + 4, 4 );
+	if( !bBigEndian ) SwapWord( 4, &nLength );
 
-	psSHP->panRecOffset[i] = nOffset * 2;
-	psSHP->panRecSize[i] = nLength * 2;
+	psSHP->panRecOffset[i] = nOffset*2;
+	psSHP->panRecSize[i] = nLength*2;
     }
-    free(pabyBuf);
+    free( pabyBuf );
 
-    return (psSHP);
+    return( psSHP );
 }
 
 /************************************************************************/
 /*                              SHPClose()                              */
-/*                                                                      */
-/*      Close the .shp and .shx files.                                  */
-
+/*								       	*/
+/*	Close the .shp and .shx files.					*/
 /************************************************************************/
 
-void SHPAPI_CALL SHPClose(SHPHandle psSHP)
+void SHPAPI_CALL
+SHPClose(SHPHandle psSHP )
+
 {
-    if (psSHP == NULL)
-	return;
+    if( psSHP == NULL )
+        return;
 
-    /* -------------------------------------------------------------------- */
-    /*      Update the header if we have modified anything.                 */
-    /* -------------------------------------------------------------------- */
-    if (psSHP->bUpdated)
-	SHPWriteHeader(psSHP);
+/* -------------------------------------------------------------------- */
+/*	Update the header if we have modified anything.			*/
+/* -------------------------------------------------------------------- */
+    if( psSHP->bUpdated )
+	SHPWriteHeader( psSHP );
 
-    /* -------------------------------------------------------------------- */
-    /*      Free all resources, and close files.                            */
-    /* -------------------------------------------------------------------- */
-    free(psSHP->panRecOffset);
-    free(psSHP->panRecSize);
+/* -------------------------------------------------------------------- */
+/*      Free all resources, and close files.                            */
+/* -------------------------------------------------------------------- */
+    free( psSHP->panRecOffset );
+    free( psSHP->panRecSize );
 
-    if (psSHP->fpSHX != NULL)
-	psSHP->sHooks.FClose(psSHP->fpSHX);
-    psSHP->sHooks.FClose(psSHP->fpSHP);
+    if ( psSHP->fpSHX != NULL)
+        psSHP->sHooks.FClose( psSHP->fpSHX );
+    psSHP->sHooks.FClose( psSHP->fpSHP );
 
-    if (psSHP->pabyRec != NULL) {
-	free(psSHP->pabyRec);
+    if( psSHP->pabyRec != NULL )
+    {
+        free( psSHP->pabyRec );
     }
-
-    free(psSHP);
+    
+    free( psSHP );
 }
 
 /************************************************************************/
 /*                             SHPGetInfo()                             */
 /*                                                                      */
 /*      Fetch general information about the shape file.                 */
-
 /************************************************************************/
 
 void SHPAPI_CALL
-SHPGetInfo(SHPHandle psSHP, int *pnEntities, int *pnShapeType,
-	   double *padfMinBound, double *padfMaxBound)
+SHPGetInfo(SHPHandle psSHP, int * pnEntities, int * pnShapeType,
+           double * padfMinBound, double * padfMaxBound )
+
 {
-    int i;
+    int		i;
 
-    if (psSHP == NULL)
-	return;
+    if( psSHP == NULL )
+        return;
+    
+    if( pnEntities != NULL )
+        *pnEntities = psSHP->nRecords;
 
-    if (pnEntities != NULL)
-	*pnEntities = psSHP->nRecords;
+    if( pnShapeType != NULL )
+        *pnShapeType = psSHP->nShapeType;
 
-    if (pnShapeType != NULL)
-	*pnShapeType = psSHP->nShapeType;
-
-    for (i = 0; i < 4; i++) {
-	if (padfMinBound != NULL)
-	    padfMinBound[i] = psSHP->adBoundsMin[i];
-	if (padfMaxBound != NULL)
-	    padfMaxBound[i] = psSHP->adBoundsMax[i];
+    for( i = 0; i < 4; i++ )
+    {
+        if( padfMinBound != NULL )
+            padfMinBound[i] = psSHP->adBoundsMin[i];
+        if( padfMaxBound != NULL )
+            padfMaxBound[i] = psSHP->adBoundsMax[i];
     }
 }
 
@@ -788,16 +783,17 @@
 /*                                                                      */
 /*      Create a new shape file and return a handle to the open         */
 /*      shape file with read/write access.                              */
-
 /************************************************************************/
 
-SHPHandle SHPAPI_CALL SHPCreate(const char *pszLayer, int nShapeType)
+SHPHandle SHPAPI_CALL
+SHPCreate( const char * pszLayer, int nShapeType )
+
 {
     SAHooks sHooks;
 
-    SASetupDefaultHooks(&sHooks);
+    SASetupDefaultHooks( &sHooks );
 
-    return SHPCreateLL(pszLayer, nShapeType, &sHooks);
+    return SHPCreateLL( pszLayer, nShapeType, &sHooks );
 }
 
 /************************************************************************/
@@ -805,121 +801,121 @@
 /*                                                                      */
 /*      Create a new shape file and return a handle to the open         */
 /*      shape file with read/write access.                              */
-
 /************************************************************************/
 
 SHPHandle SHPAPI_CALL
-SHPCreateLL(const char *pszLayer, int nShapeType, SAHooks * psHooks)
-{
-    char *pszBasename, *pszFullname;
-    int i;
-    SAFile fpSHP, fpSHX;
-    uchar abyHeader[100];
-    int32 i32;
-    double dValue;
+SHPCreateLL( const char * pszLayer, int nShapeType, SAHooks *psHooks )
 
-    /* -------------------------------------------------------------------- */
-    /*      Establish the byte order on this system.                        */
-    /* -------------------------------------------------------------------- */
+{
+    char	*pszBasename, *pszFullname;
+    int		i;
+    SAFile	fpSHP, fpSHX;
+    uchar     	abyHeader[100];
+    int32	i32;
+    double	dValue;
+    
+/* -------------------------------------------------------------------- */
+/*      Establish the byte order on this system.                        */
+/* -------------------------------------------------------------------- */
     i = 1;
-    if (*((uchar *) & i) == 1)
-	bBigEndian = FALSE;
+    if( *((uchar *) &i) == 1 )
+        bBigEndian = FALSE;
     else
-	bBigEndian = TRUE;
+        bBigEndian = TRUE;
 
-    /* -------------------------------------------------------------------- */
-    /*      Compute the base (layer) name.  If there is any extension       */
-    /*      on the passed in filename we will strip it off.                 */
-    /* -------------------------------------------------------------------- */
-    pszBasename = (char *)malloc(strlen(pszLayer) + 5);
-    strcpy(pszBasename, pszLayer);
-    for (i = strlen(pszBasename) - 1;
+/* -------------------------------------------------------------------- */
+/*	Compute the base (layer) name.  If there is any extension	*/
+/*	on the passed in filename we will strip it off.			*/
+/* -------------------------------------------------------------------- */
+    pszBasename = (char *) malloc(strlen(pszLayer)+5);
+    strcpy( pszBasename, pszLayer );
+    for( i = strlen(pszBasename)-1; 
 	 i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/'
-	 && pszBasename[i] != '\\'; i--) {
-    }
+	       && pszBasename[i] != '\\';
+	 i-- ) {}
 
-    if (pszBasename[i] == '.')
-	pszBasename[i] = '\0';
+    if( pszBasename[i] == '.' )
+        pszBasename[i] = '\0';
 
-    /* -------------------------------------------------------------------- */
-    /*      Open the two files so we can write their headers.               */
-    /* -------------------------------------------------------------------- */
-    pszFullname = (char *)malloc(strlen(pszBasename) + 5);
-    sprintf(pszFullname, "%s.shp", pszBasename);
-    fpSHP = psHooks->FOpen(pszFullname, "wb");
-    if (fpSHP == NULL) {
-	psHooks->Error("Failed to create file .shp file.");
-	return (NULL);
+/* -------------------------------------------------------------------- */
+/*      Open the two files so we can write their headers.               */
+/* -------------------------------------------------------------------- */
+    pszFullname = (char *) malloc(strlen(pszBasename) + 5);
+    sprintf( pszFullname, "%s.shp", pszBasename );
+    fpSHP = psHooks->FOpen(pszFullname, "wb" );
+    if( fpSHP == NULL )
+    {
+        psHooks->Error( "Failed to create file .shp file." );
+        return( NULL );
     }
 
-    sprintf(pszFullname, "%s.shx", pszBasename);
-    fpSHX = psHooks->FOpen(pszFullname, "wb");
-    if (fpSHX == NULL) {
-	psHooks->Error("Failed to create file .shx file.");
-	return (NULL);
+    sprintf( pszFullname, "%s.shx", pszBasename );
+    fpSHX = psHooks->FOpen(pszFullname, "wb" );
+    if( fpSHX == NULL )
+    {
+        psHooks->Error( "Failed to create file .shx file." );
+        return( NULL );
     }
 
-    free(pszFullname);
-    free(pszBasename);
+    free( pszFullname );
+    free( pszBasename );
 
-    /* -------------------------------------------------------------------- */
-    /*      Prepare header block for .shp file.                             */
-    /* -------------------------------------------------------------------- */
-    for (i = 0; i < 100; i++)
-	abyHeader[i] = 0;
+/* -------------------------------------------------------------------- */
+/*      Prepare header block for .shp file.                             */
+/* -------------------------------------------------------------------- */
+    for( i = 0; i < 100; i++ )
+      abyHeader[i] = 0;
 
-    abyHeader[2] = 0x27;	/* magic cookie */
+    abyHeader[2] = 0x27;				/* magic cookie */
     abyHeader[3] = 0x0a;
 
-    i32 = 50;			/* file size */
-    ByteCopy(&i32, abyHeader + 24, 4);
-    if (!bBigEndian)
-	SwapWord(4, abyHeader + 24);
+    i32 = 50;						/* file size */
+    ByteCopy( &i32, abyHeader+24, 4 );
+    if( !bBigEndian ) SwapWord( 4, abyHeader+24 );
+    
+    i32 = 1000;						/* version */
+    ByteCopy( &i32, abyHeader+28, 4 );
+    if( bBigEndian ) SwapWord( 4, abyHeader+28 );
+    
+    i32 = nShapeType;					/* shape type */
+    ByteCopy( &i32, abyHeader+32, 4 );
+    if( bBigEndian ) SwapWord( 4, abyHeader+32 );
 
-    i32 = 1000;			/* version */
-    ByteCopy(&i32, abyHeader + 28, 4);
-    if (bBigEndian)
-	SwapWord(4, abyHeader + 28);
+    dValue = 0.0;					/* set bounds */
+    ByteCopy( &dValue, abyHeader+36, 8 );
+    ByteCopy( &dValue, abyHeader+44, 8 );
+    ByteCopy( &dValue, abyHeader+52, 8 );
+    ByteCopy( &dValue, abyHeader+60, 8 );
 
-    i32 = nShapeType;		/* shape type */
-    ByteCopy(&i32, abyHeader + 32, 4);
-    if (bBigEndian)
-	SwapWord(4, abyHeader + 32);
-
-    dValue = 0.0;		/* set bounds */
-    ByteCopy(&dValue, abyHeader + 36, 8);
-    ByteCopy(&dValue, abyHeader + 44, 8);
-    ByteCopy(&dValue, abyHeader + 52, 8);
-    ByteCopy(&dValue, abyHeader + 60, 8);
-
-    /* -------------------------------------------------------------------- */
-    /*      Write .shp file header.                                         */
-    /* -------------------------------------------------------------------- */
-    if (psHooks->FWrite(abyHeader, 100, 1, fpSHP) != 1) {
-	psHooks->Error("Failed to write .shp header.");
-	return NULL;
+/* -------------------------------------------------------------------- */
+/*      Write .shp file header.                                         */
+/* -------------------------------------------------------------------- */
+    if( psHooks->FWrite( abyHeader, 100, 1, fpSHP ) != 1 )
+    {
+        psHooks->Error( "Failed to write .shp header." );
+        return NULL;
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Prepare, and write .shx file header.                            */
-    /* -------------------------------------------------------------------- */
-    i32 = 50;			/* file size */
-    ByteCopy(&i32, abyHeader + 24, 4);
-    if (!bBigEndian)
-	SwapWord(4, abyHeader + 24);
-
-    if (psHooks->FWrite(abyHeader, 100, 1, fpSHX) != 1) {
-	psHooks->Error("Failed to write .shx header.");
-	return NULL;
+/* -------------------------------------------------------------------- */
+/*      Prepare, and write .shx file header.                            */
+/* -------------------------------------------------------------------- */
+    i32 = 50;						/* file size */
+    ByteCopy( &i32, abyHeader+24, 4 );
+    if( !bBigEndian ) SwapWord( 4, abyHeader+24 );
+    
+    if( psHooks->FWrite( abyHeader, 100, 1, fpSHX ) != 1 )
+    {
+        psHooks->Error( "Failed to write .shx header." );
+        return NULL;
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Close the files, and then open them as regular existing files.  */
-    /* -------------------------------------------------------------------- */
-    psHooks->FClose(fpSHP);
-    psHooks->FClose(fpSHX);
+/* -------------------------------------------------------------------- */
+/*      Close the files, and then open them as regular existing files.  */
+/* -------------------------------------------------------------------- */
+    psHooks->FClose( fpSHP );
+    psHooks->FClose( fpSHX );
 
-    return (SHPOpenLL(pszLayer, "r+b", psHooks));
+    return( SHPOpenLL( pszLayer, "r+b", psHooks ) );
 }
 
 /************************************************************************/
@@ -927,21 +923,22 @@
 /*                                                                      */
 /*      Compute a bounds rectangle for a shape, and set it into the     */
 /*      indicated location in the record.                               */
-
 /************************************************************************/
 
-static void _SHPSetBounds(uchar * pabyRec, SHPObject * psShape)
+static void	_SHPSetBounds( uchar * pabyRec, SHPObject * psShape )
+
 {
-    ByteCopy(&(psShape->dfXMin), pabyRec + 0, 8);
-    ByteCopy(&(psShape->dfYMin), pabyRec + 8, 8);
-    ByteCopy(&(psShape->dfXMax), pabyRec + 16, 8);
-    ByteCopy(&(psShape->dfYMax), pabyRec + 24, 8);
+    ByteCopy( &(psShape->dfXMin), pabyRec +  0, 8 );
+    ByteCopy( &(psShape->dfYMin), pabyRec +  8, 8 );
+    ByteCopy( &(psShape->dfXMax), pabyRec + 16, 8 );
+    ByteCopy( &(psShape->dfYMax), pabyRec + 24, 8 );
 
-    if (bBigEndian) {
-	SwapWord(8, pabyRec + 0);
-	SwapWord(8, pabyRec + 8);
-	SwapWord(8, pabyRec + 16);
-	SwapWord(8, pabyRec + 24);
+    if( bBigEndian )
+    {
+        SwapWord( 8, pabyRec + 0 );
+        SwapWord( 8, pabyRec + 8 );
+        SwapWord( 8, pabyRec + 16 );
+        SwapWord( 8, pabyRec + 24 );
     }
 }
 
@@ -950,33 +947,36 @@
 /*                                                                      */
 /*      Recompute the extents of a shape.  Automatically done by        */
 /*      SHPCreateObject().                                              */
-
 /************************************************************************/
 
-void SHPAPI_CALL SHPComputeExtents(SHPObject * psObject)
-{
-    int i;
+void SHPAPI_CALL
+SHPComputeExtents( SHPObject * psObject )
 
-    /* -------------------------------------------------------------------- */
-    /*      Build extents for this object.                                  */
-    /* -------------------------------------------------------------------- */
-    if (psObject->nVertices > 0) {
-	psObject->dfXMin = psObject->dfXMax = psObject->padfX[0];
-	psObject->dfYMin = psObject->dfYMax = psObject->padfY[0];
-	psObject->dfZMin = psObject->dfZMax = psObject->padfZ[0];
-	psObject->dfMMin = psObject->dfMMax = psObject->padfM[0];
+{
+    int		i;
+    
+/* -------------------------------------------------------------------- */
+/*      Build extents for this object.                                  */
+/* -------------------------------------------------------------------- */
+    if( psObject->nVertices > 0 )
+    {
+        psObject->dfXMin = psObject->dfXMax = psObject->padfX[0];
+        psObject->dfYMin = psObject->dfYMax = psObject->padfY[0];
+        psObject->dfZMin = psObject->dfZMax = psObject->padfZ[0];
+        psObject->dfMMin = psObject->dfMMax = psObject->padfM[0];
     }
+    
+    for( i = 0; i < psObject->nVertices; i++ )
+    {
+        psObject->dfXMin = MIN(psObject->dfXMin, psObject->padfX[i]);
+        psObject->dfYMin = MIN(psObject->dfYMin, psObject->padfY[i]);
+        psObject->dfZMin = MIN(psObject->dfZMin, psObject->padfZ[i]);
+        psObject->dfMMin = MIN(psObject->dfMMin, psObject->padfM[i]);
 
-    for (i = 0; i < psObject->nVertices; i++) {
-	psObject->dfXMin = MIN(psObject->dfXMin, psObject->padfX[i]);
-	psObject->dfYMin = MIN(psObject->dfYMin, psObject->padfY[i]);
-	psObject->dfZMin = MIN(psObject->dfZMin, psObject->padfZ[i]);
-	psObject->dfMMin = MIN(psObject->dfMMin, psObject->padfM[i]);
-
-	psObject->dfXMax = MAX(psObject->dfXMax, psObject->padfX[i]);
-	psObject->dfYMax = MAX(psObject->dfYMax, psObject->padfY[i]);
-	psObject->dfZMax = MAX(psObject->dfZMax, psObject->padfZ[i]);
-	psObject->dfMMax = MAX(psObject->dfMMax, psObject->padfM[i]);
+        psObject->dfXMax = MAX(psObject->dfXMax, psObject->padfX[i]);
+        psObject->dfYMax = MAX(psObject->dfYMax, psObject->padfY[i]);
+        psObject->dfZMax = MAX(psObject->dfZMax, psObject->padfZ[i]);
+        psObject->dfMMax = MAX(psObject->dfMMax, psObject->padfM[i]);
     }
 }
 
@@ -985,107 +985,116 @@
 /*                                                                      */
 /*      Create a shape object.  It should be freed with                 */
 /*      SHPDestroyObject().                                             */
-
 /************************************************************************/
 
 SHPObject SHPAPI_CALL1(*)
-SHPCreateObject(int nSHPType, int nShapeId, int nParts,
-		const int *panPartStart, const int *panPartType,
-		int nVertices, const double *padfX, const double *padfY,
-		const double *padfZ, const double *padfM)
+SHPCreateObject( int nSHPType, int nShapeId, int nParts,
+                 const int * panPartStart, const int * panPartType,
+                 int nVertices, const double *padfX, const double *padfY,
+                 const double * padfZ, const double * padfM )
+
 {
-    SHPObject *psObject;
-    int i, bHasM, bHasZ;
+    SHPObject	*psObject;
+    int		i, bHasM, bHasZ;
 
-    psObject = (SHPObject *) calloc(1, sizeof(SHPObject));
+    psObject = (SHPObject *) calloc(1,sizeof(SHPObject));
     psObject->nSHPType = nSHPType;
     psObject->nShapeId = nShapeId;
     psObject->bMeasureIsUsed = FALSE;
 
-    /* -------------------------------------------------------------------- */
-    /*      Establish whether this shape type has M, and Z values.          */
-    /* -------------------------------------------------------------------- */
-    if (nSHPType == SHPT_ARCM
-	|| nSHPType == SHPT_POINTM
-	|| nSHPType == SHPT_POLYGONM || nSHPType == SHPT_MULTIPOINTM) {
-	bHasM = TRUE;
-	bHasZ = FALSE;
+/* -------------------------------------------------------------------- */
+/*	Establish whether this shape type has M, and Z values.		*/
+/* -------------------------------------------------------------------- */
+    if( nSHPType == SHPT_ARCM
+        || nSHPType == SHPT_POINTM
+        || nSHPType == SHPT_POLYGONM
+        || nSHPType == SHPT_MULTIPOINTM )
+    {
+        bHasM = TRUE;
+        bHasZ = FALSE;
     }
-    else if (nSHPType == SHPT_ARCZ
-	     || nSHPType == SHPT_POINTZ
-	     || nSHPType == SHPT_POLYGONZ
-	     || nSHPType == SHPT_MULTIPOINTZ || nSHPType == SHPT_MULTIPATCH) {
-	bHasM = TRUE;
-	bHasZ = TRUE;
+    else if( nSHPType == SHPT_ARCZ
+             || nSHPType == SHPT_POINTZ
+             || nSHPType == SHPT_POLYGONZ
+             || nSHPType == SHPT_MULTIPOINTZ
+             || nSHPType == SHPT_MULTIPATCH )
+    {
+        bHasM = TRUE;
+        bHasZ = TRUE;
     }
-    else {
-	bHasM = FALSE;
-	bHasZ = FALSE;
+    else
+    {
+        bHasM = FALSE;
+        bHasZ = FALSE;
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Capture parts.  Note that part type is optional, and            */
-    /*      defaults to ring.                                               */
-    /* -------------------------------------------------------------------- */
-    if (nSHPType == SHPT_ARC || nSHPType == SHPT_POLYGON
-	|| nSHPType == SHPT_ARCM || nSHPType == SHPT_POLYGONM
-	|| nSHPType == SHPT_ARCZ || nSHPType == SHPT_POLYGONZ
-	|| nSHPType == SHPT_MULTIPATCH) {
-	psObject->nParts = MAX(1, nParts);
+/* -------------------------------------------------------------------- */
+/*      Capture parts.  Note that part type is optional, and            */
+/*      defaults to ring.                                               */
+/* -------------------------------------------------------------------- */
+    if( nSHPType == SHPT_ARC || nSHPType == SHPT_POLYGON
+        || nSHPType == SHPT_ARCM || nSHPType == SHPT_POLYGONM
+        || nSHPType == SHPT_ARCZ || nSHPType == SHPT_POLYGONZ
+        || nSHPType == SHPT_MULTIPATCH )
+    {
+        psObject->nParts = MAX(1,nParts);
 
-	psObject->panPartStart = (int *)
-	    malloc(sizeof(int) * psObject->nParts);
-	psObject->panPartType = (int *)
-	    malloc(sizeof(int) * psObject->nParts);
+        psObject->panPartStart = (int *)
+            malloc(sizeof(int) * psObject->nParts);
+        psObject->panPartType = (int *)
+            malloc(sizeof(int) * psObject->nParts);
 
-	psObject->panPartStart[0] = 0;
-	psObject->panPartType[0] = SHPP_RING;
+        psObject->panPartStart[0] = 0;
+        psObject->panPartType[0] = SHPP_RING;
+        
+        for( i = 0; i < nParts; i++ )
+        {
+            psObject->panPartStart[i] = panPartStart[i];
 
-	for (i = 0; i < nParts; i++) {
-	    psObject->panPartStart[i] = panPartStart[i];
+            if( panPartType != NULL )
+                psObject->panPartType[i] = panPartType[i];
+            else
+                psObject->panPartType[i] = SHPP_RING;
+        }
 
-	    if (panPartType != NULL)
-		psObject->panPartType[i] = panPartType[i];
-	    else
-		psObject->panPartType[i] = SHPP_RING;
-	}
-
-	if (psObject->panPartStart[0] != 0)
-	    psObject->panPartStart[0] = 0;
+        if( psObject->panPartStart[0] != 0 )
+            psObject->panPartStart[0] = 0;
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Capture vertices.  Note that Z and M are optional, but X and    */
-    /*      Y are not.                                                      */
-    /* -------------------------------------------------------------------- */
-    if (nVertices > 0) {
-	psObject->padfX = (double *)calloc(sizeof(double), nVertices);
-	psObject->padfY = (double *)calloc(sizeof(double), nVertices);
-	psObject->padfZ = (double *)calloc(sizeof(double), nVertices);
-	psObject->padfM = (double *)calloc(sizeof(double), nVertices);
+/* -------------------------------------------------------------------- */
+/*      Capture vertices.  Note that Z and M are optional, but X and    */
+/*      Y are not.                                                      */
+/* -------------------------------------------------------------------- */
+    if( nVertices > 0 )
+    {
+        psObject->padfX = (double *) calloc(sizeof(double),nVertices);
+        psObject->padfY = (double *) calloc(sizeof(double),nVertices);
+        psObject->padfZ = (double *) calloc(sizeof(double),nVertices);
+        psObject->padfM = (double *) calloc(sizeof(double),nVertices);
 
-	assert(padfX != NULL);
-	assert(padfY != NULL);
-
-	for (i = 0; i < nVertices; i++) {
-	    psObject->padfX[i] = padfX[i];
-	    psObject->padfY[i] = padfY[i];
-	    if (padfZ != NULL && bHasZ)
-		psObject->padfZ[i] = padfZ[i];
-	    if (padfM != NULL && bHasM)
-		psObject->padfM[i] = padfM[i];
-	}
-	if (padfM != NULL && bHasM)
-	    psObject->bMeasureIsUsed = TRUE;
+        assert( padfX != NULL );
+        assert( padfY != NULL );
+    
+        for( i = 0; i < nVertices; i++ )
+        {
+            psObject->padfX[i] = padfX[i];
+            psObject->padfY[i] = padfY[i];
+            if( padfZ != NULL && bHasZ )
+                psObject->padfZ[i] = padfZ[i];
+            if( padfM != NULL && bHasM )
+                psObject->padfM[i] = padfM[i];
+        }
+        if( padfM != NULL && bHasM )
+            psObject->bMeasureIsUsed = TRUE;
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Compute the extents.                                            */
-    /* -------------------------------------------------------------------- */
+/* -------------------------------------------------------------------- */
+/*      Compute the extents.                                            */
+/* -------------------------------------------------------------------- */
     psObject->nVertices = nVertices;
-    SHPComputeExtents(psObject);
+    SHPComputeExtents( psObject );
 
-    return (psObject);
+    return( psObject );
 }
 
 /************************************************************************/
@@ -1093,1028 +1102,1014 @@
 /*                                                                      */
 /*      Create a simple (common) shape object.  Destroy with            */
 /*      SHPDestroyObject().                                             */
-
 /************************************************************************/
 
 SHPObject SHPAPI_CALL1(*)
-SHPCreateSimpleObject(int nSHPType, int nVertices,
-		      const double *padfX, const double *padfY,
-		      const double *padfZ)
+SHPCreateSimpleObject( int nSHPType, int nVertices,
+                       const double * padfX, const double * padfY,
+                       const double * padfZ )
+
 {
-    return (SHPCreateObject(nSHPType, -1, 0, NULL, NULL,
-			    nVertices, padfX, padfY, padfZ, NULL));
+    return( SHPCreateObject( nSHPType, -1, 0, NULL, NULL,
+                             nVertices, padfX, padfY, padfZ, NULL ) );
 }
-
+                                  
 /************************************************************************/
 /*                           SHPWriteObject()                           */
 /*                                                                      */
 /*      Write out the vertices of a new structure.  Note that it is     */
 /*      only possible to write vertices at the end of the file.         */
-
 /************************************************************************/
 
 int SHPAPI_CALL
-SHPWriteObject(SHPHandle psSHP, int nShapeId, SHPObject * psObject)
+SHPWriteObject(SHPHandle psSHP, int nShapeId, SHPObject * psObject )
+		      
 {
-    int nRecordOffset, i, nRecordSize = 0;
-    uchar *pabyRec;
-    int32 i32;
+    int	       	nRecordOffset, i, nRecordSize=0;
+    uchar	*pabyRec;
+    int32	i32;
 
     psSHP->bUpdated = TRUE;
 
-    /* -------------------------------------------------------------------- */
-    /*      Ensure that shape object matches the type of the file it is     */
-    /*      being written to.                                               */
-    /* -------------------------------------------------------------------- */
-    assert(psObject->nSHPType == psSHP->nShapeType
-	   || psObject->nSHPType == SHPT_NULL);
+/* -------------------------------------------------------------------- */
+/*      Ensure that shape object matches the type of the file it is     */
+/*      being written to.                                               */
+/* -------------------------------------------------------------------- */
+    assert( psObject->nSHPType == psSHP->nShapeType 
+            || psObject->nSHPType == SHPT_NULL );
 
-    /* -------------------------------------------------------------------- */
-    /*      Ensure that -1 is used for appends.  Either blow an             */
-    /*      assertion, or if they are disabled, set the shapeid to -1       */
-    /*      for appends.                                                    */
-    /* -------------------------------------------------------------------- */
-    assert(nShapeId == -1 || (nShapeId >= 0 && nShapeId < psSHP->nRecords));
+/* -------------------------------------------------------------------- */
+/*      Ensure that -1 is used for appends.  Either blow an             */
+/*      assertion, or if they are disabled, set the shapeid to -1       */
+/*      for appends.                                                    */
+/* -------------------------------------------------------------------- */
+    assert( nShapeId == -1 
+            || (nShapeId >= 0 && nShapeId < psSHP->nRecords) );
 
-    if (nShapeId != -1 && nShapeId >= psSHP->nRecords)
-	nShapeId = -1;
+    if( nShapeId != -1 && nShapeId >= psSHP->nRecords )
+        nShapeId = -1;
 
-    /* -------------------------------------------------------------------- */
-    /*      Add the new entity to the in memory index.                      */
-    /* -------------------------------------------------------------------- */
-    if (nShapeId == -1 && psSHP->nRecords + 1 > psSHP->nMaxRecords) {
-	psSHP->nMaxRecords = (int)(psSHP->nMaxRecords * 1.3 + 100);
+/* -------------------------------------------------------------------- */
+/*      Add the new entity to the in memory index.                      */
+/* -------------------------------------------------------------------- */
+    if( nShapeId == -1 && psSHP->nRecords+1 > psSHP->nMaxRecords )
+    {
+	psSHP->nMaxRecords =(int) ( psSHP->nMaxRecords * 1.3 + 100);
 
-	psSHP->panRecOffset = (int *)
-	    SfRealloc(psSHP->panRecOffset, sizeof(int) * psSHP->nMaxRecords);
-	psSHP->panRecSize = (int *)
-	    SfRealloc(psSHP->panRecSize, sizeof(int) * psSHP->nMaxRecords);
+	psSHP->panRecOffset = (int *) 
+            SfRealloc(psSHP->panRecOffset,sizeof(int) * psSHP->nMaxRecords );
+	psSHP->panRecSize = (int *) 
+            SfRealloc(psSHP->panRecSize,sizeof(int) * psSHP->nMaxRecords );
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Initialize record.                                              */
-    /* -------------------------------------------------------------------- */
-    pabyRec = (uchar *) malloc(psObject->nVertices * 4 * sizeof(double)
+/* -------------------------------------------------------------------- */
+/*      Initialize record.                                              */
+/* -------------------------------------------------------------------- */
+    pabyRec = (uchar *) malloc(psObject->nVertices * 4 * sizeof(double) 
 			       + psObject->nParts * 8 + 128);
+    
+/* -------------------------------------------------------------------- */
+/*  Extract vertices for a Polygon or Arc.				*/
+/* -------------------------------------------------------------------- */
+    if( psObject->nSHPType == SHPT_POLYGON
+        || psObject->nSHPType == SHPT_POLYGONZ
+        || psObject->nSHPType == SHPT_POLYGONM
+        || psObject->nSHPType == SHPT_ARC 
+        || psObject->nSHPType == SHPT_ARCZ
+        || psObject->nSHPType == SHPT_ARCM
+        || psObject->nSHPType == SHPT_MULTIPATCH )
+    {
+	int32		nPoints, nParts;
+	int    		i;
 
-    /* -------------------------------------------------------------------- */
-    /*  Extract vertices for a Polygon or Arc.                              */
-    /* -------------------------------------------------------------------- */
-    if (psObject->nSHPType == SHPT_POLYGON
-	|| psObject->nSHPType == SHPT_POLYGONZ
-	|| psObject->nSHPType == SHPT_POLYGONM
-	|| psObject->nSHPType == SHPT_ARC
-	|| psObject->nSHPType == SHPT_ARCZ
-	|| psObject->nSHPType == SHPT_ARCM
-	|| psObject->nSHPType == SHPT_MULTIPATCH) {
-	int32 nPoints, nParts;
-	int i;
-
 	nPoints = psObject->nVertices;
 	nParts = psObject->nParts;
 
-	_SHPSetBounds(pabyRec + 12, psObject);
+	_SHPSetBounds( pabyRec + 12, psObject );
 
-	if (bBigEndian)
-	    SwapWord(4, &nPoints);
-	if (bBigEndian)
-	    SwapWord(4, &nParts);
+	if( bBigEndian ) SwapWord( 4, &nPoints );
+	if( bBigEndian ) SwapWord( 4, &nParts );
 
-	ByteCopy(&nPoints, pabyRec + 40 + 8, 4);
-	ByteCopy(&nParts, pabyRec + 36 + 8, 4);
+	ByteCopy( &nPoints, pabyRec + 40 + 8, 4 );
+	ByteCopy( &nParts, pabyRec + 36 + 8, 4 );
 
-	nRecordSize = 52;
+        nRecordSize = 52;
 
-	/*
-	 * Write part start positions.
-	 */
-	ByteCopy(psObject->panPartStart, pabyRec + 44 + 8,
-		 4 * psObject->nParts);
-	for (i = 0; i < psObject->nParts; i++) {
-	    if (bBigEndian)
-		SwapWord(4, pabyRec + 44 + 8 + 4 * i);
-	    nRecordSize += 4;
+        /*
+         * Write part start positions.
+         */
+	ByteCopy( psObject->panPartStart, pabyRec + 44 + 8,
+                  4 * psObject->nParts );
+	for( i = 0; i < psObject->nParts; i++ )
+	{
+	    if( bBigEndian ) SwapWord( 4, pabyRec + 44 + 8 + 4*i );
+            nRecordSize += 4;
 	}
 
-	/*
-	 * Write multipatch part types if needed.
-	 */
-	if (psObject->nSHPType == SHPT_MULTIPATCH) {
-	    memcpy(pabyRec + nRecordSize, psObject->panPartType,
-		   4 * psObject->nParts);
-	    for (i = 0; i < psObject->nParts; i++) {
-		if (bBigEndian)
-		    SwapWord(4, pabyRec + nRecordSize);
-		nRecordSize += 4;
-	    }
-	}
+        /*
+         * Write multipatch part types if needed.
+         */
+        if( psObject->nSHPType == SHPT_MULTIPATCH )
+        {
+            memcpy( pabyRec + nRecordSize, psObject->panPartType,
+                    4*psObject->nParts );
+            for( i = 0; i < psObject->nParts; i++ )
+            {
+                if( bBigEndian ) SwapWord( 4, pabyRec + nRecordSize );
+                nRecordSize += 4;
+            }
+        }
 
-	/*
-	 * Write the (x,y) vertex values.
-	 */
-	for (i = 0; i < psObject->nVertices; i++) {
-	    ByteCopy(psObject->padfX + i, pabyRec + nRecordSize, 8);
-	    ByteCopy(psObject->padfY + i, pabyRec + nRecordSize + 8, 8);
+        /*
+         * Write the (x,y) vertex values.
+         */
+	for( i = 0; i < psObject->nVertices; i++ )
+	{
+	    ByteCopy( psObject->padfX + i, pabyRec + nRecordSize, 8 );
+	    ByteCopy( psObject->padfY + i, pabyRec + nRecordSize + 8, 8 );
 
-	    if (bBigEndian)
-		SwapWord(8, pabyRec + nRecordSize);
+	    if( bBigEndian )
+                SwapWord( 8, pabyRec + nRecordSize );
+            
+	    if( bBigEndian )
+                SwapWord( 8, pabyRec + nRecordSize + 8 );
 
-	    if (bBigEndian)
-		SwapWord(8, pabyRec + nRecordSize + 8);
-
-	    nRecordSize += 2 * 8;
+            nRecordSize += 2 * 8;
 	}
 
-	/*
-	 * Write the Z coordinates (if any).
-	 */
-	if (psObject->nSHPType == SHPT_POLYGONZ
-	    || psObject->nSHPType == SHPT_ARCZ
-	    || psObject->nSHPType == SHPT_MULTIPATCH) {
-	    ByteCopy(&(psObject->dfZMin), pabyRec + nRecordSize, 8);
-	    if (bBigEndian)
-		SwapWord(8, pabyRec + nRecordSize);
-	    nRecordSize += 8;
+        /*
+         * Write the Z coordinates (if any).
+         */
+        if( psObject->nSHPType == SHPT_POLYGONZ
+            || psObject->nSHPType == SHPT_ARCZ
+            || psObject->nSHPType == SHPT_MULTIPATCH )
+        {
+            ByteCopy( &(psObject->dfZMin), pabyRec + nRecordSize, 8 );
+            if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
+            nRecordSize += 8;
+            
+            ByteCopy( &(psObject->dfZMax), pabyRec + nRecordSize, 8 );
+            if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
+            nRecordSize += 8;
 
-	    ByteCopy(&(psObject->dfZMax), pabyRec + nRecordSize, 8);
-	    if (bBigEndian)
-		SwapWord(8, pabyRec + nRecordSize);
-	    nRecordSize += 8;
+            for( i = 0; i < psObject->nVertices; i++ )
+            {
+                ByteCopy( psObject->padfZ + i, pabyRec + nRecordSize, 8 );
+                if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
+                nRecordSize += 8;
+            }
+        }
 
-	    for (i = 0; i < psObject->nVertices; i++) {
-		ByteCopy(psObject->padfZ + i, pabyRec + nRecordSize, 8);
-		if (bBigEndian)
-		    SwapWord(8, pabyRec + nRecordSize);
-		nRecordSize += 8;
-	    }
-	}
+        /*
+         * Write the M values, if any.
+         */
+        if( psObject->bMeasureIsUsed
+            && (psObject->nSHPType == SHPT_POLYGONM
+            || psObject->nSHPType == SHPT_ARCM
+#ifndef DISABLE_MULTIPATCH_MEASURE            
+            || psObject->nSHPType == SHPT_MULTIPATCH
+#endif            
+            || psObject->nSHPType == SHPT_POLYGONZ
+            || psObject->nSHPType == SHPT_ARCZ) )
+        {
+            ByteCopy( &(psObject->dfMMin), pabyRec + nRecordSize, 8 );
+            if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
+            nRecordSize += 8;
+            
+            ByteCopy( &(psObject->dfMMax), pabyRec + nRecordSize, 8 );
+            if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
+            nRecordSize += 8;
 
-	/*
-	 * Write the M values, if any.
-	 */
-	if (psObject->bMeasureIsUsed
-	    && (psObject->nSHPType == SHPT_POLYGONM
-		|| psObject->nSHPType == SHPT_ARCM
-#ifndef DISABLE_MULTIPATCH_MEASURE
-		|| psObject->nSHPType == SHPT_MULTIPATCH
-#endif
-		|| psObject->nSHPType == SHPT_POLYGONZ
-		|| psObject->nSHPType == SHPT_ARCZ)) {
-	    ByteCopy(&(psObject->dfMMin), pabyRec + nRecordSize, 8);
-	    if (bBigEndian)
-		SwapWord(8, pabyRec + nRecordSize);
-	    nRecordSize += 8;
-
-	    ByteCopy(&(psObject->dfMMax), pabyRec + nRecordSize, 8);
-	    if (bBigEndian)
-		SwapWord(8, pabyRec + nRecordSize);
-	    nRecordSize += 8;
-
-	    for (i = 0; i < psObject->nVertices; i++) {
-		ByteCopy(psObject->padfM + i, pabyRec + nRecordSize, 8);
-		if (bBigEndian)
-		    SwapWord(8, pabyRec + nRecordSize);
-		nRecordSize += 8;
-	    }
-	}
+            for( i = 0; i < psObject->nVertices; i++ )
+            {
+                ByteCopy( psObject->padfM + i, pabyRec + nRecordSize, 8 );
+                if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
+                nRecordSize += 8;
+            }
+        }
     }
 
-    /* -------------------------------------------------------------------- */
-    /*  Extract vertices for a MultiPoint.                                  */
-    /* -------------------------------------------------------------------- */
-    else if (psObject->nSHPType == SHPT_MULTIPOINT
-	     || psObject->nSHPType == SHPT_MULTIPOINTZ
-	     || psObject->nSHPType == SHPT_MULTIPOINTM) {
-	int32 nPoints;
-	int i;
+/* -------------------------------------------------------------------- */
+/*  Extract vertices for a MultiPoint.					*/
+/* -------------------------------------------------------------------- */
+    else if( psObject->nSHPType == SHPT_MULTIPOINT
+             || psObject->nSHPType == SHPT_MULTIPOINTZ
+             || psObject->nSHPType == SHPT_MULTIPOINTM )
+    {
+	int32		nPoints;
+	int    		i;
 
 	nPoints = psObject->nVertices;
 
-	_SHPSetBounds(pabyRec + 12, psObject);
+        _SHPSetBounds( pabyRec + 12, psObject );
 
-	if (bBigEndian)
-	    SwapWord(4, &nPoints);
-	ByteCopy(&nPoints, pabyRec + 44, 4);
+	if( bBigEndian ) SwapWord( 4, &nPoints );
+	ByteCopy( &nPoints, pabyRec + 44, 4 );
+	
+	for( i = 0; i < psObject->nVertices; i++ )
+	{
+	    ByteCopy( psObject->padfX + i, pabyRec + 48 + i*16, 8 );
+	    ByteCopy( psObject->padfY + i, pabyRec + 48 + i*16 + 8, 8 );
 
-	for (i = 0; i < psObject->nVertices; i++) {
-	    ByteCopy(psObject->padfX + i, pabyRec + 48 + i * 16, 8);
-	    ByteCopy(psObject->padfY + i, pabyRec + 48 + i * 16 + 8, 8);
-
-	    if (bBigEndian)
-		SwapWord(8, pabyRec + 48 + i * 16);
-	    if (bBigEndian)
-		SwapWord(8, pabyRec + 48 + i * 16 + 8);
+	    if( bBigEndian ) SwapWord( 8, pabyRec + 48 + i*16 );
+	    if( bBigEndian ) SwapWord( 8, pabyRec + 48 + i*16 + 8 );
 	}
 
 	nRecordSize = 48 + 16 * psObject->nVertices;
 
-	if (psObject->nSHPType == SHPT_MULTIPOINTZ) {
-	    ByteCopy(&(psObject->dfZMin), pabyRec + nRecordSize, 8);
-	    if (bBigEndian)
-		SwapWord(8, pabyRec + nRecordSize);
-	    nRecordSize += 8;
+        if( psObject->nSHPType == SHPT_MULTIPOINTZ )
+        {
+            ByteCopy( &(psObject->dfZMin), pabyRec + nRecordSize, 8 );
+            if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
+            nRecordSize += 8;
 
-	    ByteCopy(&(psObject->dfZMax), pabyRec + nRecordSize, 8);
-	    if (bBigEndian)
-		SwapWord(8, pabyRec + nRecordSize);
-	    nRecordSize += 8;
+            ByteCopy( &(psObject->dfZMax), pabyRec + nRecordSize, 8 );
+            if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
+            nRecordSize += 8;
+            
+            for( i = 0; i < psObject->nVertices; i++ )
+            {
+                ByteCopy( psObject->padfZ + i, pabyRec + nRecordSize, 8 );
+                if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
+                nRecordSize += 8;
+            }
+        }
 
-	    for (i = 0; i < psObject->nVertices; i++) {
-		ByteCopy(psObject->padfZ + i, pabyRec + nRecordSize, 8);
-		if (bBigEndian)
-		    SwapWord(8, pabyRec + nRecordSize);
-		nRecordSize += 8;
-	    }
-	}
+        if( psObject->bMeasureIsUsed
+            && (psObject->nSHPType == SHPT_MULTIPOINTZ
+            || psObject->nSHPType == SHPT_MULTIPOINTM) )
+        {
+            ByteCopy( &(psObject->dfMMin), pabyRec + nRecordSize, 8 );
+            if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
+            nRecordSize += 8;
 
-	if (psObject->bMeasureIsUsed
-	    && (psObject->nSHPType == SHPT_MULTIPOINTZ
-		|| psObject->nSHPType == SHPT_MULTIPOINTM)) {
-	    ByteCopy(&(psObject->dfMMin), pabyRec + nRecordSize, 8);
-	    if (bBigEndian)
-		SwapWord(8, pabyRec + nRecordSize);
-	    nRecordSize += 8;
-
-	    ByteCopy(&(psObject->dfMMax), pabyRec + nRecordSize, 8);
-	    if (bBigEndian)
-		SwapWord(8, pabyRec + nRecordSize);
-	    nRecordSize += 8;
-
-	    for (i = 0; i < psObject->nVertices; i++) {
-		ByteCopy(psObject->padfM + i, pabyRec + nRecordSize, 8);
-		if (bBigEndian)
-		    SwapWord(8, pabyRec + nRecordSize);
-		nRecordSize += 8;
-	    }
-	}
+            ByteCopy( &(psObject->dfMMax), pabyRec + nRecordSize, 8 );
+            if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
+            nRecordSize += 8;
+            
+            for( i = 0; i < psObject->nVertices; i++ )
+            {
+                ByteCopy( psObject->padfM + i, pabyRec + nRecordSize, 8 );
+                if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
+                nRecordSize += 8;
+            }
+        }
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Write point.                                                    */
-    /* -------------------------------------------------------------------- */
-    else if (psObject->nSHPType == SHPT_POINT
-	     || psObject->nSHPType == SHPT_POINTZ
-	     || psObject->nSHPType == SHPT_POINTM) {
-	ByteCopy(psObject->padfX, pabyRec + 12, 8);
-	ByteCopy(psObject->padfY, pabyRec + 20, 8);
+/* -------------------------------------------------------------------- */
+/*      Write point.							*/
+/* -------------------------------------------------------------------- */
+    else if( psObject->nSHPType == SHPT_POINT
+             || psObject->nSHPType == SHPT_POINTZ
+             || psObject->nSHPType == SHPT_POINTM )
+    {
+	ByteCopy( psObject->padfX, pabyRec + 12, 8 );
+	ByteCopy( psObject->padfY, pabyRec + 20, 8 );
 
-	if (bBigEndian)
-	    SwapWord(8, pabyRec + 12);
-	if (bBigEndian)
-	    SwapWord(8, pabyRec + 20);
+	if( bBigEndian ) SwapWord( 8, pabyRec + 12 );
+	if( bBigEndian ) SwapWord( 8, pabyRec + 20 );
 
-	nRecordSize = 28;
-
-	if (psObject->nSHPType == SHPT_POINTZ) {
-	    ByteCopy(psObject->padfZ, pabyRec + nRecordSize, 8);
-	    if (bBigEndian)
-		SwapWord(8, pabyRec + nRecordSize);
-	    nRecordSize += 8;
-	}
-
-	if (psObject->bMeasureIsUsed
-	    && (psObject->nSHPType == SHPT_POINTZ
-		|| psObject->nSHPType == SHPT_POINTM)) {
-	    ByteCopy(psObject->padfM, pabyRec + nRecordSize, 8);
-	    if (bBigEndian)
-		SwapWord(8, pabyRec + nRecordSize);
-	    nRecordSize += 8;
-	}
+        nRecordSize = 28;
+        
+        if( psObject->nSHPType == SHPT_POINTZ )
+        {
+            ByteCopy( psObject->padfZ, pabyRec + nRecordSize, 8 );
+            if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
+            nRecordSize += 8;
+        }
+        
+        if( psObject->bMeasureIsUsed
+            && (psObject->nSHPType == SHPT_POINTZ
+            || psObject->nSHPType == SHPT_POINTM) )
+        {
+            ByteCopy( psObject->padfM, pabyRec + nRecordSize, 8 );
+            if( bBigEndian ) SwapWord( 8, pabyRec + nRecordSize );
+            nRecordSize += 8;
+        }
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Not much to do for null geometries.                             */
-    /* -------------------------------------------------------------------- */
-    else if (psObject->nSHPType == SHPT_NULL) {
-	nRecordSize = 12;
+/* -------------------------------------------------------------------- */
+/*      Not much to do for null geometries.                             */
+/* -------------------------------------------------------------------- */
+    else if( psObject->nSHPType == SHPT_NULL )
+    {
+        nRecordSize = 12;
     }
 
-    else {
-	/* unknown type */
-	assert(FALSE);
+    else
+    {
+        /* unknown type */
+        assert( FALSE );
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Establish where we are going to put this record. If we are      */
-    /*      rewriting and existing record, and it will fit, then put it     */
-    /*      back where the original came from.  Otherwise write at the end. */
-    /* -------------------------------------------------------------------- */
-    if (nShapeId == -1 || psSHP->panRecSize[nShapeId] < nRecordSize - 8) {
-	if (nShapeId == -1)
-	    nShapeId = psSHP->nRecords++;
+/* -------------------------------------------------------------------- */
+/*      Establish where we are going to put this record. If we are      */
+/*      rewriting and existing record, and it will fit, then put it     */
+/*      back where the original came from.  Otherwise write at the end. */
+/* -------------------------------------------------------------------- */
+    if( nShapeId == -1 || psSHP->panRecSize[nShapeId] < nRecordSize-8 )
+    {
+        if( nShapeId == -1 )
+            nShapeId = psSHP->nRecords++;
 
-	psSHP->panRecOffset[nShapeId] = nRecordOffset = psSHP->nFileSize;
-	psSHP->panRecSize[nShapeId] = nRecordSize - 8;
-	psSHP->nFileSize += nRecordSize;
+        psSHP->panRecOffset[nShapeId] = nRecordOffset = psSHP->nFileSize;
+        psSHP->panRecSize[nShapeId] = nRecordSize-8;
+        psSHP->nFileSize += nRecordSize;
     }
-    else {
-	nRecordOffset = psSHP->panRecOffset[nShapeId];
-	psSHP->panRecSize[nShapeId] = nRecordSize - 8;
+    else
+    {
+        nRecordOffset = psSHP->panRecOffset[nShapeId];
+        psSHP->panRecSize[nShapeId] = nRecordSize-8;
     }
+    
+/* -------------------------------------------------------------------- */
+/*      Set the shape type, record number, and record size.             */
+/* -------------------------------------------------------------------- */
+    i32 = nShapeId+1;					/* record # */
+    if( !bBigEndian ) SwapWord( 4, &i32 );
+    ByteCopy( &i32, pabyRec, 4 );
 
-    /* -------------------------------------------------------------------- */
-    /*      Set the shape type, record number, and record size.             */
-    /* -------------------------------------------------------------------- */
-    i32 = nShapeId + 1;		/* record # */
-    if (!bBigEndian)
-	SwapWord(4, &i32);
-    ByteCopy(&i32, pabyRec, 4);
+    i32 = (nRecordSize-8)/2;				/* record size */
+    if( !bBigEndian ) SwapWord( 4, &i32 );
+    ByteCopy( &i32, pabyRec + 4, 4 );
 
-    i32 = (nRecordSize - 8) / 2;	/* record size */
-    if (!bBigEndian)
-	SwapWord(4, &i32);
-    ByteCopy(&i32, pabyRec + 4, 4);
+    i32 = psObject->nSHPType;				/* shape type */
+    if( bBigEndian ) SwapWord( 4, &i32 );
+    ByteCopy( &i32, pabyRec + 8, 4 );
 
-    i32 = psObject->nSHPType;	/* shape type */
-    if (bBigEndian)
-	SwapWord(4, &i32);
-    ByteCopy(&i32, pabyRec + 8, 4);
-
-    /* -------------------------------------------------------------------- */
-    /*      Write out record.                                               */
-    /* -------------------------------------------------------------------- */
-    if (psSHP->sHooks.FSeek(psSHP->fpSHP, nRecordOffset, 0) != 0
-	|| psSHP->sHooks.FWrite(pabyRec, nRecordSize, 1, psSHP->fpSHP) < 1) {
-	psSHP->sHooks.
-	    Error
-	    ("Error in psSHP->sHooks.FSeek() or fwrite() writing object to .shp file.");
-	free(pabyRec);
-	return -1;
+/* -------------------------------------------------------------------- */
+/*      Write out record.                                               */
+/* -------------------------------------------------------------------- */
+    if( psSHP->sHooks.FSeek( psSHP->fpSHP, nRecordOffset, 0 ) != 0
+        || psSHP->sHooks.FWrite( pabyRec, nRecordSize, 1, psSHP->fpSHP ) < 1 )
+    {
+        psSHP->sHooks.Error( "Error in psSHP->sHooks.FSeek() or fwrite() writing object to .shp file." );
+        free( pabyRec );
+        return -1;
     }
+    
+    free( pabyRec );
 
-    free(pabyRec);
-
-    /* -------------------------------------------------------------------- */
-    /*      Expand file wide bounds based on this shape.                    */
-    /* -------------------------------------------------------------------- */
-    if (psSHP->adBoundsMin[0] == 0.0
-	&& psSHP->adBoundsMax[0] == 0.0
-	&& psSHP->adBoundsMin[1] == 0.0 && psSHP->adBoundsMax[1] == 0.0) {
-	if (psObject->nSHPType == SHPT_NULL || psObject->nVertices == 0) {
-	    psSHP->adBoundsMin[0] = psSHP->adBoundsMax[0] = 0.0;
-	    psSHP->adBoundsMin[1] = psSHP->adBoundsMax[1] = 0.0;
-	    psSHP->adBoundsMin[2] = psSHP->adBoundsMax[2] = 0.0;
-	    psSHP->adBoundsMin[3] = psSHP->adBoundsMax[3] = 0.0;
-	}
-	else {
-	    psSHP->adBoundsMin[0] = psSHP->adBoundsMax[0] =
-		psObject->padfX[0];
-	    psSHP->adBoundsMin[1] = psSHP->adBoundsMax[1] =
-		psObject->padfY[0];
-	    psSHP->adBoundsMin[2] = psSHP->adBoundsMax[2] =
-		psObject->padfZ[0];
-	    psSHP->adBoundsMin[3] = psSHP->adBoundsMax[3] =
-		psObject->padfM[0];
-	}
+/* -------------------------------------------------------------------- */
+/*	Expand file wide bounds based on this shape.			*/
+/* -------------------------------------------------------------------- */
+    if( psSHP->adBoundsMin[0] == 0.0
+        && psSHP->adBoundsMax[0] == 0.0
+        && psSHP->adBoundsMin[1] == 0.0
+        && psSHP->adBoundsMax[1] == 0.0 )
+    {
+        if( psObject->nSHPType == SHPT_NULL || psObject->nVertices == 0 )
+        {
+            psSHP->adBoundsMin[0] = psSHP->adBoundsMax[0] = 0.0;
+            psSHP->adBoundsMin[1] = psSHP->adBoundsMax[1] = 0.0;
+            psSHP->adBoundsMin[2] = psSHP->adBoundsMax[2] = 0.0;
+            psSHP->adBoundsMin[3] = psSHP->adBoundsMax[3] = 0.0;
+        }
+        else
+        {
+            psSHP->adBoundsMin[0] = psSHP->adBoundsMax[0] = psObject->padfX[0];
+            psSHP->adBoundsMin[1] = psSHP->adBoundsMax[1] = psObject->padfY[0];
+            psSHP->adBoundsMin[2] = psSHP->adBoundsMax[2] = psObject->padfZ[0];
+            psSHP->adBoundsMin[3] = psSHP->adBoundsMax[3] = psObject->padfM[0];
+        }
     }
 
-    for (i = 0; i < psObject->nVertices; i++) {
-	psSHP->adBoundsMin[0] =
-	    MIN(psSHP->adBoundsMin[0], psObject->padfX[i]);
-	psSHP->adBoundsMin[1] =
-	    MIN(psSHP->adBoundsMin[1], psObject->padfY[i]);
-	psSHP->adBoundsMin[2] =
-	    MIN(psSHP->adBoundsMin[2], psObject->padfZ[i]);
-	psSHP->adBoundsMin[3] =
-	    MIN(psSHP->adBoundsMin[3], psObject->padfM[i]);
-	psSHP->adBoundsMax[0] =
-	    MAX(psSHP->adBoundsMax[0], psObject->padfX[i]);
-	psSHP->adBoundsMax[1] =
-	    MAX(psSHP->adBoundsMax[1], psObject->padfY[i]);
-	psSHP->adBoundsMax[2] =
-	    MAX(psSHP->adBoundsMax[2], psObject->padfZ[i]);
-	psSHP->adBoundsMax[3] =
-	    MAX(psSHP->adBoundsMax[3], psObject->padfM[i]);
+    for( i = 0; i < psObject->nVertices; i++ )
+    {
+	psSHP->adBoundsMin[0] = MIN(psSHP->adBoundsMin[0],psObject->padfX[i]);
+	psSHP->adBoundsMin[1] = MIN(psSHP->adBoundsMin[1],psObject->padfY[i]);
+	psSHP->adBoundsMin[2] = MIN(psSHP->adBoundsMin[2],psObject->padfZ[i]);
+	psSHP->adBoundsMin[3] = MIN(psSHP->adBoundsMin[3],psObject->padfM[i]);
+	psSHP->adBoundsMax[0] = MAX(psSHP->adBoundsMax[0],psObject->padfX[i]);
+	psSHP->adBoundsMax[1] = MAX(psSHP->adBoundsMax[1],psObject->padfY[i]);
+	psSHP->adBoundsMax[2] = MAX(psSHP->adBoundsMax[2],psObject->padfZ[i]);
+	psSHP->adBoundsMax[3] = MAX(psSHP->adBoundsMax[3],psObject->padfM[i]);
     }
 
-    return (nShapeId);
+    return( nShapeId  );
 }
 
 /************************************************************************/
 /*                          SHPReadObject()                             */
 /*                                                                      */
-/*      Read the vertices, parts, and other non-attribute information   */
-/*      for one shape.                                                  */
-
+/*      Read the vertices, parts, and other non-attribute information	*/
+/*	for one shape.							*/
 /************************************************************************/
 
-SHPObject SHPAPI_CALL1(*) SHPReadObject(SHPHandle psSHP, int hEntity)
+SHPObject SHPAPI_CALL1(*)
+SHPReadObject( SHPHandle psSHP, int hEntity )
+
 {
-    int nEntitySize, nRequiredSize;
-    SHPObject *psShape;
-    char pszErrorMsg[128];
+    int                  nEntitySize, nRequiredSize;
+    SHPObject		*psShape;
+    char                 pszErrorMsg[128];
 
-    /* -------------------------------------------------------------------- */
-    /*      Validate the record/entity number.                              */
-    /* -------------------------------------------------------------------- */
-    if (hEntity < 0 || hEntity >= psSHP->nRecords)
-	return (NULL);
+/* -------------------------------------------------------------------- */
+/*      Validate the record/entity number.                              */
+/* -------------------------------------------------------------------- */
+    if( hEntity < 0 || hEntity >= psSHP->nRecords )
+        return( NULL );
 
-    /* -------------------------------------------------------------------- */
-    /*      Ensure our record buffer is large enough.                       */
-    /* -------------------------------------------------------------------- */
-    nEntitySize = psSHP->panRecSize[hEntity] + 8;
-    if (nEntitySize > psSHP->nBufSize) {
-	psSHP->pabyRec = (uchar *) SfRealloc(psSHP->pabyRec, nEntitySize);
-	if (psSHP->pabyRec == NULL) {
-	    char szError[200];
+/* -------------------------------------------------------------------- */
+/*      Ensure our record buffer is large enough.                       */
+/* -------------------------------------------------------------------- */
+    nEntitySize = psSHP->panRecSize[hEntity]+8;
+    if( nEntitySize > psSHP->nBufSize )
+    {
+	psSHP->pabyRec = (uchar *) SfRealloc(psSHP->pabyRec,nEntitySize);
+        if (psSHP->pabyRec == NULL)
+        {
+            char szError[200];
 
-	    /* Reallocate previous successfull size for following features */
-	    psSHP->pabyRec = malloc(psSHP->nBufSize);
+            /* Reallocate previous successfull size for following features */
+            psSHP->pabyRec = malloc(psSHP->nBufSize);
 
-	    sprintf(szError,
-		    "Not enough memory to allocate requested memory (nBufSize=%d). "
-		    "Probably broken SHP file", psSHP->nBufSize);
-	    psSHP->sHooks.Error(szError);
-	    return NULL;
-	}
+            sprintf( szError, 
+                     "Not enough memory to allocate requested memory (nBufSize=%d). "
+                     "Probably broken SHP file", psSHP->nBufSize );
+            psSHP->sHooks.Error( szError );
+            return NULL;
+        }
 
-	/* Only set new buffer size after successfull alloc */
+        /* Only set new buffer size after successfull alloc */
 	psSHP->nBufSize = nEntitySize;
     }
 
     /* In case we were not able to reallocate the buffer on a previous step */
-    if (psSHP->pabyRec == NULL) {
-	return NULL;
+    if (psSHP->pabyRec == NULL)
+    {
+        return NULL;
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Read the record.                                                */
-    /* -------------------------------------------------------------------- */
-    if (psSHP->sHooks.FSeek(psSHP->fpSHP, psSHP->panRecOffset[hEntity], 0) !=
-	0 ||
-	psSHP->sHooks.FRead(psSHP->pabyRec, nEntitySize, 1,
-			    psSHP->fpSHP) != 1) {
-	/*
-	 * TODO - mloskot: Consider detailed diagnostics of shape file,
-	 * for example to detect if file is truncated.
-	 */
+/* -------------------------------------------------------------------- */
+/*      Read the record.                                                */
+/* -------------------------------------------------------------------- */
+    if( psSHP->sHooks.FSeek( psSHP->fpSHP, psSHP->panRecOffset[hEntity], 0 ) != 0 
+        || psSHP->sHooks.FRead( psSHP->pabyRec, nEntitySize, 1, 
+                  psSHP->fpSHP ) != 1 )
+    {
+        /*
+         * TODO - mloskot: Consider detailed diagnostics of shape file,
+         * for example to detect if file is truncated.
+         */
 
-	psSHP->sHooks.
-	    Error
-	    ("Error in fseek() or fread() reading object from .shp file.");
-	return NULL;
+        psSHP->sHooks.Error( "Error in fseek() or fread() reading object from .shp file." );
+        return NULL;
     }
 
-    /* -------------------------------------------------------------------- */
-    /*      Allocate and minimally initialize the object.                   */
-    /* -------------------------------------------------------------------- */
-    psShape = (SHPObject *) calloc(1, sizeof(SHPObject));
+/* -------------------------------------------------------------------- */
+/*	Allocate and minimally initialize the object.			*/
+/* -------------------------------------------------------------------- */
+    psShape = (SHPObject *) calloc(1,sizeof(SHPObject));
     psShape->nShapeId = hEntity;
     psShape->bMeasureIsUsed = FALSE;
 
-    if (8 + 4 > nEntitySize) {
-	snprintf(pszErrorMsg, 128,
-		 "Corrupted .shp file : shape %d : nEntitySize = %d", hEntity,
-		 nEntitySize);
-	psSHP->sHooks.Error(pszErrorMsg);
-	SHPDestroyObject(psShape);
-	return NULL;
+    if ( 8 + 4 > nEntitySize )
+    {
+        snprintf(pszErrorMsg, 128, "Corrupted .shp file : shape %d : nEntitySize = %d",
+                    hEntity, nEntitySize); 
+        psSHP->sHooks.Error( pszErrorMsg );
+        SHPDestroyObject(psShape);
+        return NULL;
     }
-    memcpy(&psShape->nSHPType, psSHP->pabyRec + 8, 4);
+    memcpy( &psShape->nSHPType, psSHP->pabyRec + 8, 4 );
 
-    if (bBigEndian)
-	SwapWord(4, &(psShape->nSHPType));
+    if( bBigEndian ) SwapWord( 4, &(psShape->nSHPType) );
 
-    /* ==================================================================== */
-    /*  Extract vertices for a Polygon or Arc.                              */
-    /* ==================================================================== */
-    if (psShape->nSHPType == SHPT_POLYGON || psShape->nSHPType == SHPT_ARC
-	|| psShape->nSHPType == SHPT_POLYGONZ
-	|| psShape->nSHPType == SHPT_POLYGONM
-	|| psShape->nSHPType == SHPT_ARCZ
-	|| psShape->nSHPType == SHPT_ARCM
-	|| psShape->nSHPType == SHPT_MULTIPATCH) {
-	int32 nPoints, nParts;
-	int i, nOffset;
+/* ==================================================================== */
+/*  Extract vertices for a Polygon or Arc.				*/
+/* ==================================================================== */
+    if( psShape->nSHPType == SHPT_POLYGON || psShape->nSHPType == SHPT_ARC
+        || psShape->nSHPType == SHPT_POLYGONZ
+        || psShape->nSHPType == SHPT_POLYGONM
+        || psShape->nSHPType == SHPT_ARCZ
+        || psShape->nSHPType == SHPT_ARCM
+        || psShape->nSHPType == SHPT_MULTIPATCH )
+    {
+	int32		nPoints, nParts;
+	int    		i, nOffset;
 
-	if (40 + 8 + 4 > nEntitySize) {
-	    snprintf(pszErrorMsg, 128,
-		     "Corrupted .shp file : shape %d : nEntitySize = %d",
-		     hEntity, nEntitySize);
-	    psSHP->sHooks.Error(pszErrorMsg);
-	    SHPDestroyObject(psShape);
-	    return NULL;
-	}
-	/* -------------------------------------------------------------------- */
-	/*      Get the X/Y bounds.                                             */
-	/* -------------------------------------------------------------------- */
-	memcpy(&(psShape->dfXMin), psSHP->pabyRec + 8 + 4, 8);
-	memcpy(&(psShape->dfYMin), psSHP->pabyRec + 8 + 12, 8);
-	memcpy(&(psShape->dfXMax), psSHP->pabyRec + 8 + 20, 8);
-	memcpy(&(psShape->dfYMax), psSHP->pabyRec + 8 + 28, 8);
+        if ( 40 + 8 + 4 > nEntitySize )
+        {
+            snprintf(pszErrorMsg, 128, "Corrupted .shp file : shape %d : nEntitySize = %d",
+                     hEntity, nEntitySize); 
+            psSHP->sHooks.Error( pszErrorMsg );
+            SHPDestroyObject(psShape);
+            return NULL;
+        }
+/* -------------------------------------------------------------------- */
+/*	Get the X/Y bounds.						*/
+/* -------------------------------------------------------------------- */
+        memcpy( &(psShape->dfXMin), psSHP->pabyRec + 8 +  4, 8 );
+        memcpy( &(psShape->dfYMin), psSHP->pabyRec + 8 + 12, 8 );
+        memcpy( &(psShape->dfXMax), psSHP->pabyRec + 8 + 20, 8 );
+        memcpy( &(psShape->dfYMax), psSHP->pabyRec + 8 + 28, 8 );
 
-	if (bBigEndian)
-	    SwapWord(8, &(psShape->dfXMin));
-	if (bBigEndian)
-	    SwapWord(8, &(psShape->dfYMin));
-	if (bBigEndian)
-	    SwapWord(8, &(psShape->dfXMax));
-	if (bBigEndian)
-	    SwapWord(8, &(psShape->dfYMax));
+	if( bBigEndian ) SwapWord( 8, &(psShape->dfXMin) );
+	if( bBigEndian ) SwapWord( 8, &(psShape->dfYMin) );
+	if( bBigEndian ) SwapWord( 8, &(psShape->dfXMax) );
+	if( bBigEndian ) SwapWord( 8, &(psShape->dfYMax) );
 
-	/* -------------------------------------------------------------------- */
-	/*      Extract part/point count, and build vertex and part arrays      */
-	/*      to proper size.                                                 */
-	/* -------------------------------------------------------------------- */
-	memcpy(&nPoints, psSHP->pabyRec + 40 + 8, 4);
-	memcpy(&nParts, psSHP->pabyRec + 36 + 8, 4);
+/* -------------------------------------------------------------------- */
+/*      Extract part/point count, and build vertex and part arrays      */
+/*      to proper size.                                                 */
+/* -------------------------------------------------------------------- */
+	memcpy( &nPoints, psSHP->pabyRec + 40 + 8, 4 );
+	memcpy( &nParts, psSHP->pabyRec + 36 + 8, 4 );
 
-	if (bBigEndian)
-	    SwapWord(4, &nPoints);
-	if (bBigEndian)
-	    SwapWord(4, &nParts);
+	if( bBigEndian ) SwapWord( 4, &nPoints );
+	if( bBigEndian ) SwapWord( 4, &nParts );
 
-	if (nPoints < 0 || nParts < 0 ||
-	    nPoints > 50 * 1000 * 1000 || nParts > 10 * 1000 * 1000) {
-	    snprintf(pszErrorMsg, 128,
-		     "Corrupted .shp file : shape %d, nPoints=%d, nParts=%d.",
-		     hEntity, nPoints, nParts);
-	    psSHP->sHooks.Error(pszErrorMsg);
-	    SHPDestroyObject(psShape);
-	    return NULL;
-	}
+        if (nPoints < 0 || nParts < 0 ||
+            nPoints > 50 * 1000 * 1000 || nParts > 10 * 1000 * 1000)
+        {
+            snprintf(pszErrorMsg, 128, "Corrupted .shp file : shape %d, nPoints=%d, nParts=%d.",
+                        hEntity, nPoints, nParts);
+            psSHP->sHooks.Error( pszErrorMsg );
+            SHPDestroyObject(psShape);
+            return NULL;
+        }
+        
+        /* With the previous checks on nPoints and nParts, */
+        /* we should not overflow here and after */
+        /* since 50 M * (16 + 8 + 8) = 1 600 MB */
+        nRequiredSize = 44 + 8 + 4 * nParts + 16 * nPoints;
+        if ( psShape->nSHPType == SHPT_POLYGONZ
+            || psShape->nSHPType == SHPT_ARCZ
+            || psShape->nSHPType == SHPT_MULTIPATCH )
+        {
+            nRequiredSize += 16 + 8 * nPoints;
+        }
+        if( psShape->nSHPType == SHPT_MULTIPATCH )
+        {
+            nRequiredSize += 4 * nParts;
+        }
+        if (nRequiredSize > nEntitySize)
+        {
+            snprintf(pszErrorMsg, 128, "Corrupted .shp file : shape %d, nPoints=%d, nParts=%d, nEntitySize=%d.",
+                        hEntity, nPoints, nParts, nEntitySize);
+            psSHP->sHooks.Error( pszErrorMsg );
+            SHPDestroyObject(psShape);
+            return NULL;
+        }
 
-	/* With the previous checks on nPoints and nParts, */
-	/* we should not overflow here and after */
-	/* since 50 M * (16 + 8 + 8) = 1 600 MB */
-	nRequiredSize = 44 + 8 + 4 * nParts + 16 * nPoints;
-	if (psShape->nSHPType == SHPT_POLYGONZ
-	    || psShape->nSHPType == SHPT_ARCZ
-	    || psShape->nSHPType == SHPT_MULTIPATCH) {
-	    nRequiredSize += 16 + 8 * nPoints;
-	}
-	if (psShape->nSHPType == SHPT_MULTIPATCH) {
-	    nRequiredSize += 4 * nParts;
-	}
-	if (nRequiredSize > nEntitySize) {
-	    snprintf(pszErrorMsg, 128,
-		     "Corrupted .shp file : shape %d, nPoints=%d, nParts=%d, nEntitySize=%d.",
-		     hEntity, nPoints, nParts, nEntitySize);
-	    psSHP->sHooks.Error(pszErrorMsg);
-	    SHPDestroyObject(psShape);
-	    return NULL;
-	}
-
 	psShape->nVertices = nPoints;
-	psShape->padfX = (double *)calloc(nPoints, sizeof(double));
-	psShape->padfY = (double *)calloc(nPoints, sizeof(double));
-	psShape->padfZ = (double *)calloc(nPoints, sizeof(double));
-	psShape->padfM = (double *)calloc(nPoints, sizeof(double));
+        psShape->padfX = (double *) calloc(nPoints,sizeof(double));
+        psShape->padfY = (double *) calloc(nPoints,sizeof(double));
+        psShape->padfZ = (double *) calloc(nPoints,sizeof(double));
+        psShape->padfM = (double *) calloc(nPoints,sizeof(double));
 
 	psShape->nParts = nParts;
-	psShape->panPartStart = (int *)calloc(nParts, sizeof(int));
-	psShape->panPartType = (int *)calloc(nParts, sizeof(int));
+        psShape->panPartStart = (int *) calloc(nParts,sizeof(int));
+        psShape->panPartType = (int *) calloc(nParts,sizeof(int));
+        
+        if (psShape->padfX == NULL ||
+            psShape->padfY == NULL ||
+            psShape->padfZ == NULL ||
+            psShape->padfM == NULL ||
+            psShape->panPartStart == NULL ||
+            psShape->panPartType == NULL)
+        {
+            snprintf(pszErrorMsg, 128,
+                     "Not enough memory to allocate requested memory (nPoints=%d, nParts=%d) for shape %d. "
+                     "Probably broken SHP file", hEntity, nPoints, nParts );
+            psSHP->sHooks.Error( pszErrorMsg );
+            SHPDestroyObject(psShape);
+            return NULL;
+        }
 
-	if (psShape->padfX == NULL ||
-	    psShape->padfY == NULL ||
-	    psShape->padfZ == NULL ||
-	    psShape->padfM == NULL ||
-	    psShape->panPartStart == NULL || psShape->panPartType == NULL) {
-	    snprintf(pszErrorMsg, 128,
-		     "Not enough memory to allocate requested memory (nPoints=%d, nParts=%d) for shape %d. "
-		     "Probably broken SHP file", hEntity, nPoints, nParts);
-	    psSHP->sHooks.Error(pszErrorMsg);
-	    SHPDestroyObject(psShape);
-	    return NULL;
-	}
+        for( i = 0; i < nParts; i++ )
+            psShape->panPartType[i] = SHPP_RING;
 
-	for (i = 0; i < nParts; i++)
-	    psShape->panPartType[i] = SHPP_RING;
+/* -------------------------------------------------------------------- */
+/*      Copy out the part array from the record.                        */
+/* -------------------------------------------------------------------- */
+	memcpy( psShape->panPartStart, psSHP->pabyRec + 44 + 8, 4 * nParts );
+	for( i = 0; i < nParts; i++ )
+	{
+	    if( bBigEndian ) SwapWord( 4, psShape->panPartStart+i );
 
-	/* -------------------------------------------------------------------- */
-	/*      Copy out the part array from the record.                        */
-	/* -------------------------------------------------------------------- */
-	memcpy(psShape->panPartStart, psSHP->pabyRec + 44 + 8, 4 * nParts);
-	for (i = 0; i < nParts; i++) {
-	    if (bBigEndian)
-		SwapWord(4, psShape->panPartStart + i);
-
-	    /* We check that the offset is inside the vertex array */
-	    if (psShape->panPartStart[i] < 0 ||
-		psShape->panPartStart[i] >= psShape->nVertices) {
-		snprintf(pszErrorMsg, 128,
-			 "Corrupted .shp file : shape %d : panPartStart[%d] = %d, nVertices = %d",
-			 hEntity, i, psShape->panPartStart[i],
-			 psShape->nVertices);
-		psSHP->sHooks.Error(pszErrorMsg);
-		SHPDestroyObject(psShape);
-		return NULL;
-	    }
-	    if (i > 0 &&
-		psShape->panPartStart[i] <= psShape->panPartStart[i - 1]) {
-		snprintf(pszErrorMsg, 128,
-			 "Corrupted .shp file : shape %d : panPartStart[%d] = %d, panPartStart[%d] = %d",
-			 hEntity, i, psShape->panPartStart[i], i - 1,
-			 psShape->panPartStart[i - 1]);
-		psSHP->sHooks.Error(pszErrorMsg);
-		SHPDestroyObject(psShape);
-		return NULL;
-	    }
+            /* We check that the offset is inside the vertex array */
+            if (psShape->panPartStart[i] < 0 ||
+                psShape->panPartStart[i] >= psShape->nVertices)
+            {
+                snprintf(pszErrorMsg, 128, "Corrupted .shp file : shape %d : panPartStart[%d] = %d, nVertices = %d",
+                         hEntity, i, psShape->panPartStart[i], psShape->nVertices); 
+                psSHP->sHooks.Error( pszErrorMsg );
+                SHPDestroyObject(psShape);
+                return NULL;
+            }
+            if (i > 0 && psShape->panPartStart[i] <= psShape->panPartStart[i-1])
+            {
+                snprintf(pszErrorMsg, 128, "Corrupted .shp file : shape %d : panPartStart[%d] = %d, panPartStart[%d] = %d",
+                         hEntity, i, psShape->panPartStart[i], i - 1, psShape->panPartStart[i - 1]); 
+                psSHP->sHooks.Error( pszErrorMsg );
+                SHPDestroyObject(psShape);
+                return NULL;
+            }
 	}
 
-	nOffset = 44 + 8 + 4 * nParts;
+	nOffset = 44 + 8 + 4*nParts;
 
-	/* -------------------------------------------------------------------- */
-	/*      If this is a multipatch, we will also have parts types.         */
-	/* -------------------------------------------------------------------- */
-	if (psShape->nSHPType == SHPT_MULTIPATCH) {
-	    memcpy(psShape->panPartType, psSHP->pabyRec + nOffset,
-		   4 * nParts);
-	    for (i = 0; i < nParts; i++) {
-		if (bBigEndian)
-		    SwapWord(4, psShape->panPartType + i);
-	    }
+/* -------------------------------------------------------------------- */
+/*      If this is a multipatch, we will also have parts types.         */
+/* -------------------------------------------------------------------- */
+        if( psShape->nSHPType == SHPT_MULTIPATCH )
+        {
+            memcpy( psShape->panPartType, psSHP->pabyRec + nOffset, 4*nParts );
+            for( i = 0; i < nParts; i++ )
+            {
+                if( bBigEndian ) SwapWord( 4, psShape->panPartType+i );
+            }
 
-	    nOffset += 4 * nParts;
-	}
+            nOffset += 4*nParts;
+        }
+        
+/* -------------------------------------------------------------------- */
+/*      Copy out the vertices from the record.                          */
+/* -------------------------------------------------------------------- */
+	for( i = 0; i < nPoints; i++ )
+	{
+	    memcpy(psShape->padfX + i,
+		   psSHP->pabyRec + nOffset + i * 16,
+		   8 );
 
-	/* -------------------------------------------------------------------- */
-	/*      Copy out the vertices from the record.                          */
-	/* -------------------------------------------------------------------- */
-	for (i = 0; i < nPoints; i++) {
-	    memcpy(psShape->padfX + i, psSHP->pabyRec + nOffset + i * 16, 8);
-
 	    memcpy(psShape->padfY + i,
-		   psSHP->pabyRec + nOffset + i * 16 + 8, 8);
+		   psSHP->pabyRec + nOffset + i * 16 + 8,
+		   8 );
 
-	    if (bBigEndian)
-		SwapWord(8, psShape->padfX + i);
-	    if (bBigEndian)
-		SwapWord(8, psShape->padfY + i);
+	    if( bBigEndian ) SwapWord( 8, psShape->padfX + i );
+	    if( bBigEndian ) SwapWord( 8, psShape->padfY + i );
 	}
 
-	nOffset += 16 * nPoints;
+        nOffset += 16*nPoints;
+        
+/* -------------------------------------------------------------------- */
+/*      If we have a Z coordinate, collect that now.                    */
+/* -------------------------------------------------------------------- */
+        if( psShape->nSHPType == SHPT_POLYGONZ
+            || psShape->nSHPType == SHPT_ARCZ
+            || psShape->nSHPType == SHPT_MULTIPATCH )
+        {
+            memcpy( &(psShape->dfZMin), psSHP->pabyRec + nOffset, 8 );
+            memcpy( &(psShape->dfZMax), psSHP->pabyRec + nOffset + 8, 8 );
+            
+            if( bBigEndian ) SwapWord( 8, &(psShape->dfZMin) );
+            if( bBigEndian ) SwapWord( 8, &(psShape->dfZMax) );
+            
+            for( i = 0; i < nPoints; i++ )
+            {
+                memcpy( psShape->padfZ + i,
+                        psSHP->pabyRec + nOffset + 16 + i*8, 8 );
+                if( bBigEndian ) SwapWord( 8, psShape->padfZ + i );
+            }
 
-	/* -------------------------------------------------------------------- */
-	/*      If we have a Z coordinate, collect that now.                    */
-	/* -------------------------------------------------------------------- */
-	if (psShape->nSHPType == SHPT_POLYGONZ
-	    || psShape->nSHPType == SHPT_ARCZ
-	    || psShape->nSHPType == SHPT_MULTIPATCH) {
-	    memcpy(&(psShape->dfZMin), psSHP->pabyRec + nOffset, 8);
-	    memcpy(&(psShape->dfZMax), psSHP->pabyRec + nOffset + 8, 8);
+            nOffset += 16 + 8*nPoints;
+        }
 
-	    if (bBigEndian)
-		SwapWord(8, &(psShape->dfZMin));
-	    if (bBigEndian)
-		SwapWord(8, &(psShape->dfZMax));
-
-	    for (i = 0; i < nPoints; i++) {
-		memcpy(psShape->padfZ + i,
-		       psSHP->pabyRec + nOffset + 16 + i * 8, 8);
-		if (bBigEndian)
-		    SwapWord(8, psShape->padfZ + i);
-	    }
-
-	    nOffset += 16 + 8 * nPoints;
-	}
-
-	/* -------------------------------------------------------------------- */
-	/*      If we have a M measure value, then read it now.  We assume      */
-	/*      that the measure can be present for any shape if the size is    */
-	/*      big enough, but really it will only occur for the Z shapes      */
-	/*      (options), and the M shapes.                                    */
-	/* -------------------------------------------------------------------- */
-	if (nEntitySize >= nOffset + 16 + 8 * nPoints) {
-	    memcpy(&(psShape->dfMMin), psSHP->pabyRec + nOffset, 8);
-	    memcpy(&(psShape->dfMMax), psSHP->pabyRec + nOffset + 8, 8);
-
-	    if (bBigEndian)
-		SwapWord(8, &(psShape->dfMMin));
-	    if (bBigEndian)
-		SwapWord(8, &(psShape->dfMMax));
-
-	    for (i = 0; i < nPoints; i++) {
-		memcpy(psShape->padfM + i,
-		       psSHP->pabyRec + nOffset + 16 + i * 8, 8);
-		if (bBigEndian)
-		    SwapWord(8, psShape->padfM + i);
-	    }
-	    psShape->bMeasureIsUsed = TRUE;
-	}
+/* -------------------------------------------------------------------- */
+/*      If we have a M measure value, then read it now.  We assume      */
+/*      that the measure can be present for any shape if the size is    */
+/*      big enough, but really it will only occur for the Z shapes      */
+/*      (options), and the M shapes.                                    */
+/* -------------------------------------------------------------------- */
+        if( nEntitySize >= nOffset + 16 + 8*nPoints )
+        {
+            memcpy( &(psShape->dfMMin), psSHP->pabyRec + nOffset, 8 );
+            memcpy( &(psShape->dfMMax), psSHP->pabyRec + nOffset + 8, 8 );
+            
+            if( bBigEndian ) SwapWord( 8, &(psShape->dfMMin) );
+            if( bBigEndian ) SwapWord( 8, &(psShape->dfMMax) );
+            
+            for( i = 0; i < nPoints; i++ )
+            {
+                memcpy( psShape->padfM + i,
+                        psSHP->pabyRec + nOffset + 16 + i*8, 8 );
+                if( bBigEndian ) SwapWord( 8, psShape->padfM + i );
+            }
+            psShape->bMeasureIsUsed = TRUE;
+        }
     }
 
-    /* ==================================================================== */
-    /*  Extract vertices for a MultiPoint.                                  */
-    /* ==================================================================== */
-    else if (psShape->nSHPType == SHPT_MULTIPOINT
-	     || psShape->nSHPType == SHPT_MULTIPOINTM
-	     || psShape->nSHPType == SHPT_MULTIPOINTZ) {
-	int32 nPoints;
-	int i, nOffset;
+/* ==================================================================== */
+/*  Extract vertices for a MultiPoint.					*/
+/* ==================================================================== */
+    else if( psShape->nSHPType == SHPT_MULTIPOINT
+             || psShape->nSHPType == SHPT_MULTIPOINTM
+             || psShape->nSHPType == SHPT_MULTIPOINTZ )
+    {
+	int32		nPoints;
+	int    		i, nOffset;
 
-	if (44 + 4 > nEntitySize) {
-	    snprintf(pszErrorMsg, 128,
-		     "Corrupted .shp file : shape %d : nEntitySize = %d",
-		     hEntity, nEntitySize);
-	    psSHP->sHooks.Error(pszErrorMsg);
-	    SHPDestroyObject(psShape);
-	    return NULL;
-	}
-	memcpy(&nPoints, psSHP->pabyRec + 44, 4);
+        if ( 44 + 4 > nEntitySize )
+        {
+            snprintf(pszErrorMsg, 128, "Corrupted .shp file : shape %d : nEntitySize = %d",
+                     hEntity, nEntitySize); 
+            psSHP->sHooks.Error( pszErrorMsg );
+            SHPDestroyObject(psShape);
+            return NULL;
+        }
+	memcpy( &nPoints, psSHP->pabyRec + 44, 4 );
 
-	if (bBigEndian)
-	    SwapWord(4, &nPoints);
+	if( bBigEndian ) SwapWord( 4, &nPoints );
 
-	if (nPoints < 0 || nPoints > 50 * 1000 * 1000) {
-	    snprintf(pszErrorMsg, 128,
-		     "Corrupted .shp file : shape %d : nPoints = %d", hEntity,
-		     nPoints);
-	    psSHP->sHooks.Error(pszErrorMsg);
-	    SHPDestroyObject(psShape);
-	    return NULL;
-	}
+        if (nPoints < 0 || nPoints > 50 * 1000 * 1000)
+        {
+            snprintf(pszErrorMsg, 128, "Corrupted .shp file : shape %d : nPoints = %d",
+                     hEntity, nPoints); 
+            psSHP->sHooks.Error( pszErrorMsg );
+            SHPDestroyObject(psShape);
+            return NULL;
+        }
 
-	nRequiredSize = 48 + nPoints * 16;
-	if (psShape->nSHPType == SHPT_MULTIPOINTZ) {
-	    nRequiredSize += 16 + nPoints * 8;
-	}
-	if (nRequiredSize > nEntitySize) {
-	    snprintf(pszErrorMsg, 128,
-		     "Corrupted .shp file : shape %d : nPoints = %d, nEntitySize = %d",
-		     hEntity, nPoints, nEntitySize);
-	    psSHP->sHooks.Error(pszErrorMsg);
-	    SHPDestroyObject(psShape);
-	    return NULL;
-	}
-
+        nRequiredSize = 48 + nPoints * 16;
+        if( psShape->nSHPType == SHPT_MULTIPOINTZ )
+        {
+            nRequiredSize += 16 + nPoints * 8;
+        }
+        if (nRequiredSize > nEntitySize)
+        {
+            snprintf(pszErrorMsg, 128, "Corrupted .shp file : shape %d : nPoints = %d, nEntitySize = %d",
+                     hEntity, nPoints, nEntitySize); 
+            psSHP->sHooks.Error( pszErrorMsg );
+            SHPDestroyObject(psShape);
+            return NULL;
+        }
+        
 	psShape->nVertices = nPoints;
-	psShape->padfX = (double *)calloc(nPoints, sizeof(double));
-	psShape->padfY = (double *)calloc(nPoints, sizeof(double));
-	psShape->padfZ = (double *)calloc(nPoints, sizeof(double));
-	psShape->padfM = (double *)calloc(nPoints, sizeof(double));
+        psShape->padfX = (double *) calloc(nPoints,sizeof(double));
+        psShape->padfY = (double *) calloc(nPoints,sizeof(double));
+        psShape->padfZ = (double *) calloc(nPoints,sizeof(double));
+        psShape->padfM = (double *) calloc(nPoints,sizeof(double));
 
-	if (psShape->padfX == NULL ||
-	    psShape->padfY == NULL ||
-	    psShape->padfZ == NULL || psShape->padfM == NULL) {
-	    snprintf(pszErrorMsg, 128,
-		     "Not enough memory to allocate requested memory (nPoints=%d) for shape %d. "
-		     "Probably broken SHP file", hEntity, nPoints);
-	    psSHP->sHooks.Error(pszErrorMsg);
-	    SHPDestroyObject(psShape);
-	    return NULL;
-	}
+        if (psShape->padfX == NULL ||
+            psShape->padfY == NULL ||
+            psShape->padfZ == NULL ||
+            psShape->padfM == NULL)
+        {
+            snprintf(pszErrorMsg, 128,
+                     "Not enough memory to allocate requested memory (nPoints=%d) for shape %d. "
+                     "Probably broken SHP file", hEntity, nPoints );
+            psSHP->sHooks.Error( pszErrorMsg );
+            SHPDestroyObject(psShape);
+            return NULL;
+        }
 
-	for (i = 0; i < nPoints; i++) {
-	    memcpy(psShape->padfX + i, psSHP->pabyRec + 48 + 16 * i, 8);
-	    memcpy(psShape->padfY + i, psSHP->pabyRec + 48 + 16 * i + 8, 8);
+	for( i = 0; i < nPoints; i++ )
+	{
+	    memcpy(psShape->padfX+i, psSHP->pabyRec + 48 + 16 * i, 8 );
+	    memcpy(psShape->padfY+i, psSHP->pabyRec + 48 + 16 * i + 8, 8 );
 
-	    if (bBigEndian)
-		SwapWord(8, psShape->padfX + i);
-	    if (bBigEndian)
-		SwapWord(8, psShape->padfY + i);
+	    if( bBigEndian ) SwapWord( 8, psShape->padfX + i );
+	    if( bBigEndian ) SwapWord( 8, psShape->padfY + i );
 	}
 
-	nOffset = 48 + 16 * nPoints;
+        nOffset = 48 + 16*nPoints;
+        
+/* -------------------------------------------------------------------- */
+/*	Get the X/Y bounds.						*/
+/* -------------------------------------------------------------------- */
+        memcpy( &(psShape->dfXMin), psSHP->pabyRec + 8 +  4, 8 );
+        memcpy( &(psShape->dfYMin), psSHP->pabyRec + 8 + 12, 8 );
+        memcpy( &(psShape->dfXMax), psSHP->pabyRec + 8 + 20, 8 );
+        memcpy( &(psShape->dfYMax), psSHP->pabyRec + 8 + 28, 8 );
 
-	/* -------------------------------------------------------------------- */
-	/*      Get the X/Y bounds.                                             */
-	/* -------------------------------------------------------------------- */
-	memcpy(&(psShape->dfXMin), psSHP->pabyRec + 8 + 4, 8);
-	memcpy(&(psShape->dfYMin), psSHP->pabyRec + 8 + 12, 8);
-	memcpy(&(psShape->dfXMax), psSHP->pabyRec + 8 + 20, 8);
-	memcpy(&(psShape->dfYMax), psSHP->pabyRec + 8 + 28, 8);
+	if( bBigEndian ) SwapWord( 8, &(psShape->dfXMin) );
+	if( bBigEndian ) SwapWord( 8, &(psShape->dfYMin) );
+	if( bBigEndian ) SwapWord( 8, &(psShape->dfXMax) );
+	if( bBigEndian ) SwapWord( 8, &(psShape->dfYMax) );
 
-	if (bBigEndian)
-	    SwapWord(8, &(psShape->dfXMin));
-	if (bBigEndian)
-	    SwapWord(8, &(psShape->dfYMin));
-	if (bBigEndian)
-	    SwapWord(8, &(psShape->dfXMax));
-	if (bBigEndian)
-	    SwapWord(8, &(psShape->dfYMax));
+/* -------------------------------------------------------------------- */
+/*      If we have a Z coordinate, collect that now.                    */
+/* -------------------------------------------------------------------- */
+        if( psShape->nSHPType == SHPT_MULTIPOINTZ )
+        {
+            memcpy( &(psShape->dfZMin), psSHP->pabyRec + nOffset, 8 );
+            memcpy( &(psShape->dfZMax), psSHP->pabyRec + nOffset + 8, 8 );
+            
+            if( bBigEndian ) SwapWord( 8, &(psShape->dfZMin) );
+            if( bBigEndian ) SwapWord( 8, &(psShape->dfZMax) );
+            
+            for( i = 0; i < nPoints; i++ )
+            {
+                memcpy( psShape->padfZ + i,
+                        psSHP->pabyRec + nOffset + 16 + i*8, 8 );
+                if( bBigEndian ) SwapWord( 8, psShape->padfZ + i );
+            }
 
-	/* -------------------------------------------------------------------- */
-	/*      If we have a Z coordinate, collect that now.                    */
-	/* -------------------------------------------------------------------- */
-	if (psShape->nSHPType == SHPT_MULTIPOINTZ) {
-	    memcpy(&(psShape->dfZMin), psSHP->pabyRec + nOffset, 8);
-	    memcpy(&(psShape->dfZMax), psSHP->pabyRec + nOffset + 8, 8);
+            nOffset += 16 + 8*nPoints;
+        }
 
-	    if (bBigEndian)
-		SwapWord(8, &(psShape->dfZMin));
-	    if (bBigEndian)
-		SwapWord(8, &(psShape->dfZMax));
-
-	    for (i = 0; i < nPoints; i++) {
-		memcpy(psShape->padfZ + i,
-		       psSHP->pabyRec + nOffset + 16 + i * 8, 8);
-		if (bBigEndian)
-		    SwapWord(8, psShape->padfZ + i);
-	    }
-
-	    nOffset += 16 + 8 * nPoints;
-	}
-
-	/* -------------------------------------------------------------------- */
-	/*      If we have a M measure value, then read it now.  We assume      */
-	/*      that the measure can be present for any shape if the size is    */
-	/*      big enough, but really it will only occur for the Z shapes      */
-	/*      (options), and the M shapes.                                    */
-	/* -------------------------------------------------------------------- */
-	if (nEntitySize >= nOffset + 16 + 8 * nPoints) {
-	    memcpy(&(psShape->dfMMin), psSHP->pabyRec + nOffset, 8);
-	    memcpy(&(psShape->dfMMax), psSHP->pabyRec + nOffset + 8, 8);
-
-	    if (bBigEndian)
-		SwapWord(8, &(psShape->dfMMin));
-	    if (bBigEndian)
-		SwapWord(8, &(psShape->dfMMax));
-
-	    for (i = 0; i < nPoints; i++) {
-		memcpy(psShape->padfM + i,
-		       psSHP->pabyRec + nOffset + 16 + i * 8, 8);
-		if (bBigEndian)
-		    SwapWord(8, psShape->padfM + i);
-	    }
-	    psShape->bMeasureIsUsed = TRUE;
-	}
+/* -------------------------------------------------------------------- */
+/*      If we have a M measure value, then read it now.  We assume      */
+/*      that the measure can be present for any shape if the size is    */
+/*      big enough, but really it will only occur for the Z shapes      */
+/*      (options), and the M shapes.                                    */
+/* -------------------------------------------------------------------- */
+        if( nEntitySize >= nOffset + 16 + 8*nPoints )
+        {
+            memcpy( &(psShape->dfMMin), psSHP->pabyRec + nOffset, 8 );
+            memcpy( &(psShape->dfMMax), psSHP->pabyRec + nOffset + 8, 8 );
+            
+            if( bBigEndian ) SwapWord( 8, &(psShape->dfMMin) );
+            if( bBigEndian ) SwapWord( 8, &(psShape->dfMMax) );
+            
+            for( i = 0; i < nPoints; i++ )
+            {
+                memcpy( psShape->padfM + i,
+                        psSHP->pabyRec + nOffset + 16 + i*8, 8 );
+                if( bBigEndian ) SwapWord( 8, psShape->padfM + i );
+            }
+            psShape->bMeasureIsUsed = TRUE;
+        }
     }
 
-    /* ==================================================================== */
-    /*      Extract vertices for a point.                                   */
-    /* ==================================================================== */
-    else if (psShape->nSHPType == SHPT_POINT
-	     || psShape->nSHPType == SHPT_POINTM
-	     || psShape->nSHPType == SHPT_POINTZ) {
-	int nOffset;
-
+/* ==================================================================== */
+/*      Extract vertices for a point.                                   */
+/* ==================================================================== */
+    else if( psShape->nSHPType == SHPT_POINT
+             || psShape->nSHPType == SHPT_POINTM
+             || psShape->nSHPType == SHPT_POINTZ )
+    {
+        int	nOffset;
+        
 	psShape->nVertices = 1;
-	psShape->padfX = (double *)calloc(1, sizeof(double));
-	psShape->padfY = (double *)calloc(1, sizeof(double));
-	psShape->padfZ = (double *)calloc(1, sizeof(double));
-	psShape->padfM = (double *)calloc(1, sizeof(double));
+        psShape->padfX = (double *) calloc(1,sizeof(double));
+        psShape->padfY = (double *) calloc(1,sizeof(double));
+        psShape->padfZ = (double *) calloc(1,sizeof(double));
+        psShape->padfM = (double *) calloc(1,sizeof(double));
 
-	if (20 + 8 + ((psShape->nSHPType == SHPT_POINTZ) ? 8 : 0) >
-	    nEntitySize) {
-	    snprintf(pszErrorMsg, 128,
-		     "Corrupted .shp file : shape %d : nEntitySize = %d",
-		     hEntity, nEntitySize);
-	    psSHP->sHooks.Error(pszErrorMsg);
-	    SHPDestroyObject(psShape);
-	    return NULL;
-	}
-	memcpy(psShape->padfX, psSHP->pabyRec + 12, 8);
-	memcpy(psShape->padfY, psSHP->pabyRec + 20, 8);
+        if (20 + 8 + (( psShape->nSHPType == SHPT_POINTZ ) ? 8 : 0)> nEntitySize)
+        {
+            snprintf(pszErrorMsg, 128, "Corrupted .shp file : shape %d : nEntitySize = %d",
+                     hEntity, nEntitySize); 
+            psSHP->sHooks.Error( pszErrorMsg );
+            SHPDestroyObject(psShape);
+            return NULL;
+        }
+	memcpy( psShape->padfX, psSHP->pabyRec + 12, 8 );
+	memcpy( psShape->padfY, psSHP->pabyRec + 20, 8 );
 
-	if (bBigEndian)
-	    SwapWord(8, psShape->padfX);
-	if (bBigEndian)
-	    SwapWord(8, psShape->padfY);
+	if( bBigEndian ) SwapWord( 8, psShape->padfX );
+	if( bBigEndian ) SwapWord( 8, psShape->padfY );
 
-	nOffset = 20 + 8;
+        nOffset = 20 + 8;
+        
+/* -------------------------------------------------------------------- */
+/*      If we have a Z coordinate, collect that now.                    */
+/* -------------------------------------------------------------------- */
+        if( psShape->nSHPType == SHPT_POINTZ )
+        {
+            memcpy( psShape->padfZ, psSHP->pabyRec + nOffset, 8 );
+        
+            if( bBigEndian ) SwapWord( 8, psShape->padfZ );
+            
+            nOffset += 8;
+        }
 
-	/* -------------------------------------------------------------------- */
-	/*      If we have a Z coordinate, collect that now.                    */
-	/* -------------------------------------------------------------------- */
-	if (psShape->nSHPType == SHPT_POINTZ) {
-	    memcpy(psShape->padfZ, psSHP->pabyRec + nOffset, 8);
+/* -------------------------------------------------------------------- */
+/*      If we have a M measure value, then read it now.  We assume      */
+/*      that the measure can be present for any shape if the size is    */
+/*      big enough, but really it will only occur for the Z shapes      */
+/*      (options), and the M shapes.                                    */
+/* -------------------------------------------------------------------- */
+        if( nEntitySize >= nOffset + 8 )
+        {
+            memcpy( psShape->padfM, psSHP->pabyRec + nOffset, 8 );
+        
+            if( bBigEndian ) SwapWord( 8, psShape->padfM );
+            psShape->bMeasureIsUsed = TRUE;
+        }
 
-	    if (bBigEndian)
-		SwapWord(8, psShape->padfZ);
-
-	    nOffset += 8;
-	}
-
-	/* -------------------------------------------------------------------- */
-	/*      If we have a M measure value, then read it now.  We assume      */
-	/*      that the measure can be present for any shape if the size is    */
-	/*      big enough, but really it will only occur for the Z shapes      */
-	/*      (options), and the M shapes.                                    */
-	/* -------------------------------------------------------------------- */
-	if (nEntitySize >= nOffset + 8) {
-	    memcpy(psShape->padfM, psSHP->pabyRec + nOffset, 8);
-
-	    if (bBigEndian)
-		SwapWord(8, psShape->padfM);
-	    psShape->bMeasureIsUsed = TRUE;
-	}
-
-	/* -------------------------------------------------------------------- */
-	/*      Since no extents are supplied in the record, we will apply      */
-	/*      them from the single vertex.                                    */
-	/* -------------------------------------------------------------------- */
-	psShape->dfXMin = psShape->dfXMax = psShape->padfX[0];
-	psShape->dfYMin = psShape->dfYMax = psShape->padfY[0];
-	psShape->dfZMin = psShape->dfZMax = psShape->padfZ[0];
-	psShape->dfMMin = psShape->dfMMax = psShape->padfM[0];
+/* -------------------------------------------------------------------- */
+/*      Since no extents are supplied in the record, we will apply      */
+/*      them from the single vertex.                                    */
+/* -------------------------------------------------------------------- */
+        psShape->dfXMin = psShape->dfXMax = psShape->padfX[0];
+        psShape->dfYMin = psShape->dfYMax = psShape->padfY[0];
+        psShape->dfZMin = psShape->dfZMax = psShape->padfZ[0];
+        psShape->dfMMin = psShape->dfMMax = psShape->padfM[0];
     }
 
-    return (psShape);
+    return( psShape );
 }
 
 /************************************************************************/
 /*                            SHPTypeName()                             */
-
 /************************************************************************/
 
-const char SHPAPI_CALL1(*) SHPTypeName(int nSHPType)
+const char SHPAPI_CALL1(*)
+SHPTypeName( int nSHPType )
+
 {
-    switch (nSHPType) {
-    case SHPT_NULL:
-	return "NullShape";
+    switch( nSHPType )
+    {
+      case SHPT_NULL:
+        return "NullShape";
 
-    case SHPT_POINT:
-	return "Point";
+      case SHPT_POINT:
+        return "Point";
 
-    case SHPT_ARC:
-	return "Arc";
+      case SHPT_ARC:
+        return "Arc";
 
-    case SHPT_POLYGON:
-	return "Polygon";
+      case SHPT_POLYGON:
+        return "Polygon";
 
-    case SHPT_MULTIPOINT:
-	return "MultiPoint";
+      case SHPT_MULTIPOINT:
+        return "MultiPoint";
+        
+      case SHPT_POINTZ:
+        return "PointZ";
 
-    case SHPT_POINTZ:
-	return "PointZ";
+      case SHPT_ARCZ:
+        return "ArcZ";
 
-    case SHPT_ARCZ:
-	return "ArcZ";
+      case SHPT_POLYGONZ:
+        return "PolygonZ";
 
-    case SHPT_POLYGONZ:
-	return "PolygonZ";
+      case SHPT_MULTIPOINTZ:
+        return "MultiPointZ";
+        
+      case SHPT_POINTM:
+        return "PointM";
 
-    case SHPT_MULTIPOINTZ:
-	return "MultiPointZ";
+      case SHPT_ARCM:
+        return "ArcM";
 
-    case SHPT_POINTM:
-	return "PointM";
+      case SHPT_POLYGONM:
+        return "PolygonM";
 
-    case SHPT_ARCM:
-	return "ArcM";
+      case SHPT_MULTIPOINTM:
+        return "MultiPointM";
 
-    case SHPT_POLYGONM:
-	return "PolygonM";
+      case SHPT_MULTIPATCH:
+        return "MultiPatch";
 
-    case SHPT_MULTIPOINTM:
-	return "MultiPointM";
-
-    case SHPT_MULTIPATCH:
-	return "MultiPatch";
-
-    default:
-	return "UnknownShapeType";
+      default:
+        return "UnknownShapeType";
     }
 }
 
 /************************************************************************/
 /*                          SHPPartTypeName()                           */
-
 /************************************************************************/
 
-const char SHPAPI_CALL1(*) SHPPartTypeName(int nPartType)
+const char SHPAPI_CALL1(*)
+SHPPartTypeName( int nPartType )
+
 {
-    switch (nPartType) {
-    case SHPP_TRISTRIP:
-	return "TriangleStrip";
+    switch( nPartType )
+    {
+      case SHPP_TRISTRIP:
+        return "TriangleStrip";
+        
+      case SHPP_TRIFAN:
+        return "TriangleFan";
 
-    case SHPP_TRIFAN:
-	return "TriangleFan";
+      case SHPP_OUTERRING:
+        return "OuterRing";
 
-    case SHPP_OUTERRING:
-	return "OuterRing";
+      case SHPP_INNERRING:
+        return "InnerRing";
 
-    case SHPP_INNERRING:
-	return "InnerRing";
+      case SHPP_FIRSTRING:
+        return "FirstRing";
 
-    case SHPP_FIRSTRING:
-	return "FirstRing";
+      case SHPP_RING:
+        return "Ring";
 
-    case SHPP_RING:
-	return "Ring";
-
-    default:
-	return "UnknownPartType";
+      default:
+        return "UnknownPartType";
     }
 }
 
 /************************************************************************/
 /*                          SHPDestroyObject()                          */
-
 /************************************************************************/
 
-void SHPAPI_CALL SHPDestroyObject(SHPObject * psShape)
+void SHPAPI_CALL
+SHPDestroyObject( SHPObject * psShape )
+
 {
-    if (psShape == NULL)
-	return;
+    if( psShape == NULL )
+        return;
+    
+    if( psShape->padfX != NULL )
+        free( psShape->padfX );
+    if( psShape->padfY != NULL )
+        free( psShape->padfY );
+    if( psShape->padfZ != NULL )
+        free( psShape->padfZ );
+    if( psShape->padfM != NULL )
+        free( psShape->padfM );
 
-    if (psShape->padfX != NULL)
-	free(psShape->padfX);
-    if (psShape->padfY != NULL)
-	free(psShape->padfY);
-    if (psShape->padfZ != NULL)
-	free(psShape->padfZ);
-    if (psShape->padfM != NULL)
-	free(psShape->padfM);
+    if( psShape->panPartStart != NULL )
+        free( psShape->panPartStart );
+    if( psShape->panPartType != NULL )
+        free( psShape->panPartType );
 
-    if (psShape->panPartStart != NULL)
-	free(psShape->panPartStart);
-    if (psShape->panPartType != NULL)
-	free(psShape->panPartType);
-
-    free(psShape);
+    free( psShape );
 }
 
 /************************************************************************/
@@ -2122,163 +2117,167 @@
 /*                                                                      */
 /*      Reset the winding of polygon objects to adhere to the           */
 /*      specification.                                                  */
-
 /************************************************************************/
 
-int SHPAPI_CALL SHPRewindObject(SHPHandle hSHP, SHPObject * psObject)
+int SHPAPI_CALL
+SHPRewindObject( SHPHandle hSHP, SHPObject * psObject )
+
 {
-    int iOpRing, bAltered = 0;
+    int  iOpRing, bAltered = 0;
 
-    /* -------------------------------------------------------------------- */
-    /*      Do nothing if this is not a polygon object.                     */
-    /* -------------------------------------------------------------------- */
-    if (psObject->nSHPType != SHPT_POLYGON
-	&& psObject->nSHPType != SHPT_POLYGONZ
-	&& psObject->nSHPType != SHPT_POLYGONM)
-	return 0;
+/* -------------------------------------------------------------------- */
+/*      Do nothing if this is not a polygon object.                     */
+/* -------------------------------------------------------------------- */
+    if( psObject->nSHPType != SHPT_POLYGON
+        && psObject->nSHPType != SHPT_POLYGONZ
+        && psObject->nSHPType != SHPT_POLYGONM )
+        return 0;
 
-    if (psObject->nVertices == 0 || psObject->nParts == 0)
-	return 0;
+    if( psObject->nVertices == 0 || psObject->nParts == 0 )
+        return 0;
 
-    /* -------------------------------------------------------------------- */
-    /*      Process each of the rings.                                      */
-    /* -------------------------------------------------------------------- */
-    for (iOpRing = 0; iOpRing < psObject->nParts; iOpRing++) {
-	int bInner, iVert, nVertCount, nVertStart, iCheckRing;
-	double dfSum, dfTestX, dfTestY;
+/* -------------------------------------------------------------------- */
+/*      Process each of the rings.                                      */
+/* -------------------------------------------------------------------- */
+    for( iOpRing = 0; iOpRing < psObject->nParts; iOpRing++ )
+    {
+        int      bInner, iVert, nVertCount, nVertStart, iCheckRing;
+        double   dfSum, dfTestX, dfTestY;
 
-	/* -------------------------------------------------------------------- */
-	/*      Determine if this ring is an inner ring or an outer ring        */
-	/*      relative to all the other rings.  For now we assume the         */
-	/*      first ring is outer and all others are inner, but eventually    */
-	/*      we need to fix this to handle multiple island polygons and      */
-	/*      unordered sets of rings.                                        */
-	/*                                                                      */
-	/* -------------------------------------------------------------------- */
+/* -------------------------------------------------------------------- */
+/*      Determine if this ring is an inner ring or an outer ring        */
+/*      relative to all the other rings.  For now we assume the         */
+/*      first ring is outer and all others are inner, but eventually    */
+/*      we need to fix this to handle multiple island polygons and      */
+/*      unordered sets of rings.                                        */
+/*                                                                      */
+/* -------------------------------------------------------------------- */
 
-	/* Use point in the middle of segment to avoid testing
-	 * common points of rings.
-	 */
-	dfTestX = (psObject->padfX[psObject->panPartStart[iOpRing]]
-		   + psObject->padfX[psObject->panPartStart[iOpRing] +
-				     1]) / 2;
-	dfTestY = (psObject->padfY[psObject->panPartStart[iOpRing]]
-		   + psObject->padfY[psObject->panPartStart[iOpRing] +
-				     1]) / 2;
+        /* Use point in the middle of segment to avoid testing
+         * common points of rings.
+         */
+        dfTestX = ( psObject->padfX[psObject->panPartStart[iOpRing]]
+                    + psObject->padfX[psObject->panPartStart[iOpRing] + 1] ) / 2;
+        dfTestY = ( psObject->padfY[psObject->panPartStart[iOpRing]]
+                    + psObject->padfY[psObject->panPartStart[iOpRing] + 1] ) / 2;
 
-	bInner = FALSE;
-	for (iCheckRing = 0; iCheckRing < psObject->nParts; iCheckRing++) {
-	    int iEdge;
+        bInner = FALSE;
+        for( iCheckRing = 0; iCheckRing < psObject->nParts; iCheckRing++ )
+        {
+            int iEdge;
 
-	    if (iCheckRing == iOpRing)
-		continue;
+            if( iCheckRing == iOpRing )
+                continue;
+            
+            nVertStart = psObject->panPartStart[iCheckRing];
 
-	    nVertStart = psObject->panPartStart[iCheckRing];
+            if( iCheckRing == psObject->nParts-1 )
+                nVertCount = psObject->nVertices 
+                    - psObject->panPartStart[iCheckRing];
+            else
+                nVertCount = psObject->panPartStart[iCheckRing+1] 
+                    - psObject->panPartStart[iCheckRing];
 
-	    if (iCheckRing == psObject->nParts - 1)
-		nVertCount = psObject->nVertices
-		    - psObject->panPartStart[iCheckRing];
-	    else
-		nVertCount = psObject->panPartStart[iCheckRing + 1]
-		    - psObject->panPartStart[iCheckRing];
+            for( iEdge = 0; iEdge < nVertCount; iEdge++ )
+            {
+                int iNext;
 
-	    for (iEdge = 0; iEdge < nVertCount; iEdge++) {
-		int iNext;
+                if( iEdge < nVertCount-1 )
+                    iNext = iEdge+1;
+                else
+                    iNext = 0;
 
-		if (iEdge < nVertCount - 1)
-		    iNext = iEdge + 1;
-		else
-		    iNext = 0;
+                /* Rule #1:
+                 * Test whether the edge 'straddles' the horizontal ray from the test point (dfTestY,dfTestY)
+                 * The rule #1 also excludes edges collinear with the ray.
+                 */
+                if ( ( psObject->padfY[iEdge+nVertStart] < dfTestY
+                       && dfTestY <= psObject->padfY[iNext+nVertStart] )
+                    || ( psObject->padfY[iNext+nVertStart] < dfTestY
+                         && dfTestY <= psObject->padfY[iEdge+nVertStart] ) )
+                {
+                    /* Rule #2:
+                    * Test if edge-ray intersection is on the right from the test point (dfTestY,dfTestY)
+                    */
+                    double const intersect = 
+                        ( psObject->padfX[iEdge+nVertStart]
+                          + ( dfTestY - psObject->padfY[iEdge+nVertStart] ) 
+                          / ( psObject->padfY[iNext+nVertStart] - psObject->padfY[iEdge+nVertStart] )
+                          * ( psObject->padfX[iNext+nVertStart] - psObject->padfX[iEdge+nVertStart] ) );
 
-		/* Rule #1:
-		 * Test whether the edge 'straddles' the horizontal ray from the test point (dfTestY,dfTestY)
-		 * The rule #1 also excludes edges collinear with the ray.
-		 */
-		if ((psObject->padfY[iEdge + nVertStart] < dfTestY
-		     && dfTestY <= psObject->padfY[iNext + nVertStart])
-		    || (psObject->padfY[iNext + nVertStart] < dfTestY
-			&& dfTestY <= psObject->padfY[iEdge + nVertStart])) {
-		    /* Rule #2:
-		     * Test if edge-ray intersection is on the right from the test point (dfTestY,dfTestY)
-		     */
-		    double const intersect =
-			(psObject->padfX[iEdge + nVertStart]
-			 + (dfTestY - psObject->padfY[iEdge + nVertStart])
-			 / (psObject->padfY[iNext + nVertStart] -
-			    psObject->padfY[iEdge + nVertStart])
-			 * (psObject->padfX[iNext + nVertStart] -
-			    psObject->padfX[iEdge + nVertStart]));
+                    if (intersect  < dfTestX)
+                    {
+                        bInner = !bInner;
+                    }
+                }    
+            }
+        } /* for iCheckRing */
 
-		    if (intersect < dfTestX) {
-			bInner = !bInner;
-		    }
-		}
-	    }
-	}			/* for iCheckRing */
+/* -------------------------------------------------------------------- */
+/*      Determine the current order of this ring so we will know if     */
+/*      it has to be reversed.                                          */
+/* -------------------------------------------------------------------- */
+        nVertStart = psObject->panPartStart[iOpRing];
 
-	/* -------------------------------------------------------------------- */
-	/*      Determine the current order of this ring so we will know if     */
-	/*      it has to be reversed.                                          */
-	/* -------------------------------------------------------------------- */
-	nVertStart = psObject->panPartStart[iOpRing];
+        if( iOpRing == psObject->nParts-1 )
+            nVertCount = psObject->nVertices - psObject->panPartStart[iOpRing];
+        else
+            nVertCount = psObject->panPartStart[iOpRing+1] 
+                - psObject->panPartStart[iOpRing];
 
-	if (iOpRing == psObject->nParts - 1)
-	    nVertCount =
-		psObject->nVertices - psObject->panPartStart[iOpRing];
-	else
-	    nVertCount = psObject->panPartStart[iOpRing + 1]
-		- psObject->panPartStart[iOpRing];
+        dfSum = 0.0;
+        for( iVert = nVertStart; iVert < nVertStart+nVertCount-1; iVert++ )
+        {
+            dfSum += psObject->padfX[iVert] * psObject->padfY[iVert+1]
+                - psObject->padfY[iVert] * psObject->padfX[iVert+1];
+        }
 
-	dfSum = 0.0;
-	for (iVert = nVertStart; iVert < nVertStart + nVertCount - 1; iVert++) {
-	    dfSum += psObject->padfX[iVert] * psObject->padfY[iVert + 1]
-		- psObject->padfY[iVert] * psObject->padfX[iVert + 1];
-	}
+        dfSum += psObject->padfX[iVert] * psObject->padfY[nVertStart]
+               - psObject->padfY[iVert] * psObject->padfX[nVertStart];
 
-	dfSum += psObject->padfX[iVert] * psObject->padfY[nVertStart]
-	    - psObject->padfY[iVert] * psObject->padfX[nVertStart];
+/* -------------------------------------------------------------------- */
+/*      Reverse if necessary.                                           */
+/* -------------------------------------------------------------------- */
+        if( (dfSum < 0.0 && bInner) || (dfSum > 0.0 && !bInner) )
+        {
+            int   i;
 
-	/* -------------------------------------------------------------------- */
-	/*      Reverse if necessary.                                           */
-	/* -------------------------------------------------------------------- */
-	if ((dfSum < 0.0 && bInner) || (dfSum > 0.0 && !bInner)) {
-	    int i;
+            bAltered++;
+            for( i = 0; i < nVertCount/2; i++ )
+            {
+                double dfSaved;
 
-	    bAltered++;
-	    for (i = 0; i < nVertCount / 2; i++) {
-		double dfSaved;
+                /* Swap X */
+                dfSaved = psObject->padfX[nVertStart+i];
+                psObject->padfX[nVertStart+i] = 
+                    psObject->padfX[nVertStart+nVertCount-i-1];
+                psObject->padfX[nVertStart+nVertCount-i-1] = dfSaved;
 
-		/* Swap X */
-		dfSaved = psObject->padfX[nVertStart + i];
-		psObject->padfX[nVertStart + i] =
-		    psObject->padfX[nVertStart + nVertCount - i - 1];
-		psObject->padfX[nVertStart + nVertCount - i - 1] = dfSaved;
+                /* Swap Y */
+                dfSaved = psObject->padfY[nVertStart+i];
+                psObject->padfY[nVertStart+i] = 
+                    psObject->padfY[nVertStart+nVertCount-i-1];
+                psObject->padfY[nVertStart+nVertCount-i-1] = dfSaved;
 
-		/* Swap Y */
-		dfSaved = psObject->padfY[nVertStart + i];
-		psObject->padfY[nVertStart + i] =
-		    psObject->padfY[nVertStart + nVertCount - i - 1];
-		psObject->padfY[nVertStart + nVertCount - i - 1] = dfSaved;
+                /* Swap Z */
+                if( psObject->padfZ )
+                {
+                    dfSaved = psObject->padfZ[nVertStart+i];
+                    psObject->padfZ[nVertStart+i] = 
+                        psObject->padfZ[nVertStart+nVertCount-i-1];
+                    psObject->padfZ[nVertStart+nVertCount-i-1] = dfSaved;
+                }
 
-		/* Swap Z */
-		if (psObject->padfZ) {
-		    dfSaved = psObject->padfZ[nVertStart + i];
-		    psObject->padfZ[nVertStart + i] =
-			psObject->padfZ[nVertStart + nVertCount - i - 1];
-		    psObject->padfZ[nVertStart + nVertCount - i - 1] =
-			dfSaved;
-		}
-
-		/* Swap M */
-		if (psObject->padfM) {
-		    dfSaved = psObject->padfM[nVertStart + i];
-		    psObject->padfM[nVertStart + i] =
-			psObject->padfM[nVertStart + nVertCount - i - 1];
-		    psObject->padfM[nVertStart + nVertCount - i - 1] =
-			dfSaved;
-		}
-	    }
-	}
+                /* Swap M */
+                if( psObject->padfM )
+                {
+                    dfSaved = psObject->padfM[nVertStart+i];
+                    psObject->padfM[nVertStart+i] = 
+                        psObject->padfM[nVertStart+nVertCount-i-1];
+                    psObject->padfM[nVertStart+nVertCount-i-1] = dfSaved;
+                }
+            }
+        }
     }
 
     return bAltered;



More information about the grass-commit mailing list