Ejemplo n.º 1
0
void launchCygwin(char** argValues) {
    std::string ARGV0 = *argValues;
    ++ argValues;
    size_t lastBackslash = ARGV0.rfind('\\');
    std::string directoryPrefix;
    if (lastBackslash != std::string::npos) {
        directoryPrefix = ARGV0.substr(0, lastBackslash + 1);
    }
    
    std::string cygwinBin = findCygwinBin();
    
    const char* oldPath = getenv("PATH");
    if (oldPath == 0) {
        throw std::runtime_error("getenv(\"PATH\") implausibly returned null");
    }
    // Windows doesn't support setenv but does support putenv.
    // We need cygwin1.dll to be on the PATH.
    std::string putenvArgument = std::string("PATH=") + oldPath + ";" + cygwinBin;
    if (putenv(putenvArgument.c_str()) == -1) {
        throw unix_exception(std::string("putenv(\"") + putenvArgument + "\") failed");
    }
    checkReadableFile("Cygwin DLL", cygwinBin + "\\cygwin1.dll");
    
    // Windows requires that we quote the arguments ourselves.
    typedef std::vector<std::string> Arguments;
    Arguments arguments;
    std::string program = directoryPrefix + "ruby-launcher.exe";
    // We mustn't quote the program argument but we must quote argv[0].
    arguments.push_back(quote(program));
    // Make sure we invoke the Cygwin ruby, not any native version that might be ahead of it on the PATH.
    std::string rubyInterpreter = cygwinBin + "\\ruby.exe";
    checkReadableFile("Cygwin Ruby", rubyInterpreter);
    arguments.push_back(quote(rubyInterpreter));
    while (*argValues != 0) {
        const char* argument = *argValues;
        arguments.push_back(quote(argument));
        ++ argValues;
    }
    
    typedef std::vector<char*> ArgValues;
    ArgValues childArgValues;
    for (Arguments::iterator it = arguments.begin(), en = arguments.end(); it != en; ++ it) {
        std::string& argument = *it;
        childArgValues.push_back(&argument[0]);
    }
    childArgValues.push_back(0);
    WindowsDllErrorModeChange windowsDllErrorModeChange;
    execv(program.c_str(), &childArgValues[0]);
    throw unix_exception(std::string("execv(\"") + program + "\", [" + join(", ", arguments) + "]) failed");
}
Ejemplo n.º 2
0
inline std::pair<std::size_t, char **>
collection_to_argv(const Arguments &args) {
  std::size_t nargs = args.size();
  char **argv = new char *[nargs + 1];
  typename Arguments::size_type i = 0;
  for (typename Arguments::const_iterator it = args.begin(); it != args.end();
       ++it) {
    argv[i] = new char[it->size() + 1];
    std::strncpy(argv[i], it->c_str(), it->size() + 1);
    ++i;
  }
  argv[nargs] = 0;
  return std::pair<std::size_t, char **>(nargs, argv);
} // collection_to_argv
Ejemplo n.º 3
0
 virtual bool operator()(const std::string& request_path, const std::string& full_request_path, const Arguments& arguments, http::server::reply& reply)
 {
     OSG_INFO << "RestHttpDevice :: handling request " << full_request_path << " as user-event" << std::endl;
     
     osg::ref_ptr<osgGA::Event> event = new osgGA::Event();
     event->setName(full_request_path);
     event->setTime(getDevice()->getEventQueue()->getTime());
     
     for(Arguments::const_iterator i = arguments.begin(); i != arguments.end(); ++i)
     {
         event->setUserValue(i->first,i->second);
     }
     getDevice()->getEventQueue()->addEvent(event.get());
     
     return sendOkReply(reply);
 }
