--- rxvt-unicode/src/xdefaults.C 2005/02/14 18:47:54 1.55 +++ rxvt-unicode/src/xdefaults.C 2007/09/08 20:54:51 1.113 @@ -1,4 +1,4 @@ -/*--------------------------------*-C-*---------------------------------* +/*----------------------------------------------------------------------* * File: xdefaults.C *----------------------------------------------------------------------* * @@ -6,7 +6,7 @@ * Copyright (c) 1994 Robert Nation * - original version * Copyright (c) 1997,1998 mj olesen - * Copyright (c) 2003-2004 Marc Lehmann + * Copyright (c) 2003-2006 Marc Lehmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,24 +22,21 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *----------------------------------------------------------------------*/ -/*----------------------------------------------------------------------* - * get resources from ~/.Xdefaults or ~/.Xresources with the memory-saving - * default or with XGetDefault() (#define USE_XGETDEFAULT) - *----------------------------------------------------------------------*/ -#include "../config.h" /* NECESSARY */ -#include "rxvt.h" /* NECESSARY */ +#include "../config.h" +#include "rxvt.h" #include "version.h" -#include - #ifdef KEYSYM_RESOURCE -#include "keyboard.h" +# include "keyboard.h" #endif -/* #define DEBUG_RESOURCES */ +/* place holders used for parsing command-line options */ +#define Optflag_Reverse 1 +#define Optflag_Boolean 2 +#define Optflag_Switch 4 -/*{{{ monolithic option/resource structure: */ +/* monolithic option/resource structure: */ /* * `string' options MUST have a usage argument * `switch' and `boolean' options have no argument @@ -48,38 +45,39 @@ /* INFO () - descriptive information only */ #define INFO(opt, arg, desc) \ - {0, -1, NULL, (opt), (arg), (desc)} + {0, 0, -1, NULL, (opt), (arg), (desc)} /* STRG () - command-line option, with/without resource */ #define STRG(rsp, kw, opt, arg, desc) \ - {0, (rsp), (kw), (opt), (arg), (desc)} + {0, 0, (rsp), (kw), (opt), (arg), (desc)} /* RSTRG () - resource/long-option */ #define RSTRG(rsp, kw, arg) \ - {0, (rsp), (kw), NULL, (arg), NULL} + {0, 0, (rsp), (kw), NULL, (arg), NULL} /* BOOL () - regular boolean `-/+' flag */ -#define BOOL(rsp, kw, opt, flag, desc) \ - { (Opt_Boolean| (flag)), (rsp), (kw), (opt), NULL, (desc)} +#define BOOL(rsp, kw, opt, option, flag, desc) \ + { (option), (Optflag_Boolean | (flag)), (rsp), (kw), (opt), NULL, (desc)} /* SWCH () - `-' flag */ -#define SWCH(opt, flag, desc) \ - { (flag), -1, NULL, (opt), NULL, (desc)} +#define SWCH(opt, option, flag, desc) \ + { (option), (Optflag_Switch | (flag)), -1, NULL, (opt), NULL, (desc)} /* convenient macros */ #define optList_strlen(i) \ (optList[i].flag ? 0 : (optList[i].arg ? strlen (optList[i].arg) : 1)) #define optList_isBool(i) \ - (optList[i].flag & Opt_Boolean) + (optList[i].flag & Optflag_Boolean) #define optList_isReverse(i) \ - (optList[i].flag & Opt_Reverse) + (optList[i].flag & Optflag_Reverse) #define optList_size \ (sizeof (optList) / sizeof (optList[0])) static const struct { - const unsigned long flag; /* Option flag */ - const int doff; /* data offset */ + const uint8_t index; /* Option index */ + const uint8_t flag; /* Option flag */ + const int16_t doff; /* resource value index or -1 */ const char *kw; /* keyword */ const char *opt; /* option */ const char *arg; /* argument */ @@ -91,61 +89,62 @@ STRG (Rs_term_name, "termName", "tn", "string", "value of the TERM environment variable"), STRG (Rs_geometry, NULL, "g", NULL, NULL), /* short form */ STRG (Rs_geometry, "geometry", "geometry", "geometry", "size (in characters) and position"), - SWCH ("C", Opt_console, "intercept console messages"), - SWCH ("iconic", Opt_iconic, "start iconic"), - SWCH ("ic", Opt_iconic, NULL), /* short form */ - BOOL (Rs_reverseVideo, "reverseVideo", "rv", Opt_reverseVideo, "reverse video"), - BOOL (Rs_loginShell, "loginShell", "ls", Opt_loginShell, "login shell"), - BOOL (Rs_jumpScroll, "jumpScroll", "j", Opt_jumpScroll, "jump scrolling"), - BOOL (Rs_pastableTabs, "pastableTabs", "ptab", Opt_pastableTabs, "tab characters are pastable"), -#ifdef HAVE_SCROLLBARS + SWCH ("C", Opt_console, 0, "intercept console messages"), + SWCH ("iconic", Opt_iconic, 0, "start iconic"), + SWCH ("ic", Opt_iconic, 0, NULL), /* short form */ + BOOL (Rs_reverseVideo, "reverseVideo", "rv", Opt_reverseVideo, 0, "reverse video"), + BOOL (Rs_loginShell, "loginShell", "ls", Opt_loginShell, 0, "login shell"), + BOOL (Rs_jumpScroll, "jumpScroll", "j", Opt_jumpScroll, 0, "jump scrolling"), + BOOL (Rs_skipScroll, "skipScroll", "ss", Opt_skipScroll, 0, "skip scrolling"), + BOOL (Rs_pastableTabs, "pastableTabs", "ptab", Opt_pastableTabs, 0, "tab characters are pastable"), +#if HAVE_SCROLLBARS RSTRG (Rs_scrollstyle, "scrollstyle", "mode"), - BOOL (Rs_scrollBar, "scrollBar", "sb", Opt_scrollBar, "scrollbar"), - BOOL (Rs_scrollBar_right, "scrollBar_right", "sr", Opt_scrollBar_right, "scrollbar right"), - BOOL (Rs_scrollBar_floating, "scrollBar_floating", "st", Opt_scrollBar_floating, "scrollbar without a trough"), + BOOL (Rs_scrollBar, "scrollBar", "sb", Opt_scrollBar, 0, "scrollbar"), + BOOL (Rs_scrollBar_right, "scrollBar_right", "sr", Opt_scrollBar_right, 0, "scrollbar right"), + BOOL (Rs_scrollBar_floating, "scrollBar_floating", "st", Opt_scrollBar_floating, 0, "scrollbar without a trough"), RSTRG (Rs_scrollBar_align, "scrollBar_align", "mode"), STRG (Rs_scrollBar_thickness, "thickness", "sbt", "number", "scrollbar thickness/width in pixels"), #endif - BOOL (Rs_scrollTtyOutput, "scrollTtyOutput", NULL, Opt_scrollTtyOutput, NULL), - BOOL (Rs_scrollTtyOutput, NULL, "si", Opt_Reverse | Opt_scrollTtyOutput, "scroll-on-tty-output inhibit"), - BOOL (Rs_scrollTtyKeypress, "scrollTtyKeypress", "sk", Opt_scrollTtyKeypress, "scroll-on-keypress"), - BOOL (Rs_scrollWithBuffer, "scrollWithBuffer", "sw", Opt_scrollWithBuffer, "scroll-with-buffer"), -#ifdef TRANSPARENT - BOOL (Rs_transparent, "inheritPixmap", "ip", Opt_transparent, "inherit parent pixmap"), - BOOL (Rs_transparent_all, "inheritPixmapforce", "ipf", Opt_transparent_all, "forcefully inherit root pixmap"), - SWCH ("tr", Opt_transparent, NULL), -#if TINTING + BOOL (Rs_scrollTtyOutput, "scrollTtyOutput", NULL, Opt_scrollTtyOutput, 0, NULL), + BOOL (Rs_scrollTtyOutput, NULL, "si", Opt_scrollTtyOutput, Optflag_Reverse, "scroll-on-tty-output inhibit"), + BOOL (Rs_scrollTtyKeypress, "scrollTtyKeypress", "sk", Opt_scrollTtyKeypress, 0, "scroll-on-keypress"), + BOOL (Rs_scrollWithBuffer, "scrollWithBuffer", "sw", Opt_scrollWithBuffer, 0, "scroll-with-buffer"), +#if ENABLE_TRANSPARENCY + BOOL (Rs_transparent, "inheritPixmap", "ip", Opt_transparent, 0, "inherit parent pixmap"), + SWCH ("tr", Opt_transparent, 0, NULL), STRG (Rs_color + Color_tint, "tintColor", "tint", "color", "tint color"), + STRG (Rs_shade, "shading", "sh", "%", "shade background by x %."), #endif +#if OFF_FOCUS_FADING + STRG (Rs_fade, "fading", "fade", "%", "fade colors x% percent when rxvt-unicode is losing focus"), + STRG (Rs_color + Color_fade, "fadeColor", "fadecolor", "color", "target color for off-focus fading"), #endif -#ifdef OFF_FOCUS_FADING - STRG (Rs_fade, "fading", "fade", "%", "make colors x% darker when rxvt-unicode is losing focus."), -#endif -#ifdef TINTING - STRG (Rs_shade, "shading", "sh", "%", "shade background by x% when tinting."), -#endif - BOOL (Rs_utmpInhibit, "utmpInhibit", "ut", Opt_utmpInhibit, "utmp inhibit"), + BOOL (Rs_utmpInhibit, "utmpInhibit", "ut", Opt_utmpInhibit, 0, "utmp inhibit"), #ifndef NO_BELL - BOOL (Rs_visualBell, "visualBell", "vb", Opt_visualBell, "visual bell"), +# if ENABLE_FRILLS + BOOL (Rs_urgentOnBell, "urgentOnBell", NULL, Opt_urgentOnBell, 0, NULL), +# endif + BOOL (Rs_visualBell, "visualBell", "vb", Opt_visualBell, 0, "visual bell"), # if ! defined(NO_MAPALERT) && defined(MAPALERT_OPTION) - BOOL (Rs_mapAlert, "mapAlert", NULL, Opt_mapAlert, NULL), + BOOL (Rs_mapAlert, "mapAlert", NULL, Opt_mapAlert, 0, NULL), # endif #endif #ifdef META8_OPTION - BOOL (Rs_meta8, "meta8", NULL, Opt_meta8, NULL), + BOOL (Rs_meta8, "meta8", NULL, Opt_meta8, 0, NULL), #endif #ifdef MOUSE_WHEEL - BOOL (Rs_mouseWheelScrollPage, "mouseWheelScrollPage", NULL, Opt_mouseWheelScrollPage, NULL), + BOOL (Rs_mouseWheelScrollPage, "mouseWheelScrollPage", NULL, Opt_mouseWheelScrollPage, 0, NULL), #endif #if ENABLE_FRILLS - BOOL (Rs_tripleclickwords, "tripleclickwords", "tcw", Opt_tripleclickwords, "triple click word selection"), - BOOL (Rs_insecure, "insecure", "insecure", Opt_insecure, "enable possibly insecure escape sequences"), + BOOL (Rs_tripleclickwords, "tripleclickwords", "tcw", Opt_tripleclickwords, 0, "triple click word selection"), + BOOL (Rs_insecure, "insecure", "insecure", Opt_insecure, 0, "enable possibly insecure escape sequences"), + BOOL (Rs_cursorUnderline, "cursorUnderline", "uc", Opt_cursorUnderline, 0, "underline cursor"), #endif -#ifdef CURSOR_BLINK - BOOL (Rs_cursorBlink, "cursorBlink", "bc", Opt_cursorBlink, "blinking cursor"), +#if CURSOR_BLINK + BOOL (Rs_cursorBlink, "cursorBlink", "bc", Opt_cursorBlink, 0, "blinking cursor"), #endif #ifdef POINTER_BLANK - BOOL (Rs_pointerBlank, "pointerBlank", "pb", Opt_pointerBlank, "switch off pointer after delay"), + BOOL (Rs_pointerBlank, "pointerBlank", "pb", Opt_pointerBlank, 0, "switch off pointer after delay"), #endif STRG (Rs_color + Color_bg, "background", "bg", "color", "background color"), STRG (Rs_color + Color_fg, "foreground", "fg", "color", "foreground color"), @@ -157,7 +156,6 @@ RSTRG (Rs_color + minCOLOR + 5, "color5", "color"), RSTRG (Rs_color + minCOLOR + 6, "color6", "color"), RSTRG (Rs_color + minCOLOR + 7, "color7", "color"), -#ifndef NO_BRIGHTCOLOR RSTRG (Rs_color + minBrightCOLOR + 0, "color8", "color"), RSTRG (Rs_color + minBrightCOLOR + 1, "color9", "color"), RSTRG (Rs_color + minBrightCOLOR + 2, "color10", "color"), @@ -166,7 +164,6 @@ RSTRG (Rs_color + minBrightCOLOR + 5, "color13", "color"), RSTRG (Rs_color + minBrightCOLOR + 6, "color14", "color"), RSTRG (Rs_color + minBrightCOLOR + 7, "color15", "color"), -#endif /* NO_BRIGHTCOLOR */ #ifndef NO_BOLD_UNDERLINE_REVERSE RSTRG (Rs_color + Color_BD, "colorBD", "color"), RSTRG (Rs_color + Color_IT, "colorIT", "color"), @@ -191,14 +188,9 @@ STRG (Rs_color + Color_pointer_fg, "pointerColor", "pr", "color", "pointer color"), STRG (Rs_color + Color_pointer_bg, "pointerColor2", "pr2", "color", "pointer bg color"), STRG (Rs_color + Color_border, "borderColor", "bd", "color", "border color"), -#if defined (XPM_BACKGROUND) || (MENUBAR_MAX) - RSTRG (Rs_path, "path", "search path"), -#endif /* defined (XPM_BACKGROUND) || (MENUBAR_MAX) */ #ifdef XPM_BACKGROUND + RSTRG (Rs_path, "path", "search path"), STRG (Rs_backgroundPixmap, "backgroundPixmap", "pixmap", "file[;geom]", "background pixmap"), -#endif /* XPM_BACKGROUND */ -#if (MENUBAR_MAX) - RSTRG (Rs_menu, "menu", "name[;tag]"), #endif /* fonts: command-line option = resource name */ STRG (Rs_font, "font", "fn", "fontname", "normal text font"), @@ -206,6 +198,7 @@ STRG (Rs_boldFont, "boldFont", "fb", "fontname", "bold font"), STRG (Rs_italicFont, "italicFont", "fi", "fontname", "italic font"), STRG (Rs_boldItalicFont, "boldItalicFont", "fbi", "fontname", "bold italic font"), + BOOL (Rs_intensityStyles, "intensityStyles", "is", Opt_intensityStyles, 0, "font styles imply intensity changes"), #endif #ifdef USE_XIM STRG (Rs_inputMethod, "inputMethod", "im", "name", "name of input method"), @@ -218,13 +211,23 @@ STRG (Rs_title, NULL, "T", NULL, NULL), /* short form */ STRG (Rs_iconName, "iconName", "n", "string", "icon name for window"), STRG (Rs_saveLines, "saveLines", "sl", "number", "number of scrolled lines to save"), -#if ENABLE_FRILLS +#if ENABLE_XEMBED STRG (Rs_embed, NULL, "embed", "windowid", "window id to embed terminal in"), +#endif +#if XFT + STRG (Rs_depth, "depth", "depth", "number", "depth of visual to request"), +#endif +#if ENABLE_FRILLS + RSTRG (Rs_transient_for, "transient-for", "windowid"), + BOOL (Rs_override_redirect, "override-redirect", "override-redirect", Opt_override_redirect, 0, "set override-redirect on the terminal window"), + STRG (Rs_pty_fd, NULL, "pty-fd", "fileno", "file descriptor of pty to use"), + BOOL (Rs_hold, "hold", "hold", Opt_hold, 0, "retain window after shell exit"), STRG (Rs_ext_bwidth, "externalBorder", "w", "number", "external border in pixels"), STRG (Rs_ext_bwidth, NULL, "bw", NULL, NULL), STRG (Rs_ext_bwidth, NULL, "borderwidth", NULL, NULL), STRG (Rs_int_bwidth, "internalBorder", "b", "number", "internal border in pixels"), - BOOL (Rs_borderLess, "borderLess", "bl", Opt_borderLess, "borderless window"), + BOOL (Rs_borderLess, "borderLess", "bl", Opt_borderLess, 0, "borderless window"), + BOOL (Rs_skipBuiltinGlyphs, "skipBuiltinGlyphs", "sbg", Opt_skipBuiltinGlyphs, 0, "do not use internal glyphs"), STRG (Rs_lineSpace, "lineSpace", "lsp", "number", "number of extra pixels between rows"), #endif #ifdef POINTER_BLANK @@ -246,13 +249,24 @@ #endif /* CUTCHAR_RESOURCE */ RSTRG (Rs_answerbackstring, "answerbackString", "string"), #ifndef NO_SECONDARY_SCREEN - BOOL (Rs_secondaryScreen, "secondaryScreen", "ssc", Opt_secondaryScreen, "enable secondary screen"), - BOOL (Rs_secondaryScroll, "secondaryScroll", "ssr", Opt_secondaryScroll, "enable secondary screen scroll"), + BOOL (Rs_secondaryScreen, "secondaryScreen", "ssc", Opt_secondaryScreen, 0, "enable secondary screen"), + BOOL (Rs_secondaryScroll, "secondaryScroll", "ssr", Opt_secondaryScroll, 0, "enable secondary screen scroll"), #endif -#if 0 && TODO -#if !defined(NO_RESOURCES) && defined(USE_XGETDEFAULT) - INFO ("xrm", "string", "X resource"), +#if ENABLE_PERL + RSTRG (Rs_perl_lib, "perl-lib", "string"), //, "colon-separated directories with extension scripts"),TODO + RSTRG (Rs_perl_eval, "perl-eval", "perl-eval"), // "string", "code to be evaluated after all extensions have been loaded"),TODO + RSTRG (Rs_perl_ext_1, "perl-ext-common", "string"), //, "colon-separated list of perl extensions to enable"),TODO + STRG (Rs_perl_ext_2, "perl-ext", "pe", "string", "colon-separated list of perl extensions to enable for this instance"), +#endif +#if ISO_14755 + BOOL (Rs_iso14755_52, "iso14755_52", NULL, Opt_iso14755_52, 0, NULL), #endif +#ifdef HAVE_AFTERIMAGE + STRG (Rs_blendtype, "blendType", "blt", "string", "background image blending type - alpha, tint, etc..."), + STRG (Rs_blurradius, "blurRadius", "blr", "HxV", "Gaussian Blur radii to apply to the root background"), +#endif +#ifndef NO_RESOURCES + INFO ("xrm", "string", "X resource"), #endif INFO ("e", "command arg ...", "command to execute") }; @@ -262,10 +276,12 @@ #undef RSTRG #undef SWCH #undef BOOL -/*}}} */ static const char releasestring[] = "rxvt-unicode (" RXVTNAME ") v" VERSION " - released: " DATE "\n"; static const char optionsstring[] = "options: " +#if ENABLE_PERL + "perl," +#endif #if XFT "xft," #endif @@ -307,48 +323,16 @@ #if defined(XPM_BACKGROUND) "XPM," #endif -#if defined(TRANSPARENT) +#if defined(ENABLE_TRANSPARENCY) "transparent," -#endif -#if TINTING "tint," #endif -#if defined(UTMP_SUPPORT) - "utmp," -#endif -#if defined(MENUBAR) - "menubar," +#if HAVE_AFTERIMAGE + "afterimage," #endif #if defined(USE_XIM) "XIM," #endif - "scrollbars=" -#if !defined(HAVE_SCROLLBARS) - "NONE" -#else -# if defined(PLAIN_SCROLLBAR) - "plain" -# if defined(RXVT_SCROLLBAR) || defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR) - "+" -# endif -# endif -# if defined(RXVT_SCROLLBAR) - "rxvt" -# if defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR) - "+" -# endif -# endif -# if defined(NEXT_SCROLLBAR) - "NeXT" -# if defined(XTERM_SCROLLBAR) - "+" -# endif -# endif -# if defined(XTERM_SCROLLBAR) - "xterm" -# endif -#endif - "," #if defined(NO_BACKSPACE_KEY) "no_backspace," #endif @@ -358,15 +342,9 @@ #if EIGHT_BIT_CONTROLS "8bitctrls," #endif -#if !defined(NO_STRINGS) - "strings," -#endif #if defined(ENABLE_FRILLS) "frills," #endif -#if defined(PREFER_24BIT) - "24bit," -#endif #if defined(SELECTION_SCROLLING) "selectionscrolling," #endif @@ -386,18 +364,42 @@ "pointerBlank," #endif #if defined(NO_RESOURCES) - "NoResources" + "NoResources," +#endif + "scrollbars=" +#if !defined(HAVE_SCROLLBARS) + "NONE" #else -# if defined(USE_XGETDEFAULT) - "XGetDefaults" -# else - ".Xdefaults" +# if defined(PLAIN_SCROLLBAR) + "plain" +# if defined(RXVT_SCROLLBAR) || defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR) + "+" +# endif +# endif +# if defined(RXVT_SCROLLBAR) + "rxvt" +# if defined(NEXT_SCROLLBAR) || defined(XTERM_SCROLLBAR) + "+" +# endif +# endif +# if defined(NEXT_SCROLLBAR) + "NeXT" +# if defined(XTERM_SCROLLBAR) + "+" +# endif +# endif +# if defined(XTERM_SCROLLBAR) + "xterm" # endif #endif "\nUsage: "; /* Usage */ #define INDENT 18 +const char rxvt_term::resval_undef [] = ""; +const char rxvt_term::resval_on [] = "on"; +const char rxvt_term::resval_off [] = "off"; + /*{{{ usage: */ /*----------------------------------------------------------------------*/ static void @@ -415,7 +417,7 @@ for (col = 1, i = 0; i < optList_size; i++) if (optList[i].desc != NULL) { - int len = 0; + int len = 0; if (!optList_isBool (i)) { @@ -492,8 +494,7 @@ void rxvt_term::get_options (int argc, const char *const *argv) { - int i, bad_option = 0; - static const char On[3] = "ON", Off[4] = "OFF"; + int i, bad_option = 0; for (i = 1; i < argc; i++) { @@ -501,18 +502,18 @@ const char *flag, *opt; opt = argv[i]; -#ifdef DEBUG_RESOURCES - fprintf (stderr, "argv[%d] = %s: ", i, opt); -#endif + if (*opt == '-') { - flag = On; + flag = resval_on; + if (*++opt == '-') longopt = *opt++; /* long option */ } else if (*opt == '+') { - flag = Off; + flag = resval_off; + if (*++opt == '+') longopt = *opt++; /* long option */ } @@ -525,6 +526,7 @@ if (!strcmp (opt, "help")) rxvt_usage (longopt ? 2 : 1); + if (!strcmp (opt, "h")) rxvt_usage (0); @@ -538,7 +540,7 @@ if (entry < optList_size) { if (optList_isReverse (entry)) - flag = flag == On ? Off : On; + flag = flag == resval_on ? resval_off : resval_on; if (optList_strlen (entry)) { @@ -549,19 +551,16 @@ */ if (optList[entry].doff != -1) - rs[optList[entry].doff] = flag == On && argv[i+1] - ? argv[++i] : 0; + { + if (flag == resval_on && !argv [i+1]) + rxvt_fatal ("option '%s' needs an argument, aborting.\n", argv [i]); + + rs[optList[entry].doff] = flag == resval_on ? argv[++i] : resval_undef; + } } else { /* boolean value */ -#ifdef DEBUG_RESOURCES - fprintf (stderr, "boolean (%s,%s) = %s\n", - optList[entry].opt, optList[entry].kw, flag); -#endif - if (flag == On) - options |= optList[entry].flag; - else - options &= ~optList[entry].flag; + set_option (optList[entry].index, flag == resval_on); if (optList[entry].doff != -1) rs[optList[entry].doff] = flag; @@ -569,8 +568,7 @@ } else #ifdef KEYSYM_RESOURCE - /* if (!strncmp (opt, "keysym.", sizeof ("keysym.") - 1)) */ - if (rxvt_Str_match (opt, "keysym.")) + if (!strncmp (opt, "keysym.", sizeof ("keysym.") - 1)) { const char *str = argv[++i]; @@ -603,12 +601,12 @@ */ /* ARGSUSED */ int -rxvt_define_key (XrmDatabase *database __attribute__((unused)), - XrmBindingList bindings __attribute__((unused)), +rxvt_define_key (XrmDatabase *database UNUSED, + XrmBindingList bindings UNUSED, XrmQuarkList quarks, - XrmRepresentation *type __attribute__((unused)), + XrmRepresentation *type UNUSED, XrmValue *value, - XPointer closure __attribute__((unused))) + XPointer closure UNUSED) { int last; @@ -676,11 +674,12 @@ if (arg == NULL) { - if ((n = rxvt_Str_match (str, "keysym.")) == 0) + n = sizeof ("keysym.") - 1; + if (strncmp (str, "keysym.", n)) return 0; str += n; /* skip `keysym.' */ - if ((pmodend = strchr (str, ':')) < str) + if (!(pmodend = strchr (str, ':'))) return -1; } else @@ -759,8 +758,7 @@ newarg = newargstr; } - rxvt_Str_trim (newarg); - if (*newarg == '\0' || (n = rxvt_Str_escaped (newarg)) == 0) + if (*newarg == '\0') return -1; keyboard->register_user_translation (sym, state, newarg); @@ -768,251 +766,65 @@ } # endif /* KEYSYM_RESOURCE */ +#endif /* NO_RESOURCES */ -# ifndef USE_XGETDEFAULT -/*{{{ rxvt_get_xdefaults () */ -/* - * the matching algorithm used for memory-save fake resources - */ -void -rxvt_term::get_xdefaults (FILE *stream, const char *name) +static char * +get_res (XrmDatabase database, const char *program, const char *option) { - unsigned int len; - char *str, buffer[256]; - - if (stream == NULL) - return; - - len = strlen (name); - while ((str = fgets (buffer, sizeof (buffer), stream)) != NULL) - { - unsigned int entry, n; - - while (*str && isspace (*str)) - str++; /* leading whitespace */ + char resource[512]; + char *type; + XrmValue result; - if ((str[len] != '*' && str[len] != '.') - || (len && strncmp (str, name, len))) - continue; - str += (len + 1); /* skip `name*' or `name.' */ + snprintf (resource, sizeof (resource), "%s.%s", program, option); + XrmGetResource (database, resource, resource, &type, &result); -# ifdef KEYSYM_RESOURCE - if (!parse_keysym (str, NULL)) -# endif /* KEYSYM_RESOURCE */ - for (entry = 0; entry < optList_size; entry++) - { - const char *kw = optList[entry].kw; + return result.addr; +} - if (kw == NULL) - continue; +const char * +rxvt_term::x_resource (const char *name) +{ + XrmDatabase database = XrmGetDatabase (dpy); - n = strlen (kw); - if (str[n] == ':' && rxvt_Str_match (str, kw)) - { - /* skip `keyword:' */ - str += n + 1; - rxvt_Str_trim (str); - n = strlen (str); - - if (n && rs[optList[entry].doff] == NULL) - { - /* not already set */ - int s; - char *p = 0; - - for (int o = 0;;) - { - p = (char *)rxvt_realloc (p, o + n + 1); - memcpy (p + o, str, n); - o += n; - p[o] = 0; - - if (o == 0 || p[o - 1] != '\\') // continuation line - break; - - o--; // eat "\" - - if ((str = fgets (buffer, sizeof (buffer), stream)) == NULL) - break; - - rxvt_Str_trim (str); - n = strlen (str); - } - - rs[optList[entry].doff] = p; - allocated.push_back (p); - - if (optList_isBool (entry)) - { - s = strcasecmp (str, "true") == 0 - || strcasecmp (str, "yes") == 0 - || strcasecmp (str, "on") == 0 - || strcmp (str, "1") == 0; - - if (optList_isReverse (entry)) - s = !s; - - if (s) - options |= optList[entry].flag; - else - options &= ~optList[entry].flag; - } - } + const char *p = get_res (database, rs[Rs_name], name); + const char *p0 = get_res (database, "!INVALIDPROGRAMMENAMEDONTMATCH!", name); - break; - } - } + if (p == NULL || (p0 && strcmp (p, p0) == 0)) + { + p = get_res (database, RESCLASS, name); +#ifdef RESFALLBACK + if (p == NULL || (p0 && strcmp (p, p0) == 0)) + p = get_res (database, RESFALLBACK, name); +#endif } - rewind (stream); -} + if (p == NULL && p0) + p = p0; -/*}}} */ -# endif /* ! USE_XGETDEFAULT */ -#endif /* NO_RESOURCES */ + return p; +} -/*{{{ read the resources files */ -/* - * using XGetDefault () or the hand-rolled replacement - */ -/* ARGSUSED */ void rxvt_term::extract_resources () { - dDisp; - #ifndef NO_RESOURCES - - char *homedir = (char *)getenv ("HOME"); - char fname[1024]; - -# if defined XAPPLOADDIR -# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) - /* Compute the path of the possibly available localized Rxvt file */ - char localepath[1024]; - - if (locale) - snprintf (localepath, sizeof (localepath), XAPPLOADDIRLOCALE "/" RESCLASS, locale); - else - localepath[0] = 0; -# endif -# endif - -# ifdef USE_XGETDEFAULT - /* - * get resources using the X library function - */ - int entry; - -# ifdef XrmEnumOneLevel - int i; - char *displayResource, *xe; - XrmName name_prefix[3]; - XrmClass class_prefix[3]; - XrmDatabase database, rdb1; - - XrmInitialize (); - database = NULL; - - // for ordering, see for example http://www.faqs.org/faqs/Xt-FAQ/ Subject: 20 - - // 6. System wide per application default file. - /* Add in Rxvt file */ -# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) - if (*localepath - && ((rdb1 = XrmGetFileDatabase (localepath)) - || (rdb1 = XrmGetFileDatabase (XAPPLOADDIR "/" RESCLASS)))) -# endif - XrmMergeDatabases (rdb1, &database); - - /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */ - if ((xe = (char *)getenv ("XAPPLRESDIR"))) - { - snprintf (fname, sizeof (fname), "%s/%s", xe, RESCLASS); - - if ((rdb1 = XrmGetFileDatabase (fname))) - XrmMergeDatabases (rdb1, &database); - } - - // 5. User's per application default file. - // none - - // 4. User's defaults file. - /* Get any Xserver defaults */ - displayResource = XResourceManagerString (disp); - if (displayResource != NULL) - { - if ((rdb1 = XrmGetStringDatabase (displayResource))) - XrmMergeDatabases (rdb1, &database); - } - else if (homedir) - { - snprintf (fname, sizeof (fname), "%s/.Xdefaults", homedir); - - if ((rdb1 = XrmGetFileDatabase (fname))) - XrmMergeDatabases (rdb1, &database); - } - - /* Get screen specific resources */ - displayResource = XScreenResourceString (ScreenOfDisplay (disp, display->screen)); - if (displayResource != NULL) - { - if ((rdb1 = XrmGetStringDatabase (displayResource))) - /* Merge with screen-independent resources */ - XrmMergeDatabases (rdb1, &database); - - XFree (displayResource); - } - - // 3. User's per host defaults file - /* Add in XENVIRONMENT file */ - if ((xe = (char *)getenv ("XENVIRONMENT")) - && (rdb1 = XrmGetFileDatabase (xe))) - XrmMergeDatabases (rdb1, &database); - else if (homedir) - { - struct utsname un; - - if (!uname (&un)) - { - snprintf (fname, sizeof (fname), "%s/.Xdefaults-%s", homedir, un.nodename); - - if ((rdb1 = XrmGetFileDatabase (fname))) - XrmMergeDatabases (rdb1, &database); - } - } - - XrmSetDatabase (disp, database); -# endif - /* * Query resources for options that affect us */ - for (entry = 0; entry < optList_size; entry++) + for (int entry = 0; entry < optList_size; entry++) { int s; - char *p, *p0; const char *kw = optList[entry].kw; if (kw == NULL || rs[optList[entry].doff] != NULL) - continue; /* previously set */ + continue; // previously set - p = XGetDefault (disp, rs[Rs_name], kw); - p0 = XGetDefault (disp, "!INVALIDPROGRAMMENAMEDONTMATCH!", kw); - if (p == NULL || (p0 && strcmp (p, p0) == 0)) - { - p = XGetDefault (disp, RESCLASS, kw); -#ifdef RESFALLBACK - if (p == NULL || (p0 && strcmp (p, p0) == 0)) - p = XGetDefault (disp, RESFALLBACK, kw); -#endif - } - - if (p == NULL && p0) - p = p0; + const char *p = x_resource (kw); if (p) { + p = strdup (p); + allocated.push_back ((void *)p); rs[optList[entry].doff] = p; if (optList_isBool (entry)) @@ -1025,10 +837,7 @@ if (optList_isReverse (entry)) s = !s; - if (s) - options |= optList[entry].flag; - else - options &= ~optList[entry].flag; + set_option (optList[entry].index, s); } } } @@ -1037,6 +846,10 @@ * [R5 or later]: enumerate the resource database */ # ifdef KEYSYM_RESOURCE + XrmDatabase database = XrmGetDatabase (dpy); + XrmName name_prefix[3]; + XrmClass class_prefix[3]; + name_prefix[0] = XrmStringToName (rs[Rs_name]); name_prefix[1] = XrmStringToName ("keysym"); name_prefix[2] = NULLQUARK; @@ -1044,7 +857,7 @@ class_prefix[1] = XrmStringToName ("Keysym"); class_prefix[2] = NULLQUARK; /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */ - XrmEnumerateDatabase (XrmGetDatabase (disp), name_prefix, class_prefix, + XrmEnumerateDatabase (database, name_prefix, class_prefix, XrmEnumOneLevel, rxvt_define_key, NULL); # ifdef RESFALLBACK name_prefix[0] = XrmStringToName (RESFALLBACK); @@ -1052,79 +865,12 @@ class_prefix[0] = XrmStringToName (RESFALLBACK); class_prefix[1] = XrmStringToName ("Keysym"); /* XXX: Need to check sizeof (rxvt_t) == sizeof (XPointer) */ - XrmEnumerateDatabase (XrmGetDatabase (disp), name_prefix, class_prefix, + XrmEnumerateDatabase (database, name_prefix, class_prefix, XrmEnumOneLevel, rxvt_define_key, NULL); # endif # endif -# else /* USE_XGETDEFAULT */ - /* get resources the hard way, but save lots of memory */ - FILE *fd = NULL; - - if (homedir) - { - static const char *const xnames[2] = { ".Xdefaults", ".Xresources" }; - - for (int i = 0; i < (sizeof (xnames) / sizeof (xnames [0])); i++) - { - snprintf (fname, sizeof (fname), "%s/%s", homedir, xnames [i]); - - if ((fd = fopen (fname, "r")) != NULL) - break; - } - } - /* - * The normal order to match resources is the following: - * @ global resources (partial match, ~/.Xdefaults) - * @ application file resources (XAPPLOADDIR/Rxvt) - * @ class resources (~/.Xdefaults) - * @ private resources (~/.Xdefaults) - * - * However, for the hand-rolled resources, the matching algorithm - * checks if a resource string value has already been allocated - * and won't overwrite it with (in this case) a less specific - * resource value. - * - * This avoids multiple allocation. Also, when we've called this - * routine command-line string options have already been applied so we - * needn't to allocate for those resources. - * - * So, search in resources from most to least specific. - * - * Also, use a special sub-class so that we can use either or both of - * "XTerm" and "Rxvt" as class names. - */ - - get_xdefaults (fd, rs[Rs_name]); - get_xdefaults (fd, RESCLASS); -# ifdef RESFALLBACK - get_xdefaults (fd, RESFALLBACK); -# endif - -# if defined(XAPPLOADDIR) && defined(USE_XAPPLOADDIR) - { - FILE *ad = NULL; - -# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) - if (!*localepath || (ad = fopen (localepath, "r")) == NULL) -# endif - ad = fopen (XAPPLOADDIR "/" RESCLASS, "r"); - if (ad != NULL) - { - get_xdefaults (ad, RESCLASS); - get_xdefaults (ad, ""); - fclose (ad); - } - } -# endif /* XAPPLOADDIR */ - - get_xdefaults (fd, ""); /* partial match */ - if (fd != NULL) - fclose (fd); -# endif /* USE_XGETDEFAULT */ - #endif /* NO_RESOURCES */ } -/*}}} */ /*----------------------- end-of-file (C source) -----------------------*/