Skip to content

Commit

Permalink
Fix const-correctness
Browse files Browse the repository at this point in the history
  • Loading branch information
thbeu committed Feb 23, 2024
1 parent 200ae4f commit 13c45a4
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 52 deletions.
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
54 changes: 30 additions & 24 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);
int SHPAPI_CALL SHPWriteObject(SHPHandle hSHP, int iShape,
SHPObject *psObject);
SHPObject SHPAPI_CALL1(*) SHPReadObject(const SHPHandle hSHP, int iShape);
int SHPAPI_CALL SHPWriteObject(const SHPHandle hSHP, int iShape,
const SHPObject *psObject);

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

const char SHPAPI_CALL1(*) SHPTypeName(int nSHPType);
const char SHPAPI_CALL1(*) SHPPartTypeName(int nPartType);
Expand Down Expand Up @@ -362,14 +362,14 @@ extern "C"
const double *padfBoundsMin, const double *padfBoundsMax);
void SHPAPI_CALL SHPDestroyTree(SHPTree *hTree);

int SHPAPI_CALL SHPWriteTree(SHPTree *hTree, const char *pszFilename);
int SHPAPI_CALL SHPWriteTree(const SHPTree *hTree, const char *pszFilename);

int SHPAPI_CALL SHPTreeAddShapeId(SHPTree *hTree, SHPObject *psObject);

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,10 +386,12 @@ 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,
int SHPAPI_CALL SHPWriteTreeLL(const SHPTree *hTree,
const char *pszFilename,
const SAHooks *psHooks);

/* -------------------------------------------------------------------- */
Expand All @@ -404,12 +406,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 +501,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 +518,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 +535,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 +560,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
17 changes: 9 additions & 8 deletions shpopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
/* contents of the index (.shx) file. */
/************************************************************************/

void SHPAPI_CALL SHPWriteHeader(SHPHandle psSHP)
void SHPAPI_CALL SHPWriteHeader(const SHPHandle psSHP)
{
if (psSHP->fpSHX == SHPLIB_NULLPTR)
{
Expand Down Expand Up @@ -857,7 +857,7 @@ int SHPAPI_CALL SHPRestoreSHX(const char *pszLayer, const char *pszAccess,
/* Close the .shp and .shx files. */
/************************************************************************/

void SHPAPI_CALL SHPClose(SHPHandle psSHP)
void SHPAPI_CALL SHPClose(const SHPHandle psSHP)
{
if (psSHP == SHPLIB_NULLPTR)
return;
Expand Down 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 @@ -1309,8 +1310,8 @@ SHPObject SHPAPI_CALL1(*)
/* only possible to write vertices at the end of the file. */
/************************************************************************/

int SHPAPI_CALL SHPWriteObject(SHPHandle psSHP, int nShapeId,
SHPObject *psObject)
int SHPAPI_CALL SHPWriteObject(const SHPHandle psSHP, int nShapeId,
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
19 changes: 10 additions & 9 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 Expand Up @@ -1037,7 +1037,7 @@ static void SHPWriteTreeNode(SAFile fp, SHPTreeNode *node,
/* SHPWriteTree() */
/************************************************************************/

int SHPAPI_CALL SHPWriteTree(SHPTree *tree, const char *filename)
int SHPAPI_CALL SHPWriteTree(const SHPTree *tree, const char *filename)
{
SAHooks sHooks;

Expand All @@ -1050,7 +1050,8 @@ int SHPAPI_CALL SHPWriteTree(SHPTree *tree, const char *filename)
/* SHPWriteTreeLL() */
/************************************************************************/

int SHPWriteTreeLL(SHPTree *tree, const char *filename, const SAHooks *psHooks)
int SHPWriteTreeLL(const SHPTree *tree, const char *filename,
const SAHooks *psHooks)
{
const char signature[4] = "SQT";
char abyBuf[32];
Expand Down

0 comments on commit 13c45a4

Please sign in to comment.