r4722@vps: verhaegs | 2007-05-06 13:11:19 -0400
[cake.git] / workbench / libs / locale / prefsupdate.c
blob683dc949ebf51f7e7d44799dff4adffff974e856
1 /*
2 Copyright © 1995-2007, 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 HISTORY
73 27-11-96 digulla automatically created from
74 locale_lib.fd and clib/locale_protos.h
76 *****************************************************************************/
78 AROS_LIBFUNC_INIT
80 struct IntLocale *old = NULL;
81 STRPTR language, dotptr;
82 ULONG index = 0;
84 if(locale != NULL)
86 /* Lock the locale structures */
87 ObtainSemaphore(&IntLB(LocaleBase)->lb_LocaleLock);
89 /* Remote the old locale, and decrease its user count. */
90 old = IntLB(LocaleBase)->lb_CurrentLocale;
91 old->il_Count--;
93 /* Update the count and install the new locale. */
94 IntL(locale)->il_Count++;
95 IntLB(LocaleBase)->lb_CurrentLocale = IntL(locale);
96 ReleaseSemaphore(&IntLB(LocaleBase)->lb_LocaleLock);
98 /* Let's be mean to save some hassle */
99 language = locale->loc_LanguageName;
100 if ((dotptr = strchr(language, '.'))) *dotptr = 0;
102 /* Update ENV:Language */
103 SetVar("Language", language, -1, LV_VAR | GVF_GLOBAL_ONLY);
105 /* Update UtilityBase->ub_Language */
106 while (langlist[index] != NULL)
108 if (strcmp(language, langlist[index++]) == 0)
110 /* Check for american-english */
111 if (index == 1 && locale->loc_MeasuringSystem == MS_AMERICAN) --index;
113 UtilityBase->ub_Language = index+1;
114 break;
118 if (dotptr) *dotptr = '.';
120 return (struct Locale *)old;
122 AROS_LIBFUNC_EXIT
123 } /* PrefsUpdate */