Skip to content

Commit

Permalink
Combined pointer definition and initialization in ogrsf_frmts/ plscen…
Browse files Browse the repository at this point in the history
…es s57 sdts segukooa segy selafin shape sosi sqlite sua sxf tiger.

Also:
- Localize variables
- Initialize local vars
- Fix formatting
- Fit to 80 cols
- /* */ -> //
- Rename vars to allow const
- Add const
- Initialize small constant sized arrays at definition time e.g. szName and nRCID
- Define one var per line / statement
- int bFoo -> bool bFoo

Skipped tigerinfo as it does not currently build: OSGeo#6626

git-svn-id: https://svn.osgeo.org/gdal/trunk@35147 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information
schwehr committed Aug 18, 2016
1 parent 1d3f312 commit 4d91529
Show file tree
Hide file tree
Showing 34 changed files with 397 additions and 489 deletions.
4 changes: 1 addition & 3 deletions gdal/ogr/ogrsf_frmts/plscenes/ogrplscenesv1layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,11 +1433,9 @@ OGRErr OGRPLScenesV1Layer::SetAttributeFilter( const char *pszQuery )

OGRFeature *OGRPLScenesV1Layer::GetNextFeature()
{
OGRFeature *poFeature;

while( true )
{
poFeature = GetNextRawFeature();
OGRFeature *poFeature = GetNextRawFeature();
if (poFeature == NULL)
return NULL;

Expand Down
2 changes: 1 addition & 1 deletion gdal/ogr/ogrsf_frmts/s57/s57classregistrar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int S57ClassRegistrar::FindFile( const char *pszTarget,
VSILFILE **pfp )

{
const char *pszFilename;
const char *pszFilename = NULL;

if( pszDirectory == NULL )
{
Expand Down
4 changes: 2 additions & 2 deletions gdal/ogr/ogrsf_frmts/s57/s57dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ int main( int nArgc, char ** papszArgv )

oReader.AddFeatureDefn( S57GenerateDSIDFeatureDefn() );

OGRFeature *poFeature;
int nFeatures = 0;
OGRFeature *poFeature = NULL;
int nFeatures = 0;

while( (poFeature = oReader.ReadNextFeature()) != NULL )
{
Expand Down
27 changes: 12 additions & 15 deletions gdal/ogr/ogrsf_frmts/s57/s57reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,10 @@ int S57Reader::Ingest()
/* appropriate indexes. */
/* -------------------------------------------------------------------- */
CPLErrorReset();
DDFRecord *poRecord;
DDFRecord *poRecord = NULL;
while( (poRecord = poModule->ReadRecord()) != NULL )
{
DDFField *poKeyField = poRecord->GetField(1);
DDFField *poKeyField = poRecord->GetField(1);
if (poKeyField == NULL)
return FALSE;

Expand Down Expand Up @@ -1921,11 +1921,9 @@ void S57Reader::AssembleSoundingGeometry( DDFRecord * poFRecord,
int nRCNM = 0;
const int nRCID = ParseName( poFSPT, 0, &nRCNM );

DDFRecord *poSRecord;
if( nRCNM == RCNM_VI )
poSRecord = oVI_Index.FindRecord( nRCID );
else
poSRecord = oVC_Index.FindRecord( nRCID );
DDFRecord *poSRecord = nRCNM == RCNM_VI
? oVI_Index.FindRecord( nRCID )
: oVC_Index.FindRecord( nRCID );

if( poSRecord == NULL )
return;
Expand Down Expand Up @@ -3119,7 +3117,7 @@ int S57Reader::ApplyUpdates( DDFModule *poUpdateModule )
/* -------------------------------------------------------------------- */
CPLErrorReset();

DDFRecord *poRecord;
DDFRecord *poRecord = NULL;

while( (poRecord = poUpdateModule->ReadRecord()) != NULL )
{
Expand Down Expand Up @@ -3424,18 +3422,17 @@ OGRErr S57Reader::GetExtent( OGREnvelope *psExtent, int bForce )
}
else if( poSG2D != NULL )
{
int i, nVCount = poSG2D->GetRepeatCount();
GInt32 nX, nY;
const GByte *pabyData;
const int nVCount = poSG2D->GetRepeatCount();

pabyData = (const GByte*)poSG2D->GetData();
if( poSG2D->GetDataSize() < 2 * nVCount * (int)sizeof(int) )
return OGRERR_FAILURE;

for( i = 0; i < nVCount; i++ )
const GByte *pabyData = (const GByte*)poSG2D->GetData();

for( int i = 0; i < nVCount; i++ )
{
nX = CPL_LSBINT32PTR(pabyData + 4*(i*2+1));
nY = CPL_LSBINT32PTR(pabyData + 4*(i*2+0));
const GInt32 nX = CPL_LSBINT32PTR(pabyData + 4*(i*2+1));
const GInt32 nY = CPL_LSBINT32PTR(pabyData + 4*(i*2+0));

if( bGotExtents )
{
Expand Down
109 changes: 53 additions & 56 deletions gdal/ogr/ogrsf_frmts/s57/s57writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,9 @@ int S57Writer::WriteDSID( int nEXPP /*1*/, int nINTU /*4*/,
/* Add the DSID field. */
/* -------------------------------------------------------------------- */
DDFRecord *poRec = MakeRecord();
/* DDFField *poField; */

/* poField = */ poRec->AddField( poModule->FindFieldDefn( "DSID" ) );
// DDFField *poField =
poRec->AddField( poModule->FindFieldDefn( "DSID" ) );

poRec->SetIntSubfield ( "DSID", 0, "RCNM", 0, 10 );
poRec->SetIntSubfield ( "DSID", 0, "RCID", 0, 1 );
Expand Down Expand Up @@ -535,9 +535,9 @@ int S57Writer::WriteDSPM( int nHDAT, int nVDAT, int nSDAT, int nCSCL )
/* Add the DSID field. */
/* -------------------------------------------------------------------- */
DDFRecord *poRec = MakeRecord();
/* DDFField *poField; */

/* poField = */ poRec->AddField( poModule->FindFieldDefn( "DSPM" ) );
// DDFField *poField =
poRec->AddField( poModule->FindFieldDefn( "DSPM" ) );

poRec->SetIntSubfield ( "DSPM", 0, "RCNM", 0, 20 );
poRec->SetIntSubfield ( "DSPM", 0, "RCID", 0, 1 );
Expand Down Expand Up @@ -650,14 +650,14 @@ int S57Writer::WritePrimitive( OGRFeature *poFeature )

{
DDFRecord *poRec = MakeRecord();
/* DDFField *poField; */
OGRGeometry *poGeom = poFeature->GetGeometryRef();

/* -------------------------------------------------------------------- */
/* Add the VRID field. */
/* -------------------------------------------------------------------- */

/* poField = */ poRec->AddField( poModule->FindFieldDefn( "VRID" ) );
// DDFField *poField =
poRec->AddField( poModule->FindFieldDefn( "VRID" ) );

poRec->SetIntSubfield ( "VRID", 0, "RCNM", 0,
poFeature->GetFieldAsInteger( "RCNM") );
Expand Down Expand Up @@ -753,22 +753,21 @@ int S57Writer::WritePrimitive( OGRFeature *poFeature )
/* -------------------------------------------------------------------- */
if( poFeature->GetDefnRef()->GetFieldIndex( "NAME_RCNM_0" ) >= 0 )
{
/* DDFField *poField; */
char szName[5];
int nRCID;

CPLAssert( poFeature->GetFieldAsInteger( "NAME_RCNM_0") == RCNM_VC );

/* poField = */ poRec->AddField( poModule->FindFieldDefn( "VRPT" ) );
// DDFField *poField =
poRec->AddField( poModule->FindFieldDefn( "VRPT" ) );

nRCID = poFeature->GetFieldAsInteger( "NAME_RCID_0");
szName[0] = RCNM_VC;
szName[1] = nRCID & 0xff;
szName[2] = (char) ((nRCID & 0xff00) >> 8);
szName[3] = (char) ((nRCID & 0xff0000) >> 16);
szName[4] = (char) ((nRCID & 0xff000000) >> 24);
const int nRCID0 = poFeature->GetFieldAsInteger( "NAME_RCID_0");
char szName0[5] = {
RCNM_VC,
static_cast<char>(nRCID0 & 0xff),
static_cast<char>((nRCID0 & 0xff00) >> 8),
static_cast<char>((nRCID0 & 0xff0000) >> 16),
static_cast<char>((nRCID0 & 0xff000000) >> 24)
};

poRec->SetStringSubfield( "VRPT", 0, "NAME", 0, szName, 5 );
poRec->SetStringSubfield( "VRPT", 0, "NAME", 0, szName0, 5 );
poRec->SetIntSubfield ( "VRPT", 0, "ORNT", 0,
poFeature->GetFieldAsInteger( "ORNT_0") );
poRec->SetIntSubfield ( "VRPT", 0, "USAG", 0,
Expand All @@ -778,14 +777,16 @@ int S57Writer::WritePrimitive( OGRFeature *poFeature )
poRec->SetIntSubfield ( "VRPT", 0, "MASK", 0,
poFeature->GetFieldAsInteger( "MASK_0") );

nRCID = poFeature->GetFieldAsInteger( "NAME_RCID_1");
szName[0] = RCNM_VC;
szName[1] = nRCID & 0xff;
szName[2] = (char) ((nRCID & 0xff00) >> 8);
szName[3] = (char) ((nRCID & 0xff0000) >> 16);
szName[4] = (char) ((nRCID & 0xff000000) >> 24);
const int nRCID1 = poFeature->GetFieldAsInteger( "NAME_RCID_1");
const char szName1[5] = {
RCNM_VC,
static_cast<char>(nRCID1 & 0xff),
static_cast<char>((nRCID1 & 0xff00) >> 8),
static_cast<char>((nRCID1 & 0xff0000) >> 16),
static_cast<char>((nRCID1 & 0xff000000) >> 24)
};

poRec->SetStringSubfield( "VRPT", 0, "NAME", 1, szName, 5 );
poRec->SetStringSubfield( "VRPT", 0, "NAME", 1, szName1, 5 );
poRec->SetIntSubfield ( "VRPT", 0, "ORNT", 1,
poFeature->GetFieldAsInteger( "ORNT_1") );
poRec->SetIntSubfield ( "VRPT", 0, "USAG", 1,
Expand Down Expand Up @@ -859,9 +860,8 @@ int S57Writer::WriteCompleteFeature( OGRFeature *poFeature )
/* -------------------------------------------------------------------- */
/* Add the FRID. */
/* -------------------------------------------------------------------- */
/*DDFField *poField;*/

/*poField = */poRec->AddField( poModule->FindFieldDefn( "FRID" ) );
// DDFField *poField =
poRec->AddField( poModule->FindFieldDefn( "FRID" ) );

poRec->SetIntSubfield ( "FRID", 0, "RCNM", 0, 100 );
poRec->SetIntSubfield ( "FRID", 0, "RCID", 0,
Expand Down Expand Up @@ -904,23 +904,25 @@ int S57Writer::WriteCompleteFeature( OGRFeature *poFeature )
/* -------------------------------------------------------------------- */
if( poFeature->IsFieldSet( poFeature->GetFieldIndex("NAME_RCNM") ) )
{
int nItemCount, i;
const int *panRCNM, *panRCID, *panORNT, *panUSAG, *panMASK;
unsigned char *pabyRawData;
int nRawDataSize;

panRCNM = poFeature->GetFieldAsIntegerList( "NAME_RCNM", &nItemCount );
panRCID = poFeature->GetFieldAsIntegerList( "NAME_RCID", &nItemCount );
panORNT = poFeature->GetFieldAsIntegerList( "ORNT", &nItemCount );
panUSAG = poFeature->GetFieldAsIntegerList( "USAG", &nItemCount );
panMASK = poFeature->GetFieldAsIntegerList( "MASK", &nItemCount );
int nItemCount = 0;

const int *panRCNM =
poFeature->GetFieldAsIntegerList( "NAME_RCNM", &nItemCount );
const int *panRCID =
poFeature->GetFieldAsIntegerList( "NAME_RCID", &nItemCount );
const int *panORNT =
poFeature->GetFieldAsIntegerList( "ORNT", &nItemCount );
const int *panUSAG =
poFeature->GetFieldAsIntegerList( "USAG", &nItemCount );
const int *panMASK =
poFeature->GetFieldAsIntegerList( "MASK", &nItemCount );

CPLAssert( sizeof(int) == sizeof(GInt32) );

nRawDataSize = nItemCount * 8;
pabyRawData = (unsigned char *) CPLMalloc(nRawDataSize);
const int nRawDataSize = nItemCount * 8;
unsigned char *pabyRawData = (unsigned char *) CPLMalloc(nRawDataSize);

for( i = 0; i < nItemCount; i++ )
for( int i = 0; i < nItemCount; i++ )
{
GInt32 nRCID = CPL_LSBWORD32(panRCID[i]);

Expand Down Expand Up @@ -1007,42 +1009,39 @@ void S57Writer::SetClassBased( S57ClassRegistrar * poReg,

int S57Writer::WriteATTF( DDFRecord *poRec, OGRFeature *poFeature )
{
int nRawSize=0, nACount = 0;
char achRawData[5000];
char **papszAttrList;

CPLAssert( poRegistrar != NULL );

/* -------------------------------------------------------------------- */
/* Loop over all attributes. */
/* -------------------------------------------------------------------- */
papszAttrList = poClassContentExplorer->GetAttributeList(NULL);
int nRawSize = 0;
int nACount = 0;
char achRawData[5000] = {};

char **papszAttrList = poClassContentExplorer->GetAttributeList(NULL);

for( int iAttr = 0; papszAttrList[iAttr] != NULL; iAttr++ )
{
int iField = poFeature->GetFieldIndex( papszAttrList[iAttr] );
const int iField = poFeature->GetFieldIndex( papszAttrList[iAttr] );
OGRFieldType eFldType =
poFeature->GetDefnRef()->GetFieldDefn(iField)->GetType();
int nATTLInt;
GUInt16 nATTL;
const char *pszATVL;

if( iField < 0 )
continue;

if( !poFeature->IsFieldSet( iField ) )
continue;

nATTLInt = poRegistrar->FindAttrByAcronym( papszAttrList[iAttr] );
const int nATTLInt = poRegistrar->FindAttrByAcronym( papszAttrList[iAttr] );
if( nATTLInt == -1 )
continue;

nATTL = (GUInt16)nATTLInt;
GUInt16 nATTL = (GUInt16)nATTLInt;
nATTL = CPL_LSBWORD16( nATTL );
memcpy( achRawData + nRawSize, &nATTL, 2 );
nRawSize += 2;

pszATVL = poFeature->GetFieldAsString( iField );
const char *pszATVL = poFeature->GetFieldAsString( iField );

// Special hack to handle special "empty" marker in integer fields.
if( atoi(pszATVL) == EMPTY_NUMBER_MARKER
Expand Down Expand Up @@ -1074,9 +1073,7 @@ int S57Writer::WriteATTF( DDFRecord *poRec, OGRFeature *poFeature )
/* -------------------------------------------------------------------- */
/* Write the new field value. */
/* -------------------------------------------------------------------- */
DDFField *poField;

poField = poRec->AddField( poModule->FindFieldDefn( "ATTF" ) );
DDFField *poField = poRec->AddField( poModule->FindFieldDefn( "ATTF" ) );

return poRec->SetFieldRaw( poField, 0, achRawData, nRawSize );
}
11 changes: 4 additions & 7 deletions gdal/ogr/ogrsf_frmts/sdts/ogrsdtsdatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,11 @@ int OGRSDTSDataSource::Open( const char * pszFilename, int bTestOpen )
/* -------------------------------------------------------------------- */
if( bTestOpen )
{
FILE *fp;
char pachLeader[10];

fp = VSIFOpen( pszFilename, "rb" );
FILE *fp = VSIFOpen( pszFilename, "rb" );
if( fp == NULL )
return FALSE;

char pachLeader[10] = {};
if( VSIFRead( pachLeader, 1, 10, fp ) != 10
|| (pachLeader[5] != '1' && pachLeader[5] != '2'
&& pachLeader[5] != '3' )
Expand Down Expand Up @@ -187,12 +185,11 @@ int OGRSDTSDataSource::Open( const char * pszFilename, int bTestOpen )
/* -------------------------------------------------------------------- */
for( int iLayer = 0; iLayer < poTransfer->GetLayerCount(); iLayer++ )
{
SDTSIndexedReader *poReader;

if( poTransfer->GetLayerType( iLayer ) == SLTRaster )
continue;

poReader = poTransfer->GetLayerIndexedReader( iLayer );
SDTSIndexedReader *poReader =
poTransfer->GetLayerIndexedReader( iLayer );
if( poReader == NULL )
continue;

Expand Down
Loading

0 comments on commit 4d91529

Please sign in to comment.