mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-21 03:13:42 +08:00
draft attempt at fixing the fill problem
This commit is contained in:
parent
7e63849e03
commit
a62c00b4bf
@ -34,6 +34,12 @@ c_constant(Generator* generator, Constant* con, Bytebuffer* buf,...)
|
||||
char* special = NULL;
|
||||
|
||||
switch (con->nctype) {
|
||||
case NC_CHAR:
|
||||
if(con->value.charv == '\'')
|
||||
bbprintf(codetmp,"'\\''");
|
||||
else
|
||||
bbprintf(codetmp,"'%c'",con->value.charv);
|
||||
break;
|
||||
case NC_BYTE:
|
||||
bbprintf(codetmp,"%hhd",con->value.int8v);
|
||||
break;
|
||||
|
@ -596,6 +596,10 @@ retry: switch ((c=*p++)) {
|
||||
text = va_arg(argv,char*);
|
||||
bbCat(buf,text);
|
||||
break;
|
||||
case 'c':
|
||||
c = va_arg(argv,int);
|
||||
bbAppend(buf,(char)c);
|
||||
break;
|
||||
default:
|
||||
PANIC1("vbbprintf: unknown specifier: %c",(char)c);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
L="-lc"
|
||||
K="-k3"
|
||||
K="-k1"
|
||||
alias q0="./ncgen -d $K $L test.cdl"
|
||||
alias qq="gdb --args ./ncgen -d $K $L test.cdl"
|
||||
alias qv="valgrind --leak-check=full ./ncgen -d $K $L test.cdl"
|
||||
|
@ -35,11 +35,10 @@ f77_constant(Generator* generator, Constant* ci, Bytebuffer* codebuf,...)
|
||||
switch (ci->nctype) {
|
||||
|
||||
case NC_CHAR:
|
||||
{
|
||||
strcpy(tmp,"'");
|
||||
escapifychar(ci->value.charv,tmp+1,'\'');
|
||||
strcat(tmp,"'");
|
||||
}
|
||||
if(ci->value.charv == '\'')
|
||||
sprintf(tmp,"'\\''");
|
||||
else
|
||||
sprintf(tmp,"'%c'",ci->value.charv);
|
||||
break;
|
||||
case NC_BYTE:
|
||||
sprintf(tmp,"%hhd",ci->value.int8v);
|
||||
|
@ -367,10 +367,20 @@ genbin_write(Generator* generator, Symbol* sym, Bytebuffer* memory,
|
||||
|
||||
static int
|
||||
genbin_writevar(Generator* generator, Symbol* vsym, Bytebuffer* memory,
|
||||
int rank, size_t* start, size_t* count)
|
||||
int rank, size_t* start,
|
||||
#ifdef USE_NOFILL
|
||||
size_t* indices
|
||||
#else
|
||||
size_t* count
|
||||
#endif
|
||||
)
|
||||
{
|
||||
int stat = NC_NOERR;
|
||||
char* data = bbContents(memory);
|
||||
#ifdef USE_NOFILL
|
||||
size_t count[NC_MAX_VAR_DIMS];
|
||||
{ int i; for(i=0;i<rank;i++) count[i] = indices[i] - start[i];}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
|
@ -39,6 +39,15 @@ int generator_reset(Generator* generator, void* state)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
checkodom(Odometer* odom)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<odom->rank;i++) {
|
||||
ASSERT(odom->index[i] == odom->start[i]+odom->count[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************/
|
||||
|
||||
void
|
||||
@ -124,12 +133,21 @@ generate_array(Symbol* vsym,
|
||||
if(nelems == 0) break;
|
||||
generator->listbegin(generator,LISTDATA,vsym->data->length,code,&uid);
|
||||
for(i=0;i<nelems;i++) {
|
||||
Constant* con = datalistith(vsym->data,i);
|
||||
generator->list(generator,LISTDATA,uid,i,code);
|
||||
generate_basetype(basetype,con,code,filler,generator);
|
||||
Constant* con = datalistith(vsym->data,i);
|
||||
generator->list(generator,LISTDATA,uid,i,code);
|
||||
#ifdef USE_NOFILL
|
||||
if(nofill_flag && con == NULL)
|
||||
break;
|
||||
else
|
||||
#endif
|
||||
generate_basetype(basetype,con,code,filler,generator);
|
||||
}
|
||||
generator->listend(generator,LISTDATA,uid,i,code);
|
||||
#ifdef USE_NOFILL
|
||||
writer(generator,vsym,code,rank,odom->start,odom->index);
|
||||
#else
|
||||
writer(generator,vsym,code,rank,odom->start,odom->count);
|
||||
#endif
|
||||
}
|
||||
} else
|
||||
|
||||
@ -146,8 +164,13 @@ generate_array(Symbol* vsym,
|
||||
/*dim index=*/0,
|
||||
filler,generator
|
||||
);
|
||||
#ifdef USE_NOFILL
|
||||
writer(generator,vsym,code,odom->rank,odom->start,odom->index);
|
||||
#else
|
||||
writer(generator,vsym,code,odom->rank,odom->start,odom->count);
|
||||
#endif
|
||||
}
|
||||
checkodom(odom);
|
||||
}
|
||||
odometerfree(odom);
|
||||
}
|
||||
@ -189,6 +212,10 @@ generate_arrayr(Symbol* vsym,
|
||||
for(i=0;odometermore(slabodom);i++) {
|
||||
size_t offset = odometeroffset(slabodom);
|
||||
Constant* con = datalistith(list,offset);
|
||||
#ifdef USE_NOFILL
|
||||
if(nofill_flag && con == NULL)
|
||||
break;
|
||||
#endif
|
||||
generator->list(generator,LISTDATA,uid,i,code);
|
||||
generate_basetype(basetype,con,code,filler,generator);
|
||||
odometerincr(slabodom);
|
||||
@ -214,6 +241,10 @@ generate_arrayr(Symbol* vsym,
|
||||
for(i=0;odometermore(slabodom);i++) {
|
||||
size_t offset = odometeroffset(slabodom);
|
||||
Constant* con = datalistith(list,offset);
|
||||
#ifdef USE_NOFILL
|
||||
if(nofill_flag && con == NULL)
|
||||
break;
|
||||
#endif
|
||||
if(!islistconst(con))
|
||||
semwarn(constline(con),"Expected {...} representing unlimited list");
|
||||
else {
|
||||
|
@ -10,6 +10,8 @@
|
||||
#ifndef NCGEN_INCLUDES_H
|
||||
#define NCGEN_INCLUDES_H
|
||||
|
||||
#undef USE_NOFILL
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -34,6 +34,12 @@ j_constant(Generator* generator, Constant* con, Bytebuffer* buf,...)
|
||||
char* special = NULL;
|
||||
|
||||
switch (con->nctype) {
|
||||
case NC_CHAR:
|
||||
if(con->value.charv == '\'')
|
||||
bbprintf(codetmp,"'\\''");
|
||||
else
|
||||
bbprintf(codetmp,"'%c'",con->value.charv);
|
||||
break;
|
||||
case NC_BYTE:
|
||||
bbprintf(codetmp,"%hhd",con->value.int8v);
|
||||
break;
|
||||
|
@ -551,9 +551,12 @@ processspecial1(Symbol* vsym)
|
||||
if((tag=(flags & _NOFILL_FLAG))) {
|
||||
con.nctype = NC_STRING;
|
||||
/* Watch out: flags is NOFILL, but we store FILL */
|
||||
con.value.stringv.stringv
|
||||
= (vsym->var.special._Fill == 1? "false"
|
||||
: "true");
|
||||
if(vsym->var.special._Fill == 1) {
|
||||
con.value.stringv.stringv = "false";
|
||||
} else {
|
||||
nofill_flag = 1;
|
||||
con.value.stringv.stringv = "true";
|
||||
}
|
||||
con.value.stringv.len = strlen(con.value.stringv.stringv);
|
||||
dlist = builddatalist(1);
|
||||
dlappend(dlist,&con);
|
||||
|
Loading…
Reference in New Issue
Block a user