-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocale.c
163 lines (133 loc) · 4.06 KB
/
locale.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
The contents of this file are subject to the AROS Public License Version 1.1
(the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.aros.org/license.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the License.
*/
#if defined(__AROS__) || defined(__MORPHOS__) || defined(__amigaos4__)
#define CATCOMP_ARRAY 1
#else
#error Provide locale specific definition for your system
#endif
#define NEW_CATCOMP_ARRAY_IDS
#include "locale.h"
#include "version.h"
#include <proto/locale.h>
#include <proto/exec.h>
#include <SDI_hook.h>
#include "functions.h"
static struct Catalog *locale_catalog = NULL;
struct Locale *locale_locale;
/*************************************************************************/
/* /// Locale_Open()
**
*/
/*************************************************************************/
BOOL Locale_Open( STRPTR catname, ULONG version, ULONG revision)
{
if( ( LocaleBase = (APTR) OpenLibrary( (_ub_cs) "locale.library",0 ) ) ) {
#ifdef __amigaos4__
extern struct LocaleIFace *ILocale;
ILocale = (struct LocaleIFace *) GetInterface( LocaleBase, "main", 1, NULL );
#endif
RemLibrary( (struct Library *) LocaleBase );
if( ( locale_locale = OpenLocale( NULL ) ) ) {
if( ( locale_catalog = OpenCatalogA( locale_locale, catname, TAG_DONE ) ) ) {
if( locale_catalog->cat_Version == version &&
locale_catalog->cat_Revision == revision ) {
return( TRUE );
}
CloseCatalog( locale_catalog ); /* so close catalog */
locale_catalog = NULL; /* and use default (if present) */
}
}
}
return FALSE;
}
/* \\\ */
/* /// Locale_Close()
**
*/
/*************************************************************************/
void Locale_Close(void)
{
if( LocaleBase) {
if( locale_catalog) {
CloseCatalog(locale_catalog);
locale_catalog = NULL;
}
if( locale_locale) {
CloseLocale(locale_locale);
locale_locale = NULL;
}
RemLibrary( (struct Library *) LocaleBase ); /* flush our catalog */
#ifdef __amigaos4__
DropInterface((struct Interface *)ILocale);
#endif
/* flush our catalog */
RemLibrary( (struct Library *) LocaleBase );
CloseLibrary( (APTR) LocaleBase );
LocaleBase = NULL;
}
}
/* \\\ */
/* /// Locale_GetString()
**
*/
/*************************************************************************/
STRPTR Locale_GetString( long id )
{
#if defined(__AROS__) || defined(__MORPHOS__) || defined(__amigaos4__)
if (LocaleBase && locale_catalog != NULL)
{
return (STRPTR)GetCatalogStr(locale_catalog, id, CatCompArray[id].cca_Str);
}
else
{
return CatCompArray[id].cca_Str;
}
#else
#error Provide locale specific definition for your system
#endif
}
/* \\\ */
/* /// Locale_FormatDate()
**
*/
/* /// FormatDateStream() */
struct FormatDateStream
{
char *Target;
ULONG TargetSize;
};
/*************************************************************************/
HOOKPROTO( FormatDate_func, ULONG, struct Locale *locale UNUSED, ULONG c )
{
struct FormatDateStream *fs = (struct FormatDateStream*) hook->h_Data;
if( fs->TargetSize ) {
*(fs->Target)++ = (char) c;
fs->TargetSize--;
}
return(0);
}
MakeHook( FormatDate_hook, FormatDate_func );
/* \\\ */
/*************************************************************************/
ULONG Locale_FormatDate( char *format, char *target, struct DateStamp *ds, ULONG targetsize )
{
struct FormatDateStream fs;
struct Hook hook;
CopyMem( &FormatDate_hook, &hook, sizeof( struct Hook )); /* copy hook, to support reentrant */
fs.Target = target;
fs.TargetSize = targetsize;
hook.h_Data = &fs;
if( LocaleBase && locale_locale ) {
FormatDate( locale_locale, (STRPTR) format, ds, &hook );
} else {
*target = 0x00;
}
return( targetsize - fs.TargetSize );
}
/* \\\ */