Bringing v7.10 in main trunk.
[AROS.git] / workbench / libs / openurl / prefs / locale.c
bloba9f801e40b720234aa6276f39d39bb121d4c844f
1 /***************************************************************************
3 openurl.library - universal URL display and browser launcher library
4 Copyright (C) 1998-2005 by Troels Walsted Hansen, et al.
5 Copyright (C) 2005-2009 by openurl.library Open Source Team
7 This library is free software; it has been placed in the public domain
8 and you can freely redistribute it and/or modify it. Please note, however,
9 that some components may be under the LGPL or GPL license.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 openurl.library project: http://sourceforge.net/projects/openurllib/
17 $Id$
19 ***************************************************************************/
21 #include "openurl.h"
22 #define CATCOMP_ARRAY
23 #include "locale.h"
25 #include <proto/exec.h>
27 #include "macros.h"
29 /***********************************************************************/
31 #define CATNAME "OpenURL.catalog"
33 struct CatCompArrayType * privateCatCompArray = NULL;
35 /***********************************************************************/
37 static struct Catalog *openCatalog(CONST_STRPTR name, ULONG minVer, ULONG minRev)
39 struct Catalog *cat;
41 if((cat = OpenCatalog(NULL, (STRPTR)name, OC_BuiltInLanguage, (IPTR)"english", TAG_DONE)) != NULL)
43 ULONG ver = cat->cat_Version;
45 if ((ver<minVer) ? TRUE : ((ver==minVer) ? (cat->cat_Revision<minRev) : FALSE))
47 CloseCatalog(cat);
48 cat = NULL;
52 return cat;
55 /***********************************************************************/
57 void initStrings(void)
59 if((LocaleBase = (APTR)OpenLibrary("locale.library",36)) &&
60 GETINTERFACE(ILocale, LocaleBase))
62 // to be on the safe side, we initialize our CatCompArray to point on the CatComp's one
63 privateCatCompArray = (struct CatCompArrayType *)CatCompArray;
65 if((g_cat = openCatalog(CATNAME,7,0)) != NULL)
67 struct CatCompArrayType *cca;
68 int cnt;
70 // OK we managed to open the catalog, now go to initialize our own CatComArray
71 privateCatCompArray = (struct CatCompArrayType *) AllocVec( sizeof(CatCompArray), MEMF_ANY );
72 if( privateCatCompArray )
74 // ok we have allocated our memory, go for initialization : we copy the whole memory into it
75 memcpy(privateCatCompArray,CatCompArray,sizeof(CatCompArray));
77 for (cnt = (sizeof(CatCompArray)/sizeof(struct CatCompArrayType))-1, cca = (struct CatCompArrayType *)privateCatCompArray+cnt;
78 cnt>=0;
79 cnt--, cca--)
81 CONST_STRPTR s;
83 if((s = GetCatalogStr(g_cat,cca->cca_ID,cca->cca_Str)) != NULL)
84 cca->cca_Str = (STRPTR)s;
92 /***********************************************************************/
94 void uninitStrings(void)
96 if( privateCatCompArray != CatCompArray )
98 FreeVec( privateCatCompArray );
100 privateCatCompArray = NULL;
103 /***********************************************************************/
105 STRPTR getString(ULONG id)
107 struct CatCompArrayType *cca;
108 int cnt;
110 for (cnt = (sizeof(CatCompArray)/sizeof(struct CatCompArrayType))-1, cca = (struct CatCompArrayType *)privateCatCompArray+cnt;
111 cnt>=0;
112 cnt--, cca--) if (cca->cca_ID==id) return cca->cca_Str;
114 return (STRPTR)"";
117 /***********************************************************************/
119 void localizeStrings(STRPTR *s)
121 for (; *s; s++)
122 *s = getString((IPTR)*s);
125 /***********************************************************************/
127 void localizeNewMenu(struct NewMenu *nm)
129 for ( ; nm->nm_Type!=NM_END; nm++)
130 if (nm->nm_Label!=NM_BARLABEL)
131 nm->nm_Label = (STRPTR)getString((IPTR)nm->nm_Label);
134 /***********************************************************************/
136 ULONG getKeyChar(STRPTR string, ULONG id)
138 ULONG res = 0;
140 if(string == NULL)
141 string = getString(id);
143 for (; *string && *string!='_'; string++);
144 if (*string++) res = ToLower(*string);
146 return res;
149 /***********************************************************************/