void OutputNode(FILE* aFile, CSyntaxNode* aNode) { OutputNodeData(aFile, aNode); if (aNode->Left()) { fprintf (aFile, "\"node%p\" -> \"node%p\";\n", aNode, aNode->Left()); OutputNode(aFile, aNode->Left()); } if (aNode->Right()) { fprintf(aFile, "\"node%p\" -> \"node%p\";\n", aNode, aNode->Right()); OutputNode(aFile, aNode->Right()); } }
bool wxXmlDocument::Save(wxOutputStream& stream) const { if ( !IsOk() ) return false; wxString s; wxMBConv *convMem = NULL; #if wxUSE_UNICODE wxMBConv *convFile = new wxCSConv(GetFileEncoding()); #else wxMBConv *convFile = NULL; if ( GetFileEncoding() != GetEncoding() ) { convFile = new wxCSConv(GetFileEncoding()); convMem = new wxCSConv(GetEncoding()); } #endif s.Printf(wxT("<?xml version=\"%s\" encoding=\"%s\"?>\n"), GetVersion().c_str(), GetFileEncoding().c_str()); OutputString(stream, s, NULL, NULL); OutputNode(stream, GetRoot(), 0, convMem, convFile); OutputString(stream, wxT("\n"), NULL, NULL); if ( convFile ) delete convFile; if ( convMem ) delete convMem; return true; }
static void OutputNode(wxOutputStream& stream, wxXmlNode *node, int indent, wxMBConv *convMem, wxMBConv *convFile) { wxXmlNode *n, *prev; wxXmlProperty *prop; switch (node->GetType()) { case wxXML_TEXT_NODE: OutputStringEnt(stream, node->GetContent(), convMem, convFile); break; case wxXML_ELEMENT_NODE: OutputString(stream, wxT("<"), NULL, NULL); OutputString(stream, node->GetName(), NULL, NULL); prop = node->GetProperties(); while (prop) { OutputString(stream, wxT(" ") + prop->GetName() + wxT("=\""), NULL, NULL); OutputStringEnt(stream, prop->GetValue(), NULL, NULL, true/*escapeQuotes*/); OutputString(stream, wxT("\""), NULL, NULL); prop = prop->GetNext(); } if (node->GetChildren()) { OutputString(stream, wxT(">"), NULL, NULL); prev = NULL; n = node->GetChildren(); while (n) { if (n && n->GetType() != wxXML_TEXT_NODE) OutputIndentation(stream, indent + 1); OutputNode(stream, n, indent + 1, convMem, convFile); prev = n; n = n->GetNext(); } if (prev && prev->GetType() != wxXML_TEXT_NODE) OutputIndentation(stream, indent); OutputString(stream, wxT("</"), NULL, NULL); OutputString(stream, node->GetName(), NULL, NULL); OutputString(stream, wxT(">"), NULL, NULL); } else OutputString(stream, wxT("/>"), NULL, NULL); break; case wxXML_COMMENT_NODE: OutputString(stream, wxT("<!--"), NULL, NULL); OutputString(stream, node->GetContent(), convMem, convFile); OutputString(stream, wxT("-->"), NULL, NULL); break; default: wxFAIL_MSG(wxT("unsupported node type")); } }
void OutputTree(const char* aFileName, CSyntaxTree& aTree) { FILE* File = fopen(aFileName, "wt"); if (!File) __THROW("Failed to open %s for tree output.", aFileName); fputs ("digraph g {\n", File); fprintf(File, "node_info[label=\"Сгенерировано программой gtr2png %s\", shape=rect, color=black, style=bold];\n", GTR2PNG_VERSION); OutputNode(File, aTree.CoreNode()); fputs ("}", File); fclose(File); }
bool wxXmlDocument::Save(wxOutputStream& stream, int indentstep) const { if ( !IsOk() ) return false; wxString s; wxMBConv *convMem = NULL, *convFile; #if wxUSE_UNICODE convFile = new wxCSConv(GetFileEncoding()); convMem = NULL; #else if ( GetFileEncoding().CmpNoCase(GetEncoding()) != 0 ) { convFile = new wxCSConv(GetFileEncoding()); convMem = new wxCSConv(GetEncoding()); } else // file and in-memory encodings are the same, no conversion needed { convFile = convMem = NULL; } #endif s.Printf(wxT("<?xml version=\"%s\" encoding=\"%s\"?>\n"), GetVersion().c_str(), GetFileEncoding().c_str()); OutputString(stream, s); OutputNode(stream, GetRoot(), 0, convMem, convFile, indentstep); OutputString(stream, wxT("\n")); delete convFile; delete convMem; return true; }
bool wxXmlDocument::Save(wxOutputStream& stream, int indentstep) const { if ( !IsOk() ) return false; wxScopedPtr<wxMBConv> convMem, convFile; #if wxUSE_UNICODE convFile.reset(new wxCSConv(GetFileEncoding())); #else if ( GetFileEncoding().CmpNoCase(GetEncoding()) != 0 ) { convFile.reset(new wxCSConv(GetFileEncoding())); convMem.reset(new wxCSConv(GetEncoding())); } //else: file and in-memory encodings are the same, no conversion needed #endif wxString dec = wxString::Format( wxS("<?xml version=\"%s\" encoding=\"%s\"?>\n"), GetVersion(), GetFileEncoding() ); bool rc = OutputString(stream, dec, convMem.get(), convFile.get()); wxXmlNode *node = GetDocumentNode(); if ( node ) node = node->GetChildren(); while( rc && node ) { rc = OutputNode(stream, node, 0, convMem.get(), convFile.get(), indentstep) && OutputString(stream, wxS("\n"), convMem.get(), convFile.get()); node = node->GetNext(); } return rc; }
static void OutputNode(wxOutputStream& stream, wxXmlNode *node, int indent, wxMBConv *convMem, wxMBConv *convFile, int indentstep) { wxXmlNode *n, *prev; wxXmlProperty *prop; switch (node->GetType()) { case wxXML_CDATA_SECTION_NODE: OutputString( stream, wxT("<![CDATA[")); OutputString( stream, node->GetContent() ); OutputString( stream, wxT("]]>") ); break; case wxXML_TEXT_NODE: OutputEscapedString(stream, node->GetContent(), convMem, convFile, Escape_Text); break; case wxXML_ELEMENT_NODE: OutputString(stream, wxT("<")); OutputString(stream, node->GetName()); prop = node->GetProperties(); while (prop) { OutputString(stream, wxT(" ") + prop->GetName() + wxT("=\"")); OutputEscapedString(stream, prop->GetValue(), convMem, convFile, Escape_Attribute); OutputString(stream, wxT("\"")); prop = prop->GetNext(); } if (node->GetChildren()) { OutputString(stream, wxT(">")); prev = NULL; n = node->GetChildren(); while (n) { if (indentstep >= 0 && n && n->GetType() != wxXML_TEXT_NODE) OutputIndentation(stream, indent + indentstep); OutputNode(stream, n, indent + indentstep, convMem, convFile, indentstep); prev = n; n = n->GetNext(); } if (indentstep >= 0 && prev && prev->GetType() != wxXML_TEXT_NODE) OutputIndentation(stream, indent); OutputString(stream, wxT("</")); OutputString(stream, node->GetName()); OutputString(stream, wxT(">")); } else OutputString(stream, wxT("/>")); break; case wxXML_COMMENT_NODE: OutputString(stream, wxT("<!--")); OutputString(stream, node->GetContent(), convMem, convFile); OutputString(stream, wxT("-->")); break; default: wxFAIL_MSG(wxT("unsupported node type")); } }