main.cxx
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:12k
- /*
- * main.cxx
- *
- * Resource compiler
- *
- * Portable Windows Library
- *
- * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Portable Windows Library.
- *
- * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
- *
- * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
- * All Rights Reserved.
- *
- * Contributor(s): ______________________________________.
- *
- * $Log: main.cxx,v $
- * Revision 1.34 2000/06/21 03:15:24 robertj
- * Added ability to append resources to existing file.
- *
- * Revision 1.33 1999/10/29 12:01:43 robertj
- * Fixed #ifdef conditional around the wrong way.
- *
- * Revision 1.32 1999/10/19 07:08:23 robertj
- * Added #ifdef/#ifndef condition compile functionality
- *
- * Revision 1.31 1999/10/18 04:41:09 robertj
- * Added decompile of .BMP and .ICO files and fixed ability to have 64x64 icons
- *
- * Revision 1.30 1998/11/22 09:29:50 craigs
- * *** empty log message ***
- *
- * Revision 1.29 1998/11/22 08:28:26 robertj
- * Changed output file so platform dependent file is .res.cxx so is compatible with Windows.
- *
- * Revision 1.28 1998/09/26 01:24:08 robertj
- * Added open source license
- *
- * Revision 1.27 1998/09/26 00:37:45 robertj
- * Fixed name space conflict with type Cursor.
- *
- * Revision 1.26 1998/09/14 13:45:26 robertj
- * Allowed suppression of some warnings.
- *
- * Revision 1.25 1996/01/28 03:05:20 robertj
- * Editor changes back fed into command line utility.
- *
- * Revision 1.24 1996/01/02 13:04:05 robertj
- * Changed version number specs.
- *
- * Revision 1.23 1995/12/23 03:51:56 robertj
- * New startup mechanism and version numbers.
- *
- * Revision 1.22 1995/12/10 12:12:01 robertj
- * Changes to support graphical resource file editor.
- *
- * Revision 1.21 1995/10/14 15:19:11 robertj
- * Fixed missing font size on font keyword.
- * Changes required by move of standard buttons to PDialog.
- *
- * Revision 1.20 1995/08/24 12:47:35 robertj
- * Removed redundant parent parameter for ConstructEnd().
- * General updating to latest coding standard.
- *
- * Revision 1.18 1995/07/31 12:30:11 robertj
- * Changed all generated resource IDs to be in the same "number space". This
- * is to avoid problems with IDs being used for more than one type of resource
- * eg a menu item and an image for a toolbar.
- * Fixed the generated #line commands to include a relative path instead of an
- * absolute one.
- *
- * Revision 1.17 1995/04/02 09:28:13 robertj
- * Added "balloon" help.
- *
- * Revision 1.16 1995/02/19 04:17:22 robertj
- * Moved most inline code from header file to cxx file.
- *
- * Revision 1.15 1995/02/11 04:13:47 robertj
- * Strange problem with variable "small" in MSVC 2.0.
- *
- * Revision 1.14 1995/01/27 11:25:40 robertj
- * Added pattern resource.
- *
- * Revision 1.13 1995/01/14 06:27:22 robertj
- * Fixed bug in data array allocation.
- *
- * Revision 1.12 1994/12/05 11:37:58 robertj
- * Added #line to generated code.
- *
- * Revision 1.11 1994/10/30 11:47:43 robertj
- * Changed mechanism for doing notification callback functions.
- *
- * Revision 1.10 1994/07/02 03:25:39 robertj
- * Fixed bug in program return value.
- *
- * Revision 1.9 1994/06/25 12:05:01 robertj
- * Unix synchronisation.
- *
- * Revision 1.8 1994/04/20 12:47:01 robertj
- * *** empty log message ***
- *
- * Revision 1.7 1994/04/03 08:37:00 robertj
- * *** empty log message ***
- *
- * Revision 1.6 1994/04/01 14:29:16 robertj
- * New format PRC file
- *
- * Revision 1.5 1993/12/31 07:05:07 robertj
- * Changed pixmap images for one pixel one number in PRC file.
- *
- * Revision 1.4 1993/07/16 12:53:12 robertj
- * Added converted form of C literal string to resource objects.
- * Fixed header comment character.
- *
- * Revision 1.3 1993/07/15 04:38:31 robertj
- * Rationalised lex.h, parse.h and main.h out of existance.
- *
- * Revision 1.2 1993/07/14 01:57:48 robertj
- * Assure have a gray scale clut if none explicitly defined.
- *
- * Revision 1.1 1993/07/03 06:00:47 robertj
- * Initial revision
- *
- * Revision 1.1 1993/06/24 19:23:17 craigs
- * Initial revision
- *
- */
- #include <ptlib.h>
- #include "pwrc.h"
- extern void Decompile(PFile & in, PTextFile & out);
- ///////////////////////////////////////////////////////////////////////////////
- // Application class
- PDECLARE_CLASS(PwrcApp, PProcess)
- public:
- PwrcApp() : PProcess("Equivalence", "PWRC", 1, 0, AlphaCode, 22) { }
- private:
- virtual void Main();
- PTextFile prcfile, resfile, cxxfile, hdrfile;
- };
- PCREATE_PROCESS(PwrcApp);
- extern PString OutputExtension;
- extern PString CxxExtension;
- PString InputExtension(".prc");
- #if defined (YYDEBUG)
- extern int yydebug;
- #endif
- ///////////////////////////////////////////////////////////////////////////////
- // Application class functions
- void PwrcApp::Main()
- {
- // print the title
- PError << "Portable Windows Resource Compiler v" << GetVersion(TRUE) << endl
- << "Copyright (C) 1993 by Equivalence" << endl << endl;
- // parse the options
- PArgList & arguments = GetArguments();
- arguments.Parse("?nhdyvwD:o:b:I:ag:");
- SetTerminationValue(1);
- // display help if requested
- if (arguments.GetCount() < 1 ||
- arguments.HasOption('?') || arguments.HasOption('h')) {
- PError << endl << "usage: " << GetName() << " -hdvni"
- #if defined (YYDEBUG)
- "y"
- #endif
- "[-D name[=integer]] [-o resfile] [ -b basename ] [-I path ] prcfilen"
- " -d: decompile resourcen"
- #if defined (YYDEBUG)
- " -y: enable parser debugging outputn"
- #endif
- " -v verbosen"
- " -w Do not show warningsn"
- " -D name Define symbol "name" to value (default 1)n"
- " -o file set output resource file namen"
- " -a append resources to output filen"
- " -b base set base name of .cxx and .h filesn"
- " -I path set include file pathn"
- " -n suppress output of #includes in header filen"
- " -i decompile with resource idsn"
- " -g gui set GUI variant (xlib,motif)n"
- " -h or -? display helpn";
- return;
- }
- #if defined (YYDEBUG)
- if (arguments.HasOption('y')) // enable yacc debugging
- yydebug = 1;
- #endif
- if (arguments.HasOption('I'))
- IncludePath = arguments.GetOptionString('I').Tokenise(';', FALSE);
- else {
- PConfig env(PConfig::Environment);
- IncludePath = env.GetString("INCLUDE").Tokenise(';', FALSE);
- }
- PFilePath path = arguments[0];
- if (path.GetType().IsEmpty())
- path += (arguments.HasOption('d') ? OutputExtension : InputExtension);
- // attempt to open the input file
- if (!prcfile.Open(path, PFile::ReadOnly)) {
- PError << GetName() << ": cannot open ""
- << prcfile.GetFilePath() << "" :" << prcfile.GetErrorText() << endl;
- return;
- }
- PFilePath out_path;
- if (arguments.HasOption('o'))
- out_path = arguments.GetOptionString('o');
- else
- out_path = path.GetVolume() + path.GetPath() + path.GetTitle() +
- (arguments.HasOption('d') ? InputExtension : OutputExtension);
- if (out_path == prcfile.GetFilePath()) {
- PError << GetName() << ": input and output file are identical" << endl;
- return;
- }
- BOOL appendResource = arguments.HasOption('a');
- if (!resfile.Open(out_path, PFile::WriteOnly,
- PFile::Create|(appendResource ? 0 : PFile::Truncate))) {
- PError << GetName() << ": cannot create ""
- << resfile.GetFilePath() << "" :" << resfile.GetErrorText() << endl;
- return;
- }
- if (appendResource)
- resfile.seekp(0, ios::end);
- if (arguments.HasOption('d')) { // Are decompiling resource file
- if (arguments.HasOption('v'))
- cout << "Input file : " << prcfile.GetFilePath() << endl
- << "Resource file: " << resfile.GetFilePath() << endl;
- Decompile(prcfile, resfile);
- SetTerminationValue(0);
- return;
- }
- // get the base name, if specified
- if (arguments.HasOption('b')) {
- path = arguments.GetOptionString('b');
- if (!path.GetType().IsEmpty()) {
- PError << GetName() << ": cannot specify extension on base name" << endl;
- return;
- }
- }
- else
- path = path.GetVolume() + path.GetPath() + path.GetTitle();
- if (!cxxfile.Open(path + CxxExtension, PFile::WriteOnly)) {
- PError << GetName() << ": cannot create ""
- << cxxfile.GetFilePath() << "" :" << cxxfile.GetErrorText() << endl;
- return;
- }
- if (!hdrfile.Open(path + ".h", PFile::WriteOnly)) {
- PError << GetName() << ": cannot create ""
- << hdrfile.GetFilePath() << "" :" << hdrfile.GetErrorText() << endl;
- return;
- }
- if (arguments.HasOption('v')) {
- cout << "Input file : " << prcfile.GetFilePath() << endl
- << "Resource file: " << resfile.GetFilePath();
- if (appendResource)
- cout << " (appending)";
- cout << endl
- << "Source file : " << cxxfile.GetFilePath() << endl
- << "Header file : " << hdrfile.GetFilePath() << endl;
- }
- // parse the file
- ResourceFile res(prcfile, arguments.HasOption('w'), arguments.GetOptionString('D'));
- // only continue with the build if we have no errors
- if (res.Fatals() == 0) {
- res.OutputCode(hdrfile.GetFilePath(),
- hdrfile, cxxfile, arguments.HasOption('n'));
- res.Backend(resfile);
- }
- // display number of errors and warnings
- SetTerminationValue(0);
- if (res.Warnings() == 0 && res.Fatals() == 0)
- PError << "Portable resource compilation successful." << endl;
- else {
- PError << res.Warnings() << " warnings(s)" << endl;
- PError << res.Fatals() << " error(s)" << endl;
- if (res.Fatals() != 0) {
- SetTerminationValue(2);
- resfile.Remove();
- cxxfile.Remove();
- hdrfile.Remove();
- }
- }
- }
- /////////////////////////////////////////
- //
- // key code structure
- //
- PObject * PKeyCode::Clone() const
- {
- return new PKeyCode(value, modifiers);
- }
- PObject::Comparison PKeyCode::Compare(const PObject & obj) const
- {
- const PKeyCode & other = (const PKeyCode &)obj;
- if (value == other.value && modifiers == other.modifiers)
- return EqualTo;
- return value < other.value ? LessThan : GreaterThan;
- }
- PKeyCode::PKeyCode(Value theValue, int theMods)
- {
- value = theValue;
- modifiers = theMods;
- }
- PKeyCode::Value PKeyCode::GetValue() const
- {
- return value;
- }
- int PKeyCode::GetModifiers() const
- {
- return modifiers;
- }
- BOOL PKeyCode::IsModifier(int modmask) const
- {
- return (modifiers&modmask) != 0;
- }
- void StringResource::EditResource(MainWindow *, ResourceFile *) { }
- void MenuBar::EditResource(MainWindow *, ResourceFile *) { }
- void Layout::EditResource(MainWindow *, ResourceFile *) { }
- void Icon::EditResource(MainWindow *, ResourceFile *) { }
- void CursorResource::EditResource(MainWindow *, ResourceFile *) { }
- void Pattern::EditResource(MainWindow *, ResourceFile *) { }
- void Image::EditResource(MainWindow *, ResourceFile *) { }
- void DataResource::EditResource(MainWindow *, ResourceFile *) { }
- // MAIN.CXX