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.
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
, "version") == 0)
60 if(Strnicmp(input_string
, "version=", 8) == 0)
62 if(Stricmp(input_string
, "revision") == 0)
64 if(Strnicmp(input_string
, "revision=", 8) == 0)
66 if(Stricmp(input_string
, "nooptim") == 0)
68 if(Stricmp(input_string
, "fill") == 0)
70 if(Stricmp(input_string
, "quiet") == 0)
72 if(Stricmp(input_string
, "flush") == 0)
74 if(Stricmp(input_string
, "nobeep") == 0)
76 if(Stricmp(input_string
, "nobufferedio") == 0)
78 if(Strnicmp(input_string
, "newctfile=", 10) == 0)
80 if(Stricmp(input_string
, "newctfile") == 0)
82 if(Stricmp(input_string
, "nolangtolower") == 0)
84 if(Stricmp(input_string
, "modified") == 0)
86 if(Stricmp(input_string
, "warnctgaps") == 0)
88 if(Stricmp(input_string
, "copymsgnew") == 0)
90 if(Stricmp(input_string
, "oldmsgnew") == 0)
92 if(Stricmp(input_string
, "?") == 0)
94 if(Stricmp(input_string
, "-h") == 0)
96 if(Stricmp(input_string
, "help") == 0)
98 if(Stricmp(input_string
, "--help") == 0)
107 /* Finally, the main function. It does nothing special
108 except for scanning the arguments. */
110 int main(int argc
, char *argv
[])
115 char *newctfile
= NULL
;
116 char *catalog
= NULL
;
119 int makenewct
= FALSE
;
120 int makecatalog
= FALSE
;
123 if(argc
== 0) /* Aztec's entry point for workbench programs */
125 fprintf(stderr
, "FlexCat can't be run from Workbench!\n" \
127 "Open a Shell session and type FlexCat ?\n" \
128 "for more information\n");
132 if(OpenLibs() == FALSE
)
135 OpenFlexCatCatalog();
137 /* Big Endian vs. Little Endian (both supported ;-) */
141 fprintf(stderr
, "FlexCat is unable to determine\n" \
142 "the byte order used by your system.\n" \
143 "It's neither Little nor Big Endian?!.\n");
154 for(i
= 1; i
< argc
; i
++)
156 if(Strnicmp(argv
[i
], "catalog=", 8) == 0)
158 catalog
= argv
[i
] + 8;
161 else if(Stricmp(argv
[i
], "catalog") == 0)
168 else if(i
< argc
- 1)
170 if(isParam(argv
[i
+ 1]) != TRUE
)
172 catalog
= argv
[i
+ 1];
183 else if(Strnicmp(argv
[i
], "pofile=", 7) == 0)
185 pofile
= argv
[i
] + 7;
187 else if(Stricmp(argv
[i
], "pofile") == 0)
191 else if(i
< argc
- 1)
193 if(isParam(argv
[i
+ 1]) != TRUE
)
195 pofile
= argv
[i
+ 1];
202 else if(Strnicmp(argv
[i
], "codeset=", 8) == 0)
204 strcpy(DestCodeset
, argv
[i
] + 8);
206 else if(Stricmp(argv
[i
], "codeset") == 0)
209 DestCodeset
[0] = '\0';
210 else if(i
< argc
- 1)
212 if(isParam(argv
[i
+ 1]) != TRUE
)
214 strcpy(DestCodeset
, argv
[i
+ 1]);
218 DestCodeset
[0] = '\0';
221 else if(Strnicmp(argv
[i
], "version=", 8) == 0)
223 CatVersion
= strtol(argv
[i
]+8, NULL
, 10);
225 else if(Stricmp(argv
[i
], "version") == 0)
229 else if(i
< argc
- 1)
231 if(isParam(argv
[i
+ 1]) != TRUE
)
233 CatVersion
= strtol(argv
[i
+ 1], NULL
, 10);
240 else if(Strnicmp(argv
[i
], "revision=", 9) == 0)
242 CatRevision
= strtol(argv
[i
]+9, NULL
, 10);
244 else if(Stricmp(argv
[i
], "revision") == 0)
248 else if(i
< argc
- 1)
250 if(isParam(argv
[i
+ 1]) != TRUE
)
252 CatRevision
= strtol(argv
[i
+ 1], NULL
, 10);
259 else if(Stricmp(argv
[i
], "nooptim") == 0)
263 else if(Stricmp(argv
[i
], "fill") == 0)
267 else if(Stricmp(argv
[i
], "quiet") == 0)
271 else if(Stricmp(argv
[i
], "flush") == 0)
275 else if(Stricmp(argv
[i
], "nobeep") == 0)
279 else if(Stricmp(argv
[i
], "nobufferedio") == 0)
283 else if(Strnicmp(argv
[i
], "newctfile=", 10) == 0)
285 newctfile
= argv
[i
] + 10;
288 else if(Stricmp(argv
[i
], "newctfile") == 0)
295 else if(i
< argc
- 1)
297 if(isParam(argv
[i
+ 1]) != TRUE
)
299 newctfile
= argv
[i
+ 1];
310 else if(Stricmp(argv
[i
], "nolangtolower") == 0)
314 else if(Stricmp(argv
[i
], "modified") == 0)
318 else if(Stricmp(argv
[i
], "warnctgaps") == 0)
322 else if(Stricmp(argv
[i
], "copymsgnew") == 0)
326 else if(Stricmp(argv
[i
], "oldmsgnew") == 0)
328 snprintf(Old_Msg_New
, sizeof(Old_Msg_New
), "; %s", argv
[++i
]);
330 else if(Stricmp(argv
[i
], "noautodate") == 0 || Stricmp(argv
[i
], "nospaces") == 0)
332 // just swallow some no longer supported options to
333 // keep old scripts alive and happy
335 else if(cdfile
== NULL
)
337 if(Stricmp(argv
[i
], "?") == 0 ||
338 Stricmp(argv
[i
], "-h") == 0 ||
339 Stricmp(argv
[i
], "help") == 0 ||
340 Stricmp(argv
[i
], "--help") == 0)
347 // find out file extension and depending on it
348 // we eiterh scan a CD file or the supplied pot file
349 if(strstr(cdfile
, ".pot") != NULL
)
351 if(!ScanPOFile(cdfile
, FALSE
))
356 if(!ScanCDFile(cdfile
))
360 else if(strchr(argv
[i
], '=') != NULL
)
362 /* Determine basename. */
363 if(BaseName
== NULL
&& cdfile
!= NULL
)
365 char *lslash
= strrchr(cdfile
, '/');
366 char *ldot
= strrchr(cdfile
, '.');
374 ldot
= cdfile
+ strlen(cdfile
);
376 if(ldot
- lslash
> 0)
378 BaseName
= calloc(ldot
- lslash
+ 3, 1);
379 strncpy(BaseName
, lslash
, ldot
- lslash
);
383 source
=AllocString(argv
[i
]);
384 template = strchr(source
, '=');
387 CreateSourceFile(source
, template, cdfile
);
402 if(cdfile
!= NULL
&& ctfile
!= NULL
&& catalog
!= NULL
)
404 int32 cd_time
, ct_time
, cat_time
;
406 if((cd_time
= getft(cdfile
)) != -1)
408 if((ct_time
= getft(ctfile
)) != -1)
410 if((cat_time
= getft(catalog
)) == -1)
413 if(cat_time
> ct_time
&& cat_time
> cd_time
)
417 fprintf(stderr
, MSG_FILEUPTODATE
, catalog
);
421 MyExit(GlobalReturnCode
);
427 fprintf(stderr
, "--> %s\n", catalog
);
433 ShowError(MSG_ERR_CANTCHECKDATE
, ctfile
);
438 ShowError(MSG_ERR_CANTCHECKDATE
, cdfile
);
446 if(!ScanCTFile(ctfile
))
452 if(!ScanPOFile(pofile
, makecatalog
))
456 if(makecatalog
== TRUE
)
458 if(ctfile
== NULL
&& pofile
== NULL
)
460 fprintf(stderr
, "%s\n", MSG_ERR_NOCTARGUMENT
);
466 if(makenewct
== TRUE
)
468 CreateCTFile(newctfile
);
470 MyExit(GlobalReturnCode
);