1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: xdefaults.c |
2 | * File: xdefaults.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: xdefaults.C,v 1.16 2004/03/04 00:59:10 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> |
… | |
… | |
240 | RSTRG (Rs_scrollBar_align, "scrollBar_align", "mode"), |
240 | RSTRG (Rs_scrollBar_align, "scrollBar_align", "mode"), |
241 | #endif |
241 | #endif |
242 | #ifdef PRINTPIPE |
242 | #ifdef PRINTPIPE |
243 | RSTRG (Rs_print_pipe, "print-pipe", "string"), |
243 | RSTRG (Rs_print_pipe, "print-pipe", "string"), |
244 | #endif |
244 | #endif |
245 | #if defined (HOTKEY_CTRL) || defined (HOTKEY_META) |
|
|
246 | RSTRG (Rs_bigfont_key, "bigfont_key", "keysym"), |
|
|
247 | RSTRG (Rs_smallfont_key, "smallfont_key", "keysym"), |
|
|
248 | #endif |
|
|
249 | STRG (Rs_modifier, "modifier", "mod", "modifier", |
245 | STRG (Rs_modifier, "modifier", "mod", "modifier", |
250 | "meta modifier = alt|meta|hyper|super|mod1|...|mod5"), |
246 | "meta modifier = alt|meta|hyper|super|mod1|...|mod5"), |
251 | INFO ("xrm", "string", "X resource"), |
247 | INFO ("xrm", "string", "X resource"), |
252 | #ifdef CUTCHAR_RESOURCE |
248 | #ifdef CUTCHAR_RESOURCE |
253 | RSTRG (Rs_cutchars, "cutchars", "string"), |
249 | RSTRG (Rs_cutchars, "cutchars", "string"), |
254 | #endif /* CUTCHAR_RESOURCE */ |
250 | #endif /* CUTCHAR_RESOURCE */ |
255 | #ifdef ACS_ASCII |
|
|
256 | RSTRG (Rs_acs_chars, "acsChars", "string"), |
|
|
257 | #endif /* ACS_ASCII */ |
|
|
258 | RSTRG (Rs_answerbackstring, "answerbackString", "string"), |
251 | RSTRG (Rs_answerbackstring, "answerbackString", "string"), |
259 | INFO ("e", "command arg ...", "command to execute") |
252 | INFO ("e", "command arg ...", "command to execute") |
260 | }; |
253 | }; |
261 | |
254 | |
262 | #undef INFO |
255 | #undef INFO |
… | |
… | |
347 | /*{{{ usage: */ |
340 | /*{{{ usage: */ |
348 | /*----------------------------------------------------------------------*/ |
341 | /*----------------------------------------------------------------------*/ |
349 | static void |
342 | static void |
350 | rxvt_usage (int type) |
343 | rxvt_usage (int type) |
351 | { |
344 | { |
352 | unsigned int i, col; |
345 | unsigned int i, col; |
353 | |
346 | |
354 | write (STDERR_FILENO, releasestring, sizeof (releasestring) - 1); |
347 | rxvt_log ("%s%s%s", releasestring, optionsstring, RESNAME); |
355 | write (STDERR_FILENO, optionsstring, sizeof (optionsstring) - 1); |
|
|
356 | write (STDERR_FILENO, RESNAME, sizeof (RESNAME) - 1); |
|
|
357 | |
348 | |
358 | switch (type) |
349 | switch (type) |
359 | { |
350 | { |
360 | case 0: /* brief listing */ |
351 | case 0: /* brief listing */ |
361 | fprintf (stderr, " [-help] [--help]\n"); |
352 | rxvt_log (" [-help] [--help]\n"); |
|
|
353 | |
362 | for (col = 1, i = 0; i < optList_size (); i++) |
354 | for (col = 1, i = 0; i < optList_size (); i++) |
363 | if (optList[i].desc != NULL) |
355 | if (optList[i].desc != NULL) |
364 | { |
356 | { |
365 | int len = 0; |
357 | int len = 0; |
366 | |
358 | |
… | |
… | |
375 | #endif |
367 | #endif |
376 | len += 4 + STRLEN (optList[i].opt) + (optList_isBool (i) ? 2: 0); |
368 | len += 4 + STRLEN (optList[i].opt) + (optList_isBool (i) ? 2: 0); |
377 | col += len; |
369 | col += len; |
378 | if (col > 79) |
370 | if (col > 79) |
379 | { /* assume regular width */ |
371 | { /* assume regular width */ |
380 | putc ('\n', stderr); |
372 | rxvt_log ("\n"); |
381 | col = 1 + len; |
373 | col = 1 + len; |
382 | } |
374 | } |
|
|
375 | |
383 | fprintf (stderr, " [-%s%s", (optList_isBool (i) ? "/+" : ""), |
376 | rxvt_log (" [-%s%s", (optList_isBool (i) ? "/+" : ""), optList[i].opt); |
384 | optList[i].opt); |
|
|
385 | if (optList_strlen (i)) |
377 | if (optList_strlen (i)) |
386 | fprintf (stderr, " %s]", optList[i].arg); |
378 | rxvt_log (" %s]", optList[i].arg); |
387 | else |
379 | else |
388 | fprintf (stderr, "]"); |
380 | rxvt_log ("]"); |
389 | } |
381 | } |
390 | break; |
382 | break; |
391 | |
383 | |
392 | case 1: /* full command-line listing */ |
384 | case 1: /* full command-line listing */ |
393 | fprintf (stderr, " [options] [-e command args]\n\n" |
385 | rxvt_log (" [options] [-e command args]\n\nwhere options include:\n"); |
394 | "where options include:\n"); |
386 | |
395 | for (i = 0; i < optList_size (); i++) |
387 | for (i = 0; i < optList_size (); i++) |
396 | if (optList[i].desc != NULL) |
388 | if (optList[i].desc != NULL) |
397 | { |
389 | { |
398 | #ifdef DEBUG_STRICT |
390 | #ifdef DEBUG_STRICT |
399 | assert (optList[i].opt != NULL); |
391 | assert (optList[i].opt != NULL); |
400 | #endif |
392 | #endif |
401 | fprintf (stderr, " %s%s %-*s%s%s\n", |
393 | rxvt_log (" %s%s %-*s%s%s\n", |
402 | (optList_isBool (i) ? "-/+" : "-"), optList[i].opt, |
394 | (optList_isBool (i) ? "-/+" : "-"), optList[i].opt, |
403 | (INDENT - STRLEN (optList[i].opt) |
395 | (INDENT - STRLEN (optList[i].opt) |
404 | + (optList_isBool (i) ? 0 : 2)), |
396 | + (optList_isBool (i) ? 0 : 2)), |
405 | (optList[i].arg ? optList[i].arg : ""), |
397 | (optList[i].arg ? optList[i].arg : ""), |
406 | (optList_isBool (i) ? "turn on/off " : ""), |
398 | (optList_isBool (i) ? "turn on/off " : ""), |
407 | optList[i].desc); |
399 | optList[i].desc); |
408 | } |
400 | } |
409 | fprintf (stderr, "\n --help to list long-options"); |
401 | rxvt_log ("\n --help to list long-options"); |
410 | break; |
402 | break; |
411 | |
403 | |
412 | case 2: /* full resource listing */ |
404 | case 2: /* full resource listing */ |
413 | fprintf (stderr, |
|
|
414 | " [options] [-e command args]\n\n" |
405 | rxvt_log (" [options] [-e command args]\n\n" |
415 | "where resources (long-options) include:\n"); |
406 | "where resources (long-options) include:\n"); |
416 | |
407 | |
417 | for (i = 0; i < optList_size (); i++) |
408 | for (i = 0; i < optList_size (); i++) |
418 | if (optList[i].kw != NULL) |
409 | if (optList[i].kw != NULL) |
419 | fprintf (stderr, " %s: %*s%s\n", |
410 | rxvt_log (" %s: %*s%s\n", |
420 | optList[i].kw, |
411 | optList[i].kw, |
421 | (INDENT - STRLEN (optList[i].kw)), "", /* XXX */ |
412 | (INDENT - STRLEN (optList[i].kw)), "", /* XXX */ |
422 | (optList_isBool (i) ? "boolean" : optList[i].arg)); |
413 | (optList_isBool (i) ? "boolean" : optList[i].arg)); |
423 | #ifdef KEYSYM_RESOURCE |
414 | #ifdef KEYSYM_RESOURCE |
424 | fprintf (stderr, " " "keysym.sym" ": %*s%s\n", |
415 | rxvt_log (" " "keysym.sym" ": %*s%s\n", |
425 | (INDENT - sizeof ("keysym.sym") + 1), "", /* XXX */ |
416 | (INDENT - sizeof ("keysym.sym") + 1), "", /* XXX */ |
426 | "keysym"); |
417 | "keysym"); |
427 | #endif |
418 | #endif |
428 | fprintf (stderr, "\n -help to list options"); |
419 | rxvt_log ("\n -help to list options"); |
429 | break; |
420 | break; |
430 | } |
421 | } |
431 | fprintf (stderr, "\n\n"); |
422 | |
432 | exit (EXIT_FAILURE); |
423 | rxvt_log ("\n\n"); |
|
|
424 | rxvt_exit_failure (); |
433 | /* NOTREACHED */ |
425 | /* NOTREACHED */ |
434 | } |
426 | } |
435 | |
427 | |
436 | /*}}} */ |
428 | /*}}} */ |
437 | |
429 | |
… | |
… | |
464 | longopt = *opt++; /* long option */ |
456 | longopt = *opt++; /* long option */ |
465 | } |
457 | } |
466 | else |
458 | else |
467 | { |
459 | { |
468 | bad_option = 1; |
460 | bad_option = 1; |
469 | rxvt_print_error ("bad option \"%s\"", opt); |
461 | rxvt_warn ("\"%s\": malformed option.\n", opt); |
470 | continue; |
462 | continue; |
471 | } |
463 | } |
472 | |
464 | |
473 | if (!STRCMP (opt, "help")) |
465 | if (!STRCMP (opt, "help")) |
474 | rxvt_usage (longopt ? 2 : 1); |
466 | rxvt_usage (longopt ? 2 : 1); |
… | |
… | |
531 | else |
523 | else |
532 | #ifdef KEYSYM_RESOURCE |
524 | #ifdef KEYSYM_RESOURCE |
533 | /* if (!STRNCMP (opt, "keysym.", sizeof ("keysym.") - 1)) */ |
525 | /* if (!STRNCMP (opt, "keysym.", sizeof ("keysym.") - 1)) */ |
534 | if (rxvt_Str_match (opt, "keysym.")) |
526 | if (rxvt_Str_match (opt, "keysym.")) |
535 | { |
527 | { |
536 | const char *str = argv[++i]; |
528 | const char *str = argv[++i]; |
537 | |
529 | |
538 | if (str != NULL) |
530 | if (str != NULL) |
539 | parse_keysym (opt + sizeof ("keysym.") - 1, str); |
531 | parse_keysym (opt + sizeof ("keysym.") - 1, str); |
540 | } |
532 | } |
541 | else |
533 | else |
542 | #endif |
534 | #endif |
|
|
535 | { |
543 | bad_option = 1; |
536 | bad_option = 1; |
|
|
537 | rxvt_warn ("\"%s\": unknown or malformed option.\n", opt); |
|
|
538 | } |
544 | } |
539 | } |
545 | |
540 | |
546 | if (bad_option) |
541 | if (bad_option) |
547 | rxvt_usage (0); |
542 | rxvt_usage (0); |
548 | } |
543 | } |
… | |
… | |
675 | unsigned int len; |
670 | unsigned int len; |
676 | char *str, buffer[256]; |
671 | char *str, buffer[256]; |
677 | |
672 | |
678 | if (stream == NULL) |
673 | if (stream == NULL) |
679 | return; |
674 | return; |
|
|
675 | |
680 | len = STRLEN (name); |
676 | len = STRLEN (name); |
681 | while ((str = fgets (buffer, sizeof (buffer), stream)) != NULL) |
677 | while ((str = fgets (buffer, sizeof (buffer), stream)) != NULL) |
682 | { |
678 | { |
683 | unsigned int entry, n; |
679 | unsigned int entry, n; |
684 | |
680 | |
… | |
… | |
693 | # ifdef KEYSYM_RESOURCE |
689 | # ifdef KEYSYM_RESOURCE |
694 | if (!parse_keysym (str, NULL)) |
690 | if (!parse_keysym (str, NULL)) |
695 | # endif /* KEYSYM_RESOURCE */ |
691 | # endif /* KEYSYM_RESOURCE */ |
696 | for (entry = 0; entry < optList_size (); entry++) |
692 | for (entry = 0; entry < optList_size (); entry++) |
697 | { |
693 | { |
698 | const char *kw = optList[entry].kw; |
694 | const char *kw = optList[entry].kw; |
699 | |
695 | |
700 | if (kw == NULL) |
696 | if (kw == NULL) |
701 | continue; |
697 | continue; |
|
|
698 | |
702 | n = STRLEN (kw); |
699 | n = STRLEN (kw); |
703 | if (str[n] == ':' && rxvt_Str_match (str, kw)) |
700 | if (str[n] == ':' && rxvt_Str_match (str, kw)) |
704 | { |
701 | { |
705 | /* skip `keyword:' */ |
702 | /* skip `keyword:' */ |
706 | str += n + 1; |
703 | str += n + 1; |
… | |
… | |
730 | rxvt_Str_trim (str); |
727 | rxvt_Str_trim (str); |
731 | n = STRLEN (str); |
728 | n = STRLEN (str); |
732 | } |
729 | } |
733 | |
730 | |
734 | rs[optList[entry].doff] = p; |
731 | rs[optList[entry].doff] = p; |
|
|
732 | allocated.push_back (p); |
|
|
733 | |
735 | if (optList_isBool (entry)) |
734 | if (optList_isBool (entry)) |
736 | { |
735 | { |
737 | s = STRCASECMP (str, "TRUE") == 0 |
736 | s = STRCASECMP (str, "TRUE") == 0 |
738 | || STRCASECMP (str, "YES") == 0 |
737 | || STRCASECMP (str, "YES") == 0 |
739 | || STRCASECMP (str, "ON") == 0 |
738 | || STRCASECMP (str, "ON") == 0 |
740 | || STRCASECMP (str, "1") == 0; |
739 | || STRCASECMP (str, "1") == 0; |
|
|
740 | |
741 | if (optList_isReverse (entry)) |
741 | if (optList_isReverse (entry)) |
742 | s = !s; |
742 | s = !s; |
|
|
743 | |
743 | if (s) |
744 | if (s) |
744 | Options |= (optList[entry].flag); |
745 | Options |= optList[entry].flag; |
745 | else |
746 | else |
746 | Options &= ~ (optList[entry].flag); |
747 | Options &= ~optList[entry].flag; |
747 | } |
748 | } |
748 | } |
749 | } |
|
|
750 | |
749 | break; |
751 | break; |
750 | } |
752 | } |
751 | } |
753 | } |
752 | } |
754 | } |
|
|
755 | |
753 | rewind (stream); |
756 | rewind (stream); |
754 | } |
757 | } |
755 | |
758 | |
756 | /*}}} */ |
759 | /*}}} */ |
757 | # endif /* ! USE_XGETDEFAULT */ |
760 | # endif /* ! USE_XGETDEFAULT */ |
… | |
… | |
768 | #ifndef NO_RESOURCES |
771 | #ifndef NO_RESOURCES |
769 | |
772 | |
770 | # if defined XAPPLOADDIR |
773 | # if defined XAPPLOADDIR |
771 | # if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
774 | # if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
772 | /* Compute the path of the possibly available localized Rxvt file */ |
775 | /* Compute the path of the possibly available localized Rxvt file */ |
773 | char *localepath = NULL; |
776 | char *localepath = NULL; |
774 | |
777 | |
775 | if (locale != NULL) |
778 | if (locale != NULL) |
776 | { /* XXX: must limit length of string */ |
779 | { /* XXX: must limit length of string */ |
777 | localepath = (char *)rxvt_malloc (256); |
780 | localepath = (char *)rxvt_malloc (256); |
778 | sprintf (localepath, XAPPLOADDIRLOCALE "/" RESCLASS, |
781 | sprintf (localepath, XAPPLOADDIRLOCALE "/" RESCLASS, |
… | |
… | |
786 | |
789 | |
787 | # ifdef USE_XGETDEFAULT |
790 | # ifdef USE_XGETDEFAULT |
788 | /* |
791 | /* |
789 | * get resources using the X library function |
792 | * get resources using the X library function |
790 | */ |
793 | */ |
791 | int entry; |
794 | int entry; |
792 | |
795 | |
793 | # ifdef XrmEnumOneLevel |
796 | # ifdef XrmEnumOneLevel |
794 | int i; |
797 | int i; |
795 | char *displayResource, *xe; |
798 | char *displayResource, *xe; |
796 | XrmName name_prefix[3]; |
799 | XrmName name_prefix[3]; |
797 | XrmClass class_prefix[3]; |
800 | XrmClass class_prefix[3]; |
798 | XrmDatabase database, rdb1; |
801 | XrmDatabase database, rdb1; |
799 | char fname[1024]; |
802 | char fname[1024]; |
800 | |
803 | |
801 | XrmInitialize (); |
804 | XrmInitialize (); |
802 | database = NULL; |
805 | database = NULL; |
803 | |
806 | |
804 | /* Get any Xserver defaults */ |
807 | /* Get any Xserver defaults */ |
… | |
… | |
817 | |
820 | |
818 | for (i = 0; i < (sizeof (xnames) / sizeof (xnames[0])); i++) |
821 | for (i = 0; i < (sizeof (xnames) / sizeof (xnames[0])); i++) |
819 | { |
822 | { |
820 | sprintf (fname, "%-.*s/%s", sizeof (fname) - STRLEN (xnames[i]) - 2, |
823 | sprintf (fname, "%-.*s/%s", sizeof (fname) - STRLEN (xnames[i]) - 2, |
821 | ptr, xnames[i]); |
824 | ptr, xnames[i]); |
822 | if ((rdb1 = XrmGetFileDatabase (fname)) != NULL) |
825 | if ((rdb1 = XrmGetFileDatabase (fname))) |
823 | { |
826 | { |
824 | XrmMergeDatabases (rdb1, &database); |
827 | XrmMergeDatabases (rdb1, &database); |
825 | # ifndef HAVE_BOTH_XRESOURCE_FILES |
828 | # ifndef HAVE_BOTH_XRESOURCE_FILES |
826 | break; |
829 | break; |
827 | # endif |
830 | # endif |
… | |
… | |
978 | # ifdef RESFALLBACK |
981 | # ifdef RESFALLBACK |
979 | get_xdefaults (fd, RESFALLBACK); |
982 | get_xdefaults (fd, RESFALLBACK); |
980 | # endif |
983 | # endif |
981 | |
984 | |
982 | # if defined(XAPPLOADDIR) && defined(USE_XAPPLOADDIR) |
985 | # if defined(XAPPLOADDIR) && defined(USE_XAPPLOADDIR) |
983 | |
|
|
984 | { |
986 | { |
985 | FILE *ad = NULL; |
987 | FILE *ad = NULL; |
986 | |
988 | |
987 | # if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
989 | # if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
988 | if (localepath == NULL || (ad = fopen (localepath, "r")) == NULL) |
990 | if (localepath == NULL || (ad = fopen (localepath, "r")) == NULL) |
989 | # endif |
991 | # endif |
990 | ad = fopen (XAPPLOADDIR "/" RESCLASS, "r"); |
992 | ad = fopen (XAPPLOADDIR "/" RESCLASS, "r"); |
… | |
… | |
1011 | free (localepath); |
1013 | free (localepath); |
1012 | # endif |
1014 | # endif |
1013 | # endif |
1015 | # endif |
1014 | |
1016 | |
1015 | #endif /* NO_RESOURCES */ |
1017 | #endif /* NO_RESOURCES */ |
1016 | |
|
|
1017 | /* |
|
|
1018 | * even without resources, at least do this setup for command-line |
|
|
1019 | * options and command-line long options |
|
|
1020 | */ |
|
|
1021 | |
|
|
1022 | #if defined (HOTKEY_CTRL) || defined (HOTKEY_META) |
|
|
1023 | KeySym sym; |
|
|
1024 | |
|
|
1025 | if (rs[Rs_bigfont_key] |
|
|
1026 | && ((sym = XStringToKeysym (rs[Rs_bigfont_key])) != 0)) |
|
|
1027 | ks_bigfont = sym; |
|
|
1028 | if (rs[Rs_smallfont_key] |
|
|
1029 | && ((sym = XStringToKeysym (rs[Rs_smallfont_key])) != 0)) |
|
|
1030 | ks_smallfont = sym; |
|
|
1031 | #endif |
|
|
1032 | } |
1018 | } |
1033 | |
1019 | |
1034 | /*}}} */ |
1020 | /*}}} */ |
1035 | /*----------------------- end-of-file (C source) -----------------------*/ |
1021 | /*----------------------- end-of-file (C source) -----------------------*/ |