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.
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
);
124 fprintf(fp
, "## version %cVER: %s.catalog %d.<rev> (%s)\n", '$', BaseName
, CatVersion
, dateStr
);
126 fprintf(fp
, "## version %cVER: <name>.catalog %d.<rev> (%s)\n", '$', CatVersion
, dateStr
);
131 fprintf(fp
, "## version %cVER: %s.catalog <ver>.0 (%s)\n", '$', BaseName
, dateStr
);
133 fprintf(fp
, "## version %cVER: <name>.catalog <ver>.0 (%s)\n", '$', dateStr
);
141 fprintf(fp
, "## language %s\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
)
159 fprintf(fp
, ";%s\n", cd
->Line
);
163 fprintf(fp
, "%s\n", cd
->Line
);
171 fprintf(fp, "%s\n", cs->ID_Str);
172 fprintf(fp, "%s\n", cs->CT_Str ? cs->CT_Str : "");
178 "; ", cs
->ID_Str
, cs
->CT_Str
!= NULL
? cs
->CT_Str
: "");
179 for(line
= cs
->CD_Str
; *line
; ++line
)
181 putc((int)*line
, fp
);
189 if(cs
->NotInCT
&& CT_Scanned
)
199 SetProtection(NewCTFile
, FILE_MASK
);