int main( int argc, char** argv ) { xmlDocPtr pDoc; char const* pzFile = NULL; { int ct = optionProcess( &xml2agOptions, argc, argv ); argc -= ct; argv += ct; switch (argc) { case 1: if (strcmp( *argv, "-" ) != 0) { if (HAVE_OPT( DEFINITIONS )) { fprintf( stderr, zConflict ); USAGE( EXIT_FAILURE ); } pzFile = *argv; break; } case 0: if ( HAVE_OPT( DEFINITIONS ) && (strcmp( OPT_ARG( DEFINITIONS ), "-" ) != 0) ) pzFile = OPT_ARG( DEFINITIONS ); break; default: fprintf( stderr, "only one argument allowed\n" ); return EXIT_FAILURE; } } if (! HAVE_OPT( OUTPUT )) forkAutogen( pzFile ); else outFp = stdout; if (pzFile != NULL) { fprintf( outFp, "/* Parsing file %s */\n", pzFile ); pDoc = xmlParseFile( pzFile ); } else { size_t sz; char* pz = loadFile( stdin, &sz ); pDoc = xmlParseMemory( pz, (int)sz ); fprintf( outFp, "/* Parsed from stdin */\n" ); } { static char const z_not_doc[] = "/* type %d doc is not DOCUMENT or HTML_DOCUMENT */\n"; xmlNodePtr pRoot = printHeader( pDoc ); printAttrs( pRoot->properties ); switch (pDoc->type) { case XML_DOCUMENT_NODE: case XML_HTML_DOCUMENT_NODE: printChildren( pRoot->children ); break; default: fprintf( outFp, z_not_doc, pDoc->type ); } } xmlCleanupParser(); return 0; }
int main(int argc, char *argv[]) { bor_mesh3_t *mesh; size_t islen; FILE *outfile; bor_timer_t timer; readOptions(argc, argv); gsrm = svoGSRMNew(¶ms); printAttrs(); // open output file if (outfile_fn == NULL){ outfile = stdout; }else{ outfile = fopen(outfile_fn, "w"); if (outfile == NULL){ fprintf(stderr, "Can't open '%s' for writing!\n", outfile_fn); return -1; } } borTimerStart(&timer); borTimerStopAndPrintElapsed(&timer, stderr, " Reading input signals:\n"); borTimerStopAndPrintElapsed(&timer, stderr, " -- '%s'...\n", is_fn); islen = svoGSRMAddInputSignals(gsrm, is_fn); borTimerStopAndPrintElapsed(&timer, stderr, " -- Added %d input signals.\n", islen); fprintf(stderr, "\n"); if (svoGSRMRun(gsrm) == 0){ if (!no_postprocess) svoGSRMPostprocess(gsrm); borTimerStart(&timer); mesh = svoGSRMMesh(gsrm); borMesh3DumpSVT(mesh, outfile, "Result"); if (params.verbosity >= 2){ fprintf(stderr, "\n"); borTimerStopAndPrintElapsed(&timer, stderr, " Mesh dumped to '%s'.\n", (outfile == stdout ? "stdout" : outfile_fn)); } if (dump_triangles != NULL){ borMesh3DumpTriangles(mesh, dump_triangles); fclose(dump_triangles); if (params.verbosity >= 2){ borTimerStopAndPrintElapsed(&timer, stderr, " Mesh dumped as triangles into '%s'.\n", dump_triangles_fn); } } } svoGSRMDel(gsrm); // close output file if (outfile != stdout) fclose(outfile); return 0; }
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; } }