⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xdefaults.c

📁 rxvt经典的linux下的终端.小巧实用
💻 C
📖 第 1 页 / 共 3 页
字号:
# endif				/* KEYSYM_RESOURCE */# ifndef USE_XGETDEFAULT/*{{{ rxvt_get_xdefaults() *//* * the matching algorithm used for memory-save fake resources *//* INTPROTO */voidrxvt_get_xdefaults(rxvt_t *r, FILE *stream, const char *name){    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 */	if ((str[len] != '*' && str[len] != '.')	    || (len && STRNCMP(str, name, len)))	    continue;	str += (len + 1);	/* skip `name*' or `name.' */# ifdef KEYSYM_RESOURCE	if (!rxvt_parse_keysym(r, str, NULL))# endif				/* KEYSYM_RESOURCE */	    for (entry = 0; entry < optList_size(); entry++) {		const char     *kw = optList[entry].kw;		if (kw == NULL)		    continue;		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 && r->h->rs[optList[entry].doff] == NULL) {			/* not already set */			int             s;			char           *p = rxvt_malloc((n + 1) * sizeof(char));			STRCPY(p, str);			r->h->rs[optList[entry].doff] = p;			if (optList_isBool(entry)) {			    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)				r->Options |= (optList[entry].flag);			    else				r->Options &= ~(optList[entry].flag);			}		    }		    break;		}	    }    }    rewind(stream);}/*}}} */# endif				/* ! USE_XGETDEFAULT */#endif				/* NO_RESOURCES *//*{{{ read the resources files *//* * using XGetDefault() or the hand-rolled replacement *//* ARGSUSED *//* EXTPROTO */voidrxvt_extract_resources(rxvt_t *r, Display *display __attribute__((unused)), const char *name){#ifndef NO_RESOURCES# if defined XAPPLOADDIR#  if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)    /* Compute the path of the possibly available localized Rxvt file */     char           *localepath = NULL;    if (r->h->locale != NULL) {	/* 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# 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;    char            fname[1024];    XrmInitialize();    database = NULL;/* Get any Xserver defaults */    displayResource = XResourceManagerString(display);    if (displayResource != NULL)	database = XrmGetStringDatabase(displayResource);#   ifdef HAVE_EXTRA_XRESOURCE_FILES/* Add in ~/.Xdefaults or ~/.Xresources */    {	char           *ptr;	if ((ptr = (char *)getenv("HOME")) == NULL)	    ptr = ".";	for (i = 0; i < (sizeof(xnames) / sizeof(xnames[0])); i++) {	    sprintf(fname, "%-.*s/%s", sizeof(fname) - STRLEN(xnames[i]) - 2,		    ptr, xnames[i]);	    if ((rdb1 = XrmGetFileDatabase(fname)) != NULL) {		XrmMergeDatabases(rdb1, &database);#    ifndef HAVE_BOTH_XRESOURCE_FILES		break;#    endif	    }	}    }#   endif/* Add in XENVIRONMENT file */    if ((xe = (char *)getenv("XENVIRONMENT")) != NULL	&& (rdb1 = XrmGetFileDatabase(xe)) != NULL)	XrmMergeDatabases(rdb1, &database);/* Add in Rxvt file */#   if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)    if (localepath == NULL || (rdb1 = XrmGetFileDatabase(localepath)) == NULL)#   endif    rdb1 = XrmGetFileDatabase(XAPPLOADDIR "/" APL_SUBCLASS);    if (rdb1 != NULL)        XrmMergeDatabases(rdb1, &database);/* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */    if ((xe = (char *)getenv("XAPPLRESDIR")) != NULL) {	sprintf(fname, "%-.*s/" APL_SUBCLASS, sizeof(fname)		- sizeof(APL_SUBCLASS) - 2, xe);	if ((rdb1 = XrmGetFileDatabase(fname)) != NULL)	    XrmMergeDatabases(rdb1, &database);    }    XrmSetDatabase(display, database);#  endif/* * Query resources for options that affect us */    for (entry = 0; entry < optList_size(); entry++) {	int             s;	char           *p, *p0;	const char     *kw = optList[entry].kw;	if (kw == NULL || r->h->rs[optList[entry].doff] != NULL)	    continue;		/* previously set */	p = XGetDefault(display, name, kw);	p0 = XGetDefault(display, "!INVALIDPROGRAMMENAMEDONTMATCH!", kw);	if (p == NULL || (p0 && STRCMP(p, p0) == 0)) {	    p = XGetDefault(display, APL_SUBCLASS, kw);	    if (p == NULL || (p0 && STRCMP(p, p0) == 0))		p = XGetDefault(display, APL_CLASS, kw);	}	if (p == NULL && p0)	    p = p0;	if (p) {	    r->h->rs[optList[entry].doff] = p;	    if (optList_isBool(entry)) {		s = STRCASECMP(p, "TRUE") == 0		    || STRCASECMP(p, "YES") == 0		    || STRCASECMP(p, "ON") == 0		    || STRCASECMP(p, "1") == 0;		if (optList_isReverse(entry))		    s = !s;		if (s)		    r->Options |= (optList[entry].flag);		else		    r->Options &= ~(optList[entry].flag);	    }	}    }/* * [R5 or later]: enumerate the resource database */#  ifdef XrmEnumOneLevel#   ifdef KEYSYM_RESOURCE    name_prefix[0] = XrmStringToName(name);    name_prefix[1] = XrmStringToName("keysym");    name_prefix[2] = NULLQUARK;    class_prefix[0] = XrmStringToName(APL_SUBCLASS);    class_prefix[1] = XrmStringToName("Keysym");    class_prefix[2] = NULLQUARK;/* XXX: Need to check sizeof(rxvt_t) == sizeof(XPointer) */    XrmEnumerateDatabase(XrmGetDatabase(display), name_prefix, class_prefix,			 XrmEnumOneLevel, rxvt_define_key, NULL);    name_prefix[0] = XrmStringToName(APL_CLASS);    name_prefix[1] = XrmStringToName("keysym");    class_prefix[0] = XrmStringToName(APL_CLASS);    class_prefix[1] = XrmStringToName("Keysym");/* XXX: Need to check sizeof(rxvt_t) == sizeof(XPointer) */    XrmEnumerateDatabase(XrmGetDatabase(display), 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;    char           *home;    if ((home = getenv("HOME")) != NULL) {	unsigned int    i, len = STRLEN(home) + 2;	char           *f = NULL;	for (i = 0; i < (sizeof(xnames) / sizeof(xnames[0])); i++) {	    f = rxvt_realloc(f, (len + STRLEN(xnames[i])) * sizeof(char));	    sprintf(f, "%s/%s", home, xnames[i]);	    if ((fd = fopen(f, "r")) != NULL)		break;	}	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);    rxvt_get_xdefaults(r, fd, APL_SUBCLASS);#  if defined(XAPPLOADDIR) && defined(USE_XAPPLOADDIR)    {	FILE           *ad = NULL;#   if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)	if (localepath == NULL || (ad = fopen(localepath, "r")) == NULL)#   endif	ad = fopen(XAPPLOADDIR "/" APL_SUBCLASS, "r");	if (ad != NULL) {	    rxvt_get_xdefaults(r, ad, APL_SUBCLASS);	    rxvt_get_xdefaults(r, ad, "");	    fclose(ad);	}    }#  endif			/* XAPPLOADDIR */    rxvt_get_xdefaults(r, fd, APL_CLASS);    rxvt_get_xdefaults(r, fd, "");	/* partial match */    if (fd != NULL)	fclose(fd);# endif				/* USE_XGETDEFAULT */# if defined XAPPLOADDIR#  if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)    }    /* Free the path of the possibly available localized Rxvt file */     free(localepath);#  endif# endif#endif				/* NO_RESOURCES *//* * even without resources, at least do this setup for command-line * options and command-line long options */#ifdef MULTICHAR_SET    rxvt_set_multichar_encoding(r, r->h->rs[Rs_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 */#if defined (HOTKEY_CTRL) || defined (HOTKEY_META)    {	KeySym          sym;	if (r->h->rs[Rs_bigfont_key]	    && ((sym = XStringToKeysym(r->h->rs[Rs_bigfont_key])) != 0))	    r->h->ks_bigfont = sym;	if (r->h->rs[Rs_smallfont_key]	    && ((sym = XStringToKeysym(r->h->rs[Rs_smallfont_key])) != 0))	    r->h->ks_smallfont = sym;    }#endif}/*}}} *//*----------------------- end-of-file (C source) -----------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -