[BACK]Return to x11.trm CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gnuplot / term

Annotation of OpenXM_contrib/gnuplot/term/x11.trm, Revision 1.1.1.3

1.1       maekawa     1: /*
1.1.1.3 ! ohara       2:  * $Id: x11.trm,v 1.11.2.4 2002/12/04 19:31:09 lhecking Exp $
1.1       maekawa     3:  *
                      4:  */
                      5:
                      6: /*[
                      7:  * Copyright 1986 - 1993, 1998   Thomas Williams, Colin Kelley
                      8:  *
                      9:  * Permission to use, copy, and distribute this software and its
                     10:  * documentation for any purpose with or without fee is hereby granted,
                     11:  * provided that the above copyright notice appear in all copies and
                     12:  * that both that copyright notice and this permission notice appear
                     13:  * in supporting documentation.
                     14:  *
                     15:  * Permission to modify the software is granted, but not the right to
                     16:  * distribute the complete modified source code.  Modifications are to
                     17:  * be distributed as patches to the released version.  Permission to
                     18:  * distribute binaries produced by compiling modified sources is granted,
                     19:  * provided you
                     20:  *   1. distribute the corresponding source modifications from the
                     21:  *    released version in the form of a patch file along with the binaries,
                     22:  *   2. add special version identification to distinguish your version
                     23:  *    in addition to the base release version number,
                     24:  *   3. provide your name and address as the primary contact for the
                     25:  *    support of your modified version, and
                     26:  *   4. retain our contact information in regard to use of the base
                     27:  *    software.
                     28:  * Permission to distribute the released version of the source code along
                     29:  * with corresponding source modifications in the form of a patch file is
                     30:  * granted with same provisions 2 through 4 for binary distributions.
                     31:  *
                     32:  * This software is provided "as is" without express or implied warranty
                     33:  * to the extent permitted by applicable law.
                     34: ]*/
                     35:
                     36: /*
                     37:  *    x11.trm  --- inboard terminal driver for X11
                     38:  */
                     39:
                     40: #include "driver.h"
                     41:
                     42: #ifdef TERM_REGISTER
                     43: register_term(x11)
                     44: #endif
                     45:
                     46: #ifdef TERM_PROTO
                     47: int X11_args __PROTO((int argc, char *argv[]));
                     48: TERM_PUBLIC void X11_options __PROTO((void));
                     49: TERM_PUBLIC void X11_init __PROTO((void));
                     50: TERM_PUBLIC void X11_graphics __PROTO((void));
                     51: TERM_PUBLIC void X11_text __PROTO((void));
                     52: TERM_PUBLIC void X11_reset __PROTO((void));
                     53: TERM_PUBLIC void X11_move __PROTO((unsigned int x, unsigned int y));
                     54: TERM_PUBLIC void X11_vector __PROTO((unsigned int x, unsigned int y));
                     55: TERM_PUBLIC void X11_linewidth __PROTO((double lw));
                     56: TERM_PUBLIC void X11_pointsize __PROTO((double ps));
                     57: TERM_PUBLIC void X11_linetype __PROTO((int lt));
                     58: TERM_PUBLIC void X11_put_text __PROTO((unsigned int x, unsigned int y, char str[]));
                     59: TERM_PUBLIC int X11_justify_text __PROTO((enum JUSTIFY mode));
                     60: TERM_PUBLIC void X11_point __PROTO((unsigned int x, unsigned int y, int number));
                     61: TERM_PUBLIC void X11_fillbox __PROTO((int style, unsigned int x, unsigned y, unsigned int width, unsigned int height));
                     62: #define X11_XMAX 4096
                     63: #define X11_YMAX 4096
                     64:
                     65: /* approximations for typical font/screen sizes */
                     66: #define X11_VCHAR (X11_YMAX/25)
                     67: #define X11_HCHAR (X11_XMAX/100)
                     68: #define X11_VTIC (X11_YMAX/100)
                     69: #define X11_HTIC (X11_XMAX/150)
                     70: #endif
                     71:
                     72:
                     73: #ifndef TERM_PROTO_ONLY
                     74:
                     75: #ifdef TERM_BODY
1.1.1.2   maekawa    76:
                     77: /* non-zero if '-display' found on command line */
                     78: int X11_Display = 0;
1.1       maekawa    79:
                     80:
                     81: /* sunos 4 uses on_exit() in place of atexit(). If both are missing,
                     82:  * we can probably survive since gnuplot_x11 should detect EOF on
                     83:  * the pipe. Unfortunately, the handlers take different parameters.
                     84:  */
                     85:
                     86: #ifdef NO_ATEXIT
                     87: # define HANDLER_PROTO  __PROTO((int x, void *y))
                     88: # define HANDLER_DECL (x,y) int x; void *y;
                     89: # define HANDLER_PARAMS (0,NULL)
                     90: # ifdef HAVE_ON_EXIT
                     91: #  define atexit(x) on_exit(x, NULL)
                     92: # else
                     93: #  define atexit(x)            /* nowt */
                     94: # endif
                     95: #else /* !NO_ATEXIT */
                     96: # define HANDLER_PROTO __PROTO((void))
                     97: # define HANDLER_DECL   ()
                     98: # define HANDLER_PARAMS ()
                     99: #endif
                    100:
                    101: static void X11_atexit HANDLER_PROTO;
                    102:
1.1.1.2   maekawa   103: /* Merged the old char X11_opts[] and int X11_optarg[]
                    104:  * into one array of structs.
                    105:  * Loosely based on XrmOptionDescRec, the use of which
                    106:  * would probably be overkill here. */
                    107: typedef enum { hasNoArg, hasArg } OptionArg;
                    108:
                    109: static struct x11opt {
                    110:     const char *option;        /* Name of option */
                    111:     OptionArg arg;     /* Whether option has argument */
                    112: }  X11_opts[] =
                    113: {
                    114:    { "-mono", hasNoArg }, { "-gray", hasNoArg }, { "-clear", hasNoArg },
                    115:    { "-tvtwm", hasNoArg }, { "-pointsize", hasArg },
                    116:    { "-iconic", hasNoArg }, { "-rv", hasNoArg },
                    117:    { "-reverse", hasNoArg }, { "+rv", hasNoArg },
                    118:    { "-synchronous", hasNoArg },
                    119:    { "-display", hasArg }, { "-geometry", hasArg }, { "-bg", hasArg },
                    120:    { "-background", hasArg }, { "-bd", hasArg },
                    121:    { "-bordercolor", hasArg }, { "-bw", hasArg },
                    122:    { "-borderwidth", hasArg }, { "-fg", hasArg },
                    123:    { "-foreground", hasArg }, { "-fn", hasArg }, { "-font", hasArg },
                    124:    { "-name", hasArg },
                    125:    { "-selectionTimeout", hasArg }, { "-title", hasArg },
                    126:    { "-xnllanguage", hasArg }, { "-xrm", hasArg },
                    127:    { "-raise", hasNoArg }, { "-noraise", hasNoArg },
                    128:    { "-persist", hasNoArg }
1.1       maekawa   129: };
                    130:
                    131: #define X11_nopts (sizeof(X11_opts) / sizeof(X11_opts[0]))
                    132:
                    133: static FILE *X11_ipc;
