예제 #1
0
S32 PASCAL WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, S32)
{
#if 0
   // Run a unit test.
   StandardMainLoop::initCore();
   UnitTesting::TestRun tr;
   tr.test("Platform", true);
#else

   Vector<char *> argv( __FILE__, __LINE__ );

   char moduleName[256];
#ifdef TORQUE_UNICODE
   {
      TCHAR buf[ 256 ];
      GetModuleFileNameW( NULL, buf, sizeof( buf ) );
      convertUTF16toUTF8( buf, moduleName, sizeof( moduleName ) );
   }
#else
   GetModuleFileNameA(NULL, moduleName, sizeof(moduleName));
#endif
   argv.push_back(moduleName);

   for (const char* word,*ptr = lpszCmdLine; *ptr; )
   {
      // Eat white space
      for (; dIsspace(*ptr) && *ptr; ptr++)
         ;
      
      // Pick out the next word
      for (word = ptr; !dIsspace(*ptr) && *ptr; ptr++)
         ;
      
      // Add the word to the argument list.
      if (*word) 
      {
         int len = ptr - word;
         char *arg = (char *) dMalloc(len + 1);
         dStrncpy(arg, word, len);
         arg[len] = 0;
         argv.push_back(arg);
      }
   }

   winState.appInstance = hInstance;

   S32 retVal = run(argv.size(), (const char **) argv.address());

   for(U32 j = 1; j < argv.size(); j++)
      dFree(argv[j]);

   return retVal;
#endif
}
bool recommender_serv::clear() {
  check_set_config();

  clear_row_cnt_ = 0;
  update_row_cnt_ = 0;

  recommender_->clear();
  LOG(INFO) << "model cleared: " << argv().name;

  return true;
}
예제 #3
0
int TileWorldApp::RunTWorld()
{
	if (!setjmp(m_jmpBuf))	// try
	{
		return tworld(argc(), argv());
	}
	else	// catch (int)
	{
		return 0;
	}
}
예제 #4
0
bool recommender_serv::clear() {
  check_set_config();

  clear_row_cnt_ = 0;
  update_row_cnt_ = 0;
  build_cnt_ = 0;
  mix_cnt_ = 0;
  rcmdr_.get_model()->clear();
  wm_.clear();
  LOG(INFO) << "model cleared: " << argv().name;
  return true;
}
예제 #5
0
파일: parser.cpp 프로젝트: jmmv/kyua
/// Parses a command line.
///
/// \param args The command line to parse, broken down by words.
/// \param options The description of the supported options.
///
/// \return The parsed command line.
///
/// \pre args[0] must be the program or command name.
///
/// \throw cmdline::error See the description of parse(argc, argv, options) for
///     more details on the raised errors.
cmdline::parsed_cmdline
cmdline::parse(const cmdline::args_vector& args,
               const cmdline::options_vector& options)
{
    PRE_MSG(args.size() >= 1, "No progname or command name found");

    utils::auto_array< const char* > argv(new const char*[args.size() + 1]);
    for (args_vector::size_type i = 0; i < args.size(); i++)
        argv[i] = args[i].c_str();
    argv[args.size()] = NULL;
    return parse(static_cast< int >(args.size()), argv.get(), options);
}
예제 #6
0
void burst_serv::bind_watcher_() {
#ifdef HAVE_ZOOKEEPER_H
  const server_argv& a = argv();
  if (!a.is_standalone()) {
    std::string path;
    common::build_actor_path(path, a.type, a.name);
    path += "/nodes";
    zk_->bind_child_watcher(
        path, bind(&burst_serv::watcher_impl_, this, _1, _2, _3));
  }
#endif
}
예제 #7
0
bool burst_serv::will_process(const std::string& keyword) const {
#ifdef HAVE_ZOOKEEPER_H
  const server_argv& a = argv();
  if (a.is_standalone()) {
#endif
    return true;
#ifdef HAVE_ZOOKEEPER_H
  } else {
    common::cht cht(zk_, a.type, a.name);
    return is_assigned(cht, keyword, a.eth, a.port);
  }
#endif
}
예제 #8
0
파일: textslider.c 프로젝트: Bader14/Nexuiz
void NexuizTextSlider_loadCvars(entity me)
{
	if not(me.cvarName)
		return;

	var float n = tokenize_console(me.cvarName);
	var string s = cvar_string(argv(0));
	float i;
	for(i = 1; i < n; ++i)
		s = strcat(s, " ", cvar_string(argv(i)));
	me.setValueFromIdentifier(me, s);
	if(me.value < 0 && n > 1)
	{
		// if it failed: check if all cvars have the same value
		// if yes, try its value as 1-word identifier
		for(i = 1; i < n; ++i)
			if(cvar_string(argv(i)) != cvar_string(argv(i-1)))
				break;
		if(i >= n)
			me.setValueFromIdentifier(me, cvar_string(argv(0)));
	}
}
예제 #9
0
/*
 * Updates the model on the specified node and returns the score.
 * If the host/port of the current process is specified, update
 * is processed locally.
 * Caller is responsible for handling exceptions including RPC
 * errors.
 */
