diff --git a/dbfopen.c b/dbfopen.c index 7a376d9..1d108e2 100644 --- a/dbfopen.c +++ b/dbfopen.c @@ -99,9 +99,9 @@ static void DBFWriteHeader(DBFHandle psDBF) psDBF->bNoHeader = FALSE; /* -------------------------------------------------------------------- */ - /* Initialize the file header information. */ + /* Initialize the file header information. */ /* -------------------------------------------------------------------- */ - abyHeader[0] = 0x03; /* memo field? - just copying */ + abyHeader[0] = 0x03; /* memo field? - just copying */ /* write out update date */ abyHeader[1] = STATIC_CAST(unsigned char, psDBF->nUpdateYearSince1900); @@ -120,7 +120,7 @@ static void DBFWriteHeader(DBFHandle psDBF) /* -------------------------------------------------------------------- */ /* Write the initial 32 byte file header, and all the field */ - /* descriptions. */ + /* descriptions. */ /* -------------------------------------------------------------------- */ psDBF->sHooks.FSeek(psDBF->fp, 0, 0); psDBF->sHooks.FWrite(abyHeader, XBASE_FILEHDR_SZ, 1, psDBF->fp); @@ -361,8 +361,8 @@ DBFHandle SHPAPI_CALL DBFOpenLL(const char *pszFilename, const char *pszAccess, pszAccess = "rb+"; /* -------------------------------------------------------------------- */ - /* Compute the base (layer) name. If there is any extension */ - /* on the passed in filename we will strip it off. */ + /* Compute the base (layer) name. If there is any extension */ + /* on the passed in filename we will strip it off. */ /* -------------------------------------------------------------------- */ const int nLenWithoutExtension = DBFGetLenWithoutExtension(pszFilename); char *pszFullname = STATIC_CAST(char *, malloc(nLenWithoutExtension + 5)); @@ -515,8 +515,8 @@ DBFHandle SHPAPI_CALL DBFOpenLL(const char *pszFilename, const char *pszAccess, ** 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->panFieldSize[iField] = pabyFInfo[16] + pabyFInfo[17]*256; + psDBF->panFieldDecimals[iField] = 0; */ } @@ -562,8 +562,8 @@ void SHPAPI_CALL DBFClose(DBFHandle psDBF) CPL_IGNORE_RET_VAL_INT(DBFFlushRecord(psDBF)); /* -------------------------------------------------------------------- */ - /* Update last access date, and number of records if we have */ - /* write access. */ + /* Update last access date, and number of records if we have */ + /* write access. */ /* -------------------------------------------------------------------- */ if (psDBF->bUpdated) DBFUpdateHeader(psDBF); @@ -629,8 +629,8 @@ DBFHandle SHPAPI_CALL DBFCreateLL(const char *pszFilename, const SAHooks *psHooks) { /* -------------------------------------------------------------------- */ - /* Compute the base (layer) name. If there is any extension */ - /* on the passed in filename we will strip it off. */ + /* Compute the base (layer) name. If there is any extension */ + /* on the passed in filename we will strip it off. */ /* -------------------------------------------------------------------- */ const int nLenWithoutExtension = DBFGetLenWithoutExtension(pszFilename); char *pszFullname = STATIC_CAST(char *, malloc(nLenWithoutExtension + 5)); @@ -686,7 +686,7 @@ DBFHandle SHPAPI_CALL DBFCreateLL(const char *pszFilename, free(pszFullname); /* -------------------------------------------------------------------- */ - /* Create the info structure. */ + /* Create the info structure. */ /* -------------------------------------------------------------------- */ DBFHandle psDBF = STATIC_CAST(DBFHandle, calloc(1, sizeof(DBFInfo))); @@ -965,13 +965,13 @@ static void *DBFReadAttribute(DBFHandle psDBF, int hEntity, int iField, return SHPLIB_NULLPTR; /* -------------------------------------------------------------------- */ - /* Have we read the record? */ + /* Have we read the record? */ /* -------------------------------------------------------------------- */ if (!DBFLoadRecord(psDBF, hEntity)) return SHPLIB_NULLPTR; - unsigned char *pabyRec = - REINTERPRET_CAST(unsigned char *, psDBF->pszCurrentRecord); + const unsigned char *pabyRec = + REINTERPRET_CAST(const unsigned char *, psDBF->pszCurrentRecord); /* -------------------------------------------------------------------- */ /* Ensure we have room to extract the target field. */ @@ -988,7 +988,7 @@ static void *DBFReadAttribute(DBFHandle psDBF, int hEntity, int iField, } /* -------------------------------------------------------------------- */ - /* Extract the requested field. */ + /* Extract the requested field. */ /* -------------------------------------------------------------------- */ memcpy(psDBF->pszWorkField, REINTERPRET_CAST(const char *, pabyRec) + @@ -1246,15 +1246,15 @@ DBFFieldType SHPAPI_CALL DBFGetFieldInfo(DBFHandle psDBF, int iField, /************************************************************************/ /* DBFWriteAttribute() */ -/* */ -/* Write an attribute record to the file. */ +/* */ +/* Write an attribute record to the file. */ /************************************************************************/ static bool DBFWriteAttribute(DBFHandle psDBF, int hEntity, int iField, void *pValue) { /* -------------------------------------------------------------------- */ - /* Is this a valid record? */ + /* Is this a valid record? */ /* -------------------------------------------------------------------- */ if (hEntity < 0 || hEntity > psDBF->nRecords) return false; @@ -1381,10 +1381,10 @@ static bool DBFWriteAttribute(DBFHandle psDBF, int hEntity, int iField, /************************************************************************/ int SHPAPI_CALL DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, - int iField, void *pValue) + int iField, const void *pValue) { /* -------------------------------------------------------------------- */ - /* Is this a valid record? */ + /* Is this a valid record? */ /* -------------------------------------------------------------------- */ if (hEntity < 0 || hEntity > psDBF->nRecords) return (FALSE); @@ -1512,14 +1512,15 @@ int SHPAPI_CALL DBFWriteLogicalAttribute(DBFHandle psDBF, int iRecord, /************************************************************************/ /* 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, + const void *pRawTuple) { /* -------------------------------------------------------------------- */ - /* Is this a valid record? */ + /* Is this a valid record? */ /* -------------------------------------------------------------------- */ if (hEntity < 0 || hEntity > psDBF->nRecords) return (FALSE); @@ -1580,7 +1581,7 @@ const char SHPAPI_CALL1(*) DBFReadTuple(DBFHandle psDBF, int hEntity) } /************************************************************************/ -/* DBFCloneEmpty() */ +/* DBFCloneEmpty() */ /* */ /* Read one of the attribute fields of a record. */ /************************************************************************/ @@ -1690,7 +1691,7 @@ int SHPAPI_CALL DBFIsRecordDeleted(DBFHandle psDBF, int iShape) return TRUE; /* -------------------------------------------------------------------- */ - /* Have we read the record? */ + /* Have we read the record? */ /* -------------------------------------------------------------------- */ if (!DBFLoadRecord(psDBF, iShape)) return FALSE; @@ -1885,7 +1886,7 @@ int SHPAPI_CALL DBFDeleteField(DBFHandle psDBF, int iField) /* code of DBFReorderFields. */ /************************************************************************/ -int SHPAPI_CALL DBFReorderFields(DBFHandle psDBF, int *panMap) +int SHPAPI_CALL DBFReorderFields(DBFHandle psDBF, const int *panMap) { if (psDBF->nFields == 0) return TRUE; diff --git a/safileio.c b/safileio.c index cd37794..e95088b 100644 --- a/safileio.c +++ b/safileio.c @@ -40,7 +40,8 @@ static SAOffset SADFRead(void *p, SAOffset size, SAOffset nmemb, SAFile file) return (SAOffset)fread(p, (size_t)size, (size_t)nmemb, (FILE *)file); } -static SAOffset SADFWrite(void *p, SAOffset size, SAOffset nmemb, SAFile file) +static SAOffset SADFWrite(const void *p, SAOffset size, SAOffset nmemb, + SAFile file) { return (SAOffset)fwrite(p, (size_t)size, (size_t)nmemb, (FILE *)file); } diff --git a/sbnsearch.c b/sbnsearch.c index 323f473..805e4c4 100644 --- a/sbnsearch.c +++ b/sbnsearch.c @@ -746,8 +746,8 @@ static int compare_ints(const void *a, const void *b) /* SBNSearchDiskTree() */ /************************************************************************/ -int *SBNSearchDiskTree(SBNSearchHandle hSBN, double *padfBoundsMin, - double *padfBoundsMax, int *pnShapeCount) +int *SBNSearchDiskTree(SBNSearchHandle hSBN, const double *padfBoundsMin, + const double *padfBoundsMax, int *pnShapeCount) { *pnShapeCount = 0; diff --git a/shapefil.h b/shapefil.h index 0ce4959..0b8533e 100644 --- a/shapefil.h +++ b/shapefil.h @@ -55,7 +55,7 @@ extern "C" /* 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 */ + /* from Visual Basic and/or Delphi I believe) the makefile could */ /* be modified to define: */ /* */ /* /DSHPAPI_CALL=__stdcall */ @@ -121,7 +121,8 @@ extern "C" { SAFile (*FOpen)(const char *filename, const char *access); SAOffset (*FRead)(void *p, SAOffset size, SAOffset nmemb, SAFile file); - SAOffset (*FWrite)(void *p, SAOffset size, SAOffset nmemb, SAFile file); + SAOffset (*FWrite)(const void *p, SAOffset size, SAOffset nmemb, + SAFile file); SAOffset (*FSeek)(SAFile file, SAOffset offset, int whence); SAOffset (*FTell)(SAFile file); int (*FFlush)(SAFile file); @@ -333,7 +334,7 @@ extern "C" SHPTree SHPAPI_CALL1(*) SHPCreateTree(SHPHandle hSHP, int nDimension, int nMaxDepth, - double *padfBoundsMin, double *padfBoundsMax); + const double *padfBoundsMin, const double *padfBoundsMax); void SHPAPI_CALL SHPDestroyTree(SHPTree *hTree); int SHPAPI_CALL SHPWriteTree(SHPTree *hTree, const char *pszFilename); @@ -379,8 +380,8 @@ extern "C" void SHPAPI_CALL SBNCloseDiskTree(SBNSearchHandle hSBN); int SHPAPI_CALL1(*) - SBNSearchDiskTree(SBNSearchHandle hSBN, double *padfBoundsMin, - double *padfBoundsMax, int *pnShapeCount); + SBNSearchDiskTree(SBNSearchHandle hSBN, const double *padfBoundsMin, + const double *padfBoundsMax, int *pnShapeCount); int SHPAPI_CALL1(*) SBNSearchDiskTreeInteger(SBNSearchHandle hSBN, int bMinX, int bMinY, @@ -483,7 +484,7 @@ extern "C" int SHPAPI_CALL DBFDeleteField(DBFHandle hDBF, int iField); - int SHPAPI_CALL DBFReorderFields(DBFHandle psDBF, int *panMap); + int SHPAPI_CALL DBFReorderFields(DBFHandle psDBF, const int *panMap); int SHPAPI_CALL DBFAlterFieldDefn(DBFHandle psDBF, int iField, const char *pszFieldName, char chType, @@ -519,10 +520,10 @@ extern "C" int iField, const char lFieldValue); int SHPAPI_CALL DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, - int iField, void *pValue); + int iField, const void *pValue); const char SHPAPI_CALL1(*) DBFReadTuple(DBFHandle psDBF, int hEntity); int SHPAPI_CALL DBFWriteTuple(DBFHandle psDBF, int hEntity, - void *pRawTuple); + const void *pRawTuple); int SHPAPI_CALL DBFIsRecordDeleted(DBFHandle psDBF, int iShape); int SHPAPI_CALL DBFMarkRecordDeleted(DBFHandle psDBF, int iShape, diff --git a/shpopen.c b/shpopen.c index 3fcc395..7881189 100644 --- a/shpopen.c +++ b/shpopen.c @@ -97,8 +97,8 @@ static void SwapWord(int length, void *wordP) /************************************************************************/ /* 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 SHPAPI_CALL SHPWriteHeader(SHPHandle psSHP) @@ -843,8 +843,8 @@ int SHPAPI_CALL SHPRestoreSHX(const char *pszLayer, const char *pszAccess, /************************************************************************/ /* SHPClose() */ -/* */ -/* Close the .shp and .shx files. */ +/* */ +/* Close the .shp and .shx files. */ /************************************************************************/ void SHPAPI_CALL SHPClose(SHPHandle psSHP) @@ -853,7 +853,7 @@ void SHPAPI_CALL SHPClose(SHPHandle psSHP) return; /* -------------------------------------------------------------------- */ - /* Update the header if we have modified anything. */ + /* Update the header if we have modified anything. */ /* -------------------------------------------------------------------- */ if (psSHP->bUpdated) SHPWriteHeader(psSHP); @@ -1097,7 +1097,7 @@ SHPHandle SHPAPI_CALL SHPCreateLL(const char *pszLayer, int nShapeType, /* indicated location in the record. */ /************************************************************************/ -static void _SHPSetBounds(uchar *pabyRec, SHPObject *psShape) +static void _SHPSetBounds(uchar *pabyRec, const SHPObject *psShape) { ByteCopy(&(psShape->dfXMin), pabyRec + 0, 8); ByteCopy(&(psShape->dfYMin), pabyRec + 8, 8); @@ -1167,7 +1167,7 @@ SHPObject SHPAPI_CALL1(*) psObject->bMeasureIsUsed = FALSE; /* -------------------------------------------------------------------- */ - /* Establish whether this shape type has M, and Z values. */ + /* Establish whether this shape type has M, and Z values. */ /* -------------------------------------------------------------------- */ bool bHasM; bool bHasZ; @@ -1345,7 +1345,7 @@ int SHPAPI_CALL SHPWriteObject(SHPHandle psSHP, int nShapeId, return -1; /* -------------------------------------------------------------------- */ - /* Extract vertices for a Polygon or Arc. */ + /* Extract vertices for a Polygon or Arc. */ /* -------------------------------------------------------------------- */ unsigned int nRecordSize = 0; const bool bFirstFeature = psSHP->nRecords == 0; @@ -1474,7 +1474,7 @@ int SHPAPI_CALL SHPWriteObject(SHPHandle psSHP, int nShapeId, } /* -------------------------------------------------------------------- */ - /* Extract vertices for a MultiPoint. */ + /* Extract vertices for a MultiPoint. */ /* -------------------------------------------------------------------- */ else if (psObject->nSHPType == SHPT_MULTIPOINT || psObject->nSHPType == SHPT_MULTIPOINTZ || @@ -1547,7 +1547,7 @@ int SHPAPI_CALL SHPWriteObject(SHPHandle psSHP, int nShapeId, } /* -------------------------------------------------------------------- */ - /* Write point. */ + /* Write point. */ /* -------------------------------------------------------------------- */ else if (psObject->nSHPType == SHPT_POINT || psObject->nSHPType == SHPT_POINTZ || @@ -1710,7 +1710,7 @@ int SHPAPI_CALL SHPWriteObject(SHPHandle psSHP, int nShapeId, psSHP->panRecSize[nShapeId] = nRecordSize - 8; /* -------------------------------------------------------------------- */ - /* Expand file wide bounds based on this shape. */ + /* Expand file wide bounds based on this shape. */ /* -------------------------------------------------------------------- */ if (bFirstFeature) { @@ -1808,8 +1808,8 @@ static unsigned char *SHPReallocObjectBufIfNecessary(SHPHandle psSHP, /************************************************************************/ /* 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) @@ -2027,7 +2027,7 @@ SHPObject SHPAPI_CALL1(*) SHPReadObject(SHPHandle psSHP, int hEntity) SwapWord(4, &(nSHPType)); /* -------------------------------------------------------------------- */ - /* Allocate and minimally initialize the object. */ + /* Allocate and minimally initialize the object. */ /* -------------------------------------------------------------------- */ SHPObject *psShape; if (psSHP->bFastModeReadObject) @@ -2052,7 +2052,7 @@ SHPObject SHPAPI_CALL1(*) SHPReadObject(SHPHandle psSHP, int hEntity) psShape->bFastModeReadObject = psSHP->bFastModeReadObject; /* ==================================================================== */ - /* Extract vertices for a Polygon or Arc. */ + /* Extract vertices for a Polygon or Arc. */ /* ==================================================================== */ if (psShape->nSHPType == SHPT_POLYGON || psShape->nSHPType == SHPT_ARC || psShape->nSHPType == SHPT_POLYGONZ || @@ -2071,7 +2071,7 @@ SHPObject SHPAPI_CALL1(*) SHPReadObject(SHPHandle psSHP, int hEntity) return SHPLIB_NULLPTR; } /* -------------------------------------------------------------------- */ - /* Get the X/Y bounds. */ + /* Get the X/Y bounds. */ /* -------------------------------------------------------------------- */ memcpy(&(psShape->dfXMin), psSHP->pabyRec + 8 + 4, 8); memcpy(&(psShape->dfYMin), psSHP->pabyRec + 8 + 12, 8); @@ -2330,7 +2330,7 @@ SHPObject SHPAPI_CALL1(*) SHPReadObject(SHPHandle psSHP, int hEntity) } /* ==================================================================== */ - /* Extract vertices for a MultiPoint. */ + /* Extract vertices for a MultiPoint. */ /* ==================================================================== */ else if (psShape->nSHPType == SHPT_MULTIPOINT || psShape->nSHPType == SHPT_MULTIPOINTM || @@ -2436,7 +2436,7 @@ SHPObject SHPAPI_CALL1(*) SHPReadObject(SHPHandle psSHP, int hEntity) int nOffset = 48 + 16 * nPoints; /* -------------------------------------------------------------------- */ - /* Get the X/Y bounds. */ + /* Get the X/Y bounds. */ /* -------------------------------------------------------------------- */ memcpy(&(psShape->dfXMin), psSHP->pabyRec + 8 + 4, 8); memcpy(&(psShape->dfYMin), psSHP->pabyRec + 8 + 12, 8); diff --git a/shptree.c b/shptree.c index 0d55e84..7b8739b 100644 --- a/shptree.c +++ b/shptree.c @@ -61,8 +61,8 @@ static bool bBigEndian = false; /* Initialize a tree node. */ /************************************************************************/ -static SHPTreeNode *SHPTreeNodeCreate(double *padfBoundsMin, - double *padfBoundsMax) +static SHPTreeNode *SHPTreeNodeCreate(const double *padfBoundsMin, + const double *padfBoundsMax) { SHPTreeNode *psTreeNode; @@ -92,7 +92,7 @@ static SHPTreeNode *SHPTreeNodeCreate(double *padfBoundsMin, SHPTree SHPAPI_CALL1(*) SHPCreateTree(SHPHandle hSHP, int nDimension, int nMaxDepth, - double *padfBoundsMin, double *padfBoundsMax) + const double *padfBoundsMin, const double *padfBoundsMax) { SHPTree *psTree; @@ -251,9 +251,10 @@ void SHPAPI_CALL SHPDestroyTree(SHPTree *psTree) /* Do the given boxes overlap at all? */ /************************************************************************/ -int SHPAPI_CALL SHPCheckBoundsOverlap(double *padfBox1Min, double *padfBox1Max, - double *padfBox2Min, double *padfBox2Max, - int nDimension) +int SHPAPI_CALL SHPCheckBoundsOverlap(const double *padfBox1Min, + const double *padfBox1Max, + const double *padfBox2Min, + const double *padfBox2Max, int nDimension) { for (int iDim = 0; iDim < nDimension; iDim++) { @@ -273,9 +274,9 @@ int SHPAPI_CALL SHPCheckBoundsOverlap(double *padfBox1Min, double *padfBox1Max, /* Does the given shape fit within the indicated extents? */ /************************************************************************/ -static bool SHPCheckObjectContained(SHPObject *psObject, int nDimension, - double *padfBoundsMin, - double *padfBoundsMax) +static bool SHPCheckObjectContained(const SHPObject *psObject, int nDimension, + const double *padfBoundsMin, + const double *padfBoundsMax) { if (psObject->dfXMin < padfBoundsMin[0] || @@ -310,7 +311,8 @@ static bool SHPCheckObjectContained(SHPObject *psObject, int nDimension, /* longest dimension. */ /************************************************************************/ -static void SHPTreeSplitBounds(double *padfBoundsMinIn, double *padfBoundsMaxIn, +static void SHPTreeSplitBounds(const double *padfBoundsMinIn, + const double *padfBoundsMaxIn, double *padfBoundsMin1, double *padfBoundsMax1, double *padfBoundsMin2, double *padfBoundsMax2) @@ -684,11 +686,10 @@ static void SwapWord(int length, void *wordP) { int i; - unsigned char temp; for (i = 0; i < length / 2; i++) { - temp = STATIC_CAST(unsigned char *, wordP)[i]; + unsigned char temp = STATIC_CAST(unsigned char *, wordP)[i]; STATIC_CAST(unsigned char *, wordP) [i] = STATIC_CAST(unsigned char *, wordP)[length - i - 1]; STATIC_CAST(unsigned char *, wordP)[length - i - 1] = temp; @@ -1093,7 +1094,7 @@ int SHPAPI_CALL SHPWriteTree(SHPTree *tree, const char *filename) int SHPWriteTreeLL(SHPTree *tree, const char *filename, const SAHooks *psHooks) { - char signature[4] = "SQT"; + const char signature[4] = "SQT"; int i; char abyBuf[32]; SAFile fp;