forked from ghewgill/xearth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xearth.c
1405 lines (1253 loc) · 33.5 KB
/
xearth.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* xearth.c
* kirk johnson
* july 1993
*
* Copyright (C) 1989, 1990, 1993-1995, 1999 Kirk Lauritz Johnson
*
* Parts of the source code (as marked) are:
* Copyright (C) 1989, 1990, 1991 by Jim Frost
* Copyright (C) 1992 by Jamie Zawinski <jwz@lucid.com>
*
* Permission to use, copy, modify and freely distribute xearth for
* non-commercial and not-for-profit purposes is hereby granted
* without fee, provided that both the above copyright notice and this
* permission notice appear in all copies and in supporting
* documentation.
*
* Unisys Corporation holds worldwide patent rights on the Lempel Zev
* Welch (LZW) compression technique employed in the CompuServe GIF
* image file format as well as in other formats. Unisys has made it
* clear, however, that it does not require licensing or fees to be
* paid for freely distributed, non-commercial applications (such as
* xearth) that employ LZW/GIF technology. Those wishing further
* information about licensing the LZW patent should contact Unisys
* directly at (lzw_info@unisys.com) or by writing to
*
* Unisys Corporation
* Welch Licensing Department
* M/S-C1SW19
* P.O. Box 500
* Blue Bell, PA 19424
*
* The author makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*
* THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT
* OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "xearth.h"
#include "kljcpyrt.h"
extern int errno;
#ifndef NO_SETPRIORITY
/* apparently some systems (possibly mt.xinu 4.3bsd?) may need
* <sys/time.h> to be included here before <sys/resource.h>.
*/
#include <sys/resource.h> /* for setpriority() */
#endif
#define ModeX (0) /* possible output_mode values */
#define ModePPM (1)
#define ModeGIF (2)
#define ModePNG (3)
#define ModeJPEG (4)
#define ModeBMP (5)
#define ModeTest (6)
/* tokens in specifiers are delimited by spaces, tabs, commas, and
* forward slashes
*/
#define IsTokenDelim(x) (((x)==' ')||((x)=='\t')||((x)==',')||((x)==' '))
#define NotTokenDelim(x) (!IsTokenDelim(x))
int main _P((int, char *[]));
void set_priority _P((int));
void output _P((void));
void test_mode _P((void));
void sun_relative_position _P((double *, double *));
void simple_orbit _P((time_t, double *, double *));
void pick_random_position _P((double *, double *));
void set_defaults _P((void));
int using_x _P((int, char *[]));
void command_line _P((int, char *[]));
char *progname; /* program name */
int proj_type; /* projection type */
int output_mode; /* output mode (X, PPM, ...) */
double view_lon; /* viewing position longitude */
double view_lat; /* viewing position latitude */
double view_rot; /* viewing rotation (degrees) */
int rotate_type; /* type of rotation */
int view_pos_type; /* type of viewing position */
double sun_rel_lon; /* view lon, relative to sun */
double sun_rel_lat; /* view lat, relative to sun */
double orbit_period; /* orbit period (seconds) */
double orbit_inclin; /* orbit inclination (degrees) */
double view_mag; /* viewing magnification */
int do_shade; /* render with shading? */
double sun_lon; /* sun position longitude */
double sun_lat; /* sun position latitude */
int compute_sun_pos; /* compute sun's position? */
int wdth; /* image width (pixels) */
int hght; /* image height (pixels) */
int shift_x; /* image shift (x, pixels) */
int shift_y; /* image shift (y, pixels) */
int do_stars; /* show stars in background? */
double star_freq; /* frequency of stars */
int big_stars; /* percent of doublewide stars */
int do_grid; /* show lon/lat grid? */
int grid_big; /* lon/lat grid line spacing */
int grid_small; /* dot spacing along grids */
int do_label; /* label image */
int do_markers; /* display markers (X only) */
char *markerfile; /* for user-spec. marker info */
char *mapfile; /* for image overlay file */
char *overlayfile[MAX_OVERLAY]; /* for overlay file */
int overlay_count; /* number of overlay files */
int wait_time; /* wait time between redraw */
double time_warp; /* passage of time multiplier */
int fixed_time; /* fixed viewing time (ssue) */
int day; /* day side brightness (%) */
int night; /* night side brightness (%) */
int terminator; /* terminator discontinuity, % */
double xgamma; /* gamma correction (X only) */
int use_two_pixmaps; /* use two pixmaps? (X only) */
int num_colors; /* number of colors to use */
int do_fork; /* fork child process? */
int priority; /* desired process priority */
time_t start_time = 0;
time_t current_time;
char errmsgbuf[1024]; /* for formatting warning/error msgs */
int main(argc, argv)
int argc;
char *argv[];
{
set_defaults();
progname = argv[0];
if (using_x(argc, argv))
#ifdef HAVE_X11
command_line_x(argc, argv);
#else
usage("x11 display mode not supported in this build");
#endif
else
{
command_line(argc, argv);
if (isatty(fileno(stdout))) {
usage("xearth refuses to write image data to a tty");
}
}
if (mapfile != NULL || overlayfile[0] != NULL)
num_colors = TRUE_COLOR;
if (priority != 0)
set_priority(priority);
srandom(((int) time(NULL)) + ((int) getpid()));
output();
return 0;
}
#ifdef NO_SETPRIORITY
/* setpriority()-like functionality for System V
* derivates that only provide nice()
*/
void set_priority(new)
int new;
{
int old;
/* determine current priority of the process
*/
errno = 0;
old = nice(0);
if ((old == -1) && (errno != 0))
{
perror("nice");
exit(-1);
}
/* try to change priority to new
*/
new = nice(new - old);
if ((new == -1) && (errno != 0))
{
perror("nice");
exit(-1);
}
}
#else /* NO_SETPRIORITY */
/* for systems that provide setpriority(),
* set_priority() is just a wrapper
*/
void set_priority(new)
int new;
{
if ((setpriority(PRIO_PROCESS, getpid(), new) == -1))
{
perror("setpriority");
exit(-1);
}
}
#endif /* NO_SETPRIORITY */
void output()
{
switch (output_mode)
{
case ModePPM:
ppm_output();
break;
case ModeGIF:
gif_output();
break;
case ModePNG:
png_output();
break;
case ModeJPEG:
jpeg_output();
break;
case ModeBMP:
bmp_output();
break;
#ifdef HAVE_X11
case ModeX:
if ((!do_fork) || (fork() == 0))
x11_output();
break;
#endif
case ModeTest:
test_mode();
break;
default:
assert(0);
}
}
void test_mode()
{
}
void compute_positions()
{
/* determine "current" time
*/
if (fixed_time == 0)
{
current_time = time(NULL);
if (start_time == 0)
start_time = current_time;
else
current_time = start_time + (current_time - start_time) * time_warp;
}
else
{
current_time = fixed_time;
}
/* determine position on earth's surface where sun is directly
* overhead
*/
if (compute_sun_pos)
sun_position(current_time, &sun_lat, &sun_lon);
/* determine viewing position
*/
if (view_pos_type == ViewPosTypeSun)
{
sun_relative_position(&view_lat, &view_lon);
}
else if (view_pos_type == ViewPosTypeOrbit)
{
simple_orbit(current_time, &view_lat, &view_lon);
}
else if (view_pos_type == ViewPosTypeRandom)
{
pick_random_position(&view_lat, &view_lon);
}
else if (view_pos_type == ViewPosTypeMoon)
{
moon_position(current_time, &view_lat, &view_lon);
}
/* for ViewRotGalactic, compute appropriate viewing rotation
*/
if (rotate_type == ViewRotGalactic)
{
view_rot = sun_lat * sin((view_lon - sun_lon) * (M_PI / 180));
}
}
void sun_relative_position(lat_ret, lon_ret)
double *lat_ret; /* (return) latitude */
double *lon_ret; /* (return) longitude */
{
double lat, lon;
lat = sun_lat + sun_rel_lat;
lon = sun_lon + sun_rel_lon;
/* sanity check */
assert((lat >= -180) && (lat <= 180));
assert((lon >= -360) && (lon <= 360));
if (lat > 90)
{
lat = 180 - lat;
lon += 180;
}
else if (lat < -90)
{
lat = -180 - lat;
lon += 180;
}
if (lon > 180)
{
do
lon -= 360;
while (lon > 180);
}
else if (lon < -180)
{
do
lon += 360;
while (lon < -180);
}
*lat_ret = lat;
*lon_ret = lon;
}
void simple_orbit(ssue, lat, lon)
time_t ssue; /* seconds since unix epoch */
double *lat; /* (return) latitude */
double *lon; /* (return) longitude */
{
double x, y, z;
double a, c, s;
double t1, t2;
/* start at 0 N 0 E */
x = 0;
y = 0;
z = 1;
/* rotate in about y axis (from z towards x) according to the number
* of orbits we've completed
*/
a = ((double) ssue / orbit_period) * (2*M_PI);
c = cos(a);
s = sin(a);
t1 = c*z - s*x;
t2 = s*z + c*x;
z = t1;
x = t2;
/* rotate about z axis (from x towards y) according to the
* inclination of the orbit
*/
a = orbit_inclin * (M_PI/180);
c = cos(a);
s = sin(a);
t1 = c*x - s*y;
t2 = s*x + c*y;
x = t1;
y = t2;
/* rotate about y axis (from x towards z) according to the number of
* rotations the earth has made
*/
a = ((double) ssue / EarthPeriod) * (2*M_PI);
c = cos(a);
s = sin(a);
t1 = c*x - s*z;
t2 = s*x + c*z;
x = t1;
z = t2;
*lat = asin(y) * (180/M_PI);
*lon = atan2(x, z) * (180/M_PI);
}
/* pick a position (lat, lon) at random
*/
void pick_random_position(lat_ret, lon_ret)
double *lat_ret; /* (return) latitude */
double *lon_ret; /* (return) longitude */
{
int i;
double pos[3];
double mag;
double s_lat, c_lat;
double s_lon, c_lon;
/* select a vector at random */
do
{
mag = 0;
for (i=0; i<3; i++)
{
pos[i] = ((random() % 20001) * 1e-4) - 1;
mag += pos[i] * pos[i];
}
} while ((mag > 1.0) || (mag < 0.01));
/* normalize the vector */
mag = sqrt(mag);
for (i=0; i<3; i++)
pos[i] /= mag;
/* convert to (lat, lon) */
s_lat = pos[1];
c_lat = sqrt(1 - s_lat*s_lat);
s_lon = pos[0] / c_lat;
c_lon = pos[2] / c_lat;
*lat_ret = atan2(s_lat, c_lat) * (180/M_PI);
*lon_ret = atan2(s_lon, c_lon) * (180/M_PI);
}
/* look through the command line arguments to figure out if we're
* using X or not (if "-ppm", "-gif", "-png", "-jpeg", "-bmp", or "-test" is found, we're not
* using X, otherwise we are).
*/
int using_x(argc, argv)
int argc;
char *argv[];
{
int i;
/* loop through the args, break if we find "-ppm", "-gif", "-png", "-jpeg", "-bmp", or
* "-test"
*/
for (i=1; i<argc; i++)
if ((strcmp(argv[i], "-ppm") == 0) ||
(strcmp(argv[i], "-gif") == 0) ||
(strcmp(argv[i], "-png") == 0) ||
(strcmp(argv[i], "-jpeg") == 0) ||
(strcmp(argv[i], "-bmp") == 0) ||
(strcmp(argv[i], "-test") == 0))
break;
/* if we made it through the loop without finding "-ppm", "-gif", "-png", "-jpeg", "-bmp", or
* "-test" (and breaking out), assume we're using X.
*/
return (i == argc);
}
/* set_defaults() gets called at xearth startup (before command line
* arguments are handled), regardless of what output mode (x, ppm,
* gif, png, jpeg, bmp) is being used.
*/
void set_defaults()
{
output_mode = ModeX;
proj_type = ProjTypeOrthographic;
view_pos_type = ViewPosTypeSun;
sun_rel_lat = 0;
sun_rel_lon = 0;
compute_sun_pos = 1;
view_rot = 0;
rotate_type = ViewRotNorth;
wdth = DefaultWdthHght;
hght = DefaultWdthHght;
shift_x = 0;
shift_y = 0;
view_mag = 1.0;
do_shade = 1;
do_label = 0;
do_markers = 1;
wait_time = 300;
time_warp = 1;
day = 100;
night = 5;
terminator = 1;
use_two_pixmaps = 1;
num_colors = 64;
do_fork = 0;
priority = 0;
do_stars = 1;
star_freq = 0.002;
big_stars = 0;
do_grid = 0;
grid_big = 6;
grid_small = 15;
fixed_time = 0;
xgamma = 1.0;
}
/* procedure for interpreting command line arguments when we're not
* using X; command_line_x() is used when we are.
*/
void command_line(argc, argv)
int argc;
char *argv[];
{
int i;
progname = argv[0];
for (i=1; i<argc; i++)
{
if (strcmp(argv[i], "-proj") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -proj");
decode_proj_type(argv[i]);
}
else if (strcmp(argv[i], "-pos") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -pos");
decode_viewing_pos(argv[i]);
}
else if (strcmp(argv[i], "-rot") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -rot");
decode_rotation(argv[i]);
}
else if (strcmp(argv[i], "-sunpos") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -sunpos");
decode_sun_pos(argv[i]);
}
else if (strcmp(argv[i], "-mag") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -mag");
sscanf(argv[i], "%lf", &view_mag);
if (view_mag <= 0)
fatal("viewing magnification must be positive");
}
else if (strcmp(argv[i], "-size") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -size");
decode_size(argv[i]);
}
else if (strcmp(argv[i], "-shift") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -shift");
decode_shift(argv[i]);
}
else if (strcmp(argv[i], "-shade") == 0)
{
do_shade = 1;
}
else if (strcmp(argv[i], "-noshade") == 0)
{
do_shade = 0;
}
else if (strcmp(argv[i], "-label") == 0)
{
do_label = 1;
}
else if (strcmp(argv[i], "-nolabel") == 0)
{
do_label = 0;
}
else if (strcmp(argv[i], "-labelpos") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -labelpos");
warning("-labelpos not relevant for GIF or PPM output");
}
else if (strcmp(argv[i], "-markers") == 0)
{
do_markers = 1;
warning("markers not supported with GIF and PPM output");
}
else if (strcmp(argv[i], "-nomarkers") == 0)
{
do_markers = 0;
}
else if (strcmp(argv[i], "-markerfile") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -markerfile");
warning("-markerfile not relevant for GIF or PPM output");
}
else if (strcmp(argv[i], "-showmarkers") == 0)
{
warning("-showmarkers not relevant for GIF or PPM output");
}
else if (strcmp(argv[i], "-stars") == 0)
{
do_stars = 1;
}
else if (strcmp(argv[i], "-nostars") == 0)
{
do_stars = 0;
}
else if (strcmp(argv[i], "-starfreq") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -starfreq");
sscanf(argv[i], "%lf", &star_freq);
if ((star_freq < 0) || (star_freq > 1))
fatal("arg to -starfreq must be between 0 and 1");
}
else if (strcmp(argv[i], "-bigstars") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -bigstars");
sscanf(argv[i], "%d", &big_stars);
if ((big_stars < 0) || (big_stars > 100))
fatal("arg to -bigstars must be between 0 and 100");
}
else if (strcmp(argv[i], "-grid") == 0)
{
do_grid = 1;
}
else if (strcmp(argv[i], "-nogrid") == 0)
{
do_grid = 0;
}
else if (strcmp(argv[i], "-grid1") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -grid1");
sscanf(argv[i], "%d", &grid_big);
if (grid_big <= 0)
fatal("arg to -grid1 must be positive");
}
else if (strcmp(argv[i], "-grid2") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -grid2");
sscanf(argv[i], "%d", &grid_small);
if (grid_small <= 0)
fatal("arg to -grid2 must be positive");
}
else if (strcmp(argv[i], "-day") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -day");
sscanf(argv[i], "%d", &day);
if ((day > 100) || (day < 0))
fatal("arg to -day must be between 0 and 100");
}
else if (strcmp(argv[i], "-night") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -night");
sscanf(argv[i], "%d", &night);
if ((night > 100) || (night < 0))
fatal("arg to -night must be between 0 and 100");
}
else if (strcmp(argv[i], "-term") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -term");
sscanf(argv[i], "%d", &terminator);
if ((terminator > 100) || (terminator < 0))
fatal("arg to -term must be between 0 and 100");
}
else if (strcmp(argv[i], "-mapfile") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -mapfile");
mapfile = argv[i];
}
else if (strcmp(argv[i], "-overlayfile") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -overlayfile");
decode_overlay(argv[i]);
}
else if (strcmp(argv[i], "-gamma") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -gamma");
sscanf(argv[i], "%lf", &xgamma);
if (xgamma <= 0)
fatal("arg to -gamma must be positive");
warning("gamma correction not supported with GIF and PPM output");
}
else if (strcmp(argv[i], "-wait") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -wait");
sscanf(argv[i], "%d", &wait_time);
if (wait_time < 0)
fatal("arg to -wait must be non-negative");
}
else if (strcmp(argv[i], "-timewarp") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -timewarp");
sscanf(argv[i], "%lf", &time_warp);
if (time_warp <= 0)
fatal("arg to -timewarp must be positive");
}
else if (strcmp(argv[i], "-time") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -time");
sscanf(argv[i], "%d", &fixed_time);
}
else if (strcmp(argv[i], "-onepix") == 0)
{
use_two_pixmaps = 0;
warning("-onepix not relevant for GIF or PPM output");
}
else if (strcmp(argv[i], "-twopix") == 0)
{
use_two_pixmaps = 1;
warning("-twopix not relevant for GIF or PPM output");
}
else if (strcmp(argv[i], "-mono") == 0)
{
warning("monochrome mode not supported with GIF and PPM output");
}
else if (strcmp(argv[i], "-nomono") == 0)
{
warning("monochrome mode not supported with GIF and PPM output");
}
else if (strcmp(argv[i], "-ncolors") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -ncolors");
decode_colors(argv[i]);
}
else if (strcmp(argv[i], "-font") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -font");
warning("-font not relevant for GIF or PPM output");
}
else if (strcmp(argv[i], "-root") == 0)
{
warning("-root not relevant for GIF or PPM output");
}
else if (strcmp(argv[i], "-noroot") == 0)
{
warning("-noroot not relevant for GIF or PPM output");
}
else if (strcmp(argv[i], "-geometry") == 0)
{
warning("-geometry not relevant for GIF or PPM output");
}
else if (strcmp(argv[i], "-title") == 0)
{
warning("-title not relevant for GIF or PPM output");
}
else if (strcmp(argv[i], "-iconname") == 0)
{
warning("-iconname not relevant for GIF or PPM output");
}
else if (strcmp(argv[i], "-name") == 0)
{
warning("-name not relevant for GIF or PPM output");
}
else if (strcmp(argv[i], "-fork") == 0)
{
do_fork = 1;
}
else if (strcmp(argv[i], "-nofork") == 0)
{
do_fork = 0;
}
else if (strcmp(argv[i], "-once") == 0)
{
warning("-once not relevant for GIF or PPM output");
}
else if (strcmp(argv[i], "-noonce") == 0)
{
warning("-once not relevant for GIF or PPM output");
}
else if (strcmp(argv[i], "-nice") == 0)
{
i += 1;
if (i >= argc) usage("missing arg to -nice");
sscanf(argv[i], "%d", &priority);
}
else if (strcmp(argv[i], "-version") == 0)
{
version_info(1);
}
else if (strcmp(argv[i], "-ppm") == 0)
{
output_mode = ModePPM;
}
else if (strcmp(argv[i], "-gif") == 0)
{
output_mode = ModeGIF;
}
else if (strcmp(argv[i], "-png") == 0)
{
output_mode = ModePNG;
}
else if (strcmp(argv[i], "-jpeg") == 0)
{
output_mode = ModeJPEG;
}
else if (strcmp(argv[i], "-bmp") == 0)
{
output_mode = ModeBMP;
}
else if (strcmp(argv[i], "-test") == 0)
{
output_mode = ModeTest;
}
else if (strcmp(argv[i], "-display") == 0)
{
warning("-display not relevant for GIF or PPM output");
}
else
{
usage(NULL);
}
}
}
/* if efficiency really mattered here (which it doesn't), this code
* could definitely be made quite a bit more efficient.
*/
char **tokenize(s, argc_ret, msg)
char *s;
int *argc_ret;
const char **msg;
{
int lim;
int argc;
char **argv;
*msg = NULL;
lim = 4;
argc = 0;
argv = (char **) malloc((unsigned) sizeof(char *) * lim);
assert(argv != NULL);
while (1)
{
/* skip delimiters (space, tab, comma, forward slash)
*/
while (1)
{
if (NotTokenDelim(*s)) break;
*s = '\0';
s += 1;
}
if ((*s) == '\0')
{
/* if we're at the end of s, no more tokens
*/
break;
}
else if ((*s) == '#')
{
/* if we find a comment character (#), replace it
* with a NUL and act like we found the end s
*/
*s = '\0';
break;
}
/* make sure there's room for another token
*/
if (argc == lim)
{
lim *= 2;
argv = (char **) realloc(argv, (unsigned) sizeof(char *) * lim);
assert(argv != NULL);
}
/* get the next token
*/
if ((*s) == '"')
{
/* string token
*/
*s = '\0';
s += 1;
argv[argc++] = s;
while (((*s) != '"') && ((*s) != '\0'))
s += 1;
if ((*s) == '\0')
{
/* oops, never found closing double quote
*/
*msg = "unterminated string (missing \")";
}
else
{
/* string token terminated normally
*/
*s = '\0';
s += 1;
}
}
else
{
/* normal token
*/
argv[argc++] = s;
while (NotTokenDelim(*s) &&
((*s) != '#') && ((*s) != '"') && ((*s) != '\0'))
s += 1;
}
}
*argc_ret = argc;
return argv;
}
/* decode projection type; three possibilities:
* orthographic - orthographic projection (short form: orth)
* mercator - mercator projection (short form: merc)
* cylindrical - cylindrical projection (short form: cyl)
*/
void decode_proj_type(s)
char *s;
{
if ((strcmp(s, "orthographic") == 0) || (strcmp(s, "orth") == 0))
{
proj_type = ProjTypeOrthographic;
}
else if ((strcmp(s, "mercator") == 0) || (strcmp(s, "merc") == 0))
{
proj_type = ProjTypeMercator;
}
else if ((strcmp(s, "cylindrical") == 0) || (strcmp(s, "cyl") == 0))
{
proj_type = ProjTypeCylindrical;
}
else
{
sprintf(errmsgbuf, "unknown projection type (%s)", s);
fatal(errmsgbuf);
}
}
/* decode viewing position specifier; five possibilities:
*
* fixed lat lon - viewing position fixed wrt earth at (lat, lon)
*
* sunrel lat lon - viewing position fixed wrt sun at (lat, lon)
* [position interpreted as if sun was at (0, 0)]
*
* orbit per inc - moving viewing position following simple orbit
* with period per and inclination inc
*
* random - random viewing position
*
* moon - current location of the moon
*
* fields can be separated with either spaces, commas, or slashes.
*/
void decode_viewing_pos(s)
char *s;
{
int argc;
char **argv;
const char *msg;
double arg1;
double arg2;
argv = tokenize(s, &argc, &msg);
if (msg != NULL)
{
sprintf(errmsgbuf, "viewing position specifier: %s", msg);