float anomaly_serv::selective_update(
    const string& host,
    int port,
    const string& id,
    const datum& d) {
  // nolock context
  if (host == argv().eth && port == argv().port) {
    jubatus::util::concurrent::scoped_wlock lk(rw_mutex());
    event_model_updated();
    if (anomaly_->is_updatable()) {
      return this->update(id, d);
    } else {
      return this->overwrite(id, d);
    }
  } else {  // needs no lock
    client::anomaly c(host, port, argv().name, argv().interconnect_timeout);
    if (anomaly_->is_updatable()) {
      return c.update(id, d);
    } else {
      return c.overwrite(id, d);
    }
  }
}
예제 #10
0
string toStringNexuizWeaponsList(entity me)
{
	float n, i;
	string s;
	entity e;
	n = tokenize_console(W_NumberWeaponOrder(cvar_string("cl_weaponpriority")));
	s = "";
	for(i = 0; i < n; ++i)
	{
		e = get_weaponinfo(stof(argv(i)));
		s = strcat(s, e.message, ", ");
	}
	return substring(s, 0, strlen(s) - 2);
}
예제 #11
0
파일: reduce.c 프로젝트: Aanettomyys/Moo
void * reduce_phase1(const void * _exp)
{
	if(isA(_exp, Integer()) || isA(_exp, Real()) || isA(_exp, Var()))
		return copy(_exp);
	else if(isA(_exp, Sum()) || isA(_exp, Product()))
	{
		void * s = copy(_exp);
		size_t i;
		for(i = 0; i < size(s); ++i)
		{
			delete(argv(s, i));
			setArgv(s, i, reduce_phase1(argv(_exp, i)));
		}
		return s;
	}
	else if(isA(_exp, Diff()))
	{
		return diffExec(_exp);
	}
	else if(isA(_exp, Pow()))
	{
		void * p = copy(_exp);
		delete(base(p));
		delete(power(p));
		setBase(p, reduce_phase1(base(_exp)));
		setPower(p, reduce_phase1(power(_exp)));
		return p;
	}
	else if(isOf(_exp, Apply_1()))
	{
		void * f = copy(_exp);
		delete(arg(f));
		setArg(f, reduce_phase1(arg(_exp)));
		return f;
	}
	assert(0);
}
void InstantAction_LoadMap(entity btn, entity dummy)
{
	float glob, i, n, fh;
	string s;
	glob = search_begin("maps/*.instantaction", TRUE, TRUE);
	if(glob < 0)
		return;
	i = ceil(random() * search_getsize(glob)) - 1;
	fh = fopen(search_getfilename(glob, i), FILE_READ);
	search_end(glob);
	if(fh < 0)
		return;
	while((s = fgets(fh)))
	{
		if(substring(s, 0, 4) == "set ")
			s = substring(s, 4, strlen(s) - 4);
		n = tokenize_console(s);
		if(argv(0) == "bot_number")
			cvar_set("bot_number", argv(1));
		else if(argv(0) == "skill")
			cvar_set("skill", argv(1));
		else if(argv(0) == "timelimit")
			cvar_set("timelimit_override", argv(1));
		else if(argv(0) == "fraglimit")
			cvar_set("fraglimit_override", argv(1));
		else if(argv(0) == "changelevel")
		{
			fclose(fh);
			localcmd("\nmenu_loadmap_prepare\n");
			MapInfo_SwitchGameType(MAPINFO_TYPE_DEATHMATCH);
			MapInfo_LoadMap(argv(1));
			cvar_set("lastlevel", "1");
			return;
		}
	}
	fclose(fh);
}
예제 #13
0
	void TestMain()
	{
		NetSSLApp app;
		std::string argv("TestSuite");
		const char* pArgv = argv.c_str();
		try
		{
			app.init(1, (char**)&pArgv);
			app.run();
		}
		catch (Poco::Exception& exc)
		{
			app.logger().log(exc);
		}
	}
