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

📄 setlocale.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
	case LC_TIME:		/* 		 * if a table given try to load it otherwise use the 		 * default (load it if necessary)		 */		if (*table)			pi->in_sgdflt = timestr = i_ldstr(table, pi);		else {			if (pi->in_sgdflt == (str_tab*)0) {			   if (	(timestr = i_ldstr(FRM_DEF, pi)) == (str_tab*)0)				return -1;		           pi->in_sgdflt = timestr;		        } else						   timestr = pi->in_sgdflt;		}		/*		 * could not load the requested table so giveup now		 */		if (timestr == (str_tab *)0) {			return -1;		}		break;	case LC_MONETARY:		/* 		 * if a table given try to load it otherwise use the 		 * default (load it if necessary)		 */		if (*table)			pi->in_sgdflt = monstr = i_ldstr(table, pi);		else {			if (pi->in_sgdflt == (str_tab*)0) {			   if (	(monstr = i_ldstr(FRM_DEF, pi)) == (str_tab*)0)				return -1;		           pi->in_sgdflt = monstr;		        } else						   monstr = pi->in_sgdflt;		}		/*		 * could not load the requested table so giveup now		 */		if (monstr == (str_tab *)0) {			return -1;		}		break;	}	return(0);}/* * commit_tables -- switch to new locale setting(s). * * SYNOPSIS *	commit_tables(cat) *	int cat; *  * DESCRIPTION *	Only once all the specified new locales have be validated, can *	the value of the locales be changed (as an error must leave the *	international environment unchanged). * *	Once all locale values to be changed have been successfully setup *	with setuptable, commit_tables should be called to switch the *	international environment to the new setting(s). * * RETURNS *	None. * *//*  * a useful macro used below to get strings from the string table */#define getstr(string, def) ((cp = i_getstr(string, _lc_strtab[cat])) ? *cp : def)/* * another useful macro to load in string table for that category */#define ldstrtab(LC_CATEGORY) i_ldstr(FRM_DEF, new_locale[LC_CATEGORY].pi)/* * yet another useful macro to test to see if a category is set to the * C locale. */#define isclocale(CAT) (new_locale[CAT].new_setting[0] == 'C' && new_locale[CAT].new_setting[1] == '\0')staticcommit_tables(cat)register int cat;{        char *cp;        intl *pi;	extern	unsigned long _pctype_siz;	switch (cat) {	case LC_ALL:		/*		 * load up string table for LC_ALL		 */		_lc_strtab[LC_ALL] = (isclocale(LC_ALL)) ? (str_tab *) 0 : ldstrtab(LC_ALL);		strcpy(cur_locale[LC_ALL].setting, new_locale[LC_ALL].new_setting);		/* drop through */	case LC_COLLATE:		if (isclocale(LC_COLLATE)) {			_lc_cldflt = (col_tab *)0;			_lc_strtab[LC_COLLATE] = (str_tab *)0;		} else {			_lc_cldflt = collate;			_lc_strtab[LC_COLLATE] = ldstrtab(LC_COLLATE);		}		strcpy(cur_locale[LC_COLLATE].setting, new_locale[LC_COLLATE].new_setting);		/*		 * if all locales to be committed, then drop through switch		 * instruction. This has been done purely to minimise		 * execution time.		 */		if (cat != LC_ALL)			break;		/* drop through */	case LC_CTYPE:		if (isclocale(LC_CTYPE)) {			_pctype = _ctype__;			_pctype_siz = 255; 	/* 004	*/			_lc_prdflt = (prp_tab *)0;			_lc_tolower = (cnv_tab *)0;			_lc_toupper = (cnv_tab *)0;			_lc_strtab[LC_CTYPE] = (str_tab *)0;		} else {			pi = new_locale[LC_CTYPE].pi;			/*			 * minus one to take account of EOF in ctype macros			 */			_pctype = pi->in_prdflt->prp_tbl - 1;			_pctype_siz = pi->in_prdflt->prp_nbspl; /* 004 */			_lc_prdflt = property;			_lc_tolower = pi->in_ilower;			_lc_toupper = pi->in_iupper;			_lc_strtab[LC_CTYPE] = ldstrtab(LC_CTYPE);		}		strcpy(cur_locale[LC_CTYPE].setting, new_locale[LC_CTYPE].new_setting);		if (cat != LC_ALL)			break;		/* drop through */	case LC_NUMERIC:		if (isclocale(LC_NUMERIC)) {			_lc_thosep = ',';			_lc_radix  = '.';			_lc_exl    = 'e';				_lc_exu    = 'E';			_lc_strtab[LC_NUMERIC] = (str_tab *)0;		} else {			pi = new_locale[LC_NUMERIC].pi;			/*			 * setup string table now as it is used by getstr			 */			_lc_strtab[LC_NUMERIC] = numstr;			_lc_thosep = getstr(THOUSEP, ',');			_lc_radix  = getstr(RADIXCHAR, '.');			_lc_exl    = getstr(EXPL_STR, 'e');			_lc_exu    = getstr(EXPU_STR, 'E');		}		strcpy(cur_locale[LC_NUMERIC].setting, new_locale[LC_NUMERIC].new_setting);		if (cat != LC_ALL)			break;		/* drop through */	case LC_TIME:		if (isclocale(LC_TIME)) 			 	_lc_strtab[LC_TIME] = (str_tab *)0;		else			_lc_strtab[LC_TIME] = timestr;		strcpy(cur_locale[LC_TIME].setting, new_locale[LC_TIME].new_setting);		if (cat != LC_ALL)			break;		/* drop through */	case LC_MONETARY:		if (isclocale(LC_MONETARY))			_lc_strtab[LC_MONETARY] = (str_tab *)0;		else			_lc_strtab[LC_MONETARY] = monstr;		strcpy(cur_locale[LC_MONETARY].setting, new_locale[LC_MONETARY].new_setting);		if (cat != LC_ALL)			break;		/* drop though */	}}/* * setname -- set the name for a LANG type variable *  * SYNOPSIS *	char * * 	setname(name, lang, terr, code, table) *	char *name, *lang, *terr, *code, *table; * * DESCRIPTION *	Concatenates all the components (if set) into the name field which *	is then returned. This call cannot fail name MUST be long enough *	for the result which will be no longer than 2 * NL_LANGMAX + 1. *	NOTE also that lang MUST have a non-null value. * * RETURNS *	The concatenated string. */staticchar *setname(name, lang, terr, code, table)register char *name, *lang, *terr, *code, *table;{		strcpy(name, lang);	if (terr && *terr) {		strcat(name, "_");		strcat(name, terr);	}	if (code && *code) {		strcat(name, ".");		strcat(name, code);	}	if (table && *table) {		strcat(name, "@");		strcat(name, table);	}	return name;}/* * return_settings -- return current locale settings * * SYNOPSIS *	char * *	return_settings(cat) *	int cat; * * DESCRIPTION *	Returns a pointer to the locale setting of the specified category. *	If LC_ALL is inquired, then a composite string is return which *	can be passed back into setlocale to restore a locale setting. * * RETURNS *	Pointer to buffer containing required locale settings. *	NULL if the category is out of range */staticchar *return_settings(cat)int cat;{	int i;	static char resultbuf[(2 * NL_LANGMAX + 1) * (_LC_MAX + 1)];	if (cat == LC_ALL) {		strcpy(resultbuf, SEPSTR);		for (i=LC_ALL; i <= _LC_MAX; i++) {			strcat(resultbuf, cur_locale[i].setting);			strcat(resultbuf, SEPSTR);		}		return(resultbuf);	}	if (cat > LC_ALL && cat <= _LC_MAX)		return(cur_locale[cat].setting);	else		return (CNULL);}/*  * macro to get the string corresponing to  symbol from the strings table * of locale cat. The string is assigned to the field of lconv. * If the string returned was null, then that field of lconv gets * assigned to default. **/#define SETLCONV(symbol,cat,field,default)\if ((lconv.field = i_getstr(symbol, _lc_strtab[cat]))\     		== (char *) 0) lconv.field = default/* * This macro is similar to the one above except that the * category is always LC_MONETARY **/#define SETLCONV_MON(symbol,field,default)\if ((lconv.field = i_getstr(symbol, _lc_strtab[LC_MONETARY]))\     		== (char *) 0) lconv.field = default/* * This macro is similar to the one above except that  * the first character of the string returned is used. **/#define SETLCONV_MON_CHAR(symbol,field,default)\if ((cp  = i_getstr(symbol, _lc_strtab[LC_MONETARY]))\     		== (char *) 0) lconv.field = default;\else\	lconv.field = cp[0]/* * * SYNOPSIS: *	struct lconv * *      localeconv(void) * * DESCRIPTION: *    	This is the ANSI defined function used to set the components *      of static struct lconv with values appropriate for the  *      formatting of numeric quantities according to the rules  *	of the current locale. The semantics are defined in 4.4.2.1 *      of the ANSI Draft. * *      Following identifiers have to be defined in the international- *      ization database so that localeconv is aware of them.  * *	ic identifier  ic example	category    affected field    default * *	RADIXCHAR	= ".";		LC_NUMERIC   decimal_point 	"." *	THOUSEP  	= "";		LC_NUMERIC   thousands_sep 	"" *	GROUPING 	= "";		LC_NUMERIC   grouping  		"" * *      Monetary example for Italy follows  * *      INT_CURR_SYMB  = "ITL.";	LC_MONETARY  int_curr_symbol 	""  *      CRNCYSTR       = "L.";		LC_MONETARY  currency_symbol 	"" *	MON_DEC_PT     = "";		LC_MONETARY  mon_decimal_point 	"" *	MON_THOUSEP    = ".";		LC_MONETARY  mon_thousands_sep 	"" *	MON_GROUPING   = etx, '\0';	LC_MONETARY  mon_grouping 	"" *	POSITIVE_SIGN  = "";		LC_MONETARY  positive_sign  	"" *	NEGATIVE_SIGN  = "-";		LC_MONETARY  negative_sign 	"" *	INT_FRAC_DIG   = '0';		LC_MONETARY  int_frac_digits 	CHAR_MAX *	FRAC_DIGITS    = '0';		LC_MONETARY  frac_digits 	CHAR_MAX *	P_CS_PRECEDES  = '1';		LC_MONETARY  p_cs_precedes 	CHAR_MAX *	P_SEP_BY_SPAC  = '0';		LC_MONETARY  p_sep_by_space 	CHAR_MAX *	N_CS_PRECEDES  = '1';		LC_MONETARY  n_cs_precedes 	CHAR_MAX *	N_SEP_BY_SPAC  = '0';		LC_MONETARY  n_sep_by_space 	CHAR_MAX *	P_SIGN_POSN    = '1';		LC_MONETARY  p_sign_posn 	CHAR_MAX *	N_SIGN_POSN    = '1';		LC_MONETARY  n_sign_posn 	CHAR_MAX * * * * RETURN: *     Returns the address of the static struct lconv. * * */#if __STDC__ == 1struct lconv *localeconv(void)#elsestruct lconv *localeconv()#endif{	char *cp;/* 	Since the C Locale values of lconv are the same as the *	values returned if a value is not available, no special *	check for the C Locale is made (for all cases). *	For C Locale the string table is null always, i.e *      i_getstr always returns 0. */	SETLCONV("RADIXCHAR",LC_NUMERIC,decimal_point,".");	SETLCONV("THOUSEP",  LC_NUMERIC,thousands_sep,"");	SETLCONV("GROUPING", LC_NUMERIC,grouping,     "");	SETLCONV_MON("INT_CURR_SYMB",     int_curr_symbol,   ""); 	SETLCONV_MON("CRNCYSTR",          currency_symbol,   "");	SETLCONV_MON("MON_DEC_PT",        mon_decimal_point, "");	SETLCONV_MON("MON_THOUSEP",       mon_thousands_sep, "");	SETLCONV_MON("MON_GROUPING",      mon_grouping,      "");	SETLCONV_MON("POSITIVE_SIGN",     positive_sign,     "");	SETLCONV_MON("NEGATIVE_SIGN",     negative_sign,     "");	SETLCONV_MON_CHAR("INT_FRAC_DIG",      int_frac_digits,   CHAR_MAX);	SETLCONV_MON_CHAR("FRAC_DIGITS",       frac_digits,       CHAR_MAX);	SETLCONV_MON_CHAR("P_CS_PRECEDES",     p_cs_precedes,     CHAR_MAX);	SETLCONV_MON_CHAR("P_SEP_BY_SPAC",     p_sep_by_space,    CHAR_MAX);	SETLCONV_MON_CHAR("N_CS_PRECEDES",     n_cs_precedes,     CHAR_MAX);	SETLCONV_MON_CHAR("N_SEP_BY_SPAC",     n_sep_by_space,    CHAR_MAX);	SETLCONV_MON_CHAR("P_SIGN_POSN",       p_sign_posn,       CHAR_MAX);	SETLCONV_MON_CHAR("N_SIGN_POSN",       n_sign_posn,       CHAR_MAX);	return(&lconv);}

⌨️ 快捷键说明

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