test/test_config.c
/* helper function to check for known options */
helper function to check for known options
helper function to check for known options
void check_known_options(const kvtree* configured_values,
                         int ignore_id_option,
                         const char* known_options[])
{
    const kvtree_elem* elem;
    for (elem = kvtree_elem_first(configured_values);
         elem != NULL;
         elem = kvtree_elem_next(elem))
    {
        const char* key = kvtree_elem_key(elem);
        if (ignore_id_option && strcmp("id", key) == 0)
            continue;
        const kvtree* elem_hash = kvtree_elem_hash(elem);
        if (kvtree_size(elem_hash) != 1) {
            printf("Element %s has unexpected number of values: %d", key,
                   kvtree_size(elem_hash));
            exit(EXIT_FAILURE);
        }
        const kvtree* kvtree_first_elem_hash =
          kvtree_elem_hash(kvtree_elem_first(elem_hash));
        if (kvtree_size(kvtree_first_elem_hash) != 0) {
            printf("Element %s is not a pure value", key);
            exit(EXIT_FAILURE);
        }
        const char** opt;
        int found = 0;
        for (opt = known_options; *opt != NULL; opt++) {
            if (strcmp(*opt, key) == 0) {
                found = 1;
                break;
            }
        }
        if (! found) {
            printf("Unknown configuration parameter '%s' with value '%s'\n",
              kvtree_elem_key(elem),
              kvtree_elem_key(kvtree_elem_first(kvtree_elem_hash(elem)))
            );
            exit(EXIT_FAILURE);
        }
    }
}
void check_known_options ( const kvtree * configured_values , int ignore_id_option , const char * known_options [ ] ) { const kvtree_elem * elem ; for ( elem = kvtree_elem_first ( configured_values ) ; elem != NULL ; elem = kvtree_elem_next ( elem ) ) { const char * key = kvtree_elem_key ( elem ) ; if ( ignore_id_option && strcmp ( " " , key ) == 0 ) continue ; const kvtree * elem_hash = kvtree_elem_hash ( elem ) ; if ( kvtree_size ( elem_hash ) != 1 ) { printf ( " " , key , kvtree_size ( elem_hash ) ) ; exit ( EXIT_FAILURE ) ; } const kvtree * kvtree_first_elem_hash = kvtree_elem_hash ( kvtree_elem_first ( elem_hash ) ) ; if ( kvtree_size ( kvtree_first_elem_hash ) != 0 ) { printf ( " " , key ) ; exit ( EXIT_FAILURE ) ; } const char * * opt ; int found = 0 ; for ( opt = known_options ; * opt != NULL ; opt ++ ) { if ( strcmp ( * opt , key ) == 0 ) { found = 1 ; break ; } } if ( ! found ) { printf ( " \n " , kvtree_elem_key ( elem ) , kvtree_elem_key ( kvtree_elem_first ( kvtree_elem_hash ( elem ) ) ) ) ; exit ( EXIT_FAILURE ) ; } } }
helper function to check for known options
helper function to check for known options
/* report all unknown options (typos?) */ /* must be only one level deep, ie plain kev = value */ /* check against known options */