Code

still WIP. added tree-descending code
[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 {
38 }
43 /**
44  *
45  */
46 InkscapeScript::~InkscapeScript()
47 {
50 }
55 /**
56  *
57  */
58 bool InkscapeScript::interpretScript(Glib::ustring &script,
59                                  Glib::ustring &output,
60                                  Glib::ustring &error,
61                                  ScriptLanguage language)
62 {
63 #ifndef __GNUC__
64     static char const __FUNCTION__[] = "interpretScript";
65 #endif
66     char * langname=NULL;
67     InkscapeInterpreter *interp = NULL;
68     //if() instead of switch() lets us scope vars
69     if (language == InkscapeScript::PERL)
70         {
71 #ifdef WITH_PERL
72         langname="Perl";
73         interp = new InkscapePerl();
74 #endif
75         }
76     else if (language == InkscapeScript::PYTHON)
77         {
78 #ifdef WITH_PYTHON
79         langname="Python";
80         interp = new InkscapePython();
81 #endif
82         }
83     else
84         {
85         //replace with g_error
86         fprintf(stderr, "%s: Unknown Script Language type: %d\n",
87                         __FUNCTION__, language);
88         return false;
89         }
90         
91     if (!interp)
92         {
93         fprintf(stderr, "%s: error starting Language '%s'\n",
94                         __FUNCTION__, langname);
95         return false;
96         }
98     if (!interp->interpretScript(script, output, error))
99         {
100         fprintf(stderr, "%s: error in executing %s script\n",
101                         __FUNCTION__, langname);
102         return false;
103         }
104         
105     delete interp;
106     
107     return true;
110 /**
111  *
112  */
113 bool InkscapeScript::interpretUri(Glib::ustring &uri,
114                                  Glib::ustring &output,
115                                  Glib::ustring &error,
116                                  ScriptLanguage language)
119     InkscapeInterpreter *interp = NULL;
120     //if() instead of switch() lets us scope vars
121     if (language == InkscapeScript::PERL)
122         {
123 #ifdef WITH_PERL
124         interp = new InkscapePerl();
125 #endif
126         }
127     else if (language == InkscapeScript::PYTHON)
128         {
129 #ifdef WITH_PYTHON
130         interp = new InkscapePython();
131 #endif
132         }
133     else
134         {
135         //replace with g_error
136         fprintf(stderr, "Unknown Script Language type:%d\n", language);
137         return false;
138         }
139         
140     if (!interp)
141         return false;
143     if (!interp->interpretUri(uri, output, error))
144         {
145         fprintf(stderr, "error in executing script '%s'\n", uri.raw().c_str());
146         return false;
147         }
148         
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 :