From: oetiker Date: Wed, 12 Nov 2003 22:14:26 +0000 (+0000) Subject: allow to pass an open filehandle into rrd_graph as an extra argument X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d1e55cdc27a837fb0f4c54ed019e3946e7a6e08b;p=rrdtool.git allow to pass an open filehandle into rrd_graph as an extra argument git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@221 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/bindings/perl-shared/RRDs.xs b/bindings/perl-shared/RRDs.xs index 474c9c4..afb55f0 100644 --- a/bindings/perl-shared/RRDs.xs +++ b/bindings/perl-shared/RRDs.xs @@ -193,7 +193,7 @@ rrd_graph(...) } optind=0; opterr=0; rrd_clear_error(); - rrd_graph(items+1,argv,&calcpr,&xsize,&ysize); + rrd_graph(items+1,argv,&calcpr,&xsize,&ysize,NULL); for (i=0; i < items; i++) { free(argv[i+1]); } diff --git a/src/rrd.h b/src/rrd.h index b09e316..902f72a 100644 --- a/src/rrd.h +++ b/src/rrd.h @@ -5,6 +5,9 @@ ***************************************************************************** * $Id$ * $Log$ + * Revision 1.7 2003/11/12 22:14:26 oetiker + * allow to pass an open filehandle into rrd_graph as an extra argument + * * Revision 1.6 2003/11/11 19:46:21 oetiker * replaced time_value with rrd_time_value as MacOS X introduced a struct of that name in their standard headers * @@ -53,7 +56,7 @@ typedef double rrd_value_t; /* the data storage type is /* main function blocks */ int rrd_create(int, char **); int rrd_update(int, char **); -int rrd_graph(int, char **, char ***, int *, int *); +int rrd_graph(int, char **, char ***, int *, int *, FILE *); int rrd_fetch(int, char **, time_t *, time_t *, unsigned long *, unsigned long *, char ***, rrd_value_t **); int rrd_restore(int, char **); diff --git a/src/rrd_cgi.c b/src/rrd_cgi.c index b49f5f5..4543044 100644 --- a/src/rrd_cgi.c +++ b/src/rrd_cgi.c @@ -433,7 +433,7 @@ char* drawgraph(long argc, char **args){ optind=0; /* reset gnu getopt */ opterr=0; /* reset gnu getopt */ calfree(); - if( rrd_graph(argc+1, args-1, &calcpr, &xsize, &ysize) != -1 ) { + if( rrd_graph(argc+1, args-1, &calcpr, &xsize, &ysize, NULL) != -1 ) { return stralloc(calcpr[0]); } else { if (rrd_test_error()) { diff --git a/src/rrd_graph.c b/src/rrd_graph.c index ef7c9b6..c60717f 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -2477,11 +2477,11 @@ graph_paint(image_desc_t *im, char ***calcpr) if (strcmp(im->graphfile,"-")==0) { + fo = im->graphhandle ? im->graphhandle : stdout; #ifdef WIN32 /* Change translation mode for stdout to BINARY */ - _setmode( _fileno( stdout ), O_BINARY ); + _setmode( _fileno( fo ), O_BINARY ); #endif - fo = stdout; } else { if ((fo = fopen(im->graphfile,"wb")) == NULL) { rrd_set_error("Opening '%s' for write: %s",im->graphfile, @@ -2569,12 +2569,13 @@ scan_for_col(char *input, int len, char *output) ** - script parsing now in rrd_graph_script() */ int -rrd_graph(int argc, char **argv, char ***prdata, int *xsize, int *ysize) +rrd_graph(int argc, char **argv, char ***prdata, int *xsize, int *ysize, FILE *stream) { image_desc_t im; rrd_graph_init(&im); - + im.graphhandle = stream; + rrd_graph_options(argc,argv,&im); if (rrd_test_error()) { im_free(&im); diff --git a/src/rrd_graph.h b/src/rrd_graph.h index a746736..09c2f1d 100644 --- a/src/rrd_graph.h +++ b/src/rrd_graph.h @@ -128,6 +128,7 @@ typedef struct image_desc_t { /* configuration of graph */ char graphfile[MAXPATH]; /* filename for graphic */ + FILE *graphhandle; /* FILE to use if filename is "-" */ long xsize,ysize,piesize; /* graph area size in pixels */ gfx_color_t graph_col[__GRC_END__]; /* real colors for the graph */ text_prop_t text_prop[TEXT_PROP_LAST]; /* text properties */ @@ -210,7 +211,7 @@ int graph_paint(image_desc_t *, char ***); void pie_part(image_desc_t *, gfx_color_t, double, double, double, double, double); int gdes_alloc(image_desc_t *); int scan_for_col(char *, int, char *); -int rrd_graph(int, char **, char ***, int *, int *); +int rrd_graph(int, char **, char ***, int *, int *, FILE *); void rrd_graph_init(image_desc_t *); void rrd_graph_options(int, char **, image_desc_t *); void rrd_graph_script(int, char **, image_desc_t *); diff --git a/src/rrd_tool.c b/src/rrd_tool.c index cfd71a9..d23094f 100644 --- a/src/rrd_tool.c +++ b/src/rrd_tool.c @@ -609,7 +609,7 @@ int HandleInputLine(int argc, char **argv, FILE* out) int xsize, ysize; int i; int tostdout = (strcmp(argv[2],"-") == 0); - if( rrd_graph(argc-1, &argv[1], &calcpr, &xsize, &ysize) != -1 ) { + if( rrd_graph(argc-1, &argv[1], &calcpr, &xsize, &ysize, NULL) != -1 ) { if (!tostdout) printf ("%dx%d\n",xsize,ysize); if (calcpr) {