1.1.1.2   maekawa   134:
                    135: static char **xargv = (char **)NULL;
                    136: static char *optvec[2*X11_nopts+1];
                    137: # ifdef OS2
                    138: static char X11_command[] = "gnuplot_x11.exe";
                    139: # else
                    140: static char X11_command[] = "gnuplot_x11";
                    141: # endif /* !OS/2 */
1.1       maekawa   142:
                    143: /*   X11_args - scan gnuplot command line for standard X Toolkit options
                    144:  * called from plot.c so must not be TERM_PUBLIC (which may be static)
                    145:  */
                    146:
1.1.1.2   maekawa   147: int
                    148: X11_args(argc, argv)
1.1       maekawa   149: int argc;
                    150: char *argv[];
                    151: {
1.1.1.2   maekawa   152:     int nx11 = 0, i = 0, n;
                    153:
                    154:     xargv = (char **) gp_alloc (argc*sizeof(char *), "<xargv>");
1.1       maekawa   155:
1.1.1.2   maekawa   156:     if (!xargv) {
                    157:        fputs ("not enough memory to copy argv - quitting\n", stderr);
                    158:        exit (EXIT_FAILURE);
                    159:     }
                    160:
                    161:     /* We make a copy of the argument vector because
                    162:      * argv is modified later. */
                    163:     memcpy (xargv, argv, argc*sizeof(char *));
                    164:     optvec[i++] = X11_command;
                    165:
                    166:     while (++argv, ++xargv, --argc > 0) {
1.1       maekawa   167:        for (n = 0; n < X11_nopts; n++) {
1.1.1.2   maekawa   168:            if (strcmp(*argv, X11_opts[n].option) == 0) {
                    169:                optvec[i++] = *xargv;
1.1       maekawa   170:                if (strcmp(*argv, "-display") == 0)
                    171:                    X11_Display++;
1.1.1.2   maekawa   172:                if (X11_opts[n].arg == hasArg) {
1.1       maekawa   173:                    if (--argc <= 0)
1.1.1.2   maekawa   174:                        return nx11;
                    175:                    optvec[i++] = *++xargv, ++argv;
1.1       maekawa   176:                    nx11++;
                    177:                }
                    178:                nx11++;
                    179:                break;
                    180:            }
                    181:        }
                    182:        if (n == X11_nopts)
                    183:            break;
                    184:     }
1.1.1.2   maekawa   185:
1.1       maekawa   186:     return (nx11);
                    187: }
                    188:
                    189:
                    190: static unsigned int X11_plot_number;
                    191:
1.1.1.2   maekawa   192: TERM_PUBLIC void
                    193: X11_options()
1.1       maekawa   194: {
                    195:     if (almost_equals(c_token, "res$et")) {
                    196:        X11_atexit HANDLER_PARAMS;      /* tell gnuplot_x11 to shut down */
                    197:        ++c_token;
                    198:     }
                    199:     if (!END_OF_COMMAND) {
                    200:        struct value a;
                    201:        X11_plot_number = (int) real(const_express(&a));
                    202:        /* let gnuplot_x11 check range */
                    203:     }
                    204:     sprintf(term_options, "%d", X11_plot_number);
                    205: }
                    206:
                    207: /*-----------------------------------------------------------------------------
                    208:  *   Three different versions of the remainder of the X11 terminal driver
                    209:  *   are provided to support three different types of IPC with the
                    210:  *   gnuplot_x11 outboard terminal driver:
                    211:  *
                    212:  *   DEFAULT_X11:      popen() pipe for most un*x platforms
                    213:  *
                    214:  *   CRIPPLED_SELECT : file IPC for un*x platforms with incomplete or faulty
                    215:  *                     implementation of BSD select()
                    216:  *
                    217:  *   VMS :             mailbox/spawn IPC
                    218:  *---------------------------------------------------------------------------*/
                    219:
                    220: #define DEFAULT_X11
                    221: #if defined(VMS) || defined(CRIPPLED_SELECT)
1.1.1.2   maekawa   222: # undef DEFAULT_X11
1.1       maekawa   223: #endif
                    224: #if defined(VMS) && defined(CRIPPLED_SELECT)
                    225: Error.Incompatible options.
                    226: #endif
                    227:
                    228: /* we do not want to have to duplicate all the code, so we
                    229:  * do most of it with macros.
                    230:  * PRINT0(format), PRINT1(format, p1), PRINT2(format, p1, p2) etc
                    231:  * also  FLUSH0(format), etc, which do an additional flush
                    232:  */
                    233:
                    234:
                    235: #ifdef DEFAULT_X11
                    236: /*-----------------------------------------------------------------------------
                    237:  *   DEFAULT_X11 popen() pipe IPC
                    238:  *---------------------------------------------------------------------------*/
                    239:
1.1.1.2   maekawa   240: static void
                    241: X11_atexit HANDLER_DECL
                    242: {
                    243:     if (X11_ipc) {
1.1       maekawa   244:        fputs("R\n", X11_ipc);
                    245:        fclose(X11_ipc);
                    246:        /* dont wait(), since they might be -persist */
                    247:        X11_ipc = NULL;
                    248:     }
1.1.1.2   maekawa   249: }
                    250:
                    251: TERM_PUBLIC void
                    252: X11_init()
