grub2: bring back build of aros-side grub2 tools
[AROS.git] / tools / flexcat / src / main.c
blob214dd3ae1f1bf95f65a7bd8f55b8e9c45081a142
1 /*
2 * $Id$
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. **
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, "nooptim") == 0)
59 return TRUE;
60 if(Stricmp(input_string, "fill") == 0)
61 return TRUE;
62 if(Stricmp(input_string, "quiet") == 0)
63 return TRUE;
64 if(Stricmp(input_string, "flush") == 0)
65 return TRUE;
66 if(Stricmp(input_string, "nobeep") == 0)
67 return TRUE;
68 if(Stricmp(input_string, "nobufferedio") == 0)
69 return TRUE;
70 if(Strnicmp(input_string, "newctfile=", 10) == 0)
71 return TRUE;
72 if(Stricmp(input_string, "newctfile") == 0)
73 return TRUE;
74 if(Stricmp(input_string, "nolangtolower") == 0)
75 return TRUE;
76 if(Stricmp(input_string, "modified") == 0)
77 return TRUE;
78 if(Stricmp(input_string, "warnctgaps") == 0)
79 return TRUE;
80 if(Stricmp(input_string, "copymsgnew") == 0)
81 return TRUE;
82 if(Stricmp(input_string, "oldmsgnew") == 0)
83 return TRUE;
84 if(Stricmp(input_string, "?") == 0)
85 return TRUE;
86 if(Stricmp(input_string, "-h") == 0)
87 return TRUE;
88 if(Stricmp(input_string, "help") == 0)
89 return TRUE;
90 if(Stricmp(input_string, "--help") == 0)
91 return TRUE;
93 return FALSE;
96 ///
97 /// main
99 /* Finally, the main function. It does nothing special
100 except for scanning the arguments. */
102 int main(int argc, char *argv[])
104 char *cdfile = NULL;
105 char *ctfile = NULL;
106 char *pofile = NULL;
107 char *newctfile = NULL;
108 char *catalog = NULL;
109 char *source;
110 char *template;
111 int makenewct = FALSE;
112 int makecatalog = FALSE;
113 int i;
115 if(argc == 0) /* Aztec's entry point for workbench programs */
117 fprintf(stderr, "FlexCat can't be run from Workbench!\n" \
118 "\n"
119 "Open a Shell session and type FlexCat ?\n" \
120 "for more information\n");
121 exit(5);
124 if(OpenLibs() == FALSE)
125 exit(20);
127 OpenFlexCatCatalog();
129 /* Big Endian vs. Little Endian (both supported ;-) */
131 if(!SwapChoose())
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");
136 exit(5);
138 #ifdef AMIGA
139 ReadPrefs();
140 #endif
141 if(argc == 1)
143 Usage();
146 for(i = 1; i < argc; i++)
148 if(Strnicmp(argv[i], "catalog=", 8) == 0)
150 catalog = argv[i] + 8;
151 makecatalog = TRUE;
153 else if(Stricmp(argv[i], "catalog") == 0)
155 if(i == argc - 1)
157 catalog = NULL;
158 makecatalog = TRUE;
160 else if(i < argc - 1)
162 if(isParam(argv[i + 1]) != TRUE)
164 catalog = argv[i + 1];
165 i++;
166 makecatalog = TRUE;
168 else
170 catalog = NULL;
171 makecatalog = TRUE;
175 else if(Strnicmp(argv[i], "pofile=", 7) == 0)
177 pofile = argv[i] + 7;
179 else if(Stricmp(argv[i], "pofile") == 0)
181 if(i == argc - 1)
182 pofile = NULL;
183 else if(i < argc - 1)
185 if(isParam(argv[i + 1]) != TRUE)
187 pofile = argv[i + 1];
188 i++;
190 else
191 pofile = NULL;
194 else if(Strnicmp(argv[i], "codeset=", 8) == 0)
196 strcpy(DestCodeset, argv[i] + 8);
198 else if(Stricmp(argv[i], "codeset") == 0)
200 if(i == argc - 1)
201 DestCodeset[0] = '\0';
202 else if(i < argc - 1)
204 if(isParam(argv[i + 1]) != TRUE)
206 strcpy(DestCodeset, argv[i + 1]);
207 i++;
209 else
210 DestCodeset[0] = '\0';
213 else if(Stricmp(argv[i], "nooptim") == 0)
215 NoOptim = TRUE;
217 else if(Stricmp(argv[i], "fill") == 0)
219 Fill = TRUE;
221 else if(Stricmp(argv[i], "quiet") == 0)
223 Quiet = TRUE;
225 else if(Stricmp(argv[i], "flush") == 0)
227 DoExpunge = TRUE;
229 else if(Stricmp(argv[i], "nobeep") == 0)
231 NoBeep = TRUE;
233 else if(Stricmp(argv[i], "nobufferedio") == 0)
235 NoBufferedIO = TRUE;
237 else if(Strnicmp(argv[i], "newctfile=", 10) == 0)
239 newctfile = argv[i] + 10;
240 makenewct = TRUE;
242 else if(Stricmp(argv[i], "newctfile") == 0)
244 if(i == argc - 1)
246 newctfile = NULL;
247 makenewct = TRUE;
249 else if(i < argc - 1)
251 if(isParam(argv[i + 1]) != TRUE)
253 newctfile = argv[i + 1];
254 i++;
255 makenewct = TRUE;
257 else
259 newctfile = NULL;
260 makenewct = TRUE;
264 else if(Stricmp(argv[i], "nolangtolower") == 0)
266 LANGToLower = FALSE;
268 else if(Stricmp(argv[i], "modified") == 0)
270 Modified = TRUE;
272 else if(Stricmp(argv[i], "warnctgaps") == 0)
274 WarnCTGaps = TRUE;
276 else if(Stricmp(argv[i], "copymsgnew") == 0)
278 CopyNEWs = TRUE;
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)
296 Usage();
299 cdfile = argv[i];
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))
306 MyExit(10);
308 else
310 if(!ScanCDFile(cdfile))
311 MyExit(10);
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, '.');
322 if(lslash == NULL)
323 lslash = cdfile;
324 else
325 lslash++;
327 if(ldot == NULL)
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, '=');
339 *template++ = '\0';
341 CreateSourceFile(source, template, cdfile);
343 else
345 if(ctfile != NULL)
347 Usage();
349 ctfile = argv[i];
353 #ifdef AMIGA
354 if(Modified)
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)
365 cat_time = 0;
367 if(cat_time > ct_time && cat_time > cd_time)
369 if(!Quiet)
371 fprintf(stderr, MSG_FILEUPTODATE, catalog);
372 putc('\n', stderr);
375 MyExit(GlobalReturnCode);
377 else
379 if(!Quiet)
381 fprintf(stderr, "--> %s\n", catalog);
385 else
387 ShowError(MSG_ERR_CANTCHECKDATE, ctfile);
390 else
392 ShowError(MSG_ERR_CANTCHECKDATE, cdfile);
396 #endif
398 if(ctfile != NULL)
400 if(!ScanCTFile(ctfile))
401 MyExit(10);
404 if(pofile != NULL)
406 if(!ScanPOFile(pofile))
407 MyExit(10);
410 if(makecatalog == TRUE)
412 if(ctfile == NULL && pofile == NULL)
414 fprintf(stderr, "%s\n", MSG_ERR_NOCTARGUMENT);
415 Usage();
417 CreateCat(catalog);
420 if(makenewct == TRUE)
422 CreateCTFile(newctfile);
424 MyExit(GlobalReturnCode);
426 return 0;