allow to pass an open filehandle into rrd_graph as an extra argument
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 12 Nov 2003 22:14:26 +0000 (22:14 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 12 Nov 2003 22:14:26 +0000 (22:14 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@221 a5681a0c-68f1-0310-ab6d-d61299d08faa

bindings/perl-shared/RRDs.xs
src/rrd.h
src/rrd_cgi.c
src/rrd_graph.c
src/rrd_graph.h
src/rrd_tool.c

index 474c9c4..afb55f0 100644 (file)
@@ -193,7 +193,7 @@ rrd_graph(...)
                }
                optind=0; opterr=0; 
                rrd_clear_error();
                }
                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]);
                }
                for (i=0; i < items; i++) {
                    free(argv[i+1]);
                }
index b09e316..902f72a 100644 (file)
--- a/src/rrd.h
+++ b/src/rrd.h
@@ -5,6 +5,9 @@
  *****************************************************************************
  * $Id$
  * $Log$
  *****************************************************************************
  * $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
  *
  * 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 **);
 /* 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 **);
 int    rrd_fetch(int, char **, time_t *, time_t *, unsigned long *,
                 unsigned long *, char ***, rrd_value_t **);
 int    rrd_restore(int, char **);
index b49f5f5..4543044 100644 (file)
@@ -433,7 +433,7 @@ char* drawgraph(long argc, char **args){
   optind=0; /* reset gnu getopt */
   opterr=0; /* reset gnu getopt */
   calfree();
   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()) {
     return stralloc(calcpr[0]);
   } else {
     if (rrd_test_error()) {
index ef7c9b6..c60717f 100644 (file)
@@ -2477,11 +2477,11 @@ graph_paint(image_desc_t *im, char ***calcpr)
 
   
   if (strcmp(im->graphfile,"-")==0) {
 
   
   if (strcmp(im->graphfile,"-")==0) {
+    fo = im->graphhandle ? im->graphhandle : stdout;
 #ifdef WIN32
     /* Change translation mode for stdout to BINARY */
 #ifdef WIN32
     /* Change translation mode for stdout to BINARY */
-    _setmode( _fileno( stdout ), O_BINARY );
+    _setmode( _fileno( fo ), O_BINARY );
 #endif
 #endif
-    fo = stdout;
   } else {
     if ((fo = fopen(im->graphfile,"wb")) == NULL) {
       rrd_set_error("Opening '%s' for write: %s",im->graphfile,
   } 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 
 ** - 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);
 {
     image_desc_t   im;
             
     rrd_graph_init(&im);
-
+    im.graphhandle = stream;
+    
     rrd_graph_options(argc,argv,&im);
     if (rrd_test_error()) {
        im_free(&im);
     rrd_graph_options(argc,argv,&im);
     if (rrd_test_error()) {
        im_free(&im);
index a746736..09c2f1d 100644 (file)
@@ -128,6 +128,7 @@ typedef struct image_desc_t {
     /* configuration of graph */
 
     char           graphfile[MAXPATH]; /* filename for graphic */
     /* 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 */
     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 *);
 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 *);
 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 *);
index cfd71a9..d23094f 100644 (file)
@@ -609,7 +609,7 @@ int HandleInputLine(int argc, char **argv, FILE* out)
        int xsize, ysize;
        int i;
        int tostdout = (strcmp(argv[2],"-") == 0);      
        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) {
            if (!tostdout) 
                printf ("%dx%d\n",xsize,ysize);
            if (calcpr) {