Ilya Zakharevich on Thu, 20 May 1999 01:51:41 -0400 (EDT) |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
[PATCH 2.0.14] Gnuplot plotting enhancement |
The following patch: a) Updates gnuplot support to compatibility with version 3.7; b) Adds option processing to plotterm(), so that plotterm("dumb 79 33") is possible; c) Fixes a bug that plotpointsize() was setting plotpointtype(); d) Makes --graphic=gnuplot ./Configure option selfdocumenting: if it fails, it reports what needs to be done. Enjoy, Ilya --- ./src/graph/plotgnuplot.c.orig Fri Mar 5 02:52:21 1999 +++ ./src/graph/plotgnuplot.c Thu May 20 01:28:00 1999 @@ -12,6 +12,8 @@ # include "pari.h" #include "rect.h" #define croak(str) err(talker,str) +#define SET_OPTIONS_FROM_STRING +#define GNUPLOT_OUTLINE_STDOUT #include "Gnuplot.h" #ifdef __EMX__ @@ -132,15 +134,27 @@ PARI_get_plot(long fatal) long term_set(char *s) { + char *t; + if (*s == 0) s = pari_plot.name; - if (strlen(s) > PLOT_NAME_LEN) + t = s; + while (*t && !(*t == ' ' || *t == '\t' || *s == '\t')) + t++; + if ((t-s) > PLOT_NAME_LEN) err(talker,"too long name \"%s\"for terminal", s); - if (*pari_plot.name && (strcmp(pari_plot.name,s) != 0)) + if (*pari_plot.name + && (strlen(pari_plot.name) != t - s /* Why this? */ + || (strncmp(pari_plot.name, s, t-s) != 0)) ) reset(); - strcpy(pari_plot.name,s); - if (!termset( s )) - err(talker,"error setting terminal \"%s\"", s); + strncpy(pari_plot.name,s,t-s); + pari_plot.name[t-s] = '\0'; + if (!termset( pari_plot.name )) + err(talker,"error setting terminal \"\%s\"", pari_plot.name); + + /* *Needed*, say, by gif output: */ + set_options_from(t); + do_init(); /* Init terminal. */ setpointsize(pointsize); --- ./src/graph/plotport.c.orig Fri Mar 5 02:52:20 1999 +++ ./src/graph/plotport.c Thu May 20 01:23:15 1999 @@ -624,7 +624,7 @@ rectpointsize(long ne, GEN size) /* code PariRect *e = check_rect_init(ne); RectObj *z = (RectObj*) gpmalloc(sizeof(RectObjPS)); - RoNext(z) = 0; RoType(z) = ROt_PTT; + RoNext(z) = 0; RoType(z) = ROt_PTS; RoPTSsize(z) = gtodouble(size); if (!RHead(e)) RHead(e)=RTail(e)=z; else { RoNext(RTail(e))=z; RTail(e)=z; } --- ./src/graph/Gnuplot.h.orig Fri Jan 15 08:02:45 1999 +++ ./src/graph/Gnuplot.h Thu May 20 01:31:04 1999 @@ -47,9 +47,13 @@ #ifndef NO_JUNK_SMALL +/* Compatibility with the old gnuplot: */ extern FILE *outfile; FILE *outfile = stdout; +extern FILE *gpoutfile; +FILE *gpoutfile = stdout; + extern int encoding; int encoding = 0; extern float xoffset; /* x origin */ @@ -319,7 +323,91 @@ extern struct termentry term_tbl[]; #endif /* DYNAMIC_PLOTTING */ +#ifdef SET_OPTIONS_FROM_STRING +/* This sets the tokens for the options */ +void +set_tokens_string(char *start) +{ + char *s = start; + char *tstart; + int is_real, is_integer, has_exp; + + num_tokens = 0; + while (num_tokens < MAX_TOKENS) { + while (*s == ' ' || *s == '\t' || *s == '\n') + s++; + if (!*s) + return; + tstart = s; + is_integer = is_real = ((*s) != 0); + if (*s == '+' || *s == '-') + s++; + has_exp = 0; + while (*s && !(*s == ' ' || *s == '\t' || *s == '\n')) { + if (!(*s <= '9' && *s >= '0')) { + if (*s == '.') { + if (!is_integer) + is_real = 0; + else if (is_integer == 1 && !(s[1] <= '9' && s[1] >= '0')) + is_real = 0; + } else if (*s != 'e' || *s == 'E') { + if (has_exp) + is_real = 0; + has_exp = 1; + if (s[1] == '+' || s[1] == '-') + s++; + } else + is_real = 0; + is_integer = 0; + } else if (is_integer) + is_integer++; + s++; + } + if (is_integer) { + token[num_tokens].is_token = 0; + token[num_tokens].l_val.type = INTGR; + token[num_tokens].l_val.v.int_val = atoi(tstart); + } else if (is_real) { + token[num_tokens].is_token = 0; + token[num_tokens].l_val.type = CMPLX; + token[num_tokens].l_val.v.cmplx_val.real = atof(tstart); + token[num_tokens].l_val.v.cmplx_val.imag = 0; + } else { + token[num_tokens].is_token = 1; + token[num_tokens].start_index = tstart - input_line; + token[num_tokens].length = s - tstart; + } + num_tokens++; + } + if (num_tokens >= MAX_TOKENS) { + char buf[80]; + sprintf(buf, "panic: more than %d tokens for options", MAX_TOKENS); + croak(buf); + } +} + +void +set_options_from(char *s) +{ + set_tokens_string(s); + options(); + c_token = num_tokens = 0; +} +#endif + +#ifdef GNUPLOT_OUTLINE_STDOUT +int +StartOutput() {} +int +EndOutput() {} + +int +OutLine(char *s) +{ + return fprintf(stdout, "%s", s); +} +#endif #ifdef __cplusplus } --- ./Configure~ Fri Mar 5 12:24:26 1999 +++ ./Configure Wed May 19 17:25:20 1999 @@ -416,37 +416,49 @@ if test "$optimization" != profiling; th pth=$libpth # LIB: gnuplot + opth="$pth" + pth="$TOP/gnuplot-$osname-$arch $TOP/gnuplot $pth" + gpth="$pth" lib=gnuplot; . ./locatelib + pth="$opth" gnuplot_libs= case $gnuplot in /*|[c-z]:/*) addgnuplot=gnuplot - lib=png; . ./locatelib - case $png in - /*|[c-z]:/*) - gnuplot_libs="$gnuplot_libs -lpng" - lib=z; . ./locatelib - case $z in - /*|[c-z]:/*) - gnuplot_libs="$gnuplot_libs -lz";; - esac;; - esac - lib=gd; . ./locatelib - case $gd in - /*|[c-z]:/*) gnuplot_libs="$gnuplot_libs -lgd";; - esac - case "$osname" in - os2) - lib=jmgraph; . ./locatelib - lib=vesa; . ./locatelib - case $jmgraph in - /*|[c-z]:/*) - case $vesa in - /*|[c-z]:/*) - gnuplot_libs="$gnuplot_libs -ljmgraph -lvesa";; - esac;; - esac;; - esac;; + for lib in vga vesa jmgraph linuxvga gd png z + do + . ./locatelib + eval "elib=\$$lib" + case $elib in + /*|[c-z]:/*) gnuplot_libs="$gnuplot_libs -l$lib";; + esac + done + if test "$which_graphic_lib" = gnuplot; then + if test -z "$gnuplot_libs"; then + echo "...I expect that no libraries are needed for gnuplot" + else + echo "...I expect that libraries $gnuplot_libs are needed for gnuplot" + fi + fi + ;; + *) + if test "$which_graphic_lib" = gnuplot; then + echo "###" + echo "### Could not find gnuplot library in:" + echo "### ./gnuplot-$osname-$arch ./gnuplot" + echo "### $pth" + echo "###" + case "$osname" in + os2) tlib=gnuplot.a ;; + *) tlib=libgnuplot.a ;; + esac + echo "### You may need to execute" + echo "### ar cr $tlib version.o util.o term.o bitmap.o stdfn.o" + echo "### In the build directory of gnuplot-3.7, and move" + echo "### $tlib to ./gnuplot-$osname-$arch or ./gnuplot subdirs" + echo "###" + fi + ;; esac # LIB: GNU ReadLine @@ -1074,8 +1086,8 @@ EOT fi fi case "$static" in - y) echo "Default is static executable and archive library" ;; - n) echo "Default is dynamic executable and shared library" ;; + y) echo "Default is static executable and archive library, graphic=$which_graphic_lib" ;; + n) echo "Default is dynamic executable and shared library, graphic=$which_graphic_lib" ;; esac # --- ./config/Makefile.SH~ Tue Mar 2 06:34:21 1999 +++ ./config/Makefile.SH Wed May 19 17:25:01 1999 @@ -73,7 +73,7 @@ none) gnuplot) PLOTFILE=plotgnuplot.c PLOTCFLAGS= - GNUPLOT_OBJS="bitmap.o term.o util.o version.o" + GNUPLOT_OBJS="bitmap.o term.o util.o version.o stdfn.o" PLOTLIBS="$gnuplot_libs" plotrunpath= case "$osname" in