1.1       maekawa   253: {
1.1.1.2   maekawa   254:     static int been_here = 0;
                    255:
1.1       maekawa   256:     if (!X11_ipc) {
                    257:        /* first time through or after a reset */
                    258: #if defined(OSK) || defined(OS2)
                    259:        /* OS-9 popen() does not block on close for child to end, so
                    260:         * we can safely use it here
                    261:         */
                    262:        X11_ipc = popen(X11_command, "w");
1.1.1.2   maekawa   263: #else /* !(OSK || OS/2) */
1.1       maekawa   264:        int fdes[2];
1.1.1.2   maekawa   265:
                    266:        if (pipe(fdes)) perror("pipe() failed:");
                    267:
1.1       maekawa   268:        if (fork() == 0) {
                    269:            /* child */
                    270:            close(fdes[1]);
                    271:            dup2(fdes[0], 0);   /* stdin from pipe */
1.1.1.2   maekawa   272:            execvp(X11_command, optvec);
1.1       maekawa   273:            /* if we get here, something went wrong */
                    274:            perror("exec failed");
1.1.1.2   maekawa   275:            exit(EXIT_FAILURE);
1.1       maekawa   276:        }
                    277:        /* parent */
                    278:        close(fdes[0]);         /* read end of pipe */
                    279:        X11_ipc = fdopen(fdes[1], "w");
1.1.1.2   maekawa   280: #endif /* !(OSK || OS/2) */
1.1       maekawa   281:     }
                    282:
1.1.1.2   maekawa   283:     if (!been_here) {
                    284:        atexit(X11_atexit);
                    285:        been_here++;
                    286:     }
1.1       maekawa   287: }
                    288:
1.1.1.2   maekawa   289: TERM_PUBLIC void
                    290: X11_reset()
1.1       maekawa   291: {
                    292:     /* leave the pipe alone, until exit or  set term x11 reset */
                    293: }
                    294:
                    295: #define PRINT0(fmt)          fprintf(X11_ipc, fmt)
                    296: #define PRINT1(fmt,p1)       fprintf(X11_ipc, fmt,p1)
                    297: #define PRINT2(fmt,p1,p2)    fprintf(X11_ipc, fmt,p1,p2)
                    298: #define PRINT3(fmt,p1,p2,p3) fprintf(X11_ipc, fmt,p1,p2,p3)
                    299: #define PRINT4(fmt,p1,p2,p3,p4) fprintf(X11_ipc, fmt,p1,p2,p3,p4)
                    300: #define PRINT5(fmt,p1,p2,p3,p4,p5) fprintf(X11_ipc, fmt,p1,p2,p3,p4,p5)
                    301:
                    302: #define FFLUSH()             fflush(X11_ipc)
                    303:
                    304: #define BEFORE_GRAPHICS                /* nowt */
                    305: #define AFTER_TEXT             /* nowt */
                    306:
                    307:
1.1.1.2   maekawa   308: #elif defined(CRIPPLED_SELECT)
1.1       maekawa   309:
                    310: /* PLEASE CAN SOMEONE CHECK THAT THIS STILL WORKS !!! */
                    311:
                    312: /*-----------------------------------------------------------------------------
                    313:  *   CRIPPLED_SELECT file IPC
                    314:  *---------------------------------------------------------------------------*/
                    315:
                    316: static char X11_tmp[32], X11_tmp0[32], X11_shutdown[32];
                    317: static int X11_pid;
                    318:
1.1.1.2   maekawa   319: TERM_PUBLIC void
                    320: X11_init()
1.1       maekawa   321: {
                    322:     if (!(X11_pid = fork())) {
1.1.1.2   maekawa   323:        execvp(X11_command, optvec);
1.1       maekawa   324:        _exit(1);
                    325:     }
                    326:     sprintf(X11_tmp, "/tmp/Gnuplot_%d", X11_pid);
                    327:     sprintf(X11_tmp0, "%s-", X11_tmp);
                    328:     sprintf(X11_shutdown, "echo R >%s", X11_tmp);
                    329: }
                    330:
1.1.1.2   maekawa   331: TERM_PUBLIC void
                    332: X11_reset()
1.1       maekawa   333: {
                    334:     system(X11_shutdown);
                    335: }
                    336:
                    337: #define BEFORE_GRAPHICS \
                    338:  if (!(X11_ipc = fopen(X11_tmp0, "w"))) { \
                    339:    perror(X11_tmp0); system(X11_shutdown); exit(1); \
                    340:  }
                    341:
                    342: #define AFTER_TEXT \
                    343:  { fclose(X11_ipc); rename(X11_tmp0, X11_tmp); }
                    344:
                    345: #define PRINT0(fmt)          fprintf(X11_ipc, fmt)
                    346: #define PRINT1(fmt,p1)       fprintf(X11_ipc, fmt,p1)
                    347: #define PRINT2(fmt,p1,p2)    fprintf(X11_ipc, fmt,p1,p2)
                    348: #define PRINT3(fmt,p1,p2,p3) fprintf(X11_ipc, fmt,p1,p2,p3)
                    349: #define PRINT4(fmt,p1,p2,p3,p4) fprintf(X11_ipc, fmt,p1,p2,p3,p4)
                    350: #define PRINT5(fmt,p1,p2,p3,p4,p5) fprintf(X11_ipc, fmt,p1,p2,p3,p4,p5)
                    351: #define FFLUSH()             fflush(X11_ipc)
                    352:
1.1.1.2   maekawa   353: static void
                    354: X11_atexit HANDLER_DECL { /* WHAT SHOULD I DO ? */
1.1       maekawa   355: }
                    356:
1.1.1.2   maekawa   357: #elif defined(VMS)
1.1       maekawa   358: /*-----------------------------------------------------------------------------
                    359:  *   VMS mailbox/spawn IPC - Yehavi Bourvine - YEHAVI@VMS.HUJI.AC.IL
                    360:  *---------------------------------------------------------------------------*/
                    361: #include <iodef.h>
                    362: #include <descrip.h>
                    363: #include <dvidef.h>
                    364: #ifdef __DECC
                    365: #include <lib$routines.h>
                    366: #include <starlet.h>
                    367: #endif
                    368: #ifdef __GNUC__
                    369: #include <errno.h>
                    370: #else
                    371: int vaxc$errno;
                    372: #endif
                    373:
                    374: #define SS$_NORMAL 1           /* or include <ssdef.h> for all SS$_ def's */
                    375:
                    376: #define MBXMXMSG 128           /* DEFMBXMXMSG is set by SYSGEN */
                    377:
                    378: static short X11_channel;
                    379:
                    380: struct iosb {
                    381:     unsigned short stat;
                    382:     unsigned short count;
                    383:     unsigned long info;
                    384: };
                    385:
                    386:
1.1.1.2   maekawa   387: TERM_PUBLIC void
                    388: X11_init()
1.1       maekawa   389: {
                    390:
                    391:     struct iosb iosb;
                    392:
                    393:     static char devnam_string[64];
                    394:     static $DESCRIPTOR(devnam, devnam_string);
                    395:
                    396:     struct {
                    397:        short int buf_len;
                    398:        short int item;
                    399:        char *buf_addr;
                    400:        unsigned short int *ret_len;
                    401:        int end;
                    402:     } item_list = {
                    403:        devnam.dsc$w_length, DVI$_DEVNAM,
                    404:            devnam.dsc$a_pointer,
                    405:            &devnam.dsc$w_length, 0
                    406:     };
1.1.1.2   maekawa   407: #define CMDLEN 1024
                    408:     char cmdline[CMDLEN], *cmdp;
                    409:     int optindex;
1.1       maekawa   410:
                    411:     if (!X11_channel) {
                    412:        int one = 1;
                    413:
                    414:        /* Create a descriptor for the command line that starts
                    415:           GNUPLOT_X11. $DESCRIP doesn't work in this context... */
                    416:
1.1.1.2   maekawa   417:        /* FIXME!
                    418:         * This does not work anymore since X11 option passing has been
                    419:         * changed to use execvp() in the DEFAULT_X11 case
                    420:         */
1.1       maekawa   421:        struct dsc$descriptor_s pgmdsc =
                    422:        {0, DSC$K_DTYPE_T,
                    423:         DSC$K_CLASS_S, 0};
1.1.1.2   maekawa   424:         optindex = 0;
                    425:         strcpy (cmdline, optvec[optindex]);
                    426:         cmdp = cmdline + strlen (optvec[optindex]);
                    427:         while (optvec[++optindex] != NULL) {
                    428:           *cmdp++ = ' ';
                    429:           *cmdp++ = '\"';
                    430:           strcpy (cmdp, optvec[optindex]);
                    431:           cmdp += strlen (optvec[optindex]);
                    432:           *cmdp++ = '\"';
                    433:         }
                    434:        pgmdsc.dsc$w_length = cmdp-cmdline;
                    435:        pgmdsc.dsc$a_pointer = cmdline;
1.1       maekawa   436:
                    437:        /* Create a mailbox which will be used as a pipe for commands to the
1.1.1.2   maekawa   438:         * subprocess.  What we'll write to it will be read by the subprocess
                    439:         * as its STDIN.  Use an unnamed mailbox and refer to it by its device
                    440:         * number */
1.1       maekawa   441:
                    442:        vaxc$errno = sys$crembx(0, &X11_channel, MBXMXMSG, MBXMXMSG, 0, 0, 0, 0);
                    443:        if ((vaxc$errno & SS$_NORMAL) != SS$_NORMAL) {
                    444:            printf("SYS$CreMbx failed with status=%d\r\n", vaxc$errno);
                    445:            os_error("sys$crembx failed", NO_CARET);
                    446:        }
                    447:        vaxc$errno = sys$getdviw(0, X11_channel, 0, &item_list, &iosb, 0, 0, 0);
                    448:        if ((vaxc$errno & SS$_NORMAL) == SS$_NORMAL)
                    449:            vaxc$errno = iosb.stat;
                    450:        if ((vaxc$errno & SS$_NORMAL) != SS$_NORMAL) {
                    451:            printf("SYS$Getdviw failed with status=%d\r\n", vaxc$errno);
                    452:            sys$dassgn(X11_channel);
                    453:            X11_channel = 0;
                    454:            os_error("sys$getdviw failed", NO_CARET);
                    455:        }
                    456:        /* Create a subprocess whose input is this mailbox. */
                    457:        vaxc$errno = lib$spawn(&pgmdsc, &devnam, 0, &one, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                    458:        if ((vaxc$errno & SS$_NORMAL) != SS$_NORMAL) {
                    459:            printf("LIB$SPAWN failed with status=%d\r\n", vaxc$errno);
                    460:            sys$dassgn(X11_channel);
                    461:            X11_channel = 0;
                    462:            os_error("lib$spawn failed", NO_CARET);
                    463:        }
                    464:     } {
                    465:        static int been_here = 0;
                    466:        if (!been_here) {
                    467:            atexit(X11_atexit);
                    468:            been_here = 1;
                    469:        }
                    470:     }
                    471: }
                    472:
                    473:
                    474: /*   We use $QIO in order to avoid buffering problems, although it might
                    475:  *   work  as well with simple Fprintf calls.
                    476:  */
                    477:
                    478: #define GO(x) \
                    479: { \
                    480:    char buffer[512]; int status; struct iosb iosb;\
                    481:    sprintf x; \
                    482:    if (strlen(buffer) >= MBXMXMSG )  { \
                    483:      printf("buffer contents (%d char) catenated to mailbox size (%d bytes)\n", \
                    484:      strlen(buffer), MBXMXMSG); \
                    485:      buffer[MBXMXMSG-1] = '\0';\
                    486:      printf("%s\n", buffer); \
                    487:    } \
                    488:    status = sys$qiow(0, X11_channel, IO$_WRITEVBLK, &iosb, 0, 0, buffer, strlen(buffer), 0, 0, 0, 0); \
                    489:    if ((status & SS$_NORMAL) == SS$_NORMAL) status = iosb.stat; \
                    490:    if((status & SS$_NORMAL) != SS$_NORMAL) exit(status); \
                    491:  }
                    492:
                    493: #define PRINT0(fmt)          GO( (buffer, fmt) )
                    494: #define PRINT1(fmt,p1)       GO( (buffer, fmt,p1) )
                    495: #define PRINT2(fmt,p1,p2)    GO( (buffer, fmt,p1,p2) )
                    496: #define PRINT3(fmt,p1,p2,p3) GO( (buffer, fmt,p1,p2,p3) )
                    497: #define PRINT4(fmt,p1,p2,p3,p4) GO( (buffer, fmt,p1,p2,p3,p4) )
                    498: #define PRINT5(fmt,p1,p2,p3,p4,p5) GO( (buffer, fmt,p1,p2,p3,p4,p5) )
                    499:
                    500: #define FFLUSH()               /* nowt */
                    501: #define BEFORE_GRAPHICS                /* nowt */
                    502: #define AFTER_TEXT             /* nowt */
                    503:
1.1.1.2   maekawa   504: static void
                    505: X11_atexit HANDLER_DECL
                    506: {
                    507:     if (X11_channel) {
1.1       maekawa   508:        PRINT0("R\n");
                    509:        sleep(2);               /* Wait for subprocess to finish */
                    510:        sys$dassgn(X11_channel);
                    511:        X11_channel = 0;
                    512:     }
1.1.1.2   maekawa   513: }
                    514:
                    515: TERM_PUBLIC void
                    516: X11_reset()
1.1       maekawa   517: {
                    518:     /* do nothing until exit */
                    519: }
                    520:
1.1.1.2   maekawa   521: #else /* !VMS */
                    522: You lose.
                    523: #endif /* !VMS */
1.1       maekawa   524:
                    525:
                    526: /* common stuff, using macros defined above */
                    527:
                    528:
1.1.1.2   maekawa   529: TERM_PUBLIC void
                    530: X11_graphics()
1.1       maekawa   531: {
                    532:     BEFORE_GRAPHICS;           /* kludge for crippled select */
                    533:
1.1.1.2   maekawa   534:     /* for VMS sake, keep as separate prints */
                    535:     PRINT1("G%d\n", X11_plot_number);
1.1       maekawa   536:
                    537: #ifdef ULTRIX_KLUDGE
                    538:     fflush(X11_ipc);
                    539: #endif
                    540:
                    541: }
                    542:
1.1.1.2   maekawa   543: TERM_PUBLIC void
                    544: X11_text()
1.1       maekawa   545: {
                    546:     PRINT0("E\n");
                    547:     FFLUSH();
                    548: #ifdef ULTRIX_KLUDGE
                    549:     PRINT0("E\n");
                    550:     FFLUSH();
                    551: #endif
                    552:
                    553:     AFTER_TEXT;                        /* kludge for crippled select */
                    554: }
                    555:
                    556:
1.1.1.2   maekawa   557: TERM_PUBLIC void
                    558: X11_move(x, y)
1.1       maekawa   559: unsigned int x, y;
                    560: {
                    561:     PRINT2("M%04d%04d\n", x, y);
                    562: }
                    563:
1.1.1.2   maekawa   564: TERM_PUBLIC void
                    565: X11_vector(x, y)
1.1       maekawa   566: unsigned int x, y;
                    567: {
                    568:     PRINT2("V%04d%04d\n", x, y);
                    569: }
                    570:
1.1.1.2   maekawa   571: TERM_PUBLIC void
                    572: X11_pointsize(ps)
1.1       maekawa   573: double ps;
                    574: {
                    575:     PRINT2("P7%04d%04d\n",     /* size of point symbols */
                    576:           (int) (term->h_tic * ps * 0.5), (int) (term->v_tic * ps * 0.5));
                    577: }
                    578:
1.1.1.2   maekawa   579: TERM_PUBLIC void
                    580: X11_linewidth(lw)
1.1       maekawa   581: double lw;
                    582: {
                    583:     PRINT1("W%04d\n", (int) lw);
                    584: }
                    585:
1.1.1.2   maekawa   586: TERM_PUBLIC void
                    587: X11_linetype(lt)
1.1       maekawa   588: int lt;
                    589: {
                    590:     PRINT1("L%04d\n", lt);
                    591: }
                    592:
1.1.1.2   maekawa   593: TERM_PUBLIC void
                    594: X11_put_text(x, y, str)
1.1       maekawa   595: unsigned int x, y;
                    596: char str[];
                    597: {
                    598:     /* badly outrange labels can overflow into text field */
                    599:     if (x < 10000 && y < 10000) {
                    600:        PRINT3("T%04d%04d%s\n", x, y, str);
                    601:     }
                    602: }
                    603:
1.1.1.2   maekawa   604: TERM_PUBLIC int
                    605: X11_justify_text(mode)
1.1       maekawa   606: enum JUSTIFY mode;
                    607: {
                    608:     PRINT1("J%04d\n", mode);
                    609:     return (TRUE);
                    610: }
                    611:
1.1.1.2   maekawa   612: TERM_PUBLIC void
                    613: X11_point(x, y, number)
1.1       maekawa   614: unsigned int x, y;
                    615: int number;
                    616: {
                    617:     if (number >= 0)
                    618:        number %= POINT_TYPES;
                    619:     number += 1;
                    620:     PRINT3("P%01d%04d%04d\n", number, x, y);
                    621: }
                    622:
1.1.1.2   maekawa   623: TERM_PUBLIC void
                    624: X11_fillbox(style, x, y, w, h)
1.1       maekawa   625: int style;
                    626: unsigned int x, y, w, h;
                    627: {
                    628:     PRINT5("F%04d%04u%04u%04u%04u\n", style, x, y, w, h);
                    629: }
                    630:
                    631: #endif /* TERM_BODY */
                    632:
                    633: #ifdef TERM_TABLE
                    634:
                    635: TERM_TABLE_START(x11_driver)
                    636:     "x11", "X11 Window System",
                    637:     X11_XMAX, X11_YMAX, X11_VCHAR, X11_HCHAR,
                    638:     X11_VTIC, X11_HTIC, X11_options, X11_init, X11_reset,
                    639:     X11_text, null_scale, X11_graphics, X11_move, X11_vector,
                    640:     X11_linetype, X11_put_text, null_text_angle,
                    641:     X11_justify_text, X11_point, do_arrow, set_font_null,
                    642:     X11_pointsize, TERM_CAN_MULTIPLOT,
                    643:     X11_text /* suspend can use same routine */ , 0 /* resume */ ,
                    644:     X11_fillbox, X11_linewidth
                    645: TERM_TABLE_END(x11_driver)
                    646:
                    647: #undef LAST_TERM
                    648: #define LAST_TERM x11_driver
                    649:
                    650: TERM_TABLE_START(X11_driver)
                    651:     "X11", "X11 Window System (identical to x11)",
                    652:     X11_XMAX, X11_YMAX, X11_VCHAR, X11_HCHAR,
                    653:     X11_VTIC, X11_HTIC, X11_options, X11_init, X11_reset,
                    654:     X11_text, null_scale, X11_graphics, X11_move, X11_vector,
                    655:     X11_linetype, X11_put_text, null_text_angle,
                    656:     X11_justify_text, X11_point, do_arrow, set_font_null,
                    657:     X11_pointsize, TERM_CAN_MULTIPLOT,
                    658:     X11_text /* suspend can use same routine */ , 0 /* resume */ ,
                    659:     X11_fillbox, X11_linewidth
                    660: TERM_TABLE_END(X11_driver)
                    661:
                    662: #undef LAST_TERM
                    663: #define LAST_TERM x11_driver
                    664:
                    665: #endif /* TERM_TABLE */
                    666: #endif /* TERM_PROTO_ONLY */
                    667:
                    668:
                    669: #ifdef TERM_HELP
                    670: START_HELP(x11)
                    671: "1 x11",
                    672: "?commands set terminal x11",
                    673: "?set terminal x11",
                    674: "?set term x11",
                    675: "?terminal x11",
                    676: "?term x11",
                    677: "?x11",
                    678: "?X11",
                    679: " `gnuplot` provides the `x11` terminal type for use with X servers.  This",
                    680: " terminal type is set automatically at startup if the `DISPLAY` environment",
                    681: " variable is set, if the `TERM` environment variable is set to `xterm`, or",
                    682: " if the `-display` command line option is used.",
                    683: "",
                    684: " Syntax:",
                    685: "       set terminal x11 {reset} {<n>}",
                    686: "",
                    687: " Multiple plot windows are supported: `set terminal x11 <n>` directs the",
                    688: " output to plot window number n.  If n>0, the terminal number will be",
                    689: " appended to the window title and the icon will be labeled `gplt <n>`.",
                    690: " The active window may distinguished by a change in cursor (from default",
                    691: " to crosshair.)",
                    692: "",
                    693: " Plot windows remain open even when the `gnuplot` driver is changed to a",
                    694: " different device.  A plot window can be closed by pressing the letter q",
                    695: " while that window has input focus, or by choosing `close` from a window",
                    696: " manager menu.  All plot windows can be closed by specifying `reset`, which",
                    697: " actually terminates the subprocess which maintains the windows (unless",
                    698: " `-persist` was specified).",
                    699: "",
                    700: " Plot windows will automatically be closed at the end of the session",
                    701: " unless the `-persist` option was given.",
                    702: "",
                    703: " The size or aspect ratio of a plot may be changed by resizing the `gnuplot`",
                    704: " window.",
                    705: "",
                    706: " Linewidths and pointsizes may be changed from within `gnuplot` with",
                    707: " `set linestyle`.",
                    708: "",
                    709: " For terminal type `x11`, `gnuplot` accepts (when initialized) the standard",
                    710: " X Toolkit options and resources such as geometry, font, and name from the",
                    711: " command line arguments or a configuration file.  See the X(1) man page",
                    712: " (or its equivalent) for a description of such options.",
                    713: "",
                    714: " A number of other `gnuplot` options are available for the `x11` terminal.",
                    715: " These may be specified either as command-line options when `gnuplot` is",
1.1.1.3 ! ohara     716: " invoked or as resources in the configuration file \".Xdefaults\".  They are",
1.1       maekawa   717: " set upon initialization and cannot be altered during a `gnuplot` session.",
                    718: "2 command-line_options",
                    719: "?commands set terminal x11 command-line-options",
                    720: "?set terminal x11 command-line-options",
                    721: "?set term x11 command-line-options",
                    722: "?x11 command-line-options",
                    723: "?command-line-options",
                    724: " In addition to the X Toolkit options, the following options may be specified",
                    725: " on the command line when starting `gnuplot` or as resources in your",
                    726: " \".Xdefaults\" file:",
                    727: "@start table - first is interactive cleartext form",
1.1.1.3 ! ohara     728: "  `-mono`     forces monochrome rendering on color displays.",
        !           729: "  `-gray`     requests grayscale rendering on grayscale or color displays.",
        !           730: "              (Grayscale displays receive monochrome rendering by default.)",
        !           731: "  `-clear`    requests that the window be cleared momentarily before a",
        !           732: "              new plot is displayed.",
        !           733: "  `-tvtwm`    requests that geometry specifications for position of the",
        !           734: "              window be made relative to the currently displayed portion",
        !           735: "              of the virtual root.",
        !           736: "  `-raise`    raises plot window after each plot",
        !           737: "  `-noraise`  does not raise plot window after each plot",
        !           738: "  `-persist`  plot windows survive after main gnuplot program exits",
1.1       maekawa   739: "#\\begin{tabular}{|cl|} \\hline",
1.1.1.3 ! ohara     740: "#`-mono`    & forces monochrome rendering on color displays.\\\\",
        !           741: "#`-gray`    & requests grayscale rendering on grayscale or color displays.\\\\",
        !           742: "#           & (Grayscale displays receive monochrome rendering by default.) \\\\",
        !           743: "#`-clear`   & requests that the window be cleared momentarily before a\\\\",
        !           744: "#           & new plot is displayed. \\\\",
        !           745: "#`-tvtwm`   & requests that geometry specifications for position of the\\\\",
        !           746: "#           & window be made relative to the currently displayed portion\\\\",
        !           747: "#           & of the virtual root. \\\\",
        !           748: "#`-raise`   & raises plot window after each plot. \\\\",
        !           749: "#`-noraise` & does not raise plot window after each plot. \\\\",
        !           750: "#`-persist` & plot windows survive after main gnuplot program exits. \\\\",
1.1       maekawa   751: "%c l .",
                    752: "%`-mono`@forces monochrome rendering on color displays.",
                    753: "%`-gray`@requests grayscale rendering on grayscale or color displays.",
                    754: "%       @(Grayscale displays receive monochrome rendering by default.)",
                    755: "%`-clear`@requests that the window be cleared momentarily before a",
                    756: "%        @new plot is displayed.",
                    757: "%`-tvtwm`@requests that geometry specifications for position of the",
                    758: "%        @window be made relative to the currently displayed portion",
                    759: "%        @of the virtual root.",
1.1.1.3 ! ohara     760: "%`-raise`@raises plot window after each plot",
        !           761: "%`-noraise`@does not raise plot window after each plot",
1.1       maekawa   762: "%`-persist`@plot windows survive after main gnuplot program exits",
                    763: "@end table",
                    764: " The options are shown above in their command-line syntax.  When entered as",
                    765: " resources in \".Xdefaults\", they require a different syntax.",
                    766: "",
                    767: " Example:",
                    768: "       gnuplot*gray: on",
                    769: "",
                    770: " `gnuplot` also provides a command line option (`-pointsize <v>`) and a",
                    771: " resource, `gnuplot*pointsize: <v>`, to control the size of points plotted",
                    772: " with the `points` plotting style.  The value `v` is a real number (greater",
                    773: " than 0 and less than or equal to ten) used as a scaling factor for point",
                    774: " sizes.  For example, `-pointsize 2` uses points twice the default size, and",
                    775: " `-pointsize 0.5` uses points half the normal size.",
1.1.1.3 ! ohara     776: "2 monochrome_options",
1.1       maekawa   777: "?commands set terminal x11 monochrome_options",
                    778: "?set terminal x11 monochrome_options",
                    779: "?set term x11 monochrome_options",
                    780: "?x11 monochrome_options",
                    781: "?monochrome_options",
                    782: " For monochrome displays, `gnuplot` does not honor foreground or background",
                    783: " colors.  The default is black-on-white.  `-rv` or `gnuplot*reverseVideo: on`",
                    784: " requests white-on-black.",
                    785: "",
                    786: "2 color_resources",
                    787: "?commands set terminal x11 color_resources",
                    788: "?set terminal x11 color_resources",
                    789: "?set term x11 color_resources",
                    790: "?x11 color_resources",
                    791: "?color_resources",
                    792: " For color displays, `gnuplot` honors the following resources (shown here",
                    793: " with their default values) or the greyscale resources.  The values may be",
                    794: " color names as listed in the X11 rgb.txt file on your system, hexadecimal",
                    795: " RGB color specifications (see X11 documentation), or a color name followed",
                    796: " by a comma and an `intensity` value from 0 to 1.  For example, `blue, 0.5`",
                    797: " means a half intensity blue.",
                    798: "@start table - first is interactive cleartext form",
                    799: "  gnuplot*background:  white",
                    800: "  gnuplot*textColor:   black",
                    801: "  gnuplot*borderColor: black",
                    802: "  gnuplot*axisColor:   black",
                    803: "  gnuplot*line1Color:  red",
                    804: "  gnuplot*line2Color:  green",
                    805: "  gnuplot*line3Color:  blue",
                    806: "  gnuplot*line4Color:  magenta",
                    807: "  gnuplot*line5Color:  cyan",
                    808: "  gnuplot*line6Color:  sienna",
                    809: "  gnuplot*line7Color:  orange",
                    810: "  gnuplot*line8Color:  coral",
                    811: "#\\begin{tabular}{|cl|} \\hline",
                    812: "#&gnuplot*background: white\\\\",
                    813: "#&gnuplot*textColor: black\\\\",
                    814: "#&gnuplot*borderColor: black\\\\",
                    815: "#&gnuplot*axisColor: black\\\\",
                    816: "#&gnuplot*line1Color: red\\\\",
                    817: "#&gnuplot*line2Color: green\\\\",
                    818: "#&gnuplot*line3Color: blue\\\\",
                    819: "#&gnuplot*line4Color: magenta\\\\",
                    820: "#&gnuplot*line5Color: cyan\\\\",
                    821: "#&gnuplot*line6Color: sienna\\\\",
                    822: "#&gnuplot*line7Color: orange\\\\",
                    823: "#&gnuplot*line8Color: coral\\\\",
                    824: "%c l .",
                    825: "%@gnuplot*background: white",
                    826: "%@gnuplot*textColor: black",
                    827: "%@gnuplot*borderColor: black",
                    828: "%@gnuplot*axisColor: black",
                    829: "%@gnuplot*line1Color: red",
                    830: "%@gnuplot*line2Color: green",
                    831: "%@gnuplot*line3Color: blue",
                    832: "%@gnuplot*line4Color: magenta",
                    833: "%@gnuplot*line5Color: cyan",
                    834: "%@gnuplot*line6Color: sienna",
                    835: "%@gnuplot*line7Color: orange",
                    836: "%@gnuplot*line8Color: coral",
                    837: "@end table",
                    838: "",
                    839: " The command-line syntax for these is, for example,",
                    840: "",
                    841: " Example:",
                    842: "       gnuplot -background coral",
                    843: "",
                    844: "2 grayscale_resources",
                    845: "?commands set terminal x11 grayscale_resources",
                    846: "?set terminal x11 grayscale_resources",
                    847: "?set term x11 grayscale_resources",
                    848: "?x11 grayscale_resources",
                    849: "?grayscale_resources",
                    850: " When `-gray` is selected, `gnuplot` honors the following resources for",
                    851: " grayscale or color displays (shown here with their default values).  Note",
                    852: " that the default background is black.",
                    853: "@start table - first is interactive cleartext form",
                    854: "  gnuplot*background: black",
                    855: "  gnuplot*textGray:   white",
                    856: "  gnuplot*borderGray: gray50",
                    857: "  gnuplot*axisGray:   gray50",
                    858: "  gnuplot*line1Gray:  gray100",
                    859: "  gnuplot*line2Gray:  gray60",
                    860: "  gnuplot*line3Gray:  gray80",
                    861: "  gnuplot*line4Gray:  gray40",
                    862: "  gnuplot*line5Gray:  gray90",
                    863: "  gnuplot*line6Gray:  gray50",
                    864: "  gnuplot*line7Gray:  gray70",
                    865: "  gnuplot*line8Gray:  gray30",
                    866: "#\\begin{tabular}{|cl|} \\hline",
                    867: "#&gnuplot*background: black\\\\",
                    868: "#&gnuplot*textGray: white\\\\",
                    869: "#&gnuplot*borderGray: gray50\\\\",
                    870: "#&gnuplot*axisGray: gray50\\\\",
                    871: "#&gnuplot*line1Gray: gray100\\\\",
                    872: "#&gnuplot*line2Gray: gray60\\\\",
                    873: "#&gnuplot*line3Gray: gray80\\\\",
                    874: "#&gnuplot*line4Gray: gray40\\\\",
                    875: "#&gnuplot*line5Gray: gray90\\\\",
                    876: "#&gnuplot*line6Gray: gray50\\\\",
                    877: "#&gnuplot*line7Gray: gray70\\\\",
                    878: "#&gnuplot*line8Gray: gray30\\\\",
                    879: "%c l .",
                    880: "%@gnuplot*background: black",
                    881: "%@gnuplot*textGray: white",
                    882: "%@gnuplot*borderGray: gray50",
                    883: "%@gnuplot*axisGray: gray50",
                    884: "%@gnuplot*line1Gray: gray100",
                    885: "%@gnuplot*line2Gray: gray60",
                    886: "%@gnuplot*line3Gray: gray80",
                    887: "%@gnuplot*line4Gray: gray40",
                    888: "%@gnuplot*line5Gray: gray90",
                    889: "%@gnuplot*line6Gray: gray50",
                    890: "%@gnuplot*line7Gray: gray70",
                    891: "%@gnuplot*line8Gray: gray30",
                    892: "@end table",
                    893: "",
                    894: "2 line_resources",
                    895: "?commands set terminal x11 line_resources",
                    896: "?set terminal x11 line_resources",
                    897: "?set term x11 line_resources",
                    898: "?x11 line_resources",
                    899: "?line_resources",
                    900: " `gnuplot` honors the following resources for setting the width (in pixels) of",
                    901: " plot lines (shown here with their default values.)  0 or 1 means a minimal",
                    902: " width line of 1 pixel width.  A value of 2 or 3 may improve the appearance of",
                    903: " some plots.",
                    904: "@start table - first is interactive cleartext form",
                    905: "  gnuplot*borderWidth: 2",
                    906: "  gnuplot*axisWidth:   0",
                    907: "  gnuplot*line1Width:  0",
                    908: "  gnuplot*line2Width:  0",
                    909: "  gnuplot*line3Width:  0",
                    910: "  gnuplot*line4Width:  0",
                    911: "  gnuplot*line5Width:  0",
                    912: "  gnuplot*line6Width:  0",
                    913: "  gnuplot*line7Width:  0",
                    914: "  gnuplot*line8Width:  0",
                    915: "#\\begin{tabular}{|cl|} \\hline",
                    916: "#&gnuplot*borderWidth: 2\\\\",
                    917: "#&gnuplot*axisWidth: 0\\\\",
                    918: "#&gnuplot*line1Width: 0\\\\",
                    919: "#&gnuplot*line2Width: 0\\\\",
                    920: "#&gnuplot*line3Width: 0\\\\",
                    921: "#&gnuplot*line4Width: 0\\\\",
                    922: "#&gnuplot*line5Width: 0\\\\",
                    923: "#&gnuplot*line6Width: 0\\\\",
                    924: "#&gnuplot*line7Width: 0\\\\",
                    925: "#&gnuplot*line8Width: 0\\\\",
                    926: "%c l .",
                    927: "%@gnuplot*borderWidth: 2",
                    928: "%@gnuplot*axisWidth: 0",
                    929: "%@gnuplot*line1Width: 0",
                    930: "%@gnuplot*line2Width: 0",
                    931: "%@gnuplot*line3Width: 0",
                    932: "%@gnuplot*line4Width: 0",
                    933: "%@gnuplot*line5Width: 0",
                    934: "%@gnuplot*line6Width: 0",
                    935: "%@gnuplot*line7Width: 0",
                    936: "%@gnuplot*line8Width: 0",
                    937: "@end table",
                    938: "",
                    939: " `gnuplot` honors the following resources for setting the dash style used for",
                    940: " plotting lines.  0 means a solid line.  A two-digit number `jk` (`j` and `k`",
                    941: " are >= 1  and <= 9) means a dashed line with a repeated pattern of `j` pixels",
                    942: " on followed by `k` pixels off.  For example, '16' is a \"dotted\" line with one",
                    943: " pixel on followed by six pixels off.  More elaborate on/off patterns can be",
                    944: " specified with a four-digit value.  For example, '4441' is four on, four off,",
                    945: " four on, one off.  The default values shown below are for monochrome displays",
                    946: " or monochrome rendering on color or grayscale displays.  For color displays,",
                    947: " the default for each is 0 (solid line) except for `axisDashes` which defaults",
                    948: " to a '16' dotted line.",
                    949: "@start table - first is interactive cleartext form",
                    950: "  gnuplot*borderDashes:   0",
                    951: "  gnuplot*axisDashes:    16",
                    952: "  gnuplot*line1Dashes:    0",
                    953: "  gnuplot*line2Dashes:   42",
                    954: "  gnuplot*line3Dashes:   13",
                    955: "  gnuplot*line4Dashes:   44",
                    956: "  gnuplot*line5Dashes:   15",
                    957: "  gnuplot*line6Dashes: 4441",
                    958: "  gnuplot*line7Dashes:   42",
                    959: "  gnuplot*line8Dashes:   13",
                    960: "#\\begin{tabular}{|cl|} \\hline",
                    961: "#&gnuplot*borderDashes: 0\\\\",
                    962: "#&gnuplot*axisDashes: 16\\\\",
                    963: "#&gnuplot*line1Dashes: 0\\\\",
                    964: "#&gnuplot*line2Dashes: 42\\\\",
                    965: "#&gnuplot*line3Dashes: 13\\\\",
                    966: "#&gnuplot*line4Dashes: 44\\\\",
                    967: "#&gnuplot*line5Dashes: 15\\\\",
                    968: "#&gnuplot*line6Dashes: 4441\\\\",
                    969: "#&gnuplot*line7Dashes: 42\\\\",
                    970: "#&gnuplot*line8Dashes: 13\\\\",
                    971: "%c l .",
                    972: "%@gnuplot*borderDashes: 0",
                    973: "%@gnuplot*axisDashes: 16",
                    974: "%@gnuplot*line1Dashes: 0",
                    975: "%@gnuplot*line2Dashes: 42",
                    976: "%@gnuplot*line3Dashes: 13",
                    977: "%@gnuplot*line4Dashes: 44",
                    978: "%@gnuplot*line5Dashes: 15",
                    979: "%@gnuplot*line6Dashes: 4441",
                    980: "%@gnuplot*line7Dashes: 42",
                    981: "%@gnuplot*line8Dashes: 13",
                    982: "@end table"
                    983: END_HELP(x11)
                    984: #endif /* TERM_HELP */

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