Re: A bunch of minor issues
От | Heikki Linnakangas |
---|---|
Тема | Re: A bunch of minor issues |
Дата | |
Msg-id | 46FA6116.1030403@enterprisedb.com обсуждение исходный текст |
Ответ на | Re: A bunch of minor issues (Dave Page <dpage@postgresql.org>) |
Ответы |
Re: A bunch of minor issues
|
Список | pgadmin-hackers |
Dave Page wrote: > I'd be more interested in the patches so I can update my utilities and > those of developer.pgadmin.org where stringextract tends to be run (I > imagine Guillaume would like a copy too). Ok. Here's two patches to enable that: wx-linenumbers-in-wxrc-1.patch (against wxWidgets SVN trunk) modifies wxrc to output additional empty lines, so that the line numbers of the strings in the gettext output match corresponding lines in the source file. A bit hacky, but it works. I had to modify wxXml code to keep the line numbers in the wxXmlNode-objects it constructs from the XML document. pgadmin-stringextract-keep-filenames-1.patch modifies stringextract so that it runs wxrc and xgettext separately on each xrc file, to get the correct filename in the pot file. BTW, this patch alone is beneficial; you get the correct filenames though the line numbers are bogus without the wxrc patch. I'm not sure how the xargs-magic works on windows... -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com Index: stringextract =================================================================== --- stringextract (revision 6673) +++ stringextract (working copy) @@ -40,4 +40,14 @@ xgettext -k_ -k__ -j -s -o pgadmin3.pot xtra/pgagent/*.cpp xgettext -k_ -k__ -j -s -o pgadmin3.pot xtra/pgagent/include/*.h -wxrc -g pgadmin/ui/*.xrc | xgettext -k_ -k__ -L C -j -s -o pgadmin3.pot - +TMPDIR=`mktemp -d` || exit 1 +echo "$TMPDIR" + +mkdir $TMPDIR/pgadmin +mkdir $TMPDIR/pgadmin/ui + +ls pgadmin/ui/*.xrc | xargs -I filename wxrc -g filename -o $TMPDIR/filename + +ls pgadmin/ui/*.xrc | xargs xgettext -k_ -k__ -L C -j -s -o pgadmin3.pot -D $TMPDIR/ + +rm -rf $TMPDIR Index: src/xml/xml.cpp =================================================================== --- src/xml/xml.cpp (revision 48947) +++ src/xml/xml.cpp (working copy) @@ -64,6 +64,7 @@ else m_parent->m_children = this; } + m_lineNo = -1; } wxXmlNode::wxXmlNode(wxXmlNodeType type, const wxString& name, @@ -454,6 +455,7 @@ struct wxXmlParsingContext { + XML_Parser parser; wxMBConv *conv; wxXmlNode *root; wxXmlNode *node; @@ -469,6 +471,9 @@ wxXmlParsingContext *ctx = (wxXmlParsingContext*)userData; wxXmlNode *node = new wxXmlNode(wxXML_ELEMENT_NODE, CharToString(ctx->conv, name)); const char **a = atts; + + node->SetLineNumber(XML_GetCurrentLineNumber(ctx->parser)); + while (*a) { node->AddAttribute(CharToString(ctx->conv, a[0]), CharToString(ctx->conv, a[1])); @@ -508,6 +513,7 @@ if (!whiteOnly) { ctx->lastAsText = new wxXmlNode(wxXML_TEXT_NODE, wxT("text"), str); + ctx->lastAsText->SetLineNumber(XML_GetCurrentLineNumber(ctx->parser)); ctx->node->AddChild(ctx->lastAsText); } } @@ -518,6 +524,7 @@ wxXmlParsingContext *ctx = (wxXmlParsingContext*)userData; ctx->lastAsText = new wxXmlNode(wxXML_CDATA_SECTION_NODE, wxT("cdata"),wxT("")); + ctx->lastAsText->SetLineNumber(XML_GetCurrentLineNumber(ctx->parser)); ctx->node->AddChild(ctx->lastAsText); } @@ -530,8 +537,11 @@ // VS: ctx->node == NULL happens if there is a comment before // the root element (e.g. wxDesigner's output). We ignore such // comments, no big deal... - ctx->node->AddChild(new wxXmlNode(wxXML_COMMENT_NODE, - wxT("comment"), CharToString(ctx->conv, data))); + wxXmlNode *n = new wxXmlNode(wxXML_COMMENT_NODE, + wxT("comment"), CharToString(ctx->conv, data)); + n->SetLineNumber(XML_GetCurrentLineNumber(ctx->parser)); + + ctx->node->AddChild(n); } ctx->lastAsText = NULL; } @@ -609,6 +619,7 @@ ctx.conv = new wxCSConv(encoding); #endif ctx.removeWhiteOnlyNodes = (flags & wxXMLDOC_KEEP_WHITESPACE_NODES) == 0; + ctx.parser = parser; XML_SetUserData(parser, (void*)&ctx); XML_SetElementHandler(parser, StartElementHnd, EndElementHnd); Index: include/wx/xml/xml.h =================================================================== --- include/wx/xml/xml.h (revision 48947) +++ include/wx/xml/xml.h (working copy) @@ -151,6 +151,9 @@ wxString GetAttribute(const wxString& attrName, const wxString& defaultVal) const; bool HasAttribute(const wxString& attrName) const; + + int GetLineNumber() const { return m_lineNo; } + void SetLineNumber(int lineNo) { m_lineNo = lineNo; } void SetType(wxXmlNodeType type) { m_type = type; } void SetName(const wxString& name) { m_name = name; } @@ -202,6 +205,7 @@ wxString m_content; wxXmlAttribute *m_attrs; wxXmlNode *m_parent, *m_children, *m_next; + int m_lineNo; // line number in original file, or -1 void DoCopy(const wxXmlNode& node); }; Index: utils/wxrc/wxrc.cpp =================================================================== --- utils/wxrc/wxrc.cpp (revision 48947) +++ utils/wxrc/wxrc.cpp (working copy) @@ -201,7 +201,18 @@ WX_DECLARE_OBJARRAY(XRCWndClassData,ArrayOfXRCWndClassData); WX_DEFINE_OBJARRAY(ArrayOfXRCWndClassData) +class StringWithLineNumber +{ +public: + wxString str; + int lineNo; +}; +WX_DECLARE_OBJARRAY(StringWithLineNumber ,ArrayOfStringWithLineNumber); +WX_DEFINE_OBJARRAY(ArrayOfStringWithLineNumber) + + + class XmlResApp : public wxAppConsole { public: @@ -222,8 +233,8 @@ void MakePackagePython(const wxArrayString& flist); void OutputGettext(); - wxArrayString FindStrings(); - wxArrayString FindStrings(wxXmlNode *node); + ArrayOfStringWithLineNumber FindStrings(); + ArrayOfStringWithLineNumber FindStrings(wxXmlNode *node); bool flagVerbose, flagCPP, flagPython, flagGettext; wxString parOutput, parFuncname, parOutputPath; @@ -806,10 +817,16 @@ } - +static int wxCMPFUNC_CONV StringWithLineNumberCmp( +StringWithLineNumber **a, StringWithLineNumber **b) +{ + return (*a)->lineNo - (*b)->lineNo; +} + void XmlResApp::OutputGettext() { - wxArrayString str = FindStrings(); + int lineNo; + ArrayOfStringWithLineNumber str = FindStrings(); wxFFile fout; if (parOutput.empty()) @@ -817,17 +834,27 @@ else fout.Open(parOutput, wxT("wt")); + str.Sort(StringWithLineNumberCmp); + + lineNo = 1; for (size_t i = 0; i < str.GetCount(); i++) - fout.Write("_(\"" + str[i] + "\");\n"); + { + while(lineNo < str[i].lineNo) + { + fout.Write("\n"); + lineNo++; + } + fout.Write("_(\"" + str[i].str + "\"); "); + } if (!parOutput) fout.Detach(); } -wxArrayString XmlResApp::FindStrings() +ArrayOfStringWithLineNumber XmlResApp::FindStrings() { - wxArrayString arr, a2; + ArrayOfStringWithLineNumber arr, a2; for (size_t i = 0; i < parFiles.GetCount(); i++) { @@ -888,9 +915,9 @@ } -wxArrayString XmlResApp::FindStrings(wxXmlNode *node) +ArrayOfStringWithLineNumber XmlResApp::FindStrings(wxXmlNode *node) { - wxArrayString arr; + ArrayOfStringWithLineNumber arr; wxXmlNode *n = node; if (n == NULL) return arr; @@ -919,14 +946,17 @@ if (!flagGettext || node->GetAttribute(_T("translate"), _T("1")) != _T("0")) { - arr.Add(ConvertText(n->GetContent())); + StringWithLineNumber *s = new StringWithLineNumber(); + s->str = ConvertText(n->GetContent()); + s->lineNo = n->GetLineNumber(); + arr.Add(s); } } // subnodes: if (n->GetType() == wxXML_ELEMENT_NODE) { - wxArrayString a2 = FindStrings(n); + ArrayOfStringWithLineNumber a2 = FindStrings(n); WX_APPEND_ARRAY(arr, a2); }
В списке pgadmin-hackers по дате отправления: