2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 OpenLocale() - Give access to a new locale.
8 #include <exec/types.h>
9 #include <exec/memory.h>
10 #include <libraries/locale.h>
11 #include <libraries/iffparse.h>
12 #include <prefs/prefhdr.h>
13 #include <proto/dos.h>
14 #include <prefs/locale.h>
15 #include <proto/exec.h>
16 #include <proto/iffparse.h>
17 #include "locale_intern.h"
19 #define DEBUG_OPENLOCALE(x) ;
21 extern void InitLocale(
27 /*****************************************************************************
30 #include <proto/locale.h>
32 AROS_LH1(struct Locale
*, OpenLocale
,
35 AROS_LHA(STRPTR
, name
, A0
),
38 struct LocaleBase
*, LocaleBase
, 26, Locale
)
41 This function will open for use a named locale. A locale is a
42 data structure that contains many different parameters that
43 an application needs in order to localise itself. Using this
44 information, an application can dynamically adapt to the user's
47 Locales are created using the Locale Preferences Editor. If
48 you pass NULL instead of a name, then you will receive the
49 current default Locale. This is the normal procedure.
52 name - The name of the locale you wish opened, or NULL
53 to open the current default locale. This will
54 be an IFF PREF file which contains both LCLE
58 A pointer to an initialised Locale structure, or NULL if none
59 could be opened. If NULL is returned you can use IoErr()
60 to find out what caused this error.
62 If you pass NULL, you will always succeed.
75 *****************************************************************************/
79 struct IntLocale
*locale
= NULL
;
81 DEBUG_OPENLOCALE(dprintf("OpenLocale: name <%s> localebase 0x%lx\n",
85 /* Have we been asked for a disk-based locale? */
88 struct IFFHandle
*iff
;
90 struct LocalePrefs
*lp
;
91 struct ContextNode
*cn
;
93 /* Clear error condition before we start. */
97 lp
= AllocMem(sizeof(struct LocalePrefs
), MEMF_CLEAR
);
99 DEBUG_OPENLOCALE(dprintf("OpenLocale: lp 0x%lx\n",lp
));
103 SetIoErr(ERROR_NO_FREE_STORE
);
110 DEBUG_OPENLOCALE(dprintf("OpenLocale: iff 0x%lx\n",iff
));
114 FreeMem(lp
, sizeof(struct LocalePrefs
));
115 SetIoErr(ERROR_NO_FREE_STORE
);
119 iff
->iff_Stream
= (ULONG
)Open(name
, MODE_OLDFILE
);
121 DEBUG_OPENLOCALE(dprintf("OpenLocale: stream 0x%lx\n",iff
->iff_Stream
));
123 if(iff
->iff_Stream
== 0)
125 FreeMem(lp
, sizeof(struct LocalePrefs
));
132 if(!OpenIFF(iff
, IFFF_READ
))
134 if(!StopChunk(iff
, ID_PREF
, ID_LCLE
))
138 error
= ParseIFF(iff
, IFFPARSE_SCAN
);
141 cn
= CurrentChunk(iff
);
142 if((cn
->cn_ID
== ID_LCLE
) && (cn
->cn_Type
== ID_PREF
))
144 if(ReadChunkBytes(iff
, lp
, sizeof(struct LocalePrefs
)) == sizeof(struct LocalePrefs
))
146 locale
= AllocMem(sizeof(struct IntLocale
), MEMF_CLEAR
|MEMF_PUBLIC
);
147 DEBUG_OPENLOCALE(dprintf("OpenLocale: locale 0x%lx\n",locale
));
150 InitLocale(name
, locale
, lp
, LocaleBase
);
154 SetIoErr(ERROR_NO_FREE_STORE
);
157 } /* from a stop chunk */
158 else if(error
!= IFFERR_EOC
)
166 Close((BPTR
)iff
->iff_Stream
);
168 FreeMem(lp
, sizeof(struct LocalePrefs
));
172 /* Return the current default */
174 DEBUG_OPENLOCALE(dprintf("OpenLocale: LocaleLock 0x%lx\n",&IntLB(LocaleBase
)->lb_LocaleLock
));
176 ObtainSemaphore(&IntLB(LocaleBase
)->lb_LocaleLock
);
177 locale
= IntLB(LocaleBase
)->lb_CurrentLocale
;
179 ReleaseSemaphore(&IntLB(LocaleBase
)->lb_LocaleLock
);
182 DEBUG_OPENLOCALE(dprintf("OpenLocale: Locale 0x%lx\n",locale
));
183 /* We let the optimiser do some CSE above */
184 return (struct Locale
*)locale
;