Commit 73d1b971 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added support for namelist without environment

parent d97a2667
#include <errno.h>
#include "cdo_int.h"
#include "namelist.h"
......@@ -69,10 +68,14 @@ int namelist_to_pml(list_t *pmlist, namelist_parser *parser, char *buf)
}
else if ( t->type == NAMELIST_KEY )
{
if ( kvlist == NULL )
{
kvlist = kvlist_new(NULL);
list_append(pmlist, &kvlist);
}
// printf(" key >%.*s<\n", t->end - t->start, buf+t->start);
snprintf(name, sizeof(name), "%.*s", t->end - t->start, buf+t->start);
name[sizeof(name)-1] = 0;
if ( kvlist == NULL ) printf("kvlist not defined\n");
int nvalues = get_number_of_values(ntok-it-1, &tokens[it+1]);
kvlist_append_namelist(kvlist, name, buf, &tokens[it+1], nvalues);
it += nvalues;
......@@ -95,6 +98,7 @@ list_t *namelistbuf_to_pmlist(listbuf_t *listbuf)
int status = namelist_parse(p, listbuf->buffer, listbuf->size);
if ( status )
{
switch (status)
{
case NAMELIST_ERROR_INVAL: fprintf(stderr, "Namelist error: Invalid character in %s (line=%d character='%c')!\n", name, p->lineno, listbuf->buffer[p->pos]); break;
......@@ -102,11 +106,13 @@ list_t *namelistbuf_to_pmlist(listbuf_t *listbuf)
case NAMELIST_ERROR_INKEY: fprintf(stderr, "Namelist error: Invalid key word in %s (line=%d)!\n", name, p->lineno); break;
case NAMELIST_ERROR_INTYP: fprintf(stderr, "Namelist error: Invalid key word type in %s (line=%d)!\n", name, p->lineno); break;
case NAMELIST_ERROR_INOBJ: fprintf(stderr, "Namelist error: Invalid object in %s (line=%d)!\n", name, p->lineno); break;
case NAMELIST_ERROR_EMKEY: fprintf(stderr, "Namelsit error: Emtry key name in %s (line=%d)!\n", name, p->lineno); break;
default: fprintf(stderr, "Namelsit error in %s (line=%d)!\n", name, p->lineno); break;
case NAMELIST_ERROR_EMKEY: fprintf(stderr, "Namelist error: Emtry key name in %s (line=%d)!\n", name, p->lineno); break;
default: fprintf(stderr, "Namelist error in %s (line=%d)!\n", name, p->lineno); break;
}
cdoAbort("Namelist error!");
}
// namelist_dump(p, buffer);
// namelist_dump(p, listbuf->buffer);
list_t *pmlist = list_new(sizeof(list_t *), free_kvlist, listbuf->name);
......
......@@ -66,7 +66,8 @@ void kvlist_print(list_t *kvlist)
bool pmlist_print_iter(void *data)
{
list_t *kvlist = *(list_t **)data;
printf("\nFound %s list with %d key/values: \n", list_name(kvlist), list_size(kvlist));
const char *listname = list_name(kvlist);
printf("\nFound %s list with %d key/values: \n", listname?listname:"", list_size(kvlist));
list_for_each(kvlist, kvlist_print_iter);
return true;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment