[BACK]Return to Gnuplot.h CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / pari-2.2 / src / graph

Annotation of OpenXM_contrib/pari-2.2/src/graph/Gnuplot.h, Revision 1.2

1.2     ! noro        1: /* $Id: Gnuplot.h,v 1.7 2002/06/09 18:49:11 karim Exp $
1.1       noro        2:
                      3: Copyright (C) 2000  The PARI group.
                      4:
                      5: This file is part of the PARI/GP package.
                      6:
                      7: PARI/GP is free software; you can redistribute it and/or modify it under the
                      8: terms of the GNU General Public License as published by the Free Software
                      9: Foundation. It is distributed in the hope that it will be useful, but WITHOUT
                     10: ANY WARRANTY WHATSOEVER.
                     11:
                     12: Check the License for details. You should have received a copy of it, along
                     13: with the package; see the file 'COPYING'. If not, write to the Free Software
                     14: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
                     15:
                     16: /* This header should be included in one C file only! */
                     17:
                     18: #include <stdio.h>
                     19: #include <stdlib.h>
                     20: #include <setjmp.h>
                     21:
                     22: #ifdef __cplusplus
                     23:   extern "C" {
                     24: #endif
                     25:
                     26: /* CAT2:
                     27:  *      This macro catenates 2 tokens together.
                     28:  */
                     29: /* STRINGIFY:
                     30:  *      This macro surrounds its token with double quotes.
                     31:  */
                     32: #ifndef CAT2
                     33: # if 42 == 1
                     34: #  define CAT2(a,b)a/**/b
                     35: #  define CAT3(a,b,c)a/**/b/**/c
                     36: #  define CAT4(a,b,c,d)a/**/b/**/c/**/d
                     37: #  define CAT5(a,b,c,d,e)a/**/b/**/c/**/d/**/e
                     38: #  define STRINGIFY(a)"a"
                     39:                 /* If you can get stringification with catify, tell me how! */
                     40: # endif
                     41: # if 42 == 42
                     42: #  define CAT2(a,b)a ## b
                     43: #  define CAT3(a,b,c)a ## b ## c
                     44: #  define CAT4(a,b,c,d)a ## b ## c ## d
                     45: #  define CAT5(a,b,c,d,e)a ## b ## c ## d ## e
                     46: #  define StGiFy(a)# a
                     47: #  define STRINGIFY(a)StGiFy(a)
                     48: #  define SCAT2(a,b)StGiFy(a) StGiFy(b)
                     49: #  define SCAT3(a,b,c)StGiFy(a) StGiFy(b) StGiFy(c)
                     50: #  define SCAT4(a,b,c,d)StGiFy(a) StGiFy(b) StGiFy(c) StGiFy(d)
                     51: #  define SCAT5(a,b,c,d,e)StGiFy(a) StGiFy(b) StGiFy(c) StGiFy(d) StGiFy(e)
                     52: # endif
                     53: # ifndef CAT2
                     54: #   include "Bletch: How does this C preprocessor catenate tokens?"
                     55: # endif
                     56: #endif /* CAT2 */
                     57:
                     58:
                     59: #define TERM_CAN_MULTIPLOT    1  /* tested if stdout not redirected */
                     60: #define TERM_CANNOT_MULTIPLOT 2  /* tested if stdout is redirected  */
                     61: #define TERM_BINARY           4  /* open output file with "b"       */
                     62:
                     63: #ifndef NO_JUNK_SMALL
                     64:
                     65: /* Compatibility with the old gnuplot: */
                     66: extern  FILE *outfile;
                     67: FILE *outfile = NULL;
                     68:
                     69: extern  FILE *gpoutfile;
                     70: FILE *gpoutfile = NULL;
                     71:
                     72: static outfile_set;
                     73: static void
                     74: set_gpoutfile(void)
                     75: {
                     76:   outfile = stdout;
                     77:   gpoutfile = stdout;
                     78: }
                     79:
                     80: #define SET_OUTFILE (outfile_set++ ? 1 : (set_gpoutfile(), 1))
                     81:
                     82: extern int encoding;
                     83: int        encoding = 0;
                     84: extern float                   xoffset;  /* x origin */
                     85: extern float                   yoffset;  /* y origin */
                     86: float                   xoffset = 0.0;  /* x origin */
                     87: float                   yoffset = 0.0;  /* y origin */
                     88: extern int             multiplot;
                     89: int            multiplot               = 0;
                     90:
                     91: extern char *outstr;
                     92: #define MAX_ID_LEN 50
                     93: /* char        outstr[MAX_ID_LEN+1] = "STDOUT"; */
                     94: char        *outstr = NULL;
                     95: extern double ticscale; /* scale factor for tic marks (was (0..1])*/
                     96: double        ticscale = 1.0; /* scale factor for tic mark */
                     97:
                     98: char *input_line = NULL;
                     99: int inline_num;          /* from command.c */
                    100:
                    101: float xsize=1.0, ysize=1.0;
                    102: double pointsize=1.0;          /* During test! */
                    103:
                    104: int interactive;    /* from plot.c */
                    105: char *infile_name;       /* from plot.c */
                    106: extern char     default_font[];
                    107: char            default_font[MAX_ID_LEN+1] = "\0"; /* Entry added by DJL */
                    108:
                    109: typedef int TBOOLEAN;
                    110:
                    111: enum DATA_TYPES {
                    112:        INTGR, CMPLX
                    113: };
                    114:
                    115: #if !(defined(ATARI)&&defined(__GNUC__)&&defined(_MATH_H)) &&  !(defined(MTOS)&&defined(__GNUC__)&&defined(_MATH_H)) /* FF's math.h has the type already */
                    116: struct cmplx {
                    117:        double real, imag;
                    118: };
                    119: #endif
                    120:
                    121: struct value {
                    122:        enum DATA_TYPES type;
                    123:        union {
                    124:                int int_val;
                    125:                struct cmplx cmplx_val;
                    126:        } v;
                    127: };
                    128:
                    129: struct lexical_unit {  /* produced by scanner */
                    130:        TBOOLEAN is_token;      /* true if token, false if a value */
                    131:        struct value l_val;
                    132:        int start_index;        /* index of first char in token */
                    133:        int length;                     /* length of token in chars */
                    134: };
                    135:
                    136: /* char *token; */
                    137: #define MAX_TOKENS 20
                    138: extern struct lexical_unit *token;
                    139: struct lexical_unit tokens[MAX_TOKENS];        /* We only process options,
                    140:                                           there should not be many */
                    141: struct lexical_unit *token = tokens;
                    142: long c_token = 0, num_tokens = 0;
                    143: char term_options[200] = "";
                    144:
                    145: /* New with 3.7.1: */
                    146:
                    147: #define FIRST_Z_AXIS 0
                    148: #define FIRST_Y_AXIS 1
                    149: #define FIRST_X_AXIS 2
                    150: #define SECOND_Z_AXIS 4 /* for future expansion ;-) */
                    151: #define SECOND_Y_AXIS 5
                    152: #define SECOND_X_AXIS 6
                    153: /* extend list for datatype[] for t,u,v,r though IMHO
                    154:  * they are not relevant to time data [being parametric dummies]
                    155:  */
                    156: #define T_AXIS 3  /* fill gap */
                    157: #define R_AXIS 7  /* never used ? */
                    158: #define U_AXIS 8
                    159: #define V_AXIS 9
                    160:
                    161: #define AXIS_ARRAY_SIZE 10
                    162: #define DATATYPE_ARRAY_SIZE 10
                    163:
                    164: extern double base_array[], log_base_array[];
                    165: extern TBOOLEAN log_array[];
                    166: /* graphics.c */
                    167: extern TBOOLEAN is_3d_plot;
                    168:
                    169: double min_array[AXIS_ARRAY_SIZE], max_array[AXIS_ARRAY_SIZE], base_array[AXIS_ARRAY_SIZE], log_base_array[AXIS_ARRAY_SIZE];
                    170: TBOOLEAN log_array[AXIS_ARRAY_SIZE];
                    171: int xleft, xright, ybot, ytop;
                    172: TBOOLEAN is_3d_plot;
                    173:
                    174: /* End of 3.7.1 additions */
                    175:
                    176: /* 3.7.0-devel additions */
                    177:
                    178: extern float surface_rot_z;
                    179: extern TBOOLEAN polar;
                    180: extern double                  base_log_x, base_log_y, base_log_z;
                    181: extern TBOOLEAN                        is_log_x, is_log_y, is_log_z;
                    182: extern double                  log_base_log_x2, log_base_log_y2;
                    183: extern double base_z;
                    184: extern TBOOLEAN screen_ok;
                    185:
                    186: float surface_rot_z = 30.0;
                    187: TBOOLEAN polar = 0;
                    188: TBOOLEAN is_log_x = 0;
                    189: TBOOLEAN is_log_y = 0;
                    190: TBOOLEAN is_log_z = 0;
                    191: double base_log_x = 0.0;
                    192: double base_log_y = 0.0;
                    193: double base_log_z = 0.0;
                    194: double log_base_log_x = 0.0;
                    195: double log_base_log_y = 0.0;
                    196: double log_base_log_z = 0.0;
                    197: double base_z = 0.0;
                    198: TBOOLEAN screen_ok;
                    199:
                    200: void map3d_xy (double x, double y, double z, unsigned int *xt, unsigned int *yt)
                    201: {
                    202:     croak("Unsupported function map3d_xy called");
                    203: }
                    204:
                    205: /* End of 3.7.0-devel additions */
                    206:
                    207: /* Here are the only missing functions: */
                    208:
                    209: struct value*
                    210: const_express(struct value*v)
                    211: {
                    212:     if (token[c_token].is_token)
                    213:        croak("Expect a number, got a string");
                    214:     *v = token[c_token++].l_val;
                    215:     return v;
                    216: }
                    217:
                    218: void*
                    219: gp_alloc(unsigned long size, char *usage)
                    220: {
                    221:   (void)usage;
                    222:   return malloc(size);
                    223: }
                    224:
                    225: void*
                    226: gp_realloc(void *old, unsigned long size, char *usage)
                    227: {
                    228:   (void)usage;
                    229:   return realloc(old,size);
                    230: }
                    231:
                    232: void
                    233: bail_to_command_line()
                    234: {
                    235:   croak("panic: gnuplot");
                    236: }
                    237:
                    238: #endif /* NO_JUNK_SMALL */
                    239:
                    240: /* Cannot pull the whole plot.h, too many contradictions. */
                    241:
                    242: #ifdef __ZTC__
                    243: typedef int (*FUNC_PTR)(...);
                    244: #else
                    245: typedef int (*FUNC_PTR)();
                    246: #endif
                    247:
                    248: struct TERMENTRY {
                    249:         char *name;
                    250: #if defined(_Windows) && !defined(WIN32)
                    251:         char GPFAR description[80];     /* to make text go in FAR segment */
                    252: #else
                    253:         char *description;
                    254: #endif
                    255:         unsigned int xmax,ymax,v_char,h_char,v_tic,h_tic;
                    256:         FUNC_PTR options,init,reset,text,scale,graphics,move,vector,linetype,
                    257:                 put_text,text_angle,justify_text,point,arrow,set_font,
                    258:                pointsize;
                    259:        int flags;
                    260:         FUNC_PTR suspend,resume,fillbox,linewidth;
                    261: };
                    262:
                    263: #ifdef _Windows
                    264: #  define termentry TERMENTRY far
                    265: #else
                    266: #  define termentry TERMENTRY
                    267: #endif
                    268:
                    269: extern struct termentry *term;
                    270: struct termentry *term;
                    271:
                    272: #define RETVOID
                    273: #define RETINT , 1
                    274:
                    275: #define F_0 void(*)()
                    276: #define F_1 void(*)(int)
                    277: #define F_1I int(*)(int)
                    278: #define F_1D void(*)(double)
                    279: #define F_1IP int(*)(char*)
                    280: #define F_2 void(*)(unsigned int,unsigned int)
                    281: #define F_2D int(*)(double,double)
                    282: #define F_3 void(*)(unsigned int,unsigned int,int)
                    283: #define F_3T void(*)(int,int,char*)
                    284: #define F_4 void(*)(int,int,int,int)
                    285: #define F_5 void(*)(int,int,int,int,int)
                    286:
                    287: #define CALL_G_METH0(method) CALL_G_METH(method,0,(),RETVOID)
                    288: #define CALL_G_METH1(method,arg1) CALL_G_METH(method,1,(arg1),RETVOID)
                    289: #define CALL_G_METH1I(method,arg1) CALL_G_METH(method,1I,(arg1),RETINT)
                    290: #define CALL_G_METH1D(method,arg1) CALL_G_METH(method,1D,(arg1),RETVOID)
                    291: #define CALL_G_METH1IP(method,arg1) CALL_G_METH(method,1IP,(arg1),RETINT)
                    292: #define CALL_G_METH2(method,arg1,arg2) \
                    293:                CALL_G_METH(method,2,((arg1),(arg2)),RETVOID)
                    294: #define CALL_G_METH2D(method,arg1,arg2) \
                    295:                CALL_G_METH(method,2D,((arg1),(arg2)),RETINT)
                    296: #define CALL_G_METH3(method,arg1,arg2,arg3) \
                    297:                CALL_G_METH(method,3,((arg1),(arg2),(arg3)),RETVOID)
                    298: #define CALL_G_METH3T(method,arg1,arg2,arg3) \
                    299:                CALL_G_METH(method,3T,((arg1),(arg2),(arg3)),RETVOID)
                    300: #define CALL_G_METH4(method,arg1,arg2,arg3,arg4) \
                    301:                CALL_G_METH(method,4,((arg1),(arg2),(arg3),(arg4)),RETVOID)
                    302: #define CALL_G_METH5(method,arg1,arg2,arg3,arg4,arg5) \
                    303:                CALL_G_METH(method,5,((arg1),(arg2),(arg3),(arg4),(arg5)),RETVOID)
                    304:
                    305: #define CALL_G_METH(method,mult,args,returnval)    (           \
                    306:        (term==0) ? (                                           \
                    307:         croak("No terminal specified") returnval               \
                    308:        ) :                                                     \
                    309:        (*(CAT2(F_,mult))term->method)args              \
                    310:      )
                    311:
                    312: #define GET_G_FLAG(mask)    (          \
                    313:        (term==0) ? (                                           \
                    314:         croak("No terminal specified") RETINT          \
                    315:        ) :                                                     \
                    316:        (term->flags & (mask)))
                    317:
                    318: #ifdef DONT_POLLUTE_INIT
                    319: #  define gptable_init()       CALL_G_METH0(init)
                    320: #else
                    321: #  define init()               CALL_G_METH0(init)
                    322: #  define gptable_init         init
                    323: #endif
                    324: #define reset()                CALL_G_METH0(reset)
                    325: #define text()         CALL_G_METH0(text)
                    326: #define options()      CALL_G_METH0(options)
                    327: #define graphics()     CALL_G_METH0(graphics)
                    328: #define linetype(lt)   CALL_G_METH1(linetype,lt)
                    329: #define justify_text(mode)     CALL_G_METH1I(justify_text,mode)
                    330: #define text_angle(ang)        CALL_G_METH1I(text_angle,ang)
                    331: #define scale(xs,ys)   CALL_G_METH2D(scale,xs,ys)
                    332: #define move(x,y)      CALL_G_METH2(move,x,y)
                    333: #define vector(x,y)    CALL_G_METH2(vector,x,y)
                    334: #define put_text(x,y,str)      CALL_G_METH3T(put_text,x,y,str)
                    335: #define point(x,y,p)   CALL_G_METH3(point,x,y,p)
                    336: #define arrow(sx,sy,ex,ey,head)        CALL_G_METH5(arrow,sx,sy,ex,ey,head)
                    337: #define set_font(font) CALL_G_METH1IP(set_font,font)
                    338: #define setpointsize(size)     CALL_G_METH1D(pointsize,size)
                    339: #define suspend()      CALL_G_METH0(suspend)
                    340: #define resume()       CALL_G_METH0(resume)
                    341: #define fillbox(sx,sy,ex,ey,head)      CALL_G_METH5(fillbox,sx,sy,ex,ey,head)
                    342: #define linewidth(size)        CALL_G_METH1D(linewidth,size)
                    343: #define can_multiplot()        GET_G_FLAG(TERM_CAN_MULTIPLOT)
                    344: #define cannot_multiplot()     GET_G_FLAG(TERM_CANNOT_MULTIPLOT)
                    345: #define is_binary()    GET_G_FLAG(TERM_BINARY)
                    346:
                    347: #define termprop(prop) (term->prop)
                    348: #define termset(term) my_change_term(term,strlen(term))
                    349:
                    350: struct termentry * change_term(char*,int);
                    351:
                    352: #define TTABLE_STARTPLOT       0
                    353: #define TTABLE_ENDPLOT         1
                    354: #define TTABLE_STARTMPLOT      2
                    355: #define TTABLE_ENDMPLOT                3
                    356: #define TTABLE_INIT            4
                    357: #define TTABLE_LIST            5
                    358: #define TTABLE_COUNT           6
                    359:
                    360: typedef void (*TSET_FP)(char *s);
                    361: typedef void (*TST_END_FP)(void);
                    362: typedef void (*SET_SIZES_t)(double x, double y);
                    363: typedef double (*GET_SIZES_t)(int flag);
                    364: typedef void (*SET_MOUSE_FEEDBACK_RECTAGLE_t)(int term_xmin, int term_xmax,
                    365:                             int term_ymin, int term_ymax,
                    366:                             double plot_xmin, double plot_xmax,
                    367:                             double plot_ymin, double plot_ymax);
                    368:
                    369: struct t_ftable {
                    370:   int loaded;
                    371:   FUNC_PTR change_term_p;
                    372:   TSET_FP term_set_outputp;
                    373:   SET_SIZES_t set_sizesp;
                    374:   GET_SIZES_t get_sizesp;
                    375:   TST_END_FP term_funcs[TTABLE_COUNT];
                    376:   SET_MOUSE_FEEDBACK_RECTAGLE_t mouse_feedback_func;
                    377: };
                    378:
                    379: #ifdef DYNAMIC_PLOTTING                        /* Can load plotting DLL later */
                    380:
                    381: int
                    382: UNKNOWN_null()
                    383: {
                    384:     croak("gnuplot-like plotting environment not loaded yet");
                    385:     return 0;
                    386: }
                    387:
                    388: static void myterm_table_not_loaded_v(void);
                    389: static void myterm_table_not_loaded(char*);
                    390: static int myterm_table_not_loaded_u();
                    391: static void myterm_table_not_loaded_vdd(double x, double y);
                    392: static double myterm_table_not_loaded_di(int flag);
                    393: static void myterm_table_not_loaded_v4i4d(int term_xmin, int term_xmax,
                    394:                             int term_ymin, int term_ymax,
                    395:                             double plot_xmin, double plot_xmax,
                    396:                             double plot_ymin, double plot_ymax);
                    397: #if 0
                    398: static int ftable_warned;
                    399: static void
                    400: tmp_my_term_init
                    401: {
                    402:   if (!warned++)
                    403:      warn("This runtime link with gnuplot-shim does not implement midlevel start/end functions");
                    404:   shim_myinit();
                    405: }
                    406: #endif
                    407:
                    408: static struct t_ftable my_term_ftable =
                    409: {
                    410:        0, &myterm_table_not_loaded_u, &myterm_table_not_loaded,
                    411:        &myterm_table_not_loaded_vdd,
                    412:        &myterm_table_not_loaded_di,
                    413:        {&myterm_table_not_loaded_v, &myterm_table_not_loaded_v,
                    414:         &myterm_table_not_loaded_v, &myterm_table_not_loaded_v,
                    415:         &myterm_table_not_loaded_v, &myterm_table_not_loaded_v},
                    416:        myterm_table_not_loaded_v4i4d
                    417: };
                    418:
                    419: static struct t_ftable *my_term_ftablep = &my_term_ftable;
                    420:
                    421: static void
                    422: myterm_table_not_loaded_v(void)
                    423: {
                    424:     if (!my_term_ftablep->loaded) {
                    425:         UNKNOWN_null();
                    426:        return;
                    427:     }
                    428:     croak("This runtime link with gnuplot-shim does not implement midlevel start/end functions");
                    429: }
                    430:
                    431: static void
                    432: myterm_table_not_loaded(char *s)
                    433: {
                    434:   myterm_table_not_loaded_v();
                    435: }
                    436:
                    437: static void
                    438: myterm_table_not_loaded_vdd(double x, double y)
                    439: {
                    440:   myterm_table_not_loaded_v();
                    441: }
                    442:
                    443: static double
                    444: myterm_table_not_loaded_di(int flag)
                    445: {
                    446:   myterm_table_not_loaded_v();
                    447:   return 0;                    /* NOT REACHED */
                    448: }
                    449:
                    450: static int
                    451: myterm_table_not_loaded_u()
                    452: {
                    453:   myterm_table_not_loaded_v();
                    454:   return 0;
                    455: }
                    456:
                    457: void myterm_table_not_loaded_v4i4d(int term_xmin, int term_xmax,
                    458:                             int term_ymin, int term_ymax,
                    459:                             double plot_xmin, double plot_xmax,
                    460:                             double plot_ymin, double plot_ymax)
                    461: {
                    462:   myterm_table_not_loaded_v();
                    463: }
                    464:
                    465: #  define change_term          (*my_term_ftablep->change_term_p)
                    466: #  define term_set_output      (*my_term_ftablep->term_set_outputp)
                    467: #  define term_start_plot      (*my_term_ftablep->term_funcs[TTABLE_STARTPLOT])
                    468: #  define term_end_plot        (*my_term_ftablep->term_funcs[TTABLE_ENDPLOT])
                    469: #  define term_start_multiplot (*my_term_ftablep->term_funcs[TTABLE_STARTMPLOT])
                    470: #  define term_end_multiplot   (*my_term_ftablep->term_funcs[TTABLE_ENDMPLOT])
                    471: #  define term_init            (*my_term_ftablep->term_funcs[TTABLE_INIT])
                    472: #  define list_terms           (*my_term_ftablep->term_funcs[TTABLE_LIST])
                    473: #  define plotsizes_scale      (*my_term_ftablep->set_sizesp)
                    474: #  define plotsizes_scale_get  (*my_term_ftablep->get_sizesp)
1.2     ! noro      475:
        !           476: #ifdef USE_SET_FEEDBACK_RECTANGLE
        !           477: /* If DLL has it, but was compiled with older Gnuplot.h */
1.1       noro      478: #  define set_mouse_feedback_rectangle (*my_term_ftablep->mouse_feedback_func)
1.2     ! noro      479: #else
        !           480: #  define set_mouse_feedback_rectangle(term_xmin, term_xmax, term_ymin, term_ymax, plot_xmin, plot_xmax, plot_ymin, plot_ymax) \
        !           481:        ((my_term_ftablep->loaded & 2) ?        \
        !           482:         ((*my_term_ftablep->mouse_feedback_func)(term_xmin, term_xmax, term_ymin, term_ymax, plot_xmin, plot_xmax, plot_ymin, plot_ymax), 0) : 0)
        !           483: #endif /* defined USE_SET_FEEDBACK_RECTANGLE */
1.1       noro      484:
                    485: #  define scaled_xmax()        ((int)termprop(xmax)*plotsizes_scale_get(0))
                    486: #  define scaled_ymax()        ((int)termprop(ymax)*plotsizes_scale_get(1))
                    487:
                    488: #define USE_FUNCTION_FROM_TABLE
                    489:
                    490: static struct termentry *
                    491: my_change_term(char*s,int l)
                    492: {
                    493:     SET_OUTFILE;
                    494:     if (!my_term_ftablep->change_term_p)
                    495:        UNKNOWN_null();
                    496:     return term = (struct termentry *)(*my_term_ftablep->change_term_p)(s,l);
                    497: }
                    498:
                    499: #if 0
                    500: static struct termentry dummy_term_tbl[] = {
                    501:     {"unknown", "Unknown terminal type - not a plotting device",
                    502:          100, 100, 1, 1,
                    503:          1, 1, UNKNOWN_null, UNKNOWN_null, UNKNOWN_null,
                    504:          UNKNOWN_null, UNKNOWN_null, UNKNOWN_null, UNKNOWN_null, UNKNOWN_null,
                    505:          UNKNOWN_null, UNKNOWN_null, UNKNOWN_null,
                    506:      UNKNOWN_null, UNKNOWN_null, UNKNOWN_null, UNKNOWN_null, UNKNOWN_null, 0,
                    507:          UNKNOWN_null, UNKNOWN_null, UNKNOWN_null, UNKNOWN_null},
                    508: };
                    509: #endif
                    510:
                    511: #define set_term_funcp(change_p, term_p) set_term_funcp2((change_p), 0)
                    512: /* #define set_term_funcp3(change_p, term_p, tchange) \
                    513:                        set_term_funcp2((change_p), (tchange)) */
                    514:
                    515: /* This function should be called before any graphic code can be used... */
                    516: void
                    517: set_term_funcp2(FUNC_PTR change_p, TSET_FP tchange)
                    518: {
                    519:     SET_OUTFILE;
                    520:     my_term_ftable.change_term_p = change_p;
                    521:     my_term_ftable.loaded = 1;
                    522:     if (tchange) {
                    523:        my_term_ftable.term_set_outputp = tchange;
                    524:     }
                    525: }
                    526:
                    527: /* Used from Math::Pari */
                    528: void
                    529: set_term_funcp3(FUNC_PTR change_p, void *term_p, TSET_FP tchange)
                    530: {
                    531:   set_term_funcp2(change_p, tchange);
                    532: }
                    533:
                    534: void
                    535: set_term_ftable(struct t_ftable *p)
                    536: {
                    537:   SET_OUTFILE;
                    538:   my_term_ftablep = p;
                    539: }
                    540:
                    541: extern struct t_ftable *get_term_ftable();
                    542:
                    543: #else /* !DYNAMIC_PLOTTING */
