6 * Portable Windows Library
8 * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25 * All Rights Reserved.
27 * Contributor(s): ______________________________________.
30 * Revision 1.34 2000/06/21 03:15:24 robertj
31 * Added ability to append resources to existing file.
33 * Revision 1.33 1999/10/29 12:01:43 robertj
34 * Fixed #ifdef conditional around the wrong way.
36 * Revision 1.32 1999/10/19 07:08:23 robertj
37 * Added #ifdef/#ifndef condition compile functionality
39 * Revision 1.31 1999/10/18 04:41:09 robertj
40 * Added decompile of .BMP and .ICO files and fixed ability to have 64x64 icons
42 * Revision 1.30 1998/11/22 09:29:50 craigs
43 * *** empty log message ***
45 * Revision 1.29 1998/11/22 08:28:26 robertj
46 * Changed output file so platform dependent file is .res.cxx so is compatible with Windows.
48 * Revision 1.28 1998/09/26 01:24:08 robertj
49 * Added open source license
51 * Revision 1.27 1998/09/26 00:37:45 robertj
52 * Fixed name space conflict with type Cursor.
54 * Revision 1.26 1998/09/14 13:45:26 robertj
55 * Allowed suppression of some warnings.
57 * Revision 1.25 1996/01/28 03:05:20 robertj
58 * Editor changes back fed into command line utility.
60 * Revision 1.24 1996/01/02 13:04:05 robertj
61 * Changed version number specs.
63 * Revision 1.23 1995/12/23 03:51:56 robertj
64 * New startup mechanism and version numbers.
66 * Revision 1.22 1995/12/10 12:12:01 robertj
67 * Changes to support graphical resource file editor.
69 * Revision 1.21 1995/10/14 15:19:11 robertj
70 * Fixed missing font size on font keyword.
71 * Changes required by move of standard buttons to PDialog.
73 * Revision 1.20 1995/08/24 12:47:35 robertj
74 * Removed redundant parent parameter for ConstructEnd().
75 * General updating to latest coding standard.
77 * Revision 1.18 1995/07/31 12:30:11 robertj
78 * Changed all generated resource IDs to be in the same "number space". This
79 * is to avoid problems with IDs being used for more than one type of resource
80 * eg a menu item and an image for a toolbar.
81 * Fixed the generated #line commands to include a relative path instead of an
84 * Revision 1.17 1995/04/02 09:28:13 robertj
85 * Added "balloon" help.
87 * Revision 1.16 1995/02/19 04:17:22 robertj
88 * Moved most inline code from header file to cxx file.
90 * Revision 1.15 1995/02/11 04:13:47 robertj
91 * Strange problem with variable "small" in MSVC 2.0.
93 * Revision 1.14 1995/01/27 11:25:40 robertj
94 * Added pattern resource.
96 * Revision 1.13 1995/01/14 06:27:22 robertj
97 * Fixed bug in data array allocation.
99 * Revision 1.12 1994/12/05 11:37:58 robertj
100 * Added #line to generated code.
102 * Revision 1.11 1994/10/30 11:47:43 robertj
103 * Changed mechanism for doing notification callback functions.
105 * Revision 1.10 1994/07/02 03:25:39 robertj
106 * Fixed bug in program return value.
108 * Revision 1.9 1994/06/25 12:05:01 robertj
109 * Unix synchronisation.
111 * Revision 1.8 1994/04/20 12:47:01 robertj
112 * *** empty log message ***
114 * Revision 1.7 1994/04/03 08:37:00 robertj
115 * *** empty log message ***
117 * Revision 1.6 1994/04/01 14:29:16 robertj
118 * New format PRC file
120 * Revision 1.5 1993/12/31 07:05:07 robertj
121 * Changed pixmap images for one pixel one number in PRC file.
123 * Revision 1.4 1993/07/16 12:53:12 robertj
124 * Added converted form of C literal string to resource objects.
125 * Fixed header comment character.
127 * Revision 1.3 1993/07/15 04:38:31 robertj
128 * Rationalised lex.h, parse.h and main.h out of existance.
130 * Revision 1.2 1993/07/14 01:57:48 robertj
131 * Assure have a gray scale clut if none explicitly defined.
133 * Revision 1.1 1993/07/03 06:00:47 robertj
136 * Revision 1.1 1993/06/24 19:23:17 craigs
146 extern void Decompile(PFile
& in
, PTextFile
& out
);
150 ///////////////////////////////////////////////////////////////////////////////
153 PDECLARE_CLASS(PwrcApp
, PProcess
)
155 PwrcApp() : PProcess("Equivalence", "PWRC", 1, 0, AlphaCode
, 22) { }
158 PTextFile prcfile
, resfile
, cxxfile
, hdrfile
;
162 PCREATE_PROCESS(PwrcApp
);
165 extern PString OutputExtension
;
166 extern PString CxxExtension
;
168 PString
InputExtension(".prc");
170 #if defined (YYDEBUG)
175 ///////////////////////////////////////////////////////////////////////////////
176 // Application class functions
181 PError
<< "Portable Windows Resource Compiler v" << GetVersion(TRUE
) << endl
182 << "Copyright (C) 1993 by Equivalence" << endl
<< endl
;
185 PArgList
& arguments
= GetArguments();
186 arguments
.Parse("?nhdyvwD:o:b:I:ag:");
188 SetTerminationValue(1);
190 // display help if requested
191 if (arguments
.GetCount() < 1 ||
192 arguments
.HasOption('?') || arguments
.HasOption('h')) {
193 PError
<< endl
<< "usage: " << GetName() << " -hdvni"
194 #if defined (YYDEBUG)
197 "[-D name[=integer]] [-o resfile] [ -b basename ] [-I path ] prcfile\n"
198 " -d: decompile resource\n"
199 #if defined (YYDEBUG)
200 " -y: enable parser debugging output\n"
203 " -w Do not show warnings\n"
204 " -D name Define symbol \"name\" to value (default 1)\n"
205 " -o file set output resource file name\n"
206 " -a append resources to output file\n"
207 " -b base set base name of .cxx and .h files\n"
208 " -I path set include file path\n"
209 " -n suppress output of #includes in header file\n"
210 " -i decompile with resource ids\n"
211 " -g gui set GUI variant (xlib,motif)\n"
212 " -h or -? display help\n";
217 #if defined (YYDEBUG)
218 if (arguments
.HasOption('y')) // enable yacc debugging
222 if (arguments
.HasOption('I'))
223 IncludePath
= arguments
.GetOptionString('I').Tokenise(';', FALSE
);
225 PConfig
env(PConfig::Environment
);
226 IncludePath
= env
.GetString("INCLUDE").Tokenise(';', FALSE
);
229 PFilePath path
= arguments
[0];
230 if (path
.GetType().IsEmpty())
231 path
+= (arguments
.HasOption('d') ? OutputExtension
: InputExtension
);
233 // attempt to open the input file
234 if (!prcfile
.Open(path
, PFile::ReadOnly
)) {
235 PError
<< GetName() << ": cannot open \""
236 << prcfile
.GetFilePath() << "\" :" << prcfile
.GetErrorText() << endl
;
241 if (arguments
.HasOption('o'))
242 out_path
= arguments
.GetOptionString('o');
244 out_path
= path
.GetVolume() + path
.GetPath() + path
.GetTitle() +
245 (arguments
.HasOption('d') ? InputExtension
: OutputExtension
);
246 if (out_path
== prcfile
.GetFilePath()) {
247 PError
<< GetName() << ": input and output file are identical" << endl
;
251 BOOL appendResource
= arguments
.HasOption('a');
252 if (!resfile
.Open(out_path
, PFile::WriteOnly
,
253 PFile::Create
|(appendResource
? 0 : PFile::Truncate
))) {
254 PError
<< GetName() << ": cannot create \""
255 << resfile
.GetFilePath() << "\" :" << resfile
.GetErrorText() << endl
;
260 resfile
.seekp(0, ios::end
);
262 if (arguments
.HasOption('d')) { // Are decompiling resource file
263 if (arguments
.HasOption('v'))
264 cout
<< "Input file : " << prcfile
.GetFilePath() << endl
265 << "Resource file: " << resfile
.GetFilePath() << endl
;
267 Decompile(prcfile
, resfile
);
268 SetTerminationValue(0);
272 // get the base name, if specified
273 if (arguments
.HasOption('b')) {
274 path
= arguments
.GetOptionString('b');
275 if (!path
.GetType().IsEmpty()) {
276 PError
<< GetName() << ": cannot specify extension on base name" << endl
;
281 path
= path
.GetVolume() + path
.GetPath() + path
.GetTitle();
283 if (!cxxfile
.Open(path
+ CxxExtension
, PFile::WriteOnly
)) {
284 PError
<< GetName() << ": cannot create \""
285 << cxxfile
.GetFilePath() << "\" :" << cxxfile
.GetErrorText() << endl
;
289 if (!hdrfile
.Open(path
+ ".h", PFile::WriteOnly
)) {
290 PError
<< GetName() << ": cannot create \""
291 << hdrfile
.GetFilePath() << "\" :" << hdrfile
.GetErrorText() << endl
;
295 if (arguments
.HasOption('v')) {
296 cout
<< "Input file : " << prcfile
.GetFilePath() << endl
297 << "Resource file: " << resfile
.GetFilePath();
299 cout
<< " (appending)";
301 << "Source file : " << cxxfile
.GetFilePath() << endl
302 << "Header file : " << hdrfile
.GetFilePath() << endl
;
306 ResourceFile
res(prcfile
, arguments
.HasOption('w'), arguments
.GetOptionString('D'));
308 // only continue with the build if we have no errors
309 if (res
.Fatals() == 0) {
310 res
.OutputCode(hdrfile
.GetFilePath(),
311 hdrfile
, cxxfile
, arguments
.HasOption('n'));
312 res
.Backend(resfile
);
315 // display number of errors and warnings
316 SetTerminationValue(0);
317 if (res
.Warnings() == 0 && res
.Fatals() == 0)
318 PError
<< "Portable resource compilation successful." << endl
;
320 PError
<< res
.Warnings() << " warnings(s)" << endl
;
321 PError
<< res
.Fatals() << " error(s)" << endl
;
322 if (res
.Fatals() != 0) {
323 SetTerminationValue(2);
333 /////////////////////////////////////////
335 // key code structure
338 PObject
* PKeyCode::Clone() const
340 return new PKeyCode(value
, modifiers
);
344 PObject::Comparison
PKeyCode::Compare(const PObject
& obj
) const
346 const PKeyCode
& other
= (const PKeyCode
&)obj
;
347 if (value
== other
.value
&& modifiers
== other
.modifiers
)
349 return value
< other
.value
? LessThan
: GreaterThan
;
353 PKeyCode::PKeyCode(Value theValue
, int theMods
)
360 PKeyCode::Value
PKeyCode::GetValue() const
366 int PKeyCode::GetModifiers() const
372 BOOL
PKeyCode::IsModifier(int modmask
) const
374 return (modifiers
&modmask
) != 0;
378 void StringResource::EditResource(MainWindow
*, ResourceFile
*) { }
379 void MenuBar::EditResource(MainWindow
*, ResourceFile
*) { }
380 void Layout::EditResource(MainWindow
*, ResourceFile
*) { }
381 void Icon::EditResource(MainWindow
*, ResourceFile
*) { }
382 void CursorResource::EditResource(MainWindow
*, ResourceFile
*) { }
383 void Pattern::EditResource(MainWindow
*, ResourceFile
*) { }
384 void Image::EditResource(MainWindow
*, ResourceFile
*) { }
385 void DataResource::EditResource(MainWindow
*, ResourceFile
*) { }