/* * kxslt1.c */ #define USAGE "Usage: kxslt1 " #include "mystab.h" #include "myio_apr.h" #include "myio_xml.h" int apr_my_main ( int ac , char **av , apr_file_t * astdin , apr_file_t * astdout , apr_file_t * astderr , apr_pool_t * pool ) { int error_flag = 0; char *in_filename = NULL; char *xsl_filename = NULL; char *out_filename = NULL; MYIO *in = NULL; MYIO *out = NULL; xmlDocPtr srcDom = NULL; xsltStylesheetPtr style = NULL; xmlDocPtr res = NULL; if (ac < 3) { apr_file_printf(astderr, "%s\n", USAGE); error_flag = 1; goto _FINALLY_; } in_filename = av[1]; xsl_filename = av[2]; out_filename = av[3]; /* 入力ファイルのオープン */ in = MYIO_fp_open(in_filename, APR_FOPEN_READ|APR_FOPEN_BINARY, APR_OS_DEFAULT, pool); if (! in) { apr_file_printf(astderr, "ERROR: MYIO_fp_open: %s ", in_filename); error_flag = 1; goto _FINALLY_; } out = MYIO_fp_open(out_filename, APR_FOPEN_WRITE|APR_FOPEN_CREATE|APR_FOPEN_BINARY|APR_FOPEN_TRUNCATE, APR_OS_DEFAULT, pool); if (!out) { apr_file_printf(astderr, "ERROR: file open [%s] ", out_filename); error_flag = 1; goto _FINALLY_; } srcDom = my_xml_read(in); if (!srcDom) { apr_file_printf(astderr, "ERROR: my_xml_read [%s] ", in_filename); error_flag = 1; goto _FINALLY_; } style = xsltParseStylesheetFile ((const xmlChar*)xsl_filename); if (!style) { apr_file_printf(astderr, "ERROR: xsltParseStylesheetFile [%s] ", xsl_filename); error_flag = 1; goto _FINALLY_; } res = my_xml_transform(srcDom, style); if (!res) { apr_file_printf(astderr, "ERROR: my_xml_transform "); error_flag = 1; goto _FINALLY_; } { int wrote_size = MYIO_xslt_write(out, res, style); if (wrote_size<0) { error_flag = 1; apr_file_printf(astderr, "ERROR: MYIO_xslt_write "); } else { apr_file_printf(astderr, "%d bytes saved to %s.\n", wrote_size, out_filename); } } _FINALLY_: if (style) { xsltFreeStylesheet(style); style = NULL; } if (srcDom) { xmlFreeDoc(srcDom); srcDom = NULL; } if (res) { xmlFreeDoc(res); res = NULL; } xmlCleanupParser(); xsltCleanupGlobals(); xmlMemoryDump(); if (in) { MYIO_fp_close(in); in = NULL; } if (out) { MYIO_fp_close(out); out = NULL; } if (error_flag) { apr_file_printf(astderr, "failed.\n"); return 1; /* 異常終了 */ } apr_file_printf(astdout, "done.\n"); return 0; /* 正常終了 */ }