home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume30 / gnuplot3 / patch02g < prev    next >
Encoding:
Text File  |  1992-06-18  |  30.1 KB  |  879 lines

  1. Newsgroups: comp.sources.misc
  2. From: woo@ra-next.arc.nasa.gov (Alex Woo)
  3. Subject:  v30i060:  gnuplot3 - interactive function plotting utility, Patch02g/7
  4. Message-ID: <1992Jun14.214212.8711@sparky.imd.sterling.com>
  5. X-Md4-Signature: 461918f84995dba0cd2cb370bd047d58
  6. Date: Sun, 14 Jun 1992 21:42:12 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: woo@ra-next.arc.nasa.gov (Alex Woo)
  10. Posting-number: Volume 30, Issue 60
  11. Archive-name: gnuplot3/patch02g
  12. Environment: UNIX, MS-DOS, VMS
  13. Patch-To: gnuplot3: Volume 24, Issue 23-48
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then feed it
  17. # into a shell via "sh file" or similar.  To overwrite existing files,
  18. # type "sh file -c".
  19. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  20. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  21. # Contents:  patch.2
  22. # Wrapped by woo@ra-iris. on Thu May 28 22:44:40 1992
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 7 (of 7)."'
  26. if test -f 'patch.2' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'patch.2'\"
  28. else
  29.   echo shar: Extracting \"'patch.2'\" \(28136 characters\)
  30.   sed "s/^X//" >'patch.2' <<'END_OF_FILE'
  31. Xdiff -rc gnuplot/gnuplot_x11.c gnuplot3.2/gnuplot_x11.c
  32. X*** gnuplot/gnuplot_x11.c    Mon Sep  9 13:13:19 1991
  33. X--- gnuplot3.2/gnuplot_x11.c    Tue May  5 21:42:20 1992
  34. X***************
  35. X*** 1,3 ****
  36. X--- 1,7 ----
  37. X+ #ifndef lint
  38. X+ static char *RCSid = "$Id: gnuplot_x11.c,v 3.26 92/03/24 22:35:52 woo Exp Locker: woo $";
  39. X+ #endif
  40. X+ 
  41. X  /*-----------------------------------------------------------------------------
  42. X   *   gnuplot_x11 - X11 outboard terminal driver for gnuplot 3
  43. X   *
  44. X***************
  45. X*** 4,130 ****
  46. X   *   Requires installation of companion inboard x11 driver in gnuplot/term.c
  47. X   *
  48. X   *   Acknowledgements: 
  49. X!  *      Chris Peterson (MIT) - original Xlib gnuplot support (and Xaw examples)
  50. X!  *      Dana Chee (Bellcore)  - mods to original support for gnuplot 2.0
  51. X!  *      Arthur Smith (Cornell) - graphical-label-widget idea (xplot)
  52. X!  *      Hendri Hondorp (University of Twente, The Netherlands) - Motif xgnuplot
  53. X   *
  54. X   *   This code is provided as is and with no warranties of any kind.
  55. X   *       
  56. X!  *   Ed Kubaitis - Computing Services Office -  University of Illinois, Urbana
  57. X   *---------------------------------------------------------------------------*/
  58. X   
  59. X  #include <stdio.h>
  60. X  #include <signal.h>
  61. X- #include <X11/Intrinsic.h>
  62. X- #include <X11/StringDefs.h>
  63. X- #include <Label.h>          /* use -Idir for location on your system */
  64. X- #ifdef MOTIF
  65. X- #include <Xm.h>             /* use -Idir for location on your system */
  66. X- #define LabelWC xmLabelWidgetClass
  67. X- #define LabelBPM XmNbackgroundPixmap
  68. X- #else
  69. X- #define LabelWC labelWidgetClass
  70. X- #define LabelBPM XtNbitmap
  71. X- #endif
  72. X  
  73. X! #define Color (D>1)
  74. X! #define Ncolors 11
  75. X  unsigned long colors[Ncolors];
  76. X- char color_keys[Ncolors][30] =   { "text", "border", "axis", 
  77. X-    "line1", "line2", "line3", "line4", "line5", "line6", "line7", "line8" };
  78. X- char color_values[Ncolors][30] = { "black", "black", "black", 
  79. X-    "red",  "green", "blue",  "magenta", "cyan", "sienna", "orange", "coral" };
  80. X  
  81. X  char dashes[10][5] = { {0}, {1,6,0}, 
  82. X     {0}, {4,2,0}, {1,3,0}, {4,4,0}, {1,5,0}, {4,4,4,1,0}, {4,2,0}, {1,3,0}
  83. X     };
  84. X  
  85. X! Widget w_top, w_label; Window win; Display *dpy;
  86. X! Pixmap pixmap;  GC gc = (GC)NULL;
  87. X! Dimension W = 640 , H = 450;  int D;
  88. X! Arg args[5];
  89. X! static void gnuplot(), resize();
  90. X  
  91. X  int cx=0, cy=0, vchar, nc = 0, ncalloc = 0;
  92. X  double xscale, yscale;
  93. X! #define X(x) (Dimension) (x * xscale)
  94. X! #define Y(y) (Dimension) ((4095-y) * yscale)
  95. X  enum JUSTIFY { LEFT, CENTRE, RIGHT } jmode;
  96. X  #define Nbuf 1024
  97. X! char buf[Nbuf];
  98. X! String *commands = NULL;
  99. X  
  100. X! typedef struct {       /* See "X Toolkit Intrinsics Programming Manual"      */
  101. X!   XFontStruct *font;   /* Nye and O'Reilly, O'Reilly & Associates, pp. 80-85 */
  102. X!   unsigned long fg;
  103. X!   unsigned long bg;
  104. X!   } RValues, *RVptr; 
  105. X! RValues rv;
  106. X  
  107. X- XtResource resources[] = {
  108. X-    { XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), 
  109. X-      XtOffset(RVptr, font), XtRString, "fixed" },
  110. X-    { XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), 
  111. X-      XtOffset(RVptr, fg), XtRString, XtDefaultForeground },
  112. X-    { XtNbackground, XtCBackground, XtRPixel, sizeof(Pixel), 
  113. X-      XtOffset(RVptr, bg), XtRString, XtDefaultBackground },
  114. X-    };
  115. X  
  116. X  /*-----------------------------------------------------------------------------
  117. X!  *   main program - fire up application and callbacks
  118. X   *---------------------------------------------------------------------------*/
  119. X  
  120. X  main(argc, argv) int argc; char *argv[]; {
  121. X  
  122. X!    signal(SIGINT, SIG_IGN);
  123. X! #ifdef SIGTSTP
  124. X!    signal(SIGTSTP, SIG_IGN);
  125. X! #endif
  126. X  
  127. X!    /* initialize application */
  128. X!    w_top = XtInitialize("gnuplot", "Gnuplot", NULL, 0, &argc, argv);
  129. X!    XtSetArg(args[0], XtNwidth, W);
  130. X!    XtSetArg(args[1], XtNheight, H);
  131. X!    w_label = XtCreateManagedWidget ("", LabelWC, w_top, args, (Cardinal)2);
  132. X!    XtRealizeWidget(w_top);
  133. X  
  134. X!    /* extract needed information */
  135. X!    dpy = XtDisplay(w_top); win = XtWindow(w_label);
  136. X!    D = DisplayPlanes(dpy,DefaultScreen(dpy));
  137. X!    if (Color) {
  138. X!       char option[20], *value; 
  139. X!       XColor used, exact; int n;
  140. X  
  141. X!       for(n=0; n<Ncolors; n++) {
  142. X!      strcpy(option, color_keys[n]);
  143. X!      strcat(option, "Color");
  144. X!      value = XGetDefault(dpy, "gnuplot", option);
  145. X!      if (!value) { value = color_values[n]; }
  146. X!      if (XAllocNamedColor(dpy, DefaultColormap(dpy,0), value, &used,&exact))
  147. X!         colors[n] = used.pixel; 
  148. X!      else {
  149. X!         fprintf(stderr, "gnuplot: cannot allocate %s:%s\n", option, value);
  150. X!         fprintf(stderr, "gnuplot: assuming %s:black\n", option);
  151. X!         colors[n] = BlackPixel(dpy,0);
  152. X          }
  153. X       }
  154. X        }
  155. X!    XtSetArg(args[0], XtNwidth, &W);
  156. X!    XtSetArg(args[1], XtNheight,&H);
  157. X!    XtGetValues(w_label, args, (Cardinal)2);
  158. X!    XtGetApplicationResources(w_top, &rv, resources, XtNumber(resources),NULL,0);
  159. X!    vchar = (rv.font->ascent + rv.font->descent);
  160. X  
  161. X!    /* add callbacks on input-from-gnuplot-on-stdin & window-resized */
  162. X!    XtAddInput(0, XtInputReadMask, gnuplot, NULL);
  163. X!    XtAddEventHandler(w_label, StructureNotifyMask, FALSE, resize, NULL);
  164. X  
  165. X!    XtMainLoop();
  166. X     }
  167. X  
  168. X  /*-----------------------------------------------------------------------------
  169. X!  *   display - display accumulated commands from inboard driver
  170. X   *---------------------------------------------------------------------------*/
  171. X  
  172. X  display() {
  173. X--- 8,186 ----
  174. X   *   Requires installation of companion inboard x11 driver in gnuplot/term.c
  175. X   *
  176. X   *   Acknowledgements: 
  177. X!  *      Chris Peterson (MIT)
  178. X!  *      Dana Chee (Bellcore) 
  179. X!  *      Arthur Smith (Cornell)
  180. X!  *      Hendri Hondorp (University of Twente, The Netherlands)
  181. X!  *      Bill Kucharski (Solbourne)
  182. X!  *      Charlie Kline (University of Illinois)
  183. X!  *      O'Reilly & Associates: X Window System - Volumes 1 & 2
  184. X   *
  185. X   *   This code is provided as is and with no warranties of any kind.
  186. X   *       
  187. X!  *   Ed Kubaitis (ejk@uiuc.edu)
  188. X!  *   Computing & Communications Services Office 
  189. X!  *   University of Illinois, Urbana
  190. X   *---------------------------------------------------------------------------*/
  191. X+ 
  192. X+ #include <X11/Xos.h>
  193. X+ #include <X11/Xlib.h>
  194. X+ #include <X11/Xutil.h>
  195. X+ #include <X11/Xatom.h>
  196. X+ #include <X11/Xresource.h>
  197. X   
  198. X  #include <stdio.h>
  199. X  #include <signal.h>
  200. X  
  201. X! #ifndef FD_SET
  202. X! #ifndef OLD_SELECT
  203. X! #include <sys/select.h>
  204. X! #else   /* OLD_SELECT */
  205. X! #define FD_SET(n, p)    ((p)->fds_bits[0] |= (1 << ((n) % 32)))
  206. X! #define FD_CLR(n, p)    ((p)->fds_bits[0] &= ~(1 << ((n) % 32)))
  207. X! #define FD_ISSET(n, p)  ((p)->fds_bits[0] & (1 << ((n) % 32)))
  208. X! #define FD_ZERO(p)      bzero((char *)(p), sizeof(*(p)))
  209. X! #endif  /* OLD_SELECT */
  210. X! #endif  /* FD_SET */
  211. X! 
  212. X! #include <errno.h>
  213. X! extern int errno;
  214. X! 
  215. X! #define FallbackFont "fixed"
  216. X! #define Ncolors 13
  217. X  unsigned long colors[Ncolors];
  218. X  
  219. X  char dashes[10][5] = { {0}, {1,6,0}, 
  220. X     {0}, {4,2,0}, {1,3,0}, {4,4,0}, {1,5,0}, {4,4,4,1,0}, {4,2,0}, {1,3,0}
  221. X     };
  222. X  
  223. X! Display *dpy; int scr; Window win, root;
  224. X! Visual *vis; GC gc = (GC)0; Pixmap pixmap; XFontStruct *font;
  225. X! unsigned int W = 640, H = 450; int D, gX = 100, gY = 100;
  226. X  
  227. X+ Bool Mono = 0, Gray = 0, Rv = 0, Clear = 0;
  228. X+ char Name[64] = "gnuplot";
  229. X+ char Class[64] = "Gnuplot";
  230. X+ 
  231. X  int cx=0, cy=0, vchar, nc = 0, ncalloc = 0;
  232. X  double xscale, yscale;
  233. X! #define X(x) (int) (x * xscale)
  234. X! #define Y(y) (int) ((4095-y) * yscale)
  235. X  enum JUSTIFY { LEFT, CENTRE, RIGHT } jmode;
  236. X+ 
  237. X  #define Nbuf 1024
  238. X! char buf[Nbuf], **commands = (char **)0;
  239. X  
  240. X! FILE *X11_ipc = stdin;
  241. X! char X11_ipcpath[32];
  242. X  
  243. X  
  244. X  /*-----------------------------------------------------------------------------
  245. X!  *   main program 
  246. X   *---------------------------------------------------------------------------*/
  247. X  
  248. X  main(argc, argv) int argc; char *argv[]; {
  249. X  
  250. X!    preset(argc, argv);
  251. X!    mainloop();
  252. X!    exit(0);
  253. X  
  254. X!    }
  255. X  
  256. X! /*-----------------------------------------------------------------------------
  257. X!  *   mainloop - process X events and input from gnuplot
  258. X!  *
  259. X!  *   On systems with a fully implemented select(), select is used (without
  260. X!  *   timeout) to sense both input from the X server network connection and
  261. X!  *   pipe input from gnuplot. On platforms with an incomplete or faulty 
  262. X!  *   select(), select (with timeout) is used for the server, and a temporary 
  263. X!  *   file rather than a pipe is used for gnuplot input.
  264. X!  *---------------------------------------------------------------------------*/
  265. X  
  266. X! mainloop() {
  267. X!    int nf, nfds, cn = ConnectionNumber(dpy), in = fileno(X11_ipc);
  268. X!    struct timeval timeout, *timer = (struct timeval *)0;
  269. X!    fd_set rset, tset;
  270. X!    unsigned long all = 0xffffffff;
  271. X!    XEvent xe;
  272. X! 
  273. X!    FD_ZERO(&rset);
  274. X!    FD_SET(cn, &rset);
  275. X! 
  276. X! #ifndef CRIPPLED_SELECT
  277. X!    FD_SET(in, &rset);
  278. X!    nfds = (cn > in) ? cn + 1 : in + 1;
  279. X! #else  /* CRIPPLED_SELECT */
  280. X!    timeout.tv_sec = 1;
  281. X!    timeout.tv_usec = 0;
  282. X!    timer = &timeout;
  283. X!    sprintf(X11_ipcpath, "/tmp/Gnuplot_%d", getppid());
  284. X!    nfds = cn + 1;
  285. X! #endif /* CRIPPLED_SELECT */
  286. X! 
  287. X!    while(1) {
  288. X!       tset = rset;
  289. X!       nf = select(nfds, &tset, (fd_set *)0, (fd_set *)0, timer);
  290. X!       if (nf < 0) {
  291. X!      if (errno == EINTR) continue;
  292. X!      fprintf(stderr, "gnuplot: select failed. errno:%d\n", errno);
  293. X!      exit(1);
  294. X!      }
  295. X!       nf > 0 && XNoOp(dpy);
  296. X!       if (FD_ISSET(cn, &tset)) {
  297. X!      while (XCheckMaskEvent(dpy, all, &xe)) {
  298. X!         (xe.type == ConfigureNotify)  && resize(&xe); 
  299. X          }
  300. X       }
  301. X+ #ifndef CRIPPLED_SELECT
  302. X+       FD_ISSET(in, &tset) && accept();
  303. X+ #else  /* CRIPPLED_SELECT */
  304. X+       if ((X11_ipc = fopen(X11_ipcpath, "r"))) {
  305. X+      unlink(X11_ipcpath);
  306. X+      accept();
  307. X+      fclose(X11_ipc);
  308. X+      }
  309. X+ #endif /* CRIPPLED_SELECT */
  310. X        }
  311. X!    }
  312. X  
  313. X! /*-----------------------------------------------------------------------------
  314. X!  *   accept - accept & record new plot from gnuplot inboard X11 driver
  315. X!  *---------------------------------------------------------------------------*/
  316. X  
  317. X! accept() {
  318. X! 
  319. X!    while (fgets(buf, Nbuf, X11_ipc)) {
  320. X!      if (*buf == 'G') {                           /* enter graphics mode */
  321. X!      if (commands) {
  322. X!         int n; for (n=0; n<nc; n++) free(commands[n]);
  323. X!         free(commands);
  324. X!         }
  325. X!      commands = (char **)0; nc = ncalloc = 0;
  326. X!          }
  327. X!       else if (*buf == 'E') { display(); break; } /* leave graphics mode */
  328. X!       else if (*buf == 'R') { exit(0); }          /* leave X11/x11 mode  */
  329. X!       else {                                      /* record command      */
  330. X!      char *p;
  331. X!      if (nc >= ncalloc) {
  332. X!         ncalloc = ncalloc*2 + 1;
  333. X!         commands = (commands)
  334. X!            ? (char **)realloc(commands, ncalloc * sizeof(char *))
  335. X!            : (char **)malloc(sizeof(char *));
  336. X!         }
  337. X!      p = (char *)malloc((unsigned)strlen(buf)+1);
  338. X!      if (!commands || !p) {
  339. X!         fprintf(stderr, "gnuplot: can't get memory. X11 aborted.\n");
  340. X!         exit(1);
  341. X!         }
  342. X!      commands[nc++] = strcpy(p, buf);
  343. X!      }
  344. X!       }
  345. X!    if (feof(X11_ipc) || ferror(X11_ipc)) exit(1);
  346. X     }
  347. X  
  348. X  /*-----------------------------------------------------------------------------
  349. X!  *   display - display last plot from gnuplot inboard X11 driver
  350. X   *---------------------------------------------------------------------------*/
  351. X  
  352. X  display() {
  353. X***************
  354. X*** 131,166 ****
  355. X     int n, x, y, sw, sl, lt, width, type;
  356. X     char *buf, *str;
  357. X  
  358. X     /* set scaling factor between internal driver & window geometry */
  359. X     xscale = (double)W / 4096.;  yscale = (double)H / 4096.;  
  360. X  
  361. X     /* create new pixmap & GC */
  362. X     if (gc) { XFreeGC(dpy, gc); XFreePixmap(dpy, pixmap); }
  363. X!    pixmap = XCreatePixmap(dpy, RootWindow(dpy,DefaultScreen(dpy)), W, H, D);
  364. X!    gc = XCreateGC(dpy, pixmap, 0, NULL);
  365. X!    XSetFont(dpy, gc, rv.font->fid);
  366. X  
  367. X!    /* erase pixmap */
  368. X! #ifndef MOTIF
  369. X!    if (Color) { /* Athena needs different erase for color and mono */
  370. X! #endif
  371. X!       XSetForeground(dpy, gc, rv.bg);
  372. X!       XFillRectangle(dpy, pixmap, gc, 0, 0, W, H);
  373. X!       XSetForeground(dpy, gc, rv.fg);
  374. X!       XSetBackground(dpy, gc, rv.bg);
  375. X! #ifndef MOTIF
  376. X!       }
  377. X!    else {  
  378. X!       XSetFunction(dpy, gc, GXxor);
  379. X!       XCopyArea(dpy, pixmap, pixmap, gc, 0, 0, W, H, 0, 0);
  380. X!       XSetFunction(dpy, gc, GXcopyInverted);
  381. X!       }
  382. X! #endif
  383. X  
  384. X!    /* connect new pixmap to label widget */
  385. X!    XtSetArg(args[0], LabelBPM, pixmap);
  386. X!    XtSetValues(w_label, args, (Cardinal)1);
  387. X  
  388. X     /* loop over accumulated commands from inboard driver */
  389. X     for (n=0; n<nc; n++) {
  390. X        buf = commands[n];
  391. X--- 187,217 ----
  392. X     int n, x, y, sw, sl, lt, width, type;
  393. X     char *buf, *str;
  394. X  
  395. X+    if (!nc) return;
  396. X+ 
  397. X     /* set scaling factor between internal driver & window geometry */
  398. X     xscale = (double)W / 4096.;  yscale = (double)H / 4096.;  
  399. X  
  400. X     /* create new pixmap & GC */
  401. X     if (gc) { XFreeGC(dpy, gc); XFreePixmap(dpy, pixmap); }
  402. X!    pixmap = XCreatePixmap(dpy, root, W, H, D);
  403. X!    gc = XCreateGC(dpy, pixmap, 0, (XGCValues *)0);
  404. X!    XSetFont(dpy, gc, font->fid);
  405. X  
  406. X!    /* set pixmap background */
  407. X!    XSetForeground(dpy, gc, colors[0]);
  408. X!    XFillRectangle(dpy, pixmap, gc, 0, 0, W, H);
  409. X!    XSetBackground(dpy, gc, colors[0]);
  410. X  
  411. X!    /* set new pixmap as window background */
  412. X!    XSetWindowBackgroundPixmap(dpy, win, pixmap);
  413. X  
  414. X+    /* momentarily clear the window first if requested */
  415. X+    if (Clear) {
  416. X+       XClearWindow(dpy, win);
  417. X+       XFlush(dpy);
  418. X+       }
  419. X+ 
  420. X     /* loop over accumulated commands from inboard driver */
  421. X     for (n=0; n<nc; n++) {
  422. X        buf = commands[n];
  423. X***************
  424. X*** 180,198 ****
  425. X        else if (*buf == 'T') { 
  426. X       sscanf(buf, "T%4d%4d", &x, &y);  
  427. X       str = buf + 9; sl = strlen(str) - 1;
  428. X!      sw = XTextWidth(rv.font, str, sl);
  429. X       switch(jmode) {
  430. X          case LEFT:   sw = 0;     break;
  431. X          case CENTRE: sw = -sw/2; break;
  432. X          case RIGHT:  sw = -sw;   break;
  433. X          }
  434. X!      if (!Color) 
  435. X!         XDrawString(dpy, pixmap, gc, X(x)+sw, Y(y)+vchar/3, str, sl);
  436. X!      else { 
  437. X!         XSetForeground(dpy, gc, colors[0]);
  438. X!         XDrawString(dpy, pixmap, gc, X(x)+sw, Y(y)+vchar/3, str, sl);
  439. X!         XSetForeground(dpy, gc, colors[lt+1]);
  440. X!         }
  441. X       }
  442. X  
  443. X        /*   X11_justify_text(mode) - set text justification mode  */
  444. X--- 231,245 ----
  445. X        else if (*buf == 'T') { 
  446. X       sscanf(buf, "T%4d%4d", &x, &y);  
  447. X       str = buf + 9; sl = strlen(str) - 1;
  448. X!      sw = XTextWidth(font, str, sl);
  449. X       switch(jmode) {
  450. X          case LEFT:   sw = 0;     break;
  451. X          case CENTRE: sw = -sw/2; break;
  452. X          case RIGHT:  sw = -sw;   break;
  453. X          }
  454. X!      XSetForeground(dpy, gc, colors[2]);
  455. X!      XDrawString(dpy, pixmap, gc, X(x)+sw, Y(y)+vchar/3, str, sl);
  456. X!      XSetForeground(dpy, gc, colors[lt+3]);
  457. X       }
  458. X  
  459. X        /*   X11_justify_text(mode) - set text justification mode  */
  460. X***************
  461. X*** 204,210 ****
  462. X       sscanf(buf, "L%4d", <);
  463. X       lt = (lt%8)+2;
  464. X       width = (lt == 0) ? 2 : 0;
  465. X!      if (Color) {
  466. X          if (lt != 1) 
  467. X             type = LineSolid;
  468. X          else {
  469. X--- 251,257 ----
  470. X       sscanf(buf, "L%4d", <);
  471. X       lt = (lt%8)+2;
  472. X       width = (lt == 0) ? 2 : 0;
  473. X!      if (!Mono) {
  474. X          if (lt != 1) 
  475. X             type = LineSolid;
  476. X          else {
  477. X***************
  478. X*** 211,217 ****
  479. X             type = LineOnOffDash;
  480. X             XSetDashes(dpy, gc, 0, dashes[lt], strlen(dashes[lt]));
  481. X             }
  482. X!         XSetForeground(dpy, gc, colors[lt+1]);
  483. X          }
  484. X       else {
  485. X          type  = (lt == 0 || lt == 2) ? LineSolid : LineOnOffDash;
  486. X--- 258,264 ----
  487. X             type = LineOnOffDash;
  488. X             XSetDashes(dpy, gc, 0, dashes[lt], strlen(dashes[lt]));
  489. X             }
  490. X!         XSetForeground(dpy, gc, colors[lt+3]);
  491. X          }
  492. X       else {
  493. X          type  = (lt == 0 || lt == 2) ? LineSolid : LineOnOffDash;
  494. X***************
  495. X*** 222,263 ****
  496. X       }
  497. X        }
  498. X  
  499. X!    /* trigger expose events to display pixmap */
  500. X!    XClearArea(dpy, win, 0, 0, 0, 0, True);
  501. X     }
  502. X  
  503. X  /*-----------------------------------------------------------------------------
  504. X!  *   gnuplot - Xt callback on input from gnuplot inboard X11 driver
  505. X!  *   resize - Xt callback when window resized
  506. X   *---------------------------------------------------------------------------*/
  507. X  
  508. X! static void
  509. X! gnuplot(cd, s, id) char *cd; int *s; XtInputId *id; {
  510. X  
  511. X!    while (fgets(buf, Nbuf, stdin)) {
  512. X!      if (*buf == 'G') {                           /* enter graphics mode */
  513. X!      if (commands) {
  514. X!         int n; for (n=0; n<nc; n++) XtFree(commands[n]);
  515. X!         XtFree(commands);
  516. X          }
  517. X-      commands = NULL; nc = ncalloc = 0;
  518. X-          }
  519. X-       else if (*buf == 'E') { display(); break; } /* leave graphics mode */
  520. X-       else if (*buf == 'R') { exit(0); }          /* leave X11/x11 mode  */
  521. X-       else {
  522. X-      if (nc >= ncalloc) {
  523. X-         ncalloc = ncalloc*2 + 1;
  524. X-         commands = (String *)XtRealloc(commands, ncalloc * sizeof(String));
  525. X-         }
  526. X-      commands[nc++] = XtNewString(buf);
  527. X       }
  528. X        }
  529. X!    if (feof(stdin) || ferror(stdin)) exit(0);
  530. X     }
  531. X  
  532. X! static void
  533. X! resize(w, cd, e) Widget w; char *cd; XConfigureEvent *e; {
  534. X!    if (e->type != ConfigureNotify) return;
  535. X!    W = e->width; H = e->height;
  536. X!    display(); 
  537. X     }
  538. X--- 269,584 ----
  539. X       }
  540. X        }
  541. X  
  542. X!    /* trigger exposure of background pixmap */
  543. X!    XClearWindow(dpy,win);
  544. X!    XFlush(dpy);
  545. X     }
  546. X  
  547. X  /*-----------------------------------------------------------------------------
  548. X!  *   resize - rescale last plot if window resized
  549. X   *---------------------------------------------------------------------------*/
  550. X  
  551. X! Bool init = True;
  552. X  
  553. X! resize(xce) XConfigureEvent *xce; {
  554. X!    if (!init || xce->width != W || xce->height != H) {
  555. X!       W = xce->width; H = xce->height;
  556. X!       display();
  557. X!       init = True;
  558. X!       }
  559. X!    }
  560. X! 
  561. X! 
  562. X! /*-----------------------------------------------------------------------------
  563. X!  *   preset - determine options, open display, create window
  564. X!  *---------------------------------------------------------------------------*/
  565. X! 
  566. X! #define On(v) ( !strcmp(v,"on") || !strcmp(v,"true") || \
  567. X!         !strcmp(v,"On") || !strcmp(v,"True") )
  568. X! 
  569. X! #define AppDefDir "/usr/lib/X11/app-defaults"
  570. X! #ifndef MAXHOSTNAMELEN
  571. X! #define MAXHOSTNAMELEN 64
  572. X! #endif
  573. X! 
  574. X! static XrmDatabase dbCmd, dbApp, dbDef, dbEnv, db = (XrmDatabase)0;
  575. X! 
  576. X! char *pr_GetR(), *getenv(), *type[20];
  577. X! XrmValue value;
  578. X! 
  579. X! #define Nopt 25
  580. X! static XrmOptionDescRec options[] = {
  581. X!    {"-mono",             ".mono",             XrmoptionNoArg,   "on" },
  582. X!    {"-gray",             ".gray",             XrmoptionNoArg,   "on" },
  583. X!    {"-clear",            ".clear",            XrmoptionNoArg,   "on" },
  584. X!    {"-display",          ".display",          XrmoptionSepArg,  NULL },
  585. X!    {"-name",             ".name",             XrmoptionSepArg,  NULL },
  586. X!    {"-geometry",         "*geometry",         XrmoptionSepArg,  NULL },
  587. X!    {"-background",       "*background",       XrmoptionSepArg,  NULL },
  588. X!    {"-bg",               "*background",       XrmoptionSepArg,  NULL },
  589. X!    {"-foreground",       "*foreground",       XrmoptionSepArg,  NULL },
  590. X!    {"-fg",               "*foreground",       XrmoptionSepArg,  NULL },
  591. X!    {"-bordercolor",      "*bordercolor",      XrmoptionSepArg,  NULL },
  592. X!    {"-bd",               "*bordercolor",      XrmoptionSepArg,  NULL },
  593. X!    {"-borderwidth",      ".borderwidth",      XrmoptionSepArg,  NULL },
  594. X!    {"-bw",               ".borderwidth",      XrmoptionSepArg,  NULL },
  595. X!    {"-font",             "*font",             XrmoptionSepArg,  NULL },
  596. X!    {"-fn",               "*font",             XrmoptionSepArg,  NULL },
  597. X!    {"-reverse",          "*reverseVideo",     XrmoptionNoArg,   "on" },
  598. X!    {"-rv",               "*reverseVideo",     XrmoptionNoArg,   "on" },
  599. X!    {"+rv",               "*reverseVideo",     XrmoptionNoArg,   "off"},
  600. X!    {"-iconic",           "*iconic",           XrmoptionNoArg,   "on" },
  601. X!    {"-synchronous",      "*synchronous",      XrmoptionNoArg,   "on" },
  602. X!    {"-xnllanguage",      "*xnllanguage",      XrmoptionSepArg,  NULL },
  603. X!    {"-selectionTimeout", "*selectionTimeout", XrmoptionSepArg,  NULL },
  604. X!    {"-title",            ".title",            XrmoptionSepArg,  NULL },
  605. X!    {"-xrm",              NULL,                XrmoptionResArg,  NULL },
  606. X!    };
  607. X! 
  608. X! preset(argc, argv) int argc; char *argv[]; {
  609. X!    int Argc = argc; char **Argv = argv;
  610. X! 
  611. X!    char *display = getenv("DISPLAY"),  *home = getenv("HOME");
  612. X!    char *server_defaults, *env, buf[256];
  613. X! 
  614. X!    /*---set to ignore ^C and ^Z----------------------------------------------*/
  615. X! 
  616. X!    signal(SIGINT, SIG_IGN);
  617. X! #ifdef SIGTSTP
  618. X!    signal(SIGTSTP, SIG_IGN);
  619. X! #endif
  620. X! 
  621. X!    /*---prescan arguments for "-name"----------------------------------------*/
  622. X! 
  623. X!    while(++Argv, --Argc > 0) {
  624. X!       if (!strcmp(*Argv, "-name") && Argc > 1) {
  625. X!      strncpy(Name, Argv[1], 64);
  626. X!      strncpy(Class, Argv[1], 64);
  627. X!      if (Class[0] >= 'a' && Class[0] <= 'z') Class[0] -= 0x20;
  628. X!      }
  629. X!       }
  630. X!    Argc = argc; Argv = argv;
  631. X! 
  632. X!    /*---parse command line---------------------------------------------------*/
  633. X! 
  634. X!    XrmInitialize();
  635. X!    XrmParseCommand(&dbCmd, options, Nopt, Name, &Argc, Argv);
  636. X!    if (Argc > 1) {
  637. X!       fprintf(stderr, "\ngnuplot: bad option: %s\n", Argv[1]);
  638. X!       fprintf(stderr, "gnuplot: X11 aborted.\n");
  639. X!       exit(1);
  640. X!       }
  641. X!    if (pr_GetR(dbCmd, ".display")) display = value.addr;
  642. X! 
  643. X!    /*---open display---------------------------------------------------------*/
  644. X! 
  645. X!    dpy = XOpenDisplay(display); 
  646. X!    if (!dpy) {
  647. X!       fprintf(stderr, "\ngnuplot: unable to open display '%s'\n", display);
  648. X!       fprintf(stderr, "gnuplot: X11 aborted.\n");
  649. X!       exit(1);
  650. X!       }
  651. X!    scr = DefaultScreen(dpy);
  652. X!    vis = DefaultVisual(dpy,scr);
  653. X!    D = DefaultDepth(dpy,scr);
  654. X!    root = DefaultRootWindow(dpy);
  655. X!    server_defaults = XResourceManagerString(dpy);
  656. X! 
  657. X!    /*---get application defaults--(subset of Xt processing)------------------*/
  658. X! 
  659. X!    sprintf(buf, "%s/%s", AppDefDir, "Gnuplot");
  660. X!    dbApp = XrmGetFileDatabase(buf);
  661. X!    XrmMergeDatabases(dbApp, &db);
  662. X! 
  663. X!    /*---get server or ~/.Xdefaults-------------------------------------------*/
  664. X! 
  665. X!    if (server_defaults)
  666. X!       dbDef = XrmGetStringDatabase(server_defaults);
  667. X!    else {
  668. X!       sprintf(buf, "%s/.Xdefaults", home);
  669. X!       dbDef = XrmGetFileDatabase(buf);
  670. X!       }
  671. X!    XrmMergeDatabases(dbDef, &db);
  672. X! 
  673. X!    /*---get XENVIRONMENT or  ~/.Xdefaults-hostname---------------------------*/
  674. X! 
  675. X!    if (env = getenv("XENVIRONMENT")) 
  676. X!       dbEnv = XrmGetFileDatabase(env);
  677. X!    else {
  678. X!       char *p, host[MAXHOSTNAMELEN];
  679. X!       if (gethostname(host, MAXHOSTNAMELEN) < 0) {
  680. X!      fprintf(stderr, "gnuplot: gethostname failed. X11 aborted.\n");
  681. X!      exit(1);
  682. X!      }
  683. X!       if (p = index(host, '.')) *p = '\0';
  684. X!       sprintf(buf, "%s/.Xdefaults-%s", home, host);
  685. X!       dbEnv = XrmGetFileDatabase(buf);
  686. X!       }
  687. X!    XrmMergeDatabases(dbEnv, &db);
  688. X! 
  689. X!    /*---merge command line options-------------------------------------------*/
  690. X! 
  691. X!    XrmMergeDatabases(dbCmd, &db);
  692. X! 
  693. X!    /*---determine geometry, font and colors----------------------------------*/
  694. X! 
  695. X!    pr_geometry();
  696. X!    pr_font();
  697. X!    pr_color();
  698. X! 
  699. X!    /*---create window--------------------------------------------------------*/
  700. X! 
  701. X!    pr_window();
  702. X! 
  703. X!    } 
  704. X! 
  705. X! /*-----------------------------------------------------------------------------
  706. X!  *   pr_GetR - get resource from database using "-name" option (if any)
  707. X!  *---------------------------------------------------------------------------*/
  708. X! 
  709. X! char *
  710. X! pr_GetR(db, resource) XrmDatabase db; char *resource; {
  711. X!    char name[128], class[128], *rc;
  712. X! 
  713. X!    strcpy(name, Name); strcat(name, resource);
  714. X!    strcpy(class, Class); strcat(class, resource);
  715. X!    rc = XrmGetResource(db, name, class, type, &value)
  716. X!       ? (char *)value.addr 
  717. X!       : (char *)0;
  718. X!    return(rc);
  719. X!    }
  720. X! 
  721. X! /*-----------------------------------------------------------------------------
  722. X!  *   pr_color - determine color values
  723. X!  *---------------------------------------------------------------------------*/
  724. X! 
  725. X! char color_keys[Ncolors][30] =   { 
  726. X!    "background", "bordercolor", "text", "border", "axis", 
  727. X!    "line1", "line2", "line3",  "line4", 
  728. X!    "line5", "line6", "line7",  "line8" 
  729. X!    };
  730. X! char color_values[Ncolors][30] = { 
  731. X!    "white", "black",  "black",  "black",  "black", 
  732. X!    "red",   "green",  "blue",   "magenta", 
  733. X!    "cyan",  "sienna", "orange", "coral" 
  734. X!    };
  735. X! char gray_values[Ncolors][30] = { 
  736. X!    "black",   "white",  "white",  "gray50", "gray50",
  737. X!    "gray100", "gray60", "gray80", "gray40", 
  738. X!    "gray90",  "gray50", "gray70", "gray30" 
  739. X!    };
  740. X! 
  741. X! pr_color() {
  742. X!    unsigned long black = BlackPixel(dpy, scr), white = WhitePixel(dpy,scr);
  743. X!    char option[20], *v, *type = (Gray) ? "Gray" : "Color";
  744. X!    XColor used, exact;
  745. X!    Colormap cmap;
  746. X!    int n;
  747. X! 
  748. X!    pr_GetR(db, ".mono")         && On(value.addr) && Mono++;
  749. X!    pr_GetR(db, ".gray")         && On(value.addr) && Gray++;
  750. X!    pr_GetR(db, ".reverseVideo") && On(value.addr) && Rv++;
  751. X! 
  752. X!    if (!Gray && (vis->class == GrayScale || vis->class == StaticGray)) Mono++;
  753. X! 
  754. X!    if (!Mono) {
  755. X!       cmap = DefaultColormap(dpy, scr);
  756. X!       for (n=0; n<Ncolors; n++) {
  757. X!      strcpy(option, ".");
  758. X!      strcat(option, color_keys[n]);
  759. X!      (n > 1) && strcat(option, type);
  760. X!      v = pr_GetR(db, option) 
  761. X!          ? value.addr
  762. X!          : ((Gray) ? gray_values[n] : color_values[n]);
  763. X!      if (XAllocNamedColor(dpy, cmap, v, &used, &exact))
  764. X!         colors[n] = used.pixel;
  765. X!      else {
  766. X!         fprintf(stderr, "\ngnuplot: can't allocate %s:%s\n", option, v);
  767. X!         fprintf(stderr, "gnuplot: reverting to monochrome\n");
  768. X!         Mono++; break;
  769. X          }
  770. X       }
  771. X        }
  772. X!    if (Mono) {
  773. X!       colors[0] = (Rv) ? black : white ;
  774. X!       for (n=1; n<Ncolors; n++)  colors[n] = (Rv) ? white : black;
  775. X!       }
  776. X     }
  777. X  
  778. X! /*-----------------------------------------------------------------------------
  779. X!  *   pr_font - determine font          
  780. X!  *---------------------------------------------------------------------------*/
  781. X! 
  782. X! pr_font() {
  783. X!    char *fontname = pr_GetR(db, ".font");
  784. X! 
  785. X!    if (!fontname) fontname = FallbackFont;
  786. X!    font = XLoadQueryFont(dpy, fontname);
  787. X!    if (!font) {
  788. X!       fprintf(stderr, "\ngnuplot: can't load font '%s'\n", fontname);
  789. X!       fprintf(stderr, "gnuplot: using font '%s' instead.\n", FallbackFont);
  790. X!       font = XLoadQueryFont(dpy, FallbackFont);
  791. X!       if (!font) {
  792. X!      fprintf(stderr, "gnuplot: can't load font '%s'\n", FallbackFont);
  793. X!      fprintf(stderr, "gnuplot: no useable font - X11 aborted.\n");
  794. X!          exit(1);
  795. X!      }
  796. X!       }
  797. X!    vchar = font->ascent + font->descent;
  798. X!    }
  799. X! 
  800. X! /*-----------------------------------------------------------------------------
  801. X!  *   pr_geometry - determine window geometry      
  802. X!  *---------------------------------------------------------------------------*/
  803. X! 
  804. X! pr_geometry() {
  805. X!    char *geometry = pr_GetR(db, ".geometry");
  806. X!    int x, y, flags;
  807. X!    unsigned int w, h; 
  808. X! 
  809. X!    if (geometry) {
  810. X!       flags = XParseGeometry(geometry, &x, &y, &w, &h);
  811. X! 
  812. X!       if (flags & WidthValue)  W = w;
  813. X!       if (flags & HeightValue) H = h;
  814. X!       if (flags & XValue) {
  815. X!      if (flags & XNegative) x += DisplayWidth(dpy,scr);
  816. X!      gX = x;
  817. X!      }
  818. X!       if (flags & YValue) {
  819. X!      if (flags & YNegative) y += DisplayHeight(dpy,scr);
  820. X!      gY = y;
  821. X!      }
  822. X!       }
  823. X!    }
  824. X! 
  825. X! /*-----------------------------------------------------------------------------
  826. X!  *   pr_window - create window 
  827. X!  *---------------------------------------------------------------------------*/
  828. X! 
  829. X! pr_window() {
  830. X!    char *title =  pr_GetR(db, ".title");
  831. X!    XSizeHints hints;
  832. X! 
  833. X!    win = XCreateSimpleWindow(dpy, root, gX, gY, W, H, 2, colors[1], colors[0]);
  834. X! 
  835. X!    pr_GetR(db, ".clear") && On(value.addr) && Clear++;
  836. X! 
  837. X!    hints.flags = PPosition;
  838. X!    hints.x = gX; hints.y = gY;
  839. X!    XSetNormalHints(dpy, win, &hints);
  840. X! 
  841. X!    if (pr_GetR(db, ".iconic") && On(value.addr)) {
  842. X!       XWMHints wmh;
  843. X! 
  844. X!       wmh.flags = StateHint ;
  845. X!       wmh.initial_state = IconicState;
  846. X!       XSetWMHints(dpy, win, &wmh);
  847. X!       } 
  848. X! 
  849. X!    XStoreName(dpy, win, ((title) ? title : Class));
  850. X! 
  851. X!    XSelectInput(dpy, win, StructureNotifyMask);
  852. X!    XMapWindow(dpy, win);
  853. X!    
  854. X     }
  855. END_OF_FILE
  856.   if test 28136 -ne `wc -c <'patch.2'`; then
  857.     echo shar: \"'patch.2'\" unpacked with wrong size!
  858.   fi
  859.   # end of 'patch.2'
  860. fi
  861. echo shar: End of archive 7 \(of 7\).
  862. cp /dev/null ark7isdone
  863. MISSING=""
  864. for I in 1 2 3 4 5 6 7 ; do
  865.     if test ! -f ark${I}isdone ; then
  866.     MISSING="${MISSING} ${I}"
  867.     fi
  868. done
  869. if test "${MISSING}" = "" ; then
  870.     echo You have unpacked all 7 archives.
  871.     rm -f ark[1-9]isdone
  872. else
  873.     echo You still must unpack the following archives:
  874.     echo "        " ${MISSING}
  875. fi
  876. exit 0
  877.  
  878. exit 0 # Just in case...
  879.