- switch(im->gdes[i].gf){
- case GF_PRINT:
- prlines++;
- if(((*prdata) = rrd_realloc((*prdata),prlines*sizeof(char *)))==NULL){
- rrd_set_error("realloc prdata");
- return 0;
- }
- 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.
- */
- vidx = im->gdes[i].vidx;
- if (im->gdes[vidx].gf==GF_VDEF) { /* simply use vals */
- printval = im->gdes[vidx].vf.val;
- printtime = im->gdes[vidx].vf.when;
- } else { /* need to calculate max,min,avg etcetera */
- max_ii =((im->gdes[vidx].end
- - im->gdes[vidx].start)
- / im->gdes[vidx].step
- * im->gdes[vidx].ds_cnt);
- printval = DNAN;
- validsteps = 0;
- for( 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_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);
- }
- }
- } /* prepare printval */
-
- if (!strcmp(im->gdes[i].format,"%c")) { /* VDEF time print */
- char ctime_buf[128]; /* PS: for ctime_r, must be >= 26 chars */
- int iii=0;
- ctime_r(&printtime,ctime_buf);
- while(isprint(ctime_buf[iii])){iii++;}
- ctime_buf[iii]='\0';
- if (im->gdes[i].gf == GF_PRINT){
- (*prdata)[prlines-2] = malloc((FMT_LEG_LEN+2)*sizeof(char));
- sprintf((*prdata)[prlines-2],"%s (%lu)",ctime_buf,printtime);
- (*prdata)[prlines-1] = NULL;
- } else {
- sprintf(im->gdes[i].legend,"%s (%lu)",ctime_buf,printtime);
- graphelement = 1;
- }
- } else {
- if ((percent_s = strstr(im->gdes[i].format,"%S")) != NULL) {
- /* Magfact is set to -1 upon entry to print_calc. If it
- * is still less than 0, then we need to run auto_scale.
- * Otherwise, put the value into the correct units. If
- * the value is 0, then do not set the symbol or magnification
- * so next the calculation will be performed again. */
- if (magfact < 0.0) {
- auto_scale(im,&printval,&si_symb,&magfact);
- if (printval == 0.0)
- magfact = -1.0;
- } else {
- printval /= magfact;
- }
- *(++percent_s) = 's';
- } else if (strstr(im->gdes[i].format,"%s") != NULL) {
- auto_scale(im,&printval,&si_symb,&magfact);
- }
-
- if (im->gdes[i].gf == GF_PRINT){
- (*prdata)[prlines-2] = malloc((FMT_LEG_LEN+2)*sizeof(char));
- (*prdata)[prlines-1] = NULL;
- if (bad_format(im->gdes[i].format)) {
- rrd_set_error("bad format for PRINT in '%s'", im->gdes[i].format);
- return -1;
- }
+ vidx = im->gdes[i].vidx;
+ switch(im->gdes[i].gf){
+ case GF_PRINT:
+ prlines++;
+ if(((*prdata) = rrd_realloc((*prdata),prlines*sizeof(char *)))==NULL){
+ rrd_set_error("realloc prdata");
+ return 0;
+ }
+ 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.
+ */
+ 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 { /* need to calculate max,min,avg etcetera */
+ max_ii =((im->gdes[vidx].end
+ - im->gdes[vidx].start)
+ / im->gdes[vidx].step
+ * im->gdes[vidx].ds_cnt);
+ printval = DNAN;
+ validsteps = 0;
+ for( 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_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);
+ }
+ }
+ } /* prepare printval */
+
+ if ((percent_s = strstr(im->gdes[i].format,"%S")) != NULL) {
+ /* Magfact is set to -1 upon entry to print_calc. If it
+ * is still less than 0, then we need to run auto_scale.
+ * Otherwise, put the value into the correct units. If
+ * the value is 0, then do not set the symbol or magnification
+ * so next the calculation will be performed again. */
+ if (magfact < 0.0) {
+ auto_scale(im,&printval,&si_symb,&magfact);
+ if (printval == 0.0)
+ magfact = -1.0;
+ } else {
+ printval /= magfact;
+ }
+ *(++percent_s) = 's';
+ } else if (strstr(im->gdes[i].format,"%s") != NULL) {
+ auto_scale(im,&printval,&si_symb,&magfact);
+ }
+
+ if (im->gdes[i].gf == GF_PRINT){
+ (*prdata)[prlines-2] = malloc((FMT_LEG_LEN+2)*sizeof(char));
+ (*prdata)[prlines-1] = NULL;
+ if (im->gdes[i].strftm){
+ strftime((*prdata)[prlines-2],FMT_LEG_LEN,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;
+ }
+