ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/xdefaults.C
(Generate patch)

Comparing rxvt-unicode/src/xdefaults.C (file contents):
Revision 1.17 by pcg, Sun Mar 14 17:33:08 2004 UTC vs.
Revision 1.19 by pcg, Mon Mar 22 15:15:04 2004 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: xdefaults.c 2 * File: xdefaults.c
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: xdefaults.C,v 1.17 2004/03/14 17:33:08 pcg Exp $ 4 * $Id: xdefaults.C,v 1.19 2004/03/22 15:15:04 pcg Exp $
5 * 5 *
6 * All portions of code are copyright by their respective author/s. 6 * All portions of code are copyright by their respective author/s.
7 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> 7 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com>
8 * - original version 8 * - original version
9 * Copyright (c) 1997,1998 mj olesen <olesen@me.queensu.ca> 9 * Copyright (c) 1997,1998 mj olesen <olesen@me.queensu.ca>
340/*{{{ usage: */ 340/*{{{ usage: */
341/*----------------------------------------------------------------------*/ 341/*----------------------------------------------------------------------*/
342static void 342static void
343rxvt_usage (int type) 343rxvt_usage (int type)
344{ 344{
345 unsigned int i, col; 345 unsigned int i, col;
346 346
347 write (STDERR_FILENO, releasestring, sizeof (releasestring) - 1); 347 rxvt_log ("%s%s%s", releasestring, optionsstring, RESNAME);
348 write (STDERR_FILENO, optionsstring, sizeof (optionsstring) - 1);
349 write (STDERR_FILENO, RESNAME, sizeof (RESNAME) - 1);
350 348
351 switch (type) 349 switch (type)
352 { 350 {
353 case 0: /* brief listing */ 351 case 0: /* brief listing */
354 fprintf (stderr, " [-help] [--help]\n"); 352 rxvt_log (" [-help] [--help]\n");
353
355 for (col = 1, i = 0; i < optList_size (); i++) 354 for (col = 1, i = 0; i < optList_size (); i++)
356 if (optList[i].desc != NULL) 355 if (optList[i].desc != NULL)
357 { 356 {
358 int len = 0; 357 int len = 0;
359 358
368#endif 367#endif
369 len += 4 + STRLEN (optList[i].opt) + (optList_isBool (i) ? 2: 0); 368 len += 4 + STRLEN (optList[i].opt) + (optList_isBool (i) ? 2: 0);
370 col += len; 369 col += len;
371 if (col > 79) 370 if (col > 79)
372 { /* assume regular width */ 371 { /* assume regular width */
373 putc ('\n', stderr); 372 rxvt_log ("\n");
374 col = 1 + len; 373 col = 1 + len;
375 } 374 }
375
376 fprintf (stderr, " [-%s%s", (optList_isBool (i) ? "/+" : ""), 376 rxvt_log (" [-%s%s", (optList_isBool (i) ? "/+" : ""), optList[i].opt);
377 optList[i].opt);
378 if (optList_strlen (i)) 377 if (optList_strlen (i))
379 fprintf (stderr, " %s]", optList[i].arg); 378 rxvt_log (" %s]", optList[i].arg);
380 else 379 else
381 fprintf (stderr, "]"); 380 rxvt_log ("]");
382 } 381 }
383 break; 382 break;
384 383
385 case 1: /* full command-line listing */ 384 case 1: /* full command-line listing */
386 fprintf (stderr, " [options] [-e command args]\n\n" 385 rxvt_log (" [options] [-e command args]\n\nwhere options include:\n");
387 "where options include:\n"); 386
388 for (i = 0; i < optList_size (); i++) 387 for (i = 0; i < optList_size (); i++)
389 if (optList[i].desc != NULL) 388 if (optList[i].desc != NULL)
390 { 389 {
391#ifdef DEBUG_STRICT 390#ifdef DEBUG_STRICT
392 assert (optList[i].opt != NULL); 391 assert (optList[i].opt != NULL);
393#endif 392#endif
394 fprintf (stderr, " %s%s %-*s%s%s\n", 393 rxvt_log (" %s%s %-*s%s%s\n",
395 (optList_isBool (i) ? "-/+" : "-"), optList[i].opt, 394 (optList_isBool (i) ? "-/+" : "-"), optList[i].opt,
396 (INDENT - STRLEN (optList[i].opt) 395 (INDENT - STRLEN (optList[i].opt)
397 + (optList_isBool (i) ? 0 : 2)), 396 + (optList_isBool (i) ? 0 : 2)),
398 (optList[i].arg ? optList[i].arg : ""), 397 (optList[i].arg ? optList[i].arg : ""),
399 (optList_isBool (i) ? "turn on/off " : ""), 398 (optList_isBool (i) ? "turn on/off " : ""),
400 optList[i].desc); 399 optList[i].desc);
401 } 400 }
402 fprintf (stderr, "\n --help to list long-options"); 401 rxvt_log ("\n --help to list long-options");
403 break; 402 break;
404 403
405 case 2: /* full resource listing */ 404 case 2: /* full resource listing */
406 fprintf (stderr,
407 " [options] [-e command args]\n\n" 405 rxvt_log (" [options] [-e command args]\n\n"
408 "where resources (long-options) include:\n"); 406 "where resources (long-options) include:\n");
409 407
410 for (i = 0; i < optList_size (); i++) 408 for (i = 0; i < optList_size (); i++)
411 if (optList[i].kw != NULL) 409 if (optList[i].kw != NULL)
412 fprintf (stderr, " %s: %*s%s\n", 410 rxvt_log (" %s: %*s%s\n",
413 optList[i].kw, 411 optList[i].kw,
414 (INDENT - STRLEN (optList[i].kw)), "", /* XXX */ 412 (INDENT - STRLEN (optList[i].kw)), "", /* XXX */
415 (optList_isBool (i) ? "boolean" : optList[i].arg)); 413 (optList_isBool (i) ? "boolean" : optList[i].arg));
416#ifdef KEYSYM_RESOURCE 414#ifdef KEYSYM_RESOURCE
417 fprintf (stderr, " " "keysym.sym" ": %*s%s\n", 415 rxvt_log (" " "keysym.sym" ": %*s%s\n",
418 (INDENT - sizeof ("keysym.sym") + 1), "", /* XXX */ 416 (INDENT - sizeof ("keysym.sym") + 1), "", /* XXX */
419 "keysym"); 417 "keysym");
420#endif 418#endif
421 fprintf (stderr, "\n -help to list options"); 419 rxvt_log ("\n -help to list options");
422 break; 420 break;
423 } 421 }
424 fprintf (stderr, "\n\n"); 422
425 exit (EXIT_FAILURE); 423 rxvt_log ("\n\n");
424 rxvt_exit_failure ();
426 /* NOTREACHED */ 425 /* NOTREACHED */
427} 426}
428 427
429/*}}} */ 428/*}}} */
430 429
457 longopt = *opt++; /* long option */ 456 longopt = *opt++; /* long option */
458 } 457 }
459 else 458 else
460 { 459 {
461 bad_option = 1; 460 bad_option = 1;
462 rxvt_print_error ("bad option \"%s\"", opt); 461 rxvt_warn ("\"%s\": malformed option.\n", opt);
463 continue; 462 continue;
464 } 463 }
465 464
466 if (!STRCMP (opt, "help")) 465 if (!STRCMP (opt, "help"))
467 rxvt_usage (longopt ? 2 : 1); 466 rxvt_usage (longopt ? 2 : 1);
524 else 523 else
525#ifdef KEYSYM_RESOURCE 524#ifdef KEYSYM_RESOURCE
526 /* if (!STRNCMP (opt, "keysym.", sizeof ("keysym.") - 1)) */ 525 /* if (!STRNCMP (opt, "keysym.", sizeof ("keysym.") - 1)) */
527 if (rxvt_Str_match (opt, "keysym.")) 526 if (rxvt_Str_match (opt, "keysym."))
528 { 527 {
529 const char *str = argv[++i]; 528 const char *str = argv[++i];
530 529
531 if (str != NULL) 530 if (str != NULL)
532 parse_keysym (opt + sizeof ("keysym.") - 1, str); 531 parse_keysym (opt + sizeof ("keysym.") - 1, str);
533 } 532 }
534 else 533 else
535#endif 534#endif
535 {
536 bad_option = 1; 536 bad_option = 1;
537 rxvt_warn ("\"%s\": unknown or malformed option.\n", opt);
538 }
537 } 539 }
538 540
539 if (bad_option) 541 if (bad_option)
540 rxvt_usage (0); 542 rxvt_usage (0);
541} 543}
668 unsigned int len; 670 unsigned int len;
669 char *str, buffer[256]; 671 char *str, buffer[256];
670 672
671 if (stream == NULL) 673 if (stream == NULL)
672 return; 674 return;
675
673 len = STRLEN (name); 676 len = STRLEN (name);
674 while ((str = fgets (buffer, sizeof (buffer), stream)) != NULL) 677 while ((str = fgets (buffer, sizeof (buffer), stream)) != NULL)
675 { 678 {
676 unsigned int entry, n; 679 unsigned int entry, n;
677 680
686# ifdef KEYSYM_RESOURCE 689# ifdef KEYSYM_RESOURCE
687 if (!parse_keysym (str, NULL)) 690 if (!parse_keysym (str, NULL))
688# endif /* KEYSYM_RESOURCE */ 691# endif /* KEYSYM_RESOURCE */
689 for (entry = 0; entry < optList_size (); entry++) 692 for (entry = 0; entry < optList_size (); entry++)
690 { 693 {
691 const char *kw = optList[entry].kw; 694 const char *kw = optList[entry].kw;
692 695
693 if (kw == NULL) 696 if (kw == NULL)
694 continue; 697 continue;
698
695 n = STRLEN (kw); 699 n = STRLEN (kw);
696 if (str[n] == ':' && rxvt_Str_match (str, kw)) 700 if (str[n] == ':' && rxvt_Str_match (str, kw))
697 { 701 {
698 /* skip `keyword:' */ 702 /* skip `keyword:' */
699 str += n + 1; 703 str += n + 1;
723 rxvt_Str_trim (str); 727 rxvt_Str_trim (str);
724 n = STRLEN (str); 728 n = STRLEN (str);
725 } 729 }
726 730
727 rs[optList[entry].doff] = p; 731 rs[optList[entry].doff] = p;
732 allocated.push_back (p);
733
728 if (optList_isBool (entry)) 734 if (optList_isBool (entry))
729 { 735 {
730 s = STRCASECMP (str, "TRUE") == 0 736 s = STRCASECMP (str, "TRUE") == 0
731 || STRCASECMP (str, "YES") == 0 737 || STRCASECMP (str, "YES") == 0
732 || STRCASECMP (str, "ON") == 0 738 || STRCASECMP (str, "ON") == 0
733 || STRCASECMP (str, "1") == 0; 739 || STRCASECMP (str, "1") == 0;
740
734 if (optList_isReverse (entry)) 741 if (optList_isReverse (entry))
735 s = !s; 742 s = !s;
743
736 if (s) 744 if (s)
737 Options |= (optList[entry].flag); 745 Options |= optList[entry].flag;
738 else 746 else
739 Options &= ~ (optList[entry].flag); 747 Options &= ~optList[entry].flag;
740 } 748 }
741 } 749 }
750
742 break; 751 break;
743 } 752 }
744 } 753 }
745 } 754 }
755
746 rewind (stream); 756 rewind (stream);
747} 757}
748 758
749/*}}} */ 759/*}}} */
750# endif /* ! USE_XGETDEFAULT */ 760# endif /* ! USE_XGETDEFAULT */
761#ifndef NO_RESOURCES 771#ifndef NO_RESOURCES
762 772
763# if defined XAPPLOADDIR 773# if defined XAPPLOADDIR
764# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 774# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
765 /* Compute the path of the possibly available localized Rxvt file */ 775 /* Compute the path of the possibly available localized Rxvt file */
766 char *localepath = NULL; 776 char *localepath = NULL;
767 777
768 if (locale != NULL) 778 if (locale != NULL)
769 { /* XXX: must limit length of string */ 779 { /* XXX: must limit length of string */
770 localepath = (char *)rxvt_malloc (256); 780 localepath = (char *)rxvt_malloc (256);
771 sprintf (localepath, XAPPLOADDIRLOCALE "/" RESCLASS, 781 sprintf (localepath, XAPPLOADDIRLOCALE "/" RESCLASS,
779 789
780# ifdef USE_XGETDEFAULT 790# ifdef USE_XGETDEFAULT
781 /* 791 /*
782 * get resources using the X library function 792 * get resources using the X library function
783 */ 793 */
784 int entry; 794 int entry;
785 795
786# ifdef XrmEnumOneLevel 796# ifdef XrmEnumOneLevel
787 int i; 797 int i;
788 char *displayResource, *xe; 798 char *displayResource, *xe;
789 XrmName name_prefix[3]; 799 XrmName name_prefix[3];
790 XrmClass class_prefix[3]; 800 XrmClass class_prefix[3];
791 XrmDatabase database, rdb1; 801 XrmDatabase database, rdb1;
792 char fname[1024]; 802 char fname[1024];
793 803
794 XrmInitialize (); 804 XrmInitialize ();
795 database = NULL; 805 database = NULL;
796 806
797 /* Get any Xserver defaults */ 807 /* Get any Xserver defaults */
810 820
811 for (i = 0; i < (sizeof (xnames) / sizeof (xnames[0])); i++) 821 for (i = 0; i < (sizeof (xnames) / sizeof (xnames[0])); i++)
812 { 822 {
813 sprintf (fname, "%-.*s/%s", sizeof (fname) - STRLEN (xnames[i]) - 2, 823 sprintf (fname, "%-.*s/%s", sizeof (fname) - STRLEN (xnames[i]) - 2,
814 ptr, xnames[i]); 824 ptr, xnames[i]);
815 if ((rdb1 = XrmGetFileDatabase (fname)) != NULL) 825 if ((rdb1 = XrmGetFileDatabase (fname)))
816 { 826 {
817 XrmMergeDatabases (rdb1, &database); 827 XrmMergeDatabases (rdb1, &database);
818# ifndef HAVE_BOTH_XRESOURCE_FILES 828# ifndef HAVE_BOTH_XRESOURCE_FILES
819 break; 829 break;
820# endif 830# endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines