1 /**
2 * Inkscape Scripting container
3 *
4 * Authors:
5 * Bob Jamison <rjamison@titan.com>
6 *
7 * Copyright (C) 2004 Authors
8 *
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 */
12 #include "InkscapeScript.h"
14 #include "InkscapeInterpreter.h"
16 #ifdef WITH_PERL
17 # include "InkscapePerl.h"
18 #endif
20 #ifdef WITH_PYTHON
21 # include "InkscapePython.h"
22 #endif
25 namespace Inkscape {
26 namespace Extension {
27 namespace Script {
30 /**
31 *
32 */
33 InkscapeScript::InkscapeScript()
34 {
35 }
40 /**
41 *
42 */
43 InkscapeScript::~InkscapeScript()
44 {
45 }
50 /**
51 * Interprets the script in the 'script' buffer,
52 * storing the stdout output in 'output', and any
53 * error messages in 'error.' Language is one of the
54 * enumerated types in ScriptLanguage above.
55 */
56 bool InkscapeScript::interpretScript(const Glib::ustring &script,
57 Glib::ustring &output,
58 Glib::ustring &error,
59 ScriptLanguage language)
60 {
61 char * langname=NULL;
62 InkscapeInterpreter *interp = NULL;
63 //if() instead of switch() lets us scope vars
64 if (language == InkscapeScript::PERL)
65 {
66 #ifdef WITH_PERL
67 langname="Perl";
68 interp = new InkscapePerl();
69 #else
70 g_print ("Internal Perl script functionality requested, but it was not compiled in!\n");
71 return false;
72 #endif
73 }
74 else if (language == InkscapeScript::PYTHON)
75 {
76 #ifdef WITH_PYTHON
77 langname="Python";
78 interp = new InkscapePython();
79 #else
80 g_print ("Internal Python script functionality requested, but it was not compiled in!\n");
81 return false;
82 #endif
83 }
84 else
85 {
86 g_error("interpretScript: Unknown Script Language type: %d\n",
87 language);
88 return false;
89 }
91 if (!interp)
92 {
93 g_error("interpretScript: error starting Language '%s'\n",
94 langname);
95 return false;
96 }
98 if (!interp->interpretScript(script, output, error))
99 {
100 g_error("interpretScript: error in executing %s script\n",
101 langname);
102 return false;
103 }
105 delete interp;
107 return true;
108 }
110 /**
111 * Interprets the script in the 'script' buffer,
112 * storing the stdout output in 'output', and any
113 * error messages in 'error.' Language is one of the
114 * enumerated types in ScriptLanguage above.
115 */
116 bool InkscapeScript::interpretUri(const Glib::ustring &uri,
117 Glib::ustring &output,
118 Glib::ustring &error,
119 ScriptLanguage language)
120 {
122 InkscapeInterpreter *interp = NULL;
123 //if() instead of switch() lets us scope vars
124 if (language == InkscapeScript::PERL)
125 {
126 #ifdef WITH_PERL
127 interp = new InkscapePerl();
128 #endif
129 }
130 else if (language == InkscapeScript::PYTHON)
131 {
132 #ifdef WITH_PYTHON
133 interp = new InkscapePython();
134 #endif
135 }
136 else
137 {
138 g_error("interpretUri: Unknown Script Language type:%d\n",
139 language);
140 return false;
141 }
143 if (!interp)
144 return false;
146 if (!interp->interpretUri(uri, output, error))
147 {
148 g_error("interpretUri: error in executing script '%s'\n",
149 uri.raw().c_str());
150 return false;
151 }
153 delete interp;
155 return true;
156 }
166 } // namespace Script
167 } // namespace Extension
168 } // namespace Inkscape
170 //#########################################################################
171 //# E N D O F F I L E
172 //#########################################################################
174 /*
175 Local Variables:
176 mode:c++
177 c-file-style:"stroustrup"
178 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
179 indent-tabs-mode:nil
180 fill-column:99
181 End:
182 */
183 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :