home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource1 / ast40dos / xdriver.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-04  |  41.4 KB  |  1,370 lines

  1. /*
  2. ** Astrolog (Version 4.00) File: xdriver.c
  3. **
  4. ** IMPORTANT NOTICE: the graphics database and chart display routines
  5. ** used in this program are Copyright (C) 1991-1993 by Walter D. Pullen
  6. ** (cruiser1@stein.u.washington.edu). Permission is granted to freely
  7. ** use and distribute these routines provided one doesn't sell,
  8. ** restrict, or profit from them in any way. Modification is allowed
  9. ** provided these notices remain with any altered or edited versions of
  10. ** the program.
  11. **
  12. ** The main planetary calculation routines used in this program have
  13. ** been Copyrighted and the core of this program is basically a
  14. ** conversion to C of the routines created by James Neely as listed in
  15. ** Michael Erlewine's 'Manual of Computer Programming for Astrologers',
  16. ** available from Matrix Software. The copyright gives us permission to
  17. ** use the routines for personal use but not to sell them or profit from
  18. ** them in any way.
  19. **
  20. ** The PostScript code within the core graphics routines are programmed
  21. ** and Copyright (C) 1992-1993 by Brian D. Willoughby
  22. ** (brianw@sounds.wa.com). Conditions are identical to those above.
  23. **
  24. ** The extended accurate ephemeris databases and formulas are from the
  25. ** calculation routines in the program "Placalc" and are programmed and
  26. ** Copyright (C) 1989,1991,1993 by Astrodienst AG and Alois Treindl
  27. ** (alois@azur.ch). The use of that source code is subject to
  28. ** regulations made by Astrodienst Zurich, and the code is not in the
  29. ** public domain. This copyright notice must not be changed or removed
  30. ** by any user of this program.
  31. **
  32. ** Initial programming 8/28,30, 9/10,13,16,20,23, 10/3,6,7, 11/7,10,21/1991.
  33. ** X Window graphics initially programmed 10/23-29/1991.
  34. ** PostScript graphics initially programmed 11/29-30/1992.
  35. ** Last code change made 12/31/1993.
  36. */
  37.  
  38. #include "astrolog.h"
  39.  
  40. #ifdef GRAPH
  41.  
  42. #ifdef X11
  43. /* Size of the Astrolog X11 icon. These values are defined in xdata.c too. */
  44.  
  45. #define icon_width 63
  46. #define icon_height 32
  47. #endif
  48.  
  49. #ifdef MSG
  50. /* PC specific global variables. */
  51.  
  52. int hiresmode = DEFHIRESMODE;    /* 'High-resolution' graphics mode. */
  53. int loresmode = DEFLORESMODE;    /* 'Flicker-free' graphics mode.    */
  54. int xscreen   = -1000;           /* Current graphics mode.           */
  55. struct videoconfig config;       /* State of current graphics mode.  */
  56. #endif
  57.  
  58.  
  59. /*
  60. ******************************************************************************
  61. ** Interactive Screen Graphics Routines.
  62. ******************************************************************************
  63. */
  64.  
  65. #ifdef X11
  66. /* Allocate a color from the present colormap. Given a string like "red" or */
  67. /* "blue" allocate this color and return a value specifying it.             */
  68.  
  69. colrgb XMakeColor(name)
  70. char *name;
  71. {
  72.   XColor col;
  73.   XParseColor(disp, cmap, name, &col);
  74.   XAllocColor(disp, cmap, &col);
  75.   return col.pixel;
  76. }
  77. #endif
  78.  
  79.  
  80. /* Set up all the colors used by the program, i.e. the foreground and   */
  81. /* background colors, and all the colors in the object arrays, based on */
  82. /* whether or not we are in monochrome and/or reverse video mode.       */
  83.  
  84. void XColorInit()
  85. {
  86.   int i;
  87.  
  88. #ifdef X11
  89.   if (!xfile) {
  90.     cmap = XDefaultColormap(disp, screen);
  91.     for (i = 0; i < 16; i++)
  92.       rgbind[i] = XMakeColor(rgbname[i]);
  93.   }
  94. #endif
  95.   on  = mainansi[!xreverse];
  96.   off = mainansi[xreverse];
  97.   hilite = xcolor ? mainansi[2+xreverse] : on;
  98.   gray   = xcolor ? mainansi[3-xreverse] : on;
  99.   for (i = 0; i <= 6; i++)
  100.     maincolor[i]    = xcolor ? mainansi[i]    : on;
  101.   for (i = 0; i <= 7; i++)
  102.     rainbowcolor[i] = xcolor ? rainbowansi[i] : on;
  103.   for (i = 0; i < 4; i++)
  104.     elemcolor[i]    = xcolor ? elemansi[i]    : on;
  105.   for (i = 0; i <= ASPECTS; i++)
  106.     aspectcolor[i]  = xcolor ? aspectansi[i]  : on;
  107.   for (i = 0; i <= total; i++)
  108.     objectcolor[i]  = xcolor ? objectansi[i]  : on;
  109. #ifdef X11
  110.   if (!xfile) {
  111.     XSetBackground(disp, gc,   rgbind[off]);  /* Initialize X window colors. */
  112.     XSetForeground(disp, pmgc, rgbind[off]);
  113.   }
  114. #endif
  115. }
  116.  
  117.  
  118. #ifdef ISG
  119. /* This routine opens up and initializes a window and prepares it to be */
  120. /* drawn upon, and gets various information about the display, too.     */
  121.  
  122. void XBegin()
  123. {
  124. #ifdef X11
  125.   disp = XOpenDisplay(dispname);
  126.   if (!disp) {
  127.     PrintError("Can't open display.");
  128.     Terminate(_FATAL);
  129.   }
  130.   screen = DefaultScreen(disp);
  131.   bg = BlackPixel(disp, screen);
  132.   fg = WhitePixel(disp, screen);
  133.   hint.x = offsetx; hint.y = offsety;
  134.   hint.width = chartx; hint.height = charty;
  135.   hint.min_width = BITMAPX1; hint.min_height = BITMAPY1;
  136.   hint.max_width = BITMAPX;  hint.max_height = BITMAPY;
  137.   hint.flags = PPosition | PSize | PMaxSize | PMinSize;
  138. #if FALSE
  139.   wmhint = XGetWMHints(disp, window);
  140.   wmhint->input = True;
  141.   XSetWMHints(disp, window, wmhint);
  142. #endif
  143.   depth = DefaultDepth(disp, screen);
  144.   if (depth < 5) {
  145.     xmono = TRUE;      /* Is this a monochrome monitor? */
  146.     xcolor = FALSE;
  147.   }
  148.   root = RootWindow(disp, screen);
  149.   if (xroot)
  150.     window = root;     /* If -XB in effect, we'll use the root window. */
  151.   else
  152.     window = XCreateSimpleWindow(disp, DefaultRootWindow(disp),
  153.       hint.x, hint.y, hint.width, hint.height, 5, fg, bg);
  154.   pixmap = XCreatePixmap(disp, window, chartx, charty, depth);
  155.   icon = XCreateBitmapFromData(disp, DefaultRootWindow(disp),
  156.     icon_bits, icon_width, icon_height);
  157.   if (!xroot)
  158.     XSetStandardProperties(disp, window, appname, appname, icon,
  159.       (char PTR PTR)xkey, 0, &hint);
  160.  
  161.   /* We have two graphics workareas. One is what the user currently sees in */
  162.   /* the window, and the other is what we are currently drawing on. When    */
  163.   /* done, we can quickly copy this to the viewport for a smooth look.      */
  164.  
  165.   gc = XCreateGC(disp, window, 0, 0);
  166.   XSetGraphicsExposures(disp, gc, 0);
  167.   pmgc = XCreateGC(disp, window, 0, 0);
  168.   XColorInit();                            /* Go set up colors. */
  169.   if (!xroot)
  170.     XSelectInput(disp, window, KeyPressMask | StructureNotifyMask |
  171.       ExposureMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask);
  172.   XMapRaised(disp, window);
  173.   XSync(disp, 0);
  174.   XFillRectangle(disp, pixmap, pmgc, 0, 0, chartx, charty);
  175.  
  176. #else /* MSG */
  177.  
  178.   if (!IsValidResmode(xscreen))    /* Initialize graphics mode to hi-res. */
  179.     xscreen = hiresmode;
  180.   _setvideomode(xscreen);
  181.   if (_grstatus()) {
  182.     PrintError("Can't enter graphics mode.");
  183.     Terminate(_FATAL);
  184.   }
  185.   _getvideoconfig((struct videoconfig far *) &config);
  186.   if (config.numcolors < 16) {
  187.     xmono = TRUE;
  188.     xcolor = FALSE;
  189.   }
  190.   _remapallpalette((long FAR *) rgb);
  191.   _setactivepage(0);
  192.   _setvisualpage(0);
  193.   XColorInit();
  194. #ifdef MOUSE
  195.   if (MouseInit() > 0)
  196.     SetPtrVis(SHOW);
  197. #endif
  198.   textrows = abs(textrows);    /* Make sure we reset textrows upon restart. */
  199. #endif /* MSG */
  200. }
  201.  
  202.  
  203. /* Add a certain amount of time to the current hour/day/month/year quantity */
  204. /* defining the present chart. This is used by the chart animation feature. */
  205. /* We can add or subtract anywhere from 1 to 9 seconds, minutes, hours,     */
  206. /* days, months, years, decades, centuries, or millenia in any one call.    */
  207. /* This is mainly just addition to the appropriate quantity, but we have    */
  208. /* to check for overflows, e.g. Dec 30 + 3 days = Jan 2 of Current year + 1 */
  209.  
  210. void AddTime(mode, toadd)
  211. int mode, toadd;
  212. {
  213.   int d;
  214.   real h, m;
  215.  
  216.   h = floor(TT);
  217.   m = FRACT(TT)*100.0;
  218.   if (mode == 1)
  219.     m += 1.0/60.0*(real)toadd;    /* Add seconds. */
  220.   else if (mode == 2)
  221.     m += (real)toadd;             /* add minutes. */
  222.  
  223.   /* Add hours, either naturally or if minute value overflowed. */
  224.  
  225.   if (m < 0.0 || m >= 60.0 || mode == 3) {
  226.     if (m >= 60.0) {
  227.       m -= 60.0; toadd = SGN(toadd);
  228.     } else if (m < 0.0) {
  229.       m += 60.0; toadd = SGN(toadd);
  230.     }
  231.     h += (real)toadd;
  232.   }
  233.  
  234.   /* Add days, either naturally or if hour value overflowed. */
  235.  
  236.   if (h >= 24.0 || h < 0.0 || mode == 4) {
  237.     if (h >= 24.0) {
  238.       h -= 24.0; toadd = SGN(toadd);
  239.     } else if (h < 0.0) {
  240.       h += 24.0; toadd = SGN(toadd);
  241.     }
  242.     DD += toadd;
  243.   }
  244.  
  245.   /* Add months, either naturally or if day value overflowed. */
  246.  
  247.   if (DD > (d = DayInMonth(MM, YY)) || DD < 1 || mode == 5) {
  248.     if (DD > d) {
  249.       DD -= d; toadd = SGN(toadd);
  250.     } else if (DD < 1) {
  251.       DD += DayInMonth(Mod12(MM - 1), YY);
  252.       toadd = SGN(toadd);
  253.     }
  254.     MM += toadd;
  255.   }
  256.  
  257.   /* Add years, either naturally or if month value overflowed. */
  258.  
  259.   if (MM > 12 || MM < 1 || mode == 6) {
  260.     if (MM > 12) {
  261.       MM -= 12; toadd = SGN(toadd);
  262.     } else if (MM < 1) {
  263.       MM += 12; toadd = SGN(toadd);
  264.     }
  265.     YY += toadd;
  266.   }
  267.   if (mode == 7)
  268.     YY += 10 * toadd;      /* Add decades.   */
  269.   else if (mode == 8)
  270.     YY += 100 * toadd;     /* Add centuries. */
  271.   else if (mode == 9)
  272.     YY += 1000 * toadd;    /* Add millenia.  */
  273.   TT = h+m/100.0;          /* Recalibrate hour time. */
  274. }
  275.  
  276.  
  277. /* Animate the current chart based on the given values indicating how much  */
  278. /* to update by. We update and recast the current chart info appropriately. */
  279.  
  280. void Animate(mode, toadd)
  281. int mode, toadd;
  282. {
  283.   if (modex == MODEW || modex == MODEG || modex == MODEP) {
  284.     degree += toadd;
  285.     if (degree >= DEGR)     /* For animating globe display, add */
  286.       degree -= DEGR;       /* in appropriate degree value.     */
  287.     else if (degree < 0)
  288.       degree += DEGR;
  289.   } else {
  290.     if (mode == 10) {
  291. #ifdef TIME
  292.       /* For the continuous chart update to present moment */
  293.       /* animation mode, go get whatever time it is now.   */
  294.       InputData("now");
  295. #else
  296.       SetCore(Mon, Day, Yea, Tim, Zon, Lon, Lat);
  297.       AddTime(1, toadd);
  298. #endif
  299.     } else {  /* Otherwise add on appropriate time vector to chart info. */
  300.       SetCore(Mon, Day, Yea, Tim, Zon, Lon, Lat);
  301.       AddTime(mode, toadd);
  302.     }
  303.     SetMain(MM, DD, YY, TT, ZZ, OO, AA);
  304.     if (relation)
  305.       CastRelation(FALSE);
  306.     else
  307.       CastChart(TRUE);
  308.   }
  309. }
  310.  
  311.  
  312. /* Print a list of every key that one can press in an X window to do a */
  313. /* certain function, and a description of what it does. This list gets */
  314. /* displayed whenever one presses the 'H' or '?' key in the window.    */
  315.  
  316. void XDisplayKeys()
  317. {
  318.   char string[STRING];
  319.  
  320.   sprintf(string, "\n%s window keypress options (version %s):", appname,
  321.     VERSION);
  322.   Prints(string);
  323.   Prints(" Press 'H' or '?' to display this list of key options.");
  324.   Prints(" Press 'p' to toggle pause status on or off.");
  325.   Prints(" Press 'x' to toggle fg/bg colors on screen.");
  326.   Prints(" Press 'm' to toggle color/monochrome display on screen.");
  327.   Prints(" Press 'i' to toggle status of the minor chart modification.");
  328.   Prints(" Press 'T' to toggle header info on current chart on screen.");
  329.   Prints(" Press 'b' to toggle drawing of a border around the chart.");
  330.   Prints(" Press 'l' to toggle labeling of object points in chart.");
  331.   Prints(" Press 'v' to display current chart positions on text screen.");
  332.   Prints(" Press 'R', 'C', 'u', 'U' to toggle restriction status of minor");
  333.   Prints("       objects, minor house cusps, uranian planets, and stars.");
  334.   Prints(" Press 'c' to toggle relationship comparison chart mode.");
  335.   Prints(" Press 's', 'h', 'f', 'F' to toggle status of sidereal zodiac,");
  336.   Prints("       heliocentric charts, domal charts, and decan charts.");
  337.   Prints(" Press 'O' and 'o' to recall/store a previous chart from memory.");
  338. #ifdef X11
  339.   Prints(" Press 'B' to dump current window contents to root background.");
  340. #else
  341.   Prints(" Press 'B' to resize chart display to full size of screen.");
  342. #endif
  343.   Prints(" Press 'Q' to resize chart display to a square.");
  344.   Prints(" Press '<' and '>' to decrease/increase the scale size of the");
  345.   Prints("       glyphs and the size of world map.");
  346.   Prints(" Press '[' and ']' to decrease/increase tilt in globe display.");
  347.   Prints(" Press '+' and '-' to add/subtract a day from current chart.");
  348. #ifdef TIME
  349.   Prints(" Press 'n' to set chart information to current time now.");
  350. #endif
  351.   Prints(" Press 'N' to toggle animation status on or off. Charts will");
  352.   Prints("       be updated to current status and globe will rotate.");
  353.   Prints(" Press '!'-'(' to begin updating current chart by adding times.");
  354.   Prints("       !: seconds, @: minutes, #: hours, $: days, %: months,");
  355.   Prints("       ^: years, &: years*10, *: years*100, (: years*1000.");
  356.   Prints(" Press 'r' to reverse direction of time-lapse or animation.");
  357.   Prints(" Press '1'-'9' to set rate of animation to 'n' degrees, etc.");
  358. #ifdef MSG
  359.   Prints(" Press '1'-'9' to determine section of chart to show if clipped.");
  360. #endif
  361.   Prints(
  362.     " Press 'V','L','A','Z','S','E','W','G','P' to switch to normal (_v),");
  363.   Prints(
  364.     "       astro-graph (_L), grid (_g), local (_Z), space (_S), ephemeris");
  365.   Prints("       (_E), world map (_XW), globe (_XG), and polar (_XP) modes.");
  366.   Prints(" Press '0' to toggle between _Z,_Z0 & _XW,_XW0 & _E,_Ey modes.");
  367.   Prints(" Press 'space' to force update of current graphics display.");
  368. #ifdef MSG
  369.   Prints(" Press 'tab' to toggle between graphics resolutions.");
  370. #endif
  371.   Prints(" Press 'q' to terminate the window and program.");
  372. #ifdef MOUSE
  373.   printl();
  374. #ifdef X11
  375.   Prints(" Left   mouse button: Draw line strokes on chart in window.");
  376.   Prints(" Middle mouse button: Print coordinates of pointer on world map.");
  377.   Prints(" Right  mouse button: Terminate the window and program.");
  378. #endif
  379. #ifdef MSG
  380.   Prints(" Left  mouse button: Draw line strokes on chart in screen.");
  381.   Prints(" Right mouse button: Set coordinates to pointer on world map.");
  382. #endif
  383. #endif /* MOUSE */
  384. }
  385.  
  386.  
  387. /* This routine gets called after an X window is brought up and displayed   */
  388. /* on the screen. It loops, processing key presses, mouse clicks, etc, that */
  389. /* the window receives, until the user specifies they want to exit program. */
  390.  
  391. void XSpin()
  392. {
  393. #ifdef X11
  394.   XEvent event;
  395.   int xresize = FALSE, xredraw = TRUE;
  396. #else
  397. #ifdef MOUSE
  398.   EVENT event;
  399. #endif
  400.   int xresize = TRUE, xredraw = FALSE;
  401. #endif
  402.   int xbreak = FALSE, xpause = FALSE, xcast = FALSE, xcorner = 7,
  403.     buttonx = -1, buttony = -1, dir = 1, length, i;
  404.   colpal coldrw = hilite;
  405.  
  406.   xnow = -xnow;
  407.   while (!xbreak) {
  408.  
  409.     /* Some chart windows, like the world maps and aspect grids, should */
  410.     /* always be a certian size, so correct if a resize was attempted.  */
  411.  
  412.     if (modex == MODEL || modex == MODEW) {
  413.       length = DEGR*SCALE+2;
  414.       if (chartx != length) {
  415.         chartx = length;
  416.         xresize = TRUE;
  417.       }
  418.       length = (90*2+1)*SCALE+2;
  419.       if (charty != length) {
  420.         charty = length;
  421.         xresize = TRUE;
  422.       }
  423.     } else if (modex == MODEg) {
  424.       if (chartx !=
  425.         (length = (gridobjects + (relation <= DASHr0))*CELLSIZE*SCALE+1)) {
  426.         chartx = length;
  427.         xresize = TRUE;
  428.       } if (charty != length) {
  429.         charty = length;
  430.         xresize = TRUE;
  431.       }
  432.  
  433.     /* Make sure the window isn't too large or too small. */
  434.  
  435.     } else {
  436.         if (chartx < BITMAPX1) {
  437.           chartx = BITMAPX1;
  438.           xresize = TRUE;
  439.         } else if (chartx > BITMAPX) {
  440.           chartx = BITMAPX;
  441.           xresize = TRUE;
  442.         }
  443.         if (charty < BITMAPY1) {
  444.           charty = BITMAPY1;
  445.           xresize = TRUE;
  446.         } else if (charty > BITMAPY) {
  447.           charty = BITMAPY;
  448.           xresize = TRUE;
  449.         }
  450.         }
  451.  
  452.     /* If in animation mode, ensure we are in the flicker free resolution. */
  453.  
  454.     if (xnow < 0) {
  455.       xnow = -xnow;
  456. #ifdef MSG
  457.       if (xscreen == hiresmode) {
  458.         xscreen = loresmode;
  459.         XBegin();
  460.         chartx = config.numxpixels;
  461.         charty = config.numypixels;
  462.         if (chartx > charty)
  463.           chartx = charty;
  464.         if (ISEGA(xscreen))
  465.           chartx = EGATOVGA(chartx);
  466.                 else if (ISCGA(xscreen))
  467.                     chartx = CGATOVGA(chartx);
  468.         if ((modex == MODEv || modex == MODEw) && xtext &&
  469.           !(exdisplay & DASHv0))
  470.           chartx += SIDET;
  471.         xresize = TRUE;
  472.       }
  473. #endif
  474.     }
  475.  
  476.     /* Physically resize window if we've changed the size parameters. */
  477.  
  478.     if (xresize) {
  479.       xresize = FALSE;
  480. #ifdef X11
  481.       XResizeWindow(disp, window, chartx, charty);
  482.       XFreePixmap(disp, pixmap);
  483.       pixmap = XCreatePixmap(disp, window, chartx, charty, depth);
  484. #else
  485.       if (config.numxpixels > chartx)
  486.         offsetx = (config.numxpixels - chartx) >> 1;
  487.       else {
  488.         if (xcorner % 3 == 1)
  489.           offsetx = 0;
  490.         else if (xcorner % 3 == 0)
  491.           offsetx = -chartx + config.numxpixels;
  492.         else
  493.           offsetx = -(chartx - config.numxpixels) / 2;
  494.       }
  495.       if (config.numypixels > charty)
  496.         offsety = (config.numypixels - charty) >> 1;
  497.       else {
  498.         if (xcorner > 6)
  499.           offsety = 0;
  500.         else if (xcorner < 4)
  501.           offsety = -charty + config.numypixels;
  502.         else
  503.           offsety = -(charty - config.numypixels) / 2;
  504.       }
  505. #endif
  506.       xredraw = TRUE;
  507.     }
  508.  
  509.     /* Recast chart if the chart information has changed any. */
  510.  
  511.     if (xcast) {
  512.       xcast = FALSE;
  513.       SetCore(Mon, Day, Yea, Tim, Zon, Lon, Lat);
  514.       if (relation)
  515.         CastRelation(FALSE);
  516.       else
  517.         CastChart(TRUE);
  518.       xredraw = TRUE;
  519.     }
  520.     if (xnow && !xpause)
  521.       xredraw = TRUE;
  522.  
  523.     /* Update the screen if anything has changed since last time around. */
  524.  
  525.     if (xredraw) {
  526.       xredraw = FALSE;
  527.  
  528.       /* If we're in animation mode, change the chart info appropriately. */
  529.  
  530.       if (xnow)
  531.         Animate(xnow, dir);
  532. #ifdef X11
  533.       XFillRectangle(disp, pixmap, pmgc, 0, 0, chartx, charty);
  534. #else /* MSG */
  535. #ifdef MOUSE
  536.       SetPtrVis(HIDE);
  537. #endif
  538.       if (config.numvideopages > 1)
  539.         _setactivepage(_getactivepage() == 0);
  540. #endif /* MSG */
  541.       XChart();
  542. #ifdef X11
  543.       XSync(disp, 0);
  544.       XCopyArea(disp, pixmap, window, gc, 0, 0, chartx, charty, 0, 0);
  545. #else /* MSG */
  546.       if (config.numvideopages > 1)
  547.         _setvisualpage(_getactivepage());
  548. #ifdef MOUSE
  549.       if (!xnow)
  550.         SetPtrVis(SHOW);
  551. #endif
  552. #endif /* MSG */
  553.     }  /* if */
  554.  
  555.     /* Now process what's on the event queue, i.e. any keys pressed, etc. */
  556.  
  557. #ifdef X11
  558.     if (XEventsQueued(disp, QueuedAfterFlush /*QueuedAfterReading*/ )) {
  559.       XNextEvent(disp, &event);
  560.  
  561.       /* Restore what's on window if a part of it gets uncovered. */
  562.  
  563.       if (event.type == Expose && event.xexpose.count == 0) {
  564.         XSync(disp, 0);
  565.         XCopyArea(disp, pixmap, window, gc, 0, 0, chartx, charty, 0, 0);
  566.       }
  567.       switch (event.type) {
  568.  
  569.       /* Check for a manual resize of window by user. */
  570.  
  571.       case ConfigureNotify:
  572.         chartx = event.xconfigure.width;
  573.         charty = event.xconfigure.height;
  574.         XFreePixmap(disp, pixmap);
  575.         pixmap = XCreatePixmap(disp, window, chartx, charty, depth);
  576.         xredraw = TRUE;
  577.         break;
  578.       case MappingNotify:
  579.         XRefreshKeyboardMapping((XMappingEvent PTR)&event);
  580.         break;
  581.  
  582. #ifdef MOUSE
  583.       /* Process any mouse buttons the user pressed. */
  584.  
  585.       case ButtonPress:
  586.         buttonx = event.xbutton.x; buttony = event.xbutton.y;
  587.         if (event.xbutton.button == Button1) {
  588.           DrawColor(hilite);
  589.           DrawPoint(buttonx, buttony);
  590.           XSync(disp, 0);
  591.           XCopyArea(disp, pixmap, window, gc, 0, 0, chartx, charty, 0, 0);
  592.         } else if (event.xbutton.button == Button2 &&
  593.           (modex == MODEL || modex == MODEW) && degree == 0) {
  594.           Lon = DEGHALF-(real)(event.xbutton.x-1)/(real)(chartx-2)*DEGREES;
  595.           Lat =  DEGQUAD-(real)(event.xbutton.y-1)/(real)(charty-2)*181.0;
  596.           fprintf(S, "Mouse is at %s.\n", CharLocation(Lon, Lat, 60.0));
  597.         } else if (event.xbutton.button == Button3)
  598.           xbreak = TRUE;
  599.         break;
  600.  
  601.       /* Check for user dragging any of the mouse buttons across window. */
  602.  
  603.       case MotionNotify:
  604.         DrawColor(coldrw);
  605.         DrawLine(buttonx, buttony, event.xbutton.x, event.xbutton.y);
  606.         XSync(disp, 0);
  607.         XCopyArea(disp, pixmap, window, gc, 0, 0, chartx, charty, 0, 0);
  608.         buttonx = event.xbutton.x; buttony = event.xbutton.y;
  609.         break;
  610. #endif
  611.  
  612.       /* Process any keys user pressed in window. */
  613.  
  614.       case KeyPress:
  615.         length = XLookupString((XKeyEvent PTR)&event, xkey, 10, &key, 0);
  616.         if (length == 1) {
  617.           i = xkey[0];
  618. #else /* MSG */
  619. #ifdef MOUSE
  620.       if (!xnow && GetMouseEvent((EVENT *)&event)) {
  621.         if (event.fsBtn == LEFT_DOWN && buttonx >= 0) {
  622.           SetPtrVis(HIDE);
  623.           DrawColor(coldrw);
  624.           _moveto(buttonx, buttony);
  625.           buttonx = event.x; buttony = event.y;
  626.           _lineto(buttonx, buttony);
  627.         } else if (event.fsBtn == RIGHT_DOWN &&
  628.           (modex == MODEL || modex == MODEW) && degree == 0) {
  629.           Lon = DEGHALF-(real)(event.x-offsetx)/(real)(chartx-2)*DEGREES;
  630.           if (Lon < -DEGHALF)
  631.             Lon = -DEGHALF;
  632.           else if (Lon > DEGHALF)
  633.             Lon = DEGHALF;
  634.           Lat =  DEGQUAD-(real)(event.y-offsety)/(real)(charty-2)*181.0;
  635.           if (Lat < -DEGQUAD)
  636.             Lat = -DEGQUAD;
  637.           else if (Lat > DEGQUAD)
  638.             Lat = DEGQUAD;
  639.           xcast = TRUE;
  640.         } else if (event.fsBtn == MIDDLE_DOWN)
  641.           xbreak = TRUE;
  642.         else {
  643.           buttonx = event.x; buttony = event.y;
  644.         }
  645.         SetPtrVis(SHOW);
  646.       } else
  647. #endif
  648.         if (kbhit()) {
  649.           i = getch();
  650. #endif /* MSG */
  651.           switch (i) {
  652.           case ' ':
  653.             xredraw = TRUE;
  654.             break;
  655.           case 'p':
  656.             xpause = !xpause;
  657.             break;
  658.           case 'r':
  659.             dir = -dir;
  660.             break;
  661.           case 'x':
  662.             xreverse = !xreverse;
  663.             XColorInit();
  664.             xredraw = TRUE;
  665.             break;
  666.           case 'm':
  667.             if (!xmono) {
  668.               xcolor = !xcolor;
  669. #ifdef MSG
  670.               _getvideoconfig((struct videoconfig far *) &config);
  671. #endif
  672.               XColorInit();
  673.               xredraw = TRUE;
  674.             }
  675.             break;
  676.           case 'B':
  677. #ifdef X11
  678.             XSetWindowBackgroundPixmap(disp, root, pixmap);
  679.             XClearWindow(disp, root);
  680. #else
  681.             chartx = config.numxpixels;
  682.             charty = config.numypixels;
  683.             if (modex == MODEv || modex == MODEw || modex == MODEg ||
  684.               (modex == MODEZ && (exdisplay & DASHZ0) > 0) ||
  685.               modex == MODES || modex == MODEG || modex == MODEP) {
  686.               if (chartx > charty)
  687.                 chartx = charty;
  688.               if (ISEGA(xscreen))
  689.                 chartx = EGATOVGA(chartx);
  690.                             else if (ISCGA(xscreen))
  691.                 chartx = CGATOVGA(chartx);
  692.               if ((modex == MODEv || modex == MODEw) && xtext &&
  693.                 !(exdisplay & DASHv0))
  694.                 chartx += SIDET;
  695.             }
  696.             xresize = TRUE;
  697. #endif
  698.             break;
  699.           case 'T':
  700.             xtext = !xtext;
  701.             xredraw = TRUE;
  702.             break;
  703.           case 'i':
  704.             xbonus = !xbonus;
  705.             xredraw = TRUE;
  706.             break;
  707.           case 'b':
  708.             xborder = !xborder;
  709.             xredraw = TRUE;
  710.             break;
  711.           case 'l':
  712.             xlabel = !xlabel;
  713.             xredraw = TRUE;
  714.             break;
  715.           case '<':
  716.             if (scale > 100) {
  717.               scale -= 100;
  718.               xresize = TRUE;
  719.             }
  720.             break;
  721.           case '>':
  722.             if (scale < 300) {
  723.               scale += 100;
  724.               xresize = TRUE;
  725.             }
  726.             break;
  727.           case '[':
  728.             if (modex == MODEG) {
  729.               tilt = tilt > -DEGQUAD ? tilt-11.25 : -DEGQUAD;
  730.               xredraw = TRUE;
  731.             }
  732.             break;
  733.           case ']':
  734.             if (modex == MODEG) {
  735.               tilt = tilt < DEGQUAD ? tilt+11.25 : DEGQUAD;
  736.               xredraw = TRUE;
  737.             }
  738.             break;
  739.           case 'Q':
  740.             if (chartx > charty)
  741.               chartx = charty;
  742.             else
  743.               charty = chartx;
  744. #ifdef MSG
  745.             if (ISEGA(xscreen))
  746.               chartx = EGATOVGA(chartx);
  747.                         else if (ISCGA(xscreen))
  748.               chartx = CGATOVGA(chartx);
  749. #endif
  750.             xresize = TRUE;
  751.             break;
  752.           case 'R':
  753.             for (i = 11; i <= 15; i++)
  754.               ignore[i] = !ignore[i];
  755.             ignore[_FOR] = !ignore[_FOR]; ignore[_VTX] = !ignore[_VTX];
  756.             xredraw = TRUE;
  757.             break;
  758.           case 'C':
  759.             operation ^= DASHC;
  760.             for (i = C_LO; i <= C_HI; i++)
  761.               ignore[i] = !ignore[i];
  762.             xcast = TRUE;
  763.             break;
  764.           case 'u':
  765.             operation ^= DASHu;
  766.             for (i = U_LO; i <= U_HI; i++)
  767.               ignore[i] = !ignore[i];
  768.             xcast = TRUE;
  769.             break;
  770.           case 'U':
  771.             universe = !universe;
  772.             for (i = S_LO; i <= S_HI; i++)
  773.               ignore[i] = !ignore[i];
  774.             xcast = TRUE;
  775.             break;
  776.           case 'c':
  777.             if (!relation) {
  778.               relation = DASHr0;
  779.               SetTwin(Mon, Day, Yea, Tim, Zon, Lon, Lat);
  780.             } else
  781.               relation = 0;
  782.             xcast = TRUE;
  783.             break;
  784.           case 's':
  785.             operation ^= DASHs;
  786.             xcast = TRUE;
  787.             break;
  788.           case 'h':
  789.             centerplanet = centerplanet ? 0 : 1;
  790.             xcast = TRUE;
  791.             break;
  792.           case 'f':
  793.             operation ^= DASHf;
  794.             xcast = TRUE;
  795.             break;
  796.           case 'F':
  797.             operation ^= DASH3;
  798.             xcast = TRUE;
  799.             break;
  800.           case '+':
  801.             Animate(4, abs(dir));
  802.             xcast = TRUE;
  803.             break;
  804.           case '-':
  805.             Animate(4, -abs(dir));
  806.             xcast = TRUE;
  807.             break;
  808.           case 'o':
  809.             SetSave(Mon, Day, Yea, Tim, Zon, Lon, Lat);
  810.             break;
  811.           case 'O':
  812.             SetMain(MonX, DayX, YeaX, TimX, ZonX, LonX, LatX);
  813.             xcast = TRUE;
  814.             break;
  815. #ifdef TIME
  816.           case 'n':
  817.             InputData("now");
  818.             SetMain(MM, DD, YY, TT, ZZ, OO, AA);
  819.             xcast = TRUE;
  820.             break;
  821. #endif
  822.           case 'N':                      /* The continuous update animation. */
  823.             xnow = xnow ? 0 : -10;
  824.             break;
  825.           case '!': xnow = -1; break;    /* These are the nine different     */
  826.           case '@': xnow = -2; break;    /* "add time to chart" animations.  */
  827.           case '#': xnow = -3; break;
  828.           case '$': xnow = -4; break;
  829.           case '%': xnow = -5; break;
  830.           case '^': xnow = -6; break;
  831.           case '&': xnow = -7; break;
  832.           case '*': xnow = -8; break;
  833.           case '(': xnow = -9; break;
  834.           case 'V': modex = MODEv; xredraw = TRUE; break; /* Should we go    */
  835.           case 'L': modex = MODEL; xredraw = TRUE; break; /* switch to a     */
  836.           case 'A': modex = MODEg; xredraw = TRUE; break; /* new chart type? */
  837.           case 'Z': modex = MODEZ; xredraw = TRUE; break;
  838.           case 'S': modex = MODES; xredraw = TRUE; break;
  839.           case 'E': modex = MODEE; xredraw = TRUE; break;
  840.           case 'W': modex = MODEW; xredraw = TRUE; break;
  841.           case 'G': modex = MODEG; xredraw = TRUE; break;
  842.           case 'P': modex = MODEP; xredraw = TRUE; break;
  843. #ifdef BIORHYTHM
  844.           case 'Y':               /* Should we switch to biorhythm chart? */
  845.             if (!relation) {
  846.               SetTwin(Mon, Day, Yea, Tim, Zon, Lon, Lat);
  847.             }
  848.             relation = DASHrb;
  849.             modex = MODEb;
  850.             xcast = TRUE;
  851.             break;
  852. #endif
  853.           case '0':
  854.             exdisplay ^= DASHZ0 | DASHEy | DASHXW0;
  855.             modex = (modex == MODEv ? MODEw : (modex == MODEw ? MODEv :
  856.               modex));
  857.             xredraw = TRUE;
  858.             break;
  859.           case 'v': case 'H': case '?':
  860. #ifdef MSG
  861.             _setvideomode(_DEFAULTMODE);
  862.             if (i != 'v')
  863.               _settextrows(43);
  864. #endif
  865.             if (i == 'v')
  866.               ChartLocation();
  867.             else
  868.               XDisplayKeys();
  869. #ifdef MSG
  870.             while (!kbhit())
  871.               ;
  872.             i = getch();
  873.             if (i == 'q' || i == ESCAPE || i == '\3') {
  874.               xbreak = TRUE;
  875.               break;
  876.             }
  877.             XBegin();
  878.             xresize = TRUE;
  879. #endif
  880.             break;
  881. #ifdef MSG
  882.           case '\t':
  883.             if (xscreen == hiresmode)
  884.               xscreen = loresmode;
  885.             else
  886.               xscreen = hiresmode;
  887.             XBegin();
  888.             chartx = config.numxpixels;
  889.             charty = config.numypixels;
  890.             if (chartx > charty)
  891.               chartx = charty;
  892.             if (ISEGA(xscreen))
  893.               chartx = EGATOVGA(chartx);
  894.                         else if (ISCGA(xscreen))
  895.               chartx = CGATOVGA(chartx);
  896.             if ((modex == MODEv || modex == MODEw) && xtext &&
  897.               !(exdisplay & DASHv0))
  898.               chartx += SIDET;
  899.             xresize = TRUE;
  900.             break;
  901. #endif
  902.           case '\b':
  903. #ifdef MSG
  904. #ifdef MOUSE
  905.             SetPtrVis(HIDE);
  906. #endif
  907. #endif /* MSG */
  908.             DrawClearScreen();
  909.             break;
  910. #ifdef MOUSE
  911.           case 'z'-'`': coldrw = BLACK;   break;
  912.           case 'e'-'`': coldrw = MAROON;  break;
  913.           case 'f'-'`': coldrw = DKGREEN; break;
  914.           case 'o'-'`': coldrw = ORANGE;  break;
  915.           case 'n'-'`': coldrw = DKBLUE;  break;
  916.           case 'u'-'`': coldrw = PURPLE;  break;
  917.           case 'k'-'`': coldrw = DKCYAN;  break;
  918.           case 'l'-'`': coldrw = LTGRAY;  break;
  919.           case 'd'-'`': coldrw = DKGRAY;  break;
  920.           case 'r'-'`': coldrw = RED;     break;
  921.           case 'g'-'`': coldrw = GREEN;   break;
  922.           case 'y'-'`': coldrw = YELLOW;  break;
  923.           case 'b'-'`': coldrw = BLUE;    break;
  924.           case 'v'-'`': coldrw = MAGENTA; break;
  925.           case 'j'-'`': coldrw = CYAN;    break;
  926.           case 'a'-'`': coldrw = WHITE;   break;
  927. #endif
  928.           case 'q': case ESCAPE: case '\3':
  929.             xbreak = TRUE;
  930.             break;
  931.           default:
  932.             if (i > '0' && i <= '9') {
  933. #ifdef MSG
  934.               if (xnow)
  935. #endif
  936.                 /* Process numbers 1..9 signifying animation rate. */
  937.                 dir = (dir > 0 ? 1 : -1)*(i-'0');
  938. #ifdef MSG
  939.               else {
  940.                 /* If we aren't in animation mode, then 1..9 refers to the */
  941.                 /* clipping "quadrant" to use if chart size > screen size. */
  942.                 xcorner = i-'0';
  943.                 xresize = TRUE;
  944.               }
  945. #endif
  946.             break;
  947.             }
  948.             printc(BELL);    /* Any key not bound will sound a beep. */
  949.           }  /* switch */
  950.         }  /* if */
  951. #ifdef X11
  952.       default:
  953.         ;
  954.       }  /* switch */
  955.     }  /* if */
  956. #endif
  957.   }  /* while */
  958. }
  959.  
  960.  
  961. /* This is called right before program termination to get rid of the window. */
  962.  
  963. void XEnd()
  964. {
  965. #ifdef X11
  966.   XFreeGC(disp, gc);
  967.   XFreeGC(disp, pmgc);
  968.   XFreePixmap(disp, pixmap);
  969.   XDestroyWindow(disp, window);
  970.   XCloseDisplay(disp);
  971. #else
  972.   _setvideomode(_DEFAULTMODE);
  973. #endif
  974. }
  975. #endif /* ISG */
  976.  
  977.  
  978. /*
  979. ******************************************************************************
  980. ** Main graphics processing
  981. ******************************************************************************
  982. */
  983.  
  984. /* Print a list of every command switch dealing with the graphics features  */
  985. /* that can be passed to the program, and a description of what it does.    */
  986. /* This is part of what the -H switch prints, if graphics were compiled in. */
  987.  
  988. void XDisplaySwitches()
  989. {
  990.   Prints(" _X: Create a graphics chart instead of displaying it as text.");
  991. #ifdef ISG
  992.   Prints(" _Xb: Create bitmap file instead of putting graphics on screen.");
  993. #endif
  994.   Prints(" _Xb[n,c,v,a,b]: Set bitmap file output mode to X11 normal,");
  995.   Prints("     compacted, very compact, Ascii (bmtoa), or Windows bmp.");
  996. #ifdef PS
  997.   Prints(" _Xp: Create PostScript stroke graphic instead of bitmap file.");
  998.   Prints(" _Xp0: Like _Xp but create complete instead of encapsulated file.");
  999. #endif
  1000. #ifdef META
  1001.   Prints(" _XM[0]: Create Windows metafile stroke graphic instead of bitmap.");
  1002. #endif
  1003.   Prints(" _Xo <file>: Write output bitmap or graphic to specified file.");
  1004. #ifdef X11
  1005.   Prints(" _XB: Display X chart on root instead of in a separate window.");
  1006. #endif
  1007.   Prints(" _Xm: Create monochrome graphic instead of one in color.");
  1008.   Prints(" _Xr: Create chart graphic in reversed colors (white background).");
  1009. #ifdef X11
  1010.   Prints(" _Xw <hor> [<ver>], _ge[..]: Change the size of chart graphic.");
  1011. #else
  1012.   Prints(" _Xw <hor> [<ver>]: Change the size of chart graphic.");
  1013. #endif
  1014.   Prints(" _Xs <100,200,300>: Change the size of map or characters by n%.");
  1015.   Prints(" _Xi: Create chart graphic in slightly modified form.");
  1016.   Prints(" _XT: Inhibit display of chart info at bottom of graphic.");
  1017.   Prints(" _Xl: Inhibit labeling of object points in chart graphic.");
  1018.   Prints(" _X1 <object>: Rotate wheel charts so object is at left edge.");
  1019.   Prints(" _X2 <object>: Rotate wheel charts so object is at top edge.");
  1020. #ifdef X11
  1021.   Prints(" _Xd <name>, _di[..] <name>: Open X window on specified display.");
  1022. #endif
  1023.   Prints(" _XW: Simply create an image of the world map.");
  1024.   Prints(" _XW0: Like _XW but do a non-rectangular Mollewide projection.");
  1025.   Prints(" _XP: Create just the world map, but from a polar projection.");
  1026.   Prints(" _XG [<degrees>]: Display the image of the world as a globe.");
  1027. #ifdef ISG
  1028.   Prints(" _Xn [<mode>]: Start up chart or globe display in animation mode.");
  1029.   Prints("Also, press 'H' while running for list of key press options.");
  1030. #endif
  1031. }
  1032.  
  1033.  
  1034. /* Process a command line switch passed to the program dealing with the      */
  1035. /* graphics features. This is just like the processing of each switch in the */
  1036. /* main program; however, here each switch has been prefixed with an 'X'.    */
  1037.  
  1038. int XProcessSwitches(argc, argv, pos)
  1039. int argc, pos;
  1040. char **argv;
  1041. {
  1042.   int i = 0;
  1043.   char string[STRING], c;
  1044.  
  1045.   switch (argv[0][pos]) {
  1046.   case '\0':
  1047.     break;
  1048.  
  1049.   case 'b':
  1050.     c = CAP(argv[0][pos+1]);
  1051.     if (IsValidBmpmode(c))
  1052.       bitmapmode = c;
  1053.     xbitmap = TRUE;
  1054.     psfile = metafile = FALSE;
  1055.     break;
  1056.  
  1057. #ifdef PS
  1058.   case 'p':
  1059.     psfile = TRUE + (argv[0][pos+1] != '0');
  1060.     xbitmap = metafile = FALSE;
  1061.     break;
  1062. #endif
  1063.  
  1064. #ifdef META
  1065.   case 'M':
  1066.     if (argv[0][pos+1] == '0')
  1067.       xfont = !xfont;
  1068.     metafile = TRUE;
  1069.     xbitmap = psfile = FALSE;
  1070.     break;
  1071. #endif
  1072.  
  1073.   case 'o':
  1074.     if (argc <= 1) {
  1075.       TooFew("Xo");
  1076.       return -1;
  1077.     }
  1078.     if (!xbitmap && !psfile && !metafile)
  1079.       xbitmap = TRUE;
  1080.     outputfile = argv[1];
  1081.     i++;
  1082.     break;
  1083.  
  1084. #ifdef X11
  1085.   case 'B':
  1086.     xroot = !xroot;
  1087.     break;
  1088. #endif
  1089.  
  1090.   case 'm':
  1091.     xcolor = !xcolor;
  1092.     break;
  1093.  
  1094.   case 'r':
  1095.     xreverse = !xreverse;
  1096.     break;
  1097.  
  1098.   case 'w':
  1099.     if (argc <= 1) {
  1100.       TooFew("Xw");
  1101.       return -1;
  1102.     }
  1103.     chartx = atoi(argv[1]);
  1104.     if (argc > 2 && (charty = atoi(argv[2]))) {
  1105.       argc--; argv++;
  1106.       i++;
  1107.     } else
  1108.       charty = chartx;
  1109.     if (!IsValidGraphx(chartx)) {
  1110.       BadVal("Xw", chartx);
  1111.       return -1;
  1112.     }
  1113.     if (!IsValidGraphy(charty)) {
  1114.       BadVal("Xw", charty);
  1115.       return -1;
  1116.     }
  1117.     i++;
  1118.     break;
  1119.  
  1120.   case 's':
  1121.     if (argc <= 1) {
  1122.       TooFew("Xs");
  1123.       return -1;
  1124.     }
  1125.     scale = atoi(argv[1]);
  1126.     if (scale < 100)
  1127.       scale *= 100;
  1128.     if (!IsValidScale(scale)) {
  1129.       BadVal("Xs", scale);
  1130.       return -1;
  1131.     }
  1132.     i++;
  1133.     break;
  1134.  
  1135.   case 'i':
  1136.     xbonus = !xbonus;
  1137.     break;
  1138.  
  1139.   case 'T':
  1140.     xtext = !xtext;
  1141.     break;
  1142.  
  1143.   case 'l':
  1144.     xlabel = !xlabel;
  1145.     break;
  1146.  
  1147.   case '1':
  1148.     if (argc <= 1) {
  1149.       TooFew("X1");
  1150.       return -1;
  1151.     }
  1152.     xeast = atoi(argv[1]);
  1153.     if (!IsItem(xeast)) {
  1154.       BadVal("X1", xeast);
  1155.       return -1;
  1156.     }
  1157.     i++;
  1158.     break;
  1159.  
  1160.   case '2':
  1161.     if (argc <= 1) {
  1162.       TooFew("X2");
  1163.       return -1;
  1164.     }
  1165.     xeast = atoi(argv[1]);
  1166.     if (!IsItem(xeast)) {
  1167.       BadVal("X2", xeast);
  1168.       return -1;
  1169.     }
  1170.     xeast = -xeast;
  1171.     i++;
  1172.     break;
  1173.  
  1174.   case 'd':
  1175.     if (argc <= 1) {
  1176.       TooFew("Xd");
  1177.       return -1;
  1178.     }
  1179.     dispname = argv[1];
  1180.     i++;
  1181.     break;
  1182.  
  1183.   case 'W':
  1184.     if (argc > 1 && ((degree = atoi(argv[1])) || argv[1][0] == '0')) {
  1185.       i++;
  1186.       if (degree < 0 || degree >= DEGR) {
  1187.         BadVal("XW", degree);
  1188.         return -1;
  1189.       }
  1190.     } else
  1191.       degree = 0;
  1192.     modex = MODEW;
  1193.     if (argv[0][pos+1] == '0')
  1194.       exdisplay |= DASHXW0;
  1195.     autom = TRUE;
  1196.     break;
  1197.  
  1198.   case 'P':
  1199.     if (argc > 1 && ((degree = atoi(argv[1])) || argv[1][0] == '0')) {
  1200.       i++;
  1201.       if (degree < 0 || degree >= DEGR) {
  1202.         BadVal("XP", degree);
  1203.         return -1;
  1204.       }
  1205.     } else
  1206.       degree = 0;
  1207.     modex = MODEP;
  1208.     if (argv[0][pos+1] == '0')
  1209.       exdisplay |= DASHXP0;
  1210.     autom = TRUE;
  1211.     break;
  1212.  
  1213.   case 'G':
  1214.     if (argc > 1 && ((degree = atoi(argv[1])) || argv[1][0] == '0')) {
  1215.       i++;
  1216.       if (degree < 0 || degree >= DEGR) {
  1217.         BadVal("XG", degree);
  1218.         return -1;
  1219.       }
  1220.       if (argc > 2 && ((tilt = atof(argv[2])) || argv[2][0] == '0')) {
  1221.         i++;
  1222.         if (tilt < -DEGQUAD || tilt > DEGQUAD) {
  1223.           BadVal2("XG", tilt);
  1224.           return -1;
  1225.         }
  1226.       }
  1227.     }
  1228.     modex = MODEG;
  1229.     autom = TRUE;
  1230.     break;
  1231.  
  1232. #ifdef ISG
  1233.   case 'n':
  1234.     if (argc > 1 && (xnow = atoi(argv[1])))
  1235.       i++;
  1236.     else
  1237.       xnow = 10;
  1238.     if (xnow < 1 || xnow > 10) {
  1239.       BadVal("Xn", xnow);
  1240.       return -1;
  1241.     }
  1242.     break;
  1243. #endif
  1244.  
  1245.   default:
  1246.     sprintf(string, "Unknown switch '%s'", argv[0]);
  1247.     PrintError(string);
  1248.     return -1;
  1249.   }
  1250.   return i;    /* 'i' contains the value to be added to argc when we return. */
  1251. }
  1252.  
  1253.  
  1254. /* This is the main interface to all the graphics features. This routine     */
  1255. /* is called from the main program if any of the -X switches were specified, */
  1256. /* and it sets up for and goes and generates the appropriate graphics chart. */
  1257. /* We return TRUE if successfull, FALSE if some non-fatal error occurred.    */
  1258.  
  1259. bool XAction()
  1260. {
  1261.   char string[STRING];
  1262.  
  1263.   xfile = (xbitmap || psfile || metafile);
  1264.  
  1265.   /* First figure out what graphic mode to generate the chart in, based on */
  1266.   /* various non-X command switches, e.g. -L combined with -X, -g combined */
  1267.   /* with -X, and so on, and determine the size the window is to be, too.  */
  1268.  
  1269.   if (modex == MODEv) {
  1270.     if (todisplay & DASHw)
  1271.       modex = MODEw;
  1272.     else if (todisplay & DASHL)
  1273.       modex = MODEL;
  1274.     else if ((todisplay & DASHg) | (todisplay & DASHm)) {
  1275.       modex = MODEg;
  1276.       if (relation <= DASHr0 &&
  1277.         (todisplay & DASHm) > 0 && (exdisplay & DASHm0) == 0)
  1278.         exdisplay |= DASHg0;
  1279.       chartx = charty =
  1280.                 (gridobjects + (relation <= DASHr0))*CELLSIZE*SCALE + 1;
  1281.     } else if (todisplay & DASHZ)
  1282.       modex = MODEZ;
  1283.     else if (todisplay & DASHS)
  1284.       modex = MODES;
  1285.     else if (todisplay & DASHE)
  1286.       modex = MODEE;
  1287.     else if (relation == DASHrb)
  1288.       modex = MODEb;
  1289.   }
  1290.   if ((modex == MODEv || modex == MODEw) && !(exdisplay & DASHv0))
  1291.     chartx += SIDESIZE;
  1292.   if (modex == MODEL || modex == MODEW) {
  1293.     chartx = DEGR*SCALE+2;
  1294.     charty = (90*2+1)*SCALE+2;
  1295.   }
  1296.   if (xfile) {                       /* Initialize bitmap or window. */
  1297.     if (chartx > BITMAPX)
  1298.       chartx = BITMAPX;
  1299.     if (charty > BITMAPY)
  1300.       charty = BITMAPY;
  1301.     if (xbitmap) {
  1302.       bitmaprow = (chartx + 1) >> 1;
  1303.       Allocate(bm, (long)bitmaprow * charty, bitmap);
  1304.       if (bm == NULL) {
  1305.         sprintf(string,
  1306.           "Not enough memory for %d by %d bitmap (%ld bytes).",
  1307.           chartx, charty, (long)bitmaprow * charty);
  1308.         PrintError(string);
  1309.         return FALSE;
  1310.       }
  1311.     }
  1312. #ifdef PS
  1313.     else if (psfile)
  1314.         PSbegin();
  1315. #endif
  1316.     else {
  1317.       Allocate(bm, MAXMETA, bitmap);
  1318.       if (bm == NULL) {
  1319.         sprintf(string,
  1320.           "Not enough memory for metafile. (%ld bytes.)", MAXMETA);
  1321.         PrintError(string);
  1322.         return FALSE;
  1323.       }
  1324.       chartx *= METAMUL;    /* Increase chart sizes and scales behind the */
  1325.       charty *= METAMUL;    /* scenes to make graphics look smoother.     */
  1326.       scale  *= METAMUL;
  1327.     }
  1328.     XColorInit();
  1329.   }
  1330. #ifdef ISG
  1331.   else
  1332.     XBegin();
  1333. #endif
  1334.   if (xroot || xfile)    /* Go draw the graphic chart. */
  1335.     XChart();
  1336.   if (xfile) {    /* Write bitmap to file if in that mode. */
  1337.     WriteFile();
  1338.     if (!psfile)
  1339.       Deallocate(bm);
  1340.   }
  1341. #ifdef ISG
  1342.   else {
  1343. #ifdef X11
  1344.     if (xroot) {
  1345.       XSetWindowBackgroundPixmap(disp, root, pixmap);    /* Process -XB. */
  1346.       XClearWindow(disp, root);
  1347.  
  1348.       /* If -Xn in effect with -XB, then enter infinite loop where we */
  1349.       /* calculate and animate chart, displaying on the root window.  */
  1350.       if (xnow)
  1351.         loop {
  1352.           Animate(xnow, 1);
  1353.           if (relation > DASHr0 || (modex != MODEZ && modex != MODES))
  1354.             XFillRectangle(disp, pixmap, pmgc, 0, 0, chartx, charty);
  1355.           XChart();
  1356.           XSetWindowBackgroundPixmap(disp, root, pixmap);
  1357.           XClearWindow(disp, root);
  1358.         }
  1359.     } else
  1360. #endif
  1361.       XSpin();    /* Window's up; process commands given to window now. */
  1362.     XEnd();
  1363.     return TRUE;
  1364.   }
  1365. #endif /* ISG */
  1366. }
  1367. #endif /* GRAPH */
  1368.  
  1369. /* xdriver.c */
  1370.