File: x11.trm

package info (click to toggle)
gnuplot 3.7.1p1-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 5,808 kB
  • ctags: 4,418
  • sloc: ansic: 43,279; lisp: 661; makefile: 647; asm: 539; sh: 416; objc: 379; csh: 297; pascal: 194; perl: 138
file content (984 lines) | stat: -rw-r--r-- 30,679 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
/*
 * $Id: x11.trm,v 1.11.2.2 1999/08/25 16:16:40 lhecking Exp $
 *
 */

/*[
 * Copyright 1986 - 1993, 1998   Thomas Williams, Colin Kelley
 *
 * Permission to use, copy, and distribute this software and its
 * documentation for any purpose with or without fee is hereby granted,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.
 *
 * Permission to modify the software is granted, but not the right to
 * distribute the complete modified source code.  Modifications are to
 * be distributed as patches to the released version.  Permission to
 * distribute binaries produced by compiling modified sources is granted,
 * provided you
 *   1. distribute the corresponding source modifications from the
 *    released version in the form of a patch file along with the binaries,
 *   2. add special version identification to distinguish your version
 *    in addition to the base release version number,
 *   3. provide your name and address as the primary contact for the
 *    support of your modified version, and
 *   4. retain our contact information in regard to use of the base
 *    software.
 * Permission to distribute the released version of the source code along
 * with corresponding source modifications in the form of a patch file is
 * granted with same provisions 2 through 4 for binary distributions.
 *
 * This software is provided "as is" without express or implied warranty
 * to the extent permitted by applicable law.
]*/

/*
 *    x11.trm  --- inboard terminal driver for X11
 */

#include "driver.h"

#ifdef TERM_REGISTER
register_term(x11)
#endif

#ifdef TERM_PROTO
int X11_args __PROTO((int argc, char *argv[]));
TERM_PUBLIC void X11_options __PROTO((void));
TERM_PUBLIC void X11_init __PROTO((void));
TERM_PUBLIC void X11_graphics __PROTO((void));
TERM_PUBLIC void X11_text __PROTO((void));
TERM_PUBLIC void X11_reset __PROTO((void));
TERM_PUBLIC void X11_move __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void X11_vector __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void X11_linewidth __PROTO((double lw));
TERM_PUBLIC void X11_pointsize __PROTO((double ps));
TERM_PUBLIC void X11_linetype __PROTO((int lt));
TERM_PUBLIC void X11_put_text __PROTO((unsigned int x, unsigned int y, char str[]));
TERM_PUBLIC int X11_justify_text __PROTO((enum JUSTIFY mode));
TERM_PUBLIC void X11_point __PROTO((unsigned int x, unsigned int y, int number));
TERM_PUBLIC void X11_fillbox __PROTO((int style, unsigned int x, unsigned y, unsigned int width, unsigned int height));
#define X11_XMAX 4096
#define X11_YMAX 4096

/* approximations for typical font/screen sizes */
#define X11_VCHAR (X11_YMAX/25)
#define X11_HCHAR (X11_XMAX/100)
#define X11_VTIC (X11_YMAX/100)
#define X11_HTIC (X11_XMAX/150)
#endif


#ifndef TERM_PROTO_ONLY

#ifdef TERM_BODY

/* non-zero if '-display' found on command line */
int X11_Display = 0;


/* sunos 4 uses on_exit() in place of atexit(). If both are missing,
 * we can probably survive since gnuplot_x11 should detect EOF on
 * the pipe. Unfortunately, the handlers take different parameters.
 */

#ifdef NO_ATEXIT
# define HANDLER_PROTO  __PROTO((int x, void *y))
# define HANDLER_DECL (x,y) int x; void *y;
# define HANDLER_PARAMS (0,NULL)
# ifdef HAVE_ON_EXIT
#  define atexit(x) on_exit(x, NULL)
# else
#  define atexit(x)		/* nowt */
# endif
#else /* !NO_ATEXIT */
# define HANDLER_PROTO __PROTO((void))
# define HANDLER_DECL   ()
# define HANDLER_PARAMS ()
#endif

static void X11_atexit HANDLER_PROTO;

/* Merged the old char X11_opts[] and int X11_optarg[]
 * into one array of structs.
 * Loosely based on XrmOptionDescRec, the use of which
 * would probably be overkill here. */
typedef enum { hasNoArg, hasArg } OptionArg;

