14 #include "../../src/rrd_tool.h"
16 /* perl 5.004 compatibility */
17 #if PERLPATCHLEVEL < 5
18 #define PL_sv_undef sv_undef
21 #define rrdcode(name) \
22 argv = (char **) malloc((items+1)*sizeof(char *));\
24 for (i = 0; i < items; i++) { \
26 char *handle= SvPV(ST(i),len);\
27 /* actually copy the data to make sure possible modifications \
28 on the argv data does not backfire into perl */ \
29 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char)); \
30 strcpy(argv[i+1],handle); \
34 RETVAL=name(items+1,argv); \
35 for (i=0; i < items; i++) {\
40 if (rrd_test_error()) XSRETURN_UNDEF;
43 * should not be needed if libc is linked (see ntmake.pl)
47 #define realloc realloc
52 MODULE = RRDs PACKAGE = RRDs PREFIX = rrd_
55 #ifdef MUST_DISABLE_SIGFPE
56 signal(SIGFPE,SIG_IGN);
58 #ifdef MUST_DISABLE_FPMASK
66 if (! rrd_test_error()) XSRETURN_UNDEF;
67 RETVAL = newSVpv(rrd_get_error(),0);
132 argv = (char **) malloc((items+1)*sizeof(char *));
134 for (i = 0; i < items; i++) {
136 char *handle = SvPV(ST(i),len);
137 /* actually copy the data to make sure possible modifications
138 on the argv data does not backfire into perl */
139 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
140 strcpy(argv[i+1],handle);
145 rrd_graph(items+1,argv,&calcpr,&xsize,&ysize);
146 for (i=0; i < items; i++) {
151 if (rrd_test_error()) {
153 for(i=0;calcpr[i];i++)
159 for(i=0;calcpr[i];i++){
160 av_push(retar,newSVpv(calcpr[i],0));
166 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
167 PUSHs(sv_2mortal(newSViv(xsize)));
168 PUSHs(sv_2mortal(newSViv(ysize)));
175 unsigned long step, ds_cnt,i,ii;
176 rrd_value_t *data,*datai;
179 AV *retar,*line,*names;
181 argv = (char **) malloc((items+1)*sizeof(char *));
183 for (i = 0; i < items; i++) {
185 char *handle= SvPV(ST(i),len);
186 /* actually copy the data to make sure possible modifications
187 on the argv data does not backfire into perl */
188 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
189 strcpy(argv[i+1],handle);
193 rrd_fetch(items+1,argv,&start,&end,&step,&ds_cnt,&ds_namv,&data);
194 for (i=0; i < items; i++) {
198 if (rrd_test_error()) XSRETURN_UNDEF;
199 /* convert the ds_namv into perl format */
201 for (ii = 0; ii < ds_cnt; ii++){
202 av_push(names,newSVpv(ds_namv[ii],0));
206 /* convert the data array into perl format */
209 for (i = start; i <= end; i += step){
211 for (ii = 0; ii < ds_cnt; ii++){
212 av_push(line,(isnan(*datai) ? &PL_sv_undef : newSVnv(*datai)));
215 av_push(retar,newRV_noinc((SV*)line));
219 PUSHs(sv_2mortal(newSViv(start)));
220 PUSHs(sv_2mortal(newSViv(step)));
221 PUSHs(sv_2mortal(newRV_noinc((SV*)names)));
222 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
234 /* prepare argument list */
235 argv = (char **) malloc((items+1)*sizeof(char *));
237 for (i = 0; i < items; i++) {
239 char *handle= SvPV(ST(i),len);
240 /* actually copy the data to make sure possible modifications
241 on the argv data does not backfire into perl */
242 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
243 strcpy(argv[i+1],handle);
247 data=rrd_info(items+1, argv);
248 for (i=0; i < items; i++) {
252 if (rrd_test_error()) XSRETURN_UNDEF;
256 /* the newSV will get copied by hv so we create it as a mortal to make sure
257 it does not keep hanging round after the fact */
258 #define hvs(VAL) hv_store_ent(hash, sv_2mortal(newSVpv(data->key,0)),VAL,0)
259 switch (data->type) {
261 if (isnan(data->value.u_val))
264 hvs(newSVnv(data->value.u_val));
267 hvs(newSViv(data->value.u_cnt));
270 hvs(newSVpv(data->value.u_str,0));
271 free(data->value.u_str);
280 RETVAL = newRV_noinc((SV*)hash);