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 ***************************************************************************/
25 #include <proto/exec.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
)
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
))
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
;
70 // OK we managed to open the catalog, now go to initialize our own CatComArray
71 privateCatCompArray
= (struct CatCompArrayType
*) AllocVecShared( 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
;
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
;
110 for (cnt
= (sizeof(CatCompArray
)/sizeof(struct CatCompArrayType
))-1, cca
= (struct CatCompArrayType
*)privateCatCompArray
+cnt
;
112 cnt
--, cca
--) if (cca
->cca_ID
==id
) return cca
->cca_Str
;
117 /***********************************************************************/
119 void localizeStrings(STRPTR
*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
)
141 string
= getString(id
);
143 for (; *string
&& *string
!='_'; string
++);
144 if (*string
++) res
= ToLower(*string
);
149 /***********************************************************************/