fix __AROS_SETVECADDR invocations.
[AROS.git] / tools / flexcat / src / createct.c
blob3da3300bffd8c3d8a98c0fa01c5a7b5f6e5db050
1 /*
2 * $Id$
4 * Copyright (C) 1993-1999 by Jochen Wiedmann and Marcin Orlowski
5 * Copyright (C) 2002-2015 FlexCat Open Source Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "flexcat.h"
24 #include "readprefs.h"
25 #include "showfuncs.h"
26 #include "scancd.h"
27 #include "scanct.h"
28 #include "createcat.h"
29 #include "globals.h"
31 /// CreateCTFile
32 // This creates a new catalog translation file.
33 void CreateCTFile(char *NewCTFile)
35 FILE *fp;
36 struct CDLine *cd;
37 struct CatString *cs;
38 struct CatalogChunk *cc;
39 char*line;
40 char*ctlanguage = NULL;
42 if(CatVersionString == NULL && CatRcsId == NULL)
44 ScanLine = 1;
47 if(CatLanguage == NULL)
49 #ifdef AMIGA
50 char lang[80];
52 if(GetVar("language", lang, sizeof(lang), 0) != 0)
54 ctlanguage = lang;
56 #else
57 char *lang = NULL;
59 if((lang = getenv("language")) != NULL)
61 unsigned int i;
63 for(i = 0; i < strlen(lang); i++)
65 if(lang[i] == '\n')
67 lang[i] = '\0';
68 break;
71 ctlanguage = lang;
73 #endif
75 else
76 ctlanguage = CatLanguage;
78 if(ctlanguage == NULL)
79 ctlanguage = (char *)"nolanguage";
81 if(NewCTFile == NULL)
83 if(BaseName == NULL)
84 ShowError(MSG_ERR_NOCTFILENAME);
85 else
87 if(asprintf(&NewCTFile, "%s_%s.catalog", BaseName, ctlanguage) < 0)
88 MemError();
91 if((fp = fopen(NewCTFile, "w")) == NULL)
93 ShowError(MSG_ERR_NONEWCTFILE);
96 if(!NoBufferedIO)
97 setvbuf(fp, NULL, _IOFBF, buffer_size);
100 if(CatRcsId != NULL)
102 fprintf(fp, "## rcsid %s\n", CatRcsId);
103 if(CatName != NULL)
104 fprintf(fp, "## name %s\n", CatName);
106 else
108 if(CatVersionString != NULL)
109 fprintf(fp, "## version %s\n", CatVersionString);
110 else
112 char *dateStr;
113 time_t tim;
114 struct tm *t;
116 dateStr = calloc(15, 1);
117 time(&tim);
118 t = localtime(&tim);
119 strftime(dateStr, 12, "%d.%m.%Y", t);
121 if(CatVersion != -1)
123 if(CatRevision != -1)
125 if(BaseName != NULL)
126 fprintf(fp, "## version %cVER: %s.catalog %d.%d (%s)\n", '$', BaseName, CatVersion, CatRevision, dateStr);
127 else
128 fprintf(fp, "## version %cVER: <name>.catalog %d.%d (%s)\n", '$', CatVersion, CatRevision, dateStr);
130 else
132 if(BaseName != NULL)
133 fprintf(fp, "## version %cVER: %s.catalog %d.<rev> (%s)\n", '$', BaseName, CatVersion, dateStr);
134 else
135 fprintf(fp, "## version %cVER: <name>.catalog %d.<rev> (%s)\n", '$', CatVersion, dateStr);
138 else
140 if(CatRevision != -1)
142 if(BaseName != NULL)
143 fprintf(fp, "## version %cVER: %s.catalog <ver>.%d (%s)\n", '$', BaseName, CatRevision, dateStr);
144 else
145 fprintf(fp, "## version %cVER: <name>.catalog <ver>.%d (%s)\n", '$', CatRevision, dateStr);
147 else
149 if(BaseName != NULL)
150 fprintf(fp, "## version %cVER: %s.catalog <ver>.<rev> (%s)\n", '$', BaseName, dateStr);
151 else
152 fprintf(fp, "## version %cVER: <name>.catalog <ver>.<rev> (%s)\n", '$', dateStr);
156 free(dateStr);
161 fprintf(fp, "## language %s\n" \
162 "## codeset %d\n" \
163 ";\n", ctlanguage != NULL ? ctlanguage : "X", CodeSet);
164 for(cc = FirstChunk; cc != NULL; cc = cc->Next)
166 if(cc->ChunkStr != CatLanguage)
168 fprintf(fp, "## chunk ");
169 fwrite((char *)&cc->ID, sizeof(cc->ID), 1, fp);
170 fprintf(fp, " %s\n", cc->ChunkStr);
174 for(cd = FirstCDLine, cs = FirstCatString; cd != NULL; cd = cd->Next)
176 switch(*cd->Line)
178 case '#':
179 fprintf(fp, ";%s\n", cd->Line);
180 break;
182 case ';':
183 fprintf(fp, "%s\n", cd->Line);
184 break;
186 default:
187 if(cs != NULL)
191 fprintf(fp, "%s\n", cs->ID_Str);
192 fprintf(fp, "%s\n", cs->CT_Str ? cs->CT_Str : "");
193 putc(';', fp);
194 putc(' ', fp);
196 fprintf(fp, "%s\n" \
197 "%s\n" \
198 "; ", cs->ID_Str, cs->CT_Str != NULL ? cs->CT_Str : "");
199 for(line = cs->CD_Str; *line; ++line)
201 putc((int)*line, fp);
202 if(*line == '\n')
204 putc(';', fp);
205 putc(' ', fp);
208 putc('\n', fp);
209 if(cs->NotInCT && CT_Scanned)
210 fprintf(fp, ";\n" \
211 "; %s\n", Msg_New);
212 cs = cs->Next;
214 break;
217 fclose(fp);
218 #ifdef AMIGA
219 SetProtection(NewCTFile, FILE_MASK);
220 #endif