4 /****************************************************************
5 This file was created automatically by `%fv'
9 ****************************************************************/
13 #include <exec/memory.h>
14 #include <libraries/iffparse.h>
17 #if defined(__SASC) || defined(_DCC)
18 #include <proto/exec.h>
19 #include <proto/dos.h>
20 #include <proto/utility.h>
21 #include <proto/iffparse.h>
22 #include <proto/locale.h>
23 #elif defined(__GNUC__)
24 #include <inline/locale.h>
25 #include <inline/iffparse.h>
26 #include <inline/dos.h>
27 #include <inline/exec.h>
28 #include <inline/utility.h>
30 #include <clib/iffparse_protos.h>
31 #include <clib/locale_protos.h>
32 #include <clib/dos_protos.h>
33 #include <clib/exec_protos.h>
34 #include <clib/utility_protos.h>
41 static LONG %b_Version = %v;
42 static const STRPTR %b_BuiltInLanguage = (STRPTR) %l;
49 const struct FC_Type _%i = { %d, %s };
51 static struct Catalog *%b_Catalog = NULL;
52 static struct FC_Type *%b_OwnCatalog = NULL;
53 static LONG %b_OwnStrings;
54 static LONG %b_OwnBytes;
56 void Open%bCatalog(struct Locale *loc, STRPTR language)
58 extern struct Library *LocaleBase;
59 extern struct Library *IFFParseBase;
60 extern void Close%bCatalog(void);
62 Close%bCatalog(); /* Not needed if the programmer pairs Open-()
63 and CloseCatalog() right, but does no harm. */
69 tagarg = (LONG) language;
71 if (LocaleBase != NULL && %b_Catalog == NULL)
72 { %b_Catalog = OpenCatalog(loc, (STRPTR) "%b.catalog",
73 OC_BuiltInLanguage, %b_BuiltInLanguage,
75 OC_Version, %b_Version,
78 if (LocaleBase == NULL && IFFParseBase != NULL && language != NULL &&
79 Stricmp(language, %b_BuiltInLanguage) != 0)
80 { struct IFFHandle *iffhandle;
81 char path[128]; /* Enough to hold 4 path items (dos.library 3.0) */
83 if ((iffhandle = AllocIFF()) != NULL)
84 { /* Trying to open the catalog */
85 strcpy(path, "Catalogs");
86 AddPart((STRPTR) path, language, sizeof(path));
87 AddPart((STRPTR) path, (STRPTR) "%b.catalog", sizeof(path));
88 if ((iffhandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE))
90 { strcpy(path, "Locale:Catalogs");
91 AddPart((STRPTR) path, language, sizeof(path));
92 AddPart((STRPTR) path, (STRPTR) "%b.catalog", sizeof(path));
93 iffhandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE);
96 if (iffhandle->iff_Stream)
97 { InitIFFasDOS(iffhandle);
98 if (!OpenIFF(iffhandle, IFFF_READ))
99 { if (!PropChunk(iffhandle, MAKE_ID('C','T','L','G'),
100 MAKE_ID('S','T','R','S')))
101 { struct StoredProperty *sp;
105 { if ((error = ParseIFF(iffhandle, IFFPARSE_STEP))
113 if (sp = FindProp(iffhandle, MAKE_ID('C','T','L','G'),
114 MAKE_ID('S','T','R','S')))
116 LONG BytesToScan, StrLength;
118 /* First scan: Check the number of strings */
119 /* Note that this assumes that the strings are padded */
120 /* to a longword boundary! */
123 BytesToScan = sp->sp_Size;
125 while (BytesToScan > 0)
128 StrLength = *ptr+1; /* NUL-Byte! */
129 %b_OwnBytes += StrLength;
130 ptr += 1+(StrLength+3)/4; /* Skip Length and String*/
131 BytesToScan -= 8+((StrLength+3)/4)*4;
134 /* Marginal check: BytesToScan has to be 0! */
135 if (BytesToScan == 0)
139 if (%b_OwnCatalog = (struct FC_Type *)
140 AllocMem(%b_OwnStrings*sizeof(struct FC_Type)+%b_OwnBytes,
142 { /* Second scan: Copy the strings and their ID's */
143 cptr = (char *) &%b_OwnCatalog[%b_OwnStrings];
144 BytesToScan = sp->sp_Size;
147 while (BytesToScan > 0)
148 { %b_OwnCatalog[i].ID = *(ptr++);
149 %b_OwnCatalog[i].Str = (STRPTR) cptr;
150 StrLength = *ptr+1; /* NUL-Byte! */
152 strncpy(cptr, (char *) ptr, StrLength);
153 /* Not more, not less bytes! */
155 ptr += (StrLength+3)/4;
156 BytesToScan -= 8+((StrLength+3)/4)*4;
167 Close(iffhandle->iff_Stream);
176 void Close%bCatalog(void)
177 { if (LocaleBase != NULL)
178 { CloseCatalog(%b_Catalog);
181 if (%b_OwnCatalog != NULL)
182 { FreeMem(%b_OwnCatalog,
183 %b_OwnStrings*sizeof(struct FC_Type)+%b_OwnBytes);
184 %b_OwnCatalog = NULL;
189 STRPTR Get%bString(APTR fcstr)
190 { STRPTR defaultstr = NULL;
193 strnum = ((struct FC_Type *) fcstr)->ID;
194 defaultstr = ((struct FC_Type *) fcstr)->Str;
196 if (%b_Catalog == NULL)
197 { if (%b_OwnCatalog != NULL)
198 { for (i = 0; i < %b_OwnStrings; i++)
199 { if (%b_OwnCatalog[i].ID == strnum)
200 { return(%b_OwnCatalog[i].Str);
206 return(GetCatalogStr(%b_Catalog, strnum, defaultstr));