/* class */
void Gui_Front::Convert_Group()
{
bool fxml, fxslt, rfile;
#if defined Q_WS_WIN
QString disk_pre
= QDir::homePath();
/* cat c: or d: ECC...*/ #define SHORTFILE \
QString( "%1\\apache.xml" ).
arg( disk
) /* window space name file trouble xslt */ #define DATA_FILE_XML \
QString( "%1\\data.xml" ).
arg( disk
) #define DATA_CONVERTER \
QString( "%1\\convert.xml" ).
arg( disk
)
#else
#define SHORTFILE \
QString( "%1apache.xml" ).
arg( WORK_CACHEDIR
) #define DATA_FILE_XML \
QString( "%1data.xml" ).
arg( WORK_CACHEDIR
) #define DATA_CONVERTER \
QString( "%1convert.xsl" ).
arg( WORK_CACHEDIR
) #endif
#define XSLTERRORFILE \
QString( "%1ErMsgXSLT.dat" ).
arg( WORK_CACHEDIR
)
const char* params[5];
params[0] = NULL;
params[1] = NULL;
params[2] = NULL;
params[3] = NULL;
params[4] = NULL;
qDebug() << "### SHORTFILE " << SHORTFILE;
qDebug() << "### DATA_FILE_XML " << DATA_FILE_XML;
qDebug() << "### DATA_CONVERTER " << DATA_CONVERTER;
QString actualxslt
= xsl_area
->document
()->toPlainText
();
fxslt = db->file_put_contents(DATA_CONVERTER,actualxslt);
QString actualxml
= xml_area
->document
()->toPlainText
();
fxml = db->file_put_contents(DATA_FILE_XML,actualxslt);
/* ######################################### */
xsltStylesheetPtr cur = NULL;
xmlDocPtr doc, outputDoc;
xmlSubstituteEntitiesDefault(1);
xmlLoadExtDtdDefaultValue = 1;
/* ######################################### */
char* xslt_errors;
xsltSetGenericErrorFunc(&xslt_errors, qt_libxml_error_handler); /* error reg */
xmlSetGenericErrorFunc (&xslt_errors, qt_libxml_error_handler);
xsltSetGenericDebugFunc (&xslt_errors, qt_libxml_error_handler);
cur = xsltParseStylesheetFile( (const xmlChar*)gocharxslt.data() );
doc
= xmlParseFile
( QFile::encodeName(DATA_FILE_XML
) );
/*xsltSetGenericErrorFunc(doc, qt_libxml_error_handler);
xsltSetGenericDebugFunc(doc, qt_libxml_error_handler);*/
outputDoc = xsltApplyStylesheet(cur, doc, params);
xmlFreeDoc( doc ); /* free ram from xml! */
doc = outputDoc; /* swap input and output */
FILE* outfile
= fopen( QFile::encodeName( SHORTFILE
),
"w" );
xsltSaveResultToFile( outfile, doc, cur );
fclose( outfile );
xsltFreeStylesheet(cur);
xmlFreeDoc( outputDoc );
xsltCleanupGlobals();
xmlCleanupParser();
if (db->is_file(SHORTFILE)) {
result_area->clear();
result_area->insertPlainText(db->file_get_contents(SHORTFILE));
result_area->toPlainText();
}
/*db->qt_unlink(SHORTFILE);*/
/*qDebug() << "### xmlGenericErrorContext " << xmlGenericErrorContext;*/
}
/* external function !*/
void qt_libxml_error_handler(void *ctx, const char *msg, ...)
{
va_list args;
int size = 256;
char * buf = new char[ size ];
while( 1 ) {
va_start(args, msg);
int retval = ::vsnprintf( buf, size, msg, args );
va_end(args);
if( -1 < retval && retval < size ) { // everything was OK
message = buf;
/*if (!message.startsWith("error", Qt::CaseInsensitive)) {*/
qDebug() << "### 1 error captured to insert on class as list or so.... " << message;
/*}*/
break;
}
else if( retval > -1 ) { // buffer too small
size = retval + 1;
delete [] buf;
buf = new char[ size ];
}
else { // error
// ...
break;
}
}
delete [] buf;
}
/* class */
void Gui_Front::Convert_Group()
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
bool fxml, fxslt, rfile;
QString capturesdout;
#if defined Q_WS_WIN
QString disk_pre = QDir::homePath(); /* cat c: or d: ECC...*/
QString disk = disk_pre.left(2);
#define SHORTFILE \
QString( "%1\\apache.xml" ).arg( disk ) /* window space name file trouble xslt */
#define DATA_FILE_XML \
QString( "%1\\data.xml" ).arg( disk )
#define DATA_CONVERTER \
QString( "%1\\convert.xml" ).arg( disk )
#else
#define SHORTFILE \
QString( "%1apache.xml" ).arg( WORK_CACHEDIR )
#define DATA_FILE_XML \
QString( "%1data.xml" ).arg( WORK_CACHEDIR )
#define DATA_CONVERTER \
QString( "%1convert.xsl" ).arg( WORK_CACHEDIR )
#endif
#define XSLTERRORFILE \
QString( "%1ErMsgXSLT.dat" ).arg( WORK_CACHEDIR )
const char* params[5];
params[0] = NULL;
params[1] = NULL;
params[2] = NULL;
params[3] = NULL;
params[4] = NULL;
qDebug() << "### SHORTFILE " << SHORTFILE;
qDebug() << "### DATA_FILE_XML " << DATA_FILE_XML;
qDebug() << "### DATA_CONVERTER " << DATA_CONVERTER;
QString actualxslt = xsl_area->document()->toPlainText();
fxslt = db->file_put_contents(DATA_CONVERTER,actualxslt);
QString actualxml = xml_area->document()->toPlainText();
fxml = db->file_put_contents(DATA_FILE_XML,actualxslt);
/* ######################################### */
xsltStylesheetPtr cur = NULL;
xmlDocPtr doc, outputDoc;
xmlSubstituteEntitiesDefault(1);
xmlLoadExtDtdDefaultValue = 1;
/* ######################################### */
char* xslt_errors;
xsltSetGenericErrorFunc(&xslt_errors, qt_libxml_error_handler); /* error reg */
xmlSetGenericErrorFunc (&xslt_errors, qt_libxml_error_handler);
xsltSetGenericDebugFunc (&xslt_errors, qt_libxml_error_handler);
QByteArray gocharxslt = DATA_CONVERTER.toAscii();
cur = xsltParseStylesheetFile( (const xmlChar*)gocharxslt.data() );
doc = xmlParseFile( QFile::encodeName(DATA_FILE_XML) );
/*xsltSetGenericErrorFunc(doc, qt_libxml_error_handler);
xsltSetGenericDebugFunc(doc, qt_libxml_error_handler);*/
outputDoc = xsltApplyStylesheet(cur, doc, params);
xmlFreeDoc( doc ); /* free ram from xml! */
doc = outputDoc; /* swap input and output */
FILE* outfile = fopen( QFile::encodeName( SHORTFILE ), "w" );
xsltSaveResultToFile( outfile, doc, cur );
fclose( outfile );
xsltFreeStylesheet(cur);
xmlFreeDoc( outputDoc );
xsltCleanupGlobals();
xmlCleanupParser();
if (db->is_file(SHORTFILE)) {
result_area->clear();
result_area->insertPlainText(db->file_get_contents(SHORTFILE));
result_area->toPlainText();
}
/*db->qt_unlink(SHORTFILE);*/
/*qDebug() << "### xmlGenericErrorContext " << xmlGenericErrorContext;*/
QApplication::restoreOverrideCursor();
}
/* external function !*/
void qt_libxml_error_handler(void *ctx, const char *msg, ...)
{
va_list args;
QString message;
int size = 256;
char * buf = new char[ size ];
while( 1 ) {
va_start(args, msg);
int retval = ::vsnprintf( buf, size, msg, args );
va_end(args);
if( -1 < retval && retval < size ) { // everything was OK
message = buf;
/*if (!message.startsWith("error", Qt::CaseInsensitive)) {*/
qDebug() << "### 1 error captured to insert on class as list or so.... " << message;
/*}*/
break;
}
else if( retval > -1 ) { // buffer too small
size = retval + 1;
delete [] buf;
buf = new char[ size ];
}
else { // error
// ...
break;
}
}
delete [] buf;
}
To copy to clipboard, switch view to plain text mode
Bookmarks