summaryrefslogtreecommitdiffstats
path: root/kxsldbg/kxsldbgpart/libqtnotfier
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commite9ae80694875f869892f13f4fcaf1170a00dea41 (patch)
treeaa2f8d8a217e2d376224c8d46b7397b68d35de2d /kxsldbg/kxsldbgpart/libqtnotfier
downloadtdewebdev-e9ae80694875f869892f13f4fcaf1170a00dea41.tar.gz
tdewebdev-e9ae80694875f869892f13f4fcaf1170a00dea41.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdewebdev@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kxsldbg/kxsldbgpart/libqtnotfier')
-rw-r--r--kxsldbg/kxsldbgpart/libqtnotfier/Makefile.am8
-rw-r--r--kxsldbg/kxsldbgpart/libqtnotfier/qtnotifier2.cpp62
-rw-r--r--kxsldbg/kxsldbgpart/libqtnotfier/xsldbgdebuggerbase.cpp93
-rw-r--r--kxsldbg/kxsldbgpart/libqtnotfier/xsldbgdebuggerbase.h147
-rw-r--r--kxsldbg/kxsldbgpart/libqtnotfier/xsldbgevent.cpp857
-rw-r--r--kxsldbg/kxsldbgpart/libqtnotfier/xsldbgnotifier.cpp33
-rw-r--r--kxsldbg/kxsldbgpart/libqtnotfier/xsldbgthread.cpp360
7 files changed, 1560 insertions, 0 deletions
diff --git a/kxsldbg/kxsldbgpart/libqtnotfier/Makefile.am b/kxsldbg/kxsldbgpart/libqtnotfier/Makefile.am
new file mode 100644
index 00000000..82902c19
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libqtnotfier/Makefile.am
@@ -0,0 +1,8 @@
+noinst_LTLIBRARIES = libqtnotfier.la
+
+libqtnotfier_la_LIBADD = $(LIBXSLT_LIBS)
+libqtnotfier_la_METASOURCES = AUTO
+
+libqtnotfier_la_SOURCES = xsldbgthread.cpp xsldbgnotifier.cpp xsldbgevent.cpp xsldbgdebuggerbase.cpp qtnotifier2.cpp
+
+INCLUDES = $(XSLDBG_CFLAGS) $(all_includes)
diff --git a/kxsldbg/kxsldbgpart/libqtnotfier/qtnotifier2.cpp b/kxsldbg/kxsldbgpart/libqtnotfier/qtnotifier2.cpp
new file mode 100644
index 00000000..6d4b7fcb
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libqtnotfier/qtnotifier2.cpp
@@ -0,0 +1,62 @@
+/***************************************************************************
+ qtnotifier2.cpp - description
+ -------------------
+ begin : Sun Dec 23 2001
+ copyright : (C) 2001 by keith
+ email : k_isdale@tpg.com.au
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <qapplication.h>
+
+#include "../libxsldbg/xsldbgevent.h"
+#include "../libxsldbg/qtnotifier2.h"
+#include "xsldbgdebuggerbase.h"
+#include "../libxsldbg/xsldbgthread.h"
+
+XsldbgDebuggerBase *_debugger = 0L;
+
+int qtNotifyXsldbgApp(XsldbgMessageEnum type, const void *data)
+{
+ int result = 0;
+ if (::getThreadStatus() == XSLDBG_MSG_THREAD_NOTUSED){
+ return 1;
+ }
+
+ /* clear the input ready flag as quickly as possible*/
+ if ( ::getInputStatus() == XSLDBG_MSG_READ_INPUT)
+ ::setInputReady(0);
+
+ /* state of the thread */
+ if (_debugger != 0L){
+ XsldbgEvent *e = new XsldbgEvent(type, data);
+ if (e != 0L) {
+ /* The application will now have this event in its event queue
+ that all that is needed from here*/
+ QApplication::postEvent(_debugger, e);
+ }
+ }
+
+ if (::getThreadStatus() == XSLDBG_MSG_THREAD_STOP)
+ ::xsldbgThreadCleanup(); /* thread has died so cleanup after it */
+
+ result++; /* at the moment this function will always work */
+
+ return result;
+}
+
+
+
+void connectNotifier(XsldbgDebuggerBase *debugger){
+ _debugger = debugger;
+}
+
+
diff --git a/kxsldbg/kxsldbgpart/libqtnotfier/xsldbgdebuggerbase.cpp b/kxsldbg/kxsldbgpart/libqtnotfier/xsldbgdebuggerbase.cpp
new file mode 100644
index 00000000..930be808
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libqtnotfier/xsldbgdebuggerbase.cpp
@@ -0,0 +1,93 @@
+/***************************************************************************
+ xsldbgdebuggerbase.cpp - The base class from
+ which a debugger
+ could be built
+
+ -------------------
+ begin : Fri Feb 1 2001
+ copyright : (C) 2001 by Keith Isdale
+ email : k_isdale@tpg.com.au
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <qapplication.h>
+#include <qglobal.h>
+#include <qstringlist.h>
+#include <kurl.h>
+
+#include "xsldbgdebuggerbase.h"
+
+XsldbgDebuggerBase::XsldbgDebuggerBase()
+ : QObject(0L, "XsldbgDebuggerBase")
+{
+ initialized = false;
+ updateTimerID = -1;
+}
+
+
+XsldbgDebuggerBase::~XsldbgDebuggerBase()
+{
+ /* empty*/
+}
+
+
+
+QString XsldbgDebuggerBase::fromUTF8(const char *text)
+{
+ QString result;
+ if (text != 0L)
+ result = (const char*)text;
+ return result;
+}
+
+
+QString XsldbgDebuggerBase::fromUTF8(const xmlChar *text)
+{
+ QString result;
+ if (text != 0L)
+ result = QString::fromUtf8((const char*)text);
+ return result;
+}
+
+
+QString XsldbgDebuggerBase::fromUTF8FileName(const char *text)
+{
+ QString result;
+ if (text != 0L){
+ KURL url(((const char*)text));
+ if (url.isLocalFile())
+ result = QString("file:") + url.path();
+ else
+ result = url.prettyURL();
+ }
+ return result;
+}
+
+
+QString XsldbgDebuggerBase::fromUTF8FileName(const xmlChar *text)
+{
+ QString result;
+ if (text != 0L){
+ KURL url(QString::fromUtf8((const char*)text));
+ if (url.isLocalFile())
+ result = QString("file:") + url.path();
+ else
+ result = url.prettyURL();
+ }
+ return result;
+}
+
+
+void XsldbgDebuggerBase::queueMessage(const QString &text)
+{
+ updateText += text;
+}
+#include "xsldbgdebuggerbase.moc"
diff --git a/kxsldbg/kxsldbgpart/libqtnotfier/xsldbgdebuggerbase.h b/kxsldbg/kxsldbgpart/libqtnotfier/xsldbgdebuggerbase.h
new file mode 100644
index 00000000..ff830495
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libqtnotfier/xsldbgdebuggerbase.h
@@ -0,0 +1,147 @@
+/***************************************************************************
+ xsldbgdebuggerbase.h - The base class from
+ which a debugger
+ could be built
+
+ -------------------
+ begin : Fri Feb 1 2001
+ copyright : (C) 2001 by Keith Isdale
+ email : k_isdale@tpg.com.au
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+
+#ifndef XSLDBGDEBUGGERBASE_H
+#define XSLDBGDEBUGGERBASE_H
+
+#if defined WIN32
+# include <libxsldbg/xsldbgwin32config.h>
+#else
+# ifndef XSLDBG_SO_API
+# define XSLDBG_SO_API
+# endif
+#endif
+
+#include <qobject.h>
+#include <qstringlist.h>
+#include <libxml/tree.h>
+
+class XsldbgEvent;
+class QApplication;
+class QStringList;
+
+/**
+ We delegate the task of emitting our signals to XsldbgEvent , so
+ Xsldbg must become our friend
+*/
+class XsldbgDebuggerBase : public QObject
+{
+ Q_OBJECT
+
+ friend class XsldbgEvent;
+
+ public:
+ XsldbgDebuggerBase(void);
+ ~XsldbgDebuggerBase(void);
+
+ void setInitialized(bool state) {initialized = state; };
+ bool getInitialized(void) {return initialized ;};
+
+ void setUpdateTimerID(int ID) { updateTimerID = ID;};
+ int getUpdateTimerID(void) {return updateTimerID ;};
+
+
+ /** Convert from libxslt UTF8 to a QString */
+ static QString fromUTF8(const char *text);
+ static QString fromUTF8FileName(const char *text);
+
+ /** Convert from libxslt UTF8 to a QString */
+ static QString fromUTF8(const xmlChar *text);
+ static QString fromUTF8FileName(const xmlChar *text);
+
+ /* list of command yet to be processed */
+ QStringList commandQueue(void) {return _commandQueue ;};
+
+ void queueMessage(const QString &text);
+
+protected:
+ QString updateText;
+
+ private:
+ bool initialized;
+ int updateTimerID;
+ QStringList _commandQueue;
+
+ signals: // Signals
+ /** line number and/or file name changed */
+ void lineNoChanged(QString /* fileName */, int /* lineNumber */, bool /* breakpoint */);
+
+ /** Show a message in debugger window */
+ void showMessage(QString /* msg*/);
+
+ /** Add breakpoint to view, First parameter is QString::null
+ to indicate start of breakpoint list notfication */
+ void breakpointItem(QString /* fileName*/, int /* lineNumber */,
+ QString /*templateName*/, QString /* modeName */,
+ bool /* enabled */, int /* id */);
+
+ /** Add global variable to view, First parameter is QString::null
+ to indicate start of global variable list notfication */
+ void globalVariableItem(QString /* name */, QString /* fileName */, int /* lineNumber */);
+
+ /** Add local variable to view, First parameter is QString::null
+ to indicate start of local variable list notfication */
+ void localVariableItem(QString /*name */, QString /* templateContext*/,
+ QString /* fileName */, int /*lineNumber */);
+
+ /** Add a variable to view, First parameter is QString::null
+ to indicate start of local variable list notfication */
+ void variableItem(QString /*name */, QString /* templateContext*/,
+ QString /* fileName */, int /*lineNumber */,
+ QString /* select XPath */, int /* is it a local variable */);
+
+ /** Add template to view, First parameter is QString::null
+ to indicate start of template list notfication */
+ void templateItem(QString /* name*/, QString /*mode*/, QString /* fileName */, int /* lineNumber */);
+
+ /** Add source to view, First parameter is QString::null
+ to indicate start of source list notfication */
+ void sourceItem(QString /* fileName */, QString /* parentFileName */, int /*lineNumber */);
+
+ /** Add parameter to view, First parameter is QString::null
+ to indicate start of parameter list notfication */
+ void parameterItem(QString /* name*/, QString /* value */);
+
+ /** Add callStack to view, First parameter is QString::null
+ to indicate start of callstack list notfication */
+ void callStackItem(QString /* tempalteName*/, QString /* fileName */, int /* lineNumber */);
+
+ /** Add entity to view, First parameter is QString::null
+ to indicate start of entity list notfication */
+ void entityItem(QString /*SystemID*/, QString /*PublicID*/);
+
+ /* Show the URI for SystemID or PublicID requested */
+ void resolveItem(QString /*URI*/);
+
+ /* Display a integer option value First parameter is QString::null
+ to indicate start of option list notification */
+ void intOptionItem(QString /* name*/, int /* value */);
+
+ /* Display a string option value. First parameter is QString::null
+ to indicate start of option list notification */
+ void stringOptionItem(QString /* name*/, QString /* value */);
+
+ /* Cause the names for source, data and output files to be reload from xsldbg */
+ void fileDetailsChanged();
+
+};
+
+#endif
diff --git a/kxsldbg/kxsldbgpart/libqtnotfier/xsldbgevent.cpp b/kxsldbg/kxsldbgpart/libqtnotfier/xsldbgevent.cpp
new file mode 100644
index 00000000..a424eaba
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libqtnotfier/xsldbgevent.cpp
@@ -0,0 +1,857 @@
+
+/***************************************************************************
+ xsldbgevent.c - event to notify app of
+ data from xsldbg
+ -------------------
+ begin : Fri Feb 1 2001
+ copyright : (C) 2001 by Keith Isdale
+ email : k_isdale@tpg.com.au
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <qapplication.h>
+#include <qtimer.h>
+#include <qfile.h>
+#include <kurl.h>
+#include <qtextstream.h>
+
+#include <libxslt/xsltInternals.h>
+
+#include "../libxsldbg/xsldbgevent.h"
+#include "xsldbgdebuggerbase.h"
+#include "../libxsldbg/arraylist.h"
+#include "../libxsldbg/breakpoint.h"
+#include "../libxsldbg/xsldbgmsg.h"
+#include "../libxsldbg/xsldbgthread.h"
+#include "../libxsldbg/options.h"
+#include "../libxsldbg/files.h"
+
+QString updateText;
+
+XsldbgEventData::XsldbgEventData()
+{
+ int column;
+
+ for (column = 0; column < XSLDBGEVENT_COLUMNS; column++){
+ textValues[column] = QString::null;
+ }
+
+ for (column = 0; column < XSLDBGEVENT_COLUMNS; column++){
+ intValues[column] = -1;
+ }
+
+}
+
+XsldbgEventData::~XsldbgEventData()
+{
+}
+
+void XsldbgEventData::setText(int column, QString text)
+{
+ if ((column >= 0) && (column < XSLDBGEVENT_COLUMNS))
+ textValues[column] = text;
+}
+
+
+QString XsldbgEventData::getText(int column)
+{
+ if ((column >= 0) && (column < XSLDBGEVENT_COLUMNS))
+ return textValues[column];
+ else
+ return QString::null;
+}
+
+
+void XsldbgEventData::setInt(int column, int value)
+{
+ if ((column >= 0) && (column < XSLDBGEVENT_COLUMNS))
+ intValues[column] = value;
+}
+
+
+int XsldbgEventData::getInt(int column)
+{
+ if ((column >= 0) && (column < XSLDBGEVENT_COLUMNS))
+ return intValues[column];
+ else
+ return -1;
+}
+
+
+XsldbgEvent::XsldbgEvent(XsldbgMessageEnum type, const void *data)
+ : QEvent(QEvent::User)
+{
+ XsldbgEventData *eventData;
+ this->data = data;
+ debugger = 0L;
+ beenCreated = false;
+
+ if (type == XSLDBG_MSG_LIST){ /* 23 : As list of messages */
+ notifyMessageListPtr msgList = (notifyMessageListPtr)data;
+ void *msgData;
+ /* If this is an included source message, which just continues a source message,
+ we don't need to add an empty XsldbgEventData */
+ if (msgList->type != XSLDBG_MSG_INCLUDED_SOURCE_CHANGED){
+ /* add an empty event data item which indicates the start of a list */
+ eventData = new XsldbgEventData();
+ if (eventData != 0L)
+ list.append(eventData);
+ }
+ for (int index = 0; index < arrayListCount(msgList->list); index++){
+ msgData = ::arrayListGet(msgList->list, index);
+ eventData = createEventData(msgList->type, msgData);
+ if (eventData != 0L)
+ list.append(eventData);
+ }
+ ::arrayListFree(msgList->list);
+ msgList->list = 0L;
+ itemType = msgList->type;
+ }else{
+ eventData = createEventData(type, data);
+ if (eventData != 0L)
+ list.append(eventData);
+ itemType = type;
+ }
+
+ beenCreated = true;
+ /* remove any knowledge of orginal data */
+ this->data = 0L;
+}
+
+
+XsldbgEvent::~XsldbgEvent()
+{
+}
+
+
+XsldbgEventData *XsldbgEvent::createEventData(XsldbgMessageEnum type, const void *msgData)
+{
+ XsldbgEventData *result = new XsldbgEventData();
+
+ if (result == 0L)
+ return result;
+
+ switch (type){
+
+ case XSLDBG_MSG_THREAD_NOTUSED: /* 0: Thread are not to be used */
+ case XSLDBG_MSG_THREAD_INIT: /* 1: The xsldbg thread is initializing */
+ case XSLDBG_MSG_THREAD_RUN: /* 2: The xsldbg thread is running */
+ case XSLDBG_MSG_THREAD_STOP: /* 3: The xsldbg thread is about to die */
+ case XSLDBG_MSG_THREAD_DEAD: /* 4: The xsldbg thread died */
+ /* we don't need to do anything extra with this message */
+ break;
+
+ /* input status ( once thread is running) */
+ case XSLDBG_MSG_AWAITING_INPUT: /* 5: Waiting for user input */
+ /* we don't need to do anything extra with this message */
+ break;
+
+ case XSLDBG_MSG_READ_INPUT: /* 6: Read user input */
+ /* we don't need to do anything extra with this message */
+ break;
+
+ case XSLDBG_MSG_PROCESSING_INPUT: /* 7: Processing user's request */
+ /* we don't need to do anything extra with this message */
+ break;
+
+ /* provide more informatiom about state of xsldbg (optional) */
+ case XSLDBG_MSG_PROCESSING_RESULT: /* 8: An error occured performing command
+ * requested command */
+ if (msgData != 0L){
+ xsldbgErrorMsgPtr msg = (xsldbgErrorMsgPtr)msgData;
+ if (msg->text)
+ result->setText(0, XsldbgDebuggerBase::fromUTF8(msg->text));
+ }
+ break;
+
+ case XSLDBG_MSG_LINE_CHANGED: /* 9: Changed to new line number
+ * ie a step */
+ handleLineNoChanged(result, msgData);
+ break;
+
+ case XSLDBG_MSG_FILE_CHANGED: /* 10: Changed selection for source/data/output file */
+ // not used
+ break;
+
+ case XSLDBG_MSG_BREAKPOINT_CHANGED: /* 11: Response to a showbreak command */
+ handleBreakpointItem(result, msgData);
+ break;
+
+ case XSLDBG_MSG_PARAMETER_CHANGED: /* 12: Response to showparam command */
+ handleParameterItem(result, msgData);
+ break;
+
+ case XSLDBG_MSG_TEXTOUT: /* 13 : Free form text from xsldg */
+ /* this is going to be most common and its so simple we can handle
+ it here */
+ result->setText(0, XsldbgDebuggerBase::fromUTF8((xmlChar*)msgData));
+ break;
+
+ case XSLDBG_MSG_FILEOUT: /* 14 : Response to cat commmand, ie
+ * Free form text in file */
+ /* this is actualy the file to load */
+ {
+ KURL url(XsldbgDebuggerBase::fromUTF8FileName((xmlChar*)msgData));
+ if (!url.isLocalFile()){
+ qDebug("Remote path to temp file %s unsupported, unable to read message from xsldbg", url.prettyURL().local8Bit().data());
+ break;
+ }
+
+ QString fileName = url.path();
+ QString outputText;
+ if (!fileName.isNull()){
+ QFile file (fileName);
+ if (file.open(IO_ReadOnly)){
+ QTextStream textFile(&file);
+ QString textIn = "";
+ textFile.setEncoding(QTextStream::UnicodeUTF8);
+ while (1){
+ textIn = textFile.readLine();
+ if (textIn.isNull())
+ break;
+ outputText.append(textIn).append("\n");
+ }
+ file.close();
+ }
+ outputText.append("\n");
+ result->setText(0, outputText);
+ }
+ }
+ break;
+
+ case XSLDBG_MSG_LOCALVAR_CHANGED: /* 15 : Response to locals command ie a
+ * local variable */
+ handleLocalVariableItem(result, msgData);
+ break;
+
+ case XSLDBG_MSG_GLOBALVAR_CHANGED: /* 16 : Response to globals command
+ * ie a global variable */
+ handleGlobalVariableItem(result, msgData);
+ break;
+
+ case XSLDBG_MSG_TEMPLATE_CHANGED: /* 17 : Response to templates commmand
+ * ie template details */
+ handleTemplateItem(result, msgData);
+ break;
+
+ case XSLDBG_MSG_SOURCE_CHANGED: /* 18 : Response to stylesheets command,
+ * a normal stylesheet */
+ handleSourceItem(result, msgData);
+ break;
+
+ case XSLDBG_MSG_INCLUDED_SOURCE_CHANGED: /* 19: Response to stylesheets
+ * command, a xmlNodeptr of
+ * a included stylesheet */
+ handleIncludedSourceItem(result, msgData);
+ break;
+
+ case XSLDBG_MSG_CALLSTACK_CHANGED: /* 20: Response to where command,
+ * ie a item on the call stack */
+ handleCallStackItem(result, msgData);
+ break;
+
+ case XSLDBG_MSG_ENTITIY_CHANGED: /* 21: Response to entities
+ * command */
+ handleEntityItem(result, msgData);
+ break;
+
+ case XSLDBG_MSG_RESOLVE_CHANGE: /* 22: Response to system or
+ * public command */
+ handleResolveItem(result, msgData);
+ break;
+
+ default:
+ qDebug("Unhandled type in createEventData %d", type);
+
+ }
+ return result;
+}
+
+void XsldbgEvent::emitMessage(XsldbgDebuggerBase *debugger)
+{
+ XsldbgEventData *eventData;
+
+ this->debugger = debugger;
+
+ for (eventData = list.first(); eventData != 0L; eventData = list.next()){
+ emitMessage(eventData);
+ }
+
+ /* make sure that we only temporarily set the value for debugger*/
+ this->debugger = 0L;
+}
+
+
+void XsldbgEvent::emitMessage(XsldbgEventData *eventData)
+{
+
+ if ((eventData == 0L) || (debugger == 0L)){
+ qDebug("emitMessage failed");
+ if (eventData == 0L)
+ qDebug("Event data == NULL");
+ if (debugger == 0L)
+ qDebug("Debugger == NULL");
+ return;
+ }
+
+ /*
+ Method use will end up like
+
+ emit debugger->lineNoChanged("", 1, false);
+
+ */
+
+ switch (itemType){
+
+ case XSLDBG_MSG_THREAD_NOTUSED: /* 0: Thread are not to be used */
+ case XSLDBG_MSG_THREAD_INIT: /* 1: The xsldbg thread is initializing */
+ case XSLDBG_MSG_THREAD_RUN: /* 2: The xsldbg thread is running */
+ /* we don't need to do anything extra with this message */
+ break;
+
+ case XSLDBG_MSG_THREAD_STOP: /* 3: The xsldbg thread is about to die */
+ case XSLDBG_MSG_THREAD_DEAD: /* 4: The xsldbg thread died */
+ /* the debugger has stopped is about to stop */
+ debugger->setInitialized(false);
+ break;
+
+ /* input status ( once thread is running) */
+ case XSLDBG_MSG_AWAITING_INPUT: /* 5: Waiting for user input */
+ if ((getInputReady() == 0) && (debugger->commandQueue().count() > 0)){
+ qDebug("Command queue not empty");
+ QTimerEvent *e = new QTimerEvent(debugger->getUpdateTimerID());
+ QApplication::postEvent(debugger, e);
+ }
+ if (!updateText.isEmpty()){
+ debugger->queueMessage(updateText);
+ updateText = "";
+ }
+ break;
+
+ case XSLDBG_MSG_READ_INPUT: /* 6: Read user input */
+ /* we don't need to do anything extra with this message */
+ break;
+
+ case XSLDBG_MSG_PROCESSING_INPUT: /* 7: Processing user's request */
+ /* we don't need to do anything extra with this message */
+ break;
+
+ /* provide more informatiom about state of xsldbg (optional) */
+ case XSLDBG_MSG_PROCESSING_RESULT: /* 8: An error occured performing command
+ * requested command */
+ if (!eventData->getText(0).isNull())
+ updateText.append(eventData->getText(0));
+ break;
+
+ case XSLDBG_MSG_LINE_CHANGED: /* 9: Changed to new line number
+ * ie a step */
+ handleLineNoChanged(eventData, 0L);
+ break;
+
+ case XSLDBG_MSG_FILE_CHANGED: /* 10: Loaded source/data file */
+ if (beenCreated == false){
+ /* Empty data */
+ }else{
+ emit debugger->fileDetailsChanged();
+ }
+ break;
+
+ case XSLDBG_MSG_BREAKPOINT_CHANGED: /* 11: Response to a showbreak command */
+ handleBreakpointItem(eventData, 0L);
+ break;
+
+ case XSLDBG_MSG_PARAMETER_CHANGED: /* 12: Response to showparam command */
+ handleParameterItem(eventData, 0L);
+ break;
+
+ case XSLDBG_MSG_TEXTOUT: /* 13 : Free form text from xsldg */
+ /* this is going to be most common and its so simple we can handle
+ it here */
+ /*
+ emit debugger->showMessage(eventData->getText(0));
+ */
+ if (!eventData->getText(0).isNull())
+ updateText.append(eventData->getText(0));
+ break;
+
+ case XSLDBG_MSG_FILEOUT: /* 14 : Response to cat commmand */
+ if (!eventData->getText(0).isNull())
+ updateText.append(eventData->getText(0));
+ break;
+
+ case XSLDBG_MSG_LOCALVAR_CHANGED: /* 15 : Response to locals command ie a
+ * local variable */
+ handleLocalVariableItem(eventData, 0L);
+ break;
+
+ case XSLDBG_MSG_GLOBALVAR_CHANGED: /* 16 : Response to globals command
+ * ie a global variable */
+ handleGlobalVariableItem(eventData, 0L);
+ break;
+
+ case XSLDBG_MSG_TEMPLATE_CHANGED: /* 17 : Response to templates commmand
+ * ie template details */
+ handleTemplateItem(eventData, 0L);
+ break;
+
+ case XSLDBG_MSG_SOURCE_CHANGED: /* 18 : Response to stylesheets command,
+ * a normal stylesheet */
+ handleSourceItem(eventData, 0L);
+ break;
+
+ case XSLDBG_MSG_INCLUDED_SOURCE_CHANGED: /* 19: Response to stylesheets
+ * command, a xmlNodeptr of
+ * a included stylesheet */
+ handleIncludedSourceItem(eventData, 0L);
+ break;
+
+ case XSLDBG_MSG_CALLSTACK_CHANGED: /* 20: Response to where command,
+ * ie a item on the call stack */
+ handleCallStackItem(eventData, 0L);
+ break;
+
+ case XSLDBG_MSG_ENTITIY_CHANGED: /* 21: Response to entities
+ * command */
+ handleEntityItem(eventData, 0L);
+ break;
+
+ case XSLDBG_MSG_RESOLVE_CHANGE: /* 22: Response to system or
+ * public command */
+ handleResolveItem(eventData, 0L);
+ break;
+
+ default:
+ qDebug("Unhandled type in emitMessage %d", itemType);
+ }
+}
+
+
+void XsldbgEvent::handleLineNoChanged(XsldbgEventData *eventData, const void *msgData)
+{
+ if (eventData != 0L){
+ if (beenCreated == false){
+ /* add our specific data to eventData*/
+ if (xsldbgUrl() != 0L){
+ eventData->setText(0, XsldbgDebuggerBase::fromUTF8FileName(xsldbgUrl()));
+ eventData->setInt(0, xsldbgLineNo());
+ eventData->setInt(1, msgData != 0L);
+ }
+ }else{
+ /* emit the event data via debugger*/
+ emit debugger->lineNoChanged(eventData->getText(0), eventData->getInt(0),
+ eventData->getInt(1));
+ }
+ }
+}
+
+
+void XsldbgEvent::handleShowMessage(XsldbgEventData *eventData, const void *msgData)
+{
+ if (eventData != 0L){
+ if (beenCreated == false){
+ /* add our specific data to eventData*/
+ if (msgData != 0L){
+ eventData->setText(0, XsldbgDebuggerBase::fromUTF8((xmlChar*)msgData));
+ }
+ }else{
+ /* emit the event data via debugger*/
+ emit debugger->showMessage(eventData->getText(0));
+ }
+ }
+}
+
+
+void XsldbgEvent::handleBreakpointItem(XsldbgEventData *eventData, const void *msgData)
+{
+ if (eventData != 0L){
+ if (beenCreated == false){
+ /* add our specific data to eventData*/
+ if (msgData != 0L){
+ breakPointPtr breakItem = (breakPointPtr)msgData;
+ /* set the file name*/
+ eventData->setText(0, XsldbgDebuggerBase::fromUTF8FileName(breakItem->url));
+ /* line number*/
+ eventData->setInt(0, (int)breakItem->lineNo);
+
+ /* templateName */
+ eventData->setText(1, XsldbgDebuggerBase::fromUTF8(breakItem->templateName));
+
+ /* modeName */
+ eventData->setText(2, XsldbgDebuggerBase::fromUTF8(breakItem->modeName));
+ /* enabled state */
+ eventData->setInt(1, (int)(breakItem->flags & BREAKPOINT_ENABLED));
+
+ /* id value */
+ eventData->setInt(2, (int)breakItem->id);
+ }
+ }else{
+ /* emit the event data via debugger*/
+ emit debugger->breakpointItem(eventData->getText(0), /* file name*/
+ eventData->getInt(0), /* line number*/
+ eventData->getText(1), /* template name */
+ eventData->getText(2), /* mode name */
+ eventData->getInt(1), /* enabled state*/
+ eventData->getInt(2) /* id*/);
+ }
+ }
+}
+
+
+void XsldbgEvent::handleGlobalVariableItem(XsldbgEventData *eventData, const void *msgData)
+{
+ if (eventData != 0L){
+ if (beenCreated == false){
+ /* add our specific data to eventData*/
+ if (msgData != 0L){
+ xsltStackElemPtr item = (xsltStackElemPtr)msgData;
+ QString name, fileName, selectXPath;
+ int lineNumber = -1;
+
+ /* variable name*/
+ if (item->nameURI)
+ name = (XsldbgDebuggerBase::fromUTF8FileName(item->nameURI)).append(":");
+ name.append(XsldbgDebuggerBase::fromUTF8(item->name));
+
+
+
+ if (item->computed && item->comp && item->comp->inst && item->comp->inst->doc){
+ fileName = XsldbgDebuggerBase::fromUTF8FileName(item->comp->inst->doc->URL);
+ lineNumber= xmlGetLineNo(item->comp->inst);
+ }
+
+ if (item->select)
+ selectXPath = XsldbgDebuggerBase::fromUTF8(item->select);
+
+ eventData->setText(0, name);
+ eventData->setText(1, "");
+ eventData->setText(2, fileName);
+ eventData->setText(3, selectXPath);
+ eventData->setInt(0, lineNumber);
+ eventData->setInt(1, 0);
+ }
+ }else{
+ /* emit the event data via debugger*/
+ emit debugger->variableItem(eventData->getText(0), /* variable name*/
+ eventData->getText(1), /* templatecontext*/
+ eventData->getText(2), /* file name */
+ eventData->getInt(0), /* line number */
+ eventData->getText(3), /* select XPath */
+ eventData->getInt(1) /* Is this a local variable */ );
+ }
+ }
+}
+
+
+void XsldbgEvent::handleLocalVariableItem(XsldbgEventData *eventData, const void *msgData)
+{
+ if (eventData != 0L){
+ if (beenCreated == false){
+ /* add our specific data to eventData*/
+ if (msgData != 0L){
+ xsltStackElemPtr item = (xsltStackElemPtr)msgData;
+ QString name, templateContext, fileName, selectXPath;
+ int lineNumber = -1;
+ xmlNodePtr varXmlNode;
+
+ /* variable name */
+ if (item->nameURI)
+ name = (XsldbgDebuggerBase::fromUTF8FileName(item->nameURI)).append(":");
+ name.append(XsldbgDebuggerBase::fromUTF8(item->name));
+
+ if (item->computed && item->comp && item->comp->inst){
+ varXmlNode = item->comp->inst;
+
+ /* try to find out what template this variable belongs to */
+ if (varXmlNode->parent && IS_XSLT_NAME(varXmlNode->parent, "template")) {
+ xmlChar* value = xmlGetProp(varXmlNode->parent, (xmlChar *) "name");
+ if (value) {
+ templateContext = XsldbgDebuggerBase::fromUTF8(value);
+ xmlFree(value);
+ }else{
+ value = xmlGetProp(varXmlNode->parent, (xmlChar *) "match");
+ if (value) {
+ templateContext = XsldbgDebuggerBase::fromUTF8(value);
+ xmlFree(value);
+ }
+ }
+ }
+
+ if (varXmlNode->doc) {
+ fileName = XsldbgDebuggerBase::fromUTF8FileName(varXmlNode->doc->URL);
+ lineNumber = xmlGetLineNo(varXmlNode);
+ }
+
+ if (item->select)
+ selectXPath = XsldbgDebuggerBase::fromUTF8(item->select);
+
+ eventData->setText(0, name);
+ eventData->setText(1, templateContext);
+ eventData->setText(2, fileName);
+ eventData->setText(3, selectXPath);
+ eventData->setInt(0, lineNumber);
+ eventData->setInt(1, 1);
+ }
+ }
+ }else{
+ /* emit the event data via debugger*/
+ emit debugger->variableItem(eventData->getText(0), /* variable name*/
+ eventData->getText(1), /* templatecontext*/
+ eventData->getText(2), /* file name */
+ eventData->getInt(0), /* line number */
+ eventData->getText(3), /* select XPath */
+ eventData->getInt(1) /* Is this a local variable */ );
+ }
+ }
+}
+
+
+void XsldbgEvent::handleTemplateItem(XsldbgEventData *eventData, const void *msgData)
+{
+if (eventData != 0L){
+ if (beenCreated == false){
+ /* add our specific data to eventData*/
+ if(msgData != 0L){
+ xsltTemplatePtr item = (xsltTemplatePtr)msgData;
+ QString name, mode, fileName;
+ int lineNumber = -1;
+
+ if (item->nameURI)
+ name.append(XsldbgDebuggerBase::fromUTF8FileName(item->nameURI)).append(":");
+
+ if (item->name)
+ name.append(XsldbgDebuggerBase::fromUTF8(item->name));
+ else if (item->match)
+ name.append(XsldbgDebuggerBase::fromUTF8(item->match));
+
+ mode = XsldbgDebuggerBase::fromUTF8(item->mode);
+
+ if (item->elem && item->elem->doc){
+ fileName = XsldbgDebuggerBase::fromUTF8FileName(item->elem->doc->URL);
+ lineNumber = xmlGetLineNo(item->elem);
+ }
+ eventData->setText(0, name);
+ eventData->setText(1, mode);
+ eventData->setText(2, fileName);
+ eventData->setInt(0, lineNumber);
+ }
+ }else{
+ /* emit the event data via debugger*/
+ emit debugger->templateItem(eventData->getText(0), /* tempalte name*/
+ eventData->getText(1), /* mode*/
+ eventData->getText(2), /* file name*/
+ eventData->getInt(0) /* line number*/);
+ }
+ }
+
+}
+
+
+void XsldbgEvent::handleIncludedSourceItem(XsldbgEventData *eventData, const void *msgData)
+{
+ if (eventData != 0L){
+ if (beenCreated == false){
+ /* add our specific data to eventData*/
+ if (msgData != 0L){
+ xmlNodePtr item = (xmlNodePtr)msgData;
+ QString name, fileName;
+ int lineNumber = -1;
+
+ if (item->doc)
+ name = XsldbgDebuggerBase::fromUTF8FileName(item->doc->URL);
+
+ if (item->parent && item->parent->doc){
+ fileName = XsldbgDebuggerBase::fromUTF8FileName(item->parent->doc->URL);
+ lineNumber = xmlGetLineNo((xmlNodePtr)item->parent->doc);
+ }
+ eventData->setText(0, name);
+ eventData->setText(1, fileName);
+ eventData->setInt(0, lineNumber);
+ }
+ }else{
+ /* emit the event data via debugger*/
+ emit debugger->sourceItem(eventData->getText(0), /* file name*/
+ eventData->getText(1), /* parent file name*/
+ eventData->getInt(0) /* parent line number*/);
+ }
+ }
+}
+
+void XsldbgEvent::handleSourceItem(XsldbgEventData *eventData, const void *msgData)
+{
+ if (eventData != 0L){
+ if (beenCreated == false){
+ /* add our specific data to eventData*/
+ if (msgData != 0L){
+ xsltStylesheetPtr item = (xsltStylesheetPtr)msgData;
+ QString name, fileName;
+ int lineNumber = -1;
+
+ if (item->doc)
+ name = XsldbgDebuggerBase::fromUTF8FileName(item->doc->URL);
+
+ if (item->parent && item->parent->doc){
+ fileName = XsldbgDebuggerBase::fromUTF8FileName(item->parent->doc->URL);
+ lineNumber = xmlGetLineNo((xmlNodePtr)item->parent->doc);
+ }
+
+ eventData->setText(0, name);
+ eventData->setText(1, fileName);
+ eventData->setInt(0, lineNumber);
+ }
+ }else{
+ /* emit the event data via debugger*/
+ emit debugger->sourceItem(eventData->getText(0), /* name*/
+ eventData->getText(1), /* parent file name*/
+ eventData->getInt(0) /* parent line number*/);
+ }
+ }
+}
+
+void XsldbgEvent::handleParameterItem(XsldbgEventData *eventData, const void *msgData)
+{
+ if (eventData != 0L){
+ if (beenCreated == false){
+ /* add our specific data to eventData*/
+ if (msgData != 0L){
+ parameterItemPtr paramItem = (parameterItemPtr)msgData;
+ QString name, value;
+
+ name = XsldbgDebuggerBase::fromUTF8(paramItem->name);
+ value = XsldbgDebuggerBase::fromUTF8(paramItem->value);
+
+ eventData->setText(0, name);
+ eventData->setText(1, value);
+ }
+ }else{
+ /* emit the event data via debugger*/
+ emit debugger->parameterItem(eventData->getText(0), /* param name*/
+ eventData->getText(1) /* param value*/);
+ }
+ }
+}
+
+
+void XsldbgEvent::handleCallStackItem(XsldbgEventData *eventData, const void *msgData)
+{
+ if (eventData != 0L){
+ if (beenCreated == false){
+ /* add our specific data to eventData*/
+ if (msgData != 0L){
+ callPointPtr item = (callPointPtr)msgData;
+ QString templateName, fileName;
+ int lineNumber = -1;
+
+ /* template name */
+ if (item->info){
+ templateName = XsldbgDebuggerBase::fromUTF8(item->info->templateName);
+ fileName = XsldbgDebuggerBase::fromUTF8FileName(item->info->url);
+ lineNumber = item->lineNo;
+ }
+
+ eventData->setText(0, templateName);
+ eventData->setText(1, fileName);
+ eventData->setInt(0, lineNumber);
+ }
+ }else{
+ /* emit the event data via debugger*/
+ emit debugger->callStackItem(eventData->getText(0), /* template name*/
+ eventData->getText(1), /* fileName */
+ eventData->getInt(0) /* line number*/);
+ }
+ }
+}
+
+
+void XsldbgEvent::handleEntityItem(XsldbgEventData *eventData, const void *msgData)
+{
+ if (eventData != 0L){
+ if (beenCreated == false){
+ /* add our specific data to eventData*/
+ if (msgData != 0L){
+ QString SystemID, PublicID;
+
+ entityInfoPtr info = (entityInfoPtr)msgData;
+ SystemID = XsldbgDebuggerBase::fromUTF8FileName(info->SystemID);
+ PublicID = XsldbgDebuggerBase::fromUTF8(info->PublicID);
+
+ eventData->setText(0, SystemID);
+ eventData->setText(1, PublicID);
+ }
+ }else{
+ /* emit the event data via debugger*/
+ emit debugger->entityItem(eventData->getText(0), /* SystemID*/
+ eventData->getText(1) /* PublicID*/);
+ }
+ }
+}
+
+
+void XsldbgEvent::handleResolveItem(XsldbgEventData *eventData, const void *msgData)
+{
+ if (eventData != 0L){
+ if (beenCreated == false){
+ /* add our specific data to eventData*/
+ if (msgData != 0L){
+ QString URI = XsldbgDebuggerBase::fromUTF8FileName((const xmlChar*)msgData);
+
+ eventData->setText(0, URI);
+ }
+ }else{
+ /* emit the event data via debugger*/
+ emit debugger->resolveItem(eventData->getText(0) /* URI */);
+ }
+ }
+}
+
+
+void XsldbgEvent::handleIntOptionItem(XsldbgEventData *eventData, const void *msgData)
+{
+ if (eventData != 0L){
+ if (beenCreated == false){
+ /* add our specific data to eventData*/
+ if (msgData != 0L){
+ parameterItemPtr paramItem = (parameterItemPtr)msgData;
+ eventData->setText(0, XsldbgDebuggerBase::fromUTF8(paramItem->name));
+ eventData->setInt(0, paramItem->intValue);
+ }
+ }else{
+ /* emit the event data via debugger*/
+ emit debugger->intOptionItem(eventData->getText(0), /* option name*/
+ eventData->getInt(0) /* value*/);
+ }
+ }
+}
+
+
+void XsldbgEvent::handleStringOptionItem(XsldbgEventData *eventData, const void *msgData)
+{
+ if (eventData != 0L){
+ if (beenCreated == false){
+ /* add our specific data to eventData*/
+ if (msgData != 0L){
+ parameterItemPtr paramItem = (parameterItemPtr)msgData;
+ eventData->setText(0, XsldbgDebuggerBase::fromUTF8(paramItem->name));
+ eventData->setText(1, XsldbgDebuggerBase::fromUTF8(paramItem->value));
+ }
+ }else{
+ /* emit the event data via debugger*/
+ emit debugger->stringOptionItem(eventData->getText(0), /* option name*/
+ eventData->getText(1) /* value*/);
+ }
+ }
+}
+
+
+
+void XsldbgEventDataList::deleteItem( QPtrCollection::Item d )
+{
+ if ( del_item ) delete (XsldbgEventData *)d;
+}
diff --git a/kxsldbg/kxsldbgpart/libqtnotfier/xsldbgnotifier.cpp b/kxsldbg/kxsldbgpart/libqtnotfier/xsldbgnotifier.cpp
new file mode 100644
index 00000000..d76c6678
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libqtnotfier/xsldbgnotifier.cpp
@@ -0,0 +1,33 @@
+/***************************************************************************
+ xsldbgnotifier.cpp - description
+ -------------------
+ begin : Thu Dec 20 2001
+ copyright : (C) 2001 by keith
+ email : keith@linux
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "../libxsldbg/xsldbgnotifier.h"
+
+XsldbgNotifier::XsldbgNotifier(void)
+{
+}
+
+
+XsldbgNotifier::~XsldbgNotifier(void)
+{
+}
+
+
+void XsldbgNotifier::doNotify(XsldbgMessageEnum /*type*/, const void * /*data*/)
+{
+}
+
diff --git a/kxsldbg/kxsldbgpart/libqtnotfier/xsldbgthread.cpp b/kxsldbg/kxsldbgpart/libqtnotfier/xsldbgthread.cpp
new file mode 100644
index 00000000..1f428bb5
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libqtnotfier/xsldbgthread.cpp
@@ -0,0 +1,360 @@
+/***************************************************************************
+ xsldbgthread.cpp - description
+ -------------------
+ begin : Thu Dec 20 2001
+ copyright : (C) 2001 by keith
+ email : keith@linux
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+
+#include "config.h"
+#include <pthread.h> /* need to create/work with process thread */
+#include <errno.h> /* need for EAGAIN */
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdarg.h>
+
+#include <libxml/xmlerror.h>
+
+#include "../libxsldbg/breakpoint.h"
+#include "../libxsldbg/xsldbgmsg.h"
+#include "../libxsldbg/xsldbgthread.h"
+#include "../libxsldbg/qtnotifier2.h"
+
+#ifdef HAVE_READLINE
+#include <readline/readline.h>
+#ifdef HAVE_HISTORY
+#include <readline/history.h>
+#endif
+#endif
+
+#define DEBUG_BUFFER_SIZE 500
+
+static char inputBuffer[DEBUG_BUFFER_SIZE];
+static char outputBuffer[DEBUG_BUFFER_SIZE];
+
+/*the major structure to hold information about the process thread */
+pthread_t mythread;
+
+/* The reader for stdout */
+pthread_t stdoutReaderThread;
+
+FILE *stdoutIO = NULL;
+
+
+/* -----------------------------------------------
+ private functions
+ ---------------------------------------------------*/
+
+extern "C" {
+
+/**
+ * xsldbgGenericErrorFunc:
+ * @ctx: Is Valid
+ * @msg: Is valid
+ * @...: other parameters to use
+ *
+ * Handles print output from xsldbg and passes it to the application
+ */
+void
+xsldbgGenericErrorFunc(void *ctx, const char *msg, ...);
+xmlChar * qtXslDbgShellReadline(xmlChar * prompt);
+
+}
+
+/* -----------------------------------------------
+ end functions
+ ---------------------------------------------------*/
+
+/* setup all application wide items */
+int
+xsldbgThreadInit(void)
+{
+ int result = 0;
+ fprintf(stderr, "mainInit()\n");
+ xsltSetGenericErrorFunc(0, xsldbgGenericErrorFunc);
+ setThreadStatus(XSLDBG_MSG_THREAD_INIT);
+ xsldbgSetAppFunc(qtNotifyXsldbgApp);
+ xsldbgSetAppStateFunc(qtNotifyStateXsldbgApp);
+ xsldbgSetTextFunc(qtNotifyTextXsldbgApp);
+ xsldbgSetReadlineFunc(qtXslDbgShellReadline);
+
+
+ /* create the thread */
+ if (pthread_create(&mythread, NULL, xsldbgThreadMain, NULL) != EAGAIN) {
+ int counter;
+ for (counter = 0; counter < 11; counter++){
+ if (getThreadStatus() != XSLDBG_MSG_THREAD_INIT)
+ break;
+ usleep(250000); /*guess that it will take at most 2.5 seconds to startup */
+ }
+ /* xsldbg should have started by now if it can */
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN){
+ fprintf(stderr, "Created thread\n");
+ result++;
+ }else
+ fprintf(stderr, "Thread did not start\n");
+ } else {
+ fprintf(stderr, "Failed to create thread\n");
+ }
+
+ return result;
+}
+
+
+/* tell the thread to stop and free that memory !*/
+void
+xsldbgThreadFree(void)
+{
+ fprintf(stderr, "xsldbgThreadFree()\n");
+ if (getThreadStatus() != XSLDBG_MSG_THREAD_DEAD)
+ {
+ int counter;
+ fprintf(stderr, "Killing xsldbg thread\n");
+ setThreadStatus(XSLDBG_MSG_THREAD_STOP);
+ for (counter = 0; counter < 11; counter++){
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_DEAD)
+ break;
+ usleep(250000); /*guess that it will take at most 2.5 seconds to stop */
+ }
+ }
+
+}
+
+const char *getFakeInput()
+{
+ return inputBuffer;
+}
+
+
+/* put text into standard input just like we had typed it */
+int
+fakeInput(const char *text)
+{
+ int result = 0;
+
+ if (!text || (getInputReady() == 1) || (getThreadStatus() != XSLDBG_MSG_THREAD_RUN))
+ return result;
+
+ // fprintf(stderr, "\nFaking input of \"%s\"\n", text);
+ strncpy(inputBuffer, text, sizeof(inputBuffer));
+ setInputReady(1);
+ result++;
+ return result;
+}
+
+
+/* use this function instead of the one that was in debugXSL.c */
+/**
+ * qtXslDbgShellReadline:
+ * @prompt: the prompt value
+ *
+ * Read a string
+ *
+ * Returns a copy of the text inputed or NULL if EOF in stdin found.
+ * The caller is expected to free the returned string.
+ */
+xmlChar *
+qtXslDbgShellReadline(xmlChar * prompt)
+{
+
+ const char *inputReadBuff;
+
+ static char last_read[DEBUG_BUFFER_SIZE] = { '\0' };
+
+ if (getThreadStatus() != XSLDBG_MSG_THREAD_RUN)
+ {
+#ifdef HAVE_READLINE
+ xmlChar *line_read;
+
+ /* Get a line from the user. */
+ line_read = (xmlChar *) readline((char *) prompt);
+
+ /* If the line has any text in it, save it on the history. */
+ if (line_read && *line_read) {
+ add_history((char *) line_read);
+ strncpy((char*)last_read, (char*)line_read, DEBUG_BUFFER_SIZE - 1);
+ } else {
+ /* if only <Enter>is pressed then try last saved command line */
+ line_read = (xmlChar *) xmlMemStrdup(last_read);
+ }
+ return (line_read);
+#else
+ char line_read[DEBUG_BUFFER_SIZE];
+
+ if (prompt != NULL)
+ xsltGenericError(xsltGenericErrorContext, "%s", prompt);
+ if (!fgets(line_read, DEBUG_BUFFER_SIZE - 1, stdin))
+ return (NULL);
+ line_read[DEBUG_BUFFER_SIZE - 1] = 0;
+ /* if only <Enter>is pressed then try last saved command line */
+ if ((strlen(line_read) == 0) || (line_read[0] == '\n')) {
+ strcpy(line_read, last_read);
+ } else {
+ strcpy(last_read, line_read);
+ }
+ return (xmlChar *) xmlMemStrdup(line_read);
+#endif
+
+ }
+ else{
+
+ setInputStatus(XSLDBG_MSG_AWAITING_INPUT);
+ notifyXsldbgApp(XSLDBG_MSG_AWAITING_INPUT, NULL);
+
+ while (getInputReady() == 0){
+ usleep(10000);
+ /* have we been told to die */
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_STOP){
+ fprintf(stderr, "About to stop thread\n");
+ xslDebugStatus = DEBUG_QUIT;
+ return NULL;
+ }
+ }
+
+ setInputStatus(XSLDBG_MSG_READ_INPUT);
+ inputReadBuff = getFakeInput();
+ if(inputReadBuff){
+ notifyXsldbgApp(XSLDBG_MSG_READ_INPUT, inputReadBuff);
+ return (xmlChar*)xmlMemStrdup(inputReadBuff);
+ }else{
+ return NULL;
+ }
+ }
+}
+
+
+xsldbgErrorMsg msg;
+xsldbgErrorMsgPtr msgPtr = &msg;
+xmlChar *msgText = NULL;
+
+int qtNotifyStateXsldbgApp(XsldbgMessageEnum type, int commandId,
+ XsldbgCommandStateEnum commandState, const char *text)
+{
+ int result = 0;
+ msg.type = type;
+ msg.commandId = commandId;
+ msg.commandState = commandState;
+ if (text != NULL)
+ {
+ msg.text = (xmlChar*)xmlMemStrdup(text);
+ if (msg.text == NULL)
+ return result; /* out of memory */
+ }
+ else
+ msg.text = NULL;
+
+ notifyXsldbgApp(XSLDBG_MSG_PROCESSING_RESULT, msgPtr);
+ if (msg.text != NULL)
+ {
+ xmlFree(msg.text);
+ msg.text = NULL;
+ }
+
+ result = 1;
+ return result;
+}
+
+
+int qtNotifyTextXsldbgApp(XsldbgMessageEnum type, const char *text)
+{
+ return qtNotifyStateXsldbgApp(type, -1, XSLDBG_COMMAND_NOTUSED, text);
+}
+
+char mainBuffer[DEBUG_BUFFER_SIZE];
+static void xsldbgThreadCleanupQt(void);
+
+
+/* this is where the thread get to do all its work */
+void *
+xsldbgThreadMain(void *)
+{
+ // int defaultArgc = 2;
+ // char *defaultArgv[2];
+ // int i;
+
+ if (getThreadStatus() != XSLDBG_MSG_THREAD_INIT){
+ fprintf(stderr, "xsldbg thread is not ready to be started. Or one is already running.\n");
+ return NULL; /* we can't start more than one thread of xsldbg */
+ }
+
+// defaultArgv[0] = xmlMemStrdup("xsldbg");
+// defaultArgv[1] = xmlMemStrdup("--shell");
+ /*
+ defaultArgv[2] = xmlMemStrdup("xsldoc.xsl");
+ defaultArgv[3] = xmlMemStrdup("xsldoc.xml");
+ */
+/* for (i = 0; i < defaultArgc; i++){
+ if (defaultArgv[i] == NULL){
+ fprintf(stderr, "Start thread failed. Unable to create xsldbg arguments\n");
+ return NULL;
+ }
+ }
+*/
+ xsldbgSetThreadCleanupFunc(xsldbgThreadCleanupQt);
+ setThreadStatus(XSLDBG_MSG_THREAD_RUN);
+ setInputStatus(XSLDBG_MSG_AWAITING_INPUT);
+ fprintf(stderr, "Starting thread\n");
+
+ /* call the "main of xsldbg" found in debugXSL.c */
+// xsldbgMain(defaultArgc, defaultArgv);
+ xsldbgMain(0,0);
+ fprintf(stderr, "Stopping thread\n");
+/*
+ for (i = 0; i < defaultArgc; i++){
+ xmlFree(defaultArgv[i]);
+ }
+*/
+
+ setThreadStatus(XSLDBG_MSG_THREAD_DEAD);
+ setInputStatus(XSLDBG_MSG_PROCESSING_INPUT);
+ notifyXsldbgApp(XSLDBG_MSG_THREAD_DEAD, NULL);
+ return NULL;
+}
+
+
+
+/* thread has died so cleanup after it not called directly but via
+ notifyXsldbgApp*/
+void
+xsldbgThreadCleanupQt(void)
+{
+ fprintf(stderr, "Thread has finished\n");
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN)
+ {
+ xsldbgThreadFree();
+ }
+ /* its safe to modify threadStatus as the thread is now dead */
+ setThreadStatus(XSLDBG_MSG_THREAD_DEAD);
+}
+
+
+
+void *
+xsldbgThreadStdoutReader(void *data)
+{
+ if (!stdoutIO)
+ return data;
+
+ while (getThreadStatus() == XSLDBG_MSG_THREAD_RUN){
+ if (fgets(outputBuffer, sizeof(outputBuffer -1), stdoutIO)){
+ usleep(10000);
+ strcat(outputBuffer, "\n");
+ notifyTextXsldbgApp(XSLDBG_MSG_TEXTOUT, outputBuffer);
+ }else{
+ fprintf(stderr, "Unable to read from stdout from xsldbg\n");
+ break;
+ }
+ }
+ return data;
+}