From 1ace1cf8f901c64c86e57c5023dd028b2bfdfdb1 Mon Sep 17 00:00:00 2001 From: evomarc Date: Thu, 1 Feb 2001 05:17:16 +0000 Subject: [PATCH] I had forgotten to add pipecom.h Moreover, I got fed up with error due to const/non const, so I modified PipeComSend to take a const argument. THe consequence is that it will not run under plain C any more. --- eo/src/utils/eoGnuplot.h | 21 +++++++++++++----- eo/src/utils/pipecom.h | 48 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 eo/src/utils/pipecom.h diff --git a/eo/src/utils/eoGnuplot.h b/eo/src/utils/eoGnuplot.h index b5919b54..d588348f 100644 --- a/eo/src/utils/eoGnuplot.h +++ b/eo/src/utils/eoGnuplot.h @@ -67,6 +67,17 @@ class eoGnuplot /// Class name. virtual string className() const { return "eoGnuplot"; } + /** send a command to gnuplot directly + */ + void gnuplotCommand(std::string _command) + { + if( gpCom ) { + PipeComSend( gpCom, _command.c_str() ); + PipeComSend( gpCom, "\n" ); + } + } + + protected: void initGnuPlot(std::string _title, std::string _extra); // the private data @@ -99,9 +110,7 @@ void eoGnuplot::initGnuPlot(std::string _title, std::string _extra) throw runtime_error("Impossible to spawn gnuplot\n"); else { PipeComSend( gpCom, "set grid\n" ); - char s[1024]; // because .c_str() is a const - strcpy(s, _extra.c_str()); - PipeComSend( gpCom, strdup(_extra.c_str()) ); + PipeComSend( gpCom, _extra.c_str() ); PipeComSend( gpCom, "\n" ); } } @@ -120,7 +129,7 @@ void eoGnuplot::initGnuPlot(std::string _title, std::string _extra) * Created......: Mon Mar 13 13:50:11 1995 * Description..: Communication par pipe bidirectionnel avec un autre process * - * Ident........: $Id: eoGnuplot.h,v 1.1 2001-01-31 18:38:39 evomarc Exp $ + * Ident........: $Id: eoGnuplot.h,v 1.2 2001-02-01 05:17:16 evomarc Exp $ * ---------------------------------------------------------------------- */ @@ -211,7 +220,7 @@ PCom * PipeComOpenArgv( char *prog, char *argv[] ) } -int PipeComSend( PCom *to, char *line ) +int PipeComSend( PCom *to, const char *line ) { int nb = 0; if( ! Check(to ) ) @@ -222,7 +231,7 @@ int PipeComSend( PCom *to, char *line ) } -int PipeComSendn( PCom *to, char *data, int n ) +int PipeComSendn( PCom *to, const char *data, int n ) { int nb = 0; if( ! Check(to) ) diff --git a/eo/src/utils/pipecom.h b/eo/src/utils/pipecom.h new file mode 100644 index 00000000..d90f151a --- /dev/null +++ b/eo/src/utils/pipecom.h @@ -0,0 +1,48 @@ +/* ---------------------------------------------------------------------- + * Where........: CMAP - Polytechnique + * File.........: pipecom.h + * Author.......: Bertrand Lamy (EEAAX) + * Created......: Thu Mar 9 17:21:15 1995 + * Description..: Pipe communication with a process + * + * Ident........: $Id: pipecom.h,v 1.2 2001-02-09 05:09:26 evomarc Exp $ + * ---------------------------------------------------------------------- + */ + +#ifndef PIPECOM_H +#define PIPECOM_H + +// this file cannot be used from C or C++ any more due to some const additions +// however, if you remove the const, it should work in C also +#ifdef __cplusplus +extern "C" { +#endif + +#include + + +typedef struct PipeCommunication { + FILE *fWrit; + FILE *fRead; + int pid; +} PCom; + + + +PCom *PipeComOpen( char *prog ); +PCom *PipeComOpenArgv( char *prog, char *argv[] ); + +int PipeComSend( PCom *to, const char *line ); +int PipeComSendn( PCom *to, const char *data, int n ); + +int PipeComReceive( PCom *from, char *data, int max ); + +int PipeComClose( PCom *to ); + +int PipeComWaitFor( PCom *from, char *what ); + +#ifdef __cplusplus +} /* ferme extern "C" */ +#endif + +#endif /* PIPECOM_H */