static struct x11opt {
    const char *option;	/* Name of option */
    OptionArg arg;	/* Whether option has argument */
}  X11_opts[] =
{
   { "-mono", hasNoArg }, { "-gray", hasNoArg }, { "-clear", hasNoArg },
   { "-tvtwm", hasNoArg }, { "-pointsize", hasArg },
   { "-iconic", hasNoArg }, { "-rv", hasNoArg },
   { "-reverse", hasNoArg }, { "+rv", hasNoArg },
   { "-synchronous", hasNoArg },
   { "-display", hasArg }, { "-geometry", hasArg }, { "-bg", hasArg },
   { "-background", hasArg }, { "-bd", hasArg },
   { "-bordercolor", hasArg }, { "-bw", hasArg },
   { "-borderwidth", hasArg }, { "-fg", hasArg },
   { "-foreground", hasArg }, { "-fn", hasArg }, { "-font", hasArg },
   { "-name", hasArg },
   { "-selectionTimeout", hasArg }, { "-title", hasArg },
   { "-xnllanguage", hasArg }, { "-xrm", hasArg },
   { "-raise", hasNoArg }, { "-noraise", hasNoArg },
   { "-persist", hasNoArg }
};

#define X11_nopts (sizeof(X11_opts) / sizeof(X11_opts[0]))

static FILE *X11_ipc;

static char **xargv = (char **)NULL;
static char *optvec[2*X11_nopts+1];
# ifdef OS2
static char X11_command[] = "gnuplot_x11.exe";
# else
static char X11_command[] = "/usr/lib/gnuplot/gnuplot_x11";
# endif /* !OS/2 */

/*   X11_args - scan gnuplot command line for standard X Toolkit options
 * called from plot.c so must not be TERM_PUBLIC (which may be static)
 */

int
X11_args(argc, argv)
int argc;
char *argv[];
{
    int nx11 = 0, i = 0, n;

    xargv = (char **) gp_alloc (argc*sizeof(char *), "<xargv>");

    if (!xargv) {
	fputs ("not enough memory to copy argv - quitting\n", stderr);
	exit (EXIT_FAILURE);
    }

    /* We make a copy of the argument vector because
     * argv is modified later. */
    memcpy (xargv, argv, argc*sizeof(char *));
    optvec[i++] = X11_command;

    while (++argv, ++xargv, --argc > 0) {
	for (n = 0; n < X11_nopts; n++) {
	    if (strcmp(*argv, X11_opts[n].option) == 0) {
		optvec[i++] = *xargv;
		if (strcmp(*argv, "-display") == 0)
		    X11_Display++;
		if (X11_opts[n].arg == hasArg) {
		    if (--argc <= 0)
			return nx11;
		    optvec[i++] = *++xargv, ++argv;
		    nx11++;
		}
		nx11++;
		break;
	    }
	}
	if (n == X11_nopts)
	    break;
    }

    return (nx11);
}


static unsigned int X11_plot_number;

TERM_PUBLIC void
X11_options()
{
    if (almost_equals(c_token, "res$et")) {
	X11_atexit HANDLER_PARAMS;	/* tell gnuplot_x11 to shut down */
	++c_token;
    }
    if (!END_OF_COMMAND) {
	struct value a;
	X11_plot_number = (int) real(const_express(&a));
	/* let gnuplot_x11 check range */
    }
    sprintf(term_options, "%d", X11_plot_number);
}

/*-----------------------------------------------------------------------------
 *   Three different versions of the remainder of the X11 terminal driver
 *   are provided to support three different types of IPC with the
 *   gnuplot_x11 outboard terminal driver:
 * 
 *   DEFAULT_X11:      popen() pipe for most un*x platforms
 *
 *   CRIPPLED_SELECT : file IPC for un*x platforms with incomplete or faulty
 *                     implementation of BSD select()
 *
 *   VMS :             mailbox/spawn IPC
 *---------------------------------------------------------------------------*/

#define DEFAULT_X11
#if defined(VMS) || defined(CRIPPLED_SELECT)
# undef DEFAULT_X11
#endif
#if defined(VMS) && defined(CRIPPLED_SELECT)
Error.Incompatible options.
#endif

/* we do not want to have to duplicate all the code, so we
 * do most of it with macros.
 * PRINT0(format), PRINT1(format, p1), PRINT2(format, p1, p2) etc
 * also  FLUSH0(format), etc, which do an additional flush
 */


#ifdef DEFAULT_X11
/*-----------------------------------------------------------------------------
 *   DEFAULT_X11 popen() pipe IPC
 *---------------------------------------------------------------------------*/

static void
X11_atexit HANDLER_DECL
{
    if (X11_ipc) {
	fputs("R\n", X11_ipc);
	fclose(X11_ipc);
	/* dont wait(), since they might be -persist */
	X11_ipc = NULL;
    }
}

