wmmoonclock: Use unsigned char in mask bitmap to avoid overflow warnings.
[dockapps.git] / wmmoonclock / src / wmMoonClock.c
blobd7bae221098f90c30108e23922f36bd0affc0be8
1 /*
3 * wmMoonClock-1.26 (C) 1998, 1999 Mike Henderson (mghenderson@lanl.gov)
5 * - Shows Moon Phase....
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., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301 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
128 void ParseCMDLine(int argc, char *argv[]);
129 void pressEvent(XButtonEvent *xev);
130 void print_usage();
133 int ToggleWindow = 0;
134 int nMAX = 1;
135 int Flag = 1;
136 double Glat, Glon, SinGlat, CosGlat, TimeZone;
137 int UseLowColorPixmap = 0;
138 char LabelColor[30] = "#a171ff";
139 char DataColor[30] = "#3dafff";
140 char BackColor[30] = "#010101";
148 * main
150 int main(int argc, char *argv[]) {
156 struct tm *GMTTime, *LocalTime;
157 XEvent event;
158 int i, n, j, ImageNumber, Year, Month, DayOfMonth, digit;
159 long CurrentLocalTime, CurrentGMTTime, date;
160 double UT, val, RA, DEC, UTRise, UTSet, LocalHour, hour24();
161 int D, H, M, S, sgn, A, B, q;
162 CTrans c;
163 struct timeval timeout;
164 fd_set xfdset;
172 * Parse any command line arguments.
174 Glat = Glon = 0.0;
175 ParseCMDLine(argc, argv);
176 c.Glat = Glat, c.Glon = Glon;
177 Glat *= RadPerDeg; SinGlat = sin( Glat ); CosGlat = cos( Glat );
181 initXwindow(argc, argv);
182 if ((DisplayDepth <= 8)||UseLowColorPixmap)
183 openXwindow(argc, argv, wmMoonClock_masterLow, (char *)wmMoonClock_mask_bits, wmMoonClock_mask_width, wmMoonClock_mask_height, BackColor, LabelColor, DataColor);
184 else
185 openXwindow(argc, argv, wmMoonClock_master, (char *)wmMoonClock_mask_bits, wmMoonClock_mask_width, wmMoonClock_mask_height, BackColor, LabelColor, DataColor);
192 * Loop until we die
194 n = 32000;
195 while(1) {
198 if (Flag) {
199 n = 32000;
200 Flag = 0;
207 * The Moon Ephemeris calculations are somewhat costly (the Moon is one of the most
208 * difficult objects to compute position for). So only process every nMAXth cycle of this
209 * loop. We run outer loop it faster to catch expose events, button presses, etc...
212 if (n>nMAX){
214 n = 0;
216 CurrentGMTTime = time(CurrentTime); GMTTime = gmtime(&CurrentGMTTime);
217 UT = GMTTime->tm_hour + GMTTime->tm_min/60.0 + GMTTime->tm_sec/3600.0;
218 Year = GMTTime->tm_year+1900;
219 Month = GMTTime->tm_mon+1;
220 DayOfMonth = GMTTime->tm_mday;
221 date = Year*10000 + Month*100 + DayOfMonth;
222 CurrentLocalTime = CurrentGMTTime; LocalTime = localtime(&CurrentLocalTime);
223 LocalHour = LocalTime->tm_hour + LocalTime->tm_min/60.0 + LocalTime->tm_sec/3600.0;
224 TimeZone = UT - LocalHour;
227 CalcEphem(date, UT, &c);
233 if (ToggleWindow == 0){
236 * Update Moon Image
239 nMAX = 1000;
240 ImageNumber = (int)(c.MoonPhase * 60.0 + 0.5);
241 if (ImageNumber > 59) ImageNumber = 0;
242 if (Glat < 0) ImageNumber = 59 - ImageNumber; /* add southern hemisphere support, closes: #537480 */
243 j = ImageNumber/10;
244 i = ImageNumber%10;
245 copyXPMArea(67+58*i, 2+58*j, 54, 54, 5, 5);
247 } else if (ToggleWindow == 1){
250 * Update Numerical Display
253 /* This requires second precision for LT and UT */
254 nMAX = 0;
258 * Clear plotting area
260 copyXPMArea(4, 69, 56, 56, 4, 4);
265 * Paste up LT and UT.
267 val = LocalHour;
268 H = (int)val; val = (val - H)*60.0;
269 M = (int)val; val = (val - M)*60.0;
270 S = (int)val;
271 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 25, 6);
272 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 25+5, 6);
273 copyXPMArea(117, 353, 1, 6, 25+10, 6);
274 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 25+12, 6);
275 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 25+17, 6);
277 val = UT;
278 H = (int)val; val = (val - H)*60.0;
279 M = (int)val; val = (val - M)*60.0;
280 S = (int)val;
281 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 25, 15);
282 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 25+5, 15);
283 copyXPMArea(117, 353, 1, 6, 25+10, 15);
284 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 25+12, 15);
285 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 25+17, 15);
292 * Paste up AGE.
294 val = c.MoonAge;
295 q = (val < 10.0) ? 5 : 0;
296 A = (int)val;
297 val = (val - A)*100.0;
298 B = (int)val;
299 digit = A/10; if (digit != 0) copyXPMArea(67+digit*5, 353, 5, 7, 26-q, 24);
300 digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 26+5-q, 24);
301 copyXPMArea(62, 357, 3, 3, 26+11-q, 28);
302 digit = B/10; copyXPMArea(67+digit*5, 353, 5, 7, 26+15-q, 24);
303 digit = B%10; copyXPMArea(67+digit*5, 353, 5, 7, 26+20-q, 24);
304 copyXPMArea(143, 354, 3, 3, 26+25-q, 23);
310 * Paste up Phase (Percent Illuminated).
312 val = 0.5*( 1.0 - cos(c.MoonPhase*6.2831853) );
313 val *= 100.0;
314 A = (int)(val+0.5);
315 if (A == 100){
316 copyXPMArea(72, 353, 5, 7, 32+5, 42);
317 copyXPMArea(67, 353, 5, 7, 32+10, 42);
318 copyXPMArea(67, 353, 5, 7, 32+15, 42);
319 copyXPMArea(147, 353, 5, 7, 32+20, 42);
320 } else if (A >= 10){
321 digit = A/10; copyXPMArea(67+digit*5, 353, 5, 7, 32+5, 42);
322 digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 32+10, 42);
323 copyXPMArea(147, 353, 5, 7, 32+15, 42);
324 } else {
325 digit = A; copyXPMArea(67+digit*5, 353, 5, 7, 32+5, 42);
326 copyXPMArea(147, 353, 5, 7, 32+10, 42);
333 * Paste up Frac (Percent of way through current lunar cycle).
335 val = c.MoonPhase*100.0;
336 A = (int)(val+0.5);
337 if (A == 100){
338 copyXPMArea(72, 353, 5, 7, 27+5, 33);
339 copyXPMArea(67, 353, 5, 7, 27+10, 33);
340 copyXPMArea(67, 353, 5, 7, 27+15, 33);
341 copyXPMArea(147, 353, 5, 7, 27+20, 33);
342 } else if (A >= 10){
343 digit = A/10; copyXPMArea(67+digit*5, 353, 5, 7, 27+5, 33);
344 digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 27+10, 33);
345 copyXPMArea(147, 353, 5, 7, 27+15, 33);
346 } else {
347 digit = A; copyXPMArea(67+digit*5, 353, 5, 7, 27+5, 33);
348 copyXPMArea(147, 353, 5, 7, 27+10, 33);
353 * Paste up Visible Status.
355 if (c.Visible)
356 copyXPMArea(6, 327, 13, 6, 46, 51);
357 else
358 copyXPMArea(26, 327, 9, 6, 46, 51);
363 } else if (ToggleWindow == 2){
366 * Plot up Moon Rise/Set Times
370 nMAX = 60;
373 * Clear plotting area
375 copyXPMArea(4, 134, 56, 56, 4, 4);
379 * Do Yesterday's first
381 MoonRise(Year, Month, DayOfMonth-1, LocalHour, &UTRise, &UTSet);
382 UTTohhmm(UTRise, &H, &M);
383 if (H >= 0){
384 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 7, 19);
385 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+5, 19);
386 copyXPMArea(117, 354, 1, 4, 7+10, 20);
387 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 7+12, 19);
388 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+17, 19);
389 } else {
390 copyXPMArea(57, 355, 5, 1, 7, 22); copyXPMArea(57, 355, 5, 1, 7+5, 22);
391 copyXPMArea(117, 354, 1, 4, 7+10, 20);
392 copyXPMArea(57, 355, 5, 1, 7+12, 22); copyXPMArea(57, 355, 5, 1, 7+17, 22);
394 UTTohhmm(UTSet, &H, &M);
395 if (H >= 0){
396 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 35, 19);
397 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+5, 19);
398 copyXPMArea(117, 354, 1, 4, 35+10, 20);
399 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 35+12, 19);
400 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+17, 19);
401 } else {
402 copyXPMArea(57, 355, 5, 1, 35, 22); copyXPMArea(57, 355, 5, 1, 35+5, 22);
403 copyXPMArea(117, 354, 1, 4, 35+10, 20);
404 copyXPMArea(57, 355, 5, 1, 35+12, 22); copyXPMArea(57, 355, 5, 1, 35+17, 22);
409 * Plot up todays Rise/Set times.
411 MoonRise(Year, Month, DayOfMonth, LocalHour, &UTRise, &UTSet);
412 UTTohhmm(UTRise, &H, &M);
413 if (H >= 0){
414 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 7, 29);
415 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+5, 29);
416 copyXPMArea(117, 354, 1, 4, 7+10, 30);
417 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 7+12, 29);
418 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+17, 29);
419 } else {
420 copyXPMArea(57, 355, 5, 1, 7, 32); copyXPMArea(57, 355, 5, 1, 7+5, 32);
421 copyXPMArea(117, 354, 1, 4, 7+10, 30);
422 copyXPMArea(57, 355, 5, 1, 7+12, 32); copyXPMArea(57, 355, 5, 1, 7+17, 32);
424 UTTohhmm(UTSet, &H, &M);
425 if (H >= 0){
426 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 35, 29);
427 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+5, 29);
428 copyXPMArea(117, 354, 1, 4, 35+10, 30);
429 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 35+12, 29);
430 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+17, 29);
431 } else {
432 copyXPMArea(57, 355, 5, 1, 35, 32); copyXPMArea(57, 355, 5, 1, 35+5, 32);
433 copyXPMArea(117, 354, 1, 4, 35+10, 30);
434 copyXPMArea(57, 355, 5, 1, 35+12, 32); copyXPMArea(57, 355, 5, 1, 35+17, 32);
440 * Plot up tomorrow's Rise/Set times.
442 MoonRise(Year, Month, DayOfMonth+1, LocalHour, &UTRise, &UTSet);
443 UTTohhmm(UTRise, &H, &M);
444 if (H >= 0){
445 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 7, 39);
446 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+5, 39);
447 copyXPMArea(117, 354, 1, 4, 7+10, 40);
448 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 7+12, 39);
449 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+17, 39);
450 } else {
451 copyXPMArea(57, 355, 5, 1, 7, 42); copyXPMArea(57, 355, 5, 1, 7+5, 42);
452 copyXPMArea(117, 354, 1, 4, 7+10, 40);
453 copyXPMArea(57, 355, 5, 1, 7+12, 42); copyXPMArea(57, 355, 5, 1, 7+17, 42);
455 UTTohhmm(UTSet, &H, &M);
456 if (H >= 0){
457 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 35, 39);
458 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+5, 39);
459 copyXPMArea(117, 354, 1, 4, 35+10, 40);
460 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 35+12, 39);
461 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+17, 39);
462 } else {
463 copyXPMArea(57, 355, 5, 1, 35, 42); copyXPMArea(57, 355, 5, 1, 35+5, 42);
464 copyXPMArea(117, 354, 1, 4, 35+10, 40);
465 copyXPMArea(57, 355, 5, 1, 35+12, 42); copyXPMArea(57, 355, 5, 1, 35+17, 42);
469 } else if (ToggleWindow == 3){
472 * Plot up Horizon Coords
477 nMAX = 3;
480 * Clear plotting area
482 copyXPMArea(4, 199, 56, 56, 4, 4);
487 * Paste up Azimuth, A
489 val = c.A_moon;
490 sgn = (val < 0.0) ? -1 : 0;
491 val = fabs(val);
492 D = (int)val;
493 val = (val-(double)D)*100.0;
494 M = (int)val;
496 if (sgn < 0) copyXPMArea(120, 357, 2, 1, 19, 27);
498 /* degrees 100's */
499 digit = D/100; copyXPMArea(67+digit*5, 353, 5, 7, 22, 24);
500 D -= digit*100;
502 /* degrees 10's */
503 digit = D/10; copyXPMArea(67+digit*5, 353, 5, 7, 22+5, 24);
505 /* degrees 1's */
506 digit = D%10; copyXPMArea(67+digit*5, 353, 5, 7, 22+10, 24);
508 /* Decimal */
509 copyXPMArea(62, 357, 3, 3, 22+15, 28);
511 /* Decimal Part */
512 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 22+19, 24);
514 /* mins 1's */
515 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 22+24, 24);
517 copyXPMArea(120, 353, 3, 3, 22+29, 23);
524 * Paste up Altitude, h
526 val = c.h_moon;
527 sgn = (val < 0.0) ? -1 : 0;
528 val = fabs(val);
529 D = (int)val;
530 val = (val-(double)D)*100.0;
531 M = (int)val;
533 if (sgn < 0) copyXPMArea(120, 357, 2, 1, 19, 39);
535 /* degrees 10's */
536 digit = D/10; copyXPMArea(67+digit*5, 353, 5, 7, 22, 36);
538 /* degrees 1's */
539 digit = D%10; copyXPMArea(67+digit*5, 353, 5, 7, 22+5, 36);
541 /* Decimal */
542 copyXPMArea(62, 357, 3, 3, 22+10, 40);
544 /* Decimal Part */
545 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 22+14, 36);
547 /* mins 1's */
548 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 22+19, 36);
550 copyXPMArea(120, 353, 3, 3, 22+24, 35);
557 * Paste up Earth-Moon Distance (in units of Earth radii).
559 val = c.EarthMoonDistance;
560 A = (int)val;
561 val = (val - A)*100.0;
562 B = (int)val;
563 digit = A/10; if (digit != 0) copyXPMArea(67+digit*5, 353, 5, 7, 30, 47);
564 digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 30+5, 47);
565 copyXPMArea(62, 357, 3, 3, 30+11, 51);
566 digit = B/10; copyXPMArea(67+digit*5, 353, 5, 7, 30+15, 47);
567 digit = B%10; copyXPMArea(67+digit*5, 353, 5, 7, 30+20, 47);
571 } else if (ToggleWindow == 4){
574 * Plot up RA/DEC Coords
579 nMAX = 3;
582 * Clear plotting area
584 copyXPMArea(4, 264, 56, 56, 4, 4);
589 * Paste up Right Ascention
591 RA = c.RA_moon/15.0;
592 H = (int)RA;
593 RA = (RA-(double)H)*60.0;
594 M = (int)RA; RA = (RA-(double)M)*60.0;
595 S = (int)(RA+0.5);
597 /* hours 10's */
598 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 17, 25);
600 /* hours 1's */
601 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+5, 25);
603 /* hour symbol */
604 copyXPMArea(138, 354, 3, 3, 17+10, 24);
606 /* mins 10's */
607 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 17+14, 25);
609 /* mins 1's */
610 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+19, 25);
612 /* min symbol */
613 copyXPMArea(124, 353, 3, 3, 17+23, 24);
615 /* secs 10's */
616 digit = S/10; copyXPMArea(67+digit*5, 353, 5, 7, 17+27, 25);
618 /* secs 1's */
619 digit = S%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+32, 25);
621 /* sec symbol */
622 copyXPMArea(128, 353, 5, 3, 17+36, 24);
628 * Paste up Declination
630 DEC = c.DEC_moon;
631 sgn = (DEC < 0.0) ? -1 : 0;
632 DEC = fabs(DEC);
633 D = (int)DEC;
634 DEC = (DEC-(double)D)*60.0;
635 M = (int)DEC;
636 DEC = (DEC-(double)M)*60.0;
637 S = (int)(DEC+0.5);
639 if (sgn < 0) copyXPMArea(120, 357, 2, 1, 14, 39);
642 /* degrees 10's */
643 digit = D/10; copyXPMArea(67+digit*5, 353, 5, 7, 17, 36);
645 /* degrees 1's */
646 digit = D%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+5, 36);
648 /* degree symbol */
649 copyXPMArea(120, 353, 3, 3, 17+10, 35);
651 /* mins 10's */
652 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 17+14, 36);
654 /* mins 1's */
655 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+19, 36);
657 /* min symbol */
658 copyXPMArea(124, 353, 3, 3, 17+23, 35);
660 /* secs 10's */
661 digit = S/10; copyXPMArea(67+digit*5, 353, 5, 7, 17+27, 36);
663 /* secs 1's */
664 digit = S%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+32, 36);
666 /* sec symbol */
667 copyXPMArea(128, 353, 5, 3, 17+36, 35);
673 * Paste up Earth-Moon Distance (in units of Earth radii).
675 val = c.EarthMoonDistance;
676 A = (int)val;
677 val = (val - A)*100.0;
678 B = (int)val;
679 digit = A/10; if (digit != 0) copyXPMArea(67+digit*5, 353, 5, 7, 30, 47);
680 digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 30+5, 47);
681 copyXPMArea(62, 357, 3, 3, 30+11, 51);
682 digit = B/10; copyXPMArea(67+digit*5, 353, 5, 7, 30+15, 47);
683 digit = B%10; copyXPMArea(67+digit*5, 353, 5, 7, 30+20, 47);
691 } else {
694 * Update the counter.
696 ++n;
705 * Add X display to file descriptor set for polling.
707 FD_ZERO(&xfdset);
708 FD_SET(ConnectionNumber(display), &xfdset);
713 * Process any pending X events.
715 while(XPending(display)){
716 XNextEvent(display, &event);
717 switch(event.type){
718 case Expose:
719 RedrawWindow();
720 break;
721 case ButtonPress:
722 pressEvent(&event.xbutton);
723 break;
724 case ButtonRelease:
725 break;
735 * Redraw and wait for next update
737 RedrawWindow();
738 timeout.tv_sec = DELAY / 1000000L;
739 timeout.tv_usec = DELAY % 1000000L;
740 select(ConnectionNumber(display) + 1, &xfdset, NULL, NULL, &timeout);
757 * ParseCMDLine()
759 void ParseCMDLine(int argc, char *argv[]) {
761 int i;
762 char *eptr;
764 for (i = 1; i < argc; i++) {
766 if (!strcmp(argv[i], "-display")){
768 ++i;
770 } else if (!strcmp(argv[i], "-bc")){
772 if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
773 fprintf(stderr, "wmMoonClock: -bc needs a color argument.\n");
774 print_usage();
775 exit(-1);
777 strcpy(BackColor, argv[++i]);
779 } else if (!strcmp(argv[i], "-lc")){
781 if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
782 fprintf(stderr, "wmMoonClock: -lc needs a color argument.\n");
783 print_usage();
784 exit(-1);
786 strcpy(LabelColor, argv[++i]);
788 } else if (!strcmp(argv[i], "-dc")){
790 if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
791 fprintf(stderr, "wmMoonClock: -dc needs a color argument.\n");
792 print_usage();
793 exit(-1);
795 strcpy(DataColor, argv[++i]);
797 } else if (!strcmp(argv[i], "-low")){
799 UseLowColorPixmap = 1;
801 } else if (!strcmp(argv[i], "-lat")){
803 if (i+1 >= argc){
804 fprintf(stderr, "wmMoonClock: -lat needs a value in degrees.\n");
805 print_usage();
806 exit(-1);
807 } else {
808 Glat = strtod(argv[i+1], &eptr);
809 if ((Glat == 0.0)&&(eptr == argv[i+1])){
810 fprintf(stderr, "wmMoonClock: could not convert latitude %s.\n", argv[i+1]);
811 print_usage();
812 exit(-1);
814 ++i;
817 } else if (!strcmp(argv[i], "-lon")){
819 if (i+1 >= argc){
820 fprintf(stderr, "wmMoonClock: -lat needs a value in degrees.\n");
821 print_usage();
822 exit(-1);
823 } else {
824 Glon = strtod(argv[i+1], &eptr);
825 if ((Glon == 0.0)&&(eptr == argv[i+1])){
826 fprintf(stderr, "wmMoonClock: could not convert longitude %s.\n", argv[i+1]);
827 print_usage();
828 exit(-1);
830 ++i;
833 } else {
835 print_usage();
836 exit(1);
843 void print_usage(){
845 printf("\nwmMoonClock version: %s\n", PACKAGE_VERSION);
846 printf("\nusage: wmMoonClock [-display <Display>] [-lat <Latitude>] [-lon <Longitude>] [-h]\n");
847 printf(" [-bc <Color>] [-lc <Color>] [-dc <Color>]\n\n");
848 printf("\t-display <Display>\tUse alternate X display.\n");
849 printf("\t-bc <Color> \t\tBackground color. (e.g. #ffbb00 or orange)\n");
850 printf("\t-lc <Color> \t\tColor for lables.\n");
851 printf("\t-dc <Color> \t\tColor for data entries.\n");
852 printf("\t-low \t\tUse lower color pixmap (for 8-bit displays).\n");
853 printf("\t-lat <Latitude>\t\tObservers Latitude. Positive in northern\n");
854 printf("\t \t\themisphere, negative in southern hemisphere.\n");
855 printf("\t-lon <Longitude>\tObservers Longitude. Greenwich is 0.0, and longitude\n");
856 printf("\t \tincreases positively toward the west. (Alternatively,\n");
857 printf("\t \tnegative numbers can also be used to specify\n");
858 printf("\t \tlongitudes to the east of Greenwich).\n");
859 printf("\t-h\t\t\tDisplay help screen.\n\n");
865 * This routine handles button presses. Clicking in the window
866 * toggles the display.
869 void pressEvent(XButtonEvent *xev){
871 ++ToggleWindow;
872 if (ToggleWindow > 4) ToggleWindow = 0;
873 Flag = 1;
875 return;