Esempio n. 1
0
const QList< QDir >
PluginLoader::pluginDirs()
{
    QList< QDir > pluginDirs;

    QDir appDir( QCoreApplication::instance()->applicationDirPath() );
#ifdef Q_WS_MAC
    if ( appDir.dirName() == "MacOS" )
    {
        // Development convenience-hack
        appDir.cdUp();
        appDir.cdUp();
        appDir.cdUp();
    }
#endif

    QDir installLibDir( CMAKE_INSTALL_PREFIX "/lib" );

    QDir libDir( appDir );
    libDir.cdUp();
    libDir.cd( "lib" );

    QDir lib64Dir( appDir );
    lib64Dir.cdUp();
    lib64Dir.cd( "lib64" );

    pluginDirs << appDir << installLibDir << libDir << lib64Dir;
    return pluginDirs;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
    GlobalStartup();
    DoApplicationSettings ();

    char    curWd[4096],
            dirSlash = GetPlatformDirectoryChar ();
    getcwd (curWd,4096);

    _String baseDir (curWd);

    if (baseDir.getChar (baseDir.sLength-1) != dirSlash) {
        baseDir=baseDir & dirSlash;
    }

    _String libDir (_HYPHY_LIBDIRECTORY_);

    if (libDir.getChar (libDir.sLength-1) != dirSlash) {
        libDir=libDir & dirSlash;
    }

    pathNames&& &libDir;

    libDirectory  = libDir;
    libArgDir     = libDirectory;
    baseDirectory = baseDir;
    baseArgDir    = baseDirectory;


    QApplication app(argc, argv);
    HyphyMain mainWindow;
    ReadInTemplateFiles     ();

    _hyPrimaryConsoleWindow = & mainWindow;

    /*mainWindow.setGeometry(
    QStyle::alignedRect(
        Qt::LeftToRight,
        Qt::AlignCenter,
        mainWindow.size(),
        qApp->desktop()->availableGeometry()
    ));*/

    mainWindow.show();
    mainWindow.raise();
    return app.exec();
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
 char opt;
 static struct option long_options[] =
 {
  {"item", 0, 0, 'i'},
  {"monster", 0, 0, 'm'},
  {"spell", 0, 0, 's'},
  {"map", 1, 0, 'p'},
  {"editmap", 1, 0, 'e'},
  {"ascii", 0, 0, 'a'},
  {"xml", 1, 0, 'x'},
  {"multiplier", 1, 0, 'u'},
  {0, 0, 0, 0}
 };

 bool utf8 = true;
 int mode = MODE_STANDARD;
 char *mapFile = NULL;
 char *xmlFile = NULL;
 int multiplier = 0;
 std::string libDir(TOSTRING(BTBUILDERDIR));
 while ((opt = getopt_long(argc,argv,"imsap:x:e:l:u:", long_options, NULL)) != EOF)
 {
  switch (opt)
  {
   case 'i':
    mode = MODE_ITEM;
    break;
   case 'm':
    mode = MODE_MONSTER;
    break;
   case 's':
    mode = MODE_SPELL;
    break;
   case 'p':
    mode = MODE_MAP;
    if (optarg)
    {
     mapFile = strdup(optarg);
    }
    break;
   case 'e':
    mode = MODE_EDITMAP;
    if (optarg)
    {
     mapFile = strdup(optarg);
    }
    break;
   case 'l':
    if (optarg)
    {
     libDir = optarg;
    }
    break;
   case 'a':
    utf8 = false;
    break;
   case 'x':
    if (optarg)
    {
     xmlFile = strdup(optarg);
    }
    break;
   case 'u':
    if (optarg)
    {
     multiplier = atol(optarg);
    }
    break;
   default:
    break;
  }
 }

 BTMainScreen mainScreen(argv[0], libDir, multiplier);
 if (optind >= argc)
 {
  if (mode != MODE_STANDARD)
   return 0;
  mainScreen.run();
  return 0;
 }
 else if (mode == MODE_STANDARD)
 {
  std::string moduleFile("module/");
  moduleFile += argv[optind];
  moduleFile += ".xml";
  mainScreen.runModule(moduleFile);
  return 0;
 }
 else if (mode == MODE_EDITMAP)
 {
  std::string moduleFile("module/");
  moduleFile += argv[optind];
  moduleFile += ".xml";
  mainScreen.editModule(moduleFile, mapFile);
  return 0;
 }
 std::string moduleFile("module/");
 moduleFile += argv[optind];
 moduleFile += ".xml";
 BTModule module;
 mainScreen.loadModule(moduleFile, module);
 BTGame game(&module);
 BTFactory<BTMonster> &monList(game.getMonsterList());
 BTFactory<BTItem> &itmList(game.getItemList());
 BTFactory<BTSpell, BTSpell1> &splList(game.getSpellList());
 int i;
 if (mode == MODE_MONSTER)
 {
  if (xmlFile)
  {
   monList.save(xmlFile);
  }
  else
  {
   for (i = 0; i < monList.size(); i++)
   {
    BTMonster &mon(monList[i]);
    printf("Name: %s\n", mon.getName().c_str());
    printf("Illusion: %s   Base armor class: %d\n",
      (mon.isIllusion() ? "Yes" : "No"), (mon.getAc() - 10) * -1);
    printf("Level: %d   Thaumaturgical resistance: %d\n", mon.getLevel(),
      mon.getMagicResistance());
    printf("Starting distance (*10'): %d   Moves per round: %d\n",
      mon.getStartDistance(), mon.getMove());
    printf("Hit points: %dd%d   Combat options: ", mon.getHp().getNumber(),
      mon.getHp().getType());
    IShort combatAction = mon.getCombatAction(0);
    for (int a = 1; a < 4; ++a)
     if (combatAction != mon.getCombatAction(a))
      combatAction = -1;
    if (-1 == combatAction)
     printf("Multiple\n");
    else
     printf("%s\n", combatActions[combatAction]);
    printf("Rate of attacks: %d   Damage dice: %dd%d\n",
      mon.getRateAttacks(), mon.getMeleeDamage().getNumber(),
      mon.getMeleeDamage().getType());
    printf("Extra damage: %s\n", extraDamage[mon.getMeleeExtra()]);
    printf("Attack message: <monster> %s <opponent>\n", mon.getMeleeMessage());
    printf("Extra ranged attack information -\n");
    printf("   Type: %s", rangedTypes[mon.getRangedType()]);
    switch (mon.getRangedType())
    {
     case BTRANGEDTYPE_MAGIC:
      printf(": %s", splList[mon.getRangedSpell()].getCode());
     case BTRANGEDTYPE_FOE:
     case BTRANGEDTYPE_GROUP:
      printf("   Message: <monster> %s <opponent>\n", mon.getRangedMessage());
      printf("   Damage: %dd%d   Extra damage: %s   Range: %d",
        mon.getRangedDamage().getNumber(),  mon.getRangedDamage().getType(),
        extraDamage[mon.getRangedExtra()], mon.getRange());
      break;
     default:
      break;
    }
    printf("\n");
    printf("Upper limit appearing: %d  Gold: %dd%d   Picture number: %d\n",
      mon.getMaxAppearing(), mon.getGold().getNumber(),
      mon.getGold().getType(), mon.getPicture());
    printf("\n");
   }
  }
 }
 else if (mode == MODE_SPELL)
 {
  if (xmlFile)
  {
   splList.save(xmlFile);
  }
  else
  {
   BTSpellListCompare compare;
   BTSortedFactory<BTSpell, BTSpell1> sortedSplList(&splList, &compare);
   IShort caster = -1;
   IShort level = -1;
   for (i = 0; i < sortedSplList.size(); i++)
   {
    BTSpell &mon(sortedSplList[i]);
    if ((caster != mon.getCaster()) || (level != mon.getLevel()))
    {
     if (caster != mon.getCaster())
     {
      caster = mon.getCaster();
      BTJobList& jobList = BTGame::getGame()->getJobList();
      int j;
      for (j = 0; j < jobList.size(); ++j)
      {
       if (jobList[j]->getSkill(caster) != NULL)
        break;
      }
      printf("Class:  %s\n", ((j < jobList.size()) ? BTGame::getGame()->getJobList()[j]->name : "Unknown"));
     }
     level = mon.getLevel();
     printf("Level: %d\n\n", level);
    }
    printf("Name: %s\n", mon.getName().c_str());
    printf("Code: %s\n", mon.getCode());
    printf("Points: %d   Range: %d   Extra range: %s\n", mon.getSp(),
      mon.getRange() * 10, effectiveRanges[mon.getEffectiveRange()]);
    printf("Target: %s\n", areaEffect[mon.getArea()]);
    printf("Effect: %s <target>\n", mon.getEffect());
    printf("Duration: %s\n", durations[mon.getDuration()]);
    printf("%s", mon.describeManifest().data());
/*    printf("Type: %s", spellTypes[mon.getType()]);
    switch (mon.getType())
    {
     case BTSPELLTYPE_SUMMONILLUSION:
     case BTSPELLTYPE_SUMMONMONSTER:
      printf("   Name: %s", monList[mon.getExtra()].getName().c_str());
      break;
     case BTSPELLTYPE_ARMORBONUS:
     case BTSPELLTYPE_HITBONUS:
      printf("   Bonus: %d", mon.getExtra());
      break;
     case BTSPELLTYPE_PUSH:
      printf("   Distance: %d", mon.getExtra());
      break;
     case BTSPELLTYPE_REGENBARD:
      printf("   Amount: %d", mon.getExtra());
      break;
     default:
      break;
    }
    printf("\nDice: %dd%d   Duration: %s\n", mon.getDice().getNumber(),
      mon.getDice().getType(), durations[mon.getDuration()]);
*/    printf("\n");
   }
  }
 }
 else if (mode == MODE_ITEM)
 {
  if (xmlFile)
  {
   itmList.save(xmlFile);
  }
  else
  {
   for (i = 0; i < itmList.size(); i++)
   {
    BTItem &mon(itmList[i]);
    printf("Name: %s\n", mon.getName().c_str());
    printf("Type: %s\n", itemTypes[mon.getType()]);
    printf("Price: %d   User class: Multiple\n", mon.getPrice());
    printf("Armor bonus: %d   Hit bonus: %d\n", mon.getArmorPlus(),
      mon.getHitPlus());
    printf("Damage dice: %dd%d\n", mon.getDamage().getNumber(),
      mon.getDamage().getType());
    printf("Extra special damage: %s   Special damage likelihood: %d%%\n",
      extraDamage[mon.getXSpecial()], mon.getChanceXSpecial());
    if (BTTIMESUSABLE_UNLIMITED == mon.getTimesUsable())
     printf("Times useable: (unlimited)");
    else
     printf("Times useable: %d", mon.getTimesUsable());
    printf("   Spell cast: %s\n",
      ((mon.getSpellCast() == BTITEMCAST_NONE) ? "(none)" :
      splList[mon.getSpellCast()].getName().c_str()));
    printf("Cause: <member> %s <opponent>\n", mon.getCause());
    printf("Effect: %s <damage>\n", mon.getEffect());
    printf("\n");
   }
  }
 }
 else if (mode == MODE_MAP)
 {
  int x, y;
  IShort index;
  if (mapFile)
   game.loadMap(mapFile);
  BTMap &gameMap = *game.getMap();
  if (xmlFile)
  {
   XMLSerializer parser;
   parser.add("map", &gameMap);
   parser.write(xmlFile, true);
  }
  else
  {
   printf("Name: %s\n", gameMap.getName());
   printf("Type: %s   Level: %d\n", game.getPsuedo3DConfigList().getName(gameMap.getType()).c_str(), gameMap.getLevel());
   printf("Monster difficulty: %d   Chance of encounter: %d%%\n", gameMap.getMonsterLevel(), gameMap.getMonsterChance());
   printf("File: %s\n\n", gameMap.getFilename());
   for (y = 0; y < gameMap.getYSize(); y++)
   {
    printf(" ");
    for (x = 0; x < gameMap.getXSize(); x++)
    {
     index = 0;
     if ((y > 0) && (gameMap.getSquare(y - 1, x).getWall(BTDIRECTION_WEST) > 0))
     {
      index += 1 << BTDIRECTION_NORTH;
     }
     if ((x > 0) && (gameMap.getSquare(y, x - 1).getWall(BTDIRECTION_NORTH) > 0))
     {
      index += 1 << BTDIRECTION_WEST;
     }
     if (gameMap.getSquare(y, x).getWall(BTDIRECTION_NORTH) > 0)
     {
      index += 1 << BTDIRECTION_EAST;
     }
     if (gameMap.getSquare(y, x).getWall(BTDIRECTION_WEST) > 0)
     {
      index += 1 << BTDIRECTION_SOUTH;
     }
     if (utf8)
      printf("%s%s", cornerWallsUTF8[index], upperWallsUTF8[gameMap.getSquare(y, x).getWall(BTDIRECTION_NORTH)]);
     else
      printf("%c%c", cornerWalls[index], upperWalls[gameMap.getSquare(y, x).getWall(BTDIRECTION_NORTH)]);
    }
    index = 0;
    if ((y > 0) && (gameMap.getSquare(y - 1, gameMap.getXSize() - 1).getWall(BTDIRECTION_EAST) > 0))
    {
     index += 1 << BTDIRECTION_NORTH;
    }
    if (gameMap.getSquare(y, gameMap.getXSize() - 1).getWall(BTDIRECTION_NORTH) > 0)
    {
     index += 1 << BTDIRECTION_WEST;
    }
    if (gameMap.getSquare(y, gameMap.getXSize() - 1).getWall(BTDIRECTION_EAST) > 0)
    {
     index += 1 << BTDIRECTION_SOUTH;
    }
    if (utf8)
     printf("%s \n", cornerWallsUTF8[index]);
    else
     printf("%c \n", cornerWalls[index]);
    printf(" ");
    for (x = 0; x < gameMap.getXSize(); x++)
    {
     index = gameMap.getSquare(y, x).getSpecial();
     if (utf8)
      printf("%s%c", sideWallsUTF8[gameMap.getSquare(y, x).getWall(BTDIRECTION_WEST)],
        (index < 0 ) ? ' ' : ((index < 26) ? 'A' + index : 'a' - 26 + index));
     else
      printf("%c%c", sideWalls[gameMap.getSquare(y, x).getWall(BTDIRECTION_WEST)],
        (index < 0 ) ? ' ' : ((index < 26) ? 'A' + index : 'a' - 26 + index));
    }
    if (utf8)
     printf("%s \n", sideWallsUTF8[gameMap.getSquare(y, gameMap.getXSize() - 1).getWall(BTDIRECTION_EAST)]);
    else
     printf("%c \n", sideWalls[gameMap.getSquare(y, gameMap.getXSize() - 1).getWall(BTDIRECTION_EAST)]);
   }
   printf(" ");
   for (x = 0; x < gameMap.getXSize(); x++)
   {
    index = 0;
    if (gameMap.getSquare(gameMap.getYSize() - 1, x).getWall(BTDIRECTION_WEST) > 0)
    {
     index += 1 << BTDIRECTION_NORTH;
    }
    if ((x > 0) && (gameMap.getSquare(gameMap.getYSize() - 1, x - 1).getWall(BTDIRECTION_SOUTH) > 0))
    {
     index += 1 << BTDIRECTION_WEST;
    }
    if (gameMap.getSquare(gameMap.getYSize() - 1, x).getWall(BTDIRECTION_SOUTH) > 0)
    {
     index += 1 << BTDIRECTION_EAST;
    }
    if (utf8)
     printf("%s%s", cornerWallsUTF8[index], upperWallsUTF8[gameMap.getSquare(gameMap.getYSize() - 1, x).getWall(BTDIRECTION_SOUTH)]);
    else
     printf("%c%c", cornerWalls[index], upperWalls[gameMap.getSquare(gameMap.getYSize() - 1, x).getWall(BTDIRECTION_SOUTH)]);
   }
   index = 0;
   if (gameMap.getSquare(gameMap.getYSize() - 1, gameMap.getXSize() - 1).getWall(BTDIRECTION_EAST) > 0)
   {
    index += 1 << BTDIRECTION_NORTH;
   }
   if (gameMap.getSquare(gameMap.getYSize() - 1, gameMap.getXSize() - 1).getWall(BTDIRECTION_SOUTH) > 0)
   {
    index += 1 << BTDIRECTION_WEST;
   }
   if (utf8)
    printf("%s \n", cornerWallsUTF8[index]);
   else
    printf("%c \n", cornerWalls[index]);
   printf("\nDefined special squares:\n\n\n");
   for (int i = 0; i < 30; i++)
   {
    const BTSpecial *sp = gameMap.getSpecial(i);
    if (NULL != sp)
    {
     printf("%c. ", (i < 26) ? 'A' + i : 'a' - 26 + i);
     sp->print(stdout);
     printf("\n");
    }
   }
  }
 }
 PHYSFS_deinit();
 return 0;
}
Esempio n. 4
0
Ogre::Root* OgreSetup::createOgreSystem()
{
	ConfigService& configSrv(EmberServices::getSingleton().getConfigService());

	if (configSrv.getPrefix() != "") {
		//We need to set the current directory to the prefix before trying to load Ogre.
		//The reason for this is that Ogre loads a lot of dynamic modules, and in some build configuration
		//(like AppImage) the lookup path for some of these are based on the installation directory of Ember.
		if (chdir(configSrv.getPrefix().c_str())) {
			S_LOG_WARNING("Failed to change to the prefix directory '" << configSrv.getPrefix() << "'. Ogre loading might fail.");
		}
	}

	std::string pluginExtension = ".so";
	mRoot = new Ogre::Root("", "ogre.cfg", "");

	//we will try to load the plugins from series of different location, with the hope of getting at least one right
	std::vector<std::string> pluginLocations;

	if (configSrv.itemExists("ogre", "plugins")) {
		std::string plugins(configSrv.getValue("ogre", "plugins"));
		//if it's defined in the config, use that location first
		if (configSrv.itemExists("ogre", "plugindir")) {
			std::string pluginDir(configSrv.getValue("ogre", "plugindir"));
			pluginLocations.push_back(pluginDir);
		}
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
		pluginExtension = ".dll";
		pluginLocations.push_back("."); //on windows we'll bundle the dll files in the same directory as the executable
#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
		pluginExtension = ".so";
		std::string pluginDir = configSrv.getPrefix();
		pluginDir += "/lib/OGRE";
		pluginLocations.push_back(pluginDir);

#ifdef ENABLE_BINRELOC
		//binreloc might be used
		char* br_libdir = br_find_lib_dir(br_strcat(PREFIX, "/lib"));
		std::string libDir(br_libdir);
		free(br_libdir);
		pluginLocations.push_back(libDir + "/OGRE");
#endif
#ifdef OGRE_PLUGINDIR
		//also try with the plugindir defined for Ogre
		pluginLocations.push_back(OGRE_PLUGINDIR);
#endif
		//enter the usual locations if Ogre is installed system wide, with local installations taking precedence
		pluginLocations.push_back("/usr/local/lib/OGRE");
		pluginLocations.push_back("/usr/lib/OGRE");
#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
		// On Mac, plugins are found in Resources in the Main (Application) bundle, then in the Ogre framework bundle
		pluginExtension = "";
		std::string pluginDir = configSrv.getSharedDataDirectory();
		pluginLocations.push_back(pluginDir);
		pluginDir += "/../Plugins";
		pluginLocations.push_back(pluginDir);
		pluginLocations.push_back("");
#endif
		Tokeniser tokeniser(plugins, ",");
		std::string token = tokeniser.nextToken();
		while (token != "") {
			std::string pluginPath;
			bool pluginLoaded = false;
			for (std::vector<std::string>::iterator I = pluginLocations.begin(); I != pluginLocations.end(); ++I) {
				pluginPath = (*I) + "/" + token + pluginExtension;
				S_LOG_INFO("Trying to load the plugin '" << pluginPath << "'.");
				try {
					mRoot->loadPlugin(pluginPath);
					pluginLoaded = true;
					break;
				} catch (...) {
					pluginPath = (*I) + "/" + token + "_d" + pluginExtension;
					S_LOG_INFO("Trying to load the plugin '" << pluginPath << "'.");
					try {
						mRoot->loadPlugin(pluginPath);
						pluginLoaded = true;
						break;
					} catch (...) {
					}
				}
			}
			if (pluginLoaded) {
				S_LOG_INFO("Successfully loaded the plugin '" << token << "' from '" << pluginPath << "'.");
			} else {
				S_LOG_FAILURE("Failed to load the plugin '" << token << "'!");
			}
			token = tokeniser.nextToken();
		}
	}

	if (chdir(configSrv.getEmberDataDirectory().c_str())) {
		S_LOG_WARNING("Failed to change to the data directory '" << configSrv.getEmberDataDirectory() << "'.");
	}

	return mRoot;
}
Esempio n. 5
0
int main (int argc, char* argv[])
{
    mainArgCount = argc - 1;


#ifdef  __HYPHYMPI__
    int            rank,
                   size;

    MPI_Init       (&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    setParameter  (mpiNodeID,    (_Parameter)rank);
    setParameter    (mpiNodeCount, (_Parameter)size);
    _hy_mpi_node_rank = rank;

    if (rank == 0) {
        mpiNodesThatCantSwitch.Populate (size,1,0);
        /* {
              char hostname[256];
              gethostname(hostname, sizeof(hostname));
              printf("PID %d on %s ready for attach\n", getpid(), hostname);
              fflush(stdout);
              //getchar ();
          } */
#endif


        //for (long k=0; k<NSIG; k++)
        //{
        //  signal(k, &hyphyBreak);
        //}

#ifdef  __HYPHYMPI__
    }
#endif

    char    curWd[4096],
            dirSlash = GetPlatformDirectoryChar ();
    getcwd (curWd,4096);

    _String baseDir (curWd);

    if (baseDir.getChar (baseDir.sLength-1) != dirSlash) {
        baseDir=baseDir & dirSlash;
    }


#if defined _HYPHY_LIBDIRECTORY_
    _String libDir (_HYPHY_LIBDIRECTORY_);

    if (libDir.getChar (libDir.sLength-1) != dirSlash) {
        libDir=libDir & dirSlash;
    }

    pathNames&& &libDir;
#else
     pathNames&& &baseDir;
    _String libDir = baseDir;
#endif

    _String argFile;

    libDirectory  = libDir;
    libArgDir     = libDirectory;
    baseDirectory = baseDir;
    baseArgDir    = baseDirectory;

    _ExecutionList ex;

#ifdef _OPENMP
    systemCPUCount = omp_get_max_threads();
#endif

#ifdef _MINGW32_MEGA_
    {
        char pid[16];
        snprintf (pid,16,"%u", GetCurrentProcessId());

        _String pipeName = _String("\\\\.\\pipe\\MEGAPipe") & pid;
        printf ("Pipe name = %s\n", pipeName.sData);
        if ((_HY_MEGA_Pipe = CreateFile(pipeName.sData, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) {
            char* lpMsgBuf;
            FormatMessage(
                FORMAT_MESSAGE_ALLOCATE_BUFFER |
                FORMAT_MESSAGE_FROM_SYSTEM |
                FORMAT_MESSAGE_IGNORE_INSERTS,
                NULL,
                GetLastError(),
                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                (LPTSTR) &lpMsgBuf,
                0, NULL );
            FlagError (_String("Failed to create a pipe named '") & pipeName & "' to send data from HyPhy to MEGA. Error: "&lpMsgBuf);
        }
    }
#endif

    for (long i=1; i<argc; i++) {
        _String thisArg (argv[i]);
        if (thisArg.sData[0]=='-') {
            ProcessConfigStr (thisArg);
        } else if (thisArg.beginswith ("BASEPATH=")) {
            baseArgDir = thisArg.Cut(9,-1);
            if (baseArgDir.sLength) {
                if (baseArgDir.sData[baseArgDir.sLength-1]!=dirSlash) {
                    baseArgDir = baseArgDir&dirSlash;
                }

                baseDirectory = baseArgDir;
            }
        } else if (thisArg.beginswith ("LIBPATH=")) {
            libArgDir = thisArg.Cut(8,-1);
            if (libArgDir.sLength) {
                if (libArgDir.sData[libArgDir.sLength-1] != dirSlash) {
                    libArgDir = libArgDir & dirSlash;
                }
                libDirectory = libArgDir;
            }
        } else if (thisArg.beginswith ("USEPATH=")) {
            baseDir             = thisArg.Cut(8,-1);
            errorFileName       = baseDir & errorFileName;
            messageFileName     = baseDir & messageFileName;
            pathNames.Delete    (0);
            pathNames&&         &baseDir;
        } else
#ifdef __MP__
            if (thisArg.beginswith ("CPU=")) {
                _String cpus = thisArg.Cut(4,-1);
                systemCPUCount = cpus.toNum();
                if (systemCPUCount<1) {
                    systemCPUCount = 1;
                }
                pthread_setconcurrency (systemCPUCount+1);
            } else
#endif
                argFile = thisArg;
    }

    GlobalStartup();

    if (calculatorMode) {
        printf ("\nHYPHY is running in calculator mode. Type 'exit' when you are finished.\n");
        while (ExpressionCalculator()) ;
        return 0;
    }

    if (pipeMode) {
        _String bfIn (stdin);
        _ExecutionList exIn (bfIn);
        exIn.Execute();
        GlobalShutdown();
        return 0;
    }

    // try to read the preferences
    _String     prefFile (curWd);
    prefFile = prefFile & '/' & prefFileName;
    FILE     * testPrefFile = fopen (prefFile.sData,"r");
    if (!testPrefFile) {
        prefFile = baseArgDir & prefFileName;
        testPrefFile = fopen (prefFile.sData,"r");
    }
    if (testPrefFile) {
        fclose(testPrefFile);
        ReadBatchFile (prefFile,ex);
        ex.Execute();
        ex.Clear();
    }
    //printf ("Node %d before mpiParallelOptimizer\n", rank);
#ifdef __HYPHYMPI__
    if (rank>0) {
        //if (mpiParallelOptimizer || mpiPartitionOptimizer)
        //  mpiOptimizerLoop (rank, size);
        //else
        _String defaultBaseDirectory = *(_String*)pathNames(0);
        mpiNormalLoop (rank, size, defaultBaseDirectory);
        /*argFile = "SHUTDOWN_CONFIRM";
        MPISendString (argFile, senderID);*/
    } else {
#endif
        if (!argFile.sLength) {
            long selection = -2;
            if (!updateMode) {
                selection = DisplayListOfChoices();
            }

            if (selection == -1) {
                dialogPrompt = "Batch file to run:";
                _String fStr (ReturnDialogInput (true));
                if (logInputMode) {
                    _String tts = loggedFileEntry&fStr;
                    loggedUserInputs && & tts;
                }

                PushFilePath (fStr);
                ReadBatchFile (fStr,ex);
            } else {
                _String templ;

                if (selection >= 0) {
                    templ = baseArgDir &"TemplateBatchFiles" & dirSlash;
                } else {
                    templ = baseArgDir & "TemplateBatchFiles" & dirSlash & "WebUpdate.bf";
                }

                if (selection >= 0) {
                    templ= templ&*(_String*)(*(_List*)availableTemplateFiles(selection))(2);
                }

                PushFilePath (templ);
                ReadBatchFile (templ,ex);
            }
        } else {
#ifndef __MINGW32__
            if (argFile.sData[0] != '/') {
                argFile       = baseDirectory & argFile;
            }
#else
            if (argFile.sData[1] != ':') { // not an absolute path
                argFile       = baseDirectory & argFile;
            }
#endif
            PushFilePath  (argFile);
            ReadBatchFile (argFile,ex);
        }

        ex.Execute();

        if (usePostProcessors && (!updateMode)) {
            ReadInPostFiles();
            printf ("\n\n**********Continue with result processing (y/n)?");
            _String c_str (StringFromConsole());

            if (logInputMode) {
                loggedUserInputs && & c_str;
            }

            if (c_str.getChar(0) !='n' && c_str.getChar(0)!='N' ) {
                long choice = DisplayListOfPostChoices();
                while (choice != -1) {
                    _ExecutionList postEx;
                    argFile = *(_String*)(*(_List*)availablePostProcessors(choice-1))(1);
                    PushFilePath (argFile);
                    ReadBatchFile (argFile, postEx);
                    postEx.Execute();
                    PopFilePath ();
                    printf ("\n\n**********Continue with result processing (y/n)?");

                    c_str = StringFromConsole();
                    if (logInputMode) {
                        loggedUserInputs && & c_str;
                    }

                    if (c_str.getChar(0)=='n' || c_str.getChar(0)=='N' ) {
                        break;
                    }

                    choice = DisplayListOfPostChoices();
                }
            }
        }
#ifdef __HYPHYMPI__
    }
    ReportWarning               (_String ("Node ") & (long)rank & " is shutting down\n");
#endif


#ifdef _MINGW32_MEGA_
    if (_HY_MEGA_Pipe != INVALID_HANDLE_VALUE) {
        CloseHandle (_HY_MEGA_Pipe);
    }
#endif

    PurgeAll                    (true);
    GlobalShutdown              ();

#ifdef __HYPHYMPI__
    if (rank == 0) {
        printf ("\n\n");
    }
#endif

}