summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7053d7f)
raw | patch | inline | side by side (parent: 7053d7f)
author | Jon A. Cruz <jon@joncruz.org> | |
Mon, 1 Mar 2010 02:09:58 +0000 (18:09 -0800) | ||
committer | Jon A. Cruz <jon@joncruz.org> | |
Mon, 1 Mar 2010 02:09:58 +0000 (18:09 -0800) |
General cleanup.
src/extension/implementation/script.cpp | patch | blob | history | |
src/extension/implementation/script.h | patch | blob | history |
index cd25d593a069129d9529ea019bd9347ac5972e14..03bbf25c99af8ed1df8f017899edd60717289cce 100644 (file)
* Authors:
* Bryce Harrington <bryce@osdl.org>
* Ted Gould <ted@gould.cx>
+ * Jon A. Cruz <jon@joncruz.org>
*
* Copyright (C) 2002-2005,2007 Authors
*
This just keeps coming the events through so that we'll make the GUI
update and look pretty.
*/
-void
-Script::pump_events (void) {
- while( Gtk::Main::events_pending() )
+void Script::pump_events (void) {
+ while ( Gtk::Main::events_pending() ) {
Gtk::Main::iteration();
+ }
return;
}
\param interpNameArg The name of the interpreter that we're looking
for, should be an entry in interpreterTab
*/
-Glib::ustring
-Script::resolveInterpreterExecutable(const Glib::ustring &interpNameArg)
+Glib::ustring Script::resolveInterpreterExecutable(const Glib::ustring &interpNameArg)
{
-
Glib::ustring interpName = interpNameArg;
- interpreter_t const *interp;
+ interpreter_t const *interp = 0;
bool foundInterp = false;
for (interp = interpreterTab ; interp->identity ; interp++ ){
if (interpName == interp->identity) {
}
// Do we have a supported interpreter type?
- if (!foundInterp)
+ if (!foundInterp) {
return "";
+ }
interpName = interp->defaultval;
// 1. Check preferences
Glib::ustring path;
Glib::ustring exeName;
if (rt.getExeInfo(fullPath, path, exeName)) {
+// TODO replace with proper glib/glibmm path building routines:
Glib::ustring interpPath = path;
interpPath.append("\\");
interpPath.append(interpNameArg);
interpPath.append(interpName);
interpPath.append(".exe");
struct stat finfo;
- if (stat(interpPath .c_str(), &finfo) ==0) {
+ if (stat(interpPath .c_str(), &finfo) == 0) {
g_message("Found local interpreter, '%s', Size: %d",
interpPath .c_str(),
(int)finfo.st_size);
}
// 3. Try searching the path
- char szExePath[MAX_PATH];
- char szCurrentDir[MAX_PATH];
+ char szExePath[MAX_PATH] = {0};
+ char szCurrentDir[MAX_PATH] = {0};
GetCurrentDirectory(sizeof(szCurrentDir), szCurrentDir);
- HINSTANCE ret = FindExecutable(
- interpName.c_str(), szCurrentDir, szExePath);
- if (((unsigned long) ret) > 32) {
+ HINSTANCE ret = FindExecutable(interpName.c_str(), szCurrentDir, szExePath);
+ if (ret > reinterpret_cast<HINSTANCE>(32)) {
interpName = szExePath;
return interpName;
}
Glib::ustring filename = fname;
g_free(fname);
- if ( Inkscape::IO::file_test(filename.c_str(), G_FILE_TEST_EXISTS) )
+ if ( Inkscape::IO::file_test(filename.c_str(), G_FILE_TEST_EXISTS) ) {
return filename;
-
+ }
}
} else {
Glib::ustring str = sp_repr_children(reprin)->content();
then a TRUE is returned. If we get all the way through the path
then a FALSE is returned, the command could not be found.
*/
-bool
-Script::check_existance(const Glib::ustring &command)
+bool Script::check_existance(const Glib::ustring &command)
{
// Check the simple case first
//Don't search when it contains a slash. */
if (command.find(G_DIR_SEPARATOR) != command.npos) {
- if (Inkscape::IO::file_test(command.c_str(), G_FILE_TEST_EXISTS))
+ if (Inkscape::IO::file_test(command.c_str(), G_FILE_TEST_EXISTS)) {
return true;
- else
+ } else {
return false;
+ }
}
Glib::ustring path;
gchar *s = (gchar *) g_getenv("PATH");
- if (s)
+ if (s) {
path = s;
- else
+ } else {
/* There is no `PATH' in the environment.
The default search path is the current directory */
path = G_SEARCHPATH_SEPARATOR_S;
+ }
std::string::size_type pos = 0;
std::string::size_type pos2 = 0;
and should error out at a higher level.
*/
-bool
-Script::load(Inkscape::Extension::Extension *module)
+bool Script::load(Inkscape::Extension::Extension *module)
{
- if (module->loaded())
+ if (module->loaded()) {
return true;
+ }
helper_extension = "";
This function just sets the module to unloaded. It free's the
command if it has been allocated.
*/
-void
-Script::unload(Inkscape::Extension::Extension */*module*/)
+void Script::unload(Inkscape::Extension::Extension */*module*/)
{
command.clear();
helper_extension = "";
bool
Script::check(Inkscape::Extension::Extension *module)
{
- int script_count = 0;
+ int script_count = 0;
Inkscape::XML::Node *child_repr = sp_repr_children(module->get_repr());
while (child_repr != NULL) {
if (!strcmp(child_repr->name(), INKSCAPE_EXTENSION_NS "script")) {
- script_count++;
+ script_count++;
child_repr = sp_repr_children(child_repr);
while (child_repr != NULL) {
if (!strcmp(child_repr->name(), INKSCAPE_EXTENSION_NS "check")) {
child_repr = sp_repr_next(child_repr);
}
- if (script_count == 0) {
- return false;
- }
+ if (script_count == 0) {
+ return false;
+ }
return true;
}
unlink(_filename.c_str());
}
-ImplementationDocumentCache *
-Script::newDocCache( Inkscape::Extension::Extension * /*ext*/, Inkscape::UI::View::View * view ) {
+ImplementationDocumentCache *Script::newDocCache( Inkscape::Extension::Extension * /*ext*/, Inkscape::UI::View::View * view ) {
return new ScriptDocCache(view);
}
@@ -502,8 +501,7 @@ Script::newDocCache( Inkscape::Extension::Extension * /*ext*/, Inkscape::UI::Vie
This function should really do something, right now it doesn't.
*/
-Gtk::Widget *
-Script::prefs_input(Inkscape::Extension::Input *module,
+Gtk::Widget *Script::prefs_input(Inkscape::Extension::Input *module,
const gchar */*filename*/)
{
return module->autogui(NULL, NULL);
This function should really do something, right now it doesn't.
*/
-Gtk::Widget *
-Script::prefs_output(Inkscape::Extension::Output *module)
+Gtk::Widget *Script::prefs_output(Inkscape::Extension::Output *module)
{
return module->autogui(NULL, NULL);
}
the incoming filename (so that it's not the temporary filename).
That document is then returned from this function.
*/
-SPDocument *
-Script::open(Inkscape::Extension::Input *module,
+SPDocument *Script::open(Inkscape::Extension::Input *module,
const gchar *filenameArg)
{
std::list<std::string> params;
put the output of the script into the final output file. We then
delete the temporary file.
*/
-void
-Script::save(Inkscape::Extension::Output *module,
+void Script::save(Inkscape::Extension::Output *module,
SPDocument *doc,
const gchar *filenameArg)
{
// FIXME: convert to utf8 (from "filename encoding") and unlink_utf8name
unlink(tempfilename_in.c_str());
- if(success == false) {
+ if (success == false) {
throw Inkscape::Extension::Output::save_failed();
}
exists at the time, the other is created by that script). At that
point both should be full, and the second one is loaded.
*/
-void
-Script::effect(Inkscape::Extension::Effect *module,
+void Script::effect(Inkscape::Extension::Effect *module,
Inkscape::UI::View::View *doc,
ImplementationDocumentCache * docCache)
{
elements and putting them into the old document. The copy
is then complete.
*/
-void
-Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newroot)
+void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newroot)
{
std::vector<Inkscape::XML::Node *> delete_list;
Inkscape::XML::Node * oldroot_namedview = NULL;
delete_list.push_back(child);
}
}
- for (unsigned int i = 0; i < delete_list.size(); i++)
+ for (unsigned int i = 0; i < delete_list.size(); i++) {
sp_repr_unparent(delete_list[i]);
+ }
for (Inkscape::XML::Node * child = newroot->firstChild();
child != NULL;
}
// Delete the attributes of the old root nodes.
- for (std::vector<gchar const *>::const_iterator it = attribs.begin(); it != attribs.end(); it++)
+ for (std::vector<gchar const *>::const_iterator it = attribs.begin(); it != attribs.end(); it++) {
oldroot->setAttribute(*it, NULL);
+ }
// Set the new attributes.
for (List<AttributeRecord const> iter = newroot->attributeList(); iter; ++iter) {
shows it in a warning dialog to the user
\param filename Filename of the stderr file
*/
-void
-Script::checkStderr (const Glib::ustring &data,
+void Script::checkStderr (const Glib::ustring &data,
Gtk::MessageType type,
const Glib::ustring &message)
{
return;
}
-bool
-Script::cancelProcessing (void) {
+bool Script::cancelProcessing (void) {
_canceled = true;
_main_loop->quit();
Glib::spawn_close_pid(_pid);
At the very end (after the data has been copied) both of the files
are closed, and we return to what we were doing.
*/
-int
-Script::execute (const std::list<std::string> &in_command,
+int Script::execute (const std::list<std::string> &in_command,
const std::list<std::string> &in_params,
const Glib::ustring &filein,
file_listener &fileout)
//std::cout << "first space " << first_space << std::endl;
//std::cout << "first quote " << first_quote << std::endl;
- if((first_quote != std::string::npos) && (first_quote == 0)) {
+ if ((first_quote != std::string::npos) && (first_quote == 0)) {
size_t next_quote = param_str.find_first_of('"', first_quote + 1);
//std::cout << "next quote " << next_quote << std::endl;
- if(next_quote != std::string::npos) {
+ if (next_quote != std::string::npos) {
//std::cout << "now split " << next_quote << std::endl;
//std::cout << "now split " << param_str.substr(1, next_quote - 1) << std::endl;
//std::cout << "now split " << param_str.substr(next_quote + 1) << std::endl;
std::string part_str = param_str.substr(1, next_quote - 1);
- if(part_str.size() > 0)
+ if (part_str.size() > 0)
argv.push_back(part_str);
param_str = param_str.substr(next_quote + 1);
- }
- else {
- if(param_str.size() > 0)
+ } else {
+ if (param_str.size() > 0)
argv.push_back(param_str);
param_str = "";
}
- }
- else if(first_space != std::string::npos) {
+ } else if (first_space != std::string::npos) {
//std::cout << "now split " << first_space << std::endl;
//std::cout << "now split " << param_str.substr(0, first_space) << std::endl;
//std::cout << "now split " << param_str.substr(first_space + 1) << std::endl;
std::string part_str = param_str.substr(0, first_space);
- if(part_str.size() > 0)
+ if (part_str.size() > 0) {
argv.push_back(part_str);
+ }
param_str = param_str.substr(first_space + 1);
- }
- else {
- if(param_str.size() > 0)
+ } else {
+ if (param_str.size() > 0) {
argv.push_back(param_str);
+ }
param_str = "";
}
- } while(param_str.size() > 0);
+ } while (param_str.size() > 0);
}
for (std::list<std::string>::const_iterator i = in_params.begin();
i != in_params.end(); i++) {
- //g_message("Script parameter: %s",(*i)g.c_str());
+ //g_message("Script parameter: %s",(*i)g.c_str());
argv.push_back(*i);
}
if (!(filein.empty())) {
- argv.push_back(filein);
+ argv.push_back(filein);
}
int stdout_pipe, stderr_pipe;
_main_loop->run();
// Ensure all the data is out of the pipe
- while (!fileout.isDead())
+ while (!fileout.isDead()) {
fileout.read(Glib::IO_IN);
- while (!fileerr.isDead())
+ }
+ while (!fileerr.isDead()) {
fileerr.read(Glib::IO_IN);
+ }
if (_canceled) {
// std::cout << "Script Canceled" << std::endl;
index 8e25fb3517b53a74e249952442650a68c230ee1c..e0b6701bf105cb5b8435c1c04a0692f0f28558f6 100644 (file)
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-#ifndef __INKSCAPE_EXTENSION_IMPEMENTATION_SCRIPT_H__
-#define __INKSCAPE_EXTENSION_IMPEMENTATION_SCRIPT_H__
+#ifndef INKSCAPE_EXTENSION_IMPEMENTATION_SCRIPT_H_SEEN
+#define INKSCAPE_EXTENSION_IMPEMENTATION_SCRIPT_H_SEEN
#include "implementation.h"
#include <gtkmm/messagedialog.h>
*/
virtual bool check(Inkscape::Extension::Extension *module);
- ImplementationDocumentCache * newDocCache (Inkscape::Extension::Extension * ext, Inkscape::UI::View::View * view);
+ ImplementationDocumentCache * newDocCache(Inkscape::Extension::Extension * ext, Inkscape::UI::View::View * view);
/**
*
*/
virtual void effect(Inkscape::Extension::Effect *module,
Inkscape::UI::View::View *doc,
- ImplementationDocumentCache * docCache);
+ ImplementationDocumentCache * docCache);
virtual bool cancelProcessing (void);
const Glib::ustring &filein,
file_listener &fileout);
- void pump_events (void);
+ void pump_events(void);
- /** \brief A definition of an interpreter, which can be specified
- in the INX file, but we need to know what to call */
- struct interpreter_t {
- gchar const *identity; /**< The ID that is in the INX file */
- gchar const *prefstring; /**< The preferences key that can override the default */
- gchar const *defaultval; /**< The default value if there are no preferences */
- };
+ /** \brief A definition of an interpreter, which can be specified
+ in the INX file, but we need to know what to call */
+ struct interpreter_t {
+ gchar const *identity; /**< The ID that is in the INX file */
+ gchar const *prefstring; /**< The preferences key that can override the default */
+ gchar const *defaultval; /**< The default value if there are no preferences */
+ };
static interpreter_t const interpreterTab[];
- Glib::ustring resolveInterpreterExecutable(const Glib::ustring &interpNameArg);
+ Glib::ustring resolveInterpreterExecutable(const Glib::ustring &interpNameArg);
}; // class Script
} // namespace Extension
} // namespace Inkscape
-#endif /* __INKSCAPE_EXTENSION_IMPEMENTATION_SCRIPT_H__ */
+#endif // INKSCAPE_EXTENSION_IMPEMENTATION_SCRIPT_H_SEEN
/*
Local Variables: