2000-07-25 14:47:21 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wxrc.cpp
|
|
|
|
// Purpose: XML resource compiler
|
|
|
|
// Author: Vaclav Slavik
|
|
|
|
// Created: 2000/03/05
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2000 Vaclav Slavik
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// for all others, include the necessary headers (this file is usually all you
|
|
|
|
// need because it includes almost all "standard" wxWindows headers
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/cmdline.h"
|
2001-06-09 18:18:45 -04:00
|
|
|
#include "wx/xrc/xml.h"
|
2000-07-25 14:47:21 -04:00
|
|
|
#include "wx/ffile.h"
|
2000-08-11 15:07:43 -04:00
|
|
|
#include "wx/wfstream.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-07-25 14:47:21 -04:00
|
|
|
|
2000-07-26 08:40:49 -04:00
|
|
|
/*
|
2000-07-25 14:47:21 -04:00
|
|
|
#if wxUSE_GUI
|
|
|
|
#error "You must compile the resource compiler with wxBase!"
|
|
|
|
#endif
|
2000-07-26 08:40:49 -04:00
|
|
|
*/
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
class XmlResApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
2000-07-26 08:40:49 -04:00
|
|
|
|
|
|
|
#if wxUSE_GUI
|
|
|
|
bool OnInit();
|
|
|
|
#else
|
2000-07-25 14:47:21 -04:00
|
|
|
virtual int OnRun();
|
2000-07-26 08:40:49 -04:00
|
|
|
#endif
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void ParseParams(const wxCmdLineParser& cmdline);
|
|
|
|
void CompileRes();
|
|
|
|
wxArrayString PrepareTempFiles();
|
2000-08-11 15:07:43 -04:00
|
|
|
void FindFilesInXML(wxXmlNode *node, wxArrayString& flist, const wxString& inputPath);
|
|
|
|
|
2002-06-22 19:33:12 -04:00
|
|
|
wxString GetInternalFileName(const wxString& name, const wxArrayString& flist);
|
2000-07-25 14:47:21 -04:00
|
|
|
void DeleteTempFiles(const wxArrayString& flist);
|
|
|
|
void MakePackageZIP(const wxArrayString& flist);
|
|
|
|
void MakePackageCPP(const wxArrayString& flist);
|
2000-11-24 12:20:20 -05:00
|
|
|
|
|
|
|
void OutputGettext();
|
|
|
|
wxArrayString FindStrings();
|
|
|
|
wxArrayString FindStrings(wxXmlNode *node);
|
2000-07-25 14:47:21 -04:00
|
|
|
|
2002-02-02 18:17:38 -05:00
|
|
|
bool flagVerbose, flagCPP, flagGettext;
|
2000-07-25 14:47:21 -04:00
|
|
|
wxString parOutput, parFuncname, parOutputPath;
|
|
|
|
wxArrayString parFiles;
|
|
|
|
int retCode;
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_APP(XmlResApp)
|
|
|
|
|
2000-07-26 08:40:49 -04:00
|
|
|
#if wxUSE_GUI
|
|
|
|
bool XmlResApp::OnInit()
|
|
|
|
#else
|
2000-07-25 14:47:21 -04:00
|
|
|
int XmlResApp::OnRun()
|
2000-07-26 08:40:49 -04:00
|
|
|
#endif
|
2000-07-25 14:47:21 -04:00
|
|
|
{
|
|
|
|
static const wxCmdLineEntryDesc cmdLineDesc[] =
|
|
|
|
{
|
2002-07-02 18:06:00 -04:00
|
|
|
{ wxCMD_LINE_SWITCH, "h", "help", "show help message",
|
|
|
|
wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
|
2000-07-25 14:47:21 -04:00
|
|
|
{ wxCMD_LINE_SWITCH, "v", "verbose", "be verbose" },
|
|
|
|
{ wxCMD_LINE_SWITCH, "c", "cpp-code", "output C++ source rather than .rsc file" },
|
2002-01-24 16:14:52 -05:00
|
|
|
{ wxCMD_LINE_SWITCH, "g", "gettext", "output list of translatable strings (to stdout or file if -o used)" },
|
2000-07-25 14:47:21 -04:00
|
|
|
{ wxCMD_LINE_OPTION, "n", "function", "C++ function name (with -c) [InitXmlResource]" },
|
2000-10-07 17:56:37 -04:00
|
|
|
{ wxCMD_LINE_OPTION, "o", "output", "output file [resource.xrs/cpp]" },
|
2002-07-02 18:06:00 -04:00
|
|
|
#if 0 // not yet implemented
|
2000-07-31 18:03:55 -04:00
|
|
|
{ wxCMD_LINE_OPTION, "l", "list-of-handlers", "output list of neccessary handlers to this file" },
|
2002-07-02 18:06:00 -04:00
|
|
|
#endif
|
2000-11-24 12:20:20 -05:00
|
|
|
{ wxCMD_LINE_PARAM, NULL, NULL, "input file(s)",
|
2002-07-02 18:06:00 -04:00
|
|
|
wxCMD_LINE_VAL_STRING,
|
|
|
|
wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_OPTION_MANDATORY },
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
{ wxCMD_LINE_NONE }
|
|
|
|
};
|
|
|
|
|
|
|
|
wxCmdLineParser parser(cmdLineDesc, argc, argv);
|
|
|
|
|
|
|
|
switch (parser.Parse())
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
retCode = 0;
|
|
|
|
ParseParams(parser);
|
2000-11-24 12:20:20 -05:00
|
|
|
if (flagGettext)
|
|
|
|
OutputGettext();
|
|
|
|
else
|
|
|
|
CompileRes();
|
2000-07-26 08:40:49 -04:00
|
|
|
#if wxUSE_GUI
|
|
|
|
return FALSE;
|
|
|
|
#else
|
2000-07-25 14:47:21 -04:00
|
|
|
return retCode;
|
2000-07-26 08:40:49 -04:00
|
|
|
#endif
|
2000-07-25 14:47:21 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-07-26 08:40:49 -04:00
|
|
|
#if wxUSE_GUI
|
|
|
|
return FALSE;
|
|
|
|
#else
|
2000-07-25 14:47:21 -04:00
|
|
|
return 1;
|
2000-07-26 08:40:49 -04:00
|
|
|
#endif
|
2000-07-25 14:47:21 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void XmlResApp::ParseParams(const wxCmdLineParser& cmdline)
|
|
|
|
{
|
2000-11-24 12:20:20 -05:00
|
|
|
flagGettext = cmdline.Found("g");
|
2000-07-25 14:47:21 -04:00
|
|
|
flagVerbose = cmdline.Found("v");
|
|
|
|
flagCPP = cmdline.Found("c");
|
|
|
|
|
|
|
|
if (!cmdline.Found("o", &parOutput))
|
2000-11-24 12:20:20 -05:00
|
|
|
{
|
|
|
|
if (flagGettext)
|
|
|
|
parOutput = wxEmptyString;
|
|
|
|
else
|
|
|
|
parOutput = flagCPP ? "resource.cpp" : "resource.xrs";
|
|
|
|
}
|
2000-07-25 14:47:21 -04:00
|
|
|
parOutputPath = wxPathOnly(parOutput);
|
|
|
|
if (!parOutputPath) parOutputPath = ".";
|
|
|
|
|
|
|
|
if (!cmdline.Found("n", &parFuncname))
|
|
|
|
parFuncname = "InitXmlResource";
|
|
|
|
|
|
|
|
for (size_t i = 0; i < cmdline.GetParamCount(); i++)
|
|
|
|
parFiles.Add(cmdline.GetParam(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void XmlResApp::CompileRes()
|
|
|
|
{
|
|
|
|
wxArrayString files = PrepareTempFiles();
|
|
|
|
|
|
|
|
wxRemoveFile(parOutput);
|
|
|
|
|
|
|
|
if (!retCode)
|
|
|
|
{
|
|
|
|
if (flagCPP)
|
|
|
|
MakePackageCPP(files);
|
|
|
|
else
|
|
|
|
MakePackageZIP(files);
|
|
|
|
}
|
|
|
|
|
|
|
|
DeleteTempFiles(files);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-22 19:33:12 -04:00
|
|
|
wxString XmlResApp::GetInternalFileName(const wxString& name, const wxArrayString& flist)
|
|
|
|
{
|
|
|
|
wxString name2 = name;
|
|
|
|
name2.Replace(":", "_");
|
|
|
|
name2.Replace("/", "_");
|
|
|
|
name2.Replace("\\", "_");
|
|
|
|
name2.Replace("*", "_");
|
|
|
|
name2.Replace("?", "_");
|
|
|
|
|
|
|
|
wxString s = wxFileNameFromPath(parOutput) + "$" + name2;
|
|
|
|
|
|
|
|
if (wxFileExists(s) && flist.Index(s) == wxNOT_FOUND)
|
|
|
|
{
|
|
|
|
for (int i = 0;; i++)
|
|
|
|
{
|
|
|
|
s.Printf(wxFileNameFromPath(parOutput) + "$%03i-" + name2, i);
|
|
|
|
if (!wxFileExists(s) || flist.Index(s) != wxNOT_FOUND)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
wxArrayString XmlResApp::PrepareTempFiles()
|
|
|
|
{
|
|
|
|
wxArrayString flist;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < parFiles.Count(); i++)
|
|
|
|
{
|
|
|
|
if (flagVerbose)
|
|
|
|
wxPrintf("processing " + parFiles[i] + "...\n");
|
|
|
|
|
|
|
|
wxXmlDocument doc;
|
|
|
|
|
|
|
|
if (!doc.Load(parFiles[i]))
|
|
|
|
{
|
|
|
|
wxLogError("Error parsing file " + parFiles[i]);
|
|
|
|
retCode = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2000-08-11 15:07:43 -04:00
|
|
|
wxString name, ext, path;
|
|
|
|
wxSplitPath(parFiles[i], &path, &name, &ext);
|
|
|
|
|
|
|
|
FindFilesInXML(doc.GetRoot(), flist, path);
|
2000-07-25 14:47:21 -04:00
|
|
|
|
2002-06-22 19:33:12 -04:00
|
|
|
wxString internalName = GetInternalFileName(parFiles[i], flist);
|
|
|
|
|
|
|
|
doc.Save(parOutputPath + "/" + internalName);
|
|
|
|
flist.Add(internalName);
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return flist;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-08-11 15:07:43 -04:00
|
|
|
// find all files mentioned in structure, e.g. <bitmap>filename</bitmap>
|
|
|
|
void XmlResApp::FindFilesInXML(wxXmlNode *node, wxArrayString& flist, const wxString& inputPath)
|
|
|
|
{
|
|
|
|
wxXmlNode *n = node;
|
|
|
|
if (n == NULL) return;
|
|
|
|
n = n->GetChildren();
|
|
|
|
|
|
|
|
while (n)
|
|
|
|
{
|
|
|
|
if ((node->GetType() == wxXML_ELEMENT_NODE) &&
|
|
|
|
// parent is an element, i.e. has subnodes...
|
|
|
|
(n->GetType() == wxXML_TEXT_NODE ||
|
|
|
|
n->GetType() == wxXML_CDATA_SECTION_NODE) &&
|
|
|
|
// ...it is textnode...
|
2002-03-09 11:35:00 -05:00
|
|
|
((node/*not n!*/->GetName() == "bitmap") ||
|
|
|
|
(node/*not n!*/->GetName() == "url")))
|
2000-08-11 15:07:43 -04:00
|
|
|
// ...and known to contain filename
|
|
|
|
{
|
|
|
|
wxString fullname;
|
2002-07-16 12:58:02 -04:00
|
|
|
if (wxIsAbsolutePath(n->GetContent()) || inputPath == "") fullname = n->GetContent();
|
2000-08-11 15:07:43 -04:00
|
|
|
else fullname = inputPath + "/" + n->GetContent();
|
2002-06-22 19:33:12 -04:00
|
|
|
|
|
|
|
if (flagVerbose)
|
|
|
|
wxPrintf("adding " + fullname + "...\n");
|
2000-08-11 15:07:43 -04:00
|
|
|
|
2002-06-22 19:33:12 -04:00
|
|
|
wxString filename = GetInternalFileName(n->GetContent(), flist);
|
2000-08-11 15:07:43 -04:00
|
|
|
n->SetContent(filename);
|
|
|
|
|
|
|
|
flist.Add(filename);
|
|
|
|
|
|
|
|
wxFileInputStream sin(fullname);
|
|
|
|
wxFileOutputStream sout(parOutputPath + "/" + filename);
|
|
|
|
sin.Read(sout); // copy the stream
|
|
|
|
}
|
|
|
|
|
|
|
|
// subnodes:
|
|
|
|
if (n->GetType() == wxXML_ELEMENT_NODE)
|
|
|
|
FindFilesInXML(n, flist, inputPath);
|
|
|
|
|
|
|
|
n = n->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-07-25 14:47:21 -04:00
|
|
|
void XmlResApp::DeleteTempFiles(const wxArrayString& flist)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < flist.Count(); i++)
|
|
|
|
wxRemoveFile(parOutputPath + "/" + flist[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void XmlResApp::MakePackageZIP(const wxArrayString& flist)
|
|
|
|
{
|
|
|
|
wxString files;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < flist.Count(); i++)
|
|
|
|
files += flist[i] + " ";
|
|
|
|
files.RemoveLast();
|
|
|
|
|
|
|
|
if (flagVerbose)
|
|
|
|
wxPrintf("compressing " + parOutput + "...\n");
|
|
|
|
|
|
|
|
if (wxExecute("zip -9 -j " + wxString(flagVerbose ? "" : "-q ") +
|
|
|
|
parOutput + " " + files, TRUE) == -1)
|
|
|
|
{
|
|
|
|
wxLogError("Unable to execute zip program. Make sure it is in the path.");
|
|
|
|
wxLogError("You can download it at http://www.cdrom.com/pub/infozip/");
|
|
|
|
retCode = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static wxString FileToCppArray(wxString filename, int num)
|
|
|
|
{
|
|
|
|
wxString output;
|
|
|
|
wxString tmp;
|
2000-08-11 15:07:43 -04:00
|
|
|
wxString snum;
|
2000-07-25 14:47:21 -04:00
|
|
|
wxFFile file(filename, "rb");
|
|
|
|
size_t lng = file.Length();
|
|
|
|
|
|
|
|
snum.Printf("%i", num);
|
|
|
|
output.Printf("static size_t xml_res_size_" + snum + " = %i;\n", lng);
|
2000-10-07 17:56:37 -04:00
|
|
|
output += "static unsigned char xml_res_file_" + snum + "[] = {\n";
|
|
|
|
// we cannot use string literals because MSVC is dumb wannabe compiler
|
|
|
|
// with arbitrary limitation to 2048 strings :(
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
unsigned char *buffer = new unsigned char[lng];
|
|
|
|
file.Read(buffer, lng);
|
|
|
|
|
2000-08-11 15:07:43 -04:00
|
|
|
for (size_t i = 0, linelng = 0; i < lng; i++)
|
2000-07-25 14:47:21 -04:00
|
|
|
{
|
2000-10-07 17:56:37 -04:00
|
|
|
tmp.Printf("%i", buffer[i]);
|
|
|
|
if (i != 0) output << ',';
|
|
|
|
if (linelng > 70)
|
2000-08-11 15:07:43 -04:00
|
|
|
{
|
|
|
|
linelng = 0;
|
2000-10-07 17:56:37 -04:00
|
|
|
output << "\n";
|
2000-08-11 15:07:43 -04:00
|
|
|
}
|
2000-10-07 17:56:37 -04:00
|
|
|
output << tmp;
|
|
|
|
linelng += tmp.Length()+1;
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
delete[] buffer;
|
|
|
|
|
2000-10-07 17:56:37 -04:00
|
|
|
output += "};\n\n";
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XmlResApp::MakePackageCPP(const wxArrayString& flist)
|
|
|
|
{
|
|
|
|
wxFFile file(parOutput, "wt");
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (flagVerbose)
|
|
|
|
wxPrintf("creating C++ source file " + parOutput + "...\n");
|
|
|
|
|
|
|
|
file.Write("\
|
2002-06-22 19:33:12 -04:00
|
|
|
#include <wx/wxprec.h>\n\
|
2000-07-25 14:47:21 -04:00
|
|
|
\n\
|
|
|
|
#ifdef __BORLANDC__\n\
|
|
|
|
#pragma hdrstop\n\
|
|
|
|
#endif\n\
|
|
|
|
\n\
|
|
|
|
#ifndef WX_PRECOMP\n\
|
2002-06-22 19:33:12 -04:00
|
|
|
#include <wx/wx.h>\n\
|
2000-07-25 14:47:21 -04:00
|
|
|
#endif\n\
|
|
|
|
\
|
2002-06-22 19:33:12 -04:00
|
|
|
#include <wx/filesys.h>\n\
|
|
|
|
#include <wx/fs_mem.h>\n\
|
|
|
|
#include <wx/xrc/xmlres.h>\n\
|
|
|
|
#include <wx/xrc/xh_all.h>\n\
|
2000-07-25 14:47:21 -04:00
|
|
|
\n");
|
|
|
|
|
|
|
|
for (i = 0; i < flist.Count(); i++)
|
|
|
|
file.Write(FileToCppArray(flist[i], i));
|
|
|
|
|
|
|
|
file.Write("\
|
|
|
|
void " + parFuncname + "()\n\
|
|
|
|
{\n\
|
|
|
|
\n\
|
|
|
|
// Check for memory FS. If not present, load the handler:\n\
|
|
|
|
{\n\
|
2002-06-22 19:33:12 -04:00
|
|
|
wxMemoryFSHandler::AddFile(\"XRC_resource/dummy_file\", \"dummy one\");\n\
|
2000-07-25 14:47:21 -04:00
|
|
|
wxFileSystem fsys;\n\
|
2002-06-22 19:33:12 -04:00
|
|
|
wxFSFile *f = fsys.OpenFile(\"memory:XRC_resource/dummy_file\");\n\
|
|
|
|
wxMemoryFSHandler::RemoveFile(\"XRC_resource/dummy_file\");\n\
|
2000-07-25 14:47:21 -04:00
|
|
|
if (f) delete f;\n\
|
|
|
|
else wxFileSystem::AddHandler(new wxMemoryFSHandler);\n\
|
|
|
|
}\n\
|
|
|
|
\n");
|
|
|
|
|
|
|
|
for (i = 0; i < flist.Count(); i++)
|
|
|
|
{
|
|
|
|
wxString s;
|
2002-06-22 19:33:12 -04:00
|
|
|
s.Printf(" wxMemoryFSHandler::AddFile(\"XRC_resource/" + flist[i] +
|
2000-08-11 15:07:43 -04:00
|
|
|
"\", xml_res_file_%i, xml_res_size_%i);\n", i, i);
|
2000-07-25 14:47:21 -04:00
|
|
|
file.Write(s);
|
|
|
|
}
|
2000-08-11 15:07:43 -04:00
|
|
|
|
|
|
|
for (i = 0; i < parFiles.Count(); i++)
|
|
|
|
{
|
2002-06-22 19:33:12 -04:00
|
|
|
file.Write(" wxXmlResource::Get()->Load(\"memory:XRC_resource/" +
|
|
|
|
GetInternalFileName(parFiles[i], flist) + "\");\n");
|
2000-08-11 15:07:43 -04:00
|
|
|
}
|
2000-07-25 14:47:21 -04:00
|
|
|
|
2002-01-24 16:14:52 -05:00
|
|
|
file.Write("}\n");
|
2000-07-25 14:47:21 -04:00
|
|
|
|
2000-08-11 15:07:43 -04:00
|
|
|
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
2000-11-24 12:20:20 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void XmlResApp::OutputGettext()
|
|
|
|
{
|
|
|
|
wxArrayString str = FindStrings();
|
|
|
|
|
|
|
|
wxFFile fout;
|
|
|
|
if (!parOutput) fout.Attach(stdout);
|
|
|
|
else fout.Open(parOutput, _T("wt"));
|
|
|
|
|
|
|
|
for (size_t i = 0; i < str.GetCount(); i++)
|
2002-01-24 16:14:52 -05:00
|
|
|
fout.Write(_T("_(\"") + str[i] + _T("\")\n"));
|
2000-11-24 12:20:20 -05:00
|
|
|
|
|
|
|
if (!parOutput) fout.Detach();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wxArrayString XmlResApp::FindStrings()
|
|
|
|
{
|
|
|
|
wxArrayString arr, a2;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < parFiles.Count(); i++)
|
|
|
|
{
|
|
|
|
if (flagVerbose)
|
|
|
|
wxPrintf("processing " + parFiles[i] + "...\n");
|
|
|
|
|
|
|
|
wxXmlDocument doc;
|
|
|
|
if (!doc.Load(parFiles[i]))
|
|
|
|
{
|
|
|
|
wxLogError("Error parsing file " + parFiles[i]);
|
|
|
|
retCode = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
a2 = FindStrings(doc.GetRoot());
|
|
|
|
WX_APPEND_ARRAY(arr, a2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-03-09 11:35:00 -05:00
|
|
|
static wxString ConvertText(const wxString& str)
|
|
|
|
{
|
|
|
|
wxString str2;
|
|
|
|
const wxChar *dt;
|
|
|
|
|
|
|
|
for (dt = str.c_str(); *dt; dt++)
|
|
|
|
{
|
|
|
|
if (*dt == wxT('_'))
|
|
|
|
{
|
|
|
|
if ( *(++dt) == wxT('_') )
|
|
|
|
str2 << wxT('_');
|
|
|
|
else
|
|
|
|
str2 << wxT('&') << *dt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (*dt)
|
|
|
|
{
|
|
|
|
case wxT('\n') : str2 << wxT("\\n"); break;
|
|
|
|
case wxT('\t') : str2 << wxT("\\t"); break;
|
|
|
|
case wxT('\r') : str2 << wxT("\\r"); break;
|
|
|
|
default : str2 << *dt; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return str2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-24 12:20:20 -05:00
|
|
|
wxArrayString XmlResApp::FindStrings(wxXmlNode *node)
|
|
|
|
{
|
|
|
|
wxArrayString arr;
|
|
|
|
|
|
|
|
wxXmlNode *n = node;
|
|
|
|
if (n == NULL) return arr;
|
|
|
|
n = n->GetChildren();
|
|
|
|
|
|
|
|
while (n)
|
|
|
|
{
|
|
|
|
if ((node->GetType() == wxXML_ELEMENT_NODE) &&
|
|
|
|
// parent is an element, i.e. has subnodes...
|
|
|
|
(n->GetType() == wxXML_TEXT_NODE ||
|
|
|
|
n->GetType() == wxXML_CDATA_SECTION_NODE) &&
|
|
|
|
// ...it is textnode...
|
|
|
|
(
|
|
|
|
node/*not n!*/->GetName() == _T("label") ||
|
|
|
|
(node/*not n!*/->GetName() == _T("value") &&
|
|
|
|
!n->GetContent().IsNumber()) ||
|
|
|
|
node/*not n!*/->GetName() == _T("help") ||
|
|
|
|
node/*not n!*/->GetName() == _T("longhelp") ||
|
|
|
|
node/*not n!*/->GetName() == _T("tooltip") ||
|
|
|
|
node/*not n!*/->GetName() == _T("htmlcode") ||
|
|
|
|
node/*not n!*/->GetName() == _T("title")
|
|
|
|
))
|
2002-03-09 11:35:00 -05:00
|
|
|
// ...and known to contain translatable string
|
2000-11-24 12:20:20 -05:00
|
|
|
{
|
2002-03-09 11:35:00 -05:00
|
|
|
arr.Add(ConvertText(n->GetContent()));
|
2000-11-24 12:20:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// subnodes:
|
|
|
|
if (n->GetType() == wxXML_ELEMENT_NODE)
|
|
|
|
{
|
|
|
|
wxArrayString a2 = FindStrings(n);
|
|
|
|
WX_APPEND_ARRAY(arr, a2);
|
|
|
|
}
|
|
|
|
|
|
|
|
n = n->GetNext();
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}
|