static void convert_FrameKit_facet(FrFrame *frame,FrSymbol *slot, FrList *facetspec,bool views) { FrSymbol *facet = (FrSymbol *)facetspec->first() ; if (facet && facet->symbolp()) { facetspec = facetspec->rest() ; if (views) { FrObject *first = facetspec->first() ; if (first && first->consp()) facetspec = (FrList *)first ; first = facetspec->first() ; if (first && first->symbolp() && (FrSymbol *)first == symbolCOMMON) facetspec = facetspec->rest() ; else { bad_format("view other than COMMON encountered") ; facetspec = nullptr ; } } if (facetspec) frame->addFillers(slot,facet,facetspec) ; else frame->createSlot(slot) ; } else bad_format(errmsg_facet_symbol) ; }
void dimension::read(const char *s) { int a, b, c; bool negative = false; // Minus sign first while(isspace(*s)) s++; if(*s == '-') { negative = true; s++; } // Now a number while(isspace(*s)) s++; if(!isdigit(*s)) THROW_OR_RETURN_VOID( bad_format() ); a = *s++ - '0'; while(isdigit(*s)) a = 10*a + (*s++ - '0'); if(*s == '.') { // We have a number in decimal format s++; b = 1; while(isdigit(*s)) { a = 10*a + (*s++ - '0'); b = 10*b; } read_units(s); n = negative ? -a : a; d = b; } else { // Look for a fractional part while(isspace(*s)) s++; if(isdigit(*s)) { // Found a fractional part b = *s++ - '0'; while(isdigit(*s)) b = 10*b + (*s++ - '0'); while(isspace(*s)) s++; if(*s++ != '/') THROW_OR_RETURN_VOID( bad_format() ); while(isspace(*s)) s++; if(!isdigit(*s)) THROW_OR_RETURN_VOID( bad_format() ); c = *s++ - '0'; while(isdigit(*s)) c = 10*c + (*s++ - '0'); read_units(s); n = a * c + b; d = c; if(negative) n = -n; } else if(*s == '/') { // Just a fractional part s++; while(isspace(*s)) s++; if(!isdigit(*s)) THROW_OR_RETURN_VOID( bad_format() ); c = *s++ - '0'; while(isdigit(*s)) c = 10*c + (*s++ - '0'); read_units(s); n = negative ? -a : a; d = c; } else { // Just an integer read_units(s); n = negative ? -a : a; d = 1; } } reduce(); }
void dimension::read_units(const char *s) { while(isspace(*s)) s++; const char *t = s; while(*t != '\0' && !isspace(*t)) t++; map<string, units>::const_iterator i = unit_names.find(string(s,t)); if(i != unit_names.end()) u = (*i).second; else THROW_OR_RETURN_VOID( bad_format() ); }
static void convert_FrameKit_slot(FrFrame *frame,const FrList *slotspec, bool views) { if (slotspec && slotspec->consp()) { FrSymbol *slot = (FrSymbol *)slotspec->first() ; if (slot && slot->symbolp()) { slotspec = slotspec->rest() ; while (slotspec) { convert_FrameKit_facet(frame,slot,(FrList *)slotspec->first(), views) ; slotspec = slotspec->rest() ; } } else bad_format(errmsg_slot_symbol) ; } else bad_format("slotspec must be a list") ; }
FrFrame *FrameKit_to_FramepaC(const FrList *framespec, bool warn) { FrSymbol *makefr = (FrSymbol*)framespec->first() ; if (makefr && makefr->symbolp() && *makefr == stringMAKEFR_OLD) return convert_FrameKit_frame(framespec->rest(),false) ; else if (makefr && makefr->symbolp() && *makefr == stringMAKEFRAME) return convert_FrameKit_frame(framespec->rest(),true) ; else { if (warn) bad_format("FrameKit frame not converted") ; return 0 ; } }
static FrFrame *convert_FrameKit_frame(const FrList *framespec,bool views) { FrFrame *frame ; FrSymbol *framename = (FrSymbol*)framespec->first() ; if (framename && framename->symbolp()) { frame = read_as_VFrame ? framename->createVFrame() : framename->createFrame() ; framespec = framespec->rest() ; while (framespec) { convert_FrameKit_slot(frame,(const FrList *)framespec->first(),views) ; framespec = framespec->rest() ; } } else { bad_format(errmsg_frame_name) ; frame = nullptr ; } return frame ; }
int rrd_xport_format_addprints(int flags,stringbuffer_t *buffer,image_desc_t *im) { /* initialize buffer */ stringbuffer_t prints= {1024,0,NULL,NULL}; stringbuffer_t rules= {1024,0,NULL,NULL}; stringbuffer_t gprints= {4096,0,NULL,NULL}; char buf[256]; char dbuf[1024]; char* val; char* timefmt=NULL; if (im->xlab_user.minsec!=-1) { timefmt=im->xlab_user.stst; } /* define some other stuff based on flags */ int json=0; if (flags &1) { json=1; } // int showtime=0; if (flags &2) { showtime=1;} -> unused here // int enumds=0; if (flags &4) { enumds=1;} -> unused here /* define some values */ time_t now = time(NULL); struct tm tmvdef; localtime_r(&now, &tmvdef); double printval=DNAN; /* iterate over all fields and start the work writing to the correct buffers */ for (long i = 0; i < im->gdes_c; i++) { long vidx = im->gdes[i].vidx; char* entry; switch (im->gdes[i].gf) { case GF_PRINT: case GF_GPRINT: { /* PRINT and GPRINT can now print VDEF generated values. * There's no need to do any calculations on them as these * calculations were already made. * we do not support the depreciated version here */ printval=DNAN; /* decide to which buffer we print to*/ stringbuffer_t *usebuffer=&gprints; char* usetag="gprint"; if (im->gdes[i].gf==GF_PRINT) { usebuffer=&prints; usetag="print"; } /* get the value */ if (im->gdes[vidx].gf == GF_VDEF) { /* simply use vals */ printval = im->gdes[vidx].vf.val; localtime_r(&im->gdes[vidx].vf.when, &tmvdef); } else { int max_ii = ((im->gdes[vidx].end - im->gdes[vidx].start) / im->gdes[vidx].step * im->gdes[vidx].ds_cnt); printval = DNAN; long validsteps = 0; for (long ii = im->gdes[vidx].ds; ii < max_ii; ii += im->gdes[vidx].ds_cnt) { if (!finite(im->gdes[vidx].data[ii])) continue; if (isnan(printval)) { printval = im->gdes[vidx].data[ii]; validsteps++; continue; } switch (im->gdes[i].cf) { case CF_HWPREDICT: case CF_MHWPREDICT: case CF_DEVPREDICT: case CF_DEVSEASONAL: case CF_SEASONAL: case CF_AVERAGE: validsteps++; printval += im->gdes[vidx].data[ii]; break; case CF_MINIMUM: printval = min(printval, im->gdes[vidx].data[ii]); break; case CF_FAILURES: case CF_MAXIMUM: printval = max(printval, im->gdes[vidx].data[ii]); break; case CF_LAST: printval = im->gdes[vidx].data[ii]; } } if (im->gdes[i].cf == CF_AVERAGE || im->gdes[i].cf > CF_LAST) { if (validsteps > 1) { printval = (printval / validsteps); } } } /* we handle PRINT and GPRINT the same - format now*/ if (im->gdes[i].strftm) { if (im->gdes[vidx].vf.never == 1) { time_clean(buf, im->gdes[i].format); } else { strftime(dbuf,sizeof(dbuf), im->gdes[i].format, &tmvdef); } } else if (bad_format(im->gdes[i].format)) { rrd_set_error ("bad format for PRINT in \"%s'", im->gdes[i].format); return -1; } else { snprintf(dbuf,sizeof(dbuf), im->gdes[i].format, printval,""); } /* print */ if (json) { escapeJSON(dbuf,sizeof(dbuf)); snprintf(buf,sizeof(buf),",\n { \"%s\": \"%s\" }",usetag,dbuf); } else { snprintf(buf,sizeof(buf)," <%s>%s</%s>\n",usetag,dbuf,usetag); } addToBuffer(usebuffer,buf,0); } break; case GF_COMMENT: if (json) { strncpy(dbuf,im->gdes[i].legend,sizeof(dbuf)); escapeJSON(dbuf,sizeof(dbuf)); snprintf(buf,sizeof(buf),",\n { \"comment\": \"%s\" }",dbuf); } else { snprintf(buf,sizeof(buf)," <comment>%s</comment>\n",im->gdes[i].legend); } addToBuffer(&gprints,buf,0); break; case GF_LINE: entry = im->gdes[i].legend; /* I do not know why the legend is "spaced", but let us skip it */ while(isspace(*entry)) { entry++; } if (json) { snprintf(buf,sizeof(buf),",\n { \"line\": \"%s\" }",entry); } else { snprintf(buf,sizeof(buf)," <line>%s</line>\n",entry); } addToBuffer(&gprints,buf,0); break; case GF_AREA: if (json) { snprintf(buf,sizeof(buf),",\n { \"area\": \"%s\" }",im->gdes[i].legend); } else { snprintf(buf,sizeof(buf)," <area>%s</area>\n",im->gdes[i].legend); } addToBuffer(&gprints,buf,0); break; case GF_STACK: if (json) { snprintf(buf,sizeof(buf),",\n { \"stack\": \"%s\" }",im->gdes[i].legend); } else { snprintf(buf,sizeof(buf)," <stack>%s</stack>\n",im->gdes[i].legend); } addToBuffer(&gprints,buf,0); break; case GF_TEXTALIGN: val=""; switch (im->gdes[i].txtalign) { case TXA_LEFT: val="left"; break; case TXA_RIGHT: val="right"; break; case TXA_CENTER: val="center"; break; case TXA_JUSTIFIED: val="justified"; break; } if (json) { snprintf(buf,sizeof(buf),",\n { \"align\": \"%s\" }",val); } else { snprintf(buf,sizeof(buf)," <align>%s</align>\n",val); } addToBuffer(&gprints,buf,0); break; case GF_HRULE: /* This does not work as expected - Tobi please help!!! */ snprintf(dbuf,sizeof(dbuf),"%0.10e",im->gdes[i].vf.val); /* and output it */ if (json) { snprintf(buf,sizeof(buf),",\n { \"hrule\": \"%s\" }",dbuf); } else { snprintf(buf,sizeof(buf)," <hrule>%s</hrule>\n",dbuf); } addToBuffer(&rules,buf,0); break; case GF_VRULE: if (timefmt) { struct tm loc; localtime_r(&im->gdes[i].xrule,&loc); strftime(dbuf,254,timefmt,&loc); } else { snprintf(dbuf,254,"%lld",(long long int)im->gdes[i].vf.when); } /* and output it */ if (json) { snprintf(buf,sizeof(buf),",\n { \"vrule\": \"%s\" }",dbuf); } else { snprintf(buf,sizeof(buf)," <vrule>%s</vrule>\n",dbuf); } addToBuffer(&rules,buf,0); break; default: break; } } /* now add prints */ if (prints.len) { if (json) { snprintf(buf,sizeof(buf)," \"%s\": [\n","prints"); addToBuffer(buffer,buf,0); addToBuffer(buffer,(char*)prints.data+2,prints.len-2); addToBuffer(buffer,"\n ],\n",0); } else { snprintf(buf,sizeof(buf)," <%s>\n", "prints"); addToBuffer(buffer,buf,0); addToBuffer(buffer,(char*)prints.data,prints.len); snprintf(buf,sizeof(buf)," </%s>\n", "prints"); addToBuffer(buffer,buf,0); } free(prints.data); } /* now add gprints */ if (gprints.len) { if (json) { snprintf(buf,sizeof(buf)," \"%s\": [\n","gprints"); addToBuffer(buffer,buf,0); addToBuffer(buffer,(char*)gprints.data+2,gprints.len-2); addToBuffer(buffer,"\n ],\n",0); } else { snprintf(buf,sizeof(buf)," <%s>\n", "gprints"); addToBuffer(buffer,buf,0); addToBuffer(buffer,(char*)gprints.data,gprints.len); snprintf(buf,sizeof(buf)," </%s>\n", "gprints"); addToBuffer(buffer,buf,0); } free(gprints.data); } /* now add rules */ if (rules.len) { if (json) { snprintf(buf,sizeof(buf)," \"%s\": [\n","rules"); addToBuffer(buffer,buf,0); addToBuffer(buffer,(char*)rules.data+2,rules.len-2); addToBuffer(buffer,"\n ],\n",0); } else { snprintf(buf,sizeof(buf)," <%s>\n", "rules"); addToBuffer(buffer,buf,0); addToBuffer(buffer,(char*)rules.data,rules.len); snprintf(buf,sizeof(buf)," </%s>\n", "rules"); addToBuffer(buffer,buf,0); } free(rules.data); } /* and return */ return 0; }