char* dumpprojection1(NCprojection* p) { int i; NCbytes* buf; char* pstring; if(p == NULL) return nulldup(""); buf = ncbytesnew(); for(i=0;i<nclistlength(p->segments);i++) { NCsegment* segment = (NCsegment*)nclistget(p->segments,i); char tmp[1024]; snprintf(tmp,sizeof(tmp),"%s%s/%lu", (i > 0?".":""), (segment->segment?segment->segment:"<unknown>"), (unsigned long)segment->slicerank); ncbytescat(buf,tmp); if(segment->slicesdefined) ncbytescat(buf,dumpslices(segment->slices,segment->slicerank)); else ncbytescat(buf,"[-]"); } if(iswholeprojection(p)) ncbytescat(buf,"*"); ncbytescat(buf,"("); if(p->leaf != NULL) ncbytescat(buf,p->leaf->name); ncbytescat(buf,")"); pstring = ncbytesdup(buf); ncbytesfree(buf); return pstring; }
char* dumpcachenode(NCcachenode* node) { char* result = NULL; char tmp[8192]; int i; NCbytes* buf; if(node == NULL) return strdup("cachenode{null}"); buf = ncbytesnew(); snprintf(tmp,sizeof(tmp),"cachenode%s(%lx){size=%lu; constraint=%s; vars=", node->prefetch?"*":"", (unsigned long)node, (unsigned long)node->xdrsize, buildconstraintstring3(node->constraint)); ncbytescat(buf,tmp); if(nclistlength(node->vars)==0) ncbytescat(buf,"null"); else for(i=0;i<nclistlength(node->vars);i++) { CDFnode* var = (CDFnode*)nclistget(node->vars,i); if(i > 0) ncbytescat(buf,","); ncbytescat(buf,makesimplepathstring3(var)); } ncbytescat(buf,"}"); result = ncbytesdup(buf); ncbytesfree(buf); return result; }
char* dumpcache(NCcache* cache) { char* result = NULL; char tmp[8192]; int i; NCbytes* buf; if(cache == NULL) return strdup("cache{null}"); buf = ncbytesnew(); snprintf(tmp,sizeof(tmp),"cache{limit=%lu; size=%lu;\n", (unsigned long)cache->cachelimit, (unsigned long)cache->cachesize); ncbytescat(buf,tmp); if(cache->prefetch) { ncbytescat(buf,"\tprefetch="); ncbytescat(buf,dumpcachenode(cache->prefetch)); ncbytescat(buf,"\n"); } if(nclistlength(cache->nodes) > 0) { for(i=0;i<nclistlength(cache->nodes);i++) { NCcachenode* node = (NCcachenode*)nclistget(cache->nodes,i); ncbytescat(buf,"\t"); ncbytescat(buf,dumpcachenode(node)); ncbytescat(buf,"\n"); } } ncbytescat(buf,"}"); result = ncbytesdup(buf); ncbytesfree(buf); return result; }
char* buildconstraintstring(DCEconstraint* constraints) { NCbytes* buf = ncbytesnew(); char* result = NULL; dcetobuffer((DCEnode*)constraints,buf); result = ncbytesdup(buf); ncbytesfree(buf); return result; }
char* buildselectionstring(NClist* selections) { NCbytes* buf = ncbytesnew(); char* sstring; dcelisttobuffer(selections,buf,","); sstring = ncbytesdup(buf); ncbytesfree(buf); return sstring; }
char* dumpvisible(CDFnode* root) { NCbytes* buf = ncbytesnew(); char* result; dumptreer(root,buf,0,1); result = ncbytesdup(buf); ncbytesfree(buf); return result; }
char* buildprojectionstring(NClist* projections) { char* pstring; NCbytes* buf = ncbytesnew(); dcelisttobuffer(projections,buf,","); pstring = ncbytesdup(buf); ncbytesfree(buf); return pstring; }
char* dumpselection(NCselection* sel) { NCbytes* buf = ncbytesnew(); NCbytes* segbuf = ncbytesnew(); char* sstring; NClist* segments = NULL; int j; if(sel == NULL) return nulldup(""); segments = sel->lhs->var->segments; ncbytescat(buf,"&"); tostringncsegments(segments,segbuf); ncbytescat(buf,ncbytescontents(segbuf)); ncbytescat(buf,opstrings[sel->operator]); ncbytescat(buf,"{"); for(j=0;j<nclistlength(sel->rhs);j++) { NCvalue* value = (NCvalue*)nclistget(sel->rhs,j); NCconstant* con = value->constant; char tmp[64]; if(j > 0) ncbytescat(buf,","); switch (value->discrim) { case NS_STR: ncbytescat(buf,con->text); break; case NS_CONST: switch (con->discrim) { case NS_INT: snprintf(tmp,sizeof(tmp),"%lld",con->intvalue); ncbytescat(buf,tmp); break; case NS_FLOAT: snprintf(tmp,sizeof(tmp),"%g",con->floatvalue); ncbytescat(buf,tmp); break; default: PANIC1("unexpected discriminator %d",(int)con->discrim); } break; case NS_VAR: segments = value->var->segments; ncbytesclear(segbuf); tostringncsegments(segments,segbuf); ncbytescat(buf,ncbytescontents(segbuf)); break; default: PANIC1("unexpected discriminator %d",(int)value->discrim); } } ncbytescat(buf,"}"); sstring = ncbytesdup(buf); ncbytesfree(buf); ncbytesfree(segbuf); return sstring; }
char* dumpselection1(NCselection* sel) { NCbytes* buf = ncbytesnew(); char* sstring; NClist* path = NULL; char* pathstring = NULL; int j; if(sel == NULL) return nulldup(""); path = sel->path; ncbytescat(buf,"&"); if(path == NULL) pathstring = makecdfpathstring3(sel->node,"."); else pathstring = simplepathstring3(path,"."); ncbytescat(buf,pathstring); efree(pathstring); ncbytescat(buf,opstrings[sel->operator]); ncbytescat(buf,"{"); for(j=0;j<nclistlength(sel->values);j++) { NCvalue* value = (NCvalue*)nclistget(sel->values,j); char tmp[64]; if(j > 0) ncbytescat(buf,","); switch (value->kind) { case ST_STR: ncbytescat(buf,value->value.text); break; case ST_INT: snprintf(tmp,sizeof(tmp),"%lld",value->value.intvalue); ncbytescat(buf,tmp); break; case ST_FLOAT: snprintf(tmp,sizeof(tmp),"%g",value->value.floatvalue); ncbytescat(buf,tmp); break; case ST_VAR: path = value->value.var.path; if(path == NULL) pathstring = makecdfpathstring3(value->value.var.node,"."); else pathstring = simplepathstring3(path,"."); ncbytescat(buf,pathstring); efree(pathstring); break; default: PANIC1("unexpected tag: %d",(int)value->kind); } } ncbytescat(buf,"}"); sstring = ncbytesdup(buf); ncbytesfree(buf); return sstring; }
char* dumpsegment(NCsegment* segment) { NCbytes* buf; char* result; if(segment == NULL) return nulldup("(nullsegment)"); buf = ncbytesnew(); ncbytescat(buf,(segment->segment?segment->segment:"(null)")); if(!segment->slicesdefined) ncbytescat(buf,dumpslices(segment->slices,segment->slicerank)); result = ncbytesdup(buf); ncbytesfree(buf); return result; }
char* dumpsegments(NClist* segments) { int i; NCbytes* buf = ncbytesnew(); char* sstring; if(nclistlength(segments) == 0) return nulldup(""); for(i=0;i<nclistlength(segments);i++) { NCsegment* seg = (NCsegment*)nclistget(segments,i); ncbytescat(buf,dumpsegment(seg)); } sstring = ncbytesdup(buf); ncbytesfree(buf); return sstring; }
/* Convert an NCprojection instance into a string that can be used with the url */ char* dumpprojections(NClist* projections) { int i; NCbytes* buf = ncbytesnew(); char* pstring; for(i=0;i<nclistlength(projections);i++) { NCprojection* p = (NCprojection*)nclistget(projections,i); if(i > 0) ncbytescat(buf,","); ncbytescat(buf,dumpprojection1(p)); } pstring = ncbytesdup(buf); ncbytesfree(buf); return pstring; }
char* dumpslices(DCEslice* slice, unsigned int rank) { int i; NCbytes* buf; char* result = NULL; buf = ncbytesnew(); for(i=0;i<rank;i++,slice++) { ncbytescat(buf,dumpslice(slice)); } result = ncbytesdup(buf); ncbytesfree(buf); return result; }
char* dumppath(CDFnode* leaf) { NClist* path = nclistnew(); NCbytes* buf = ncbytesnew(); char* result; int i; if(leaf == NULL) return nulldup(""); collectnodepath3(leaf,path,!WITHDATASET); for(i=0;i<nclistlength(path);i++) { CDFnode* node = (CDFnode*)nclistget(path,i); if(i > 0) ncbytescat(buf,"."); ncbytescat(buf,node->name); } result = ncbytesdup(buf); ncbytesfree(buf); nclistfree(path); return result; }
char* dumpconstraint(NCconstraint* con) { NCbytes* buf = ncbytesnew(); char* result = NULL; if(nclistlength(con->projections)==0 && nclistlength(con->selections)==0) goto done; if(nclistlength(con->projections) > 0) { char* pstring = dumpprojections(con->projections); ncbytescat(buf,pstring); efree(pstring); } if(nclistlength(con->selections) > 0) { char* sstring = dumpselections(con->selections); ncbytescat(buf,sstring); efree(sstring); } done: result = ncbytesdup(buf); ncbytesfree(buf); return result; }
int daplex(YYSTYPE* lvalp, DAPparsestate* state) { DAPlexstate* lexstate = state->lexstate; int token; int c; unsigned int i; char* p; char* tmp; YYSTYPE lval = NULL; token = 0; ncbytesclear(lexstate->yytext); /* invariant: p always points to current char */ for(p=lexstate->next;token==0&&(c=*p);p++) { if(c == '\n') { lexstate->lineno++; } else if(c <= ' ' || c == '\177') { /* whitespace: ignore */ } else if(c == '#') { /* single line comment */ while((c=*(++p))) {if(c == '\n') break;} } else if(strchr(lexstate->worddelims,c) != NULL) { /* don't put in lexstate->yytext to avoid memory leak */ token = c; } else if(c == '"') { int more = 1; /* We have a string token; will be reported as WORD_STRING */ while(more && (c=*(++p))) { if(c == '"') { more = 0; continue; } #ifdef DAP2ENCODE if(c == '\\') { /* Resolve spec ambiguity about handling of \c: 1. !KEEPSLASH: convert \c to c for any character c 2. KEEPSLASH: convert \c to \c for any character c; that is, keep the backslash. It is clear that the problem being addressed was \". But it is unclear what to to do about \n: convert to Ascii LF or leave as \n. This code will leave as \n and assume higher levels of code will address the issue. */ #ifdef KEEPSLASH dapaddyytext(lexstate,c); #endif c=*(++p); if(c == '\0') more = 0; } #else /*Non-standard*/ switch (c) { case '\\': c=*(++p); switch (c) { case 'r': c = '\r'; break; case 'n': c = '\n'; break; case 'f': c = '\f'; break; case 't': c = '\t'; break; case 'x': { int d1,d2; c = '?'; ++p; d1 = tohex(*p++); if(d1 < 0) { daperror(state,"Illegal \\xDD in TOKEN_STRING"); } else { d2 = tohex(*p++); if(d2 < 0) { daperror(state,"Illegal \\xDD in TOKEN_STRING"); } else { c=(((unsigned int)d1)<<4) | (unsigned int)d2; } } } break; default: break; } break; default: break; } #endif /*!DAP2ENCODE*/ if(more) dapaddyytext(lexstate,c); } token=WORD_STRING; } else if(strchr(lexstate->wordchars1,c) != NULL) { int isdatamark = 0; /* we have a WORD_WORD */ dapaddyytext(lexstate,c); while((c=*(++p))) { #ifdef URLCVT if(c == '%' && p[1] != 0 && p[2] != 0 && strchr(hexdigits,p[1]) != NULL && strchr(hexdigits,p[2]) != NULL) { int d1,d2; d1 = tohex(p[1]); d2 = tohex(p[2]); if(d1 >= 0 || d2 >= 0) { c=(((unsigned int)d1)<<4) | (unsigned int)d2; p+=2; } } else { if(strchr(lexstate->wordcharsn,c) == NULL) {p--; break;} } dapaddyytext(lexstate,c); #else if(strchr(lexstate->wordcharsn,c) == NULL) {p--; break;} dapaddyytext(lexstate,c); #endif } /* Special check for Data: */ tmp = ncbytescontents(lexstate->yytext); if(strcmp(tmp,"Data")==0 && *p == ':') { dapaddyytext(lexstate,*p); p++; if(p[0] == '\n') { token = SCAN_DATA; isdatamark = 1; p++; } else if(p[0] == '\r' && p[1] == '\n') { token = SCAN_DATA; isdatamark = 1; p+=2; } } if(!isdatamark) { /* check for keyword */ token=WORD_WORD; /* assume */ for(i=0;;i++) { if(keywords[i] == NULL) break; if(strcasecmp(keywords[i],tmp)==0) { token=keytokens[i]; break; } } } } else { /* illegal */ } } lexstate->next = p; strncpy(lexstate->lasttokentext,ncbytescontents(lexstate->yytext),MAX_TOKEN_LENGTH); lexstate->lasttoken = token; if(ocdebug >= 2) dumptoken(lexstate); /*Put return value onto Bison stack*/ if(ncbyteslength(lexstate->yytext) == 0) lval = NULL; else { lval = ncbytesdup(lexstate->yytext); nclistpush(lexstate->reclaim,(void*)lval); } if(lvalp) *lvalp = lval; return token; /* Return the type of the token. */ }
int dcelex(YYSTYPE* lvalp, DCEparsestate* state) { DCElexstate* lexstate = state->lexstate; int token; int c; int len; char* p=NULL; token = 0; ncbytesclear(lexstate->yytext); ncbytesnull(lexstate->yytext); p=lexstate->next; while(token == 0 && (c=*p)) { if(c <= ' ' || c >= '\177') {p++; continue;} if(c == '"') { int more = 1; ceaddyytext(lexstate,c); /* We have a SCAN_STRINGCONST */ while(more && (c=*(++p))) { switch (c) { case '"': p++; more=0; break; case '\\': c=*(++p); switch (c) { case 'r': c = '\r'; break; case 'n': c = '\n'; break; case 'f': c = '\f'; break; case 't': c = '\t'; break; case 'x': { int d1,d2; c = '?'; ++p; d1 = tohex(*p++); if(d1 < 0) { dceerror(state,"Illegal \\xDD in SCAN_STRING"); } else { d2 = tohex(*p++); if(d2 < 0) { dceerror(state,"Illegal \\xDD in SCAN_STRING"); } else { c=(((unsigned int)d1)<<4) | (unsigned int)d2; } } } break; default: break; } break; default: break; } ceaddyytext(lexstate,c); } token=SCAN_STRINGCONST; } else if(strchr(numchars1,c) != NULL) { /* we might have a SCAN_NUMBERCONST */ int isnumber = 0; char* yytext; char* endpoint; ceaddyytext(lexstate,c); for(p++;(c=*p);p++) { if(strchr(numcharsn,c) == NULL) break; ceaddyytext(lexstate,c); } /* See if this is a number */ ncbytesnull(lexstate->yytext); yytext = ncbytescontents(lexstate->yytext); (void)strtoll(yytext,&endpoint,10); if(*yytext != '\0' && *endpoint == '\0') isnumber = 1; else { (void)strtod(yytext,&endpoint); if(*yytext != '\0' && *endpoint == '\0') isnumber = 1; /* maybe */ } /* A number followed by an id char is assumed to just be a funny id */ if(isnumber && (*p == '\0' || strchr(wordcharsn,*p) == NULL)) { token = SCAN_NUMBERCONST; } else { /* Now, if the funny word has a "." in it, we have to back up to that dot */ char* dotpoint = strchr(yytext,'.'); if(dotpoint != NULL) { p = dotpoint; *dotpoint = '\0'; } token = SCAN_WORD; } } else if(strchr(wordchars1,c) != NULL) { /* we have a SCAN_WORD */ ceaddyytext(lexstate,c); for(p++;(c=*p);p++) { if(strchr(wordcharsn,c) == NULL) break; ceaddyytext(lexstate,c); } token=SCAN_WORD; } else { /* we have a single char token */ token = c; ceaddyytext(lexstate,c); p++; } } lexstate->next = p; len = ncbyteslength(lexstate->yytext); if(len > MAX_TOKEN_LENGTH) len = MAX_TOKEN_LENGTH; strncpy(lexstate->lasttokentext,ncbytescontents(lexstate->yytext),len); lexstate->lasttokentext[len] = '\0'; lexstate->lasttoken = token; if(dcedebug) dumptoken(lexstate); /*Put return value onto Bison stack*/ if(ncbyteslength(lexstate->yytext) == 0) *lvalp = NULL; else { *lvalp = ncbytesdup(lexstate->yytext); nclistpush(lexstate->reclaim,(void*)*lvalp); } return token; }
/* Provide detailed data on a CDFnode */ char* dumpnode(CDFnode* node) { NCbytes* buf = ncbytesnew(); char* result; int i; char* nctype = NULL; char* primtype = NULL; char tmp[1024]; switch (node->nctype) { case NC_Dataset: nctype = "Dataset"; break; case NC_Sequence: nctype = "Sequence"; break; case NC_Structure: nctype = "Structure"; break; case NC_Grid: nctype = "Grid"; break; case NC_Primitive: switch (node->etype) { case NC_BYTE: primtype = "byte"; break; case NC_CHAR: primtype = "char"; break; case NC_SHORT: primtype = "short"; break; case NC_INT: primtype = "int"; break; case NC_FLOAT: primtype = "float"; break; case NC_DOUBLE: primtype = "double"; break; case NC_UBYTE: primtype = "ubyte"; break; case NC_USHORT: primtype = "ushort"; break; case NC_UINT: primtype = "uint"; break; case NC_INT64: primtype = "int64"; break; case NC_UINT64: primtype = "uint64"; break; case NC_STRING: primtype = "string"; break; default: break; } break; default: break; } snprintf(tmp,sizeof(tmp),"%s %s {\n", (nctype?nctype:primtype),node->name); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"dds=%lx\n",(unsigned long)node->dds); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"container=%s\n", (node->container?node->container->name:"null")); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"root=%s\n", (node->root?node->root->name:"null")); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"ncbasename=%s\n",node->ncbasename); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"ncfullname=%s\n",node->ncfullname); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"|subnodes|=%d\n",nclistlength(node->subnodes)); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"externaltype=%d\n",node->externaltype); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"ncid=%d\n",node->ncid); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"maxstringlength=%ld\n",node->maxstringlength); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"sequencelimit=%ld\n",node->sequencelimit); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"usesequence=%d\n",node->usesequence); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"elided=%d\n",node->elided); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"visible=%d\n",node->visible); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"attachment=%s\n", (node->attachment?node->attachment->name:"null")); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"rank=%u\n",nclistlength(node->array.dimensions)); ncbytescat(buf,tmp); for(i=0;i<nclistlength(node->array.dimensions);i++) { CDFnode* dim = (CDFnode*)nclistget(node->array.dimensions,i); snprintf(tmp,sizeof(tmp),"dims[%d]={\n",i); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp)," name=%s\n",dim->name); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp)," dimflags=%u\n", (unsigned int)dim->dim.dimflags); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp)," declsize=%lu\n", (unsigned long)dim->dim.declsize); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp)," declsize0=%lu\n", (unsigned long)dim->dim.declsize0); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp)," }\n"); ncbytescat(buf,tmp); } result = ncbytesdup(buf); ncbytesfree(buf); return result; }