-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.c
566 lines (494 loc) · 13.5 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
/*
* @(#)main.c
*
* Copyright 1997-1999, Wes Cherry (mailto:wesc@technosis.com)
* 2000-2005, Aaron Ardiri (mailto:aaron@ardiri.com)
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, please write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Revisions:
* ==========
*
* pre 18-Jun-2000 <numerous developers>
* creation
* 18-Jun-2000 Aaron Ardiri
* GNU GPL documentation additions
* 20-Nov-2000 Renaud malaval (rmalaval@palm.com)
* Add full support of PalmOS 3.5 (bitfields, structures, ...)
* Add resource LAUNCHERCATEGORY (taic)
* Add support for Little Endian 32 bits: LE32 (ARM and NT)
* Jan-2001 Regis Nicolas
* Merged 68K and LE32 version into one binary
* 12-Jan-2001 Renaud Malaval
* Added 'wrdl' resource support
* 4-Jun-2002 Ben Combee
* Added more control over AUTOID numbers
* 3-Oct-2002 Ben Combee
* Changed include path mechanism to allow unlimited
* numbers of include paths (constrained by memory)
* 23-Oct-2003 Don't print copyright string when -q used
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef PALM_INTERNAL
#include <io.h>
#include <direct.h>
#endif
#include "pilrc.h"
#include "version.h"
#include "restype.h"
#if !defined(__GNUC__) && !defined(__MWERKS__)
#ifdef PALM_INTERNAL
#pragma message( "- Palm internal version" )
#else
#pragma message( "- Standard version" )
#endif
#endif
#define Str(x) #x
#define XStr(x) Str(x)
static const char header[] =
"PilRC v" PILRC_VERSION_STR "\n"
" Copyright 1997-1999 Wes Cherry (wesc@ricochet.net)\n"
" Copyright 2000-2005 Aaron Ardiri (aaron@ardiri.com)\n";
static const char disclaimer[] =
"This program is free software; you may redistribute it under the\n"
"terms of the GNU General Public License. This program has absolutely\n"
"no warranty, you use it AS IS at your own risk.\n";
static const char usage[] =
"Usage: pilrc [options...] infile [outfiledir]\n"
"\n"
"Options:\n"
" -L <language> Use the TRANSLATION section for the given language\n"
" Up to " XStr(MAXLANG) " -L options may be given\n"
" -I <path> Search for bitmap and include files in <path> as well as\n"
" the current directory (may be given more than once)\n"
#ifdef PALM_INTERNAL
" -noIFIH Parse includes files in header files\n"
#else
" -noIFIH Ignore includes files in header files\n"
#endif
" -R <resfile> Generate JUMP/PilA .res file\n"
" -ro Generate resource database file (.ro) instead of .bins\n"
" -ts put POSIX timestamp on .ro file generated\n"
" -o <filedir> Equivalent to [outfiledir]\n"
" -H <incfile> Autoassign IDs and write .h file with #defines\n"
" -idStart <n> Start autoID assignment at number <n>, counting up\n"
" -D <macro> Define a pre-processor macro symbol\n"
" -F5 Use Big5 Chinese font widths\n"
" -Fkt Use Korean font widths (hantip font)\n"
" -Fkm Use Korean font widths (hanme font)\n"
" -Fg Use GB Chinese font widths\n"
" -Fj Use Japense font widths\n"
" -Fh Use Hebrew font widths\n"
" -Fc Use Cyrillic font widths\n"
" -rtl Right to left support\n"
" -q Less noisy output\n"
" -V Generate M$ (VS-type) error/warning output\n"
" -allowEditID Disable warnings about menu item IDs in the\n"
" edit (10000-10007) range\n"
" -allowBadSize Disable warnings about icon sizes being incorrect\n"
" -allowLargeRes Disable warnings about resources that exceed the maximum\n"
" HotSync resource size\n"
" -noEllipsis Disable special handling of \"...\" and ellipsis char\n"
" -PalmRez Generate res with PalmRez option\n"
" -LE32 Generate 32 bit little endian (ARM, NT) resources\n"
#ifdef PALM_INTERNAL
" -AppIcon68K Force AppIcon resources generation in 68K format\n"
" -amdc <name> Generate resource 'amdc' id=1 with <name>.dll as content\n"
#endif
" -Loc <code> Compile only res with the attribute LOCALE \"code\"\n"
" code samples: deDE, esES, enUS, frFR, itIT, jpJP\n"
" -StripLoc Don't compile 'non localisable resources'\n"
" -type Specify the type to use when generating a prc (-ro)\n"
" -creator Specify the creator to use when generating a prc (-ro)\n"
" -name Specify the database name when generating a prc (-ro)\n"
" <outfiledir> Directory where .bin files should be generated, or name of\n"
" the file to generate containing all the generated resources\n"
" -M Generate dependency list only; suppress all other output\n"
" -MD Generate dependency list\n";
static void
ArgError()
{
fprintf(stderr, "%s", usage);
exit(1);
}
/**
* The main entry point of PilRC.
*
* @param cArg the number of command line arguments.
* @param rgszArg a reference to a list of command line argument strings.
* @return program exit status, zero successful, non-zero otherwise.
*/
int
main(int cArg,
char *rgszArg[])
{
char *szOutputPath;
char *szInputFile;
char *szResFile;
char *szMacro;
char *szValue;
char *szIncFile;
char *szIDStart;
int i;
int fontType;
int macroValue;
if (cArg < 2)
{
printf("%s\n%s\n%s", header, disclaimer, usage);
exit(1);
}
// initialize
vfCheckDupes = 1;
szResFile = NULL;
szIncFile = NULL;
fontType = fontDefault;
szOutputPath = ".";
vfPrcName = NULL;
vfPrcCreator = NULL;
vfPrcType = NULL;
vfStripNoLocRes = fFalse;
szLocaleP = NULL;
szDllNameP = NULL;
// vfIFIH = fFalse;
#ifdef PALM_INTERNAL
vfIFIH = fTrue; // RMa Default no Parse include in header file
#else
vfIFIH = fFalse;
#endif
vfLE32 = fFalse;
vfAppIcon68K = fFalse;
vfAutoAmdc = fFalse;
// process as many command line arguments as possible
for (i = 1; i < cArg; i++)
{
// no more options to process
if (rgszArg[i][0] != '-')
break;
// RMa localisation
if (FSzEqI(rgszArg[i], "-Loc"))
{
if (i++ == cArg)
ArgError();
szLocaleP = rgszArg[i];
continue;
}
if (FSzEqI(rgszArg[i], "-StripLoc"))
{
vfStripNoLocRes = fTrue;
continue;
}
// language
if (FSzEqI(rgszArg[i], "-L"))
{
if (i++ == cArg || totalLanguages >= MAXLANG)
ArgError();
aszLanguage[totalLanguages++] = rgszArg[i];
continue;
}
// include directory(s)
if (FSzEqI(rgszArg[i], "-I"))
{
if (i++ == cArg)
ArgError();
AddAccessPath(rgszArg[i]);
continue;
}
// define macro(s) for #ifdef's
if (FSzEqI(rgszArg[i], "-D"))
{
if (i++ == cArg)
ArgError();
szMacro = strdup(rgszArg[i]);
// Check if there is a value defined for the macro, otherwise use '1'
if ((szValue = strchr(szMacro, '=')) != NULL)
{
*szValue++ = '\0';
macroValue = atoi(szValue);
}
else
{
macroValue = 1;
}
AddSym(szMacro, macroValue);
free(szMacro);
continue;
}
// resource file for PILA?
if (FSzEqI(rgszArg[i], "-R"))
{
if (i++ == cArg)
ArgError();
szResFile = rgszArg[i];
continue;
}
// header file generation (autoID for ALL)
if (FSzEqI(rgszArg[i], "-H"))
{
if (i++ == cArg)
ArgError();
szIncFile = rgszArg[i];
vfAutoId = fTrue;
continue;
}
// ID value control -- Increasing IDs
if (FSzEqI(rgszArg[i], "-idStart"))
{
if (i++ == cArg)
ArgError();
szIDStart = rgszArg[i];
// reset ID start sequence to this number and start counting up.
vfAutoStartID = atoi(szIDStart);
idAutoDirection = +1;
continue;
}
// be quiet?
if (FSzEqI(rgszArg[i], "-q"))
{
vfQuiet = fTrue;
continue;
}
// allow "edit" ID's?
if (FSzEqI(rgszArg[i], "-allowEditID"))
{
vfAllowEditIDs = fTrue;
continue;
}
// allow "edit" ID's?
if (FSzEqI(rgszArg[i], "-allowBadSize"))
{
vfAllowBadIconSizes = fTrue;
continue;
}
// allow "edit" ID's?
if (FSzEqI(rgszArg[i], "-allowLargeRes"))
{
vfAllowLargeResources = fTrue;
continue;
}
// disable ellipsis processing?
if (FSzEqI(rgszArg[i], "-noEllipsis"))
{
vfNoEllipsis = fTrue;
continue;
}
// No default flag for form and object form
if (FSzEqI(rgszArg[i], "-PalmRez"))
{
vfPalmRez = fTrue;
continue;
}
// M$ (VS-type) error/warning ouput (regis_nicolas@palm.com)
if (FSzEqI(rgszArg[i], "-V"))
{
vfVSErrors = fTrue;
continue;
}
// font hebrew
if (FSzEqI(rgszArg[i], "-Fh"))
{
fontType = fontHebrew;
continue;
}
// font japanese
if (FSzEqI(rgszArg[i], "-Fj"))
{
fontType = fontJapanese;
continue;
}
// font chinese big 5
if (FSzEqI(rgszArg[i], "-F5"))
{
fontType = fontChineseBig5;
continue;
}
// font chinese GB
if (FSzEqI(rgszArg[i], "-Fg"))
{
fontType = fontChineseGB;
continue;
}
// font korean (jmjeong@oopsla.snu.ac.kr)
if (FSzEqI(rgszArg[i], "-Fkm"))
{
fontType = fontKoreanHanme;
continue;
}
// font korean (jmjeong@oopsla.snu.ac.kr)
if (FSzEqI(rgszArg[i], "-Fkt"))
{
fontType = fontKoreanHantip;
continue;
}
// font cyrillic
if (FSzEqI(rgszArg[i], "-Fc"))
{
fontType = fontCyrillic;
continue;
}
// right to left?
if (FSzEqI(rgszArg[i], "-rtl"))
{
vfRTL = fTrue;
continue;
}
// LE32
if (FSzEqI(rgszArg[i], "-LE32"))
{
vfLE32 = fTrue;
continue;
}
#ifdef PALM_INTERNAL
// AppIcon68K
if (FSzEqI(rgszArg[i], "-AppIcon68K"))
{
vfAppIcon68K = fTrue;
continue;
}
if (FSzEqI(rgszArg[i], "-amdc"))
{
if (i++ == cArg)
ArgError();
szDllNameP = rgszArg[i];
vfAutoAmdc = fTrue;
continue;
}
#endif
// Output a 'ro' File
if (FSzEqI(rgszArg[i], "-ro"))
{
vfPrc = fTrue;
continue;
}
// place timestamp (POSIX standard) on .ro file
if (FSzEqI(rgszArg[i], "-ts"))
{
vfPrcTimeStamp = fTrue;
continue;
}
/*
* LDu 31-8-2001 : Ignore Include File In Header Files
*/
if (FSzEqI(rgszArg[i], "-noIFIH"))
{
#ifdef PALM_INTERNAL
vfIFIH = fFalse;
#else
vfIFIH = fTrue;
#endif
continue;
}
// Output filename
if (FSzEqI(rgszArg[i], "-o"))
{
if (i++ == cArg)
ArgError();
szOutputPath = rgszArg[i];
continue;
}
// name definition for prc output?
if (FSzEqI(rgszArg[i], "-name"))
{
if (i++ == cArg)
ArgError();
vfPrcName = rgszArg[i];
continue;
}
// creator definition for prc output?
if (FSzEqI(rgszArg[i], "-creator"))
{
if (i++ == cArg)
ArgError();
vfPrcCreator = rgszArg[i];
continue;
}
// type definition for prc output?
if (FSzEqI(rgszArg[i], "-type"))
{
if (i++ == cArg)
ArgError();
vfPrcType = 0;
vfPrcType = rgszArg[i];
continue;
}
// dependency tracking, no output files
if (FSzEqI(rgszArg[i], "-M"))
{
vfTrackDepends = fTrue;
vfInhibitOutput = fTrue;
continue;
}
// dependency tracking, compiler resources too
if (FSzEqI(rgszArg[i], "-MD"))
{
vfTrackDepends = fTrue;
continue;
}
if (FSzEqI(rgszArg[i], "--version"))
{
printf("%s\n%s", header, disclaimer);
exit(0);
}
if (FSzEqI(rgszArg[i], "--help"))
{
printf("%s\n%s\n%s", header, disclaimer, usage);
exit(0);
}
// unknown argument?
ArgError();
}
// display the (c) string
if (!vfQuiet)
printf("%s\n", header);
if ((cArg - i) < 1)
ArgError();
if ((!szLocaleP) && (vfStripNoLocRes))
{
ErrorLine
("no -Loc option and strip no localizable resource, PilRc have nothing to do.");
}
// determine the input path
szInputFile = rgszArg[i++];
// determine the ouput path
if (cArg != i)
szOutputPath = rgszArg[i++];
// else
// szOutputPath = ".";
#ifdef PALM_INTERNAL
// if output folder not exist create it
if (strstr(szOutputPath, ".prc") == NULL)
if ((_access(szOutputPath, 0)) == -1)
{
_mkdir(szOutputPath);
}
#endif
// last minute check? (extra stuff?)
if (cArg != i)
ArgError();
if (!vfQuiet)
{
if (vfLE32)
printf("Generating LE32 resources (ARM/NT) from '%s'.\n", szInputFile);
else
printf("Generating 68K resources from '%s'.\n", szInputFile);
}
ResTypeInit();
CbInit();
FreeRcpfile(ParseFile(szInputFile, szOutputPath, szResFile, szIncFile, fontType));
FreeAccessPathsList();
return 0;
}