TERM_PUBLIC void
X11_init()
{
    static int been_here = 0;

    if (!X11_ipc) {
	/* first time through or after a reset */
#if defined(OSK) || defined(OS2)
	/* OS-9 popen() does not block on close for child to end, so
	 * we can safely use it here
	 */
	X11_ipc = popen(X11_command, "w");
#else /* !(OSK || OS/2) */
	int fdes[2];

	if (pipe(fdes)) perror("pipe() failed:");

	if (fork() == 0) {
	    /* child */
	    close(fdes[1]);
	    dup2(fdes[0], 0);	/* stdin from pipe */
	    execvp(X11_command, optvec);
	    /* if we get here, something went wrong */
	    perror("exec failed");
	    exit(EXIT_FAILURE);
	}
	/* parent */
	close(fdes[0]);		/* read end of pipe */
	X11_ipc = fdopen(fdes[1], "w");
#endif /* !(OSK || OS/2) */
    }

    if (!been_here) {
	atexit(X11_atexit);
	been_here++;
    }
}

TERM_PUBLIC void
X11_reset()
{
    /* leave the pipe alone, until exit or  set term x11 reset */
}

#define PRINT0(fmt)          fprintf(X11_ipc, fmt)
#define PRINT1(fmt,p1)       fprintf(X11_ipc, fmt,p1)
#define PRINT2(fmt,p1,p2)    fprintf(X11_ipc, fmt,p1,p2)
#define PRINT3(fmt,p1,p2,p3) fprintf(X11_ipc, fmt,p1,p2,p3)
#define PRINT4(fmt,p1,p2,p3,p4) fprintf(X11_ipc, fmt,p1,p2,p3,p4)
#define PRINT5(fmt,p1,p2,p3,p4,p5) fprintf(X11_ipc, fmt,p1,p2,p3,p4,p5)

#define FFLUSH()             fflush(X11_ipc)

#define BEFORE_GRAPHICS		/* nowt */
#define AFTER_TEXT		/* nowt */


#elif defined(CRIPPLED_SELECT)

/* PLEASE CAN SOMEONE CHECK THAT THIS STILL WORKS !!! */

/*-----------------------------------------------------------------------------
 *   CRIPPLED_SELECT file IPC
 *---------------------------------------------------------------------------*/

static char X11_tmp[32], X11_tmp0[32], X11_shutdown[32];
static int X11_pid;

TERM_PUBLIC void
X11_init()
{
    if (!(X11_pid = fork())) {
	execvp(X11_command, optvec);
	_exit(1);
    }
    sprintf(X11_tmp, "/tmp/Gnuplot_%d", X11_pid);
    sprintf(X11_tmp0, "%s-", X11_tmp);
    sprintf(X11_shutdown, "echo R >%s", X11_tmp);
}

TERM_PUBLIC void
X11_reset()
{
    system(X11_shutdown);
}

#define BEFORE_GRAPHICS \
 if (!(X11_ipc = fopen(X11_tmp0, "w"))) { \
   perror(X11_tmp0); system(X11_shutdown); exit(1); \
 }

#define AFTER_TEXT \
 { fclose(X11_ipc); rename(X11_tmp0, X11_tmp); }

#define PRINT0(fmt)          fprintf(X11_ipc, fmt)
#define PRINT1(fmt,p1)       fprintf(X11_ipc, fmt,p1)
#define PRINT2(fmt,p1,p2)    fprintf(X11_ipc, fmt,p1,p2)
#define PRINT3(fmt,p1,p2,p3) fprintf(X11_ipc, fmt,p1,p2,p3)
#define PRINT4(fmt,p1,p2,p3,p4) fprintf(X11_ipc, fmt,p1,p2,p3,p4)
#define PRINT5(fmt,p1,p2,p3,p4,p5) fprintf(X11_ipc, fmt,p1,p2,p3,p4,p5)
#define FFLUSH()             fflush(X11_ipc)

static void
X11_atexit HANDLER_DECL { /* WHAT SHOULD I DO ? */
}

#elif defined(VMS)
/*-----------------------------------------------------------------------------
 *   VMS mailbox/spawn IPC - Yehavi Bourvine - YEHAVI@VMS.HUJI.AC.IL
 *---------------------------------------------------------------------------*/
#include <iodef.h>
#include <descrip.h>
#include <dvidef.h>
#ifdef __DECC
#include <lib$routines.h>
#include <starlet.h>
#endif
#ifdef __GNUC__
#include <errno.h>
#else
int vaxc$errno;
#endif

#define SS$_NORMAL 1		/* or include <ssdef.h> for all SS$_ def's */

#define MBXMXMSG 128		/* DEFMBXMXMSG is set by SYSGEN */

static short X11_channel;

struct iosb {
    unsigned short stat;
    unsigned short count;
    unsigned long info;
};