예제 #14
0
tools::auto_array< const char* >
collection_to_argv(const C& c)
{
    tools::auto_array< const char* > argv(new const char*[c.size() + 1]);

    std::size_t pos = 0;
    for (typename C::const_iterator iter = c.begin(); iter != c.end();
         iter++) {
        argv[pos] = (*iter).c_str();
        pos++;
    }
    assert(pos == c.size());
    argv[pos] = NULL;

    return argv;
}
예제 #15
0
void burst_serv::watcher_impl_(int type, int state, const std::string& path) {
#ifdef HAVE_ZOOKEEPER_H
  JUBATUS_ASSERT(!argv().is_standalone());

  if (type == ZOO_CHILD_EVENT) {
    jubatus::util::concurrent::scoped_wlock lk(rw_mutex());
    rehash_keywords();
  } else {
    LOG(WARNING) << "burst_serv::watcher_impl_ got unexpected event ("
                 << type << "), something wrong: " << path;
  }

  // reregister
  bind_watcher_();
#endif
}
예제 #16
0
파일: qtmain_win.cpp 프로젝트: BGmot/Qt
int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR /*cmdParamarg*/, int cmdShow)
#endif
{
    QByteArray cmdParam = QString::fromWCharArray(GetCommandLine()).toLocal8Bit();

#if defined(Q_OS_WINCE)
    wchar_t appName[MAX_PATH];
    GetModuleFileName(0, appName, MAX_PATH);
    cmdParam.prepend(QString(QLatin1String("\"%1\" ")).arg(QString::fromWCharArray(appName)).toLocal8Bit());
#endif

    int argc = 0;
    QVector<char *> argv(8);
    qWinMain(instance, prevInstance, cmdParam.data(), cmdShow, argc, argv);

#if defined(Q_OS_WINCE)
    wchar_t uniqueAppID[MAX_PATH];
    GetModuleFileName(0, uniqueAppID, MAX_PATH);
    QString uid = QString::fromWCharArray(uniqueAppID).toLower().replace(QLatin1String("\\"), QLatin1String("_"));

    // If there exists an other instance of this application
    // it will be the owner of a mutex with the unique ID.
    HANDLE mutex = CreateMutex(NULL, TRUE, (LPCWSTR)uid.utf16());
    if (mutex && ERROR_ALREADY_EXISTS == GetLastError()) {
        CloseHandle(mutex);

        // The app is already running, so we use the unique
        // ID to create a unique messageNo, which is used
        // as the registered class name for the windows
        // created. Set the first instance's window to the
        // foreground, else just terminate.
        // Use bitwise 0x01 OR to reactivate window state if
        // it was hidden
        UINT msgNo = RegisterWindowMessage((LPCWSTR)uid.utf16());
        HWND aHwnd = FindWindow((LPCWSTR)QString::number(msgNo).utf16(), 0);
        if (aHwnd)
            SetForegroundWindow((HWND)(((ULONG)aHwnd) | 0x01));
        return 0;
    }
#endif // Q_OS_WINCE

    int result = main(argc, argv.data());
#if defined(Q_OS_WINCE)
    CloseHandle(mutex);
#endif
    return result;
}
예제 #17
0
파일: sync.cpp 프로젝트: Gudui/pyclustering
void sync_network::calculate_phases(const solve_type solver, const double t, const double step, const double int_step) {
	std::vector<double> next_phases(size(), 0);
	std::vector<void *> argv(2, NULL);

	argv[0] = (void *) this;

	unsigned int number_int_steps = (unsigned int) (step / int_step);

	for (unsigned int index = 0; index < size(); index++) {
		argv[1] = (void *) &index;

		switch(solver) {
			case solve_type::FAST: {
				double result = m_oscillators[index].phase + phase_kuramoto(t, m_oscillators[index].phase, argv);
				next_phases[index] = phase_normalization(result);
				break;
			}
			case solve_type::RK4: {
				differ_state<double> inputs(1, m_oscillators[index].phase);
				differ_result<double> outputs;

				runge_kutta_4(m_callback_solver, inputs, t, t + step, number_int_steps, false, argv, outputs);
				next_phases[index] = phase_normalization( outputs[0].state[0] );

				break;
			}
			case solve_type::RKF45: {
				differ_state<double> inputs(1, m_oscillators[index].phase);
				differ_result<double> outputs;

				runge_kutta_fehlberg_45(m_callback_solver, inputs, t, t + step, 0.00001, false, argv, outputs);
				next_phases[index] = phase_normalization( outputs[0].state[0] );

				break;
			}
			default: {
				throw std::runtime_error("Unknown type of solver");
			}
		}
	}

	/* store result */
	for (unsigned int index = 0; index < size(); index++) {
		m_oscillators[index].phase = next_phases[index];
	}
}
예제 #18
0
파일: sys.c 프로젝트: Nurb432/plan9front
static void
sysseek(void)
{
	u32int fd, type;
	vlong n, *ret;
	Segment *seg;
	
	ret = vaddr(arg(0), 8, &seg);
	fd = arg(1);
	n = argv(2);
	type = arg(4);
	if(systrace)
		fprint(2, "seek(%d, %lld, %d)\n", fd, n, type);
	*ret = seek(fd, n, type);
	if(*ret < 0) noteerr(0, 1);
	segunlock(seg);
}
예제 #19
0
  void Callback::eval(const double** arg, double** res, int* iw, double* w, int mem) {
    // Allocate input matrices
    int n_in = this->n_in();
    std::vector<DM> argv(n_in);
    for (int i=0; i<n_in; ++i) {
      argv[i] = DM(sparsity_in(i));
      casadi_copy(arg[i], argv[i].nnz(), argv[i].ptr());
    }

    // Evaluate
    std::vector<DM> resv = eval(argv);

    // Get the outputs
    int n_out = this->n_out();
    for (int i=0; i<n_out; ++i) {
      casadi_copy(resv[i].ptr(), resv[i].nnz(), res[i]);
    }
  }
