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

📄 xdefaults.c

📁 Mrxvt是一个小巧
💻 C
📖 第 1 页 / 共 3 页
字号:
				STRNCPY (bufshort, optList[entry].opt,					sizeof(bufshort)-1);				bufshort[sizeof(bufshort)-1] = '\0';			}			/* 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];				DBG_MSG(2, (stderr, "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))				{					DBG_MSG(2, (stderr, "\"%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					 */				}#ifdef DEBUG_VERBOSE				else					DBG_MSG(2, (stderr, "???\n"));#endif			}			/* boolean value */			else			{				DBG_MSG(2, (stderr, "boolean (%s,%s) = %s\n",					optList[entry].opt, optList[entry].kw, flag));				if ((optList[entry].doff+profileNum) < Rs_options2)				{					if (flag == On)						r->Options |= (optList[entry].flag);					else						r->Options &= ~(optList[entry].flag);				}				else				{					if (flag == On)						r->Options2 |= (optList[entry].flag);					else						r->Options2 &= ~(optList[entry].flag);				}				if ((optList[entry].doff+profileNum) != -1)					r->h->rs[optList[entry].doff+profileNum] = flag;			}		}		/* No option found */		else		{			if ( rxvt_str_match( opt, "macro."))			{				const char	*str = argv[++i];				if( str != NULL )					rxvt_parse_macros( r, opt + sizeof( "macro." ) - 1,							str, False); /* Replace previous macros */			}			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_print_error("%s option \"%s\"", msg, --opt);			}		}	}	if (bad_option)	{		/* Printing the usage is too verbose ... */#if 0		rxvt_usage(0);#endif		rxvt_print_error( "Use -h, -help or --help to get help" );		exit( EXIT_FAILURE );	}	DBG_MSG( 2, (stderr, "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){	DBG_MSG( 2, ( stderr, "rxvt_get_xdefaults()\n" ) );	unsigned int	len;	char TAINTED *	str;	char			buffer[256];	/* Macros defined with APL_CLASS or APL_SUBCLASS will not replace previous	 * user defined macros */	Bool	noReplace = !STRCMP( name, APL_CLASS )							|| !STRCMP( name, APL_SUBCLASS);	DBG_MSG(1, (stderr, "rxvt_get_xdefaults (%s)\n", name));	if (stream == NULL)		return;	len = STRLEN(name);	while ((str = fgets(buffer, sizeof(buffer), stream)) != NULL)	{		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.' */		{			/* 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, noReplace) )		{			for (entry = 0; entry < optList_size(); entry++)			{				/* const char*	kw = optList[entry].kw; */				char	kw[256];				int		profileNum = 0;	/* default is no offset */				if (optList[entry].kw == NULL)					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';						DBG_MSG( 3, ( stderr, "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;						DBG_MSG( 3, ( stderr,									"Matched default kw=%s for option %s",									kw, str) );					}				}				n = STRLEN(kw);				if (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 */					if( !r->h->rs[optList[entry].doff+profileNum] )					{						int		s;						r->h->rs[optList[entry].doff+profileNum] =							n ? STRDUP( str ) : emptyResource;						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 ((optList[entry].doff+profileNum) < Rs_options2)							{								if (s)									r->Options |= (optList[entry].flag);								else									r->Options &= ~(optList[entry].flag);							}							else							{								if (s)									r->Options2 |= (optList[entry].flag);								else									r->Options2 &= ~(optList[entry].flag);							}						}					}					break;				}	/* 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# 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	/* get resources the hard way, but save lots of memory */	FILE		   *fd = NULL;	char		   *home;	/* open user supplied config file first */	if (r->h->rs[Rs_confFile])		fd = fopen( r->h->rs[Rs_confFile], "r" );	if( NULL == fd && NULL != ( home = getenv("HOME") ) )	{		unsigned 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]) > 0 );			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);	rxvt_get_xdefaults(r, fd, APL_CLASS);#if 0	rxvt_get_xdefaults(r, fd, "");	/* partial match */#endif	if (fd != NULL)		fclose(fd);#  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);#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, "");#endif			fclose(ad);		}	}#  endif			/* XAPPLOADDIR */	/*	 * Now read config from system wide config file.	 */	if(		!(r->Options2 & Opt2_noSysConfig) &&		(fd = fopen( PKG_CONF_DIR "/mrxvtrc", "r") ) != NULL	  )	{		rxvt_get_xdefaults( r, fd, APL_SUBCLASS );		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 )			{				DBG_TMSG( 3, ( stderr, "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 */ 	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!	 */	r->Options &= ~(Opt_Boolean | Opt_Reverse);	r->Options2 &= ~(Opt_Boolean | Opt_Reverse);	/*	 * 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		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 + -