Example #1
0
static nc_type
inferattributetype1(Datasrc* src)
{
    nc_type result = NC_NAT;
    /* Recurse down any enclosing compound markers to find first non-fill "primitive"*/
    while(result == NC_NAT && srcmore(src)) {
	if(issublist(src)) {
	    srcpush(src);
	    result = inferattributetype1(src);
	    srcpop(src);
	} else {	
	    Constant* con = srcnext(src);
	    if(isprimplus(con->nctype)) result = con->nctype;
	    /* else keep looking*/
	}
    }
    return result;
}
Example #2
0
void
bufdump(Datalist* list, Bytebuffer* buf)
{
    int i;
    NCConstant** dpl;
    unsigned int count;

    if(list == NULL) {
	bbCat(buf,"NULL");
	return;
    }

    count = list->length;
    for(dpl=list->data,i=0;i<count;i++,dpl++) {
       NCConstant* dp = *dpl;
       switch (dp->nctype) {
        case NC_COMPOUND:
	    bbCat(buf,"{");
	    bufdump(dp->value.compoundv,buf);
	    bbCat(buf,"}");
            break;
        case NC_ARRAY:
	    bbCat(buf,"[");
	    bufdump(dp->value.compoundv,buf);
	    bbCat(buf,"]");
            break;
        case NC_VLEN:
	    bbCat(buf,"{*");
	    bufdump(dp->value.compoundv,buf);
	    bbCat(buf,"}");
            break;
	default:
	    if(isprimplus(dp->nctype) || dp->nctype == NC_FILLVALUE) {
                bbCat(buf," ");
                dumpdataprim(dp,buf);
	    } else {
  	        char tmp[64];
	        sprintf(tmp,"?%d? ",dp->nctype);
   	        bbCat(buf,tmp);
            } break;
	}
    }
}
Example #3
0
/* Force an Opaque or string to conform to a given length*/
void
setprimlength(Constant* prim, unsigned long len)
{
    ASSERT(isprimplus(prim->nctype));
    if(prim->nctype == NC_STRING) {
        if(prim->value.stringv.len == len) {
	    /* do nothing*/
        } else if(prim->value.stringv.len > len) { /* truncate*/
	    prim->value.stringv.stringv[len] = '\0';
	    prim->value.stringv.len = len;
        } else {/* prim->value.stringv.len > srcov->len*/
	    char* s;
            s = (char*)emalloc(len+1);
	    memset(s,NC_FILL_CHAR,len);
	    s[len] = '\0';
	    memcpy(s,prim->value.stringv.stringv,prim->value.stringv.len);
	    efree(prim->value.stringv.stringv);
	    prim->value.stringv.stringv = s;
            prim->value.stringv.len = len;
	}
    } else if(prim->nctype == NC_OPAQUE) {
	/* Note that expansion/contraction is in terms of whole
           bytes = 2 nibbles */
	ASSERT((len % 2) == 0);
        if(prim->value.opaquev.len == len) { 
	    /* do nothing*/
        } else if(prim->value.opaquev.len > len) { /* truncate*/
	    prim->value.opaquev.stringv[len] = '\0';
	    prim->value.opaquev.len = len;
        } else {/* prim->value.opaquev.len < len => expand*/
	    char* s;
	    s = (char*)emalloc(len+1);
	    memset(s,'0',len);
	    memcpy(s,prim->value.opaquev.stringv,prim->value.opaquev.len);
	    s[len] = '\0';
	    efree(prim->value.opaquev.stringv);
	    prim->value.opaquev.stringv=s;
	    prim->value.opaquev.len = len;
        }
    }
}
Example #4
0
static void
checkconsistency(void)
{
    int i;
    for(i=0;i<listlength(grpdefs);i++) {
	Symbol* sym = (Symbol*)listget(grpdefs,i);
	if(sym == rootgroup) {
	    if(sym->container != NULL)
	        PANIC("rootgroup has a container");
	} else if(sym->container == NULL && sym != rootgroup)
	    PANIC1("symbol with no container: %s",sym->name);
	else if(sym->container->ref.is_ref != 0)
	    PANIC1("group with reference container: %s",sym->name);
	else if(sym != rootgroup && !sqContains(sym->container->subnodes,sym))
	    PANIC1("group not in container: %s",sym->name);
	if(sym->subnodes == NULL)
	    PANIC1("group with null subnodes: %s",sym->name);
    }
    for(i=0;i<listlength(typdefs);i++) {
	Symbol* sym = (Symbol*)listget(typdefs,i);
        if(!sqContains(sym->container->subnodes,sym))
	    PANIC1("type not in container: %s",sym->name);
    }
    for(i=0;i<listlength(dimdefs);i++) {
	Symbol* sym = (Symbol*)listget(dimdefs,i);
        if(!sqContains(sym->container->subnodes,sym))
	    PANIC1("dimension not in container: %s",sym->name);
    }
    for(i=0;i<listlength(vardefs);i++) {
	Symbol* sym = (Symbol*)listget(vardefs,i);
        if(!sqContains(sym->container->subnodes,sym))
	    PANIC1("variable not in container: %s",sym->name);
	if(!(isprimplus(sym->typ.typecode)
	     || sqContains(typdefs,sym->typ.basetype)))
	    PANIC1("variable with undefined type: %s",sym->name);
    }
}
Example #5
0
static void
dumpdataprim(NCConstant* ci, Bytebuffer* buf)
{
    char tmp[64];
    ASSERT(isprimplus(ci->nctype) || ci->nctype == NC_FILLVALUE);
    switch (ci->nctype) {
    case NC_CHAR: {
	bbCat(buf,"'");
	escapifychar(ci->value.charv,tmp,'\'');
	bbCat(buf,tmp);
	bbCat(buf,"'");
	} break;
    case NC_BYTE:
	sprintf(tmp,"%hhd",ci->value.int8v);
	bbCat(buf,tmp);
	break;
    case NC_SHORT:
	sprintf(tmp,"%hd",ci->value.int16v);
	bbCat(buf,tmp);
	break;
    case NC_INT:
	sprintf(tmp,"%d",ci->value.int32v);
	bbCat(buf,tmp);
	break;
    case NC_FLOAT:
	sprintf(tmp,"%g",ci->value.floatv);
	bbCat(buf,tmp);
	break;
    case NC_DOUBLE:
	sprintf(tmp,"%lg",ci->value.doublev);
	bbCat(buf,tmp);
	break;
    case NC_UBYTE:
	sprintf(tmp,"%hhu",ci->value.int8v);
	bbCat(buf,tmp);
	break;
    case NC_USHORT:
	sprintf(tmp,"%hu",ci->value.uint16v);
	bbCat(buf,tmp);
	break;
    case NC_UINT:
	sprintf(tmp,"%u",ci->value.uint32v);
	bbCat(buf,tmp);
	break;
    case NC_INT64:
	sprintf(tmp,"%lld",ci->value.int64v);
	bbCat(buf,tmp);
	break;
    case NC_UINT64:
	sprintf(tmp,"%llu",ci->value.uint64v);
	bbCat(buf,tmp);
	break;
    case NC_ECONST:
	sprintf(tmp,"%s",ci->value.enumv->fqn);
	bbCat(buf,tmp);
	break;
    case NC_STRING:
	bbCat(buf,"\"");
	bbCat(buf,ci->value.stringv.stringv);
	bbCat(buf,"\"");
	break;
    case NC_OPAQUE:
	bbCat(buf,"0x");
	bbCat(buf,ci->value.opaquev.stringv);
	break;
    case NC_FILLVALUE:
	bbCat(buf,"_");
	break;
    default: PANIC1("dumpdataprim: bad type code:%d",ci->nctype);
    }
}