Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix const-correctness #101

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions dbfopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,8 @@ static bool DBFIsValueNULL(char chType, const char *pszValue)
/* Contributed by Jim Matthews. */
/************************************************************************/

int SHPAPI_CALL DBFIsAttributeNULL(DBFHandle psDBF, int iRecord, int iField)
int SHPAPI_CALL DBFIsAttributeNULL(const DBFHandle psDBF, int iRecord,
int iField)
{
const char *pszValue = DBFReadStringAttribute(psDBF, iRecord, iField);

Expand All @@ -1185,7 +1186,7 @@ int SHPAPI_CALL DBFIsAttributeNULL(DBFHandle psDBF, int iRecord, int iField)
/* Return the number of fields in this table. */
/************************************************************************/

int SHPAPI_CALL DBFGetFieldCount(DBFHandle psDBF)
int SHPAPI_CALL DBFGetFieldCount(const DBFHandle psDBF)
{
return (psDBF->nFields);
}
Expand All @@ -1196,7 +1197,7 @@ int SHPAPI_CALL DBFGetFieldCount(DBFHandle psDBF)
/* Return the number of records in this table. */
/************************************************************************/

int SHPAPI_CALL DBFGetRecordCount(DBFHandle psDBF)
int SHPAPI_CALL DBFGetRecordCount(const DBFHandle psDBF)
{
return (psDBF->nRecords);
}
Expand All @@ -1209,7 +1210,7 @@ int SHPAPI_CALL DBFGetRecordCount(DBFHandle psDBF)
/* bytes long. */
/************************************************************************/

DBFFieldType SHPAPI_CALL DBFGetFieldInfo(DBFHandle psDBF, int iField,
DBFFieldType SHPAPI_CALL DBFGetFieldInfo(const DBFHandle psDBF, int iField,
char *pszFieldName, int *pnWidth,
int *pnDecimals)
{
Expand Down Expand Up @@ -1621,7 +1622,8 @@ const char SHPAPI_CALL1(*) DBFReadTuple(DBFHandle psDBF, int hEntity)
/* Read one of the attribute fields of a record. */
/************************************************************************/

DBFHandle SHPAPI_CALL DBFCloneEmpty(DBFHandle psDBF, const char *pszFilename)
DBFHandle SHPAPI_CALL DBFCloneEmpty(const DBFHandle psDBF,
const char *pszFilename)
{
DBFHandle newDBF = DBFCreateEx(pszFilename, psDBF->pszCodePage);
if (newDBF == SHPLIB_NULLPTR)
Expand Down Expand Up @@ -1680,7 +1682,7 @@ DBFHandle SHPAPI_CALL DBFCloneEmpty(DBFHandle psDBF, const char *pszFilename)
/* 'M' (Memo: 10 digits .DBT block ptr) */
/************************************************************************/

char SHPAPI_CALL DBFGetNativeFieldType(DBFHandle psDBF, int iField)
char SHPAPI_CALL DBFGetNativeFieldType(const DBFHandle psDBF, int iField)
{
if (iField >= 0 && iField < psDBF->nFields)
return psDBF->pachFieldType[iField];
Expand All @@ -1696,7 +1698,8 @@ char SHPAPI_CALL DBFGetNativeFieldType(DBFHandle psDBF, int iField)
/* Contributed by Jim Matthews. */
/************************************************************************/

int SHPAPI_CALL DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName)
int SHPAPI_CALL DBFGetFieldIndex(const DBFHandle psDBF,
const char *pszFieldName)
{
char name[XBASE_FLDNAME_LEN_READ + 1];

Expand All @@ -1716,7 +1719,7 @@ int SHPAPI_CALL DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName)
/* it returns FALSE. */
/************************************************************************/

int SHPAPI_CALL DBFIsRecordDeleted(DBFHandle psDBF, int iShape)
int SHPAPI_CALL DBFIsRecordDeleted(const DBFHandle psDBF, int iShape)
{
/* -------------------------------------------------------------------- */
/* Verify selection. */
Expand Down Expand Up @@ -1779,7 +1782,7 @@ int SHPAPI_CALL DBFMarkRecordDeleted(DBFHandle psDBF, int iShape,
/* DBFGetCodePage */
/************************************************************************/

const char SHPAPI_CALL1(*) DBFGetCodePage(DBFHandle psDBF)
const char SHPAPI_CALL1(*) DBFGetCodePage(const DBFHandle psDBF)
{
if (psDBF == SHPLIB_NULLPTR)
return SHPLIB_NULLPTR;
Expand Down
4 changes: 2 additions & 2 deletions sbnsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ static int compare_ints(const void *a, const void *b)
/* SBNSearchDiskTree() */
/************************************************************************/

int *SBNSearchDiskTree(SBNSearchHandle hSBN, const double *padfBoundsMin,
int *SBNSearchDiskTree(const SBNSearchHandle hSBN, const double *padfBoundsMin,
const double *padfBoundsMax, int *pnShapeCount)
{
*pnShapeCount = 0;
Expand Down Expand Up @@ -808,7 +808,7 @@ int *SBNSearchDiskTree(SBNSearchHandle hSBN, const double *padfBoundsMin,
/* SBNSearchDiskTreeInteger() */
/************************************************************************/

int *SBNSearchDiskTreeInteger(SBNSearchHandle hSBN, int bMinX, int bMinY,
int *SBNSearchDiskTreeInteger(const SBNSearchHandle hSBN, int bMinX, int bMinY,
int bMaxX, int bMaxY, int *pnShapeCount)
{
*pnShapeCount = 0;
Expand Down
43 changes: 24 additions & 19 deletions shapefil.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,13 @@ extern "C"
SHPHandle SHPAPI_CALL SHPCreate(const char *pszShapeFile, int nShapeType);
SHPHandle SHPAPI_CALL SHPCreateLL(const char *pszShapeFile, int nShapeType,
const SAHooks *psHooks);
void SHPAPI_CALL SHPGetInfo(SHPHandle hSHP, int *pnEntities,
void SHPAPI_CALL SHPGetInfo(const SHPHandle hSHP, int *pnEntities,
int *pnShapeType, double *padfMinBound,
double *padfMaxBound);

SHPObject SHPAPI_CALL1(*) SHPReadObject(SHPHandle hSHP, int iShape);
SHPObject SHPAPI_CALL1(*) SHPReadObject(const SHPHandle hSHP, int iShape);
int SHPAPI_CALL SHPWriteObject(SHPHandle hSHP, int iShape,
SHPObject *psObject);
const SHPObject *psObject);

void SHPAPI_CALL SHPDestroyObject(SHPObject *psObject);
void SHPAPI_CALL SHPComputeExtents(SHPObject *psObject);
Expand All @@ -311,7 +311,7 @@ extern "C"
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(const SHPHandle hSHP, SHPObject *psObject);

void SHPAPI_CALL SHPClose(SHPHandle hSHP);
void SHPAPI_CALL SHPWriteHeader(SHPHandle hSHP);
Expand Down Expand Up @@ -369,7 +369,7 @@ extern "C"
void SHPAPI_CALL SHPTreeTrimExtraNodes(SHPTree *hTree);

int SHPAPI_CALL1(*)
SHPTreeFindLikelyShapes(SHPTree *hTree, double *padfBoundsMin,
SHPTreeFindLikelyShapes(const SHPTree *hTree, double *padfBoundsMin,
double *padfBoundsMax, int *);
int SHPAPI_CALL SHPCheckBoundsOverlap(const double *, const double *,
const double *, const double *, int);
Expand All @@ -386,8 +386,9 @@ extern "C"
void SHPAPI_CALL SHPCloseDiskTree(SHPTreeDiskHandle hDiskTree);

int SHPAPI_CALL1(*)
SHPSearchDiskTreeEx(SHPTreeDiskHandle hDiskTree, double *padfBoundsMin,
double *padfBoundsMax, int *pnShapeCount);
SHPSearchDiskTreeEx(const SHPTreeDiskHandle hDiskTree,
double *padfBoundsMin, double *padfBoundsMax,
int *pnShapeCount);

int SHPAPI_CALL SHPWriteTreeLL(SHPTree *hTree, const char *pszFilename,
const SAHooks *psHooks);
Expand All @@ -404,12 +405,14 @@ extern "C"
void SHPAPI_CALL SBNCloseDiskTree(SBNSearchHandle hSBN);

int SHPAPI_CALL1(*)
SBNSearchDiskTree(SBNSearchHandle hSBN, const double *padfBoundsMin,
SBNSearchDiskTree(const SBNSearchHandle hSBN,
const double *padfBoundsMin,
const double *padfBoundsMax, int *pnShapeCount);

int SHPAPI_CALL1(*)
SBNSearchDiskTreeInteger(SBNSearchHandle hSBN, int bMinX, int bMinY,
int bMaxX, int bMaxY, int *pnShapeCount);
SBNSearchDiskTreeInteger(const SBNSearchHandle hSBN, int bMinX,
int bMinY, int bMaxX, int bMaxY,
int *pnShapeCount);

void SHPAPI_CALL SBNSearchFreeIds(int *panShapeId);

Expand Down Expand Up @@ -497,8 +500,8 @@ extern "C"
const char *pszCodePage,
const SAHooks *psHooks);

int SHPAPI_CALL DBFGetFieldCount(DBFHandle psDBF);
int SHPAPI_CALL DBFGetRecordCount(DBFHandle psDBF);
int SHPAPI_CALL DBFGetFieldCount(const DBFHandle psDBF);
int SHPAPI_CALL DBFGetRecordCount(const DBFHandle psDBF);
int SHPAPI_CALL DBFAddField(DBFHandle hDBF, const char *pszFieldName,
DBFFieldType eType, int nWidth, int nDecimals);

Expand All @@ -514,11 +517,12 @@ extern "C"
const char *pszFieldName, char chType,
int nWidth, int nDecimals);

DBFFieldType SHPAPI_CALL DBFGetFieldInfo(DBFHandle psDBF, int iField,
DBFFieldType SHPAPI_CALL DBFGetFieldInfo(const DBFHandle psDBF, int iField,
char *pszFieldName, int *pnWidth,
int *pnDecimals);

int SHPAPI_CALL DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName);
int SHPAPI_CALL DBFGetFieldIndex(const DBFHandle psDBF,
const char *pszFieldName);

int SHPAPI_CALL DBFReadIntegerAttribute(DBFHandle hDBF, int iShape,
int iField);
Expand All @@ -530,7 +534,8 @@ extern "C"
DBFReadLogicalAttribute(DBFHandle hDBF, int iShape, int iField);
SHPDate SHPAPI_CALL DBFReadDateAttribute(DBFHandle hDBF, int iShape,
int iField);
int SHPAPI_CALL DBFIsAttributeNULL(DBFHandle hDBF, int iShape, int iField);
int SHPAPI_CALL DBFIsAttributeNULL(const DBFHandle hDBF, int iShape,
int iField);

int SHPAPI_CALL DBFWriteIntegerAttribute(DBFHandle hDBF, int iShape,
int iField, int nFieldValue);
Expand All @@ -554,18 +559,18 @@ extern "C"
int SHPAPI_CALL DBFWriteTuple(DBFHandle psDBF, int hEntity,
const void *pRawTuple);

int SHPAPI_CALL DBFIsRecordDeleted(DBFHandle psDBF, int iShape);
int SHPAPI_CALL DBFIsRecordDeleted(const DBFHandle psDBF, int iShape);
int SHPAPI_CALL DBFMarkRecordDeleted(DBFHandle psDBF, int iShape,
int bIsDeleted);

DBFHandle SHPAPI_CALL DBFCloneEmpty(DBFHandle psDBF,
DBFHandle SHPAPI_CALL DBFCloneEmpty(const 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);
char SHPAPI_CALL DBFGetNativeFieldType(const DBFHandle hDBF, int iField);

const char SHPAPI_CALL1(*) DBFGetCodePage(DBFHandle psDBF);
const char SHPAPI_CALL1(*) DBFGetCodePage(const DBFHandle psDBF);

void SHPAPI_CALL DBFSetLastModifiedDate(DBFHandle psDBF, int nYYSince1900,
int nMM, int nDD);
Expand Down
11 changes: 6 additions & 5 deletions shpopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,9 @@ void SHPAPI_CALL SHPSetFastModeReadObject(SHPHandle hSHP, int bFastMode)
/* Fetch general information about the shape file. */
/************************************************************************/

void SHPAPI_CALL SHPGetInfo(SHPHandle psSHP, int *pnEntities, int *pnShapeType,
double *padfMinBound, double *padfMaxBound)
void SHPAPI_CALL SHPGetInfo(const SHPHandle psSHP, int *pnEntities,
int *pnShapeType, double *padfMinBound,
double *padfMaxBound)
{
if (psSHP == SHPLIB_NULLPTR)
return;
Expand Down Expand Up @@ -1310,7 +1311,7 @@ SHPObject SHPAPI_CALL1(*)
/************************************************************************/

int SHPAPI_CALL SHPWriteObject(SHPHandle psSHP, int nShapeId,
SHPObject *psObject)
const SHPObject *psObject)
{
psSHP->bUpdated = TRUE;

Expand Down Expand Up @@ -1882,7 +1883,7 @@ static unsigned char *SHPReallocObjectBufIfNecessary(SHPHandle psSHP,
/* for one shape. */
/************************************************************************/

SHPObject SHPAPI_CALL1(*) SHPReadObject(SHPHandle psSHP, int hEntity)
SHPObject SHPAPI_CALL1(*) SHPReadObject(const SHPHandle psSHP, int hEntity)
{
/* -------------------------------------------------------------------- */
/* Validate the record/entity number. */
Expand Down Expand Up @@ -2913,7 +2914,7 @@ static int SHPRewindIsInnerRing(const SHPObject *psObject, int iOpRing,
/* specification. */
/************************************************************************/

int SHPAPI_CALL SHPRewindObject(SHPHandle hSHP, SHPObject *psObject)
int SHPAPI_CALL SHPRewindObject(const SHPHandle hSHP, SHPObject *psObject)
{
(void)hSHP;
/* -------------------------------------------------------------------- */
Expand Down
14 changes: 7 additions & 7 deletions shptree.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ int SHPAPI_CALL SHPTreeAddShapeId(SHPTree *psTree, SHPObject *psObject)
/* tree node by tree node basis. */
/************************************************************************/

static void SHPTreeCollectShapeIds(SHPTree *hTree, SHPTreeNode *psTreeNode,
static void SHPTreeCollectShapeIds(const SHPTree *hTree,
const SHPTreeNode *psTreeNode,
double *padfBoundsMin, double *padfBoundsMax,
int *pnShapeCount, int *pnMaxShapes,
int **ppanShapeList)
Expand Down Expand Up @@ -566,7 +567,7 @@ static int SHPTreeCompareInts(const void *a, const void *b)
}

int SHPAPI_CALL1(*)
SHPTreeFindLikelyShapes(SHPTree *hTree, double *padfBoundsMin,
SHPTreeFindLikelyShapes(const SHPTree *hTree, double *padfBoundsMin,
double *padfBoundsMax, int *pnShapeCount)

{
Expand Down Expand Up @@ -598,7 +599,6 @@ int SHPAPI_CALL1(*)
/************************************************************************/

static int SHPTreeNodeTrim(SHPTreeNode *psTreeNode)

{
int i;

Expand Down Expand Up @@ -657,7 +657,6 @@ static int SHPTreeNodeTrim(SHPTreeNode *psTreeNode)
/************************************************************************/

void SHPAPI_CALL SHPTreeTrimExtraNodes(SHPTree *hTree)

{
SHPTreeNodeTrim(hTree->psRoot);
}
Expand Down Expand Up @@ -713,7 +712,7 @@ void SHPCloseDiskTree(SHPTreeDiskHandle hDiskTree)
/* SHPSearchDiskTreeNode() */
/************************************************************************/

static bool SHPSearchDiskTreeNode(SHPTreeDiskHandle hDiskTree,
static bool SHPSearchDiskTreeNode(const SHPTreeDiskHandle hDiskTree,
double *padfBoundsMin, double *padfBoundsMax,
int **ppanResultBuffer, int *pnBufferMax,
int *pnResultCount, int bNeedSwap,
Expand Down Expand Up @@ -907,8 +906,9 @@ int SHPAPI_CALL1(*) SHPSearchDiskTree(FILE *fp, double *padfBoundsMin,
/************************************************************************/

int SHPAPI_CALL1(*)
SHPSearchDiskTreeEx(SHPTreeDiskHandle hDiskTree, double *padfBoundsMin,
double *padfBoundsMax, int *pnShapeCount)
SHPSearchDiskTreeEx(const SHPTreeDiskHandle hDiskTree,
double *padfBoundsMin, double *padfBoundsMax,
int *pnShapeCount)

{
int nBufferMax = 0;
Expand Down