static void printAttrs( xmlAttrPtr pAttr ) { while (pAttr != NULL) { char* pzCont = (char*)pAttr->children->content; emitIndentation(); fputs( (char*)(void*)pAttr->name, outFp ); fputs( " = ", outFp ); if (pAttr->children->children == NULL) fprintf( outFp, "'%s';\n", TRIM( pzCont, NULL )); else { fputs( "{\n", outFp ); level++; if (pzCont != NULL) { emitIndentation(); fprintf( outFp, zTextFmt, TRIM( pzCont, NULL )); } printChildren( pAttr->children->children ); level--; emitIndentation(); fputs( "};\n", outFp ); } pAttr = pAttr->next; } }
SAWYER_EXPORT void Reflow::emitAccumulated() { if (nonspaces_.empty()) { // emit nothing } else if (column_ == 0) { emitIndentation(); out_ <<nonspaces_; column_ += nonspaces_.size(); } else if (column_ + spaces_.size() + nonspaces_.size() > pageWidth_) { emitNewLine(); emitIndentation(); out_ <<nonspaces_; column_ += nonspaces_.size(); } else { out_ <<spaces_ <<nonspaces_; column_ += spaces_.size() + nonspaces_.size(); } spaces_ = nonspaces_ = ""; }
static void printNode( xmlNodePtr pNode ) { switch (pNode->type) { case XML_ELEMENT_NODE: { size_t sz; char* pzTxt; emitIndentation(); fputs( (char*)(void*)pNode->name, outFp ); pzTxt = TRIM( pNode->content, &sz ); if ( (pNode->properties == NULL) && (pNode->children == NULL)) { if (sz == 0) fputs( ";\n", outFp ); else fprintf( outFp, " = '%s';\n", pzTxt ); break; } fputs( " = {\n", outFp ); level++; emitIndentation(); fprintf( outFp, "content = '%s';\n", pzTxt ); printAttrs( pNode->properties ); printChildren( pNode->children ); level--; emitIndentation(); fputs( "};\n", outFp ); break; } case XML_ATTRIBUTE_NODE: fputs( "Misplaced attribute\n", outFp ); exit( EXIT_FAILURE ); case XML_TEXT_NODE: { size_t sz; char* pzTxt = TRIM( pNode->content, &sz ); if (sz == 0) break; emitIndentation(); fprintf( outFp, zTextFmt, pzTxt ); break; } case XML_COMMENT_NODE: { size_t sz; char* pzTxt = TRIM( pNode->content, &sz ); if (sz == 0) break; emitIndentation(); fputs( "/* ", outFp ); for (;;) { char* pz = strstr( pzTxt, "*/" ); if (pz == NULL) break; fwrite(pzTxt, (size_t)((pz - pzTxt) + 1), (size_t)1, outFp); pzTxt = pz+1; fputc( ' ', outFp ); } fprintf( outFp, "%s */\n", pzTxt ); break; } case XML_CDATA_SECTION_NODE: case XML_ENTITY_REF_NODE: case XML_ENTITY_NODE: case XML_PI_NODE: case XML_DOCUMENT_NODE: case XML_HTML_DOCUMENT_NODE: case XML_DOCUMENT_TYPE_NODE: case XML_DOCUMENT_FRAG_NODE: case XML_NOTATION_NODE: case XML_DTD_NODE: case XML_ELEMENT_DECL: case XML_ATTRIBUTE_DECL: case XML_ENTITY_DECL: case XML_NAMESPACE_DECL: case XML_XINCLUDE_START: case XML_XINCLUDE_END: emitIndentation(); fprintf( outFp, "/* Unsupported XML node type: %s */\n", typeName[ pNode->type ]); break; default: emitIndentation(); fprintf( outFp, "/* Unknown XML node type %d */\n", pNode->type ); break; } }