summaryrefslogtreecommitdiffstats
path: root/kxsldbg
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
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')
-rw-r--r--kxsldbg/Makefile.am66
-rw-r--r--kxsldbg/configure.in.in176
-rw-r--r--kxsldbg/data/Makefile.am16
-rw-r--r--kxsldbg/data/empty.xml12
-rw-r--r--kxsldbg/data/empty.xsl19
-rw-r--r--kxsldbg/data/test1.xml17
-rw-r--r--kxsldbg/data/test2.xml30
-rw-r--r--kxsldbg/data/test3.xml29
-rw-r--r--kxsldbg/data/test4.xml27
-rw-r--r--kxsldbg/data/test_import.xsl17
-rw-r--r--kxsldbg/data/test_include_bot.xsl17
-rw-r--r--kxsldbg/data/test_include_top.xsl17
-rw-r--r--kxsldbg/data/testdoc.dtd6
-rw-r--r--kxsldbg/data/testdoc.xml33
-rw-r--r--kxsldbg/data/testdoc.xsl141
-rw-r--r--kxsldbg/kxsldbg.cpp173
-rw-r--r--kxsldbg/kxsldbg.desktop53
-rw-r--r--kxsldbg/kxsldbg.h84
-rw-r--r--kxsldbg/kxsldbg_shell.rc29
-rw-r--r--kxsldbg/kxsldbgif.h17
-rw-r--r--kxsldbg/kxsldbgpart/Makefile.am31
-rw-r--r--kxsldbg/kxsldbgpart/dummy.cpp0
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-1downarrow.pngbin0 -> 865 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-configure.pngbin0 -> 1055 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-exit.pngbin0 -> 882 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-hash.pngbin0 -> 591 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-mark.pngbin0 -> 440 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-next.pngbin0 -> 835 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-run.pngbin0 -> 1114 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-step.pngbin0 -> 466 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-xsldbg_break.pngbin0 -> 661 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-xsldbg_data.pngbin0 -> 580 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-xsldbg_delete.pngbin0 -> 892 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-xsldbg_enable.pngbin0 -> 512 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-xsldbg_output.pngbin0 -> 936 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-xsldbg_refresh.pngbin0 -> 910 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-xsldbg_source.pngbin0 -> 576 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-xsldbg_stepdown.pngbin0 -> 260 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi16-action-xsldbg_stepup.pngbin0 -> 245 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi22-action-1downarrow.pngbin0 -> 1357 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi22-action-configure.pngbin0 -> 3797 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi22-action-exit.pngbin0 -> 1398 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi22-action-next.pngbin0 -> 1311 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi22-action-run.pngbin0 -> 1354 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi22-action-step.pngbin0 -> 473 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi22-action-xsldbg_break.pngbin0 -> 769 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi22-action-xsldbg_data.pngbin0 -> 268 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi22-action-xsldbg_delete.pngbin0 -> 951 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi22-action-xsldbg_enable.pngbin0 -> 246 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi22-action-xsldbg_output.pngbin0 -> 1471 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi22-action-xsldbg_refresh.pngbin0 -> 1420 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi22-action-xsldbg_source.pngbin0 -> 345 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi22-action-xsldbg_stepdown.pngbin0 -> 166 bytes
-rw-r--r--kxsldbg/kxsldbgpart/hi22-action-xsldbg_stepup.pngbin0 -> 165 bytes
-rw-r--r--kxsldbg/kxsldbgpart/kxsldbg_part.cpp875
-rw-r--r--kxsldbg/kxsldbgpart/kxsldbg_part.desktop15
-rw-r--r--kxsldbg/kxsldbgpart/kxsldbg_part.h170
-rw-r--r--kxsldbg/kxsldbgpart/kxsldbg_part.rc61
-rw-r--r--kxsldbg/kxsldbgpart/kxsldbg_partif.h14
-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
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/Makefile.am12
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/allmoc.cpp2
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/arraylist.cpp240
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/arraylist.h291
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/breakpoint.cpp696
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/breakpoint.h633
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/breakpoint_cmds.cpp1036
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/callstack.cpp509
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/callstack.h275
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/cmds.h197
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/debug.cpp235
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/debug.h101
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/debugXSL.cpp2118
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/debugXSL.h1078
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/file_cmds.cpp274
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/files.cpp1420
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/files.h981
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/files_unix.cpp225
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/help.h73
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/help_unix.cpp115
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/nodeview_cmds.cpp609
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/option_cmds.cpp299
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/options.cpp902
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/options.h476
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/options_unix.cpp118
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/os_cmds.cpp100
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/param_cmds.cpp175
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/qtnotifier2.h38
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/search.cpp1584
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/search.h1087
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/search_cmds.cpp88
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/template_cmds.cpp331
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/trace_cmds.cpp77
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/utils.cpp187
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/utils.h217
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/variable_cmds.cpp114
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/xsldbg.cpp1367
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/xsldbg.h188
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/xsldbgconfig.h0
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/xsldbgevent.h302
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/xsldbgio.h41
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/xsldbgmsg.cpp119
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/xsldbgmsg.h210
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/xsldbgnotifier.h48
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/xsldbgthread.cpp184
-rw-r--r--kxsldbg/kxsldbgpart/libxsldbg/xsldbgthread.h90
-rw-r--r--kxsldbg/kxsldbgpart/qxsldbgdoc.cpp162
-rw-r--r--kxsldbg/kxsldbgpart/qxsldbgdoc.h56
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgbreakpointlistitem.cpp46
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgbreakpointlistitem.h51
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgbreakpoints.ui582
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgbreakpointsimpl.cpp202
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgbreakpointsimpl.h71
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgcallstack.ui157
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgcallstackimpl.cpp71
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgcallstackimpl.h53
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgconfig.ui817
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgconfigimpl.cpp499
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgconfigimpl.h151
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgdebugger.cpp474
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgdebugger.h176
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgdialogbase.cpp39
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgdialogbase.h46
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgdoc.cpp61
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgdoc.h28
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgdocmap.h5
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgentities.ui161
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgentitiesimpl.cpp79
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgentitiesimpl.h53
-rw-r--r--kxsldbg/kxsldbgpart/xsldbggloballistitem.cpp38
-rw-r--r--kxsldbg/kxsldbgpart/xsldbggloballistitem.h41
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgglobalvariables.ui272
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgglobalvariablesimpl.cpp77
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgglobalvariablesimpl.h55
-rw-r--r--kxsldbg/kxsldbgpart/xsldbginspector.cpp210
-rw-r--r--kxsldbg/kxsldbgpart/xsldbginspector.h67
-rw-r--r--kxsldbg/kxsldbgpart/xsldbglistitem.cpp46
-rw-r--r--kxsldbg/kxsldbgpart/xsldbglistitem.h45
-rw-r--r--kxsldbg/kxsldbgpart/xsldbglocallistitem.cpp59
-rw-r--r--kxsldbg/kxsldbgpart/xsldbglocallistitem.h51
-rw-r--r--kxsldbg/kxsldbgpart/xsldbglocalvariables.ui374
-rw-r--r--kxsldbg/kxsldbgpart/xsldbglocalvariablesimpl.cpp121
-rw-r--r--kxsldbg/kxsldbgpart/xsldbglocalvariablesimpl.h60
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgmsgdialog.ui175
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgmsgdialogimpl.h30
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgoutputview.cpp156
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgoutputview.h51
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgsources.ui154
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgsourcesimpl.cpp73
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgsourcesimpl.h53
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgtemplatelistitem.cpp32
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgtemplatelistitem.h44
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgtemplates.ui100
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgtemplatesimpl.cpp68
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgtemplatesimpl.h55
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgwalkspeed.ui239
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgwalkspeedimpl.cpp49
-rw-r--r--kxsldbg/kxsldbgpart/xsldbgwalkspeedimpl.h45
-rw-r--r--kxsldbg/lo16-app-kxsldbg.pngbin0 -> 377 bytes
-rw-r--r--kxsldbg/lo32-app-kxsldbg.pngbin0 -> 576 bytes
-rw-r--r--kxsldbg/main.cpp38
-rw-r--r--kxsldbg/output.txt50
-rw-r--r--kxsldbg/simpleio.c144
-rw-r--r--kxsldbg/xsldbgmain.cpp256
170 files changed, 30535 insertions, 0 deletions
diff --git a/kxsldbg/Makefile.am b/kxsldbg/Makefile.am
new file mode 100644
index 00000000..e70c4127
--- /dev/null
+++ b/kxsldbg/Makefile.am
@@ -0,0 +1,66 @@
+bin_PROGRAMS = kxsldbg xsldbg
+
+kxsldbg_SOURCES = kxsldbg.cpp main.cpp kxsldbgif.skel
+noinst_HEADERS = kxsldbg.h
+kxsldbg_DEPENDENCIES = ./kxsldbgpart/libqtnotfier/libqtnotfier.la ./kxsldbgpart/libkxsldbgcommon.la ./kxsldbgpart/libxsldbg/libxsldbg.la
+kxsldbg_LDADD = ./kxsldbgpart/libqtnotfier/libqtnotfier.la ./kxsldbgpart/libkxsldbgcommon.la ./kxsldbgpart/libxsldbg/libxsldbg.la $(LIB_KDEUI) $(LIBXSLT_LIBS) $(LIBXML_LIBS) $(LIB_KPARTS)
+
+SUBDIRS = kxsldbgpart
+
+xdg_apps_DATA = kxsldbg.desktop
+
+# Disable building xsldbg application as documentation for it is not ready
+#
+xsldbg_SOURCES = xsldbgmain.cpp
+
+xsldbg_CFLAGS = $(XSLDBG_CFLAGS) $(all_includes)
+
+xsldbg_DEPENDENCIES = kxsldbgpart/libxsldbg/libxsldbg.la
+
+# use of configure defined libraries
+xsldbg_LDADD = kxsldbgpart/libxsldbg/libxsldbg.la $(LIBXSLT_LIBS) $(LIBXML_LIBS) $(LIB_KDEUI)
+#
+# the library search path.
+xsldbg_LDFLAGS = $(all_libraries) $(XSLDBG_EXTRA_LIBS)
+
+# These paths are KDE specific. Use them:
+# kde_appsdir Where your application's menu entry (.desktop) should go to.
+# kde_icondir Where your icon should go to - better use KDE_ICON.
+# kde_sounddir Where your sounds should go to.
+# kde_htmldir Where your docs should go to. (contains lang subdirs)
+# kde_datadir Where you install application data. (Use a subdir)
+# kde_locale Where translation files should go to. (contains lang subdirs)
+# kde_cgidir Where cgi-bin executables should go to.
+# kde_confdir Where config files should go to (system-wide ones with default values).
+# kde_mimedir Where mimetypes .desktop files should go to.
+# kde_servicesdir Where services .desktop files should go to.
+# kde_servicetypesdir Where servicetypes .desktop files should go to.
+# kde_toolbardir Where general toolbar icons should go to (deprecated, use KDE_ICON).
+# kde_wallpaperdir Where general wallpapers should go to.
+# kde_templatesdir Where templates for the "New" menu (Konqueror/KDesktop) should go to.
+# kde_bindir Where executables should go to. Use bin_PROGRAMS or bin_SCRIPTS.
+# kde_libdir Where shared libraries should go to. Use lib_LTLIBRARIES.
+# kde_moduledir Where modules (e.g. parts) should go to. Use kde_module_LTLIBRARIES.
+# kde_styledir Where Qt/KDE widget styles should go to (new in KDE 3).
+# kde_designerdir Where Qt Designer plugins should go to (new in KDE 3).
+
+# set the include path for X, qt and KDE
+INCLUDES= $(LIBXML_CFLAGS) $(LIBXSLT_CFLAGS) $(all_includes)
+
+METASOURCES = AUTO
+
+# the application source, library search path, and link libraries
+kxsldbg_LDFLAGS = $(KDE_RPATH) $(all_libraries)
+
+# this is where the shell's XML-GUI resource file goes
+shellrcdir = $(kde_datadir)/kxsldbg
+shellrc_DATA = kxsldbg_shell.rc
+
+messages: rc.cpp
+ LIST=`find . -name \*.ui -o -name \*.rc`; \
+ $(EXTRACTRC) $$LIST >> rc.cpp ;\
+ LIST=`find . -name \*.h -o -name \*.hh -o -name \*.H -o -name \*.hxx -o -name \*.hpp -o -name \*.cpp -o -name \*.cc -o -name \*.cxx -o -name \*.ecpp -o -name \*.C`; \
+ if test -n "$$LIST"; then \
+ $(XGETTEXT) $$LIST -o $(podir)/kxsldbg.pot; \
+ fi
+
diff --git a/kxsldbg/configure.in.in b/kxsldbg/configure.in.in
new file mode 100644
index 00000000..b4f1ef5e
--- /dev/null
+++ b/kxsldbg/configure.in.in
@@ -0,0 +1,176 @@
+LIBXSLT_REQUIRED_VERSION="1.0.18"
+AC_SUBST(LIBXSLT_REQUIRED_VERSION)
+
+dnl
+dnl Math detection
+dnl
+
+AC_CHECK_HEADERS(sys/types.h unistd.h string.h)
+AC_CHECK_HEADERS(ieeefp.h nan.h math.h fp_class.h float.h ansidecl.h)
+AC_CHECK_HEADERS(time.h sys/stat.h stdarg.h)
+AC_CHECK_FUNCS(stat _stat)
+
+AC_CHECK_FUNC(isnan, , AC_CHECK_LIB(m, isnan,
+ [M_LIBS="-lm"; AC_DEFINE(HAVE_ISNAN)]))
+
+AC_CHECK_FUNC(isinf, , AC_CHECK_LIB(m, isinf,
+ [M_LIBS="-lm"; AC_DEFINE(HAVE_ISINF)]))
+
+AC_CHECK_FUNC(pow, , AC_CHECK_LIB(m, pow,
+ [M_LIBS="-lm"; AC_DEFINE(HAVE_POW)]))
+
+AC_CHECK_FUNC(floor, , AC_CHECK_LIB(m, pow,
+ [M_LIBS="-lm"; AC_DEFINE(HAVE_FLOOR)]))
+
+AC_CHECK_FUNC(fabs, , AC_CHECK_LIB(m, pow,
+ [M_LIBS="-lm"; AC_DEFINE(HAVE_FABS)]))
+AC_CHECK_FUNCS(gettimeofday)
+AC_CHECK_FUNCS(mktime localtime asctime)
+
+AH_TEMPLATE(USE_DOCS_MACRO)
+AH_TEMPLATE(TIMESTAMP)
+AH_TEMPLATE(WITH_DEBUG_HELP)
+AH_TEMPLATE(WITH_XSLDBG_DEBUG)
+AH_TEMPLATE(XSLDBG_BIN)
+AH_TEMPLATE(USE_XSLDBG_AS_THREAD)
+AH_TEMPLATE(HAVE_INCLUDE_FIX)
+
+AH_TEMPLATE(_GNU_SOURCE)
+AH_TEMPLATE(HAVE_ISINF)
+AH_TEMPLATE(HAVE_ISNAN)
+AH_TEMPLATE(HAVE_POW)
+AH_TEMPLATE(HAVE_FLOOR)
+AH_TEMPLATE(HAVE_FABS)
+AH_TEMPLATE(HAVE_QT)
+AH_TEMPLATE(HAVE_PTHREAD)
+AH_TEMPLATE(HAVE_READLINE)
+AH_TEMPLATE(HAVE_HISTORY)
+
+dnl
+dnl how are we to invoke xsldbg, or the other stylesheet processor (xsltproc?)
+dnl
+
+AC_DEFINE(XSLDBG_BIN, "xsldbg")
+
+
+dnl
+dnl Do we have we fix for included xml files
+dnl
+
+save_LDFLAGS="$LDFLAGS"
+save_CFLAGS="$CFLAGS"
+LDFLAGS="$LDFLAGS $LIBXML_LIBS"
+CFLAGS="$CFLAGS $LIBXML_CFLAGS"
+
+AC_CHECK_LIB(xml2, xmlSetEntityReferenceFunc,
+ [AC_DEFINE(HAVE_INCLUDE_FIX)],
+ [AC_MSG_RESULT(
+!!Warning!! The version of libxml2 installed does not support
+ debugging of files included as entities. Test 10 will be skipped
+ as it will fail. You will not be able to set breakpoints on external
+ entities. Try upgrading your libxml2.
+ See also --enable-includefix)
+ RUNTEST10="false"
+ ])
+
+LDFLAGS="$save_LDFLAGS"
+CFLAGS="$save_CFLAGS"
+
+AC_ARG_ENABLE([includefix],
+ [ --enable-includefix Do you want to force the use of include fix (no)], [do_include_fix=$enableval], [do_include_fix="no"])
+
+if test "x$do_include_fix" = "xyes"; then
+ AC_DEFINE(HAVE_INCLUDE_FIX)
+ AC_MSG_RESULT(Forcing the use if include fix)
+fi
+
+
+
+XSLDBG_MAJOR_VERSION=3
+XSLDBG_MINOR_VERSION=1
+XSLDBG_MICRO_VERSION=7
+XSLDBG_VERSION=$XSLDBG_MAJOR_VERSION.$XSLDBG_MINOR_VERSION.$XSLDBG_MICRO_VERSION
+XSLDBG_VERSION_INFO=`expr $XSLDBG_MAJOR_VERSION + \
+$XSLDBG_MINOR_VERSION`:$XSLDBG_MICRO_VERSION:$XSLDBG_MINOR_VERSION
+
+XSLDBG_VERSION_NUMBER=`expr $XSLDBG_MAJOR_VERSION \* 10000 + \
+$XSLDBG_MINOR_VERSION \* 100 + $XSLDBG_MICRO_VERSION`
+AC_SUBST(XSLDBG_MAJOR_VERSION)
+AC_SUBST(XSLDBG_MINOR_VERSION)
+AC_SUBST(XSLDBG_MICRO_VERSION)
+AC_SUBST(XSLDBG_VERSION)
+AC_SUBST(XSLDBG_VERSION_INFO)
+AC_SUBST(XSLDBG_VERSION_NUMBER)
+
+
+dnl
+dnl We must run xsldbg as a thread
+dnl
+AC_CHECK_HEADERS(pthread.h,
+ AC_DEFINE(HAVE_PTHREAD)
+ AVE_PTHREAD=1
+ SE_XSLDBG_AS_THREAD=1
+ AC_DEFINE(USE_XSLDBG_AS_THREAD),
+ AC_MSG_ERROR(PThread library not found)
+)
+XSLDBG_INCLUDEDIR="`pwd`/kxsldbg/kxsldbgpart"
+
+dnl Where is the xsldbg documentation stored
+dnl
+docs_macro=true
+AC_ARG_ENABLE(docs_macro,
+ [ --enable-docs-macro Use a compiler macro to specify where documentation is (PREFIX/doc/xsldbg/)],
+ [docs_macro=$enableval], [docs_macro="yes"])
+
+if test "x$docs_macro" = "xyes"; then
+ AC_DEFINE(USE_DOCS_MACRO, 1)
+ if test "x$prefix" != "x"
+ then
+ AC_MSG_RESULT(xsldbg will look for installed documentation in ${prefix}/doc/xsldbg)
+ else
+ AC_MSG_RESULT(xsldbg will look for installed documentation in ${ac_default_prefix}doc/xsldbg/)
+ fi
+ DOCS_PATH="${prefix}/doc/xsldbg"
+AC_SUBST(DOCS_PATH)
+
+else
+ AC_MSG_RESULT(
+
+ !!Warning!! Using a environment variable for specifiying location of documentation.
+ On non risc os systems : XSLDBG_DOCS_DIR
+ On risc os systems : XSLDebugDocs\$Dir
+ See --enable-docs-macro in ./configure
+ )
+fi
+
+
+dnl include extra debugging for xsldbg?
+AC_ARG_ENABLE([xsldbg-debugging],
+ [ --enable-xsldbg-debugging Do you want to enable lots of debugging messages in xsldbg (no)], [do_xsldbg_debugging=$enableval], [do_xsldbg_debugging="no"])
+
+if test "x$do_xsldbg_debugging" = "xyes"; then
+ AC_DEFINE(WITH_XSLDBG_DEBUG)
+ AC_MSG_RESULT(Enabling lots of debug messages in xsldbg)
+fi
+
+
+
+
+AC_MSG_RESULT(Using xsldbg as a part of kxsldbg)
+
+dnl
+dnl Check for readline and history
+dnl
+XSLDBG_EXTRA_LIBS=""
+dnl AC_CHECK_HEADERS(readline/readline.h, [
+dnl AC_DEFINE(HAVE_READLINE)
+dnl XSLDBG_EXTRA_LIBS="-lreadline -lncurses"])
+dnl AC_CHECK_HEADER(readline/history.h, [
+dnl AC_DEFINE(HAVE_HISTORY)
+dnl XSLDBG_EXTRA_LIBS="$XSLDBG_EXTRA_LIBS -lhistory"])
+
+AC_SUBST(XSLDBG_INCLUDEDIR)
+AC_SUBST(XSLDBG_EXTRA_LIBS)
+XSLDBG_CFLAGS="-I${XSLDBG_INCLUDEDIR} ${LIBXSLT_CFLAGS} "
+AC_SUBST(XSLDBG_CFLAGS)
+AC_SUBST(XSLDBG_PREFIX)
diff --git a/kxsldbg/data/Makefile.am b/kxsldbg/data/Makefile.am
new file mode 100644
index 00000000..d6bd3286
--- /dev/null
+++ b/kxsldbg/data/Makefile.am
@@ -0,0 +1,16 @@
+SUBDIRS =
+
+
+# Provide a example XSLT scripts : testdoc.xsl and empty.xsl
+commondata = test1.xml test2.xml test3.xml test4.xml \
+ test_import.xsl test_include_bot.xsl test_include_top.xsl \
+ testdoc.dtd testdoc.xml testdoc.xsl \
+ empty.xsl empty.xml
+
+
+kxsldbgdir = ${kde_datadir}/kxsldbg
+kxsldbg_DATA = ${commondata}
+
+
+xsldbgdir = ${kde_datadir}/xsldbg
+xsldbg_DATA = ${commondata}
diff --git a/kxsldbg/data/empty.xml b/kxsldbg/data/empty.xml
new file mode 100644
index 00000000..aa9ac07e
--- /dev/null
+++ b/kxsldbg/data/empty.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ File : empty.xml
+ Author: Keith Isdale <k_isdale@tpg.com.au>
+ Description: empty xml data for getting started
+ Copyright Reserved Under GPL
+-->
+<!-- This file does not require translation -->
+<!-- NO TRANSLATION -->
+<empty>
+ Empty example data file
+</empty>
diff --git a/kxsldbg/data/empty.xsl b/kxsldbg/data/empty.xsl
new file mode 100644
index 00000000..ab4548ef
--- /dev/null
+++ b/kxsldbg/data/empty.xsl
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ File : empty.xsl
+ Author: Keith Isdale <k_isdale@tpg.com.au>
+ Description: empty stylesheet for getting started
+ Copyright Reserved Under GPL
+-->
+<!-- This file does not require translation -->
+<!-- NO TRANSLATION -->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+version="1.0">
+
+ <xsl:output method="text"/>
+
+ <xsl:template match="/">
+ <xsl:apply-templates />
+ </xsl:template>
+</xsl:stylesheet>
+
diff --git a/kxsldbg/data/test1.xml b/kxsldbg/data/test1.xml
new file mode 100644
index 00000000..06c35dde
--- /dev/null
+++ b/kxsldbg/data/test1.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ File : test1.xml
+ Author: Keith Isdale <k_isdale@tpg.com.au>
+ Description: xml data for stylesheet for testing
+ Copyright Reserved Under GPL
+-->
+<!-- This file does not require translation -->
+<!-- NO TRANSLATION -->
+<html>
+<head>
+</head>
+<body>
+ <h1>test1</h1>
+ <p>text1</p>
+</body>
+</html>
diff --git a/kxsldbg/data/test2.xml b/kxsldbg/data/test2.xml
new file mode 100644
index 00000000..80bf77a7
--- /dev/null
+++ b/kxsldbg/data/test2.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ File : test2.xml
+ Author: Keith Isdale <k_isdale@tpg.com.au>
+ Description: xml data for stylesheet for testing
+ Copyright Reserved Under GPL
+-->
+<!-- This file does not require translation -->
+<!-- NO TRANSLATION -->
+
+<result>
+ <head name="foo"/>
+ <data name="fred"/>
+ <data name="barney"/>
+ <data name="pebbles"/>
+ <extra name="wilma"/>
+</result>
+
+
+
+<!-- initialization code for xemacs -->
+<!--
+Local Variables:
+mode: sgml
+sgml-minimize-attributes:nil
+sgml-general-insert-case:lower
+sgml-indent-step:0
+sgml-indent-data:nil
+End:
+-->
diff --git a/kxsldbg/data/test3.xml b/kxsldbg/data/test3.xml
new file mode 100644
index 00000000..706321e4
--- /dev/null
+++ b/kxsldbg/data/test3.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ File : test3.xml
+ Author: Keith Isdale <k_isdale@tpg.com.au>
+ Description: xml data for stylesheet for testing
+ Copyright Reserved Under GPL
+-->
+<!-- This file does not require translation -->
+<!-- NO TRANSLATION -->
+
+<result>
+ <data>2</data>
+ <data>1</data>
+ <data>3</data>
+ <extra/>
+</result>
+
+
+
+<!-- initialization code for xemacs -->
+<!--
+Local Variables:
+mode: sgml
+sgml-minimize-attributes:nil
+sgml-general-insert-case:lower
+sgml-indent-step:0
+sgml-indent-data:nil
+End:
+-->
diff --git a/kxsldbg/data/test4.xml b/kxsldbg/data/test4.xml
new file mode 100644
index 00000000..437ca18e
--- /dev/null
+++ b/kxsldbg/data/test4.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ File : test4.xml
+ Author: Keith Isdale <k_isdale@tpg.com.au>
+ Description: xml data for stylesheet for testing
+ Copyright Reserved Under GPL
+-->
+<!-- This file does not require translation -->
+<!-- NO TRANSLATION -->
+
+<result>
+ <data/>
+ <extra/>
+</result>
+
+
+
+<!-- initialization code for xemacs -->
+<!--
+Local Variables:
+mode: sgml
+sgml-minimize-attributes:nil
+sgml-general-insert-case:lower
+sgml-indent-step:0
+sgml-indent-data:nil
+End:
+-->
diff --git a/kxsldbg/data/test_import.xsl b/kxsldbg/data/test_import.xsl
new file mode 100644
index 00000000..e48539eb
--- /dev/null
+++ b/kxsldbg/data/test_import.xsl
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ File : test_import.xsl
+ Author: Keith Isdale <k_isdale@tpg.com.au>
+ Description: stylesheet for testing
+ Copyright Reserved Under GPL
+-->
+<!-- This file does not require translation -->
+<!-- NO TRANSLATION -->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="1.0">
+
+ <xsl:template match="head">
+ <xsl:apply-templates/>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/kxsldbg/data/test_include_bot.xsl b/kxsldbg/data/test_include_bot.xsl
new file mode 100644
index 00000000..6dd6c9aa
--- /dev/null
+++ b/kxsldbg/data/test_include_bot.xsl
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ File : test_include.xsl
+ Author: Keith Isdale <k_isdale@tpg.com.au>
+ Description: stylesheet for include testing
+ Copyright Reserved Under GPL
+-->
+<!-- This file does not require translation -->
+<!-- NO TRANSLATION -->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="1.0">
+
+ <xsl:template match="include_bot">
+ <xsl:apply-templates/>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/kxsldbg/data/test_include_top.xsl b/kxsldbg/data/test_include_top.xsl
new file mode 100644
index 00000000..df7e4967
--- /dev/null
+++ b/kxsldbg/data/test_include_top.xsl
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ File : test_include_top.xsl
+ Author: Keith Isdale <k_isdale@tpg.com.au>
+ Description: stylesheet for include testing
+ Copyright Reserved Under GPL
+-->
+<!-- This file does not require translation -->
+<!-- NO TRANSLATION -->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="1.0">
+
+ <xsl:template name="import_top">
+ <xsl:apply-templates select="result/head"/>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/kxsldbg/data/testdoc.dtd b/kxsldbg/data/testdoc.dtd
new file mode 100644
index 00000000..08e9108a
--- /dev/null
+++ b/kxsldbg/data/testdoc.dtd
@@ -0,0 +1,6 @@
+<!ELEMENT simple (#PCDATA)>
+<!ENTITY mytext "Some text">
+<!ENTITY anotherDoc SYSTEM "test1.xml" >
+<!ENTITY anotherDoc2 SYSTEM "test2.xml" >
+<!ENTITY anotherDoc3 SYSTEM "test3.xml" >
+<!ENTITY anotherDoc4 SYSTEM "test4.xml" > \ No newline at end of file
diff --git a/kxsldbg/data/testdoc.xml b/kxsldbg/data/testdoc.xml
new file mode 100644
index 00000000..894fbbfe
--- /dev/null
+++ b/kxsldbg/data/testdoc.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ File : testdoc.xml
+ Author: Keith Isdale <k_isdale@tpg.com.au>
+ Description: xml data for stylesheet for testing
+ Copyright Reserved Under GPL
+-->
+<!-- This file does not require translation -->
+<!-- NO TRANSLATION -->
+
+<!DOCTYPE simple SYSTEM "testdoc.dtd">
+
+<simple>
+ &mytext;
+ &anotherDoc;
+ &anotherDoc;
+ &anotherDoc;
+ &anotherDoc2;
+ &anotherDoc3;
+ &anotherDoc4;
+</simple>
+
+
+<!-- initialization code for xemacs -->
+<!--
+Local Variables:
+mode: sgml
+sgml-minimize-attributes:nil
+sgml-general-insert-case:lower
+sgml-indent-step:0
+sgml-indent-data:nil
+End:
+-->
diff --git a/kxsldbg/data/testdoc.xsl b/kxsldbg/data/testdoc.xsl
new file mode 100644
index 00000000..da6447f3
--- /dev/null
+++ b/kxsldbg/data/testdoc.xsl
@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ File : testdoc.xsl
+ Author: Keith Isdale <k_isdale@tpg.com.au>
+ Description: stylesheet for testing
+ Copyright Reserved Under GPL
+-->
+<!-- This file does not require translation -->
+<!-- NO TRANSLATION -->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+version="1.0">
+
+ <xsl:import href="test_import.xsl"/>
+ <xsl:include href="test_include_top.xsl"/>
+ <xsl:strip-space elements="text()"/>
+ <xsl:decimal-format name="test" decimal-separator="."/>
+ <xsl:output method="text"/>
+ <xsl:variable name="globalvariable" select="'foo'"/>
+
+ <xsl:template match="/">
+ <xsl:call-template name="test_set_variable">
+ <xsl:with-param name="item" select="'1234'"/>
+ </xsl:call-template>
+
+ <xsl:variable name="localvariable" select="'bar'"/>
+ <xsl:text>Global variable contains </xsl:text><xsl:value-of select="$globalvariable"/><xsl:text>
+</xsl:text>
+ <xsl:text>Local variable contains </xsl:text><xsl:value-of select="$localvariable"/><xsl:text>
+</xsl:text>
+
+ <!-- test import of xsl file -->
+ <xsl:call-template name="import_top"/>
+
+ <!-- Basic xsl:apply-templates, xsl:call-template usage -->
+ <!-- Test basic usage of xsl:apply-templates -->
+ <xsl:apply-templates select="//result/data"/>
+ <!-- Test basic usage of xsl:call-template -->
+ <xsl:call-template name="call-template1"/>
+
+ <!-- Test xsl:apply-templates with parameter value.
+ Test the ability to step into a xsl:with-param child -->
+ <xsl:apply-templates select="//result/data">
+ <xsl:with-param name="item">
+ <item/>
+ </xsl:with-param>
+ </xsl:apply-templates>
+
+ <!-- Test xsl:call-template with parameter value
+ Test the ability to step into a xsl:with-param child -->
+ <xsl:call-template name="call-template2">
+ <xsl:with-param name="item">
+ <item />
+ </xsl:with-param>
+ </xsl:call-template>
+
+ <!-- Test ability to step into xsl:param from xsl:apply-templates -->
+ <xsl:apply-templates select="//result/extra" />
+
+ <!-- Test ability to step into xsl:param from xsl:call-template -->
+ <xsl:call-template name="call-template3" />
+
+ <!-- Test ability to step into xsl:sort from xsl:apply-templates -->
+ <xsl:apply-templates select="//result/data">
+ <xsl:sort select="."/>
+ <xsl:text>
+</xsl:text>
+ </xsl:apply-templates>
+
+ <xsl:apply-imports/> <!-- useless but test that we can step to it -->
+
+ <xsl:apply-templates select="//result/data" mode="verbose" />
+
+ </xsl:template>
+
+
+ <xsl:template match="result">
+ <xsl:param name="item" select="'default'"/>
+ <!-- ignore node content -->
+ </xsl:template>
+
+
+ <xsl:template match="data">
+ <!-- ignore node content -->
+ </xsl:template>
+
+ <xsl:template match="data" mode="verbose">
+ <xsl:apply-templates />
+ </xsl:template>
+
+
+ <xsl:template match="extra">
+ <xsl:param name="item">
+ <item/>
+ </xsl:param>
+ <!-- ignore node content -->
+ <xsl:text>
+</xsl:text>
+ </xsl:template>
+
+
+ <xsl:template name="call-template1">
+ <xsl:number value="position()" format="1."/>
+ <xsl:text>
+</xsl:text>
+ </xsl:template>
+
+
+ <xsl:template name="call-template2">
+ <!-- ignore any param provided -->
+ <!-- test message -->
+ <xsl:message terminate="no">Message here</xsl:message>
+ <xsl:processing-instruction name="pitest">
+ pi text
+ </xsl:processing-instruction>
+ <xsl:text>
+</xsl:text>
+ </xsl:template>
+
+
+ <xsl:template name="call-template3">
+ <xsl:param name="item">
+ <item/>
+ </xsl:param>
+ <!-- test comments -->
+ <xsl:comment>A text comment.</xsl:comment>
+ <!-- test copy and copy-of -->
+ <xsl:copy>copy text</xsl:copy>
+ <xsl:copy-of select="'copy-of Text'"/>
+ <xsl:text>
+</xsl:text>
+ </xsl:template>
+
+
+ <xsl:template name="test_set_variable">
+ <xsl:param name="item" select="'default-value'"/>
+ <xsl:value-of select="$item"/>
+ <xsl:text>
+</xsl:text>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/kxsldbg/kxsldbg.cpp b/kxsldbg/kxsldbg.cpp
new file mode 100644
index 00000000..c28325a3
--- /dev/null
+++ b/kxsldbg/kxsldbg.cpp
@@ -0,0 +1,173 @@
+/*
+ * kxsldbg.cpp
+ *
+ * Copyright (C) 2001 <kurt@granroth.org>
+ */
+#include "kxsldbg.h"
+
+#include <kkeydialog.h>
+#include <kconfig.h>
+#include <klocale.h>
+
+#include <kedittoolbar.h>
+
+#include <kaction.h>
+#include <kstdaction.h>
+
+#include <klibloader.h>
+#include <kmessagebox.h>
+#include <kstatusbar.h>
+
+KXsldbg::KXsldbg()
+ : DCOPObject("KXsldbg"), KParts::MainWindow( 0L, "kxsldbg" )
+{
+ // set the shell's ui resource file
+ setXMLFile("kxsldbg_shell.rc");
+
+ // then, setup our actions
+ setupActions();
+
+ // and a status bar
+ statusBar()->show();
+ statusBar()->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
+
+ // this routine will find and load our Part. it finds the Part by
+ // name which is a bad idea usually.. but it's alright in this
+ // case since our Part is made for this Shell
+ KLibFactory *factory = KLibLoader::self()->factory("libkxsldbgpart");
+ if (factory)
+ {
+ // now that the Part is loaded, we cast it to a Part to get
+ // our hands on it
+ m_part = static_cast<KParts::ReadOnlyPart *>(factory->create(this,
+ "kxsldbg_part", "KParts::ReadOnlyPart" ));
+
+ if (m_part)
+ {
+ // tell the KParts::MainWindow that this is indeed the main widget
+ setCentralWidget(m_part->widget());
+
+ // and integrate the part's GUI with the shell's
+ createGUI(m_part);
+
+ // connect up signals
+ kapp->dcopClient()->attach();
+ connectDCOPSignal(0, 0, "debuggerPositionChanged(QString,int)", "newDebuggerPosition(QString,int)", false );
+ connectDCOPSignal(0, 0, "editorPositionChanged(QString,int,int)", "newCursorPosition(QString,int,int)", false );
+ }
+
+ }
+ else
+ {
+ // if we couldn't find our Part, we exit since the Shell by
+ // itself can't do anything useful
+ KMessageBox::error(this, i18n("Could not find our part."));
+ kapp->quit();
+ }
+}
+
+KXsldbg::~KXsldbg()
+{
+ if (m_part)
+ m_part->closeURL();
+
+ delete m_part;
+}
+
+void KXsldbg::quit()
+{
+ closeURL();
+ close();
+}
+
+bool KXsldbg::closeURL()
+{
+ if (m_part)
+ m_part->closeURL();
+
+ return true;
+}
+
+void KXsldbg::setupActions()
+{
+ KAction *act = KStdAction::quit(kapp, SLOT(quit()), actionCollection());
+ connect(act, SIGNAL(activated()), this, SLOT(quit()));
+
+ m_toolbarAction = KStdAction::showToolbar(this, SLOT(optionsShowToolbar()), actionCollection());
+ m_statusbarAction = KStdAction::showStatusbar(this, SLOT(optionsShowStatusbar()), actionCollection());
+
+ KStdAction::keyBindings(this, SLOT(optionsConfigureKeys()), actionCollection());
+ KStdAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection());
+}
+
+void KXsldbg::saveProperties(KConfig* /*config*/)
+{
+ // the 'config' object points to the session managed
+ // config file. anything you write here will be available
+ // later when this app is restored
+}
+
+void KXsldbg::readProperties(KConfig* /*config*/)
+{
+ // the 'config' object points to the session managed
+ // config file. this function is automatically called whenever
+ // the app is being restored. read in here whatever you wrote
+ // in 'saveProperties'
+}
+
+
+void KXsldbg::optionsShowToolbar()
+{
+ // this is all very cut and paste code for showing/hiding the
+ // toolbar
+ if (m_toolbarAction->isChecked())
+ toolBar()->show();
+ else
+ toolBar()->hide();
+}
+
+void KXsldbg::optionsShowStatusbar()
+{
+ // this is all very cut and paste code for showing/hiding the
+ // statusbar
+ if (m_statusbarAction->isChecked())
+ statusBar()->show();
+ else
+ statusBar()->hide();
+}
+
+void KXsldbg::optionsConfigureKeys()
+{
+ KKeyDialog::configure(actionCollection(), "kxsldbg_shell.rc");
+}
+
+void KXsldbg::optionsConfigureToolbars()
+{
+ saveMainWindowSettings(KGlobal::config(), "MainWindow");
+
+ // use the standard toolbar editor
+ KEditToolbar dlg(factory());
+ connect(&dlg, SIGNAL(newToolbarConfig()),
+ this, SLOT(applyNewToolbarConfig()));
+ dlg.exec();
+}
+
+void KXsldbg::applyNewToolbarConfig()
+{
+ applyMainWindowSettings(KGlobal::config(), "MainWindow");
+}
+
+
+void KXsldbg::newCursorPosition(const QString &file, int lineNumber, int columnNumber)
+{
+ statusBar()->clear();
+ statusBar()->message( i18n("File: %1 Line: %2 Col: %3").arg(file).arg(lineNumber).arg(columnNumber));
+}
+
+void KXsldbg::newDebuggerPosition(const QString &file, int lineNumber)
+{
+ // maybe do something extra here later
+ newCursorPosition(file, lineNumber);
+}
+
+#include "kxsldbg.moc"
diff --git a/kxsldbg/kxsldbg.desktop b/kxsldbg/kxsldbg.desktop
new file mode 100644
index 00000000..8ab7ad9e
--- /dev/null
+++ b/kxsldbg/kxsldbg.desktop
@@ -0,0 +1,53 @@
+[Desktop Entry]
+Name=KXSLDbg
+Name[sv]=Kxsldbg
+Name[ta]=KXSLDபிஜி
+GenericName=XSLT Debugger
+GenericName[bg]=Дебъгер XSLT
+GenericName[br]=Dizraener XSLT
+GenericName[ca]=Depurador XSLT
+GenericName[cs]=XSLT debugger
+GenericName[da]=XSLT-Fejlretter
+GenericName[de]=XSLT-Debugger
+GenericName[el]=Αποσφαλματωτής XSLT
+GenericName[es]=Depurador XSLT
+GenericName[et]=XSLT silur
+GenericName[eu]=XSLT araztailea
+GenericName[fa]=اشکال‌زدای XSLT
+GenericName[fi]=XSLT debuggeri
+GenericName[fr]=Débogueur XSLT
+GenericName[ga]=Dífhabhtóir XSLT
+GenericName[gl]=Depurador XSLT
+GenericName[hi]=XSLT डिबगर
+GenericName[hu]=XSLT-nyomkövető
+GenericName[is]=XSLT aflúsari
+GenericName[it]=Debugger per XSLT
+GenericName[ja]=XSLT デバッガ
+GenericName[lt]=XSLT derintuvė
+GenericName[ms]=Penyahralat XSLT
+GenericName[nds]=XSLT-Fehlersöker
+GenericName[ne]=त्रुटिमोचक एक्सएसएलटी
+GenericName[nl]=XSLT-debugger
+GenericName[pl]=Debuger XSLT
+GenericName[pt]=Depuração de XSLT
+GenericName[pt_BR]=Debugger para XSLT
+GenericName[ro]=Depanator XSLT
+GenericName[ru]=Отладчик XSLT
+GenericName[sk]=XSLT debuger
+GenericName[sl]=Razhroščevalnik XSLT
+GenericName[sr]=Исправљач XSLT-а
+GenericName[sr@Latn]=Ispravljač XSLT-a
+GenericName[sv]=XSLT-felsökare
+GenericName[ta]=XSLT வழுநீக்குபவர்
+GenericName[tg]=Ғалатёби XSLT
+GenericName[tr]=XSLT Hata Ayıklayıcısı
+GenericName[uk]=Зневаджувач XSLT
+GenericName[zh_CN]=XSLT 调试器
+GenericName[zh_HK]=XSLT 除錯器
+GenericName[zh_TW]=XSLT 除錯器
+Exec=kxsldbg %i %m -caption "%c"
+Icon=kxsldbg
+Type=Application
+DocPath=kxsldbg/index.html
+Terminal=false
+Categories=Qt;KDE;Development;WebDevelopment;
diff --git a/kxsldbg/kxsldbg.h b/kxsldbg/kxsldbg.h
new file mode 100644
index 00000000..7c75629a
--- /dev/null
+++ b/kxsldbg/kxsldbg.h
@@ -0,0 +1,84 @@
+#ifndef KXSLDBG_H
+#define KXSLDBG_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <kapplication.h>
+#include <kparts/mainwindow.h>
+#include <dcopobject.h>
+#include <dcopclient.h>
+#include "kxsldbgif.h"
+
+class KToggleAction;
+
+/**
+ * This is the application "Shell". It has a menubar, toolbar, and
+ * statusbar but relies on the "Part" to do all the real work.
+ *
+ * @short Application Shell
+ * @author Keith Isdale <k_isdale@tpg.com.au>
+ * @version 0.4
+ */
+class KXsldbg : public KParts::MainWindow, public KXsldbgIf
+{
+ Q_OBJECT
+
+public:
+ /**
+ * Default Constructor
+ */
+ KXsldbg();
+
+ /**
+ * Default Destructor
+ */
+ virtual ~KXsldbg();
+
+ /**
+ KxsldbgIf implementation
+ */
+ void newCursorPosition(const QString &file, int lineNumber, int columnNumber=0);
+ void newDebuggerPosition(const QString & file, int lineNumber);
+
+protected:
+ /**
+ * This method is called when it is time for the app to save its
+ * properties for session management purposes.
+ */
+ void saveProperties(KConfig *);
+
+ /**
+ * This method is called when this app is restored. The KConfig
+ * object points to the session management config file that was saved
+ * with @ref saveProperties
+ */
+ void readProperties(KConfig *);
+
+ virtual bool closeURL();
+
+public slots:
+ void quit();
+
+private slots:
+ void optionsShowToolbar();
+ void optionsShowStatusbar();
+ void optionsConfigureKeys();
+ void optionsConfigureToolbars();
+
+ void applyNewToolbarConfig();
+
+
+private:
+ void setupAccel();
+ void setupActions();
+
+private:
+ KParts::ReadOnlyPart *m_part;
+
+ KToggleAction *m_toolbarAction;
+ KToggleAction *m_statusbarAction;
+};
+
+#endif // KXSLDBG_H
diff --git a/kxsldbg/kxsldbg_shell.rc b/kxsldbg/kxsldbg_shell.rc
new file mode 100644
index 00000000..d3e2fc86
--- /dev/null
+++ b/kxsldbg/kxsldbg_shell.rc
@@ -0,0 +1,29 @@
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui name="kxsldbg_shell" version="1">
+<MenuBar>
+ <Menu noMerge="1" name="file"><text>&amp;File</text>
+ <Merge/>
+ <Separator/>
+ <Action name="file_quit"/>
+ </Menu>
+ <Menu name="debug"><text>Debug</text>
+ </Menu>
+ <Menu noMerge="1" name="settings"><text>&amp;Settings</text>
+ <Action name="options_show_toolbar"/>
+ <Action name="options_show_statusbar"/>
+ <Merge name="show_merge"/>
+ <Separator/>
+ <Action name="options_configure_keybinding"/>
+ <Action name="options_configure_toolbars"/>
+ <Action name="options_configure"/>
+ <Action name="configureEditorCmd"/>
+ <Merge name="configure_merge"/>
+ <Separator/>
+ <Merge/>
+ </Menu>
+</MenuBar>
+<ToolBar noMerge="1" name="mainToolBar"><text>Main Toolbar</text>
+ <Merge/>
+ <Action name="help"/>
+</ToolBar>
+</kpartgui>
diff --git a/kxsldbg/kxsldbgif.h b/kxsldbg/kxsldbgif.h
new file mode 100644
index 00000000..a9942bfc
--- /dev/null
+++ b/kxsldbg/kxsldbgif.h
@@ -0,0 +1,17 @@
+#ifndef KXSLDBGIF_H
+#define KXSLDBGIF_H
+
+#include <dcopobject.h>
+
+class KXsldbgIf : virtual public DCOPObject
+{
+ K_DCOP
+ k_dcop:
+
+ virtual void newCursorPosition(const QString & file, int lineNumber, int columnNumber=0) = 0;
+ virtual void newDebuggerPosition(const QString & file, int lineNumber) = 0;
+
+};
+
+#endif
+
diff --git a/kxsldbg/kxsldbgpart/Makefile.am b/kxsldbg/kxsldbgpart/Makefile.am
new file mode 100644
index 00000000..ee5e1e9a
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/Makefile.am
@@ -0,0 +1,31 @@
+noinst_LTLIBRARIES = libkxsldbgcommon.la
+libkxsldbgcommon_la_SOURCES = xsldbgwalkspeedimpl.cpp xsldbgtemplatesimpl.cpp xsldbgtemplatelistitem.cpp xsldbgsourcesimpl.cpp xsldbgoutputview.cpp xsldbglocalvariablesimpl.cpp xsldbglocallistitem.cpp xsldbglistitem.cpp xsldbginspector.cpp xsldbgglobalvariablesimpl.cpp xsldbggloballistitem.cpp xsldbgentitiesimpl.cpp xsldbgdoc.cpp xsldbgdialogbase.cpp xsldbgdebugger.cpp xsldbgconfigimpl.cpp xsldbgcallstackimpl.cpp xsldbgbreakpointsimpl.cpp xsldbgbreakpointlistitem.cpp qxsldbgdoc.cpp kxsldbg_part.cpp kxsldbg_partif.skel xsldbgwalkspeed.ui xsldbgtemplates.ui xsldbgsources.ui xsldbgmsgdialog.ui xsldbglocalvariables.ui xsldbgglobalvariables.ui xsldbgentities.ui xsldbgconfig.ui xsldbgcallstack.ui xsldbgbreakpoints.ui
+libkxsldbgcommon_la_METASOURCES = AUTO
+libkxsldbgcommon_la_LDFLAGS = $(all_libraries)
+libkxsldbgcommon_la_LIBADD = libxsldbg/libxsldbg.la libqtnotfier/libqtnotfier.la
+
+noinst_HEADERS = kxsldbg_part.h qxsldbgdoc.h xsldbgbreakpointlistitem.h xsldbgbreakpointsimpl.h xsldbgcallstackimpl.h xsldbgconfigimpl.h xsldbgdebugger.h xsldbgdialogbase.h xsldbgdoc.h xsldbgdocmap.h xsldbgentitiesimpl.h xsldbggloballistitem.h xsldbgglobalvariablesimpl.h xsldbginspector.h xsldbglistitem.h xsldbglocallistitem.h xsldbglocalvariablesimpl.h xsldbgmsgdialogimpl.h xsldbgoutputview.h xsldbgsourcesimpl.h xsldbgtemplatelistitem.h xsldbgtemplatesimpl.h xsldbgwalkspeedimpl.h
+
+kde_module_LTLIBRARIES = libkxsldbgpart.la
+
+libkxsldbgpart_la_SOURCES = dummy.cpp
+
+SUBDIRS = libqtnotfier libxsldbg
+
+INCLUDES = $(XSLDBG_CFLAGS) -I.. $(all_includes)
+
+
+libkxsldbgpart_la_LDFLAGS = -module $(KDE_PLUGIN) -lkatepartinterfaces $(all_libraries) $(XSLDBG_EXTRA_LIBS)
+libkxsldbgpart_la_LIBADD = libkxsldbgcommon.la $(LIB_KPARTS)
+
+
+# this is where the desktop file will go
+partdesktopdir = $(kde_servicesdir)
+partdesktop_DATA = kxsldbg_part.desktop
+
+# this is where the part's XML-GUI resource file goes
+partrcdir = $(kde_datadir)/kxsldbgpart
+partrc_DATA = kxsldbg_part.rc
+
+KDE_ICON = AUTO
+
diff --git a/kxsldbg/kxsldbgpart/dummy.cpp b/kxsldbg/kxsldbgpart/dummy.cpp
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/dummy.cpp
diff --git a/kxsldbg/kxsldbgpart/hi16-action-1downarrow.png b/kxsldbg/kxsldbgpart/hi16-action-1downarrow.png
new file mode 100644
index 00000000..f545e039
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-1downarrow.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi16-action-configure.png b/kxsldbg/kxsldbgpart/hi16-action-configure.png
new file mode 100644
index 00000000..95bd319c
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-configure.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi16-action-exit.png b/kxsldbg/kxsldbgpart/hi16-action-exit.png
new file mode 100644
index 00000000..3ce53009
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-exit.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi16-action-hash.png b/kxsldbg/kxsldbgpart/hi16-action-hash.png
new file mode 100644
index 00000000..dd8c43ce
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-hash.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi16-action-mark.png b/kxsldbg/kxsldbgpart/hi16-action-mark.png
new file mode 100644
index 00000000..8ab861a1
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-mark.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi16-action-next.png b/kxsldbg/kxsldbgpart/hi16-action-next.png
new file mode 100644
index 00000000..a9300537
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-next.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi16-action-run.png b/kxsldbg/kxsldbgpart/hi16-action-run.png
new file mode 100644
index 00000000..215fc6aa
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-run.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi16-action-step.png b/kxsldbg/kxsldbgpart/hi16-action-step.png
new file mode 100644
index 00000000..56f1baf6
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-step.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi16-action-xsldbg_break.png b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_break.png
new file mode 100644
index 00000000..543710fb
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_break.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi16-action-xsldbg_data.png b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_data.png
new file mode 100644
index 00000000..6f359b41
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_data.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi16-action-xsldbg_delete.png b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_delete.png
new file mode 100644
index 00000000..6d0d29d7
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_delete.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi16-action-xsldbg_enable.png b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_enable.png
new file mode 100644
index 00000000..59522882
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_enable.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi16-action-xsldbg_output.png b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_output.png
new file mode 100644
index 00000000..0d826bbf
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_output.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi16-action-xsldbg_refresh.png b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_refresh.png
new file mode 100644
index 00000000..5c6a26dd
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_refresh.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi16-action-xsldbg_source.png b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_source.png
new file mode 100644
index 00000000..4e1c214c
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_source.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi16-action-xsldbg_stepdown.png b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_stepdown.png
new file mode 100644
index 00000000..4eec6e5a
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_stepdown.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi16-action-xsldbg_stepup.png b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_stepup.png
new file mode 100644
index 00000000..22220d87
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi16-action-xsldbg_stepup.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi22-action-1downarrow.png b/kxsldbg/kxsldbgpart/hi22-action-1downarrow.png
new file mode 100644
index 00000000..6dce81ca
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi22-action-1downarrow.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi22-action-configure.png b/kxsldbg/kxsldbgpart/hi22-action-configure.png
new file mode 100644
index 00000000..96ba4338
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi22-action-configure.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi22-action-exit.png b/kxsldbg/kxsldbgpart/hi22-action-exit.png
new file mode 100644
index 00000000..119e5ef7
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi22-action-exit.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi22-action-next.png b/kxsldbg/kxsldbgpart/hi22-action-next.png
new file mode 100644
index 00000000..cfab7cfb
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi22-action-next.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi22-action-run.png b/kxsldbg/kxsldbgpart/hi22-action-run.png
new file mode 100644
index 00000000..b5c89495
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi22-action-run.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi22-action-step.png b/kxsldbg/kxsldbgpart/hi22-action-step.png
new file mode 100644
index 00000000..a0e64fc0
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi22-action-step.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi22-action-xsldbg_break.png b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_break.png
new file mode 100644
index 00000000..31c064ba
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_break.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi22-action-xsldbg_data.png b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_data.png
new file mode 100644
index 00000000..bcd6c2f5
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_data.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi22-action-xsldbg_delete.png b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_delete.png
new file mode 100644
index 00000000..6fb193f0
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_delete.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi22-action-xsldbg_enable.png b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_enable.png
new file mode 100644
index 00000000..aa6ed24c
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_enable.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi22-action-xsldbg_output.png b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_output.png
new file mode 100644
index 00000000..bb4a9447
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_output.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi22-action-xsldbg_refresh.png b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_refresh.png
new file mode 100644
index 00000000..3fa8db76
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_refresh.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi22-action-xsldbg_source.png b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_source.png
new file mode 100644
index 00000000..1f9c87bb
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_source.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi22-action-xsldbg_stepdown.png b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_stepdown.png
new file mode 100644
index 00000000..384f0c32
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_stepdown.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/hi22-action-xsldbg_stepup.png b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_stepup.png
new file mode 100644
index 00000000..fffef2ec
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/hi22-action-xsldbg_stepup.png
Binary files differ
diff --git a/kxsldbg/kxsldbgpart/kxsldbg_part.cpp b/kxsldbg/kxsldbgpart/kxsldbg_part.cpp
new file mode 100644
index 00000000..5c4742ab
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/kxsldbg_part.cpp
@@ -0,0 +1,875 @@
+#include "kxsldbg_part.h"
+#include "libxsldbg/files.h"
+#include "libxsldbg/xsldbg.h"
+
+#include <kinstance.h>
+#include <kaction.h>
+#include <kstdaction.h>
+#include <kfiledialog.h>
+#include <kparts/genericfactory.h>
+#include <ktexteditor/markinterface.h>
+#include <ktexteditor/editinterface.h>
+#include <ktexteditor/viewcursorinterface.h>
+#include <ktexteditor/configinterface.h>
+#include <kate/view.h>
+
+#include <qfile.h>
+#include <qtextstream.h>
+
+#include "../kxsldbg.h"
+#include <kaction.h>
+#include <kcmdlineargs.h>
+#include <kinstance.h>
+#include <kiconloader.h>
+#include <qmessagebox.h>
+#include <klocale.h>
+#include <kdeversion.h>
+#if KDE_IS_VERSION(3,1,90)
+#include <kinputdialog.h>
+#else
+#include <klineeditdlg.h>
+#endif
+
+// Qxsldbg specific includes
+#include "qxsldbgdoc.h"
+#include <qvariant.h>
+#include <qfile.h>
+#include <qstatusbar.h>
+#include <qsplitter.h>
+#include <qvbox.h>
+
+
+#include <qmime.h>
+#include <qdragobject.h>
+#include <qlayout.h>
+#include <qtooltip.h>
+#include <qwhatsthis.h>
+#include <qaction.h>
+#include <qmenubar.h>
+#include <qpopupmenu.h>
+#include <qtoolbar.h>
+#include <qimage.h>
+#include <qpixmap.h>
+#include <qtextstream.h>
+#include <qtextbrowser.h>
+#include <qmessagebox.h>
+#include <qlineedit.h>
+#include <qdockwindow.h>
+#include <qpushbutton.h>
+#include <qinputdialog.h>
+#include <qobjectlist.h>
+#include <qwidgetstack.h>
+#include "xsldbgoutputview.h"
+#include "xsldbgconfigimpl.h"
+#include <kdebug.h>
+#include "xsldbgdebugger.h"
+
+typedef KParts::GenericFactory<KXsldbgPart> KXsldbgPartFactory;
+K_EXPORT_COMPONENT_FACTORY( libkxsldbgpart, KXsldbgPartFactory )
+
+KXsldbgPart::KXsldbgPart( QWidget *parentWidget, const char * /*widgetName*/,
+ QObject *parent, const char *name,
+ const QStringList & /*args*/ )
+ : DCOPObject("KXsldbgPart"), KParts::ReadOnlyPart(parent, name)
+{
+ currentLineNo = 0;
+ currentColumnNo = 0;
+ inspector = 0L;
+ debugger = 0L;
+ configWidget = 0L;
+ currentDoc = 0L;
+
+ // we need an instance
+ setInstance( KXsldbgPartFactory::instance() );
+ QVBox *frame = new QVBox(parentWidget);
+ QHBox *h = new QHBox(frame);
+ newXPath = new QLineEdit(h);
+ xPathBtn = new QPushButton(i18n("Goto XPath"), h);
+/* Disable searching as searching documentation is not ready
+ h = new QHBox(frame);
+ newSearch = new QLineEdit(h);
+ searchBtn = new QPushButton(i18n("Search"), h);
+*/
+ h = new QHBox(frame);
+ newEvaluate = new QLineEdit(h);
+ evaluateBtn = new QPushButton(i18n("Evaluate"), h);
+
+ QSplitter *splitter = new QSplitter(QSplitter::Vertical, frame);
+ mainView = new QWidgetStack(splitter);
+ mainView->setMinimumHeight(400); //## TODO don't use a magic number
+ outputview = new XsldbgOutputView(splitter);
+ setWidget(frame);
+ docDictionary.setAutoDelete(true);
+
+ // create our actions
+ KStdAction::open(this, SLOT(fileOpen()), actionCollection());
+
+ // set our XML-UI resource file
+ setXMLFile("kxsldbg_part.rc");
+ (void) new KAction( i18n("Configure Editor..."),
+ "configure", 0,
+ this, SLOT(configureEditorCmd_activated()),
+ actionCollection(), "configureEditorCmd" );
+ (void) new KAction( i18n("Configure..."),
+ "configure", Key_C,
+ this, SLOT(configureCmd_activated()),
+ actionCollection(), "configureCmd" );
+
+ (void) new KAction( i18n("Inspect..."),
+ "find", Key_I,
+ this, SLOT(inspectorCmd_activated()),
+ actionCollection(), "inspectCmd" );
+
+
+ // Motions commands
+ (void) new KAction( i18n("Run"),
+ "run", Key_F5,
+ this, SLOT(runCmd_activated()),
+ actionCollection(), "runCmd" );
+
+ (void) new KAction( i18n("Continue"),
+ "1downarrow", Key_F4,
+ this, SLOT(continueCmd_activated()),
+ actionCollection(), "continueCmd" );
+
+ (void) new KAction( i18n("Step"),
+ "step", Key_F8,
+ this, SLOT(stepCmd_activated()),
+ actionCollection(), "stepCmd" );
+
+ (void) new KAction( i18n("Next"),
+ "next", Key_F10,
+ this, SLOT(nextCmd_activated()),
+ actionCollection(), "nextCmd" );
+
+ (void) new KAction( i18n("Step Up"),
+ "xsldbg_stepup", Key_F6,
+ this, SLOT(stepupCmd_activated()),
+ actionCollection(), "stepupCmd" );
+
+ (void) new KAction( i18n("Step Down"),
+ "xsldbg_stepdown", Key_F7,
+ this, SLOT(stepCmd_activated()),
+ actionCollection(), "stepdownCmd" );
+
+ // Breakpoint commands
+ (void) new KAction( i18n("Break"),
+ "xsldbg_break", Key_F2,
+ this, SLOT(breakCmd_activated()),
+ actionCollection(), "breakCmd" );
+
+ (void) new KAction( i18n("Enable/Disable"),
+ "xsldbg_enable", Key_F3,
+ this, SLOT(enableCmd_activated()),
+ actionCollection(), "enableCmd" );
+
+ (void) new KAction( i18n("Delete"),
+ "xsldbg_delete", Key_Delete,
+ this, SLOT(deleteCmd_activated()),
+ actionCollection(), "deleteCmd" );
+
+ (void) new KAction( i18n("&Source"),
+ "xsldbg_source", Key_S,
+ this, SLOT(sourceCmd_activated()),
+ actionCollection(), "sourceCmd" );
+
+ (void) new KAction( i18n("&Data"),
+ "xsldbg_data", Key_D,
+ this, SLOT(dataCmd_activated()),
+ actionCollection(), "dataCmd" );
+
+ (void) new KAction( i18n("&Output"),
+ "xsldbg_output", Key_O,
+ this, SLOT(outputCmd_activated()),
+ actionCollection(), "outputCmd" );
+
+ (void) new KAction( i18n("Reload Current File From Disk"),
+ "xsldbg_refresh", CTRL + Key_F5,
+ this, SLOT(refreshCmd_activated()),
+ actionCollection(), "refreshCmd" );
+
+ /* tracing and walking */
+ (void) new KAction( i18n("Walk Through Stylesheet..."),
+ Key_W,
+ this, SLOT(walkCmd_activated()),
+ actionCollection(), "walkCmd" );
+ (void) new KAction( i18n("Stop Wal&king Through Stylesheet"),
+ Key_K,
+ this, SLOT(walkStopCmd_activated()),
+ actionCollection(), "walkStopCmd" );
+ (void) new KAction( i18n("Tr&ace Execution of Stylesheet"),
+ Key_A,
+ this, SLOT(traceCmd_activated()),
+ actionCollection(), "traceCmd" );
+ (void) new KAction( i18n("Stop Tracing of Stylesheet"),
+ Key_K,
+ this, SLOT(traceStopCmd_activated()),
+ actionCollection(), "traceStopCmd" );
+
+ (void) new KAction( i18n("&Evaluate Expression..."),
+ Key_E,
+ this, SLOT(evaluateCmd_activated()),
+ actionCollection(), "evaluateCmd" );
+
+ (void) new KAction( i18n("Goto &XPath..."),
+ Key_X,
+ this, SLOT(gotoXPathCmd_activated()),
+ actionCollection(), "gotoXPathCmd" );
+
+ (void) new KAction( i18n("Lookup SystemID..."),
+ 0,
+ this, SLOT(slotLookupSystemID()),
+ actionCollection(), "lookupSystemID" );
+
+ (void) new KAction( i18n("Lookup PublicID..."),
+ 0,
+ this, SLOT(slotLookupPublicID()),
+ actionCollection(), "lookupPublicID" );
+
+ (void) new KAction( i18n("Quit"),
+ 0, CTRL + Key_Q,
+ this, SLOT(quit()),
+ actionCollection(), "file_quit" );
+
+ /*
+ (void) new KAction( i18n("Exit KXsldbg"),
+ "xsldbg_output", CTRL + Key_Q,
+ this, SLOT(exitCmd_activated()),
+ actionCollection(), "exitCmd" );
+ */
+ connect( xPathBtn, SIGNAL( clicked() ),
+ this, SLOT( slotGotoXPath() ) );
+ connect( evaluateBtn, SIGNAL( clicked() ),
+ this, SLOT( slotEvaluate() ) );
+/*
+
+ connect( searchBtn, SIGNAL( clicked() ),
+ this, SLOT( slotSearch() ) );
+*/
+/* We must have a valid debugger and inspector */
+ createInspector();
+ if (checkDebugger()){
+ configWidget = new XsldbgConfigImpl( debugger, 0L );
+ Q_CHECK_PTR( configWidget );
+ debugger->start();
+ }else{
+ openURL("");
+ }
+}
+
+KXsldbgPart::~KXsldbgPart()
+{
+ docDictionary.clear();
+}
+
+void KXsldbgPart::quit()
+{
+ qWarning("Custom void KXsldbgPart::quit()");
+ closeURL();
+}
+
+
+KAboutData *KXsldbgPart::createAboutData()
+{
+ // the non-i18n name here must be the same as the directory in
+ // which the part's rc file is installed ('partrcdir' in the
+ // Makefile)
+ KAboutData *aboutData = new KAboutData("kxsldbgpart", I18N_NOOP("KXsldbgPart"), "0.1");
+ aboutData->addAuthor("Keith Isdale", 0L, "k_isdale@tpg.com.au");
+ return aboutData;
+}
+
+
+bool KXsldbgPart::openURL(const KURL &url)
+{
+ bool result = fetchURL(url);
+ if (result){
+ QXsldbgDoc *docPtr = docDictionary[url.prettyURL()];
+ if (docPtr && docPtr->kateView()){
+ if (docPtr != currentDoc){
+ currentDoc = docPtr;
+ currentFileName = url.prettyURL();
+ mainView->raiseWidget(currentDoc->kateView());
+ emit setWindowCaption(currentDoc->url().prettyURL());
+ }
+ } else{
+ result = false;
+ }
+ }
+
+ return result;
+}
+
+
+/* Don't show the content of URL just loaded it into our data structures */
+bool KXsldbgPart::fetchURL(const KURL &url)
+{
+ QString docID = url.prettyURL();
+ QXsldbgDoc *docPtr = docDictionary[docID];
+ if (!docPtr){
+ docPtr = new QXsldbgDoc(mainView, url);
+ docDictionary.insert(docID, docPtr);
+ if (docPtr->kateView()){
+ mainView->addWidget(docPtr->kateView());
+ Kate::View *v = Kate::view((docPtr->kateView()));
+ connect(v, SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChanged()));
+ }
+ }
+
+ return true;
+}
+
+bool KXsldbgPart::openFile()
+{
+ qWarning("bool KXsldbgPart::openFile() called");
+ return false;
+}
+
+bool KXsldbgPart::closeURL()
+{
+ docDictionary.clear();
+ return true;
+}
+
+void KXsldbgPart::fileOpen()
+{
+ // this slot is called whenever the File->Open menu is selected,
+ // the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
+ // button is clicked
+ QString file_name = KFileDialog::getOpenFileName();
+
+ if (file_name.isEmpty() == false)
+ openURL(KURL( file_name ));
+}
+
+void KXsldbgPart::configureEditorCmd_activated()
+{
+ if (currentDoc){
+ KTextEditor::ConfigInterface *configIf = KTextEditor::configInterface(currentDoc->kateDoc());
+ if (configIf)
+ configIf->configDialog();
+ }
+}
+
+bool KXsldbgPart::checkDebugger()
+{
+ bool result = debugger != 0L;
+ if (!result){
+ QMessageBox::information(0L, i18n("Debugger Not Ready"),
+ i18n("Configure and start the debugger first."),
+ QMessageBox::Ok);
+ }
+
+ return result;
+}
+
+
+void KXsldbgPart::lookupSystemID( QString systemID)
+{
+ bool ok = false;
+ if (!checkDebugger())
+ return;
+
+ if (systemID.isEmpty()){
+#if KDE_IS_VERSION(3, 1, 90)
+ systemID = KInputDialog::getText(
+ i18n( "Lookup SystemID" ),
+ i18n( "Please enter SystemID to find:" ),
+ QString::null, &ok,
+ mainView);
+#else
+ systemID = QInputDialog::getText(
+ i18n( "Lookup SystemID" ),
+ i18n( "Please enter SystemID to find:" ),
+ QLineEdit::Normal, QString::null, &ok,
+ mainView);
+#endif
+ }else{
+ ok = true;
+ }
+ if ( ok && !systemID.isEmpty() ){
+ // user entered something and pressed ok
+ QString msg(QString("system %1").arg(systemID)); // noTr
+ debugger->fakeInput(msg, true);
+ }
+
+}
+
+
+void KXsldbgPart::lookupPublicID(QString publicID)
+{
+ bool ok = false;
+ if (!checkDebugger())
+ return;
+
+ if (publicID.isEmpty()){
+#if KDE_IS_VERSION(3, 1, 90)
+ publicID = KInputDialog::getText(
+ i18n( "Lookup PublicID" ),
+ i18n( "Please enter PublicID to find:" ),
+ QString::null, &ok, mainView );
+#else
+ publicID = QInputDialog::getText(
+ i18n( "Lookup PublicID" ),
+ i18n( "Please enter PublicID to find:" ),
+ QLineEdit::Normal, QString::null, &ok, mainView );
+#endif
+ }else{
+ ok = true;
+ }
+ if ( ok && !publicID.isEmpty()){
+ // user entered something and pressed ok
+ QString msg(QString("public %1").arg(publicID)); // noTr
+ debugger->fakeInput(msg, true);
+ }
+}
+
+
+void KXsldbgPart::slotLookupSystemID()
+{
+ lookupSystemID("");
+}
+
+void KXsldbgPart::slotLookupPublicID()
+{
+ lookupPublicID("");
+}
+
+void KXsldbgPart::configureCmd_activated()
+{
+ if (!checkDebugger())
+ return;
+
+ if (configWidget != 0L){
+ configWidget->refresh();
+ configWidget->show();
+ }
+}
+
+void
+KXsldbgPart::runCmd_activated()
+{
+ if ( checkDebugger() )
+ debugger->slotRunCmd();
+}
+
+void KXsldbgPart::inspectorCmd_activated()
+{
+ if (inspector == 0L)
+ createInspector();
+
+ if (checkDebugger() && (inspector != 0L)){
+ inspector->show();
+ }
+}
+
+
+void KXsldbgPart::createInspector()
+{
+ if ( inspector == 0L ) {
+ debugger = new XsldbgDebugger();
+ Q_CHECK_PTR( debugger );
+ if ( debugger != 0L ) {
+ connect(debugger, SIGNAL( debuggerReady()),
+ this, SLOT(debuggerStarted()));
+ if (outputview){
+ connect(debugger,
+ SIGNAL( showMessage(QString /* msg*/)),
+ outputview,
+ SLOT(slotProcShowMessage(QString /* msg*/)));
+ }
+ inspector = new XsldbgInspector( debugger );
+ Q_CHECK_PTR( inspector );
+ debugger->setInspector( inspector );
+ if (inspector != 0L){
+ /*process line number and/or file name changed */
+ connect(debugger,
+ SIGNAL(lineNoChanged
+ (QString /* fileName */ ,
+ int /* lineNumber */ ,
+ bool /* breakpoint */ ) ),
+ this,
+ SLOT(lineNoChanged
+ ( QString /* fileName */ ,
+ int /* lineNumber */ ,
+ bool /* breakpoint */ ) ) );
+ connect(debugger,
+ SIGNAL(breakpointItem(QString /* fileName*/,
+ int /* lineNumber */,
+ QString /*templateName*/,
+ QString /* modeName */,
+ bool /* enabled */,
+ int /* id */)),
+ this,
+ SLOT( breakpointItem(QString /* fileName*/,
+ int /* lineNumber */,
+ QString /*templateName*/,
+ QString /* modeName */,
+ bool /* enabled */,
+ int /* id */)));
+ connect(debugger, SIGNAL(resolveItem(QString /*URI*/)),
+ this, SLOT(slotProcResolveItem(QString /*URI*/)));
+ }
+ }
+ }
+}
+
+void KXsldbgPart::emitOpenFile(QString file, int line, int row)
+{
+ QByteArray params;
+ QDataStream stream(params, IO_WriteOnly);
+ stream << file << line << row;
+ emitDCOPSignal("openFile(QString,int,int)", params);
+}
+void KXsldbgPart::continueCmd_activated()
+{
+ if ( checkDebugger() )
+ debugger->slotContinueCmd();
+
+}
+
+void KXsldbgPart::stepCmd_activated()
+{
+ if ( checkDebugger() )
+ debugger->slotStepCmd();
+}
+
+void KXsldbgPart::nextCmd_activated()
+{
+ if ( checkDebugger() )
+ debugger->fakeInput("next", true); // noTr
+}
+
+
+void KXsldbgPart::stepupCmd_activated()
+{
+ if ( checkDebugger() )
+ debugger->fakeInput("stepup", true); // noTr
+}
+
+
+void KXsldbgPart::stepdownCmd_activated()
+{
+ if ( checkDebugger() )
+ debugger->fakeInput("stepdown", true); // noTr
+}
+
+
+void KXsldbgPart::dataCmd_activated()
+{
+ if ( checkDebugger() )
+ debugger->slotDataCmd();
+}
+
+void
+KXsldbgPart::sourceCmd_activated()
+{
+ if ( checkDebugger() )
+ debugger->slotSourceCmd();
+}
+
+void
+KXsldbgPart::outputCmd_activated()
+{
+ if ( ( inspector != 0L ) && checkDebugger() && ( configWidget != 0L ) ){
+ debugger->setOutputFileActive(true);
+ lineNoChanged( configWidget->getOutputFile(), 1, false );
+ refreshCmd_activated();
+ }
+}
+
+void KXsldbgPart::refreshCmd_activated()
+{
+
+ if ( !currentFileName.isEmpty() ){
+ QDictIterator<QXsldbgDoc> it(docDictionary);
+ QXsldbgDoc *docPtr;
+ while (it.current()){
+ docPtr = it.current();
+ docPtr->refresh();
+ ++it;
+ }
+ if ( checkDebugger() ){
+ debugger->fakeInput("showbreak", true); // noTr
+ }
+ }
+}
+
+void KXsldbgPart::enableCmd_activated()
+{
+ if ( checkDebugger() ){
+ debugger->slotEnableCmd( currentFileName, currentLineNo);
+ }
+}
+
+void KXsldbgPart::deleteCmd_activated()
+{
+ if ( checkDebugger() ){
+ debugger->slotDeleteCmd( currentFileName, currentLineNo);
+ }
+}
+
+void KXsldbgPart::breakCmd_activated()
+{
+ if ( checkDebugger() ){
+ debugger->slotBreakCmd( currentFileName, currentLineNo);
+ }
+}
+
+void KXsldbgPart::evaluateCmd_activated()
+{
+#if KDE_IS_VERSION(3,1,90)
+ QString expression = KInputDialog::getText(i18n("Evalute Expression"), i18n("XPath:"));
+#else
+ QString expression = KLineEditDlg::getText(i18n("Evalute Expression"), i18n("XPath:"));
+#endif
+ if (checkDebugger() && (expression.length() > 0)){
+ debugger->slotCatCmd( expression);
+ }
+}
+
+void KXsldbgPart::gotoXPathCmd_activated()
+{
+#if KDE_IS_VERSION(3,1,90)
+ QString xpath = KInputDialog::getText(i18n("Goto XPath"), i18n("XPath:"));
+#else
+ QString xpath = KLineEditDlg::getText(i18n("Goto XPath"), i18n("XPath:"));
+#endif
+ if (checkDebugger() && xpath.length() > 0){
+ debugger->slotCdCmd( xpath );
+ }
+}
+
+void
+KXsldbgPart::lineNoChanged(QString fileName, int lineNumber, bool breakpoint)
+{
+ if ( fileName.isEmpty() ) {
+ kdDebug() << "Empty file Name" << endl; // noTr
+ return;
+ }
+
+ openURL(fileName);
+
+ QXsldbgDoc *docPtr;
+ QDictIterator<QXsldbgDoc> it(docDictionary);
+ while (it.current()){
+ docPtr = it.current();
+ // cause all Execution and BreakpointReached marks to be cleared
+ docPtr->clearMarks(false);
+ ++it;
+ }
+ /* Did we stop at a breakpoint if so move the marker */
+ if (currentDoc) {
+ currentDoc->selectBreakPoint(lineNumber -1, breakpoint);
+ QByteArray params;
+ QDataStream stream(params, IO_WriteOnly);
+ stream << currentFileName << lineNumber;
+ emitDCOPSignal("debuggerPositionChanged(QString,int)", params);
+ }else {
+ qWarning("Unable to retrieve document from internal cache");
+ }
+
+
+ /* Move cursor and update status bar */
+ if (currentDoc && currentDoc->kateView()){
+ KTextEditor::ViewCursorInterface *cursorIf = KTextEditor::viewCursorInterface(currentDoc->kateView());
+ if (cursorIf){
+ cursorIf->setCursorPositionReal(lineNumber - 1, 0);
+ currentLineNo = lineNumber;
+ }
+ }
+}
+
+void KXsldbgPart::cursorPositionChanged()
+{
+ if (currentDoc && currentDoc->kateView()){
+ KTextEditor::ViewCursorInterface *viewCurIf = KTextEditor::viewCursorInterface(currentDoc->kateView());
+ if (viewCurIf){
+ viewCurIf->cursorPosition(&currentLineNo, &currentColumnNo);
+ currentLineNo++;
+ currentColumnNo++;
+ QByteArray params;
+ QDataStream stream(params, IO_WriteOnly);
+ stream << currentFileName << currentLineNo << currentColumnNo;
+ emitDCOPSignal("editorPositionChanged(QString,int,int)", params);
+ }
+ }
+}
+
+void KXsldbgPart::docChanged()
+{
+ if (!currentDoc || currentDoc->kateDoc() || currentDoc->kateView())
+ return;
+}
+
+void KXsldbgPart::debuggerStarted()
+{
+ if (configWidget != 0L){
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ if (args){
+ int i=0, result=1, noFilesFound = 0;
+ QString expandedName; /* contains file name with path expansion if any */
+
+ for (i = 0; i < args->count(); i++) {
+ if (!result)
+ break;
+
+ if (args->arg(i)[0] != '-') {
+ expandedName = QString::fromUtf8((const char*)filesExpandName((const xmlChar*)args->arg(i)));
+ if (expandedName.isEmpty()) {
+ result = 0;
+ break;
+ }
+ switch (noFilesFound) {
+ case 0:
+ configWidget->slotSourceFile(expandedName);
+ noFilesFound++;
+ break;
+ case 1:
+ configWidget->slotDataFile(expandedName);
+ noFilesFound++;
+ break;
+ case 2:
+ configWidget->slotOutputFile(expandedName);
+ noFilesFound++;
+ break;
+
+ default:
+ xsldbgGenericErrorFunc(i18n("Error: Too many file names supplied via command line.\n"));
+ result = 0;
+ }
+ continue;
+ }
+ }
+ configWidget->refresh();
+ configWidget->show();
+ }
+ }
+}
+
+void KXsldbgPart::addBreakPoint(int lineNumber)
+{
+ if ( checkDebugger() ){
+ debugger->slotBreakCmd( currentFileName, lineNumber);
+ }
+}
+
+void KXsldbgPart::enableBreakPoint(int lineNumber)
+{
+ if ( checkDebugger() ){
+ debugger->slotEnableCmd( currentFileName, lineNumber);
+ }
+}
+
+
+void KXsldbgPart::deleteBreakPoint(int lineNumber)
+{
+ if ( checkDebugger() ){
+ debugger->slotDeleteCmd( currentFileName, lineNumber);
+ }
+}
+
+
+
+void KXsldbgPart::slotSearch()
+{
+ if ((newSearch != 0L) && checkDebugger() ) {
+ QString msg(QString("search \"%1\"").arg(newSearch->text())); // noTr
+ debugger->fakeInput(msg, false);
+ }
+}
+
+
+void KXsldbgPart::slotEvaluate()
+{
+ if ((newEvaluate != 0L) && checkDebugger() ){
+ debugger->slotCatCmd( newEvaluate->text() );
+ }
+}
+
+void KXsldbgPart::slotGotoXPath()
+{
+ if ((newXPath != 0L) && checkDebugger() ){
+ debugger->slotCdCmd( newXPath->text() );
+ }
+}
+
+
+
+void KXsldbgPart::slotProcResolveItem(QString URI)
+{
+ if (!URI.isEmpty()){
+ QMessageBox::information(mainView, i18n("SystemID or PublicID Resolution Result"),
+ i18n("SystemID or PublicID has been resolved to\n.%1").arg(URI),
+ QMessageBox::Ok);
+ }
+}
+
+void KXsldbgPart::breakpointItem(QString fileName, int lineNumber ,
+ QString /*templateName*/, QString /* modeName */,
+ bool enabled , int /* id */)
+{
+
+ if (fileName == 0L){
+ /* Go through all documents and remove all breakpoints */
+ QDictIterator<QXsldbgDoc> it(docDictionary);
+ QXsldbgDoc *docPtr;
+ while (it.current()){
+ docPtr = it.current();
+ docPtr->clearMarks(true);
+ ++it;
+ }
+ }else{
+/*
+ if (!fileName.contains("://")){
+ // relative path ? must handle this special case
+ KURL url;
+ url.setFileName(fileName);
+ fetchURL(url);
+ }else{
+ fetchURL(fileName);
+ }
+*/
+ fileName = XsldbgDebugger::fixLocalPaths(fileName);
+ KURL temp(fileName);
+ fileName = temp.prettyURL();
+ fetchURL(fileName);
+ QXsldbgDoc *docPtr = docDictionary[fileName] ;
+ if (docPtr){
+ docPtr->addBreakPoint(lineNumber - 1, enabled);
+ }else {
+ qWarning("Unable to get doc %s from docDictionary", fileName.local8Bit().data());
+ }
+ }
+}
+
+
+
+void KXsldbgPart::walkCmd_activated()
+{
+ if (checkDebugger()){
+ debugger->slotWalkCmd();
+ }
+}
+
+void KXsldbgPart::walkStopCmd_activated()
+{
+ if (checkDebugger()){
+ debugger->slotWalkStopCmd();
+ }
+}
+
+void KXsldbgPart::traceCmd_activated()
+{
+ if (checkDebugger()){
+ debugger->slotTraceCmd();
+ }
+}
+
+void KXsldbgPart::traceStopCmd_activated()
+{
+ walkStopCmd_activated();
+}
+
+
+#include "kxsldbg_part.moc"
diff --git a/kxsldbg/kxsldbgpart/kxsldbg_part.desktop b/kxsldbg/kxsldbgpart/kxsldbg_part.desktop
new file mode 100644
index 00000000..229c6cad
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/kxsldbg_part.desktop
@@ -0,0 +1,15 @@
+[Desktop Entry]
+Name=KXsldbgPart
+Name[de]=KXsldbg-Komponente
+Name[fr]=Module externe KXsldbg
+Name[ja]=KXsldbgPort
+Name[nds]=KXsldbg-Komponent
+Name[pl]=Osadzalny program KPart KXsldbg
+Name[pt_BR]=KXSsldbgPart
+Name[sv]=Kxsldbg-delprogram
+Name[ta]=KXsldbg பகுதி
+Name[tg]=Қисми KXsldbg
+MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
+ServiceTypes=KParts/ReadOnlyPart
+X-KDE-Library=libkxsldbgpart
+Type=Service
diff --git a/kxsldbg/kxsldbgpart/kxsldbg_part.h b/kxsldbg/kxsldbgpart/kxsldbg_part.h
new file mode 100644
index 00000000..1da5ceb8
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/kxsldbg_part.h
@@ -0,0 +1,170 @@
+#ifndef KXSLDBGKPART_H
+#define KXSLDBGKPART_H
+
+#include <kparts/part.h>
+#include <qvariant.h>
+#include <qdict.h>
+#include <qmainwindow.h>
+#include "xsldbgdebugger.h"
+#include "xsldbginspector.h"
+#include <dcopclient.h>
+#include "kxsldbg_partif.h"
+#include <ktexteditor/document.h>
+#include <ktexteditor/view.h>
+
+class QVBoxLayout;
+class QHBoxLayout;
+class QGridLayout;
+class QAction;
+class QActionGroup;
+class QToolBar;
+class QPopupMenu;
+class QTextBrowser;
+class QLineEdit;
+class QDockWindow;
+class QWidgetStack;
+
+class XsldbgBrkStatusView;
+class QXsldbgDoc;
+class XsldbgOutputView;
+class XsldbgConfigImpl;
+
+class QWidget;
+class QPainter;
+class KURL;
+class QMultiLineEdit;
+class KAboutData;
+
+typedef QDict<QXsldbgDoc> XsldbgDocDict;
+
+/**
+ * This is a "Part". It that does all the real work in a KPart
+ * application.
+ *
+ * @short Main Part
+ * @author Keith Isdale <k_isdale@tpg.com.au>
+ * @version 0.1
+ */
+class KXsldbgPart : public KParts::ReadOnlyPart, public KXsldbgPartIf
+{
+ Q_OBJECT
+
+public:
+ /**
+ * Default constructor
+ */
+ KXsldbgPart(QWidget *parentWidget, const char *widgetName,
+ QObject *parent, const char *name, const QStringList &args);
+
+ /**
+ * Destructor
+ */
+ virtual ~KXsldbgPart();
+
+ static KAboutData *createAboutData();
+
+
+ /** Checks the debugger, if it is not ready then
+ * display a error in a message box
+ *
+ * @returns TRUE if debugger is ready, otherwise FALSE
+ */
+ bool checkDebugger();
+ void lookupSystemID(QString systemID);
+ void lookupPublicID(QString publicID);
+ void createInspector();
+
+public slots:
+ virtual bool openURL(const KURL &url);
+ virtual bool closeURL();
+ void quit();
+ void emitOpenFile(QString file, int line, int row);
+ void slotLookupSystemID();
+ void slotLookupPublicID();
+ void walkCmd_activated();
+ void walkStopCmd_activated();
+ void traceCmd_activated();
+ void traceStopCmd_activated();
+ void configureEditorCmd_activated();
+
+ //Tool bar commands
+ void configureCmd_activated();
+ void inspectorCmd_activated();
+ void runCmd_activated();
+ void stepCmd_activated();
+ void nextCmd_activated();
+ void continueCmd_activated();
+ void stepupCmd_activated();
+ void stepdownCmd_activated();
+ void sourceCmd_activated();
+ void dataCmd_activated();
+ void outputCmd_activated();
+ void refreshCmd_activated();
+ void enableCmd_activated();
+ void breakCmd_activated();
+ void deleteCmd_activated();
+
+ /** Evaluate expression entered */
+ void evaluateCmd_activated();
+
+ /** Goto/display file XPath entered */
+ void gotoXPathCmd_activated();
+
+ virtual void lineNoChanged( QString fileName, int lineNumber,
+ bool breakpoint );
+
+ void addBreakPoint(int lineNumber);
+ void enableBreakPoint(int lineNumber);
+ void deleteBreakPoint(int lineNumber);
+
+ /** Evaluate expression entered in expressionEdit */
+ void slotEvaluate();
+
+ /** Goto/display file that matches XPath specified in xPathEdit */
+ void slotGotoXPath();
+
+ /** Run search on data base , see search.dtd for DTD of search database */
+ void slotSearch();
+
+ /* Process the the URI for SystemID or PublicID requested */
+ void slotProcResolveItem(QString URI);
+
+ /* used to get breakpoint list notfication */
+ void breakpointItem(QString fileName, int lineNumber ,
+ QString /*templateName*/, QString /* modeName */,
+ bool enabled , int /* id */);
+
+ void cursorPositionChanged();
+ void docChanged();
+
+ void debuggerStarted();
+
+protected:
+ /**
+ * This must be implemented by each part
+ */
+ virtual bool openFile();
+ bool fetchURL(const KURL &url);
+
+protected slots:
+ void fileOpen();
+
+private:
+ QXsldbgDoc *currentDoc;
+ QWidgetStack *mainView;
+
+ QPushButton *xPathBtn, *searchBtn, *evaluateBtn;
+ QLineEdit *newXPath, *newSearch, *newEvaluate;
+ QGridLayout* qxsldbgLayout;
+
+ uint currentLineNo, currentColumnNo;
+ XsldbgDocDict docDictionary;
+ XsldbgInspector *inspector;
+ XsldbgDebugger *debugger;
+ XsldbgConfigImpl *configWidget;
+ QString currentFileName;
+
+ XsldbgOutputView *outputview;
+};
+
+#endif // KXSLDBGPART_H
diff --git a/kxsldbg/kxsldbgpart/kxsldbg_part.rc b/kxsldbg/kxsldbgpart/kxsldbg_part.rc
new file mode 100644
index 00000000..b8daea6e
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/kxsldbg_part.rc
@@ -0,0 +1,61 @@
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui name="kxsldbg_part" version="1">
+<MenuBar>
+ <Menu name="debug"><text>Debug</text>
+ <Action name="configureCmd"/>
+ <Action name="inspectCmd"/>
+ <Action name="runCmd"/>
+ <Action name="continueCmd"/>
+ <Action name="stepCmd"/>
+ <Action name="nextCmd"/>
+ <Separator/>
+ <Action name="stepupCmd"/>
+ <Action name="stepdownCmd"/>
+ <Separator/>
+ <Action name="breakCmd"/>
+ <Action name="deleteCmd"/>
+ <Action name="enableCmd"/>
+ <Separator/>
+ <Action name="sourceCmd"/>
+ <Action name="dataCmd"/>
+ <Action name="outputCmd"/>
+ <Action name="refreshCmd"/>
+ <Separator/>
+ <Action name="walkCmd"/>
+ <Action name="walkStopCmd"/>
+ <Action name="traceCmd"/>
+ <Action name="traceStopCmd"/>
+ <Separator/>
+ <Action name="evaluateCmd"/>
+ <Action name="gotoXPathCmd"/>
+ <Action name="lookupSystemID"/>
+ <Action name="lookupPublicID"/>
+ </Menu>
+ <Menu name="settings"><text>&amp;Settings</text>
+ <Action name="configureEditorCmd"/>
+ </Menu>
+
+</MenuBar>
+
+<ToolBar name="debugToolBar">
+ <Action name="configureCmd"/>
+ <Action name="inspectCmd"/>
+ <Action name="runCmd"/>
+ <Action name="continueCmd"/>
+ <Action name="stepCmd"/>
+ <Action name="nextCmd"/>
+ <Separator/>
+ <Action name="stepupCmd"/>
+ <Action name="stepdownCmd"/>
+ <Separator/>
+ <Action name="breakCmd"/>
+ <Action name="deleteCmd"/>
+ <Action name="enableCmd"/>
+ <Separator/>
+ <Action name="sourceCmd"/>
+ <Action name="dataCmd"/>
+ <Action name="outputCmd"/>
+ <Action name="refreshCmd"/>
+ <Separator/>
+ </ToolBar>
+</kpartgui>
diff --git a/kxsldbg/kxsldbgpart/kxsldbg_partif.h b/kxsldbg/kxsldbgpart/kxsldbg_partif.h
new file mode 100644
index 00000000..bd537cec
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/kxsldbg_partif.h
@@ -0,0 +1,14 @@
+#ifndef KXSLDBG_PARTIF_H
+#define KXSLDBG_PARTIF_H
+
+#include <dcopobject.h>
+
+class KXsldbgPartIf : virtual public DCOPObject
+{
+ K_DCOP
+ k_dcop:
+
+ /* reserved for future expansion*/
+};
+
+#endif
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;
+}
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/Makefile.am b/kxsldbg/kxsldbgpart/libxsldbg/Makefile.am
new file mode 100644
index 00000000..aaea2e53
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/Makefile.am
@@ -0,0 +1,12 @@
+noinst_LTLIBRARIES = libxsldbg.la
+
+libxsldbg_la_METASOURCES = AUTO
+
+libxsldbg_la_SOURCES = allmoc.cpp xsldbgthread.cpp xsldbg.cpp xsldbgmsg.cpp variable_cmds.cpp utils.cpp trace_cmds.cpp template_cmds.cpp search_cmds.cpp search.cpp param_cmds.cpp os_cmds.cpp options_unix.cpp options.cpp option_cmds.cpp nodeview_cmds.cpp help_unix.cpp files_unix.cpp files.cpp file_cmds.cpp debugXSL.cpp debug.cpp callstack.cpp breakpoint_cmds.cpp breakpoint.cpp arraylist.cpp
+
+libxsldbg_la_LIBADD = $(LIBXSLT_LIBS)
+libxsldbg_la_LDFLAGS = $(all_libraries)
+
+AM_CPPFLAGS = -DDOCS_PATH=\"$(DOCS_PATH)\" -I.. $(LIBXSLT_CFLAGS) $(all_includes)
+
+KDE_OPTIONS= nofinal
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/allmoc.cpp b/kxsldbg/kxsldbgpart/libxsldbg/allmoc.cpp
new file mode 100644
index 00000000..41decae4
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/allmoc.cpp
@@ -0,0 +1,2 @@
+#include "../xsldbgdebugger.h"
+#include "qtnotifier2.h"
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/arraylist.cpp b/kxsldbg/kxsldbgpart/libxsldbg/arraylist.cpp
new file mode 100644
index 00000000..a9de14fe
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/arraylist.cpp
@@ -0,0 +1,240 @@
+
+/***************************************************************************
+ arraylist.c - define array implementation of a list
+ -------------------
+ begin : Sat Nov 10 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 "arraylist.h"
+#include <libxslt/xsltutils.h>
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+/**
+ * arrayListNew:
+ * @initialSize: The initial size of list
+ * @deleteFunction: The function to call to free items in the list
+ *
+ * Create a new list with a size of @initialSize
+ *
+ * Returns Non-null on success,
+ * NULL otherwise
+ */
+arrayListPtr
+arrayListNew(int initialSize, freeItemFunc deleteFunction)
+{
+ arrayListPtr list = NULL;
+
+ if (initialSize <= 0) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "arrayListNew invalid initialSize %d\n",
+ initialSize);
+#endif
+ } else
+ list = (arrayListPtr) xmlMalloc(sizeof(arrayList));
+
+ if (list) {
+ list->data = (void **) xmlMalloc(sizeof(void *) * initialSize);
+ list->deleteFunction = deleteFunction;
+ list->count = 0;
+ list->size = initialSize;
+ }
+
+ return list;
+}
+
+
+/**
+ * arrayListFree:
+ * @list: A valid list
+ *
+ * Free memory assocated with array list, if the array list
+ * has a valid deleteFunction then content with be freed with
+ * using that deleteFunction
+ */
+void
+arrayListFree(arrayListPtr list)
+{
+ if (!list)
+ return;
+
+ arrayListEmpty(list);
+ xmlFree(list->data);
+ xmlFree(list);
+}
+
+
+/**
+ * arrayListEmpty:
+ * @list: A valid list
+ *
+ * Empties the list of its content
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+arrayListEmpty(arrayListPtr list)
+{
+ int index, result = 0;
+
+ if (list) {
+ if (list->deleteFunction) {
+ for (index = 0; index < list->count; index++) {
+ if (list->data[index])
+ (*list->deleteFunction) (list->data[index]);
+ }
+ result = 1;
+ list->count = 0;
+ }
+ }
+ return result;
+}
+
+
+/**
+ * arrayListSize:
+ * @list: A valid list
+ *
+ * Return The maximum number elements this list can contain
+ *
+ * Returns The maximum number elements this list can contain
+ */
+int
+arrayListSize(arrayListPtr list)
+{
+ int result = 0;
+
+ if (list)
+ result = list->size;
+
+ return result;
+}
+
+
+/**
+ * arrayListCount:
+ * @list: A valid list
+ *
+ * Return the count of number items in list
+ *
+ * Returns The count of number items in list
+ */
+int
+arrayListCount(arrayListPtr list)
+{
+ int result = 0;
+
+ if (list)
+ result = list->count;
+
+ return result;
+}
+
+
+/**
+ * arrayListAdd:
+ * @list: A valid list
+ * @item: A valid list
+ *
+ * Add @item to @list
+ *
+ * Returns 1 if able to add @item to end of @list,
+ * 0 otherwise
+ */
+int
+arrayListAdd(arrayListPtr list, void *item)
+{
+ int result = 0;
+
+ if (list && item) {
+ if (list->count + 1 > list->size) {
+ /* grow the size of data */
+ void **temp;
+ int newSize, index;
+
+ if (list->size < DOUBLE_SIZE_MAX_ITEM)
+ newSize = list->size * 2;
+ else
+ newSize = (int) (list->size * 1.5);
+ temp = (void **) xmlMalloc(sizeof(void *) * newSize);
+ for (index = 0; index < list->count; index++) {
+ temp[index] = list->data[index];
+ }
+ xmlFree(list->data);
+ list->data = temp;
+ list->size = newSize;
+ }
+ list->data[list->count++] = item;
+ result = 1;
+ }
+ return result;
+}
+
+
+/**
+ * arrayListDelete:
+ * @list: A valid list
+ * @position: 0 =< @position < arrayListCount(@list)
+ *
+ * Delete item at position @position from @list
+ *
+ * Returns 1 if able to delete element in @list at position @position,
+ * 0 otherwise
+ */
+int
+arrayListDelete(arrayListPtr list, int position)
+{
+ int result = 0, index;
+
+ if (list && (list->count > 0) && (position >= 0) &&
+ (position < list->count) && list->data[position]) {
+ if (list->deleteFunction)
+ (*list->deleteFunction) (list->data[position]);
+
+ /* shuffle all elements upwards */
+ for (index = position; index < (list->count - 1); index++) {
+ list->data[index] = list->data[index + 1];
+ }
+ list->count--;
+ result = 1;
+ }
+ return result;
+}
+
+
+
+/**
+ * arrayListGet:
+ * @list: A valid list
+ * @position: 0 =< @position < arrayListCount(@list)
+ *
+ * Get item at position @position from @list
+ *
+ * Returns Non-null if able to retrieve element in @list at position @position,
+ * NULL otherwise
+ */
+void *
+arrayListGet(arrayListPtr list, int position)
+{
+ void *result = NULL;
+
+ if (list && (position >= 0) && (position < list->count)) {
+ result = list->data[position];
+ }
+ return result;
+}
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/arraylist.h b/kxsldbg/kxsldbgpart/libxsldbg/arraylist.h
new file mode 100644
index 00000000..81398459
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/arraylist.h
@@ -0,0 +1,291 @@
+
+/**************************************************************************
+ arraylist.h - declare the functions for
+ implementation of the array list
+ -------------------
+ begin : Sat Nov 10 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 ARRAYLIST_H
+#define ARRAYLIST_H
+
+#ifdef USE_KDE_DOCS
+
+/**
+ * Provide a fast easy to use array list. Support the basic functions of add
+ * delete, empty, count, free
+ *
+ * @short Array list support
+ *
+ * @author Keith Isdale <k_isdale@tpg.com.au>
+ */
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef USE_GNOME_DOCS
+
+#else
+#ifdef USE_KDE_DOCS
+
+#endif
+#endif
+
+
+ typedef void (*freeItemFunc) (void *item);
+ /* A dynamic structure behave like a list */
+ typedef struct _arrayList arrayList;
+ typedef arrayList *arrayListPtr;
+ struct _arrayList {
+ int size, count;
+ void **data;
+ freeItemFunc deleteFunction;
+ };
+
+/* what size of the list do we stop automatic doubling of capacity
+ if array list size growth is needed */
+#define DOUBLE_SIZE_MAX_ITEM 10
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * arrayListNew:
+ * @initialSize: The initial size of list
+ * @deleteFunction: The function to call to free items in the list
+ *
+ * Create a new list with a size of @initialSize
+ *
+ * Returns Non-null on success,
+ * NULL otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Create a new list with a size of @p initialSize
+ *
+ * @returns Non-null on success,
+ * NULL otherwise
+ *
+ * @param initial The initial size of list
+ * @param deleteFunction the Function to call to free items in the list
+ */
+#endif
+#endif
+ arrayListPtr arrayListNew(int initialSize,
+ freeItemFunc deleteFunction);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * arrayListFree:
+ * @list: A valid list
+ *
+ * Free memory assocated with array list, if the array list
+ * has a valid deleteFunction then content with be freed with
+ * using that deleteFunction
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Free memory assocated with array list, if the array list
+ * has a valid deleteFunction then content with be freed with
+ * using that deleteFunction
+ *
+ * @param list A valid list
+ */
+#endif
+#endif
+ void arrayListFree(arrayListPtr list);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * arrayListEmpty:
+ * @list: A valid list
+ *
+ * Empties the list of its content
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Empties the list of its content
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param list A valid list
+ */
+#endif
+#endif
+ int arrayListEmpty(arrayListPtr list);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * arrayListSize:
+ * @list: A valid list
+ *
+ * Return The maximum number elements this list can contain
+ *
+ * Returns The maximum number elements this list can contain
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Return the maximum number elements this list can contain
+ *
+ * @returns The maximum number elements this list can contain
+ *
+ * @param list A valid list
+ */
+#endif
+#endif
+ int arrayListSize(arrayListPtr list);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * arrayListCount:
+ * @list: A valid list
+ *
+ * Return the count of number items in list
+ *
+ * Returns The count of number items in list
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Return the count of number items in list
+ * @returns The count of number items in list
+ *
+ * @param list A valid list
+ */
+#endif
+#endif
+
+ int arrayListCount(arrayListPtr list);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * arrayListAdd:
+ * @list: A valid list
+ * @item:A valid item
+ *
+ * Add @item to @list
+ *
+ * Returns 1 if able to add @item to end of @list,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Add @p item to @p list
+ *
+ * @returns 1 if able to add @p item to end of @p list,
+ * 0 otherwise
+ *
+ * @param list A valid list
+ * @param item A valid item
+ */
+#endif
+#endif
+ int arrayListAdd(arrayListPtr list, void *item);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * arrayListDelete:
+ * @list: A valid list
+ * @position: 0 =< @position < arrayListCount(@list)
+ *
+ * Delete item at position @position from @list
+ *
+ * Returns 1 if able to delete element in @list at position @position,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * @returns 1 if able to delete element in @p list at position @p position,
+ * 0 otherwise
+ *
+ * @param list A valid list
+ * @param position 0 =< @p position < arrayListCount(@p list)
+ */
+#endif
+#endif
+ int arrayListDelete(arrayListPtr list, int position);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * arrayListGet:
+ * @list: A valid list
+ * @position: 0 =< @position < arrayListCount(@list)
+ *
+ * Get item at position @position from @list
+ *
+ * Returns Non-null if able to retrieve element in @list at position
+ * @position,
+ * NULL otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * @returns Non-null if able to retrieve element in @p list at position
+ * @p position,
+ * NULL otherwise
+ *
+ * @param list A valid list
+ * @param position 0 =< @p position < arrayListCount(@p list)
+ */
+#endif
+#endif
+ void *arrayListGet(arrayListPtr list, int position);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/breakpoint.cpp b/kxsldbg/kxsldbgpart/libxsldbg/breakpoint.cpp
new file mode 100644
index 00000000..270ce82d
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/breakpoint.cpp
@@ -0,0 +1,696 @@
+
+/***************************************************************************
+ breakpoint.c - breakpoint implementation
+ -------------------
+ begin : Fri Nov 2 2001
+ copyright : (C) 2001 by Keith Isdale
+ email : k_isdale@tpg.com.au
+ ***************************************************************************/
+
+#include "xsldbg.h"
+#include "breakpoint.h"
+#include "arraylist.h"
+#include "options.h"
+
+extern int xsldbgValidateBreakpoints; /*located in debugXSL.c*/
+
+/*-----------------------------------------------------------
+ Private functions
+-----------------------------------------------------------*/
+
+/**
+ * lineNoItemNew:
+ *
+ * Returns a new hash table for break points
+ */
+xmlHashTablePtr lineNoItemNew(void);
+
+
+/**
+ * lineNoItemFree:
+ * @item: valid hashtable of break points
+ *
+ * Free @item and all its contents
+ */
+void lineNoItemFree(void *item);
+
+
+/**
+ * lineNoItemDelete:
+ * @breakPointHash: Is valid
+ * @breakPtr: Is valid
+ *
+ * Returns 1 if able to delete @breakPtr from @breakPointHash,
+ * 0 otherwise
+ */
+int lineNoItemDelete(xmlHashTablePtr breakPointHash,
+ breakPointPtr breakPtr);
+
+/**
+ * lineNoItemAdd:
+ * @breakPointHash: is valid
+ * @breakPtr: is valid
+ *
+ * Add breakpoint to hash
+ *
+ * Returns 1 if able to add @breakPtr to @breakPointHash,
+ * 0 otherwise
+ */
+int lineNoItemAdd(xmlHashTablePtr breakPointHash, breakPointPtr breakPtr);
+
+/*-----------------------------------------------------------
+ Breakpoint debugger functions
+-----------------------------------------------------------*/
+
+
+/* This is our major structure, it is a list of hash tables. Each
+ hash table has breakpoints with the same line number. A line
+ number is used as an index into this list to get the right hash table.
+ Then its just a matter of a simple hash table lookup */
+arrayListPtr breakList;
+
+/* keep track of what break point id we're up to*/
+int breakPointCounter = 0;
+
+/* What is the current breakpoint is only valid up to the start of
+ xsldbg command prompt. ie don't use it after deletion of breakpoints */
+breakPointPtr activeBreakPointItem = NULL;
+
+
+/**
+ * lineNoItemNew:
+ *
+ * Returns a new hash table for break points
+ */
+xmlHashTablePtr
+lineNoItemNew(void)
+{
+ xmlHashTablePtr hash;
+
+ hash = xmlHashCreate(4);
+
+ return hash;
+}
+
+
+/**
+ * lineNoItemFree:
+ * @item: valid hashtable of break points
+ *
+ * Free @item and all its contents
+ */
+void
+lineNoItemFree(void *item)
+{
+ xmlHashTablePtr hash = (xmlHashTablePtr) item;
+
+ if (item) {
+#if 0
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Freeing breakpoint line hash"
+ " with %d elements \n", xmlHashSize(item));
+#endif
+#endif
+ xmlHashFree(hash, breakPointItemFree);
+ }
+}
+
+
+/**
+ * lineNoItemDelete:
+ * @breakPointHash: is valid
+ * @breakPtr: is valid
+ *
+ * Returns 1 if able to delete @breakPtr from @breakPointHash,
+ * 0 otherwise
+ */
+int
+lineNoItemDelete(xmlHashTablePtr breakPointHash, breakPointPtr breakPtr)
+{
+ int result = 0;
+
+ if (breakPointHash && breakPtr) {
+ if (xmlHashRemoveEntry(breakPointHash, breakPtr->url,
+ breakPointItemFree) == 0){
+ result = 1;
+ }else{
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,"lineNoItemDelete failed");
+#endif
+ }
+
+ }else {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext, "lineNoItemDelete failed args %d %d", breakPointHash, breakPtr);
+#endif
+ }
+ return result;
+}
+
+
+/**
+ * lineNoItemAdd:
+ * @breakPointHash: is valid
+ * @breakPtr: is valid
+ *
+ * Returns 1 if able to add @breakPtr to @breakPointHash,
+ * 0 otherwise
+ */
+int
+lineNoItemAdd(xmlHashTablePtr breakPointHash, breakPointPtr breakPtr)
+{
+ int result = 0;
+
+ if (breakPointHash && breakPtr) {
+ if (xmlHashAddEntry(breakPointHash, breakPtr->url, breakPtr) == 0)
+ result = 1;
+ }
+ return result;
+}
+
+/**
+ * breakPointGetLineNoHash:
+ * @lineNo: Line number of of breakpoints of interest
+ *
+ * Return A hash of breakpoints with same line number
+ *
+ * Returns A hash of breakpoints with a line number of @lineNo
+ */
+xmlHashTablePtr
+breakPointGetLineNoHash(long lineNo)
+{
+ if (!breakList) {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Breakpoints structures not initialized\n");
+#endif
+ return NULL;
+ } else
+ return (xmlHashTablePtr) arrayListGet(breakList, lineNo);
+}
+
+
+/**
+ * breakPointInit:
+ *
+ * Returns 1 if breakpoints have been initialized properly and all
+ * memory required has been obtained,
+ * 0 otherwise
+*/
+int
+breakPointInit(void)
+{
+ int result = 0;
+
+ /* the average file has 395 lines of code so add 100 lines now */
+ breakList = arrayListNew(100, lineNoItemFree);
+ if (breakList) {
+ /*
+ * We don't need to do any thing else, as its done when we add the
+ * breakPoints
+ */
+ result = 1;
+ } else {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Unable to intialize breakPoints: memory error\n");
+#endif
+ }
+ return result;
+}
+
+
+/**
+ * breakPointFree:
+ *
+ * Free all memory used by breakPoints
+ */
+void
+breakPointFree(void)
+{
+ if (breakList)
+ arrayListFree(breakList);
+ breakList = NULL;
+}
+
+
+/**
+ * breakPointEmpty:
+ *
+ * Empty the break point collection
+ *
+ * Returns 1 if able to empty the breakpoint list of its contents,
+ * 0 otherwise
+ */
+int
+breakPointEmpty(void)
+{
+ return arrayListEmpty(breakList);
+}
+
+
+/**
+ * breakPointItemNew:
+ *
+ * Create a new break point item
+ * Returns valid break point with default values set if successful,
+ * NULL otherwise
+ */
+breakPointPtr
+breakPointItemNew(void)
+{
+ breakPointPtr breakPtr = (breakPointPtr) xmlMalloc(sizeof(breakPoint));
+
+ if (breakPtr) {
+ breakPtr->url = NULL;
+ breakPtr->lineNo = -1;
+ breakPtr->templateName = NULL;
+ breakPtr->modeName = NULL;
+ breakPtr->flags = BREAKPOINT_ENABLED;
+ breakPtr->id = ++breakPointCounter;
+ breakPtr->type = DEBUG_BREAK_SOURCE;
+ }
+ return breakPtr;
+}
+
+
+/**
+ * breakPointItemFree:
+ * @payload: valid breakPointPtr
+ * @name: not used
+ *
+ * Free memory associated with this break point
+ */
+void
+breakPointItemFree(void *payload, xmlChar * name)
+{
+ Q_UNUSED(name);
+ if (payload) {
+ breakPointPtr breakPtr = (breakPointPtr) payload;
+
+ if (breakPtr->url)
+ xmlFree(breakPtr->url);
+ if (breakPtr->templateName)
+ xmlFree(breakPtr->templateName);
+ if (breakPtr->modeName)
+ xmlFree(breakPtr->modeName);
+ xmlFree(breakPtr);
+ }
+}
+
+
+/**
+ * breakPointActiveBreakPoint:
+ *
+ * Get the active break point
+ *
+ * Returns The last break point that we stoped at
+ *
+ * Depreciated
+ */
+breakPointPtr
+breakPointActiveBreakPoint(void)
+{
+ /* This function is depreciated */
+ return NULL; /* activeBreakPointItem; */
+}
+
+
+
+/**
+ * breakPointSetActiveBreakPoint:
+ * @breakPtr: Is valid break point or NULL
+ *
+ * Set the active break point
+ *
+ * Depreciated
+ */
+void
+breakPointSetActiveBreakPoint(breakPointPtr breakPtr)
+{
+ Q_UNUSED(breakPtr);
+ /*
+ * activeBreakPointItem = breakPtr;
+ */
+
+}
+
+
+/**
+ * breakPointAdd:
+ * @url: Non-null, non-empty file name that has been loaded by
+ * debugger
+ * @lineNumber: @lineNumber >= 0 and is available in url specified and
+ * points to an xml element
+ * @templateName: The template name of breakPoint or NULL
+ * @modeName : The mode of breakpoint or NULL
+ * @type: Valid BreakPointTypeEnum
+ *
+ * Add break point at file and line number specified
+ *
+ * Returns 1 if successful,
+ * 0 otherwise
+*/
+int
+breakPointAdd(const xmlChar * url, long lineNumber,
+ const xmlChar * templateName,
+ const xmlChar * modeName,
+ BreakPointTypeEnum type)
+{
+ int result = 0, breakPointType = type;
+ xmlHashTablePtr breakPointHash = NULL; /* hash of breakPoints */
+ breakPointPtr breakPtr;
+
+ if (!breakList) {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Breakpoints structures not initialized\n");
+#endif
+ return result;
+ }
+
+ if (!url || (lineNumber == -1)) {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Invalid url or line number to breakPointAdd\n");
+#endif
+ return result;
+ }
+
+ /* if breakpoint already exists then don;t add it */
+ if (breakPointIsPresent(url, lineNumber)) {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Warning: Breakpoint at file %s: line %d exists\n",
+ url, lineNumber);
+#endif
+ return result;
+ }
+
+ breakPtr = breakPointItemNew();
+ if (breakPtr) {
+ breakPtr->url = (xmlChar *) xmlMemStrdup((char *) url);
+ breakPtr->lineNo = lineNumber;
+ if (templateName)
+ breakPtr->templateName =
+ xmlStrdup( templateName);
+ else
+ breakPtr->templateName = NULL;
+ if (modeName)
+ breakPtr->modeName =
+ xmlStrdup(modeName);
+ else
+ breakPtr->modeName = NULL;
+ breakPtr->type = BreakPointTypeEnum(breakPointType);
+
+ /* add new breakPoint to the right hash table */
+ breakPointHash = breakPointGetLineNoHash(lineNumber);
+ if (breakPointHash) {
+ result = lineNoItemAdd(breakPointHash, breakPtr);
+ } else {
+ /* Grow breakList size */
+ int lineIndex;
+ int newEntries = breakList->count;
+ xmlHashTablePtr hash;
+
+ result = 1;
+ if ((lineNumber < breakList->count) && breakList->count) {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Unable to find breakpoint line hash at %d\n",
+ lineNumber);
+#endif
+ } else {
+ if (breakList->count + newEntries < lineNumber)
+ newEntries = lineNumber - breakList->count + 1;
+
+
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ /*
+ * xsltGenericError(xsltGenericErrorContext,
+ * "Size of line list was %d adding %d entries\n",
+ * breakList->count, newEntries);
+ */
+#endif
+ lineIndex = 0;
+ while ((lineIndex < newEntries) && result) {
+ hash = lineNoItemNew();
+ if (hash) {
+ result = result && arrayListAdd(breakList, hash);
+ } else {
+ result = 0;
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Unable to create hash table breakPoint list: memory error\n");
+#endif
+ return result;
+ }
+ lineIndex++;
+ }
+ /* find the newly added hashtable of breakpoints */
+ breakPointHash = breakPointGetLineNoHash(lineNumber);
+ if (breakPointHash) {
+ result = lineNoItemAdd(breakPointHash, breakPtr);
+ } else {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Unable to create new breakPoint:interal error\n");
+#endif
+ return result;
+ }
+ }
+
+ }
+ } else {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Unable to create new breakPoint: memory error\n");
+#endif
+ }
+
+ if (result && (optionsGetIntOption(OPTIONS_GDB) > 1) &&
+ (xsldbgValidateBreakpoints != BREAKPOINTS_BEING_VALIDATED)){
+ breakPointPrint(breakPtr);
+ xsldbgGenericErrorFunc("\n");
+ }
+ return result;
+}
+
+
+/**
+ * breakPointDelete:
+ * @breakPtr: Is valid
+ *
+ * Delete the break point specified if it can be found using
+ * @breakPoint's url and lineNo
+ *
+ * Returns 1 if successful,
+ * 0 otherwise
+*/
+int
+breakPointDelete(breakPointPtr breakPtr)
+{
+ int result = 0;
+ xmlHashTablePtr breakPointHash; /* hash of breakPoints */
+
+ if (!breakPtr)
+ return result;
+
+ breakPointHash = breakPointGetLineNoHash(breakPtr->lineNo);
+ if (breakPointHash) {
+ result = lineNoItemDelete(breakPointHash, breakPtr);
+ } else {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Breakpoint not found: xslDeleteBreakPoint\n");
+#endif
+ }
+ return result;
+}
+
+
+/**
+ * breakPointEnable:
+ * @breakPtr: A valid breakpoint
+ * @enable: Enable break point if 1, disable if 0, toggle if -1
+ *
+ * Enable or disable a break point
+ *
+ * Returns 1 if successful,
+ * 0 otherwise
+*/
+int
+breakPointEnable(breakPointPtr breakPtr, int enable)
+{
+ int result = 0;
+
+ if (breakPtr) {
+ int enableFlag = 1;
+ if (enable != XSL_TOGGLE_BREAKPOINT){
+ enableFlag = enable;
+ }else {
+ if (breakPtr->flags & BREAKPOINT_ENABLED)
+ enableFlag = 0;
+ }
+ if (enableFlag)
+ breakPtr->flags |= BREAKPOINT_ENABLED;
+ else
+ breakPtr->flags = breakPtr->flags & (BREAKPOINT_ALLFLAGS ^ BREAKPOINT_ENABLED);
+ result = 1;
+ }
+ return result;
+}
+
+
+/**
+ * breakPointLinesCount:
+ *
+ * Return the number of hash tables of break points with the same line number
+ *
+ * Returns The number of hash tables of break points with the same line number
+ */
+int
+breakPointLinesCount(void)
+{
+ if (!breakList) {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Breakpoints structures not initialized\n");
+#endif
+ return 0;
+ } else
+ return arrayListCount(breakList);
+}
+
+
+/**
+ * breakPointLinesList:
+ *
+ * Returns The list of hash tables for break points
+ * Dangerous function to use!!
+ */
+arrayListPtr
+breakPointLineList(void)
+{
+ return breakList;
+}
+
+
+/**
+ * breakPointGet:
+ * @url: Non-null, non-empty file name that has been loaded by
+ * debugger
+ * @lineNumber: lineNumber >= 0 and is available in @url
+ *
+ * Get a break point for the breakpoint collection
+ *
+ * Returns break point if break point exists at location specified,
+ * NULL otherwise
+*/
+breakPointPtr
+breakPointGet(const xmlChar * url, long lineNumber)
+{
+ xmlHashTablePtr breakHash = breakPointGetLineNoHash(lineNumber);
+ breakPointPtr breakPtr = NULL;
+
+ if (!breakHash || !url)
+ return breakPtr;
+
+ breakPtr = (breakPointPtr)xmlHashLookup(breakHash, url);
+ return breakPtr;
+}
+
+
+/**
+ * breakPointPrint:
+ * @breakPtr: A valid break point
+ *
+ * Print the details of @breakPtr
+ *
+ * Returns 1 if successful,
+ * 0 otherwise
+ */
+int
+breakPointPrint(breakPointPtr breakPtr)
+{
+ int result = 0;
+ const char *breakStatusText[2] = {
+ I18N_NOOP("disabled"),
+ I18N_NOOP("enabled")
+ };
+ const char *breakTemplate="";
+ const char *breakMode = "";
+ const char *breakStatus;
+
+
+ if (!breakPtr)
+ return result;
+
+ if (breakPtr->templateName){
+ if (breakPtr->modeName)
+ breakMode = (const char*)breakPtr->modeName;
+ breakTemplate = (const char*)breakPtr->templateName;
+ }
+
+
+ breakStatus = breakStatusText[breakPtr->flags & BREAKPOINT_ENABLED];
+ if (breakPtr->url)
+ xsldbgGenericErrorFunc(i18n("Breakpoint %1 %2 for template: \"%3\" mode: \"%4\" in file \"%5\" at line %6").arg(breakPtr->id).arg(i18n(breakStatus)).arg(xsldbgText(breakTemplate)).arg(xsldbgText(breakMode)).arg(xsldbgUrl(breakPtr->url)).arg(breakPtr->lineNo));
+ else
+ xsldbgGenericErrorFunc(i18n("Breakpoint %1 %2 for template: \"%3\" mode: \"%4\"").arg(breakPtr->id).arg(i18n(breakStatus)).arg(xsldbgText(breakTemplate)).arg(xsldbgText(breakMode)));
+ return ++result;
+}
+
+
+/**
+ * breakPointIsPresent:
+ * @url: Non-null, non-empty file name that has been loaded by
+ * debugger
+ * @lineNumber: @lineNumber >= 0 and is available in @url
+ *
+ * Determine if there is a break point at file and line number specified
+ *
+ * Returns 1 if successful,
+ * 0 otherwise
+*/
+int
+breakPointIsPresent(const xmlChar * url, long lineNumber)
+{
+ int result = 0;
+
+ if (!url || (lineNumber == -1))
+ return result;
+
+ result = (breakPointGet(url, lineNumber) != NULL);
+
+ return result;
+}
+
+
+/**
+ * breakPointIsPresentNode:
+ * @node: node != NULL
+ *
+ * Determine if a node is a break point
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+breakPointIsPresentNode(xmlNodePtr node)
+{
+ int result = 0;
+
+ if (!node || !node->doc)
+ return result;
+
+ if (xmlGetLineNo(node) == -1)
+ return result;
+
+ if (node->doc->URL) {
+ result = breakPointIsPresent(node->doc->URL, xmlGetLineNo(node));
+ }
+
+ return result;
+}
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/breakpoint.h b/kxsldbg/kxsldbgpart/libxsldbg/breakpoint.h
new file mode 100644
index 00000000..83f2e712
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/breakpoint.h
@@ -0,0 +1,633 @@
+
+/**************************************************************************
+ breakpoint.h - public functions for the
+ breakpoint API
+ -------------------
+ begin : Fri Dec 7 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 XSLBREAKPOINT_H
+#define XSLBREAKPOINT_H
+
+#ifdef USE_KDE_DOCS
+
+/**
+ * Provide a basic break point support
+ *
+ * @short break point support
+ *
+ * @author Keith Isdale <k_isdale@tpg.com.au>
+ */
+#endif
+
+#ifndef BUILD_DOCS
+#include <libxml/tree.h>
+#include <libxml/xpath.h>
+#include <libxslt/xsltInternals.h>
+#include <libxslt/xsltutils.h>
+
+#include "arraylist.h"
+#endif /* BUILD_DOCS */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ /* indicate that we are to toggle a breakpoint , used for enableBreakPoint */
+#define XSL_TOGGLE_BREAKPOINT -1
+
+ /* Define the types of status whilst debugging */
+#ifndef USE_KDOC
+ typedef enum {
+ DEBUG_NONE = 0, /* must start at zero!! */
+ DEBUG_INIT,
+ DEBUG_STEP,
+ DEBUG_STEPUP,
+ DEBUG_STEPDOWN,
+ DEBUG_NEXT,
+ DEBUG_STOP,
+ DEBUG_CONT,
+ DEBUG_RUN,
+ DEBUG_RUN_RESTART,
+ DEBUG_QUIT,
+ DEBUG_TRACE,
+ DEBUG_WALK
+ } DebugStatusEnum;
+
+
+ typedef enum {
+ DEBUG_BREAK_SOURCE = 300,
+ DEBUG_BREAK_DATA
+ } BreakPointTypeEnum;
+
+
+/*Indicate what type of variable to print out.
+ Is used by print_variable and searching functions */
+ typedef enum {
+ DEBUG_GLOBAL_VAR = 200, /* pick a unique starting point */
+ DEBUG_LOCAL_VAR,
+ DEBUG_ANY_VAR
+ } VariableTypeEnum;
+
+/*What type of flags can breakpoints have */
+ typedef enum {
+ BREAKPOINT_ENABLED = 1,
+ BREAKPOINT_ORPHANED = 2,
+ BREAKPOINT_ALLFLAGS = 255
+ } BreakPointFlags;
+
+/*What state of breakpoint validation can we be in */
+ typedef enum {
+ BREAKPOINTS_ARE_VALID,
+ BREAKPOINTS_NEED_VALIDATION,
+ BREAKPOINTS_BEING_VALIDATED
+ } BreakPointValidationStates;
+#else
+ /* keep kdoc happy */
+ enum DebugStatusEnum {
+ DEBUG_NONE = 0, /* must start at zero!! */
+ DEBUG_INIT,
+ DEBUG_STEP,
+ DEBUG_STEPUP,
+ DEBUG_STEPDOWN,
+ DEBUG_NEXT,
+ DEBUG_STOP,
+ DEBUG_CONT,
+ DEBUG_RUN,
+ DEBUG_RUN_RESTART,
+ DEBUG_QUIT,
+ DEBUG_TRACE,
+ DEBUG_WALK
+ };
+
+
+ enum BreakPointTypeEnum {
+ DEBUG_BREAK_SOURCE = 300,
+ DEBUG_BREAK_DATA
+ };
+
+
+/*Indicate what type of variable to print out.
+ Is used by print_variable and searching functions */
+ enum VariableTypeEnum {
+ DEBUG_GLOBAL_VAR = 200, /* pick a unique starting point */
+ DEBUG_LOCAL_VAR,
+ DEBUG_ANY_VAR
+ } VariableTypeEnum;
+
+/*What type of flags can breakpoints have */
+ enum BreakPointFlags {
+ BREAKPOINT_ENABLED = 1,
+ BREAKPOINT_ORPHANED = 2,
+ BREAKPOINT_ALLFLAGS = 255
+ } BreakPointFlags;
+
+/*What state of breakpoint validation can we be in */
+ enum BreakPointValidationStates {
+ BREAKPOINTS_ARE_VALID,
+ BREAKPOINTS_NEED_VALIDATION,
+ BREAKPOINTS_BEING_VALIDATED
+ } BreakPointValidationStates;
+#endif
+
+ /* The main structure for holding breakpoints */
+ typedef struct _breakPoint breakPoint;
+ typedef breakPoint *breakPointPtr;
+ struct _breakPoint {
+ xmlChar *url;
+ long lineNo;
+ xmlChar *templateName, *modeName;
+ int flags;
+ BreakPointTypeEnum type;
+ int id;
+ };
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointInit:
+ *
+ * Intialized the breakpoint module
+ *
+ * Returns 1 if breakpoint module haas been initialized properly and all
+ * memory required has been obtained,
+ * 0 otherwise
+*/
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Intialized the breakpoint module
+ *
+ * @returns 1 if breakpoint module has been initialized properly and all
+ * memory required has been obtained,
+ * 0 otherwise
+*/
+#endif
+#endif
+ int breakPointInit(void);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointFree:
+ *
+ * Free all memory used by breakpoint module
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Free all memory used by breakpoint module
+ */
+#endif
+#endif
+ void breakPointFree(void);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointActiveBreakPoint:
+ *
+ * Get the active break point
+ *
+ * Returns the last break point that we stoped at
+ *
+ * Depreciated
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Get the active break point
+ *
+ * @returns The last break point that we stoped at
+ *
+ * Depreciated
+ */
+#endif
+#endif
+ breakPointPtr breakPointActiveBreakPoint(void);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointSetActiveBreakPoint:
+ * @breakPtr: Is valid break point or NULL
+ *
+ * Set the active break point
+ *
+ * Depreciated
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Set the active break point
+ *
+ * @param breakPoint Is valid break point or NULL
+ *
+ * Depreciated
+ */
+#endif
+#endif
+ void breakPointSetActiveBreakPoint(breakPointPtr breakPtr);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointAdd:
+ * @url: Non-null, non-empty file name that has been loaded by
+ * debugger
+ * @lineNumber: @lineNumber >= 0 and is available in url specified and
+ * points to an xml element
+ * @templateName: The template name of breakPoint or NULL
+ * @modeName : The mode of breakpoint or NULL
+ * @type: Valid BreakPointTypeEnum
+ *
+ * Add break point at file and line number specified
+ *
+ * Returns 1 if successful,
+ * 0 otherwise
+*/
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Add break point at file and line number specified
+ *
+ * @returns 1 if successful,
+ * 0 otherwise
+ *
+ * @param url Non-null, non-empty file name that has been loaded by
+ * debugger
+ * @param lineNumber @p lineNumber >= 0 and is available in url specified and
+ * points to an xml element
+ * @param temlateName The template name of break point or NULL
+ * @param modeName : The mode of breakpoint or NULL
+ * @param type Valid BreakPointTypeEnum
+*/
+#endif
+#endif
+ int breakPointAdd(const xmlChar * url, long lineNumber,
+ const xmlChar * templateName,
+ const xmlChar * modeName,
+ BreakPointTypeEnum type);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointDelete:
+ * @breakPtr: Is valid
+ *
+ * Delete the break point specified if it can be found using
+ * @breakPoint's url and lineNo
+ *
+ * Returns 1 if successful,
+ * 0 otherwise
+*/
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Delete the break point specified if it can be found using
+ * @p breakPtr's url and lineNo
+ *
+ * @returns 1 if successful,
+ * 0 otherwise
+ *
+ * @param breakPoint Is valid
+ *
+*/
+#endif
+#endif
+ int breakPointDelete(breakPointPtr breakPtr);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointEmpty:
+ *
+ * Empty the break point collection
+ *
+ * Returns 1 if able to empty the breakpoint list of its contents,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Empty the break point collection
+ *
+ * @returns 1 if able to empty the break point list of its contents,
+ * 0 otherwise
+ */
+#endif
+#endif
+ int breakPointEmpty(void);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointEnable:
+ * @breakPtr: A valid breakpoint
+ * @enable: Enable break point if 1, disable if 0, toggle if -1
+ *
+ * Enable or disable a break point
+ *
+ * Returns 1 if successful,
+ * 0 otherwise
+*/
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Enable or disable a break point
+ *
+ * @returns 1 if successful,
+ * 0 otherwise
+ *
+ * @param breakPoint A valid breakpoint
+ * @param enable Enable break point if 1, disable if 0, toggle if -1
+*/
+#endif
+#endif
+ int breakPointEnable(breakPointPtr breakPtr, int enable);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointGet:
+ * @url: Non-null, non-empty file name that has been loaded by
+ * debugger
+ * @lineNumber: lineNumber >= 0 and is available in @url
+ *
+ * Get a break point for the breakpoint collection
+ *
+ * Returns break point if break point exists at location specified,
+ * NULL otherwise
+*/
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Get a break point for the breakpoint collection
+ *
+ * @returns break point if break point exists at location specified,
+ * NULL otherwise
+ *
+ * @param url Non-null, non-empty file name that has been loaded by
+ * debugger
+ * @param lineNumber @p lineNumber >= 0 and is available in url specified
+*/
+#endif
+#endif
+ breakPointPtr breakPointGet(const xmlChar * url, long lineNumber);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointGetLineNoHash:
+ * @lineNo: Line number of of breakpoints of interest
+ *
+ * Return A hash of breakpoints with same line number
+ *
+ * Returns A hash of breakpoints with a line number of @lineNo
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Return A hash of breakpoints with same line number
+ *
+ * @param lineNo : Line number of of breakpoints of interest
+ *
+ * @returns A hash of breakpoints with a line number of @p lineNo
+ */
+#endif
+#endif
+ xmlHashTablePtr breakPointGetLineNoHash(long lineNo);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointItemNew:
+ *
+ * Create a new break point item
+ * Returns A valid break point with default values set if successful,
+ * NULL otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Create a new break point item
+ *
+ * @returns A valid break point with default values set if successful,
+ * NULL otherwise
+ */
+#endif
+#endif
+ breakPointPtr breakPointItemNew(void);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointItemFree:
+ * @payload: valid breakPointPtr
+ * @name: not used
+ *
+ * Free memory associated with this break point
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Free memory associated with this break point
+ *
+ * @param payload Valid breakPointPtr
+ * @param name not used
+ *
+ */
+#endif
+#endif
+ void breakPointItemFree(void *payload, xmlChar * name);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointLinesCount:
+ *
+ * Return the number of hash tables of break points with the same line number
+ *
+ * Returns the number of hash tables of break points with the same line number
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Return the number of hash tables of break points with the same line number
+ *
+ * @returns the number of hash tables of break points with the same line number
+ */
+#endif
+#endif
+ int breakPointLinesCount(void);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointPrint:
+ * @breakPtr: A valid break point
+ *
+ * Print the details of @breakPtr to @file
+ *
+ * Returns 1 if successful,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Print the details of @p breakPtr to @p file
+ *
+ * @returns 1 if successful,
+ * 0 otherwise
+ *
+ * @param breakPoint A valid break point
+ */
+#endif
+#endif
+ int breakPointPrint(breakPointPtr breakPtr);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointIsPresent:
+ * @url: Non-null, non-empty file name that has been loaded by
+ * debugger
+ * @lineNumber: @lineNumber >= 0 and is available in @url
+ *
+ * Determine if there is a break point at file and line number specified
+ *
+ * Returns 1 if successful,
+ * 0 otherwise
+*/
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Determine if there is a break point at file and line number specified
+ *
+ * @returns 1 if successful,
+ * 0 otherwise
+ *
+ * @param url Non-null, non-empty file name that has been loaded by
+ * debugger
+ * @lineNumber @p lineNumber >= 0 and is available in url specified
+*/
+#endif
+#endif
+ int breakPointIsPresent(const xmlChar * url, long lineNumber);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointIsPresentNode:
+ * @node: node != NULL
+ *
+ * Determine if a node is a break point
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Determine if a node is a break point
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param node Is valid
+ */
+#endif
+#endif
+ int breakPointIsPresentNode(xmlNodePtr node);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * breakPointLinesList:
+ *
+ * Return The list of hash tables for break points
+ * Dangerous function to use!!
+ *
+ * Returns The list of hash tables for break points
+ * Dangerous function to use!!
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Return The list of hash tables for break points
+ * Dangerous function to use!!
+ *
+ * Returns The list of hash tables for break points
+ * Dangerous function to use!!
+ */
+#endif
+#endif
+ arrayListPtr breakPointLineList(void);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/breakpoint_cmds.cpp b/kxsldbg/kxsldbgpart/libxsldbg/breakpoint_cmds.cpp
new file mode 100644
index 00000000..7935ea8c
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/breakpoint_cmds.cpp
@@ -0,0 +1,1036 @@
+
+/***************************************************************************
+ breakpoint_cmds.c - breakpoint commands for xsldbg
+ -------------------
+ begin : Wed Nov 21 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 "xsldbg.h"
+#include "debugXSL.h"
+#include "files.h"
+#include "utils.h"
+#include <libxml/valid.h> /* needed for xmlSplitQName2 */
+#include <libxml/xpathInternals.h> /* needed for xmlNSLookup */
+#include <libxml/uri.h> /* needed for xmlURIEscapeStr */
+#include "xsldbgthread.h" /* for getThreadStatus() */
+#include "xsldbgmsg.h"
+#include "options.h"
+
+/* temp buffer needed occationaly */
+static xmlChar buff[DEBUG_BUFFER_SIZE];
+
+/* needed by breakpoint validation */
+extern int breakPointCounter;
+
+/* we need to have a fake URL and line number for orphaned template breakpoints */
+int orphanedTemplateLineNo = 1;
+const xmlChar *orphanedTemplateURL= (xmlChar*)"http://xsldbg.sourceforge.net/default.xsl";
+/* ---------------------------------------------------
+ Private function declarations for breakpoint_cmds.c
+ ----------------------------------------------------*/
+
+/**
+ * validateSource:
+ * @url : is valid name of a xsl source file
+ * @lineNo : lineNo >= 0
+ *
+ * Returns 1 if a breakpoint could be set at specified file url and line number
+ * 0 otherwise
+ */
+int validateSource(xmlChar ** url, long *lineNo);
+
+/**
+ * validateData:
+ * @url : is valid name of a xml data file
+ * @lineNo : lineNo >= 0
+ *
+ * Returns 1 if a breakpoint could be set at specified file url and line number
+ * 0 otherwise
+ */
+int validateData(xmlChar ** url, long *lineNo);
+
+
+/* -------------------------------------
+ End private functions
+---------------------------------------*/
+
+
+
+/* -----------------------------------------
+
+ BreakPoint related commands
+
+ ------------------------------------------- */
+
+
+/**
+ * xslDbgShellFrameBreak:
+ * @arg: Is valid number of frames to change location by
+ * @stepup: If != 1 then we step up, otherwise step down
+ *
+ * Set a "frame" break point either up or down from here
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+xslDbgShellFrameBreak(xmlChar * arg, int stepup)
+{
+ int result = 0;
+
+ /* how many frames to go up/down */
+ int noOfFrames;
+ static const char *errorPrompt = I18N_NOOP("Failed to add breakpoint.");
+
+ if (!filesGetStylesheet() || !filesGetMainDoc()) {
+ xsldbgGenericErrorFunc(i18n("Error: Debugger has no files loaded. Try reloading files.\n"));
+ xsldbgGenericErrorFunc(QString("Error: %1.\n").arg(i18n(errorPrompt)));
+ return result;
+ }
+
+ if (!arg) {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: NULL argument provided\n");
+#endif
+ xsldbgGenericErrorFunc(QString("Error: %1\n").arg(i18n(errorPrompt)));
+ return result;
+ }
+
+ if (xmlStrLen(arg) > 0) {
+ if (!sscanf((char *) arg, "%d", &noOfFrames)) {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to parse %1 as a number of frames.\n").arg((char*)arg));
+ noOfFrames = -1;
+ }
+ } else {
+ noOfFrames = 0;
+ }
+
+ if (noOfFrames >0){
+ if (stepup) {
+ result = callStackStepup(callStackGetDepth() - noOfFrames);
+ } else {
+ result = callStackStepdown(callStackGetDepth() + noOfFrames);
+ }
+ }
+
+ if (!result)
+ xsldbgGenericErrorFunc(QString("Error: %1\n").arg(i18n(errorPrompt)));
+ return result;
+}
+
+
+/**
+ * validateSource:
+ * @url : is valid name of a xsl source file
+ * @lineNo : lineNo >= 0
+ *
+ * Returns 1 if a breakpoint could be set at specified file url and line number
+ * 0 otherwise
+ */
+int
+validateSource(xmlChar ** url, long *lineNo)
+{
+
+ int result = 0, type;
+ searchInfoPtr searchInf;
+ nodeSearchDataPtr searchData = NULL;
+
+ if (!filesGetStylesheet()) {
+ xsldbgGenericErrorFunc(i18n("Error: Stylesheet is not valid or file is not loaded.\n"));
+ return result;
+ }
+
+ if (!url) {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: NULL argument provided\n");
+#endif
+ return result;
+ }
+
+ searchInf = searchNewInfo(SEARCH_NODE);
+
+ if (searchInf && searchInf->data) {
+ type = DEBUG_BREAK_SOURCE;
+ searchData = (nodeSearchDataPtr) searchInf->data;
+ if (lineNo != NULL)
+ searchData->lineNo = *lineNo;
+ searchData->nameInput = (xmlChar *) xmlMemStrdup((char *) *url);
+ guessStylesheetName(searchInf);
+ /* try to verify that the line number is valid */
+ if (searchInf->found) {
+ /* ok it looks like we've got a valid url */
+ /* searchData->url will be freed by searchFreeInfo */
+ if (searchData->absoluteNameMatch)
+ searchData->url = (xmlChar *)
+ xmlMemStrdup((char *) searchData->absoluteNameMatch);
+ else
+ searchData->url = (xmlChar *)
+ xmlMemStrdup((char *) searchData->guessedNameMatch);
+
+ if (lineNo != NULL) {
+ /* now to check the line number */
+ if (searchData->node) {
+ searchInf->found = 0;
+ /* searchData->node is set to the topmost node in stylesheet */
+ walkChildNodes((xmlHashScanner) scanForNode, searchInf,
+ searchData->node);
+ if (!searchInf->found) {
+ xsldbgGenericErrorFunc(i18n("Warning: Breakpoint for file \"%1\" at line %2 does not seem to be valid.\n").arg(xsldbgUrl(*url)).arg(*lineNo));
+ }
+
+ *lineNo = searchData->lineNo;
+ xmlFree(*url);
+ *url = xmlStrdup(searchData->url);
+ result = 1;
+ }
+
+ } else {
+ /* we've been asked just to check the file name */
+ if (*url)
+ xmlFree(*url);
+ if (searchData->absoluteNameMatch)
+ *url = (xmlChar *)
+ xmlMemStrdup((char *) searchData->absoluteNameMatch);
+ else
+ *url = (xmlChar *)
+ xmlMemStrdup((char *) searchData->guessedNameMatch);
+ result = 1;
+ }
+ } else{
+ xsldbgGenericErrorFunc(i18n("Error: Unable to find a stylesheet file whose name contains %1.\n").arg(xsldbgUrl(*url)));
+ if (lineNo){
+ xsldbgGenericErrorFunc(i18n("Warning: Breakpoint for file \"%1\" at line %2 does not seem to be valid.\n").arg(xsldbgUrl(*url)).arg(*lineNo));
+ }
+ }
+ }
+
+ if (searchInf)
+ searchFreeInfo(searchInf);
+ else
+ xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
+
+ return result;
+}
+
+
+
+
+/**
+ * validateData:
+ * @url : is valid name of a xml data file
+ * @lineNo : lineNo >= 0
+ *
+ * Returns 1 if a breakpoint could be set at specified file url and line number
+ * 0 otherwise
+ */
+int
+validateData(xmlChar ** url, long *lineNo)
+{
+ int result = 0;
+ searchInfoPtr searchInf;
+ nodeSearchDataPtr searchData = NULL;
+ char *lastSlash;
+
+ if (!filesGetMainDoc()) {
+ if (!optionsGetIntOption(OPTIONS_GDB)){
+ xsldbgGenericErrorFunc(i18n("Error: Data file is invalid. Try the run command first.\n"));
+ }
+ return result;
+ }
+
+ if (!url) {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: NULL argument provided\n");
+#endif
+ return result;
+ }
+
+ searchInf = searchNewInfo(SEARCH_NODE);
+ if (searchInf && searchInf->data && filesGetMainDoc()) {
+ /* Try to verify that the line number is valid.
+ First try an absolute name match */
+ searchData = (nodeSearchDataPtr) searchInf->data;
+ if (lineNo != NULL)
+ searchData->lineNo = *lineNo;
+ else
+ searchData->lineNo = -1;
+ searchData->url = (xmlChar *) xmlMemStrdup((char *) *url);
+ walkChildNodes((xmlHashScanner) scanForNode, searchInf,
+ (xmlNodePtr) filesGetMainDoc());
+
+ /* Next try to guess file name by adding the prefix of main document
+ if no luck so far */
+ if (!searchInf->found) {
+ /* Find the last separator of the documents URL */
+ lastSlash = xmlStrrChr(filesGetMainDoc()->URL, URISEPARATORCHAR);
+ if (!lastSlash)
+ lastSlash = xmlStrrChr(filesGetMainDoc()->URL, PATHCHAR);
+
+ if (lastSlash) {
+ lastSlash++;
+ xmlStrnCpy(buff, filesGetMainDoc()->URL,
+ lastSlash - (char *) filesGetMainDoc()->URL);
+ buff[lastSlash - (char *) filesGetMainDoc()->URL] = '\0';
+ xmlStrCat(buff, *url);
+ } else
+ xmlStrCpy(buff, "");
+ if (xmlStrLen(buff) > 0) {
+ if (searchData->url)
+ xmlFree(searchData->url);
+ searchData->url = (xmlChar *) xmlMemStrdup((char *) buff);
+ walkChildNodes((xmlHashScanner) scanForNode, searchInf,
+ (xmlNodePtr) filesGetMainDoc());
+ }
+ }
+
+ if (!searchInf->found) {
+ if (lineNo){
+ xsldbgGenericErrorFunc(i18n("Warning: Breakpoint for file \"%1\" at line %2 does not seem to be valid.\n").arg(xsldbgUrl(*url)).arg(*lineNo));
+ } else{
+ xsldbgGenericErrorFunc(i18n("Error: Unable to find a data file whose name contains %1.\n").arg(xsldbgUrl(*url)));
+ }
+ result = 1;
+ } else {
+ if (*url)
+ xmlFree(*url);
+ *url = xmlStrdup(searchData->url);
+ result = 1;
+ }
+ }
+
+ if (searchInf)
+ searchFreeInfo(searchInf);
+ else
+ xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
+
+ return result;
+}
+
+
+/**
+ * xslDbgShellBreak:
+ * @arg: Is valid and in UTF-8
+ * @style: Is valid
+ * @ctxt: Is valid
+ *
+ * Add break point specified by arg
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+xslDbgShellBreak(xmlChar * arg, xsltStylesheetPtr style,
+ xsltTransformContextPtr ctxt)
+{
+ int result = 0;
+ long lineNo = -1;
+ xmlChar *url = NULL;
+ int orphanedBreakPoint = 0;
+ breakPointPtr breakPtr;
+
+ static const char *errorPrompt = I18N_NOOP("Failed to add breakpoint.");
+
+ if (style == NULL) {
+ style = filesGetStylesheet();
+ }
+ if (!style || !filesGetMainDoc()) {
+ if (!optionsGetIntOption(OPTIONS_GDB)){
+ xsldbgGenericErrorFunc(i18n("Error: Debugger has no files loaded. Try reloading files.\n"));
+ xsldbgGenericErrorFunc(QString("Error: %1\n").arg(i18n(errorPrompt)));
+ return result;
+ }else{
+ orphanedBreakPoint = 1;
+ }
+ }
+
+ if (!arg) {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: NULL argument provided\n");
+#endif
+ return result;
+ }
+
+ if (arg[0] == '-') {
+ xmlChar *opts[2];
+
+ if ((xmlStrLen(arg) > 1) && (arg[1] == 'l')) {
+ if (splitString(&arg[2], 2, opts) == 2) {
+ if ((xmlStrlen(opts[1]) == 0) ||
+ !sscanf((char *) opts[1], "%ld", &lineNo)) {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to parse %1 as a line number.\n").arg((char*)opts[1]));
+ xsldbgGenericErrorFunc(QString("Error: %1\n").arg(i18n(errorPrompt)));
+ return result;
+ } else {
+ /* try to guess whether we are looking for source or data
+ * break point
+ */
+ xmlChar *escapedURI;
+ trimString(opts[0]);
+ url = filesExpandName(opts[0]);
+ if (url){
+ escapedURI = xmlURIEscapeStr(url, (const xmlChar*)"/");
+ if (escapedURI){
+ xmlFree(url);
+ url = escapedURI;
+ }
+ }
+ if (url) {
+ if (!orphanedBreakPoint){
+ if (filesIsSourceFile(url)) {
+ if (validateSource(&url, &lineNo))
+ result =
+ breakPointAdd(url, lineNo, NULL, NULL,
+ DEBUG_BREAK_SOURCE);
+ } else {
+ if (validateData(&url, &lineNo))
+ result =
+ breakPointAdd(url, lineNo, NULL, NULL,
+ DEBUG_BREAK_DATA);
+ }
+ }else{
+ if (filesIsSourceFile(url)) {
+ result =
+ breakPointAdd(url, lineNo, NULL, NULL,
+ DEBUG_BREAK_SOURCE);
+ }else{
+ result =
+ breakPointAdd(url, lineNo, NULL, NULL,
+ DEBUG_BREAK_DATA);
+ }
+ breakPtr = breakPointGet(url, lineNo);
+ if (breakPtr){
+ breakPtr->flags |= BREAKPOINT_ORPHANED;
+ }else{
+ xsldbgGenericErrorFunc(i18n("Error: Unable to find the added breakpoint."));
+ }
+ }
+ }
+ }
+ } else
+ xsldbgGenericErrorFunc(i18n("Error: Invalid arguments to command %1.\n").arg("break"));
+ }
+ } else {
+ /* add breakpoint at specified template names */
+ xmlChar *opts[2];
+ xmlChar *name = NULL, *nameURI = NULL, *mode = NULL, *modeURI = NULL;
+ xmlChar *templateName = NULL, *modeName = NULL;
+ xmlChar *tempUrl = NULL; /* we must use a non-const xmlChar *
+ and we are not making a copy
+ of orginal value so this must not be
+ freed */
+ xmlChar *defaultUrl = (xmlChar *) "<n/a>";
+ int newBreakPoints = 0, validatedBreakPoints = 0;
+ int allTemplates = 0;
+ int ignoreTemplateNames = 0;
+ int argCount;
+ int found;
+ xsltTemplatePtr templ;
+ if (orphanedBreakPoint || !ctxt){
+ /* Add an orphaned template breakpoint we will need to call this function later to
+ activate the breakpoint */
+ result =
+ breakPointAdd(orphanedTemplateURL, orphanedTemplateLineNo, arg, NULL,
+ DEBUG_BREAK_SOURCE);
+ breakPtr = breakPointGet(orphanedTemplateURL, orphanedTemplateLineNo++);
+ if (breakPtr){
+ breakPtr->flags |= BREAKPOINT_ORPHANED;
+ }else{
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Unable to find added breakpoint");
+#endif
+ }
+ return result;
+ }
+
+ argCount = splitString(arg, 2, opts);
+ if ((argCount == 2) && (xmlStrLen(opts[1]) == 0))
+ argCount = 1;
+
+ switch (argCount){
+ case 0:
+ allTemplates = 1;
+ break;
+
+ case 1:
+ if (xmlStrEqual(opts[0], (xmlChar*)"*")){
+ allTemplates = 1;
+ }else{
+
+ if (xmlStrEqual(opts[0], (xmlChar*)"\\*")){
+ opts[0][0] = '*';
+ opts[0][1] = '\0';
+ }
+
+ name = xmlSplitQName2(opts[0], &nameURI);
+ if (name == NULL){
+ name = xmlStrdup(opts[0]);
+ }else{
+ if (nameURI){
+ /* get the real URI for this namespace */
+ const xmlChar *temp = xmlXPathNsLookup(ctxt->xpathCtxt, nameURI);
+ if (temp)
+ xmlFree(nameURI);
+ nameURI = xmlStrdup(temp);
+ }
+
+ }
+ }
+ break;
+
+ case 2:
+ if (xmlStrLen(opts[0]) == 0){
+ /* we don't care about the template name ie we are trying to match
+ templates with a given mode */
+ ignoreTemplateNames = 1;
+ }else{
+ name = xmlSplitQName2(opts[0], &nameURI);
+ if (name == NULL)
+ name = xmlStrdup(opts[0]);
+ if (nameURI){
+ /* get the real URI for this namespace */
+ const xmlChar *temp = xmlXPathNsLookup(ctxt->xpathCtxt,
+ nameURI);
+ if (temp)
+ xmlFree(nameURI);
+ nameURI = xmlStrdup(temp);
+ }
+ }
+ mode = xmlSplitQName2(opts[1], &modeURI);
+ if (mode == NULL)
+ mode = xmlStrdup(opts[1]);
+ if (modeURI){
+ /* get the real URI for this namespace */
+ const xmlChar *temp = xmlXPathNsLookup(ctxt->xpathCtxt, modeURI);
+ if (temp)
+ xmlFree(modeURI);
+ modeURI = xmlStrdup(temp);
+ }
+ break;
+
+ default:
+ xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for command %1.\n").arg("break"));
+ return 0;
+ }
+
+ while (style) {
+ templ = style->templates;
+ while (templ) {
+ found = 0;
+ if (templ->elem && templ->elem->doc
+ && templ->elem->doc->URL) {
+ tempUrl = (xmlChar *) templ->elem->doc->URL;
+ } else {
+ tempUrl = defaultUrl;
+ }
+
+ if (templ->match)
+ templateName = xmlStrdup(templ->match);
+ else
+ templateName = fullQName(templ->nameURI, templ->name);
+
+ if (allTemplates)
+ found = 1;
+ else {
+ if (ignoreTemplateNames){
+ if (!mode || (xmlStrEqual(templ->mode, mode) &&
+ (!modeURI || xmlStrEqual(templ->modeURI,
+ modeURI))))
+ found = 1;
+ } else if (templ->match){
+ if ((xmlStrEqual(templ->match, name) &&
+ (!modeURI || xmlStrEqual(templ->modeURI,
+ modeURI)) &&
+ (!mode || xmlStrEqual(templ->mode,
+ mode))))
+ found = 1;
+ }else{
+ if(xmlStrEqual(templ->name, name) &&
+ (!nameURI || xmlStrEqual(templ->nameURI, nameURI)))
+ found = 1;
+ }
+ }
+ if (found) {
+ int templateLineNo = xmlGetLineNo(templ->elem);
+ breakPointPtr searchPtr = breakPointGet(tempUrl, templateLineNo);
+
+ if (templ->mode)
+ modeName =
+ fullQName(templ->modeURI, templ->mode);
+
+
+ if (!searchPtr){
+ if (breakPointAdd(tempUrl, templateLineNo,
+ templateName, modeName,
+ DEBUG_BREAK_SOURCE)){
+ newBreakPoints++;
+ }
+ }else{
+
+ if ((templateLineNo != searchPtr->lineNo ) || !xmlStrEqual(tempUrl, searchPtr->url)){
+ int lastId = searchPtr->id;
+ int lastCounter = breakPointCounter;
+ /* we have a new location for breakpoint */
+ if (breakPointDelete(searchPtr)){
+ if (breakPointAdd(tempUrl, templateLineNo, templateName, modeName,DEBUG_BREAK_SOURCE)){
+ searchPtr = breakPointGet(tempUrl, templateLineNo);
+ if (searchPtr){
+ searchPtr->id = lastId;
+ result = 1;
+ breakPointCounter = lastCounter;
+ xsldbgGenericErrorFunc(i18n("Information: Breakpoint validation has caused breakpoint %1 to be re-created.\n").arg(searchPtr->id));
+ validatedBreakPoints++;
+ }
+ }
+ }
+ }else{
+ if (xsldbgValidateBreakpoints != BREAKPOINTS_BEING_VALIDATED){
+ xsldbgGenericErrorFunc(i18n("Warning: Breakpoint exits for file \"%1\" at line %2.\n").arg(xsldbgUrl(tempUrl)).arg(templateLineNo));
+ }
+ validatedBreakPoints++;
+ }
+ }
+ }
+ if (templateName){
+ xmlFree(templateName);
+ templateName = NULL;
+ }
+ if (modeName){
+ xmlFree(modeName);
+ modeName = NULL;
+ }
+ templ = templ->next;
+ }
+ if (style->next)
+ style = style->next;
+ else
+ style = style->imports;
+ }
+
+ if ((newBreakPoints == 0) && (validatedBreakPoints == 0)) {
+ xsldbgGenericErrorFunc(i18n("Error: No templates found or unable to add breakpoint.\n"));
+ url = NULL; /* flag that we've printed partial error message about the problem url */
+ } else {
+ result = 1;
+ if (newBreakPoints){
+ xsldbgGenericErrorFunc(i18n("Information: Added %n new breakpoint.", "Information: Added %n new breakpoints.", newBreakPoints) + QString("\n"));
+ }
+ }
+
+ if (name)
+ xmlFree(name);
+ if (nameURI)
+ xmlFree(nameURI);
+ if (mode)
+ xmlFree(mode);
+ if (modeURI)
+ xmlFree(modeURI);
+ if (defaultUrl && !xmlStrEqual((xmlChar*)"<n/a>", defaultUrl))
+ xmlFree(defaultUrl);
+ if (tempUrl)
+ url = xmlStrdup(tempUrl);
+ } /* end add template breakpoints */
+
+ if (!result) {
+ if (url)
+ xsldbgGenericErrorFunc(i18n("Error: Failed to add breakpoint for file \"%1\" at line %2.\n").arg(xsldbgUrl(url)).arg(lineNo));
+ else
+ xsldbgGenericErrorFunc(i18n("Error: Failed to add breakpoint.\n"));
+ }
+
+ if (url)
+ xmlFree(url);
+ return result;
+}
+
+
+/**
+ * xslDbgShellDelete:
+ * @arg: Is valid and in UTF-8
+ *
+ * Delete break point specified by arg
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+xslDbgShellDelete(xmlChar * arg)
+{
+ int result = 0, breakPointId;
+ long lineNo;
+ breakPointPtr breakPtr = NULL;
+ static const char *errorPrompt = I18N_NOOP("Failed to delete breakpoint.");
+
+ if (!arg) {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: NULL argument provided\n");
+#endif
+ xsldbgGenericErrorFunc(QString("Error: %1\n").arg(i18n(errorPrompt)));
+ return result;
+ }
+
+ if (arg[0] == '-') {
+ xmlChar *opts[2], *url = NULL;
+
+ if ((xmlStrLen(arg) > 1) && (arg[1] == 'l')) {
+ if (splitString(&arg[2], 2, opts) == 2) {
+ if ((xmlStrlen(opts[1]) == 0) ||
+ !sscanf((char *) opts[1], "%ld", &lineNo)) {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to parse %1 as a line number.\n").arg((char*)opts[1]));
+ } else {
+ xmlChar *escapedURI;
+ trimString(opts[0]);
+ url = filesExpandName(opts[0]);
+ if (url){
+ escapedURI = xmlURIEscapeStr(url, (const xmlChar*)"/");
+ if (escapedURI){
+ xmlFree(url);
+ url = escapedURI;
+ }
+ }
+ if (url) {
+ if (filesIsSourceFile(url)) {
+ if (validateSource(&url, &lineNo))
+ breakPtr = breakPointGet(url, lineNo);
+ } else if (validateData(&url, &lineNo))
+ breakPtr = breakPointGet(url, lineNo);
+ if (!breakPtr || !breakPointDelete(breakPtr)){
+ xsldbgGenericErrorFunc(i18n("Error: Breakpoint does not exist for file \"%1\" at line %2.\n").arg(xsldbgUrl(url)).arg(lineNo));
+ }else{
+ result = 1;
+ }
+ xmlFree(url);
+ }
+ }
+ } else{
+ xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for command %1.\n").arg("delete"));
+ }
+ }
+ } else if (xmlStrEqual((xmlChar*)"*", arg)) {
+ result = 1;
+ /*remove all from breakpoints */
+ breakPointEmpty();
+
+ } else if (sscanf((char *) arg, "%d", &breakPointId)) {
+ breakPtr = findBreakPointById(breakPointId);
+ if (breakPtr) {
+ result = breakPointDelete(breakPtr);
+ if (!result) {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to delete breakpoint %1.\n").arg(breakPointId));
+ }
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Breakpoint %1 does not exist.\n").arg(breakPointId));
+ }
+ } else {
+ breakPtr = findBreakPointByName(arg);
+ if (breakPtr) {
+ result = breakPointDelete(breakPtr);
+ if (!result) {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to delete breakpoint at template %1.\n").arg(xsldbgText(arg)));
+ }
+ } else{
+ xsldbgGenericErrorFunc(i18n("Error: Breakpoint at template \"%1\" does not exist.\n").arg(xsldbgText(arg)));
+ }
+ }
+ if (!result)
+ xsldbgGenericErrorFunc(QString("Error: %1\n").arg(i18n(errorPrompt)));
+ return result;
+}
+
+
+/**
+ * xslDbgShellEnableBreakPoint:
+ * @payload: A valid breakPointPtr
+ * @data: Enable type, a pointer to an integer
+ * for a value of
+ * 1 enable break point
+ * 0 disable break point
+ * -1 toggle enabling of break point
+ * @name: Not used
+ *
+ * Enable/disable break points via use of scan of break points
+*/
+void
+xslDbgShellEnableBreakPoint(void *payload, void *data,
+ xmlChar * name)
+{
+ Q_UNUSED(name);
+ if (payload && data) {
+ breakPointEnable((breakPointPtr) payload, *(int *) data);
+ }
+}
+
+
+/**
+ * xslDbgShellEnable:
+ * @arg : is valid and in UTF-8
+ * @enableType : enable break point if 1, disable if 0, toggle if -1
+ *
+ * Enable/disable break point specified by arg using enable
+ * type of @enableType
+ * Returns 1 if successful,
+ * 0 otherwise
+ */
+
+int
+xslDbgShellEnable(xmlChar * arg, int enableType)
+{
+ int result = 0, breakPointId;
+ long lineNo;
+ breakPointPtr breakPtr = NULL;
+ static const char *errorPrompt = I18N_NOOP("Failed to enable/disable breakpoint.");
+
+ if (!filesGetStylesheet() || !filesGetMainDoc()) {
+ xsldbgGenericErrorFunc(i18n("Error: Debugger has no files loaded. Try reloading files.\n"));
+ xsldbgGenericErrorFunc(QString("Error: %1\n").arg(i18n(errorPrompt)));
+ return result;
+ }
+
+ if (!arg) {
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: NULL argument provided\n");
+#endif
+ xsldbgGenericErrorFunc(QString("Error: %1\n").arg(i18n(errorPrompt)));
+ return result;
+ }
+
+ if (arg[0] == '-') {
+ xmlChar *opts[2], *url = NULL;
+
+ if ((xmlStrLen(arg) > 1) && (arg[1] == 'l')) {
+ if (splitString(&arg[2], 2, opts) == 2) {
+ if ((xmlStrlen(opts[1]) == 0) ||
+ !sscanf((char *) opts[1], "%ld", &lineNo)) {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to parse %1 as a line number.\n").arg((char*)opts[1]));
+ } else {
+ xmlChar *escapedURI;
+ trimString(opts[0]);
+ url = filesExpandName(opts[0]);
+ if (url){
+ escapedURI = xmlURIEscapeStr(url, (const xmlChar*)"/");
+ if (escapedURI){
+ xmlFree(url);
+ url = escapedURI;
+ }
+ }
+ if (url) {
+ if (strstr((char *) url, ".xsl")) {
+ if (validateSource(&url, NULL))
+ breakPtr = breakPointGet(url, lineNo);
+ } else if (validateData(&url, NULL))
+ breakPtr = breakPointGet(url, lineNo);
+ if (breakPtr){
+ result = breakPointEnable(breakPtr, enableType);
+ }else{
+ xsldbgGenericErrorFunc(i18n("Error: Breakpoint does not exist for file \"%1\" at line %2.\n").arg(xsldbgUrl(url)).arg(lineNo));
+ }
+ xmlFree(url);
+ }
+ }
+ } else
+ xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for command %1.\n").arg("enable"));
+ }
+ } else if (xmlStrEqual((xmlChar*)"*", arg)) {
+ result = 1;
+ /*enable/disable all from breakpoints */
+ walkBreakPoints((xmlHashScanner) xslDbgShellEnableBreakPoint,
+ &enableType);
+
+ } else if (sscanf((char *) arg, "%d", &breakPointId)) {
+ breakPtr = findBreakPointById(breakPointId);
+ if (breakPtr) {
+ result = breakPointEnable(breakPtr, enableType);
+ if (!result) {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to enable/disable breakpoint %1.\n").arg(breakPointId));
+ }
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Breakpoint %1 does not exist.\n").arg(breakPointId));
+ }
+ } else {
+ breakPtr = findBreakPointByName(arg);
+ if (breakPtr) {
+ result = breakPointEnable(breakPtr, enableType);
+ } else
+ xsldbgGenericErrorFunc(i18n("Error: Breakpoint at template \"%1\" does not exist.\n").arg(xsldbgText(arg)));
+ }
+
+ if (!result)
+ xsldbgGenericErrorFunc(QString("Error: %1\n").arg(i18n(errorPrompt)));
+ return result;
+}
+
+
+/**
+ * xslDbgShellPrintBreakPoint:
+ * @payload: A valid breakPointPtr
+ * @data: Not used
+ * @name: Not used
+ *
+ * Print data given by scan of break points
+*/
+void
+xslDbgShellPrintBreakPoint(void *payload, void *data,
+ xmlChar * name)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(name);
+
+ if (payload) {
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
+ notifyListQueue(payload);
+ } else {
+ printCount++;
+ xsldbgGenericErrorFunc(" ");
+ breakPointPrint((breakPointPtr) payload);
+ xsldbgGenericErrorFunc("\n");
+ }
+ }
+}
+
+
+/* Validiate a breakpoint at a given URL and line number
+ breakPtr and copy must be valid
+*/
+static int validateBreakPoint(breakPointPtr breakPtr, breakPointPtr copy)
+{
+
+ int result = 0;
+ if (!breakPtr || !copy){
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Warning: NULL arguments passed to validateBreakPoint\n");
+#endif
+ return result;
+ }
+
+ if (filesIsSourceFile(breakPtr->url)) {
+ result = validateSource(&copy->url, &copy->lineNo);
+ } else {
+ result = validateData(&copy->url, &copy->lineNo);
+ }
+ if (result)
+ breakPtr->flags &= BREAKPOINT_ALLFLAGS ^ BREAKPOINT_ORPHANED;
+ else
+ breakPtr->flags |= BREAKPOINT_ORPHANED;
+
+ if ( breakPtr->flags & BREAKPOINT_ORPHANED){
+ xsldbgGenericErrorFunc(QString("Warning: Breakpoint %1 is orphaned. Result: %2. Old flags: %3. New flags: %4.\n").arg(breakPtr->id).arg(result).arg(copy->flags).arg(breakPtr->flags));
+ }
+
+ if (!(breakPtr->flags & BREAKPOINT_ORPHANED) && ((copy->lineNo != breakPtr->lineNo ) ||
+ (xmlStrlen(copy->url) != xmlStrlen(breakPtr->url)) || xmlStrCmp(copy->url, breakPtr->url))){
+ /* we have a new location for breakpoint */
+ int lastCounter = breakPointCounter;
+ copy->templateName = xmlStrdup(breakPtr->templateName);
+ copy->modeName = xmlStrdup(breakPtr->modeName);
+ if (breakPointDelete(breakPtr) && !breakPointGet(copy->url, copy->lineNo)){
+ if (breakPointAdd(copy->url, copy->lineNo, NULL, NULL, copy->type)){
+ breakPtr = breakPointGet(copy->url, copy->lineNo);
+ if (breakPtr){
+ breakPtr->id = copy->id;
+ breakPtr->flags = copy->flags;
+ breakPointCounter = lastCounter; /* compensate for breakPointAdd which always
+ increments the breakPoint counter */
+ result = 1;
+ xsldbgGenericErrorFunc(i18n("Information: Breakpoint validation has caused breakpoint %1 to be re-created.\n").arg(breakPtr->id));
+ }
+ }
+ if (!result){
+ xsldbgGenericErrorFunc(i18n("Warning: Validation of breakpoint %1 failed.\n").arg(copy->id));
+ }
+ }
+ }
+
+ return result;
+}
+
+/* Validiate a breakpoint at a given URL and line number
+ breakPtr, copy and ctx must be valid
+ */
+static int validateTemplateBreakPoint(breakPointPtr breakPtr, breakPointPtr copy, xsltTransformContextPtr ctxt)
+{
+ int result = 0;
+ if (!breakPtr || !copy || !ctxt){
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Warning: NULL arguments passed to validateTemplateBreakPoint\n");
+#endif
+ return result;
+ }
+
+ copy->templateName = xmlStrdup(breakPtr->templateName);
+ if ((xmlStrlen(copy->templateName) == 0) || xmlStrEqual(copy->templateName, (xmlChar*)"*")){
+ if (xmlStrEqual(breakPtr->url, orphanedTemplateURL))
+ breakPointDelete(breakPtr);
+ if ( xslDbgShellBreak(copy->templateName, NULL, ctxt)){
+ result = 1;
+ xsldbgGenericErrorFunc(i18n("Information: Breakpoint validation has caused one or more breakpoints to be re-created.\n"));
+ }
+ }else{
+ if (xmlStrEqual(breakPtr->url, orphanedTemplateURL))
+ breakPointDelete(breakPtr);
+ if (xslDbgShellBreak(copy->templateName, NULL, ctxt)){
+ result = 1;
+ }
+ }
+ xmlFree(copy->templateName);
+ if (!result){
+ xsldbgGenericErrorFunc(i18n("Warning: Validation of breakpoint %1 failed.\n").arg(copy->id));
+ }
+ return result;
+}
+
+/**
+ * xslDbgShellValidateBreakPoint:
+ * @payload: A valid breakPointPtr
+ * @data: Not used
+ * @name: Not used
+ *
+ * Print an warning if a breakpoint is invalid
+
+ */
+void xslDbgShellValidateBreakPoint(void *payload, void *data,
+ xmlChar * name)
+{
+ Q_UNUSED(name);
+ int result = 0;
+ if (payload){
+ breakPointPtr breakPtr = (breakPointPtr) payload;
+
+ breakPoint copy; /* create a copy of the breakpoint */
+ copy.lineNo = breakPtr->lineNo;
+ copy.url = xmlStrdup(breakPtr->url);
+ copy.flags = breakPtr->flags;
+ copy.type = breakPtr->type;
+ copy.id = breakPtr->id;
+ if (copy.url){
+ if (breakPtr->templateName){
+ /* template name is used to contain the rules to add template breakpoint */
+ result = validateTemplateBreakPoint(breakPtr, &copy, (xsltTransformContextPtr)data);
+ }else{
+ result = validateBreakPoint(breakPtr, &copy);
+ }
+ }else{
+ xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
+ }
+
+ xmlFree(copy.url);
+ }
+}
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/callstack.cpp b/kxsldbg/kxsldbgpart/libxsldbg/callstack.cpp
new file mode 100644
index 00000000..585a70d1
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/callstack.cpp
@@ -0,0 +1,509 @@
+
+/***************************************************************************
+ callstack.c - call stack implementation
+ -------------------
+ begin : Fri Nov 2 2001
+ copyright : (C) 2001 by Keith Isdale
+ email : k_isdale@tpg.com.au
+ ***************************************************************************/
+
+#include "xsldbg.h"
+#include "utils.h"
+#include "breakpoint.h"
+#include "arraylist.h"
+#include "callstack.h"
+#include "xsldbgmsg.h"
+
+
+/*------------------------------------------------------
+ Private functions
+ -----------------------------------------------------*/
+
+/**
+ * addCallInfo:
+ * @templateName: Template name to add
+ * @templateURI: QName part of template name to add
+ * @modeName: Mode of template
+ * @modeURI: QName part of node of template
+ * @url: The url for the template
+ *
+ * Add template "call" to call stack
+ *
+ * Returns A reference to the added info if successful,
+ * NULL otherwise
+ */
+callPointInfoPtr
+addCallInfo(const xmlChar * templateName, const xmlChar *templateURI,
+ const xmlChar * modeName, const xmlChar* modeURI, const xmlChar * url);
+
+
+/*------------------------------------------------------
+ Xsl call stack related
+-----------------------------------------------------*/
+
+/* keep track of the top and bottom of call stack*/
+
+/* This is the major structure and contains a stack of call points */
+callPointPtr callStackBot, callStackTop;
+
+/* save memory by keep only one copy of data used for several
+ items on call stack */
+callPointInfoPtr callInfo;
+
+/* What frame depth are we to stop at */
+int stopDepth = -1;
+
+
+/**
+ * callStackInit:
+ *
+ * Returns If callStack has been initialized properly and all
+ * memory required has been obtained,
+ * 0 otherwise
+ *
+ * Returns 1 if callStack has been initialized properly and all
+ * memory required has been obtained,
+ * 0 otherwise
+*/
+int
+callStackInit(void)
+{
+
+ callInfo = (callPointInfoPtr) xmlMalloc(sizeof(callPointInfo));
+ if (callInfo) {
+ callInfo->next = NULL;
+ callInfo->templateName = NULL;
+ callInfo->templateURI = NULL;
+ callInfo->modeName = NULL;
+ callInfo->modeURI = NULL;
+ callInfo->url = NULL;
+ }
+ callStackBot = (callPointPtr) xmlMalloc(sizeof(callPoint));
+ if (callStackBot) {
+ callStackBot->next = NULL;
+ callStackBot->info = NULL;
+ callStackBot->lineNo = -1;
+ callStackTop = callStackBot;
+ }
+ return (callInfo != NULL) && (callStackBot != NULL);
+}
+
+
+
+/**
+ * callStackFree:
+ *
+ *
+ * Free all memory used by callStack
+ */
+void
+callStackFree(void)
+{
+
+ callPointInfoPtr curInfo = callInfo, nextInfo;
+ callPointPtr curCall = callStackBot, nextCall;
+
+ /* remove all call info's */
+ while (curInfo) {
+ nextInfo = curInfo->next;
+ if (curInfo->templateName)
+ xmlFree(curInfo->templateName);
+ if (curInfo->templateURI)
+ xmlFree(curInfo->templateURI);
+ if (curInfo->modeName)
+ xmlFree(curInfo->modeName);
+ if (curInfo->modeURI)
+ xmlFree(curInfo->modeURI);
+ if (curInfo->url)
+ xmlFree(curInfo->url);
+ xmlFree(curInfo);
+ curInfo = nextInfo;
+ }
+ curInfo = NULL;
+
+ /* remove all call stack items left. There should be none !! */
+ while (curCall) {
+ nextCall = curCall->next;
+ xmlFree(curCall);
+ curCall = nextCall;
+ }
+
+ callStackBot = NULL;
+ callStackTop = NULL;
+ callInfo = NULL;
+}
+
+
+/**
+ * addCallInfo:
+ * @templateName: Template name to add
+ * @templateURI: QName part of template name to add
+ * @modeName: Mode of template
+ * @modeURI: QName part of node of template
+ * @url: The url for the template
+ *
+ * Add template "call" to call stack
+ *
+ * Returns A reference to the added info if successful,
+ * NULL otherwise
+ */
+callPointInfoPtr
+addCallInfo(const xmlChar * templateName, const xmlChar *templateURI,
+ const xmlChar * modeName, const xmlChar* modeURI, const xmlChar * url)
+{
+ callPointInfoPtr result = NULL, cur = callInfo;
+ int found;
+
+ if (!templateName || !url) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Null template name or url: addCallInfo\n");
+ if (templateName)
+ xsltGenericError(xsltGenericErrorContext, "template :\"%s\"\n",
+ templateName);
+ if (url)
+ xsltGenericError(xsltGenericErrorContext, "url :\"%s\"\n", url);
+
+#endif
+ return result;
+ }
+
+ while (cur->next) {
+ found = 1;
+ if (templateName && cur->templateName
+ && !xmlStrEqual(cur->templateName, templateName))
+ found = 0;
+ if (found && !xmlStrEqual(cur->templateURI, templateURI))
+ found = 0;
+ if (found && !xmlStrEqual(cur->modeName, modeName))
+ found = 0;
+ if (found && !xmlStrEqual(cur->modeURI, modeURI))
+ found = 0;
+ if (found && !xmlStrEqual(cur->url, url))
+ found = 0;
+
+ if (found){
+ result = cur;
+ break;
+ }
+ cur = cur->next;
+ }
+
+ if (!result && cur) {
+ result = (callPointInfoPtr) xmlMalloc(sizeof(callPointInfo));
+ if (result) {
+ if ((cur == callInfo) && !cur->templateName && !cur->templateURI
+ && !cur->modeName && !cur->modeURI
+ && !cur->url){
+ xmlFree(callInfo);
+ callInfo = result;
+ } else{
+ cur->next = result;
+ }
+ result->templateName =
+ (xmlChar *) xmlMemStrdup((char *) templateName);
+ result->templateURI =
+ (xmlChar *) xmlMemStrdup((char *) templateURI);
+ result->modeName =
+ (xmlChar *) xmlMemStrdup((char *) modeName);
+ result->modeURI =
+ (xmlChar *) xmlMemStrdup((char *) modeURI);
+ result->url = (xmlChar *) xmlMemStrdup((char *) url);
+ result->next = NULL;
+ }else {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Unable to create callPointInfo from : addCallInfo\n");
+#endif
+ }
+ }
+ if (!cur){
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Unable to create callPointInfo from : addCallInfo\n");
+#endif
+ }
+ return result;
+}
+
+
+/**
+ * callStackAdd:
+ * @templ: The current template being applied
+ * @source: The source node being processed
+ *
+ * Add template "call" to call stack
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+callStackAdd(xsltTemplatePtr templ, xmlNodePtr source)
+{
+ int result = 0;
+ const char *name = "Default template";
+ callPointInfoPtr info;
+
+ if (!templ || !source)
+ return result;
+
+ if (!source->doc || !source->doc->URL) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Invalid document url in call from : callStackAdd\n");
+#endif
+ return result;
+ }
+
+ /* are at a "frame" break point ie "step down" */
+ if ((xslDebugStatus == DEBUG_STEPDOWN)
+ && (stopDepth == callStackGetDepth())) {
+ xslDebugStatus = DEBUG_STOP;
+ stopDepth = 0;
+ }
+
+ /* this need not be an error just we've got a text in source */
+ if (xmlGetLineNo(source) == -1) {
+ return result;
+ }
+
+ if (templ) {
+ if (templ->name)
+ name = (char *) templ->name;
+ else {
+ if (templ->match)
+ name = (char *) templ->match;
+ }
+ }
+
+ if (!name) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Invalid template name : callStackAdd\n");
+#endif
+ return result;
+ }
+
+ info = addCallInfo((xmlChar *) name, (xmlChar *) templ->nameURI,
+ (xmlChar *) templ->mode, (xmlChar *) templ->modeURI,
+ source->doc->URL);
+
+ if (info) {
+ callPointPtr cur;
+
+ cur = (callPointPtr) xmlMalloc(sizeof(callPoint));
+ if (cur) {
+ callStackTop->next = cur;
+ callStackTop = cur;
+ cur->info = info;
+ cur->lineNo = xmlGetLineNo(source);
+ cur->next = NULL;
+ result = 1;
+ } else {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Unable to create call point : callStackAdd\n");
+#endif
+ }
+ } else {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Unable to create call info : callStackAdd\n");
+#endif
+ }
+
+ return result;
+}
+
+
+/**
+ * callStackDrop:
+ *
+ *
+ * Drop the topmost item off the call stack
+ */
+void
+callStackDrop(void)
+{
+
+ if (!callStackBot) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: callStackDrop failed invalid call stack: dbgcallstack.c");
+#endif
+ return;
+ }
+
+ /* are we at a "frame" break point ie "step up". if we've gone too
+ * far stop imediately */
+ if ((xslDebugStatus == DEBUG_STEPUP)
+ && (-1 * callStackGetDepth()) >= stopDepth) {
+ xslDebugStatus = DEBUG_STOP;
+ stopDepth = 0;
+ }
+
+ if (callStackBot->next) {
+ callPointPtr cur = callStackBot;
+
+ while (cur->next && cur->next->next) {
+ cur = cur->next;
+ }
+ if (cur->next)
+ xmlFree(cur->next);
+ cur->next = NULL;
+ callStackTop = cur;
+ } else {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: callStackDrop failed no items on call stack : dbgcallstack.c");
+#endif
+ }
+}
+
+
+/**
+ * callStackStepup:
+ * @depth:The frame depth to step up to
+ * 0 < @depth <= callStackGetDepth()
+ *
+ * Set the frame depth to step up to
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+callStackStepup(int depth)
+{
+ int result = 0;
+
+ if ((depth > 0) && (depth <= callStackGetDepth())) {
+ stopDepth = -1 * depth;
+ xslDebugStatus = DEBUG_STEPUP;
+ result = 1;
+ } else {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: callStackStepup failed invalid depth %d: callstack.c", depth);
+#endif
+ }
+ return result;
+}
+
+
+/**
+ * callStackStepdown:
+ * @depth: The frame depth to step down to,
+ * 0 < @depth <= callStackGetDepth()
+ *
+ * Set the frame depth to step down to
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+callStackStepdown(int depth)
+{
+ int result = 0;
+
+ if ((depth > 0) && (depth >= callStackGetDepth())) {
+ stopDepth = depth;
+ xslDebugStatus = DEBUG_STEPDOWN;
+ result = 1;
+ } else {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: callStackStepdown failed invalid depth %d: dbgcallstack.c", depth);
+#endif
+ }
+ return result;
+}
+
+
+/**
+ * callStackGet:
+ * @depth: 0 < @depth <= callStackGetDepth()
+ *
+ * Retrieve the call point at specified call depth
+
+ * Returns Non-null if depth is valid,
+ * NULL otherwise
+ */
+callPointPtr
+callStackGet(int depth)
+{
+ callPointPtr result = NULL, cur = callStackBot;
+
+ if (!callStackBot) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: callStackGet failed invalid call stack: callstack.c");
+#endif
+ return result;
+ }
+ if ((depth < 1) && (depth > callStackGetDepth())) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: callStackGet failed invalid call depth: callstack.c");
+#endif
+ return result;
+ }
+
+ while (depth > 0 && cur->next) {
+ cur = cur->next;
+ depth--;
+ }
+
+ if (depth == 0)
+ result = cur;
+ else {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: callStackGet failed invalid call depth: callstack.c");
+#endif
+ }
+ return result;
+}
+
+
+/**
+ * callStackGetTop:
+ *
+ * Get the top item in the call stack
+ *
+ * Returns The top of the call stack
+ */
+callPointPtr
+callStackGetTop(void)
+{
+ return callStackTop;
+}
+
+
+/**
+ * callStackGetDepth:
+ *
+ * Return the depth of call stack
+ *
+ * Returns The depth of call stack
+ */
+int
+callStackGetDepth(void)
+{
+ callPointPtr cur = callStackBot;
+ int depthCount = 0;
+
+ if (!callStackBot) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: calldepth failed invalid call stack: dbgcallstack.c");
+#endif
+ return depthCount;
+ }
+
+
+ while (cur->next) {
+ depthCount++;
+ cur = cur->next;
+ }
+ return depthCount;
+}
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/callstack.h b/kxsldbg/kxsldbgpart/libxsldbg/callstack.h
new file mode 100644
index 00000000..fd87b9bd
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/callstack.h
@@ -0,0 +1,275 @@
+
+/* *************************************************************************
+ xslcallpoint.h - public functions for the
+ the call stack
+ -------------------
+ begin : Fri Dec 7 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 XSLCALLSTACK_H
+#define XSLCALLSTACK_H
+
+/**
+ * Provide a call stack support
+ *
+ * @short call stack support
+ *
+ * @author Keith Isdale <k_isdale@tpg.com.au>
+ */
+
+#ifndef BUILD_DOCS
+#include "breakpoint.h"
+#endif
+
+#ifdef WITH_XSLT_DEBUG
+#ifndef WITH_XSLT_DEBUG_BREAKPOINTS
+#define WITH_XSLT_DEBUG_BREAKPOINTS
+#endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+ typedef struct _callPointInfo callPointInfo;
+ typedef callPointInfo *callPointInfoPtr;
+ struct _callPointInfo {
+ xmlChar *templateName, *templateURI;
+ xmlChar *modeName, *modeURI;
+ xmlChar *url;
+ callPointInfoPtr next;
+ };
+
+ typedef struct _callPoint callPoint;
+ typedef callPoint *callPointPtr;
+ struct _callPoint {
+ callPointInfoPtr info;
+ long lineNo;
+ callPointPtr next;
+ };
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * callStackInit:
+ *
+ * Returns If callStack has been initialized properly and all
+ * memory required has been obtained,
+ * 0 otherwise
+ *
+ * Returns 1 if callStack has been initialized properly and all
+ * memory required has been obtained,
+ * 0 otherwise
+*/
+#endif
+ int
+ callStackInit(void);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * callStackFree:
+ *
+ *
+ * Free all memory used by callStack
+ */
+#endif
+ void
+ callStackFree(void);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * callStackAdd:
+ * @templ: The current template being applied
+ * @source: The source node being processed
+ *
+ * Add template "call" to call stack
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Add template "call" to call stack
+ *
+ * @param templ The current template being applied
+ * @param source The source node being processed
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ */
+#endif
+#endif
+ int callStackAdd(xsltTemplatePtr templ, xmlNodePtr source);
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * callStackDrop:
+ *
+ *
+ * Drop the topmost item off the call stack
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Drop the topmost item off the call stack
+ */
+#endif
+#endif
+ void callStackDrop(void);
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * callStackStepup:
+ * @depth:The frame depth to step up to
+ * 0 < @depth <= callDepth()
+ *
+ * Set the frame depth to step up to
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Set the frame depth to step up to
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param depth The frame depth to step up to
+ * 0 < @p depth <= callDepth()
+ */
+#endif
+#endif
+ int callStackStepup(int depth);
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * callStackStepdown:
+ * @depth: The frame depth to step down to,
+ * 0 < @depth <= callDepth()
+ *
+ * Set the frame depth to step down to
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Set the frame depth to step down to
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param depth The frame depth to step down to
+ * 0 < @p depth <= callDepth()
+ */
+#endif
+#endif
+ int callStackStepdown(int depth);
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * callStackGet:
+ * @depth: 0 < @depth <= callDepth()
+ *
+ * Retrieve the call point at specified call depth
+
+ * Returns Non-null a if depth is valid,
+ * NULL otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Retrieve the call point at specified call depth
+
+ * @returns Non-null a if depth is valid,
+ * NULL otherwise
+ *
+ * @param depth 0 < @p depth <= callDepth()
+ */
+#endif
+#endif
+ callPointPtr callStackGet(int depth);
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * callStackGetTop:
+ *
+ * Get the top item in the call stack
+ *
+ * Returns The top of the call stack
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Get the top item in the call stack
+ *
+ * @returns The top of the call stack
+ */
+#endif
+#endif
+ callPointPtr callStackGetTop(void);
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * callStackGetDepth:
+ *
+ * Return the depth of call stack
+ *
+ * Returns The depth of call stack
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * @returns the depth of call stack
+ */
+#endif
+#endif
+ int callStackGetDepth(void);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/cmds.h b/kxsldbg/kxsldbgpart/libxsldbg/cmds.h
new file mode 100644
index 00000000..f12648c7
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/cmds.h
@@ -0,0 +1,197 @@
+
+/***************************************************************************
+ cmds.h - A list of valid commands ID's for xsldbg
+ -------------------
+ begin : Thu Dec 27 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 CMDS_H
+#define CMDS_H
+
+/* See the top of debugXSL.c for a list of command names and thier shortcuts */
+#ifndef USE_KDE_DOCS
+typedef enum { /* id's for commands of xslDbgShell */
+ DEBUG_HELP_CMD = 100,
+ DEBUG_BYE_CMD,
+ DEBUG_EXIT_CMD,
+ DEBUG_QUIT_CMD,
+
+ DEBUG_STEP_CMD,
+ DEBUG_STEPUP_CMD,
+ DEBUG_STEPDOWN_CMD,
+ DEBUG_NEXT_CMD,
+ DEBUG_CONT_CMD,
+ DEBUG_RUN_CMD,
+
+ DEBUG_TEMPLATES_CMD,
+ DEBUG_WHERE_CMD,
+ DEBUG_FRAME_CMD,
+ DEBUG_STYLESHEETS_CMD,
+
+ DEBUG_BREAK_CMD,
+ DEBUG_SHOWBREAK_CMD,
+ DEBUG_DELETE_CMD,
+ DEBUG_ENABLE_CMD,
+ DEBUG_DISABLE_CMD,
+
+ DEBUG_LS_CMD,
+ DEBUG_DIR_CMD,
+ DEBUG_DU_CMD,
+ DEBUG_CAT_CMD,
+ DEBUG_PRINT_CMD, /* cat alternative */
+ DEBUG_PWD_CMD,
+ DEBUG_DUMP_CMD,
+ DEBUG_BASE_CMD,
+
+ DEBUG_GLOBALS_CMD,
+ DEBUG_LOCALS_CMD,
+ /* DEBUG_CAT_CMD, already listed */
+ DEBUG_SOURCE_CMD,
+ DEBUG_DATA_CMD,
+ DEBUG_OUTPUT_CMD,
+ DEBUG_CD_CMD,
+
+ /* file related */
+ /* DEBUG_OUTPUT_CMD, already listed */
+ DEBUG_ENTITIES_CMD,
+ DEBUG_SYSTEM_CMD,
+ DEBUG_PUBLIC_CMD,
+ DEBUG_ENCODING_CMD,
+ DEBUG_VALIDATE_CMD,
+ DEBUG_LOAD_CMD,
+ DEBUG_SAVE_CMD,
+ DEBUG_WRITE_CMD,
+ DEBUG_FREE_CMD,
+
+ /* Operating system related */
+ DEBUG_CHDIR_CMD,
+ DEBUG_SHELL_EXEC_CMD,
+ DEBUG_TTY_CMD,
+
+ /* libxslt parameter and options related */
+ DEBUG_ADDPARAM_CMD,
+ DEBUG_DELPARAM_CMD,
+ DEBUG_SHOWPARAM_CMD,
+ DEBUG_SETOPTION_CMD,
+ DEBUG_OPTIONS_CMD, /* print options */
+
+ /* extra options/commands */
+ DEBUG_TRACE_CMD,
+ DEBUG_WALK_CMD,
+ DEBUG_ADDWATCH_CMD,
+ DEBUG_DELWATCH_CMD,
+ DEBUG_SHOWWATCH_CMD,
+
+ /* searching */
+ DEBUG_SEARCH_CMD,
+
+ /* variable change */
+ DEBUG_SET_CMD,
+
+ /* language change */
+ DEBUG_LANG_CMD
+
+ /* NULL */
+
+} CommandsEnum;
+#else
+
+/* Keep kdoc happy*/
+enum CommandsEnum { /* id's for commands of xslDbgShell */
+ DEBUG_HELP_CMD = 100,
+ DEBUG_BYE_CMD,
+ DEBUG_EXIT_CMD,
+ DEBUG_QUIT_CMD,
+
+ DEBUG_STEP_CMD,
+ DEBUG_STEPUP_CMD,
+ DEBUG_STEPDOWN_CMD,
+ DEBUG_NEXT_CMD,
+ DEBUG_CONT_CMD,
+ DEBUG_RUN_CMD,
+
+ DEBUG_TEMPLATES_CMD,
+ DEBUG_WHERE_CMD,
+ DEBUG_FRAME_CMD,
+ DEBUG_STYLESHEETS_CMD,
+
+ DEBUG_BREAK_CMD,
+ DEBUG_SHOWBREAK_CMD,
+ DEBUG_DELETE_CMD,
+ DEBUG_ENABLE_CMD,
+ DEBUG_DISABLE_CMD,
+
+ DEBUG_LS_CMD,
+ DEBUG_DIR_CMD,
+ DEBUG_DU_CMD,
+ DEBUG_CAT_CMD,
+ DEBUG_PRINT_CMD, /* cat alternative */
+ DEBUG_PWD_CMD,
+ DEBUG_DUMP_CMD,
+ DEBUG_BASE_CMD,
+
+ DEBUG_GLOBALS_CMD,
+ DEBUG_LOCALS_CMD,
+ /* DEBUG_CAT_CMD, already listed */
+ DEBUG_SOURCE_CMD,
+ DEBUG_DATA_CMD,
+ DEBUG_OUTPUT_CMD,
+ DEBUG_CD_CMD,
+
+ /* file related */
+ /* DEBUG_OUTPUT_CMD, already listed */
+ DEBUG_ENTITIES_CMD,
+ DEBUG_SYSTEM_CMD,
+ DEBUG_PUBLIC_CMD,
+ DEBUG_ENCODING_CMD,
+ DEBUG_VALIDATE_CMD,
+ DEBUG_LOAD_CMD,
+ DEBUG_SAVE_CMD,
+ DEBUG_WRITE_CMD,
+ DEBUG_FREE_CMD,
+
+ /* Operating system related */
+ DEBUG_CHDIR_CMD,
+ DEBUG_SHELL_EXEC_CMD,
+ DEBUG_TTY_CMD,
+
+ /* libxslt parameter and options related */
+ DEBUG_ADDPARAM_CMD,
+ DEBUG_DELPARAM_CMD,
+ DEBUG_SHOWPARAM_CMD,
+ DEBUG_SETOPTION_CMD,
+ DEBUG_OPTIONS_CMD, /* print options */
+
+ /* extra options/commands */
+ DEBUG_TRACE_CMD,
+ DEBUG_WALK_CMD,
+ DEBUG_ADDWATCH_CMD,
+ DEBUG_DELWATCH_CMD,
+ DEBUG_SHOWWATCH_CMD,
+
+ /* searching */
+ DEBUG_SEARCH_CMD,
+
+ /* variable change */
+ DEBUG_SET_CMD
+
+ /* language change */
+ DEBUG_LANG_CMD
+
+ /* NULL */
+};
+#endif
+
+#endif
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/debug.cpp b/kxsldbg/kxsldbgpart/libxsldbg/debug.cpp
new file mode 100644
index 00000000..2975f814
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/debug.cpp
@@ -0,0 +1,235 @@
+
+/***************************************************************************
+ debug.c - main functions for debugger use
+ -------------------
+ begin : Fri Nov 2 2001
+ copyright : (C) 2001 by Keith Isdale
+ email : k_isdale@tpg.com.au
+ ***************************************************************************/
+
+#include "xsldbg.h"
+#include "debug.h"
+#include "debugXSL.h" /* needed for debugXSLBreak function */
+#include "breakpoint.h"
+#include "callstack.h"
+#include "files.h"
+#include "options.h"
+
+#include <libxslt/xsltutils.h> /* need for breakpoint callback support */
+
+/* setup debugger callbacks */
+struct DebuggerCallbacks {
+ xsltHandleDebuggerCallback debuggercallback;
+ xsltAddCallCallback addcallback;
+ xsltDropCallCallback dropcallback;
+} debuggerDriver;
+
+
+/* -----------------------------------------
+ Private functions
+ -------------------------------------------*/
+
+/**
+ * debugHandleDebugger:
+ * @cur : source node being executed
+ * @node : data node being processed
+ * @templ : temlate that applies to node
+ * @ctxt : the xslt transform context
+ *
+ * If either cur or node are a breakpoint, or xslDebugStatus in state
+ * where debugging must occcur at this time, then transfer control
+ * to the debugXSLBreak function
+ */
+void debugHandleDebugger(xmlNodePtr cur, xmlNodePtr node,
+ xsltTemplatePtr templ,
+ xsltTransformContextPtr ctxt);
+
+/* -------------------------------------
+ End private functions
+---------------------------------------*/
+
+
+/*-----------------------------------------------------------
+ Main debugger functions
+-----------------------------------------------------------*/
+
+
+
+/**
+ * debugInit :
+ *
+ * Initialize debugger
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+debugInit(void)
+{
+ int result;
+
+ xslDebugStatus = DEBUG_NONE;
+ result = breakPointInit();
+ result = result && callStackInit();
+
+ /* setup debugger callbacks */
+ debuggerDriver.debuggercallback = debugHandleDebugger;
+ debuggerDriver.addcallback = callStackAdd;
+ debuggerDriver.dropcallback = callStackDrop;
+ xsltSetDebuggerCallbacks(3, &debuggerDriver);
+ return result;
+}
+
+
+/**
+ * debugFree :
+ *
+ * Free up any memory taken by debugging
+ */
+void
+debugFree(void)
+{
+ breakPointFree();
+ callStackFree();
+}
+
+
+/**
+ * debugGotControl:
+ * @reached: 1 if debugger has received control, -1 to read its value,
+ 0 to clear the flag
+ *
+ * Set flag that debugger has received control to value of @reached
+ *
+ * Returns 1 if any break point was reached previously,
+ * 0 otherwise
+ */
+int
+debugGotControl(int reached)
+{
+ static int hasReached;
+ int result = hasReached;
+
+ if (reached != -1)
+ hasReached = reached;
+ return result;
+}
+
+
+/**
+ * debugHandleDebugger:
+ * @cur : source node being executed
+ * @node : data node being processed
+ * @templ : temlate that applies to node
+ * @ctxt : the xslt transform context
+ *
+ * If either cur or node are a breakpoint, or xslDebugStatus in state
+ * where debugging must occcur at this time then transfer control
+ * to the debugXSLBreak function
+ */
+void
+debugHandleDebugger(xmlNodePtr cur, xmlNodePtr node,
+ xsltTemplatePtr templ, xsltTransformContextPtr ctxt)
+{
+
+ if (!cur && !node) {
+ xsldbgGenericErrorFunc(i18n("Error: XSLT source and XML data are empty. Cannot enter the debugger.\n"));
+ } else {
+ if (optionsGetIntOption(OPTIONS_GDB)){
+ int doValidation = 0;
+ switch(xsldbgValidateBreakpoints){
+ case BREAKPOINTS_ARE_VALID:
+ if (!filesGetStylesheet() || !filesGetMainDoc()) {
+ xsldbgValidateBreakpoints = BREAKPOINTS_NEED_VALIDATION;
+ doValidation = 1;
+ }
+
+ break;
+
+ case BREAKPOINTS_NEED_VALIDATION:
+ if (filesGetStylesheet() && filesGetMainDoc() && templ){
+ xsldbgValidateBreakpoints = BREAKPOINTS_BEING_VALIDATED;
+ doValidation = 1;
+ }
+ break;
+
+ case BREAKPOINTS_BEING_VALIDATED:
+ /*should never be in the state for any length of time */
+#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Unexpected breakpoint validation state %d", xsldbgValidateBreakpoints);
+#endif
+ break;
+ }
+ if (doValidation){
+ /* breakpoints will either be marked as orphaned or not as needed */
+ xsldbgValidateBreakpoints = BREAKPOINTS_BEING_VALIDATED;
+ walkBreakPoints((xmlHashScanner)
+ xslDbgShellValidateBreakPoint, ctxt);
+ if (filesGetStylesheet() && filesGetMainDoc() && templ){
+ xsldbgValidateBreakpoints = BREAKPOINTS_ARE_VALID;
+ }else{
+ xsldbgValidateBreakpoints = BREAKPOINTS_NEED_VALIDATION;
+ }
+ }
+ }
+ switch (xslDebugStatus) {
+
+ /* A temparary stopping point */
+ case DEBUG_WALK:
+ case DEBUG_TRACE:
+ /* only allow breakpoints at xml elements */
+ if (xmlGetLineNo(cur) != -1)
+ debugXSLBreak(cur, node, templ, ctxt);
+ break;
+
+ case DEBUG_STOP:
+ xslDebugStatus = DEBUG_CONT;
+ /* only allow breakpoints at xml elements */
+ if (xmlGetLineNo(cur) != -1)
+ debugXSLBreak(cur, node, templ, ctxt);
+ break;
+
+ case DEBUG_STEP:
+ /* only allow breakpoints at xml elements */
+ if (xmlGetLineNo(cur) != -1)
+ debugXSLBreak(cur, node, templ, ctxt);
+ break;
+
+ case DEBUG_CONT:
+ {
+ breakPointPtr breakPtr = NULL;
+ xmlChar *baseUri = NULL;
+
+ if (cur) {
+ breakPtr =
+ breakPointGet(cur->doc->URL,
+ xmlGetLineNo(cur));
+
+ if (breakPtr && (breakPtr->flags & BREAKPOINT_ENABLED) ){
+ debugXSLBreak(cur, node, templ, ctxt);
+ return;
+ }
+ }
+ if (node) {
+ baseUri = filesGetBaseUri(node);
+ if (baseUri != NULL) {
+ breakPtr =
+ breakPointGet(baseUri, xmlGetLineNo(node));
+ } else {
+ breakPtr =
+ breakPointGet(node->doc->URL,
+ xmlGetLineNo(node));
+ }
+ if (breakPtr) {
+ if (breakPtr->flags & BREAKPOINT_ENABLED) {
+ debugXSLBreak(cur, node, templ, ctxt);
+ }
+ }
+ if (baseUri)
+ xmlFree(baseUri);
+ }
+ }
+ break;
+ }
+ }
+}
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/debug.h b/kxsldbg/kxsldbgpart/libxsldbg/debug.h
new file mode 100644
index 00000000..c38f37eb
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/debug.h
@@ -0,0 +1,101 @@
+
+/**************************************************************************
+ debug.h - declare major debugger functions
+ -------------------
+ begin : Thur Jan 31 2002
+ 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 XSL_DEBUG_H
+#define XSL_DEBUG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * debugInit:
+ *
+ * Initialize debugger allocating any memory needed by debugger
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Initialize debugger allocating any memory needed by debugger
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ */
+#endif
+#endif
+ int debugInit(void);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * debugFree:
+ *
+ * Free up any memory taken by debugger
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Free up any memory taken by debugger
+ */
+#endif
+#endif
+ void debugFree(void);
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * debugGotControl:
+ * @reached: 1 if debugger has received control, -1 to read its value,
+ 0 to clear the flag
+ *
+ * Set flag that debuger has received control to value of @reached
+ *
+ * Returns 1 if any break point was reached previously,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Set flag that debuger has received control to value of @p reached
+ *
+ * @returns 1 if any breakpoint was reached previously,
+ * 0 otherwise
+ *
+ * @param reached 1 if debugger has received control, -1 to read its value,
+ * 0 to clear the flag
+ */
+#endif
+#endif
+ int debugGotControl(int reached);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/debugXSL.cpp b/kxsldbg/kxsldbgpart/libxsldbg/debugXSL.cpp
new file mode 100644
index 00000000..39aea804
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/debugXSL.cpp
@@ -0,0 +1,2118 @@
+
+/***************************************************************************
+ debugXSL.c - debugger commands to use
+ -------------------
+ begin : Sun Sep 16 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. *
+ * *
+ ***************************************************************************/
+
+/*
+ * Orinal file : debugXML.c : This is a set of routines used for
+ * debugging the tree produced by the XML parser.
+ *
+ * New file : shell.c : Debug support version
+ *
+ * See Copyright for the status of this software.
+ *
+ * Daniel Veillard <daniel@veillard.com>
+ *
+ * Permission obtained to modify the LGPL'd code and extend to include breakpoints, inspections of
+ * stylesheet source, xml data, stylesheet variables
+ */
+
+#ifdef WIN32
+#include <wtypes.h>
+#include <winbase.h> /* needed fort the sleep function */
+#endif
+
+#include "xsldbg.h"
+#include "files.h"
+#include "cmds.h" /* list of command Id's */
+#include "debug.h"
+#include "debugXSL.h"
+#include "options.h"
+#include "breakpoint.h"
+#include "help.h"
+#include <stdlib.h>
+#include <libxslt/transform.h> /* needed by source command */
+#include <libxslt/xsltInternals.h>
+#include <libxml/debugXML.h>
+#include <stdio.h>
+
+/* language change support */
+#ifdef LOCALE_PREFIX
+#include <locale.h>
+#endif
+
+#include "xsldbgmsg.h"
+#include "xsldbgthread.h" /* for get thread status */
+#include "xsldbgio.h"
+
+/* current template being processed */
+xsltTemplatePtr rootCopy;
+
+/* how may items have been printed */
+int printCount;
+
+/* used to sending small amounts data when xsldbg runs as a thread */
+xmlChar messageBuffer[2000];
+
+/* To achieve the same fucntionality of a next command
+ we first do a step, then a step up */
+int nextCommandActive = 0;
+
+/* Do we print the values for watches each time the debugger stops */
+int showWatchesActive = 1;
+
+extern FILE *terminalIO;
+
+int xsldbgStop = 0;
+int xsldbgValidateBreakpoints = BREAKPOINTS_NEED_VALIDATION;
+int xsldbgHasLineNumberFix;
+bool xsldbgReachedFirstTemplate = false;
+
+/* valid commands of xslDbgShell */
+const char *commandNames[] = {
+ "help",
+
+ "bye",
+ "exit",
+ "quit",
+
+ "step",
+ "stepup",
+ "stepdown",
+ "next", /* next ie step over template function call*/
+ "continue",
+ "run",
+
+ "templates",
+ "where",
+ "frame",
+ "stylesheets",
+
+ "break",
+ "showbreak",
+ "delete",
+ "enable",
+ "disable",
+
+ "ls",
+ "dir",
+ "du",
+ "cat",
+ "print",
+ "pwd",
+ "dump",
+ "base",
+
+ "globals",
+ "locals",
+ /* "cat", already listed */
+ "source",
+ "data",
+ "output", /* output file name */
+ "cd",
+
+ /* file related */
+ /* "output", already listed */
+ "entities",
+ "system",
+ "public",
+ "encoding",
+ "validate",
+ "load",
+ "save",
+ "write",
+ "free",
+
+ /* Operating system related */
+ "chdir",
+ "shell",
+ "tty",
+
+ /* libxslt parameter related */
+ "addparam",
+ "delparam",
+ "showparam",
+ "setoption",
+ "options",
+
+ /* extra options */
+ "trace",
+ "walk",
+ "addwatch",
+ "delwatch",
+ "showwatch",
+
+ /* searching */
+ "search",
+
+ /*variable value change */
+ "set",
+
+ /* language change */
+ "lang",
+
+ NULL /* Indicate the end of list */
+};
+
+/* valid commands of xslShell in there alternative|shorter format */
+const char *shortCommandNames[] = {
+ "h",
+
+ "bye",
+ "exit",
+ "q", /*quit */
+
+ "s", /* step */
+ "up", /*stepup */
+ "down", /* stepdown */
+ "n", /* next ie step over function call*/
+ "c", /* continue */
+ "r", /* run */
+
+ "t", /* templates */
+ "w", /* where */
+ "f",
+ "style",
+
+ "b", /* break */
+ "show",
+ "d", /* delete */
+ "e", /* enabled */
+ "disable",
+
+ "ls",
+ "dir",
+ "du",
+ "cat",
+ "print",
+ "pwd",
+ "dump",
+ "base",
+
+ "globals",
+ "locals",
+ /* "cat", already listed */
+ "source",
+ "data",
+ "o", /* output file name */
+ "cd",
+
+
+ /* file related */
+ /* "output", already listed */
+ "ent", /* entities command */
+ "sys", /* sytem command */
+ "pub", /* public command */
+ "encoding",
+ "validate",
+ "load",
+ "save",
+ "write",
+ "free",
+
+ /* Operating system related */
+ "chdir",
+ "shell",
+ "tty",
+
+ /* libxslt parameter related */
+ "addparam",
+ "delparam",
+ "showparam",
+ "setoption",
+ "options",
+
+ /* extra options/commands */
+ "trace",
+ "walk",
+ "watch",
+ "delwatch",
+ "watches",
+
+ /* searching */
+ "search",
+
+ /*variable value change */
+ "set",
+
+ /* language change */
+ "lang",
+
+ NULL /* Indicate the end of list */
+};
+
+
+/* some convenient short cuts when using cd command*/
+const char *cdShortCuts[] = {
+ "<<",
+ ">>",
+ "<-",
+ "->",
+ NULL /* indicate end of list */
+};
+
+/* what to replace shortcuts with */
+const char *cdAlternative[] = {
+ "preceding-sibling::node()",
+ "following-sibling::node()",
+ "ancestor::node()",
+ "descendant::node()",
+ NULL /* indicate end of list */
+};
+
+/* what enum to use for shortcuts */
+enum ShortcutsEnum {
+ DEBUG_PREV_SIBLING = 200,
+ DEBUG_NEXT_SIBLING,
+ DEBUG_ANCESTOR_NODE,
+ DEBUG_DESCENDANT_NODE
+};
+
+
+
+#include <libxml/xpathInternals.h>
+
+#include <libxslt/extra.h>
+#include <string.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+
+#include <libxml/xmlmemory.h>
+#include <libxml/tree.h>
+#include <libxml/parser.h>
+#include <libxml/valid.h>
+#include <libxml/debugXML.h>
+#include <libxml/HTMLtree.h>
+#include <libxml/HTMLparser.h>
+
+
+/* -----------------------------------------
+ Private function declarations for debugXSL.c
+ -------------------------------------------*/
+
+
+/* xslDbgCd :
+ * Change directories
+ * @styleCtxt : current stylesheet context
+ * @ctxt : current shell context
+ * @arg : path to change to
+ * @source : is valid
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int xslDbgCd(xsltTransformContextPtr styleCtxt, xmlShellCtxtPtr ctxt,
+ xmlChar * arg, xmlNodePtr source);
+
+
+/**
+ * xslDbgPrintCallStack:
+ * @arg : the number of frame to print, NULL if all items
+ *
+ * Print all items found on the callStack
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int xslDbgPrintCallStack(const xmlChar * arg);
+
+
+/**
+ * xslDbgSleep:
+ * @delay : the number of microseconds to delay exection by
+ *
+ * Delay execution by a specified number of microseconds. On some system
+ * this will not be at all accurate.
+ */
+void xslDbgSleep(long delay);
+
+
+/**
+ * xslDbgWalkContinue:
+ *
+ * Delay execution for time as indicated by OPTION_WALK_SPEED
+ * Can only be called from within shellPrompt!
+ * OPTION_WALK_SPEED != WALKSPEED_STOP
+ *
+ * Returns 1 if walk is to continue,
+ * 0 otherwise
+ */
+int xslDbgWalkContinue(void);
+
+
+
+/**
+ * addBreakPointNode:
+ * @payload : valid breakPointPtr
+ * @data : not used
+ * @name : not used
+ *
+ * Convert payload into format needed, and add to search dataBase
+ */
+void
+ addBreakPointNode(void *payload, void *data,
+ xmlChar * name);
+
+
+/**
+ * addSourceNode:
+ * @payload : valid xsltStylesheetPtr
+ * @data : not used
+ * @name : not used
+ *
+ * Convert payload into format needed, and add to search dataBase
+ */
+void
+ addSourceNode(void *payload, void *data,
+ xmlChar * name);
+
+
+/**
+ * addTemplateNode:
+ * @payload : valid xsltTemplatePtr
+ * @data : not used
+ * @name : not used
+ *
+ * Convert payload into format needed, and add to search dataBase
+ */
+void
+ addTemplateNode(void *payload, void *data,
+ xmlChar * name);
+
+/**
+ * addGlobalNode:
+ * @payload : valid xmlNodePtr of global variable
+ * @data : not used
+ * @name : not used
+ *
+ * Convert payload into format needed, and add to search dataBase
+ */
+void
+ addGlobalNode(void *payload, void *data,
+ xmlChar * name);
+
+/**
+ * addLocalNode:
+ * @payload : valid xmlNodePtr of local variable
+ * @data : not used
+ * @name : not used
+ *
+ * Convert payload into format needed, and add to search dataBase
+ */
+void
+ addLocalNode(void *payload, void *data,
+ xmlChar * name);
+
+
+/**
+ * addIncludeNode:
+ * @payload : valid xmlNodePtr of include instuction
+ * @data : not used
+ * @name : not used
+ *
+ * Convert payload into format needed, and add to search dataBase
+ */
+void
+ addIncludeNode(void *payload, void *data,
+ xmlChar * name);
+
+
+
+/**
+ * addCallStackItems:
+ *
+ * Convert call stack items into format needed, and add to search dataBase
+ */
+void
+ addCallStackItems(void);
+
+
+/**
+ * shellPrompt:
+ * @source: The current stylesheet instruction being executed
+ * @doc: The current document node being processed
+ * @filename: Not used
+ * @input: The function to call to when reading commands from stdio
+ * @output: Where to put the results
+ * @styleCtxt: Is valid
+ *
+ * Present to the user the xsldbg shell
+ */
+void shellPrompt(xmlNodePtr source, xmlNodePtr doc,
+ xmlChar * filename,
+ xmlShellReadlineFunc input,
+ FILE * output, xsltTransformContextPtr styleCtxt);
+
+/* -------------------------------------
+ End private functions
+---------------------------------------*/
+
+
+
+/**
+ * debugXSLGetTemplate:
+ *
+ * Return the last template node found, if an
+ *
+ * Returns The last template node found, if any
+ */
+xsltTemplatePtr
+debugXSLGetTemplate(void)
+{
+ return rootCopy;
+}
+
+
+/****************************************************************
+ * *
+ * The XSL shell related functions *
+ * *
+ ****************************************************************/
+
+
+/* xslDbgCd :
+ * Change directories
+ * @styleCtxt : current stylesheet context
+ * @ctxt : current shell context
+ * @arg : path to change to and in UTF-8
+ * @source : is valid
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+xslDbgCd(xsltTransformContextPtr styleCtxt, xmlShellCtxtPtr ctxt,
+ xmlChar * arg, xmlNodePtr source)
+{
+ xmlXPathObjectPtr list = NULL;
+ int result = 0;
+ int offset = 2; /* in some cases I'm only interested after first two chars */
+
+ if (!ctxt) {
+ xsldbgGenericErrorFunc(i18n("Error: Debugger has no files loaded. Try reloading files.\n"));
+ return result;
+ }
+
+ if (arg == NULL)
+ arg = (xmlChar *) "";
+ if (arg[0] == 0) {
+ ctxt->node = (xmlNodePtr) ctxt->doc;
+ } else {
+ if ((arg[0] == '-') && (xmlStrLen(arg) > 2)) {
+ if (styleCtxt) {
+ if (arg[1] == 't') {
+ xmlNodePtr templateNode;
+
+ /* quickly find a template */
+ /* skip any white spaces */
+ while (_IS_BLANK(arg[offset]))
+ offset++;
+
+ templateNode =
+ findTemplateNode(styleCtxt->style, &arg[offset]);
+ if (!templateNode) {
+ xsldbgGenericErrorFunc(i18n("Error: The XSLT template named \"%1\" was not found.\n").arg(xsldbgText(&arg[offset])));
+ return result;
+ } else {
+ xsldbgGenericErrorFunc(i18n(" template: \"%1\"\n").arg(xsldbgText(&arg[offset])));
+ ctxt->node = templateNode;
+ result = 1;
+ return result;
+ }
+ } else if (arg[1] == 's') {
+ /*quickly switch to another stylesheet node */
+ xmlXPathContextPtr pctxt;
+
+ if (source) {
+ pctxt = xmlXPathNewContext(source->doc);
+ if (pctxt == NULL) {
+ xmlFree(ctxt);
+ /* xslDebugStatus = DEBUG_QUIT; */
+ return result;
+ }
+ if (!xmlXPathNsLookup(pctxt, (xmlChar *) "xsl"))
+ xmlXPathRegisterNs(pctxt, (xmlChar *) "xsl",
+ XSLT_NAMESPACE);
+ list =
+ xmlXPathEval((xmlChar *) & arg[offset], pctxt);
+ if (pctxt) {
+ xmlFree(pctxt);
+ }
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to cd. No stylesheet loaded.\n"));
+ }
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Unknown arguments to the command %1.\n").arg("cd"));
+ }
+ } else
+ xsldbgGenericErrorFunc(i18n("Error: Unable to cd. No stylesheet loaded.\n"));
+ } else {
+ xmlNodePtr savenode;
+
+ if (styleCtxt) {
+ savenode = styleCtxt->xpathCtxt->node;
+ ctxt->pctxt->node = ctxt->node;
+ styleCtxt->xpathCtxt->node = ctxt->node;
+ if (!xmlXPathNsLookup(ctxt->pctxt, (xmlChar *) "xsl"))
+ xmlXPathRegisterNs(ctxt->pctxt, (xmlChar *) "xsl",
+ XSLT_NAMESPACE);
+ list = xmlXPathEval((xmlChar *) arg, styleCtxt->xpathCtxt);
+ styleCtxt->xpathCtxt->node = savenode;
+ } else if (ctxt->pctxt) {
+ if (!xmlXPathNsLookup(ctxt->pctxt, (xmlChar *) "xsl"))
+ xmlXPathRegisterNs(ctxt->pctxt, (xmlChar *) "xsl",
+ XSLT_NAMESPACE);
+ list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Invalid arguments to the command %1.\n").arg("cd"));
+ }
+ }
+
+ if (list != NULL) {
+ switch (list->type) {
+ case XPATH_NODESET:
+ if (list->nodesetval) {
+ if (list->nodesetval->nodeNr == 1) {
+ ctxt->node = list->nodesetval->nodeTab[0];
+ /* tell the application about the new line
+ * number we are looking at */
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
+ int breakpoint = 0;
+
+ xsldbgUpdateFileDetails(ctxt->node);
+ notifyXsldbgApp(XSLDBG_MSG_LINE_CHANGED,
+ &breakpoint);
+ }
+ result = 1;
+ } else
+ xsldbgGenericErrorFunc(i18n("Warning: XPath %1 is a Node Set with %n child.", "Warning: XPath %1 is a Node Set with %n children.", list->nodesetval->nodeNr).arg(xsldbgText(arg)) + QString("\n"));
+ } else {
+ xsldbgGenericErrorFunc(i18n("Warning: XPath %1 is an empty Node Set.\n").arg(xsldbgText(arg)));
+ }
+ break;
+
+ default:
+ xmlShellPrintXPathError(list->type, (char *) arg);
+ }
+ xmlXPathFreeObject(list);
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: XPath %1 was not found.\n").arg(xsldbgText(arg)));
+ }
+ if (ctxt->pctxt)
+ ctxt->pctxt->node = NULL;
+ }
+ return result;
+}
+
+
+/**
+ * xslDbgPrintCallStack:
+ * @arg : the number of frame to print, NULL if all items
+ *
+ * Print all items found on the callStack
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+xslDbgPrintCallStack(const xmlChar * arg)
+{
+ int depth = 0;
+ int result = 1;
+ callPointPtr callPointItem;
+
+ if (arg == NULL) {
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
+ notifyListStart(XSLDBG_MSG_CALLSTACK_CHANGED);
+ /* we send the oldest frame stack first */
+ for (depth = 1; depth <= callStackGetDepth(); depth++) {
+ callPointItem = callStackGet(depth);
+ if (callPointItem && callPointItem->info) {
+ notifyListQueue(callPointItem);
+ }
+ }
+ notifyListSend();
+ } else {
+ xmlChar *nameTemp, *modeTemp;
+ for (depth = callStackGetDepth(); depth >= 1; depth--) {
+ callPointItem = callStackGet(depth);
+ nameTemp = NULL;
+ modeTemp = NULL;
+ if (callPointItem && callPointItem->info) {
+ if (depth == callStackGetDepth()) {
+ xmlChar *curUrl = xsldbgUrl();
+ long curLine = xsldbgLineNo();
+ /* if possible list the current location */
+ if (rootCopy && (rootCopy->match || rootCopy->name)
+ && curUrl) {
+ xmlChar *rootNameTemp, *rootModeTemp;
+ rootNameTemp = fullQName(rootCopy->nameURI, rootCopy->name);
+ rootModeTemp = fullQName(rootCopy->modeURI, rootCopy->mode);
+ if (rootNameTemp && rootModeTemp){
+ if (rootCopy->match)
+ /* display information about the current XSLT template */
+ xsldbgGenericErrorFunc(i18n("#%1 template: \"%2\" mode: \"%3\"").arg(depth).arg(xsldbgText(rootCopy->match)).arg(xsldbgText(rootModeTemp)));
+ else
+ /* display information about the current XSLT template */
+ xsldbgGenericErrorFunc(i18n("#%1 template: \"%2\" mode: \"%3\"").arg(depth).arg(xsldbgText(rootNameTemp)).arg(xsldbgText(rootModeTemp)));
+ /* display where we are in the source/document file */
+ xsldbgGenericErrorFunc(i18n(" in file \"%1\" at line %2\n").arg(xsldbgUrl(curUrl)).arg(curLine));
+ }else{
+ xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
+ result = 0;
+ }
+ if (rootNameTemp){
+ xmlFree(rootNameTemp);
+ rootNameTemp = NULL;
+ }
+ if (rootModeTemp){
+ xmlFree(rootModeTemp);
+ rootModeTemp = NULL;
+ }
+ } else if (curUrl) {
+ /* display information about the current XSLT template */
+ xsldbgGenericErrorFunc(i18n("#%1 template: \"LIBXSLT_DEFAULT\" mode: \"\"").arg(depth));
+ /* display where we are in the source/document file */
+ xsldbgGenericErrorFunc(i18n(" in file \"%1\" at line %2\n").arg(xsldbgUrl(curUrl)).arg(curLine));
+ }
+ if (curUrl)
+ xmlFree(curUrl);
+
+ }
+ nameTemp = fullQName(callPointItem->info->templateURI,
+ callPointItem->info->templateName);
+ modeTemp = fullQName(callPointItem->info->modeURI,
+ callPointItem->info->modeName);
+ if (nameTemp && modeTemp){
+ /* display information about the current XSLT template */
+ xsldbgGenericErrorFunc(i18n("#%1 template: \"%2\" mode: \"%3\"").arg(depth - 1).arg(xsldbgText(nameTemp)).arg(xsldbgText(modeTemp)));
+ if (callPointItem->info->url)
+ /* display where we are in the source/document file */
+ xsldbgGenericErrorFunc(i18n(" in file \"%1\" at line %2\n").arg(xsldbgUrl(callPointItem->info->url)).arg(callPointItem->lineNo));
+ else
+ xsldbgGenericErrorFunc("\n");
+ }else{
+ xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
+ result = 0;
+ }
+ if (nameTemp){
+ xmlFree(nameTemp);
+ nameTemp = NULL;
+ }
+ if(modeTemp){
+ xmlFree(modeTemp);
+ modeTemp = NULL;
+ }
+
+ } else {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Call stack item not found at depth %d : xslDbgPrintCallStack\n", depth);
+#endif
+ result = 0;
+ break;
+ }
+ }
+ if (callStackGetDepth() == 0)
+ xsldbgGenericErrorFunc(i18n("\tNo items in call stack.\n"));
+ else
+ xsldbgGenericErrorFunc("\n");
+ }
+ } else {
+ long templateDepth = atol((char *) arg);
+
+
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
+ /* should never happen but just in case, when running as a
+ * thread always provide NO params to the where command */
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Notification of a frame not supported\n");
+#endif
+ result = 0;
+ return result;
+ }
+
+ if (templateDepth >= 0) {
+ callPointItem = callStackGet(templateDepth + 1);
+ if (callPointItem && callPointItem->info) {
+ /* display information about the current XSLT template */
+ xsldbgGenericErrorFunc(i18n("#%1 template: \"%2\"").arg(templateDepth).arg(xsldbgText(callPointItem->info->templateName)));
+ /* should alays be present but .. */
+ if (callPointItem->info->url)
+ /* display where we are in the source/document file */
+ xsldbgGenericErrorFunc(i18n(" in file \"%1\" at line %2\n").arg(xsldbgUrl(callPointItem->info->url)).arg(callPointItem->lineNo));
+ else
+ xsldbgGenericErrorFunc("\n");
+ } else {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Call stack item not found at templateDepth %d : xslDbgPrintCallStack\n", depth);
+#endif
+ result = 0;
+ }
+ }
+ }
+ return result;
+}
+
+
+/**
+ * xslDbgSleep:
+ * @delay : the number of microseconds to delay exection by
+ *
+ * Delay execution by a specified number of microseconds. On some system
+ * this will not be at all accurate.
+ */
+void
+xslDbgSleep(long delay)
+{
+#ifdef HAVE_USLEEP
+ usleep(delay);
+#else
+#ifdef WIN32
+ Sleep(delay / 1000);
+#else
+ /* try to delay things by doing a lot of floating point
+ * multiplication
+ */
+ long loop1, loop2;
+ float f1 = 1.0000001, f2;
+
+ for (loop1 = 0; loop1 < 100000 * delay; loop1++)
+ for (loop2 = 0; loop2 < 100000; loop2++) {
+ f2 = f1 * f1;
+ }
+#endif
+#endif
+}
+
+
+/**
+ * xslDbgWalkContinue:
+ *
+ * Delay execution for time as indicated by OPTION_WALK_SPEED
+ * Can only be called from within shellPrompt!
+ * OPTION_WALK_SPEED != WALKSPEED_STOP
+ *
+ * Returns 1 if walk is to continue,
+ * 0 otherwise
+ */
+int
+xslDbgWalkContinue(void)
+{
+ int result = 0, speed = optionsGetIntOption(OPTIONS_WALK_SPEED);
+
+ /* We need to ensure that output is realy sent. Otherwise
+ * walking using xemacs under WIN32 will not work */
+ fflush(stderr);
+
+ switch (speed) {
+ case WALKSPEED_1:
+ case WALKSPEED_2:
+ case WALKSPEED_3:
+ case WALKSPEED_4:
+ case WALKSPEED_5:
+ case WALKSPEED_6:
+ case WALKSPEED_7:
+ case WALKSPEED_8:
+ case WALKSPEED_9:
+ /* see options.h for defintion of WALKDAY */
+ xslDbgSleep(speed * WALKDELAY);
+ result = 1;
+ break;
+
+ default: /* stop walking */
+ optionsSetIntOption(OPTIONS_WALK_SPEED, WALKSPEED_STOP);
+ xslDebugStatus = DEBUG_STOP;
+ break;
+ }
+
+ return result;
+}
+
+
+/**
+ * addBreakPointNode:
+ * @payload : valid breakPointPtr
+ * @data : not used
+ * @name : not used
+ *
+ * Convert payload into format needed, and add to search dataBase
+ */
+void
+addBreakPointNode(void *payload, void *data,
+ xmlChar * name)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(name);
+ xmlNodePtr node = searchBreakPointNode((breakPointPtr) payload);
+
+ searchAdd(node);
+}
+
+
+/**
+ * addSourceNode:
+ * @payload : valid xsltStylesheetPtr
+ * @data : not used
+ * @name : not used
+ *
+ * Convert payload into format needed, and add to search dataBase
+ */
+void
+addSourceNode(void *payload, void *data,
+ xmlChar * name)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(name);
+ xmlNodePtr node = searchSourceNode((xsltStylesheetPtr) payload);
+
+ searchAdd(node);
+}
+
+
+/**
+ * addTemplateNode:
+ * @payload : valid xsltTemplatePtr
+ * @data : not used
+ * @name : not used
+ *
+ * Convert payload into format needed, and add to search dataBase
+ */
+void
+addTemplateNode(void *payload, void *data,
+ xmlChar * name)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(name);
+ xmlNodePtr node =
+ searchTemplateNode(((xsltTemplatePtr) payload)->elem);
+ searchAdd(node);
+}
+
+
+/**
+ * addGlobalNode:
+ * @payload : valid xmlNodePtr of global variable
+ * @data : not used
+ * @name : not used
+ *
+ * Convert payload into format needed, and add to search dataBase
+ */
+void
+addGlobalNode(void *payload, void *data,
+ xmlChar * name)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(name);
+ xmlNodePtr node = searchGlobalNode((xmlNodePtr) payload);
+
+ searchAdd(node);
+}
+
+
+/**
+ * addLocalNode:
+ * @payload : valid xmlNodePtr of local variable
+ * @data : not used
+ * @name : not used
+ *
+ * Convert payload into format needed, and add to search dataBase
+ */
+void
+addLocalNode(void *payload, void *data,
+ xmlChar * name)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(name);
+ xmlNodePtr node = searchLocalNode((xmlNodePtr) payload);
+
+ searchAdd(node);
+}
+
+
+/**
+ * addIncludeNode:
+ * @payload : valid xmlNodePtr of include instuction
+ * @data : not used
+ * @name : not used
+ *
+ * Convert payload into format needed, and add to search dataBase
+ */
+void
+addIncludeNode(void *payload, void *data,
+ xmlChar * name)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(name);
+ xmlNodePtr node = searchIncludeNode((xmlNodePtr) payload);
+
+ searchAdd(node);
+}
+
+
+/**
+ * addCallStackItems:
+ *
+ * Convert call stack items into format needed, and add to search dataBase
+ */
+void
+addCallStackItems(void)
+{
+ callPointPtr item;
+ xmlNodePtr node;
+ int depth;
+
+ for (depth = callStackGetDepth(); depth > 0; depth--) {
+ item = callStackGet(depth);
+ if (item) {
+ node = searchCallStackNode(item);
+ if (node)
+ searchAdd(node);
+ }
+ }
+}
+
+
+/**
+ * updateSearchData:
+ * @styleCtxt: Not used
+ * @style: Is valid
+ * @data: Not used but MUST be NULL for the moment
+ * @variableTypes: What types of variables to look
+ *
+ * Update the searchDatabase
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+updateSearchData(xsltTransformContextPtr styleCtxt,
+ xsltStylesheetPtr style,
+ void *data, VariableTypeEnum variableTypes)
+{
+ Q_UNUSED(styleCtxt);
+ Q_UNUSED(variableTypes);
+ int result = 0;
+
+ if (!style) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Unable to update search database no stylesheet loaded\n");
+#endif
+ return result;
+ }
+ searchEmpty();
+ xsldbgGenericErrorFunc(i18n("Information: Updating search database. This may take a while...\n"));
+ /* add items to the search dataBase */
+ addCallStackItems();
+ xsldbgGenericErrorFunc(i18n("Information: Looking for breakpoints.\n"));
+ walkBreakPoints((xmlHashScanner) addBreakPointNode, data);
+ xsldbgGenericErrorFunc(i18n("Information: Looking for imports and top-level stylesheets.\n"));
+ walkStylesheets((xmlHashScanner) addSourceNode, data, style);
+ xsldbgGenericErrorFunc(i18n("Information: Looking for xsl:includes.\n"));
+ walkIncludeInst((xmlHashScanner) addIncludeNode, data, style);
+ xsldbgGenericErrorFunc(i18n("Information: Looking for templates.\n"));
+ walkTemplates((xmlHashScanner) addTemplateNode, data, style);
+ xsldbgGenericErrorFunc(i18n("Information: Looking for global variables.\n"));
+ walkGlobals((xmlHashScanner) addGlobalNode, data, style);
+ xsldbgGenericErrorFunc(i18n("Information: Looking for local variables.\n"));
+ walkLocals((xmlHashScanner) addLocalNode, data, style);
+ xsldbgGenericErrorFunc(i18n("Information: Formatting output.\n"));
+
+ result = searchSave(NULL);
+ return result;
+}
+
+
+/**
+ * debugXSLBreak:
+ * @templ: The source node being executed
+ * @node: The data node being processed
+ * @root: The template being applied to "node"
+ * @ctxt: The transform context for stylesheet being processed
+ *
+ * A break point has been found so pass control to user
+ */
+void
+debugXSLBreak(xmlNodePtr templ, xmlNodePtr node, xsltTemplatePtr root,
+ xsltTransformContextPtr ctxt)
+{
+ xmlDocPtr tempDoc = NULL;
+ xmlNodePtr tempNode = NULL;
+ rootCopy = root;
+ static const xmlChar *lastTemplate = NULL;
+ xmlBufferPtr buffer = xmlBufferCreate();
+ static char mybuff[6] = " 0\n\x0";
+
+ if (ctxt && templ && root && !xsldbgReachedFirstTemplate)
+ xsldbgReachedFirstTemplate = true;
+
+ if (templ == NULL) {
+ tempDoc = xmlNewDoc((xmlChar *) "1.0");
+ if (!tempDoc)
+ return;
+ tempNode = xmlNewNode(NULL, (xmlChar *) "xsldbg_default_node");
+ if (!tempNode) {
+ xmlFreeDoc(tempDoc);
+ return;
+ }
+ xmlAddChild((xmlNodePtr) tempDoc, tempNode);
+ templ = tempNode;
+ }
+
+ if (node == NULL)
+ node = (xmlNodePtr) filesGetMainDoc();
+
+ if (node == NULL) {
+ tempDoc = xmlNewDoc((xmlChar *) "1.0");
+ if (!tempDoc)
+ return;
+ tempNode = xmlNewNode(NULL, (xmlChar *) "xsldbg_default_node");
+ if (!tempNode) {
+ xmlFreeDoc(tempDoc);
+ return;
+ }
+ xmlAddChild((xmlNodePtr) tempDoc, tempNode);
+ node = tempNode;
+ }
+ if (root) {
+ xmlChar *nameTemp = NULL, *modeTemp = NULL;
+ nameTemp = fullQName(root->nameURI, root->name);
+ modeTemp = fullQName(root->modeURI, root->mode);
+ if (!nextCommandActive){
+ /* we only want messages if we are not
+ in the process of completing the next command */
+ if (terminalIO == NULL) {
+
+ if (root->match){
+ xsldbgGenericErrorFunc(i18n("\nReached template: \"%1\" mode: \"%2\"\n").arg(xsldbgText(root->match)).arg(xsldbgText(modeTemp)));
+ if (lastTemplate != root->match && buffer){
+ xmlBufferCCat(buffer, "\nreached matched template:");
+ xmlBufferCat(buffer, root->match);
+ xmlBufferCCat(buffer, mybuff);
+ xsltCopyTextString(ctxt, ctxt->insert,xmlBufferContent(buffer),0);
+ mybuff[1]++;
+ lastTemplate = root->match;
+ }
+ }else{
+ xsldbgGenericErrorFunc(i18n("\nReached template: \"%1\" mode: \"%2\"\n").arg(xsldbgText(nameTemp)).arg(xsldbgText(modeTemp)));
+ if (lastTemplate != root->name && buffer){
+ xmlBufferCCat(buffer, "\nreached named template:");
+ xmlBufferCat(buffer,root->match);
+ xmlBufferCCat(buffer,mybuff);
+ xsltCopyTextString(ctxt, ctxt->insert,xmlBufferContent(buffer),0);
+ mybuff[1]++;
+ lastTemplate = root->name;
+ }
+
+ }
+ if (buffer)
+ xmlBufferFree(buffer);
+ } else {
+ if ((xslDebugStatus == DEBUG_TRACE) ||
+ (xslDebugStatus == DEBUG_WALK)) {
+ QString message;
+ if (root->match)
+ message = i18n("\nReached template: \"%1\" mode: \"%2\"\n").arg(xsldbgText(root->match)).arg(xsldbgText(modeTemp));
+ else
+ message = i18n("\nReached template: \"%1\" mode: \"%2\"\n").arg(xsldbgText(nameTemp)).arg(xsldbgText(modeTemp));
+ fprintf(terminalIO, "%s", message.local8Bit().data());
+ }
+ }
+ }
+ if (nameTemp)
+ xmlFree(nameTemp);
+ if (modeTemp)
+ xmlFree(modeTemp);
+ }
+
+ shellPrompt(templ, node, (xmlChar *) "index.xsl",
+ (xmlShellReadlineFunc) xslDbgShellReadline, stdout, ctxt);
+ if (tempDoc)
+ xmlFreeDoc(tempDoc);
+}
+
+
+/* Highly modified function based on xmlShell */
+
+/**
+ * shellPrompt:
+ * @source: The current stylesheet instruction being executed
+ * @doc: The current document node being processed
+ * @filename: Not used
+ * @input: The function to call to when reading commands from stdio
+ * @output: Where to put the results
+ * @styleCtxt: Is valid
+ *
+ * Present to the user the xsldbg shell
+ */
+void
+shellPrompt(xmlNodePtr source, xmlNodePtr doc, xmlChar * filename,
+ xmlShellReadlineFunc input, FILE * output,
+ xsltTransformContextPtr styleCtxt)
+{
+ xmlChar prompt[DEBUG_BUFFER_SIZE] = "/ > ";
+ xmlChar *cmdline = NULL, *cur;
+ int nbargs = 0;
+ int loadedFiles = 0;
+ int commandId = -1; /* stores what was the last
+ * command id entered by user */
+ xmlChar command[DEBUG_BUFFER_SIZE]; /* holds the command user entered */
+ xmlChar arg[DEBUG_BUFFER_SIZE]; /* holds any extra arguments to
+ * command entered */
+ xmlChar dir[DEBUG_BUFFER_SIZE]; /* temporary buffer used by where
+ * and pwd commands */
+ int cmdResult; /* result of last command */
+ int shortCutId = -1; /* used by cd command */
+ int i;
+ static int showSource = 1; /* Do we first show source or data ? */
+ xmlChar *baseUri = NULL; /* for used for included xml entities */
+ const xmlChar *breakUri;
+
+ /* for convenience keep track of which node was last
+ * selected of source and doc */
+ xmlNodePtr lastSourceNode, lastDocNode;
+
+
+ xmlShellCtxtPtr ctxt;
+ int exitShell = 0; /* Indicate when to exit xslShell */
+
+ if (source == NULL){
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Source NULL in shellPrompt\n");
+#endif
+ return;
+ }
+ if (doc == NULL){
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: doc NULL in shellPrompt\n");
+#endif
+ return;
+ }
+ if (filename == NULL){
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: fileName NULL in shellPrompt\n");
+#endif
+ return;
+ }
+ if (input == NULL){
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Input function NULL in shellPrompt\n");
+#endif
+ return;
+ }
+ if (output == NULL){
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Output NULL in shellPrompt\n");
+#endif
+ return;
+ }
+ ctxt = (xmlShellCtxtPtr) xmlMalloc(sizeof(xmlShellCtxt));
+ if (ctxt == NULL){
+ xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
+ return;
+ }
+
+ /* flag that we've received control */
+ debugGotControl(1);
+ ctxt->loaded = 0;
+ lastSourceNode = source;
+ lastDocNode = doc;
+ /* show the doc or source first? */
+ if (showSource) {
+ ctxt->doc = source->doc;
+ ctxt->node = source;
+ xsldbgUpdateFileDetails(source);
+ } else {
+ ctxt->doc = doc->doc;
+ ctxt->node = (xmlNodePtr) doc;
+ xsldbgUpdateFileDetails((xmlNodePtr) doc);
+ }
+
+ ctxt->input = input;
+ ctxt->output = output;
+ ctxt->filename = (char *) xmlStrdup((xmlChar *) filename);
+
+
+ if (xsldbgStop == 1){
+ xslDebugStatus = DEBUG_STOP;
+ optionsSetIntOption(OPTIONS_TRACE, TRACE_OFF);
+ optionsSetIntOption(OPTIONS_WALK_SPEED, WALKSPEED_STOP);
+ xsldbgStop = 0;
+ }
+
+ /* let any listener know that we got to a new line */
+ if (xslDebugStatus != DEBUG_TRACE) {
+ /* don't send notify message if we are tracing stylesheet */
+ int breakpoint = 1;
+
+ notifyXsldbgApp(XSLDBG_MSG_LINE_CHANGED, &breakpoint);
+ }
+
+
+ /* If using a thread and the thread is running then we don't need to
+ * send this as the application will see the XSLDBG_MSG_LINE_CHANGED message */
+ if ((getThreadStatus() == XSLDBG_MSG_THREAD_NOTUSED) ||
+ (xslDebugStatus == DEBUG_TRACE)) {
+ QString messageTxt;
+ if (!nextCommandActive && ctxt->node && ctxt->node && ctxt->node->doc
+ && ctxt->node->doc->URL) {
+ if (!showSource) {
+ baseUri = filesGetBaseUri(ctxt->node);
+ if (baseUri != NULL)
+ breakUri = baseUri;
+ else
+ breakUri = ctxt->node->doc->URL;
+ } else
+ breakUri = ctxt->node->doc->URL;
+
+ if (xmlGetLineNo(ctxt->node) != -1)
+ messageTxt = i18n("Breakpoint for file \"%1\" at line %2.\n").arg(xsldbgUrl(breakUri)).arg(xmlGetLineNo(ctxt->node));
+ else
+ messageTxt = i18n("Breakpoint at text node in file \"%1\".\n").arg(xsldbgUrl(breakUri));
+ if (baseUri != NULL) {
+ xmlFree(baseUri);
+ baseUri = NULL;
+ }
+
+ if (((xslDebugStatus == DEBUG_TRACE) ||
+ (xslDebugStatus == DEBUG_WALK)) && (terminalIO != NULL))
+ fprintf(terminalIO, "%s", messageTxt.utf8().data());
+ else
+ xsldbgGenericErrorFunc(messageTxt);
+
+ }
+ }
+ if ((showWatchesActive && (xslDebugStatus == DEBUG_TRACE)) ||
+ (xslDebugStatus == DEBUG_WALK)){
+ ctxt->pctxt = xmlXPathNewContext(ctxt->doc);
+ if (ctxt->pctxt) {
+ xslDbgShellShowWatches(styleCtxt, ctxt, 0);
+ xsldbgGenericErrorFunc("\n");
+ xmlXPathFreeContext(ctxt->pctxt);
+ ctxt->pctxt = NULL;
+ }
+ }
+
+ if (xslDebugStatus == DEBUG_TRACE) {
+ if (ctxt->filename)
+ xmlFree(ctxt->filename);
+ xmlFree(ctxt);
+ return; /* All done. Trace next instruction/node */
+ }
+ if (xslDebugStatus == DEBUG_WALK) {
+ if (xslDbgWalkContinue()) {
+ if (ctxt->filename)
+ xmlFree(ctxt->filename);
+ xmlFree(ctxt);
+ return; /* All done. Walk to next instruction/node */
+ }
+ }
+
+ ctxt->pctxt = xmlXPathNewContext(ctxt->doc);
+ if (ctxt->pctxt == NULL) {
+ xmlFree(ctxt);
+ xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
+ return;
+ }
+
+ if (showWatchesActive){
+ xslDbgShellShowWatches(styleCtxt, ctxt, 0);
+ xsldbgGenericErrorFunc("\n");
+ }
+
+ while (!exitShell && (xslDebugStatus != DEBUG_QUIT)) {
+ if (getThreadStatus() != XSLDBG_MSG_THREAD_RUN) {
+ if (ctxt->node == (xmlNodePtr) ctxt->doc)
+ snprintf((char *) prompt, DEBUG_BUFFER_SIZE - 1,
+ "(xsldbg) %s > ", "/");
+ else if ((ctxt->node->name) && (ctxt->node->ns))
+ snprintf((char *) prompt, DEBUG_BUFFER_SIZE - 1,
+ "(xsldbg) %s:%s > ", ctxt->node->ns->prefix,
+ ctxt->node->name);
+ else if (ctxt->node->name)
+ snprintf((char *) prompt, DEBUG_BUFFER_SIZE - 1,
+ "(xsldbg) %s > ", ctxt->node->name);
+
+ else
+ snprintf((char *) prompt, DEBUG_BUFFER_SIZE - 1,
+ "(xsldbg) ? > ");
+
+ prompt[sizeof(prompt) - 1] = 0;
+
+ /*
+ * Get a new command line
+ */
+ if (nextCommandActive && (xslDebugStatus == DEBUG_STEP))
+ /* we are processing the "next command" do the next
+ part of the command which is the up command */
+ cmdline = xmlStrdup((xmlChar*)"up");
+ else
+ cmdline = (xmlChar *) ctxt->input((char *) prompt);
+ if (cmdline && (optionsGetIntOption(OPTIONS_UTF8_INPUT) == 0)) {
+ /* we are getting encoded characters from the command line
+ * so decode them into UTF-8 */
+ xmlChar *tempResult = filesDecode(cmdline);
+
+ if (tempResult) {
+ xmlFree(cmdline);
+ cmdline = tempResult;
+ }
+ }
+ } else {
+ /* don't need a prompt for running as when running as a thread */
+ xmlStrCpy(messageBuffer, "");
+ if (nextCommandActive && (xslDebugStatus == DEBUG_STEP))
+ /* we are processing the "next command" do the next
+ part of the command which is the up command */
+ cmdline = xmlStrdup((xmlChar*)"up");
+ else
+ cmdline = (xmlChar *) ctxt->input((char *) messageBuffer);
+ }
+
+ if (cmdline == NULL)
+ break;
+
+ /* don't allow next command to be active more than at one breakpoint */
+ if (nextCommandActive)
+ nextCommandActive = 0;
+
+ notifyXsldbgApp(XSLDBG_MSG_PROCESSING_INPUT, NULL);
+
+ /* remove leading/trailing blanks */
+ trimString(cmdline);
+
+ /*
+ * Parse the command itself
+ */
+ cur = cmdline;
+ nbargs = 0;
+ while ((*cur == ' ') || (*cur == '\t'))
+ cur++;
+ i = 0;
+ while ((*cur != ' ') && (*cur != '\t') &&
+ (*cur != '\n') && (*cur != '\r')) {
+ if (*cur == 0)
+ break;
+ command[i++] = *cur++;
+ }
+ command[i] = 0;
+ if (i == 0)
+ continue;
+ nbargs++;
+
+ /*
+ * Parse the argument
+ */
+ while ((*cur == ' ') || (*cur == '\t'))
+ cur++;
+ i = 0;
+ while ((*cur != '\n') && (*cur != '\r') && (*cur != 0)) {
+ if (*cur == 0)
+ break;
+ arg[i++] = *cur++;
+ }
+ arg[i] = 0;
+ if (i != 0)
+ nbargs++;
+
+
+ commandId = lookupName(command, (xmlChar **) commandNames);
+ /* try command shorts if command is not found */
+ if (commandId < 0)
+ commandId =
+ lookupName(command, (xmlChar **) shortCommandNames);
+
+ cmdResult = -1; /* flag that it contains no result */
+ /*
+ * start interpreting the command
+ */
+ switch (commandId + DEBUG_HELP_CMD) {
+ /* --- Help related commands --- */
+ case DEBUG_HELP_CMD:
+ cmdResult = helpTop(arg);
+ if (!cmdResult)
+ xsldbgGenericErrorFunc(i18n("Unable to print local help. Online help can be found at http://xsldbg.sourceforge.net/docs/index.html.\n"));
+ break;
+
+
+ /* --- Running related commands --- */
+ case DEBUG_BYE_CMD:
+ case DEBUG_EXIT_CMD:
+ case DEBUG_QUIT_CMD:
+ /* allow the stylesheet to exit */
+ xslDebugStatus = DEBUG_QUIT;
+ exitShell++;
+ cmdResult = 1;
+ break;
+
+ case DEBUG_NEXT_CMD:
+ xslDebugStatus = DEBUG_STEP;
+ exitShell++;
+ cmdResult = 1;
+ /* Do the the next part of this command
+ which is the up command */
+ nextCommandActive = 1;
+ break;
+
+ case DEBUG_STEP_CMD:
+ xslDebugStatus = DEBUG_STEP;
+ exitShell++;
+ cmdResult = 1;
+ break;
+
+ case DEBUG_STEPUP_CMD:
+ {
+ xmlChar *noOfFrames = arg;
+
+ /* skip until next space character */
+ while (*noOfFrames && (*noOfFrames != ' ')) {
+ noOfFrames++;
+ }
+ cmdResult = xslDbgShellFrameBreak(noOfFrames, 1);
+ exitShell++;
+ }
+ break;
+
+ case DEBUG_STEPDOWN_CMD:
+ {
+ xmlChar *noOfFrames = arg;
+
+ /* skip until next space character */
+ while (*noOfFrames && (*noOfFrames != ' ')) {
+ noOfFrames++;
+ }
+ cmdResult = xslDbgShellFrameBreak(noOfFrames, 0);
+ exitShell++;
+ }
+ break;
+
+ /* continue to next break point */
+ case DEBUG_CONT_CMD:
+ xslDebugStatus = DEBUG_CONT;
+ exitShell++;
+ cmdResult = 1;
+ break;
+
+ /* restart */
+ case DEBUG_RUN_CMD:
+ xslDebugStatus = DEBUG_RUN_RESTART;
+ exitShell++;
+ cmdResult = 1;
+ break;
+
+
+ /* --- Template related commands --- */
+ case DEBUG_TEMPLATES_CMD:
+ {
+ int allFiles = 1, verbose = 1;
+
+ if (xmlStrLen(arg) && (xmlStrCmp(arg, "this") == 0)) {
+ allFiles = 0;
+ }
+
+ /* be verbose when printing template names */
+ /* if args is not empty then print names this stylesheet */
+ cmdResult =
+ xslDbgShellPrintTemplateNames(styleCtxt, ctxt, arg,
+ verbose, allFiles);
+ break;
+ }
+
+
+ case DEBUG_WHERE_CMD:
+ /* Print the current working directory as well */
+ xslDbgPrintCallStack(NULL);
+ if (getThreadStatus() != XSLDBG_MSG_THREAD_RUN) {
+ if (!xmlShellPwd(ctxt, (char *) dir, ctxt->node, NULL)){
+ xsldbgGenericErrorFunc((const char*)dir);
+ xsldbgGenericErrorFunc("\n");
+ }
+ }
+ cmdResult = 1;
+
+ break;
+
+ case DEBUG_FRAME_CMD:
+ cmdResult = xslDbgPrintCallStack(arg);
+ break;
+
+ case DEBUG_STYLESHEETS_CMD:
+ cmdResult = xslDbgShellPrintStyleSheets(arg);
+ break;
+
+ /* --- Break point related commands --- */
+ case DEBUG_BREAK_CMD:
+ if (xmlStrLen(arg)) {
+ if (styleCtxt)
+ cmdResult =
+ xslDbgShellBreak(arg, styleCtxt->style,
+ styleCtxt);
+ else
+ cmdResult = xslDbgShellBreak(arg, NULL, styleCtxt);
+ } else {
+ /* select current node to break at */
+ xmlChar buff[100];
+ xmlChar *tempBaseName = filesGetBaseUri(ctxt->node);
+ if (tempBaseName){
+ snprintf((char *) buff, sizeof(buff), "-l %s %ld",
+ tempBaseName,
+ xmlGetLineNo(ctxt->node));
+ xmlFree(tempBaseName);
+ }
+ if (styleCtxt)
+ cmdResult =
+ xslDbgShellBreak(buff, styleCtxt->style,
+ styleCtxt);
+ else
+ cmdResult =
+ xslDbgShellBreak(buff, NULL, styleCtxt);
+ }
+
+ break;
+
+ case DEBUG_SHOWBREAK_CMD:
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
+ notifyListStart(XSLDBG_MSG_BREAKPOINT_CHANGED);
+ walkBreakPoints((xmlHashScanner)
+ xslDbgShellPrintBreakPoint, NULL);
+ notifyListSend();
+ } else {
+ xsldbgGenericErrorFunc("\n");
+ printCount = 0; /* printCount will get updated by
+ * xslDbgShellPrintBreakPoint */
+
+ walkBreakPoints((xmlHashScanner)
+ xslDbgShellPrintBreakPoint, NULL);
+ if (printCount == 0)
+ xsldbgGenericErrorFunc(i18n("\nNo breakpoints are set for the file.\n"));
+ else
+ xsldbgGenericErrorFunc(i18n("\tTotal of %n breakpoint present.","\tTotal of %n breakpoints present.", printCount) + QString("\n"));
+ }
+ cmdResult = 1;
+ break;
+
+ case DEBUG_DELETE_CMD:
+ if (xmlStrLen(arg))
+ cmdResult = xslDbgShellDelete((xmlChar *) arg);
+ else {
+ breakPointPtr breakPtr = NULL;
+ xmlChar* tempBaseName = filesGetBaseUri(ctxt->node);
+
+ if (tempBaseName){
+ breakPtr =
+ breakPointGet(tempBaseName,
+ xmlGetLineNo(ctxt->node));
+ xmlFree(tempBaseName);
+ }
+ if (!breakPtr || !breakPointDelete(breakPtr)) {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to delete breakpoint.\n"));
+ cmdResult = 0;
+ }
+ }
+ break;
+
+ case DEBUG_ENABLE_CMD:
+ if (xmlStrLen(arg))
+ cmdResult =
+ xslDbgShellEnable(arg, XSL_TOGGLE_BREAKPOINT);
+ else {
+ breakPointPtr breakPtr = NULL;
+ xmlChar * tempBaseName = filesGetBaseUri(ctxt->node);
+
+ if (tempBaseName){
+ breakPtr =
+ breakPointGet(tempBaseName,
+ xmlGetLineNo(ctxt->node));
+ xmlFree(tempBaseName);
+ }
+ if (!breakPtr ||
+ (!breakPointEnable(breakPtr, !(breakPtr->flags & BREAKPOINT_ENABLED)))) {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to enable/disable breakpoint.\n"));
+ cmdResult = 0;
+ }
+ }
+ break;
+
+ case DEBUG_DISABLE_CMD:
+ if (xmlStrLen(arg))
+ cmdResult = xslDbgShellEnable(arg, 0);
+ else {
+ breakPointPtr breakPtr = NULL;
+ xmlChar *tempBaseName = filesGetBaseUri(ctxt->node);
+
+ if (tempBaseName){
+ breakPtr =
+ breakPointGet(tempBaseName,
+ xmlGetLineNo(ctxt->node));
+ xmlFree(tempBaseName);
+ }
+ if (!breakPtr || !breakPointEnable(breakPtr, 0)) {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to enable/disable breakpoint.\n"));
+ cmdResult = 0;
+ }
+ }
+ break;
+
+
+
+ /* --- Node view related commands --- */
+ case DEBUG_LS_CMD:
+ cmdResult = xslDbgShellPrintList(ctxt, arg, 0);
+ break;
+
+ case DEBUG_DIR_CMD:
+ cmdResult = xslDbgShellPrintList(ctxt, arg, 1);
+ break;
+
+ case DEBUG_DU_CMD:
+ xmlShellDu(ctxt, NULL, ctxt->node, NULL);
+ cmdResult = 1;
+ break;
+
+ case DEBUG_CAT_CMD:
+ case DEBUG_PRINT_CMD:
+ cmdResult = xslDbgShellCat(styleCtxt, ctxt, arg);
+ break;
+
+ case DEBUG_PWD_CMD:
+ if (!xmlShellPwd(ctxt, (char *) dir, ctxt->node, NULL)) {
+ xmlChar* tempBaseName = filesGetBaseUri(ctxt->node);
+ if(tempBaseName){
+ xsldbgGenericErrorFunc("\n");
+ xsldbgGenericErrorFunc((char*)dir);
+ xsldbgGenericErrorFunc(i18n(" in file \"%1\" at line %2").arg(xsldbgUrl(tempBaseName)).arg(xmlGetLineNo(ctxt->node)));
+ xmlFree(tempBaseName);
+ cmdResult = 1;
+ }
+ }
+ if (cmdResult)
+ xsldbgGenericErrorFunc("\n");
+ else
+ xsldbgGenericErrorFunc(i18n("Error: Unable to print working directory.\n"));
+ break;
+
+ case DEBUG_DUMP_CMD:
+ xmlDebugDumpDocument(stdout, ctxt->doc);
+ cmdResult = 1;
+ break;
+
+ case DEBUG_BASE_CMD:
+ xmlShellBase(ctxt, NULL, ctxt->node, NULL);
+ cmdResult = 1;
+ break;
+
+
+ /* --- Variable related commands --- */
+ case DEBUG_GLOBALS_CMD:
+ if (loadedFiles == 0)
+ cmdResult = xslDbgShellPrintVariable(styleCtxt, arg,
+ DEBUG_GLOBAL_VAR);
+ else {
+ xsldbgGenericErrorFunc(i18n("Error: Need to use the run command first.\n"));
+ cmdResult = 0;
+ }
+ break;
+
+ case DEBUG_LOCALS_CMD:
+ if (loadedFiles == 0)
+ /* if gdb compatability mode is enable print the globals then
+ * the locals */
+ if (optionsGetIntOption(OPTIONS_GDB) == 1) {
+ cmdResult =
+ xslDbgShellPrintVariable(styleCtxt, arg,
+ DEBUG_GLOBAL_VAR);
+ if (cmdResult == 1)
+ cmdResult =
+ xslDbgShellPrintVariable(styleCtxt, arg,
+ DEBUG_LOCAL_VAR);
+ } else
+ cmdResult =
+ xslDbgShellPrintVariable(styleCtxt, arg,
+ DEBUG_LOCAL_VAR);
+ else {
+ xsldbgGenericErrorFunc(i18n("Error: Need to use the run command first.\n"));
+ cmdResult = 0;
+ }
+ break;
+
+
+ /* It's difficult to put the following commands into
+ * a separe file so they stay here! */
+ /* --- Node selection related commands --- */
+ case DEBUG_SOURCE_CMD:
+ cmdResult = 1; /* only one case where this will command fail */
+ xsldbgValidateBreakpoints = BREAKPOINTS_NEED_VALIDATION;
+ if (xmlStrLen(arg) == 0) {
+ if (ctxt->doc == doc->doc)
+ lastDocNode = ctxt->node;
+ ctxt->doc = source->doc;
+ ctxt->node = lastSourceNode;
+ if (ctxt->pctxt)
+ xmlXPathFreeContext(ctxt->pctxt);
+ ctxt->pctxt = xmlXPathNewContext(ctxt->doc);
+ showSource = 1;
+ xsldbgUpdateFileDetails((xmlNodePtr) ctxt->node);
+ /* let any listener know that we got to a new line */
+ notifyXsldbgApp(XSLDBG_MSG_LINE_CHANGED, NULL);
+ if (ctxt->pctxt == NULL) {
+ xmlFree(ctxt);
+ xslDebugStatus = DEBUG_QUIT;
+ return;
+ } else
+ break;
+ } else {
+ /* load new stylesheet file, actual loading happens later */
+ xmlChar *expandedName = filesExpandName(arg);
+
+ if (expandedName) {
+ xsldbgGenericErrorFunc(i18n("Load of source deferred. Use the run command.\n"));
+
+ optionsSetStringOption(OPTIONS_SOURCE_FILE_NAME,
+ expandedName);
+ notifyXsldbgApp(XSLDBG_MSG_FILE_CHANGED, 0L);
+ loadedFiles = 1;
+ xmlFree(expandedName);
+ cmdResult = 1;
+ } else {
+ cmdResult = 0;
+ }
+ }
+ break;
+
+ case DEBUG_DATA_CMD:
+ cmdResult = 1; /* only one case where this will command fail */
+ xsldbgValidateBreakpoints = BREAKPOINTS_NEED_VALIDATION;
+ if (xmlStrLen(arg) == 0) {
+ if (ctxt->doc == source->doc)
+ lastSourceNode = ctxt->node;
+ ctxt->doc = doc->doc;
+ ctxt->node = lastDocNode;
+ if (ctxt->pctxt)
+ xmlXPathFreeContext(ctxt->pctxt);
+ ctxt->pctxt = xmlXPathNewContext(ctxt->doc);
+ showSource = 0;
+ xsldbgUpdateFileDetails((xmlNodePtr) ctxt->node);
+ /* let any listener know that we got to a new line */
+ notifyXsldbgApp(XSLDBG_MSG_LINE_CHANGED, NULL);
+ if (ctxt->pctxt == NULL) {
+ xmlFree(ctxt);
+ xslDebugStatus = DEBUG_QUIT;
+ return;
+ } else
+ break;
+ } else {
+ /* load new xml file actual loading hapens later */
+ xmlChar *expandedName = filesExpandName(arg);
+
+ if (expandedName) {
+ xsldbgGenericErrorFunc(i18n("Load of data file deferred. Use the run command.\n"));
+
+ optionsSetStringOption(OPTIONS_DATA_FILE_NAME,
+ expandedName);
+ notifyXsldbgApp(XSLDBG_MSG_FILE_CHANGED, 0L);
+ loadedFiles = 1;
+ xmlFree(expandedName);
+ cmdResult = 1;
+ } else {
+ cmdResult = 0;
+ }
+ }
+ break;
+
+ case DEBUG_OUTPUT_CMD:
+ /* set the output file name to use */
+ cmdResult = xslDbgShellOutput(arg);
+ break;
+
+ case DEBUG_CD_CMD:
+ /* use dir as a working buffer */
+ xmlStrnCpy(dir, arg, 2);
+ dir[2] = '\0';
+ shortCutId = lookupName(dir, (xmlChar **) cdShortCuts);
+ if (shortCutId >= 0) {
+ if (xmlStrLen(arg) == 2) {
+ cmdResult = xslDbgCd(styleCtxt, ctxt, (xmlChar *)
+ cdAlternative[shortCutId],
+ source);
+ } else {
+
+ xmlStrCpy(dir, cdAlternative[shortCutId]);
+ xmlStrCat(dir, &arg[2]);
+ cmdResult = xslDbgCd(styleCtxt, ctxt, dir, source);
+ }
+
+ } else
+ cmdResult = xslDbgCd(styleCtxt, ctxt, arg, source);
+ break;
+
+
+ /* --- File related commands --- */
+ case DEBUG_ENTITIES_CMD:
+ cmdResult = xslDbgEntities();
+ break;
+
+ case DEBUG_SYSTEM_CMD:
+ /* strip off a single argument. I need to do it this
+ way because I've already public this API */
+ {
+ xmlChar *systemID;
+ if (splitString(arg, 1, &systemID) == 1){
+ cmdResult = xslDbgSystem(systemID);
+ }else{
+ xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for the command %1.\n").arg("system"));
+ }
+ }
+ break;
+
+ case DEBUG_PUBLIC_CMD:
+ /* strip off a single argument. I need to do it this
+ way because I've already public this API */
+ {
+ xmlChar *publicID;
+ if (splitString(arg, 1, &publicID) == 1){
+ cmdResult = xslDbgPublic(publicID);
+ }else{
+ xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for the command %1.\n").arg("public"));
+ }
+ }
+ break;
+
+ case DEBUG_ENCODING_CMD:
+ cmdResult = xslDbgEncoding(arg);
+ break;
+
+ case DEBUG_VALIDATE_CMD:
+ xsldbgGenericErrorFunc(i18n("Warning: The %1 command is disabled.\n").arg("validate"));
+ cmdResult = 0;
+ /*
+ * xmlShellValidate(ctxt, arg, NULL, NULL);
+ */
+ break;
+
+ case DEBUG_LOAD_CMD:
+ cmdResult = optionsLoad();
+ /* restart xsldbg and activate new configuration */
+ if (cmdResult == 1) {
+ xslDebugStatus = DEBUG_RUN_RESTART;
+ exitShell++;
+ }
+ break;
+
+ case DEBUG_SAVE_CMD:
+ cmdResult = optionsSave();
+ break;
+
+ case DEBUG_WRITE_CMD:
+ xsldbgGenericErrorFunc(i18n("Warning: The %1 command is disabled.\n").arg("write"));
+ cmdResult = 0;
+ /*
+ * xmlShellWrite(ctxt, arg, NULL, NULL);
+ */
+ break;
+
+ case DEBUG_FREE_CMD:
+ xsldbgGenericErrorFunc(i18n("Warning: The %1 command is disabled.\n").arg("free"));
+ cmdResult = 0;
+ /*
+ * if (arg[0] == 0) {
+ * xmlMemShow(stdout, 0);
+ * } else {
+ * int len = 0;
+ * sscanf(arg, "%d", &len);
+ * xmlMemShow(stdout, len);
+ * }
+ */
+ break;
+
+
+ /* operating system related */
+ case DEBUG_CHDIR_CMD:
+ cmdResult = xslDbgShellChangeWd(arg);
+ break;
+
+ case DEBUG_SHELL_EXEC_CMD:
+ cmdResult = xslDbgShellExecute(arg, 1);
+ break;
+
+
+ /* libxslt parameter related commands */
+ case DEBUG_ADDPARAM_CMD:
+ cmdResult = xslDbgShellAddParam(arg);
+ break;
+
+ case DEBUG_DELPARAM_CMD:
+ cmdResult = xslDbgShellDelParam(arg);
+ break;
+
+ case DEBUG_SHOWPARAM_CMD:
+ cmdResult = xslDbgShellShowParam(arg);
+ break;
+
+
+
+ /* option related commmands */
+ case DEBUG_SETOPTION_CMD:
+ cmdResult = xslDbgShellSetOption(arg);
+ break;
+
+ case DEBUG_OPTIONS_CMD:
+ cmdResult = xslDbgShellOptions();
+ break;
+
+
+
+ /* misc commands */
+ case DEBUG_TTY_CMD:
+ if (openTerminal(arg)) {
+ /* gdb does to say anything after redirecting its
+ output */
+ if (optionsGetIntOption(OPTIONS_GDB) < 2)
+ xsldbgGenericErrorFunc(i18n("Opening terminal %1.\n").arg(xsldbgText(arg)));
+ cmdResult = 1;
+ } else
+ cmdResult = 0;
+ break;
+
+
+ /* language selection for messages */
+ case DEBUG_LANG_CMD:
+#ifdef LOCALE_PREFIX
+ if (xmlStrlen(arg) > 0){
+ setlocale(LC_MESSAGES, (char*)arg);
+ textdomain("kdewebdev/xsldsbg");
+ bindtextdomain("kdewebdev/xsldbg", LOCALE_PREFIX);
+ cmdResult = 1;
+ }else{
+ xsldbgGenericErrorFunc(i18n("Error: Missing arguments for the command %1.\n").arg("lang"));
+ cmdResult = 0;
+ }
+#else
+ xsldbgGenericErrorFunc(i18n("Warning: The %1 command is disabled\n").arg("lang"));
+ cmdResult = 1;
+#endif
+ break;
+
+ /* tracing related commands */
+ case DEBUG_TRACE_CMD:
+ if (xslDbgShellTrace(arg)) {
+ exitShell++;
+ cmdResult = 1;
+ } else
+ cmdResult = 0;
+
+ break;
+
+ case DEBUG_WALK_CMD:
+ if (xslDbgShellWalk(arg)) {
+ exitShell++;
+ cmdResult = 1;
+ } else
+ cmdResult = 0;
+ break;
+
+ case DEBUG_ADDWATCH_CMD:
+ cmdResult = xslDbgShellAddWatch(arg);
+ break;
+
+ case DEBUG_DELWATCH_CMD:
+ cmdResult = xslDbgShellDeleteWatch(arg);
+ break;
+
+ case DEBUG_SHOWWATCH_CMD:
+ trimString(arg);
+ switch (arg[0]){
+ case '\0':
+ cmdResult = xslDbgShellShowWatches(styleCtxt, ctxt, 1);
+ break;
+
+ case '0':
+ case '1':
+ showWatchesActive = arg[0] - '0';
+ cmdResult = 1;
+ break;
+
+ default:
+ xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for the command %1.\n").arg("showmatch"));
+ }
+ break;
+
+
+ /* search related commands */
+ case DEBUG_SEARCH_CMD:
+ cmdResult =
+ xslDbgShellSearch(styleCtxt, filesGetStylesheet(),
+ arg);
+ break;
+
+
+
+ case DEBUG_SET_CMD:
+ cmdResult = xslDbgShellSetVariable(styleCtxt, arg);
+ break;
+
+ default:
+ xsldbgGenericErrorFunc(i18n("Error: Unknown command %1. Try help.\n").arg(xsldbgText(command)));
+ cmdResult = 0;
+ }
+
+ /* KDbg likes to get the marker after every command so here it is */
+ if ((optionsGetIntOption(OPTIONS_GDB) >1) && optionsGetIntOption(OPTIONS_VERBOSE) && !nextCommandActive
+ && (commandId != DEBUG_STEPUP_CMD - DEBUG_HELP_CMD)) {
+ if (ctxt->node && ctxt->node &&
+ ctxt->node->doc && ctxt->node->doc->URL) {
+
+ if (xmlGetLineNo(ctxt->node) != -1)
+ xsldbgGenericErrorFunc(i18n("Breakpoint for file \"%1\" at line %2.\n").arg(xsldbgUrl(ctxt->node->doc->URL)).arg(xmlGetLineNo(ctxt->node)));
+ else
+ xsldbgGenericErrorFunc(i18n("Breakpoint at text node in file \"%1\".\n").arg(xsldbgUrl(ctxt->node->doc->URL)));
+ }
+ }
+
+ /* notify any listeners of that the command failed */
+ if (cmdResult == 0 && (xmlStrlen(messageBuffer) > 0)) {
+ snprintf((char *) messageBuffer, sizeof(messageBuffer),
+ "\nRequest to xsldbg failed:%s\n", cmdline);
+ notifyTextXsldbgApp(XSLDBG_MSG_TEXTOUT,
+ (char *) messageBuffer);
+ }
+
+ xmlFree(cmdline);
+ cmdline = NULL;
+ }
+
+ xmlXPathFreeContext(ctxt->pctxt);
+
+ if (ctxt->filename)
+ xmlFree(ctxt->filename);
+
+ xmlFree(ctxt);
+
+ if (cmdline)
+ xmlFree(cmdline);
+}
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/debugXSL.h b/kxsldbg/kxsldbgpart/libxsldbg/debugXSL.h
new file mode 100644
index 00000000..df50a53b
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/debugXSL.h
@@ -0,0 +1,1078 @@
+
+/**************************************************************************
+ debugXSL.h - describes the core xsldbg shell functions
+ -------------------
+ begin : Sun Sep 16 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. *
+ * *
+ **************************************************************************/
+
+/*
+ * Orinal file : debugXML.h : This is a set of routines used for
+ * debugging the tree produced by the XML parser.
+ *
+ * New file : debugXSL.h : Debug support version
+ *
+ * See Copyright for the status of this software.
+ *
+ * Daniel Veillard <daniel@veillard.com>
+ *
+ * Permission abtained to modify the LGPL'd code and extend to include
+ * break points, inspections of stylesheet source, xml data, stylesheet
+ * variables Keith Isdale <k_isdale@tpg.com.au>
+ */
+
+#ifndef __DEBUG_XSL__
+#define __DEBUG_XSL__
+
+#ifdef USE_XSLDBG_AS_THREAD
+#include "xsldbgmsg.h"
+#include "xsldbgthread.h"
+#endif
+
+/* We want skip most of these includes when building documentation*/
+#ifndef BUILD_DOCS
+#include "utils.h"
+#include "breakpoint.h"
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define DEBUG_BUFFER_SIZE 500 /*used by xslDbgShell */
+
+/* how may items have been printed */
+ extern int printCount;
+
+ /* used to indicated that xsldbg should stop tracing/walking
+ value : 1 stop tracing at start of next cycle
+ value : 0 normal operation
+ */
+
+ extern int xsldbgStop;
+ extern int xsldbgValidateBreakpoints;
+ /* Some versions of libxml/libxslt need a different type of
+ line numbers handling */
+ extern int xsldbgHasLineNumberFix;
+ extern bool xsldbgReachedFirstTemplate;
+
+/****************************************************************
+ * *
+ * The XSL shell related structures and functions *
+ * *
+ ****************************************************************/
+
+/*
+ Note that functions that have a prefix of xslDbgShell are NOT implemented
+ in debugXSL.c unless stated
+
+ All functions with the prefix of debygXSL are implemented in debugXSL.c
+
+ */
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * debugXSLBreak:
+ * @templ: The source node being executed
+ * @node: The data node being processed
+ * @root: The template being applied to "node"
+ * @ctxt: The transform context for stylesheet being processed
+ *
+ * A break point has been found so pass control to user
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * A break point has been found so pass control to user
+ *
+ * @param templ The source node being executed
+ * @param node The data node being processed
+ * @param root The template being applied to "node"
+ * @param ctxt transform context for stylesheet being processed
+ */
+#endif
+#endif
+ void debugXSLBreak(xmlNodePtr templ, xmlNodePtr node,
+ xsltTemplatePtr root, xsltTransformContextPtr ctxt);
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * debugXSLGetTemplate:
+ *
+ * Get the last template node found, if any
+ *
+ * Returns The last template node found, if any
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Get the last template node found, if any
+ *
+ * @returns the last template node found, if any
+ */
+#endif
+#endif
+ xsltTemplatePtr debugXSLGetTemplate(void);
+
+
+
+/* -----------------------------------------
+ Break Point related commands
+
+ They are implemented in breakpoint_cmds.c
+ ------------------------------------------- */
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellFrameBreak:
+ * @arg: Is valid number of frames to change location by
+ * @stepup: If != 1 then we step up, otherwise step down
+ *
+ * Set a "frame" break point either up or down from here
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Set a "frame" break point either up or down from here
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param arg Is valid and in UTF-8
+ * @param stepup If != 1 then we step up, otherwise step down
+ */
+#endif
+#endif
+ int xslDbgShellFrameBreak(xmlChar * arg, int stepup);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellBreak:
+ * @arg: Is valid and in UTF-8
+ * @style: Is valid
+ * @ctxt: Is valid
+ *
+ * Add break point specified by arg
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Add break point specified by arg
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param arg Is valid and in UTF-8
+ * @param style Is valid
+ * @param ctxt Is valid
+ */
+#endif
+#endif
+ int xslDbgShellBreak(xmlChar * arg, xsltStylesheetPtr style,
+ xsltTransformContextPtr ctxt);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellDelete:
+ * @arg: Is valid and in UTF-8
+ *
+ * Delete break point specified by arg
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Delete break point specified by arg
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param arg Is valid and in UTF-8
+ */
+#endif
+#endif
+ int xslDbgShellDelete(xmlChar * arg);
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellEnableBreakPoint:
+ * @payload: A valid xslBreakPointPtr
+ * @data: Enable type, a pointer to an integer
+ * for a value of
+ * 1 enable break point
+ * 0 disable break point
+ * -1 toggle enabling of break point
+ * @name: Not used
+ *
+ * Enable/disable break points via use of scan of break points
+*/
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Enable/disable break points via use of scan of break points
+ *
+ * @param payload Is valid xslBreakPointPtr
+ * @param data Enable type, a pointer to an integer
+ * for a value of
+ * @li 1 enable break point
+ * @li 0 disable break point
+ * @li -1 toggle enabling of break point
+ * @param name Not used
+*/
+#endif
+#endif
+ void xslDbgShellEnableBreakPoint(void *payload, void *data,
+ xmlChar * name);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellEnable:
+ * @arg : is valid enable "commmand text" and in UTF-8
+ * @enableType : enable break point if 1, disable if 0, toggle if -1
+ *
+ * Enable/disable break point specified by arg using enable
+ * type of @enableType
+ * Returns 1 if successful,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Enable/disable break point specified by arg using enable
+ *
+ * @param arg: is valid enable "commmand text" and in UTF-8
+ * @param enableType : enable break point if 1, disable if 0, toggle if -1
+ *
+ * @returns 1 if successful,
+ * 0 otherwise
+ */
+#endif
+#endif
+ int xslDbgShellEnable(xmlChar * arg, int enableType);
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellPrintBreakPoint:
+ * @payload: A valid xslBreakPointPtr
+ * @data: Not used
+ * @name: Not used
+ *
+ * Print data given by scan of break points
+*/
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Print data given by scan of break points
+ *
+ * @param payload Is valid xslBreakPointPtr
+ * @param data Not used
+ * @param name Not used
+*/
+#endif
+#endif
+ void xslDbgShellPrintBreakPoint(void *payload, void *data,
+ xmlChar * name);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellValidateBreakPoint:
+ * @payload: A valid xslBreakPointPtr
+ * @data: Not used
+ * @name: Not used
+ *
+ * Print an warning if a breakpoint is invalid
+*/
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Print an warning if a breakpoint is invalid
+ *
+ * @param payload Is valid xslBreakPointPtr
+ * @param data Not used
+ * @param name Not used
+*/
+#endif
+#endif
+ void xslDbgShellValidateBreakPoint(void *payload, void *data,
+ xmlChar * name);
+
+
+/* -----------------------------------------
+ Template related commands
+
+ They are implemented in template_cmds.c
+ ------------------------------------------- */
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellPrintStyleSheets:
+ * @arg: The stylesheets of interests and in UTF-8, is NULL for all stylesheets
+ *
+ * Print stylesheets that can be found in loaded stylsheet
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Print stylesheets that can be found in loaded stylsheet
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param arg The stylesheets of interests and in UTF-8, is NULL for all stylesheets
+ *
+ */
+#endif
+#endif
+ int xslDbgShellPrintStyleSheets(xmlChar * arg);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellPrintTemplateNames:
+ * @styleCtxt: Is valid
+ * @ctxt: Not used
+ * @arg: Not used
+ * @verbose: If 1 then print extra messages about templates found,
+ * otherwise print normal messages only
+ * @allFiles: If 1 then look for all templates in stylsheets found in
+ * @styleCtxt
+ * otherwise look in the stylesheet found by
+ * debugXSLBreak function
+ *
+ * Print out the list of template names found that match critieria
+*
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Print out the list of template names found that match critieria
+ *
+ * @param styleCtxt Is valid
+ * @param ctxt Not used
+ * @param arg Not used
+ * @param verbose If 1 then print extra messages about templates found,
+ * otherwise print normal messages only
+ * @param allFiles If 1 then look for all templates in stylsheets found in
+ * @p styleCtxt
+ * otherwise look in the stylesheet found by
+ * debugXSLBreak function
+ * @returns 1 on success,
+ * 0 otherwise
+ */
+#endif
+#endif
+ int xslDbgShellPrintTemplateNames(xsltTransformContextPtr styleCtxt,
+ xmlShellCtxtPtr ctxt,
+ xmlChar * arg, int verbose,
+ int allFiles);
+
+
+
+
+/* -----------------------------------------
+
+ Node viewing related commands
+
+ ------------------------------------------- */
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellPrintList:
+ * @ctxt: The current shell context
+ * @arg: What xpath to display and in UTF-8
+ * @dir: If 1 print in dir mode?,
+ * otherwise ls mode
+ *
+ * Print list of nodes in either ls or dir format
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Print list of nodes in either ls or dir format
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param ctxt The current shell context
+ * @param arg What xpath to display and in UTF-8
+ * @param dir If 1 print in dir mode,
+ * otherwise ls mode
+ */
+#endif
+#endif
+ int xslDbgShellPrintList(xmlShellCtxtPtr ctxt, xmlChar * arg, int dir);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellCat:
+ * @styleCtxt: the current stylesheet context
+ * @ctxt: The current shell context
+ * @arg: The xpath to print and in UTF-8
+ *
+ * Print the result of an xpath expression. This can include variables
+ * if styleCtxt is not NULL
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Print the result of an xpath expression. This can include variables
+ * if styleCtxt is not NULL
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param styleCtxt Current stylesheet context
+ * @param ctxt Current shell context
+ * @param arg The xpath to print and in UTF-8
+ */
+#endif
+#endif
+ int xslDbgShellCat(xsltTransformContextPtr styleCtxt,
+ xmlShellCtxtPtr ctxt, xmlChar * arg);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellPrintVariable:
+ * @styleCtxt: The current stylesheet context
+ * @arg: The name of variable to look for '$' prefix is optional and in UTF-8
+ * @type: A valid VariableTypeEnum
+ *
+ * Print the value variable specified by args.
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Print the value variable specified by args.
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+
+ *
+ * @param styleCtxt The current stylesheet context
+ * @param arg The name of variable to look for '$' prefix is optional and in UTF-8
+ * @param type Is valid VariableTypeEnum
+ */
+#endif
+#endif
+ int xslDbgShellPrintVariable(xsltTransformContextPtr styleCtxt,
+ xmlChar * arg, VariableTypeEnum type);
+
+
+/* -----------------------------------------
+
+ File related command
+
+ Implemented in file_cmds.c
+ ------------------------------------------- */
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellOutput:
+ * @arg : Is valid, either a local file name which will be expanded
+ * if needed, or a "file://" protocol URI
+ *
+ * Set the output file name to use
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * xslDbgShellOutput:
+ * @arg : Is valid, either a local file name which will be expanded
+ * if needed, or a "file://" protocol URI
+ *
+ * Set the output file name to use
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#endif
+#endif
+ int xslDbgShellOutput(const xmlChar *arg);
+
+
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * xslDbgEntities:
+ *
+ * Print list of entites found
+ *
+ * Returns 1 on sucess,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+#endif
+#endif
+ int xslDbgEntities(void);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * xslDbgSystem:
+ * @arg : Is valid in UTF-8
+ *
+ * Print what a system file @arg maps to via the current xml catalog
+ *
+ * Returns 1 on sucess,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Print what a system file @p arg maps to via the current xml catalog
+ *
+ * @param arg Is valid in UTF-8
+ *
+ * @returns 1 on sucess,
+ * 0 otherwise
+ */
+#endif
+#endif
+ int xslDbgSystem(const xmlChar * arg);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * xslDbgPublic:
+ * @arg : Is valid PublicID in UTF-8
+ *
+ * Print what a public ID @arg maps to via the current xml catalog
+ *
+ * Returns 1 on sucess,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Print what a public ID @p arg maps to via the current xml catalog
+ *
+ * @param arg Is valid PublicID in UTF-8
+ *
+ * @returns 1 on sucess,
+ * 0 otherwise
+ */
+#endif
+#endif
+ int xslDbgPublic(const xmlChar * arg);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * xslDbgEncoding:
+ * @arg: Is valid encoding supported by libxml2
+ *
+ * Set current encoding to use for output to standard output
+ *
+ * Returns 1 on sucess,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Set current encoding to use for output to standard output
+ *
+ * @param arg Is valid encoding supported by libxml2
+ *
+ *
+ * Returns 1 on sucess,
+ */
+#endif
+#endif
+ int xslDbgEncoding(xmlChar * arg);
+
+/* -----------------------------------------
+
+ Operating system related commands
+
+ Implemented in os_cmds.c
+ ------------------------------------------- */
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellChangeWd:
+ * @path: The path to change to and in UTF-8
+ *
+ * Change the current working directory of the operating system
+ *
+ * Returns 1 if able to change xsldbg's working directory to @path
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * @returns 1 if able to change xsldbg working direcorty to @p path
+ * 0 otherwise
+ *
+ * @param path Operating system path(directory) to change to and in UTF-8
+ */
+#endif
+#endif
+ int xslDbgShellChangeWd(xmlChar * path);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellExecute:
+ * @name: The name of command string to be executed by operating system shell
+ * @verbose: If 1 then print extra debugging messages,
+ * normal messages otherwise
+ *
+ * Execute an operating system command
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * @returns 1 if able to execute command @p name,
+ * 0 otherwise
+ *
+ * @param name The name of command string to be executed
+ * by operating system shell
+ * @param verbose If 1 then print extra debugging messages,
+ * normal messages otherwise
+ */
+#endif
+#endif
+ int xslDbgShellExecute(xmlChar * name, int verbose);
+
+
+
+
+/* -----------------------------------------
+
+ libxslt parameter related commands
+
+ Implemented in param_cmds.c
+ ------------------------------------------- */
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellAddParam:
+ * @arg: A string comprised of two words separated by
+ * one or more spaces which are in UTF-8.
+ *
+ * Add a libxslt parameter to be sent to libxslt later on
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+*/
+#else
+#ifdef USE_KDE_DOCS
+
+/*
+ * Add a parameter to be sent to libxslt later on
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param arg A string comprised of two words separated by
+ * one or more spaces which are in UTF-8
+ */
+#endif
+#endif
+ int xslDbgShellAddParam(xmlChar * arg);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellDelParam:
+ * @arg: A single white space trimmed parameter number to look for
+ *
+ * Delete a libxslt parameter that was to be sent to libxslt later on
+ *
+ * Returns 1 if able to delete parameter @name,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Delete a libxslt parameter that was to be sent to libxslt later on
+ *
+ * @returns 1 if able to delete parameter @p name,
+ * 0 otherwise
+ *
+ * @param arg A single white space trimmed libxslt parameter number to look for
+ */
+#endif
+#endif
+ int xslDbgShellDelParam(xmlChar * arg);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellShowParam:
+ * @arg: Not used
+ *
+ * Print list of current paramters
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Print list of current paramters
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param arg Not used
+ */
+#endif
+#endif
+ int xslDbgShellShowParam(xmlChar * arg);
+
+
+ /* -----------------------------------------
+ *
+ * Option related commands
+ *
+ * Implemented in option_cmds.c
+ *
+ * ------------------------------------------- */
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellSetOption:
+ * @arg: Is valid, and in the format <NAME> <VALUE>
+ *
+ * Set the value of an option
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Set the value of an option
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param arg is valid, and in format <NAME> <VALUE>
+ *
+ */
+#endif
+#endif
+ int xslDbgShellSetOption(xmlChar * arg);
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellOptions:
+ *
+ * Prints out values for user options
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Prints out values for user options
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ */
+#endif
+#endif
+ int xslDbgShellOptions(void);
+
+
+ /**
+ * xslDbgShellShowWatches:
+ * @styleCtxt: the current stylesheet context
+ * @ctxt: The current shell context
+ * @showWarnings : If 1 then showWarning messages,
+ * otherwise do not show warning messages
+ *
+ * Print the current watches and their values
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+ int xslDbgShellShowWatches(xsltTransformContextPtr styleCtxt,
+ xmlShellCtxtPtr ctx,int showWarnings);
+
+ /**
+ * xslDbgShellAddWatch:
+ * @arg : A valid xPath of expression to watch the value of
+ *
+ * Add expression to list of expressions to watch value of
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+ int xslDbgShellAddWatch(xmlChar* arg);
+
+ /**
+ * xslDbgShellDeleteWatch:
+ * @arg : A watch ID to remove
+ *
+ * Delete a given watch ID from our list of expressions to watch
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+ int xslDbgShellDeleteWatch(xmlChar* arg);
+
+
+ /* -----------------------------------------
+ *
+ * Tracing, walking related commands
+ *
+ * Implemented in shell.c
+ *
+ * ------------------------------------------- */
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellTrace:
+ * @arg: Not used
+ *
+ * Start the tracing of the stylesheet. First need to restart it.
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Start the tracing of the stylesheet. First need to restart it.
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param arg Not used
+ */
+#endif
+#endif
+ int xslDbgShellTrace(xmlChar * arg);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellWalk:
+ * @arg: An interger between 0 and 9 indicate the speed of walk
+ *
+ * Start walking through the stylesheet.
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Start walking through the stylesheet.
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param arg An interger between 0 and 9 indicate the speed of walk
+ */
+#endif
+#endif
+ int xslDbgShellWalk(xmlChar * arg);
+
+
+
+ /* -----------------------------------------
+ *
+ * Seach related commands
+ *
+ * Implemented in search_cmds.c
+ * ------------------------------------------- */
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellSearch:
+ * @styleCtxt: Is valid
+ * @style: Is valid
+ * @arg: The xpath query to use for searching dataBase
+ *
+ * Displays the result of performing a query on the search dataBase
+ *
+ * Returns 1 if able to run query with @arg,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * @returns 1 if able to run query with @p arg,
+ * 0 otherwise
+ *
+ * @param styleCtxt Is valid
+ * @param style Is valid
+ * @param arg The xpath query to use for searching dataBase
+ */
+#endif
+#endif
+ int xslDbgShellSearch(xsltTransformContextPtr styleCtxt,
+ xsltStylesheetPtr style, xmlChar * arg);
+
+
+/* -----------------------------------------
+
+ Seach related commands
+
+ Implemented in variable_cmds.c
+ ------------------------------------------- */
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xslDbgShellSetVariable:
+ * @styleCtxt : Is valid
+ * @arg : Is valid must be in the format of
+ * <VARIABLE_NAME> <XPATH>
+ *
+ * Change the value of a global or local variable
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Change the value of a global or local variable
+ *
+ * @param styleCtxt Is valid
+ * @param arg Is valid must be in the format of
+ * <VARIABLE_NAME> <XPATH>
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ */
+#endif
+#endif
+
+ int xslDbgShellSetVariable(xsltTransformContextPtr styleCtxt,
+ xmlChar * arg);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+ /* __DEBUG_XSL__ */
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/file_cmds.cpp b/kxsldbg/kxsldbgpart/libxsldbg/file_cmds.cpp
new file mode 100644
index 00000000..083b33b2
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/file_cmds.cpp
@@ -0,0 +1,274 @@
+
+/***************************************************************************
+ file_cmds.c - define file command related functions
+ -------------------
+ begin : Sat Jan 19 2002
+ copyright : (C) 2002 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 <stdio.h>
+#include <libxml/tree.h>
+#include <libxml/catalog.h>
+
+#include "xsldbg.h"
+#include "debugXSL.h"
+#include "files.h"
+#include "options.h"
+#include "utils.h"
+#include "xsldbgthread.h"
+
+static char buffer[500];
+
+/**
+ * xslDbgEntities:
+ *
+ * Print list of entites found
+ *
+ * Returns 1 on sucess,
+ * 0 otherwise
+ */
+int
+xslDbgEntities(void)
+{
+ int result = 0;
+
+ if (filesEntityList()) {
+ int entityIndex;
+ entityInfoPtr entInfo;
+
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
+ /* notify that we are starting new list of entity names */
+ notifyListStart(XSLDBG_MSG_ENTITIY_CHANGED);
+ for (entityIndex = 0;
+ entityIndex < arrayListCount(filesEntityList());
+ entityIndex++) {
+ entInfo = (entityInfoPtr) arrayListGet(filesEntityList(),
+ entityIndex);
+ if (entInfo)
+ notifyListQueue(entInfo);
+
+ }
+ notifyListSend();
+ result = 1;
+ } else {
+ for (entityIndex = 0;
+ entityIndex < arrayListCount(filesEntityList());
+ entityIndex++) {
+ entInfo = (entityInfoPtr) arrayListGet(filesEntityList(),
+ entityIndex);
+ if (entInfo) {
+ /* display identifier of an XML entity */
+ xsldbgGenericErrorFunc(i18n("Entity %1 ").arg(xsldbgText(entInfo->SystemID)));
+ if (entInfo->PublicID)
+ xsldbgGenericErrorFunc(xsldbgText(entInfo->PublicID));
+ xsldbgGenericErrorFunc("\n");
+ }
+ }
+ if (arrayListCount(filesEntityList()) == 0) {
+ xsldbgGenericErrorFunc(i18n("No external General Parsed entities present.\n"));
+ } else {
+ xsldbgGenericErrorFunc(i18n("\tTotal of %n entity found.", "\tTotal of %n entities found.", arrayListCount(filesEntityList())) + QString("\n"));
+ }
+
+ result = 1;
+ }
+ }
+ return result;
+}
+
+
+/**
+ * xslDbgSystem:
+ * @arg : Is valid
+ *
+ * Print what a system file @arg maps to via the current xml catalog
+ *
+ * Returns 1 on sucess,
+ * 0 otherwise
+ */
+int
+xslDbgSystem(const xmlChar * arg)
+{
+ int result = 0;
+ xmlChar *name;
+
+ if (!arg || (xmlStrlen(arg) == 0)) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: NULL argument provided\n");
+#endif
+ return result;
+ }
+
+ name = xmlCatalogResolveSystem(arg);
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
+ if (name) {
+ notifyXsldbgApp(XSLDBG_MSG_RESOLVE_CHANGE, name);
+ result = 1;
+ xmlFree(name);
+ } else {
+ notifyXsldbgApp(XSLDBG_MSG_RESOLVE_CHANGE, "");
+ xsldbgGenericErrorFunc(i18n("SystemID \"%1\" was not found in current catalog.\n").arg(xsldbgText(arg)));
+ }
+ } else {
+ if (name) {
+ xsldbgGenericErrorFunc(i18n("SystemID \"%1\" maps to: \"%2\"\n").arg(xsldbgText(arg)).arg(xsldbgText(name)));
+ xmlFree(name);
+ result = 1;
+ } else {
+ xsldbgGenericErrorFunc(i18n("SystemID \"%1\" was not found in current catalog.\n").arg(xsldbgText(arg)));
+ }
+ }
+
+ return result;
+}
+
+
+/**
+ * xslDbgPublic:
+ * @arg : Is valid
+ *
+ * Print what a public ID @arg maps to via the current xml catalog
+ *
+ * Returns 1 on sucess,
+ * 0 otherwise
+ */
+int
+xslDbgPublic(const xmlChar * arg)
+{
+ int result = 0;
+ xmlChar *name;
+
+ if (!arg || (xmlStrlen(arg) == 0)) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: NULL argument provided\n");
+#endif
+ return result;
+ }
+
+ name = xmlCatalogResolvePublic(arg);
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
+ if (name) {
+ notifyXsldbgApp(XSLDBG_MSG_RESOLVE_CHANGE, name);
+ result = 1;
+ xmlFree(name);
+ } else {
+ notifyXsldbgApp(XSLDBG_MSG_RESOLVE_CHANGE, "");
+ xsldbgGenericErrorFunc(i18n("PublicID \"%1\" was not found in current catalog.\n").arg(xsldbgText(arg)));
+ }
+ } else {
+ if (name) {
+ xsldbgGenericErrorFunc(i18n("PublicID \"%1\" maps to: \"%2\"\n").arg(xsldbgText(arg)).arg(xsldbgText(name)));
+ xmlFree(name);
+ result = 1;
+ } else {
+ xsldbgGenericErrorFunc(i18n("PublicID \"%1\" was not found in current catalog.\n").arg(xsldbgText(arg)));
+ }
+ xsltGenericError(xsltGenericErrorContext, "%s", buffer);
+ }
+ return result;
+}
+
+
+/**
+ * xslDbgEncoding:
+ * @arg: Is valid encoding supported by libxml2
+ *
+ * Set current encoding to use for output to standard output
+ *
+ * Returns 1 on sucess,
+ * 0 otherwise
+ */
+int
+xslDbgEncoding(xmlChar * arg)
+{
+ int result = 0;
+ xmlChar *opts[2];
+
+ if (!arg) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: NULL argument provided\n");
+#endif
+ return result;
+ }
+
+ if (splitString(arg, 1, opts) == 1) {
+ if (filesSetEncoding((char *) opts[0])) {
+ optionsSetStringOption(OPTIONS_ENCODING, opts[0]);
+ result = 1;
+ }
+ } else
+ xsldbgGenericErrorFunc(i18n("Error: Missing arguments for the command %1.\n").arg("encoding"));
+ return result;
+}
+
+
+/**
+ * xslDbgShellOutput:
+ * @arg : Is valid, either a local file name which will be expanded
+ * if needed, or a "file://" protocol URI
+ *
+ * Set the output file name to use
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int xslDbgShellOutput(const xmlChar *arg)
+{
+ int result = 0;
+ if (arg && (xmlStrLen(arg) > 0)){
+ if (!xmlStrnCmp(arg, "file:/", 6)){
+ /* convert URI to local file name */
+ xmlChar *outputFileName = filesURItoFileName(arg);
+ if (outputFileName){
+ optionsSetStringOption(OPTIONS_OUTPUT_FILE_NAME,
+ outputFileName);
+ notifyXsldbgApp(XSLDBG_MSG_FILE_CHANGED, 0L);
+ xmlFree(outputFileName);
+ result = 1;
+ }
+ } else if (xmlStrEqual(arg, (xmlChar*)"-")) {
+ optionsSetStringOption(OPTIONS_OUTPUT_FILE_NAME,
+ NULL);
+ notifyXsldbgApp(XSLDBG_MSG_FILE_CHANGED, 0L);
+ result = 1;
+ } else if (!xmlStrnCmp(arg, "ftp://", 6) || !xmlStrnCmp(arg, "http://", 7)){
+ xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for the command %1.\n").arg("output"));
+ return 0;
+ } else {
+ /* assume that we were provided a local file name
+ * that may need expanding
+ */
+ xmlChar *expandedName = filesExpandName(arg);
+
+ // The output file must not be the same as our SOURCE or DATA file
+ if (expandedName &&
+ (!xmlStrEqual(optionsGetStringOption(OPTIONS_SOURCE_FILE_NAME), expandedName)) &&
+ (!xmlStrEqual(optionsGetStringOption(OPTIONS_DATA_FILE_NAME), expandedName)) ){
+ optionsSetStringOption(OPTIONS_OUTPUT_FILE_NAME, expandedName);
+ notifyXsldbgApp(XSLDBG_MSG_FILE_CHANGED, 0L);
+ xmlFree(expandedName);
+ result = 1;
+ }else{
+ xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for the command %1.\n").arg("output"));
+ }
+ }
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Missing arguments for the command %1.\n").arg("output"));
+ }
+
+ return result;
+}
+
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/files.cpp b/kxsldbg/kxsldbgpart/libxsldbg/files.cpp
new file mode 100644
index 00000000..73d3713b
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/files.cpp
@@ -0,0 +1,1420 @@
+
+/***************************************************************************
+ files.h - define file related functions
+ -------------------
+ begin : Sat Nov 10 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. *
+ * *
+ ***************************************************************************/
+
+/* We want skip most of these includes when building documentation */
+#ifndef BUILD_DOCS
+
+#include "xsldbg.h"
+#include <stdio.h>
+#include <libxml/entities.h>
+#include <libxml/tree.h>
+#include <libxml/catalog.h>
+#include <libxml/parserInternals.h>
+#include <libxml/encoding.h> /* needed by filesTranslate, filesEncoding functions */
+#include <libxml/uri.h> /* needed for xmlURIUnescapeString */
+#include "debugXSL.h"
+#include "files.h"
+#include "utils.h"
+#include "options.h"
+#include "xsldbgthread.h"
+#ifdef WIN32
+#include <direct.h>
+#endif
+
+#endif /* BUILD_DOCS */
+
+
+/* top xml document */
+static xmlDocPtr topDocument;
+
+/* temporary xml document */
+static xmlDocPtr tempDocument;
+
+/* used as a scratch pad for temporary results*/
+static xmlChar filesBuffer[DEBUG_BUFFER_SIZE];
+
+/* top stylsheet */
+static xsltStylesheetPtr topStylesheet;
+
+/* what is the base path for top stylesheet */
+static xmlChar *stylePathName = NULL;
+
+/* what is the path for current working directory*/
+static xmlChar *workingDirPath = NULL;
+
+static arrayListPtr entityNameList = NULL;
+
+/* Current encoding to use for standard output*/
+static xmlCharEncodingHandlerPtr stdoutEncoding = NULL;
+
+/* input and output buffers for encoding*/
+static xmlBufferPtr encodeInBuff = NULL;
+static xmlBufferPtr encodeOutBuff = NULL;
+
+/* Current line number and URI for xsldbg*/
+static int currentLineNo = -1;
+static xmlChar *currentUrl = NULL;
+
+/* -----------------------------------------
+ Private function declarations for files.c
+ -------------------------------------------*/
+
+/**
+ * guessStylesheetHelper:
+ * @payload: valid xsltStylesheetPtr
+ * @data: valid searchInfoPtr of type SEARCH_NODE
+ * @name: not used
+ *
+ * Try to guess what the complete file/URI is. If successful the search
+ * info will be set to found and the search data will contain the
+ * file name found. We are given our payload via walkStylesheets
+ */
+static void guessStylesheetHelper(void *payload, void *data,
+ xmlChar * name);
+
+
+/**
+ * guessStylesheetHelper2:
+ * @payload: valid xmlNodePtr of the included stylesheet
+ * @data: valid searchInfoPtr of type SEARCH_NODE
+ * @name: not used
+ *
+ * Try to guess what the complete file/URI is. If successful the search
+ * info will be set to found and the search data will contain the
+ * file name found. We are given our payload via walkIncludes
+ */
+static void guessStylesheetHelper2(void *payload, void *data,
+ xmlChar * name);
+
+
+entityInfoPtr filesNewEntityInfo(const xmlChar * SystemID,
+ const xmlChar * PublicID);
+
+void filesFreeEntityInfo(entityInfoPtr info);
+
+void filesAddEntityName(const xmlChar * SystemID,
+ const xmlChar * PublicID);
+
+
+/* -------------------------------------
+ End private functions
+---------------------------------------*/
+
+
+FILE *terminalIO;
+
+/* No longer needed
+ static FILE *oldStdin, *oldStdout, *oldStderr;*/
+
+
+//static char *ttyName = NULL; /* what is the name of the default terminal */
+static char *termName = NULL; /* what is the name of terminal we are redirected to */
+
+
+/**
+ * redirectToTerminal:
+ * @device: terminal to redirect i/o to , will not work under win32
+ *
+ * Open communications to the terminal device @device
+ *
+ * Returns 1 if sucessful
+ * 0 otherwise
+ */
+int
+openTerminal(xmlChar * device)
+{
+ int result = 0;
+
+ if (!device) { /* Failed; there's no device */
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: NULL argument provided\n");
+#endif
+ return result;
+ }
+
+ /*
+ * On RISC OS, you get one terminal - the screen.
+ * we assume that the parameter is meant to be an output device as
+ * per normal - we can use vdu:, rawvdu: or :tt, or a filename for
+ * normal VDU output, VDU output without newline expansion,
+ * C terminal output with control code escaping, or a raw file
+ * respectively.
+ * The name passed is expected to be in native file format - no
+ * URI escaping here.
+ * One assumes that you might use a socket or a pipe here.
+ */
+
+ if (terminalIO) {
+ fclose(terminalIO);
+ terminalIO = NULL;
+ }
+
+
+ switch (device[0]) {
+ case '\0':
+ case '0':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ /* look like we are supposed to close the terminal
+ * but we've already done that
+ */
+ break;
+
+ case '1':
+ if (termName) {
+ terminalIO = fopen((char *) termName, "w");
+ if (terminalIO != NULL) {
+ xmlFree(termName);
+ termName = xmlMemStrdup((char *) device);
+ result = 1;
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to open terminal %1.\n").arg(xsldbgText(termName)));
+ }
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Did not previously open terminal.\n"));
+ }
+ break;
+
+ case '2':
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Warning: Terminal level 2 not implemented\n");
+#endif
+ break;
+
+
+ default:
+ terminalIO = fopen((char *) device, "w");
+ if (terminalIO != NULL) {
+ if (termName)
+ xmlFree(termName);
+ termName = xmlMemStrdup((char *) device);
+ result = 1;
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to open terminal %1.\n").arg(xsldbgText(device)));
+ }
+
+ }
+
+ return result;
+}
+
+
+/**
+ * guessStylesheetHelper:
+ * @payload: valid xsltStylesheetPtr
+ * @data: valid searchInfoPtr of type SEARCH_NODE
+ * @name: not used
+ *
+ * Try to guess what the complete file/URI is. If successful the search
+ * info will be set to found and the search data will contain the
+ * file name found. We are given our payload via walkStylesheets
+ */
+void
+guessStylesheetHelper(void *payload, void *data,
+ xmlChar * name)
+{
+ Q_UNUSED(name);
+ xsltStylesheetPtr style = (xsltStylesheetPtr) payload;
+ searchInfoPtr searchCriteria = (searchInfoPtr) data;
+ nodeSearchDataPtr searchData = NULL;
+ /* where did the directory/URI separator occur */
+ char *lastSlash;
+
+ if (!style || !style->doc || !searchCriteria || !searchCriteria->data
+ || (searchCriteria->type != SEARCH_NODE))
+ return;
+
+ searchData = (nodeSearchDataPtr) searchCriteria->data;
+ if (searchData->nameInput && (searchData->absoluteNameMatch == NULL)) {
+ /* at this point we know that we have not made an absolute match
+ * but we may have made a relative match */
+ if (xmlStrCmp(style->doc->URL, searchData->nameInput) == 0) {
+ /* absolute path match great! */
+ searchData->absoluteNameMatch =
+ (xmlChar *) xmlMemStrdup((char *) style->doc->URL);
+ searchData->node = (xmlNodePtr) style->doc;
+ searchCriteria->found = 1;
+ return;
+ }
+
+
+ /* try to guess we assume that the files are unique */
+ xmlStrCpy(filesBuffer, "__#!__");
+ /* try relative to top stylesheet directory */
+ if (stylePath()) {
+ xmlStrCpy(filesBuffer, stylePath());
+ xmlStrCat(filesBuffer, searchData->nameInput);
+ }
+ if (xmlStrCmp(style->doc->URL, filesBuffer) == 0) {
+ /* guessed right! */
+ searchData->guessedNameMatch =
+ (xmlChar *) xmlMemStrdup((char *) filesBuffer);
+ searchData->node = (xmlNodePtr) style->doc;
+ searchCriteria->found = 1;
+ return;
+ }
+
+ if (workingPath()) {
+ /* try relative to working directory */
+ xmlStrCpy(filesBuffer, workingPath());
+ xmlStrCat(filesBuffer, searchData->nameInput);
+ }
+ if (xmlStrCmp(style->doc->URL, filesBuffer) == 0) {
+ /* guessed right! */
+ searchData->guessedNameMatch =
+ (xmlChar *) xmlMemStrdup((char *) filesBuffer);
+ searchData->node = (xmlNodePtr) style->doc;
+ searchCriteria->found = 1;
+ return;
+ }
+
+
+ /* Find the last separator of the stylsheet's URL */
+ lastSlash = xmlStrChr(style->doc->URL, URISEPARATORCHAR);
+ if (!lastSlash)
+ lastSlash = xmlStrChr(style->doc->URL, PATHCHAR);
+
+ if (lastSlash) {
+ /* Last try, assume nameInput contains only a file name
+ * Strip of the file name at end of the stylesheet doc URL */
+ lastSlash++; /* skip the slash */
+ if (xmlStrCmp(lastSlash, searchData->nameInput) == 0) {
+ /* guessed right! */
+ searchData->guessedNameMatch =
+ (xmlChar *) xmlMemStrdup((char *) style->doc->URL);
+ searchData->node = (xmlNodePtr) style->doc;
+ searchCriteria->found = 1;
+ }
+ }
+ }
+}
+
+
+/**
+ * guessStylesheetHelper2:
+ * @payload: valid xmlNodePtr of the included stylesheet
+ * @data: valid searchInfoPtr of type SEARCH_NODE
+ * @name: not used
+ *
+ * Try to guess what the complete file/URI is. If successful the search
+ * info will be set to found and the search data will contain the
+ * file name found. We are given our payload via walkIncludes
+ */
+void
+guessStylesheetHelper2(void *payload, void *data,
+ xmlChar * name)
+{
+ Q_UNUSED(name);
+ xmlNodePtr node = (xmlNodePtr) payload;
+ searchInfoPtr searchCriteria = (searchInfoPtr) data;
+ nodeSearchDataPtr searchData = NULL;
+ /* where did the directory/URI separator occur */
+ char *lastSlash;
+
+ if (!node || !node->doc || !searchCriteria || !searchCriteria->data ||
+ (searchCriteria->type != SEARCH_NODE))
+ return;
+
+ searchData = (nodeSearchDataPtr) searchCriteria->data;
+ if (searchData->nameInput && (searchData->absoluteNameMatch == NULL)) {
+ /* at this point we know that we have not made an absolute match
+ * but we may have made a relative match */
+ if (xmlStrCmp(node->doc->URL, searchData->nameInput) == 0) {
+ /* absolute path match great! */
+ searchData->absoluteNameMatch =
+ (xmlChar *) xmlMemStrdup((char *) node->doc->URL);
+ searchData->node = node;
+ searchCriteria->found = 1;
+ return;
+ }
+
+
+ /* try to guess we assume that the files are unique */
+ xmlStrCpy(filesBuffer, "__#!__");
+ /* try relative to top stylesheet directory */
+ if (stylePath()) {
+ xmlStrCpy(filesBuffer, stylePath());
+ xmlStrCat(filesBuffer, searchData->nameInput);
+ }
+ if (xmlStrCmp(node->doc->URL, filesBuffer) == 0) {
+ /* guessed right! */
+ searchData->guessedNameMatch =
+ (xmlChar *) xmlMemStrdup((char *) filesBuffer);
+ searchData->node = node;
+ searchCriteria->found = 1;
+ return;
+ }
+
+ if (workingPath()) {
+ /* try relative to working directory */
+ xmlStrCpy(filesBuffer, workingPath());
+ xmlStrCat(filesBuffer, searchData->nameInput);
+ }
+ if (xmlStrCmp(node->doc->URL, filesBuffer) == 0) {
+ /* guessed right! */
+ searchData->guessedNameMatch =
+ (xmlChar *) xmlMemStrdup((char *) filesBuffer);
+ searchData->node = node;
+ searchCriteria->found = 1;
+ return;
+ }
+
+
+ /* Find the last separator of the stylsheet's URL */
+ lastSlash = xmlStrChr(node->doc->URL, URISEPARATORCHAR);
+ if (!lastSlash)
+ lastSlash = xmlStrChr(node->doc->URL, PATHCHAR);
+
+ if (lastSlash) {
+ /* Last try, assume nameInput contains only a file name
+ * Strip of the file name at end of the stylesheet doc URL */
+ lastSlash++; /* skip the slash */
+ if (xmlStrCmp(lastSlash, searchData->nameInput) == 0) {
+ /* guessed right! */
+ searchData->guessedNameMatch =
+ (xmlChar *) xmlMemStrdup((char *) node->doc->URL);
+ searchData->node = node;
+ searchCriteria->found = 1;
+ }
+ }
+ }
+}
+
+
+/**
+ * guessStylesheetName:
+ * @searchInf: Is valid
+ *
+ * Try to find a matching stylesheet name
+ * Sets the values in @searchinf depending on outcome of search
+ */
+void
+guessStylesheetName(searchInfoPtr searchCriteria)
+{
+ nodeSearchDataPtr searchData;
+
+ if (!searchCriteria)
+ return;
+
+ searchData = (nodeSearchDataPtr) searchCriteria->data;
+ if (searchData->nameInput == NULL)
+ return; /* must supply name of file to look for */
+
+ walkStylesheets((xmlHashScanner) guessStylesheetHelper,
+ searchCriteria, filesGetStylesheet());
+ if (!searchCriteria->found) {
+ /* try looking in the included stylesheets */
+ walkIncludes((xmlHashScanner) guessStylesheetHelper2,
+ searchCriteria, filesGetStylesheet());
+ }
+}
+
+
+/**
+ * stylePath:
+ *
+ * Return The base path for the top stylesheet ie
+ * ie URL minus the actual file name
+ *
+ * Returns The base path for the top stylesheet ie
+ * ie URL minus the actual file name
+ */
+xmlChar *
+stylePath(void)
+{
+ return stylePathName;
+}
+
+
+/**
+ * workingPath:
+ *
+ * Return the working directory as set by changeDir function
+ *
+ * Returns The working directory as set by changeDir function
+ */
+xmlChar *
+workingPath(void)
+{
+ return workingDirPath;
+}
+
+
+/**
+ * changeDir:
+ * @path: The path to adopt as new working directory
+ *
+ * Change working directory to path
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+changeDir(const xmlChar * path)
+{
+ int result = 0;
+ int charIndex;
+ const char endString[2] = { PATHCHAR, '\0' };
+ xmlChar *expandedName = NULL;
+
+
+ if (path && (xmlStrLen(path) > 0)) {
+ expandedName = filesExpandName(path);
+ } else {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Empty path provided to changeDir");
+#endif
+ return result;
+ }
+
+ if (!expandedName)
+ return result; /* out of memory ? */
+
+ if (xmlStrLen(expandedName) + 1 > sizeof(filesBuffer)) {
+ xsldbgGenericErrorFunc(i18n("Error: The file name \"%1\" is too long.\n").arg(xsldbgText(path)));
+ return result;
+ }
+
+ xmlStrCpy(filesBuffer, expandedName);
+ /* strip off any extra PATHCHAR's as win32's chdir function
+ * fails if we don't */
+ charIndex = xmlStrLen(filesBuffer) - 1;
+ while (charIndex && (filesBuffer[charIndex] == PATHCHAR)) {
+ charIndex--;
+ }
+ filesBuffer[charIndex + 1] = '\0';
+
+
+ if (chdir((char *) filesBuffer) == 0) {
+ if (workingDirPath)
+ xmlFree(workingDirPath);
+ /* must have path char at end of path name */
+ xmlStrCat(filesBuffer, endString);
+ workingDirPath = (xmlChar *) xmlMemStrdup((char *) filesBuffer);
+ result = 1;
+ }
+ xmlFree(expandedName); /* this will always be valid time */
+ if (!result) {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to change to directory %1.\n").arg(xsldbgText(path)));
+ } else {
+ if (xslDebugStatus != DEBUG_NONE)
+ xsldbgGenericErrorFunc(i18n("Changed to directory %1.\n").arg(xsldbgText(path)));
+ }
+ return result;
+}
+
+
+/**
+ * filesLoadXmlFile:
+ * @path: xml file to load
+ * @fileType: A valid FileTypeEnum
+ *
+ * Load specified file type, freeing any memory previously used
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+filesLoadXmlFile(const xmlChar * path, FileTypeEnum fileType)
+{
+ int result = 0;
+
+ if (!filesFreeXmlFile(fileType))
+ return result;
+
+ switch (fileType) {
+ case FILES_XMLFILE_TYPE:
+ if (path && xmlStrLen(path)) {
+ if (optionsGetIntOption(OPTIONS_SHELL)) {
+ xsldbgGenericErrorFunc(i18n("Setting XML Data file name to %1.\n").arg(xsldbgText(path)));
+ }
+ optionsSetStringOption(OPTIONS_DATA_FILE_NAME, path);
+ }
+ topDocument = xsldbgLoadXmlData();
+ if (topDocument)
+ result = 1;
+ break;
+
+ case FILES_SOURCEFILE_TYPE:
+ if (path && xmlStrLen(path)) {
+ if (optionsGetIntOption(OPTIONS_SHELL)) {
+ xsldbgGenericErrorFunc(i18n("Setting stylesheet file name to %1.\n").arg(xsldbgText(path)));
+ }
+ optionsSetStringOption(OPTIONS_SOURCE_FILE_NAME, path);
+ }
+ topStylesheet = xsldbgLoadStylesheet();
+ if (topStylesheet && topStylesheet->doc) {
+ /* look for last slash (or baskslash) of URL */
+ char *lastSlash = xmlStrrChr(topStylesheet->doc->URL,
+ PATHCHAR);
+ const char *docUrl =
+ (const char *) topStylesheet->doc->URL;
+
+ result = 1;
+ if (docUrl && lastSlash) {
+ stylePathName = (xmlChar *) xmlMemStrdup(docUrl);
+ stylePathName[lastSlash - docUrl + 1] = '\0';
+ if (optionsGetIntOption(OPTIONS_SHELL)) {
+ xsldbgGenericErrorFunc(i18n("Setting stylesheet base path to %1.\n").arg(xsldbgText(stylePathName)));
+ }
+ } else {
+ const char cwd[4] = { '.', PATHCHAR, '\0' };
+
+ /* ie for *nix this becomes "./" */
+ stylePathName = xmlStrdup(BAD_CAST cwd);
+ }
+
+ /* try to find encoding for this stylesheet */
+ if (optionsGetIntOption(OPTIONS_AUTOENCODE))
+ filesSetEncoding((char *) topStylesheet->encoding);
+ }
+ break;
+
+ case FILES_TEMPORARYFILE_TYPE:
+ if (!path || !xmlStrLen(path)) {
+ xsldbgGenericErrorFunc(i18n("Missing file name.\n"));
+ break;
+ }
+ topDocument = xsldbgLoadXmlTemporary(path);
+ if (tempDocument)
+ result = 1;
+ break;
+ }
+ return result;
+}
+
+
+/**
+ * filesFreeXmlFile:
+ * @fileType: A valid FileTypeEnum
+ *
+ * Free memory associated with the xml file
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+filesFreeXmlFile(FileTypeEnum fileType)
+{
+ int result = 0, type = fileType;
+
+ switch (type) {
+ case FILES_XMLFILE_TYPE:
+ if (topDocument)
+ xmlFreeDoc(topDocument);
+ topDocument = NULL;
+ result = 1;
+ break;
+
+ case FILES_SOURCEFILE_TYPE:
+ if (topStylesheet)
+ xsltFreeStylesheet(topStylesheet);
+ if (stylePathName)
+ xmlFree(stylePathName);
+ stylePathName = NULL;
+ topStylesheet = NULL;
+ result = 1;
+ break;
+
+ case FILES_TEMPORARYFILE_TYPE:
+ if (tempDocument)
+ xmlFreeDoc(tempDocument);
+ tempDocument = NULL;
+ result = 1;
+ break;
+ }
+ return result;
+}
+
+
+/**
+ * filesGetStylesheet:
+ *
+ * Return The topmost stylesheet non-null on success,
+ * NULL otherwise
+ *
+ * Returns The topmost stylesheet non-null on success,
+ * NULL otherwise
+ */
+xsltStylesheetPtr
+filesGetStylesheet(void)
+{
+ return topStylesheet;
+}
+
+
+/**
+ * filesGetTemporaryDoc:
+ *
+ * Return The current "temporary" document
+ *
+ * Returns The current "temporary" document
+ */
+xmlDocPtr
+filesGetTemporaryDoc(void)
+{
+ return tempDocument;
+}
+
+
+/**
+ * filesGetMainDoc:
+ *
+ * Return The main docment
+ *
+ * Returns The main docment
+ */
+xmlDocPtr
+filesGetMainDoc(void)
+{
+ return topDocument;
+}
+
+
+/**
+ * filesReloaded:
+ * @reloaded: if = -1 then ignore @reloaded
+ * otherwise change the status of files to value of @reloaded
+ *
+ * Returns 1 if stylesheet or its xml data file has been "flaged" as reloaded,
+ * 0 otherwise
+ */
+int
+filesReloaded(int reloaded)
+{
+ static int changed = 0;
+
+ if (reloaded >= 0) {
+ changed = reloaded;
+ }
+
+ return changed;
+}
+
+
+
+/**
+ * filesInit:
+ *
+ * Initialize the file related structures
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+filesInit(void)
+{
+ int result = 0;
+
+ terminalIO = NULL;
+#ifdef __riscos
+ ttyName = ":tt"; /* Default tty */
+#endif
+#ifdef HAVE_UNISTD
+ ttyName = ttyname(fileno(stdin));
+ /* save out io for when/if we send debugging to a terminal */
+ oldStdin = stdin;
+ oldStdout = stdout;
+ oldStderr = stderr;
+#endif
+ topDocument = NULL;
+ tempDocument = NULL;
+ topStylesheet = NULL;
+ entityNameList = arrayListNew(4, (freeItemFunc) filesFreeEntityInfo);
+#if defined(HAVE_INCLUDE_FIX) && (LIBXML_VERSION < 20508)
+ xmlSetEntityReferenceFunc(filesEntityRef);
+#endif
+
+ /* setup the encoding */
+ encodeInBuff = xmlBufferCreate();
+ encodeOutBuff = xmlBufferCreate();
+
+ /* check the result so far and lastly perform platform specific
+ * initialization */
+ if (entityNameList && encodeInBuff && encodeOutBuff &&
+ filesPlatformInit())
+ result = 1;
+ return result;
+}
+
+/**
+ * filesFree:
+ *
+ * Free memory used by file related structures
+ */
+void
+filesFree(void)
+{
+ int result;
+
+ if (terminalIO) {
+ fclose(terminalIO);
+ terminalIO = NULL;
+ }
+ if (termName) {
+ xmlFree(termName);
+ termName = NULL;
+ }
+
+ result = filesFreeXmlFile(FILES_SOURCEFILE_TYPE);
+ if (result)
+ result = filesFreeXmlFile(FILES_XMLFILE_TYPE);
+ if (result)
+ result = filesFreeXmlFile(FILES_TEMPORARYFILE_TYPE);
+ if (!result){
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Unable to free memory used by XML/XSLT files\n");
+#endif
+ }
+ if (stylePathName) {
+ xmlFree(stylePathName);
+ stylePathName = NULL;
+ }
+
+ if (workingDirPath) {
+ xmlFree(workingDirPath);
+ workingDirPath = NULL;
+ }
+
+ if (entityNameList) {
+ arrayListFree(entityNameList);
+ entityNameList = NULL;
+ }
+
+ /* Free memory used by encoding related structures */
+ if (encodeInBuff)
+ xmlBufferFree(encodeInBuff);
+
+ if (encodeOutBuff)
+ xmlBufferFree(encodeOutBuff);
+
+ /* close current encoding */
+ filesSetEncoding(NULL);
+
+ if (currentUrl)
+ xmlFree(currentUrl);
+
+ /* free any memory used by platform specific files module */
+ filesPlatformFree();
+}
+
+
+/**
+ * filesIsSourceFile:
+ * @fileName : is valid
+ *
+ * Returns true if @name has the ".xsl" externsion
+ */
+int
+filesIsSourceFile(xmlChar * fileName)
+{
+ return strstr((char *) fileName, ".xsl") ||
+ strstr((char *) fileName, ".Xsl") ||
+ strstr((char *) fileName, ".XSL");
+}
+
+
+
+entityInfoPtr
+filesNewEntityInfo(const xmlChar * SystemID, const xmlChar * PublicID)
+{
+
+ entityInfoPtr result = (entityInfoPtr) xmlMalloc(sizeof(entityInfo));
+
+ if (result) {
+ if (SystemID)
+ result->SystemID = xmlStrdup(SystemID);
+ else
+ result->SystemID = xmlStrdup(BAD_CAST "");
+
+ if (PublicID)
+ result->PublicID = xmlStrdup(PublicID);
+ else
+ result->PublicID = xmlStrdup(BAD_CAST "");
+ }
+ return result;
+}
+
+void
+filesFreeEntityInfo(entityInfoPtr info)
+{
+ if (!info)
+ return;
+
+ if (info->SystemID)
+ xmlFree(info->SystemID);
+
+ if (info->PublicID)
+ xmlFree(info->PublicID);
+ xmlFree(info);
+}
+
+/**
+ * filesAddEntityName:
+ * @name : is valid
+ *
+ * Add name to entity name list of know external entities if
+ * it does not already exist in list
+ */
+void
+
+filesAddEntityName(const xmlChar * SystemID, const xmlChar * PublicID)
+{
+ int entityIndex = 0;
+ entityInfoPtr tempItem;
+
+ if (!SystemID || !filesEntityList())
+ return;
+
+ for (entityIndex = 0;
+ entityIndex < arrayListCount(filesEntityList()); entityIndex++) {
+ tempItem =
+ (entityInfoPtr) arrayListGet(filesEntityList(), entityIndex);
+ if (tempItem && xmlStrEqual(SystemID, tempItem->SystemID)) {
+ /* name aready exits so don't add it */
+ return;
+ }
+
+ }
+
+ tempItem = filesNewEntityInfo(SystemID, PublicID);
+ arrayListAdd(filesEntityList(), tempItem);
+}
+
+
+/**
+ * filesEntityRef :
+ * @ent : Is valid as provided by libxslt
+ * @firstNode : Is valid
+ * @lastNode : Is Valid
+ *
+ * Fixes the nodes from firstNode to lastNode so that debugging can occur
+ */
+void
+
+filesEntityRef(xmlEntityPtr ent, xmlNodePtr firstNode, xmlNodePtr lastNode)
+{
+ xmlNodePtr node = firstNode;
+ if (!firstNode || !ent || !ent->SystemID ||
+ (ent->etype != XML_EXTERNAL_GENERAL_PARSED_ENTITY) )
+ return;
+
+ if (ent->ExternalID)
+ filesAddEntityName(ent->SystemID, ent->ExternalID);
+ else
+ filesAddEntityName(ent->URI, BAD_CAST "");
+ while (node){
+ filesSetBaseUri(node, ent->URI);
+ if (node != lastNode)
+ node = node->next;
+ else
+ node = NULL;
+ }
+}
+
+
+
+ /**
+ * filesSetBaseUri:
+ * @node : Is valid and has a doc parent
+ * @uri : Is Valid
+ *
+ * Set the base uri for this node. Function is used when xml file
+ * has external entities in its DTD
+ *
+ * Returns 1 if successful,
+ * 0 otherwise
+ */
+
+int
+filesSetBaseUri(xmlNodePtr node, const xmlChar * uri)
+{
+ int result = 0;
+
+ if (!node || !uri)
+ return result;
+ else {
+ if (node->type == XML_ELEMENT_NODE){
+ xmlChar *xsldbgUrlCopy = xmlGetProp(node, BAD_CAST "xsldbg:uri");
+ if (!xsldbgUrlCopy)
+ xmlNewProp(node, BAD_CAST "xsldbg:uri", uri);
+ else
+ xmlFree(xsldbgUrlCopy);
+ }
+ result = 1;
+ }
+ return result;
+}
+
+
+ /**
+ * filesGetBaseUri:
+ * @node : Is valid and has a doc parent
+ *
+ * Get a copy of the base uri for this node. Function is most usefull
+ * used when xml file has external entities in its DTD
+ *
+ * Returns the a copy of the base uri for this node,
+ * NULL otherwise
+ */
+xmlChar *
+filesGetBaseUri(xmlNodePtr node)
+{
+ xmlChar *result = NULL;
+
+ if (!node || !node->doc)
+ return result;
+
+ while (node && node->parent) {
+ /*
+ * result = xmlGetNsProp(node, BAD_CAST "uri", XSLDBG_XML_NAMESPACE);
+ */
+ if (node->type == XML_ELEMENT_NODE) {
+ result = xmlGetProp(node, BAD_CAST "xsldbg:uri");
+ if (result)
+ break;
+ }
+ node = node->parent;
+ }
+
+ if (!result && node->doc && node->doc->URL)
+ result = xmlStrdup(node->doc->URL);
+
+ return result;
+}
+
+
+
+
+/**
+ * filesEntityList:
+ *
+ * Return the list entity names used for documents loaded
+ *
+ * Returns the list entity names used for documents loaded
+ */
+arrayListPtr
+filesEntityList(void)
+{
+ return entityNameList;
+}
+
+extern int intVolitileOptions[OPTIONS_LAST_INT_OPTIONID - OPTIONS_FIRST_INT_OPTIONID + 1];
+
+/**
+ * filesLoadCatalogs:
+ *
+ * Load the catalogs specifed by OPTIONS_CATALOG_NAMES if
+ * OPTIONS_CATALOGS is enabled
+ * Returns 1 if sucessful
+ * 0 otherwise
+ */
+int
+filesLoadCatalogs(void)
+{
+ int result = 0;
+ const char *catalogs = NULL;
+
+ xmlCatalogCleanup();
+ if (optionsGetIntOption(OPTIONS_CATALOGS)) {
+ if (optionsGetStringOption(OPTIONS_CATALOG_NAMES) == NULL) {
+ /* use the SGML catalog */
+#ifdef __riscos
+ catalogs = getenv("SGML$CatalogFiles");
+#else
+ catalogs = getenv("SGML_CATALOG_FILES");
+#endif
+ if (catalogs == NULL) {
+#ifdef __riscos
+ xsldbgGenericErrorFunc("Warning: Environment variable SGML$CatalogFiles is not set.\n");
+#else
+ xsldbgGenericErrorFunc("Warning: Environment variabe SGML_CATALOG_FILES FILES not set.\n");
+#endif
+ } else
+ /* copy the current catalog name(s) for user to see */
+ optionsSetStringOption(OPTIONS_CATALOG_NAMES,
+ (xmlChar *) catalogs);
+ } else
+ /* Use the current catalog settings from users*/
+ catalogs = (char *)
+ optionsGetStringOption(OPTIONS_CATALOG_NAMES);
+
+ result = 1;
+ }
+
+ if (catalogs){
+ /* Load the new cataog selection */
+ xmlLoadCatalogs(catalogs);
+ }else{
+ /* Use default catalogs */
+ xmlInitializeCatalog();
+ }
+ return result;
+}
+
+
+
+
+ /**
+ * filesEncode:
+ * @text: Is valid, text to translate from UTF-8,
+ *
+ * Return A new string of converted @text
+ *
+ * Returns A new string of converted @text, may be NULL
+ */
+xmlChar *
+filesEncode(const xmlChar * text)
+{
+ xmlChar *result = NULL;
+
+ if (!text)
+ return result;
+
+ if (!stdoutEncoding || !encodeInBuff || !encodeOutBuff)
+ return xmlStrdup(text); /* no encoding active return as UTF-8 */
+
+ xmlBufferEmpty(encodeInBuff);
+ xmlBufferEmpty(encodeOutBuff);
+ xmlBufferCat(encodeInBuff, text);
+
+ if (xmlCharEncOutFunc(stdoutEncoding, encodeOutBuff, encodeInBuff)
+ >= 0) {
+ result = xmlStrdup(xmlBufferContent(encodeOutBuff));
+ } else {
+ xsldbgGenericErrorFunc(i18n("Encoding of text failed.\n"));
+ return xmlStrdup(text); /* panic, return as UTF-8 */
+ }
+ return result;
+}
+
+
+
+ /**
+ * filesDeccode:
+ * @text: Is valid, text to translate from current encoding to UTF-8,
+ *
+ * Return A string of converted @text
+ *
+ * Returns A string of converted @text, may be NULL
+ */
+xmlChar *
+filesDecode(const xmlChar * text)
+{
+ xmlChar *result = NULL;
+
+ if (!text)
+ return result;
+
+ if (!stdoutEncoding || !encodeInBuff || !encodeOutBuff)
+ return xmlStrdup(text); /* no encoding active return as UTF-8 */
+
+ xmlBufferEmpty(encodeInBuff);
+ xmlBufferEmpty(encodeOutBuff);
+ xmlBufferCat(encodeInBuff, text);
+
+ if (xmlCharEncInFunc(stdoutEncoding, encodeOutBuff, encodeInBuff)
+ >= 0) {
+ result = xmlStrdup(xmlBufferContent(encodeOutBuff));
+ } else {
+ xsldbgGenericErrorFunc(i18n("Encoding of text failed.\n"));
+ return xmlStrdup(text); /* panic, return @text unchanged */
+ }
+ return result;
+}
+
+
+ /*
+ * filesSetEncoding:
+ * @encoding : Is a valid encoding supported by the iconv library or NULL
+ *
+ * Opens encoding for all standard output to @encoding. If @encoding
+ * is NULL then close current encoding and use UTF-8 as output encoding
+ *
+ * Returns 1 if successful in setting the encoding of all standard output
+ * to @encoding
+ * 0 otherwise
+ */
+int
+filesSetEncoding(const char *encoding)
+{
+ int result = 0;
+
+ if (encoding) {
+ /* don't switch encoding unless we've found a valid encoding */
+ xmlCharEncodingHandlerPtr tempEncoding =
+ xmlFindCharEncodingHandler(encoding);
+ if (tempEncoding) {
+ filesSetEncoding(NULL); /* re-use code to close encoding */
+ stdoutEncoding = tempEncoding;
+ result =
+ (xmlCharEncOutFunc(stdoutEncoding, encodeOutBuff, NULL)
+ >= 0);
+ if (!result) {
+ xmlCharEncCloseFunc(stdoutEncoding);
+ stdoutEncoding = NULL;
+ xsldbgGenericErrorFunc(i18n("Unable to initialize encoding %1.").arg(xsldbgText(encoding)));
+ } else
+ optionsSetStringOption(OPTIONS_ENCODING,
+ (xmlChar *) encoding);
+ } else {
+ xsldbgGenericErrorFunc(i18n("Invalid encoding %1.\n").arg(xsldbgText(encoding)));
+ }
+ } else {
+ /* close encoding and use UTF-8 */
+ if (stdoutEncoding)
+ result = (xmlCharEncCloseFunc(stdoutEncoding) >= 0);
+ else
+ result = 1;
+ stdoutEncoding = NULL;
+ }
+ return result;
+}
+
+
+
+ /**
+ * filesMoreFile:
+ * @fileName : May be NULL
+ * @file : May be NULL
+ *
+ * Do a "more" like print of file specified by @fileName OR
+ * @file. If both are provided @file will be used. The content
+ * of file chosen must be in UTF-8, and will be printed in
+ * the current encoding selected.The function will pause output
+ * after FILES_NO_LINES lines have been printed waiting for
+ * user to enter "q" to quit or any other text to continue.
+ *
+ * Returns 1 if successful,
+ * 0 otherwise
+ */
+int
+filesMoreFile(const xmlChar * fileName, FILE * file)
+{
+ int result = 0;
+ int openedFile = 0;
+ int lineCount;
+ int reachedEof = 0;
+
+ if (fileName && !file) {
+#ifdef __riscos
+ /* convert into RISC OS format a *nix style file name */
+ fileName = (const xmlChar *) riscosfilename((char *) fileName);
+#endif
+ file = fopen((char *) fileName, "r");
+ openedFile = 1; /* since we opened the file we must close it */
+ }
+ if (file) {
+ while (!feof(file) && !reachedEof) {
+ lineCount = 0;
+ while (!feof(file) && (lineCount < FILES_NO_LINES) &&
+ !reachedEof) {
+ if (fgets((char *) filesBuffer, sizeof(filesBuffer), file)) {
+ xsltGenericError(xsltGenericErrorContext, "%s",
+ filesBuffer);
+ lineCount++;
+ } else {
+ reachedEof = 1;
+ }
+ }
+
+ if (!feof(file) && !reachedEof) {
+ xsldbgGenericErrorFunc(i18n(" ----- more ---- \n"));
+ fflush(stderr);
+ if (fgets((char *) filesBuffer, sizeof(filesBuffer), stdin)) {
+ if ((*filesBuffer == 'q') || (*filesBuffer == 'Q'))
+ reachedEof = 1;
+ } else {
+ reachedEof = 1;
+ }
+ }
+ }
+
+ if (openedFile) {
+ fclose(file);
+ }
+ xsltGenericError(xsltGenericErrorContext, "\n");
+ result = 1;
+ } else {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: No valid file provided to print\n");
+#endif
+ }
+
+
+ return result;
+}
+
+
+ /**
+ * filesSearchResultsPath:
+ *
+ * Get the base path to be used for storing search results
+ *
+ * Returns The base path to be used for storing search results
+ */
+const xmlChar *
+filesSearchResultsPath()
+{
+ const xmlChar *result;
+
+ if (optionsGetStringOption(OPTIONS_SEARCH_RESULTS_PATH))
+ result = optionsGetStringOption(OPTIONS_SEARCH_RESULTS_PATH);
+ else
+ result = stylePath();
+
+ return result;
+}
+
+
+ /**
+ * filesURItoFileName:
+ * @uri : A valid URI that uses the "file://" prefix
+ *
+ * Return A copy of the conversion of @uri to a file name
+ * that is suitable to be used with the fopen function.
+ * May be NULL, if out of memory, @uri does not use the
+ * "file://" prefix, or unable to convert to a valid file name
+ *
+ * Returns A copy of the conversion of @uri to a file name
+ * that is suitable to be used with the fopen function.
+ * May be NULL, if out of memory, @uri does not use the
+ * "file://" prefix, or unable to convert to a valid file name
+ *
+ */
+xmlChar *filesURItoFileName(const xmlChar* uri)
+{
+ xmlChar *result = NULL;
+ xmlChar *unescapedFileName = NULL;
+ const xmlChar* tempName = NULL;
+
+ if (uri){
+ if (!xmlStrnCmp(uri, "file://localhost", 16 )){
+ tempName = uri + 16;
+ }else{
+#if defined(WIN32) && ! defined(CYGWIN)
+ if (!xmlStrnCmp(uri, "file:///", 8))
+ tempName = uri + 8;
+#else
+ if (!xmlStrnCmp(uri, "file:/", 6))
+ tempName = uri + 5; // we need the leading '/'*/
+ while (tempName[0] == '/' && tempName[1] == '/' )
+ tempName++;
+#endif
+ }
+
+ /* If we've found something check to see if the file name
+ found is to be valid */
+ if (tempName)
+ result = (xmlChar*) xmlStrdup(tempName);
+ unescapedFileName = (xmlChar*) xmlStrdup(tempName);
+ if (result && unescapedFileName){
+ if (PATHCHAR != URISEPARATORCHAR){
+ /* Must convert path separators first */
+ xmlChar *probe = result;
+ while(*probe != '\0'){
+ if (*probe == (xmlChar)URISEPARATORCHAR)
+ *probe = (xmlChar)PATHCHAR;
+ probe++;
+ }
+ }
+ /* Now unescape the file name in result so far
+ * NB: An unescaped name takes less memory that an escaped name
+ */
+ xmlURIUnescapeString((char*)result, -1, (char*)unescapedFileName);
+ xmlFree(result);
+ /* success we've got an local unescaped file name */
+ result = unescapedFileName;
+ }else{
+ xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
+ if (result){
+ xmlFree(result);
+ }
+ if (unescapedFileName) /* not needed, here for completeness */
+ xmlFree(unescapedFileName);
+
+ result = NULL;
+ }
+ }else{
+ xsldbgGenericErrorFunc(i18n("Error: Unable to convert %1 to local file name.\n").arg(xsldbgText(uri)));
+ }
+
+
+ return result;
+}
+
+
+/* TODO in xsldbg 3.x rename these to use files prefix */
+
+/**
+ * xsldbgUpdateFileDetails:
+ * @node : A valid node
+ *
+ * Update the URL and line number that we stoped at
+ */
+void
+xsldbgUpdateFileDetails(xmlNodePtr node)
+{
+ if ((node != NULL) && (node->doc != NULL)){
+ if (currentUrl != NULL)
+ xmlFree(currentUrl);
+ currentUrl = filesGetBaseUri(node);
+ currentLineNo = xmlGetLineNo(node);
+ }
+}
+
+
+/**
+ * xsldbgLineNo:
+ *
+ * What line number are we at
+ *
+ * Returns The current line number of xsldbg, may be -1
+ **/
+int
+xsldbgLineNo(void)
+{
+ return currentLineNo;
+}
+
+
+/**
+ * xsldbgUrl:
+ *
+ * What URL did we stop at
+ *
+ * Returns A NEW copy of URL stopped at. Caller must free memory for URL.
+ * May be NULL
+ */
+xmlChar *
+xsldbgUrl(void)
+{
+ if (currentUrl != NULL)
+ return (xmlChar *) xmlMemStrdup((char *) currentUrl);
+ else
+ return NULL;
+}
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/files.h b/kxsldbg/kxsldbgpart/libxsldbg/files.h
new file mode 100644
index 00000000..05e49828
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/files.h
@@ -0,0 +1,981 @@
+
+/***************************************************************************
+ files.h - define file related functions
+ -------------------
+ begin : Sat Nov 10 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 FILES_H
+#define FILES_H
+
+#ifndef BUILD_DOCS
+
+#include "search.h"
+#include "arraylist.h"
+
+#endif
+
+#ifdef USE_KDE_DOCS
+
+/**
+ * Provide a file support
+ *
+ * @short file support
+ *
+ * @author Keith Isdale <k_isdale@tpg.com.au>
+ */
+#endif
+
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h> /* need chdir function */
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ extern FILE *terminalIO;
+
+#define XSLDBG_XML_NAMESPACE \
+ (const xmlChar *) "http://xsldbg.sourceforge.net/namespace"
+
+ typedef struct _entityInfo entityInfo;
+ typedef entityInfo *entityInfoPtr;
+ struct _entityInfo {
+ xmlChar *SystemID;
+ xmlChar *PublicID;
+ };
+
+
+ /* how many lines do we print before pausing when
+ * performing "more" on a UTF-8 file. See function filesMoreFile */
+#define FILES_NO_LINES 20
+
+ /* Define the types of file names that we are intested in when creating
+ * search results */
+#ifndef USE_KDOC
+ typedef enum {
+ FILES_SEARCHINPUT,
+ FILES_SEARCHXSL,
+ FILES_SEARCHRESULT
+ } FilesSearchFileNameEnum;
+#else
+ /* keep kdoc happy */
+ enum FilesSearchFileNameEnum {
+ FILES_SEARCHINPUT,
+ FILES_SEARCHXSL,
+ FILES_SEACHRESULT
+ };
+#endif
+
+
+
+ /*-----------------------------------------------------------
+ General function for working with files
+ -----------------------------------------------------------*/
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesEntityRef :
+ * @ent : Is valid as provided by libxslt
+ * @firstNode : Is valid
+ * @lastNode : Is Valid
+ *
+ * Fixes the nodes from firstNode to lastNode so that debugging can occur
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Fixes the nodes from firstNode to lastNode so that debugging can occur
+ *
+ * @param uri Is valid as provided by libxslt
+ * @param firstNode Is valid
+ * @param lastNode Is Valid
+ */
+#endif
+#endif
+ void filesEntityRef(xmlEntityPtr ent, xmlNodePtr firstNode,
+ xmlNodePtr lastNode);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesEntityList:
+ *
+ * Return the list entity names used for documents loaded
+ *
+ * Returns The list entity names used for documents loaded
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Return the list entity names used for documents loaded
+ *
+ * @returns The list entity names used for documents loaded
+ */
+#endif
+#endif
+ arrayListPtr filesEntityList(void);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesSetBaseUri:
+ * @node : Is valid and has a doc parent
+ * @uri : Is Valid
+ *
+ * Set the base uri for this node. Function is used when xml file
+ * has external entities in its DTD
+ *
+ * Returns 1 if successful,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Set the base uri for this node. Function is used when xml file
+ * has external entities in its DTD
+ *
+ * @param node Is valid and has a doc parent
+ * @param uri Is Valid
+ *
+ * @returns 1 if successful,
+ * 0 otherwise
+ */
+#endif
+#endif
+ int filesSetBaseUri(xmlNodePtr node, const xmlChar * uri);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesGetBaseUri:
+ * @node : Is valid and has a doc parent
+ *
+ * Get a copy of the base uri for this node. Function is most usefull
+ * used when xml file has external entities in its DTD
+ *
+ * Returns the a copy of the base uri for this node,
+ * NULL otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Get a copy of the base uri for this node. Function is most usefull
+ * used when xml file has external entities in its DTD
+ *
+ * @param node : Is valid and has a doc parent
+ *
+ * @returns The a copy of the base uri for this node,
+ * NULL otherwise
+ */
+#endif
+#endif
+ xmlChar *filesGetBaseUri(xmlNodePtr node);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesTempFileName:
+ * @fleNumber : Number of temp file required
+ * where @fileNumber is
+ * 0 : file name used by cat command
+ * 1 : file name used by profiling output
+ *
+ * Return the name of tempfile requirested
+ *
+ * This is a platform specific interface
+ *
+ * Returns The name of temp file to be used for temporary results if sucessful,
+ * NULL otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Return the name of tempfile requested.
+ * @param fleNumber : Number of temp file required
+ * where @p fileNumber is
+ * 0 : file name used by cat command
+ * 1 : file name used by profiling output
+ *
+ * This is a platform specific interface
+ *
+ * Returns The name of temp file to be used for temporary results if sucessful,
+ * NULL otherwise
+ */
+#endif
+#endif
+ const char *filesTempFileName(int fileNumber);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesLoadCatalogs:
+ *
+ * Load the catalogs specifed by OPTIONS_CATALOG_NAMES if
+ * OPTIONS_CATALOGS is enabled
+ *
+ * Returns 1 if sucessful
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Load the catalogs specifed by OPTIONS_CATALOG_NAMES if
+ * OPTIONS_CATALOGS is enabled
+ *
+ * @returns 1 if sucessful
+ * 0 otherwise
+ */
+#endif
+#endif
+ int filesLoadCatalogs(void);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesEncode:
+ * @text: Is valid, text to translate from UTF-8,
+ *
+ * Return A string of converted @text
+ *
+ * Returns A string of converted @text, may be NULL
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Return A string of converted @text
+ *
+ * @param text Is valid, text to translate from UTF-8,
+ *
+ * Returns A string of converted @text, may be NULL
+ */
+#endif
+#endif
+ xmlChar *filesEncode(const xmlChar * text);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesDeccode:
+ * @text: Is valid, text to translate from current encoding to UTF-8,
+ *
+ * Return A string of converted @text
+ *
+ * Returns A string of converted @text, may be NULL
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Return A string of converted @text
+ *
+ * @param test Is valid, text to translate from current encoding to UTF-8,
+ *
+ * Returns A string of converted @text, may be NULL
+ */
+#endif
+#endif
+ xmlChar *filesDecode(const xmlChar * text);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesSetEncoding:
+ * @encoding : Is a valid encoding supported by the iconv library or NULL
+ *
+ * Opens encoding for all standard output to @encoding. If @encoding
+ * is NULL then close current encoding and use UTF-8 as output encoding
+ *
+ * Returns 1 if successful in setting the encoding of all standard output
+ * to @encoding
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Opens encoding for all standard output to @p encoding. If @p encoding
+ * is NULL then close current encoding and use UTF-8 as output encoding
+ *
+ * @param encoding Is a valid encoding supported by the iconv library or NULL
+ *
+ * Returns 1 if successful in setting the encoding of all standard output
+ * to @p encoding
+ * 0 otherwise
+ */
+#endif
+#endif
+ int filesSetEncoding(const char *encoding);
+
+
+#ifndef USE_KDOC
+ /* used by filesLoadXmlFile, filesFreeXmlFile functions */
+ typedef enum {
+ FILES_XMLFILE_TYPE = 100, /* pick a unique starting point */
+ FILES_SOURCEFILE_TYPE,
+ FILES_TEMPORARYFILE_TYPE
+ } FileTypeEnum;
+#else
+
+ /* used by filesLoadXmlFile, filesFreeXmlFile functions */
+ enum FileTypeEnum {
+ FILES_XMLFILE_TYPE = 100, /* pick a unique starting point */
+ FILES_SOURCEFILE_TYPE,
+ FILES_TEMPORARYFILE_TYPE
+ };
+#endif
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * openTerminal
+ * @device: terminal to redirect i/o to , will not work under win32
+ *
+ * Open communications to the terminal device @device
+ * Returns 1 if sucessful
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Open communications to the terminal device @p device
+ *
+ * @param device Terminal to redirect i/o to , will not work under win32
+ *
+ * @returns 1 if sucessful
+ * 0 otherwise
+ */
+#endif
+#endif
+ int openTerminal(xmlChar * device);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * guessStyleSheetName:
+ * @searchInf : Is valid
+ *
+ * Try to find a matching stylesheet name
+ * Sets the values in @searchinf depending on outcome of search
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Try to find a matching stylesheet name
+ * Sets the values in @p searchinf depending on outcome of search
+ *
+ * @param searchInf Is valid
+ */
+#endif
+#endif
+ void guessStylesheetName(searchInfoPtr searchInf);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * stylePath:
+ *
+ * Returns the base path for the top stylesheet ie
+ * ie URL minus the actual file name
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Return the base path for the top stylesheet ie
+ * ie URL minus the actual file name
+ *
+ * @returns The base path for the top stylesheet ie
+ * ie URL minus the actual file name
+ */
+#endif
+#endif
+ xmlChar *stylePath(void);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * workingPath:
+ *
+ * Return the working directory as set by changeDir function
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Return the working directory as set by changeDir function
+ *
+ * @return the working directory as set by changeDir function
+ */
+#endif
+#endif
+ xmlChar *workingPath(void);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * changeDir:
+ * @path : path to adopt as new working directory
+ *
+ * Change working directory to path
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Change working directory to path
+ *
+ * @param path The operating system path(directory) to adopt as
+ * new working directory
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ */
+#endif
+#endif
+ int changeDir(const xmlChar * path);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesLoadXmlFile:
+ * @path : xml file to load
+ * @fileType : A valid FileTypeEnum
+ *
+ * Load specified file type, freeing any memory previously used
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Load specified file type, freeing any memory previously used
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param path The xml file to load
+ * @param fileType A valid FileTypeEnum
+ */
+#endif
+#endif
+ int filesLoadXmlFile(const xmlChar * path, FileTypeEnum fileType);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesFreeXmlFile:
+ * @fileType : A valid FileTypeEnum
+ *
+ * Free memory associated with the xml file
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Free memory associated with the xml file
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param fileType : A valid FileTypeEnum
+ */
+#endif
+#endif
+ int filesFreeXmlFile(FileTypeEnum fileType);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesGetStylesheet:
+ *
+ * Return the topmost stylesheet
+ *
+ * Returns non-null on success,
+ * NULL otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Return the topmost stylesheet
+ *
+ * @returns Non-null on success,
+ * NULL otherwise
+ */
+#endif
+#endif
+ xsltStylesheetPtr filesGetStylesheet(void);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesGetTemporaryDoc:
+ *
+ * Return the current "temporary" document
+ *
+ * Returns the current "temporary" document
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Return the current "temporary" document
+ *
+ * @returns non-null on success,
+ * NULL otherwise
+ */
+#endif
+#endif
+ xmlDocPtr filesGetTemporaryDoc(void);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesGetMainDoc:
+ *
+ * Returns the main docment
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Return the main docment
+ *
+ * @returns the main document
+ */
+#endif
+#endif
+ xmlDocPtr filesGetMainDoc(void);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesReloaded:
+ * @reloaded : if = -1 then ignore @reloaded
+ * otherwise change the status of files to value of @reloaded
+ *
+ * Returns 1 if stylesheet or its xml data file has been "flaged" as reloaded,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * @returns 1 if stylesheet or its xml data file has been "flaged" as reloaded,
+ * 0 otherwise
+ *
+ * @param reloaded If = -1 then ignore @p reloaded
+ * otherwise change the status of files to value of @p reloaded
+ */
+#endif
+#endif
+ int filesReloaded(int reloaded);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesInit:
+ *
+ * Initialize the file module
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Initialize the file module
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ */
+#endif
+#endif
+ int filesInit(void);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesFree:
+ *
+ * Free memory used by file related structures
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Free memory used by file related structures
+ */
+#endif
+#endif
+ void filesFree(void);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesIsSourceFile:
+ * @fileName : Is valid
+ *
+ * Test if filename could be a stylesheet
+ *
+ * Returns true if @name has the ".xsl" extension
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Test if filename could be a stylesheet
+ *
+ * @returns True if @name has the ".xsl" extension
+ *
+ * @param fileName Is valid
+ */
+#endif
+#endif
+ int filesIsSourceFile(xmlChar * fileName);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesMoreFile:
+ * @fileName : May be NULL
+ * @file : May be NULL
+ *
+ * Do a "more" like print of file specified by @fileName OR
+ * @file. If both are provided @file will be used. The content
+ * of file chosen must be in UTF-8, and will be printed in
+ * the current encoding selected.The function will pause output
+ * after FILES_NO_LINES lines have been printed waiting for
+ * user to enter "q" to quit or any other text to continue.
+ *
+ * Returns 1 if successful,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Do a "more" like print of file specified by @fileName OR
+ * @file. If both are provided @file will be used. The content
+ * of file chosen must be in UTF-8, and will be printed in
+ * the current encoding selected. The function will pause output
+ * after FILES_NO_LINES lines have been printed waiting for
+ * user to enter "q" to quit or any other text to continue.
+ *
+ * @returns 1 if successful,
+ * 0 otherwise
+ *
+ * @param fileName May be NULL
+ * @param file May be NULL
+ *
+ */
+#endif
+#endif
+ int filesMoreFile(const xmlChar * fileName, FILE * file);
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesSearchResultsPath:
+ *
+ * Get the base path to be used for storing search results
+ *
+ * Returns The base path to be used for storing search results
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Get the base path to be used for storing search results
+ *
+ * @returns The base path to be used for storing search results
+ */
+#endif
+#endif
+ const xmlChar *filesSearchResultsPath(void);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesURItoFileName:
+ * @uri : A valid URI that uses the "file://" prefix
+ *
+ * Return A copy of the conversion of @uri to a file name
+ * that is suitable to be used with the fopen function.
+ * May be NULL, if out of memory, @uri does not use the
+ * "file://" prefix, or unable to convert to a valid file name
+ *
+ * Returns A copy of the conversion of @uri to a file name
+ * that is suitable to be used with the fopen function.
+ * May be NULL, if out of memory, @uri does not use the
+ * "file://" prefix, or unable to convert to a valid file name
+ *
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Return A copy of the conversion of @uri to a file name
+ * that is suitable to be used with the fopen function.
+ * May be NULL, if out of memory, @uri does not use the
+ * "file://" protocol, or unable to convert to a valid file name
+ *
+ * Returns A copy of the conversion of @uri to a file name
+ * that is suitable to be used with the fopen function.
+ * May be NULL, if out of memory, @uri does not use the
+ * "file://" prefix, or unable to convert to a valid file name
+ *
+ * @param uri A valid URI that uses the "file://" prefix
+ *
+ */
+#endif
+#endif
+ xmlChar *filesURItoFileName(const xmlChar* uri);
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * xsldbgUpdateFileDetails:
+ * @node : A valid node
+ *
+ * Update the URL and line number that we stoped at
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Update the URL and line number that we stoped at
+ *
+ * @param node A valid node
+ */
+#endif
+#endif
+ void xsldbgUpdateFileDetails(xmlNodePtr node);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * xsldbgLineNo:
+ *
+ * What line number are we at
+ *
+ * Returns The current line number of xsldbg, may be -1
+ **/
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * What line number are we at
+ *
+ * @returns The current line number of xsldbg, may be -1
+ **/
+#endif
+#endif
+ int xsldbgLineNo(void);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * xsldbgUrl:
+ *
+ * What URL did we stop at
+ *
+ * Returns A NEW copy of URL stopped at. Caller must free memory for URL,
+ * may be NULL
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * What URL did we stop at
+ *
+ * @returns A NEW copy of URL stopped at. Caller must free memory for URL,
+ * may be NULL
+ */
+#endif
+#endif
+ xmlChar *xsldbgUrl(void);
+
+ /*-----------------------------------------------------------
+ Platform specific file functions
+ -----------------------------------------------------------*/
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesPlatformInit:
+ *
+ * Intialize the platform specific files module
+ *
+ * This is a platform specific interface
+ *
+ * Returns 1 if sucessful
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Intialize the platform specific files module
+ *
+ * This is a platform specific interface
+ *
+ * @returns 1 if sucessful
+ * 0 otherwise
+ */
+#endif
+#endif
+ int filesPlatformInit(void);
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesPlatformFree:
+ *
+ * Free memory used by the platform specific files module
+ *
+ * This is a platform specific interface
+ *
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Free memory used by the platform specific files module
+ *
+ * This is a platform specific interface
+ *
+ */
+#endif
+#endif
+ void filesPlatformFree(void);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesExpandName:
+ * @fileName : A valid fileName
+ *
+ * Converts a fileName to an absolute path
+ * If operating system supports it a leading "~" in the fileName
+ * will be converted to the user's home path. Otherwise
+ * the same name will be returned
+ *
+ * Returns A copy of the converted @fileName or a copy of
+ * the @fileName as supplied. May return NULL
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Converts a fileName to an absolute path
+ * If operating system supports it a leading "~" in the fileName
+ * will be converted to the user's home path. Otherwise
+ * the same name will be returned
+ *
+ * Returns A copy of the converted @p fileName or a copy of
+ * the @p fileName as supplied. May return NULL
+ *
+ * @param fileName A valid fileName
+ */
+#endif
+#endif
+ xmlChar *filesExpandName(const xmlChar * fileName);
+
+
+
+#ifdef USE_GNOME_DOCS
+
+ /**
+ * filesSearchFileName:
+ * @fileType : Is valid
+ *
+ * Return a copy of the file name to use as an argument to searching
+ *
+ * Returns A copy of the file name to use as an argument to searching
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+ /**
+ * Return a copy of the file name to use as an argument to searching
+ *
+ * @returns A copy of the file name to use as an argument to searching
+ *
+ * @param fileType Is valid
+ *
+ */
+#endif
+#endif
+ xmlChar *filesSearchFileName(FilesSearchFileNameEnum fileType);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/files_unix.cpp b/kxsldbg/kxsldbgpart/libxsldbg/files_unix.cpp
new file mode 100644
index 00000000..5c1bcbff
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/files_unix.cpp
@@ -0,0 +1,225 @@
+
+/***************************************************************************
+ files_unix.c - file functions *nix platform
+ specific
+ -------------------
+ begin : Tue Jan 29 2002
+ 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 "xsldbg.h"
+#include "files.h"
+#include "utils.h"
+#include "options.h"
+
+static char *tempNames[2] = { NULL, NULL };
+
+ /**
+ * filesPlatformInit:
+ *
+ * Intialize the platform specific files module
+ *
+ * This is a platform specific interface
+ *
+ *
+ * Returns 1 if sucessful
+ * 0 otherwise
+ */
+int
+filesPlatformInit(void)
+{
+ const char *namePrefix = "/tmp/";
+ int nameIndex;
+ int result = 1;
+
+ /* The "base" names for files files to use */
+ const char *names[] = {
+ "_xsldbg_tmp1.txt",
+ "_xsldbg_tmp2.txt"
+ };
+
+ if (getenv("USER")) {
+ for (nameIndex = 0; nameIndex < 2; nameIndex++) {
+ tempNames[nameIndex] = (char*)
+ xmlMalloc(strlen(namePrefix) + strlen(getenv("USER")) +
+ strlen(names[nameIndex]) + 1);
+ if (tempNames[nameIndex]) {
+ xmlStrCpy(tempNames[nameIndex], namePrefix);
+ xmlStrCat(tempNames[nameIndex], getenv("USER"));
+ xmlStrCat(tempNames[nameIndex], names[nameIndex]);
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
+ break;
+ result = 0;
+ }
+ }
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: USER environment variable is not set.\n"));
+ }
+ return result;
+}
+
+
+ /**
+ * filesPlatformFree:
+ *
+ * Free memory used by the platform specific files module
+ *
+ * This is a platform specific interface
+ *
+ */
+void
+filesPlatformFree(void)
+{
+ int nameIndex;
+
+ for (nameIndex = 0; nameIndex < 2; nameIndex++) {
+ if (tempNames[nameIndex])
+ xmlFree(tempNames[nameIndex]);
+ }
+}
+
+ /**
+ * filesTempFileName:
+ * @fileNumber : Number of temp file required
+ *
+ * Return the name of tempfile. For each call to this function
+ * with the same @fileNumber the same file name will be returned
+ * File number : 0 is used by cat command
+ * File number : 1 is used by profiling output
+ *
+ * This is a platform specific interface
+ *
+ * Returns The name of temp file to be used for temporary results,
+ * NULL otherwise
+ */
+const char *
+filesTempFileName(int fileNumber)
+{
+
+ const char *result = NULL;
+
+ if ((fileNumber < 0) || ((fileNumber + 1) > 2)){ //don't use > (int) sizeof(tempNames), it depends on the platform and is wrong even on i586
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Unable to allocate temporary file %d for xsldbg\n",
+ fileNumber);
+#endif
+ }else{
+ result = tempNames[fileNumber];
+ }
+
+ return result;
+}
+
+
+
+ /**
+ * filesExpandName:
+ * @fileName : A valid fileName
+ *
+ * Converts a fileName to an absolute path
+ * If operating system supports it a leading "~" in the fileName
+ * will be converted to the user's home path. Otherwise
+ * the same name will be returned
+ *
+ * Returns A copy of the converted @fileName or a copy of
+ * the @fileName as supplied. May return NULL
+ */
+xmlChar *
+filesExpandName(const xmlChar * fileName)
+{
+ xmlChar *result = NULL;
+
+ if (fileName) {
+ if ((fileName[0] == '~') && getenv("HOME")) {
+ result =
+ (xmlChar *) xmlMalloc(xmlStrLen(fileName) +
+ strlen(getenv("HOME")) + 1);
+ if (result) {
+ xmlStrCpy(result, getenv("HOME"));
+ xmlStrCat(result, &fileName[1]);
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
+ }
+ } else if (!xmlStrnCmp(fileName, "file:/", 6)){
+ /* return a copy of the corrected path */
+ result = filesURItoFileName(fileName);
+ }else{
+ /* return a copy only */
+ result = xmlStrdup(fileName);
+ }
+ }
+ return result;
+}
+
+
+ /**
+ * filesSearchFileName:
+ * @fileType : Is valid
+ *
+ * Return a copy of the file name to use as an argument to searching
+ *
+ * Returns A copy of the file name to use as an argument to searching
+ */
+xmlChar *
+filesSearchFileName(FilesSearchFileNameEnum fileType)
+{
+ xmlChar *result = NULL;
+ int type = fileType;
+ int preferHtml = optionsGetIntOption(OPTIONS_PREFER_HTML);
+ const xmlChar *baseDir = NULL;
+ const xmlChar *name = NULL;
+ static const char *searchNames[] = {
+ /* Note: File names here are in native format, to be appended to the
+ * help directory name or search results path
+ */
+ /* First list names when prefer html is false */
+ "searchresult.xml", /* input */
+ "search.xsl", /* stylesheet to use */
+ "searchresult.txt", /* where to put the result */
+ /*Now for the names to use when prefer html is true */
+ "searchresult.xml", /* input */
+ "searchhtml.xsl", /* stylesheet to use */
+ "searchresult.html" /* where to put the result */
+ };
+
+ if (!optionsGetStringOption(OPTIONS_DOCS_PATH)
+ || !filesSearchResultsPath()) {
+ xsldbgGenericErrorFunc(i18n("Error: The value of the option docspath or searchresultspath is empty. See help on setoption or options command for more information.\n"));
+ return result;
+ }
+
+
+ name = (xmlChar *) searchNames[(preferHtml * 3) + type];
+ switch (type) {
+ case FILES_SEARCHINPUT:
+ baseDir = filesSearchResultsPath();
+ break;
+
+ case FILES_SEARCHXSL:
+ baseDir = optionsGetStringOption(OPTIONS_DOCS_PATH);
+ break;
+
+ case FILES_SEARCHRESULT:
+ baseDir = filesSearchResultsPath();
+ break;
+ }
+
+ result = (xmlChar*)xmlMalloc(xmlStrLen(baseDir) + xmlStrLen(name) + 1);
+ if (result) {
+ xmlStrCpy(result, baseDir);
+ xmlStrCat(result, name);
+ }
+ return result;
+}
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/help.h b/kxsldbg/kxsldbgpart/libxsldbg/help.h
new file mode 100644
index 00000000..de77a71d
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/help.h
@@ -0,0 +1,73 @@
+
+/***************************************************************************
+ help.h - describe the help support functions
+ -------------------
+ begin : Sun Sep 16 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 XSLDBG_HELP_H
+#define XSLDBG_HELP_H
+
+#ifdef USE_KDE_DOCS
+
+/**
+ * Provide a help system for user
+ *
+ * @short help system support
+ *
+ * @author Keith Isdale <k_isdale@tpg.com.au>
+ */
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#ifdef USE_GNOME_DOCS
+
+/**
+ * helpTop:
+ * @args : Is valid command or empty string
+ *
+ * Display help about the command in @arg
+ *
+ * This is a platform specific interface
+ *
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+#else
+#ifdef USE_KDE_DOCS
+
+/**
+ * Display help about the command in @p arg
+ *
+ *
+ * This is a platform specific interface
+ *
+ * @param args Is valid or empty string
+ * @returns 1 on success,
+ * 0 otherwise
+ */
+#endif
+#endif
+ int helpTop(const xmlChar * args);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/help_unix.cpp b/kxsldbg/kxsldbgpart/libxsldbg/help_unix.cpp
new file mode 100644
index 00000000..d3e91f92
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/help_unix.cpp
@@ -0,0 +1,115 @@
+
+/***************************************************************************
+ help.c - help system for *nix platform
+ -------------------
+ begin : Tue Jan 29 2002
+ 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. *
+ * *
+ ***************************************************************************/
+
+/*
+ * Uses docs/xsldoc.xsl docs/xsldoc.xml and xslproc to generate text
+ */
+
+#include "xsldbg.h"
+#include "options.h"
+#include "utils.h"
+#include "debugXSL.h"
+#include "help.h"
+#include "files.h"
+#include <stdlib.h>
+#include <kglobal.h>
+#include <kstandarddirs.h>
+
+/**
+ * helpTop:
+ * @args : Is valid command or empty string
+ *
+ * Display help about the command in @args
+ *
+ * This is a platform specific interface
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+helpTop(const xmlChar * args)
+{
+
+ //Extra phrases to support translation of help display see kdewebdev/doc/xsldbg/xsldbghelp.xml and kdewebdev/kxsldbg/xsldbghelp.xsl
+ static const char* xsldbghelp_translations[] =
+ {
+ I18N_NOOP("xsldbg version"),
+ I18N_NOOP("Help document version"),
+ I18N_NOOP("Help not found for command")
+ };
+
+ QString xsldbgVerTxt(i18n("xsldbg version"));
+ QString helpDocVerTxt(i18n("Help document version"));
+ QString helpErrorTxt(i18n("Help not found for command"));
+
+
+ char buff[500], helpParam[100];
+
+ const char *docsDirPath =
+ (const char *) optionsGetStringOption(OPTIONS_DOCS_PATH);
+ int result = 0;
+
+ if (xmlStrLen(args) > 0) {
+ snprintf(helpParam, 100, "--param help:%c'%s'%c", QUOTECHAR, args,
+ QUOTECHAR);
+ } else
+ xmlStrCpy(helpParam, "");
+ if (docsDirPath && filesTempFileName(0)) {
+ snprintf((char *) buff, sizeof(buff), "%s %s"
+ " --param xsldbg_version:%c'%s'%c "
+ " --param xsldbgVerTxt:%c'%s'%c "
+ " --param helpDocVerTxt:%c'%s'%c "
+ " --param helpErrorTxt:%c'%s'%c "
+ " --output %s "
+ " --cd %s "
+ "xsldbghelp.xsl xsldbghelp.xml",
+ XSLDBG_BIN, helpParam,
+ QUOTECHAR, VERSION, QUOTECHAR,
+ QUOTECHAR, xsldbgVerTxt.utf8().data(), QUOTECHAR,
+ QUOTECHAR, helpDocVerTxt.utf8().data(), QUOTECHAR,
+ QUOTECHAR, helpErrorTxt.utf8().data(), QUOTECHAR,
+ filesTempFileName(0),
+ docsDirPath);
+ if (xslDbgShellExecute((xmlChar *) buff, optionsGetIntOption(OPTIONS_VERBOSE)) == 0) {
+ if (docsDirPath)
+ xsldbgGenericErrorFunc(i18n("Error: Unable to display help. Help files not found in %1 or xsldbg not found in path.\n").arg(docsDirPath)); /* FIXME: Comments not correct - the command is that invoked */
+ else
+ xsldbgGenericErrorFunc(i18n("Error: Unable to find xsldbg or help files.\n"));
+ } else {
+ if (filesMoreFile((xmlChar*)filesTempFileName(0), NULL) == 1) {
+ result = 1;
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to print help file.\n"));
+ }
+ }
+
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: No path to documentation; aborting help.\n"));
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+#ifdef USE_DOCS_MACRO
+ xsltGenericError(xsltGenericErrorContext,"MACRO has been defined look at Makefile.am\n");
+#else
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Environment variable %s is not set to the directory of xsldbg documentation.\n",
+ XSLDBG_DOCS_DIR_VARIABLE);
+#endif
+#endif
+ }
+ return result;
+}
+
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/nodeview_cmds.cpp b/kxsldbg/kxsldbgpart/libxsldbg/nodeview_cmds.cpp
new file mode 100644
index 00000000..5fcbef00
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/nodeview_cmds.cpp
@@ -0,0 +1,609 @@
+
+/***************************************************************************
+ nodeview_cmds.c - node viewing commands for xsldbg
+ -------------------
+ begin : Wed Nov 21 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 "xsldbg.h"
+#include <libxml/xpathInternals.h>
+#include <libxml/HTMLparser.h>
+#include <libxml/HTMLtree.h>
+#include <ctype.h> /* for isspace*/
+#include "debugXSL.h"
+#include "arraylist.h"
+#include "breakpoint.h"
+#include "xsldbgmsg.h"
+#include "xsldbgthread.h" /* for getThreadStatus */
+#include "files.h"
+#include "options.h"
+
+
+/* -----------------------------------------
+ Private function declarations for nodeview_cmds.c
+ -------------------------------------------*/
+static xmlChar nodeViewBuffer[500];
+static int printVariableValue = 0;
+
+/*
+ * xslDbgShellPrintNames:
+ * Print a name of variable found by scanning variable table
+ * It is used by print_variable function.
+ * @payload : not used
+ * @data : not used
+ * @name : the variable name
+ */
+void *xslDbgShellPrintNames(void *payload,
+ void *data, xmlChar * name);
+
+/**
+ * xslDbgCatToFile:
+ * @node : Is valid
+ * @file : Is valid
+ *
+ * Send the results of cat command in @node to @file
+ */
+static void xslDbgCatToFile(xmlNodePtr node, FILE * file);
+
+
+/**
+ * printXPathObject:
+ * @item : XPath object to print
+ * @xPath : The XPath used to find item
+ *
+ * Print an XPath object
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+static int printXPathObject(xmlXPathObjectPtr item, xmlChar* xPath);
+
+/* -------------------------------------
+ End private functions
+---------------------------------------*/
+
+
+/**
+ * xslDbgShellPrintList:
+ * @ctxt: The current shell context
+ * @arg: What xpath to display and in UTF-8
+ * @dir: If 1 print in dir mode?,
+ * otherwise ls mode
+ *
+ * Print list of nodes in either ls or dir format
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+xslDbgShellPrintList(xmlShellCtxtPtr ctxt, xmlChar * arg, int dir)
+{
+ xmlXPathObjectPtr list;
+ int result = 0;
+
+ if (!ctxt || !arg) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: NULL arguments provided\n");
+#endif
+ return result;
+ }
+
+ if (arg[0] == 0) {
+ if (dir)
+ xmlShellDir(ctxt, NULL, ctxt->node, NULL);
+ else
+ xmlShellList(ctxt, NULL, ctxt->node, NULL);
+ result = 1; /*assume that this worked */
+ } else {
+ ctxt->pctxt->node = ctxt->node;
+ ctxt->pctxt->node = ctxt->node;
+ if (!xmlXPathNsLookup(ctxt->pctxt, (xmlChar *) "xsl"))
+ xmlXPathRegisterNs(ctxt->pctxt, (xmlChar *) "xsl",
+ XSLT_NAMESPACE);
+ list = xmlXPathEval(arg, ctxt->pctxt);
+ if (list != NULL) {
+ switch (list->type) {
+ case XPATH_NODESET:{
+ int indx;
+
+ for (indx = 0;
+ indx < list->nodesetval->nodeNr; indx++) {
+ if (dir)
+ xmlShellList(ctxt, NULL,
+ list->nodesetval->
+ nodeTab[indx], NULL);
+ else
+ xmlShellList(ctxt, NULL,
+ list->nodesetval->
+ nodeTab[indx], NULL);
+ }
+ result = 1;
+ break;
+ }
+ default:
+ xmlShellPrintXPathError(list->type, (char *) arg);
+ }
+ xmlXPathFreeObject(list);
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: XPath %1 results in an empty Node Set.\n").arg(xsldbgText(arg)));
+ }
+ ctxt->pctxt->node = NULL;
+ }
+ return result;
+}
+
+
+
+/**
+ * xslDbgCatToFile:
+ * @node : Is valid
+ * @file : Is valid
+ *
+ * Send the results of cat command in @node to @file
+ */
+void
+xslDbgCatToFile(xmlNodePtr node, FILE * file)
+{
+ if (!node || !file)
+ return;
+
+ /* assume that HTML usage is enabled */
+ if (node->doc->type == XML_HTML_DOCUMENT_NODE) {
+ if (node->type == XML_HTML_DOCUMENT_NODE)
+ htmlDocDump(file, (htmlDocPtr) node);
+ else
+ htmlNodeDumpFile(file, node->doc, node);
+ } else if (node->type == XML_DOCUMENT_NODE) {
+ /* turn off encoding for the moment and just dump UTF-8
+ * which will be converted by xsldbgGeneralErrorFunc */
+ xmlDocPtr doc = (xmlDocPtr) node;
+ const xmlChar *encoding = doc->encoding;
+
+ if (encoding) {
+ xsldbgGenericErrorFunc(i18n("Information: Temporarily setting document's encoding to UTF-8. Previously was %1.\n").arg(xsldbgText(encoding)));
+ }
+ doc->encoding = (xmlChar *) "UTF-8";
+ xmlDocDump(file, (xmlDocPtr) node);
+ doc->encoding = encoding;
+ } else {
+ xmlElemDump(file, node->doc, node);
+ }
+}
+
+
+/**
+ * printXPathObject:
+ * @item : XPath object to print
+ * @xPath : The XPath used to find item
+ *
+ * Print an XPath object
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+
+static int
+printXPathObject(xmlXPathObjectPtr item, xmlChar* xPath){
+ int result = 0;
+ if (item){
+ switch (item->type) {
+ case XPATH_BOOLEAN:
+ xsltGenericError(xsltGenericErrorContext,
+ "= %s\n%s\n", xPath,
+ xmlBoolToText(item->boolval));
+ result = 1;
+ break;
+
+ case XPATH_NUMBER:
+ xsltGenericError(xsltGenericErrorContext,
+ "= %s\n%0g\n", xPath, item->floatval);
+ result = 1;
+ break;
+
+ /* case XPATH_NODESET:*/
+ default:{
+ /* We may need to convert this XPath to a string,
+ plus ensure that we print required the number of
+ lines of text */
+ int indx;
+
+ const char *fileName = filesTempFileName(0);
+ FILE *file = NULL;
+
+ if (!fileName)
+ break;
+ file = fopen(fileName, "w+");
+ if (!file) {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to save temporary results to %1.\n").arg(xsldbgText(fileName)));
+ break;
+ } else {
+ fprintf(file, "= %s\n", xPath);
+ switch(item->type){
+
+ case XPATH_NODESET:
+ if (item->nodesetval){
+ for (indx = 0;
+ indx < item->nodesetval->nodeNr; indx++){
+ xslDbgCatToFile(item->nodesetval->
+ nodeTab[indx], file);
+ }
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: XPath %1 results in an empty Node Set.\n").arg(xsldbgText(xPath)));
+ }
+ break;
+
+ case XPATH_STRING:
+ if (item->stringval)
+ fprintf(file, "\'%s\'", item->stringval);
+ else
+ fprintf(file, "%s", i18n("NULL string value supplied.").utf8().data());
+ break;
+
+ default:{
+ xmlXPathObjectPtr tempObj =
+ xmlXPathObjectCopy(item);
+ if (tempObj)
+ tempObj = xmlXPathConvertString(tempObj);
+ if (tempObj && tempObj->stringval){
+ fprintf(file, "%s", tempObj->stringval);
+ }else{
+ fprintf(file, "%s", i18n("Unable to convert XPath to string.").utf8().data());
+ }
+ if (tempObj)
+ xmlXPathFreeObject(tempObj);
+ }
+ break;
+ fprintf(file,"\n");
+
+ } /* inner switch statement */
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
+ fclose(file);
+ file = NULL;
+ /* send the data to application */
+ notifyXsldbgApp(XSLDBG_MSG_FILEOUT, fileName);
+ } else {
+ int lineCount = 0, gdbModeEnabled = 0;
+
+ /* save the value of option to speed things up
+ * a bit */
+ gdbModeEnabled =
+ optionsGetIntOption(OPTIONS_GDB);
+ rewind(file);
+
+ /* when gdb mode is enable then only print the first
+ * GDB_LINES_TO_PRINT lines */
+ while (!feof(file)) {
+ if (fgets
+ ((char *) nodeViewBuffer, sizeof(nodeViewBuffer),
+ file))
+ xsltGenericError
+ (xsltGenericErrorContext, "%s",
+ nodeViewBuffer);
+ if (gdbModeEnabled) {
+ lineCount++;
+ /* there is an overhead of two lines
+ * when print expression values */
+ if (lineCount ==
+ GDB_LINES_TO_PRINT + 2) {
+ xsltGenericError
+ (xsltGenericErrorContext,
+ "...");
+ break;
+ }
+ }
+ }
+ xsltGenericError
+ (xsltGenericErrorContext, "\n");
+ }
+ if (file)
+ fclose(file);
+ result = 1;
+ break;
+ }
+ }
+ }
+ }
+ return result;
+}
+
+
+/**
+ * xslDbgShellCat:
+ * @styleCtxt: the current stylesheet context
+ * @ctxt: The current shell context
+ * @arg: The xpath to print (in UTF-8)
+ *
+ * Print the result of an xpath expression. This can include variables
+ * if styleCtxt is not NULL
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+
+int
+xslDbgShellCat(xsltTransformContextPtr styleCtxt, xmlShellCtxtPtr ctxt,
+ xmlChar * arg)
+{
+ xmlXPathObjectPtr list;
+ int result = 0;
+ static const char * QUIET_STR = "-q";
+ bool silenceCtxtErrors = false;
+
+ if ((arg == NULL) || (xmlStrLen(arg) == 0))
+ arg = (xmlChar *) ".";
+
+ /* Do we quietly ingore style context errors */
+ if (strncasecmp((char*)arg, QUIET_STR, strlen(QUIET_STR))== 0){
+ silenceCtxtErrors = true;
+ arg = arg + strlen(QUIET_STR);
+ while (isspace(*arg)){
+ arg++;
+ }
+ }
+
+ if (!styleCtxt || !ctxt || !ctxt->node) {
+ if (!(!xsldbgReachedFirstTemplate && silenceCtxtErrors))
+ xsldbgGenericErrorFunc(i18n("Warning: Unable to print expression. No stylesheet was properly loaded.\n"));
+ return 0;
+ }
+
+ if ((arg == NULL) || (xmlStrLen(arg) == 0))
+ arg = (xmlChar *) ".";
+
+ ctxt->pctxt->node = ctxt->node;
+ if (!styleCtxt) {
+ list = xmlXPathEval((xmlChar *) arg, ctxt->pctxt);
+ } else {
+ xmlNodePtr savenode = styleCtxt->xpathCtxt->node;
+
+ ctxt->pctxt->node = ctxt->node;
+ styleCtxt->xpathCtxt->node = ctxt->node;
+ if (!xmlXPathNsLookup(styleCtxt->xpathCtxt, (xmlChar *) "xsl"))
+ xmlXPathRegisterNs(styleCtxt->xpathCtxt, (xmlChar *) "xsl",
+ XSLT_NAMESPACE);
+ list = xmlXPathEval((xmlChar *) arg, styleCtxt->xpathCtxt);
+ styleCtxt->xpathCtxt->node = savenode;
+ }
+ if (list != NULL) {
+ result = printXPathObject(list, arg);
+ xmlXPathFreeObject(list);
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: XPath %1 results in an empty Node Set.\n").arg(xsldbgText(arg)));
+ }
+ ctxt->pctxt->node = NULL;
+ return result;
+}
+
+/* only used by xslDbgPrintNames and xslDbgPrintVariable cound number of variables */
+static int varCount;
+
+/*
+ * xslDbgShellPrintNames:
+ * Print a name of variable found by scanning variable table
+ * It is used by print_variable function.
+ * @payload : Global variable of type xsltStackElemPtr
+ * @data : not used
+ * @name : the variable name
+ */
+void *
+xslDbgShellPrintNames(void *payload,
+ void *data, xmlChar * name)
+{
+ Q_UNUSED(payload);
+ Q_UNUSED(data);
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
+ notifyListQueue(payload);
+ } else if (payload && name) {
+ xmlChar * fullQualifiedName = nodeViewBuffer;
+ xsltStackElemPtr item = (xsltStackElemPtr)payload;
+ if (item->nameURI == NULL){
+ snprintf((char*)fullQualifiedName, sizeof(nodeViewBuffer), "$%s", item->name);
+ }else{
+ snprintf((char*)fullQualifiedName, sizeof(nodeViewBuffer), "$%s:%s",
+ item->nameURI, item->name);
+ }
+ if (printVariableValue == 0){
+ xsldbgGenericErrorFunc(i18n(" Global %1\n").arg(xsldbgText(fullQualifiedName)));
+ }else{
+ if (item->computed == 1){
+ xsldbgGenericErrorFunc(i18n(" Global "));
+ printXPathObject(item->value, fullQualifiedName);
+ }else if (item->tree){
+ xsldbgGenericErrorFunc(i18n(" Global = %1\n").arg(xsldbgText(fullQualifiedName)));
+ xslDbgCatToFile(item->tree, stderr);
+ }else if (item->select){
+ xsldbgGenericErrorFunc(i18n(" Global = %1\n%2").arg(xsldbgText(fullQualifiedName)).arg(xsldbgText(item->select)));
+ }else{
+ /* can't find a value give only a variable name an error message */
+ xsldbgGenericErrorFunc(i18n(" Global = %1\n%2").arg(xsldbgText(fullQualifiedName)).arg(i18n("Warning: No value assigned to variable.\n")));
+ }
+ xsltGenericError(xsltGenericErrorContext, "\n\032\032\n");
+ }
+ varCount++;
+ }
+ return NULL;
+}
+
+
+
+/**
+ * xslDbgShellPrintVariable:
+ * @styleCtxt: The current stylesheet context
+ * @arg: The name of variable to look for '$' prefix is optional and in UTF-8
+ * @type: A valid VariableTypeEnum
+ *
+ * Print the value variable specified by args.
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+xslDbgShellPrintVariable(xsltTransformContextPtr styleCtxt, xmlChar * arg,
+ VariableTypeEnum type)
+{
+ int result = 0;
+ /* command argument to include both name and its value */
+ static const char * FULLNAME_STR = "-f";
+ /* Quietly exit if an invalid stylesheet is provided */
+ static const char * QUIET_STR = "-q";
+ bool silenceCtxtErrors = false;
+
+ if (!arg) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: NULL argument provided\n");
+#endif
+ return result;
+ }
+
+ varCount = 0;
+ /* Do we quietly ingore style context errors */
+ if (strncasecmp((char*)arg, QUIET_STR, strlen(QUIET_STR))== 0){
+ silenceCtxtErrors = true;
+ arg = arg + strlen(QUIET_STR);
+ while (isspace(*arg)){
+ arg++;
+ }
+ }
+
+ if (!styleCtxt) {
+ if (!(!xsldbgReachedFirstTemplate && silenceCtxtErrors))
+ xsldbgGenericErrorFunc(i18n("Error: Debugger has no files loaded or libxslt has not reached a template.\nTry reloading files or taking more steps.\n"));
+ return result;
+ }
+
+ /* Do we include the name as well as its value */
+ if (strncasecmp((char*)arg, FULLNAME_STR, strlen(FULLNAME_STR))== 0){
+ printVariableValue = 1;
+ arg = arg + strlen(FULLNAME_STR);
+ while (isspace(*arg)){
+ arg++;
+ }
+ }
+ if (arg[0] == 0) {
+ /* list variables of type requested */
+ if (type == DEBUG_GLOBAL_VAR) {
+ if (styleCtxt->globalVars) {
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
+ notifyListStart(XSLDBG_MSG_GLOBALVAR_CHANGED);
+ /* list global variables */
+ xmlHashScan(styleCtxt->globalVars,
+ (xmlHashScanner) xslDbgShellPrintNames,
+ NULL);
+ notifyListSend();
+ } else
+ /* list global variables */
+ xmlHashScan(styleCtxt->globalVars,
+ (xmlHashScanner) xslDbgShellPrintNames,
+ NULL);
+ result = 1;
+ /* ensure that the locals follow imediately after the
+ * globals when in gdb mode */
+ if (optionsGetIntOption(OPTIONS_GDB) == 0)
+ xsltGenericError(xsltGenericErrorContext, "\n");
+ } else {
+ if (getThreadStatus() != XSLDBG_MSG_THREAD_RUN) {
+ /* Don't show this message when running as a thread as it
+ * is annoying */
+ xsldbgGenericErrorFunc(i18n("Error: Libxslt has not initialized variables yet; try stepping to a template.\n"));
+ } else {
+ /* send an empty list */
+ notifyListStart(XSLDBG_MSG_GLOBALVAR_CHANGED);
+ notifyListSend();
+ result = 1;
+ }
+ }
+ } else {
+ /* list local variables */
+ if (styleCtxt->varsNr && styleCtxt->varsTab) {
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
+ notifyListStart(XSLDBG_MSG_LOCALVAR_CHANGED);
+ for (int i = styleCtxt->varsNr; i > styleCtxt->varsBase; i--) {
+ xsltStackElemPtr item = styleCtxt->varsTab[i-1];
+ while (item) {
+ notifyListQueue(item);
+ item = item->next;
+ }
+ }
+ notifyListSend();
+ } else {
+ xmlChar * fullQualifiedName = nodeViewBuffer;
+ for (int i = styleCtxt->varsNr; i > styleCtxt->varsBase; i--) {
+ xsltStackElemPtr item = styleCtxt->varsTab[i-1];
+ while (item) {
+ if (item->name) {
+ if (item->nameURI == NULL){
+ snprintf((char*)fullQualifiedName, sizeof(nodeViewBuffer), "$%s",
+ item->name);
+ }else{
+
+ snprintf((char*)fullQualifiedName, sizeof(nodeViewBuffer), "$%s:%s",
+ item->nameURI, item->name);
+ }
+ if (printVariableValue == 0){
+ xsldbgGenericErrorFunc(i18n(" Local %1").arg(xsldbgText(fullQualifiedName)));
+ }else{
+ if (item->computed == 1){
+ xsldbgGenericErrorFunc(i18n(" Local "));
+ printXPathObject(item->value, fullQualifiedName);
+ }else if (item->tree){
+ xsldbgGenericErrorFunc(i18n(" Local = %1\n").arg(xsldbgText(fullQualifiedName)));
+ xslDbgCatToFile(item->tree, stderr);
+ }else if (item->select){
+ xsldbgGenericErrorFunc(i18n(" Local = %1\n%2").arg(xsldbgText(fullQualifiedName)).arg(xsldbgText(item->select)));
+ }else{
+ /* can't find a value give only a variable name and an error */
+ xsldbgGenericErrorFunc(i18n(" Local = %1\n%2").arg(xsldbgText(fullQualifiedName)).arg(i18n("Warning: No value assigned to variable.\n")));
+ }
+ }
+ xsltGenericError(xsltGenericErrorContext, "\n\032\032\n");
+ }
+ item = item->next;
+ }
+ }
+ }
+ result = 1;
+ xsltGenericError(xsltGenericErrorContext, "\n");
+ } else {
+ if (getThreadStatus() != XSLDBG_MSG_THREAD_RUN) {
+ /* Don't show this message when running as a thread as it
+ * is annoying */
+ xsldbgGenericErrorFunc(i18n("Error: Libxslt has not initialized variables yet; try stepping past the xsl:param elements in the template.\n"));
+ } else {
+ /* send an empty list */
+ notifyListStart(XSLDBG_MSG_LOCALVAR_CHANGED);
+ notifyListSend();
+ result = 1;
+ }
+ }
+ }
+ } else {
+ /* Display the value of variable */
+ if (arg[0] == '$') {
+ printXPathObject(xmlXPathEval(arg, styleCtxt->xpathCtxt), arg);
+ xsltGenericError(xsltGenericErrorContext, "\032\032\n");
+ } else {
+ xmlStrCpy(nodeViewBuffer, "$");
+ xmlStrCat(nodeViewBuffer, arg);
+ printXPathObject(xmlXPathEval((xmlChar*)nodeViewBuffer,styleCtxt->xpathCtxt),
+ (xmlChar*)nodeViewBuffer);
+ xsltGenericError(xsltGenericErrorContext, "\032\032\n");
+ }
+
+ }
+
+ printVariableValue = 0;
+ return result;
+}
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/option_cmds.cpp b/kxsldbg/kxsldbgpart/libxsldbg/option_cmds.cpp
new file mode 100644
index 00000000..0bc54364
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/option_cmds.cpp
@@ -0,0 +1,299 @@
+
+/***************************************************************************
+ option_cmds.c - implementation for option
+ related commands
+
+ -------------------
+ 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 "xsldbg.h"
+#include "utils.h"
+#include "options.h"
+#include "xsldbgmsg.h"
+#include "xsldbgthread.h"
+#include "debugXSL.h"
+
+
+/**
+ * xslDbgShellSetOption:
+ * @arg : Is valid, and in the format <NAME> <VALUE>
+ *
+ * Set the value of an option
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+xslDbgShellSetOption(xmlChar * arg)
+{
+ int result = 0;
+
+ if (!arg) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: NULL argument provided\n");
+#endif
+ return result;
+ }
+
+ if (xmlStrLen(arg) > 0) {
+ xmlChar *opts[2];
+ long optValue;
+ long optID;
+
+
+ if (splitString(arg, 2, opts) == 2) {
+ bool invertOption = false;
+ optID = optionsGetOptionID(opts[0]);
+ if ((optID == -1) && (opts[0][0] == 'n') && (opts[0][1] == 'o')){
+ optID = optionsGetOptionID(&opts[0][2]);
+ if (optID != -1){
+ // invert the value the user provides
+ invertOption = true;
+ }
+ }
+
+ if (optID >= OPTIONS_FIRST_INT_OPTIONID) {
+ if (optID <= OPTIONS_LAST_INT_OPTIONID) {
+ /* handle setting integer option */
+ if ((xmlStrlen(opts[1]) == 0) ||
+ !sscanf((char *) opts[1], "%ld", &optValue)) {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to parse %1 as an option value.\n").arg(xsldbgText(opts[1])));
+ } else {
+ if (invertOption)
+ optValue = !optValue;
+ result = optionsSetIntOption(OptionTypeEnum(optID), optValue);
+ }
+ } else {
+ /* handle setting a string option */
+ result = optionsSetStringOption(OptionTypeEnum(optID), opts[1]);
+
+ }
+ } else {
+ static xmlExternalEntityLoader xsldbgDefaultEntLoader = 0;
+ bool invertOption = false;
+ bool enableNet = false;
+
+ if (!xsldbgDefaultEntLoader)
+ xsldbgDefaultEntLoader = xmlGetExternalEntityLoader();
+
+ if (xmlStrEqual(opts[0], (const xmlChar *)"nonet" ))
+ invertOption = true;
+
+ if (xmlStrEqual(&opts[0][2*invertOption], (const xmlChar *)"net" )){
+ if (sscanf((char *) opts[1], "%ld", &optValue)) {
+ if (invertOption)
+ optValue = !optValue;
+ if (optValue)
+ enableNet = true;
+ result = true;
+ if (enableNet)
+ xmlSetExternalEntityLoader(xsldbgDefaultEntLoader);
+ else
+ xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader);
+ }else{
+ xsldbgGenericErrorFunc(i18n("Error: Unable to parse %1 as an option value.\n").arg(xsldbgText(opts[1])));
+ }
+ } else
+ xsldbgGenericErrorFunc(i18n("Error: Unknown option name %1.\n").arg(xsldbgText(opts[0])));
+ }
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Missing arguments for the command %1.\n").arg("setoption"));
+ }
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Missing arguments for the command %1.\n").arg("setoption"));
+ }
+
+ return result;
+}
+
+
+
+/**
+ * xslDbgShellOptions:
+ *
+ * Prints out values for user options
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+xslDbgShellOptions(void)
+{
+ int result = 1;
+ int optionIndex;
+ const xmlChar *optionName, *optionValue;
+
+ /* Print out the integer options and thier values */
+ if (getThreadStatus() != XSLDBG_MSG_THREAD_RUN) {
+ for (optionIndex = OPTIONS_XINCLUDE;
+ optionIndex <= OPTIONS_VERBOSE; optionIndex++) {
+ /* skip any non-user options */
+ optionName = optionsGetOptionName(OptionTypeEnum(optionIndex));
+ if (optionName && (optionName[0] != '*')) {
+ xsldbgGenericErrorFunc(i18n("Option %1 = %2\n").arg(xsldbgText(optionName)).arg(optionsGetIntOption(OptionTypeEnum(optionIndex))));
+
+ }
+ }
+ /* Print out the string options and thier values */
+ for (optionIndex = OPTIONS_OUTPUT_FILE_NAME;
+ optionIndex <= OPTIONS_DATA_FILE_NAME; optionIndex++) {
+ optionName = optionsGetOptionName(OptionTypeEnum(optionIndex));
+ if (optionName && (optionName[0] != '*')) {
+ optionValue = optionsGetStringOption(OptionTypeEnum(optionIndex));
+ if (optionValue) {
+ xsldbgGenericErrorFunc(i18n("Option %1 = \"%2\"\n").arg(xsldbgText(optionName)).arg((char*)optionValue));
+ } else {
+ xsldbgGenericErrorFunc(i18n("Option %1 = \"\"\n").arg(xsldbgText(optionName)));
+
+ }
+ }
+
+ }
+ xsldbgGenericErrorFunc("\n");
+ } else {
+ /* we are now notifying the application of the value of options */
+ parameterItemPtr paramItem;
+
+ notifyListStart(XSLDBG_MSG_INTOPTION_CHANGE);
+ /* send the integer options and their values */
+ for (optionIndex = OPTIONS_XINCLUDE;
+ optionIndex <= OPTIONS_VERBOSE; optionIndex++) {
+ /* skip any non-user options */
+ optionName = optionsGetOptionName(OptionTypeEnum(optionIndex));
+ if (optionName && (optionName[0] != '*')) {
+ paramItem = optionsParamItemNew(optionName, 0L);
+ if (!paramItem) {
+ notifyListSend(); /* send what ever we've got so far */
+ return 0; /* out of memory */
+ }
+ paramItem->intValue = optionsGetIntOption(OptionTypeEnum(optionIndex));
+ notifyListQueue(paramItem); /* this will be free later */
+ }
+ }
+
+ notifyListSend();
+ notifyListStart(XSLDBG_MSG_STRINGOPTION_CHANGE);
+ /* Send the string options and thier values */
+ for (optionIndex = OPTIONS_OUTPUT_FILE_NAME;
+ optionIndex <= OPTIONS_DATA_FILE_NAME; optionIndex++) {
+ optionName = optionsGetOptionName(OptionTypeEnum(optionIndex));
+ if (optionName && (optionName[0] != '*')) {
+ paramItem =
+ optionsParamItemNew(optionName,
+ optionsGetStringOption
+ (OptionTypeEnum(optionIndex)));
+ if (!paramItem) {
+ notifyListSend(); /* send what ever we've got so far */
+ return 0; /* out of memory */
+ } else
+ notifyListQueue(paramItem); /* this will be freed later */
+ }
+ }
+ notifyListSend();
+ }
+
+ return result;
+}
+
+
+ /**
+ * xslDbgShellShowWatches:
+ * @styleCtxt: the current stylesheet context
+ * @ctxt: The current shell context
+ * @showWarnings : If 1 then showWarning messages,
+ * otherwise do not show warning messages
+ *
+ * Print the current watches and their values
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+ int xslDbgShellShowWatches(xsltTransformContextPtr styleCtxt,
+ xmlShellCtxtPtr ctx,int showWarnings)
+{
+ int result = 0, counter;
+ xmlChar* watchExpression;
+ if ((showWarnings == 1) && (arrayListCount(optionsGetWatchList()) == 0)){
+ xsldbgGenericErrorFunc(i18n("\tNo expression watches set.\n"));
+ }
+ for ( counter = 0;
+ counter < arrayListCount(optionsGetWatchList());
+ counter++){
+ watchExpression = (xmlChar*)arrayListGet(optionsGetWatchList(), counter);
+ if (watchExpression){
+ xsldbgGenericErrorFunc(i18n(" WatchExpression %1 ").arg(counter + 1));
+ result = xslDbgShellCat(styleCtxt, ctx, watchExpression);
+ }else
+ break;
+ }
+
+ return result;
+}
+
+
+ /**
+ * xslDbgShellAddWatch:
+ * @arg : A valid xPath of expression to watch the value of
+ *
+ * Add expression to list of expressions to watch value of
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+ int xslDbgShellAddWatch(xmlChar* arg)
+{
+ int result = 0;
+ if (arg){
+ trimString(arg);
+ result = optionsAddWatch(arg);
+ if (!result)
+ xsldbgGenericErrorFunc(i18n("Error: Unable to add watch expression \"%1\". It already has been added or it cannot be watched.\n").arg(xsldbgText(arg)));
+ }
+ return result;
+}
+
+ /**
+ * xslDbgShellDeleteWatch:
+ * @arg : A watch ID to remove or "*" to remove all watches
+ *
+ * Delete a given watch ID from our list of expressions to watch
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+ int xslDbgShellDeleteWatch(xmlChar* arg)
+{
+ int result = 0;
+ long watchID;
+ if (arg){
+ trimString(arg);
+ if (arg[0] == '*') {
+ arrayListEmpty(optionsGetWatchList());
+ }else if ((xmlStrlen(arg) == 0) ||
+ !sscanf((char *) arg, "%ld", &watchID)) {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to parse %1 as a watchID.\n").arg(xsldbgText(arg)));
+ return result;
+ } else {
+ result = optionsRemoveWatch(watchID);
+ if (!result)
+ xsldbgGenericErrorFunc(i18n("Error: Watch expression %1 does not exist.\n").arg(watchID));
+ }
+ }
+ return result;
+}
+
+
+
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/options.cpp b/kxsldbg/kxsldbgpart/libxsldbg/options.cpp
new file mode 100644
index 00000000..9f667eb3
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/options.cpp
@@ -0,0 +1,902 @@
+
+/***************************************************************************
+ options.c - provide the implementation for option
+ related functions
+ -------------------
+ begin : Sat Nov 10 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 "xsldbg.h"
+#include "xsldbgthread.h"
+#include "options.h"
+#include "arraylist.h"
+#include "xsldbgmsg.h"
+#include "utils.h"
+#include <kglobal.h>
+#include <kstandarddirs.h>
+#include <qfileinfo.h>
+#include <qstringlist.h>
+
+
+/* keep track of our integer/boolean options */
+static int intOptions[OPTIONS_LAST_INT_OPTIONID - OPTIONS_FIRST_INT_OPTIONID + 1];
+
+/* make use that use of options are safe by only copying
+ critical values from intVolitleOptions just before stylesheet is started
+ */
+int intVolitileOptions[OPTIONS_LAST_INT_OPTIONID - OPTIONS_FIRST_INT_OPTIONID + 1];
+
+/* keep track of our string options */
+static xmlChar *stringOptions[OPTIONS_LAST_STRING_OPTIONID -
+ OPTIONS_FIRST_STRING_OPTIONID + 1];
+
+/* keep track of our parameters */
+static arrayListPtr parameterList;
+
+/* what are the expressions to be printed out when xsldbg stops */
+static arrayListPtr watchExpressionList;
+
+
+/* the names for our options
+ Items that start with *_ are options that CANNOT be used by the user
+ Once you set an option you need to give a run command to activate
+ new settings */
+const char *optionNames[] = {
+ "xinclude", /* Use xinclude during xml parsing */
+ "docbook", /* Use of docbook sgml parsing */
+ "timing", /* Use of timing */
+ "profile", /* Use of profiling */
+ "valid", /* Enable file validation */
+ "out", /* Enable output to stdout */
+ "html", /* Enable the use of html parsing */
+ "debug", /* Enable the use of xml tree debugging */
+ "shell", /* Enable the use of debugger shell */
+ "gdb", /* Run in gdb modem prints more messages */
+ "preferhtml", /* Prefer html output for search results */
+ "autoencode", /* Try to use the encoding from the stylesheet */
+ "utf8input", /* All input from "user" will be in UTF-8 */
+ "stdout", /* Print all error messages to stdout,
+ * normally error messages go to stderr */
+ "autorestart", /* When finishing the debug of a XSLT script
+ automaticly restart at the beginning */
+ "verbose", /* Be verbose with messages */
+ "repeat", /* The number of times to repeat */
+ "*_trace_*", /* Trace execution */
+ "*_walkspeed_*", /* How fast do we walk through code */
+ "catalogs", /* do we use catalogs in SGML_CATALOG_FILES */
+ "output", /* what is the output file name */
+ "source", /* The stylesheet source to use */
+ "docspath", /* Path of xsldbg's documentation */
+ "catalognames", /* The names of the catalogs to use when the catalogs option is active */
+ "encoding", /* What encoding to use for standard output */
+ "searchresultspath", /* Where do we store the results of search */
+ "data", /* The xml data file to use */
+ NULL /* indicate end of list */
+};
+
+
+
+// find the translated help documentation directory
+// langLookupDir code modified from langLookup function in kdebase/khelpcenter/view.cpp
+
+static QString langLookupDir( const QString &fname )
+{
+ QStringList search;
+
+ // assemble the local search paths
+ QStringList localDoc = KGlobal::dirs()->resourceDirs("html");
+ // also look in each of the KDEDIR paths
+ QString kdeDirs = getenv("KDEDIRS");
+ QStringList kdeDirsList = QStringList::split(":", kdeDirs);
+ if (!kdeDirs.isEmpty() && !kdeDirsList.isEmpty()){
+ for (QStringList::iterator it = kdeDirsList.begin(); it != kdeDirsList.end(); it++)
+ localDoc.append((*it) + "/share/doc/HTML/") ;
+ }
+
+ // look up the different languages
+ for (uint id=0; id < localDoc.count(); id++)
+ {
+ QStringList langs = KGlobal::locale()->languageList();
+ langs.append( "en" );
+ langs.remove( "C" );
+ QStringList::ConstIterator lang;
+ for (lang = langs.begin(); lang != langs.end(); ++lang)
+ search.append(QString("%1%2/%3/%4").arg(localDoc[id]).arg(*lang).arg("xsldbg").arg(fname));
+ }
+
+ // try to locate the file
+ QStringList::Iterator it;
+ for (it = search.begin(); it != search.end(); ++it)
+ {
+ QString baseDir = (*it).left((*it).findRev('/')) ;
+ QFileInfo info(baseDir + "/"+ fname);
+ if (info.exists() && info.isFile() && info.isReadable())
+ return baseDir;
+ }
+
+ return QString::null;
+}
+
+
+/**
+ * optionsInit:
+ *
+ * Intialize the options module
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+optionsInit(void)
+{
+ int optionId;
+
+ for (optionId = 0;
+ optionId <= OPTIONS_LAST_INT_OPTIONID - OPTIONS_FIRST_INT_OPTIONID; optionId++) {
+ intOptions[optionId] = 0;
+ intVolitileOptions[optionId] = 0;
+ }
+
+ for (optionId = 0;
+ optionId <= OPTIONS_LAST_STRING_OPTIONID - OPTIONS_FIRST_STRING_OPTIONID;
+ optionId++) {
+ stringOptions[optionId] = NULL;
+ }
+
+ /* init our parameter list */
+ parameterList = arrayListNew(10, (freeItemFunc) optionsParamItemFree);
+
+ /* setup the docs path */
+ optionsSetStringOption(OPTIONS_DOCS_PATH, (const xmlChar*)(langLookupDir("xsldbghelp.xml").utf8().data()));
+
+ optionsSetIntOption(OPTIONS_TRACE, TRACE_OFF);
+ optionsSetIntOption(OPTIONS_WALK_SPEED, WALKSPEED_STOP);
+ /* always try to use encoding if found */
+ optionsSetIntOption(OPTIONS_AUTOENCODE, 1);
+ /* start up with auto restart turned off */
+ optionsSetIntOption(OPTIONS_AUTORESTART, 0);
+ /* start up with gdb mode turned on */
+ optionsSetIntOption(OPTIONS_GDB, 1);
+ /* start up with output mode turned on */
+ optionsSetIntOption(OPTIONS_OUT, 1);
+ /* start up with validation turned on */
+ optionsSetIntOption(OPTIONS_VALID, 1);
+ /* start up with xinclude turned on */
+ optionsSetIntOption(OPTIONS_XINCLUDE, 1);
+
+ /* set output default as standard output. Must be changed if not using
+ * xsldbg's command line. Or the tty command is used */
+ optionsSetStringOption(OPTIONS_OUTPUT_FILE_NAME, NULL);
+
+ /* init our list of expressions to watch which are only a list of
+ strings ie xmlChar*'s */
+ watchExpressionList = arrayListNew(10, (freeItemFunc) xmlFree);
+
+ return (parameterList && watchExpressionList);
+}
+
+
+/**
+ * optionsFree:
+ *
+ * Free memory used by the options module
+ */
+void
+optionsFree(void)
+{
+ int string_option;
+
+ for (string_option = OPTIONS_FIRST_STRING_OPTIONID;
+ string_option <= OPTIONS_LAST_STRING_OPTIONID; string_option++) {
+ optionsSetStringOption(OptionTypeEnum(string_option), NULL);
+ }
+
+ /* Free up memory used by parameters and watches*/
+ arrayListFree(parameterList);
+ arrayListFree(watchExpressionList);
+ parameterList = NULL;
+ watchExpressionList = NULL;
+}
+
+
+ /**
+ * optionsGetOptionID:
+ * @optionName : A valid option name see documentation for "setoption"
+ * command and program usage documentation
+ *
+ * Find the option id for a given option name
+ *
+ * Returns The optionID for @optionName if successful, where
+ * OPTIONS_FIRST_OPTIONID<= optionID <= OPTIONS_LAST_OPTIONID,
+ * otherwise returns -1
+ */
+int
+optionsGetOptionID(xmlChar * optionName)
+{
+ int result = -1;
+ int optID = lookupName(optionName, (xmlChar **) optionNames);
+
+ if (optID >= 0) {
+ result = optID + OPTIONS_FIRST_OPTIONID;
+ }
+
+ return result;
+}
+
+
+ /**
+ * optionsGetOptionName:
+ * @ID : A valid option ID
+ *
+ * Get the name text for an option
+ *
+ * Returns The name of option if @ID is valid,
+ * NULL otherwise
+ */
+const xmlChar *
+optionsGetOptionName(OptionTypeEnum ID)
+{
+ const xmlChar *result = 0;
+ if ( (ID >= OPTIONS_FIRST_OPTIONID) && (ID <= OPTIONS_LAST_OPTIONID)){
+ /* An option ID is always valid at the moment */
+ result = (const xmlChar *) optionNames[ID - OPTIONS_FIRST_OPTIONID];
+ }
+
+ return result;
+}
+
+
+/**
+ * optionsSetIntOption:
+ * @optionType: A valid boolean option
+ * @value: 1 to enable, 0 otherwise
+ *
+ * Set the state of a boolean xsldbg option to @value
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+optionsSetIntOption(OptionTypeEnum optionType, int value)
+{
+ int type = optionType, result = 1;
+
+ if ((type >= OPTIONS_FIRST_INT_OPTIONID) && (type <= OPTIONS_LAST_INT_OPTIONID)) {
+ /* make sure that use of options are safe by only copying
+ * critical values from intVolitleOptions just before
+ * stylesheet is started
+ */
+ intVolitileOptions[type - OPTIONS_FIRST_INT_OPTIONID] = value;
+
+ /* the following types must be activated imediately */
+ switch (type) {
+
+ case OPTIONS_TRACE:
+ case OPTIONS_WALK_SPEED:
+ case OPTIONS_GDB:
+ intOptions[type - OPTIONS_FIRST_INT_OPTIONID] = value;
+ break;
+
+ default:
+ break;
+ }
+ } else {
+ if ((type >= OPTIONS_FIRST_OPTIONID) && (type <= OPTIONS_LAST_OPTIONID)){
+ xsldbgGenericErrorFunc(i18n("Error: Option %1 is not a valid boolean/integer option.\n").arg(xsldbgText(optionNames[type - OPTIONS_FIRST_OPTIONID])));
+ }else{
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsldbgGenericErrorFunc(QString("Error: Invalid arguments for the command %1.\n").arg("setoption"));
+#endif
+ }
+ result = 0;
+ }
+ return result;
+}
+
+
+/**
+ * optionsGetIntOption:
+ * @optionType: A valid boolean option to query
+ *
+ * Return the state of a boolean option
+ *
+ * Returns The state of a boolean xsldbg option.
+ * ie 1 for enabled , 0 for disabled
+ */
+int
+optionsGetIntOption(OptionTypeEnum optionType)
+{
+ int type = optionType, result = 0;
+
+ if ((type >= OPTIONS_FIRST_INT_OPTIONID) && (type <= OPTIONS_LAST_INT_OPTIONID)) {
+ result = intOptions[type - OPTIONS_FIRST_INT_OPTIONID];
+ } else {
+ if ((type >= OPTIONS_FIRST_OPTIONID) && (type <= OPTIONS_LAST_OPTIONID)){
+ xsldbgGenericErrorFunc(i18n("Error: Option %1 is not a valid boolean/integer option.\n").arg(xsldbgText(optionNames[type - OPTIONS_FIRST_OPTIONID])));
+ }else{
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsldbgGenericErrorFunc(QString("Error: Invalid arguments for the command %1.\n").arg("options"));
+#endif
+ }
+ }
+ return result;
+}
+
+
+
+/**
+ * optionsSetStringOption:
+ * @optionType: A valid string option
+ * @value: The value to copy
+ *
+ * Set value for a string xsldbg option to @value.
+ * Any memory used currently by option @optionType will be freed
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+optionsSetStringOption(OptionTypeEnum optionType, const xmlChar * value)
+{
+ int type = optionType, result = 0;
+
+ if ((type >= OPTIONS_FIRST_STRING_OPTIONID) &&
+ (type <= OPTIONS_LAST_STRING_OPTIONID)) {
+ int optionId = type - OPTIONS_FIRST_STRING_OPTIONID;
+
+ if (stringOptions[optionId])
+ xmlFree(stringOptions[optionId]);
+ if (value)
+ stringOptions[optionId] =
+ (xmlChar *) xmlMemStrdup((char *) value);
+ else /* we want to be able to provide a NULL value */
+ stringOptions[optionId] = NULL;
+ result = 1;
+ } else{
+ if ((type >= OPTIONS_FIRST_OPTIONID) && (type <= OPTIONS_LAST_OPTIONID)){
+ xsldbgGenericErrorFunc(i18n("Error: Option %1 is not a valid string xsldbg option.\n").arg(xsldbgText(optionNames[type - OPTIONS_LAST_OPTIONID])));
+ }else{
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsldbgGenericErrorFunc(QString("Error: Invalid arguments for the command %1.\n").arg("setoption"));
+#endif
+ }
+ }
+ return result;
+}
+
+
+/**
+ * optionsGetStringOption:
+ * @optionType: A valid string option
+ *
+ * Get value for a string xsldbg option of @optionType
+
+ * Returns current option value which may be NULL
+ */
+const xmlChar *
+optionsGetStringOption(OptionTypeEnum optionType)
+{
+ int type = optionType;
+ xmlChar *result = NULL;
+
+ if ((type >= OPTIONS_FIRST_STRING_OPTIONID) &&
+ (type <= OPTIONS_LAST_STRING_OPTIONID)) {
+ int optionId = type - OPTIONS_FIRST_STRING_OPTIONID;
+ result = stringOptions[optionId];
+ } else{
+ if ((type >= OPTIONS_FIRST_OPTIONID) && (type <= OPTIONS_LAST_OPTIONID)){
+ xsldbgGenericErrorFunc(i18n("Error: Option %1 is not a valid string xsldbg option.\n").arg(xsldbgText(optionNames[type - OPTIONS_FIRST_OPTIONID])));
+ }else{
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsldbgGenericErrorFunc(QString("Error: Invalid arguments for the command %1.\n").arg("options"));
+#endif
+ }
+ }
+ return result;
+}
+
+
+ /**
+ * optionsCopyVolitleOptions:
+ *
+ * Copy volitile options to the working area for xsldbg to be used
+ * just after xsldbg starts its processing loop
+ */
+void
+optionsCopyVolitleOptions(void)
+{
+ int optionId;
+
+ for (optionId = 0;
+ optionId <= OPTIONS_LAST_INT_OPTIONID - OPTIONS_FIRST_INT_OPTIONID; optionId++) {
+ intOptions[optionId] = intVolitileOptions[optionId];
+ }
+}
+
+
+/**
+ * optionsParamItemNew:
+ * @name: Is valid
+ * @value: Is valid
+ *
+ * Create a new libxslt parameter item
+ * Returns non-null if sucessful
+ * NULL otherwise
+ */
+parameterItemPtr
+optionsParamItemNew(const xmlChar * name, const xmlChar * value)
+{
+ parameterItemPtr result = NULL;
+
+ if (name) {
+ result = (parameterItem *) xmlMalloc(sizeof(parameterItem));
+ if (result) {
+ result->name = (xmlChar *) xmlMemStrdup((char *) name);
+ if (value)
+ result->value = (xmlChar *) xmlMemStrdup((char *) value);
+ else
+ result->value = (xmlChar *) xmlMemStrdup("");
+ result->intValue = -1;
+ }
+ }
+ return result;
+}
+
+
+/**
+ * optionsParamItemFree:
+ * @item: Is valid
+ *
+ * Free memory used by libxslt parameter item @item
+ */
+void
+optionsParamItemFree(parameterItemPtr item)
+{
+ if (item) {
+ if (item->name)
+ xmlFree(item->name);
+ if (item->value)
+ xmlFree(item->value);
+ xmlFree(item);
+ }
+
+}
+
+
+/**
+ * optionsGetParamItemList:
+ *
+ * Return the list of libxlt parameters
+ *
+ * Returns The list of parameters to provide to libxslt when doing
+ * stylesheet transformation if successful
+ * NULL otherwise
+ */
+arrayListPtr
+optionsGetParamItemList(void)
+{
+ return parameterList;
+}
+
+
+/**
+ * optionsPrintParam:
+ * @paramId: 0 =< paramID < arrayListCount(getParamList())
+ *
+ * Print parameter information
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+optionsPrintParam(int paramId)
+{
+ int result = 0;
+ parameterItemPtr paramItem =
+ (parameterItemPtr) arrayListGet(optionsGetParamItemList(),
+ paramId);
+
+ if (paramItem && paramItem->name && paramItem->value) {
+ xsldbgGenericErrorFunc(i18n(" Parameter %1 %2=\"%3\"\n").arg(paramId).arg(xsldbgText(paramItem->name)).arg(xsldbgText(paramItem->value)));
+ result = 1;
+ }
+ return result;
+}
+
+
+/**
+ * optionsPrintParamList:
+ *
+ * Prints all items in parameter list
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+optionsPrintParamList(void)
+{
+ int result = 1;
+ int paramIndex = 0;
+ int itemCount = arrayListCount(optionsGetParamItemList());
+
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
+ if (itemCount > 0) {
+ while (result && (paramIndex < itemCount)) {
+ result = optionsPrintParam(paramIndex++);
+ }
+ }
+ } else {
+ if (itemCount > 0) {
+ xsltGenericError(xsltGenericErrorContext, "\n");
+ while (result && (paramIndex < itemCount)) {
+ result = optionsPrintParam(paramIndex++);
+ }
+ } else
+ xsldbgGenericErrorFunc(i18n("\nNo parameters present.\n"));
+ }
+ return result;
+}
+
+
+ /**
+ * optionsNode:
+ * @optionType : Is valid, option to convert to a xmlNodePtr
+ *
+ * Convert option into a xmlNodePtr
+ *
+ * Returns the option @optionType as a xmlNodePtr if successful,
+ * NULL otherwise
+ */
+xmlNodePtr
+optionsNode(OptionTypeEnum optionType)
+{
+ xmlNodePtr node = NULL;
+ char numberBuffer[10];
+ int result = 1;
+
+ numberBuffer[0] = '\0';
+ if (optionType <= OPTIONS_VERBOSE) {
+ /* integer option */
+ node = xmlNewNode(NULL, (xmlChar *) "intoption");
+ if (node) {
+ snprintf(numberBuffer, sizeof(numberBuffer), "%d",
+ optionsGetIntOption(optionType));
+ result = result && (xmlNewProp
+ (node, (xmlChar *) "name",
+ (xmlChar *) optionNames[optionType -
+ OPTIONS_XINCLUDE])
+ != NULL);
+ if (result)
+ result = result && (xmlNewProp(node, (xmlChar *) "value",
+ (xmlChar *) numberBuffer) !=
+ NULL);
+ if (!result) {
+ xmlFreeNode(node);
+ node = NULL;
+ }
+
+ }
+ } else {
+ /* string option */
+ node = xmlNewNode(NULL, (xmlChar *) "stringoption");
+ if (node) {
+ result = result && (xmlNewProp
+ (node, (xmlChar *) "name",
+ (xmlChar *) optionNames[optionType -
+ OPTIONS_XINCLUDE])
+ != NULL);
+ if (result) {
+ if (optionsGetStringOption(optionType))
+ result = result && (xmlNewProp
+ (node, (xmlChar *) "value",
+ optionsGetStringOption
+ (optionType)) != NULL);
+ else
+ result = result && (xmlNewProp
+ (node, (xmlChar *) "value",
+ (xmlChar *) "") != NULL);
+ }
+
+ if (!result) {
+ xmlFreeNode(node);
+ node = NULL;
+ }
+
+ }
+ }
+ return node;
+}
+
+
+ /**
+ * optionsReadDoc:
+ * @doc : Is valid xsldbg config document, in the format as indicated
+ * by config.dtd
+ *
+ * Read options from document provided.
+ *
+ * Returns 1 if able to read @doc and load options found,
+ * 0 otherwise
+ */
+int
+optionsReadDoc(xmlDocPtr doc)
+{
+ int result = 1;
+ xmlChar *name, *value;
+ int optID;
+ xmlNodePtr node;
+
+ /* very primative search for config node
+ * we skip the DTD and then go straight to the first child of
+ * config node */
+ if (doc && doc->children->next && doc->children->next->children) {
+ /* find the first configuration option */
+ node = doc->children->next->children;
+ while (node && result) {
+ if (node->type == XML_ELEMENT_NODE) {
+ if (xmlStrCmp(node->name, "intoption") == 0) {
+ name = xmlGetProp(node, (xmlChar *) "name");
+ value = xmlGetProp(node, (xmlChar *) "value");
+ if (name && value && (atoi((char *) value) >= 0)) {
+ optID = lookupName(name, (xmlChar **) optionNames);
+ if (optID >= 0)
+ result =
+ optionsSetIntOption(OptionTypeEnum(optID + OPTIONS_XINCLUDE),
+ atoi((char *) value));
+ }
+ if (name)
+ xmlFree(name);
+ if (value)
+ xmlFree(value);
+ } else if (xmlStrCmp(node->name, "stringoption") == 0) {
+ name = xmlGetProp(node, (xmlChar *) "name");
+ value = xmlGetProp(node, (xmlChar *) "value");
+ if (name && value) {
+ optID = lookupName(name, (xmlChar **) optionNames);
+ if (optID >= 0)
+ result =
+ optionsSetStringOption(OptionTypeEnum(optID + OPTIONS_XINCLUDE),
+ value);
+ }
+ if (name)
+ xmlFree(name);
+ if (value)
+ xmlFree(value);
+ }
+ }
+ node = node->next;
+ }
+ }
+ return result;
+}
+
+
+
+/**
+ * optionsSavetoFile:
+ * @fileName : Must be NON NULL be a local file that can be written to
+ *
+ * Save configuation to file specified
+ *
+ * Returns 1 if able to save options to @fileName,
+ * 0 otherwise
+ */
+int
+optionsSavetoFile(xmlChar * fileName)
+{
+ int result = 0;
+ int optionIndex = 0;
+ xmlDocPtr configDoc;
+ xmlNodePtr rootNode;
+ xmlNodePtr node = NULL;
+
+ if (!fileName) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: NULL file name provided\n");
+#endif
+ return result;
+ }
+
+ configDoc = xmlNewDoc((xmlChar *) "1.0");
+ rootNode = xmlNewNode(NULL, (xmlChar *) "config");
+
+ if (configDoc && rootNode) {
+ xmlCreateIntSubset(configDoc, (xmlChar *) "config", (xmlChar *)
+ "-//xsldbg//DTD config XML V1.0//EN",
+ (xmlChar *) "config.dtd");
+ xmlAddChild((xmlNodePtr) configDoc, rootNode);
+
+ /*now to do the work of adding configuration items */
+ for (optionIndex = OPTIONS_XINCLUDE;
+ optionIndex <= OPTIONS_DATA_FILE_NAME; optionIndex++) {
+ result = 1;
+ if (optionNames[optionIndex - OPTIONS_XINCLUDE][0] == '*')
+ continue; /* don't save non user options */
+
+ node = optionsNode(OptionTypeEnum(optionIndex));
+ if (node)
+ xmlAddChild(rootNode, node);
+ else {
+ result = 0;
+ break;
+ }
+ }
+
+ if (result) {
+ /* so far so good, now to serialize it to disk */
+ if (!xmlSaveFormatFile((char *) fileName, configDoc, 1))
+ result = 0;
+ }
+
+ xmlFreeDoc(configDoc);
+ } else {
+
+ if (configDoc)
+ xmlFreeDoc(configDoc);
+
+ if (rootNode)
+ xmlFreeNode(rootNode);
+
+ }
+
+ return result;
+}
+
+
+
+ /**
+ * optionsConfigState:
+ * @value : Is valid
+ *
+ * Set/Get the state of configuration loading/saving
+ *
+ * Returns The current/new value of configuration flag. Where
+ * @value means:
+ * OPTIONS_CONFIG_READVALUE : No change return current
+ * value of read configuration flag
+ * OPTIONS_CONFIG_WRITING : Clear flag and return
+ * OPTIONS_CONFIG_WRITING which mean configuration
+ * file is being written
+ * OPTIONS_CONFIG_READING : Set flag and return
+ * OPTIONS_CONFIG_READING, which means configuration
+ * file is being read
+ * OPTIONS_CONFIG_IDLE : We are neither reading or writing
+ * configuration and return OPTIONS_CONFIG_IDLE
+ */
+int
+optionsConfigState(OptionsConfigState value)
+{
+ int result = OPTIONS_CONFIG_IDLE;
+
+ /* work around as some compiler refuse to switch on enums */
+ int configValue = value;
+
+ /* hold the current state of configuration reading/writing */
+ static int configState = OPTIONS_CONFIG_IDLE;
+
+ switch (configValue) {
+ case OPTIONS_CONFIG_READVALUE:
+ /* read the current value only */
+ result = configState;
+ break;
+
+ case OPTIONS_CONFIG_READING:
+ case OPTIONS_CONFIG_WRITING:
+ /* update the value */
+ result = configValue;
+ configState = configValue;
+ break;
+ }
+
+ return result;
+}
+
+ /**
+ * optionsAddWatch:
+ * @xPath : A valid xPath to evaluate in a context and
+ * has not already been addded
+ *
+ * Add xPath to be evaluated and printed out each time the debugger stops
+ *
+ * Returns 1 if able to add xPath to watched
+ * 0 otherwise
+ */
+ int optionsAddWatch(const xmlChar* xPath)
+{
+ int result = 0;
+ if (!xPath || (xmlStrlen(xPath) == 0)){
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Invalid XPath supplied\n");
+#endif
+ } else{
+ if (optionsGetWatchID(xPath) == 0){
+ xmlChar * nameCopy = xmlStrdup(xPath);
+ if (nameCopy){
+ arrayListAdd(watchExpressionList, nameCopy);
+ result = 1;
+ }
+ }
+ }
+
+ return result;
+}
+
+
+ /**
+ * optionsGetWatchID:
+ * @xPath : A valid watch expression that has already been added
+ *
+ * Finds the ID of watch expression previously added
+ *
+ * Returns 0 if not found,
+ * otherwise returns the ID of watch expression
+ */
+ int optionsGetWatchID(const xmlChar* xPath)
+{
+ int result = 0, counter;
+ xmlChar* watchExpression;
+ if (!xPath){
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Invalid xPath supplied\n");
+#endif
+ } else{
+ for ( counter = 0;
+ counter < arrayListCount(watchExpressionList);
+ counter++){
+ watchExpression = (xmlChar*)arrayListGet(watchExpressionList, counter);
+ if (watchExpression){
+ if (xmlStrEqual(xPath, watchExpression)){
+ result = counter + 1;
+ break;
+ }
+ }else{
+ break;
+ }
+ }
+ }
+
+ return result;
+}
+
+ /**
+ * optionsRemoveWatch:
+ * @watchID : A valid watchID as indicated by last optionsPrintWatches
+ * @showWarnings : Print more error messages if 1,
+ * print less if 0
+ *
+ * Remove the watch with given ID from our list of expressions to watch
+ *
+ * Returns 1 if able to remove to watch expression
+ * 0 otherwise
+ */
+ int optionsRemoveWatch(int watchID)
+{
+ return arrayListDelete(watchExpressionList, watchID - 1);
+}
+
+ /**
+ * optionsGetWatchList:
+ *
+ * Return the current list of expressions to watch
+ *
+ * Return the current list of expressions to watch
+ */
+ arrayListPtr optionsGetWatchList()
+{
+ return watchExpressionList;
+}
+
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/options.h b/kxsldbg/kxsldbgpart/libxsldbg/options.h
new file mode 100644
index 00000000..60ab69d3
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/options.h
@@ -0,0 +1,476 @@
+
+/***************************************************************************
+ options.h - define option related functions
+ -------------------
+ begin : Sat Nov 10 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 OPTIONS_H
+#define OPTIONS_H
+
+#include "arraylist.h"
+
+/**
+ * Provide a mechanism to change option. The Options structure is not in use,
+ * it has been added so that kdoc puts all option related
+ * functions together
+ *
+ * @short file support
+ *
+ * @author Keith Isdale <k_isdale@tpg.com.au>
+ */
+
+/* We want skip most of these includes when building documentation */
+#ifndef BUILD_DOCS
+#include <libxslt/xslt.h>
+#endif
+
+/* ---------------------------------------
+ Misc options
+-------------------------------------------*/
+
+/** The largest number lines of text can be print print printing documents
+ This is equivant to gdb shorting of evaluation values
+ */
+#define GDB_LINES_TO_PRINT 3
+
+
+ enum OptionsConfigState {
+ OPTIONS_CONFIG_READVALUE = -1, /* Read configuration flag */
+ OPTIONS_CONFIG_READING = 1, /* Configuration file is being read */
+ OPTIONS_CONFIG_WRITING, /* Configuration file is being written */
+ OPTIONS_CONFIG_IDLE /* We are neither reading or writing */
+ };
+
+ enum OptionTypeEnum {
+ OPTIONS_XINCLUDE = 500, /* Use xinclude during xml parsing */
+ OPTIONS_FIRST_BOOL_OPTIONID = OPTIONS_XINCLUDE,
+ OPTIONS_FIRST_INT_OPTIONID = OPTIONS_XINCLUDE,
+ OPTIONS_FIRST_OPTIONID = OPTIONS_XINCLUDE,
+ OPTIONS_DOCBOOK, /* Use of docbook sgml parsing */
+ OPTIONS_TIMING, /* Use of timing */
+ OPTIONS_PROFILING, /* Use of profiling */
+ OPTIONS_VALID, /* Enables file validation */
+ OPTIONS_OUT, /* Enables output to stdout */
+ OPTIONS_HTML, /* Enable the use of html parsing */
+ OPTIONS_DEBUG, /* Enable the use of xml tree debugging */
+ OPTIONS_SHELL, /* Enable the use of debugger shell */
+ OPTIONS_GDB, /* Run in gdb modem prints more messages) */
+ OPTIONS_PREFER_HTML, /* Prefer html output for search results */
+ OPTIONS_AUTOENCODE, /* try to use the encoding from the stylesheet */
+ OPTIONS_UTF8_INPUT, /* All input from user is in UTF-8.This normaly
+ * used when xsldbg is running as a thread */
+ OPTIONS_STDOUT, /* Print all error messages to stdout,
+ * normally error messages go to stderr */
+ OPTIONS_AUTORESTART, /* When finishing the debug of a XSLT script
+ automaticly restart at the beginning */
+ OPTIONS_VERBOSE, /* Be verbose with messages */
+ OPTIONS_LAST_BOOL_OPTIONID = OPTIONS_VERBOSE,
+ OPTIONS_REPEAT, /* The number of times to repeat */
+ OPTIONS_TRACE, /* Trace execution */
+ OPTIONS_WALK_SPEED, /* How fast do we walk through code */
+ OPTIONS_CATALOGS, /* Get the catalogs from SGML_CATALOG_FILES and
+ * store it in OPTIONS_CATALOG_NAMES */
+ OPTIONS_LAST_INT_OPTIONID = OPTIONS_CATALOGS,
+ OPTIONS_OUTPUT_FILE_NAME, /* what is the output file name */
+ OPTIONS_FIRST_STRING_OPTIONID = OPTIONS_OUTPUT_FILE_NAME,
+ OPTIONS_SOURCE_FILE_NAME, /* the stylesheet source to use */
+ OPTIONS_DOCS_PATH, /* path of xsldbg's documentation */
+ OPTIONS_CATALOG_NAMES, /* the names of the catalogs to use when catalogs option is active */
+ OPTIONS_ENCODING, /* What encoding to use for standard output */
+ OPTIONS_SEARCH_RESULTS_PATH, /* Where do we store the results of searching */
+ OPTIONS_DATA_FILE_NAME, /* xml data file to use */
+ OPTIONS_LAST_STRING_OPTIONID = OPTIONS_DATA_FILE_NAME,
+ OPTIONS_LAST_OPTIONID = OPTIONS_DATA_FILE_NAME
+ };
+
+ /* define what tracing is used */
+ enum TraceModeEnum {
+ TRACE_OFF = 600, /* disable tracing */
+ TRACE_ON, /* enable tracing */
+ TRACE_RUNNING, /* tracing is running */
+ TRACE_FINISHED /* not needed but just in case */
+ };
+
+ /* what speeds can we walk through a stylesheet */
+ /* must start walkSpeed enums from zero !! */
+ enum WalkSpeedEnum {
+ WALKSPEED_0 = 0,
+ WALKSPEED_STOP = WALKSPEED_0,
+ WALKSPEED_1,
+ WALKSPEED_FAST = WALKSPEED_1,
+ WALKSPEED_2,
+ WALKSPEED_3,
+ WALKSPEED_4,
+ WALKSPEED_5,
+ WALKSPEED_NORMAL = WALKSPEED_5,
+ WALKSPEED_6,
+ WALKSPEED_7,
+ WALKSPEED_8,
+ WALKSPEED_9,
+ WALKSPEED_SLOW = WALKSPEED_9
+ };
+
+extern int intVolitileOptions[OPTIONS_LAST_INT_OPTIONID - OPTIONS_FIRST_INT_OPTIONID + 1];
+
+/* how many microseconds is each speed increase worth*/
+#define WALKDELAY 250000
+
+
+/* for non win32 environments see the macro in xsldebugger/Makefile.am
+ Win32 type systems see macro in libxslt/xsltwin32config.h
+*/
+#ifdef __riscos
+
+/* The environment variable name we are going to use is the readable version
+ of the application name */
+#define XSLDBG_DOCS_DIR_VARIABLE "XSLDebugDocs$Dir"
+#else
+
+/* The environment variable name on normal systems */
+#define XSLDBG_DOCS_DIR_VARIABLE "XSLDBG_DOCS_DIR"
+#endif
+
+/* used to keep track of libxslt paramters
+ see Parameter related options near end of file
+*/
+ typedef struct _parameterItem parameterItem;
+ typedef parameterItem *parameterItemPtr;
+ struct _parameterItem {
+ xmlChar *name; /* libxslt parameter name */
+ xmlChar *value; /* libxslt parameter value */
+ int intValue; /* reserved */
+ };
+
+
+
+/**
+ * Initialized the options module
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ */
+ int optionsInit(void);
+
+
+
+/**
+ * Free memory used by the options module
+ */
+ void optionsFree(void);
+
+
+ /**
+ * Find the option id for a given option name
+ *
+ * @returns The optionID for @optionName if successful, where
+ * OPTIONS_XINCLUDE<= optionID <= OPTIONS_DATA_FILE_NAME,
+ * otherwise returns -1
+ *
+ * @param optionName A valid option name see documentation for "setoption"
+ * command and program usage documentation
+ *
+ */
+ int optionsGetOptionID(xmlChar * optionName);
+
+
+
+ /**
+ * Get the name text for an option
+ *
+ * Returns The name of option if @ID is valid,
+ * NULL otherwise
+ *
+ * @param ID A valid option ID
+ *
+ */
+ const xmlChar *optionsGetOptionName(OptionTypeEnum ID);
+
+
+/**
+ * Set the value of an integer xsldbg option to @p value
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param optionType Is a valid integer option
+ * @param value Is the valid to adopt
+ */
+ int optionsSetIntOption(OptionTypeEnum optionType, int value);
+
+
+/**
+ * @returns The state of a integer xsldbg option
+ *
+ * @param optionType Is a valid integer option
+ */
+ int optionsGetIntOption(OptionTypeEnum optionType);
+
+
+/**
+ * Set value for a string xsldbg option to @p value.
+ * Any memory used currently by option @p optionType will be freed
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ *
+ * @param optionType A valid string option
+ * @param value The value to copy
+ */
+ int optionsSetStringOption(OptionTypeEnum optionType,
+ const xmlChar * value);
+
+
+/**
+ * Get value for a string xsldbg option of @p optionType
+ *
+ * @returns current option value which may be NULL
+ *
+ * @param optionType A valid string option
+ */
+ const xmlChar *optionsGetStringOption(OptionTypeEnum optionType);
+
+
+ /**
+ * Copy volitile options to the working area for xsldbg to be used
+ * just after xsldbg starts its processing loop
+ */
+ void optionsCopyVolitleOptions(void);
+
+
+
+/*---------------------------------------------
+ Parameter related options
+-------------------------------------------------*/
+
+
+/**
+ * Return the list of libxlt parameters
+ *
+ * @returns The list of parameters to provide to libxslt when doing
+ * stylesheet transformation if successful
+ * NULL otherwise
+ */
+ arrayListPtr optionsGetParamItemList(void);
+
+
+
+/**
+ * Create a new libxslt parameter item
+ *
+ * @returns non-null if sucessful
+ * NULL otherwise
+ *
+ * @param name Is valid
+ * @param value Is valid
+ */
+ parameterItemPtr optionsParamItemNew(const xmlChar * name,
+ const xmlChar * value);
+
+
+/**
+ * Free memory used by libxslt parameter item @p item
+ *
+ * @param item Is valid
+ */
+ void optionsParamItemFree(parameterItemPtr item);
+
+
+/**
+ * Prints all items in parameter list
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ */
+ int optionsPrintParam(int paramId);
+
+
+
+/**
+ * Prints all items in parameter list
+ *
+ * @returns 1 on success,
+ * 0 otherwise
+ */
+ int optionsPrintParamList(void);
+
+/* ---------------------------------------------
+ Option serialization functions
+-------------------------------------------------*/
+
+ /**
+ * Convert option into a xmlNodePtr
+ *
+ * @returns The option @p optionType as a xmlNodePtr if successful,
+ * NULL otherwise
+ *
+ * @param optionType Is valid, option to convert to a xmlNodePtr
+ *
+ */
+ xmlNodePtr optionsNode(OptionTypeEnum optionType);
+
+
+
+ /**
+ * Read options from document provided.
+ *
+ * @returns 1 if able to read @p doc and load options found,
+ * 0 otherwise
+ *
+ * @param doc Is valid xsldbg config document, in the format as indicated
+ * by config.dtd
+ */
+ int optionsReadDoc(xmlDocPtr doc);
+
+
+ /**
+ * Save configuation to file specified
+ *
+ * @returns 1 if able to save options to @fileName,
+ * 0 otherwise
+ *
+ * @fileName : Must be NON NULL be a local file that can be written to
+ */
+ int optionsSavetoFile(xmlChar * fileName);
+
+
+/* ---------------------------------------------
+ Platform specific option functions
+-------------------------------------------------*/
+
+ /**
+ * Intialize the platform specific options module
+ *
+ * This is a platform specific interface
+ *
+ * @returns 1 if sucessful
+ * 0 otherwise
+ */
+ int optionsPlatformInit(void);
+
+
+ /**
+ * Free memory used by the platform specific options module
+ *
+ * This is a platform specific interface
+ *
+ */
+ void optionsPlatformFree(void);
+
+
+ /**
+ * Return xsldbg's the configuration file name
+ *
+ * Returns A copy of the file name that will be used to load xsldbgs
+ * configuration from,
+ * NULL otherwise
+ *
+ * This is a platform specific interface
+ *
+ */
+ xmlChar *optionsConfigFileName(void);
+
+
+ /**
+ * Load options from configuration file/registry
+ *
+ * This is a platform specific interface
+ *
+ * Returns 1 if able to load options
+ * 0 otherwise
+ */
+ int optionsLoad(void);
+
+
+ /**
+ * Save options to configuration file/registry
+ *
+ * This is a platform specific interface
+ *
+ * Returns 1 if able to load options
+ * 0 otherwise
+ */
+ int optionsSave(void);
+
+
+ /**
+ * Set/Get the state of configuration loading/saving. Normally only used
+ * by RISC OS
+ *
+ *
+ * Returns The current/new value of configuration flag. Where
+ * @p value means:
+ * OPTIONS_CONFIG_READVALUE : No change return current
+ * value of read configuration flag
+ * OPTIONS_CONFIG_WRITING : Clear flag and return
+ * OPTIONS_CONFIG_WRITING which mean configuration
+ * file is being written
+ * OPTIONS_CONFIG_READING : Set flag and return
+ * OPTIONS_CONFIG_READING, which means configuration
+ * file is being read
+ * OPTIONS_CONFIG_IDLE : We are neither reading or writing
+ * configuration and return OPTIONS_CONFIG_IDLE
+ *
+ * @param value Is valid
+ *
+ */
+ int optionsConfigState(OptionsConfigState value);
+
+ /**
+ * optionsAddWatch:
+ * @xPath : A valid xPath to evaluate in a context and
+ * has not already been addded
+ *
+ * Add xPath to be evaluated and printed out each time the debugger stops
+ *
+ * Returns 1 if able to add xPath to watched
+ * 0 otherwise
+ */
+ int optionsAddWatch(const xmlChar* xPath);
+
+ /**
+ * optionsGetWatchID:
+ * @xPath : A valid watch expression that has already been added
+ *
+ * Finds the ID of watch expression previously added
+ *
+ * Returns 0 if not found,
+ * otherwise returns the ID of watch expression
+ */
+ int optionsGetWatchID(const xmlChar* xPath);
+
+
+ /**
+ * optionsRemoveWatch:
+ * @watchID : A valid watchID as indicated by last optionsPrintWatches
+ *
+ * Remove the watch with given ID from our list of expressions to watch
+ *
+ * Returns 1 if able to remove to watch expression
+ * 0 otherwise
+ */
+ int optionsRemoveWatch(int watchID);
+
+
+ /**
+ * optionsGetWatchList:
+ *
+ * Return the current list of expressions to watch
+ *
+ * Return the current list of expressions to watch
+ */
+ arrayListPtr optionsGetWatchList(void);
+
+
+#endif
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/options_unix.cpp b/kxsldbg/kxsldbgpart/libxsldbg/options_unix.cpp
new file mode 100644
index 00000000..27c7d2f1
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/options_unix.cpp
@@ -0,0 +1,118 @@
+
+/***************************************************************************
+ options_unix.c - *nix specific option functions
+ -------------------
+ begin : Tue Jan 29 2002
+ 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 <libxml/parser.h>
+#include <stdlib.h>
+#include <string.h>
+#include "xsldbg.h"
+#include "options.h"
+
+ /**
+ * optionsPlatformInit:
+ *
+ * Intialize the platform specific options module
+ *
+ * This is a platform specific interface
+ *
+ * Returns 1 if sucessful
+ * 0 otherwise
+ */
+int
+optionsPlatformInit(void)
+{
+ return 1;
+}
+
+
+ /**
+ * optionsPlatformFree:
+ *
+ * Free memory used by the platform specific options module
+ *
+ * This is a platform specific interface
+ *
+ */
+void
+optionsPlatformFree(void)
+{
+ /* empty */
+}
+
+ /**
+ * optionsConfigFileName:
+ *
+ * Returns A copy of the file name that will be used to load xsldbgs
+ * configuration from,
+ * NULL otherwise
+ */
+xmlChar *
+optionsConfigFileName(void)
+{
+ xmlChar *result = NULL;
+ const char *homeDir = getenv("HOME");
+ const char *configName = "xsldbg.rc";
+ int bufferSize = 0;
+
+ if (homeDir) {
+ /* give ourselves a bit of room to move */
+ bufferSize = strlen(homeDir) + strlen(configName) + 10;
+ result = (xmlChar *) xmlMalloc(bufferSize);
+ snprintf((char *) result, bufferSize, "%s/%s", homeDir,
+ configName);
+ }
+ return result;
+}
+
+
+ /**
+ * optionsLoad:
+ *
+ * Load options from configuration file/registry
+ *
+ * This is a platform specific interface
+ *
+ * Returns 1 if able to load options
+ * 0 otherwise
+ */
+int
+optionsLoad(void)
+{
+ int result = 0;
+ xmlDocPtr doc = xmlParseFile((char *) optionsConfigFileName());
+
+ if (doc)
+ result = optionsReadDoc(doc);
+ return 0;
+}
+
+
+ /**
+ * optionsSave:
+ *
+ * Save options to configuration file/registry
+ *
+ * This is a platform specific interface
+ *
+ * Returns 1 if able to save options
+ * 0 otherwise
+ */
+int
+optionsSave(void)
+{
+ return optionsSavetoFile(optionsConfigFileName());
+}
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/os_cmds.cpp b/kxsldbg/kxsldbgpart/libxsldbg/os_cmds.cpp
new file mode 100644
index 00000000..dac5bb0f
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/os_cmds.cpp
@@ -0,0 +1,100 @@
+
+/***************************************************************************
+ os_cmds.c - operating system commands for xsldbg
+ -------------------
+ begin : Wed Nov 21 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 "xsldbg.h"
+#include "debugXSL.h"
+#include "files.h"
+
+/* -----------------------------------------
+
+ Operating system related commands
+
+ ------------------------------------------- */
+
+
+/**
+ * xslDbgShellChangeWd:
+ * @path: The path to change to
+ *
+ * Change the current working directory of the operating system
+ *
+ * Returns 1 if able to change xsldbg's working directory to @path
+ * 0 otherwise
+ */
+int
+xslDbgShellChangeWd(xmlChar * path)
+{
+ int result = 0;
+
+ if (xmlStrLen(path)) {
+ /* call function in files.c to do the work */
+ result = changeDir(path);
+ } else
+ xsldbgGenericErrorFunc(i18n("Error: Missing arguments for the command %1.\n").arg("chdir"));
+ return result;
+}
+
+
+/**
+ * xslDbgShellExecute:
+ * @name: The name of command string to be executed by operating system shell
+ * @verbose: If 1 then print extra debugging messages,
+ * normal messages otherwise
+ *
+ * Execute an operating system command
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+xslDbgShellExecute(xmlChar * name, int verbose)
+{
+ int result = 0;
+
+ /* Quick check to see if we have a command processor; embedded systems
+ * may not have such a thing */
+ if (system(NULL) == 0) {
+ xsldbgGenericErrorFunc(i18n("Error: No command processor available for shell command \"%1\".\n").arg(xsldbgText(name)));
+ } else {
+ int return_code;
+
+ if (verbose)
+ xsldbgGenericErrorFunc(i18n("Information: Starting shell command \"%1\".\n").arg(xsldbgText(name)));
+
+ return_code = system((char *) name);
+ /* JRF: Strictly system returns an implementation defined value -
+ * we are interpreting that value here, so we need
+ * implementation specific code to handle each case */
+
+#ifdef __riscos
+ /* on RISC OS -2 means 'system call failed', otherwise it is the
+ * return code from the sub-program */
+ if (return_code != -2) {
+#else
+ if (return_code == 0) {
+#endif
+ if (verbose)
+ xsldbgGenericErrorFunc(i18n("Information: Finished shell command.\n"));
+ result = 1;
+ } else {
+ if (verbose)
+ xsldbgGenericErrorFunc(i18n("Error: Unable to run command. System error %1.\n").arg(return_code));
+ }
+ }
+ return result;
+}
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/param_cmds.cpp b/kxsldbg/kxsldbgpart/libxsldbg/param_cmds.cpp
new file mode 100644
index 00000000..e4255797
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/param_cmds.cpp
@@ -0,0 +1,175 @@
+
+/***************************************************************************
+ param_cmds.c - libxslt parameter commands for xsldbg
+ -------------------
+ begin : Wed Nov 21 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 "xsldbg.h"
+#include "debugXSL.h"
+#include "options.h"
+
+#include "xsldbgmsg.h"
+#include "xsldbgthread.h" /* for get thread status */
+
+
+/* -----------------------------------------
+
+ libxslt parameter related commands
+
+ ------------------------------------------- */
+
+/**
+ * xslDbgShellAddParam:
+ * @arg: A string comprised of two words separated by
+ * one or more spaces which are in UTF-8
+ *
+ * Add a libxslt parameter to be sent to libxslt later on
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+*/
+int
+xslDbgShellAddParam(xmlChar * arg)
+{
+ int result = 0;
+ parameterItemPtr paramItem = NULL;
+ static const char *errorPrompt = I18N_NOOP("Failed to add parameter");
+ xmlChar *opts[2];
+
+ if (!arg) {
+ xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for the command %1.\n").arg("addparam"));
+ }else{
+ if ((xmlStrLen(arg) > 1) && splitString(arg, 2, opts) == 2) {
+ int count;
+ for (count = 0; count < arrayListCount(optionsGetParamItemList()); count++){
+ paramItem = (parameterItemPtr)arrayListGet(optionsGetParamItemList(), count);
+ if (paramItem != NULL){
+ if (xmlStrCmp(opts[0], paramItem->name) == 0){
+ /* parameter exist just update its value */
+ if (paramItem->value)
+ xmlFree(paramItem->value);
+ paramItem->value = xmlStrdup(opts[1]);
+ return 1;
+ }
+ }
+ }
+ paramItem = optionsParamItemNew(opts[0], opts[1]);
+ result = arrayListAdd(optionsGetParamItemList(), paramItem);
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for the command %1.\n").arg("addparam"));
+ }
+ }
+ if (!result)
+ xsldbgGenericErrorFunc(QString("Error: %1\n").arg(i18n(errorPrompt)));
+ else {
+ xsldbgGenericErrorFunc("\n");
+ }
+ return result;
+}
+
+
+/**
+ * xslDbgShellDelParam:
+ * @arg: A single white space trimmed parameter number to look for
+ *
+ * Delet a libxslt parameter to be sent to libxslt later on
+ *
+ * Returns 1 if able to delete parameter @name,
+ * 0 otherwise
+ */
+int
+xslDbgShellDelParam(xmlChar * arg)
+{
+ int result = 0;
+ static const char *errorPrompt = I18N_NOOP("Failed to delete parameter");
+ long paramId;
+ xmlChar *opts[2];
+
+ if (!arg) {
+ xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for the command %1.\n").arg("delparam"));
+ }else{
+ if (xmlStrLen(arg) > 0) {
+ if (splitString(arg, 1, opts) == 1) {
+ if ((xmlStrlen(opts[0]) == 0) ||
+ !sscanf((char *) opts[0], "%ld", &paramId)) {
+ xsldbgGenericErrorFunc(i18n("Error: Unable to parse %1 as a line number.\n").arg(xsldbgText(opts[0])));
+ } else {
+ result =
+ arrayListDelete(optionsGetParamItemList(), paramId);
+ if (!result)
+ xsldbgGenericErrorFunc(i18n("Error: Unable to find parameter %1.\n").arg(paramId));
+ }
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for the command %1.\n").arg("delparam"));
+ }
+ } else {
+ /* Delete all parameters */
+ arrayListEmpty(optionsGetParamItemList());
+ result = 1;
+ }
+ }
+ if (!result)
+ xsldbgGenericErrorFunc(QString("Error: %1\n").arg(i18n(errorPrompt)));
+ else
+ xsldbgGenericErrorFunc("\n");
+
+ return result;
+}
+
+
+/**
+ * xslDbgShellShowParam:
+ * @arg: Not used
+ *
+ * Print list of current paramters
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+xslDbgShellShowParam(xmlChar * arg)
+{
+ Q_UNUSED(arg);
+ int result = 0;
+ static const char *errorPrompt = I18N_NOOP("Unable to print parameters");
+
+ if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
+ int paramIndex = 0;
+ int itemCount = arrayListCount(optionsGetParamItemList());
+
+ notifyListStart(XSLDBG_MSG_PARAMETER_CHANGED);
+
+ if (itemCount > 0) {
+ parameterItemPtr paramItem = NULL;
+
+ while (paramIndex < itemCount) {
+ paramItem = (parameterItemPtr)
+ arrayListGet(optionsGetParamItemList(), paramIndex++);
+ if (paramItem != NULL)
+ notifyListQueue(paramItem);
+ }
+ }
+ notifyListSend();
+ result = 1;
+ } else {
+
+ if (optionsPrintParamList())
+ result = 1;
+ else
+ xsldbgGenericErrorFunc(QString("Error: %1\n").arg(i18n(errorPrompt)));
+ xsldbgGenericErrorFunc("\n");
+ }
+ return result;
+}
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/qtnotifier2.h b/kxsldbg/kxsldbgpart/libxsldbg/qtnotifier2.h
new file mode 100644
index 00000000..dfe57f0c
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/qtnotifier2.h
@@ -0,0 +1,38 @@
+/***************************************************************************
+ qtnotifier.h - notify the qt app of changes
+ -------------------
+ begin : Sun Dec 23 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 QTNOTIFIER_H
+#define QTNOTIFIER_H
+
+#if defined WIN32
+#include <libxsldbg/xsldbgwin32config.h>
+#endif
+
+#include "xsldbgnotifier.h"
+
+
+class XsldbgDebuggerBase;
+
+extern "C" {
+
+ void connectNotifier(XsldbgDebuggerBase *debugger);
+ int qtNotifyXsldbgApp(XsldbgMessageEnum type, const void *data);
+ int qtNotifyStateXsldbgApp(XsldbgMessageEnum type, int commandId, XsldbgCommandStateEnum commandState, const char *text);
+ int qtNotifyTextXsldbgApp(XsldbgMessageEnum type, const char *text);
+}
+
+#endif
diff --git a/kxsldbg/kxsldbgpart/libxsldbg/search.cpp b/kxsldbg/kxsldbgpart/libxsldbg/search.cpp
new file mode 100644
index 00000000..68fcd7e1
--- /dev/null
+++ b/kxsldbg/kxsldbgpart/libxsldbg/search.cpp
@@ -0,0 +1,1584 @@
+
+/***************************************************************************
+ search.c - search implementation
+ -------------------
+ begin : Fri Nov 2 2001
+ copyright : (C) 2001 by Keith Isdale
+ email : k_isdale@tpg.com.au
+ ***************************************************************************/
+
+
+#include "xsldbg.h"
+#include "debugXSL.h"
+#include "breakpoint.h"
+#include "search.h"
+#include "options.h"
+#include "files.h"
+
+#ifdef __riscos
+
+/* Include for filename conversions */
+#include "libxml/riscos.h"
+#endif
+
+/* our private function*/
+void scanForBreakPoint(void *payload, void *data,
+ xmlChar * name);
+
+/* store all data in this document so we can write it to file*/
+static xmlDocPtr searchDataBase;
+
+/* the topmost node in document*/
+static xmlNodePtr searchDataBaseRoot;
+
+/* what was the last query that was run */
+static xmlChar *lastQuery;
+
+#define BUFFER_SIZE 500
+static xmlChar searchBuffer[BUFFER_SIZE];
+
+/* -----------------------------------------
+ Private function declarations for dbgsearch.c
+ -------------------------------------------*/
+
+/**
+ * findNodeByLineNoHelper:
+ * @payload: valid xsltStylesheetPtr
+ * @data: valid searchInfoPtr
+ * @name: not used
+ *
+ * We are walking through stylesheets looking for a match
+ */
+void
+ findNodeByLineNoHelper(void *payload, void *data,
+ xmlChar * name);
+
+/**
+ * globalVarHelper:
+ * @payload: valid xsltStylesheetPtr
+ * @data: is valid
+ * @name: not used
+ *
+ * Helper to find the global variables. We are given control via
+ * walkStylesheets globalWalkFunc will always be set to the
+ * walkFunc to call
+ */
+void
+ globalVarHelper(void **payload, void *data,
+ xmlChar * name);
+
+/**
+ * localVarHelper:
+ * @payload: valid xsltTemplatePtr
+ * @data: is valid
+ * @name: not used
+ *
+ * Helper to find the local variables. We are given control via walkTemplates
+ * globalWalkFunc will always be set to the walkFunc to call
+ * localWalkFunc will always be set to the walkFunc to call
+ */
+void
+ localVarHelper(void **payload, void *data,
+ xmlChar * name);
+
+
+/* -------------------------------------
+ End private functions
+ ---------------------------------------*/
+
+
+/**
+ * searchInit:
+ *
+ * Initialize the search module
+ *
+ * Returns 1 if search structures have been initialized properly and all
+ * memory required has been obtained,
+ * 0 otherwise
+*/
+int
+searchInit(void)
+{
+ searchDataBase = NULL;
+ searchDataBaseRoot = NULL;
+ lastQuery = NULL;
+ if (!searchEmpty()) {
+ xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
+ }
+ return (searchRootNode() != NULL);
+}
+
+
+/**
+ * searchFree:
+ *
+ * Free all memory used by the search module
+ */
+void
+searchFree(void)
+{
+ if (searchDataBase) {
+ xmlFreeDoc(searchDataBase);
+ searchDataBase = NULL;
+ searchDataBaseRoot = NULL;
+ }
+}
+
+
+/**
+ * searchNewInfo:
+ * @type: What type of search is required
+ *
+ * Create a new search
+ *
+ * Returns A valid search info pointer if successful
+ * NULL otherwise
+ */
+searchInfoPtr
+searchNewInfo(SearchEnum type)
+{
+ searchInfoPtr result = NULL;
+ int searchType = type;
+
+ switch (searchType) {
+ case SEARCH_BREAKPOINT:
+ result = (searchInfoPtr) xmlMalloc(sizeof(searchInfo));
+ if (result) {
+ breakPointSearchDataPtr searchData;
+
+ result->type = SEARCH_BREAKPOINT;
+ searchData = (breakPointSearchDataPtr)
+ xmlMalloc(sizeof(breakPointSearchData));
+ if (searchData) {
+ searchData->id = -1;
+ searchData->templateName = NULL;
+ searchData->breakPtr = NULL;
+ result->data = searchData;
+ } else {
+ xmlFree(result);
+ result = NULL;
+ }
+ }
+ break;
+
+ case SEARCH_NODE:
+ result = (searchInfoPtr) xmlMalloc(sizeof(searchInfo));
+ if (result) {
+ nodeSearchDataPtr searchData;
+
+ result->type = SEARCH_NODE;
+ searchData =
+ (nodeSearchDataPtr) xmlMalloc(sizeof(nodeSearchData));
+ if (searchData) {
+ searchData->node = NULL;
+ searchData->lineNo = -1;
+ searchData->url = NULL;
+ searchData->nameInput = NULL;
+ searchData->guessedNameMatch = NULL;
+ searchData->absoluteNameMatch = NULL;
+ result->data = searchData;
+ } else {
+ xmlFree(result);
+ result = NULL;
+ }
+ }
+ break;
+
+ case SEARCH_XSL:
+ break;
+
+ case SEARCH_VARIABLE:
+ result = (searchInfoPtr) xmlMalloc(sizeof(searchInfo));
+ if (result) {
+ variableSearchDataPtr searchData;
+
+ result->type = SEARCH_VARIABLE;
+ searchData = (variableSearchDataPtr)
+ xmlMalloc(sizeof(variableSearchData));
+ if (searchData) {
+ searchData->name = NULL;
+ searchData->nameURI = NULL;
+ searchData->select = NULL;
+ result->data = searchData;
+ } else {
+ xmlFree(result);
+ result = NULL;
+ }
+ }
+ break;
+
+ }
+ if (result) {
+ result->found = 0;
+ result->error = 0;
+ }
+ return result;
+}
+
+
+/**
+ * searchFreeInfo:
+ * @info: valid search info
+ *
+ * Free memory used by @info
+ */
+void
+searchFreeInfo(searchInfoPtr info)
+{
+ if (info) {
+ if (info->data) {
+ switch (info->type) {
+ case SEARCH_BREAKPOINT:
+ {
+ breakPointSearchDataPtr searchData =
+ (breakPointSearchDataPtr) info->data;
+
+ if (searchData->templateName)
+ xmlFree(searchData->templateName);
+ }
+ break;
+
+ case SEARCH_NODE:
+ {
+ nodeSearchDataPtr searchData =
+ (nodeSearchDataPtr) info->data;
+
+ if (searchData->url)
+ xmlFree(searchData->url);
+
+ if (searchData->nameInput)
+ xmlFree(searchData->nameInput);
+
+ if (searchData->guessedNameMatch)
+ xmlFree(searchData->guessedNameMatch);
+
+ if (searchData->absoluteNameMatch)
+ xmlFree(searchData->absoluteNameMatch);
+
+ /* we never free searchData->node as we did not create it! */
+ }
+ break;
+
+ case SEARCH_XSL:
+ break;
+
+ case SEARCH_VARIABLE:
+ {
+ variableSearchDataPtr searchData =
+ (variableSearchDataPtr) info->data;
+
+ if (searchData->name)
+ xmlFree(searchData->name);
+
+ if (searchData->nameURI)
+ xmlFree(searchData->nameURI);
+
+ if (searchData->select)
+ xmlFree(searchData->select);
+ }
+ break;
+
+ }
+ xmlFree(info->data);
+ }
+ xmlFree(info);
+ }
+}
+
+
+/**
+ * searchEmpty:
+ *
+ * Empty the seach dataBase of its contents
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+searchEmpty(void)
+{
+ if (searchDataBase) {
+ xmlFreeDoc(searchDataBase);
+ }
+ searchDataBase = xmlNewDoc((xmlChar *) "1.0");
+ searchDataBaseRoot = NULL;
+ if (searchDataBase) {
+ xmlCreateIntSubset(searchDataBase,
+ (xmlChar *) "search", (xmlChar *)
+ "-//xsldbg//DTD search XML V1.1//EN",
+ (xmlChar *) "search_v1_1.dtd");
+ searchDataBaseRoot = xmlNewNode(NULL, (xmlChar *) "search");
+ if (searchDataBaseRoot)
+ xmlAddChild((xmlNodePtr) searchDataBase, searchDataBaseRoot);
+ }
+ if (lastQuery)
+ xmlFree(lastQuery);
+ lastQuery = NULL;
+ if (searchRootNode() == NULL) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Unable to clear old search results, memory error?\n");
+#endif
+ }
+
+ return (searchRootNode() != NULL);
+}
+
+
+/**
+ * searchDoc:
+ *
+ * Return the document used for seaching ie the search dataBase
+ *
+ * Returns The document used for searching
+ * Dangerous function to use! Does NOT return a copy of
+ * search data so don't free it
+ */
+xmlDocPtr
+searchDoc(void)
+{
+ return searchDataBase;
+}
+
+
+/**
+ * searchRootNode:
+ *
+ * Get the topmost node in the search dataBase
+ *
+ * Returns The topmost xml node in search dataBase.
+ * Dangerous function to use! Does NOT return a copy of
+ * search root node so don't free it
+ */
+xmlNodePtr
+searchRootNode(void)
+{
+ return searchDataBaseRoot;
+}
+
+
+/**
+ * searchAdd:
+ * @node: Is valid
+ *
+ * Add a node to the search dataBase
+ *
+ * Returns 1 if able to add @node to top node in search dataBase,
+ * 0 otherwise
+ */
+int
+searchAdd(xmlNodePtr node)
+{
+ int result = 0;
+
+ if (node && searchDataBaseRoot
+ && xmlAddChild(searchDataBaseRoot, node)) {
+ result = 1;
+ }
+
+ return result;
+}
+
+
+/**
+ * searchSave:
+ * @fileName: A valid file name, or NULL for the default
+ *
+ * Save the search dataBase to @fileName
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+searchSave(const xmlChar * fileName)
+{
+
+ int result = 0;
+ xmlChar *searchInput = NULL;
+
+ if (fileName == NULL)
+ searchInput = filesSearchFileName(FILES_SEARCHINPUT);
+ else
+ searchInput = xmlStrdup(fileName);
+
+ if (xmlSaveFormatFile((char *) searchInput, searchDataBase, 1) != -1){
+ result = 1;
+ }else{
+ xsldbgGenericErrorFunc(i18n("Error: Unable to write search Database to file %1. Try setting the \"searchresultspath\" option to a writable path.\n").arg(xsldbgText(searchInput)));
+ }
+
+ if (searchInput)
+ xmlFree(searchInput);
+
+ return result;
+}
+
+
+/**
+ * searchQuery:
+ * @query: The query to run . If NULL then query is "//search/ *"
+ * @tempFile: Where do we load the search dataBase from to execute
+ * query. If tempFile is NULL "searchresult.xml" is used
+ * @outputFile : Where do we store the result. If NULL
+ * then default to "searchresult.html"
+ *
+ * Send query as parameter for execution of search.xsl using
+ * data stored in @tempFile
+ *
+ * Returns 1 on success,
+ * 0 otherwise
+ */
+int
+searchQuery(const xmlChar * tempFile, const xmlChar * outputFile,
+ const xmlChar * query)
+{
+ int result = 0;
+
+ /* The file name of where the input is comming from */
+ xmlChar *searchInput = NULL;
+
+ /* The XSL file name to use during transformation of searchInput */
+ xmlChar *searchXSL = NULL;
+
+ /* Where to store the result of transformation */
+ xmlChar *searchOutput = NULL;
+
+
+ /* if a tempFile if provided its up you to make sure that it is correct !! */
+ if (tempFile == NULL)
+ searchInput = filesSearchFileName(FILES_SEARCHINPUT);
+ else
+ searchInput = xmlStrdup(tempFile);
+
+ searchXSL = filesSearchFileName(FILES_SEARCHXSL);
+
+ /* if a outputFile if provided its up you to make sure that it is correct */
+ if (outputFile == NULL)
+ searchOutput = filesSearchFileName(FILES_SEARCHRESULT);
+ else
+ searchOutput = xmlStrdup(outputFile);
+
+ if (!query || (xmlStrlen(query) == 0))
+ query = (xmlChar *) "--param query //search/*";
+
+ /* see configure.in for the definition of XSLDBG_BIN, the name of our binary */
+ if (searchInput && searchXSL && searchOutput) {
+ if (optionsGetIntOption(OPTIONS_CATALOGS) == 0)
+ snprintf((char *) searchBuffer, sizeof(searchBuffer),
+ "%s -o %s %s %s %s", XSLDBG_BIN,
+ searchOutput, query, searchXSL, searchInput);
+ else
+ /* assume that we are to use catalogs as well in our query */
+ snprintf((char *) searchBuffer, sizeof(searchBuffer),
+ "%s --catalogs -o %s %s %s %s", XSLDBG_BIN,
+ searchOutput, query, searchXSL, searchInput);
+ result = xslDbgShellExecute(searchBuffer, 1);
+
+ if (result && (optionsGetIntOption(OPTIONS_PREFER_HTML) == 0)) {
+ /* try printing out the file */
+ result = filesMoreFile(searchOutput, NULL);
+ }
+
+ xsldbgGenericErrorFunc(i18n("Information: Transformed %1 using %2 and saved to %3.\n").arg(xsldbgText(searchInput)).arg(xsldbgText(searchXSL)).arg(xsldbgText(searchOutput)));
+ } else {
+ xsldbgGenericErrorFunc(i18n("Error: Invalid arguments to command %1.\n").arg("search"));
+ }
+
+ if (searchInput)
+ xmlFree(searchInput);
+
+ if (searchXSL)
+ xmlFree(searchXSL);
+
+ if (searchOutput)
+ xmlFree(searchOutput);
+
+ return result;
+}
+
+
+/**
+ * scanForBreakPoint:
+ * @payload: A valid breakPointPtr
+ * @data: The criteria to look for and a valid searchInfoPtr of
+ * type SEARCH_BREAKPOINT
+ * @name: Not used
+ *
+ * Test if break point matches criteria given by @data. If so then
+ * set @data->found to 1 and stores reference to break point found in
+ * @data->data->node
+ * otherwise @data is unchanged
+*/
+void
+scanForBreakPoint(void *payload, void *data,
+ xmlChar * name)
+{
+ Q_UNUSED(name);
+ breakPointPtr breakPtr = (breakPointPtr) payload;
+ searchInfoPtr searchInf = (searchInfoPtr) data;
+ breakPointSearchDataPtr searchData = NULL;
+ int found = 0;
+
+ if (!payload || !searchInf || !searchInf->data
+ || (searchInf->type != SEARCH_BREAKPOINT) || searchInf->found)
+ return;
+
+ searchData = (breakPointSearchDataPtr) searchInf->data;
+
+ if (searchData->id && (breakPtr->id == searchData->id))
+ found = 1;
+ else if (searchData->templateName && breakPtr->templateName &&
+ (xmlStrCmp(breakPtr->templateName, searchData->templateName)
+ == 0))
+ found = 1;
+
+ if (found) {
+ searchInf->found = 1;
+ searchData->breakPtr = breakPtr;
+ }
+}
+
+
+
+/**
+ * scanForNode:
+ * @payload: A valid xmlNodePtr
+ * @data: The criteria to look for and a valid searchInfo of
+ * type SEARCH_NODE
+ * @name: Not used
+
+ * Test if node matches criteria given by @data if so then set @data->found
+ * to 1 and stores reference to node found in @data->data->node
+ * otherwise @data is unchanged
+ */
+void
+scanForNode(void *payload, void *data, xmlChar * name)
+{
+ Q_UNUSED(name);
+ searchInfoPtr searchInf = (searchInfoPtr) data;
+ nodeSearchDataPtr searchData = NULL;
+ xmlNodePtr node = (xmlNodePtr) payload;
+ xmlChar *baseUri = NULL;
+ int match = 1;
+
+ if (!node || !node->doc || !node->doc->URL ||
+ !searchInf || (searchInf->type != SEARCH_NODE))
+ return;
+
+ searchData = (nodeSearchDataPtr) searchInf->data;
+
+ if (searchData->lineNo >= 0)
+ match = searchData->lineNo == xmlGetLineNo(node);
+
+ if (searchData->url)
+ baseUri = filesGetBaseUri(node);
+ if (baseUri) {
+ match = match && (xmlStrCmp(searchData->url, baseUri) == 0);
+ xmlFree(baseUri);
+ } else {
+ match = match && (xmlStrcmp(searchData->url, node->doc->URL) == 0);
+ }
+
+ if (match) {
+ searchData->node = node;
+ searchInf->found = 1;
+ }
+
+}
+
+
+/**
+ * findNodeByLineNoHelper:
+ * @payload: A valid xsltStylesheetPtr
+ * @data: A valid searchInfoPtr
+ * @name: Not used
+ *
+ * We are walking through stylesheets looking for a match
+ */
+void
+findNodeByLineNoHelper(void *payload, void *data,
+ xmlChar * name)
+{
+ Q_UNUSED(name);
+ xsltStylesheetPtr style = (xsltStylesheetPtr) payload;
+ searchInfoPtr searchInf = (searchInfoPtr) data;
+
+ if (!payload || !searchInf || !style->doc)
+ return;
+
+ walkChildNodes((xmlHashScanner) scanForNode, searchInf,
+ (xmlNodePtr) style->doc);
+
+ /* try the included stylesheets */
+ if (!searchInf->found)
+ walkIncludes((xmlHashScanner) scanForNode, searchInf, style);
+}
+
+
+/**
+ * findNodeByLineNo:
+ * @ctxt: Valid ctxt to look into
+ * @url: Non-null, non-empty file name that has been loaded by debugger
+ * @lineNumber: @lineNumber >= 0 and is available in @url
+ *
+ * Finds the closest line number in file specified that can be a point
+ *
+ * Returns The node at line number number specified if successfull,
+ * NULL otherwise
+ */
+xmlNodePtr
+findNodeByLineNo(xsltTransformContextPtr ctxt,
+ const xmlChar * url, long lineNumber)
+{
+ xmlNodePtr result = NULL;
+ searchInfoPtr searchInf = searchNewInfo(SEARCH_NODE);
+ nodeSearchDataPtr searchData = NULL;
+
+ if (!searchInf) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Unable to create searchInfo in findNodeByLineNo\n");
+#endif
+ return result;
+ }
+
+ if (!ctxt || !url || (lineNumber == -1)) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Invalid ctxt, url or line number to findNodeByLineNo\n");
+#endif
+ return result;
+ }
+
+ searchData = (nodeSearchDataPtr) searchInf->data;
+ searchData->url = (xmlChar *) xmlMemStrdup((char *) url);
+ searchData->lineNo = lineNumber;
+ walkStylesheets((xmlHashScanner) findNodeByLineNoHelper, searchInf,
+ ctxt->style);
+ if (!searchInf->found) {
+ /* try searching the document set */
+ xsltDocumentPtr document = ctxt->document;
+
+ while (document && !searchInf->found) {
+ walkChildNodes((xmlHashScanner) scanForNode, searchInf,
+ (xmlNodePtr) document->doc);
+ document = document->next;
+ }
+ }
+ result = searchData->node;
+ searchFreeInfo(searchInf);
+
+ return result;
+}
+
+
+/**
+ * findTemplateNode:
+ * @style: A valid stylesheet collection to look into
+ * @name: A valid template name to look for
+ *
+ * Find a template node
+ *
+ * Returns The template node found if successful,
+ * NULL otherwise
+ */
+xmlNodePtr
+findTemplateNode(xsltStylesheetPtr style, const xmlChar * name)
+{
+ xmlNodePtr result = NULL;
+ xmlChar *templName;
+ xsltTemplatePtr templ;
+
+ if (!style || !name) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Invalid stylesheet or template name : findTemplateNode\n");
+#endif
+ return result;
+ }
+
+ while (style) {
+ templ = style->templates;
+
+ while (templ) {
+ if (templ->match)
+ templName = (xmlChar *) templ->match;
+ else
+ templName = (xmlChar *) templ->name;
+
+ if (templName) {
+ if (!xmlStrCmp((char *) templName, (char *) name)) {
+ return templ->elem;
+ }
+ }
+ templ = templ->next;
+ }
+ if (style->next)
+ style = style->next;
+ else
+ style = style->imports;
+ }
+
+ if (!result)
+ xsldbgGenericErrorFunc(i18n("Error: XSLT template named \"%1\" was not found.\n").arg(xsldbgText(name)));
+ return result;
+}
+
+
+/**
+ * findBreakPointByName:
+ * @templateName: The template name to look for
+ *
+ * Find the breakpoint at template with "match" or "name" equal
+ * to templateName
+ *
+ * Returns The break point that matches @templateName
+ * NULL otherwise
+*/
+breakPointPtr
+findBreakPointByName(const xmlChar * templateName)
+{
+ breakPointPtr result = NULL;
+ searchInfoPtr searchInf = searchNewInfo(SEARCH_BREAKPOINT);
+ breakPointSearchDataPtr searchData;
+
+ if (!searchInf || (searchInf->type != SEARCH_BREAKPOINT))
+ return result;
+
+ searchData = (breakPointSearchDataPtr) searchInf->data;
+ searchData->templateName = (xmlChar *) xmlStrdup(templateName);
+ if (templateName) {
+ walkBreakPoints((xmlHashScanner) scanForBreakPoint, searchInf);
+ if (!searchInf->found) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Breakpoint with template name of \"%s\" not found\n",
+ templateName);
+#endif
+ } else
+ result = searchData->breakPtr;
+ }
+
+ searchFreeInfo(searchInf);
+
+ return result;
+}
+
+
+/**
+ * findBreakPointById:
+ * @id: The break point id to look for
+ *
+ * Find a break point by its id
+ *
+ * Returns The break point with given the break point id if found,
+ * NULL otherwise
+ */
+breakPointPtr
+findBreakPointById(int id)
+{
+ breakPointPtr result = NULL;
+ searchInfoPtr searchInf = searchNewInfo(SEARCH_BREAKPOINT);
+ breakPointSearchDataPtr searchData;
+
+ if (!searchInf || !searchInf->data)
+ return result;
+
+ searchData = (breakPointSearchDataPtr) searchInf->data;
+ if (id >= 0) {
+ searchData->id = id;
+ walkBreakPoints((xmlHashScanner) scanForBreakPoint, searchInf);
+ if (!searchInf->found) {
+#ifdef WITH_XSLDBG_DEBUG_PROCESS
+ xsltGenericError(xsltGenericErrorContext,
+ "Error: Breakpoint id %d not found\n", id);
+#endif
+ } else
+ result = searchData->breakPtr;
+ }
+
+ searchFreeInfo(searchInf);
+ return result;
+}
+
+
+/**
+ * findNodesByQuery:
+ * @query: The xpath query to run, see docs/en/search.dtd for more details
+ *
+ * Find nodes in search dataBase using an xpath query
+ *
+ * Returns The nodes that match the given query on success,
+ * NULL otherwise
+ */
+xmlXPathObjectPtr
+findNodesByQuery(const xmlChar * query)
+{
+ Q_UNUSED(query);
+ xmlXPathObjectPtr list = NULL;
+
+ return list;
+}
+
+
+
+/**
+ * walkBreakPoints:
+ * @walkFunc: The function to callback for each break point found
+ * @data: The extra data to pass onto walkFunc
+ *
+ * Walks through all break points calling walkFunc for each. The payload
+ * sent to walkFunc is of type breakPointPtr
+ */
+void
+walkBreakPoints(xmlHashScanner walkFunc, void *data)
+{
+ int lineNo;
+ xmlHashTablePtr hashTable;
+
+ if (!walkFunc)
+ return;
+
+ for (lineNo = 0; lineNo < breakPointLinesCount(); lineNo++) {
+ hashTable = breakPointGetLineNoHash(lineNo);
+ if (hashTable) {
+ xmlHashScan(hashTable, walkFunc, data);
+ }
+ }
+}
+
+
+/**
+ * walkTemplates:
+ * @walkFunc: The function to callback for each template found
+ * @data: The extra data to pass onto walkFunc
+ * @style: The stylesheet to start from
+ *
+ * Walks through all templates calling walkFunc for each. The payload
+ * of walkFunc is of type xsltTemplatePtr
+ */
+void
+walkTemplates(xmlHashScanner walkFunc, void *data, xsltStylesheetPtr style)
+{
+ xsltTemplatePtr templ;
+
+ if (!walkFunc || !style)
+ return;
+
+ while (style) {
+ templ = style->templates;
+ while (templ) {
+ (*walkFunc) (templ, data, NULL);
+ templ = templ->next;
+ }
+ if (style->next)
+ style = style->next;
+ else
+ style = style->imports;
+ }
+}
+
+
+/**
+ * walkStylesheets:
+ * @walkFunc: The function to callback for each stylesheet found
+ * @data: The extra data to pass onto walkFunc
+ * @style: The stylesheet to start from
+ *
+ * Walks through all templates calling walkFunc for each. The payload
+ * sent to walkFunc is of type xsltStylesheetPtr
+ */
+void
+walkStylesheets(xmlHashScanner walkFunc, void *data,
+ xsltStylesheetPtr style)
+{
+ xsltStylesheetPtr next;
+
+ if (!walkFunc || !style)
+ return;
+
+ next = style->next;
+ while (style) {
+ (*walkFunc) (style, data, NULL);
+ if (style->imports)
+ style = style->imports;
+ else
+ style = next;
+ }
+}
+
+
+
+xmlHashScanner globalWalkFunc = NULL;
+
+/**
+ * globalVarHelper:
+ * @payload: valid xsltStylesheetPtr
+ * @data: is valid
+ * @name: not used
+ *
+ * Helper to find the global variables. We are given control via
+ * walkStylesheets globalWalkFunc will always be set to the
+ * walkFunc to call
+ */
+void
+globalVarHelper(void **payload, void *data,
+ xmlChar * name)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(name);
+ xsltStylesheetPtr style = (xsltStylesheetPtr) payload;
+ xsltStackElemPtr global;
+
+ if (style) {
+ global = style->variables;
+
+ while (global &&global->comp) {
+ (*globalWalkFunc) (global->comp->inst, data, NULL);
+ global = global->next;
+ }
+ }
+}
+
+
+/**
+ * walkGlobals:
+ * @walkFunc: The function to callback for each gobal variable found
+ * @data: The extra data to pass onto walkFunc
+ * @style: The stylesheet to start from
+ *
+ * Call walkFunc for each global variable. The payload
+ * sent to walkFunc is of type xmlNodePtr
+ */
+void
+walkGlobals(xmlHashScanner walkFunc, void *data,
+ xsltStylesheetPtr style)
+{
+ Q_UNUSED(data);
+ if (!walkFunc || !style)
+ return;
+
+ globalWalkFunc = walkFunc;
+
+ walkStylesheets((xmlHashScanner) globalVarHelper, data, style);
+}
+
+
+
+xmlHashScanner localWalkFunc = NULL;
+
+/**
+ * localVarHelper:
+ * @payload: valid xsltTemplatePtr
+ * @data: is valid
+ * @name: not used
+ *
+ * Helper to find the local variables. We are given control via walkTemplates
+ * globalWalkFunc will always be set to the walkFunc to call
+ * localWalkFunc will always be set to the walkFunc to call
+ */
+void
+localVarHelper(void **payload, void *data,
+ xmlChar * name)
+{
+ Q_UNUSED(data);
+ Q_UNUSED(name);
+ xsltTemplatePtr templ = (xsltTemplatePtr) payload;
+ xmlNodePtr node;
+
+ if (templ && templ->elem) {
+ node = templ->elem->children;
+
+ while (node) {
+ if (IS_XSLT_NAME(node, "param")
+ || IS_XSLT_NAME(node, "variable")) {
+ (*localWalkFunc) (node, data, NULL);
+ node = node->next;
+ } else
+ break;
+ }
+ }
+}
+
+
+/**
+ * walkLocals:
+ * @walkFunc: The function to callback for each local variable found
+ * @data: The extra data to pass onto walkFunc
+ * @style: The stylesheet to start from
+ *
+ * Walks through all local variables calling walkFunc for each. The payload
+ * of walkFunc is of type xmlNodePtr
+ */
+void
+walkLocals(xmlHashScanner walkFunc, void *data, xsltStylesheetPtr style)
+{
+ if (!walkFunc || !style)
+ return;
+
+ localWalkFunc = walkFunc;
+
+ walkTemplates((xmlHashScanner) localVarHelper, data, style);
+
+}
+
+
+/**
+ * walkIncludes:
+ * @walkFunc: The function to callback for each included stylesheet
+ * @data: The extra data to pass onto walkFunc
+ * @style: The stylesheet to start from
+ *
+ * Walks through all included stylesheets calling walkFunc for each.
+ * The payload of walkFunc is of type xmlNodePtr
+ */
+
+void
+walkIncludes(xmlHashScanner walkFunc, void *data, xsltStylesheetPtr style)
+{
+ xsltDocumentPtr document; /* included xslt documents */
+
+ if (!walkFunc || !style)
+ return;
+
+ while (style) {
+ document = style->docList;
+ /* look at included documents */
+ while (document) {
+ (*walkFunc) ((xmlNodePtr) document->doc, data, NULL);
+ document = document->next;
+ }
+ /* try next stylesheet */
+ if (style->next)
+ style = style->next;
+ else
+ style = style->imports;
+ }
+}
+
+
+/**
+ * walkIncludeInst:
+ * @walkFunc: The function to callback for each xsl:include instruction found
+ * @data: The extra data to pass onto walkFunc
+ * @style: The stylesheet to start from
+ *
+ * Walks through all xsl:include calling walkFunc for each. The payload
+ * of walkFunc is of type xmlNodePtr
+ */
+void
+walkIncludeInst(xmlHashScanner walkFunc, void *data,
+ xsltStylesheetPtr style)
+{
+ xmlNodePtr node = NULL, styleChild = NULL;
+
+ if (!walkFunc || !style)
+ return;
+
+ while (style) {
+ /*look for stylesheet node */
+ if (style->doc) {
+ node = (xmlNodePtr) style->doc->children;
+ while (node) {
+ /* not need but just in case :) */
+ if (IS_XSLT_NAME(node, "stylesheet")
+ || IS_XSLT_NAME(node, "transform")) {
+ styleChild = node->children; /* get the topmost elements */
+ break;
+ } else
+ node = node->next;
+ }
+
+ /* look for includes */
+ while (styleChild) {
+ if (IS_XSLT_NAME(styleChild, "include"))
+ (*walkFunc) (styleChild, data, NULL);
+ styleChild = styleChild->next;
+ }
+ }
+ /* try next stylesheet */
+ if (style->next)
+ style = style->next;
+ else
+ style = style->imports;
+ }
+}
+
+
+/**
+ * walkChildNodes:
+ * @walkFunc: The function to callback for each child/sibling found
+ * @data: The extra data to pass onto walkFunc
+ * @node: Is valid
+ *
+ * Call walkFunc for each child of @node the payload sent to walkFunc is
+ * a xmlNodePtr
+ */
+void
+walkChildNodes(xmlHashScanner walkFunc, void *data, xmlNodePtr node)
+{
+ xmlNodePtr child = NULL;
+ searchInfoPtr searchInf = (searchInfoPtr) data;
+
+ if (!walkFunc || !searchInf || !searchInf->data)
+ return;
+
+ while (node && !searchInf->found) {
+ (walkFunc) (node, data, NULL);
+ child = node->children;
+ if (child && !searchInf->found) {
+ walkChildNodes(walkFunc, data, child);
+ }
+ node = node->next;
+ }
+}
+
+
+/**
+ * searchBreakPointNode:
+ * @breakPtr: Is valid
+ *
+ * Convert @breakPtr into search dataBase format
+ *
+ * Returns @breakPtr as a new xmlNode in search dataBase format
+ * if successful,
+ * NULL otherwise
+ */
+xmlNodePtr
+searchBreakPointNode(breakPointPtr breakPtr)
+{
+
+ xmlNodePtr node = NULL;
+ int result = 1;
+
+ if (breakPtr) {
+ node = xmlNewNode(NULL, (xmlChar *) "breakpoint");
+ if (node) {
+ /* if unable to create any property failed then result will be equal to 0 */
+ result = result
+ && (xmlNewProp(node, (xmlChar *) "url", breakPtr->url) !=
+ NULL);
+ sprintf((char *) searchBuffer, "%ld", breakPtr->lineNo);
+ result = result
+ &&
+ (xmlNewProp(node, (xmlChar *) "line", (xmlChar *) searchBuffer)
+ != NULL);
+ if (breakPtr->templateName) {
+ result = result
+ &&
+ (xmlNewProp
+ (node, (xmlChar *) "template",
+ breakPtr->templateName) != NULL);
+ }
+ sprintf((char *) searchBuffer, "%d", breakPtr->flags & BREAKPOINT_ENABLED);
+ result = result
+ &&
+ (xmlNewProp
+ (node, (xmlChar *) "enabled", (xmlChar *) searchBuffer)
+ != NULL);
+ sprintf((char *) searchBuffer, "%d", breakPtr->type);
+ result = result
+ &&
+ (xmlNewProp(node, (xmlChar *) "type", (xmlChar *) searchBuffer)
+ != NULL);
+ sprintf((char *) searchBuffer, "%d", breakPtr->id);
+ result = result
+ && (xmlNewProp(node, (xmlChar *) "id", (xmlChar *) searchBuffer)
+ != NULL);
+ } else
+ result = 0;
+ if (!result) {
+ xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
+ }
+ }
+ return node;
+}
+
+
+/**
+ * searchTemplateNode:
+ * @templNode: Is valid
+ *
+ * Convert @templateNode into search dataBase format
+ *
+ * Returns @templNode as a new xmlNode in search dataBase format
+ * if successful,
+ * NULL otherwise
+ */
+xmlNodePtr
+searchTemplateNode(xmlNodePtr templNode)
+{
+ xmlNodePtr node = NULL;
+ xmlChar *value;
+ int result = 1;
+
+ if (templNode) {
+ node = xmlNewNode(NULL, (xmlChar *) "template");
+ if (node) {
+ /* if unable to create any property failed then result will be equal to 0 */
+ value = xmlGetProp(templNode, (xmlChar *) "match");
+ if (value) {
+ result = result
+ && (xmlNewProp(node, (xmlChar *) "match", value) !=
+ NULL);
+ xmlFree(value);
+ }
+ value = xmlGetProp(templNode, (xmlChar *) "name");
+ if (value) {
+ result = result
+ && (xmlNewProp(node, (xmlChar *) "name", value) !=
+ NULL);
+ xmlFree(value);
+ }
+ if (templNode->doc) {
+ result = result
+ &&
+ (xmlNewProp
+ (node, (xmlChar *) "url",
+ templNode->doc->URL) != NULL);
+ }
+ sprintf((char *) searchBuffer, "%ld", xmlGetLineNo(templNode));
+ result = result
+ &&
+ (xmlNewProp(node, (xmlChar *) "line", (xmlChar *) searchBuffer)
+ != NULL);
+ if (result) {
+ xmlNodePtr textNode = searchCommentNode(templNode);
+
+ if (textNode && !xmlAddChild(node, textNode))
+ result = 0;
+ }
+ } else
+ result = 0;
+ if (!result) {
+ xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
+ }
+ }
+ return node;
+}
+
+
+/**
+ * searchGlobalNode:
+ * @globalVariable: Is valid
+ *
+ * Convert @globalVariable into search dataBase format
+ *
+ * Returns @globalVariable as a new xmlNode in search dataBase format
+ * if successful,
+ * NULL otherwise
+ */
+xmlNodePtr
+searchGlobalNode(xmlNodePtr variable)
+{
+ xmlNodePtr node = NULL;
+ int result = 1;
+ xmlChar *value;
+
+ if (variable) {
+ node = xmlNewNode(NULL, (xmlChar *) "variable");
+ if (node) {
+ /* if unable to create any property failed then result will be equal to 0 */
+ if (variable->doc) {
+ result = result &&
+ (xmlNewProp(node, (xmlChar *) "url",
+ variable->doc->URL) != NULL);
+ sprintf((char *) searchBuffer, "%ld", xmlGetLineNo(variable));
+ result = result
+ && (xmlNewProp(node, (xmlChar *) "line",
+ (xmlChar *) searchBuffer) != NULL);