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.
21 ******************************************************************
22 ** If you use GoldED or any other text editor featuring folding **
23 ** you may want to set up "///" as fold opening phrase, and **
24 ** "///" as closing one, as this source is using it. **
26 ******************************************************************
30 #include "readprefs.h"
31 #include "showfuncs.h"
32 #include "swapfuncs.h"
36 #include "createcat.h"
40 #include "createcatsrc.h"
44 int isParam(char *input_string
)
46 if(Stricmp(input_string
, "catalog") == 0)
48 if(Strnicmp(input_string
, "catalog=", 8) == 0)
50 if(Stricmp(input_string
, "pofile") == 0)
52 if(Strnicmp(input_string
, "pofile=", 7) == 0)
54 if(Stricmp(input_string
, "codeset") == 0)
56 if(Strnicmp(input_string
, "codeset=", 8) == 0)
58 if(Stricmp(input_string
, "nooptim") == 0)
60 if(Stricmp(input_string
, "fill") == 0)
62 if(Stricmp(input_string
, "quiet") == 0)
64 if(Stricmp(input_string
, "flush") == 0)
66 if(Stricmp(input_string
, "nobeep") == 0)
68 if(Stricmp(input_string
, "nobufferedio") == 0)
70 if(Strnicmp(input_string
, "newctfile=", 10) == 0)
72 if(Stricmp(input_string
, "newctfile") == 0)
74 if(Stricmp(input_string
, "nolangtolower") == 0)
76 if(Stricmp(input_string
, "modified") == 0)
78 if(Stricmp(input_string
, "warnctgaps") == 0)
80 if(Stricmp(input_string
, "copymsgnew") == 0)
82 if(Stricmp(input_string
, "oldmsgnew") == 0)
84 if(Stricmp(input_string
, "?") == 0)
86 if(Stricmp(input_string
, "-h") == 0)
88 if(Stricmp(input_string
, "help") == 0)
90 if(Stricmp(input_string
, "--help") == 0)
99 /* Finally, the main function. It does nothing special
100 except for scanning the arguments. */
102 int main(int argc
, char *argv
[])
107 char *newctfile
= NULL
;
108 char *catalog
= NULL
;
111 int makenewct
= FALSE
;
112 int makecatalog
= FALSE
;
115 if(argc
== 0) /* Aztec's entry point for workbench programs */
117 fprintf(stderr
, "FlexCat can't be run from Workbench!\n" \
119 "Open a Shell session and type FlexCat ?\n" \
120 "for more information\n");
124 if(OpenLibs() == FALSE
)
127 OpenFlexCatCatalog();
129 /* Big Endian vs. Little Endian (both supported ;-) */
133 fprintf(stderr
, "FlexCat is unable to determine\n" \
134 "the byte order used by your system.\n" \
135 "It's neither Little nor Big Endian?!.\n");
146 for(i
= 1; i
< argc
; i
++)
148 if(Strnicmp(argv
[i
], "catalog=", 8) == 0)
150 catalog
= argv
[i
] + 8;
153 else if(Stricmp(argv
[i
], "catalog") == 0)
160 else if(i
< argc
- 1)
162 if(isParam(argv
[i
+ 1]) != TRUE
)
164 catalog
= argv
[i
+ 1];
175 else if(Strnicmp(argv
[i
], "pofile=", 7) == 0)
177 pofile
= argv
[i
] + 7;
179 else if(Stricmp(argv
[i
], "pofile") == 0)
183 else if(i
< argc
- 1)
185 if(isParam(argv
[i
+ 1]) != TRUE
)
187 pofile
= argv
[i
+ 1];
194 else if(Strnicmp(argv
[i
], "codeset=", 8) == 0)
196 strcpy(DestCodeset
, argv
[i
] + 8);
198 else if(Stricmp(argv
[i
], "codeset") == 0)
201 DestCodeset
[0] = '\0';
202 else if(i
< argc
- 1)
204 if(isParam(argv
[i
+ 1]) != TRUE
)
206 strcpy(DestCodeset
, argv
[i
+ 1]);
210 DestCodeset
[0] = '\0';
213 else if(Stricmp(argv
[i
], "nooptim") == 0)
217 else if(Stricmp(argv
[i
], "fill") == 0)
221 else if(Stricmp(argv
[i
], "quiet") == 0)
225 else if(Stricmp(argv
[i
], "flush") == 0)
229 else if(Stricmp(argv
[i
], "nobeep") == 0)
233 else if(Stricmp(argv
[i
], "nobufferedio") == 0)
237 else if(Strnicmp(argv
[i
], "newctfile=", 10) == 0)
239 newctfile
= argv
[i
] + 10;
242 else if(Stricmp(argv
[i
], "newctfile") == 0)
249 else if(i
< argc
- 1)
251 if(isParam(argv
[i
+ 1]) != TRUE
)
253 newctfile
= argv
[i
+ 1];
264 else if(Stricmp(argv
[i
], "nolangtolower") == 0)
268 else if(Stricmp(argv
[i
], "modified") == 0)
272 else if(Stricmp(argv
[i
], "warnctgaps") == 0)
276 else if(Stricmp(argv
[i
], "copymsgnew") == 0)
280 else if(Stricmp(argv
[i
], "oldmsgnew") == 0)
282 snprintf(Old_Msg_New
, sizeof(Old_Msg_New
), "; %s", argv
[++i
]);
284 else if(Stricmp(argv
[i
], "noautodate") == 0 || Stricmp(argv
[i
], "nospaces") == 0)
286 // just swallow some no longer supported options to
287 // keep old scripts alive and happy
289 else if(cdfile
== NULL
)
291 if(Stricmp(argv
[i
], "?") == 0 ||
292 Stricmp(argv
[i
], "-h") == 0 ||
293 Stricmp(argv
[i
], "help") == 0 ||
294 Stricmp(argv
[i
], "--help") == 0)
301 // find out file extension and depending on it
302 // we eiterh scan a CD file or the supplied pot file
303 if(strstr(cdfile
, ".pot") != NULL
)
305 if(!ScanPOFile(cdfile
))
310 if(!ScanCDFile(cdfile
))
314 else if(strchr(argv
[i
], '=') != NULL
)
316 /* Determine basename. */
317 if(BaseName
== NULL
&& cdfile
!= NULL
)
319 char *lslash
= strrchr(cdfile
, '/');
320 char *ldot
= strrchr(cdfile
, '.');
328 ldot
= cdfile
+ strlen(cdfile
);
330 if(ldot
- lslash
> 0)
332 BaseName
= calloc(ldot
- lslash
+ 3, 1);
333 strncpy(BaseName
, lslash
, ldot
- lslash
);
337 source
=AllocString(argv
[i
]);
338 template = strchr(source
, '=');
341 CreateSourceFile(source
, template, cdfile
);
356 if(cdfile
!= NULL
&& ctfile
!= NULL
&& catalog
!= NULL
)
358 int32 cd_time
, ct_time
, cat_time
;
360 if((cd_time
= getft(cdfile
)) != -1)
362 if((ct_time
= getft(ctfile
)) != -1)
364 if((cat_time
= getft(catalog
)) == -1)
367 if(cat_time
> ct_time
&& cat_time
> cd_time
)
371 fprintf(stderr
, MSG_FILEUPTODATE
, catalog
);
375 MyExit(GlobalReturnCode
);
381 fprintf(stderr
, "--> %s\n", catalog
);
387 ShowError(MSG_ERR_CANTCHECKDATE
, ctfile
);
392 ShowError(MSG_ERR_CANTCHECKDATE
, cdfile
);
400 if(!ScanCTFile(ctfile
))
406 if(!ScanPOFile(pofile
))
410 if(makecatalog
== TRUE
)
412 if(ctfile
== NULL
&& pofile
== NULL
)
414 fprintf(stderr
, "%s\n", MSG_ERR_NOCTARGUMENT
);
420 if(makenewct
== TRUE
)
422 CreateCTFile(newctfile
);
424 MyExit(GlobalReturnCode
);