TERM_PUBLIC void
X11_init()
{

    struct iosb iosb;

    static char devnam_string[64];
    static $DESCRIPTOR(devnam, devnam_string);

    struct {
	short int buf_len;
	short int item;
	char *buf_addr;
	unsigned short int *ret_len;
	int end;
    } item_list = {
	devnam.dsc$w_length, DVI$_DEVNAM,
	    devnam.dsc$a_pointer,
	    &devnam.dsc$w_length, 0
    };
#define CMDLEN 1024
    char cmdline[CMDLEN], *cmdp;
    int optindex;

    if (!X11_channel) {
	int one = 1;

	/* Create a descriptor for the command line that starts
	   GNUPLOT_X11. $DESCRIP doesn't work in this context... */

	/* FIXME!
	 * This does not work anymore since X11 option passing has been
	 * changed to use execvp() in the DEFAULT_X11 case
	 */
	struct dsc$descriptor_s pgmdsc =
	{0, DSC$K_DTYPE_T,
	 DSC$K_CLASS_S, 0};
        optindex = 0;
        strcpy (cmdline, optvec[optindex]);
        cmdp = cmdline + strlen (optvec[optindex]);
        while (optvec[++optindex] != NULL) {
          *cmdp++ = ' ';
          *cmdp++ = '\"';
          strcpy (cmdp, optvec[optindex]);
          cmdp += strlen (optvec[optindex]);
          *cmdp++ = '\"';
        }
	pgmdsc.dsc$w_length = cmdp-cmdline;
	pgmdsc.dsc$a_pointer = cmdline;

	/* Create a mailbox which will be used as a pipe for commands to the 
	 * subprocess.  What we'll write to it will be read by the subprocess
	 * as its STDIN.  Use an unnamed mailbox and refer to it by its device
	 * number */

	vaxc$errno = sys$crembx(0, &X11_channel, MBXMXMSG, MBXMXMSG, 0, 0, 0, 0);
	if ((vaxc$errno & SS$_NORMAL) != SS$_NORMAL) {
	    printf("SYS$CreMbx failed with status=%d\r\n", vaxc$errno);
	    os_error("sys$crembx failed", NO_CARET);
	}
	vaxc$errno = sys$getdviw(0, X11_channel, 0, &item_list, &iosb, 0, 0, 0);
	if ((vaxc$errno & SS$_NORMAL) == SS$_NORMAL)
	    vaxc$errno = iosb.stat;
	if ((vaxc$errno & SS$_NORMAL) != SS$_NORMAL) {
	    printf("SYS$Getdviw failed with status=%d\r\n", vaxc$errno);
	    sys$dassgn(X11_channel);
	    X11_channel = 0;
	    os_error("sys$getdviw failed", NO_CARET);
	}
	/* Create a subprocess whose input is this mailbox. */
	vaxc$errno = lib$spawn(&pgmdsc, &devnam, 0, &one, 0, 0, 0, 0, 0, 0, 0, 0, 0);
	if ((vaxc$errno & SS$_NORMAL) != SS$_NORMAL) {
	    printf("LIB$SPAWN failed with status=%d\r\n", vaxc$errno);
	    sys$dassgn(X11_channel);
	    X11_channel = 0;
	    os_error("lib$spawn failed", NO_CARET);
	}
    } {
	static int been_here = 0;
	if (!been_here) {
	    atexit(X11_atexit);
	    been_here = 1;
	}
    }
}


/*   We use $QIO in order to avoid buffering problems, although it might 
 *   work  as well with simple Fprintf calls.
 */

#define GO(x) \
{ \
   char buffer[512]; int status; struct iosb iosb;\
   sprintf x; \
   if (strlen(buffer) >= MBXMXMSG )  { \
     printf("buffer contents (%d char) catenated to mailbox size (%d bytes)\n", \
     strlen(buffer), MBXMXMSG); \
     buffer[MBXMXMSG-1] = '\0';\
     printf("%s\n", buffer); \
   } \
   status = sys$qiow(0, X11_channel, IO$_WRITEVBLK, &iosb, 0, 0, buffer, strlen(buffer), 0, 0, 0, 0); \
   if ((status & SS$_NORMAL) == SS$_NORMAL) status = iosb.stat; \
   if((status & SS$_NORMAL) != SS$_NORMAL) exit(status); \
 }

#define PRINT0(fmt)          GO( (buffer, fmt) )
#define PRINT1(fmt,p1)       GO( (buffer, fmt,p1) )
#define PRINT2(fmt,p1,p2)    GO( (buffer, fmt,p1,p2) )
#define PRINT3(fmt,p1,p2,p3) GO( (buffer, fmt,p1,p2,p3) )
#define PRINT4(fmt,p1,p2,p3,p4) GO( (buffer, fmt,p1,p2,p3,p4) )
#define PRINT5(fmt,p1,p2,p3,p4,p5) GO( (buffer, fmt,p1,p2,p3,p4,p5) )

#define FFLUSH()		/* nowt */
#define BEFORE_GRAPHICS		/* nowt */
#define AFTER_TEXT		/* nowt */

