void CModuleIndexDialog::indexAllModules( const QList<CSwordModuleInfo*>& modules ) {
    static bool indexing = false;
    if (!indexing) {
        indexing = true;
        if (modules.count() < 1) return;

        m_currentModuleIndex = 0;
        m_progress = new QProgressDialog(QString(""), tr("Cancel"), 0, modules.count()*100);
        m_progress->setWindowModality(Qt::WindowModal); // not useful actually, should have parent for this
        m_progress->setWindowTitle(tr("Creating indices"));
        m_progress->show();
        m_progress->raise();

        foreach (CSwordModuleInfo* info, modules) {
            //TODO: how to cancel
            //QObject::connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged()), this, SLOT(swordSetupChanged()));
            connect(this, SIGNAL(sigCancel()), info, SLOT(cancelIndexing()) );
            connect(m_progress, SIGNAL(canceled()), info, SLOT(cancelIndexing()));
            connect(info, SIGNAL(indexingFinished()), this, SLOT(slotFinished()));
            connect(info, SIGNAL(indexingProgress(int)), this, SLOT(slotModuleProgress(int)) );
            QString modname(info->name());
            const QString labelText = tr("Creating index for work: %1").arg(modname);
            m_progress->setLabelText(labelText);
            //todo: if we want to cancel indexing from
            info->buildIndex(); //waits until this module is finished

            m_currentModuleIndex++;
            disconnect(m_progress, SIGNAL(canceled()), info, SLOT(cancelIndexing()));
            disconnect(info, SIGNAL(indexingFinished()), this, SLOT(slotFinished()));
            disconnect(info, SIGNAL(indexingProgress(int)), this, SLOT(slotModuleProgress(int)) );
            if (m_progress->wasCanceled()) break;
        }
Пример #2
0
void CapabilityWizard::slotCreateCapabilities()
{
	int start = m_startSpin->value();
	int gap = m_gapSpin->value();
	int amount = m_amountSpin->value();
	QString name = m_nameEdit->text();
	t_value min = start;
	t_value max = min + gap;
	QLCCapability* cap;

	/* Destroy existing capabilities */
	foreach (QLCCapability* cap, m_caps)
		delete cap;
	m_caps.clear();

	/* Create new capabilities */
	for (int i = 0; i < amount; i++)
	{
		/* Create a name with the optional hash mark */
		QString modname(name);
		modname.replace("#", QString("%1").arg(i + 1));

		/* Create a new capability and add it to our list */
		cap = new QLCCapability(min, max, modname);
		m_caps << cap;

		/* Bail out when the maximum DMX value has been reached */
		if (max == 255)
			break;

		/* Increment for the next round */
		min = max + 1;
		max = min + gap;

		/* Bail out if next round would overflow */
		if (max < min)
			break;
	}

	/* Replace capabilities in the list widget */
	m_list->clear();
	foreach (cap, m_caps)
	{
		QListWidgetItem* item;
		item = new QListWidgetItem(m_list);
		item->setText(QString("[%1 - %2] %3").arg(cap->min())
				.arg(cap->max()).arg(cap->name()));

		if (m_channel->searchCapability(cap->min()) != NULL ||
		    m_channel->searchCapability(cap->max()) != NULL)
		{
			/* Disable the item to indicate overlapping */
			item->setFlags(0);
		}
	}
bool ModuleManager::UserInput(wchar_t* module, wchar_t* msg, bool fromGame) {
	bool block = false;
	std::string name;
	std::wstring modname(module);
	name.assign(modname.begin(), modname.end());
	for (map<string, Module*>::iterator it = moduleList.begin(); it != moduleList.end(); ++it) {
		if(it->first == name)
			__raise it->second->UserInput(msg, fromGame, &block);
	}
	return block;
}
Пример #4
0
int main(int argc, char *argv[])
{
  bool success = true;

  if (argc < 3) {
    std::cerr << "Syntax error: use" << std::endl;
    std::cerr << argv[0] << " classname inputpath" << std::endl;
    return 1;
  }

  std::string modname(argv[1]);
  std::string inputpath(argv[2]);
  std::string ifname = inputpath + std::string("/") + modname + std::string("_tests.un");
  std::string impl_fname = modname + std::string("_test_impls-tmp.F90");
  std::string calls_fname = modname + std::string("_test_calls.F90");
  std::string list_fname = modname + std::string("_tests.tests");
  std::string mpilist_fname = modname + std::string("_tests.mpitests");

  std::vector<std::string> input, output;

  try {
    success = success && read_template(ifname, input);
    success = success && replace_modname(modname, input);

    success = success && parse_impl(ifname, input, output);
    success = success && write_output(impl_fname, output);
    output.clear();

    success = success && parse_calls(ifname, input, output);
    success = success && write_output(calls_fname, output);
    output.clear();

    success = success && parse_list(ifname, input, output);
    success = success && write_output(list_fname, output);
    output.clear();

    success = success && parse_mpilist(ifname, input, output);
    success = success && write_output(mpilist_fname, output);
    output.clear();
  } catch (ParserException &ex) {
    std::cerr << "Caught exception: " << ex.getMsg() << std::endl;
    success = false;
  } catch (std::string &ex) {
    std::cerr << "Caught exception: " << ex << std::endl;
    success = false;
  } catch (...) {
    std::cerr << "Caught unknown exception." << std::endl;
    success = false;
  }

  return (success ? 0 : 1);
}
bool Modules::loadWithDeps(QString name, QString args)
{
	QFile modules("/proc/modules");
	if(!modules.open(QFile::ReadOnly)) {
		perror("modules");
	} else {
		// Prevent dependency loops -- abort if we're already loaded.
		QString mn=modname(name) + " ";
		QString line;
		while(!modules.atEnd()) {
			line=modules.readLine();
			if(line.startsWith(mn)) // Already loaded
				return true;
		}
		modules.close();
	}

	QString const fn=filename(name);
	QFile modulesDep(_modDir + "modules.dep");
	if(!modulesDep.open(QFile::ReadOnly)) {
		perror("modules.dep");
	} else {
		QString line;
		while(!modulesDep.atEnd()) {
			line=modulesDep.readLine();
			if(!line.contains(':'))
				continue;
			QString module=line.section(':', 0, 0);
			if(!module.startsWith('/'))
				module = _modDir + module;
			if(module != fn)
				continue;
			QStringList deps=line.section(':', 1).simplified().split(' ', QString::SkipEmptyParts);
			foreach(QString dep, deps) {
				if(!dep.startsWith('/') && dep.contains('/'))
					dep = _modDir + dep;
				loadWithDeps(dep);
			}
		}
		modulesDep.close();
	}
	return load(fn, args);
}
Пример #6
0
static void
blog_plugin_init_dir (const gchar *realpath)
{
  GDir *dir;
  GModule *mod;
  const gchar *name;
  gchar *modpath;
  blog_plugin_t *plg;
  const gchar * (*modname) ();
  GList *cur;

  dir = g_dir_open (realpath, 0600, NULL);
  if (dir == NULL)
    {
      return;
    }

  while ((name = g_dir_read_name (dir)) != NULL)
    {
      if (*name == '.')
        {
          continue;
        }

#ifdef WIN32
      if (g_ascii_strcasecmp (name + strlen (name) - 4, ".dll") != 0)
#else
      if (g_ascii_strcasecmp (name + strlen (name) - 3, ".so") != 0)
#endif
        {
          continue;
        }

      modpath = g_build_filename (realpath, name, NULL);
      if (modpath == NULL)
        {
          continue;
        }

      mod = g_module_open (modpath, G_MODULE_BIND_MASK);
      g_free (modpath);
      if (mod == NULL)
        {
          g_error (g_module_error ());
          continue;
        }

      g_module_symbol (mod, "module_name", (gpointer) &modname);
      if (modname == NULL)
        {
          g_error (g_module_error ());
          continue;
        }

      for (cur = blog_plugin_list;
           cur != NULL;
           cur = g_list_next (cur)
      )
        {
          plg = cur->data;
          if (plg 
              && plg->name 
              && strcmp (plg->name (), modname ()) == 0)
            {
              break;
            }
        }

      if (cur)
        {
          g_module_close (mod);
          continue;
        }

      plg = g_malloc (sizeof (blog_plugin_t));
      if (plg == NULL)
        {
          g_error (_ ("Memory error.\n"));
          g_module_close (mod);
          continue;
        } 

      g_module_symbol (mod, "module_name", (gpointer) &plg->name);
      g_module_symbol (mod, "module_version", (gpointer) &plg->version);
      g_module_symbol (mod, "module_init", (gpointer) &plg->init);
      g_module_symbol (mod, "module_destroy", (gpointer) &plg->destroy);
      g_module_symbol (mod, "blog_add_widget", (gpointer) &plg->add_widget);
      g_module_symbol (mod, "blog_add", (gpointer) &plg->add);
      g_module_symbol (mod, "blog_pub", (gpointer) &plg->pub);

      if (plg->init () == FALSE)
        {
          g_error (_ ("Module '%s' init failed.\n"), name);
          g_module_close (mod);
          g_free (plg);
        }

      blog_plugin_list = g_list_append (blog_plugin_list, plg);
    }

  g_dir_close (dir);
}
Пример #7
0
CPathfinder::CPathfinder(AIClasses *ai): ARegistrar(600, std::string("pathfinder")) {
	this->ai   = ai;
	// NOTE: X and Z are in slope map resolution units
	this->X    = int(ai->cb->GetMapWidth()/HEIGHT2SLOPE);
	this->Z    = int(ai->cb->GetMapHeight()/HEIGHT2SLOPE);
	// NOTE: XX and ZZ are in pathgraph map resolution units
	this->XX   = this->X / I_MAP_RES;
	this->ZZ   = this->Z / I_MAP_RES;
	graphSize = XX * ZZ;
	update      = 0;
	repathGroup = -1;
	drawPaths   = false;

	hm = ai->cb->GetHeightMap();
	sm = ai->cb->GetSlopeMap();

	if (CPathfinder::graph.empty()) {
		const std::string cacheVersion(CACHE_VERSION);

		bool readOk = false;
		unsigned int N;
		std::string modname(ai->cb->GetModName());
		modname.resize(modname.size()-4);
		std::string filename = modname + "/" + std::string(ai->cb->GetMapName());
		std::string cacheMarker;

		cacheMarker.resize(cacheVersion.size());

		filename = std::string(CACHE_FOLDER) + filename.substr(0, filename.size()-4) + "-graph.bin";
		filename = util::GetAbsFileName(ai->cb, filename);

		/* See if we can read from binary */
		std::ifstream fin;
		fin.open(filename.c_str(), std::ios::binary | std::ios::in);
		if (fin.good() && fin.is_open()) {
			LOG_II("CPathfinder reading graph from " << filename)
			fin.read(&cacheMarker[0], cacheMarker.size());
			if (!fin.eof() && cacheMarker == cacheVersion) {
				fin.read((char*)&N, sizeof(N));
				if(N == graphSize) {
					for (unsigned int i = 0; i < N; i++) {
						Node *n = Node::unserialize(fin);
						CPathfinder::graph.push_back(n);
					}
					LOG_II("CPathfinder parsed " << CPathfinder::graph.size() << " nodes")
					readOk = true;
				}
			}
			fin.close();
			if(!readOk)
				// TODO: explain for user why?
				LOG_WW("CPathfinder detected invalid cache data")
		}

		if (!readOk)
		{
			std::ofstream fout;

			LOG_II("CPathfinder creating graph at " << filename)
			
			calcGraph();
			
			fout.open(filename.c_str(), std::ios::binary | std::ios::out);
			N = CPathfinder::graph.size();
			fout.write(&cacheVersion[0], cacheVersion.size());
			fout.write((char*)&N, sizeof(N));
			for (unsigned int i = 0; i < N; i++)
				CPathfinder::graph[i]->serialize(fout);
			fout.close();
		}
	}
Пример #8
0
CUnitTable::CUnitTable(AIClasses *ai): ARegistrar(100) {
	this->ai = ai;
	
	if (cat2str.empty()) {
		/* techlevels */
		cat2str[TECH1]       = "TECH1";
		cat2str[TECH2]       = "TECH2";
		cat2str[TECH3]       = "TECH3";

		/* main categories */
		cat2str[AIR]         = "AIR";
		cat2str[SEA]         = "SEA";
		cat2str[LAND]        = "LAND";
		cat2str[STATIC]      = "STATIC";
		cat2str[MOBILE]      = "MOBILE";

		/* builders */
		cat2str[FACTORY]     = "FACTORY";
		cat2str[BUILDER]     = "BUILDER";
		cat2str[ASSISTER]    = "ASSISTER";
		cat2str[RESURRECTOR] = "RESURRECTOR";

		/* offensives */
		cat2str[COMMANDER]   = "COMMANDER";
		cat2str[ATTACKER]    = "ATTACKER";
		cat2str[ANTIAIR]     = "ANTIAIR";
		cat2str[SCOUTER]     = "SCOUTER";
		cat2str[ARTILLERY]   = "ARTILLERY";  
		cat2str[SNIPER]      = "SNIPER";  
		cat2str[ASSAULT]     = "ASSAULT";  

		/* economic */
		cat2str[MEXTRACTOR]  = "MEXTRACTOR";
		cat2str[MMAKER]      = "MMAKER";
		cat2str[EMAKER]      = "EMAKER";
		cat2str[MSTORAGE]    = "MSTORAGE";
		cat2str[ESTORAGE]    = "ESTORAGE";
		cat2str[WIND]        = "WIND";
		cat2str[TIDAL]       = "TIDAL";

		/* ground types */
		cat2str[KBOT]        = "KBOT";
		cat2str[VEHICLE]     = "VEHICLE";
		cat2str[HOVER]       = "HOVER";

		cat2str[DEFENSE]     = "DEFENSE";
	}

	if (str2cat.empty()) {
		/* Create the str2cat table and cats vector */
		std::map<unitCategory,std::string>::iterator i;
		for (i = cat2str.begin(); i != cat2str.end(); i++) {
			cats.push_back(i->first);
			str2cat[i->second] = i->first;
		}
	}

	numUnits = ai->cb->GetNumUnitDefs();

 	/* Build the techtree, note that this is actually a graph in XTA */
	buildTechTree();

	/* Determine the modname */
	std::string modname(ai->cb->GetModName());
	modname = modname.substr(0, modname.size()-4) + "-categorization.cfg";

	/* Parse or generate categories */
	if (!ai->cfgparser->parseCategories(modname, units)) {
		modname = util::GetAbsFileName(ai->cb, std::string(CFG_FOLDER)+modname, false);
		generateCategorizationFile(modname.c_str());
	}

	/* Generate the buildBy and canBuild lists per UnitType */
	std::map<int, UnitType>::iterator j;
	UnitType *utParent;

	std::map<int, UnitType*>::iterator l;
	std::string buildBy, canBuild;

	for (j = units.begin(); j != units.end(); j++) {
		utParent = &(j->second);
		MoveData* movedata = utParent->def->movedata;

		if (movedata != NULL)
			moveTypes[movedata->pathType] = movedata;

		debugCategories(utParent);
		debugUnitDefs(utParent);
		debugWeapons(utParent);
		canBuild = buildBy = "";
		for (l = utParent->buildBy.begin(); l != utParent->buildBy.end(); l++) {
			std::stringstream out;
			out << l->first;
			buildBy += l->second->def->name + "(" + out.str() + "), ";
		}
		buildBy = buildBy.substr(0, buildBy.length()-2);
		for (l = utParent->canBuild.begin(); l != utParent->canBuild.end(); l++) {
			std::stringstream out;
			out << l->first;
			canBuild += l->second->def->name + "(" + out.str() + "), ";
		}
		canBuild = canBuild.substr(0, canBuild.length()-2);
	}
}