Fix grib_keys_iterator_set_flags and also cleanup indents etc

This commit is contained in:
Shahram Najm 2013-07-17 14:42:36 +01:00
parent db93e2f6af
commit 4dfda27c0b
1 changed files with 128 additions and 127 deletions

View File

@ -11,13 +11,12 @@
/*
* C Implementation: grib_keys_iterator
*
* Description:
*
*/
#include "grib_api_internal.h"
GRIB_INLINE static int grib_inline_strcmp(const char* a,const char* b) {
GRIB_INLINE static int grib_inline_strcmp(const char* a,const char* b)
{
if (*a != *b) return 1;
while((*a!=0 && *b!=0) && *(a) == *(b) ) {a++;b++;}
return (*a==0 && *b==0) ? 0 : 1;
@ -34,9 +33,8 @@ struct grib_keys_iterator{
grib_trie *seen;
};
grib_keys_iterator* grib_keys_iterator_new(grib_handle* h,unsigned long filter_flags, char* name_space) {
grib_keys_iterator* grib_keys_iterator_new(grib_handle* h,unsigned long filter_flags, char* name_space)
{
grib_keys_iterator* ki=NULL;
if (!h) return NULL;
@ -59,7 +57,8 @@ grib_keys_iterator* grib_keys_iterator_new(grib_handle* h,unsigned long filter_
return ki;
}
int grib_keys_iterator_set_flags(grib_keys_iterator* ki,unsigned long flags) {
int grib_keys_iterator_set_flags(grib_keys_iterator* ki,unsigned long flags)
{
int ret=0;
grib_handle* h;
@ -67,7 +66,7 @@ int grib_keys_iterator_set_flags(grib_keys_iterator* ki,unsigned long flags) {
h=ki->handle;
if((flags & GRIB_KEYS_ITERATOR_SKIP_DUPLICATES) && ki->seen!=NULL )
if((flags & GRIB_KEYS_ITERATOR_SKIP_DUPLICATES) && ki->seen==NULL )
ki->seen = grib_trie_new(h->context);
if(flags & GRIB_KEYS_ITERATOR_SKIP_FUNCTION)
@ -92,15 +91,14 @@ static int was_seen(grib_keys_iterator* ki,const char* name)
return grib_trie_get(ki->seen,name) != NULL;
}
int grib_keys_iterator_rewind(grib_keys_iterator* ki)
{
ki->at_start = 1;
return GRIB_SUCCESS;
}
static int skip(grib_keys_iterator* kiter) {
static int skip(grib_keys_iterator* kiter)
{
/* TODO: set the section to hidden, to speed up that */
/* if(grib_get_sub_section(kiter->current)) */
if(kiter->current->sub_section)
@ -120,12 +118,11 @@ static int skip(grib_keys_iterator* kiter) {
if(kiter->name_space)
{
kiter->match = 0;
while(kiter->match < MAX_ACCESSOR_NAMES)
{
if(kiter->current->all_name_spaces[kiter->match] != NULL)
if(kiter->current->all_name_spaces[kiter->match] != NULL) {
if(grib_inline_strcmp(kiter->current->all_name_spaces[kiter->match],kiter->name_space) == 0)
{
if(kiter->seen)
@ -136,12 +133,11 @@ static int skip(grib_keys_iterator* kiter) {
}
return 0;
}
}
kiter->match++;
}
return 1;
}
if(kiter->seen)
@ -152,11 +148,12 @@ static int skip(grib_keys_iterator* kiter) {
}
return 0;
}
int grib_keys_iterator_next(grib_keys_iterator* kiter){
if(kiter->at_start) {
int grib_keys_iterator_next(grib_keys_iterator* kiter)
{
if(kiter->at_start)
{
kiter->current = kiter->handle->root->block->first;
kiter->at_start = 0;
}
@ -171,7 +168,6 @@ int grib_keys_iterator_next(grib_keys_iterator* kiter){
return kiter->current != NULL;
}
const char* grib_keys_iterator_get_name(grib_keys_iterator* kiter)
{
/* if(kiter->name_space) */
@ -183,7 +179,8 @@ grib_accessor* grib_keys_iterator_get_accessor(grib_keys_iterator* kiter)
return kiter->current;
}
int grib_keys_iterator_delete( grib_keys_iterator* kiter){
int grib_keys_iterator_delete( grib_keys_iterator* kiter)
{
if (kiter) {
if(kiter->seen)
grib_trie_delete(kiter->seen);
@ -194,23 +191,27 @@ int grib_keys_iterator_delete( grib_keys_iterator* kiter){
return 0;
}
int grib_keys_iterator_get_long(grib_keys_iterator* kiter,long* v,size_t* len) {
int grib_keys_iterator_get_long(grib_keys_iterator* kiter,long* v,size_t* len)
{
return grib_unpack_long( kiter->current,v,len);
}
int grib_keys_iterator_get_double(grib_keys_iterator* kiter,double* v,size_t* len) {
int grib_keys_iterator_get_double(grib_keys_iterator* kiter,double* v,size_t* len)
{
return grib_unpack_double( kiter->current,v,len);
}
int grib_keys_iterator_get_string(grib_keys_iterator* kiter,char* v,size_t* len) {
int grib_keys_iterator_get_string(grib_keys_iterator* kiter,char* v,size_t* len)
{
return grib_unpack_string( kiter->current,v,len);
}
int grib_keys_iterator_get_bytes(grib_keys_iterator* kiter,unsigned char* v,size_t* len) {
int grib_keys_iterator_get_bytes(grib_keys_iterator* kiter,unsigned char* v,size_t* len)
{
return grib_unpack_bytes( kiter->current,v,len);
}
int grib_keys_iterator_get_native_type(grib_keys_iterator* kiter) {
int grib_keys_iterator_get_native_type(grib_keys_iterator* kiter)
{
return grib_accessor_get_native_type(kiter->current);
}