PDA

View Full Version : QTextStream capture stdout from xsltParseStylesheetFile



patrik08
17th June 2006, 13:13
a external lib funktion write to stdout i see on debug mode this...
cur = xsltParseStylesheetFile( (const xmlChar*)gocharxslt.data() );

How i can capture this important error to say user error line xx tag ...

wenn i start a QTextStream out(stdout); is only write to stdout
i grab only ###start#### & #### end ##### and not stdout from xsltParseStylesheetFile on php i use http://php.net/ob-start and grab all or partial...



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);
/* ######################################### */
QTextStream out(stdout);
out << "######################start####################### #####\n";
QByteArray gocharxslt = DATA_CONVERTER.toAscii();
cur = xsltParseStylesheetFile( (const xmlChar*)gocharxslt.data() );
if (!cur) {
xslt_error = "XSLT! [7] XsltParseStylesheetFile Failture files =>"+DATA_CONVERTER;
}
out << "\n#######################stop##################### ######\n" << endl;
capturesdout = out.readAll();
out.flush();
qDebug() << "### CUR error " << cur;
qDebug() << "### capturesdout error " << capturesdout;
xsltFreeStylesheet(cur);

patrik08
17th June 2006, 17:11
And ....

QString str;
QTextStream in(stdin);
function outputs ....
in >> str;

not grab nothing...! I am sure ... a method must exist....
$content = file_get_contents("php://input");
qt it must be able to read the stdin or stdout ecc...

jacek
17th June 2006, 17:27
not grab nothing...! I am sure ... a method must exist....
$content = file_get_contents("php://input");
Remember that C++ is not PHP and things in C++ not necessarily must work the same way as in PHP.


qt it must be able to read the stdin or stdout ecc...
It depends on what mechanism does xsltParseStylesheetFile() function use, because it certainly isn't a Qt function. You might try freopen().

patrik08
17th June 2006, 18:05
It depends on what mechanism does xsltParseStylesheetFile() function use, because it certainly isn't a Qt function. You might try freopen().


QByteArray gocharxslt = DATA_CONVERTER.toAscii();
freopen ("myfile.txt","w",stdout);
printf ("This sentence is redirected to a file.");
cur = xsltParseStylesheetFile( (const xmlChar*)gocharxslt.data() );
qDebug() << "## say hello world ###.. ";
fclose (stdout);



on myfile.txt found....

This sentence is redirected to a file.

console ..... say ....


file:///C%3A/convert.xml:1: parser error : parsing XML declaration: '?>' expecte
d
<?xml version="1.0" encoding="utf-8"?
^
file:///C%3A/convert.xml:2: namespace error : Namespace prefix xsl on output is
not defined
<xsl:output method="html" encoding="utf-8"/>
^
file:///C%3A/convert.xml:3: parser error : Extra content at the end of the docum
ent
<xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"/>
^
error
xsltParseStylesheetFile : cannot parse C:\convert.xml
## say hello world ###..



i suppose "xsltParseStylesheetFile" output is ... throw but is important to say on edit xslt file...

if (!out.is_open())
throw internal_fatal("can't open temporary file %s", fname.c_str());
out << n;
out.close();

I found a other method same as a callback http://www.stylusstudio.com/xsllist/200503/post90770.html
xsltSetGenericErrorFunc(cur,myhandler);


void myhandler(void *ctx, const char *msg, ...) {
qDebug() << "### start or no #### ";
va_list args;

if (xmlGenericErrorContext == NULL)
xmlGenericErrorContext = (void *) stderr;

va_start(args, msg);
vfprintf((FILE *)xmlGenericErrorContext, msg, args);
va_end(args);
}

but not start....

cur = xsltParseStylesheetFile((const xmlChar*)gocharxslt.data());
xsltSetGenericErrorFunc(cur,myhandler);

jacek
17th June 2006, 19:02
I found a other method same as a callback
So you want to capture stdout or stderr?


but not start....
Can you elaborate? What's happening and what did you expect to happen?

patrik08
17th June 2006, 20:10
So you want to capture stdout or stderr?
Can you elaborate? What's happening and what did you expect to happen?

stderr .... i want to show only on user the parse file error line ... throw i think is not possibel ....

stdin grab null , stderr grab null...

if i make an external qprocess to a xsltproc.exe param ecc i can grab and read all error and parser error.... ...
and here no?
The extarnal callback not start ... is possibel is a old version function...

people normal not like to see error .... but on a xslt editor must debug all error and tag ....
the list http://www.biglist.com/lists/xsl-list/archives/ have only 4 result by search
xsltParseStylesheetFile




QByteArray gocharxslt = DATA_CONVERTER.toAscii();
QTextStream in(stderr);
cur = xsltParseStylesheetFile( (const xmlChar*)gocharxslt.data() );
in >> capturesdout; /* fill QString */
qDebug() << "### xmlGenericErrorContext " << xmlGenericErrorContext;
qDebug() << "## capturesdout ###.. " << capturesdout;

QByteArray gocharxslt = DATA_CONVERTER.toAscii();
QTextStream in(stdin);
cur = xsltParseStylesheetFile( (const xmlChar*)gocharxslt.data() );
in >> capturesdout; /* fill QString */
qDebug() << "### xmlGenericErrorContext " << xmlGenericErrorContext;
qDebug() << "## capturesdout ###.. " << capturesdout;

patrik08
17th June 2006, 20:39
I continue post on c-programming ... why? problem is moore C and not QT

http://www.qtcentre.org/forum/f-c-programming-9/t-bring-va-list-args-to-a-qstringlist-or-a-qmap-2690.html

jacek
17th June 2006, 21:46
stderr .... i want to show only on user the parse file error line ... throw i think is not possibel ....
It is possible, you have even found the right method --- use xsltSetGenericErrorFunc() function and write your own handler that will store all error messages in a QString or it will send them directly to the right widget. QString::sprintf() might come in handy.

patrik08
18th June 2006, 14:33
Now i cann capture all error from xslt line nr.. tag ....bla bla....

SUPER!

is running so....


/* class */
void Gui_Front::Convert_Group()
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCu rsor));
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;
}

patrik08
25th June 2006, 12:24
Much tanks to jacek http://www.qtcentre.org/forum/u-jacek-7.html

from This Thread is Been born a new sf.net projekt...

A Visual xsltproc Debugger ....

http://sourceforge.net/projects/visual-xsltproc/