index cf3fb07597a51cd6689bef4cee8ab1cdcfa1cf02..65748cc491cf1933ee48934aa2b7ebb9dc3463dc 100644 (file)
/****************************************************************************
/****************************************************************************
- * RRDtool 1.0.28 Copyright Tobias Oetiker, 1997 - 2000
+ * RRDtool 1.0.28 Copyright Tobias Oetiker, 1997 - 2002
****************************************************************************
* rrd_rpncalc.c RPN calculator functions
****************************************************************************/
#include "rrd_tool.h"
#include "rrd_rpncalc.h"
****************************************************************************
* rrd_rpncalc.c RPN calculator functions
****************************************************************************/
#include "rrd_tool.h"
#include "rrd_rpncalc.h"
+#include "rrd_graph.h"
#include <limits.h>
short addop2str(enum op_en op, enum op_en op_type, char *op_str,
#include <limits.h>
short addop2str(enum op_en op, enum op_en op_type, char *op_str,
return -1;
}
(*rpnc)[i].val = (short) temp;
return -1;
}
(*rpnc)[i].val = (short) temp;
- } else if (rpnp[i].op == OP_VARIABLE) {
+ } else if (rpnp[i].op == OP_VARIABLE ||
+ rpnp[i].op == OP_PREV_OTHER) {
(*rpnc)[i].val = (short) rpnp[i].ptr;
}
}
(*rpnc)[i].val = (short) rpnp[i].ptr;
}
}
rpnp[i].op = (long) rpnc[i].op;
if (rpnp[i].op == OP_NUMBER) {
rpnp[i].val = (double) rpnc[i].val;
rpnp[i].op = (long) rpnc[i].op;
if (rpnp[i].op == OP_NUMBER) {
rpnp[i].val = (double) rpnc[i].val;
- } else if (rpnp[i].op == OP_VARIABLE) {
+ } else if (rpnp[i].op == OP_VARIABLE ||
+ rpnp[i].op == OP_PREV_OTHER) {
rpnp[i].ptr = (long) rpnc[i].val;
}
}
rpnp[i].ptr = (long) rpnc[i].val;
}
}
* into a CDEF string. This function is used by rrd_dump.
* arguments:
* rpnc: an array of compact RPN operator nodes
* into a CDEF string. This function is used by rrd_dump.
* arguments:
* rpnc: an array of compact RPN operator nodes
- * rrd: a pointer an rrd header (only the ds_cnt and ds_def elements need
- * to be valid) for lookup of data source names by index
+ * ds_def: a pointer to the data source definition section of an RRD header
+ * for lookup of data source names by index
* str: out string, memory is allocated by the function, must be freed by the
* the caller */
void rpn_compact2str(rpn_cdefds_t *rpnc,ds_def_t *ds_def,char **str)
* str: out string, memory is allocated by the function, must be freed by the
* the caller */
void rpn_compact2str(rpn_cdefds_t *rpnc,ds_def_t *ds_def,char **str)
char *ds_name = ds_def[rpnc[i].val].ds_nam;
add_op(OP_VARIABLE, ds_name)
}
char *ds_name = ds_def[rpnc[i].val].ds_nam;
add_op(OP_VARIABLE, ds_name)
}
+
+ if (rpnc[i].op == OP_PREV_OTHER) {
+ char *ds_name = ds_def[rpnc[i].val].ds_nam;
+ add_op(OP_VARIABLE, ds_name)
+ }
+
#undef add_op
#define add_op(VV,VVV) \
#undef add_op
#define add_op(VV,VVV) \
add_op(OP_UNKN,UNKN)
add_op(OP_UN,UN)
add_op(OP_NEGINF,NEGINF)
add_op(OP_UNKN,UNKN)
add_op(OP_UN,UN)
add_op(OP_NEGINF,NEGINF)
+ add_op(OP_NE,NE)
add_op(OP_PREV,PREV)
add_op(OP_INF,INF)
add_op(OP_PREV,PREV)
add_op(OP_INF,INF)
+ add_op(OP_ISINF,ISINF)
add_op(OP_NOW,NOW)
add_op(OP_LTIME,LTIME)
add_op(OP_TIME,TIME)
add_op(OP_NOW,NOW)
add_op(OP_LTIME,LTIME)
add_op(OP_TIME,TIME)
* occur too often. */
for (i = 0; rpnp[i].op != OP_END; i++) {
if (rpnp[i].op == OP_TIME || rpnp[i].op == OP_LTIME ||
* occur too often. */
for (i = 0; rpnp[i].op != OP_END; i++) {
if (rpnp[i].op == OP_TIME || rpnp[i].op == OP_LTIME ||
- rpnp[i].op == OP_PREV)
+ rpnp[i].op == OP_PREV || rpnp[i].op == OP_COUNT)
{
rrd_set_error(
{
rrd_set_error(
- "operators time, ltime and prev not supported with DS COMPUTE");
+ "operators time, ltime, prev and count not supported with DS COMPUTE");
free(rpnp);
return;
}
free(rpnp);
return;
}
*/
long lookup_DS(void *rrd_vptr,char *ds_name)
{
*/
long lookup_DS(void *rrd_vptr,char *ds_name)
{
- int i;
+ unsigned int i;
rrd_t *rrd;
rrd = (rrd_t *) rrd_vptr;
rrd_t *rrd;
rrd = (rrd_t *) rrd_vptr;
expr+=strlen(#VVV); \
}
expr+=strlen(#VVV); \
}
+
+#define match_op_param(VV,VVV) \
+ else if (sscanf(expr, #VVV "(" DEF_NAM_FMT ")",vname) == 1) { \
+ int length = 0; \
+ if ((length = strlen(#VVV)+strlen(vname)+2, \
+ expr[length] == ',' || expr[length] == '\0') ) { \
+ rpnp[steps].op = VV; \
+ rpnp[steps].ptr = (*lookup)(key_hash,vname); \
+ if (rpnp[steps].ptr < 0) { \
+ free(rpnp); \
+ return NULL; \
+ } else expr+=length; \
+ } \
+ }
+
match_op(OP_ADD,+)
match_op(OP_SUB,-)
match_op(OP_MUL,*)
match_op(OP_ADD,+)
match_op(OP_SUB,-)
match_op(OP_MUL,*)
match_op(OP_UNKN,UNKN)
match_op(OP_UN,UN)
match_op(OP_NEGINF,NEGINF)
match_op(OP_UNKN,UNKN)
match_op(OP_UN,UN)
match_op(OP_NEGINF,NEGINF)
+ match_op(OP_NE,NE)
+ match_op(OP_COUNT,COUNT)
+ match_op_param(OP_PREV_OTHER,PREV)
match_op(OP_PREV,PREV)
match_op(OP_INF,INF)
match_op(OP_PREV,PREV)
match_op(OP_INF,INF)
+ match_op(OP_ISINF,ISINF)
match_op(OP_NOW,NOW)
match_op(OP_LTIME,LTIME)
match_op(OP_TIME,TIME)
match_op(OP_NOW,NOW)
match_op(OP_LTIME,LTIME)
match_op(OP_TIME,TIME)
#undef match_op
#undef match_op
- else if ((sscanf(expr,"%29[_A-Za-z0-9]%n",
+ else if ((sscanf(expr, DEF_NAM_FMT "%n",
vname,&pos) == 1)
&& ((rpnp[steps].ptr = (*lookup)(key_hash,vname)) != -1)){
rpnp[steps].op = OP_VARIABLE;
vname,&pos) == 1)
&& ((rpnp[steps].ptr = (*lookup)(key_hash,vname)) != -1)){
rpnp[steps].op = OP_VARIABLE;
rpn_calc(rpnp_t *rpnp, rpnstack_t *rpnstack, long data_idx,
rrd_value_t *output, int output_idx)
{
rpn_calc(rpnp_t *rpnp, rpnstack_t *rpnstack, long data_idx,
rrd_value_t *output, int output_idx)
{
- int rpi;
- long stptr = -1;
+ int rpi;
+ long stptr = -1;
- /* process each op from the rpn in turn */
- for (rpi=0; rpnp[rpi].op != OP_END; rpi++){
- /* allocate or grow the stack */
- if (stptr + 5 > rpnstack -> dc_stacksize){
- /* could move this to a separate function */
- rpnstack -> dc_stacksize += rpnstack -> dc_stackblock;
- rpnstack -> s = rrd_realloc(rpnstack -> s,
- (rpnstack -> dc_stacksize)*sizeof(*(rpnstack -> s)));
- if (rpnstack -> s == NULL){
- rrd_set_error("RPN stack overflow");
- return -1;
- }
- }
- switch (rpnp[rpi].op){
- case OP_NUMBER:
- rpnstack -> s[++stptr] = rpnp[rpi].val;
- break;
- case OP_VARIABLE:
- /* make sure we pull the correct value from the *.data array
- * adjust the pointer into the array acordingly.
- * Advance the ptr one row in the rra (skip over
- * non-relevant data sources) */
- if (data_idx % rpnp[rpi].step == 0){
- rpnp[rpi].data += rpnp[rpi].ds_cnt;
- }
- rpnstack -> s[++stptr] = *(rpnp[rpi].data);
- break;
- case OP_PREV:
- if ((output_idx-1) <= 0) {
- rpnstack -> s[++stptr] = DNAN;
- } else {
- rpnstack -> s[++stptr] = output[output_idx-1];
- }
- break;
- case OP_UNKN:
- rpnstack -> s[++stptr] = DNAN;
- break;
- case OP_INF:
- rpnstack -> s[++stptr] = DINF;
- break;
- case OP_NEGINF:
- rpnstack -> s[++stptr] = -DINF;
- break;
- case OP_NOW:
- rpnstack -> s[++stptr] = (double)time(NULL);
- break;
- case OP_TIME:
- /* HACK: this relies on the data_idx being the time,
- * which the within-function scope is unaware of */
- rpnstack -> s[++stptr] = (double) data_idx;
- break;
- case OP_LTIME:
- rpnstack -> s[++stptr] = (double) tzoffset(data_idx) + (double)data_idx;
- break;
- case OP_ADD:
- if(stptr<1){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1]
- + rpnstack -> s[stptr];
- stptr--;
- break;
- case OP_SUB:
- if(stptr<1){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1] - rpnstack -> s[stptr];
- stptr--;
- break;
- case OP_MUL:
- if(stptr<1){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- rpnstack -> s[stptr-1] = (rpnstack -> s[stptr-1]) * (rpnstack -> s[stptr]);
- stptr--;
- break;
- case OP_DIV:
- if(stptr<1){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1] / rpnstack -> s[stptr];
- stptr--;
- break;
- case OP_MOD:
- if(stptr<1){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- rpnstack -> s[stptr-1] = fmod(rpnstack -> s[stptr-1],rpnstack -> s[stptr]);
- stptr--;
- break;
- case OP_SIN:
- if(stptr<0){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- rpnstack -> s[stptr] = sin(rpnstack -> s[stptr]);
- break;
- case OP_COS:
- if(stptr<0){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- rpnstack -> s[stptr] = cos(rpnstack -> s[stptr]);
- break;
- case OP_CEIL:
- if(stptr<0){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- rpnstack -> s[stptr] = ceil(rpnstack -> s[stptr]);
- break;
- case OP_FLOOR:
- if(stptr<0){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- rpnstack -> s[stptr] = floor(rpnstack -> s[stptr]);
- break;
- case OP_LOG:
- if(stptr<0){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- rpnstack -> s[stptr] = log(rpnstack -> s[stptr]);
- break;
- case OP_DUP:
- if(stptr<0){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- rpnstack -> s[stptr+1] = rpnstack -> s[stptr];
- stptr++;
- break;
- case OP_POP:
- if(stptr<0){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- stptr--;
- break;
- case OP_EXC:
- if(stptr<1){
- rrd_set_error("RPN stack underflow");
- return -1;
- } else {
- double dummy;
- dummy = rpnstack -> s[stptr] ;
- rpnstack -> s[stptr] = rpnstack -> s[stptr-1];
- rpnstack -> s[stptr-1] = dummy;
- }
- break;
- case OP_EXP:
- if(stptr<0){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- rpnstack -> s[stptr] = exp(rpnstack -> s[stptr]);
- break;
- case OP_LT:
- if(stptr<1){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- if (isnan(rpnstack -> s[stptr-1]))
- ;
- else if (isnan(rpnstack -> s[stptr]))
- rpnstack -> s[stptr-1] = rpnstack -> s[stptr];
- else
- rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1] < rpnstack -> s[stptr] ? 1.0 : 0.0;
- stptr--;
- break;
- case OP_LE:
- if(stptr<1){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- if (isnan(rpnstack -> s[stptr-1]))
- ;
- else if (isnan(rpnstack -> s[stptr]))
- rpnstack -> s[stptr-1] = rpnstack -> s[stptr];
- else
- rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1] <= rpnstack -> s[stptr] ? 1.0 : 0.0;
- stptr--;
- break;
- case OP_GT:
- if(stptr<1){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- if (isnan(rpnstack -> s[stptr-1]))
- ;
- else if (isnan(rpnstack -> s[stptr]))
- rpnstack -> s[stptr-1] = rpnstack -> s[stptr];
- else
- rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1] > rpnstack -> s[stptr] ? 1.0 : 0.0;
- stptr--;
- break;
- case OP_GE:
- if(stptr<1){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- if (isnan(rpnstack -> s[stptr-1]))
- ;
- else if (isnan(rpnstack -> s[stptr]))
- rpnstack -> s[stptr-1] = rpnstack -> s[stptr];
- else
- rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1] >= rpnstack -> s[stptr] ? 1.0 : 0.0;
- stptr--;
- break;
- case OP_EQ:
- if(stptr<1){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- if (isnan(rpnstack -> s[stptr-1]))
- ;
- else if (isnan(rpnstack -> s[stptr]))
- rpnstack -> s[stptr-1] = rpnstack -> s[stptr];
- else
- rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1] == rpnstack -> s[stptr] ? 1.0 : 0.0;
- stptr--;
- break;
- case OP_IF:
- if(stptr<2){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- rpnstack->s[stptr-2] = rpnstack->s[stptr-2] != 0.0 ? rpnstack->s[stptr-1] : rpnstack->s[stptr];
- stptr--;
- stptr--;
- break;
- case OP_MIN:
- if(stptr<1){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- if (isnan(rpnstack->s[stptr-1]))
- ;
- else if (isnan(rpnstack->s[stptr]))
- rpnstack->s[stptr-1] = rpnstack->s[stptr];
- else if (rpnstack->s[stptr-1] > rpnstack->s[stptr])
- rpnstack->s[stptr-1] = rpnstack->s[stptr];
- stptr--;
- break;
- case OP_MAX:
- if(stptr<1){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- if (isnan(rpnstack->s[stptr-1]))
- ;
- else if (isnan(rpnstack->s[stptr]))
- rpnstack->s[stptr-1] = rpnstack->s[stptr];
- else if (rpnstack->s[stptr-1] < rpnstack->s[stptr])
- rpnstack->s[stptr-1] = rpnstack->s[stptr];
- stptr--;
- break;
- case OP_LIMIT:
- if(stptr<2){
- rrd_set_error("RPN stack underflow");
- free(rpnstack->s);
- return -1;
- }
- if (isnan(rpnstack->s[stptr-2]))
+ /* process each op from the rpn in turn */
+ for (rpi=0; rpnp[rpi].op != OP_END; rpi++){
+ /* allocate or grow the stack */
+ if (stptr + 5 > rpnstack -> dc_stacksize){
+ /* could move this to a separate function */
+ rpnstack -> dc_stacksize += rpnstack -> dc_stackblock;
+ rpnstack -> s = rrd_realloc(rpnstack -> s,
+ (rpnstack -> dc_stacksize)*sizeof(*(rpnstack -> s)));
+ if (rpnstack -> s == NULL){
+ rrd_set_error("RPN stack overflow");
+ return -1;
+ }
+ }
+
+#define stackunderflow(MINSIZE) \
+ if(stptr<MINSIZE){ \
+ rrd_set_error("RPN stack underflow"); \
+ return -1; \
+ }
+
+ switch (rpnp[rpi].op){
+ case OP_NUMBER:
+ rpnstack -> s[++stptr] = rpnp[rpi].val;
+ break;
+ case OP_VARIABLE:
+ /* Sanity check: VDEFs shouldn't make it here */
+ if (rpnp[rpi].ds_cnt == 0) {
+ rrd_set_error("VDEF made it into rpn_calc... aborting");
+ return -1;
+ } else {
+ /* make sure we pull the correct value from
+ * the *.data array. Adjust the pointer into
+ * the array acordingly. Advance the ptr one
+ * row in the rra (skip over non-relevant
+ * data sources)
+ */
+ rpnstack -> s[++stptr] = *(rpnp[rpi].data);
+ if (data_idx % rpnp[rpi].step == 0){
+ rpnp[rpi].data += rpnp[rpi].ds_cnt;
+ }
+ }
+ break;
+ case OP_COUNT:
+ rpnstack -> s[++stptr] = (output_idx+1); /* Note: Counter starts at 1 */
+ break;
+ case OP_PREV:
+ if ((output_idx) <= 0) {
+ rpnstack -> s[++stptr] = DNAN;
+ } else {
+ rpnstack -> s[++stptr] = output[output_idx-1];
+ }
+ break;
+ case OP_PREV_OTHER:
+ if ((output_idx) <= 0) {
+ rpnstack -> s[++stptr] = DNAN;
+ } else {
+ rpnstack -> s[++stptr] = rpnp[rpnp[rpi].ptr].data[output_idx-1];
+ }
+ break;
+ case OP_UNKN:
+ rpnstack -> s[++stptr] = DNAN;
+ break;
+ case OP_INF:
+ rpnstack -> s[++stptr] = DINF;
+ break;
+ case OP_NEGINF:
+ rpnstack -> s[++stptr] = -DINF;
+ break;
+ case OP_NOW:
+ rpnstack -> s[++stptr] = (double)time(NULL);
+ break;
+ case OP_TIME:
+ /* HACK: this relies on the data_idx being the time,
+ ** which the within-function scope is unaware of */
+ rpnstack -> s[++stptr] = (double) data_idx;
+ break;
+ case OP_LTIME:
+ rpnstack -> s[++stptr] =
+ (double) tzoffset(data_idx) + (double)data_idx;
+ break;
+ case OP_ADD:
+ stackunderflow(1);
+ rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1]
+ + rpnstack -> s[stptr];
+ stptr--;
+ break;
+ case OP_SUB:
+ stackunderflow(1);
+ rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1]
+ - rpnstack -> s[stptr];
+ stptr--;
+ break;
+ case OP_MUL:
+ stackunderflow(1);
+ rpnstack -> s[stptr-1] = (rpnstack -> s[stptr-1])
+ * (rpnstack -> s[stptr]);
+ stptr--;
+ break;
+ case OP_DIV:
+ stackunderflow(1);
+ rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1]
+ / rpnstack -> s[stptr];
+ stptr--;
+ break;
+ case OP_MOD:
+ stackunderflow(1);
+ rpnstack -> s[stptr-1]= fmod( rpnstack -> s[stptr-1]
+ ,rpnstack -> s[stptr]);
+ stptr--;
+ break;
+ case OP_SIN:
+ stackunderflow(0);
+ rpnstack -> s[stptr] = sin(rpnstack -> s[stptr]);
+ break;
+ case OP_COS:
+ stackunderflow(0);
+ rpnstack -> s[stptr] = cos(rpnstack -> s[stptr]);
+ break;
+ case OP_CEIL:
+ stackunderflow(0);
+ rpnstack -> s[stptr] = ceil(rpnstack -> s[stptr]);
+ break;
+ case OP_FLOOR:
+ stackunderflow(0);
+ rpnstack -> s[stptr] = floor(rpnstack -> s[stptr]);
+ break;
+ case OP_LOG:
+ stackunderflow(0);
+ rpnstack -> s[stptr] = log(rpnstack -> s[stptr]);
+ break;
+ case OP_DUP:
+ stackunderflow(0);
+ rpnstack -> s[stptr+1] = rpnstack -> s[stptr];
+ stptr++;
+ break;
+ case OP_POP:
+ stackunderflow(0);
+ stptr--;
+ break;
+ case OP_EXC:
+ stackunderflow(1);
+ {
+ double dummy;
+ dummy = rpnstack -> s[stptr] ;
+ rpnstack -> s[stptr] = rpnstack -> s[stptr-1];
+ rpnstack -> s[stptr-1] = dummy;
+ }
+ break;
+ case OP_EXP:
+ stackunderflow(0);
+ rpnstack -> s[stptr] = exp(rpnstack -> s[stptr]);
+ break;
+ case OP_LT:
+ stackunderflow(1);
+ if (isnan(rpnstack -> s[stptr-1]))
+ ;
+ else if (isnan(rpnstack -> s[stptr]))
+ rpnstack -> s[stptr-1] = rpnstack -> s[stptr];
+ else
+ rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1] <
+ rpnstack -> s[stptr] ? 1.0 : 0.0;
+ stptr--;
+ break;
+ case OP_LE:
+ stackunderflow(1);
+ if (isnan(rpnstack -> s[stptr-1]))
+ ;
+ else if (isnan(rpnstack -> s[stptr]))
+ rpnstack -> s[stptr-1] = rpnstack -> s[stptr];
+ else
+ rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1] <=
+ rpnstack -> s[stptr] ? 1.0 : 0.0;
+ stptr--;
+ break;
+ case OP_GT:
+ stackunderflow(1);
+ if (isnan(rpnstack -> s[stptr-1]))
+ ;
+ else if (isnan(rpnstack -> s[stptr]))
+ rpnstack -> s[stptr-1] = rpnstack -> s[stptr];
+ else
+ rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1] >
+ rpnstack -> s[stptr] ? 1.0 : 0.0;
+ stptr--;
+ break;
+ case OP_GE:
+ stackunderflow(1);
+ if (isnan(rpnstack -> s[stptr-1]))
+ ;
+ else if (isnan(rpnstack -> s[stptr]))
+ rpnstack -> s[stptr-1] = rpnstack -> s[stptr];
+ else
+ rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1] >=
+ rpnstack -> s[stptr] ? 1.0 : 0.0;
+ stptr--;
+ break;
+ case OP_NE:
+ stackunderflow(1);
+ if (isnan(rpnstack -> s[stptr-1]))
+ ;
+ else if (isnan(rpnstack -> s[stptr]))
+ rpnstack -> s[stptr-1] = rpnstack -> s[stptr];
+ else
+ rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1] ==
+ rpnstack -> s[stptr] ? 0.0 : 1.0;
+ stptr--;
+ break;
+ case OP_EQ:
+ stackunderflow(1);
+ if (isnan(rpnstack -> s[stptr-1]))
+ ;
+ else if (isnan(rpnstack -> s[stptr]))
+ rpnstack -> s[stptr-1] = rpnstack -> s[stptr];
+ else
+ rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1] ==
+ rpnstack -> s[stptr] ? 1.0 : 0.0;
+ stptr--;
+ break;
+ case OP_IF:
+ stackunderflow(2);
+ rpnstack->s[stptr-2] = rpnstack->s[stptr-2] != 0.0 ?
+ rpnstack->s[stptr-1] : rpnstack->s[stptr];
+ stptr--;
+ stptr--;
+ break;
+ case OP_MIN:
+ stackunderflow(1);
+ if (isnan(rpnstack->s[stptr-1]))
+ ;
+ else if (isnan(rpnstack->s[stptr]))
+ rpnstack->s[stptr-1] = rpnstack->s[stptr];
+ else if (rpnstack->s[stptr-1] > rpnstack->s[stptr])
+ rpnstack->s[stptr-1] = rpnstack->s[stptr];
+ stptr--;
+ break;
+ case OP_MAX:
+ stackunderflow(1);
+ if (isnan(rpnstack->s[stptr-1]))
;
;
- else if (isnan(rpnstack->s[stptr-1]))
- rpnstack->s[stptr-2] = rpnstack->s[stptr-1];
- else if (isnan(rpnstack->s[stptr]))
- rpnstack->s[stptr-2] = rpnstack->s[stptr];
- else if (rpnstack->s[stptr-2] < rpnstack->s[stptr-1])
- rpnstack->s[stptr-2] = DNAN;
- else if (rpnstack->s[stptr-2] > rpnstack->s[stptr])
- rpnstack->s[stptr-2] = DNAN;
- stptr-=2;
- break;
- case OP_UN:
- if(stptr<0){
- rrd_set_error("RPN stack underflow");
- return -1;
- }
- rpnstack->s[stptr] = isnan(rpnstack->s[stptr]) ? 1.0 : 0.0;
- break;
- case OP_END:
- break;
+ else if (isnan(rpnstack->s[stptr]))
+ rpnstack->s[stptr-1] = rpnstack->s[stptr];
+ else if (rpnstack->s[stptr-1] < rpnstack->s[stptr])
+ rpnstack->s[stptr-1] = rpnstack->s[stptr];
+ stptr--;
+ break;
+ case OP_LIMIT:
+ stackunderflow(2);
+ if (isnan(rpnstack->s[stptr-2]))
+ ;
+ else if (isnan(rpnstack->s[stptr-1]))
+ rpnstack->s[stptr-2] = rpnstack->s[stptr-1];
+ else if (isnan(rpnstack->s[stptr]))
+ rpnstack->s[stptr-2] = rpnstack->s[stptr];
+ else if (rpnstack->s[stptr-2] < rpnstack->s[stptr-1])
+ rpnstack->s[stptr-2] = DNAN;
+ else if (rpnstack->s[stptr-2] > rpnstack->s[stptr])
+ rpnstack->s[stptr-2] = DNAN;
+ stptr-=2;
+ break;
+ case OP_UN:
+ stackunderflow(0);
+ rpnstack->s[stptr] = isnan(rpnstack->s[stptr]) ? 1.0 : 0.0;
+ break;
+ case OP_ISINF:
+ stackunderflow(0);
+ rpnstack->s[stptr] = isinf(rpnstack->s[stptr]) ? 1.0 : 0.0;
+ break;
+ case OP_END:
+ break;
}
}
+#undef stackunderflow
}
if(stptr!=0){
rrd_set_error("RPN final stack size != 1");
}
if(stptr!=0){
rrd_set_error("RPN final stack size != 1");
tzoffset( time_t now ){
int gm_sec, gm_min, gm_hour, gm_yday, gm_year,
l_sec, l_min, l_hour, l_yday, l_year;
tzoffset( time_t now ){
int gm_sec, gm_min, gm_hour, gm_yday, gm_year,
l_sec, l_min, l_hour, l_yday, l_year;
- struct tm *t;
+ struct tm t;
int off;
int off;
- t = gmtime(&now);
- gm_sec = t->tm_sec;
- gm_min = t->tm_min;
- gm_hour = t->tm_hour;
- gm_yday = t->tm_yday;
- gm_year = t->tm_year;
- t = localtime(&now);
- l_sec = t->tm_sec;
- l_min = t->tm_min;
- l_hour = t->tm_hour;
- l_yday = t->tm_yday;
- l_year = t->tm_year;
+ gmtime_r(&now, &t);
+ gm_sec = t.tm_sec;
+ gm_min = t.tm_min;
+ gm_hour = t.tm_hour;
+ gm_yday = t.tm_yday;
+ gm_year = t.tm_year;
+ localtime_r(&now, &t);
+ l_sec = t.tm_sec;
+ l_min = t.tm_min;
+ l_hour = t.tm_hour;
+ l_yday = t.tm_yday;
+ l_year = t.tm_year;
off = (l_sec-gm_sec)+(l_min-gm_min)*60+(l_hour-gm_hour)*3600;
if ( l_yday > gm_yday || l_year > gm_year){
off += 24*3600;
off = (l_sec-gm_sec)+(l_min-gm_min)*60+(l_hour-gm_hour)*3600;
if ( l_yday > gm_yday || l_year > gm_year){
off += 24*3600;