1 ##rem $Id: C_c.sd 253 2014-02-18 11:15:58Z damato $
5 /****************************************************************
7 This file was created automatically by `%fv'
12 ****************************************************************/
14 /****************************************************************
15 This file uses the auto initialization features of
16 Dice, gcc and SAS/C, respectively.
18 Dice does this by using the __autoinit and __autoexit
19 keywords, whereas SAS/C uses names beginning with _STI
20 or _STD, respectively. gcc uses the asm() instruction
21 to emulate C++ constructors and destructors.
23 Using this file you don't have *all* the benefits of
24 locale.library (no Locale or Language arguments are
25 supported when opening the catalog). However, these are
26 *very* rarely used, so this should be sufficient for most
28 ****************************************************************/
31 Include files and compiler specific stuff
34 #include <exec/memory.h>
35 #include <libraries/locale.h>
36 #include <libraries/iffparse.h>
38 #include <proto/exec.h>
39 #include <proto/dos.h>
40 #include <proto/locale.h>
41 #include <proto/utility.h>
42 #include <proto/iffparse.h>
56 struct FC_String %b_Strings[%n] = {
57 { (STRPTR) %s, %d }%(,)
60 STATIC struct Catalog *%bCatalog = NULL;
62 STATIC STRPTR %bStrings = NULL;
63 STATIC ULONG %bStringsSize;
68 STATIC __autoexit VOID _STDClose%bCatalog(VOID)
70 VOID _STDClose%bCatalog(VOID)
71 #elif defined(__GNUC__)
72 STATIC VOID __attribute__ ((destructor)) _STDClose%bCatalog(VOID)
74 VOID Close%bCatalog(VOID)
79 CloseCatalog(%bCatalog);
83 FreeMem(%bStrings, %bStringsSize);
90 STATIC __autoinit VOID _STIOpen%bCatalog(VOID)
92 VOID _STIOpen%bCatalog(VOID)
93 #elif defined(__GNUC__)
94 VOID __attribute__ ((constructor)) _STIOpen%bCatalog(VOID)
96 VOID Open%bCatalog(VOID)
101 if ((%bCatalog = OpenCatalog(NULL, (STRPTR) "%b.catalog",
102 OC_BuiltInLanguage, %l,
105 struct FC_String *fc;
108 for (i = 0, fc = %b_Strings; i < %n; i++, fc++) {
109 fc->msg = GetCatalogStr(%bCatalog, fc->id, (STRPTR) fc->msg);
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 V40) */
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);