- Tabs to spaces.
[AROS.git] / workbench / libs / locale / prefsupdate.c
bloba3fb903e51d84bc0f9d20ad40422da2d84ce64cd
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Tell locale that the preferences have been changed.
6 Lang: english
7 */
9 #include <string.h>
10 #include <exec/types.h>
11 #include <proto/exec.h>
12 #include <proto/dos.h>
13 #include <proto/utility.h>
14 #include <dos/var.h>
15 #include <utility/utility.h>
16 #include "locale_intern.h"
18 static const char *langlist[] =
20 "english",
21 "deutsch",
22 "français",
23 "español",
24 "italiano",
25 "português",
26 "dansk",
27 "nederlands",
28 "norsk",
29 "suomi",
30 "svenska",
31 NULL
34 /*****i***********************************************************************
36 NAME */
37 #include <proto/locale.h>
39 AROS_LH1(struct Locale *, LocalePrefsUpdate,
41 /* SYNOPSIS */
42 AROS_LHA(struct Locale *, locale, A0),
44 /* LOCATION */
45 struct LocaleBase *, LocaleBase, 28, Locale)
47 /* FUNCTION
48 This internal function is called by the IPrefs program to
49 notify the locale.library that the system preferences have
50 been changed.
52 INPUTS
53 locale - A pointer to the new locale preferences.
55 RESULT
56 The address of the old locale preferences data. This should
57 have CloseLocale() called upon it.
59 NOTES
60 You can safely call CloseLocale() on the new Locale as this
61 function will ensure that the Locale will not be freed until
62 PrefsUpdate() is called again.
64 EXAMPLE
66 BUGS
68 SEE ALSO
70 INTERNALS
72 *****************************************************************************/
74 AROS_LIBFUNC_INIT
76 struct IntLocale *old = NULL;
77 STRPTR language, dotptr;
78 ULONG index = 0;
80 if(locale != NULL)
82 /* Lock the locale structures */
83 ObtainSemaphore(&IntLB(LocaleBase)->lb_LocaleLock);
85 /* Remote the old locale, and decrease its user count. */
86 old = IntLB(LocaleBase)->lb_CurrentLocale;
87 old->il_Count--;
89 /* Update the count and install the new locale. */
90 IntL(locale)->il_Count++;
91 IntLB(LocaleBase)->lb_CurrentLocale = IntL(locale);
92 ReleaseSemaphore(&IntLB(LocaleBase)->lb_LocaleLock);
94 /* Let's be mean to save some hassle */
95 language = locale->loc_LanguageName;
96 if ((dotptr = strchr(language, '.')))
97 *dotptr = 0;
99 /* Update ENV:Language */
100 SetVar("Language", language, -1, LV_VAR | GVF_GLOBAL_ONLY);
102 /* Update UtilityBase->ub_Language */
103 while (langlist[index] != NULL)
105 if (strcmp(language, langlist[index++]) == 0)
107 /* Check for american-english */
108 if (index == 1 && locale->loc_MeasuringSystem == MS_AMERICAN)
109 --index;
111 UtilityBase->ub_Language = index+1;
112 break;
116 if (dotptr) *dotptr = '.';
118 return (struct Locale *)old;
120 AROS_LIBFUNC_EXIT