1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: xdefaults.c |
2 | * File: xdefaults.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: xdefaults.C,v 1.15 2004/03/03 04:07:52 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 | } |
… | |
… | |
670 | * the matching algorithm used for memory-save fake resources |
665 | * the matching algorithm used for memory-save fake resources |
671 | */ |
666 | */ |
672 | void |
667 | void |
673 | rxvt_term::get_xdefaults (FILE *stream, const char *name) |
668 | rxvt_term::get_xdefaults (FILE *stream, const char *name) |
674 | { |
669 | { |
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; |
707 | rxvt_Str_trim (str); |
704 | rxvt_Str_trim (str); |
708 | n = STRLEN (str); |
705 | n = STRLEN (str); |
709 | if (n && rs[optList[entry].doff] == NULL) |
706 | if (n && rs[optList[entry].doff] == NULL) |
710 | { |
707 | { |
711 | /* not already set */ |
708 | /* not already set */ |
712 | int s; |
709 | int s; |
713 | char *p = (char *)rxvt_malloc ((n + 1) * sizeof (char)); |
710 | char *p = 0; |
714 | |
711 | |
|
|
712 | for (int o = 0;;) |
|
|
713 | { |
|
|
714 | p = (char *)rxvt_realloc (p, o + n + 1); |
715 | STRCPY (p, str); |
715 | MEMCPY (p + o, str, n); |
|
|
716 | o += n; |
|
|
717 | p[o] = 0; |
|
|
718 | |
|
|
719 | if (o == 0 || p[o - 1] != '\\') // continuation line |
|
|
720 | break; |
|
|
721 | |
|
|
722 | o--; // eat "\" |
|
|
723 | |
|
|
724 | if ((str = fgets (buffer, sizeof (buffer), stream)) == NULL) |
|
|
725 | break; |
|
|
726 | |
|
|
727 | rxvt_Str_trim (str); |
|
|
728 | n = STRLEN (str); |
|
|
729 | } |
|
|
730 | |
716 | rs[optList[entry].doff] = p; |
731 | rs[optList[entry].doff] = p; |
|
|
732 | allocated.push_back (p); |
|
|
733 | |
717 | if (optList_isBool (entry)) |
734 | if (optList_isBool (entry)) |
718 | { |
735 | { |
719 | s = STRCASECMP (str, "TRUE") == 0 |
736 | s = STRCASECMP (str, "TRUE") == 0 |
720 | || STRCASECMP (str, "YES") == 0 |
737 | || STRCASECMP (str, "YES") == 0 |
721 | || STRCASECMP (str, "ON") == 0 |
738 | || STRCASECMP (str, "ON") == 0 |
722 | || STRCASECMP (str, "1") == 0; |
739 | || STRCASECMP (str, "1") == 0; |
|
|
740 | |
723 | if (optList_isReverse (entry)) |
741 | if (optList_isReverse (entry)) |
724 | s = !s; |
742 | s = !s; |
|
|
743 | |
725 | if (s) |
744 | if (s) |
726 | Options |= (optList[entry].flag); |
745 | Options |= optList[entry].flag; |
727 | else |
746 | else |
728 | Options &= ~ (optList[entry].flag); |
747 | Options &= ~optList[entry].flag; |
729 | } |
748 | } |
730 | } |
749 | } |
|
|
750 | |
731 | break; |
751 | break; |
732 | } |
752 | } |
733 | } |
753 | } |
734 | } |
754 | } |
|
|
755 | |
735 | rewind (stream); |
756 | rewind (stream); |
736 | } |
757 | } |
737 | |
758 | |
738 | /*}}} */ |
759 | /*}}} */ |
739 | # endif /* ! USE_XGETDEFAULT */ |
760 | # endif /* ! USE_XGETDEFAULT */ |
… | |
… | |
750 | #ifndef NO_RESOURCES |
771 | #ifndef NO_RESOURCES |
751 | |
772 | |
752 | # if defined XAPPLOADDIR |
773 | # if defined XAPPLOADDIR |
753 | # if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
774 | # if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
754 | /* Compute the path of the possibly available localized Rxvt file */ |
775 | /* Compute the path of the possibly available localized Rxvt file */ |
755 | char *localepath = NULL; |
776 | char *localepath = NULL; |
756 | |
777 | |
757 | if (locale != NULL) |
778 | if (locale != NULL) |
758 | { /* XXX: must limit length of string */ |
779 | { /* XXX: must limit length of string */ |
759 | localepath = (char *)rxvt_malloc (256); |
780 | localepath = (char *)rxvt_malloc (256); |
760 | sprintf (localepath, XAPPLOADDIRLOCALE "/" RESCLASS, |
781 | sprintf (localepath, XAPPLOADDIRLOCALE "/" RESCLASS, |
… | |
… | |
768 | |
789 | |
769 | # ifdef USE_XGETDEFAULT |
790 | # ifdef USE_XGETDEFAULT |
770 | /* |
791 | /* |
771 | * get resources using the X library function |
792 | * get resources using the X library function |
772 | */ |
793 | */ |
773 | int entry; |
794 | int entry; |
774 | |
795 | |
775 | # ifdef XrmEnumOneLevel |
796 | # ifdef XrmEnumOneLevel |
776 | int i; |
797 | int i; |
777 | char *displayResource, *xe; |
798 | char *displayResource, *xe; |
778 | XrmName name_prefix[3]; |
799 | XrmName name_prefix[3]; |
779 | XrmClass class_prefix[3]; |
800 | XrmClass class_prefix[3]; |
780 | XrmDatabase database, rdb1; |
801 | XrmDatabase database, rdb1; |
781 | char fname[1024]; |
802 | char fname[1024]; |
782 | |
803 | |
783 | XrmInitialize (); |
804 | XrmInitialize (); |
784 | database = NULL; |
805 | database = NULL; |
785 | |
806 | |
786 | /* Get any Xserver defaults */ |
807 | /* Get any Xserver defaults */ |
… | |
… | |
799 | |
820 | |
800 | for (i = 0; i < (sizeof (xnames) / sizeof (xnames[0])); i++) |
821 | for (i = 0; i < (sizeof (xnames) / sizeof (xnames[0])); i++) |
801 | { |
822 | { |
802 | sprintf (fname, "%-.*s/%s", sizeof (fname) - STRLEN (xnames[i]) - 2, |
823 | sprintf (fname, "%-.*s/%s", sizeof (fname) - STRLEN (xnames[i]) - 2, |
803 | ptr, xnames[i]); |
824 | ptr, xnames[i]); |
804 | if ((rdb1 = XrmGetFileDatabase (fname)) != NULL) |
825 | if ((rdb1 = XrmGetFileDatabase (fname))) |
805 | { |
826 | { |
806 | XrmMergeDatabases (rdb1, &database); |
827 | XrmMergeDatabases (rdb1, &database); |
807 | # ifndef HAVE_BOTH_XRESOURCE_FILES |
828 | # ifndef HAVE_BOTH_XRESOURCE_FILES |
808 | break; |
829 | break; |
809 | # endif |
830 | # endif |
… | |
… | |
960 | # ifdef RESFALLBACK |
981 | # ifdef RESFALLBACK |
961 | get_xdefaults (fd, RESFALLBACK); |
982 | get_xdefaults (fd, RESFALLBACK); |
962 | # endif |
983 | # endif |
963 | |
984 | |
964 | # if defined(XAPPLOADDIR) && defined(USE_XAPPLOADDIR) |
985 | # if defined(XAPPLOADDIR) && defined(USE_XAPPLOADDIR) |
965 | |
|
|
966 | { |
986 | { |
967 | FILE *ad = NULL; |
987 | FILE *ad = NULL; |
968 | |
988 | |
969 | # if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
989 | # if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
970 | if (localepath == NULL || (ad = fopen (localepath, "r")) == NULL) |
990 | if (localepath == NULL || (ad = fopen (localepath, "r")) == NULL) |
971 | # endif |
991 | # endif |
972 | ad = fopen (XAPPLOADDIR "/" RESCLASS, "r"); |
992 | ad = fopen (XAPPLOADDIR "/" RESCLASS, "r"); |
… | |
… | |
993 | free (localepath); |
1013 | free (localepath); |
994 | # endif |
1014 | # endif |
995 | # endif |
1015 | # endif |
996 | |
1016 | |
997 | #endif /* NO_RESOURCES */ |
1017 | #endif /* NO_RESOURCES */ |
998 | |
|
|
999 | /* |
|
|
1000 | * even without resources, at least do this setup for command-line |
|
|
1001 | * options and command-line long options |
|
|
1002 | */ |
|
|
1003 | |
|
|
1004 | #if defined (HOTKEY_CTRL) || defined (HOTKEY_META) |
|
|
1005 | KeySym sym; |
|
|
1006 | |
|
|
1007 | if (rs[Rs_bigfont_key] |
|
|
1008 | && ((sym = XStringToKeysym (rs[Rs_bigfont_key])) != 0)) |
|
|
1009 | ks_bigfont = sym; |
|
|
1010 | if (rs[Rs_smallfont_key] |
|
|
1011 | && ((sym = XStringToKeysym (rs[Rs_smallfont_key])) != 0)) |
|
|
1012 | ks_smallfont = sym; |
|
|
1013 | #endif |
|
|
1014 | } |
1018 | } |
1015 | |
1019 | |
1016 | /*}}} */ |
1020 | /*}}} */ |
1017 | /*----------------------- end-of-file (C source) -----------------------*/ |
1021 | /*----------------------- end-of-file (C source) -----------------------*/ |