static void
X11_atexit HANDLER_DECL
{
    if (X11_channel) {
	PRINT0("R\n");
	sleep(2);		/* Wait for subprocess to finish */
	sys$dassgn(X11_channel);
	X11_channel = 0;
    }
}

TERM_PUBLIC void
X11_reset()
{
    /* do nothing until exit */
}

#else /* !VMS */
You lose.
#endif /* !VMS */


/* common stuff, using macros defined above */


TERM_PUBLIC void
X11_graphics()
{
    BEFORE_GRAPHICS;		/* kludge for crippled select */

    /* for VMS sake, keep as separate prints */
    PRINT1("G%d\n", X11_plot_number);

#ifdef ULTRIX_KLUDGE
    fflush(X11_ipc);
#endif

}

TERM_PUBLIC void
X11_text()
{
    PRINT0("E\n");
    FFLUSH();
#ifdef ULTRIX_KLUDGE
    PRINT0("E\n");
    FFLUSH();
#endif

    AFTER_TEXT;			/* kludge for crippled select */
}


TERM_PUBLIC void
X11_move(x, y)
unsigned int x, y;
{
    PRINT2("M%04d%04d\n", x, y);
}

TERM_PUBLIC void
X11_vector(x, y)
unsigned int x, y;
{
    PRINT2("V%04d%04d\n", x, y);
}

TERM_PUBLIC void
X11_pointsize(ps)
double ps;
{
    PRINT2("P7%04d%04d\n",	/* size of point symbols */
	   (int) (term->h_tic * ps * 0.5), (int) (term->v_tic * ps * 0.5));
}

TERM_PUBLIC void
X11_linewidth(lw)
double lw;
{
    PRINT1("W%04d\n", (int) lw);
}

TERM_PUBLIC void
X11_linetype(lt)
int lt;
{
    PRINT1("L%04d\n", lt);
}

TERM_PUBLIC void
X11_put_text(x, y, str)
unsigned int x, y;
char str[];
{
    /* badly outrange labels can overflow into text field */
    if (x < 10000 && y < 10000) {
	PRINT3("T%04d%04d%s\n", x, y, str);
    }
}

TERM_PUBLIC int
X11_justify_text(mode)
enum JUSTIFY mode;
{
    PRINT1("J%04d\n", mode);
    return (TRUE);
}

TERM_PUBLIC void
X11_point(x, y, number)
unsigned int x, y;
int number;
{
    if (number >= 0)
	number %= POINT_TYPES;
    number += 1;
    PRINT3("P%01d%04d%04d\n", number, x, y);
}

TERM_PUBLIC void
X11_fillbox(style, x, y, w, h)
int style;
unsigned int x, y, w, h;
{
    PRINT5("F%04d%04u%04u%04u%04u\n", style, x, y, w, h);
}

#endif /* TERM_BODY */

#ifdef TERM_TABLE

TERM_TABLE_START(x11_driver)
    "x11", "X11 Window System",
    X11_XMAX, X11_YMAX, X11_VCHAR, X11_HCHAR,
    X11_VTIC, X11_HTIC, X11_options, X11_init, X11_reset,
    X11_text, null_scale, X11_graphics, X11_move, X11_vector,
    X11_linetype, X11_put_text, null_text_angle,
    X11_justify_text, X11_point, do_arrow, set_font_null,
    X11_pointsize, TERM_CAN_MULTIPLOT,
    X11_text /* suspend can use same routine */ , 0 /* resume */ ,
    X11_fillbox, X11_linewidth
TERM_TABLE_END(x11_driver)

#undef LAST_TERM
#define LAST_TERM x11_driver

TERM_TABLE_START(X11_driver)
    "X11", "X11 Window System (identical to x11)",
    X11_XMAX, X11_YMAX, X11_VCHAR, X11_HCHAR,
    X11_VTIC, X11_HTIC, X11_options, X11_init, X11_reset,
    X11_text, null_scale, X11_graphics, X11_move, X11_vector,
    X11_linetype, X11_put_text, null_text_angle,
    X11_justify_text, X11_point, do_arrow, set_font_null,
    X11_pointsize, TERM_CAN_MULTIPLOT,
    X11_text /* suspend can use same routine */ , 0 /* resume */ ,
    X11_fillbox, X11_linewidth
TERM_TABLE_END(X11_driver)

#undef LAST_TERM
#define LAST_TERM x11_driver

#endif /* TERM_TABLE */
#endif /* TERM_PROTO_ONLY */


