1 ##rem $Id: C_c_V20.sd 253 2014-02-18 11:15:58Z damato $
5 /****************************************************************
7 This file was created automatically by `%fv'
12 ****************************************************************/
16 #include <exec/memory.h>
17 #include <libraries/iffparse.h>
20 #if defined(__SASC) || defined(_DCC)
21 #include <proto/exec.h>
22 #include <proto/dos.h>
23 #include <proto/utility.h>
24 #include <proto/iffparse.h>
25 #include <proto/locale.h>
26 #elif defined(__GNUC__)
27 #include <inline/locale.h>
28 #include <inline/iffparse.h>
29 #include <inline/dos.h>
30 #include <inline/exec.h>
31 #include <inline/utility.h>
33 #include <clib/iffparse_protos.h>
34 #include <clib/locale_protos.h>
35 #include <clib/dos_protos.h>
36 #include <clib/exec_protos.h>
37 #include <clib/utility_protos.h>
44 static LONG %b_Version = %v;
45 static const STRPTR %b_BuiltInLanguage = (STRPTR) %l;
52 const struct FC_Type _%i = { %d, %s };
54 static struct Catalog *%b_Catalog = NULL;
55 static struct FC_Type *%b_OwnCatalog = NULL;
56 static LONG %b_OwnStrings;
57 static LONG %b_OwnBytes;
59 void Open%bCatalog(struct Locale *loc, STRPTR language)
61 extern struct Library *LocaleBase;
62 extern struct Library *IFFParseBase;
63 extern void Close%bCatalog(void);
65 Close%bCatalog(); /* Not needed if the programmer pairs Open-()
66 and CloseCatalog() right, but does no harm. */
72 tagarg = (LONG) language;
74 if (LocaleBase != NULL && %b_Catalog == NULL)
75 { %b_Catalog = OpenCatalog(loc, (STRPTR) "%b.catalog",
76 OC_BuiltInLanguage, %b_BuiltInLanguage,
78 OC_Version, %b_Version,
81 if (LocaleBase == NULL && IFFParseBase != NULL && language != NULL &&
82 Stricmp(language, %b_BuiltInLanguage) != 0)
83 { struct IFFHandle *iffhandle;
84 char path[128]; /* Enough to hold 4 path items (dos.library V40) */
86 if ((iffhandle = AllocIFF()) != NULL)
87 { /* Trying to open the catalog */
88 strcpy(path, "Catalogs");
89 AddPart((STRPTR) path, language, sizeof(path));
90 AddPart((STRPTR) path, (STRPTR) "%b.catalog", sizeof(path));
91 if ((iffhandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE))
93 { strcpy(path, "Locale:Catalogs");
94 AddPart((STRPTR) path, language, sizeof(path));
95 AddPart((STRPTR) path, (STRPTR) "%b.catalog", sizeof(path));
96 iffhandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE);
99 if (iffhandle->iff_Stream)
100 { InitIFFasDOS(iffhandle);
101 if (!OpenIFF(iffhandle, IFFF_READ))
102 { if (!PropChunk(iffhandle, MAKE_ID('C','T','L','G'),
103 MAKE_ID('S','T','R','S')))
104 { struct StoredProperty *sp;
108 { if ((error = ParseIFF(iffhandle, IFFPARSE_STEP))
116 if (sp = FindProp(iffhandle, MAKE_ID('C','T','L','G'),
117 MAKE_ID('S','T','R','S')))
119 LONG BytesToScan, StrLength;
121 /* First scan: Check the number of strings */
122 /* Note that this assumes that the strings are padded */
123 /* to a longword boundary! */
126 BytesToScan = sp->sp_Size;
128 while (BytesToScan > 0)
131 StrLength = *ptr+1; /* NUL-Byte! */
132 %b_OwnBytes += StrLength;
133 ptr += 1+(StrLength+3)/4; /* Skip Length and String*/
134 BytesToScan -= 8+((StrLength+3)/4)*4;
137 /* Marginal check: BytesToScan has to be 0! */
138 if (BytesToScan == 0)
142 if (%b_OwnCatalog = (struct FC_Type *)
143 AllocMem(%b_OwnStrings*sizeof(struct FC_Type)+%b_OwnBytes,
145 { /* Second scan: Copy the strings and their ID's */
146 cptr = (char *) &%b_OwnCatalog[%b_OwnStrings];
147 BytesToScan = sp->sp_Size;
150 while (BytesToScan > 0)
151 { %b_OwnCatalog[i].ID = *(ptr++);
152 %b_OwnCatalog[i].Str = (STRPTR) cptr;
153 StrLength = *ptr+1; /* NUL-Byte! */
155 strncpy(cptr, (char *) ptr, StrLength);
156 /* Not more, not less bytes! */
158 ptr += (StrLength+3)/4;
159 BytesToScan -= 8+((StrLength+3)/4)*4;
170 Close(iffhandle->iff_Stream);
179 void Close%bCatalog(void)
180 { if (LocaleBase != NULL)
181 { CloseCatalog(%b_Catalog);
184 if (%b_OwnCatalog != NULL)
185 { FreeMem(%b_OwnCatalog,
186 %b_OwnStrings*sizeof(struct FC_Type)+%b_OwnBytes);
187 %b_OwnCatalog = NULL;
192 STRPTR Get%bString(APTR fcstr)
193 { STRPTR defaultstr = NULL;
196 strnum = ((struct FC_Type *) fcstr)->ID;
197 defaultstr = ((struct FC_Type *) fcstr)->Str;
199 if (%b_Catalog == NULL)
200 { if (%b_OwnCatalog != NULL)
201 { for (i = 0; i < %b_OwnStrings; i++)
202 { if (%b_OwnCatalog[i].ID == strnum)
203 { return(%b_OwnCatalog[i].Str);
209 return(GetCatalogStr(%b_Catalog, strnum, defaultstr));