Beispiel #1
0
static void
dumpocnode1(OCnode* node, int depth)
{
    unsigned int n;
    switch (node->octype) {
    case OC_Atomic: {
        fprintf(stdout,"[%2d]%s ",depth,dent(depth));
	if(node->name == NULL) OCPANIC("prim without name");
	fprintf(stdout,"%s %s",octypetostring(node->etype),node->name);
	dumpdimensions(node);
	fprintf(stdout," &%lx",(unsigned long)node);
	fprintf(stdout,"\n");
    } break;

    case OC_Dataset: {
        fprintf(stdout,"[%2d]%s ",depth,dent(depth));
	fprintf(stdout,"dataset %s\n",
		(node->name?node->name:""));
	for(n=0;n<oclistlength(node->subnodes);n++) {
	    dumpocnode1((OCnode*)oclistget(node->subnodes,n),depth+1);
	}
    } break;

    case OC_Structure: {
        fprintf(stdout,"[%2d]%s ",depth,dent(depth));
	fprintf(stdout,"struct %s",
		(node->name?node->name:""));
	dumpdimensions(node);
	fprintf(stdout," &%lx",(unsigned long)node);
	fprintf(stdout,"\n");
	for(n=0;n<oclistlength(node->subnodes);n++) {
	    dumpocnode1((OCnode*)oclistget(node->subnodes,n),depth+1);
	}
    } break;

    case OC_Sequence: {
        fprintf(stdout,"[%2d]%s ",depth,dent(depth));
	fprintf(stdout,"sequence %s",
		(node->name?node->name:""));
	dumpdimensions(node);
	fprintf(stdout," &%lx",(unsigned long)node);
	fprintf(stdout,"\n");
	for(n=0;n<oclistlength(node->subnodes);n++) {
	    dumpocnode1((OCnode*)oclistget(node->subnodes,n),depth+1);
	}
    } break;

    case OC_Grid: {
	unsigned int i;
        fprintf(stdout,"[%2d]%s ",depth,dent(depth));
	fprintf(stdout,"grid %s",
		(node->name?node->name:""));
	dumpdimensions(node);
	fprintf(stdout," &%lx",(unsigned long)node);
	fprintf(stdout,"\n");
	fprintf(stdout,"%sarray:\n",dent2(depth+1));
	dumpocnode1((OCnode*)oclistget(node->subnodes,0),depth+2);
	fprintf(stdout,"%smaps:\n",dent2(depth+1));
	for(i=1;i<oclistlength(node->subnodes);i++) {
	    dumpocnode1((OCnode*)oclistget(node->subnodes,i),depth+2);
	}
    } break;

    case OC_Attribute: {
        fprintf(stdout,"[%2d]%s ",depth,dent(depth));
	if(node->name == NULL) OCPANIC("Attribute without name");
	fprintf(stdout,"%s %s",octypetostring(node->etype),node->name);
	for(n=0;n<oclistlength(node->att.values);n++) {
	    char* value = (char*)oclistget(node->att.values,n);
	    if(n > 0) fprintf(stdout,",");
	    fprintf(stdout," %s",value);
	}
	fprintf(stdout," &%lx",(unsigned long)node);
	fprintf(stdout,"\n");
    } break;

    case OC_Attributeset: {
        fprintf(stdout,"[%2d]%s ",depth,dent(depth));
	fprintf(stdout,"%s:\n",node->name?node->name:"Attributes");
	for(n=0;n<oclistlength(node->subnodes);n++) {
	    dumpocnode1((OCnode*)oclistget(node->subnodes,n),depth+1);
	}
    } break;

    default:
	OCPANIC1("encountered unexpected node type: %x",node->octype);
    }

    if(node->attributes != NULL) {
	unsigned int i;
	for(i=0;i<oclistlength(node->attributes);i++) {
	    OCattribute* att = (OCattribute*)oclistget(node->attributes,i);
	    fprintf(stdout,"%s[%s=",dent2(depth+2),att->name);
	    if(att->nvalues == 0)
		OCPANIC("Attribute.nvalues == 0");
	    if(att->nvalues == 1) {
		dumpattvalue(att->etype,att->values,0);
	    } else {
		unsigned int j;
	        fprintf(stdout,"{");
		for(j=0;j<att->nvalues;j++) {
		    if(j>0) fprintf(stdout,", ");
		    dumpattvalue(att->etype,att->values,j);
		}
	        fprintf(stdout,"}");
	    }
	    fprintf(stdout,"]\n");
	}
    }
}
Beispiel #2
0
static void
ocdumpmemdata1(OCmemdata* md, OCbytes* buf, int depth)
{
    OCmemdata** mdp;
    unsigned int i;
    char tmp[1024];

    switch ((OCtype)md->octype) {

    case OC_Sequence:
    case OC_Grid:    
    case OC_Structure:
    case OC_Dataset:
	sprintf(tmp,"%s%s/%s (%lu) {\n",dent(depth),
		octypetostring((OCtype)md->octype),
		ocmodestr(md->mode),
		(unsigned long)md->count);
	ocbytescat(buf,tmp);
	mdp = (OCmemdata**)md->data.data;
	switch ((OCmode)md->mode) {
        case Fieldmode:
	    for(i=0;i<md->count;i++) {
	        sprintf(tmp,"%s[%u]",dent(depth+1),i);
	        ocbytescat(buf,tmp);
	        ocdumpmemdata1(mdp[i],buf,depth+1);
	    }	    
	    break;

	case Dimmode:
	    for(i=0;i<md->count;i++) {
	        sprintf(tmp,"%s(%u)",dent(depth+1),i);
	        ocbytescat(buf,tmp);
	        ocdumpmemdata1(mdp[i],buf,depth+1);
	    }	    
	    break;

	case Recordmode:
	    for(i=0;i<md->count;i++) {
	        sprintf(tmp,"%s{%u}",dent(depth+1),i);
	        ocbytescat(buf,tmp);
	        ocdumpmemdata1(mdp[i],buf,depth+1);
	    }
	    break;

        default: break;
	}
	sprintf(tmp,"%s}\n",dent(depth));
	break;
	
    case OC_Primitive: {
	OCtype etype = (OCtype)md->etype;
        char* data = md->data.data;
	sprintf(tmp,"%s%s/%s (%lu) {",dent(depth),
		octypetostring(etype),ocmodestr(md->mode),(unsigned long)md->count);
	ocbytescat(buf,tmp);
        for(i=0;i<md->count;i++) {
	    char* p = data + (octypesize(etype)*i);
	    ocbytescat(buf," ");
	    octypeprint(etype,tmp,sizeof(tmp),(void*)p);
	    ocbytescat(buf,tmp);
	}
        ocbytescat(buf," }\n");
    } break;

    default: break;
    }
}