13 #include "../../src/rrd_tool.h"
15 /* perl 5.004 compatibility */
16 #if PERLPATCHLEVEL < 5
17 #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);
144 rrd_graph(items+1,argv,&calcpr,&xsize,&ysize);
145 for (i=0; i < items; i++) {
150 if (rrd_test_error()) {
152 for(i=0;calcpr[i];i++)
153 rrd_freemem(calcpr[i]);
158 for(i=0;calcpr[i];i++){
159 av_push(retar,newSVpv(calcpr[i],0));
160 rrd_freemem(calcpr[i]);
165 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
166 PUSHs(sv_2mortal(newSViv(xsize)));
167 PUSHs(sv_2mortal(newSViv(ysize)));
174 unsigned long step, ds_cnt,i,ii;
175 rrd_value_t *data,*datai;
178 AV *retar,*line,*names;
180 argv = (char **) malloc((items+1)*sizeof(char *));
182 for (i = 0; i < items; i++) {
184 char *handle= SvPV(ST(i),len);
185 /* actually copy the data to make sure possible modifications
186 on the argv data does not backfire into perl */
187 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
188 strcpy(argv[i+1],handle);
192 rrd_fetch(items+1,argv,&start,&end,&step,&ds_cnt,&ds_namv,&data);
193 for (i=0; i < items; i++) {
197 if (rrd_test_error()) XSRETURN_UNDEF;
198 /* convert the ds_namv into perl format */
200 for (ii = 0; ii < ds_cnt; ii++){
201 av_push(names,newSVpv(ds_namv[ii],0));
202 rrd_freemem(ds_namv[ii]);
204 rrd_freemem(ds_namv);
205 /* convert the data array into perl format */
208 for (i = start+step; i <= end; i += step){
210 for (ii = 0; ii < ds_cnt; ii++){
211 av_push(line,(isnan(*datai) ? &PL_sv_undef : newSVnv(*datai)));
214 av_push(retar,newRV_noinc((SV*)line));
218 PUSHs(sv_2mortal(newSViv(start+step)));
219 PUSHs(sv_2mortal(newSViv(step)));
220 PUSHs(sv_2mortal(newRV_noinc((SV*)names)));
221 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
230 unsigned long step, col_cnt,row_cnt,i,ii;
231 rrd_value_t *data,*ptr;
232 char **argv,**legend_v;
233 AV *retar,*line,*names;
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 rrd_xport(items+1,argv,&xsize,&start,&end,&step,&col_cnt,&legend_v,&data);
248 for (i=0; i < items; i++) {
252 if (rrd_test_error()) XSRETURN_UNDEF;
254 /* convert the legend_v into perl format */
256 for (ii = 0; ii < col_cnt; ii++){
257 av_push(names,newSVpv(legend_v[ii],0));
258 rrd_freemem(legend_v[ii]);
260 rrd_freemem(legend_v);
262 /* convert the data array into perl format */
265 for (i = start+step; i <= end; i += step){
267 for (ii = 0; ii < col_cnt; ii++){
268 av_push(line,(isnan(*ptr) ? &PL_sv_undef : newSVnv(*ptr)));
271 av_push(retar,newRV_noinc((SV*)line));
276 PUSHs(sv_2mortal(newSViv(start+step)));
277 PUSHs(sv_2mortal(newSViv(end)));
278 PUSHs(sv_2mortal(newSViv(step)));
279 PUSHs(sv_2mortal(newSViv(col_cnt)));
280 PUSHs(sv_2mortal(newRV_noinc((SV*)names)));
281 PUSHs(sv_2mortal(newRV_noinc((SV*)retar)));
292 /* prepare argument list */
293 argv = (char **) malloc((items+1)*sizeof(char *));
295 for (i = 0; i < items; i++) {
297 char *handle= SvPV(ST(i),len);
298 /* actually copy the data to make sure possible modifications
299 on the argv data does not backfire into perl */
300 argv[i+1] = (char *) malloc((strlen(handle)+1)*sizeof(char));
301 strcpy(argv[i+1],handle);
305 data=rrd_info(items+1, argv);
306 for (i=0; i < items; i++) {
310 if (rrd_test_error()) XSRETURN_UNDEF;
314 /* the newSV will get copied by hv so we create it as a mortal to make sure
315 it does not keep hanging round after the fact */
316 #define hvs(VAL) hv_store_ent(hash, sv_2mortal(newSVpv(data->key,0)),VAL,0)
317 switch (data->type) {
319 if (isnan(data->value.u_val))
322 hvs(newSVnv(data->value.u_val));
325 hvs(newSViv(data->value.u_cnt));
328 hvs(newSVpv(data->value.u_str,0));
329 rrd_freemem(data->value.u_str);
333 rrd_freemem(data->key);
338 RETVAL = newRV_noinc((SV*)hash);