Version 1.28 Debian patches in upstream
[dockapps.git] / wmmoonclock / src / wmMoonClock.c
blob87861e67a41bab72fafb4b4129850d51931bc9ec
1 /*
3 * wmMoonClock-1.26 (C) 1998, 1999 Mike Henderson (mghenderson@lanl.gov)
4 *
5 * - Shows Moon Phase....
6 *
7 *
8 *
9 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program (see the file COPYING); if not, write to the
23 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA
26 * Things TODO:
27 * - clean up code!
28 * - more detailed documentation.
29 * - reduce size of pixmap! Dont need it in one pixmap.
30 * Aslo, does the hi-color pixmap really need all those colors?
31 * - add rotation of moon so user sees it as they would in reality?
32 * - eclipses. The calcs are quite acurate so this should be easily doable.
33 * (Note the Sun position calcs in CalcEphem are low precision -- high is not
34 * as costly as the Moon calcs.) Sun posiiton is calculated but not used yet...
35 * - Next new moons, next full moons, next quarters, etc...
36 * - Moon names. I.e. Harvest, Blue, etc...
40 * Changes:
41 * Version 1.27 - released June 7, 1999.
42 * fixed a minor bug in computation of azimuth (A in Horizon Coords). Thanks to
43 * Dan Moraru for spotting this one. (There were two SinGlat factors instead of one).
45 * Version 1.26 - released April 22, 1999 (?).
46 * Version 1.25 - released March 22, 1999.
47 * Now auto-detects 8-bit display and forces the LowColor pixmap to
48 * be used. The -low option still works if you need to conserve colors
49 * even on high-color displays.
51 * Added 3 command line options + code to change colors of the data
52 * entries:
54 * -bc <Color> to change background color.
55 * -lc <Color> to change color of labels and headers.
56 * -dc <Color> to change color of data values.
58 * Version 1.24 - released February 9, 1999.
59 * Added low color support via the -low command line option.
61 * Version 1.23 - released February 4, 1999.
62 * cosmetic for AfterStep users. removed spurious black line at RHS edge an mask.
64 * Version 1.22 - released January 8, 1999.
66 * + Changed PI2 to TwoPi in Moon.c -- Linux Pyth. had probs because
67 * PI2 was defined in <math.h>.
69 * Version 1.21 - released January 7, 1999.
71 * + minor bug fixes in Makefile and manpage.
73 * Version 1.2 - released January 3, 1999.
74 * Added:
76 * + Local Time/ Universal Time display.
77 * + Visible: Yes/No to indicate if Moon is up or not.
78 * + Frac (percent through orbit -- this is NOT a simple
79 * conversion of AGE....).
80 * + Horizon Coords. Altitude is measured up from horizon to
81 * Moon in degrees. Azimuth is in degrees from due south.
83 * Also shuffled things around a bit...
87 * Version 1.1 - released December 24, 1998.
88 * Fixed bug in AGE calculation. It now should be highly accurate.
89 * Note that AGE is not the same as Phase*29.530589 ...
90 * I have checked with the Astronomical Almanac and it agrees very
91 * well....
94 * Version 1.0 - released December 16, 1998.
105 * Includes
107 #include <stdio.h>
108 #include <unistd.h>
109 #include <stdlib.h>
110 #include <string.h>
111 #include <time.h>
112 #include <X11/X.h>
113 #include <X11/xpm.h>
114 #include "CalcEphem.h"
115 #include "MoonRise.h"
116 #include "xutils.h"
117 #include "wmMoonClock_master.xpm"
118 #include "wmMoonClock_masterLow.xpm"
119 #include "wmMoonClock_mask.xbm"
124 * Delay between refreshes (in microseconds)
126 #define DELAY 1000000L
127 #define WMMOONCLOCK_VERSION "1.27"
133 void ParseCMDLine(int argc, char *argv[]);
134 void pressEvent(XButtonEvent *xev);
135 void print_usage();
138 int ToggleWindow = 0;
139 int nMAX = 1;
140 int Flag = 1;
141 double Glat, Glon, SinGlat, CosGlat, TimeZone;
142 int UseLowColorPixmap = 0;
143 char LabelColor[30] = "#a171ff";
144 char DataColor[30] = "#3dafff";
145 char BackColor[30] = "#010101";
153 * main
155 int main(int argc, char *argv[]) {
161 struct tm *GMTTime, *LocalTime;
162 XEvent event;
163 int i, n, j, ImageNumber, Year, Month, DayOfMonth, digit;
164 long CurrentLocalTime, CurrentGMTTime, date;
165 double UT, val, RA, DEC, UTRise, UTSet, LocalHour, hour24();
166 int D, H, M, S, sgn, A, B, q;
167 CTrans c;
168 struct timeval timeout;
169 fd_set xfdset;
177 * Parse any command line arguments.
179 Glat = Glon = 0.0;
180 ParseCMDLine(argc, argv);
181 c.Glat = Glat, c.Glon = Glon;
182 Glat *= RadPerDeg; SinGlat = sin( Glat ); CosGlat = cos( Glat );
186 initXwindow(argc, argv);
187 if ((DisplayDepth <= 8)||UseLowColorPixmap)
188 openXwindow(argc, argv, wmMoonClock_masterLow, wmMoonClock_mask_bits, wmMoonClock_mask_width, wmMoonClock_mask_height, BackColor, LabelColor, DataColor);
189 else
190 openXwindow(argc, argv, wmMoonClock_master, wmMoonClock_mask_bits, wmMoonClock_mask_width, wmMoonClock_mask_height, BackColor, LabelColor, DataColor);
197 * Loop until we die
199 n = 32000;
200 while(1) {
203 if (Flag) {
204 n = 32000;
205 Flag = 0;
212 * The Moon Ephemeris calculations are somewhat costly (the Moon is one of the most
213 * difficult objects to compute position for). So only process every nMAXth cycle of this
214 * loop. We run outer loop it faster to catch expose events, button presses, etc...
217 if (n>nMAX){
219 n = 0;
221 CurrentGMTTime = time(CurrentTime); GMTTime = gmtime(&CurrentGMTTime);
222 UT = GMTTime->tm_hour + GMTTime->tm_min/60.0 + GMTTime->tm_sec/3600.0;
223 Year = GMTTime->tm_year+1900;
224 Month = GMTTime->tm_mon+1;
225 DayOfMonth = GMTTime->tm_mday;
226 date = Year*10000 + Month*100 + DayOfMonth;
227 CurrentLocalTime = CurrentGMTTime; LocalTime = localtime(&CurrentLocalTime);
228 LocalHour = LocalTime->tm_hour + LocalTime->tm_min/60.0 + LocalTime->tm_sec/3600.0;
229 TimeZone = UT - LocalHour;
232 CalcEphem(date, UT, &c);
238 if (ToggleWindow == 0){
241 * Update Moon Image
244 nMAX = 1000;
245 ImageNumber = (int)(c.MoonPhase * 60.0 + 0.5);
246 if (ImageNumber > 59) ImageNumber = 0;
247 if (Glat < 0) ImageNumber = 59 - ImageNumber; /* add southern hemisphere support, closes: #537480 */
248 j = ImageNumber/10;
249 i = ImageNumber%10;
250 copyXPMArea(67+58*i, 2+58*j, 54, 54, 5, 5);
252 } else if (ToggleWindow == 1){
255 * Update Numerical Display
258 /* This requires second precision for LT and UT */
259 nMAX = 0;
263 * Clear plotting area
265 copyXPMArea(4, 69, 56, 56, 4, 4);
270 * Paste up LT and UT.
272 val = LocalHour;
273 H = (int)val; val = (val - H)*60.0;
274 M = (int)val; val = (val - M)*60.0;
275 S = (int)val;
276 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 25, 6);
277 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 25+5, 6);
278 copyXPMArea(117, 353, 1, 6, 25+10, 6);
279 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 25+12, 6);
280 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 25+17, 6);
282 val = UT;
283 H = (int)val; val = (val - H)*60.0;
284 M = (int)val; val = (val - M)*60.0;
285 S = (int)val;
286 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 25, 15);
287 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 25+5, 15);
288 copyXPMArea(117, 353, 1, 6, 25+10, 15);
289 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 25+12, 15);
290 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 25+17, 15);
297 * Paste up AGE.
299 val = c.MoonAge;
300 q = (val < 10.0) ? 5 : 0;
301 A = (int)val;
302 val = (val - A)*100.0;
303 B = (int)val;
304 digit = A/10; if (digit != 0) copyXPMArea(67+digit*5, 353, 5, 7, 26-q, 24);
305 digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 26+5-q, 24);
306 copyXPMArea(62, 357, 3, 3, 26+11-q, 28);
307 digit = B/10; copyXPMArea(67+digit*5, 353, 5, 7, 26+15-q, 24);
308 digit = B%10; copyXPMArea(67+digit*5, 353, 5, 7, 26+20-q, 24);
309 copyXPMArea(143, 354, 3, 3, 26+25-q, 23);
315 * Paste up Phase (Percent Illuminated).
317 val = 0.5*( 1.0 - cos(c.MoonPhase*6.2831853) );
318 val *= 100.0;
319 A = (int)(val+0.5);
320 if (A == 100){
321 copyXPMArea(72, 353, 5, 7, 32+5, 42);
322 copyXPMArea(67, 353, 5, 7, 32+10, 42);
323 copyXPMArea(67, 353, 5, 7, 32+15, 42);
324 copyXPMArea(147, 353, 5, 7, 32+20, 42);
325 } else if (A >= 10){
326 digit = A/10; copyXPMArea(67+digit*5, 353, 5, 7, 32+5, 42);
327 digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 32+10, 42);
328 copyXPMArea(147, 353, 5, 7, 32+15, 42);
329 } else {
330 digit = A; copyXPMArea(67+digit*5, 353, 5, 7, 32+5, 42);
331 copyXPMArea(147, 353, 5, 7, 32+10, 42);
338 * Paste up Frac (Percent of way through current lunar cycle).
340 val = c.MoonPhase*100.0;
341 A = (int)(val+0.5);
342 if (A == 100){
343 copyXPMArea(72, 353, 5, 7, 27+5, 33);
344 copyXPMArea(67, 353, 5, 7, 27+10, 33);
345 copyXPMArea(67, 353, 5, 7, 27+15, 33);
346 copyXPMArea(147, 353, 5, 7, 27+20, 33);
347 } else if (A >= 10){
348 digit = A/10; copyXPMArea(67+digit*5, 353, 5, 7, 27+5, 33);
349 digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 27+10, 33);
350 copyXPMArea(147, 353, 5, 7, 27+15, 33);
351 } else {
352 digit = A; copyXPMArea(67+digit*5, 353, 5, 7, 27+5, 33);
353 copyXPMArea(147, 353, 5, 7, 27+10, 33);
358 * Paste up Visible Status.
360 if (c.Visible)
361 copyXPMArea(6, 327, 13, 6, 46, 51);
362 else
363 copyXPMArea(26, 327, 9, 6, 46, 51);
368 } else if (ToggleWindow == 2){
371 * Plot up Moon Rise/Set Times
375 nMAX = 60;
378 * Clear plotting area
380 copyXPMArea(4, 134, 56, 56, 4, 4);
384 * Do Yesterday's first
386 MoonRise(Year, Month, DayOfMonth-1, LocalHour, &UTRise, &UTSet);
387 UTTohhmm(UTRise, &H, &M);
388 if (H >= 0){
389 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 7, 19);
390 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+5, 19);
391 copyXPMArea(117, 354, 1, 4, 7+10, 20);
392 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 7+12, 19);
393 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+17, 19);
394 } else {
395 copyXPMArea(57, 355, 5, 1, 7, 22); copyXPMArea(57, 355, 5, 1, 7+5, 22);
396 copyXPMArea(117, 354, 1, 4, 7+10, 20);
397 copyXPMArea(57, 355, 5, 1, 7+12, 22); copyXPMArea(57, 355, 5, 1, 7+17, 22);
399 UTTohhmm(UTSet, &H, &M);
400 if (H >= 0){
401 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 35, 19);
402 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+5, 19);
403 copyXPMArea(117, 354, 1, 4, 35+10, 20);
404 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 35+12, 19);
405 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+17, 19);
406 } else {
407 copyXPMArea(57, 355, 5, 1, 35, 22); copyXPMArea(57, 355, 5, 1, 35+5, 22);
408 copyXPMArea(117, 354, 1, 4, 35+10, 20);
409 copyXPMArea(57, 355, 5, 1, 35+12, 22); copyXPMArea(57, 355, 5, 1, 35+17, 22);
414 * Plot up todays Rise/Set times.
416 MoonRise(Year, Month, DayOfMonth, LocalHour, &UTRise, &UTSet);
417 UTTohhmm(UTRise, &H, &M);
418 if (H >= 0){
419 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 7, 29);
420 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+5, 29);
421 copyXPMArea(117, 354, 1, 4, 7+10, 30);
422 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 7+12, 29);
423 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+17, 29);
424 } else {
425 copyXPMArea(57, 355, 5, 1, 7, 32); copyXPMArea(57, 355, 5, 1, 7+5, 32);
426 copyXPMArea(117, 354, 1, 4, 7+10, 30);
427 copyXPMArea(57, 355, 5, 1, 7+12, 32); copyXPMArea(57, 355, 5, 1, 7+17, 32);
429 UTTohhmm(UTSet, &H, &M);
430 if (H >= 0){
431 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 35, 29);
432 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+5, 29);
433 copyXPMArea(117, 354, 1, 4, 35+10, 30);
434 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 35+12, 29);
435 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+17, 29);
436 } else {
437 copyXPMArea(57, 355, 5, 1, 35, 32); copyXPMArea(57, 355, 5, 1, 35+5, 32);
438 copyXPMArea(117, 354, 1, 4, 35+10, 30);
439 copyXPMArea(57, 355, 5, 1, 35+12, 32); copyXPMArea(57, 355, 5, 1, 35+17, 32);
445 * Plot up tomorrow's Rise/Set times.
447 MoonRise(Year, Month, DayOfMonth+1, LocalHour, &UTRise, &UTSet);
448 UTTohhmm(UTRise, &H, &M);
449 if (H >= 0){
450 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 7, 39);
451 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+5, 39);
452 copyXPMArea(117, 354, 1, 4, 7+10, 40);
453 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 7+12, 39);
454 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+17, 39);
455 } else {
456 copyXPMArea(57, 355, 5, 1, 7, 42); copyXPMArea(57, 355, 5, 1, 7+5, 42);
457 copyXPMArea(117, 354, 1, 4, 7+10, 40);
458 copyXPMArea(57, 355, 5, 1, 7+12, 42); copyXPMArea(57, 355, 5, 1, 7+17, 42);
460 UTTohhmm(UTSet, &H, &M);
461 if (H >= 0){
462 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 35, 39);
463 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+5, 39);
464 copyXPMArea(117, 354, 1, 4, 35+10, 40);
465 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 35+12, 39);
466 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+17, 39);
467 } else {
468 copyXPMArea(57, 355, 5, 1, 35, 42); copyXPMArea(57, 355, 5, 1, 35+5, 42);
469 copyXPMArea(117, 354, 1, 4, 35+10, 40);
470 copyXPMArea(57, 355, 5, 1, 35+12, 42); copyXPMArea(57, 355, 5, 1, 35+17, 42);
474 } else if (ToggleWindow == 3){
477 * Plot up Horizon Coords
482 nMAX = 3;
485 * Clear plotting area
487 copyXPMArea(4, 199, 56, 56, 4, 4);
492 * Paste up Azimuth, A
494 val = c.A_moon;
495 sgn = (val < 0.0) ? -1 : 0;
496 val = fabs(val);
497 D = (int)val;
498 val = (val-(double)D)*100.0;
499 M = (int)val;
501 if (sgn < 0) copyXPMArea(120, 357, 2, 1, 19, 27);
503 /* degrees 100's */
504 digit = D/100; copyXPMArea(67+digit*5, 353, 5, 7, 22, 24);
505 D -= digit*100;
507 /* degrees 10's */
508 digit = D/10; copyXPMArea(67+digit*5, 353, 5, 7, 22+5, 24);
510 /* degrees 1's */
511 digit = D%10; copyXPMArea(67+digit*5, 353, 5, 7, 22+10, 24);
513 /* Decimal */
514 copyXPMArea(62, 357, 3, 3, 22+15, 28);
516 /* Decimal Part */
517 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 22+19, 24);
519 /* mins 1's */
520 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 22+24, 24);
522 copyXPMArea(120, 353, 3, 3, 22+29, 23);
529 * Paste up Altitude, h
531 val = c.h_moon;
532 sgn = (val < 0.0) ? -1 : 0;
533 val = fabs(val);
534 D = (int)val;
535 val = (val-(double)D)*100.0;
536 M = (int)val;
538 if (sgn < 0) copyXPMArea(120, 357, 2, 1, 19, 39);
540 /* degrees 10's */
541 digit = D/10; copyXPMArea(67+digit*5, 353, 5, 7, 22, 36);
543 /* degrees 1's */
544 digit = D%10; copyXPMArea(67+digit*5, 353, 5, 7, 22+5, 36);
546 /* Decimal */
547 copyXPMArea(62, 357, 3, 3, 22+10, 40);
549 /* Decimal Part */
550 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 22+14, 36);
552 /* mins 1's */
553 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 22+19, 36);
555 copyXPMArea(120, 353, 3, 3, 22+24, 35);
562 * Paste up Earth-Moon Distance (in units of Earth radii).
564 val = c.EarthMoonDistance;
565 A = (int)val;
566 val = (val - A)*100.0;
567 B = (int)val;
568 digit = A/10; if (digit != 0) copyXPMArea(67+digit*5, 353, 5, 7, 30, 47);
569 digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 30+5, 47);
570 copyXPMArea(62, 357, 3, 3, 30+11, 51);
571 digit = B/10; copyXPMArea(67+digit*5, 353, 5, 7, 30+15, 47);
572 digit = B%10; copyXPMArea(67+digit*5, 353, 5, 7, 30+20, 47);
576 } else if (ToggleWindow == 4){
579 * Plot up RA/DEC Coords
584 nMAX = 3;
587 * Clear plotting area
589 copyXPMArea(4, 264, 56, 56, 4, 4);
594 * Paste up Right Ascention
596 RA = c.RA_moon/15.0;
597 H = (int)RA;
598 RA = (RA-(double)H)*60.0;
599 M = (int)RA; RA = (RA-(double)M)*60.0;
600 S = (int)(RA+0.5);
602 /* hours 10's */
603 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 17, 25);
605 /* hours 1's */
606 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+5, 25);
608 /* hour symbol */
609 copyXPMArea(138, 354, 3, 3, 17+10, 24);
611 /* mins 10's */
612 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 17+14, 25);
614 /* mins 1's */
615 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+19, 25);
617 /* min symbol */
618 copyXPMArea(124, 353, 3, 3, 17+23, 24);
620 /* secs 10's */
621 digit = S/10; copyXPMArea(67+digit*5, 353, 5, 7, 17+27, 25);
623 /* secs 1's */
624 digit = S%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+32, 25);
626 /* sec symbol */
627 copyXPMArea(128, 353, 5, 3, 17+36, 24);
633 * Paste up Declination
635 DEC = c.DEC_moon;
636 sgn = (DEC < 0.0) ? -1 : 0;
637 DEC = fabs(DEC);
638 D = (int)DEC;
639 DEC = (DEC-(double)D)*60.0;
640 M = (int)DEC;
641 DEC = (DEC-(double)M)*60.0;
642 S = (int)(DEC+0.5);
644 if (sgn < 0) copyXPMArea(120, 357, 2, 1, 14, 39);
647 /* degrees 10's */
648 digit = D/10; copyXPMArea(67+digit*5, 353, 5, 7, 17, 36);
650 /* degrees 1's */
651 digit = D%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+5, 36);
653 /* degree symbol */
654 copyXPMArea(120, 353, 3, 3, 17+10, 35);
656 /* mins 10's */
657 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 17+14, 36);
659 /* mins 1's */
660 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+19, 36);
662 /* min symbol */
663 copyXPMArea(124, 353, 3, 3, 17+23, 35);
665 /* secs 10's */
666 digit = S/10; copyXPMArea(67+digit*5, 353, 5, 7, 17+27, 36);
668 /* secs 1's */
669 digit = S%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+32, 36);
671 /* sec symbol */
672 copyXPMArea(128, 353, 5, 3, 17+36, 35);
678 * Paste up Earth-Moon Distance (in units of Earth radii).
680 val = c.EarthMoonDistance;
681 A = (int)val;
682 val = (val - A)*100.0;
683 B = (int)val;
684 digit = A/10; if (digit != 0) copyXPMArea(67+digit*5, 353, 5, 7, 30, 47);
685 digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 30+5, 47);
686 copyXPMArea(62, 357, 3, 3, 30+11, 51);
687 digit = B/10; copyXPMArea(67+digit*5, 353, 5, 7, 30+15, 47);
688 digit = B%10; copyXPMArea(67+digit*5, 353, 5, 7, 30+20, 47);
696 } else {
699 * Update the counter.
701 ++n;
710 * Add X display to file descriptor set for polling.
712 FD_ZERO(&xfdset);
713 FD_SET(ConnectionNumber(display), &xfdset);
718 * Process any pending X events.
720 while(XPending(display)){
721 XNextEvent(display, &event);
722 switch(event.type){
723 case Expose:
724 RedrawWindow();
725 break;
726 case ButtonPress:
727 pressEvent(&event.xbutton);
728 break;
729 case ButtonRelease:
730 break;
740 * Redraw and wait for next update
742 RedrawWindow();
743 timeout.tv_sec = DELAY / 1000000L;
744 timeout.tv_usec = DELAY % 1000000L;
745 select(ConnectionNumber(display) + 1, &xfdset, NULL, NULL, &timeout);
762 * ParseCMDLine()
764 void ParseCMDLine(int argc, char *argv[]) {
766 int i;
767 char *eptr;
769 for (i = 1; i < argc; i++) {
771 if (!strcmp(argv[i], "-display")){
773 ++i;
775 } else if (!strcmp(argv[i], "-bc")){
777 if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
778 fprintf(stderr, "wmMoonClock: -bc needs a color argument.\n");
779 print_usage();
780 exit(-1);
782 strcpy(BackColor, argv[++i]);
784 } else if (!strcmp(argv[i], "-lc")){
786 if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
787 fprintf(stderr, "wmMoonClock: -lc needs a color argument.\n");
788 print_usage();
789 exit(-1);
791 strcpy(LabelColor, argv[++i]);
793 } else if (!strcmp(argv[i], "-dc")){
795 if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
796 fprintf(stderr, "wmMoonClock: -dc needs a color argument.\n");
797 print_usage();
798 exit(-1);
800 strcpy(DataColor, argv[++i]);
802 } else if (!strcmp(argv[i], "-low")){
804 UseLowColorPixmap = 1;
806 } else if (!strcmp(argv[i], "-lat")){
808 if (i+1 >= argc){
809 fprintf(stderr, "wmMoonClock: -lat needs a value in degrees.\n");
810 print_usage();
811 exit(-1);
812 } else {
813 Glat = strtod(argv[i+1], &eptr);
814 if ((Glat == 0.0)&&(eptr == argv[i+1])){
815 fprintf(stderr, "wmMoonClock: could not convert latitude %s.\n", argv[i+1]);
816 print_usage();
817 exit(-1);
819 ++i;
822 } else if (!strcmp(argv[i], "-lon")){
824 if (i+1 >= argc){
825 fprintf(stderr, "wmMoonClock: -lat needs a value in degrees.\n");
826 print_usage();
827 exit(-1);
828 } else {
829 Glon = strtod(argv[i+1], &eptr);
830 if ((Glon == 0.0)&&(eptr == argv[i+1])){
831 fprintf(stderr, "wmMoonClock: could not convert longitude %s.\n", argv[i+1]);
832 print_usage();
833 exit(-1);
835 ++i;
838 } else {
840 print_usage();
841 exit(1);
848 void print_usage(){
850 printf("\nwmMoonClock version: %s\n", WMMOONCLOCK_VERSION);
851 printf("\nusage: wmMoonClock [-display <Display>] [-lat <Latitude>] [-lon <Longitude>] [-h]\n");
852 printf(" [-bc <Color>] [-lc <Color>] [-dc <Color>]\n\n");
853 printf("\t-display <Display>\tUse alternate X display.\n");
854 printf("\t-bc <Color> \t\tBackground color. (e.g. #ffbb00 or orange)\n");
855 printf("\t-lc <Color> \t\tColor for lables.\n");
856 printf("\t-dc <Color> \t\tColor for data entries.\n");
857 printf("\t-low \t\tUse lower color pixmap (for 8-bit displays).\n");
858 printf("\t-lat <Latitude>\t\tObservers Latitude. Positive in northern\n");
859 printf("\t \t\themisphere, negative in southern hemisphere.\n");
860 printf("\t-lon <Longitude>\tObservers Longitude. Greenwich is 0.0, and longitude\n");
861 printf("\t \tincreases positively toward the west. (Alternatively,\n");
862 printf("\t \tnegative numbers can also be used to specify\n");
863 printf("\t \tlongitudes to the east of Greenwich).\n");
864 printf("\t-h\t\t\tDisplay help screen.\n\n");
870 * This routine handles button presses. Clicking in the window
871 * toggles the display.
874 void pressEvent(XButtonEvent *xev){
876 ++ToggleWindow;
877 if (ToggleWindow > 4) ToggleWindow = 0;
878 Flag = 1;
880 return;