summaryrefslogtreecommitdiffstats
path: root/src/extension/script/InkscapeScript.cpp
diff options
context:
space:
mode:
authorMenTaLguY <mental@rydia.net>2006-01-16 02:36:01 +0000
committermental <mental@users.sourceforge.net>2006-01-16 02:36:01 +0000
commit179fa413b047bede6e32109e2ce82437c5fb8d34 (patch)
treea5a6ac2c1708bd02288fbd8edb2ff500ff2e0916 /src/extension/script/InkscapeScript.cpp
downloadinkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.tar.gz
inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.zip
moving trunk for module inkscape
(bzr r1)
Diffstat (limited to 'src/extension/script/InkscapeScript.cpp')
-rw-r--r--src/extension/script/InkscapeScript.cpp177
1 files changed, 177 insertions, 0 deletions
diff --git a/src/extension/script/InkscapeScript.cpp b/src/extension/script/InkscapeScript.cpp
new file mode 100644
index 000000000..cc9271caa
--- /dev/null
+++ b/src/extension/script/InkscapeScript.cpp
@@ -0,0 +1,177 @@
+/**
+ * Inkscape Scripting container
+ *
+ * Authors:
+ * Bob Jamison <rjamison@titan.com>
+ *
+ * Copyright (C) 2004 Authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "InkscapeScript.h"
+
+#include "InkscapeInterpreter.h"
+
+#ifdef WITH_PERL
+# include "InkscapePerl.h"
+#endif
+
+#ifdef WITH_PYTHON
+# include "InkscapePython.h"
+#endif
+
+
+namespace Inkscape {
+namespace Extension {
+namespace Script {
+
+
+/**
+ *
+ */
+InkscapeScript::InkscapeScript()
+{
+
+
+
+}
+
+
+
+
+/**
+ *
+ */
+InkscapeScript::~InkscapeScript()
+{
+
+
+}
+
+
+
+
+/**
+ *
+ */
+bool InkscapeScript::interpretScript(Glib::ustring &script,
+ Glib::ustring &output,
+ Glib::ustring &error,
+ ScriptLanguage language)
+{
+#ifndef __GNUC__
+ static char const __FUNCTION__[] = "interpretScript";
+#endif
+ char * langname=NULL;
+ InkscapeInterpreter *interp = NULL;
+ //if() instead of switch() lets us scope vars
+ if (language == InkscapeScript::PERL)
+ {
+#ifdef WITH_PERL
+ langname="Perl";
+ interp = new InkscapePerl();
+#endif
+ }
+ else if (language == InkscapeScript::PYTHON)
+ {
+#ifdef WITH_PYTHON
+ langname="Python";
+ interp = new InkscapePython();
+#endif
+ }
+ else
+ {
+ //replace with g_error
+ fprintf(stderr, "%s: Unknown Script Language type: %d\n",
+ __FUNCTION__, language);
+ return false;
+ }
+
+ if (!interp)
+ {
+ fprintf(stderr, "%s: error starting Language '%s'\n",
+ __FUNCTION__, langname);
+ return false;
+ }
+
+ if (!interp->interpretScript(script, output, error))
+ {
+ fprintf(stderr, "%s: error in executing %s script\n",
+ __FUNCTION__, langname);
+ return false;
+ }
+
+ delete interp;
+
+ return true;
+}
+
+/**
+ *
+ */
+bool InkscapeScript::interpretUri(Glib::ustring &uri,
+ Glib::ustring &output,
+ Glib::ustring &error,
+ ScriptLanguage language)
+{
+
+ InkscapeInterpreter *interp = NULL;
+ //if() instead of switch() lets us scope vars
+ if (language == InkscapeScript::PERL)
+ {
+#ifdef WITH_PERL
+ interp = new InkscapePerl();
+#endif
+ }
+ else if (language == InkscapeScript::PYTHON)
+ {
+#ifdef WITH_PYTHON
+ interp = new InkscapePython();
+#endif
+ }
+ else
+ {
+ //replace with g_error
+ fprintf(stderr, "Unknown Script Language type:%d\n", language);
+ return false;
+ }
+
+ if (!interp)
+ return false;
+
+ if (!interp->interpretUri(uri, output, error))
+ {
+ fprintf(stderr, "error in executing script '%s'\n", uri.raw().c_str());
+ return false;
+ }
+
+ return true;
+}
+
+
+
+
+
+
+
+
+
+} // namespace Script
+} // namespace Extension
+} // namespace Inkscape
+
+//#########################################################################
+//# E N D O F F I L E
+//#########################################################################
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :