Fixed another typo in 8-bit pixel handling (BYTE should have been UBYTE).
[AROS.git] / external / openurl / raPrefs / locale.c
blob8f6c0b062dce13c4dac45341b6a30b832d785956
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-2013 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 "prefs.h"
22 #define CATCOMP_ARRAY
23 #include "locale.h"
24 struct Catalog *g_cat = NULL;
26 /***********************************************************************/
28 #define CATNAME "OpenURL.catalog"
30 struct CatCompArrayType * privateCatCompArray = NULL;
32 /***********************************************************************/
34 static struct Catalog *openCatalog(CONST_STRPTR name,ULONG minVer,ULONG minRev)
36 struct Catalog *cat;
38 if((cat = ILocale->OpenCatalogA(NULL,name,NULL)) != NULL)
40 ULONG ver = cat->cat_Version;
42 if ((ver<minVer) ? TRUE : ((ver==minVer) ? (cat->cat_Revision<minRev) : FALSE))
44 ILocale->CloseCatalog(cat);
45 cat = NULL;
49 return cat;
52 /***********************************************************************/
54 void initStrings(void)
56 if((LocaleBase = (struct LocaleBase *)IExec->OpenLibrary("locale.library",36)) != NULL)
58 if ( NULL == (ILocale = (struct LocaleIFace*)IExec->GetInterface((struct Library*)LocaleBase, "main", 1L, NULL)) ) return;
60 // to be on the safe side, we initialize our CatCompArray to point on the CatComp's one
61 privateCatCompArray = (struct CatCompArrayType *)CatCompArray;
63 if((g_cat = openCatalog(CATNAME,7,0)) != NULL)
65 struct CatCompArrayType *cca;
66 int cnt;
68 // OK we managed to open the catalog, now go to initialize our own CatComArray
69 privateCatCompArray = (struct CatCompArrayType *) IExec->AllocVecTags( sizeof(CatCompArray), AVT_Type, MEMF_SHARED, AVT_Lock, FALSE, TAG_DONE);
70 if( privateCatCompArray )
72 // ok we have allocated our memory, go for initialization : we copy the whole memory into it
73 IExec->CopyMem(CatCompArray,privateCatCompArray,sizeof(CatCompArray));
75 for (cnt = (sizeof(CatCompArray)/sizeof(struct CatCompArrayType))-1, cca = (struct CatCompArrayType *)privateCatCompArray+cnt;
76 cnt>=0;
77 cnt--, cca--)
79 CONST_STRPTR s;
81 if((s = ILocale->GetCatalogStr(g_cat,cca->cca_ID,cca->cca_Str)) != NULL)
82 cca->cca_Str = (STRPTR)s;
90 /***********************************************************************/
92 void uninitStrings(void)
94 if(privateCatCompArray != NULL && privateCatCompArray != (struct CatCompArrayType *)CatCompArray)
96 IExec->FreeVec(privateCatCompArray);
98 privateCatCompArray = NULL;
100 if(g_cat != NULL)
102 ILocale->CloseCatalog(g_cat);
104 g_cat = NULL;
107 /***********************************************************************/
109 STRPTR getString(ULONG id)
111 struct CatCompArrayType *cca;
112 int cnt;
114 for (cnt = (sizeof(CatCompArray)/sizeof(struct CatCompArrayType))-1, cca = (struct CatCompArrayType *)CatCompArray+cnt;
115 cnt>=0;
116 cnt--, cca--)
117 if (cca->cca_ID==id)
118 return cca->cca_Str;
120 return (STRPTR)"";
123 /***********************************************************************/
125 void localizeStrings(STRPTR *s)
127 for (; *s; s++) *s = getString((ULONG)*s);
130 /***********************************************************************/
132 void localizeNewMenu(struct NewMenu *nm)
134 STRPTR str = NULL;
135 for ( ; nm->nm_Type!=NM_END; nm++)
136 if (nm->nm_Label!=NM_BARLABEL)
138 str = getString((ULONG)nm->nm_Label);
139 if( str[1] == '\0' )
141 nm->nm_CommKey = str;
142 str += 2;
144 nm->nm_Label = str;
148 /***********************************************************************/
150 ULONG getKeyChar(STRPTR string,ULONG id)
152 ULONG res = 0;
154 if (!string) string = getString(id);
156 for (; *string && *string!='_'; string++);
157 if (*string++) res = IUtility->ToLower(*string);
159 return res;
162 /***********************************************************************/