| Ilya Zakharevich on Sat, 4 May 2002 05:21:09 -0400 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| [PATCH 2.2.2] mneumonics for flags |
This patch improves support of DYNAMIC_PLOTTING with gnuplot: now it
a) always allows specification of the DLL name via $GNUPLOT_DRAW_DLL;
b) If DYNAMIC_PLOTTING_RUNTIME_LINK is not specified at compile
time, and $GNUPLOT_DRAW_DLL is not set, gp will try to locate
Term::Gnuplot Perl module, and use its DLL (at compile time this
behaviour may be switched off by
-DDYNAMIC_PLOTTING_RUNTIME_LINK_NO_PERL, at runtime by setting
$GNUPLOT_DRAW_DLL_NO_PERL);
c) Supports --graphic=gnuplot-dynamic;
Now on most systems Gnuplot-enabled GP can be made by
sh Configure --graphic=gnuplot-dynamic
make gp
make install
perl -MCPAN -e "install Term::Gnuplot"
(tested on OS/2 only as of today). Note that the last step may be
postponed arbitrary late; until done, ploth() and friends will emit a
message with an advice on installation of Term::Gnuplot.
Enjoy,
Ilya
--- ./Configure-pre Wed Dec 19 08:37:50 2001
+++ ./Configure Sat May 4 01:38:18 2002
@@ -122,7 +122,8 @@ Options: some names can be abbreviated t
-v, --verbhelp a longer help message
Build Options:
--host=<arch-osname> target achitecture
- --graphic=<gr> graphic library used (default X11) (none X11 gnuplot)
+ --graphic=<gr> graphic library used (default X11) (none X11 gnuplot
+ gnuplot-dynamic)
Additional developer options:
-g creates debugging version (in Oxxx.dbg)
-pg creates profiling version (in Oxxx.prf)
@@ -445,6 +446,12 @@ if test "$optimization" != profiling; th
# We want these libraries:
#
echo Checking for optional libraries and headers...
+
+# ======== GRAPHICS environment search ==============
+
+# At this moment $which_graphic_lib is either none, or the argument to
+# --graphic option; $graph_cmd is "" unless --graphic option was specified.
+
# LIB: X11
pth=$x11pth
lib=X11; . ./locatelib
@@ -456,6 +463,8 @@ if test "$optimization" != profiling; th
pth=$libpth
# LIB: gnuplot
+# Look for it unconditionally, without read/write of
+# $which_graphic_lib or $graph_cmd
opth="$pth"
pth="$TOP/gnuplot-$osname-$arch $TOP/gnuplot $TOP/../gnuplot-$osname-$arch $TOP/../gnuplot $TOP/../../gnuplot-$osname-$arch $TOP/../../gnuplot $pth"
gpth="$pth"
@@ -505,6 +514,8 @@ if test "$optimization" != profiling; th
;;
esac
+# ======== END of GRAPHICS environment search ==============
+
# LIB: GNU ReadLine
readline_add="$GP_READLINE $TOP/readline-$osname-$arch $TOP/readline"
pth="$readline_add $pth"
@@ -645,10 +656,10 @@ EOM
cat << EOT
==========================================================================
GP contains high resolution plotting functions. Choose among
- none $addX11 $addgnuplot
+ none $addX11 $addgnuplot gnuplot-dynamic
EOT
echo $n ..."Use which graphic library (\"none\" means no hi-res plot) ? $c"
- rep="none $addX11 $addgnuplot";
+ rep="none $addX11 $addgnuplot gnuplot-dynamic";
dflt=$which_graphic_lib; . ./myread
which_graphic_lib=$ans
@@ -702,14 +713,15 @@ EOT
pth=$x11pth;
lib=X11; . ./locatelib
fi ;;
- gnuplot);;
+ gnuplot*) ;;
*)gnuplot=;;
esac
else # fastread = yes
+ # TEST: --graphic was not given, X11 not found, and gnuplot library found
if test "$which_graphic_lib" = none -a -z "$graph_cmd" -a -n "$gnuplot"; then
which_graphic_lib=gnuplot
fi
- if test -z "$X11" -a -z "$gnuplot" -a -z "$readline"; then
+ if test -z "$X11" -a -z "$gnuplot" -a -z "$readline" -a "X$which_graphic_lib" != Xgnuplot-dynamic; then
echo ...none
fi
fi
--- ./config/Makefile.SH-pre Fri Jan 11 01:12:12 2002
+++ ./config/Makefile.SH Sat May 4 01:39:12 2002
@@ -88,6 +88,12 @@ gnuplot)
*) libgnuplot=$gnuplot/libgnuplot.a;;
esac
;;
+gnuplot-dynamic)
+ PLOTFILE=plotgnuplot.c
+ PLOTCFLAGS="-DDYNAMIC_PLOTTING -DDYNAMIC_PLOTTING_RUNTIME_LINK=NULL"
+ PLOTLIBS=
+ plotrunpath=
+ ;;
X11)
PLOTFILE=plotX.c
PLOTCFLAGS=-I$Xincroot
--- ./src/graph/plotgnuplot.c-pre Tue Mar 13 09:56:52 2001
+++ ./src/graph/plotgnuplot.c Sat May 4 02:01:44 2002
@@ -25,6 +25,9 @@ Foundation, Inc., 59 Temple Place - Suit
#define SET_OPTIONS_FROM_STRING
#define GNUPLOT_OUTLINE_STDOUT
#define DONT_POLLUTE_INIT
+
+/* The gnuplot library may reference a function with *this* name */
+#define mys_mouse_feedback_rectangle set_mouse_feedback_rectangle
#include "Gnuplot.h"
#ifdef __EMX__
@@ -300,22 +303,85 @@ set_pointsize(double d)
setpointsize(d);
}
-#ifdef DYNAMIC_PLOTTING_RUNTIME_LINK
+#ifdef HAS_DLOPEN
#include <dlfcn.h>
get_term_ftable_t *
get_term_ftable_get(void) /* Establish runtime link with gnuplot engine */
{
- char *s = getenv("GNUPLOT_DRAW_DLL"), buf[4096];
+ char *s = getenv("GNUPLOT_DRAW_DLL"), *s1, buf[4096];
void *h, *f;
int mode = RTLD_LAZY;
+ char fbuf[2048];
#ifdef RTLD_GLOBAL
mode |= RTLD_GLOBAL;
#endif
+#ifdef DYNAMIC_PLOTTING_RUNTIME_LINK
if (!s)
s = DYNAMIC_PLOTTING_RUNTIME_LINK;
+#endif
+#ifndef DYNAMIC_PLOTTING_RUNTIME_LINK_NO_PERL
+ /* Allow user disabling by setting GNUPLOT_DRAW_DLL_NO_PERL=1 */
+ if (!s && (!(s1 = getenv("GNUPLOT_DRAW_DLL_NO_PERL")) || !atoi(s1))) {
+ char cmdbuf[256];
+ FILE *p;
+ char ext[256];
+ char *sub;
+ char name[256];
+ char *n = "Gnuplot";
+
+ /* Make 2 runs of Perl to shorten the command length */
+ /* Find the directory of the Term::Gnuplot's PM and DLL extension */
+ sprintf(cmdbuf, "perl -MTerm::Gnuplot -MConfig -wle %c"
+ "print $INC{qq(Term/Gnuplot.pm)};print $Config{dlext}%c",
+ SHELL_Q, SHELL_Q);
+ p = popen(cmdbuf, "r");
+ if (!p || !fgets(fbuf, sizeof(fbuf), p) || !fgets(ext, sizeof(ext), p))
+ goto end_find;
+ pclose(p);
+ /* Find the directory of the DLL file */
+ sub = strrchr(fbuf,'/');
+ if (!sub)
+ goto end_find;
+ /* Do as XSLoader */
+ sub[0] = 0;
+ sub = strrchr(fbuf,'/');
+ if (!sub)
+ goto end_find;
+ if (sub - fbuf >= 9 && !strncmp(sub - 9, "/blib/lib",9)) {
+ strcpy(sub - 3,"arch/"); /* Uninstalled module */
+ sub++;
+ }
+ strcpy(sub + 1,"auto/Term/Gnuplot/");
+ /* Find the name of the DLL file */
+ sprintf(cmdbuf, "perl -MDynaLoader -we %c"
+ "package DynaLoader; "
+ "print mod2fname[qw(Term Gnuplot)] if defined &mod2fname%c",
+ SHELL_Q, SHELL_Q);
+ p = popen(cmdbuf, "r");
+ if (p) {
+ if (fgets(name, sizeof(name), p))
+ n = name;
+ pclose(p);
+ }
+ if (strlen(fbuf) + 10 + strlen(n) + strlen(ext) > sizeof(fbuf))
+ croak("Buffer overflow finding gnuplot DLL");
+ strcpy(sub + strlen(sub), n);
+ strcpy(sub + strlen(sub), ".");
+ strcpy(sub + strlen(sub), ext);
+ sub[strlen(sub)-1] = 0; /* Trailing \n of ext */
+ s = fbuf;
+ }
+ end_find:
+#endif
+ if (!s) /* The trailing \n is important: one may put . to the command */
+ croak("Can't find Gnuplot drawing engine DLL,\n\t"
+ "set GNUPLOT_DRAW_DLL environment variable"
+ " to the name of the DLL,\n\t"
+ "or install Perl module Term::Gnuplot, e.g., by running\n\t\t"
+ "perl -MCPAN -e \"install Term::Gnuplot\"\n");
h = dlopen(s, mode);
if (!h) {
sprintf(buf,"Can't load Gnuplot drawing engine from '%s': %s", s, dlerror());
--- ./src/graph/Gnuplot.h-pre Tue Mar 13 09:56:52 2001
+++ ./src/graph/Gnuplot.h Fri May 3 20:50:48 2002
@@ -472,7 +472,15 @@ void myterm_table_not_loaded_v4i4d(int t
# define list_terms (*my_term_ftablep->term_funcs[TTABLE_LIST])
# define plotsizes_scale (*my_term_ftablep->set_sizesp)
# define plotsizes_scale_get (*my_term_ftablep->get_sizesp)
+
+#ifdef USE_SET_FEEDBACK_RECTANGLE
+/* If DLL has it, but was compiled with older Gnuplot.h */
# define set_mouse_feedback_rectangle (*my_term_ftablep->mouse_feedback_func)
+#else
+# define set_mouse_feedback_rectangle(term_xmin, term_xmax, term_ymin, term_ymax, plot_xmin, plot_xmax, plot_ymin, plot_ymax) \
+ ((my_term_ftablep->loaded & 2) ? \
+ ((*my_term_ftablep->mouse_feedback_func)(term_xmin, term_xmax, term_ymin, term_ymax, plot_xmin, plot_xmax, plot_ymin, plot_ymax), 0) : 0)
+#endif /* defined USE_SET_FEEDBACK_RECTANGLE */
# define scaled_xmax() ((int)termprop(xmax)*plotsizes_scale_get(0))
# define scaled_ymax() ((int)termprop(ymax)*plotsizes_scale_get(1))
@@ -571,7 +579,8 @@ plotsizes_get(int flag) { return (flag ?
struct t_ftable my_term_ftable =
{
- 1, (FUNC_PTR)&change_term, &term_set_output,
+ 2, /* bit 2 means it has mys_mouse_feedback_rectangle */
+ (FUNC_PTR)&change_term, &term_set_output,
&plotsizes_scale, &plotsizes_get,
{&term_start_plot, &term_end_plot,
&term_start_multiplot, &term_end_multiplot, &term_init, &list_terms},