1.2     ! noro      544: #define set_mouse_feedback_rectangle  mys_mouse_feedback_rectangle
1.1       noro      545:
                    546: extern struct termentry term_tbl[];
                    547: extern double min_array[], max_array[];
                    548: extern int xleft, xright, ybot, ytop;
                    549:
                    550: void
                    551: mys_mouse_feedback_rectangle(int term_xmin, int term_xmax,
                    552:                             int term_ymin, int term_ymax,
                    553:                             double plot_xmin, double plot_xmax,
                    554:                             double plot_ymin, double plot_ymax)
                    555: {
                    556:   xleft = term_xmin, xright = term_xmax;
                    557:   ybot = term_ymin, ytop = term_ymax;
                    558:   min_array[FIRST_X_AXIS] = min_array[SECOND_X_AXIS] = plot_xmin;
                    559:   max_array[FIRST_X_AXIS] = max_array[SECOND_X_AXIS] = plot_xmax;
                    560:   min_array[FIRST_Y_AXIS] = min_array[SECOND_Y_AXIS] = plot_ymin;
                    561:   max_array[FIRST_Y_AXIS] = max_array[SECOND_Y_AXIS] = plot_ymax;
                    562: }
                    563:
                    564: #  define my_change_term       change_term
                    565: #  define my_term_tbl          term_tbl
                    566:
                    567: extern void term_set_output(char *s);
                    568: extern void term_start_plot(void);
                    569: extern void term_end_plot(void);
                    570: extern void term_start_multiplot(void);
                    571: extern void term_end_multiplot(void);
                    572: extern void term_init(void);
                    573: extern void list_terms(void);
                    574:
                    575: static void
                    576: plotsizes_scale(double x, double y)    { xsize=x; ysize=y; }
                    577:
                    578: static double
                    579: plotsizes_get(int flag)        { return (flag ? ysize : xsize); }
                    580:
                    581: struct t_ftable my_term_ftable =
                    582: {
1.2     ! noro      583:        2,              /* bit 2 means it has mys_mouse_feedback_rectangle */
        !           584:        (FUNC_PTR)&change_term, &term_set_output,
1.1       noro      585:        &plotsizes_scale, &plotsizes_get,
                    586:        {&term_start_plot, &term_end_plot,
                    587:         &term_start_multiplot, &term_end_multiplot, &term_init, &list_terms},
                    588:        &mys_mouse_feedback_rectangle
                    589: };
                    590:
                    591: struct t_ftable *get_term_ftable()     { SET_OUTFILE; return &my_term_ftable; }
                    592: void set_term_ftable() { SET_OUTFILE; }
                    593:
                    594: void
                    595: set_term_funcp3(FUNC_PTR change_p, void *term_p, TSET_FP tchange)
                    596: {
                    597:     SET_OUTFILE;
                    598:     (void)term_p;
                    599:     my_term_ftable.change_term_p = change_p;
                    600:     my_term_ftable.loaded = 1;
                    601:     if (tchange) {
                    602:        my_term_ftable.term_set_outputp = tchange;
                    603:     }
                    604: }
                    605:
                    606: #define scaled_xmax()  ((int)termprop(xmax)*xsize)
                    607: #define scaled_ymax()  ((int)termprop(ymax)*ysize)
                    608:
                    609: #endif /* !DYNAMIC_PLOTTING */
                    610:
                    611: #define int_get_term_ftable()  ((IV)get_term_ftable())
                    612: #define int_set_term_ftable(a) (v_set_term_ftable((void*)a))
                    613:
                    614: void
                    615: v_set_term_ftable(void *a) { set_term_ftable((struct t_ftable*)a); }
                    616:
                    617: typedef void (*set_term_ftable_t)(struct t_ftable *p);
                    618: typedef struct t_ftable *(get_term_ftable_t)(void);
                    619:
                    620: extern get_term_ftable_t *get_term_ftable_get(void);
                    621:
                    622: static int shim_set;
                    623:
                    624: void
                    625: setup_gpshim(void) {
                    626: #if 0
                    627:   if (shim_set++)
                    628:     return;
                    629: #endif
                    630:
                    631:   if (!shim_set++) {
                    632: #ifdef DYNAMIC_PLOTTING_RUNTIME_LINK
                    633:     get_term_ftable_t *f = get_term_ftable_get(); /* Resolve the getter */
                    634:
                    635:     if (f)
                    636:        v_set_term_ftable(f());                 /* Get the external table */
                    637: #endif
                    638:
                    639: #ifdef DYNAMIC_PLOTTING_STATIC_LINK
                    640:     void *a = get_term_ftable();               /* Get the external one */
                    641:     v_set_term_ftable(get_term_ftable());
                    642: #endif
                    643:   }
                    644:   SET_OUTFILE;
                    645: }
                    646:
                    647: #ifdef SET_OPTIONS_FROM_STRING
                    648: /* This sets the tokens for the options */
                    649: void
                    650: set_tokens_string(char *start)
                    651: {
                    652:     char *s = start;
                    653:     char *tstart;
                    654:     int is_real, is_integer, has_exp;
                    655:
                    656:     num_tokens = 0;
                    657:     while (num_tokens < MAX_TOKENS) {
                    658:        while (*s == ' ' || *s == '\t' || *s == '\n')
                    659:            s++;
                    660:        if (!*s)
                    661:            return;
                    662:        tstart = s;
                    663:        if (*s == ',') {
                    664:            s++;
                    665:            is_integer = is_real = 0;
                    666:            goto process;
                    667:        }
                    668:        is_integer = is_real = ((*s) != 0);
                    669:        if (*s == '+' || *s == '-')
                    670:            s++;
                    671:        has_exp = 0;
                    672:        while (*s && !(*s == ' ' || *s == '\t' || *s == '\n')) {
                    673:            if (!(*s <= '9' && *s >= '0')) {
                    674:                if (*s == '.') {
                    675:                    if (!is_integer)
                    676:                        is_real = 0;
                    677:                    else if (is_integer == 1 && !(s[1] <= '9' && s[1] >= '0'))
                    678:                        is_real = 0;
                    679:                } else if (*s == 'e' || *s == 'E') {
                    680:                    if (has_exp)
                    681:                        is_real = 0;
                    682:                    has_exp = 1;
                    683:                    if (s[1] == '+' || s[1] == '-')
                    684:                        s++;
                    685:                } else if (*s == ',' && (is_integer || is_real))
                    686:                    break;
                    687:                else
                    688:                    is_real = 0;
                    689:                is_integer = 0;
                    690:            } else if (is_integer)
                    691:                is_integer++;
                    692:            s++;
                    693:        }
                    694:       process:
                    695:        token[num_tokens].start_index = tstart - input_line;
                    696:        token[num_tokens].length = s - tstart;
                    697:        if (is_integer) {
                    698:            token[num_tokens].is_token = 0;
                    699:            token[num_tokens].l_val.type = INTGR;
                    700:            token[num_tokens].l_val.v.int_val = atoi(tstart);
                    701:        } else if (is_real) {
                    702:            token[num_tokens].is_token = 0;
                    703:            token[num_tokens].l_val.type = CMPLX;
                    704:            token[num_tokens].l_val.v.cmplx_val.real = atof(tstart);
                    705:            token[num_tokens].l_val.v.cmplx_val.imag = 0;
                    706:        } else {
                    707:            token[num_tokens].is_token = 1;
                    708:        }
                    709:        num_tokens++;
                    710:     }
                    711:     if (num_tokens >= MAX_TOKENS) {
                    712:        char buf[80];
                    713:        sprintf(buf, "panic: more than %d tokens for options", MAX_TOKENS);
                    714:        croak(buf);
                    715:     }
                    716: }
                    717:
                    718: void
                    719: set_options_from(char *s)
                    720: {
                    721:     char *o = input_line;
                    722:
                    723:     input_line = s;            /* for error reports */
                    724:     set_tokens_string(s);
                    725:     options();
                    726:     input_line = o;
                    727:     c_token = num_tokens = 0;
                    728: }
                    729: #endif
                    730:
                    731: #ifdef GNUPLOT_OUTLINE_STDOUT
                    732: int
                    733: StartOutput() { return 0; }
                    734:
                    735: int
                    736: EndOutput() { return 0; }
                    737:
                    738: int
                    739: OutLine(char *s)
                    740: {
                    741:    return fprintf(stdout, "%s", s);
                    742: }
                    743: #endif
                    744:
                    745: #ifdef __cplusplus
                    746:   }
                    747: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>