Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / openurl / prefs / loc.c
blob125703b58b783173103df7d4e28a0b69da642fc6
1 /*
2 ** OpenURL - MUI preferences for openurl.library
3 **
4 ** Written by Troels Walsted Hansen <troels@thule.no>
5 ** Placed in the public domain.
6 **
7 ** Developed by:
8 ** - Alfonso Ranieri <alforan@tin.it>
9 ** - Stefan Kost <ensonic@sonicpulse.de>
11 ** Ported to OS4 by Alexandre Balaban <alexandre@balaban.name>
13 ** Localization
17 #include "OpenURL.h"
18 #define CATCOMP_ARRAY
19 #include "loc.h"
21 #include <proto/exec.h>
23 /***********************************************************************/
25 #define CATNAME "OpenURL.catalog"
27 struct CatCompArrayType * privateCatCompArray = NULL;
29 /***********************************************************************/
31 static struct Catalog *
32 openCatalog(STRPTR name,ULONG minVer,ULONG minRev)
34 struct Catalog *cat;
36 if (cat = OpenCatalogA(NULL,name,NULL))
38 ULONG ver = cat->cat_Version;
40 if ((ver<minVer) ? TRUE : ((ver==minVer) ? (cat->cat_Revision<minRev) : FALSE))
42 CloseCatalog(cat);
43 cat = NULL;
47 return cat;
50 /***********************************************************************/
52 void
53 initStrings(void)
55 if (LocaleBase = (struct LocaleBase *)OpenLibrary("locale.library",36))
57 #if defined(__amigaos4__)
58 if ( NULL == (ILocale = (struct LocaleIFace*)GetInterface((struct Library*)LocaleBase, "main", 1L, NULL)) ) return;
59 #endif
61 // to be on the safe side, we initialize our CatCompArray to point on the CatComp's one
62 privateCatCompArray = (struct CatCompArrayType *)CatCompArray;
64 if (g_cat = openCatalog(CATNAME,7,0))
66 struct CatCompArrayType *cca;
67 int cnt;
69 // OK we managed to open the catalog, now go to initialize our own CatComArray
70 privateCatCompArray = (struct CatCompArrayType *) AllocVec( sizeof(CatCompArray), MEMF_ANY );
71 if( privateCatCompArray )
73 // ok we have allocated our memory, go for initialization : we copy the whole memory into it
74 CopyMem(CatCompArray,privateCatCompArray,sizeof(CatCompArray));
76 for (cnt = (sizeof(CatCompArray)/sizeof(struct CatCompArrayType))-1, cca = (struct CatCompArrayType *)privateCatCompArray+cnt;
77 cnt>=0;
78 cnt--, cca--)
80 CONST_STRPTR s;
82 if (s = GetCatalogStr(g_cat,cca->cca_ID,cca->cca_Str)) cca->cca_Str = (STRPTR)s;
90 /***********************************************************************/
92 void
93 uninitStrings(void)
95 if( privateCatCompArray != CatCompArray )
97 FreeVec( privateCatCompArray );
99 privateCatCompArray = NULL;
102 /***********************************************************************/
104 STRPTR
105 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 "";
117 /***********************************************************************/
119 void
120 localizeStrings(STRPTR *s)
122 for (; *s; s++) *s = getString((ULONG)*s);
125 /***********************************************************************/
127 void
128 localizeNewMenu(struct NewMenu *nm)
130 for ( ; nm->nm_Type!=NM_END; nm++)
131 if (nm->nm_Label!=NM_BARLABEL)
132 nm->nm_Label = (STRPTR)getString((ULONG)nm->nm_Label);
135 /***********************************************************************/
137 ULONG
138 getKeyChar(UBYTE *string,ULONG id)
140 ULONG res = 0;
142 if (!string) string = (UBYTE *)getString(id);
144 for (; *string && *string!='_'; string++);
145 if (*string++) res = ToLower(*string);
147 return res;
150 /***********************************************************************/