4 /****************************************************************
5 This file was created automatically by `%fv'
9 ****************************************************************/
11 /****************************************************************
12 This file uses the auto initialization possibilities of
13 Dice, gcc and SAS/C, respectively.
15 Dice does this by using the keywords __autoinit and
16 __autoexit, SAS uses names beginning with _STI or
17 _STD, respectively. gcc uses the asm() instruction,
18 to emulate C++ constructors and destructors.
20 Using this file you don't have *all* possibilities of
21 the locale.library. (No Locale or Language arguments are
22 supported when opening the catalog. However, these are
23 *very* rarely used, so this should be sufficient for most
25 ****************************************************************/
29 Include files and compiler specific stuff
31 #include <exec/memory.h>
32 #include <libraries/locale.h>
33 #include <libraries/iffparse.h>
35 #include <proto/exec.h>
36 #include <proto/dos.h>
37 #include <proto/locale.h>
38 #include <proto/utility.h>
39 #include <proto/iffparse.h>
52 struct FC_String %b_Strings[%n] = {
53 { (STRPTR) %s, %d }%(,)
56 STATIC struct Catalog *%bCatalog = NULL;
58 STATIC STRPTR %bStrings = NULL;
59 STATIC ULONG %bStringsSize;
64 STATIC __autoexit VOID _STDClose%bCatalog(VOID)
66 VOID _STDClose%bCatalog(VOID)
67 #elif defined(__GNUC__)
68 STATIC VOID _STDClose%bCatalog(VOID)
70 VOID Close%bCatalog(VOID)
75 CloseCatalog(%bCatalog);
79 FreeMem(%bStrings, %bStringsSize);
86 STATIC __autoinit VOID _STIOpen%bCatalog(VOID)
88 VOID _STIOpen%bCatalog(VOID)
89 #elif defined(__GNUC__)
90 VOID _STIOpen%bCatalog(VOID)
92 VOID Open%bCatalog(VOID)
97 if ((%bCatalog = OpenCatalog(NULL, (STRPTR) "%b.catalog",
98 OC_BuiltInLanguage, %l,
101 struct FC_String *fc;
104 for (i = 0, fc = %b_Strings; i < %n; i++, fc++) {
105 fc->msg = GetCatalogStr(%bCatalog, fc->id, (STRPTR) fc->msg);
111 #if defined(__GNUC__)
112 __asm (" .text; .stabs \\\"___CTOR_LIST__\\\",22,0,0,__STIOpen%bCatalog");
113 __asm (" .text; .stabs \\\"___DTOR_LIST__\\\",22,0,0,__STDClose%bCatalog");
119 VOID Init%bCatalog(STRPTR language)
122 struct IFFHandle *iffHandle;
125 ** Use iffparse.library only, if we need to.
127 if (LocaleBase || !IFFParseBase || !language ||
128 Stricmp(language, %l) == 0) {
132 if ((iffHandle = AllocIFF())) {
133 char path[128]; /* Enough to hold 4 path items (dos.library 3.1) */
134 strcpy(path, "PROGDIR:Catalogs");
135 AddPart((STRPTR) path, language, sizeof(path));
136 AddPart((STRPTR) path, "%b.catalog", sizeof(path));
137 if (!(iffHandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE))) {
138 strcpy(path, "LOCALE:Catalogs");
139 AddPart((STRPTR) path, language, sizeof(path));
140 AddPart((STRPTR) path, language, sizeof(path));
141 iffHandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE);
144 if (iffHandle->iff_Stream) {
145 InitIFFasDOS(iffHandle);
146 if (!OpenIFF(iffHandle, IFFF_READ)) {
147 if (!PropChunk(iffHandle, MAKE_ID('C','T','L','G'),
148 MAKE_ID('S','T','R','S'))) {
149 struct StoredProperty *sp;
153 if ((error = ParseIFF(iffHandle, IFFPARSE_STEP))
161 if ((sp = FindProp(iffHandle, MAKE_ID('C','T','L','G'),
162 MAKE_ID('S','T','R','S')))) {
164 ** Check catalog and calculate the needed
166 ** A catalog string consists of
169 ** Bytes (long word padded)
175 bytesRemaining = sp->sp_Size;
176 ptr = (LONG *) sp->sp_Data;
178 while (bytesRemaining > 0) {
179 LONG skipSize, stringSize;
183 skipSize = ((stringSize+3) >> 2);
185 %bStringsSize += stringSize+1; /* NUL */
186 bytesRemaining -= 8 + (skipSize << 2);
190 if (!bytesRemaining &&
191 (%bStrings = AllocMem(%bStringsSize, MEMF_ANY))) {
194 bytesRemaining = sp->sp_Size;
195 ptr = (LONG *) sp->sp_Data;
198 while (bytesRemaining) {
199 LONG skipSize, stringSize, id;
200 struct FC_String *fc;
205 skipSize = ((stringSize+3) >> 2);
207 CopyMem(ptr, sptr, stringSize);
208 bytesRemaining -= 8 + (skipSize << 2);
211 for (i = 0, fc = %b_Strings; i < %n; i++, fc++) {
227 Close(iffHandle->iff_Stream);