comparison src/xmu.c @ 183:e121b013d1f0 r20-3b18

Import from CVS: tag r20-3b18
author cvs
date Mon, 13 Aug 2007 09:54:23 +0200
parents 15872534500d
children 3d6bfa290dbd
comparison
equal deleted inserted replaced
182:f07455f06202 183:e121b013d1f0
25 * 25 *
26 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 26 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T. 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
28 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 28 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
29 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 29 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
30 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 30 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
31 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 31 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32 */ 32 */
33 #include <X11/cursorfont.h> 33 #include <X11/cursorfont.h>
34 #if 0 /* mrb */ 34 #if 0 /* mrb */
35 #include <X11/Xos.h> 35 #include <X11/Xos.h>
141 {"xterm", XC_xterm}, 141 {"xterm", XC_xterm},
142 }; 142 };
143 const struct _CursorName *table; 143 const struct _CursorName *table;
144 int i; 144 int i;
145 char tmp[40]; 145 char tmp[40];
146 146
147 if (strlen (name) >= sizeof tmp) return -1; 147 if (strlen (name) >= sizeof tmp) return -1;
148 for (i=0; i<strlen(name); i++) 148 for (i=0; i<strlen(name); i++)
149 if (isupper((unsigned char) name[i])) 149 if (isupper((unsigned char) name[i]))
150 tmp[i] = tolower((unsigned char) name[i]); 150 tmp[i] = tolower((unsigned char) name[i]);
151 else 151 else
152 tmp[i] = name[i]; 152 tmp[i] = name[i];
153 tmp[i] = 0; 153 tmp[i] = 0;
200 200
201 /* delimiters of significance are flagged w/ negative value */ 201 /* delimiters of significance are flagged w/ negative value */
202 hexTable[' '] = -1; hexTable[','] = -1; 202 hexTable[' '] = -1; hexTable[','] = -1;
203 hexTable['}'] = -1; hexTable['\n'] = -1; 203 hexTable['}'] = -1; hexTable['\n'] = -1;
204 hexTable['\t'] = -1; 204 hexTable['\t'] = -1;
205 205
206 hex_initialized = 1; 206 hex_initialized = 1;
207 } 207 }
208 208
209 /* 209 /*
210 * read next hex value in the input stream, return -1 if EOF 210 * read next hex value in the input stream, return -1 if EOF
213 { 213 {
214 int ch; 214 int ch;
215 int value = 0; 215 int value = 0;
216 int gotone = 0; 216 int gotone = 0;
217 int done = 0; 217 int done = 0;
218 218
219 /* loop, accumulate hex value until find delimiter */ 219 /* loop, accumulate hex value until find delimiter */
220 /* skip any initial delimiters found in read stream */ 220 /* skip any initial delimiters found in read stream */
221 221
222 while (!done) { 222 while (!done) {
223 ch = getc(fstream); 223 ch = getc(fstream);
297 if (!strcmp("y_hot", type)) 297 if (!strcmp("y_hot", type))
298 hy = value; 298 hy = value;
299 } 299 }
300 continue; 300 continue;
301 } 301 }
302 302
303 if (sscanf(line, "static short %s = {", name_and_type) == 1) 303 if (sscanf(line, "static short %s = {", name_and_type) == 1)
304 version10p = 1; 304 version10p = 1;
305 else if (sscanf(line,"static unsigned char %s = {",name_and_type) == 1) 305 else if (sscanf(line,"static unsigned char %s = {",name_and_type) == 1)
306 version10p = 0; 306 version10p = 0;
307 else if (sscanf(line, "static char %s = {", name_and_type) == 1) 307 else if (sscanf(line, "static char %s = {", name_and_type) == 1)
314 else 314 else
315 type++; 315 type++;
316 316
317 if (strcmp("bits[]", type)) 317 if (strcmp("bits[]", type))
318 continue; 318 continue;
319 319
320 if (!ww || !hh) 320 if (!ww || !hh)
321 RETURN (BitmapFileInvalid); 321 RETURN (BitmapFileInvalid);
322 322
323 if ((ww % 16) && ((ww % 16) < 9) && version10p) 323 if ((ww % 16) && ((ww % 16) < 9) && version10p)
324 padding = 1; 324 padding = 1;
327 327
328 bytes_per_line = (ww+7)/8 + padding; 328 bytes_per_line = (ww+7)/8 + padding;
329 329
330 size = bytes_per_line * hh; 330 size = bytes_per_line * hh;
331 data = (unsigned char *) Xmalloc ((unsigned int) size); 331 data = (unsigned char *) Xmalloc ((unsigned int) size);
332 if (!data) 332 if (!data)
333 RETURN (BitmapNoMemory); 333 RETURN (BitmapNoMemory);
334 334
335 if (version10p) { 335 if (version10p) {
336 unsigned char *ptr; 336 unsigned char *ptr;
337 int bytes; 337 int bytes;
346 } else { 346 } else {
347 unsigned char *ptr; 347 unsigned char *ptr;
348 int bytes; 348 int bytes;
349 349
350 for (bytes=0, ptr=data; bytes<size; bytes++, ptr++) { 350 for (bytes=0, ptr=data; bytes<size; bytes++, ptr++) {
351 if ((value = NextInt(fstream)) < 0) 351 if ((value = NextInt(fstream)) < 0)
352 RETURN (BitmapFileInvalid); 352 RETURN (BitmapFileInvalid);
353 *ptr=value; 353 *ptr=value;
354 } 354 }
355 } 355 }
356 break; 356 break;
371 } 371 }
372 372
373 373
374 int XmuReadBitmapDataFromFile (const char *filename, 374 int XmuReadBitmapDataFromFile (const char *filename,
375 /* Remaining args are RETURNED */ 375 /* Remaining args are RETURNED */
376 unsigned int *width, 376 unsigned int *width,
377 unsigned int *height, 377 unsigned int *height,
378 unsigned char **datap, 378 unsigned char **datap,
379 int *x_hot, int *y_hot) 379 int *x_hot, int *y_hot)
380 { 380 {
381 FILE *fstream; 381 FILE *fstream;
388 fclose (fstream); 388 fclose (fstream);
389 return status; 389 return status;
390 } 390 }
391 391
392 /* 392 /*
393 * XmuPrintDefaultErrorMessage - print a nice error that looks like the usual 393 * XmuPrintDefaultErrorMessage - print a nice error that looks like the usual
394 * message. Returns 1 if the caller should consider exitting else 0. 394 * message. Returns 1 if the caller should consider exitting else 0.
395 */ 395 */
396 int XmuPrintDefaultErrorMessage (Display *dpy, XErrorEvent *event, FILE *fp) 396 int XmuPrintDefaultErrorMessage (Display *dpy, XErrorEvent *event, FILE *fp)
397 { 397 {
398 char buffer[BUFSIZ]; 398 char buffer[BUFSIZ];
400 char number[32]; 400 char number[32];
401 char *mtype = "XlibMessage"; 401 char *mtype = "XlibMessage";
402 _XExtension *ext = (_XExtension *)NULL; 402 _XExtension *ext = (_XExtension *)NULL;
403 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ); 403 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
404 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); 404 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
405 (void) fprintf(fp, "%s: %s\n ", mesg, buffer); 405 fprintf(fp, "%s: %s\n ", mesg, buffer);
406 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", 406 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d",
407 mesg, BUFSIZ); 407 mesg, BUFSIZ);
408 (void) fprintf(fp, mesg, event->request_code); 408 fprintf(fp, mesg, event->request_code);
409 if (event->request_code < 128) { 409 if (event->request_code < 128) {
410 sprintf(number, "%d", event->request_code); 410 sprintf(number, "%d", event->request_code);
411 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); 411 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
412 } else { 412 } else {
413 /* XXX this is non-portable */ 413 /* XXX this is non-portable */
418 if (ext) 418 if (ext)
419 strcpy(buffer, ext->name); 419 strcpy(buffer, ext->name);
420 else 420 else
421 buffer[0] = '\0'; 421 buffer[0] = '\0';
422 } 422 }
423 (void) fprintf(fp, " (%s)", buffer); 423 fprintf(fp, " (%s)", buffer);
424 fputs("\n ", fp); 424 fputs("\n ", fp);
425 #if (XtSpecificationRelease >= 5) 425 #if (XtSpecificationRelease >= 5)
426 if (event->request_code >= 128) { 426 if (event->request_code >= 128) {
427 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", 427 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
428 mesg, BUFSIZ); 428 mesg, BUFSIZ);
429 (void) fprintf(fp, mesg, event->minor_code); 429 fprintf(fp, mesg, event->minor_code);
430 if (ext) { 430 if (ext) {
431 sprintf(mesg, "%s.%d", ext->name, event->minor_code); 431 sprintf(mesg, "%s.%d", ext->name, event->minor_code);
432 XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ); 432 XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ);
433 (void) fprintf(fp, " (%s)", buffer); 433 fprintf(fp, " (%s)", buffer);
434 } 434 }
435 fputs("\n ", fp); 435 fputs("\n ", fp);
436 } 436 }
437 if (event->error_code >= 128) { 437 if (event->error_code >= 128) {
438 /* let extensions try to print the values */ 438 /* let extensions try to print the values */
443 } 443 }
444 /* the rest is a fallback, providing a simple default */ 444 /* the rest is a fallback, providing a simple default */
445 /* kludge, try to find the extension that caused it */ 445 /* kludge, try to find the extension that caused it */
446 buffer[0] = '\0'; 446 buffer[0] = '\0';
447 for (ext = dpy->ext_procs; ext; ext = ext->next) { 447 for (ext = dpy->ext_procs; ext; ext = ext->next) {
448 if (ext->error_string) 448 if (ext->error_string)
449 (*ext->error_string)(dpy, event->error_code, &ext->codes, 449 (*ext->error_string)(dpy, event->error_code, &ext->codes,
450 buffer, BUFSIZ); 450 buffer, BUFSIZ);
451 if (buffer[0]) 451 if (buffer[0])
452 break; 452 break;
453 } 453 }
454 if (buffer[0]) 454 if (buffer[0])
455 sprintf(buffer, "%s.%d", ext->name, 455 sprintf(buffer, "%s.%d", ext->name,
456 event->error_code - ext->codes.first_error); 456 event->error_code - ext->codes.first_error);
457 else 457 else
458 strcpy(buffer, "Value"); 458 strcpy(buffer, "Value");
459 XGetErrorDatabaseText(dpy, mtype, buffer, "", mesg, BUFSIZ); 459 XGetErrorDatabaseText(dpy, mtype, buffer, "", mesg, BUFSIZ);
460 if (*mesg) { 460 if (*mesg) {
461 (void) fprintf(fp, mesg, event->resourceid); 461 fprintf(fp, mesg, event->resourceid);
462 fputs("\n ", fp); 462 fputs("\n ", fp);
463 } 463 }
464 } else if ((event->error_code == BadWindow) || 464 } else if ((event->error_code == BadWindow) ||
465 (event->error_code == BadPixmap) || 465 (event->error_code == BadPixmap) ||
466 (event->error_code == BadCursor) || 466 (event->error_code == BadCursor) ||
478 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", 478 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
479 mesg, BUFSIZ); 479 mesg, BUFSIZ);
480 else 480 else
481 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", 481 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
482 mesg, BUFSIZ); 482 mesg, BUFSIZ);
483 (void) fprintf(fp, mesg, event->resourceid); 483 fprintf(fp, mesg, event->resourceid);
484 fputs("\n ", fp); 484 fputs("\n ", fp);
485 } 485 }
486 #elif (XtSpecificationRelease == 4) 486 #elif (XtSpecificationRelease == 4)
487 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", 487 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
488 mesg, BUFSIZ); 488 mesg, BUFSIZ);
489 (void) fprintf(fp, mesg, event->minor_code); 489 fprintf(fp, mesg, event->minor_code);
490 fputs("\n ", fp); 490 fputs("\n ", fp);
491 if (ext) { 491 if (ext) {
492 sprintf(mesg, "%s.%d", ext->name, event->minor_code); 492 sprintf(mesg, "%s.%d", ext->name, event->minor_code);
493 XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ); 493 XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ);
494 (void) fprintf(fp, " (%s)", buffer); 494 fprintf(fp, " (%s)", buffer);
495 } 495 }
496 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", 496 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
497 mesg, BUFSIZ); 497 mesg, BUFSIZ);
498 (void) fprintf(fp, mesg, event->resourceid); 498 fprintf(fp, mesg, event->resourceid);
499 fputs("\n ", fp); 499 fputs("\n ", fp);
500 #else 500 #else
501 ERROR! Unsupported release of X11 501 ERROR! Unsupported release of X11
502 #endif 502 #endif
503 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", 503 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
504 mesg, BUFSIZ); 504 mesg, BUFSIZ);
505 (void) fprintf(fp, mesg, event->serial); 505 fprintf(fp, mesg, event->serial);
506 fputs("\n ", fp); 506 fputs("\n ", fp);
507 XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d", 507 XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d",
508 mesg, BUFSIZ); 508 mesg, BUFSIZ);
509 (void) fprintf(fp, mesg, NextRequest(dpy)-1); 509 fprintf(fp, mesg, NextRequest(dpy)-1);
510 fputs("\n", fp); 510 fputs("\n", fp);
511 if (event->error_code == BadImplementation) return 0; 511 if (event->error_code == BadImplementation) return 0;
512 return 1; 512 return 1;
513 } 513 }
514 514
529 if (errorp->error_code == BadDrawable) return 0; 529 if (errorp->error_code == BadDrawable) return 0;
530 break; 530 break;
531 } 531 }
532 /* got a "real" X error */ 532 /* got a "real" X error */
533 return XmuPrintDefaultErrorMessage (dpy, errorp, stderr); 533 return XmuPrintDefaultErrorMessage (dpy, errorp, stderr);
534 } 534 }
535 535
536 void XmuCopyISOLatin1Lowered(char *dst, char *src) 536 void XmuCopyISOLatin1Lowered(char *dst, char *src)
537 { 537 {
538 unsigned char *dest = (unsigned char *) dst; 538 unsigned char *dest = (unsigned char *) dst;
539 unsigned char *source = (unsigned char *) src; 539 unsigned char *source = (unsigned char *) src;