usr/src/lib/liborchestrator/locale.c
branchoi_151a
changeset 1431 be5c727ec6be
parent 1416 2c9d399a58c0
child 1432 cedb79a30277
equal deleted inserted replaced
1430:398513b48d4c 1431:be5c727ec6be
   100     int lang_total, lang_info_t **return_list, int *ll_total);
   100     int lang_total, lang_info_t **return_list, int *ll_total);
   101 static void	build_ll_list(char **list, int lang_total,
   101 static void	build_ll_list(char **list, int lang_total,
   102 		    lang_info_t **, int *total);
   102 		    lang_info_t **, int *total);
   103 static	char	*copy_up_to(char *start, char *t);
   103 static	char	*copy_up_to(char *start, char *t);
   104 static int	create_lang_entry(char *lang, char *locale, char *region,
   104 static int	create_lang_entry(char *lang, char *locale, char *region,
   105     lang_info_t **, boolean_t is_default);
   105     lang_info_t **, boolean_t locale_app_locale, boolean_t locale_in_installer_lang);
   106 static void	end_of_comp(char **t, char **start);
   106 static void	end_of_comp(char **t, char **start);
   107 static char 	**get_actual_languages(char **list, int *);
   107 static char 	**get_actual_languages(char **list, int *);
   108 static lang_info_t *get_lang_entry(char *, lang_info_t *search_list);
   108 static lang_info_t *get_lang_entry(char *, lang_info_t *search_list);
   109 static char 	*get_locale_component(char **t, char **start);
   109 static char 	*get_locale_component(char **t, char **start);
   110 static char 	*get_locale_description(char *lang, char *region);
   110 static char 	*get_locale_description(char *lang, char *region);
   111 static int 	handle_chinese_language(char *region, char **lang);
   111 static int 	handle_chinese_language(char *region, char **lang);
   112 static boolean_t is_locale_in_installer_lang(char *locale_name);
   112 static boolean_t is_locale_in_installer_lang(char *locale_name);
       
   113 static boolean_t is_locale_app_locale(char *locale_name);
   113 static boolean_t is_valid_locale(char *locale);
   114 static boolean_t is_valid_locale(char *locale);
   114 static int 	list_cmp(const void *p1, const void *p2);
   115 static int 	list_cmp(const void *p1, const void *p2);
   115 static int 	lang_init(char *path, char **list, int *total, int *init_var);
   116 static int 	lang_init(char *path, char **list, int *total, int *init_var);
   116 static int 	save_system_default_locale(char *locale);
   117 static int 	save_system_default_locale(char *locale);
   117 static void 	set_lang(char *locale);
   118 static void 	set_lang(char *locale);
   634  *		none
   635  *		none
   635  *
   636  *
   636  */
   637  */
   637 static int
   638 static int
   638 create_lang_entry(char *lang, char *locale, char *region,
   639 create_lang_entry(char *lang, char *locale, char *region,
   639     lang_info_t **return_list, boolean_t is_default)
   640     lang_info_t **return_list, boolean_t locale_app_locale, boolean_t locale_in_installer_lang)
   640 {
   641 {
   641 	lang_info_t	*tmp, *last, *new;
   642 	lang_info_t	*tmp, *last, *new;
   642 	locale_info_t	*lp = NULL;
   643 	locale_info_t	*lp = NULL;
   643 	char		**trans_lang = NULL;
   644 	char		**trans_lang = NULL;
   644 	char		*sub = NULL;
   645 	char		*sub = NULL;
   689 	} else {
   690 	} else {
   690 		om_set_error(OM_NOT_LANG);
   691 		om_set_error(OM_NOT_LANG);
   691 		goto error;
   692 		goto error;
   692 	}
   693 	}
   693 
   694 
   694 	new->def_lang = is_default;
   695 	new->def_lang = locale_in_installer_lang;
   695 
   696 
   696 	if (locale != NULL) {
   697 	if (locale != NULL) {
   697 		lp = (locale_info_t *)malloc(sizeof (locale_info_t));
   698 		lp = (locale_info_t *)malloc(sizeof (locale_info_t));
   698 		if (lp == NULL) {
   699 		if (lp == NULL) {
   699 			om_set_error(OM_NO_SPACE);
   700 			om_set_error(OM_NO_SPACE);
   708 		}
   709 		}
   709 
   710 
   710 		desc = get_locale_description(new->lang_name, region);
   711 		desc = get_locale_description(new->lang_name, region);
   711 		lp->locale_desc = desc;
   712 		lp->locale_desc = desc;
   712 		new->locale_info = lp;
   713 		new->locale_info = lp;
   713 		new->locale_info->def_locale = is_default;
   714 		new->locale_info->def_locale = locale_app_locale;
   714 		new->n_locales++;
   715 		new->n_locales++;
   715 	}
   716 	}
   716 	if (list != NULL) {
   717 	if (list != NULL) {
   717 		for (tmp = list, last = NULL; tmp != NULL;
   718 		for (tmp = list, last = NULL; tmp != NULL;
   718 		    last = tmp, tmp = tmp->next) {
   719 		    last = tmp, tmp = tmp->next) {
   857 	locp->locale_desc = desc;
   858 	locp->locale_desc = desc;
   858 	locp->def_locale = is_default;
   859 	locp->def_locale = is_default;
   859 
   860 
   860 	locp->next = langp->locale_info;
   861 	locp->next = langp->locale_info;
   861 	langp->locale_info = locp;
   862 	langp->locale_info = locp;
   862 	langp->def_lang = is_default;
       
   863 	langp->n_locales++;
   863 	langp->n_locales++;
   864 }
   864 }
   865 
   865 
   866 static void
   866 static void
   867 build_install_ll_list(char *nlspath, char **install_list, int lang_total,
   867 build_install_ll_list(char *nlspath, char **install_list, int lang_total,
   937 
   937 
   938 		if ((lp = get_lang_entry(lang, *return_list)) != NULL) {
   938 		if ((lp = get_lang_entry(lang, *return_list)) != NULL) {
   939 			continue;
   939 			continue;
   940 		} else {
   940 		} else {
   941 			ret = create_lang_entry(install_list[i],
   941 			ret = create_lang_entry(install_list[i],
   942 			    install_list[i], region, return_list, is_default);
   942 			    install_list[i], region, return_list, is_default, is_default);
   943 			if (!ret)
   943 			if (!ret)
   944 				num_entries++;
   944 				num_entries++;
   945 		}
   945 		}
   946 		free(lang);
   946 		free(lang);
   947 		free(region);
   947 		free(region);
  1065 	char		*lang = NULL, *encoding = NULL, *region = NULL;
  1065 	char		*lang = NULL, *encoding = NULL, *region = NULL;
  1066 	char		*locale = NULL;
  1066 	char		*locale = NULL;
  1067 	lang_info_t	*lp = NULL;
  1067 	lang_info_t	*lp = NULL;
  1068 	char		*orig, *start = NULL;
  1068 	char		*orig, *start = NULL;
  1069 	char		*t = NULL;
  1069 	char		*t = NULL;
  1070 	boolean_t	is_default = B_FALSE;
  1070 	boolean_t	locale_app_locale = B_FALSE;
       
  1071 	boolean_t	locale_in_installer_lang = B_FALSE;
  1071 
  1072 
  1072 	*total = 0;
  1073 	*total = 0;
  1073 
  1074 
  1074 	/*
  1075 	/*
  1075 	 * lang_list passed in is a sorted list of the data found in
  1076 	 * lang_list passed in is a sorted list of the data found in
  1160 		/*
  1161 		/*
  1161 		 * If we don't have the locale value, we haven't found
  1162 		 * If we don't have the locale value, we haven't found
  1162 		 * anything we are interested in, so skip.
  1163 		 * anything we are interested in, so skip.
  1163 		 */
  1164 		 */
  1164 		if (locale != NULL)  {
  1165 		if (locale != NULL)  {
  1165 			is_default = is_locale_in_installer_lang(locale);
  1166 			locale_in_installer_lang = is_locale_in_installer_lang(locale);
       
  1167 			locale_app_locale = is_locale_app_locale(locale);
       
  1168 			
  1166 			om_debug_print(OM_DBGLVL_INFO, "Adding locale: "
  1169 			om_debug_print(OM_DBGLVL_INFO, "Adding locale: "
  1167 			    "locale=%s,lang=%s,region=%s\n", locale,
  1170 			    "locale=%s,lang=%s,region=%s\n", locale,
  1168 			    lang == NULL ? "#" : lang,
  1171 			    lang == NULL ? "#" : lang,
  1169 			    region == NULL ? "#" : region);
  1172 			    region == NULL ? "#" : region);
  1170 
  1173 
  1171 			if ((lp = get_lang_entry(lang, *return_list)) != NULL) {
  1174 			if ((lp = get_lang_entry(lang, *return_list)) != NULL) {
  1172 				add_locale_entry_to_lang(lp, locale, region,
  1175 				add_locale_entry_to_lang(lp, locale, region,
  1173 				    is_default);
  1176 				    locale_app_locale);
  1174 			} else {
  1177 			} else {
  1175 				ret = create_lang_entry(lang, locale, region,
  1178 				ret = create_lang_entry(lang, locale, region,
  1176 				    return_list, is_default);
  1179 				    return_list, locale_app_locale, locale_in_installer_lang);
  1177 				if (!ret) {
  1180 				if (!ret) {
  1178 					num_langs++;
  1181 					num_langs++;
  1179 					om_debug_print(OM_DBGLVL_INFO,
  1182 					om_debug_print(OM_DBGLVL_INFO,
  1180 					    "num_langs = %d\n", num_langs);
  1183 					    "num_langs = %d\n", num_langs);
  1181 				}
  1184 				}
  1767 	(void) memset(sub, 0, diff + 1);
  1770 	(void) memset(sub, 0, diff + 1);
  1768 	(void) strlcpy(sub, start, (diff + 1));
  1771 	(void) strlcpy(sub, start, (diff + 1));
  1769 	return (sub);
  1772 	return (sub);
  1770 }
  1773 }
  1771 
  1774 
       
  1775 /* This method checks to see if the locale passed in as an argument
       
  1776  * is in the same language as the application.
       
  1777  */
  1772 static boolean_t
  1778 static boolean_t
  1773 is_locale_in_installer_lang(char *locale_name)
  1779 is_locale_in_installer_lang(char *locale_name)
  1774 {
  1780 {
  1775 	if (app_locale == NULL) {
  1781 	if (app_locale == NULL) {
  1776 		app_locale = strdup(setlocale(LC_MESSAGES, NULL));
  1782 		app_locale = strdup(setlocale(LC_MESSAGES, NULL));
  1807 		}
  1813 		}
  1808 	}
  1814 	}
  1809 
  1815 
  1810 	return (B_FALSE);
  1816 	return (B_FALSE);
  1811 }
  1817 }
       
  1818 
       
  1819 /*
       
  1820  * This method checks to see if the currently used locale is the same
       
  1821  * as the locale passed as an argument. We do this by comparing
       
  1822  * app_locale to locale_name.
       
  1823  */
       
  1824 static boolean_t
       
  1825 is_locale_app_locale(char *locale_name)
       
  1826 {
       
  1827 	if (app_locale == NULL) {
       
  1828 		app_locale = strdup(setlocale(LC_MESSAGES, NULL));
       
  1829 	}
       
  1830 
       
  1831 	if (app_locale != NULL) {
       
  1832 		if (strcmp(locale_name, app_locale) == 0) {
       
  1833 			/* locale name is same */
       
  1834 			return (B_TRUE);
       
  1835 		} 
       
  1836 	}
       
  1837 
       
  1838 	return (B_FALSE);
       
  1839 }
       
  1840 
  1812 void
  1841 void
  1813 om_save_locale(char *locale, boolean_t install_only)
  1842 om_save_locale(char *locale, boolean_t install_only)
  1814 {
  1843 {
  1815 	FILE 	*fp, *tfp;
  1844 	FILE 	*fp, *tfp;
  1816 	char	line[BUFSIZ];
  1845 	char	line[BUFSIZ];