fix __AROS_SETVECADDR invocations.
[AROS.git] / tools / flexcat / src / main.c
blob41f0e6448e7aa23d6bc672cc8e7a07d9a44de96e
1 /*
2 * $Id$
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. **
25 ** Marcin **
26 ******************************************************************
29 #include "flexcat.h"
30 #include "readprefs.h"
31 #include "showfuncs.h"
32 #include "swapfuncs.h"
33 #include "scanct.h"
34 #include "scancd.h"
35 #include "scanpo.h"
36 #include "createcat.h"
37 #include "createct.h"
38 #include "utils.h"
39 #include "globals.h"
40 #include "createcatsrc.h"
41 #include "openlibs.h"
43 /// isParam
44 int isParam(char *input_string)
46 if(Stricmp(input_string, "catalog") == 0)
47 return TRUE;
48 if(Strnicmp(input_string, "catalog=", 8) == 0)
49 return TRUE;
50 if(Stricmp(input_string, "pofile") == 0)
51 return TRUE;
52 if(Strnicmp(input_string, "pofile=", 7) == 0)
53 return TRUE;
54 if(Stricmp(input_string, "codeset") == 0)
55 return TRUE;
56 if(Strnicmp(input_string, "codeset=", 8) == 0)
57 return TRUE;
58 if(Stricmp(input_string, "version") == 0)
59 return TRUE;
60 if(Strnicmp(input_string, "version=", 8) == 0)
61 return TRUE;
62 if(Stricmp(input_string, "revision") == 0)
63 return TRUE;
64 if(Strnicmp(input_string, "revision=", 8) == 0)
65 return TRUE;
66 if(Stricmp(input_string, "nooptim") == 0)
67 return TRUE;
68 if(Stricmp(input_string, "fill") == 0)
69 return TRUE;
70 if(Stricmp(input_string, "quiet") == 0)
71 return TRUE;
72 if(Stricmp(input_string, "flush") == 0)
73 return TRUE;
74 if(Stricmp(input_string, "nobeep") == 0)
75 return TRUE;
76 if(Stricmp(input_string, "nobufferedio") == 0)
77 return TRUE;
78 if(Strnicmp(input_string, "newctfile=", 10) == 0)
79 return TRUE;
80 if(Stricmp(input_string, "newctfile") == 0)
81 return TRUE;
82 if(Stricmp(input_string, "nolangtolower") == 0)
83 return TRUE;
84 if(Stricmp(input_string, "modified") == 0)
85 return TRUE;
86 if(Stricmp(input_string, "warnctgaps") == 0)
87 return TRUE;
88 if(Stricmp(input_string, "copymsgnew") == 0)
89 return TRUE;
90 if(Stricmp(input_string, "oldmsgnew") == 0)
91 return TRUE;
92 if(Stricmp(input_string, "?") == 0)
93 return TRUE;
94 if(Stricmp(input_string, "-h") == 0)
95 return TRUE;
96 if(Stricmp(input_string, "help") == 0)
97 return TRUE;
98 if(Stricmp(input_string, "--help") == 0)
99 return TRUE;
101 return FALSE;
105 /// main
107 /* Finally, the main function. It does nothing special
108 except for scanning the arguments. */
110 int main(int argc, char *argv[])
112 char *cdfile = NULL;
113 char *ctfile = NULL;
114 char *pofile = NULL;
115 char *newctfile = NULL;
116 char *catalog = NULL;
117 char *source;
118 char *template;
119 int makenewct = FALSE;
120 int makecatalog = FALSE;
121 int i;
123 if(argc == 0) /* Aztec's entry point for workbench programs */
125 fprintf(stderr, "FlexCat can't be run from Workbench!\n" \
126 "\n"
127 "Open a Shell session and type FlexCat ?\n" \
128 "for more information\n");
129 exit(5);
132 if(OpenLibs() == FALSE)
133 exit(20);
135 OpenFlexCatCatalog();
137 /* Big Endian vs. Little Endian (both supported ;-) */
139 if(!SwapChoose())
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");
144 exit(5);
146 #ifdef AMIGA
147 ReadPrefs();
148 #endif
149 if(argc == 1)
151 Usage();
154 for(i = 1; i < argc; i++)
156 if(Strnicmp(argv[i], "catalog=", 8) == 0)
158 catalog = argv[i] + 8;
159 makecatalog = TRUE;
161 else if(Stricmp(argv[i], "catalog") == 0)
163 if(i == argc - 1)
165 catalog = NULL;
166 makecatalog = TRUE;
168 else if(i < argc - 1)
170 if(isParam(argv[i + 1]) != TRUE)
172 catalog = argv[i + 1];
173 i++;
174 makecatalog = TRUE;
176 else
178 catalog = NULL;
179 makecatalog = TRUE;
183 else if(Strnicmp(argv[i], "pofile=", 7) == 0)
185 pofile = argv[i] + 7;
187 else if(Stricmp(argv[i], "pofile") == 0)
189 if(i == argc - 1)
190 pofile = NULL;
191 else if(i < argc - 1)
193 if(isParam(argv[i + 1]) != TRUE)
195 pofile = argv[i + 1];
196 i++;
198 else
199 pofile = NULL;
202 else if(Strnicmp(argv[i], "codeset=", 8) == 0)
204 strcpy(DestCodeset, argv[i] + 8);
206 else if(Stricmp(argv[i], "codeset") == 0)
208 if(i == argc - 1)
209 DestCodeset[0] = '\0';
210 else if(i < argc - 1)
212 if(isParam(argv[i + 1]) != TRUE)
214 strcpy(DestCodeset, argv[i + 1]);
215 i++;
217 else
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)
227 if(i == argc - 1)
228 CatVersion = -1;
229 else if(i < argc - 1)
231 if(isParam(argv[i + 1]) != TRUE)
233 CatVersion = strtol(argv[i + 1], NULL, 10);
234 i++;
236 else
237 CatVersion = -1;
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)
246 if(i == argc - 1)
247 CatRevision = -1;
248 else if(i < argc - 1)
250 if(isParam(argv[i + 1]) != TRUE)
252 CatRevision = strtol(argv[i + 1], NULL, 10);
253 i++;
255 else
256 CatRevision = -1;
259 else if(Stricmp(argv[i], "nooptim") == 0)
261 NoOptim = TRUE;
263 else if(Stricmp(argv[i], "fill") == 0)
265 Fill = TRUE;
267 else if(Stricmp(argv[i], "quiet") == 0)
269 Quiet = TRUE;
271 else if(Stricmp(argv[i], "flush") == 0)
273 DoExpunge = TRUE;
275 else if(Stricmp(argv[i], "nobeep") == 0)
277 NoBeep = TRUE;
279 else if(Stricmp(argv[i], "nobufferedio") == 0)
281 NoBufferedIO = TRUE;
283 else if(Strnicmp(argv[i], "newctfile=", 10) == 0)
285 newctfile = argv[i] + 10;
286 makenewct = TRUE;
288 else if(Stricmp(argv[i], "newctfile") == 0)
290 if(i == argc - 1)
292 newctfile = NULL;
293 makenewct = TRUE;
295 else if(i < argc - 1)
297 if(isParam(argv[i + 1]) != TRUE)
299 newctfile = argv[i + 1];
300 i++;
301 makenewct = TRUE;
303 else
305 newctfile = NULL;
306 makenewct = TRUE;
310 else if(Stricmp(argv[i], "nolangtolower") == 0)
312 LANGToLower = FALSE;
314 else if(Stricmp(argv[i], "modified") == 0)
316 Modified = TRUE;
318 else if(Stricmp(argv[i], "warnctgaps") == 0)
320 WarnCTGaps = TRUE;
322 else if(Stricmp(argv[i], "copymsgnew") == 0)
324 CopyNEWs = TRUE;
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)
342 Usage();
345 cdfile = argv[i];
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))
352 MyExit(10);
354 else
356 if(!ScanCDFile(cdfile))
357 MyExit(10);
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, '.');
368 if(lslash == NULL)
369 lslash = cdfile;
370 else
371 lslash++;
373 if(ldot == NULL)
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, '=');
385 *template++ = '\0';
387 CreateSourceFile(source, template, cdfile);
389 else
391 if(ctfile != NULL)
393 Usage();
395 ctfile = argv[i];
399 #ifdef AMIGA
400 if(Modified)
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)
411 cat_time = 0;
413 if(cat_time > ct_time && cat_time > cd_time)
415 if(!Quiet)
417 fprintf(stderr, MSG_FILEUPTODATE, catalog);
418 putc('\n', stderr);
421 MyExit(GlobalReturnCode);
423 else
425 if(!Quiet)
427 fprintf(stderr, "--> %s\n", catalog);
431 else
433 ShowError(MSG_ERR_CANTCHECKDATE, ctfile);
436 else
438 ShowError(MSG_ERR_CANTCHECKDATE, cdfile);
442 #endif
444 if(ctfile != NULL)
446 if(!ScanCTFile(ctfile))
447 MyExit(10);
450 if(pofile != NULL)
452 if(!ScanPOFile(pofile, makecatalog))
453 MyExit(10);
456 if(makecatalog == TRUE)
458 if(ctfile == NULL && pofile == NULL)
460 fprintf(stderr, "%s\n", MSG_ERR_NOCTARGUMENT);
461 Usage();
463 CreateCat(catalog);
466 if(makenewct == TRUE)
468 CreateCTFile(newctfile);
470 MyExit(GlobalReturnCode);
472 return 0;