예제 #20
0
파일: sys.c 프로젝트: Nurb432/plan9front
static void
syspread(void)
{
	int buffered;
	u32int fd, size, buf;
	u64int off;
	void *targ;
	
	fd = arg(0);
	buf = arg(1);
	size = arg(2);
	off = argv(3);
	if(systrace)
		fprint(2, "pread(%d, %#ux, %ud, %#ullx)\n", fd, buf, size, off);
	targ = bufifnec(buf, size, &buffered);
	P->R[0] = noteerr(pread(fd, targ, size, off), size);
	if(buffered)
		copyback(buf, P->R[0], targ);
}
예제 #21
0
void burst_serv::rehash_keywords() {
#ifdef HAVE_ZOOKEEPER_H
  if (argv().is_standalone()) {
    return;
  }

  core::driver::burst::keyword_list keywords = burst_->get_all_keywords();
  std::vector<std::string> processed_keywords;

  for (core::driver::burst::keyword_list::iterator iter = keywords.begin();
       iter != keywords.end(); ++iter) {
    if (will_process(iter->keyword)) {
      processed_keywords.push_back(iter->keyword);
    }
  }

  burst_->set_processed_keywords(processed_keywords);
#endif
}
예제 #22
0
bool s_abicollab_command_invoke(AV_View* /*v*/, EV_EditMethodCallData *d)
{
	UT_DEBUGMSG(("s_abicollab_command_invoke()\n"));

	UT_UTF8String argv(d->m_pData, d->m_dataLength);
	UT_DEBUGMSG(("command line arguments: %s\n", argv.utf8_str()));
	
	AbiCollab_Command command(argv);
	if (command.execute())
	{
		UT_DEBUGMSG(("AbiCollab command executed successful\n"));
	}
	else
	{
		UT_DEBUGMSG(("AbiCollab command failed to execute successfully\n"));
	}

	return true;
}
예제 #23
0
파일: sys.c 프로젝트: Nurb432/plan9front
static void
syspwrite(void)
{
	u32int fd, size, buf;
	u64int off;
	int copied;
	void *buft;
	
	fd = arg(0);
	buf = arg(1);
	size = arg(2);
	off = argv(3);
	buft = copyifnec(buf, size, &copied);
	if(systrace)
		fprint(2, "pwrite(%d, %#ux, %ud, %#ullx)\n", fd, buf, size, off);
	P->R[0] = noteerr(pwrite(fd, buft, size, off), size);
	if(copied)
		free(buft);
}
예제 #24
0
  /* @todo Improve error messages */
  Object* System::vm_exec(VM* state, String* path, Array* args)
  {
    std::size_t argc = args->size();

    /* execvp() requires a NULL as last element */
    std::vector<char*> argv((argc + 1), NULL);

    for (std::size_t i = 0; i < argc; ++i) {
      /* strdup should be OK. Trying to exec with strings containing NUL == bad. --rue */
      argv[i] = ::strdup(as<String>(args->get(state, i))->c_str());
    }

    (void) ::execvp(path->c_str(), &argv[0]); /* std::vector is contiguous. --rue */

    /* execvp() returning means it failed. */
    Exception::errno_error(state, "execvp() failed!");

    return Qnil;
  }
