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/
19 ***************************************************************************/
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
)
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
);
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
;
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
;
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
;
102 ILocale
->CloseCatalog(g_cat
);
107 /***********************************************************************/
109 STRPTR
getString(ULONG id
)
111 struct CatCompArrayType
*cca
;
114 for (cnt
= (sizeof(CatCompArray
)/sizeof(struct CatCompArrayType
))-1, cca
= (struct CatCompArrayType
*)CatCompArray
+cnt
;
123 /***********************************************************************/
125 void localizeStrings(STRPTR
*s
)
127 for (; *s
; s
++) *s
= getString((ULONG
)*s
);
130 /***********************************************************************/
132 void localizeNewMenu(struct NewMenu
*nm
)
135 for ( ; nm
->nm_Type
!=NM_END
; nm
++)
136 if (nm
->nm_Label
!=NM_BARLABEL
)
138 str
= getString((ULONG
)nm
->nm_Label
);
141 nm
->nm_CommKey
= str
;
148 /***********************************************************************/
150 ULONG
getKeyChar(STRPTR string
,ULONG id
)
154 if (!string
) string
= getString(id
);
156 for (; *string
&& *string
!='_'; string
++);
157 if (*string
++) res
= IUtility
->ToLower(*string
);
162 /***********************************************************************/