1 ##rem $Id: C++_CatalogF.cc 253 2014-02-18 11:15:58Z damato $
3 // Multipurpose CatalogF class implementation
4 // Written by Antonio J. Gomez Glez. on 20.6.94
5 // You MUST include CatalogF.h in your code.
6 // If you use FlexCat, you only have to include the file generated
12 #include <clib/locale_protos.h>
13 #include <inline/locale.h>
14 #include <clib/exec_protos.h>
17 unsigned CatalogF::counter
= 0; // counter of open catalogs
18 struct LocaleBase
* LocaleBase
= 0; // We will try to open locale.library
21 // Needs:- filename of the catalog to be used. NEEDED!!
22 // - built in language of the catalog descriptor. defaults to "english"
23 // - language requested. Otherwise, it will use the user defined one.
24 // - requested version number for the catalog. defaults to any.
25 // - Locale (as returned by OpenLocale). defaults to user defined one.
27 // Try to open locale.library for the first CatalogF object declared. And
28 // keeps with this with following objects.
29 // Counts the number of defined objects.
30 // And opens the catalog if avaible.
32 CatalogF::CatalogF( const STRPTR catalogFileName
,
33 const STRPTR builtInLanguage
,
34 const LONG versionNumber
,
35 const STRPTR languageName
,
38 if ( counter
== 0 ) // means that this is the first object
40 LocaleBase
= (struct LocaleBase
* )OpenLibrary("locale.library", 38L );
44 if ( LocaleBase
!= 0 )
45 { // locale.library is avaible
46 LONG tag
= TAG_IGNORE
; // in case language not provided use default
48 if (languageName
!= 0) // if language specified, use that
52 thecatalog
= OpenCatalog( loc
,
54 OC_BuiltInLanguage
, builtInLanguage
,
56 OC_Version
, versionNumber
,
58 } // else use built-in strings
62 // If locale.library was opened, try to close the catalog, even if no catalog
63 // was opened (this is supported by CloseCatalog()).
64 // When the counter of avaible objects reaches 0, it try to close locale.library
69 if ( LocaleBase
!= 0 )
71 CloseCatalog( thecatalog
);
74 struct LocaleBase
* lb
= LocaleBase
;
75 CloseLibrary( (struct Library
* )lb
);
81 // Retrive the string.
82 // If there is locale.library and a opened catalog returns the catalog
83 // string, else returns the built-in string.
85 // Needs a struct of type catMessage that contains the value ID and the
86 // string itself. The name of this constant struct is the ID name. This way
87 // we avoid the use of #define's or const, or any type of search ...
88 // it returns a const pointer (STRPTR) to the string.
89 // This method is constant so CatalogFs object can be declared to be const
92 CatalogF::GetStr(const CatMessage
& mess
) const
94 if ( LocaleBase
== 0 )
96 return( mess
.textstring
);
100 return( GetCatalogStr(thecatalog
, mess
.ID
, mess
.textstring
) );