📄 xdefaults.c
字号:
} /* Check to see if option matches */ if( ( optList[entry].kw && !STRCMP(opt, buflong) ) || ( !longopt && optList[entry].opt && !STRCASECMP(opt, bufshort) ) ) break; } /* for */ /* Found option */ if (entry < optList_size()) { if (optList_isReverse(entry)) flag = (flag == On) ? Off : On; /* string value */ if( optList_STRLEN(entry) ) { const char *str = argv[++i]; rxvt_dbgmsg ((DBG_DEBUG, DBG_RESOURCE, "string (%s,%s) = ", optList[entry].opt ? optList[entry].opt : "nil", optList[entry].kw ? optList[entry].kw : "nil")); if (flag == On && str && (optList[entry].doff != -1)) { rxvt_dbgmsg ((DBG_DEBUG, DBG_RESOURCE, "\"%s\"\n", str)); r->h->rs[optList[entry].doff + profileNum] = str; /* * special cases are handled in main.c:main() to allow X * resources to set these values before we settle for * default values */ } else rxvt_dbgmsg ((DBG_DEBUG, DBG_RESOURCE, "???\n")); } /* boolean value */ else { rxvt_dbgmsg ((DBG_DEBUG, DBG_RESOURCE, "boolean (%s,%s) = %s\n", optList[entry].opt, optList[entry].kw, flag )); if( flag == On ) SET_OPTION( r, optList[entry].flag ); else UNSET_OPTION( r, optList[entry].flag ); /* * Remember that we've set this option, so it does not get reset * later. */ SET_ARRAYOPT( pSetOpts, optList[entry].flag ); } } /* No option found */ else { if ( rxvt_str_match( opt, "macro.")) { const char *str = argv[++i]; if (NOT_NULL(str)) rxvt_parse_macros( r, opt + sizeof( "macro." ) - 1, str, 0); /* priority 0 = highest. All previous macros get replaced. */ } else { /* * various old-style options, just ignore * Obsolete since about Jan 96, * so they can probably eventually be removed */ const char *msg = "bad"; if (longopt) { opt--; bad_option = 1; } else if (!STRCMP(opt, "7") || !STRCMP(opt, "8")#ifdef GREEK_SUPPORT /* obsolete 12 May 1996 (v2.17) */ || rxvt_str_match(opt, "grk")#endif ) msg = "obsolete"; else bad_option = 1; rxvt_msg (DBG_ERROR, DBG_RESOURCE, "%s option \"%s\"", msg, --opt); } } } if (bad_option) { /* Printing the usage is too verbose ... */#if 0 rxvt_usage(0);#endif rxvt_msg (DBG_ERROR, DBG_RESOURCE, "Use -h, -help or --help to get help\n" ); exit( EXIT_FAILURE ); } rxvt_dbgmsg ((DBG_DEBUG, DBG_RESOURCE, "rxvt_get_options() done.\n"));}#ifndef NO_RESOURCES/* * Read resources from a file. "name" is the class name to use. *//* INTPROTO */voidrxvt_get_xdefaults(rxvt_t *r, FILE *stream, const char *name, macro_priority_t priority){ unsigned int len, lenstr; char TAINTED * str; char buffer[256]; rxvt_msg (DBG_INFO, DBG_RESOURCE, "rxvt_get_xdefaults (%s)\n", name); if (IS_NULL(stream)) return; len = STRLEN(name); while (NOT_NULL(str = fgets(buffer, sizeof(buffer), stream))) { unsigned int entry, n; while (*str && isspace((int) *str)) str++; /* leading whitespace */ if( (str[len] != '*' && str[len] != '.') || (len && STRNCMP(str, name, len)) ) continue; str += (len + 1); /* skip `name*' or `name.' */ lenstr = STRLEN( str ); { /* * replace '*' with '.', but stop at ':'! bug reported by * afo@zlug.org */ char* ptr = str; while (*ptr && *ptr != ':') { if ('*' == *ptr) *ptr = '.'; ptr ++; } } if( !rxvt_parse_macros( r, str, NULL, priority ) ) { for (entry = 0; entry < optList_size(); entry++) { /* const char* kw = optList[entry].kw; */ char kw[256]; int profileNum = 0; /* default is no offset */ if (IS_NULL(optList[entry].kw)) continue; STRNCPY (kw, optList[entry].kw, sizeof(kw)-1); kw[sizeof(kw)-1] = (char) 0; if( optList[entry].multiple ) { int offset = 0; /* * For backward compatibility, accept vt%d style options. */ offset = rxvt_str_match( str, "vt" ); if( offset == 0 ) offset = rxvt_str_match( str, "profile" ); /* * Copy profile%d.resource into kw. */ if( offset ) { char buf[256]; profileNum = atoi( str + offset ); if (profileNum < 0 || profileNum >= MAX_PROFILES) continue; /* out of range */ snprintf( buf, sizeof(buf)-1, "%.*s%d.%s", offset, str, profileNum, kw ); buf[sizeof(buf)-1] = '\0'; STRNCPY (kw, buf, sizeof(kw)-1); kw[sizeof(kw)-1] = '\0'; rxvt_dbgmsg ((DBG_DEBUG, DBG_RESOURCE, "Matched profile=%d kw=%s\n", profileNum, kw)); } /* * No profile%d specified. Match resource on it's own, and * use profile 0. */ else { profileNum = 0; rxvt_dbgmsg ((DBG_DEBUG, DBG_RESOURCE, "Matched default kw=%s for option %s", kw, str)); } } n = STRLEN(kw); if( n < lenstr && str[n] == ':' && rxvt_str_match(str, kw) ) { /* skip `keyword:' */ str += (n + 1); rxvt_str_trim(str); n = STRLEN(str); /* * Only set the resource if it's not already set. We read * config file items in reverse order (most significant to * least significant). So if a resource is already set, then * we should not over ride it. */ if( optList_isBool( entry ) ) { /* * Boolean options: We dont' need to duplicate the * argument of the resource string. That only wastes * memory. */ if( NOTSET_ARRAYOPT( pSetOpts, optList[entry].flag ) ) { /* * Only set this option if we've not already set it. */ int s; s = STRCASECMP(str, "true") == 0 || STRCASECMP(str, "yes") == 0 || STRCASECMP(str, "on") == 0 || STRCASECMP(str, "1") == 0; if (optList_isReverse(entry)) s = !s; if (s) SET_OPTION(r, optList[entry].flag); else UNSET_OPTION(r, optList[entry].flag); /* Remember we've already set this option */ SET_ARRAYOPT( pSetOpts, optList[entry].flag ); } } else if( IS_NULL( r->h->rs[ optList[entry].doff + profileNum ] ) ) { /* * Regular option, that has not previously been set. * The argument needs to be duplicated and stored. */ r->h->rs[optList[entry].doff+profileNum] = n && !optList_isBool(entry) ? STRDUP( str ) : emptyResource; } break; /* out of for( entry=0 ... ) */ } /* if( str[n] =':' ...) */ } /* for (entry = 0...) */ } /* if( !rxvt_parse_macros ... ) */ } /* while() */ rewind( stream );}#endif /* NO_RESOURCES *//* * Open resource files and call rxvt_get_xdefaults() for each one in turn. *//* ARGSUSED *//* EXTPROTO */voidrxvt_extract_resources ( rxvt_t *r, Display *display __attribute__((unused)), const char *name ){#ifndef NO_RESOURCES /* get resources the hard way, but save lots of memory */ FILE *fd = NULL; char *home; macro_priority_t priority = 1; /* As resources get more general, we increment this value so that resources with lower priority are not overwritten */# if defined XAPPLOADDIR# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) /* Compute the path of the possibly available localized Rxvt file */ char *localepath = NULL; if (NOT_NULL(r->h->locale)) { /* XXX: must limit length of string */ localepath = rxvt_malloc(256); sprintf( localepath, XAPPLOADDIRLOCALE "/" APL_SUBCLASS, (int) ( 258 - sizeof(XAPPLOADDIRLOCALE) - sizeof(APL_SUBCLASS)), r->h->locale); /* 258 = 255 + 4 (-.*s) - 1 (/) */ }# endif# endif /* XAPPLOADDIR */ /* open user supplied config file first */ if (NOT_NULL(r->h->rs[Rs_confFile])) fd = fopen( r->h->rs[Rs_confFile], "r" ); if (IS_NULL(fd) && NOT_NULL(home = getenv("HOME"))) { int i, len = STRLEN(home) + 2; char* f = NULL; /* possible integer overflow? */ assert (len > 0); for( i = 0; i < (sizeof(xnames) / sizeof(xnames[0])); i++ ) { /* possible integer overflow? */ assert (len + STRLEN(xnames[i]) >= len); f = rxvt_realloc( f, ( len + STRLEN(xnames[i]) ) * sizeof(char) ); sprintf( f, "%s/%s", home, xnames[i] ); if (NOT_NULL(fd = fopen(f, "r"))) break; } rxvt_free(f); } /* * 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. */ rxvt_get_xdefaults(r, fd, name, priority++); rxvt_get_xdefaults(r, fd, APL_SUBCLASS, priority++); rxvt_get_xdefaults(r, fd, APL_CLASS, priority++);#if 0 rxvt_get_xdefaults(r, fd, "", priority++); /* partial match */#endif if (NOT_NULL(fd)) fclose(fd);# if defined(XAPPLOADDIR) && defined(USE_XAPPLOADDIR) { FILE* ad = NULL;# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) if (IS_NULL(localepath) || IS_NULL(ad = fopen(localepath, "r")))# endif ad = fopen(XAPPLOADDIR "/" APL_SUBCLASS, "r"); if (NOT_NULL(ad)) { rxvt_get_xdefaults(r, ad, APL_SUBCLASS, priority++);#if 0 /* * 2006-05-23 gi1242: If we don't use the X resource database, we * don't have to match the empty class. */ rxvt_get_xdefaults(r, ad, "", priority++);#endif fclose(ad); } }# endif /* XAPPLOADDIR */ /* * Now read config from system wide config file. */ if (NOTSET_OPTION(r, Opt2_noSysConfig) && NOT_NULL(fd = fopen( PKG_CONF_DIR "/mrxvtrc", "r"))) { rxvt_get_xdefaults( r, fd, APL_SUBCLASS, priority++ ); fclose(fd); } /* * Unset resources that point to emptyResource * * 2006-06-02 gi1242: On second thought, let's leave them pointing to * emptyResource. That way we will be able to tell which resources have been * cleared by the user, and which were never set in the first place. */#if 0 { int i; for( i=0; i < NUM_RESOURCES; i++) { if( r->h->rs[i] == emptyResource ) { rxvt_dbgmsg ((DBG_DEBUG, DBG_RESOURCE, "Setting resource #%d to NULL\n", i)); r->h->rs[i] = NULL; } } }#endif# if defined XAPPLOADDIR# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) /* Free the path of the possibly available localized Rxvt file */ rxvt_free(localepath);# endif# endif#endif /* NO_RESOURCES */ /* * Clear the boolean and reverse flags from Options and Options2. Otherwise * this will cause trouble when we want to save the options. In that case, * the boolean flag is set for each boolean options. Then if we compare * Options(2) to the flag, we always get TRUE! */ UNSET_OPTION(r, ( Opt_Reverse | IS_OPTION1 ) ); UNSET_OPTION(r, ( Opt_Reverse | IS_OPTION2 ) ); UNSET_OPTION(r, ( Opt_Reverse | IS_OPTION3 ) ); UNSET_OPTION(r, ( Opt_Reverse | IS_OPTION4 ) ); /* * even without resources, at least do this setup for command-line options * and command-line long options */#ifdef MULTICHAR_SET if (r->h->rs[Rs_multichar_encoding]) rxvt_set_multichar_encoding(r, r->h->rs[Rs_multichar_encoding]); else { char* enc; if (NOT_NULL(enc = rxvt_get_encoding_from_locale (r))) rxvt_set_multichar_encoding (r, enc); else rxvt_set_multichar_encoding(r, MULTICHAR_ENCODING); }#endif#ifdef GREEK_SUPPORT /* this could be a function in grkelot.c */ /* void set_greek_keyboard (const char * str); */ if (r->h->rs[Rs_greek_keyboard]) { if (!STRCMP(r->h->rs[Rs_greek_keyboard], "iso")) greek_setmode(GREEK_ELOT928); /* former -grk9 */ else if (!STRCMP(r->h->rs[Rs_greek_keyboard], "ibm")) greek_setmode(GREEK_IBM437); /* former -grk4 */ } { KeySym sym; if (r->h->rs[Rs_greektoggle_key] && ((sym = XStringToKeysym(r->h->rs[Rs_greektoggle_key]))!=0)) r->h->ks_greekmodeswith = sym; }#endif /* GREEK_SUPPORT */}/*----------------------- end-of-file (C source) -----------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -