grub2: bring back build of aros-side grub2 tools
[AROS.git] / tools / flexcat / src / sd / C_c.sd
blobff70072fc0b6a78a5c56f23120f2636fbb85ac7f
1 ##rem $Id: C_c.sd 253 2014-02-18 11:15:58Z damato $
2 ##stringtype C
3 ##shortstrings
5 /****************************************************************
7    This file was created automatically by `%fv'
8    from "%f0".
10    Do NOT edit by hand!
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
27     applications.
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>
44 #include <stdlib.h>
45 #include <string.h>
49 #include "%b_cat.h"
53     Variables
56 struct FC_String %b_Strings[%n] = {
57     { (STRPTR) %s, %d }%(,)
60 STATIC struct Catalog *%bCatalog = NULL;
61 #ifdef LOCALIZE_V20
62 STATIC STRPTR %bStrings = NULL;
63 STATIC ULONG %bStringsSize;
64 #endif
67 #if defined(_DCC)
68 STATIC __autoexit VOID _STDClose%bCatalog(VOID)
69 #elif defined(__SASC)
70 VOID _STDClose%bCatalog(VOID)
71 #elif defined(__GNUC__)
72 STATIC VOID __attribute__ ((destructor)) _STDClose%bCatalog(VOID)
73 #else
74 VOID Close%bCatalog(VOID)
75 #endif
78     if (%bCatalog) {
79         CloseCatalog(%bCatalog);
80     }
81 #ifdef LOCALIZE_V20
82     if (%bStrings) {
83         FreeMem(%bStrings, %bStringsSize);
84     }
85 #endif
89 #if defined(_DCC)
90 STATIC __autoinit VOID _STIOpen%bCatalog(VOID)
91 #elif defined(__SASC)
92 VOID _STIOpen%bCatalog(VOID)
93 #elif defined(__GNUC__)
94 VOID __attribute__ ((constructor)) _STIOpen%bCatalog(VOID)
95 #else
96 VOID Open%bCatalog(VOID)
97 #endif
100     if (LocaleBase) {
101         if ((%bCatalog = OpenCatalog(NULL, (STRPTR) "%b.catalog",
102                                      OC_BuiltInLanguage, %l,
103                                      OC_Version, %v,
104                                      TAG_DONE))) {
105             struct FC_String *fc;
106             int i;
108             for (i = 0, fc = %b_Strings;  i < %n;  i++, fc++) {
109                  fc->msg = GetCatalogStr(%bCatalog, fc->id, (STRPTR) fc->msg);
110             }
111         }
112     }
118 #ifdef LOCALIZE_V20
119 VOID Init%bCatalog(STRPTR language)
122     struct IFFHandle *iffHandle;
124     /*
125     **  Use iffparse.library only, if we need to.
126     */
127     if (LocaleBase  ||  !IFFParseBase  ||  !language  ||
128         Stricmp(language, %l) == 0) {
129         return;
130     }
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);
142         }
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;
150                     int error;
152                     for (;;) {
153                         if ((error = ParseIFF(iffHandle, IFFPARSE_STEP))
154                                    ==  IFFERR_EOC) {
155                             continue;
156                         }
157                         if (error) {
158                             break;
159                         }
161                         if ((sp = FindProp(iffHandle, MAKE_ID('C','T','L','G'),
162                                            MAKE_ID('S','T','R','S')))) {
163                             /*
164                             **  Check catalog and calculate the needed
165                             **  number of bytes.
166                             **  A catalog string consists of
167                             **      ID (LONG)
168                             **      Size (LONG)
169                             **      Bytes (long word padded)
170                             */
171                             LONG bytesRemaining;
172                             LONG *ptr;
174                             %bStringsSize = 0;
175                             bytesRemaining = sp->sp_Size;
176                             ptr = (LONG *) sp->sp_Data;
178                             while (bytesRemaining > 0) {
179                                 LONG skipSize, stringSize;
181                                 ptr++;                  /* Skip ID */
182                                 stringSize = *ptr++;
183                                 skipSize = ((stringSize+3) >> 2);
185                                 %bStringsSize += stringSize+1;  /* NUL */
186                                 bytesRemaining -= 8 + (skipSize << 2);
187                                 ptr += skipSize;
188                             }
190                             if (!bytesRemaining  &&
191                                 (%bStrings = AllocMem(%bStringsSize, MEMF_ANY))) {
192                                 STRPTR sptr;
194                                 bytesRemaining = sp->sp_Size;
195                                 ptr = (LONG *) sp->sp_Data;
196                                 sptr = %bStrings;
198                                 while (bytesRemaining) {
199                                     LONG skipSize, stringSize, id;
200                                     struct FC_String *fc;
201                                     int i;
203                                     id = *ptr++;
204                                     stringSize = *ptr++;
205                                     skipSize = ((stringSize+3) >> 2);
207                                     CopyMem(ptr, sptr, stringSize);
208                                     bytesRemaining -= 8 + (skipSize << 2);
209                                     ptr += skipSize;
211                                     for (i = 0, fc = %b_Strings;  i < %n;  i++, fc++) {
212                                         if (fc->id == id) {
213                                             fc->msg = sptr;
214                                         }
215                                     }
217                                     sptr += stringSize;
218                                     *sptr++ = '\\0';
219                                 }
220                             }
221                             break;
222                         }
223                     }
224                 }
225                 CloseIFF(iffHandle);
226             }
227             Close(iffHandle->iff_Stream);
228         }
229         FreeIFF(iffHandle);
230     }
232 #endif