#endif
#include "wx/cmdline.h"
-#include "wx/xml/xml.h"
-#include "wx/xml/xmlio.h"
+#include "wx/xrc/xml.h"
#include "wx/ffile.h"
#include "wx/wfstream.h"
void DeleteTempFiles(const wxArrayString& flist);
void MakePackageZIP(const wxArrayString& flist);
void MakePackageCPP(const wxArrayString& flist);
+
+ void OutputGettext();
+ wxArrayString FindStrings();
+ wxArrayString FindStrings(wxXmlNode *node);
- bool flagVerbose, flagCPP, flagCompress;
+ bool flagVerbose, flagCPP, flagGettext;
wxString parOutput, parFuncname, parOutputPath;
wxArrayString parFiles;
int retCode;
{
static const wxCmdLineEntryDesc cmdLineDesc[] =
{
+ { wxCMD_LINE_SWITCH, "h", "help", "show help message" },
{ wxCMD_LINE_SWITCH, "v", "verbose", "be verbose" },
{ wxCMD_LINE_SWITCH, "c", "cpp-code", "output C++ source rather than .rsc file" },
- { wxCMD_LINE_SWITCH, "u", "uncompressed", "do not compress .xml files (C++ only)" },
+ { wxCMD_LINE_SWITCH, "g", "gettext", "output list of translatable strings (to stdout or file if -o used)" },
{ wxCMD_LINE_OPTION, "n", "function", "C++ function name (with -c) [InitXmlResource]" },
- { wxCMD_LINE_OPTION, "o", "output", "output file [resource.rsc/cpp]" },
+ { wxCMD_LINE_OPTION, "o", "output", "output file [resource.xrs/cpp]" },
{ wxCMD_LINE_OPTION, "l", "list-of-handlers", "output list of neccessary handlers to this file" },
- { wxCMD_LINE_PARAM, NULL, NULL, "input file",
+ { wxCMD_LINE_PARAM, NULL, NULL, "input file(s)",
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE },
{ wxCMD_LINE_NONE }
};
- wxXmlDocument::AddHandler(new wxXmlIOHandlerBinZ);
+#if wxUSE_GUI
+ // VS: I need reasonable output to console from wxCmdLineParser
+ wxLog::SetTimestamp(NULL);
+ delete wxLog::SetActiveTarget(new wxLogStderr);
+#endif
wxCmdLineParser parser(cmdLineDesc, argc, argv);
case 0:
retCode = 0;
ParseParams(parser);
- CompileRes();
+ if (flagGettext)
+ OutputGettext();
+ else
+ CompileRes();
#if wxUSE_GUI
return FALSE;
#else
void XmlResApp::ParseParams(const wxCmdLineParser& cmdline)
{
+ flagGettext = cmdline.Found("g");
flagVerbose = cmdline.Found("v");
flagCPP = cmdline.Found("c");
- flagCompress = flagCPP && !cmdline.Found("u");
if (!cmdline.Found("o", &parOutput))
- parOutput = flagCPP ? "resource.cpp" : "resource.rsc";
+ {
+ if (flagGettext)
+ parOutput = wxEmptyString;
+ else
+ parOutput = flagCPP ? "resource.cpp" : "resource.xrs";
+ }
parOutputPath = wxPathOnly(parOutput);
if (!parOutputPath) parOutputPath = ".";
FindFilesInXML(doc.GetRoot(), flist, path);
- doc.Save(parOutputPath + "/" + name + ".xmb", flagCompress ? wxXML_IO_BINZ : wxXML_IO_BIN);
- flist.Add(name + ".xmb");
+ doc.Save(parOutputPath + "/" + name + ".xrc");
+ flist.Add(name + ".xrc");
}
return flist;
(n->GetType() == wxXML_TEXT_NODE ||
n->GetType() == wxXML_CDATA_SECTION_NODE) &&
// ...it is textnode...
- (node/*not n!*/->GetName() == "bitmap"))
+ ((node/*not n!*/->GetName() == "bitmap") ||
+ (node/*not n!*/->GetName() == "url")))
// ...and known to contain filename
{
wxString fullname;
wxString snum;
wxFFile file(filename, "rb");
size_t lng = file.Length();
- int linelng;
snum.Printf("%i", num);
output.Printf("static size_t xml_res_size_" + snum + " = %i;\n", lng);
- output += "static unsigned char xml_res_file_" + snum + "[] = \"\\\n";
+ 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 :(
unsigned char *buffer = new unsigned char[lng];
file.Read(buffer, lng);
for (size_t i = 0, linelng = 0; i < lng; i++)
{
- if (linelng > 70)
+ tmp.Printf("%i", buffer[i]);
+ if (i != 0) output << ',';
+ if (linelng > 70)
{
linelng = 0;
- output += "\\\n";
- }
- if (buffer[i] < 32 || buffer[i] == '"' || buffer[i] == '\\')
- {
- tmp.Printf("\\%03o", buffer[i]);
- output += tmp;
- linelng += 4;
- }
- else
- {
- output << (wxChar)buffer[i];
- linelng++;
+ output << "\n";
}
+ output << tmp;
+ linelng += tmp.Length()+1;
}
delete[] buffer;
- output += "\"\n;\n\n";
+ output += "};\n\n";
return output;
}
\
#include \"wx/filesys.h\"\n\
#include \"wx/fs_mem.h\"\n\
-#include \"wx/xml/xmlres.h\"\n\
-#include \"wx/xml/xh_all.h\"\n\
+#include \"wx/xrc/xmlres.h\"\n\
+#include \"wx/xrc/xh_all.h\"\n\
\n");
for (i = 0; i < flist.Count(); i++)
{
wxString name, ext, path;
wxSplitPath(parFiles[i], &path, &name, &ext);
- file.Write(" wxTheXmlResource->Load(\"memory:xml_resource/" +
- name + ".xmb" + "\");\n");
+ file.Write(" wxXmlResource::Get()->Load(\"memory:xml_resource/" +
+ name + ".xrc" + "\");\n");
+ }
+
+ file.Write("}\n");
+
+
+}
+
+
+
+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++)
+ fout.Write(_T("_(\"") + str[i] + _T("\")\n"));
+
+ 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);
}
- file.Write("\n}\n");
+ return arr;
+}
+
+
+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;
+}
+
+
+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")
+ ))
+ // ...and known to contain translatable string
+ {
+ arr.Add(ConvertText(n->GetContent()));
+ }
+
+ // subnodes:
+ if (n->GetType() == wxXML_ELEMENT_NODE)
+ {
+ wxArrayString a2 = FindStrings(n);
+ WX_APPEND_ARRAY(arr, a2);
+ }
+
+ n = n->GetNext();
+ }
+ return arr;
}