-
Notifications
You must be signed in to change notification settings - Fork 0
/
xv.c
4815 lines (3758 loc) · 133 KB
/
xv.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
/*
* xv.c - main section of xv. X setup, window creation, etc.
*/
#include "copyright.h"
#define MAIN
#define NEEDSTIME
#define NEEDSDIR /* for value of MAXPATHLEN */
#include "xv.h"
#include "bits/icon"
#include "bits/iconmask"
#include "bits/runicon"
#include "bits/runiconm"
#include "bits/cboard50"
#include "bits/gray25"
#include <X11/Xatom.h>
#ifdef VMS
extern Window pseudo_root();
#endif
/* program needs one of the following fonts. Trys them in ascending order */
#define FONT1 "-*-lucida-medium-r-*-*-12-*-*-*-*-*-*-*"
#define FONT2 "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*"
#define FONT3 "-*-helvetica-medium-r-*-*-11-*-*-*-*-*-*-*"
#define FONT4 "6x13"
#define FONT5 "fixed"
/* a mono-spaced font needed for the 'pixel value tracking' feature */
#define MFONT1 "-misc-fixed-medium-r-normal-*-13-*"
#define MFONT2 "6x13"
#define MFONT3 "-*-courier-medium-r-*-*-12-*"
#define MFONT4 "fixed"
/* default positions for various windows */
#define DEFINFOGEOM "-10+10" /* default position of info window */
#define DEFCTRLGEOM "+170+380" /* default position of ctrl window */
#define DEFGAMGEOM "+10-10" /* default position of gamma window */
#define DEFBROWGEOM "-10-10" /* default position of browse window */
#define DEFTEXTGEOM "-10+320" /* default position of text window */
#define DEFCMTGEOM "-10+300" /* default position of comment window */
static int revvideo = 0; /* true if we should reverse video */
static int dfltkludge = 0; /* true if we want dfltpic dithered */
static int clearonload; /* clear window/root (on colormap visuals) */
static int randomShow = 0; /* do a 'random' slideshow */
static int startIconic = 0; /* '-iconic' option */
static int defaultVis = 0; /* true if using DefaultVisual */
#ifdef HAVE_G3
static int fax = 0; /* temporary(?) kludge */
int highresfax = 0;
#endif
static double hexpand = 1.0; /* '-expand' argument */
static double vexpand = 1.0; /* '-expand' argument */
static const char *maingeom = NULL;
static const char *icongeom = NULL;
static Atom __SWM_VROOT = None;
static char basefname[128]; /* just the current fname, no path */
#ifdef TV_L10N
# ifndef TV_FONTSET
# define TV_FONTSET "-*-fixed-medium-r-normal--%d-*"
# endif
# ifndef TV_FONTSIZE
# define TV_FONTSIZE 14,16
# endif
static int mfontsize[] = { TV_FONTSIZE, 0 };
static char mfontset[256];
#endif
#ifdef HAVE_JP2K
static byte jp2k_magic[12] =
{ 0, 0, 0, 0x0c, 'j', 'P', ' ', ' ', 0x0d, 0x0a, 0x87, 0x0a };
#endif
/* things to do upon successfully loading an image */
static int autoraw = 0; /* force raw if using stdcmap */
static int autodither = 0; /* dither */
static int autosmooth = 0; /* smooth */
static int auto4x3 = 0; /* do a 4x3 */
static int autorotate = 0; /* rotate 0, +-90, +-180, +-270 */
static int autohflip = 0; /* Flip Horizontally */
static int autovflip = 0; /* Flip Vertically */
static int autocrop = 0; /* do an 'AutoCrop' command */
static int acrop = 0; /* automatically do a 'Crop' */
static int acropX, acropY, acropW, acropH;
static int autonorm = 0; /* normalize */
static int autohisteq = 0; /* Histogram equalization */
static int force8 = 0; /* force 8-bit mode */
static int force24 = 0; /* force 24-bit mode */
#ifdef HAVE_PCD
static int PcdSize = -1; /* force dialog to ask */
#endif
static float waitsec_nonfinal = -1; /* "normal" waitsec value */
static float waitsec_final = -1; /* final-image waitsec value */
/* used in DeleteCmd() and Quit() */
static char **mainargv;
static int mainargc;
/* local function pre-definitions */
int main PARM((int, char **));
static int highbit PARM((unsigned long));
static void makeDirectCmap PARM((void));
static void useOtherVisual PARM((XVisualInfo *, int));
static void parseResources PARM((int, char **));
static void parseCmdLine PARM((int, char **));
static void verifyArgs PARM((void));
static void printoption PARM((const char *));
static void cmdSyntax PARM((void));
static void rmodeSyntax PARM((void));
static int openPic PARM((int));
static int readpipe PARM((char *, char *));
static void openFirstPic PARM((void));
static void openNextPic PARM((void));
static void openNextQuit PARM((void));
static void openNextLoop PARM((void));
static void openPrevPic PARM((void));
static void openNamedPic PARM((void));
static void mainLoop PARM((void));
static void createMainWindow PARM((const char *, const char *));
static void setWinIconNames PARM((const char *));
static void makeDispNames PARM((void));
static void fixDispNames PARM((void));
static void deleteFromList PARM((int));
static int argcmp PARM((const char *, const char *,
int, int, int *));
static void add_filelist_to_namelist PARM((char *, char **, int *, int));
/* formerly local vars in main, made local to this module when
parseResources() and parseCmdLine() were split out of main() */
static int imap, ctrlmap, gmap, browmap, cmtmap, clrroot, nopos, limit2x;
static const char *histr, *lostr, *fgstr, *bgstr, *tmpstr;
static const char *infogeom, *ctrlgeom, *gamgeom, *browgeom, *textgeom, *cmtgeom;
static char *display, *whitestr, *blackstr;
static char *rootfgstr, *rootbgstr, *imagebgstr, *visualstr;
static char *monofontname, *flistName;
#ifdef TV_L10N
static char **misscharset, *defstr;
static int nmisscharset;
#endif
static int curstype, stdinflag, browseMode, savenorm, preview, pscomp, preset,
rmodeset, gamset, cgamset, perfect, owncmap, rwcolor, stdcmap;
static int nodecor;
static double gamval, rgamval, ggamval, bgamval;
/*******************************************/
int main(argc, argv)
int argc;
char **argv;
/*******************************************/
{
int i;
#ifdef TV_L10N
int j;
#endif
XColor ecdef;
Window rootReturn, parentReturn, *children;
unsigned int numChildren, rootDEEP;
#ifdef VMS
/* convert VMS-style arguments to unix names and glob */
do_vms_wildcard(&argc, &argv);
getredirection(&argc, &argv);
#endif
/*****************************************************/
/*** variable Initialization ***/
/*****************************************************/
#ifdef TV_L10N
/* setlocale(LC_ALL, localeList[LOCALE_EUCJ]); */
setlocale(LC_ALL, "");
xlocale = (int)XSupportsLocale(); /* assume that (Bool) is (int) */
/* if X doesn't support ja_JP.ujis text viewer l10n doesn't work. */
#endif
xv_getwd(initdir, sizeof(initdir));
searchdir[0] = '\0';
fullfname[0] = '\0';
mainargv = argv;
mainargc = argc;
/* init internal variables */
display = NULL;
fgstr = bgstr = rootfgstr = rootbgstr = imagebgstr = NULL;
histr = lostr = whitestr = blackstr = NULL;
visualstr = monofontname = flistName = NULL;
winTitle = NULL;
pic = egampic = epic = cpic = NULL;
theImage = NULL;
picComments = (char *) NULL;
if (picExifInfo) free(picExifInfo);
picExifInfo = (byte *) NULL;
picExifInfoSize = 0;
numPages = 1; curPage = 0;
pageBaseName[0] = '\0';
LocalCmap = browCmap = 0;
stdinflag = 0;
autoclose = autoDelete = 0;
cmapInGam = 0;
grabDelay = 0;
startGrab = 0;
showzoomcursor = 0;
perfect = owncmap = stdcmap = rwcolor = 0;
ignoreConfigs = 0;
browPerfect = 1;
gamval = rgamval = ggamval = bgamval = 1.0;
picType = -1; /* gets set once file is loaded */
colorMapMode = CM_NORMAL;
haveStdCmap = STD_NONE;
allocMode = AM_READONLY;
novbrowse = 0;
#ifndef VMS
strcpy(printCmd, "lpr");
#else
strcpy(printCmd, "Print /Queue = XV_Queue");
#endif
forceClipFile = 0;
clearR = clearG = clearB = 0;
InitSelection();
/* default Ghostscript parameters */
gsDev = "ppmraw";
#ifdef GS_DEV
gsDev = GS_DEV;
#endif
gsRes = 72;
gsGeomStr = NULL;
/* init default colors */
fgstr = "#000000"; bgstr = "#B2C0DC";
histr = "#C6D5E2"; lostr = "#8B99B5";
cmd = (char *) rindex(argv[0],'/');
if (!cmd) cmd = argv[0]; else cmd++;
tmpstr = (const char *) getenv("TMPDIR");
if (!tmpstr) tmpstr = "/tmp";
tmpdir = (char *) malloc(strlen(tmpstr) + 1);
if (!tmpdir) FatalError("can't malloc 'tmpdir'\n");
strcpy(tmpdir, tmpstr);
#ifdef AUTO_EXPAND
Vdinit();
vd_handler_setup();
#endif
/* init command-line options flags */
infogeom = DEFINFOGEOM; ctrlgeom = DEFCTRLGEOM;
gamgeom = DEFGAMGEOM; browgeom = DEFBROWGEOM;
textgeom = DEFTEXTGEOM; cmtgeom = DEFCMTGEOM;
ncols = -1; mono = 0;
ninstall = 0; fixedaspect = 0; noFreeCols = nodecor = 0;
DEBUG = 0; bwidth = 2;
nolimits = useroot = clrroot = noqcheck = 0;
waitsec = waitsec_final = -1.0; waitloop = 0; automax = 0;
rootMode = 0; hsvmode = 0;
rmodeset = gamset = cgamset = 0;
nopos = limit2x = 0;
resetroot = 1;
clearonload = 0;
curstype = XC_top_left_arrow;
browseMode = savenorm = nostat = 0;
preview = 0;
pscomp = 0;
preset = 0;
viewonly = 0;
#ifdef ENABLE_FIXPIX_SMOOTH
do_fixpix_smooth = 0;
#endif
/* init 'xormasks' array */
xorMasks[0] = 0x01010101;
xorMasks[1] = 0x02020203;
xorMasks[2] = 0x84848485;
xorMasks[3] = 0x88888889;
xorMasks[4] = 0x10101011;
xorMasks[5] = 0x20202023;
xorMasks[6] = 0xc4c4c4c5;
xorMasks[7] = 0xffffffff;
kludge_offx = kludge_offy = winCtrPosKludge = 0;
conv24 = CONV24_SLOW; /* use 'slow' algorithm by default */
defaspect = normaspect = 1.0;
mainW = dirW = infoW = ctrlW = gamW = psW = (Window) NULL;
anyBrowUp = 0;
incrementalSearchTimeout = 30;
#ifdef HAVE_JPEG
jpegW = (Window) NULL; jpegUp = 0;
#endif
#ifdef HAVE_JP2K
jp2kW = (Window) NULL; jp2kUp = 0;
#endif
#ifdef HAVE_TIFF
tiffW = (Window) NULL; tiffUp = 0;
#endif
#ifdef HAVE_PNG
pngW = (Window) NULL; pngUp = 0;
#endif
pcdW = (Window) NULL; pcdUp = 0;
#ifdef HAVE_PIC2
pic2W = (Window) NULL; pic2Up = 0;
#endif
#ifdef HAVE_PCD
pcdW = (Window) NULL; pcdUp = 0;
#endif
#ifdef HAVE_MGCSFX
mgcsfxW = (Window) NULL; mgcsfxUp = 0;
#endif
imap = ctrlmap = gmap = browmap = cmtmap = 0;
ch_offx = ch_offy = p_offx = p_offy = 0;
/* init info box variables */
infoUp = 0;
infoMode = INF_STR;
for (i=0; i<NISTR; i++) SetISTR(i,"");
/* init ctrl box variables */
ctrlUp = 0;
curname = -1;
formatStr[0] ='\0';
gamUp = 0;
psUp = 0;
Init24to8();
/* handle user-specified resources and cmd-line arguments */
parseResources(argc,argv);
parseCmdLine(argc, argv);
verifyArgs();
#if 0
#ifdef XVEXECPATH
/* set up path to search for external executables */
{
char *systempath = getenv("PATH");
char *xvexecpath = getenv("XVPATH");
if (xvexecpath == NULL) xvexecpath = XVEXECPATH;
/* FIXME: can systempath == NULL? */
strcat(systempath, ":"); /* FIXME: writing to mem we don't own */
strcat(systempath, xvexecpath); /* FIXME: writing to mem we don't own */
/* FIXME: was there supposed to be a setenv() call in here? */
if (DEBUG)
fprintf(stderr, "DEBUG: executable search path: %s\n", systempath);
}
#endif
#endif
/*****************************************************/
/*** X Setup ***/
/*****************************************************/
theScreen = DefaultScreen(theDisp);
theCmap = DefaultColormap(theDisp, theScreen);
if (spec_window) {
rootW = spec_window;
} else {
rootW = RootWindow(theDisp,theScreen);
}
theGC = DefaultGC(theDisp,theScreen);
theVisual = DefaultVisual(theDisp,theScreen);
ncells = DisplayCells(theDisp, theScreen);
dispDEEP = DisplayPlanes(theDisp,theScreen);
maxWIDE = vrWIDE = dispWIDE = DisplayWidth(theDisp,theScreen);
maxHIGH = vrHIGH = dispHIGH = DisplayHeight(theDisp,theScreen);
rootDEEP = dispDEEP;
/* things dependent on theVisual:
* dispDEEP, theScreen, rootW, ncells, theCmap, theGC,
* vrWIDE, dispWIDE, vrHIGH, dispHIGH, maxWIDE, maxHIGH
*/
/* if we *haven't* had a non-default visual specified,
see if we have a TrueColor or DirectColor visual of 24 or 32 bits,
and if so, use that as the default visual (prefer TrueColor) */
if (!visualstr && !useroot) {
VisualID defvid;
XVisualInfo *vinfo, rvinfo;
int best, numvis;
long flags;
best = -1;
rvinfo.class = TrueColor;
rvinfo.screen = theScreen;
flags = VisualClassMask | VisualScreenMask;
defvid = XVisualIDFromVisual(DefaultVisual(theDisp,
DefaultScreen(theDisp)));
vinfo = XGetVisualInfo(theDisp, flags, &rvinfo, &numvis);
if (vinfo) {
/* Check list, use 'default', first 24-bit, or first >24-bit */
for (i=0; i<numvis && best==-1; i++) { /* default? */
if ((vinfo[i].visualid == defvid) && (vinfo[i].depth >= 24)) best=i;
}
for (i=0; i<numvis && best==-1; i++) { /* 24-bit ? */
if (vinfo[i].depth == 24) best = i;
}
for (i=0; i<numvis && best==-1; i++) { /* >24-bit ? */
if (vinfo[i].depth >= 24) best = i;
}
}
if (best == -1) { /* look for a DirectColor, 24-bit or more (pref 24) */
rvinfo.class = DirectColor;
if (vinfo) XFree((char *) vinfo);
vinfo = XGetVisualInfo(theDisp, flags, &rvinfo, &numvis);
if (vinfo) {
for (i=0; i<numvis && best==-1; i++) { /* default? */
if ((vinfo[i].visualid == defvid) && (vinfo[i].depth >= 24)) best=i;
}
for (i=0; i<numvis && best==-1; i++) { /* 24-bit ? */
if (vinfo[i].depth == 24) best = i;
}
for (i=0; i<numvis && best==-1; i++) { /* >24-bit ? */
if (vinfo[i].depth >= 24) best = i;
}
}
}
if (best>=0 && best<numvis) useOtherVisual(vinfo, best);
if (vinfo) XFree((char *) vinfo);
}
if (visualstr && useroot) {
fprintf(stderr, "%s: %sUsing default visual.\n",
cmd, "Warning: Can't use specified visual on root. ");
visualstr = NULL;
}
if (visualstr && !useroot) { /* handle non-default visual */
int vclass = -1;
int vid = -1;
lower_str(visualstr);
if (!strcmp(visualstr,"staticgray")) vclass = StaticGray;
else if (!strcmp(visualstr,"staticcolor")) vclass = StaticColor;
else if (!strcmp(visualstr,"truecolor")) vclass = TrueColor;
else if (!strcmp(visualstr,"grayscale")) vclass = GrayScale;
else if (!strcmp(visualstr,"pseudocolor")) vclass = PseudoColor;
else if (!strcmp(visualstr,"directcolor")) vclass = DirectColor;
else if (!strcmp(visualstr,"default")) {} /* recognize it as valid */
else if (!strncmp(visualstr,"0x",(size_t) 2)) { /* specified visual id */
if (sscanf(visualstr, "0x%x", &vid) != 1) vid = -1;
}
else {
fprintf(stderr,"%s: Unrecognized visual type '%s'. %s\n",
cmd, visualstr, "Using server default.");
}
/* if 'default', vclass and vid will both be '-1' */
if (vclass >= 0 || vid >= 0) { /* try to find asked-for visual type */
XVisualInfo *vinfo, rvinfo;
long vinfomask;
int numvis, best;
if (vclass >= 0) {
rvinfo.class = vclass; vinfomask = VisualClassMask;
}
else { rvinfo.visualid = vid; vinfomask = VisualIDMask; }
rvinfo.screen = theScreen;
vinfomask |= VisualScreenMask;
vinfo = XGetVisualInfo(theDisp, vinfomask, &rvinfo, &numvis);
if (vinfo) { /* choose the 'best' one, if multiple */
for (i=0, best = 0; i<numvis; i++) {
if (vinfo[i].depth > vinfo[best].depth) best = i;
}
useOtherVisual(vinfo, best);
XFree((char *) vinfo);
}
else fprintf(stderr,"%s: Visual type '%s' not available. %s\n",
cmd, visualstr, "Using server default.");
}
}
/* make linear colormap for DirectColor visual */
if (theVisual->class == DirectColor) makeDirectCmap();
defaultVis = (XVisualIDFromVisual(theVisual) ==
XVisualIDFromVisual(DefaultVisual(theDisp, DefaultScreen(theDisp))));
/* turn GraphicsExposures OFF in the default GC */
{
XGCValues xgcv;
xgcv.graphics_exposures = False;
XChangeGC(theDisp, theGC, GCGraphicsExposures, &xgcv);
}
XSetErrorHandler(xvErrorHandler);
/* always search for virtual root window */
vrootW = rootW;
#ifndef VMS
__SWM_VROOT = XInternAtom(theDisp, "__SWM_VROOT", False);
XQueryTree(theDisp, rootW, &rootReturn, &parentReturn, &children,
&numChildren);
for (i = 0; i < numChildren; i++) {
Atom actual_type;
int actual_format;
unsigned long nitems, bytesafter;
byte *newRoot = NULL; /* byte instead of Window avoids type-pun warning */
XWindowAttributes xwa;
if (XGetWindowProperty (theDisp, children[i], __SWM_VROOT, 0L, 1L,
False, XA_WINDOW, &actual_type, &actual_format, &nitems,
&bytesafter, (unsigned char **) &newRoot) == Success && newRoot) {
vrootW = *(Window *)newRoot;
XGetWindowAttributes(theDisp, vrootW, &xwa);
maxWIDE = vrWIDE = xwa.width; maxHIGH = vrHIGH = xwa.height;
dispDEEP = xwa.depth;
break;
}
}
#else /* VMS */
vrootW = pseudo_root(theDisp, theScreen);
#endif
if (!useroot && limit2x) { maxWIDE *= 2; maxHIGH *= 2; }
if (nolimits) { maxWIDE = 65000; maxHIGH = 65000; }
if (clrroot || useroot) {
/* have enough info to do a '-clear' now */
KillOldRootInfo(); /* if any */
if (resetroot || clrroot) ClearRoot(); /* don't clear on '-noresetroot' */
if (clrroot) Quit(0);
}
arrow = XCreateFontCursor(theDisp,(u_int) curstype);
cross = XCreateFontCursor(theDisp,XC_crosshair);
tcross = XCreateFontCursor(theDisp,XC_tcross);
tlcorner = XCreateFontCursor(theDisp,XC_top_left_corner);
zoom = XCreateFontCursor(theDisp,XC_sizing);
{
XColor fc, bc;
fc.red = fc.green = fc.blue = 0xffff;
bc.red = bc.green = bc.blue = 0x0000;
XRecolorCursor(theDisp, zoom, &fc, &bc);
}
{ /* create inviso cursor */
Pixmap pix;
static char bits[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
XColor cfg;
cfg.red = cfg.green = cfg.blue = 0;
pix = XCreateBitmapFromData(theDisp, rootW, bits, 8, 8);
inviso = XCreatePixmapCursor(theDisp, pix, pix, &cfg, &cfg, 0,0);
XFreePixmap(theDisp, pix);
}
/* set up white,black colors */
whtRGB = 0xffffff; blkRGB = 0x000000;
if (defaultVis) {
white = WhitePixel(theDisp,theScreen);
black = BlackPixel(theDisp,theScreen);
}
else {
ecdef.flags = DoRed | DoGreen | DoBlue;
ecdef.red = ecdef.green = ecdef.blue = 0xffff;
if (xvAllocColor(theDisp, theCmap, &ecdef)) white = ecdef.pixel;
else white = 0xffffffff; /* probably evil... */
ecdef.red = ecdef.green = ecdef.blue = 0x0000;
if (xvAllocColor(theDisp, theCmap, &ecdef)) black = ecdef.pixel;
else black = 0x00000000; /* probably evil... */
}
if (whitestr && XParseColor(theDisp, theCmap, whitestr, &ecdef) &&
xvAllocColor(theDisp, theCmap, &ecdef)) {
white = ecdef.pixel;
whtRGB = ((ecdef.red>>8)<<16) | (ecdef.green&0xff00) | (ecdef.blue>>8);
}
if (blackstr && XParseColor(theDisp, theCmap, blackstr, &ecdef) &&
xvAllocColor(theDisp, theCmap, &ecdef)) {
black = ecdef.pixel;
blkRGB = ((ecdef.red>>8)<<16) | (ecdef.green&0xff00) | (ecdef.blue>>8);
}
/* set up fg,bg colors */
fg = black; bg = white;
if (fgstr && XParseColor(theDisp, theCmap, fgstr, &ecdef) &&
xvAllocColor(theDisp, theCmap, &ecdef)) {
fg = ecdef.pixel;
}
if (bgstr && XParseColor(theDisp, theCmap, bgstr, &ecdef) &&
xvAllocColor(theDisp, theCmap, &ecdef)) {
bg = ecdef.pixel;
}
/* set up root fg,bg colors */
rootfg = white; rootbg = black;
if (rootfgstr && XParseColor(theDisp, theCmap, rootfgstr, &ecdef) &&
xvAllocColor(theDisp, theCmap, &ecdef)) rootfg = ecdef.pixel;
if (rootbgstr && XParseColor(theDisp, theCmap, rootbgstr, &ecdef) &&
xvAllocColor(theDisp, theCmap, &ecdef)) rootbg = ecdef.pixel;
/* GRR 19980308: set up image bg color (for transparent images) */
have_imagebg = 0;
if (imagebgstr && XParseColor(theDisp, theCmap, imagebgstr, &ecdef) &&
xvAllocColor(theDisp, theCmap, &ecdef)) {
/* imagebg = ecdef.pixel; */
have_imagebg = 1;
imagebgR = ecdef.red;
imagebgG = ecdef.green;
imagebgB = ecdef.blue;
}
/* set up hi/lo colors */
i=0;
if (dispDEEP > 1) { /* only if we're on a reasonable display */
if (histr && XParseColor(theDisp, theCmap, histr, &ecdef) &&
xvAllocColor(theDisp, theCmap, &ecdef)) { hicol = ecdef.pixel; i|=1; }
if (lostr && XParseColor(theDisp, theCmap, lostr, &ecdef) &&
xvAllocColor(theDisp, theCmap, &ecdef)) { locol = ecdef.pixel; i|=2; }
}
if (i==0) ctrlColor = 0;
else if (i==3) ctrlColor = 1;
else { /* only got some of them */
if (i&1) xvFreeColors(theDisp, theCmap, &hicol, 1, 0L);
if (i&2) xvFreeColors(theDisp, theCmap, &locol, 1, 0L);
ctrlColor = 0;
}
if (!ctrlColor) { hicol = bg; locol = fg; }
XSetForeground(theDisp,theGC,fg);
XSetBackground(theDisp,theGC,bg);
infofg = fg; infobg = bg;
/* if '-mono' not forced, determine if we're on a grey or color monitor */
if (!mono) {
if (theVisual->class == StaticGray || theVisual->class == GrayScale)
mono = 1;
}
iconPix = MakePix1(rootW, icon_bits, icon_width, icon_height);
iconmask = MakePix1(rootW, iconmask_bits, icon_width, icon_height);
riconPix = MakePix1(rootW, runicon_bits, runicon_width, runicon_height);
riconmask= MakePix1(rootW, runiconm_bits, runiconm_width,runiconm_height);
if (!iconPix || !iconmask || !riconPix || !riconmask)
FatalError("Unable to create icon pixmaps\n");
gray50Tile = XCreatePixmapFromBitmapData(theDisp, rootW,
(char *) cboard50_bits,
cboard50_width, cboard50_height,
infofg, infobg, dispDEEP);
if (!gray50Tile) FatalError("Unable to create gray50Tile bitmap\n");
gray25Tile = XCreatePixmapFromBitmapData(theDisp, rootW,
(char *) gray25_bits,
gray25_width, gray25_height,
infofg, infobg, dispDEEP);
if (!gray25Tile) FatalError("Unable to create gray25Tile bitmap\n");
/* try to load fonts */
if ( (mfinfo = XLoadQueryFont(theDisp,FONT1))==NULL &&
(mfinfo = XLoadQueryFont(theDisp,FONT2))==NULL &&
(mfinfo = XLoadQueryFont(theDisp,FONT3))==NULL &&
(mfinfo = XLoadQueryFont(theDisp,FONT4))==NULL &&
(mfinfo = XLoadQueryFont(theDisp,FONT5))==NULL) {
sprintf(dummystr,
"couldn't open the following fonts:\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s",
FONT1, FONT2, FONT3, FONT4, FONT5);
FatalError(dummystr);
}
mfont=mfinfo->fid;
XSetFont(theDisp,theGC,mfont);
monofinfo = (XFontStruct *) NULL;
if (monofontname) {
monofinfo = XLoadQueryFont(theDisp, monofontname);
if (!monofinfo) fprintf(stderr,"xv: unable to load font '%s'\n",
monofontname);
}
if (!monofinfo) {
if ((monofinfo = XLoadQueryFont(theDisp,MFONT1))==NULL &&
(monofinfo = XLoadQueryFont(theDisp,MFONT2))==NULL &&
(monofinfo = XLoadQueryFont(theDisp,MFONT3))==NULL &&
(monofinfo = XLoadQueryFont(theDisp,MFONT4))==NULL) {
sprintf(dummystr,"couldn't open %s fonts:\n\t%s\n\t%s\n\t%s\n\t%s",
"any of the following",
MFONT1, MFONT2, MFONT3, MFONT4);
FatalError(dummystr);
}
}
monofont=monofinfo->fid;
#ifdef TV_L10N
if (xlocale) {
i = 0;
while (mfontsize[i]) {
xlocale = 1; /* True */
sprintf(mfontset, TV_FONTSET, mfontsize[i]);
/*fprintf(stderr, "FontSet: %s\n", mfontset);*/
monofset = XCreateFontSet(theDisp, mfontset,
&misscharset, &nmisscharset, &defstr);
# if 0 /* not useful */
if (!monofset) {
/* the current locale is not supported */
/*fprintf(stderr, "Current locale `%s' is not supported.\n", localeList[i]);*/
xlocale = 0;
break;
}
# endif
/*fprintf(stderr, "# of misscharset in mfontsize[%d]: %d\n", i,nmisscharset);*/
for (j = 0; j < nmisscharset; j++) {
if (!strncmp(misscharset[j], "jisx0208", 8)) {
/* font for JIS X 0208 is not found */
xlocale = 0;
break;
}
}
if (xlocale) {
monofsetinfo = XExtentsOfFontSet(monofset);
monofsetinfo->max_logical_extent.width = mfontsize[i];
/* correct size of TextViewer
in case that JIS X 0208 is not found */
break;
}
i++;
} /* while (mfontsize[i]) */
# if 0
if (nmisscharset > 0) {
sprintf(dummystr,"missing %d charset:\n", nmisscharset);
for (i = 0; i < nmisscharset; i++) {
sprintf(dummystr, "%s\t%s\n", dummystr, misscharset[i]);
}
# if 0
FatalError(dummystr);
# else
fprintf(stderr, "%s", dummystr);
# endif
}
# endif
}
#endif /* TV_L10N */
/* if ncols wasn't set, set it to 2^dispDEEP, unless dispDEEP=1, in which
case ncols = 0; (ncols = max number of colors allocated. on 1-bit
displays, no colors are allocated */
if (ncols == -1) {
if (dispDEEP>1) ncols = 1 << ((dispDEEP>8) ? 8 : dispDEEP);
else ncols = 0;
}
else if (ncols>256) ncols = 256; /* so program doesn't blow up */
GenerateFSGamma(); /* has to be done before 'OpenBrowse()' is called */
/* no filenames. build one-name (stdio) list (if stdinflag) */
if (numnames==0) {
if (stdinflag) {
/* have to malloc namelist[0] so we can free it in deleteFromList() */
namelist[0] = (char *) malloc(strlen(STDINSTR) + 1);
if (!namelist[0]) FatalError("unable to to build namelist[0]");
strcpy(namelist[0], STDINSTR);
numnames = 1;
}
else namelist[0] = NULL;
}
else if (randomShow) {
int i, j;
char *tmp;
srandom((int)time((time_t *)0));
for (i = numnames; i > 1; i--) {
j = random() % i;
tmp = namelist[i-1];
namelist[i-1] = namelist[j];
namelist[j] = tmp;
}
}
if (numnames) makeDispNames();
if (viewonly || autoquit) {
imap = ctrlmap = gmap = browmap = cmtmap = 0;
novbrowse = 1;
}
/* create the info box window */
CreateInfo(infogeom);
XSelectInput(theDisp, infoW, ExposureMask | ButtonPressMask | KeyPressMask
| StructureNotifyMask);
InfoBox(imap); /* map it (or not) */
if (imap) {
RedrawInfo(0,0,1000,1000); /* explicit draw if mapped */
XFlush(theDisp);
}
/* create the control box window */
CreateCtrl(ctrlgeom);
epicMode = EM_RAW; SetEpicMode();
XSelectInput(theDisp, ctrlW, ExposureMask | ButtonPressMask | KeyPressMask
| StructureNotifyMask);
if (ctrlmap < 0) { /* map iconified */
XWMHints xwmh;
xwmh.input = True;
xwmh.initial_state = IconicState;
xwmh.flags = (InputHint | StateHint);
XSetWMHints(theDisp, ctrlW, &xwmh);
ctrlmap = 1;
}
CtrlBox(ctrlmap); /* map it (or not) */
if (ctrlmap) {
RedrawCtrl(0,0,1000,1000); /* explicit draw if mapped */
XFlush(theDisp);
}
fixDispNames();
ChangedCtrlList();
/* disable root modes if using non-default visual */
if (!defaultVis) {
for (i=RMB_ROOT; i<RMB_MAX; i++) rootMB.dim[i] = 1;
}
/* create the directory window */
CreateDirW(NULL);
XSelectInput(theDisp, dirW, ExposureMask | ButtonPressMask | KeyPressMask);
browseCB.val = browseMode;
savenormCB.val = savenorm;
/* create the gamma window */
CreateGam(gamgeom, (gamset) ? gamval : -1.0,
(cgamset) ? rgamval : -1.0,
(cgamset) ? ggamval : -1.0,
(cgamset) ? bgamval : -1.0,
preset);
XSelectInput(theDisp, gamW, ExposureMask | ButtonPressMask | KeyPressMask
| StructureNotifyMask
| (cmapInGam ? ColormapChangeMask : 0));
GamBox(gmap); /* map it (or not) */
stdnfcols = 0; /* so we don't try to free any if we don't create any */
if (!novbrowse) {
MakeBrowCmap();
/* create the visual browser window */
CreateBrowse(browgeom, fgstr, bgstr, histr, lostr);
if (browmap) OpenBrowse();
}
else windowMB.dim[WMB_BROWSE] = 1; /* disable visual schnauzer */
CreateTextWins(textgeom, cmtgeom);
if (cmtmap) OpenCommentText();
/* create the ps window */
CreatePSD(NULL);
XSetTransientForHint(theDisp, psW, dirW);
encapsCB.val = preview;
pscompCB.val = pscomp;
#ifdef HAVE_JPEG
CreateJPEGW();
XSetTransientForHint(theDisp, jpegW, dirW);
#endif
#ifdef HAVE_JP2K
CreateJP2KW();
XSetTransientForHint(theDisp, jp2kW, dirW);
#endif
#ifdef HAVE_TIFF
CreateTIFFW();
XSetTransientForHint(theDisp, tiffW, dirW);
#endif
#ifdef HAVE_PNG
CreatePNGW();
XSetTransientForHint(theDisp, pngW, dirW);
#endif
#ifdef HAVE_PCD
CreatePCDW();
XSetTransientForHint(theDisp, pcdW, dirW);
#endif
#ifdef HAVE_PIC2
CreatePIC2W();
XSetTransientForHint(theDisp, pic2W, dirW);
#endif
#ifdef HAVE_MGCSFX
CreateMGCSFXW();
XSetTransientForHint(theDisp, mgcsfxW, dirW);
#endif
LoadFishCursors();
SetCursors(-1);