Added some SD files which are needed by "contrib".
[AROS.git] / tools / flexcat / src / createct.c
blob163924e4096e88223341f4b220508bc02be718ab
1 /*
2 * $Id$
4 * Copyright (C) 1993-1999 by Jochen Wiedmann and Marcin Orlowski
5 * Copyright (C) 2002-2010 by the 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 != 0L)
123 if(BaseName != NULL)
124 fprintf(fp, "## version %cVER: %s.catalog %d.<rev> (%s)\n", '$', BaseName, CatVersion, dateStr);
125 else
126 fprintf(fp, "## version %cVER: <name>.catalog %d.<rev> (%s)\n", '$', CatVersion, dateStr);
128 else
130 if(BaseName != NULL)
131 fprintf(fp, "## version %cVER: %s.catalog <ver>.0 (%s)\n", '$', BaseName, dateStr);
132 else
133 fprintf(fp, "## version %cVER: <name>.catalog <ver>.0 (%s)\n", '$', dateStr);
136 free(dateStr);
141 fprintf(fp, "## language %s\n" \
142 "## codeset %d\n" \
143 ";\n", ctlanguage != NULL ? ctlanguage : "X", CodeSet);
144 for(cc = FirstChunk; cc != NULL; cc = cc->Next)
146 if(cc->ChunkStr != CatLanguage)
148 fprintf(fp, "## chunk ");
149 fwrite((char *)&cc->ID, sizeof(cc->ID), 1, fp);
150 fprintf(fp, " %s\n", cc->ChunkStr);
154 for(cd = FirstCDLine, cs = FirstCatString; cd != NULL; cd = cd->Next)
156 switch(*cd->Line)
158 case '#':
159 fprintf(fp, ";%s\n", cd->Line);
160 break;
162 case ';':
163 fprintf(fp, "%s\n", cd->Line);
164 break;
166 default:
167 if(cs != NULL)
171 fprintf(fp, "%s\n", cs->ID_Str);
172 fprintf(fp, "%s\n", cs->CT_Str ? cs->CT_Str : "");
173 putc(';', fp);
174 putc(' ', fp);
176 fprintf(fp, "%s\n" \
177 "%s\n" \
178 "; ", cs->ID_Str, cs->CT_Str != NULL ? cs->CT_Str : "");
179 for(line = cs->CD_Str; *line; ++line)
181 putc((int)*line, fp);
182 if(*line == '\n')
184 putc(';', fp);
185 putc(' ', fp);
188 putc('\n', fp);
189 if(cs->NotInCT && CT_Scanned)
190 fprintf(fp, ";\n" \
191 "; %s\n", Msg_New);
192 cs = cs->Next;
194 break;
197 fclose(fp);
198 #ifdef AMIGA
199 SetProtection(NewCTFile, FILE_MASK);
200 #endif