bool muhkuh_split_testdescription::write_textfile(MUHKUH_TESTDESCRIPTION_TYP_T tTyp, size_t sizSubTextIndex, wxString strContents)
{
	bool fResult;
	wxString strFileName;
	wxFFileOutputStream *ptOutputStream;
	wxTextOutputStream *ptTextOutputStream;


	/* Create a new file. */
	strFileName = get_lua_filename(tTyp, sizSubTextIndex);
	ptOutputStream = new wxFFileOutputStream(strFileName, "w");
	if( ptOutputStream->IsOk()!=true )
	{
		wxLogError("Failed to create new file %s!", strFileName);
		fResult = false;
	}
	else
	{
		/* Create the text output stream. */
		ptTextOutputStream = new wxTextOutputStream(*ptOutputStream);

		/* Write the complete data to the file. */
		ptTextOutputStream->WriteString(strContents);

		delete ptTextOutputStream;

		ptOutputStream->Close();

		fResult = true;
	}
	delete ptOutputStream;

	return fResult;
}
Esempio n. 2
0
void
wait_filter::wait() {
    if (this->lua_file.empty()) {
    if (get_lua_filename() != NULL) {
      const char *luaf_tmp = get_lua_filename();
      this->lua_file = luaf_tmp;
    }
    else {
      luaL_error(this->L, "ERROR: Lua file not defined");
      return;
    }
  }

  if (this->func_filter.empty()) {
    std::cerr << "WARNING: Filter function is not defined" << std::endl;
    return;
  }

  lua_openlibs();

  if (luaL_loadfile(this->L, this->lua_file.c_str()) != 0) {
    luaL_error(this->L, "ERROR: Could not load: %s", this->lua_file.c_str());
    return;
  }

  if (lua_pcall(this->L, 0, 0, 0) != 0)   {
    std::cerr << "ERROR: " << lua_tostring(this->L, -1) << std::endl;
    lua_pop(this->L, 1);
    return;
  }

  char err[PCAP_ERRBUF_SIZE];
  if (this->dev->open(err)) {
    this->started = true;
    wait_filter::exec();
  }
  else {
    std::cerr << "WARNING: Fail open device: " << err << std::endl;
    return;
  }
}