예제 #25
0
// nolock, random
id_with_score anomaly_serv::add(const datum& data) {
  check_set_config();

  uint64_t id = idgen_->generate();
  string id_str = jubatus::util::lang::lexical_cast<string>(id);

#ifdef HAVE_ZOOKEEPER_H
  if (argv().is_standalone()) {
#endif
    jubatus::util::concurrent::scoped_wlock lk(rw_mutex());
    event_model_updated();
    // TODO(unno): remove conversion code
    pair<string, float> res = anomaly_->add(id_str, data);
    return id_with_score(res.first, res.second);
#ifdef HAVE_ZOOKEEPER_H
  } else {
    return add_zk(id_str, data);
  }
#endif
}
예제 #26
0
파일: shexec.cpp 프로젝트: tiehuis/shell
int Shell::executecommand(std::vector<std::string> &commands)
{
    if (commands.size() == 0) {
        return 0;
    }
    else if (Shell::isbuiltin(commands[0])) {
        Shell::execbuiltin(commands);
    }
    else {
        pid_t pid = fork();

        /* Convert to c-style strings for exevp */
        std::vector<char*> argv(commands.size() + 1);
        for (std::size_t i = 0; i != commands.size(); ++i)
            argv[i] = &commands[i][0];

        if (pid == 0) {
            if (execvp(argv[0], argv.data()) == -1) {
                std::cerr << "\033[31m";
                std::cerr << "Could not execute command: " << commands[0] << std::endl;
                std::cerr << "\033[0m";
                _exit(1);
            }
        }
        else if (pid > 0) {
            int exitstat;
            waitpid(pid, &exitstat, 0);

            /* Don't deal with specific errors for now */
            if (WIFEXITED(exitstat))
                return 0;
            else
                return 1;
        }
        else {
            std::cerr << "Failed to fork: " << commands[0];
        }
    }

    return 0;
}
예제 #27
0
Subprocess::Subprocess(
    const std::string& cmd,
    const Options& options,
    const std::vector<std::string>* env)
  : pid_(-1),
    returnCode_(RV_NOT_STARTED) {
  if (options.usePath_) {
    throw std::invalid_argument("usePath() not allowed when running in shell");
  }
  const char* shell = getenv("SHELL");
  if (!shell) {
    shell = "/bin/sh";
  }

  std::unique_ptr<const char*[]> argv(new const char*[4]);
  argv[0] = shell;
  argv[1] = "-c";
  argv[2] = cmd.c_str();
  argv[3] = nullptr;
  spawn(std::move(argv), shell, options, env);
}
예제 #28
0
void EvaluationMX::evaluateSX(const SXMatrixPtrV& arg, SXMatrixPtrV& res,
    const SXMatrixPtrVV& fseed, SXMatrixPtrVV& fsens,
    const SXMatrixPtrVV& aseed, SXMatrixPtrVV& asens) {
  
  // Create input arguments
  vector<SXMatrix> argv(arg.size());
  for(int i=0; i<arg.size(); ++i){
    argv[i] = SXMatrix(fcn_.input(i).sparsity(),0.);
    if(arg[i] != 0)
      argv[i].set(*arg[i]);
  }

  // Evaluate symbolically
  vector<SXMatrix> resv = fcn_.eval(argv);

  // Collect the result
  for (int i = 0; i < res.size(); ++i) {
    if (res[i] != 0)
      *res[i] = resv[i];
  }
}
예제 #29
0
void Command::forkProcess()
{
	std::vector<char *> argv(this->argVector.size()+2);//exec argument vector
	for(int i=0; i<this->argVector.size(); ++i)
		argv[i+1] = &this->argVector[i][0];
	argv[0] = &this->command[0];
	argv[this->argVector.size()+1] = NULL;

	if(this->command.compare(0,2,"./")!=0 || this->command.compare(0,3,"../")!=0 || this->command.compare(0,1,"/")!=0)
		setenv("PATH", "/bin:/usr/bin:.", 1);//set to relative path
	signal(SIGINT,  SIG_DFL);
	signal(SIGTERM, SIG_DFL);
	signal(SIGQUIT, SIG_DFL);
	signal(SIGTSTP, SIG_DFL);

	if(execvp(this->command.c_str(), argv.data()) == -1)
		std::cout << "["<<this->command<<"]: command not found"<<std::endl;
	else
		std::cout << "["<<this->command<<"]: unknown error"	<<std::endl;
	//safety measure exit, prevent zombie
	exit(0);
}
예제 #30
0
  boost::any JSFunctionInvokable::invoke(std::vector<boost::any>& params)
  {
    /* Invoke the function handle */

    int argc = params.size();

    v8::HandleScope handle_scope;
    v8::Context::Scope  context_scope(script_->context());

   std::vector<v8::Handle<v8::Value> >argv(argc);

   for(uint32 i = 0; i < params.size(); i++)
       argv[i] = InvokableUtil::AnyToV8(script_, params[i]);


  //TryCatch try_catch;

   // We are currently executing in the global context of the entity
   // FIXME: need to take care fo the "this" pointer
   v8::Handle<v8::Value> result;
   if (argc > 0)
       result = script_->invokeCallback(script_->rootContext(), function_, argc, &argv[0]);
   else
       result = script_->invokeCallback(script_->rootContext(), function_);

   if(result.IsEmpty())
   {
     /*
     v8::String::Utf8Value error(try_catch.Exception());
     const char* cMsg = ToCString(error);
     std::cerr << cMsg << "\n";
     */
   }


   return boost::any(result) ;


  }