Ilya Zakharevich on Mon, 6 May 2002 15:34:32 -0400 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
[PATCH 2.2.2] X11 and gnuplot |
This supports having both GNUPLOT plotting and the builtin-X11 plotting. To switch to GNUPLOT, use plotterm(NAME); to switch back, use "builtin" as NAME. As of today, there is no Configure support for such a build. To compile: a) CFLAGS : add -DBOTH_GNUPLOT_AND_X11 b) Put both plotX$(_O) and plotgnuplot$(_O) to the list of objects; c) have build rules for both plotX$(_O) and plotgnuplot$(_O); Enjoy, Ilya --- ./src/graph/plotX.c-pre-x Mon Mar 19 16:03:58 2001 +++ ./src/graph/plotX.c Sun May 5 21:44:28 2002 @@ -18,6 +18,16 @@ Foundation, Inc., 59 Temple Place - Suit /* HIGH RESOLUTION PLOT */ /* */ /*******************************************************************/ + +#ifdef BOTH_GNUPLOT_AND_X11 /* The switch support in plotgnuplot */ +# define rectdraw0 X11_rectdraw0 +# define term_set X11_term_set +# define PARI_get_plot X11_PARI_get_plot +# define plot_outfile_set X11_plot_outfile_set +# define set_pointsize X11_set_pointsize +# define pari_plot pari_X11plot +#endif + #include "pari.h" #include "rect.h" #include "../language/anal.h" --- ./src/graph/plotgnuplot.c-pre-x Sat May 4 02:01:44 2002 +++ ./src/graph/plotgnuplot.c Sun May 5 18:25:36 2002 @@ -36,8 +36,36 @@ Foundation, Inc., 59 Temple Place - Suit # define DEF_TERM (getenv("DISPLAY") ? "X11" : "dumb") #endif +#ifdef BOTH_GNUPLOT_AND_X11 +# ifdef GNUPLOT_AND_X11_PREFER_GNUPLOT +# define DEFAULT_IS_BUILTIN 0 +# else /* !( defined GNUPLOT_AND_X11_PREFER_GNUPLOT ) */ +# define DEFAULT_IS_BUILTIN 1 +# endif /* defined GNUPLOT_AND_X11_PREFER_GNUPLOT */ +#endif + +# ifdef BOTH_GNUPLOT_AND_X11 +int is_builtin = DEFAULT_IS_BUILTIN; +int X11_init; +static void my_rectdraw0(long *w, long *x, long *y, long lw, long do_free); +# endif + void rectdraw0(long *w, long *x, long *y, long lw, long do_free) +# ifdef BOTH_GNUPLOT_AND_X11 +{ + if (is_builtin) { + X11_rectdraw0(w, x, y, lw, do_free); + return; + } + + my_rectdraw0(w, x, y, lw, do_free); + return; +} + +static void +my_rectdraw0(long *w, long *x, long *y, long lw, long do_free) +# endif /* defined BOTH_GNUPLOT_AND_X11 */ { double *ptx,*pty; long i,j,x0,y0, hjust, vjust, hgap, vgap, hgapsize, vgapsize; @@ -199,11 +227,22 @@ rectdraw0(long *w, long *x, long *y, lon void PARI_get_plot(long fatal) { - (void)fatal; - if (pari_plot.init) { - return; +#ifdef BOTH_GNUPLOT_AND_X11 + if (is_builtin) { + if (X11_init) + return; + if (getenv("DISPLAY")) { + X11_PARI_get_plot(fatal); + X11_init = 1; + return; + } + is_builtin = 0; /* Don't defaut to X11 if no DISPLAY */ } +#endif /* defined BOTH_GNUPLOT_AND_X11 */ + if (pari_plot.init) + return; term_set( DEF_TERM ); + (void)fatal; } @@ -214,6 +253,23 @@ term_set(char *s) double x, y; static int had_error; +#ifdef BOTH_GNUPLOT_AND_X11 + if (is_builtin) { + if (!strcmp(s,"builtin")) + return X11_term_set(s); + is_builtin = 0; + PARI_get_plot(1); + } else if (!strcmp(s,"builtin")) { + is_builtin = 1; + if (!X11_init) { + if (!getenv("DISPLAY")) + croak("The builtin-X11 plotting requires DISPLAY environment variable set"); + X11_PARI_get_plot(1); + X11_init = 1; + } + return X11_term_set(s); + } +#endif /* defined BOTH_GNUPLOT_AND_X11 */ setup_gpshim(); if (*s == 0) s = pari_plot.name; @@ -277,9 +333,13 @@ term_set(char *s) } long -plot_outfile_set(char *s) { +plot_outfile_set(char *s) +{ int normal = (strcmp(s,"-") == 0); + /* Intentionally no check for is_builtin, let it always affect gnuplot: + this way one can set the outfile before switching the terminal... */ + setup_gpshim(); /* Delegate all the hard work to term_set_output() */ @@ -298,6 +358,12 @@ plot_outfile_set(char *s) { void set_pointsize(double d) { +#ifdef BOTH_GNUPLOT_AND_X11 + if (is_builtin) { + X11_set_pointsize(d); + return; + } +#endif /* defined BOTH_GNUPLOT_AND_X11 */ pointsize = d; if (pari_plot.init) setpointsize(d); --- ./src/graph/plotport.c-pre-x Wed Dec 5 11:37:12 2001 +++ ./src/graph/plotport.c Sun May 5 21:45:36 2002 @@ -31,6 +31,8 @@ static void PARI_get_psplot(void); static long current_color[NUMRECT]; PariRect **rectgraph = NULL; PARI_plot pari_plot, pari_psplot; +PARI_plot *pari_plot_engine = &pari_plot; +PARI_plot pari_X11plot; /* Used if BOTH_GNUPLOT_AND_X11 */ long rectpoint_itype = 0; long rectline_itype = 0; --- ./src/graph/rect.h-pre-x Wed Dec 5 11:37:14 2001 +++ ./src/graph/rect.h Sun May 5 18:12:20 2002 @@ -30,13 +30,17 @@ typedef struct PARI_plot { } PARI_plot; extern PARI_plot pari_plot, pari_psplot; +#ifdef BOTH_GNUPLOT_AND_X11 +extern PARI_plot pari_X11plot; +#endif +extern PARI_plot *pari_plot_engine; -#define w_height (pari_plot.height) -#define w_width (pari_plot.width) -#define f_height (pari_plot.fheight) -#define f_width (pari_plot.fwidth) -#define h_unit (pari_plot.hunit) -#define v_unit (pari_plot.vunit) +#define w_height (pari_plot_engine->height) +#define w_width (pari_plot_engine->width) +#define f_height (pari_plot_engine->fheight) +#define f_width (pari_plot_engine->fwidth) +#define h_unit (pari_plot_engine->hunit) +#define v_unit (pari_plot_engine->vunit) #define lmargin (f_width*10) #define rmargin (h_unit - 1) #define tmargin (v_unit - 1)