Added
Link Here
|
1 |
--- xv.c |
2 |
+++ xv.c 2003-01-27 00:03:36.000000000 +0100 |
3 |
@@ -146,9 +146,7 @@ |
4 |
rmodeset, gamset, cgamset, perfect, owncmap, rwcolor, stdcmap; |
5 |
int nodecor; |
6 |
double gamval, rgamval, ggamval, bgamval; |
7 |
- |
8 |
- |
9 |
- |
10 |
+winRepositionningInfoST winRepositionningInfo = { 0, 0}; |
11 |
|
12 |
/*******************************************/ |
13 |
int main(argc, argv) |
14 |
@@ -2125,6 +2145,7 @@ |
15 |
/* if the file is STDIN, write it out to a temp file */ |
16 |
|
17 |
if (strcmp(filename,STDINSTR)==0) { |
18 |
+ int tmpfd; |
19 |
FILE *fp; |
20 |
|
21 |
#ifndef VMS |
22 |
@@ -2135,11 +2156,15 @@ |
23 |
mktemp(filename); |
24 |
|
25 |
clearerr(stdin); |
26 |
- fp = fopen(filename,"w"); |
27 |
+ tmpfd = open(filename,O_WRONLY|O_CREAT|O_EXCL,S_IRWUSR); |
28 |
+ if (tmpfd < 0) FatalError("openPic(): can't create temporary file"); |
29 |
+ fp = fdopen(tmpfd,"w"); |
30 |
if (!fp) FatalError("openPic(): can't write temporary file"); |
31 |
|
32 |
while ( (i=getchar()) != EOF) putc(i,fp); |
33 |
+ fflush(fp); |
34 |
fclose(fp); |
35 |
+ close(tmpfd); |
36 |
|
37 |
/* and remove it from list, since we can never reload from stdin */ |
38 |
if (strcmp(namelist[0], STDINSTR)==0) deleteFromList(0); |
39 |
@@ -2672,7 +2697,11 @@ |
40 |
to generate the correct exposes (particularly with 'BitGravity' turned |
41 |
on */ |
42 |
|
43 |
- if (mainW && !useroot) GenExpose(mainW, 0, 0, (u_int) eWIDE, (u_int) eHIGH); |
44 |
+ /*Brian T. Schellenberger: fix for X 4.2 refresh problem*/ |
45 |
+ if (mainW && !useroot) { |
46 |
+ XSync(theDisp, False); |
47 |
+ GenExpose(mainW, 0, 0, (u_int) eWIDE, (u_int) eHIGH); |
48 |
+ } |
49 |
|
50 |
return 1; |
51 |
|
52 |
@@ -2812,7 +2846,8 @@ |
53 |
|
54 |
#ifdef GS_PATH |
55 |
else if (strncmp((char *) magicno, "%!", (size_t) 2)==0 || |
56 |
- strncmp((char *) magicno, "\004%!", (size_t) 3)==0) rv = RFT_PS; |
57 |
+ strncmp((char *) magicno, "\004%!", (size_t) 3)==0 || |
58 |
+ strncmp((char *) magicno, "%PDF", (size_t) 4)==0) rv = RFT_PS; |
59 |
#endif |
60 |
|
61 |
#ifdef HAVE_MAG |
62 |
@@ -2959,6 +2998,7 @@ |
63 |
returns '0' on failure */ |
64 |
|
65 |
char namez[128], *fname, buf[512]; |
66 |
+ int tmpfd; |
67 |
|
68 |
fname = name; |
69 |
namez[0] = '\0'; |
70 |
@@ -3047,15 +3090,18 @@ |
71 |
char *src, *dst; |
72 |
{ |
73 |
char tmpname[128], buffer[8192]; /* XXX */ |
74 |
- int n, eof; |
75 |
+ int n, eof, tmpfd; |
76 |
FILE *sfp, *dfp; |
77 |
|
78 |
sprintf(dst, "%s/xvmXXXXXX", tmpdir); |
79 |
mktemp(dst); |
80 |
+ tmpfd = open(dst,O_WRONLY|O_CREAT|O_EXCL,S_IRWUSR); |
81 |
+ if (tmpfd < 0) FatalError("RemoveMacbinary(): can't create temporary file"); |
82 |
+ |
83 |
SetISTR(ISTR_INFO, "Removing MacBinary..."); |
84 |
|
85 |
sfp = xv_fopen(src, "r"); |
86 |
- dfp = xv_fopen(dst, "w"); |
87 |
+ dfp = fdopen(tmpfd, "w"); |
88 |
if (!sfp || !dfp) { |
89 |
SetISTR(ISTR_INFO, "Unable to remove a InfoFile header form '%s'.", src); |
90 |
Warning(); |
91 |
@@ -3067,7 +3113,9 @@ |
92 |
if (eof = feof(sfp)) |
93 |
fwrite(buffer, 1, n, dfp); |
94 |
fclose(sfp); |
95 |
+ fflush(dfp); |
96 |
fclose(dfp); |
97 |
+ close(tmpfd); |
98 |
if (!eof) { |
99 |
SetISTR(ISTR_INFO, "Unable to remove a InfoFile header form '%s'.", src); |
100 |
Warning(); |
101 |
@@ -3199,7 +3247,7 @@ |
102 |
*/ |
103 |
|
104 |
char fullcmd[512], tmpname[64], str[512]; |
105 |
- int i; |
106 |
+ int i, tmpfd; |
107 |
|
108 |
if (!cmd || (strlen(cmd) < (size_t) 2)) return 1; |
109 |
|
110 |
@@ -3210,6 +3258,9 @@ |
111 |
ErrPopUp(str, "\nHow unlikely!"); |
112 |
return 1; |
113 |
} |
114 |
+ tmpfd = open(tmpname,O_WRONLY|O_CREAT|O_EXCL,S_IRWUSR); |
115 |
+ if (tmpfd < 0) FatalError("openPic(): can't create temporary file"); |
116 |
+ close(tmpfd); |
117 |
|
118 |
/* build command */ |
119 |
strcpy(fullcmd, cmd+1); /* skip the leading '!' character in cmd */ |
120 |
--- xv.h |
121 |
+++ xv.h 2003-01-27 00:03:36.000000000 +0100 |
122 |
@@ -310,7 +294,9 @@ |
123 |
# endif |
124 |
#endif |
125 |
|
126 |
- |
127 |
+#ifndef S_IRWUSR |
128 |
+# define S_IRWUSR (S_IRUSR|S_IWRITE) |
129 |
+#endif |
130 |
|
131 |
#ifndef MAXPATHLEN |
132 |
# define MAXPATHLEN 256 |
133 |
@@ -813,6 +811,13 @@ |
134 |
#define WHERE |
135 |
#endif |
136 |
|
137 |
+/* Needed for repositionning with negative geometries */ |
138 |
+typedef struct { |
139 |
+ int negativeX; |
140 |
+ int negativeY; |
141 |
+} winRepositionningInfoST; |
142 |
+extern winRepositionningInfoST winRepositionningInfo; |
143 |
+ |
144 |
typedef unsigned char byte; |
145 |
|
146 |
typedef struct scrl { |
147 |
--- xvdir.c |
148 |
+++ xvdir.c 2003-01-27 00:03:36.000000000 +0100 |
149 |
@@ -80,7 +83,7 @@ |
150 |
"PIC", |
151 |
#endif /* HAVE_PIC */ |
152 |
#ifdef HAVE_MAKI |
153 |
- "MAKI", |
154 |
+ "MAKI (640x400 only)", |
155 |
#endif /* HAVE_MAKI */ |
156 |
#ifdef HAVE_PI |
157 |
"PI", |
158 |
--- xvevent.c |
159 |
+++ xvevent.c 2003-01-27 00:03:36.000000000 +0100 |
160 |
@@ -64,6 +64,8 @@ |
161 |
|
162 |
static void annotatePic PARM((void)); |
163 |
|
164 |
+static int debkludge_offx; |
165 |
+static int debkludge_offy; |
166 |
|
167 |
/****************/ |
168 |
int EventLoop() |
169 |
@@ -676,6 +694,29 @@ |
170 |
p_offy = xwa.y; |
171 |
} |
172 |
|
173 |
+ /* Gather info to keep right border inside */ |
174 |
+ { |
175 |
+ Window current; |
176 |
+ Window root_r; |
177 |
+ Window parent_r; |
178 |
+ Window *children_r; |
179 |
+ int nchildren_r; |
180 |
+ XWindowAttributes xwa; |
181 |
+ |
182 |
+ parent_r=mainW; |
183 |
+ current=mainW; |
184 |
+ do { |
185 |
+ current=parent_r; |
186 |
+ XQueryTree(theDisp, current, &root_r, &parent_r, |
187 |
+ &children_r, &nchildren_r); |
188 |
+ if (children_r!=NULL) { |
189 |
+ XFree(children_r); |
190 |
+ } |
191 |
+ } while(parent_r!=root_r); |
192 |
+ XGetWindowAttributes(theDisp, current, &xwa); |
193 |
+ debkludge_offx=eWIDE-xwa.width+p_offx; |
194 |
+ debkludge_offy=eHIGH-xwa.height+p_offy; |
195 |
+ } |
196 |
|
197 |
/* move window around a bit... */ |
198 |
{ |
199 |
@@ -2078,6 +2127,26 @@ |
200 |
if (xwa->width < dispWIDE && xwc.x < p_offx) xwc.x = p_offx; |
201 |
if (xwa->height < dispHIGH && xwc.y < p_offy) xwc.y = p_offy; |
202 |
|
203 |
+ /* Try to keep bottom right decorations inside */ |
204 |
+ if (xwc.x+eWIDE-debkludge_offx>dispWIDE) { |
205 |
+ xwc.x=dispWIDE-eWIDE+debkludge_offx; |
206 |
+ if (xwc.x<0) xwc.x=0; |
207 |
+ } |
208 |
+ if (xwc.y+eHIGH-debkludge_offy>dispHIGH) { |
209 |
+ xwc.y=dispHIGH-eHIGH+debkludge_offy; |
210 |
+ if (xwc.y<0) xwc.y=0; |
211 |
+ } |
212 |
+ |
213 |
+ /* In case of negative offset for first image */ |
214 |
+ if (winRepositionningInfo.negativeX) { |
215 |
+ xwc.x+=winRepositionningInfo.negativeX; |
216 |
+ winRepositionningInfo.negativeX=0; |
217 |
+ } |
218 |
+ if (winRepositionningInfo.negativeY) { |
219 |
+ xwc.y+=winRepositionningInfo.negativeY; |
220 |
+ winRepositionningInfo.negativeY=0; |
221 |
+ } |
222 |
+ |
223 |
xwc.width = xwa->width; |
224 |
xwc.height = xwa->height; |
225 |
|
226 |
--- xvfits.c |
227 |
+++ xvfits.c 2003-01-27 00:03:36.000000000 +0100 |
228 |
@@ -14,7 +14,7 @@ |
229 |
* provided "as is" without express or implied warranty. |
230 |
*/ |
231 |
|
232 |
- |
233 |
+#define NEEDSDIR /* for S_IRUSR|S_IWUSR */ |
234 |
#include "xv.h" |
235 |
|
236 |
#define NCARDS (36) |
237 |
@@ -223,7 +223,7 @@ |
238 |
* If there was a problem writing files, then a error message will be set. |
239 |
*/ |
240 |
|
241 |
- int i, np=nx * ny, ioerror, nwrt; |
242 |
+ int i, np=nx * ny, ioerror, nwrt, tmpfd; |
243 |
FILE *fp; |
244 |
char *error; |
245 |
byte *work; |
246 |
@@ -246,7 +246,12 @@ |
247 |
|
248 |
for (i=0; i < nz && !error; i++) { |
249 |
sprintf(filename, "%s%d", basename, i+1); |
250 |
- fp = xv_fopen(filename, "w"); |
251 |
+ tmpfd = open(filename,O_WRONLY|O_CREAT|O_EXCL,S_IRWUSR); |
252 |
+ if (tmpfd < 0) { |
253 |
+ error = "Unable to open temporary file"; |
254 |
+ break; |
255 |
+ } |
256 |
+ fp = fdopen(tmpfd, "w"); |
257 |
if (!fp) { |
258 |
error = "Unable to open temporary file"; |
259 |
break; |
260 |
@@ -254,13 +259,17 @@ |
261 |
|
262 |
if (wrheader(fp, nx, ny, comment)) { |
263 |
error = "I/O error writing temporary file"; |
264 |
+ fflush(fp); |
265 |
fclose(fp); |
266 |
+ close(tmpfd); |
267 |
unlink(filename); |
268 |
break; |
269 |
} |
270 |
|
271 |
nwrt = fwrite(image+i*np, sizeof(byte), (size_t) np, fp); |
272 |
+ fflush(fp); |
273 |
fclose(fp); |
274 |
+ close(tmpfd); |
275 |
|
276 |
if (nwrt == 0) { /* failed to write any data */ |
277 |
error = "I/O error writing temporary file"; |
278 |
--- xvimage.c |
279 |
+++ xvimage.c 2003-01-27 00:03:36.000000000 +0100 |
280 |
@@ -21,6 +21,7 @@ |
281 |
* int LoadPad(pinfo, fname); |
282 |
*/ |
283 |
|
284 |
+#define NEEDSDIR /* for S_IRUSR|S_IWUSR */ |
285 |
#include "copyright.h" |
286 |
|
287 |
#include "xv.h" |
288 |
@@ -2927,7 +2930,7 @@ |
289 |
char *str; |
290 |
int wide, high, opaque,omode; |
291 |
{ |
292 |
- int i; |
293 |
+ int i, tmpfd; |
294 |
byte *bgpic24; |
295 |
char syscmd[512], fname[128], errstr[512]; |
296 |
PICINFO pinfo; |
297 |
@@ -2949,6 +2952,13 @@ |
298 |
strcpy(fname, "Sys$Disk:[]xvuXXXXXX"); |
299 |
#endif |
300 |
mktemp(fname); |
301 |
+ tmpfd = open(fname, O_WRONLY|O_CREAT|O_EXCL,S_IRWUSR); |
302 |
+ if (tmpfd < 0) { |
303 |
+ sprintf(errstr, "Error: can't create temporary file %s", fname); |
304 |
+ ErrPopUp(errstr, "\nDoh!"); |
305 |
+ return 0; |
306 |
+ } |
307 |
+ close(tmpfd); |
308 |
|
309 |
/* run bggen to generate the background */ |
310 |
sprintf(syscmd, "bggen -g %dx%d %s > %s", wide, high, str, fname); |
311 |
--- xvmaki.c |
312 |
+++ xvmaki.c 2003-01-27 00:03:36.000000000 +0100 |
313 |
@@ -355,8 +355,12 @@ |
314 |
return -1; |
315 |
} |
316 |
|
317 |
- if(w != 640 || h != 400) |
318 |
+ if(w != 640 || h != 400) { |
319 |
+ char str[512]; |
320 |
+ sprintf(str,"MAKI: %s Should be 640x400", maki_msgs[MAKI_SIZE]); |
321 |
+ ErrPopUp(str, "\nBummer!"); |
322 |
maki_error(mi, MAKI_SIZE); |
323 |
+ } |
324 |
|
325 |
maki.fp = fp; |
326 |
maki.width = w; |
327 |
@@ -669,6 +673,7 @@ |
328 |
static void maki_init_info(mi) |
329 |
struct maki_info *mi; |
330 |
{ |
331 |
+ xvbzero((char *)mi, sizeof(struct maki_info)); |
332 |
mi->fp = NULL; |
333 |
mi->fsize = 0; |
334 |
mi->x0 = mi->y0 = mi->x1 = mi->y1 = 0; |
335 |
--- xvpds.c |
336 |
+++ xvpds.c 2003-01-27 00:03:36.000000000 +0100 |
337 |
@@ -102,7 +102,7 @@ |
338 |
* This software is provided "as is" without any express or implied warranty. |
339 |
*/ |
340 |
|
341 |
- |
342 |
+#define NEEDSDIR /* for S_IRUSR|S_IWUSR */ |
343 |
#include "xv.h" |
344 |
|
345 |
#ifdef HAVE_PDS |
346 |
@@ -250,7 +250,7 @@ |
347 |
{ |
348 |
/* returns '1' on success, '0' on failure */ |
349 |
|
350 |
- int tempnum; |
351 |
+ int tempnum, tmpfd; |
352 |
FILE *zf; |
353 |
static int isfixed,teco,i,j,itype,vaxbyte, |
354 |
recsize,hrecsize,irecsize,isimage,labelrecs,labelsofar, |
355 |
@@ -690,6 +690,12 @@ |
356 |
#ifndef VMS |
357 |
sprintf(pdsuncompfname,"%s/xvhuffXXXXXX", tmpdir); |
358 |
mktemp(pdsuncompfname); |
359 |
+ tmpfd = open(pdsuncompfname,O_WRONLY|O_CREAT|O_EXCL,S_IRWUSR); |
360 |
+ if (tmpfd < 0) { |
361 |
+ SetISTR(ISTR_WARNING,"Unable to create temporarly file."); |
362 |
+ return 0; |
363 |
+ } |
364 |
+ close(tmpfd); |
365 |
sprintf(scanbuff,"%s %s - 4 >%s",PDSUNCOMP,fname,pdsuncompfname); |
366 |
#else |
367 |
strcpy(pdsuncompfname,"sys$disk:[]xvhuffXXXXXX"); |
368 |
--- xvps.c |
369 |
+++ xvps.c 2003-01-27 00:03:36.000000000 +0100 |
370 |
@@ -1564,7 +1564,7 @@ |
371 |
/* build command string */ |
372 |
|
373 |
#ifndef VMS /* VMS needs quotes around mixed case command lines */ |
374 |
- sprintf(tmp, "%s -sDEVICE=%s -r%d -q -dNOPAUSE -sOutputFile=%s%%d ", |
375 |
+ sprintf(tmp, "%s -sDEVICE=%s -r%d -q -dSAFER -dNOPAUSE -sOutputFile=%s%%d ", |
376 |
GS_PATH, gsDev, gsRes, tmpname); |
377 |
#else |
378 |
sprintf(tmp, |
379 |
--- xvtiff.c |
380 |
+++ xvtiff.c 2003-01-27 00:03:36.000000000 +0100 |
381 |
@@ -5,6 +5,7 @@ |
382 |
* LoadTIFF(fname, numcols, quick) - load a TIFF file |
383 |
*/ |
384 |
|
385 |
+#define NEEDSDIR /* for S_IRUSR|S_IWUSR */ |
386 |
#ifndef va_start |
387 |
# define NEEDSARGS |
388 |
#endif |
389 |
@@ -56,7 +89,7 @@ |
390 |
return 0; |
391 |
} |
392 |
|
393 |
- fseek(fp, 0L, 2); |
394 |
+ fseek(fp, 0L, SEEK_END); |
395 |
filesize = ftell(fp); |
396 |
fclose(fp); |
397 |
|
398 |
@@ -1065,7 +1308,7 @@ |
399 |
int fromskew, toskew; |
400 |
{ |
401 |
while (h-- > 0) { |
402 |
- UNROLL8(w,0, *cp++ = PALmap[*pp++][0]); |
403 |
+ UNROLL8(w,, *cp++ = PALmap[*pp++][0]); |
404 |
cp += toskew; |
405 |
pp += fromskew; |
406 |
} |
407 |
@@ -1262,7 +1504,7 @@ |
408 |
} |
409 |
} else { |
410 |
while (h-- > 0) { |
411 |
- UNROLL8(w,0, |
412 |
+ UNROLL8(w,, |
413 |
*cp++ = pp[0]; |
414 |
*cp++ = pp[1]; |
415 |
*cp++ = pp[2]; |
416 |
@@ -1335,7 +1577,7 @@ |
417 |
} |
418 |
} else { |
419 |
while (h-- > 0) { |
420 |
- UNROLL8(w,0, |
421 |
+ UNROLL8(w,, |
422 |
*cp++ = *r++; |
423 |
*cp++ = *g++; |
424 |
*cp++ = *b++; |
425 |
--- xvtiffwr.c |
426 |
+++ xvtiffwr.c 2003-01-27 00:03:36.000000000 +0100 |
427 |
@@ -78,6 +78,9 @@ |
428 |
TIFFSetField(tif, TIFFTAG_GROUP3OPTIONS, |
429 |
GROUP3OPT_2DENCODING+GROUP3OPT_FILLBITS); |
430 |
|
431 |
+ if (comp == COMPRESSION_LZW) |
432 |
+ TIFFSetField(tif, TIFFTAG_PREDICTOR, 2); |
433 |
+ |
434 |
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); |
435 |
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1); |
436 |
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); |
437 |
--- xvvd.c |
438 |
+++ xvvd.c 2003-01-27 00:03:36.000000000 +0100 |
439 |
@@ -793,7 +794,7 @@ |
440 |
returns '0' on failure */ |
441 |
|
442 |
char namez[128], *fname, buf[512], tmp[HEADERSIZE]; |
443 |
- int n; |
444 |
+ int n, tmpfd; |
445 |
FILE *pfp, *tfp; |
446 |
|
447 |
fname = name; |
448 |
@@ -834,10 +835,17 @@ |
449 |
Warning(); |
450 |
return 0; |
451 |
} |
452 |
- if ((tfp = fopen(uncompname, "w")) == NULL) { |
453 |
+ if ((tmpfd = open(uncompname,O_WRONLY|O_CREAT|O_EXCL,S_IRWUSR)) < 0) { |
454 |
+ SetISTR(ISTR_INFO, "Unable to create temporarly file.", |
455 |
+ BaseName(uncompname)); |
456 |
+ Warning(); |
457 |
+ pclose(pfp); |
458 |
+ } |
459 |
+ if ((tfp = fdopen(tmpfd, "w")) == NULL) { |
460 |
SetISTR(ISTR_INFO, "Unable to create temporarly file.", |
461 |
BaseName(uncompname)); |
462 |
Warning(); |
463 |
+ close(tmpfd); |
464 |
pclose(pfp); |
465 |
return 0; |
466 |
} |
467 |
@@ -846,11 +854,15 @@ |
468 |
BaseName(fname)); |
469 |
Warning(); |
470 |
pclose(pfp); |
471 |
+ fflush(tfp); |
472 |
fclose(tfp); |
473 |
+ close(tmpfd); |
474 |
return 0; |
475 |
} |
476 |
fwrite(tmp, 1, n, tfp); |
477 |
+ fflush(tfp); |
478 |
fclose(tfp); |
479 |
+ close(tmpfd); |
480 |
pclose(pfp); |
481 |
|
482 |
/* if we renamed the file to end with a .Z for the sake of 'uncompress', |
483 |
--- xvxpm.c |
484 |
+++ xvxpm.c 2003-01-27 00:03:36.000000000 +0100 |
485 |
@@ -77,96 +77,104 @@ |
486 |
hentry *clmp; /* colormap hash-table */ |
487 |
hentry *c_sptr; /* cmap hash-table search pointer*/ |
488 |
XColor col; |
489 |
- |
490 |
+ |
491 |
bname = BaseName(fname); |
492 |
fp = fopen(fname, "r"); |
493 |
if (!fp) |
494 |
return (XpmLoadError(bname, "couldn't open file")); |
495 |
- |
496 |
+ |
497 |
if (DEBUG) |
498 |
printf("LoadXPM(): Loading xpm from %s\n", fname); |
499 |
- |
500 |
+ |
501 |
fseek(fp, 0L, 2); |
502 |
filesize = ftell(fp); |
503 |
fseek(fp, 0L, 0); |
504 |
- |
505 |
+ |
506 |
bufchar = -2; |
507 |
in_quote = FALSE; |
508 |
- |
509 |
+ |
510 |
/* Read in the values line. It is the first string in the |
511 |
* xpm, and contains four numbers. w, h, num_colors, and |
512 |
* chars_per_pixel. */ |
513 |
- |
514 |
+ |
515 |
/* First, get to the first string */ |
516 |
while (((c = XpmGetc(fp))!=EOF) && (c != '"')) ; |
517 |
line_pos = 0; |
518 |
- |
519 |
+ |
520 |
/* Now, read in the string */ |
521 |
while (((c = XpmGetc(fp))!=EOF) && (line_pos < VALUES_LEN) && (c != '"')) { |
522 |
values[line_pos++] = c; |
523 |
} |
524 |
if (c != '"') |
525 |
return (XpmLoadError(bname, "error parsing values line")); |
526 |
- |
527 |
+ |
528 |
values[line_pos] = '\0'; |
529 |
sscanf(values, "%d%d%d%d", &w, &h, &nc, &cpp); |
530 |
if (nc <= 0 || cpp <= 0) |
531 |
return (XpmLoadError(bname, "No colours in Xpm?")); |
532 |
- |
533 |
+ |
534 |
if (nc > 256) |
535 |
pinfo->type = PIC24; |
536 |
else |
537 |
pinfo->type = PIC8; |
538 |
- |
539 |
+ |
540 |
if (DEBUG) |
541 |
printf("LoadXPM(): reading a %dx%d image (%d colors)\n", w, h, nc); |
542 |
- |
543 |
+ |
544 |
/* We got this far... */ |
545 |
WaitCursor(); |
546 |
- |
547 |
+ |
548 |
if (!hash_init(nc)) |
549 |
return (XpmLoadError(bname, "Not enough memory to hash colormap")); |
550 |
- |
551 |
+ |
552 |
clmp = (hentry *) malloc(nc * sizeof(hentry)); /* Holds the colormap */ |
553 |
if (pinfo->type == PIC8) pic = (byte *) malloc((size_t) (w*h)); |
554 |
else pic = (byte *) malloc((size_t) (w*h*3)); |
555 |
- |
556 |
+ |
557 |
if (!clmp || !pic) |
558 |
return (XpmLoadError(bname, "Not enough memory to load pixmap")); |
559 |
- |
560 |
+ |
561 |
c_sptr = clmp; |
562 |
i_sptr = pic; |
563 |
- |
564 |
+ |
565 |
/* initialize the 'hex' array for zippy ASCII-hex -> int conversion */ |
566 |
- |
567 |
+ |
568 |
for (i = 0 ; i < 256 ; i++) hex[i] = 0; |
569 |
for (i = '0'; i <= '9' ; i++) hex[i] = i - '0'; |
570 |
for (i = 'a'; i <= 'f' ; i++) hex[i] = i - 'a' + 10; |
571 |
for (i = 'A'; i <= 'F' ; i++) hex[i] = i - 'A' + 10; |
572 |
- |
573 |
+ |
574 |
/* Again, we've made progress. */ |
575 |
WaitCursor(); |
576 |
- |
577 |
+ |
578 |
/* Now, we need to read the colormap. */ |
579 |
pinfo->colType = F_BWDITHER; |
580 |
for (i = 0 ; i < nc ; i++) { |
581 |
while (((c = XpmGetc(fp))!=EOF) && (c != '"')) ; |
582 |
if (c != '"') |
583 |
return (XpmLoadError(bname, "Error reading colormap")); |
584 |
- |
585 |
+ |
586 |
for (j = 0 ; j < cpp ; j++) |
587 |
c_sptr->token[j] = XpmGetc(fp); |
588 |
c_sptr->token[j] = '\0'; |
589 |
- |
590 |
+ |
591 |
while (((c = XpmGetc(fp))!=EOF) && ((c == ' ') || (c == '\t'))) ; |
592 |
if (c == EOF) /* The failure condition of getc() */ |
593 |
return (XpmLoadError(bname, "Error parsing colormap line")); |
594 |
- |
595 |
+ |
596 |
do { |
597 |
char key[3]; |
598 |
- char color[40]; /* Need to figure a good size for this... */ |
599 |
+ char color[80]; /* Need to figure a good size for this... */ |
600 |
short hd; /* Hex digits per R, G, or B */ |
601 |
- |
602 |
+ |
603 |
+/* |
604 |
+ * Problem with spaces in color names |
605 |
+ * |
606 |
+ * X s Color Name m Other Name c Last Name |
607 |
+ * |
608 |
+ * ... this parser doesn't find `Any Name' |
609 |
+ */ |
610 |
+ |
611 |
for (j=0; j<2 && (c != ' ') && (c != '\t') && (c != EOF); j++) { |
612 |
key[j] = c; |
613 |
c = XpmGetc(fp); |
614 |
@@ -177,7 +185,7 @@ |
615 |
if (c == EOF) /* The failure condition of getc() */ |
616 |
return (XpmLoadError(bname, "Error parsing colormap line")); |
617 |
|
618 |
- for (j=0; j<39 && (c!=' ') && (c!='\t') && (c!='"') && c!=EOF; j++) { |
619 |
+ for (j=0; j<79 && (c!=' ') && (c!='\t') && (c!='"') && c!=EOF; j++) { |
620 |
color[j] = c; |
621 |
c = XpmGetc(fp); |
622 |
} |
623 |
@@ -236,13 +244,13 @@ |
624 |
else { /* 'None' or unrecognized color spec */ |
625 |
int rgb; |
626 |
|
627 |
- if (strcmp(color, "None") == 0) rgb = 0xb2c0dc; /* infobg */ |
628 |
+ if (strcasecmp(color, "None") == 0) rgb = 0xb2c0dc; /* infobg */ |
629 |
else { |
630 |
SetISTR(ISTR_INFO, "%s: unknown color spec '%s'", bname, color); |
631 |
Timer(1000); |
632 |
rgb = 0x808080; |
633 |
} |
634 |
- |
635 |
+ |
636 |
if (pinfo->type == PIC8) { |
637 |
pinfo->r[i] = (rgb>>16) & 0xff; |
638 |
pinfo->g[i] = (rgb>> 8) & 0xff; |
639 |
@@ -309,28 +317,29 @@ |
640 |
*i_sptr++ = mapentry->cv_rgb[2]; |
641 |
} |
642 |
} /* for ( j < w ) */ |
643 |
- (void)XpmGetc(fp); /* Throw away the close " */ |
644 |
- |
645 |
+ while (((c = XpmGetc(fp))!=EOF) && /* Throw away the close " and */ |
646 |
+ (c != '"')) ; /* erase all remaining pixels */ |
647 |
+ |
648 |
if (!(i%7)) WaitCursor(); |
649 |
} /* for ( i < h ) */ |
650 |
- |
651 |
+ |
652 |
pinfo->pic = pic; |
653 |
pinfo->normw = pinfo->w = w; |
654 |
pinfo->normh = pinfo->h = h; |
655 |
pinfo->frmType = F_XPM; |
656 |
|
657 |
if (DEBUG) printf("LoadXPM(): pinfo->colType is %d\n", pinfo->colType); |
658 |
- |
659 |
+ |
660 |
sprintf(pinfo->fullInfo, "Xpm v3 Pixmap (%ld bytes)", filesize); |
661 |
sprintf(pinfo->shrtInfo, "%dx%d Xpm.", w, h); |
662 |
pinfo->comment = (char *)NULL; |
663 |
- |
664 |
+ |
665 |
hash_destroy(); |
666 |
free(clmp); |
667 |
- |
668 |
+ |
669 |
if (fp != stdin) |
670 |
fclose(fp); |
671 |
- |
672 |
+ |
673 |
return(1); |
674 |
} |
675 |
|