1 /* Hello, Emacs, this is -*-C-*-
2 * $Id: be.trm,v 1.18 2006/07/21 02:35:45 sfeam Exp $
7 * Copyright 1986 - 1993, 1998, 2004 Thomas Williams, Colin Kelley
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.
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,
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
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.
32 * This software is provided "as is" without express or implied warranty
33 * to the extent permitted by applicable law.
37 * This file is included by ../term.c.
39 * be.trm --- inboard terminal driver for BE
53 int BE_args __PROTO((int argc, char *argv[]));
54 TERM_PUBLIC void BE_options __PROTO((void));
55 TERM_PUBLIC void BE_init __PROTO((void));
56 TERM_PUBLIC void BE_graphics __PROTO((void));
57 TERM_PUBLIC void BE_text __PROTO((void));
58 TERM_PUBLIC void BE_reset __PROTO((void));
59 TERM_PUBLIC void BE_move __PROTO((unsigned int x, unsigned int y));
60 TERM_PUBLIC void BE_vector __PROTO((unsigned int x, unsigned int y));
61 TERM_PUBLIC void BE_linewidth __PROTO((double lw));
62 TERM_PUBLIC void BE_pointsize __PROTO((double ps));
63 TERM_PUBLIC void BE_linetype __PROTO((int lt));
64 TERM_PUBLIC void BE_put_text __PROTO((unsigned int x, unsigned int y, const char str[]));
65 TERM_PUBLIC int BE_justify_text __PROTO((enum JUSTIFY mode));
66 TERM_PUBLIC void BE_point __PROTO((unsigned int x, unsigned int y, int number));
67 TERM_PUBLIC void BE_fillbox __PROTO((int style, unsigned int x, unsigned y, unsigned int width, unsigned int height));
71 /* approximations for typical font/screen sizes */
72 #define BE_VCHAR (BE_YMAX/25)
73 #define BE_HCHAR (BE_XMAX/100)
74 #define BE_VTIC (BE_YMAX/100)
75 #define BE_HTIC (BE_XMAX/150)
79 #ifndef TERM_PROTO_ONLY
83 /* non-zero if '-display' found on command line */
86 static void BE_atexit __PROTO((void));
88 typedef enum { hasNoArg, hasArg } OptionArg;
91 const char *option; /* Name of option */
92 OptionArg arg; /* Whether option has argument */
95 { "-mono", hasNoArg }, { "-gray", hasNoArg }, { "-clear", hasNoArg },
96 { "-pointsize", hasArg },
97 { "-iconic", hasNoArg }, { "-rv", hasNoArg },
98 { "-reverse", hasNoArg }, { "+rv", hasNoArg },
99 { "-synchronous", hasNoArg },
100 { "-display", hasArg }, { "-geometry", hasArg }, { "-bg", hasArg },
101 { "-background", hasArg }, { "-bd", hasArg },
102 { "-bordercolor", hasArg }, { "-bw", hasArg },
103 { "-borderwidth", hasArg }, { "-fg", hasArg },
104 { "-foreground", hasArg }, { "-fn", hasArg }, { "-font", hasArg },
106 { "-title", hasArg },
107 /* { "-xnllanguage", hasArg }, { "-xrm", hasArg }, */
108 { "-raise", hasNoArg }, { "-noraise", hasNoArg },
109 { "-persist", hasNoArg }
112 #define BE_nopts (sizeof(BE_cmdargs) / sizeof(BE_cmdargs[0]))
116 static char **xargv = (char **)NULL;
117 static char *optvec[2*BE_nopts+1];
119 static char BE_command[] = "gnuplot_be";
121 /* Almost not worth the hassle, be want a uniform interface */
122 enum BE_id { BE_RESET, BE_OTHER };
124 static struct gen_table BE_opts[] =
126 { "res$et", BE_RESET },
130 static unsigned int BE_plot_number;
137 while (!END_OF_COMMAND) {
138 switch(lookup_table(&BE_opts[0],c_token)) {
141 BE_atexit (); /* tell gnuplot_be to shut down */
145 BE_plot_number = (int) real(const_express(&a));
146 /* let gnuplot_be check range */
151 sprintf(term_options, "%d", BE_plot_number);
155 /* BE_args - scan gnuplot command line for standard Toolkit options (to be
156 * done) called from plot.c so must not be TERM_PUBLIC (which may be static)
160 BE_args(int argc, char *argv[])
162 int nbe = 0, i = 0, n;
164 xargv = (char **) gp_alloc (argc*sizeof(char *), "<xargv>");
167 fputs ("not enough memory to copy argv - quitting\n", stderr);
171 /* We make a copy of the argument vector because
172 * argv is modified later. */
173 memcpy (xargv, argv, argc*sizeof(char *));
174 optvec[i++] = BE_command;
176 while (++argv, --argc > 0) {
177 for (n = 0; n < BE_nopts; n++) {
178 if (strcmp(*argv, BE_cmdargs[n].option) == 0) {
179 optvec[i++] = *xargv;
180 if (strcmp(*argv, "-display") == 0)
182 if (BE_cmdargs[n].arg == hasArg) {
185 optvec[i++] = *++xargv, ++argv;
199 /* we do not want to have to duplicate all the code, so we
200 * do most of it with macros.
201 * PRINT0(format), PRINT1(format, p1), PRINT2(format, p1, p2) etc
202 * also FLUSH0(format), etc, which do an additional flush
207 * The Be terminal driver uses popen() pipe IPC
213 fputs("R\n", BE_ipc);
215 /* dont wait(), since they might be -persist */
224 /* first time through or after a reset */
230 dup2(fdes[0], 0); /* stdin from pipe */
231 execvp(BE_command, optvec);
232 /* if we get here, something went wrong */
233 perror("exec failed");
237 close(fdes[0]); /* read end of pipe */
238 BE_ipc = fdopen(fdes[1], "w");
240 static int been_here = 0;
251 /* leave the pipe alone, until exit or set term be reset */
254 #define PRINT0(fmt) fprintf(BE_ipc, fmt)
255 #define PRINT1(fmt,p1) fprintf(BE_ipc, fmt,p1)
256 #define PRINT2(fmt,p1,p2) fprintf(BE_ipc, fmt,p1,p2)
257 #define PRINT3(fmt,p1,p2,p3) fprintf(BE_ipc, fmt,p1,p2,p3)
258 #define PRINT4(fmt,p1,p2,p3,p4) fprintf(BE_ipc, fmt,p1,p2,p3,p4)
259 #define PRINT5(fmt,p1,p2,p3,p4,p5) fprintf(BE_ipc, fmt,p1,p2,p3,p4,p5)
261 #define FFLUSH() fflush(BE_ipc)
263 #define BEFORE_GRAPHICS /* nowt */
264 #define AFTER_TEXT /* nowt */
267 /* common stuff, using macros defined above */
273 BEFORE_GRAPHICS; /* kludge for crippled select */
274 PRINT1("G%d\n", BE_plot_number); /* for VMS sake, keep as separate prints */
282 AFTER_TEXT; /* kludge for crippled select */
287 BE_move(unsigned int x, unsigned int y)
289 PRINT2("M%04d%04d\n", x, y);
293 BE_vector(unsigned int x, unsigned int y)
295 PRINT2("V%04d%04d\n", x, y);
299 BE_pointsize(double ps)
303 PRINT2("P7%04d%04d\n", /* size of point symbols */
304 (int) (term->h_tic * ps * 0.5), (int) (term->v_tic * ps * 0.5));
308 BE_linewidth(double lw)
310 PRINT1("W%04d\n", (int) lw);
316 PRINT1("L%04d\n", lt);
320 BE_put_text(unsigned int x, unsigned int y, const char str[])
322 /* badly outrange labels can overflow into text field */
323 if (x < 10000 && y < 10000) {
324 PRINT3("T%04d%04d%s\n", x, y, str);
329 BE_justify_text(enum JUSTIFY mode)
331 PRINT1("J%04d\n", mode);
336 BE_point(unsigned int x, unsigned int y, int number)
339 number %= POINT_TYPES;
341 PRINT3("P%01d%04d%04d\n", number, x, y);
347 unsigned int x, unsigned int y,
348 unsigned int w, unsigned int h)
350 PRINT5("F%04d%04u%04u%04u%04u\n", style, x, y, w, h);
353 #endif /* TERM_BODY */
357 TERM_TABLE_START(be_driver)
358 "be", "BeOS Window System",
359 BE_XMAX, BE_YMAX, BE_VCHAR, BE_HCHAR,
360 BE_VTIC, BE_HTIC, BE_options, BE_init, BE_reset,
361 BE_text, null_scale, BE_graphics, BE_move, BE_vector,
362 BE_linetype, BE_put_text, null_text_angle,
363 BE_justify_text, BE_point, do_arrow, set_font_null,
364 BE_pointsize, TERM_CAN_MULTIPLOT|TERM_NO_OUTPUTFILE,
365 BE_text /* suspend can use same routine */ , 0 /* resume */ ,
366 BE_fillbox, BE_linewidth
367 TERM_TABLE_END(be_driver)
370 #define LAST_TERM be_driver
372 TERM_TABLE_START(BE_driver)
373 "BE", "BE Window System (identical to be)",
374 BE_XMAX, BE_YMAX, BE_VCHAR, BE_HCHAR,
375 BE_VTIC, BE_HTIC, BE_options, BE_init, BE_reset,
376 BE_text, null_scale, BE_graphics, BE_move, BE_vector,
377 BE_linetype, BE_put_text, null_text_angle,
378 BE_justify_text, BE_point, do_arrow, set_font_null,
379 BE_pointsize, TERM_CAN_MULTIPLOT,
380 BE_text /* suspend can use same routine */ , 0 /* resume */ ,
381 BE_fillbox, BE_linewidth
382 TERM_TABLE_END(BE_driver)
385 #define LAST_TERM be_driver
387 #endif /* TERM_TABLE */
388 #endif /* TERM_PROTO_ONLY */
394 "?commands set terminal be",
401 " `gnuplot` provides the `be` terminal type for use with X servers. This",
402 " terminal type is set automatically at startup if the `DISPLAY` environment",
403 " variable is set, if the `TERM` environment variable is set to `xterm`, or",
404 " if the `-display` command line option is used.",
407 " set terminal be {reset} {<n>}",
409 " Multiple plot windows are supported: `set terminal be <n>` directs the",
410 " output to plot window number n. If n>0, the terminal number will be",
411 " appended to the window title and the icon will be labeled `gplt <n>`.",
412 " The active window may distinguished by a change in cursor (from default",
415 " Plot windows remain open even when the `gnuplot` driver is changed to a",
416 " different device. A plot window can be closed by pressing the letter q",
417 " while that window has input focus, or by choosing `close` from a window",
418 " manager menu. All plot windows can be closed by specifying `reset`, which",
419 " actually terminates the subprocess which maintains the windows (unless",
420 " `-persist` was specified).",
422 " Plot windows will automatically be closed at the end of the session",
423 " unless the `-persist` option was given.",
425 " The size or aspect ratio of a plot may be changed by resizing the `gnuplot`",
428 " Linewidths and pointsizes may be changed from within `gnuplot` with",
431 " For terminal type `be`, `gnuplot` accepts (when initialized) the standard",
432 " X Toolkit options and resources such as geometry, font, and name from the",
433 " command line arguments or a configuration file. See the X(1) man page",
434 " (or its equivalent) for a description of such options.",
436 " A number of other `gnuplot` options are available for the `be` terminal.",
437 " These may be specified either as command-line options when `gnuplot` is",
438 " invoked or as resources in the configuration file \".Xdefaults\". They are",
439 " set upon initialization and cannot be altered during a `gnuplot` session.",
440 "2 command-line_options",
441 "?commands set terminal be command-line-options",
442 "?set terminal be command-line-options",
443 "?set term be command-line-options",
444 "?be command-line-options",
445 " In addition to the X Toolkit options, the following options may be specified",
446 " on the command line when starting `gnuplot` or as resources in your",
447 " \".Xdefaults\" file:",
448 "@start table - first is interactive cleartext form",
449 " `-mono` forces monochrome rendering on color displays.",
450 " `-gray` requests grayscale rendering on grayscale or color displays.",
451 " (Grayscale displays receive monochrome rendering by default.)",
452 " `-clear` requests that the window be cleared momentarily before a",
453 " new plot is displayed.",
454 " `-raise` raises plot window after each plot",
455 " `-noraise` does not raise plot window after each plot",
456 " `-persist` plots windows survive after main gnuplot program exits",
457 "#\\begin{tabular}{|cl|} \\hline",
458 "#`-mono` & forces monochrome rendering on color displays.\\\\",
459 "#`-gray` & requests grayscale rendering on grayscale or color displays.\\\\",
460 "# & (Grayscale displays receive monochrome rendering by default.) \\\\",
461 "#`-clear` & requests that the window be cleared momentarily before a\\\\",
462 "# & new plot is displayed. \\\\",
463 "#`-raise` & raises plot window after each plot. \\\\",
464 "#`-noraise` & does not raise plot window after each plot. \\\\",
465 "#`-persist`&plots windows survive after main gnuplot program exits. \\\\",
467 "%`-mono`@forces monochrome rendering on color displays.",
468 "%`-gray`@requests grayscale rendering on grayscale or color displays.",
469 "% @(Grayscale displays receive monochrome rendering by default.)",
470 "%`-clear`@requests that the window be cleared momentarily before a",
471 "% @new plot is displayed.",
472 "%`-raise`@raises plot window after each plot",
473 "%`-noraise`@does not raise plot window after each plot",
474 "%`-persist`@plots windows survive after main gnuplot program exits",
476 " The options are shown above in their command-line syntax. When entered as",
477 " resources in \".Xdefaults\", they require a different syntax.",
482 " `gnuplot` also provides a command line option (`-pointsize <v>`) and a",
483 " resource, `gnuplot*pointsize: <v>`, to control the size of points plotted",
484 " with the `points` plotting style. The value `v` is a real number (greater",
485 " than 0 and less than or equal to ten) used as a scaling factor for point",
486 " sizes. For example, `-pointsize 2` uses points twice the default size, and",
487 " `-pointsize 0.5` uses points half the normal size.",
488 "2 monochrome_options",
489 "?commands set terminal be monochrome_options",
490 "?set terminal be monochrome_options",
491 "?set term be monochrome_options",
492 "?be monochrome_options",
493 " For monochrome displays, `gnuplot` does not honor foreground or background",
494 " colors. The default is black-on-white. `-rv` or `gnuplot*reverseVideo: on`",
495 " requests white-on-black.",
498 "?commands set terminal be color_resources",
499 "?set terminal be color_resources",
500 "?set term be color_resources",
501 "?be color_resources",
502 " For color displays, `gnuplot` honors the following resources (shown here",
503 " with their default values) or the greyscale resources. The values may be",
504 " color names as listed in the BE rgb.txt file on your system, hexadecimal",
505 " RGB color specifications (see BE documentation), or a color name followed",
506 " by a comma and an `intensity` value from 0 to 1. For example, `blue, 0.5`",
507 " means a half intensity blue.",
508 "@start table - first is interactive cleartext form",
509 " gnuplot*background: white",
510 " gnuplot*textColor: black",
511 " gnuplot*borderColor: black",
512 " gnuplot*axisColor: black",
513 " gnuplot*line1Color: red",
514 " gnuplot*line2Color: green",
515 " gnuplot*line3Color: blue",
516 " gnuplot*line4Color: magenta",
517 " gnuplot*line5Color: cyan",
518 " gnuplot*line6Color: sienna",
519 " gnuplot*line7Color: orange",
520 " gnuplot*line8Color: coral",
521 "#\\begin{tabular}{|cl|} \\hline",
522 "#&gnuplot*background: white\\\\",
523 "#&gnuplot*textColor: black\\\\",
524 "#&gnuplot*borderColor: black\\\\",
525 "#&gnuplot*axisColor: black\\\\",
526 "#&gnuplot*line1Color: red\\\\",
527 "#&gnuplot*line2Color: green\\\\",
528 "#&gnuplot*line3Color: blue\\\\",
529 "#&gnuplot*line4Color: magenta\\\\",
530 "#&gnuplot*line5Color: cyan\\\\",
531 "#&gnuplot*line6Color: sienna\\\\",
532 "#&gnuplot*line7Color: orange\\\\",
533 "#&gnuplot*line8Color: coral\\\\",
535 "%@gnuplot*background: white",
536 "%@gnuplot*textColor: black",
537 "%@gnuplot*borderColor: black",
538 "%@gnuplot*axisColor: black",
539 "%@gnuplot*line1Color: red",
540 "%@gnuplot*line2Color: green",
541 "%@gnuplot*line3Color: blue",
542 "%@gnuplot*line4Color: magenta",
543 "%@gnuplot*line5Color: cyan",
544 "%@gnuplot*line6Color: sienna",
545 "%@gnuplot*line7Color: orange",
546 "%@gnuplot*line8Color: coral",
549 " The command-line syntax for these is, for example,",
552 " gnuplot -background coral",
554 "2 grayscale_resources",
555 "?commands set terminal be grayscale_resources",
556 "?set terminal be grayscale_resources",
557 "?set term be grayscale_resources",
558 "?be grayscale_resources",
559 " When `-gray` is selected, `gnuplot` honors the following resources for",
560 " grayscale or color displays (shown here with their default values). Note",
561 " that the default background is black.",
562 "@start table - first is interactive cleartext form",
563 " gnuplot*background: black",
564 " gnuplot*textGray: white",
565 " gnuplot*borderGray: gray50",
566 " gnuplot*axisGray: gray50",
567 " gnuplot*line1Gray: gray100",
568 " gnuplot*line2Gray: gray60",
569 " gnuplot*line3Gray: gray80",
570 " gnuplot*line4Gray: gray40",
571 " gnuplot*line5Gray: gray90",
572 " gnuplot*line6Gray: gray50",
573 " gnuplot*line7Gray: gray70",
574 " gnuplot*line8Gray: gray30",
575 "#\\begin{tabular}{|cl|} \\hline",
576 "#&gnuplot*background: black\\\\",
577 "#&gnuplot*textGray: white\\\\",
578 "#&gnuplot*borderGray: gray50\\\\",
579 "#&gnuplot*axisGray: gray50\\\\",
580 "#&gnuplot*line1Gray: gray100\\\\",
581 "#&gnuplot*line2Gray: gray60\\\\",
582 "#&gnuplot*line3Gray: gray80\\\\",
583 "#&gnuplot*line4Gray: gray40\\\\",
584 "#&gnuplot*line5Gray: gray90\\\\",
585 "#&gnuplot*line6Gray: gray50\\\\",
586 "#&gnuplot*line7Gray: gray70\\\\",
587 "#&gnuplot*line8Gray: gray30\\\\",
589 "%@gnuplot*background: black",
590 "%@gnuplot*textGray: white",
591 "%@gnuplot*borderGray: gray50",
592 "%@gnuplot*axisGray: gray50",
593 "%@gnuplot*line1Gray: gray100",
594 "%@gnuplot*line2Gray: gray60",
595 "%@gnuplot*line3Gray: gray80",
596 "%@gnuplot*line4Gray: gray40",
597 "%@gnuplot*line5Gray: gray90",
598 "%@gnuplot*line6Gray: gray50",
599 "%@gnuplot*line7Gray: gray70",
600 "%@gnuplot*line8Gray: gray30",
604 "?commands set terminal be line_resources",
605 "?set terminal be line_resources",
606 "?set term be line_resources",
607 "?be line_resources",
608 " `gnuplot` honors the following resources for setting the width (in pixels) of",
609 " plot lines (shown here with their default values.) 0 or 1 means a minimal",
610 " width line of 1 pixel width. A value of 2 or 3 may improve the appearance of",
612 "@start table - first is interactive cleartext form",
613 " gnuplot*borderWidth: 2",
614 " gnuplot*axisWidth: 0",
615 " gnuplot*line1Width: 0",
616 " gnuplot*line2Width: 0",
617 " gnuplot*line3Width: 0",
618 " gnuplot*line4Width: 0",
619 " gnuplot*line5Width: 0",
620 " gnuplot*line6Width: 0",
621 " gnuplot*line7Width: 0",
622 " gnuplot*line8Width: 0",
623 "#\\begin{tabular}{|cl|} \\hline",
624 "#&gnuplot*borderWidth: 2\\\\",
625 "#&gnuplot*axisWidth: 0\\\\",
626 "#&gnuplot*line1Width: 0\\\\",
627 "#&gnuplot*line2Width: 0\\\\",
628 "#&gnuplot*line3Width: 0\\\\",
629 "#&gnuplot*line4Width: 0\\\\",
630 "#&gnuplot*line5Width: 0\\\\",
631 "#&gnuplot*line6Width: 0\\\\",
632 "#&gnuplot*line7Width: 0\\\\",
633 "#&gnuplot*line8Width: 0\\\\",
635 "%@gnuplot*borderWidth: 2",
636 "%@gnuplot*axisWidth: 0",
637 "%@gnuplot*line1Width: 0",
638 "%@gnuplot*line2Width: 0",
639 "%@gnuplot*line3Width: 0",
640 "%@gnuplot*line4Width: 0",
641 "%@gnuplot*line5Width: 0",
642 "%@gnuplot*line6Width: 0",
643 "%@gnuplot*line7Width: 0",
644 "%@gnuplot*line8Width: 0",
647 " `gnuplot` honors the following resources for setting the dash style used for",
648 " plotting lines. 0 means a solid line. A two-digit number `jk` (`j` and `k`",
649 " are >= 1 and <= 9) means a dashed line with a repeated pattern of `j` pixels",
650 " on followed by `k` pixels off. For example, '16' is a \"dotted\" line with one",
651 " pixel on followed by six pixels off. More elaborate on/off patterns can be",
652 " specified with a four-digit value. For example, '4441' is four on, four off,",
653 " four on, one off. The default values shown below are for monochrome displays",
654 " or monochrome rendering on color or grayscale displays. For color displays,",
655 " the default for each is 0 (solid line) except for `axisDashes` which defaults",
656 " to a '16' dotted line.",
657 "@start table - first is interactive cleartext form",
658 " gnuplot*borderDashes: 0",
659 " gnuplot*axisDashes: 16",
660 " gnuplot*line1Dashes: 0",
661 " gnuplot*line2Dashes: 42",
662 " gnuplot*line3Dashes: 13",
663 " gnuplot*line4Dashes: 44",
664 " gnuplot*line5Dashes: 15",
665 " gnuplot*line6Dashes: 4441",
666 " gnuplot*line7Dashes: 42",
667 " gnuplot*line8Dashes: 13",
668 "#\\begin{tabular}{|cl|} \\hline",
669 "#&gnuplot*borderDashes: 0\\\\",
670 "#&gnuplot*axisDashes: 16\\\\",
671 "#&gnuplot*line1Dashes: 0\\\\",
672 "#&gnuplot*line2Dashes: 42\\\\",
673 "#&gnuplot*line3Dashes: 13\\\\",
674 "#&gnuplot*line4Dashes: 44\\\\",
675 "#&gnuplot*line5Dashes: 15\\\\",
676 "#&gnuplot*line6Dashes: 4441\\\\",
677 "#&gnuplot*line7Dashes: 42\\\\",
678 "#&gnuplot*line8Dashes: 13\\\\",
680 "%@gnuplot*borderDashes: 0",
681 "%@gnuplot*axisDashes: 16",
682 "%@gnuplot*line1Dashes: 0",
683 "%@gnuplot*line2Dashes: 42",
684 "%@gnuplot*line3Dashes: 13",
685 "%@gnuplot*line4Dashes: 44",
686 "%@gnuplot*line5Dashes: 15",
687 "%@gnuplot*line6Dashes: 4441",
688 "%@gnuplot*line7Dashes: 42",
689 "%@gnuplot*line8Dashes: 13",
692 #endif /* TERM_HELP */