Fix issues with flexcat file paths
[AROS.git] / tools / flexcat / C_c.sd
blob0c1888b0df264261479c6938393a3c622508d6a0
1 ##rem $Id$
2 ##stringtype C
3 ##shortstrings
4 /****************************************************************
5    This file was created automatically by `%fv'
6    from "%f0".
8    Do NOT edit by hand!
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
24     applications.
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>
41 #include <stdlib.h>
42 #include <string.h>
46 #include "%b_cat.h"
50     Variables
52 struct FC_String %b_Strings[%n] = {
53     { (STRPTR) %s, %d }%(,)
56 STATIC struct Catalog *%bCatalog = NULL;
57 #ifdef LOCALIZE_V20
58 STATIC STRPTR %bStrings = NULL;
59 STATIC ULONG %bStringsSize;
60 #endif
63 #if defined(_DCC)
64 STATIC __autoexit VOID _STDClose%bCatalog(VOID)
65 #elif defined(__SASC)
66 VOID _STDClose%bCatalog(VOID)
67 #elif defined(__GNUC__)
68 STATIC VOID _STDClose%bCatalog(VOID)
69 #else
70 VOID Close%bCatalog(VOID)
71 #endif
74     if (%bCatalog) {
75         CloseCatalog(%bCatalog);
76     }
77 #ifdef LOCALIZE_V20
78     if (%bStrings) {
79         FreeMem(%bStrings, %bStringsSize);
80     }
81 #endif
85 #if defined(_DCC)
86 STATIC __autoinit VOID _STIOpen%bCatalog(VOID)
87 #elif defined(__SASC)
88 VOID _STIOpen%bCatalog(VOID)
89 #elif defined(__GNUC__)
90 VOID _STIOpen%bCatalog(VOID)
91 #else
92 VOID Open%bCatalog(VOID)
93 #endif
96     if (LocaleBase) {
97         if ((%bCatalog = OpenCatalog(NULL, (STRPTR) "%b.catalog",
98                                      OC_BuiltInLanguage, %l,
99                                      OC_Version, %v,
100                                      TAG_DONE))) {
101             struct FC_String *fc;
102             int i;
104             for (i = 0, fc = %b_Strings;  i < %n;  i++, fc++) {
105                  fc->msg = GetCatalogStr(%bCatalog, fc->id, (STRPTR) fc->msg);
106             }
107         }
108     }
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");
114 #endif
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 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);
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