Code

const types
[inkscape.git] / src / extension / script / InkscapeScript.cpp
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 #endif
70         }
71     else if (language == InkscapeScript::PYTHON)
72         {
73 #ifdef WITH_PYTHON
74         langname="Python";
75         interp = new InkscapePython();
76 #endif
77         }
78     else
79         {
80         g_error("interpretScript: Unknown Script Language type: %d\n",
81                         language);
82         return false;
83         }
85     if (!interp)
86         {
87         g_error("interpretScript: error starting Language '%s'\n",
88                         langname);
89         return false;
90         }
92     if (!interp->interpretScript(script, output, error))
93         {
94         g_error("interpretScript: error in executing %s script\n",
95                         langname);
96         return false;
97         }
99     delete interp;
101     return true;
104 /**
105  * Interprets the script in the 'script' buffer,
106  * storing the stdout output in 'output', and any
107  * error messages in 'error.'  Language is one of the
108  * enumerated types in ScriptLanguage above.
109  */
110 bool InkscapeScript::interpretUri(const Glib::ustring &uri,
111                                  Glib::ustring &output,
112                                  Glib::ustring &error,
113                                  ScriptLanguage language)
116     InkscapeInterpreter *interp = NULL;
117     //if() instead of switch() lets us scope vars
118     if (language == InkscapeScript::PERL)
119         {
120 #ifdef WITH_PERL
121         interp = new InkscapePerl();
122 #endif
123         }
124     else if (language == InkscapeScript::PYTHON)
125         {
126 #ifdef WITH_PYTHON
127         interp = new InkscapePython();
128 #endif
129         }
130     else
131         {
132         g_error("interpretUri: Unknown Script Language type:%d\n",
133                            language);
134         return false;
135         }
137     if (!interp)
138         return false;
140     if (!interp->interpretUri(uri, output, error))
141         {
142         g_error("interpretUri: error in executing script '%s'\n",
143                            uri.raw().c_str());
144         return false;
145         }
147     delete interp;
149     return true;
160 }  // namespace Script
161 }  // namespace Extension
162 }  // namespace Inkscape
164 //#########################################################################
165 //# E N D    O F    F I L E
166 //#########################################################################
168 /*
169   Local Variables:
170   mode:c++
171   c-file-style:"stroustrup"
172   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
173   indent-tabs-mode:nil
174   fill-column:99
175   End:
176 */
177 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :