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.
24 #include "readprefs.h"
25 #include "showfuncs.h"
28 #include "createcat.h"
32 // This creates a new catalog translation file.
33 void CreateCTFile(char *NewCTFile
)
38 struct CatalogChunk
*cc
;
40 char*ctlanguage
= NULL
;
42 if(CatVersionString
== NULL
&& CatRcsId
== NULL
)
47 if(CatLanguage
== NULL
)
52 if(GetVar("language", lang
, sizeof(lang
), 0) != 0)
59 if((lang
= getenv("language")) != NULL
)
63 for(i
= 0; i
< strlen(lang
); i
++)
76 ctlanguage
= CatLanguage
;
78 if(ctlanguage
== NULL
)
79 ctlanguage
= (char *)"nolanguage";
84 ShowError(MSG_ERR_NOCTFILENAME
);
87 if(asprintf(&NewCTFile
, "%s_%s.catalog", BaseName
, ctlanguage
) < 0)
91 if((fp
= fopen(NewCTFile
, "w")) == NULL
)
93 ShowError(MSG_ERR_NONEWCTFILE
);
97 setvbuf(fp
, NULL
, _IOFBF
, buffer_size
);
102 fprintf(fp
, "## rcsid %s\n", CatRcsId
);
104 fprintf(fp
, "## name %s\n", CatName
);
108 if(CatVersionString
!= NULL
)
109 fprintf(fp
, "## version %s\n", CatVersionString
);
116 dateStr
= calloc(15, 1);
119 strftime(dateStr
, 12, "%d.%m.%Y", t
);
123 if(CatRevision
!= -1)
126 fprintf(fp
, "## version %cVER: %s.catalog %d.%d (%s)\n", '$', BaseName
, CatVersion
, CatRevision
, dateStr
);
128 fprintf(fp
, "## version %cVER: <name>.catalog %d.%d (%s)\n", '$', CatVersion
, CatRevision
, dateStr
);
133 fprintf(fp
, "## version %cVER: %s.catalog %d.<rev> (%s)\n", '$', BaseName
, CatVersion
, dateStr
);
135 fprintf(fp
, "## version %cVER: <name>.catalog %d.<rev> (%s)\n", '$', CatVersion
, dateStr
);
140 if(CatRevision
!= -1)
143 fprintf(fp
, "## version %cVER: %s.catalog <ver>.%d (%s)\n", '$', BaseName
, CatRevision
, dateStr
);
145 fprintf(fp
, "## version %cVER: <name>.catalog <ver>.%d (%s)\n", '$', CatRevision
, dateStr
);
150 fprintf(fp
, "## version %cVER: %s.catalog <ver>.<rev> (%s)\n", '$', BaseName
, dateStr
);
152 fprintf(fp
, "## version %cVER: <name>.catalog <ver>.<rev> (%s)\n", '$', dateStr
);
161 fprintf(fp
, "## language %s\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
)
179 fprintf(fp
, ";%s\n", cd
->Line
);
183 fprintf(fp
, "%s\n", cd
->Line
);
191 fprintf(fp, "%s\n", cs->ID_Str);
192 fprintf(fp, "%s\n", cs->CT_Str ? cs->CT_Str : "");
198 "; ", cs
->ID_Str
, cs
->CT_Str
!= NULL
? cs
->CT_Str
: "");
199 for(line
= cs
->CD_Str
; *line
; ++line
)
201 putc((int)*line
, fp
);
209 if(cs
->NotInCT
&& CT_Scanned
)
219 SetProtection(NewCTFile
, FILE_MASK
);