summaryrefslogtreecommitdiffstats
path: root/src/extension/script/InkscapeScript.cpp
blob: 87d120245f038983fc15780bb8c3bb18d49ff84d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
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()
{
}




/**
 * Interprets the script in the 'script' buffer,
 * storing the stdout output in 'output', and any
 * error messages in 'error.'  Language is one of the
 * enumerated types in ScriptLanguage above.
 */
bool InkscapeScript::interpretScript(const Glib::ustring &script,
                                 Glib::ustring &output,
                                 Glib::ustring &error,
                                 ScriptLanguage language)
{
    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
        {
        g_error("interpretScript: Unknown Script Language type: %d\n",
                        language);
        return false;
        }

    if (!interp)
        {
        g_error("interpretScript: error starting Language '%s'\n",
                        langname);
        return false;
        }

    if (!interp->interpretScript(script, output, error))
        {
        g_error("interpretScript: error in executing %s script\n",
                        langname);
        return false;
        }

    delete interp;

    return true;
}

/**
 * Interprets the script in the 'script' buffer,
 * storing the stdout output in 'output', and any
 * error messages in 'error.'  Language is one of the
 * enumerated types in ScriptLanguage above.
 */
bool InkscapeScript::interpretUri(const 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
        {
        g_error("interpretUri: Unknown Script Language type:%d\n",
                           language);
        return false;
        }

    if (!interp)
        return false;

    if (!interp->interpretUri(uri, output, error))
        {
        g_error("interpretUri: error in executing script '%s'\n",
                           uri.raw().c_str());
        return false;
        }

    delete interp;

    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 :