--- src/extension/implementation/script.cpp Mon Jan 06 07:49:17 2014 +++ src/extension/implementation/script.cpp Wed Jan 15 10:40:18 2014 @@ -63,7 +63,17 @@ #include "registrytool.h" #endif +#define SCRIPT_DEBUG +#ifdef SCRIPT_DEBUG +# define debug(f, a...) { g_print("%s(%d) %s:", \ + __FILE__,__LINE__,__FUNCTION__); \ + g_print(f, ## a); \ + g_print("\n"); \ + } +#else +# define debug(f, a...) /* */ +#endif /** This is the command buffer that gets allocated from the stack */ #define BUFSIZE (255) @@ -117,23 +127,40 @@ { interpreter_t const *interp = 0; bool foundInterp = false; + std::string interpName = ""; + std::string interpArgs = ""; + debug("Full interpNameArg: %s", interpNameArg.c_str()); + size_t argspos = interpNameArg.find_first_of(" ", 0); + debug("Args position: %i", argspos); + interpName = interpNameArg.substr(0, argspos); + if (argspos != std::string::npos) { + interpArgs = interpNameArg.substr(argspos); + } for (interp = interpreterTab ; interp->identity ; interp++ ){ - if (interpNameArg == interp->identity) { + if (interpName == interp->identity) { foundInterp = true; break; } } // Do we have a supported interpreter type? + std::string interpreter_path; if (!foundInterp) { - return ""; + interpreter_path = Glib::filename_from_utf8(interpName); + } else { + interpreter_path = Glib::filename_from_utf8(interp->defaultval); } - std::string interpreter_path = Glib::filename_from_utf8(interp->defaultval); // 1. Check preferences for an override. // Note: this must be an absolute path. Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring prefInterp = prefs->getString("/extensions/" + Glib::ustring(interp->prefstring)); + Glib::ustring prefInterp; + + if (!foundInterp) { + prefInterp = prefs->getString("/extensions/" + Glib::ustring(interpName)); + } else { + prefInterp = prefs->getString("/extensions/" + Glib::ustring(interp->prefstring)); + } if (!prefInterp.empty()) { interpreter_path = Glib::filename_from_utf8(prefInterp); @@ -146,6 +173,13 @@ if (!Glib::path_is_absolute(interpreter_path)) { interpreter_path = Glib::find_program_in_path(interpreter_path); } + + // 2. Add the arguments. + if (!interpArgs.empty()) { + debug("Arguments: %s", interpArgs.c_str()); + interpreter_path.append(interpArgs); + } + return interpreter_path; } @@ -326,7 +360,11 @@ const gchar *interpretstr = child_repr->attribute("interpreter"); if (interpretstr != NULL) { std::string interpString = resolveInterpreterExecutable(interpretstr); - command.insert(command.end(), interpString); + if (!interpString.empty()) { + command.insert(command.end(), interpString); + } else { + break; + } } command.insert(command.end(), solve_reldir(child_repr)); } @@ -958,8 +996,21 @@ if (!Glib::path_is_absolute(program)) { program = Glib::find_program_in_path(program); } + size_t argspos = program.find_first_of(" ", 0); + std::string programArgs = ""; + if (argspos != std::string::npos) { + programArgs = program.substr(argspos); + } + program = program.substr(0, argspos); argv.push_back(program); - + debug("Executed programm: %s", program.c_str()); + + // get the command line arguments + if (!programArgs.empty()) { + argv.push_back(programArgs); + debug("Executed programm arguments: %s", programArgs.c_str()); + } + if (interpreted) { // On Windows, Python garbles Unicode command line parameters // in an useless way. This means extensions fail when Inkscape @@ -974,7 +1025,8 @@ working_directory = workdir_s; g_free(workdir_s); #endif - + debug(" ## Working directory: %s", working_directory.c_str()); + debug(" ## Executed script: %s", script.c_str()); argv.push_back(script); }