#ifdef TERM_HELP
START_HELP(x11)
"1 x11",
"?commands set terminal x11",
"?set terminal x11",
"?set term x11",
"?terminal x11",
"?term x11",
"?x11",
"?X11",
" `gnuplot` provides the `x11` terminal type for use with X servers.  This",
" terminal type is set automatically at startup if the `DISPLAY` environment",
" variable is set, if the `TERM` environment variable is set to `xterm`, or",
" if the `-display` command line option is used.",
"",
" Syntax:",
"       set terminal x11 {reset} {<n>}",
"",
" Multiple plot windows are supported: `set terminal x11 <n>` directs the",
" output to plot window number n.  If n>0, the terminal number will be",
" appended to the window title and the icon will be labeled `gplt <n>`.",
" The active window may distinguished by a change in cursor (from default",
" to crosshair.)",
"",
" Plot windows remain open even when the `gnuplot` driver is changed to a",
" different device.  A plot window can be closed by pressing the letter q",
" while that window has input focus, or by choosing `close` from a window",
" manager menu.  All plot windows can be closed by specifying `reset`, which",
" actually terminates the subprocess which maintains the windows (unless",
" `-persist` was specified).",
"",
" Plot windows will automatically be closed at the end of the session",
" unless the `-persist` option was given.",
"",
" The size or aspect ratio of a plot may be changed by resizing the `gnuplot`",
" window.",
"",
" Linewidths and pointsizes may be changed from within `gnuplot` with",
" `set linestyle`.",
"",
" For terminal type `x11`, `gnuplot` accepts (when initialized) the standard",
" X Toolkit options and resources such as geometry, font, and name from the",
" command line arguments or a configuration file.  See the X(1) man page",
" (or its equivalent) for a description of such options.",
"",
" A number of other `gnuplot` options are available for the `x11` terminal.",
" These may be specified either as command-line options when `gnuplot` is",
" invoked or as resources in the configuration file \"/.Xdefaults\".  They are",
" set upon initialization and cannot be altered during a `gnuplot` session.",
"2 command-line_options",
"?commands set terminal x11 command-line-options",
"?set terminal x11 command-line-options",
"?set term x11 command-line-options",
"?x11 command-line-options",
"?command-line-options",
" In addition to the X Toolkit options, the following options may be specified",
" on the command line when starting `gnuplot` or as resources in your",
" \".Xdefaults\" file:",
"@start table - first is interactive cleartext form",
"  `-clear`   requests that the window be cleared momentarily before a",
"             new plot is displayed.",
"  `-gray`    requests grayscale rendering on grayscale or color displays.",
"             (Grayscale displays receive monochrome rendering by default.)",
"  `-mono`    forces monochrome rendering on color displays.",
"  `-persist` plot windows survive after main gnuplot program exits",
"  `-raise`   raise plot window after each plot",
"  `-noraise` do not raise plot window after each plot",
"  `-tvtwm`   requests that geometry specifications for position of the",
"             window be made relative to the currently displayed portion",
"             of the virtual root.",
"#\\begin{tabular}{|cl|} \\hline",
"#`-mono`  & forces monochrome rendering on color displays.\\\\",
"#`-gray`  & requests grayscale rendering on grayscale or color displays.\\\\",
"#         & (Grayscale displays receive monochrome rendering by default.) \\\\",
"#`-clear` & requests that the window be cleared momentarily before a\\\\",
"#         & new plot is displayed. \\\\",
"#`-tvtwm` & requests that geometry specifications for position of the\\\\",
"#         & window be made relative to the currently displayed portion\\\\",
"#         & of the virtual root. \\\\",
"#`-raise` & raise plot window after each plot. \\\\",
"#`-noraise` & do not raise plot window after each plot. \\\\",
"#`-persist`&plot windows survive after main gnuplot program exits. \\\\",
"%c l .",
"%`-mono`@forces monochrome rendering on color displays.",
"%`-gray`@requests grayscale rendering on grayscale or color displays.",
"%       @(Grayscale displays receive monochrome rendering by default.)",
"%`-clear`@requests that the window be cleared momentarily before a",
"%        @new plot is displayed.",
"%`-tvtwm`@requests that geometry specifications for position of the",
"%        @window be made relative to the currently displayed portion",
"%        @of the virtual root.",
"%`-raise`@raise plot window after each plot",
"%`-noraise`@do not raise plot window after each plot",
"%`-persist`@plot windows survive after main gnuplot program exits",
"@end table",
" The options are shown above in their command-line syntax.  When entered as",
" resources in \".Xdefaults\", they require a different syntax.",
"",
" Example:",
"       gnuplot*gray: on",
"",
" `gnuplot` also provides a command line option (`-pointsize <v>`) and a",
" resource, `gnuplot*pointsize: <v>`, to control the size of points plotted",
" with the `points` plotting style.  The value `v` is a real number (greater",
" than 0 and less than or equal to ten) used as a scaling factor for point",
" sizes.  For example, `-pointsize 2` uses points twice the default size, and",
" `-pointsize 0.5` uses points half the normal size.",
"2 monochome_options",
"?commands set terminal x11 monochrome_options",
"?set terminal x11 monochrome_options",
"?set term x11 monochrome_options",
"?x11 monochrome_options",
"?monochrome_options",
" For monochrome displays, `gnuplot` does not honor foreground or background",
" colors.  The default is black-on-white.  `-rv` or `gnuplot*reverseVideo: on`",
" requests white-on-black.",
"",
"2 color_resources",
"?commands set terminal x11 color_resources",
"?set terminal x11 color_resources",
"?set term x11 color_resources",
"?x11 color_resources",
"?color_resources",
" For color displays, `gnuplot` honors the following resources (shown here",
" with their default values) or the greyscale resources.  The values may be",
" color names as listed in the X11 rgb.txt file on your system, hexadecimal",
" RGB color specifications (see X11 documentation), or a color name followed",
" by a comma and an `intensity` value from 0 to 1.  For example, `blue, 0.5`",
" means a half intensity blue.",
"@start table - first is interactive cleartext form",
"  gnuplot*background:  white",
"  gnuplot*textColor:   black",
"  gnuplot*borderColor: black",
"  gnuplot*axisColor:   black",
"  gnuplot*line1Color:  red",
"  gnuplot*line2Color:  green",
"  gnuplot*line3Color:  blue",
"  gnuplot*line4Color:  magenta",
"  gnuplot*line5Color:  cyan",
"  gnuplot*line6Color:  sienna",
"  gnuplot*line7Color:  orange",
"  gnuplot*line8Color:  coral",
"#\\begin{tabular}{|cl|} \\hline",
"#&gnuplot*background: white\\\\",
"#&gnuplot*textColor: black\\\\",
"#&gnuplot*borderColor: black\\\\",
"#&gnuplot*axisColor: black\\\\",
"#&gnuplot*line1Color: red\\\\",
"#&gnuplot*line2Color: green\\\\",
"#&gnuplot*line3Color: blue\\\\",
"#&gnuplot*line4Color: magenta\\\\",
"#&gnuplot*line5Color: cyan\\\\",
"#&gnuplot*line6Color: sienna\\\\",
"#&gnuplot*line7Color: orange\\\\",
"#&gnuplot*line8Color: coral\\\\",
"%c l .",
"%@gnuplot*background: white",
"%@gnuplot*textColor: black",
"%@gnuplot*borderColor: black",
"%@gnuplot*axisColor: black",
"%@gnuplot*line1Color: red",
"%@gnuplot*line2Color: green",
"%@gnuplot*line3Color: blue",
"%@gnuplot*line4Color: magenta",
"%@gnuplot*line5Color: cyan",
"%@gnuplot*line6Color: sienna",
"%@gnuplot*line7Color: orange",
"%@gnuplot*line8Color: coral",
"@end table",
"",
" The command-line syntax for these is, for example,",
"",
" Example:",
"       gnuplot -background coral",
"",
"2 grayscale_resources",
"?commands set terminal x11 grayscale_resources",
"?set terminal x11 grayscale_resources",
"?set term x11 grayscale_resources",
"?x11 grayscale_resources",
"?grayscale_resources",
" When `-gray` is selected, `gnuplot` honors the following resources for",
" grayscale or color displays (shown here with their default values).  Note",
" that the default background is black.",
"@start table - first is interactive cleartext form",
"  gnuplot*background: black",
"  gnuplot*textGray:   white",
"  gnuplot*borderGray: gray50",
"  gnuplot*axisGray:   gray50",
"  gnuplot*line1Gray:  gray100",
"  gnuplot*line2Gray:  gray60",
"  gnuplot*line3Gray:  gray80",
"  gnuplot*line4Gray:  gray40",
"  gnuplot*line5Gray:  gray90",
"  gnuplot*line6Gray:  gray50",
"  gnuplot*line7Gray:  gray70",
"  gnuplot*line8Gray:  gray30",
"#\\begin{tabular}{|cl|} \\hline",
"#&gnuplot*background: black\\\\",
"#&gnuplot*textGray: white\\\\",
"#&gnuplot*borderGray: gray50\\\\",
"#&gnuplot*axisGray: gray50\\\\",
"#&gnuplot*line1Gray: gray100\\\\",
"#&gnuplot*line2Gray: gray60\\\\",
"#&gnuplot*line3Gray: gray80\\\\",
"#&gnuplot*line4Gray: gray40\\\\",
"#&gnuplot*line5Gray: gray90\\\\",
"#&gnuplot*line6Gray: gray50\\\\",
"#&gnuplot*line7Gray: gray70\\\\",
"#&gnuplot*line8Gray: gray30\\\\",
"%c l .",
"%@gnuplot*background: black",
"%@gnuplot*textGray: white",
"%@gnuplot*borderGray: gray50",
"%@gnuplot*axisGray: gray50",
"%@gnuplot*line1Gray: gray100",
"%@gnuplot*line2Gray: gray60",
"%@gnuplot*line3Gray: gray80",
"%@gnuplot*line4Gray: gray40",
"%@gnuplot*line5Gray: gray90",
"%@gnuplot*line6Gray: gray50",
"%@gnuplot*line7Gray: gray70",
"%@gnuplot*line8Gray: gray30",
"@end table",
"",
"2 line_resources",
"?commands set terminal x11 line_resources",
"?set terminal x11 line_resources",
"?set term x11 line_resources",
"?x11 line_resources",
"?line_resources",
" `gnuplot` honors the following resources for setting the width (in pixels) of",
" plot lines (shown here with their default values.)  0 or 1 means a minimal",
" width line of 1 pixel width.  A value of 2 or 3 may improve the appearance of",
" some plots.",
"@start table - first is interactive cleartext form",
"  gnuplot*borderWidth: 2",
"  gnuplot*axisWidth:   0",
"  gnuplot*line1Width:  0",
"  gnuplot*line2Width:  0",
"  gnuplot*line3Width:  0",
"  gnuplot*line4Width:  0",
"  gnuplot*line5Width:  0",
"  gnuplot*line6Width:  0",
"  gnuplot*line7Width:  0",
"  gnuplot*line8Width:  0",
"#\\begin{tabular}{|cl|} \\hline",
"#&gnuplot*borderWidth: 2\\\\",
"#&gnuplot*axisWidth: 0\\\\",
"#&gnuplot*line1Width: 0\\\\",
"#&gnuplot*line2Width: 0\\\\",
"#&gnuplot*line3Width: 0\\\\",
"#&gnuplot*line4Width: 0\\\\",
"#&gnuplot*line5Width: 0\\\\",
"#&gnuplot*line6Width: 0\\\\",
"#&gnuplot*line7Width: 0\\\\",
"#&gnuplot*line8Width: 0\\\\",
"%c l .",
"%@gnuplot*borderWidth: 2",
"%@gnuplot*axisWidth: 0",
"%@gnuplot*line1Width: 0",
"%@gnuplot*line2Width: 0",
"%@gnuplot*line3Width: 0",
"%@gnuplot*line4Width: 0",
"%@gnuplot*line5Width: 0",
"%@gnuplot*line6Width: 0",
"%@gnuplot*line7Width: 0",
"%@gnuplot*line8Width: 0",
"@end table",
"",
" `gnuplot` honors the following resources for setting the dash style used for",
" plotting lines.  0 means a solid line.  A two-digit number `jk` (`j` and `k`",
" are >= 1  and <= 9) means a dashed line with a repeated pattern of `j` pixels",
" on followed by `k` pixels off.  For example, '16' is a \"dotted\" line with one",
" pixel on followed by six pixels off.  More elaborate on/off patterns can be",
" specified with a four-digit value.  For example, '4441' is four on, four off,",
" four on, one off.  The default values shown below are for monochrome displays",
" or monochrome rendering on color or grayscale displays.  For color displays,",
" the default for each is 0 (solid line) except for `axisDashes` which defaults",
" to a '16' dotted line.",
"@start table - first is interactive cleartext form",
"  gnuplot*borderDashes:   0",
"  gnuplot*axisDashes:    16",
"  gnuplot*line1Dashes:    0",
"  gnuplot*line2Dashes:   42",
"  gnuplot*line3Dashes:   13",
"  gnuplot*line4Dashes:   44",
"  gnuplot*line5Dashes:   15",
"  gnuplot*line6Dashes: 4441",
"  gnuplot*line7Dashes:   42",
"  gnuplot*line8Dashes:   13",
"#\\begin{tabular}{|cl|} \\hline",
"#&gnuplot*borderDashes: 0\\\\",
"#&gnuplot*axisDashes: 16\\\\",
"#&gnuplot*line1Dashes: 0\\\\",
"#&gnuplot*line2Dashes: 42\\\\",
"#&gnuplot*line3Dashes: 13\\\\",
"#&gnuplot*line4Dashes: 44\\\\",
"#&gnuplot*line5Dashes: 15\\\\",
"#&gnuplot*line6Dashes: 4441\\\\",
"#&gnuplot*line7Dashes: 42\\\\",
"#&gnuplot*line8Dashes: 13\\\\",
"%c l .",
"%@gnuplot*borderDashes: 0",
"%@gnuplot*axisDashes: 16",
"%@gnuplot*line1Dashes: 0",
"%@gnuplot*line2Dashes: 42",
"%@gnuplot*line3Dashes: 13",
"%@gnuplot*line4Dashes: 44",
"%@gnuplot*line5Dashes: 15",
"%@gnuplot*line6Dashes: 4441",
"%@gnuplot*line7Dashes: 42",
"%@gnuplot*line8Dashes: 13",
"@end table"
END_HELP(x11)
#endif /* TERM_HELP */