Ejemplo n.º 4
0
inline
std::pair< std::size_t, char** >
collection_to_posix_argv(const Arguments& args)
{
    std::size_t nargs = args.size();
    BOOST_ASSERT(nargs > 0);

    char** argv = new char*[nargs + 1];
    typename Arguments::size_type i = 0;
    for (typename Arguments::const_iterator iter = args.begin();
         iter != args.end(); iter++) {
        argv[i] = ::strdup((*iter).c_str());
        i++;
    }
    argv[nargs] = NULL;

    return std::pair< std::size_t, char ** >(nargs, argv);
}
Ejemplo n.º 5
0
KeywordArguments::KeywordArguments(const Arguments &args) {
  bool started = false;
  unsigned count = 0;

  for (Arguments::const_iterator it = args.begin(); it != args.end(); it++) {
    size_t equal = it->find('=');

    if (equal == string::npos) {
      if (started)
        THROWS("Positional argument '" << *it << "' at " << count
               << " not allowed after keyword");

      push_back(*it); // Add positional arg

    } else {
      started = true;
      set(it->substr(0, equal), it->substr(equal + 1));
    }

    count++;
  }
}
void convertQueryArgumentsToRPCValueParams(const Arguments& args, Rpc::Value& params)
{
    for (auto arg_it = args.begin(),
              end    = args.end();
              arg_it != end;
              ++arg_it
         )
    {
        const std::string& value = arg_it->second;
        // Prevent rpc value's type errors in EmulationOfWebCtlPlugin() rpc method: use integer type if possible.
        // Strange but original webctl client code sends integer params as strings.
        try {
            params[arg_it->first] = boost::lexical_cast<int>(value); // as int
        } catch(boost::bad_lexical_cast&) {
            try {
                params[arg_it->first] = boost::lexical_cast<unsigned int>(value); // as uint
            } catch(boost::bad_lexical_cast&) {
                params[arg_it->first] = value; // as string
            }
        }
    }
}
Ejemplo n.º 7
0
inline boost::shared_array<char> collection_to_win32_cmdline(const Arguments &args) 
{ 
    typedef std::vector<std::string> arguments_t; 
    arguments_t args2; 
    typename Arguments::size_type i = 0; 
    std::size_t size = 0; 
    for (typename Arguments::const_iterator it = args.begin(); it != args.end(); ++it) 
    { 
        std::string arg = *it; 

        std::string::size_type pos = 0; 
        while ( (pos = arg.find('"', pos)) != std::string::npos) 
        { 
            arg.replace(pos, 1, "\\\""); 
            pos += 2; 
        } 

        if (arg.find(' ') != std::string::npos) 
            arg = '\"' + arg + '\"'; 

        if (i++ != args.size() - 1) 
            arg += ' '; 

        args2.push_back(arg); 
        size += arg.size() + 1; 
    } 

    boost::shared_array<char> cmdline(new char[size]); 
    cmdline.get()[0] = '\0'; 
    for (arguments_t::size_type i = 0; i < args.size(); ++i) 
#if defined(__CYGWIN__) || defined(_SCL_SECURE_NO_DEPRECATE) 
        ::strncat(cmdline.get(), args2[i].c_str(), args2[i].size()); 
#else 
        ::strcat_s(cmdline.get(), size, args2[i].c_str()); 
#endif 

    return cmdline; 
} 
Ejemplo n.º 8
0
    int run(const Properties& options, const Arguments& arguments) {
        int r = 0;

        if ((r = checkOptions(options, arguments)) != 0) {
            return r;
        }

        // parameters
        LOG4CXX_INFO(logger, "Parameters:");
        LOG4CXX_INFO(logger, boost::format("PE Mode: %d") % options.get< int >("pe-mode", 0));
        if (options.find("min-length") != options.not_found()) {
            LOG4CXX_INFO(logger, boost::format("Min length: %d") % options.get< int >("min-length"));
        }
        if (options.find("hard-clip") != options.not_found()) {
            LOG4CXX_INFO(logger, boost::format("hard clip: %d") % options.get< int >("hard-clip"));
        }
        if (options.find("quality-trim") != options.not_found()) {
            LOG4CXX_INFO(logger, boost::format("Quality Trim: %d") % options.get< int >("quality-trim"));
        }
        if (options.find("quality-filter") != options.not_found()) {
            LOG4CXX_INFO(logger, boost::format("Quality Filter: %d") % options.get< int >("quality-filter"));
        }

        // input
        std::vector< std::string > filelist;
        std::copy(arguments.begin(), arguments.end(), std::back_inserter(filelist));
        LOG4CXX_INFO(logger, boost::format("input: %s") % boost::algorithm::join(filelist, ":"));

        // output
        std::ostream* out = &std::cout;
        if (options.find("out") != options.not_found()) {
            std::string file = options.get< std::string >("out");
            out = new std::ofstream(file.c_str());
            LOG4CXX_INFO(logger, boost::format("output: %s") % file);
        }

        // process
        if (*out) {
            Statistics stats;
            if ((r = processReads(options, filelist, *out, stats)) == 0) {
                // report statistics
                LOG4CXX_INFO(logger, "Preprocess stats:");
                LOG4CXX_INFO(logger, boost::format("Reads parsed:\t%d") % stats.numReadsRead);
                if (stats.numReadsRead > 0) {
                    LOG4CXX_INFO(logger, boost::format("Reads kept:\t%d(%f)") % stats.numReadsKept % ((double)stats.numReadsKept / stats.numReadsRead));
                    LOG4CXX_INFO(logger, boost::format("Reads failed primer screen:\t%d(%e)") % stats.numReadsPrimer % ((double)stats.numReadsPrimer / stats.numReadsRead));
                }
                LOG4CXX_INFO(logger, boost::format("Bases parsed:\t%d") % stats.numBasesRead);
                if (stats.numBasesRead) {
                    LOG4CXX_INFO(logger, boost::format("Bases kept:\t%d(%f)") % stats.numBasesKept % ((double)stats.numBasesKept / stats.numBasesRead));
                }
                LOG4CXX_INFO(logger, boost::format("Number of incorrectly paired reads that were discarded: %d") % stats.numInvalidPE);
            }
        } else {
            LOG4CXX_ERROR(logger, "Failed to open output stream");
        }

        if (out != &std::cout) {
            SAFE_DELETE(out);
        }

        return r;
    }