home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume16 / xephem / part04 < prev    next >
Encoding:
Text File  |  1992-03-05  |  50.2 KB  |  1,722 lines

  1. Newsgroups: comp.sources.x
  2. Path: uunet!think.com!mips!msi!dcmartin
  3. From: e_downey@hwking.cca.cr.rockwell.com (Elwood Downey)
  4. Subject: v16i115: xephem - astronomical ephemeris program., Part04/24
  5. Message-ID: <1992Mar6.135244.2052@msi.com>
  6. Originator: dcmartin@fascet
  7. Sender: dcmartin@msi.com (David C. Martin - Moderator)
  8. Organization: Molecular Simulations, Inc.
  9. References: <csx-16i112-xephem@uunet.UU.NET>
  10. Date: Fri, 6 Mar 1992 13:52:44 GMT
  11. Approved: dcmartin@msi.com
  12.  
  13. Submitted-by: e_downey@hwking.cca.cr.rockwell.com (Elwood Downey)
  14. Posting-number: Volume 16, Issue 115
  15. Archive-name: xephem/part04
  16.  
  17. # this is part.04 (part 4 of a multipart archive)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file help.c continued
  20. #
  21. if test ! -r _shar_seq_.tmp; then
  22.     echo 'Please unpack part 1 first!'
  23.     exit 1
  24. fi
  25. (read Scheck
  26.  if test "$Scheck" != 4; then
  27.     echo Please unpack part "$Scheck" next!
  28.     exit 1
  29.  else
  30.     exit 0
  31.  fi
  32. ) < _shar_seq_.tmp || exit 1
  33. if test ! -f _shar_wnt_.tmp; then
  34.     echo 'x - still skipping help.c'
  35. else
  36. echo 'x - continuing file help.c'
  37. sed 's/^X//' << 'SHAR_EOF' >> 'help.c' &&
  38. X    cb_w = XmCreatePushButton (hlp_w, "HelpC", args, n);
  39. X    XtAddCallback (cb_w, XmNactivateCallback, hlp_ok_cb, (caddr_t)hlp_w);
  40. X    set_xmstring (cb_w, XmNlabelString, "Ok");
  41. X    XtManageChild (cb_w);
  42. X    set_something (hlp_w, XmNdefaultButton, cb_w);
  43. X
  44. X    /* make the scrolled text area to help the help text */
  45. X
  46. X    n = 0;
  47. X    XtSetArg (args[n], XmNheight, NR*char_height()); n++;
  48. X    XtSetArg (args[n], XmNwidth, NC*char_width()); n++;
  49. X    XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  50. X    XtSetArg (args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
  51. X    XtSetArg (args[n], XmNbottomWidget, cb_w); n++;
  52. X    XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  53. X    XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  54. X    XtSetArg (args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
  55. X    XtSetArg (args[n], XmNeditable, False); n++;
  56. X    XtSetArg (args[n], XmNcursorPositionVisible, False); n++;
  57. X    t_w = XmCreateScrolledText (hlp_w, "SrchST", args, n);
  58. X    XtManageChild (t_w);
  59. X
  60. X    return (t_w);
  61. }
  62. X
  63. static void
  64. hlp_ok_cb (w, client, call)
  65. Widget w;
  66. caddr_t client;
  67. caddr_t call;
  68. {
  69. X    Widget d_w = (Widget) client;
  70. X
  71. X    XtDestroyWidget (d_w);
  72. }
  73. X
  74. /* open the help file and position at first line after we see "@tag\n".
  75. X * if successfull return a FILE *, else return 0.
  76. X */
  77. static FILE *
  78. hlp_openfile (tag)
  79. char *tag;
  80. {
  81. X    char *fn;
  82. X    FILE *fp;
  83. X    char buf[MAXLINE];
  84. X    char tagline[MAXLINE];
  85. X
  86. X    if (hlpfile)
  87. X        fn = hlpfile;
  88. X    else {
  89. X        fn = getenv ("XEPHEMHELP");
  90. X        if (!fn)
  91. X        fn = hlpfdef;
  92. X    }
  93. X
  94. X    fp = fopen (fn, "r");
  95. X    if (!fp)
  96. X        return ((FILE *)0);
  97. X
  98. X    (void) sprintf (tagline, "%c%s\n", HLP_TAG, tag);
  99. X    while (fgets (buf, sizeof(buf), fp))
  100. X        if (strcmp (buf, tagline) == 0)
  101. X        return (fp);
  102. X
  103. X    fclose (fp);
  104. X    return ((FILE *)0);
  105. }
  106. X
  107. /* search help file for tag entry, then copy that entry into txt_w.
  108. X * l is the number of chars already in txt_w.
  109. X * also recursively follow any NESTed entries found.
  110. X * return new length of txt_w, else -1 if error.
  111. X */
  112. static
  113. hlp_fillfromfile(tag, txt_w, l)
  114. char *tag;
  115. Widget txt_w;
  116. int l;
  117. {
  118. X    FILE *fp;
  119. X    char buf[MAXLINE];
  120. X    
  121. X    fp = hlp_openfile (tag);
  122. X    if (!fp)
  123. X        return (-1);
  124. X
  125. X    while (fgets (buf, sizeof(buf), fp)) {
  126. X        if (buf[0] == HLP_TAG)
  127. X        break;
  128. X        else if (buf[0] == HLP_NEST) {
  129. X        int newl;
  130. X        buf[strlen(buf)-1] = '\0';    /* remove trailing \n */
  131. X        newl = hlp_fillfromfile (buf+1, txt_w, l);
  132. X        if (newl > l)
  133. X            l = newl;
  134. X        } else {
  135. X        /* buf already includes a trailing \n */
  136. X        XmTextReplace (txt_w, l, l, buf);
  137. X        l += strlen (buf);
  138. X        }
  139. X    }
  140. X
  141. X    fclose (fp);
  142. X    return (l);
  143. }
  144. X
  145. static
  146. hlp_fillfromstrings(msg, nmsg, txt_w)
  147. char *msg[];
  148. int nmsg;
  149. Widget txt_w;
  150. {
  151. X    int i, l;
  152. X
  153. X    l = 0;
  154. X    for (i = 0; i < nmsg; i++) {
  155. X        XmTextReplace (txt_w, l, l, msg[i]);
  156. X        l += strlen (msg[i]);
  157. X        XmTextReplace (txt_w, l, l, "\n");
  158. X        l += 1;
  159. X    }
  160. }
  161. SHAR_EOF
  162. echo 'File help.c is complete' &&
  163. chmod 0644 help.c ||
  164. echo 'restore of help.c failed'
  165. Wc_c="`wc -c < 'help.c'`"
  166. test 5658 -eq "$Wc_c" ||
  167.     echo 'help.c: original size 5658, current size' "$Wc_c"
  168. rm -f _shar_wnt_.tmp
  169. fi
  170. # ============= jupmenu.c ==============
  171. if test -f 'jupmenu.c' -a X"$1" != X"-c"; then
  172.     echo 'x - skipping jupmenu.c (File already exists)'
  173.     rm -f _shar_wnt_.tmp
  174. else
  175. > _shar_wnt_.tmp
  176. echo 'x - extracting jupmenu.c (Text)'
  177. sed 's/^X//' << 'SHAR_EOF' > 'jupmenu.c' &&
  178. /* code to manage the stuff on the "jupiter" menu.
  179. X */
  180. X
  181. #include <stdio.h>
  182. #include <ctype.h>
  183. #include <math.h>
  184. #ifdef VMS
  185. #include <stdlib.h>
  186. #endif
  187. #include <X11/Xlib.h>
  188. #include <Xm/Xm.h>
  189. #include <Xm/Form.h>
  190. #include <Xm/Frame.h>
  191. #include <Xm/LabelG.h>
  192. #include <Xm/PushBG.h>
  193. #include <Xm/DrawingA.h>
  194. #include <Xm/ToggleBG.h>
  195. #include "fieldmap.h"
  196. #include "astro.h"
  197. #include "circum.h"
  198. #include "moreobjs.h"
  199. X
  200. extern char *strncpy();
  201. extern char *getenv();
  202. extern Widget toplevel_w;
  203. extern XmString str_width();
  204. extern Now *mm_get_now();
  205. extern char *objname[];
  206. #define    XtD    XtDisplay(toplevel_w)
  207. X
  208. /* locations of each field.
  209. X * these are in terms of a 1-based row/col on a 24x80 alpha screen, for
  210. X * historical reasons.
  211. X */
  212. #define    NR    (R_MAP+5)
  213. #define    NC    60
  214. X
  215. #define    R_TOP        1
  216. X
  217. /* menu for jupiter aux info items */
  218. #define    R_JCMLI        (R_TOP)
  219. #define    R_JCMLII    (R_TOP+1)
  220. #define    C_JCMLSI    36
  221. #define    C_JCMLSII    36
  222. #define    C_JMNAMES    (2)
  223. #define    C_JMX        (1*NC/4+2)
  224. #define    C_JMY        (2*NC/4+2)
  225. #define    C_JMZ        (3*NC/4+2)
  226. #define    R_JCOLHDNGS    (R_TOP+4)
  227. #define    R_IO        (R_JCOLHDNGS+1)
  228. #define    R_EUROPA    (R_JCOLHDNGS+2)
  229. #define    R_GANYMEDE    (R_JCOLHDNGS+3)
  230. #define    R_CALLISTO    (R_JCOLHDNGS+4)
  231. #define    R_MAP        (R_CALLISTO+1)
  232. #define    R_CONTROL    NR
  233. X
  234. static FieldMap jm_field_map[] = {
  235. X    {mkid(R_IO,C_JMX), PLT, 7, 0, "Io.X"},
  236. X    {mkid(R_IO,C_JMY), PLT, 7, 0, "Io.Y"},
  237. X    {mkid(R_IO,C_JMZ), PLT, 7, 0, "Io.Z"},
  238. X    {mkid(R_EUROPA,C_JMX), PLT, 7, 0, "Europa.X"},
  239. X    {mkid(R_EUROPA,C_JMY), PLT, 7, 0, "Europa.Y"},
  240. X    {mkid(R_EUROPA,C_JMZ), PLT, 7, 0, "Europa.Z"},
  241. X    {mkid(R_GANYMEDE,C_JMX), PLT, 7, 0, "Ganymede.X"},
  242. X    {mkid(R_GANYMEDE,C_JMY), PLT, 7, 0, "Ganymede.Y"},
  243. X    {mkid(R_GANYMEDE,C_JMZ), PLT, 7, 0, "Ganymede.Z"},
  244. X    {mkid(R_CALLISTO,C_JMX), PLT, 7, 0, "Callisto.X"},
  245. X    {mkid(R_CALLISTO,C_JMY), PLT, 7, 0, "Callisto.Y"},
  246. X    {mkid(R_CALLISTO,C_JMZ), PLT, 7, 0, "Callisto.Z"},
  247. X
  248. X    {mkid(R_JCMLI,1), 0, 0, "Central Meridian Longitude (degs):"},
  249. X    {mkid(R_JCMLI,C_JCMLSI), PLT, 7, 0, "Jup.CMLI"},
  250. X    {mkid(R_JCMLI,45), 0, 0, "(Sys I)"},
  251. X    {mkid(R_JCMLII,C_JCMLSII), PLT, 7, 0, "Jup.CMLII"},
  252. X    {mkid(R_JCMLII,1), 0, 0, "(GRS is at 30 degs in System II)"},
  253. X    {mkid(R_JCMLII,45), 0, 0, "(Sys II)"},
  254. X
  255. X    {mkid(R_IO,C_JMNAMES), 0, 0, "I   Io"},
  256. X    {mkid(R_EUROPA,C_JMNAMES), 0, 0, "II  Europa"},
  257. X    {mkid(R_GANYMEDE,C_JMNAMES), 0, 0, "III Ganymede"},
  258. X    {mkid(R_CALLISTO,C_JMNAMES), 0, 0, "IV  Callisto"},
  259. X    {mkid(R_JCOLHDNGS-1,C_JMY-2), 0, 0, "Jupiter Radii"},
  260. X    {mkid(R_JCOLHDNGS,C_JMX+1), 0, 0, "X (+E)"},
  261. X    {mkid(R_JCOLHDNGS,C_JMY+1), 0, 0, "Y (+S)"},
  262. X    {mkid(R_JCOLHDNGS,C_JMZ-2), 0, 0, "Z (+towards)"},
  263. };
  264. #define    NFM    (sizeof(jm_field_map)/sizeof(jm_field_map[0]))
  265. #define    LFM    (&jm_field_map[NFM])
  266. #define    fw(r,c)    (fm(r,c)->w)
  267. X
  268. static Widget jupform_w;
  269. static Widget jda_w;
  270. static int jm_selecting;    /* set while our fields are being selected */
  271. static int bigdots = 1;
  272. X
  273. static FieldMap *
  274. fm(r,c)
  275. int r, c;
  276. {
  277. X    FieldMap *fp;
  278. X    int id = mkid(r,c);
  279. X
  280. X    for (fp = jm_field_map; fp < LFM; fp++)
  281. X        if (fp->id == id)
  282. X        return (fp);
  283. X    printf ("fm: can't find id 0x%x (%d,%d)\n", id, r, c);
  284. X    exit (1);
  285. X    return(0);    /* for lint */
  286. }
  287. X
  288. /* method by which another module can access our field map.
  289. X * this is used by the search compiler.
  290. X */
  291. jm_getfieldmap (fmpp)
  292. FieldMap **fmpp;
  293. {
  294. X    *fmpp = jm_field_map;
  295. X    return (NFM);
  296. }
  297. X
  298. /* called when the jupiter menu is activated via the main menu pulldown.
  299. X * if never called before, create and manage all the widgets as a child of a
  300. X * form. otherwise, just toggle whether the form is managed.
  301. X */
  302. jm_manage ()
  303. {
  304. X    if (!jupform_w) {
  305. X        void jm_activate_cb();
  306. X        void jm_da_exp_cb();
  307. X        void jm_control_cb();
  308. X        void jm_close_cb();
  309. X        void jm_bigd_cb();
  310. X        FieldMap *fp;
  311. X        Widget w, cl_w, frame_w;
  312. X        Widget big_w;
  313. X        XmString str;
  314. X        Arg args[20];
  315. X        int n;
  316. X
  317. X        /* create form */
  318. X        n = 0;
  319. X        XtSetArg (args[n], XmNfractionBase, 1000); n++;
  320. X        XtSetArg (args[n], XmNautoUnmanage, False); n++;
  321. X        XtSetArg (args[n], XmNdefaultPosition, False); n++;
  322. X        XtSetArg (args[n], XmNwidth, char_width()*NC); n++;
  323. X        jupform_w = XmCreateFormDialog (toplevel_w, "Jupiter", args, n);
  324. X
  325. X        /* set some stuff in the parent DialogShell.
  326. X         * setting XmNdialogTitle in the Form didn't work..
  327. X         */
  328. X        n = 0;
  329. X        XtSetArg (args[n], XmNtitle, "xephem Jupiter Table"); n++;
  330. X        XtSetValues (XtParent(jupform_w), args, n);
  331. X
  332. X        /* establish the buttons and labels */
  333. X        for (fp = jm_field_map; fp < LFM; fp++) {
  334. X        int free_str;
  335. X        n = 0;
  336. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  337. X        XtSetArg (args[n], XmNtopPosition, ypos(fp->id)); n++;
  338. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  339. X        XtSetArg (args[n], XmNleftPosition, xpos(fp->id)); n++;
  340. X        free_str = 0;
  341. X        if (fp->prompt) {
  342. X            str = XmStringCreate (fp->prompt,XmSTRING_DEFAULT_CHARSET);
  343. X            free_str = 1;
  344. X        } else if (fp->width) {
  345. X            str = str_width (fp->width);
  346. X            XtSetArg (args[n], XmNrecomputeSize, False); n++;
  347. X        } else {
  348. X            str = XmStringCreate("?",XmSTRING_DEFAULT_CHARSET);
  349. X            free_str = 1;
  350. X        }
  351. X        XtSetArg (args[n], XmNlabelString, str); n++;
  352. X        if (fp->how) {
  353. X            /* pushbutton */
  354. X            XtSetArg (args[n], XmNalignment, XmALIGNMENT_END); n++;
  355. X            fp->w = XtCreateManagedWidget ("JupButton",
  356. X                xmPushButtonGadgetClass, jupform_w, args, n);
  357. X            XtAddCallback (fp->w, XmNactivateCallback, jm_activate_cb,
  358. X                                        fp);
  359. X        } else {
  360. X            /* label */
  361. X            fp->w = XtCreateManagedWidget ("JupLabel",
  362. X                    xmLabelGadgetClass, jupform_w, args, n);
  363. X        }
  364. X        if (free_str)
  365. X            XmStringFree(str);
  366. X        }
  367. X
  368. X        /* make the close button */
  369. X        str = XmStringCreate("Close", XmSTRING_DEFAULT_CHARSET);
  370. X        n = 0;
  371. X        XtSetArg (args[n], XmNlabelString, str); n++;
  372. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  373. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_CONTROL)); n++;
  374. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  375. X        XtSetArg (args[n], XmNleftPosition, 0); n++;
  376. X        cl_w = XmCreatePushButtonGadget (jupform_w, "JupClose", args, n);
  377. X        XtAddCallback (cl_w, XmNactivateCallback, jm_close_cb, 0);
  378. X        XtManageChild (cl_w);
  379. X        XmStringFree (str);
  380. X
  381. X        /* "big dots" toggle button */
  382. X
  383. X        str = XmStringCreate("Big dots", XmSTRING_DEFAULT_CHARSET);
  384. X        n = 0;
  385. X        XtSetArg (args[n], XmNlabelString, str); n++;
  386. X        XtSetArg (args[n], XmNset, bigdots); n++;
  387. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  388. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_CONTROL)); n++;
  389. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  390. X        big_w = XmCreateToggleButtonGadget(jupform_w,"JupBigDots",args,n);
  391. X        XmStringFree (str);
  392. X        XtManageChild (big_w);
  393. X        XtAddCallback(big_w, XmNvalueChangedCallback, jm_bigd_cb, 0);
  394. X
  395. X
  396. X        /* make a frame for the drawing area */
  397. X        n = 0;
  398. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  399. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_MAP)); n++;
  400. X        XtSetArg (args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
  401. X        XtSetArg (args[n], XmNbottomWidget, cl_w); n++;
  402. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  403. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  404. X        XtSetArg (args[n], XmNshadowType, XmSHADOW_ETCHED_OUT); n++;
  405. X        frame_w = XmCreateFrame (jupform_w, "JupFrame", args, n);
  406. X        XtManageChild (frame_w);
  407. X
  408. X        /* make a drawing area for drawing the little map */
  409. X        n = 0;
  410. X        jda_w = XmCreateDrawingArea (frame_w, "JupMap", args, n);
  411. X        XtAddCallback (jda_w, XmNexposeCallback, jm_da_exp_cb, 0);
  412. X        XtAddCallback (jda_w, XmNresizeCallback, jm_da_exp_cb, 0);
  413. X        XtManageChild (jda_w);
  414. X    }
  415. X    
  416. X    if (XtIsManaged(jupform_w))
  417. X        XtUnmanageChild (jupform_w);
  418. X    else {
  419. X        XtManageChild (jupform_w);
  420. X        jm_update (mm_get_now(), 1);
  421. X        jm_set_buttons(jm_selecting);
  422. X    }
  423. }
  424. X
  425. jm_ison()
  426. {
  427. X    return (jupform_w && XtIsManaged(jupform_w));
  428. }
  429. X
  430. /* called by other menus as they want to hear from our buttons or not.
  431. X * the "on"s and "off"s stack - only really redo the buttons if it's the
  432. X * first on or the last off.
  433. X */
  434. jm_selection_mode (whether)
  435. int whether;    /* whether setting up for plotting or for not plotting */
  436. {
  437. X    jm_selecting += whether ? 1 : -1;
  438. X
  439. X    if (jupform_w && XtIsManaged(jupform_w))
  440. X        if (whether && jm_selecting == 1     /* first one to want on */
  441. X        || !whether && jm_selecting == 0 /* last one to want off */)
  442. X        jm_set_buttons (whether);
  443. }
  444. X
  445. /* go through all the buttons pickable for plotting and set whether they
  446. X * should appear to look like buttons or just flat labels.
  447. X */
  448. static
  449. jm_set_buttons (whether)
  450. int whether;    /* whether setting up for plotting or for not plotting */
  451. {
  452. X    static Arg look_like_button[] = {
  453. X        {XmNshadowThickness, (XtArgVal) 2},
  454. X        {XmNfillOnArm, (XtArgVal) True},
  455. X    };
  456. X    static Arg look_like_label[] = {
  457. X        {XmNshadowThickness, (XtArgVal) 0},
  458. X        {XmNfillOnArm, (XtArgVal) False},
  459. X    };
  460. X    FieldMap *fp;
  461. X
  462. X    for (fp = jm_field_map; fp < LFM; fp++)
  463. X        if (whether && fp->how & PLT)
  464. X        XtSetValues (fp->w,look_like_button,XtNumber(look_like_button));
  465. X        else
  466. X        XtSetValues (fp->w,look_like_label,XtNumber(look_like_label));
  467. }
  468. X
  469. /* callback from the big dots toggle button
  470. X * TODO: really shouldn't get present time, just redo dots in same location.
  471. X */
  472. void
  473. jm_bigd_cb (w, client, call)
  474. Widget w;
  475. caddr_t client;
  476. caddr_t call;
  477. {
  478. X    bigdots = XmToggleButtonGadgetGetState(w);
  479. X    jm_update (mm_get_now(), 1);
  480. }
  481. X
  482. /* callback from any of the data menu buttons being activated.
  483. X */
  484. void
  485. jm_activate_cb (w, client, call)
  486. Widget w;
  487. caddr_t client;
  488. caddr_t call;
  489. {
  490. X    FieldMap *fp = (FieldMap *)client;
  491. X
  492. X    if (jm_selecting) {
  493. X        plt_selection (fp);
  494. X        lst_selection (fp);
  495. X        srch_selection (fp);
  496. X    }
  497. }
  498. X
  499. /* callback from the Close button
  500. X */
  501. void
  502. jm_close_cb (w, client, call)
  503. Widget w;
  504. caddr_t client;
  505. caddr_t call;
  506. {
  507. X    XtUnmanageChild (jupform_w);
  508. }
  509. X
  510. /* callback from either expose or resize of the drawing area.
  511. X */
  512. void
  513. jm_da_exp_cb (w, client, call)
  514. Widget w;
  515. caddr_t client;
  516. caddr_t call;
  517. {
  518. X    XmDrawingAreaCallbackStruct *c = (XmDrawingAreaCallbackStruct *)call;
  519. X
  520. X    /* filter out a few oddball cases */
  521. X    switch (c->reason) {
  522. X    case XmCR_RESIZE:
  523. X        /* seems we can get one resize before the first expose.
  524. X         * hence, we don't have a good window to use yet. just let it
  525. X         * go; we'll get the expose soon.
  526. X         */
  527. X        if (!XtWindow(w))
  528. X        return;
  529. X        break;
  530. X    case XmCR_EXPOSE: {
  531. X        XExposeEvent *e = &c->event->xexpose;
  532. X        /* wait for the last in the series */
  533. X        if (e->count != 0)
  534. X        return;
  535. X        break;
  536. X        }
  537. X    default:
  538. X        printf ("Unexpected jupform_w event. type=%d\n", c->reason);
  539. X        return;
  540. X    }
  541. X
  542. X    jm_update (mm_get_now(), 1);
  543. }
  544. X
  545. /* called to recompute and fill in values for the jupiter menu.
  546. X * don't bother if it doesn't exist or is unmanaged now.
  547. X */
  548. jm_update (np, how_much)
  549. Now *np;
  550. int how_much;
  551. {
  552. X    static char fmt[] = "%7.3f";
  553. X    double ix, ex, gx, cx;
  554. X    double iy, ey, gy, cy;
  555. X    double iz, ez, gz, cz;
  556. X    double sIcml, sIIcml;
  557. X
  558. X    if (!jupform_w || !(how_much || XtIsManaged(jupform_w)))
  559. X        return;
  560. X
  561. X    /* compute jupiter info.
  562. X     */
  563. X    jupinfo (mjd, &ix, &ex, &gx, &cx, &iy, &ey, &gy, &cy,
  564. X                    &iz, &ez, &gz, &cz, &sIcml, &sIIcml);
  565. X
  566. X    f_double (fw(R_JCMLI,C_JCMLSI), fmt, sIcml);
  567. X    f_double (fw(R_JCMLII,C_JCMLSII), fmt, sIIcml);
  568. X    f_double (fw(R_IO,C_JMX), fmt, ix);
  569. X    f_double (fw(R_EUROPA,C_JMX), fmt, ex);
  570. X    f_double (fw(R_GANYMEDE,C_JMX), fmt, gx);
  571. X    f_double (fw(R_CALLISTO,C_JMX), fmt, cx);
  572. X    f_double (fw(R_IO,C_JMY), fmt, iy);
  573. X    f_double (fw(R_EUROPA,C_JMY), fmt, ey);
  574. X    f_double (fw(R_GANYMEDE,C_JMY), fmt, gy);
  575. X    f_double (fw(R_CALLISTO,C_JMY), fmt, cy);
  576. X    f_double (fw(R_IO,C_JMZ), fmt, iz);
  577. X    f_double (fw(R_EUROPA,C_JMZ), fmt, ez);
  578. X    f_double (fw(R_GANYMEDE,C_JMZ), fmt, gz);
  579. X    f_double (fw(R_CALLISTO,C_JMZ), fmt, cz);
  580. X
  581. X    jm_draw_map (jda_w, ix, ex, gx, cx, iy, ey, gy, cy,
  582. X                    iz, ez, gz, cz, sIcml, sIIcml);
  583. }
  584. X
  585. /* given the loc of the moons, draw a nifty little picture.
  586. X * scale of the locations is in terms of jupiter radii == 1.
  587. X */
  588. static
  589. jm_draw_map (w, ix, ex, gx, cx, iy, ey, gy, cy, iz, ez, gz, cz, sIcml, sIIcml)
  590. Widget w;
  591. double ix, ex, gx, cx;
  592. double iy, ey, gy, cy;
  593. double iz, ez, gz, cz;
  594. double sIcml, sIIcml;
  595. {
  596. X    static GC j_fgc, j_bgc;
  597. X    static XFontStruct *j_fs;
  598. #define    NORM    26.6    /* max callisto orbit radius; used to normalize */
  599. X    Display *dsp = XtDisplay(w);
  600. X    Window win = XtWindow(w);
  601. X    Window root;
  602. X    char c;
  603. X    int x, y;
  604. X    int nx, ny, bw, d;
  605. X    int cw;
  606. #define    MAPSCALE(v)    ((v)*nx/NORM/2)
  607. #define    XCORD(x)    ((int)(nx/2.0 + MAPSCALE(x) + 0.5))
  608. #define    YCORD(y)    ((int)(ny/2.0 - MAPSCALE(y) + 0.5))
  609. X
  610. X    if (!j_fgc) {
  611. X        XGCValues gcv;
  612. X        unsigned int gcm;
  613. X        gcm = GCForeground;
  614. X        get_something (w, XmNforeground, (char *)&gcv.foreground);
  615. X        j_fgc = XCreateGC (dsp, win, gcm, &gcv);
  616. X        get_something (w, XmNbackground, (char *)&gcv.foreground);
  617. X        j_bgc = XCreateGC (dsp, win, gcm, &gcv);
  618. X        j_fs = XQueryFont (dsp, XGContextFromGC (j_fgc));
  619. X    }
  620. X
  621. X    XGetGeometry(dsp, win, &root, &x, &y, &nx, &ny, &bw, &d);
  622. X    XClearWindow (dsp, win);
  623. X
  624. X    c = 'E'; XDrawString (dsp, win, j_fgc, nx-j_fs->max_bounds.width-1,
  625. X                                ny/2-2, &c, 1);
  626. X    c = 'S'; XDrawString (dsp, win, j_fgc, (nx-j_fs->max_bounds.width)/2-1,
  627. X                            j_fs->ascent, &c, 1);
  628. X    XFillArc (dsp, win, j_fgc, XCORD(-1), YCORD(1), 2*(int)MAPSCALE(1),
  629. X                        2*(int)MAPSCALE(1), 0, 360*64);
  630. X
  631. X    cw = j_fs->max_bounds.width;
  632. X    x = XCORD(ix);
  633. X    y = YCORD(iy);
  634. X    XDrawPoint (dsp, win, (fabs(ix)>1 || iz<0) ? j_fgc : j_bgc, x, y);
  635. X    if (bigdots) {
  636. X        XDrawPoint (dsp, win, (fabs(ix)>1 || iz<0) ? j_fgc:j_bgc, x+1, y);
  637. X        XDrawPoint (dsp, win, (fabs(ix)>1 || iz<0) ? j_fgc:j_bgc, x,   y+1);
  638. X        XDrawPoint (dsp, win, (fabs(ix)>1 || iz<0) ? j_fgc:j_bgc, x+1, y+1);
  639. X    }
  640. X    XDrawString(dsp, win, j_fgc, x-cw/2, y+ny/3, "I", 1);
  641. X
  642. X    x = XCORD(ex);
  643. X    y = YCORD(ey);
  644. X    XDrawPoint (dsp, win, (fabs(ex)>1 || ez<0) ? j_fgc : j_bgc, x, y);
  645. X    if (bigdots) {
  646. X        XDrawPoint (dsp, win, (fabs(ex)>1 || ez<0) ? j_fgc:j_bgc, x+1, y);
  647. X        XDrawPoint (dsp, win, (fabs(ex)>1 || ez<0) ? j_fgc:j_bgc, x,   y+1);
  648. X        XDrawPoint (dsp, win, (fabs(ex)>1 || ez<0) ? j_fgc:j_bgc, x+1, y+1);
  649. X    }
  650. X    XDrawString(dsp, win, j_fgc, x-cw, y+ny/3, "II", 2);
  651. X
  652. X    x = XCORD(gx);
  653. X    y = YCORD(gy);
  654. X    XDrawPoint (dsp, win, (fabs(gx)>1 || gz<0) ? j_fgc : j_bgc, x, y);
  655. X    if (bigdots) {
  656. X        XDrawPoint (dsp, win, (fabs(gx)>1 || gz<0) ? j_fgc:j_bgc, x+1, y);
  657. X        XDrawPoint (dsp, win, (fabs(gx)>1 || gz<0) ? j_fgc:j_bgc, x,   y+1);
  658. X        XDrawPoint (dsp, win, (fabs(gx)>1 || gz<0) ? j_fgc:j_bgc, x+1, y+1);
  659. X    }
  660. X    XDrawString(dsp, win,j_fgc, x-3*cw/2, y+ny/3, "III", 3);
  661. X
  662. X    x = XCORD(cx);
  663. X    y = YCORD(cy);
  664. X    XDrawPoint (dsp, win, (fabs(cx)>1 || cz<0) ? j_fgc : j_bgc, x, y);
  665. X    if (bigdots) {
  666. X        XDrawPoint (dsp, win, (fabs(cx)>1 || cz<0) ? j_fgc:j_bgc, x+1, y);
  667. X        XDrawPoint (dsp, win, (fabs(cx)>1 || cz<0) ? j_fgc:j_bgc, x,   y+1);
  668. X        XDrawPoint (dsp, win, (fabs(cx)>1 || cz<0) ? j_fgc:j_bgc, x+1, y+1);
  669. X    }
  670. X    XDrawString(dsp, win, j_fgc, x-cw, y+ny/3, "IV", 2);
  671. }
  672. X
  673. X
  674. #define    dsin(x)    sin(degrad(x))
  675. #define    dcos(x)    cos(degrad(x))
  676. X
  677. /* given a modified julian date (ie, days since Jan .5 1900), d, return x, y, z
  678. X *   location of each Galilean moon as a multiple of Jupiter's radius. on this
  679. X *   scale, Callisto is never more than 26.5593. +x is easterly, +y is
  680. X *   southerly, +z is towards earth. x and z are relative to the equator
  681. X *   of Jupiter; y is further corrected for earth's position above or below
  682. X *   this plane. also, return the system I and II central meridian longitude,
  683. X *   in degress, relative to the true disk of jupiter and corrected for light
  684. X *   travel time.
  685. X * from "Astronomical Formulae for Calculators", 2nd ed, by Jean Meeus,
  686. X *   Willmann-Bell, Richmond, Va., U.S.A. (c) 1982, chapters 35 and 36.
  687. X */
  688. static
  689. jupinfo (d, ix, ex, gx, cx, iy, ey, gy, cy, iz, ez, gz, cz, sIcml, sIIcml)
  690. double d;
  691. double *ix, *ex, *gx, *cx;
  692. double *iy, *ey, *gy, *cy;
  693. double *iz, *ez, *gz, *cz;
  694. double *sIcml, *sIIcml;
  695. {
  696. X    double A, B, Del, J, K, M, N, R, V;
  697. X    double cor_u1, cor_u2, cor_u3, cor_u4;
  698. X    double solc, tmp, G, H, psi, r, r1, r2, r3, r4;
  699. X    double u1, u2, u3, u4;
  700. X    double lam, Ds;
  701. X    double z1, z2, z3,  z4;
  702. X    double De, dsinDe;
  703. X
  704. X    V = 134.63 + 0.00111587 * d;
  705. X
  706. X    M = (358.47583 + 0.98560003*d);
  707. X    N = (225.32833 + 0.0830853*d) + 0.33 * dsin (V);
  708. X
  709. X    J = 221.647 + 0.9025179*d - 0.33 * dsin(V);;
  710. X
  711. X    A = 1.916*dsin(M) + 0.02*dsin(2*M);
  712. X    B = 5.552*dsin(N) + 0.167*dsin(2*N);
  713. X    K = (J+A-B);
  714. X    R = 1.00014 - 0.01672 * dcos(M) - 0.00014 * dcos(2*M);
  715. X    r = 5.20867 - 0.25192 * dcos(N) - 0.00610 * dcos(2*N);
  716. X    Del = sqrt (R*R + r*r - 2*R*r*dcos(K));
  717. X    psi = raddeg (asin (R/Del*dsin(K)));
  718. X
  719. X    solc = (d - Del/173.);    /* speed of light correction */
  720. X    tmp = psi - B;
  721. X
  722. X    u1 = 84.5506 + 203.4058630 * solc + tmp;
  723. X    u2 = 41.5015 + 101.2916323 * solc + tmp;
  724. X    u3 = 109.9770 + 50.2345169 * solc + tmp;
  725. X    u4 = 176.3586 + 21.4879802 * solc + tmp;
  726. X
  727. X    G = 187.3 + 50.310674 * solc;
  728. X    H = 311.1 + 21.569229 * solc;
  729. X      
  730. X    cor_u1 =  0.472 * dsin (2*(u1-u2));
  731. X    cor_u2 =  1.073 * dsin (2*(u2-u3));
  732. X    cor_u3 =  0.174 * dsin (G);
  733. X    cor_u4 =  0.845 * dsin (H);
  734. X      
  735. X    r1 = 5.9061 - 0.0244 * dcos (2*(u1-u2));
  736. X    r2 = 9.3972 - 0.0889 * dcos (2*(u2-u3));
  737. X    r3 = 14.9894 - 0.0227 * dcos (G);
  738. X    r4 = 26.3649 - 0.1944 * dcos (H);
  739. X
  740. X    *ix = -r1 * dsin (u1+cor_u1);
  741. X    *ex = -r2 * dsin (u2+cor_u2);
  742. X    *gx = -r3 * dsin (u3+cor_u3);
  743. X    *cx = -r4 * dsin (u4+cor_u4);
  744. X
  745. X    lam = 238.05 + 0.083091*d + 0.33*dsin(V) + B;
  746. X    Ds = 3.07*dsin(lam + 44.5);
  747. X    De = Ds - 2.15*dsin(psi)*dcos(lam+24.)
  748. X        - 1.31*(r-Del)/Del*dsin(lam-99.4);
  749. X    dsinDe = dsin(De);
  750. X
  751. X    z1 = r1 * dcos(u1+cor_u1);
  752. X    z2 = r2 * dcos(u2+cor_u2);
  753. X    z3 = r3 * dcos(u3+cor_u3);
  754. X    z4 = r4 * dcos(u4+cor_u4);
  755. X
  756. X    *iy = z1*dsinDe;
  757. X    *ey = z2*dsinDe;
  758. X    *gy = z3*dsinDe;
  759. X    *cy = z4*dsinDe;
  760. X
  761. X    *iz = z1;
  762. X    *ez = z2;
  763. X    *gz = z3;
  764. X    *cz = z4;
  765. X
  766. X    *sIcml  = 268.28 + 877.8169088*(d - Del/173) + psi - B;
  767. X    range (sIcml, 360.0);
  768. X    *sIIcml = 290.28 + 870.1869088*(d - Del/173) + psi - B;
  769. X    range (sIIcml, 360.0);
  770. }
  771. SHAR_EOF
  772. chmod 0644 jupmenu.c ||
  773. echo 'restore of jupmenu.c failed'
  774. Wc_c="`wc -c < 'jupmenu.c'`"
  775. test 17844 -eq "$Wc_c" ||
  776.     echo 'jupmenu.c: original size 17844, current size' "$Wc_c"
  777. rm -f _shar_wnt_.tmp
  778. fi
  779. # ============= listing.c ==============
  780. if test -f 'listing.c' -a X"$1" != X"-c"; then
  781.     echo 'x - skipping listing.c (File already exists)'
  782.     rm -f _shar_wnt_.tmp
  783. else
  784. > _shar_wnt_.tmp
  785. echo 'x - extracting listing.c (Text)'
  786. sed 's/^X//' << 'SHAR_EOF' > 'listing.c' &&
  787. /* code to manage the stuff on the "listing" menu.
  788. X */
  789. X
  790. #include <stdio.h>
  791. #include <ctype.h>
  792. #include <math.h>
  793. #ifdef VMS
  794. #include <stdlib.h>
  795. #endif
  796. #include <X11/Xlib.h>
  797. #include <Xm/Xm.h>
  798. #include <Xm/Form.h>
  799. #include <Xm/DrawingA.h>
  800. #include <Xm/LabelG.h>
  801. #include <Xm/PushBG.h>
  802. #include <Xm/ToggleBG.h>
  803. #include <Xm/Text.h>
  804. #include "fieldmap.h"
  805. X
  806. extern Widget toplevel_w;
  807. X
  808. #ifdef VMS
  809. #include <perror.h>
  810. #include <errno.h>
  811. #else
  812. extern char *sys_errlist[];
  813. extern errno;
  814. #endif
  815. X
  816. #define    errsys    (sys_errlist[errno])
  817. X
  818. #define MAXLSTFLDS      10      /* max number of fields we can track.
  819. X                 * note we can't store more than NFLOGS fields
  820. X                 * anyway (see flog.c).
  821. X                     */
  822. X
  823. /* locations of each field.
  824. X * these are in terms of a 1-based row/col on a 24x80 alpha screen, for
  825. X * historical reasons.
  826. X */
  827. #define    NR    (R_TABLE+MAXLSTFLDS+1)    /* +1 for close and help buttons */
  828. #define    NC    35
  829. X
  830. #define    R_SELECT    1
  831. #define    R_ACTIVE    2
  832. #define    R_SHOW        3
  833. X
  834. #define    R_FNLABEL    5
  835. #define    R_FILENAME    6
  836. X
  837. #define    R_TLABEL    8
  838. #define    R_TITLE        9
  839. X
  840. #define    R_PROMPT    11
  841. #define    R_TABLE        12
  842. #define    R_CONTROL    NR
  843. X
  844. #define    C_TAG        (3*NC/8)
  845. X
  846. static Widget lstform_w;
  847. static Widget select_w, active_w, prompt_w;
  848. static Widget title_w, filename_w;
  849. static Widget table_w[MAXLSTFLDS];    /* row indeces follow.. */
  850. X
  851. #define    DEF_LSTFN    "ephem.lst"    /* default plot file name */
  852. static FILE *lst_fp;            /* the listing file; == 0 means don't plot */
  853. X
  854. X
  855. /* lst_activate_cb client values. */
  856. #define    SELECT    0
  857. #define    ACTIVE    1
  858. X
  859. /* store the Widget for each field to track.
  860. X * we get the label straight from the Text widget in the table as needed.
  861. X */
  862. static Widget lstflds[MAXLSTFLDS];
  863. static int nlstflds;        /* number of lstflds[] in actual use */
  864. X
  865. /* called when the list menu is activated via the main menu pulldown.
  866. X * if never called before, create and manage all the widgets as a child of a
  867. X * form. otherwise, just toggle whether the form is managed.
  868. X */
  869. lst_manage ()
  870. {
  871. X    if (!lstform_w) {
  872. X        void lst_activate_cb();
  873. X        void lst_close_cb();
  874. X        void lst_help_cb();
  875. X        XmString str;
  876. X        Widget w;
  877. X        Arg args[20];
  878. X        int i, n;
  879. X
  880. X        /* create form */
  881. X        n = 0;
  882. X        XtSetArg (args[n], XmNfractionBase, 1000); n++;
  883. X        XtSetArg (args[n], XmNwidth, char_width()*NC); n++;
  884. X        XtSetArg (args[n], XmNautoUnmanage, False); n++;
  885. X        XtSetArg (args[n], XmNdefaultPosition, False); n++;
  886. X        XtSetArg (args[n], XmNresizePolicy, XmRESIZE_NONE); n++;
  887. X        lstform_w = XmCreateFormDialog (toplevel_w, "List", args, n);
  888. X
  889. X        /* set some stuff in the parent DialogShell.
  890. X         * setting XmNdialogTitle in the Form didn't work..
  891. X         */
  892. X        n = 0;
  893. X        XtSetArg (args[n], XmNtitle, "xephem Listing Control"); n++;
  894. X        XtSetValues (XtParent(lstform_w), args, n);
  895. X
  896. X        /* make the control controls */
  897. X
  898. X        str = XmStringCreate("Select fields", XmSTRING_DEFAULT_CHARSET);
  899. X        n = 0;
  900. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  901. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_SELECT)); n++;
  902. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  903. X        XtSetArg (args[n], XmNleftPosition, 0); n++;
  904. X        XtSetArg (args[n], XmNlabelString, str); n++;
  905. X        select_w = XmCreateToggleButtonGadget(lstform_w, "ListSelect",
  906. X                                    args, n);
  907. X        XmStringFree (str);
  908. X        XtManageChild (select_w);
  909. X        XtAddCallback(select_w,XmNvalueChangedCallback, lst_activate_cb,
  910. X                                    SELECT);
  911. X
  912. X        str = XmStringCreate("List to file", XmSTRING_DEFAULT_CHARSET);
  913. X        n = 0;
  914. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  915. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_ACTIVE)); n++;
  916. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  917. X        XtSetArg (args[n], XmNleftPosition, 0); n++;
  918. X        XtSetArg (args[n], XmNlabelString, str); n++;
  919. X        active_w = XmCreateToggleButtonGadget(lstform_w, "ListActive",
  920. X                                    args, n);
  921. X        XmStringFree (str);
  922. X        XtManageChild (active_w);
  923. X        XtAddCallback (active_w, XmNvalueChangedCallback, lst_activate_cb,
  924. X                                    ACTIVE);
  925. X
  926. X        /* make the close button */
  927. X
  928. X        str = XmStringCreate ("Close", XmSTRING_DEFAULT_CHARSET);
  929. X        n = 0;
  930. X        XtSetArg (args[n], XmNlabelString, str); n++;
  931. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  932. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_CONTROL)); n++;
  933. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  934. X        XtSetArg (args[n], XmNleftPosition, 0); n++;
  935. X        w = XmCreatePushButtonGadget (lstform_w, "ListClose", args, n);
  936. X        XtAddCallback (w, XmNactivateCallback, lst_close_cb, 0);
  937. X        XtManageChild (w);
  938. X        XmStringFree (str);
  939. X
  940. X        /* make the help button */
  941. X
  942. X        str = XmStringCreate ("Help", XmSTRING_DEFAULT_CHARSET);
  943. X        n = 0;
  944. X        XtSetArg (args[n], XmNlabelString, str); n++;
  945. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  946. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_CONTROL)); n++;
  947. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  948. X        XtSetArg (args[n], XmNrightPosition, 1000); n++;
  949. X        w = XmCreatePushButtonGadget (lstform_w, "ListHelp", args, n);
  950. X        XtAddCallback (w, XmNactivateCallback, lst_help_cb, 0);
  951. X        XtManageChild (w);
  952. X        XmStringFree (str);
  953. X
  954. X        /* create filename text area and its label */
  955. X        n = 0;
  956. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  957. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_FILENAME)); n++;
  958. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  959. X        XtSetArg (args[n], XmNleftPosition, 50); n++;
  960. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  961. X        XtSetArg (args[n], XmNrightPosition, 950); n++;
  962. X        filename_w = XmCreateText (lstform_w, "ListFilename", args, n);
  963. X        XmTextSetString (filename_w, DEF_LSTFN);
  964. X        XtManageChild (filename_w);
  965. X
  966. X        n = 0;
  967. X        str = XmStringCreate("File name:", XmSTRING_DEFAULT_CHARSET);
  968. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  969. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_FNLABEL)); n++;
  970. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  971. X        XtSetArg (args[n], XmNleftPosition, 0); n++;
  972. X        XtSetArg (args[n], XmNlabelString, str); n++;
  973. X        w = XmCreateLabelGadget (lstform_w, "ListFnL", args, n);
  974. X        XmStringFree (str);
  975. X        XtManageChild (w);
  976. X
  977. X        /* create title text area and its label */
  978. X        n = 0;
  979. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  980. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_TITLE)); n++;
  981. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  982. X        XtSetArg (args[n], XmNleftPosition, 50); n++;
  983. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  984. X        XtSetArg (args[n], XmNrightPosition, 950); n++;
  985. X        title_w = XmCreateText (lstform_w, "ListTitle", args, n);
  986. X        XtManageChild (title_w);
  987. X
  988. X        n = 0;
  989. X        str = XmStringCreate("Title:", XmSTRING_DEFAULT_CHARSET);
  990. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  991. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_TLABEL)); n++;
  992. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  993. X        XtSetArg (args[n], XmNleftPosition, 0); n++;
  994. X        XtSetArg (args[n], XmNlabelString, str); n++;
  995. X        w = XmCreateLabelGadget (lstform_w, "ListTL", args, n);
  996. X        XtManageChild (w);
  997. X        XmStringFree (str);
  998. X
  999. X        /* create prompt line and table headings */
  1000. X
  1001. X        n = 0;
  1002. X        str = XmStringCreate("", XmSTRING_DEFAULT_CHARSET);
  1003. X        XtSetArg (args[n], XmNlabelString, str); n++;
  1004. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1005. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_PROMPT)); n++;
  1006. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1007. X        XtSetArg (args[n], XmNleftPosition, 50); n++;
  1008. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  1009. X        XtSetArg (args[n], XmNrightPosition, 950); n++;
  1010. X        XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  1011. X        prompt_w = XmCreateLabelGadget (lstform_w, "ListPrompt", args, n);
  1012. X        XtManageChild (prompt_w);
  1013. X        XmStringFree (str);
  1014. X
  1015. X        /* make the field name table, but don't manage them now */
  1016. X        for (i = 0; i < MAXLSTFLDS; i++) {
  1017. X        n = 0;
  1018. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1019. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_TABLE+i)); n++;
  1020. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1021. X        XtSetArg (args[n], XmNleftPosition, c2xpos(C_TAG)); n++;
  1022. X        table_w[i] = XmCreateLabelGadget (lstform_w, "ListLabel",
  1023. X                                    args, n);
  1024. X        }
  1025. X    }
  1026. X    
  1027. X    if (XtIsManaged(lstform_w))
  1028. X        XtUnmanageChild (lstform_w);
  1029. X    else
  1030. X        XtManageChild (lstform_w);
  1031. }
  1032. X
  1033. /* called by the other menus (data, riset, etc) as their buttons are
  1034. X * selected to inform us that that button is to be included in a listing.
  1035. X */
  1036. lst_selection (fp)
  1037. FieldMap *fp;
  1038. {
  1039. X    Widget tw;
  1040. X
  1041. X
  1042. X    if (!lstform_w
  1043. X        || !XtIsManaged(lstform_w)
  1044. X        || !XmToggleButtonGadgetGetState(select_w))
  1045. X            return;
  1046. X
  1047. X    if (flog_add(fp->w) < 0) {
  1048. X        f_msg ("Sorry; can not log any more fields.", 0);
  1049. X        return;
  1050. X    }
  1051. X
  1052. X    tw = table_w[nlstflds];
  1053. X    set_xmstring (tw, XmNlabelString, fp->name);
  1054. X    XtManageChild (tw);
  1055. X
  1056. X    lstflds[nlstflds] = fp->w;
  1057. X    if (++nlstflds == MAXLSTFLDS)
  1058. X        lst_stop_selecting();
  1059. }
  1060. X
  1061. /* write the active listing to the current listing file, if one is open. */
  1062. listing()
  1063. {
  1064. X    if (lst_fp) {
  1065. X        /* list in order of original selection */
  1066. X        int n;
  1067. X        double flx;
  1068. X        char flstr[32];
  1069. X        for (n = 0; n < nlstflds; n++)
  1070. X        if (flog_get (lstflds[n], &flx, flstr) == 0)
  1071. X            (void) fprintf (lst_fp, "%s  ", flstr);
  1072. X        (void) fprintf (lst_fp, "\n");
  1073. X    }
  1074. }
  1075. X
  1076. listing_ison()
  1077. {
  1078. X    return (lst_fp != 0);
  1079. }
  1080. X
  1081. /* callback from any of the listing menu toggle buttons being activated.
  1082. X */
  1083. void
  1084. lst_activate_cb (w, client, call)
  1085. Widget w;
  1086. caddr_t client;
  1087. caddr_t call;
  1088. {
  1089. X    XmToggleButtonCallbackStruct *t = (XmToggleButtonCallbackStruct *) call;
  1090. X    int what = (int) client;
  1091. X
  1092. X    switch (what) {
  1093. X    case SELECT:
  1094. X        if (t->set) {
  1095. X        /* first turn off listing, if on, while we change things */
  1096. X        if (XmToggleButtonGadgetGetState(active_w))
  1097. X            XmToggleButtonGadgetSetState(active_w, False, True);
  1098. X        lst_reset();    /* reset lstflds array and unmanage the table*/
  1099. X        lst_select(1);    /* inform other menus to inform us of fields */
  1100. X        f_string (prompt_w, "Select quantity for next column...");
  1101. X        } else
  1102. X        lst_stop_selecting();
  1103. X        break;
  1104. X    case ACTIVE:
  1105. X        if (t->set) {
  1106. X        /* first turn off selecting, if on */
  1107. X        if (XmToggleButtonGadgetGetState(select_w))
  1108. X            XmToggleButtonGadgetSetState(select_w, False, True);
  1109. X        lst_try_turn_on();
  1110. X        } else
  1111. X        lst_turn_off();
  1112. X        break;
  1113. X    }
  1114. }
  1115. X
  1116. /* callback from the Close button.
  1117. X */
  1118. void
  1119. lst_close_cb (w, client, call)
  1120. Widget w;
  1121. caddr_t client;
  1122. caddr_t call;
  1123. {
  1124. X    XtUnmanageChild (lstform_w);
  1125. }
  1126. X
  1127. /* callback from the Help
  1128. X */
  1129. void
  1130. lst_help_cb (w, client, call)
  1131. Widget w;
  1132. caddr_t client;
  1133. caddr_t call;
  1134. {
  1135. X    static char *msg[] = {
  1136. "Select fields to become each column of a listing, then run xephem. Each step",
  1137. "will yield one line in the output file. The filename may be specified in the",
  1138. "text area provided."
  1139. };
  1140. X
  1141. X    hlp_dialog ("Listing", msg, sizeof(msg)/sizeof(msg[0]));
  1142. }
  1143. X
  1144. /* inform the other menues whether we are setting up for them to tell us
  1145. X * what fields to list.
  1146. X */
  1147. lst_select(whether)
  1148. int whether;
  1149. {
  1150. X    dm_selection_mode(whether);
  1151. X    mm_selection_mode(whether);
  1152. X    rm_selection_mode(whether);
  1153. X    sm_selection_mode(whether);
  1154. X    jm_selection_mode(whether);
  1155. X    srch_selection_mode(whether);
  1156. }
  1157. X
  1158. /* stop logging our collection of selected widgets, forget our list,
  1159. X * and unmanage the table.
  1160. X */
  1161. static
  1162. lst_reset()
  1163. {
  1164. X    Widget *lp;
  1165. X    int i;
  1166. X
  1167. X    for (lp = lstflds; lp < &lstflds[nlstflds]; lp++) {
  1168. X        (void) flog_delete (*lp);
  1169. X        *lp = 0;
  1170. X    }
  1171. X
  1172. X    for (i = 0; i < nlstflds; i++)
  1173. X        XtUnmanageChild (table_w[i]);
  1174. X
  1175. X    nlstflds = 0;
  1176. }
  1177. X
  1178. /* stop selecting: tell everybody else to drop their buttons, make sure toggle
  1179. X * is off.
  1180. X */
  1181. static
  1182. lst_stop_selecting()
  1183. {
  1184. X    XmToggleButtonGadgetSetState (select_w, False, False);
  1185. X    lst_select(0);
  1186. X    f_string (prompt_w, "");
  1187. }
  1188. X
  1189. static
  1190. lst_turn_off ()
  1191. {
  1192. X    if (lst_fp) {
  1193. X        (void) fclose (lst_fp);
  1194. X        lst_fp = 0;
  1195. X    }
  1196. }
  1197. X
  1198. /* called from the query routine when want to append to an existing list file.*/
  1199. static void
  1200. lst_try_append()
  1201. {
  1202. X    lst_turn_on("a");
  1203. }
  1204. X
  1205. /* called from the query routine when want to overwrite to an existing list
  1206. X * file.
  1207. X */
  1208. static void
  1209. lst_try_overwrite()
  1210. {
  1211. X    lst_turn_on("w");
  1212. }
  1213. X
  1214. /* called from the query routine when decided not to make a listing file.  */
  1215. static void
  1216. lst_try_cancel()
  1217. {
  1218. X    XmToggleButtonGadgetSetState (active_w, False, False);
  1219. }
  1220. X
  1221. /* attempt to open file for use as a listing file.
  1222. X * if it doesn't exist, then go ahead and make it.
  1223. X * but if it does, first ask wheher to append or overwrite.
  1224. X */
  1225. static
  1226. lst_try_turn_on()
  1227. {
  1228. X    char *txt = XmTextGetString (filename_w);
  1229. X    if (access (txt, 0) == 0) {
  1230. X        char *buf;
  1231. X        buf = XtMalloc (strlen(txt)+100);
  1232. X        (void) sprintf (buf, "%s exists: Append or Overwrite?", txt);
  1233. X        query (toplevel_w, buf, "Append", "Overwrite", "Cancel",
  1234. X                lst_try_append, lst_try_overwrite, lst_try_cancel);
  1235. X        XtFree (buf);
  1236. X    } else
  1237. X        lst_turn_on("w");
  1238. X    XtFree (txt);
  1239. }
  1240. X
  1241. /* turn on listing facility.
  1242. X * establish a file to use (and thereby set lst_fp, the "listing-is-on" flag).
  1243. X */
  1244. static
  1245. lst_turn_on (how)
  1246. char *how;    /* fopen how argument */
  1247. {
  1248. X    char *txt;
  1249. X
  1250. X    /* listing is on if file opens ok */
  1251. X    txt = XmTextGetString (filename_w);
  1252. X    lst_fp = fopen (txt, how);
  1253. X    if (!lst_fp) {
  1254. X        char *buf;
  1255. X        XmToggleButtonGadgetSetState (active_w, False, False);
  1256. X        buf = XtMalloc (strlen(txt)+100);
  1257. X        (void) sprintf (buf, "can not open %s: %s", txt, errsys);
  1258. X        f_msg (buf, 0);
  1259. X        XtFree (buf);
  1260. X    }
  1261. X    XtFree (txt);
  1262. X    
  1263. X    if (lst_fp) {
  1264. X        /* add a title if desired */
  1265. X        txt = XmTextGetString (title_w);
  1266. X        if (txt[0] != '\0')
  1267. X        (void) fprintf (lst_fp, "* %s\n", txt);
  1268. X        XtFree (txt);
  1269. X    }
  1270. }
  1271. SHAR_EOF
  1272. chmod 0644 listing.c ||
  1273. echo 'restore of listing.c failed'
  1274. Wc_c="`wc -c < 'listing.c'`"
  1275. test 13788 -eq "$Wc_c" ||
  1276.     echo 'listing.c: original size 13788, current size' "$Wc_c"
  1277. rm -f _shar_wnt_.tmp
  1278. fi
  1279. # ============= mainmenu.c ==============
  1280. if test -f 'mainmenu.c' -a X"$1" != X"-c"; then
  1281.     echo 'x - skipping mainmenu.c (File already exists)'
  1282.     rm -f _shar_wnt_.tmp
  1283. else
  1284. > _shar_wnt_.tmp
  1285. echo 'x - extracting mainmenu.c (Text)'
  1286. sed 's/^X//' << 'SHAR_EOF' > 'mainmenu.c' &&
  1287. /* code to manage the stuff on the (permanent) top half of the main menu.
  1288. X * this is also where the single static Now struct is maintained.
  1289. X */
  1290. X
  1291. #include <stdio.h>
  1292. #include <ctype.h>
  1293. #include <math.h>
  1294. #ifdef VMS
  1295. #include <stdlib.h>
  1296. #endif
  1297. #include <X11/Xlib.h>
  1298. #include <Xm/Xm.h>
  1299. #include <Xm/Form.h>
  1300. #include <Xm/Label.h>
  1301. #include <Xm/PushB.h>
  1302. #include <Xm/Separator.h>
  1303. #include <Xm/SelectioB.h>
  1304. #include "fieldmap.h"
  1305. #include "astro.h"
  1306. #include "circum.h"
  1307. #include "moreobjs.h"
  1308. X
  1309. extern char *strncpy();
  1310. extern char *getenv();
  1311. extern Widget toplevel_w;
  1312. extern XtAppContext xe_app;
  1313. #define    XtD    XtDisplay(toplevel_w)
  1314. X
  1315. /* shorthands for fields of a Now structure, now.
  1316. X * first undo the ones for a Now pointer from circum.h.
  1317. X */
  1318. #undef mjd
  1319. #undef lat
  1320. #undef lng
  1321. #undef tz
  1322. #undef temp
  1323. #undef pressure
  1324. #undef height
  1325. #undef epoch
  1326. #undef tznm
  1327. X
  1328. #define mjd    now.n_mjd
  1329. #define lat    now.n_lat
  1330. #define lng    now.n_lng
  1331. #define tz    now.n_tz
  1332. #define temp    now.n_temp
  1333. #define pressure now.n_pressure
  1334. #define height    now.n_height
  1335. #define epoch    now.n_epoch
  1336. #define tznm    now.n_tznm
  1337. X
  1338. /* Name of each object.
  1339. X * N.B. index must match the object name #define (in astro.h)
  1340. X */
  1341. char *objname[] = {
  1342. X    "Me", "Ve", "Ma", "Ju", "Sa", "Ur", "Ne", "Pl", "Su", "Mo", "X", "Y"
  1343. };
  1344. X
  1345. static char *cfgfile;        /* !0 if -c used */
  1346. static char cfgdef[] = "ephem.cfg"; /* default configuration file name */
  1347. static Now now;        /* where when and how, right now */
  1348. static double tminc;    /* hrs to inc time by each loop; RTC means use clock */
  1349. static int nstep;    /* steps to go before stopping */
  1350. static int spause;    /* secs to pause between steps */
  1351. static int newcir = 1; /* set when circumstances change - means don't tminc */
  1352. static int oppl;    /* mask of (1<<planet) bits; set when want to show it */
  1353. X
  1354. static XtIntervalId mm_interval_id;    /* set while waiting in a pause loop */
  1355. static int mm_selecting;        /* set while our fields are being selected */
  1356. X
  1357. /* locations of each field.
  1358. X * these are in terms of a 1-based row/col on a 24x80 alpha screen, for
  1359. X * historical reasons.
  1360. X */
  1361. #define    NR    9
  1362. #define    NC    82
  1363. X
  1364. #define    COL1        1
  1365. #define    COL2        26
  1366. #define    COL3        44
  1367. #define    COL4        62    /* calendar */
  1368. X
  1369. #define    R_STATUS    1
  1370. #define    R_TOP        2    /* first row of top menu items */
  1371. X
  1372. /* we use FieldMap.width to mean anchor the left side at xpos(id) if 0,
  1373. X * else anchor the right
  1374. X */
  1375. #define    LS    0
  1376. #define    RS    1
  1377. X
  1378. #define    R_TZN    (R_TOP+0)
  1379. #define    C_TZN    COL1
  1380. #define    R_LT    R_TZN
  1381. #define    C_LT    (C_TZN+5)
  1382. #define    R_LD    R_TZN
  1383. #define    C_LD    (COL2-1)
  1384. X
  1385. #define    R_UT    (R_TOP+1)
  1386. #define    C_UT    COL1
  1387. #define    C_UTV    (C_UT+5)
  1388. #define    R_UD    R_UT
  1389. #define    C_UD    (COL2-1)
  1390. X
  1391. #define    R_JD    (R_TOP+2)
  1392. #define    C_JD    COL1
  1393. #define    C_JDV    (COL2-1)
  1394. X
  1395. #define    R_LST    (R_TOP)
  1396. #define    C_LST    (COL2+1)
  1397. #define    C_LSTV    (COL3-1)
  1398. X
  1399. #define    R_DAWN    (R_TOP+2)
  1400. #define    C_DAWN    (COL2+1)
  1401. #define    C_DAWNV    (COL3-1)
  1402. X
  1403. #define    R_DUSK    (R_TOP+3)
  1404. #define    C_DUSK    (COL2+1)
  1405. #define    C_DUSKV    (COL3-1)
  1406. X
  1407. #define    R_LON    (R_TOP+4)
  1408. #define    C_LON    (COL2+1)
  1409. #define    C_LONV    (COL3-1)
  1410. X
  1411. #define    R_NSTEP (R_TOP+6)
  1412. #define    C_NSTEP    (COL2+1)
  1413. #define    C_NSTEPV (COL3-1)
  1414. X
  1415. #define    R_STPSZ    (R_TOP+7)
  1416. #define    C_STPSZ    (COL2+1)
  1417. #define    C_STPSZV (COL3-1)
  1418. X
  1419. #define    R_LAT    (R_TOP+0)
  1420. #define    C_LAT    (COL3+1)
  1421. #define    C_LATV    (COL4-1)
  1422. X
  1423. #define    R_LONG    (R_TOP+1)
  1424. #define    C_LONG    (COL3+1)
  1425. #define    C_LONGV    (COL4-1)
  1426. X
  1427. #define    R_HEIGHT (R_TOP+2)
  1428. #define    C_HEIGHT (COL3+1)
  1429. #define    C_HEIGHTV (COL4-1)
  1430. X
  1431. #define    R_TEMP    (R_TOP+3)
  1432. #define    C_TEMP    (COL3+1)
  1433. #define    C_TEMPV    (COL4-1)
  1434. X
  1435. #define    R_PRES    (R_TOP+4)
  1436. #define    C_PRES    (COL3+1)
  1437. #define    C_PRESV    (COL4-1)
  1438. X
  1439. #define    R_TZONE    (R_TOP+5)
  1440. #define    C_TZONE    (COL3+1)
  1441. #define    C_TZONEV (COL4-1)
  1442. X
  1443. #define    R_EPOCH    (R_TOP+6)
  1444. #define    C_EPOCH    (COL3+1)
  1445. #define    C_EPOCHV (COL4-1)
  1446. X
  1447. #define    R_PAUSE (R_TOP+7)
  1448. #define    C_PAUSE    (COL3+1)
  1449. #define    C_PAUSEV (COL4-1)
  1450. X
  1451. #define    R_CAL    R_TOP
  1452. #define    C_CAL   (COL4+1)
  1453. X
  1454. #define    R_NEWCIR (R_TOP+4)
  1455. #define    C_NEWCIR COL1
  1456. X
  1457. #define    R_GO    (R_TOP+6)
  1458. X
  1459. static FieldMap mm_field_map[] = {
  1460. X    {mkid(R_TZN,C_TZN),    CHG, LS, "timezone abbreviation (3 char max): "},
  1461. X    {mkid(R_LT,C_LT), CHG|PLT, LS, "local time (h:m:s, or n for Now): ", "LT"},
  1462. X    {mkid(R_LD,C_LD), CHG|PLT, RS,"local date (m/d/y, or year.d, n for Now): ",
  1463. X                                    "LD"},
  1464. X    {mkid(R_UT,C_UT), 0, LS, "UTC"},
  1465. X    {mkid(R_UT,C_UTV), CHG|PLT,    LS, "utc time (h:m:s, or n for Now): ", "UT"},
  1466. X    {mkid(R_UD,C_UD), CHG|PLT,RS,"utc date (m/d/y, or year.d, or n for Now): ",
  1467. X                                    "UD"},
  1468. X    {mkid(R_JD,C_JD), 0, LS, "JulianDat"},
  1469. X    {mkid(R_JD,C_JDV), CHG|PLT,    RS, "Julian Date (or n for Now): ", "JD"},
  1470. X    {mkid(R_LST,C_LST),    0, LS, "LST"},
  1471. X    {mkid(R_LST,C_LSTV),CHG|PLT,RS,"local sidereal time (h:m:s or n for Now): ",
  1472. X                                    "LST"},
  1473. X    {mkid(R_DAWN,C_DAWN), 0, LS, "Dawn"},
  1474. X    {mkid(R_DAWN,C_DAWNV), PLT, RS, "", "Dawn"},
  1475. X    {mkid(R_DUSK,C_DUSK), 0, LS, "Dusk"},
  1476. X    {mkid(R_DUSK,C_DUSKV), PLT, RS, "", "Dusk"},
  1477. X    {mkid(R_LON,C_LON),    0, LS, "NiteLn"},
  1478. X    {mkid(R_LON,C_LONV), PLT, RS, "", "NiteLen"},
  1479. X    {mkid(R_NSTEP,C_NSTEP), 0, LS, "NStep"},
  1480. X    {mkid(R_NSTEP,C_NSTEPV), CHG, RS, "number of steps to run: "},
  1481. X    {mkid(R_STPSZ,C_STPSZ), 0,LS, "StpSz"},
  1482. X    {mkid(R_STPSZ,C_STPSZV), CHG, RS, "\
  1483. step size increment:\n\
  1484. X    h:m:s, or\n\
  1485. X    <x>d for x days, or\n\
  1486. X    <x>s for x sidereal days, or\n\
  1487. X    r for RTC"},
  1488. X    {mkid(R_LAT,C_LAT),    0, LS, "Lat"},
  1489. X    {mkid(R_LAT,C_LATV), CHG|PLT, RS, "latitude (+ north) (d:m:s): ", "Lat"},
  1490. X    {mkid(R_LONG,C_LONG), 0, LS, "Long"},
  1491. X    {mkid(R_LONG,C_LONGV), CHG|PLT, RS, "longitude (+ west) (d:m:s): ", "Long"},
  1492. X    {mkid(R_HEIGHT,C_HEIGHT), 0, LS, "Elev"},
  1493. X    {mkid(R_HEIGHT,C_HEIGHTV), CHG|PLT,    RS, "height above sea level (ft): ",
  1494. X                                    "Elev"},
  1495. X    {mkid(R_TEMP,C_TEMP), 0, LS, "Temp"},
  1496. X    {mkid(R_TEMP,C_TEMPV), CHG|PLT, RS, "temperature (deg.F): ", "Temp"},
  1497. X    {mkid(R_PRES,C_PRES), 0, LS, "AtmPr"},
  1498. X    {mkid(R_PRES,C_PRESV), CHG|PLT, RS,
  1499. X    "atmos pressure (in. Hg; 0 for no refraction correction): ", "AtmPr"},
  1500. X    {mkid(R_TZONE,C_TZONE), 0, LS, "TZ"},
  1501. X    {mkid(R_TZONE,C_TZONEV), CHG|PLT, RS, "hours behind utc: ", "TZ"},
  1502. X    {mkid(R_EPOCH,C_EPOCH), 0, LS, "Epoch"},
  1503. X    {mkid(R_EPOCH,C_EPOCHV), CHG,RS,"epoch (year, or e for Epoch of Date): "},
  1504. X    {mkid(R_PAUSE,C_PAUSE), 0, LS, "Pause"},
  1505. X    {mkid(R_PAUSE,C_PAUSEV), CHG,RS, "seconds to pause between steps: "},
  1506. };
  1507. #define    NFM    (sizeof(mm_field_map)/sizeof(mm_field_map[0]))
  1508. #define    LFM    (&mm_field_map[NFM])
  1509. #define    fw(r,c)    (fm(r,c)->w)
  1510. X
  1511. #define    CAL_ROWS    8
  1512. #define    CAL_COLS    20
  1513. static Widget cal_w[CAL_ROWS];
  1514. static Widget newcir_w;
  1515. static Widget status_w;
  1516. static Widget go_w;
  1517. X
  1518. static FieldMap *
  1519. fm(r,c)
  1520. int r, c;
  1521. {
  1522. X    FieldMap *fp;
  1523. X    int id = mkid(r,c);
  1524. X
  1525. X    for (fp = mm_field_map; fp < LFM; fp++)
  1526. X        if (fp->id == id)
  1527. X        return (fp);
  1528. X    printf ("fm: can't find id 0x%x (%d,%d)\n", id, r, c);
  1529. X    exit (1);
  1530. X    return(0);    /* for lint */
  1531. }
  1532. X
  1533. /* method by which another module can access our field map.
  1534. X * this is used by the search compiler.
  1535. X */
  1536. mm_getfieldmap (fmpp)
  1537. FieldMap **fmpp;
  1538. {
  1539. X    *fmpp = mm_field_map;
  1540. X    return (NFM);
  1541. }
  1542. X
  1543. /* called exactly once when the main form is made.
  1544. X * create and manage all the widgets in the top half as children of the form_w.
  1545. X */
  1546. mm_manage (main_window, argc, argv)
  1547. Widget main_window;
  1548. int argc;
  1549. char *argv[];
  1550. {
  1551. X    void mm_activate_cb(), mm_go_cb();
  1552. X    Widget form_w;
  1553. X    FieldMap *fp;
  1554. X    XmString str;
  1555. X    Arg args[20];
  1556. X    int i, n;
  1557. X
  1558. X    /* create form */
  1559. X    n = 0;
  1560. X    XtSetArg (args[n], XmNshowSeparator, True);  n++;
  1561. X    XtSetArg (args[n], XmNfractionBase, 1000); n++;
  1562. X    XtSetArg (args[n], XmNallowOverlap, False); n++;
  1563. X    XtSetArg (args[n], XmNwidth, char_width()*NC); n++;
  1564. X    XtSetArg (args[n], XmNheight, char_height()*NR); n++;
  1565. X    form_w = XmCreateForm (main_window, "MainForm", args, n);
  1566. X
  1567. X    /* establish the buttons and labels */
  1568. X    for (fp = mm_field_map; fp < LFM; fp++) {
  1569. X        n = 0;
  1570. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1571. X        XtSetArg (args[n], XmNtopPosition, ypos(fp->id)); n++;
  1572. X        if (fp->width == LS) {
  1573. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1574. X        XtSetArg (args[n], XmNleftPosition, xpos(fp->id)); n++;
  1575. X        } else {
  1576. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  1577. X        XtSetArg (args[n], XmNrightPosition, xpos(fp->id)); n++;
  1578. X        }
  1579. X        if (fp->how) {
  1580. X        /* pushbutton */
  1581. X        XtSetArg (args[n], XmNalignment, XmALIGNMENT_END); n++;
  1582. X        fp->w = XtCreateManagedWidget ("MainButton",
  1583. X                    xmPushButtonWidgetClass, form_w, args, n);
  1584. X        XtAddCallback (fp->w, XmNactivateCallback, mm_activate_cb, fp);
  1585. X        } else {
  1586. X        /* label */
  1587. X        str = XmStringCreate(fp->prompt, XmSTRING_DEFAULT_CHARSET);
  1588. X        XtSetArg (args[n], XmNlabelString, str); n++;
  1589. X        fp->w = XtCreateManagedWidget ("MainLabel",
  1590. X                    xmLabelWidgetClass, form_w, args, n);
  1591. X        XmStringFree(str);
  1592. X        }
  1593. X    }
  1594. X
  1595. X    /* establish the "NEW CIRCUMSTANCES" label */
  1596. X    n = 0;
  1597. X    XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1598. X    XtSetArg (args[n], XmNtopPosition, r2ypos(R_NEWCIR)); n++;
  1599. X    XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1600. X    XtSetArg (args[n], XmNleftPosition, c2xpos(COL1)); n++;
  1601. X    XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  1602. X    XtSetArg (args[n], XmNrightPosition, c2xpos(COL2-1)); n++;
  1603. X    newcir_w = XtCreateManagedWidget ("NewCir",
  1604. X                xmLabelWidgetClass, form_w, args, n);
  1605. X
  1606. X    /* establish the main "go" button */
  1607. X    n = 0;
  1608. X    XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1609. X    XtSetArg (args[n], XmNtopPosition, r2ypos(R_GO)); n++;
  1610. X    XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1611. X    XtSetArg (args[n], XmNleftPosition, c2xpos(COL1)); n++;
  1612. X    XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  1613. X    XtSetArg (args[n], XmNrightPosition, c2xpos(COL2-1)); n++;
  1614. X    XtSetArg (args[n], XmNshowAsDefault, True); n++;
  1615. X    go_w = XmCreatePushButton (form_w, "Update", args, n);
  1616. X    XtAddCallback (go_w, XmNactivateCallback, mm_go_cb, 0);
  1617. X    XtManageChild (go_w);
  1618. X    /*
  1619. X    set_something (form_w, XmNdefaultButton, go_w);
  1620. X    */
  1621. X
  1622. X    /* establish the status label */
  1623. X    n = 0;
  1624. X    XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1625. X    XtSetArg (args[n], XmNtopPosition, r2ypos(R_STATUS)); n++;
  1626. X    XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1627. X    XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1628. X    XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  1629. X    XtSetArg (args[n], XmNrecomputeSize, False); n++;
  1630. X    status_w = XtCreateManagedWidget ("Status",
  1631. X                xmLabelWidgetClass, form_w, args, n);
  1632. X
  1633. X    /* establish the separator widgets */
  1634. X    n = 0;
  1635. X    XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  1636. X    XtSetArg (args[n], XmNtopWidget, status_w); n++;
  1637. X    XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  1638. X    XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1639. X    XtSetArg (args[n], XmNleftPosition, c2xpos(COL2)); n++;
  1640. X    XtSetArg (args[n], XmNorientation, XmVERTICAL); n++;
  1641. X    (void) XtCreateManagedWidget ("MainCol1",
  1642. X                    xmSeparatorWidgetClass, form_w, args, n);
  1643. X
  1644. X    n = 0;
  1645. X    XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  1646. X    XtSetArg (args[n], XmNtopWidget, status_w); n++;
  1647. X    XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  1648. X    XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1649. X    XtSetArg (args[n], XmNleftPosition, c2xpos(COL3)); n++;
  1650. X    XtSetArg (args[n], XmNorientation, XmVERTICAL); n++;
  1651. X    (void) XtCreateManagedWidget ("MainCol2",
  1652. X                    xmSeparatorWidgetClass, form_w, args, n);
  1653. X
  1654. X    n = 0;
  1655. X    XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  1656. X    XtSetArg (args[n], XmNtopWidget, status_w); n++;
  1657. X    XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  1658. X    XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1659. X    XtSetArg (args[n], XmNleftPosition, c2xpos(COL4)); n++;
  1660. X    XtSetArg (args[n], XmNorientation, XmVERTICAL); n++;
  1661. X    (void) XtCreateManagedWidget ("MainCol3",
  1662. X                    xmSeparatorWidgetClass, form_w, args, n);
  1663. X
  1664. X    /* establish the labels used for the calendar */
  1665. X    for (i = 0; i < CAL_ROWS; i++) {
  1666. X        n = 0;
  1667. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1668. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_CAL+i)); n++;
  1669. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1670. X        XtSetArg (args[n], XmNleftPosition, c2xpos(C_CAL)); n++;
  1671. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  1672. X        XtSetArg (args[n], XmNrightPosition, c2xpos(NC)); n++;
  1673. X        cal_w[i] = XtCreateManagedWidget ("Calendar",
  1674. X                xmLabelWidgetClass, form_w, args, n);
  1675. X    }
  1676. X
  1677. X    mm_crackargs(&argc, &argv);
  1678. X    mm_readcfg();
  1679. X    read_fieldargs (argc, argv);
  1680. X
  1681. X    /* can now set which objects are to be on in each of the menus. */
  1682. X    dm_set_objs_on (oppl);
  1683. X    rm_set_objs_on (oppl);
  1684. X    sm_set_objs_on (oppl);
  1685. X    ss_set_objs_on (oppl);
  1686. X    aa_set_objs_on (oppl);
  1687. X    sd_set_objs_on (oppl);
  1688. X
  1689. X    redraw_screen (1);
  1690. X    mm_newcir(0);
  1691. X    mm_set_buttons (mm_selecting);
  1692. X    print_idle();
  1693. X
  1694. X    XtManageChild (form_w);
  1695. }
  1696. X
  1697. mm_crackargs (ac, av)
  1698. int *ac;
  1699. char **av[];
  1700. {
  1701. X    while ((--*ac > 0) && (**++*av == '-')) {
  1702. X        char *s;
  1703. X        for (s = **av+1; *s != '\0'; s++)
  1704. X        switch (*s) {
  1705. X        case 'c': /* set name of config file to use */
  1706. X            if (--*ac <= 0) usage("-c but no config file");
  1707. X            cfgfile = *++*av;
  1708. X            break;
  1709. X        case 'd': /* set alternate database file name */
  1710. SHAR_EOF
  1711. true || echo 'restore of mainmenu.c failed'
  1712. fi
  1713. echo 'End of  part 4'
  1714. echo 'File mainmenu.c is continued in part 5'
  1715. echo 5 > _shar_seq_.tmp
  1716. exit 0
  1717. -- 
  1718. --
  1719. Molecular Simulations, Inc.            mail: dcmartin@msi.com
  1720. 796 N. Pastoria Avenue                uucp: uunet!dcmartin
  1721. Sunnyvale, California 94086            at&t: 408/522-9236
  1722.