Skip to content

Commit

Permalink
Localize loop counters in ogr.
Browse files Browse the repository at this point in the history
Also:
- Initialize local vars
- Fix formatting
- Localize vars
- Combine definition and initialization
- Define one var per line
- Add const
- /* */ -> //

git-svn-id: https://svn.osgeo.org/gdal/trunk@35127 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information
schwehr committed Aug 16, 2016
1 parent b6e4c32 commit 5af4734
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 264 deletions.
15 changes: 6 additions & 9 deletions gdal/ogr/ogr_srs_panorama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,10 @@ OGRErr OGRSpatialReference::importFromPanorama( long iProjSys, long iDatum,

if( padfPrjParams == NULL )
{
int i;

padfPrjParams = (double *)CPLMalloc( 8 * sizeof(double) );
if ( !padfPrjParams )
return OGRERR_NOT_ENOUGH_MEMORY;
for ( i = 0; i < 7; i++ )
for ( int i = 0; i < 7; i++ )
padfPrjParams[i] = 0.0;
bProjAllocated = true;
}
Expand Down Expand Up @@ -558,12 +556,10 @@ OGRErr OGRSpatialReference::exportToPanorama( long *piProjSys, long *piDatum,
/* -------------------------------------------------------------------- */
/* Fill all projection parameters with zero. */
/* -------------------------------------------------------------------- */
int i;

*piDatum = 0L;
*piEllips = 0L;
*piZone = 0L;
for ( i = 0; i < 7; i++ )
for ( int i = 0; i < 7; i++ )
padfPrjParams[i] = 0.0;

/* ==================================================================== */
Expand Down Expand Up @@ -812,12 +808,13 @@ OGRErr OGRSpatialReference::exportToPanorama( long *piProjSys, long *piDatum,
"Trying to translate an ellipsoid definition.", pszDatum );
#endif

for ( i = 0; i < NUMBER_OF_ELLIPSOIDS; i++ )
int i = 0; // Used after for.
for ( ; i < NUMBER_OF_ELLIPSOIDS; i++ )
{
if ( aoEllips[i] )
{
double dfSM = 0.0;
double dfIF = 1.0;
double dfSM = 0.0;
double dfIF = 1.0;

if ( OSRGetEllipsoidInfo( aoEllips[i], NULL,
&dfSM, &dfIF ) == OGRERR_NONE
Expand Down
10 changes: 3 additions & 7 deletions gdal/ogr/ogr_srs_pci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,10 @@ OGRErr OGRSpatialReference::importFromPCI( const char *pszProj,

if( padfPrjParams == NULL )
{
int i;

padfPrjParams = (double *)CPLMalloc( 17 * sizeof(double) );
if ( !padfPrjParams )
return OGRERR_NOT_ENOUGH_MEMORY;
for ( i = 0; i < 17; i++ )
for( int i = 0; i < 17; i++ )
padfPrjParams[i] = 0.0;
bProjAllocated = true;
}
Expand Down Expand Up @@ -795,10 +793,8 @@ OGRErr OGRSpatialReference::exportToPCI( char **ppszProj, char **ppszUnits,
/* -------------------------------------------------------------------- */
/* Fill all projection parameters with zero. */
/* -------------------------------------------------------------------- */
int i;

*ppadfPrjParams = (double *)CPLMalloc( 17 * sizeof(double) );
for ( i = 0; i < 17; i++ )
for ( int i = 0; i < 17; i++ )
(*ppadfPrjParams)[i] = 0.0;

/* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -1133,7 +1129,7 @@ OGRErr OGRSpatialReference::exportToPCI( char **ppszProj, char **ppszUnits,
{
int nGCS_EPSG = atoi(GetAuthorityCode("GEOGCS"));

for( i = 0; asDatums[i].nEPSGCode != 0; i++ )
for( int i = 0; asDatums[i].nEPSGCode != 0; i++ )
{
if( asDatums[i].nEPSGCode == nGCS_EPSG )
{
Expand Down
5 changes: 3 additions & 2 deletions gdal/ogr/ogr_srs_proj4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ static const OGRProj4PM* OGRGetProj4PMFromCode(int nPMCode)

static const OGRProj4PM* OGRGetProj4PMFromVal(double dfVal)
{
unsigned int i;
for(i=0;i<sizeof(ogr_pj_pms)/sizeof(ogr_pj_pms[0]);i++)
for( unsigned int i = 0;
i < sizeof(ogr_pj_pms) / sizeof(ogr_pj_pms[0]);
i++ )
{
if (fabs(dfVal - CPLDMSToDec(ogr_pj_pms[i].pszFromGreenwich)) < 1e-10)
{
Expand Down
17 changes: 8 additions & 9 deletions gdal/ogr/ogr_srs_usgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,10 +827,8 @@ OGRErr OGRSpatialReference::exportToUSGS( long *piProjSys, long *piZone,
/* -------------------------------------------------------------------- */
/* Fill all projection parameters with zero. */
/* -------------------------------------------------------------------- */
int i;

*ppadfPrjParams = (double *)CPLMalloc( 15 * sizeof(double) );
for ( i = 0; i < 15; i++ )
for ( int i = 0; i < 15; i++ )
(*ppadfPrjParams)[i] = 0.0;

*piZone = 0L;
Expand Down Expand Up @@ -1143,22 +1141,23 @@ OGRErr OGRSpatialReference::exportToUSGS( long *piProjSys, long *piZone,
else if( EQUAL( pszDatum, SRS_DN_WGS84 ) )
*piDatum = WGS84;

// If not found well known datum, translate ellipsoid
// If not found well known datum, translate ellipsoid.
else
{
double dfSemiMajor = GetSemiMajor();
double dfInvFlattening = GetInvFlattening();
const double dfSemiMajor = GetSemiMajor();
const double dfInvFlattening = GetInvFlattening();

#ifdef DEBUG
CPLDebug( "OSR_USGS",
"Datum \"%s\" unsupported by USGS GCTP. "
"Try to translate ellipsoid definition.", pszDatum );
#endif

for ( i = 0; i < NUMBER_OF_ELLIPSOIDS; i++ )
int i = 0; // Used after for.
for ( ; i < NUMBER_OF_ELLIPSOIDS; i++ )
{
double dfSM;
double dfIF;
double dfSM = 0.0;
double dfIF = 0.0;

if ( OSRGetEllipsoidInfo( aoEllips[i], NULL,
&dfSM, &dfIF ) == OGRERR_NONE
Expand Down
89 changes: 33 additions & 56 deletions gdal/ogr/ogr_srs_validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,9 @@ OGRErr OGRSpatialReference::Validate(OGR_SRSNode *poRoot)
/* -------------------------------------------------------------------- */
if( EQUAL(poRoot->GetValue(),"COMPD_CS") )
{
OGR_SRSNode *poNode;
int i;

for( i = 1; i < poRoot->GetChildCount(); i++ )
for( int i = 1; i < poRoot->GetChildCount(); i++ )
{
poNode = poRoot->GetChild(i);
OGR_SRSNode *poNode = poRoot->GetChild(i);

if( EQUAL(poNode->GetValue(),"GEOGCS") ||
EQUAL(poNode->GetValue(),"PROJCS") ||
Expand Down Expand Up @@ -686,15 +683,13 @@ OGRErr OGRSpatialReference::Validate(OGR_SRSNode *poRoot)
/* -------------------------------------------------------------------- */
if( EQUAL(poRoot->GetValue(),"VERT_CS") )
{
OGR_SRSNode *poNode;
int i;
bool bGotVertDatum = false;
bool bGotUnit = false;
int nCountAxis = 0;
bool bGotVertDatum = false;
bool bGotUnit = false;
int nCountAxis = 0;

for( i = 1; i < poRoot->GetChildCount(); i++ )
for( int i = 1; i < poRoot->GetChildCount(); i++ )
{
poNode = poRoot->GetChild(i);
OGR_SRSNode *poNode = poRoot->GetChild(i);

if( EQUAL(poNode->GetValue(),"VERT_DATUM") )
{
Expand Down Expand Up @@ -764,16 +759,14 @@ OGRErr OGRSpatialReference::Validate(OGR_SRSNode *poRoot)
/* -------------------------------------------------------------------- */
if( EQUAL(poRoot->GetValue(),"GEOCCS") )
{
OGR_SRSNode *poNode;
int i;
bool bGotDatum = false;
bool bGotPrimeM = false;
bool bGotUnit = false;
int nCountAxis = 0;

for( i = 1; i < poRoot->GetChildCount(); i++ )
bool bGotDatum = false;
bool bGotPrimeM = false;
bool bGotUnit = false;
int nCountAxis = 0;

for( int i = 1; i < poRoot->GetChildCount(); i++ )
{
poNode = poRoot->GetChild(i);
OGR_SRSNode *poNode = poRoot->GetChild(i);

if( EQUAL(poNode->GetValue(),"DATUM") )
{
Expand Down Expand Up @@ -862,12 +855,9 @@ OGRErr OGRSpatialReference::Validate(OGR_SRSNode *poRoot)
/* -------------------------------------------------------------------- */
if( EQUAL(poRoot->GetValue(),"PROJCS") )
{
OGR_SRSNode *poNode;
int i;

for( i = 1; i < poRoot->GetChildCount(); i++ )
for( int i = 1; i < poRoot->GetChildCount(); i++ )
{
poNode = poRoot->GetChild(i);
OGR_SRSNode *poNode = poRoot->GetChild(i);

if( EQUAL(poNode->GetValue(),"GEOGCS") )
{
Expand Down Expand Up @@ -986,12 +976,9 @@ OGRErr OGRSpatialReference::Validate(OGR_SRSNode *poRoot)

if( poGEOGCS != NULL )
{
OGR_SRSNode *poNode;
int i;

for( i = 1; i < poGEOGCS->GetChildCount(); i++ )
for( int i = 1; i < poGEOGCS->GetChildCount(); i++ )
{
poNode = poGEOGCS->GetChild(i);
OGR_SRSNode *poNode = poGEOGCS->GetChild(i);

if( EQUAL(poNode->GetValue(),"DATUM") )
{
Expand Down Expand Up @@ -1059,10 +1046,6 @@ OGRErr OGRSpatialReference::Validate(OGR_SRSNode *poRoot)

if( poDATUM != NULL )
{
OGR_SRSNode *poSPHEROID;
bool bGotSpheroid = false;
int i;

if( poDATUM->GetChildCount() == 0 )
{
CPLDebug( "OGRSpatialReference::Validate",
Expand All @@ -1071,14 +1054,15 @@ OGRErr OGRSpatialReference::Validate(OGR_SRSNode *poRoot)
return OGRERR_CORRUPT_DATA;
}

for( i = 1; i < poDATUM->GetChildCount(); i++ )
bool bGotSpheroid = false;

for( int i = 1; i < poDATUM->GetChildCount(); i++ )
{
OGR_SRSNode *poNode;
poNode = poDATUM->GetChild(i);
OGR_SRSNode *poNode = poDATUM->GetChild(i);

if( EQUAL(poNode->GetValue(),"SPHEROID") )
{
poSPHEROID = poDATUM->GetChild(1);
OGR_SRSNode *poSPHEROID = poDATUM->GetChild(1);
bGotSpheroid = true;

if( poSPHEROID->GetChildCount() != 3
Expand Down Expand Up @@ -1186,16 +1170,15 @@ int OGRSpatialReference::IsAliasFor( const char *pszParm1,
const char *pszParm2 )

{
int iGroup;

/* -------------------------------------------------------------------- */
/* Look for a group containing pszParm1. */
/* -------------------------------------------------------------------- */
for( iGroup = 0; papszAliasGroupList[iGroup] != NULL; iGroup++ )
int iGroup = 0; // Used after for.
for( ; papszAliasGroupList[iGroup] != NULL; iGroup++ )
{
int i;
int i = iGroup; // Used after for.

for( i = iGroup; papszAliasGroupList[i] != NULL; i++ )
for( ; papszAliasGroupList[i] != NULL; i++ )
{
if( EQUAL(pszParm1,papszAliasGroupList[i]) )
break;
Expand Down Expand Up @@ -1269,20 +1252,17 @@ OGRErr OGRSpatialReference::ValidateProjection(OGR_SRSNode *poRoot)
/* Check all parameters, and verify they are in the permitted */
/* list. */
/* -------------------------------------------------------------------- */
int iNode;

for( iNode = 0; iNode < poPROJCS->GetChildCount(); iNode++ )
for( int iNode = 0; iNode < poPROJCS->GetChildCount(); iNode++ )
{
OGR_SRSNode *poParm = poPROJCS->GetChild(iNode);
int i;
const char *pszParmName;

if( !EQUAL(poParm->GetValue(),"PARAMETER") )
continue;

pszParmName = poParm->GetChild(0)->GetValue();
const char *pszParmName = poParm->GetChild(0)->GetValue();

for( i = iOffset; papszProjWithParms[i] != NULL; i++ )
int i = iOffset; // Used after for.
for( ; papszProjWithParms[i] != NULL; i++ )
{
if( EQUAL(papszProjWithParms[i],pszParmName) )
break;
Expand Down Expand Up @@ -1348,12 +1328,9 @@ OGRErr OGRSpatialReference::ValidateVertDatum(OGR_SRSNode *poRoot)
return OGRERR_CORRUPT_DATA;
}

OGR_SRSNode *poNode;
int i;

for( i = 2; i < poRoot->GetChildCount(); i++ )
for( int i = 2; i < poRoot->GetChildCount(); i++ )
{
poNode = poRoot->GetChild(i);
OGR_SRSNode *poNode = poRoot->GetChild(i);

if( EQUAL(poNode->GetValue(),"AUTHORITY") )
{
Expand Down
Loading

0 comments on commit 5af4734

Please sign in to comment.