コード例 #1
0
void CmdSystemEx::Cmd_ListCmds_f( const CmdArgs &args ) {
	DictEx<ConsoleCmd> & cmdList = CmdSystemObject.cmdList;
	bool match = false;
	const char *matchstr = 0;

	if( args.Argc() > 1 ) {
		match = true;
		matchstr = args.Argv(1);
	}

	int num = cmdList.Num();
	int i = 0;
	int disp = 0;
	Format out("  $+18* - $*\n");
	for( i=0; i<num; i++ ) {
		if ( match && String::Find(cmdList.GetKey(i).c_str(), matchstr, false) == String::INVALID_POSITION )
			continue;
		out << cmdList.GetKey(i) << cmdList[i].usage->strDescription;
		Console::Print( out );
		out.Reset();
		disp++;
	}

	if( match )
		Console::Print( Format( "\n  $* command$* matching \"$*\"\n" ) << disp << (disp == 1 ? "" : "s") << matchstr );
	else
		Console::Print( Format( "\n  $* command$*\n" ) << disp << (disp == 1 ? "" : "s") );
}
コード例 #2
0
void CmdSystemEx::Cmd_Wait_f( const CmdArgs &args ) {
	int ms = CmdSystemObject.minWaitTime;
	if ( args.Argc() > 1 ) {
		ms = String::ToInt(args.Argv(1));
		if ( ms < CmdSystemObject.minWaitTime )
			ms = CmdSystemObject.minWaitTime;
	}
	CmdSystemObject.waitTime = SysInfo::GetTime() + ms;
}
コード例 #3
0
ファイル: programSetUp.hpp プロジェクト: umass-bib/bibcpp
	/**@brief Once all options have been looked for call finishSetUp() so that any
	 *warnings or help messages can be print and to find out if set up was
	 *successful
	 * @param out The std::ostream out object to print to
	 *
	 */
	void finishSetUp(std::ostream &out = std::cout) {
		if (commands_.printingHelp() || commands_.gettingFlags() ) {
			printFlags(out);
			exit(1);
		}
		lookForInvalidOptionsDashInsens();
		printWarnings(out);
		if (failed_) {
			exit(1);
		}
	}
コード例 #4
0
ファイル: programSetUp.hpp プロジェクト: umass-bib/bibcpp
	/**@brief A function to start a runLog in the named directory
	 * @param dirName The name of the directory to start the runLog, runLog name
	 *will be runLog_[NAME_OF_PROGRAM]
	 *
	 */
	void startARunLog(const std::string &dirName) {
		rLog_.setFilenameAndOpen(
				files::make_path(dirName,"runLog_"
						+ replaceString(replaceString(commands_.getProgramName(), "./", ""),
								" ", "-")+ "_" + getCurrentDate() + ".txt").string(), timer_.start_);
		rLog_.startRunLog(commands_);
	}
コード例 #5
0
ファイル: main.cpp プロジェクト: rousse/vle
static int manage_remote_mode(const std::string &remotecmd, const CmdArgs &args)
{
    vle::utils::RemoteManagerActions act = vle::utils::REMOTE_MANAGER_UPDATE;
    int ret = EXIT_SUCCESS;

    if (remotecmd == "update")
        act = vle::utils::REMOTE_MANAGER_UPDATE;
    else if (remotecmd == "source")
        act = vle::utils::REMOTE_MANAGER_SOURCE;
    else if (remotecmd == "install")
        act = vle::utils::REMOTE_MANAGER_INSTALL;
    else if (remotecmd == "local_search")
        act = vle::utils::REMOTE_MANAGER_LOCAL_SEARCH;
    else if (remotecmd == "search")
        act = vle::utils::REMOTE_MANAGER_SEARCH;
    else if (remotecmd == "show")
        act = vle::utils::REMOTE_MANAGER_SHOW;

    try {
        vle::utils::RemoteManager rm;
        rm.start(act, args.front(), &std::cout);
        rm.join();
    } catch (const std::exception &e) {
        std::cerr << vle::fmt(_("Remote error: %1%\n")) % e.what();
        ret = EXIT_FAILURE;
    }

    return ret;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: alsabadel/vle
static bool init_package(vle::utils::Package& pkg, const CmdArgs &args)
{

    if (not pkg.existsBinary()) {
        if (not pkg.existsSource()) {
            if (std::find(args.begin(), args.end(), "create") == args.end()) {
                std::cerr << vle::fmt(
                    _("Package `%1%' does not exist. Use the create command"
                      " before other command.\n")) % pkg.name();

                return false;
            }
        }
    }
    return true;
}
コード例 #7
0
	void Complete( const CmdArgs &args, argCompletionCB_t callback ) const {
		const DictEx<CVarDataEx> &cvarDataList = cvarSystemEx->GetCVarDataList();
		int num = cvarDataList.Num();
		Format complete( "$* $*" );
		for ( int i=0; i<num; i++ ) {
			callback( complete << args.Argv( 0 ) << cvarDataList[i].strName );
			complete.Reset();
		}
	}
コード例 #8
0
ファイル: programSetUp.hpp プロジェクト: umass-bib/bibcpp
	bool setOption(T &option, std::string flagStr,
			const std::string & shortDescription, bool required,
			const std::string & flagGrouping) {
		bool found = false;
		try {
			Flag currentFlag(option, flagStr, shortDescription, required, flagGrouping);
			std::vector<std::string> flagsFound;
			for (const auto &fTok : currentFlag.flags_) {
				if (commands_.lookForOptionDashCaseInsen(option, fTok)) {
					currentFlag.setValue(option);
					found = true;
					flagsFound.emplace_back(fTok);
				}
			}

			if (required && !found) {
				std::stringstream tempStream;
				tempStream << bashCT::bold + bashCT::black << "Need to have "
						<< bashCT::red << conToStr(tokenizeString(flagStr, ","), " or ")
						<< bashCT::black << " see " << bashCT::red
						<< commands_.getProgramName() + " --help " << bashCT::black
						<< "for more details" << bashCT::reset;
				warnings_.emplace_back(tempStream.str());
				failed_ = true;
			}
			if (found && flagsFound.size() > 1) {
				std::stringstream tempStream;
				tempStream << "Found multiple flags for the same option, found "
						<< conToStr(flagsFound, ", ") << " but should only have one";
				warnings_.emplace_back(tempStream.str());
				failed_ = true;
			}
			flags_.addFlag(currentFlag);
		} catch (std::exception & e) {
			std::stringstream ss;
			ss << "Error setting option for " << flagStr << "\n";
			ss << "Exception: " << e.what() << "\n";
			throw std::runtime_error{ss.str()};
		}
		return found;
	}
コード例 #9
0
ファイル: main.cpp プロジェクト: rousse/vle
static int manage_config_mode(const std::string &configvar, const CmdArgs &args)
{
    int ret = EXIT_SUCCESS;

    try {
        vle::utils::Preferences prefs("vle.conf");

        std::string concat = std::accumulate(args.begin(), args.end(),
                std::string(), Comma());

        if (not prefs.set(configvar, concat))
            throw vle::utils::ArgError(vle::fmt(_("Unknown variable `%1%'")) %
                    configvar);

    } catch (const std::exception &e) {
        std::cerr << vle::fmt(_("Config error: %1%\n")) % e.what();
        ret = EXIT_FAILURE;
    }

    return ret;
}
コード例 #10
0
ファイル: main.cpp プロジェクト: rousse/vle
int main(int argc, char *argv[])
{
    int ret;
    int verbose = 0;
    int processor = 1;
    int trace = -1; /* < 0 = stderr, 0 = file and > 0 = stdout */
    bool manager_mode = false;
    std::string packagename, remotecmd, configvar;
    CmdArgs args;

    {
        ProgramOptions prgs(&verbose, &trace, &processor, &manager_mode,
                &packagename, &remotecmd, &configvar, &args);

        ret = prgs.run(argc, argv);

        if (ret == PROGRAM_OPTIONS_FAILURE)
            return EXIT_FAILURE;
        else if (ret == PROGRAM_OPTIONS_END or args.empty())
            return EXIT_SUCCESS;
    }

    VLE app(verbose, trace); /* We are in package, remote or configuration
                                mode, we need to initialize VLE's API. */

    switch (ret) {
    case PROGRAM_OPTIONS_PACKAGE:
        return manage_package_mode(packagename, manager_mode, processor,
                args);
    case PROGRAM_OPTIONS_REMOTE:
        return manage_remote_mode(remotecmd, args);
    case PROGRAM_OPTIONS_CONFIG:
        return manage_config_mode(configvar, args);
    default:
        break;
    };

    return EXIT_SUCCESS;
}
コード例 #11
0
void CmdSystemEx::Cmd_Help_f( const CmdArgs &args ) {
	if ( args.Argc() > 2 ) {
		Cmd_Help_Usage.ShowUsage();
		return;
	}

	const char *cmd = args.Argv(1);
	// Try Command List
	int i = CmdSystemObject.cmdList.Find(cmd);
	if ( i != -1 ) {
		Console::Print( Format( "$*: $*\n" ) << CmdSystemObject.cmdList.GetKey(i) << CmdSystemObject.cmdList[i].usage->strDescription );
		CmdSystemObject.cmdList[i].usage->ShowUsage();
		return;
	}
	// Not a Command, is it a CVar?
	CVar *cv = cvarSystem->Find(cmd);
	if ( cv ) {
		Console::Print( Format( "$*: $*\n" ) << cv->data->strName << cv->data->strDescription );
		return;
	}
	Console::Print( Format( "Command/Cvar not found: '$*'.\n" ) << cmd );
}
コード例 #12
0
ファイル: main.cpp プロジェクト: alsabadel/vle
int main(int argc, char **argv)
{
    int ret;
    int verbose = 0;
    std::string packagename;
    CmdArgs args;

    {
       ProgramOptions prgs(&verbose, &packagename, &args);
       ret = prgs.run(argc, argv);

       if (ret == PROGRAM_OPTIONS_END)
           return EXIT_SUCCESS;
       else if (ret == PROGRAM_OPTIONS_FAILURE)
           return EXIT_FAILURE;
    }

    vle::gvle::GVLE::start(argc, argv, packagename,
           args.empty() ? std::string() : args.front());

    return EXIT_SUCCESS;
}
コード例 #13
0
ファイル: main.cpp プロジェクト: rousse/vle
static bool init_current_package(const std::string &packagename,
        const CmdArgs &args)
{
    if (not vle::utils::Package::package().existsPackage(packagename)) {
        if (not vle::utils::Path::existDirectory(packagename)) {
            if (std::find(args.begin(), args.end(), "create") == args.end()) {
                std::cerr << vle::fmt(
                    _("Package `%1%' does not exist. Use the create command"
                      " before other command.\n")) % packagename;

                return false;
            }
        }

        vle::utils::Package::package().refresh();
        vle::utils::Package::package().select(packagename);
        vle::utils::Package::package().create();
    } else {
        vle::utils::Package::package().refresh();
        vle::utils::Package::package().select(packagename);
    }

    return true;
}
コード例 #14
0
	void Complete( const CmdArgs &args, argCompletionCB_t callback ) const {
		int num, i;
		StringList fullList;
		const DictEx<ConsoleCmd> &cmdList = CmdSystemObject.GetCommandList();
		num = cmdList.Num();
		for( i = 0; i < num; i++ )
			fullList.Append( cmdList.GetKey(i) );
		const DictEx<CVarDataEx> &cvarDataList = cvarSystemEx->GetCVarDataList();
		num = cvarDataList.Num();
		for( i = 0; i < num; i++ )
			fullList.Append( cvarDataList.GetKey(i) );

		fullList.Sort( StringListICmp, true );
		num = fullList.Num();
		Format complete( "$* $*" );
		for( i = 0; i < num; i++ ) {
			callback( complete << args.Argv( 0 ) << fullList[i] );
			complete.Reset();
		}
	}
コード例 #15
0
ファイル: main.cpp プロジェクト: rousse/vle
static int manage_package_mode(const std::string &packagename, bool manager,
                               int processor, const CmdArgs &args)
{
    CmdArgs::const_iterator it = args.begin();
    CmdArgs::const_iterator end = args.end();
    bool stop = false;

    if (not init_current_package(packagename, args))
        return EXIT_FAILURE;

    for (; not stop and it != end; ++it) {
        if (*it == "create") {
            vle::utils::Package::package().create();
        } else if (*it == "configure") {
            vle::utils::Package::package().configure();
            vle::utils::Package::package().wait(std::cerr, std::cerr);
            stop = not vle::utils::Package::package().isSuccess();
        } else if (*it == "build") {
            vle::utils::Package::package().build();
            vle::utils::Package::package().wait(std::cerr, std::cerr);
            if (vle::utils::Package::package().isSuccess()) {
                vle::utils::Package::package().install();
                vle::utils::Package::package().wait(std::cerr, std::cerr);
            }
            stop = not vle::utils::Package::package().isSuccess();
        } else if (*it == "test") {
            vle::utils::Package::package().test();
            vle::utils::Package::package().wait(std::cerr, std::cerr);
            stop = not vle::utils::Package::package().isSuccess();
        } else if (*it == "install") {
            vle::utils::Package::package().install();
            vle::utils::Package::package().wait(std::cerr, std::cerr);
            stop = not vle::utils::Package::package().isSuccess();
        } else if (*it == "clean") {
            vle::utils::Package::package().clean();
            vle::utils::Package::package().wait(std::cerr, std::cerr);
            stop = not vle::utils::Package::package().isSuccess();
        } else if (*it == "rclean") {
            vle::utils::Package::removePackageBinary(
                vle::utils::Package::package().name());
        } else if (*it == "package") {
            vle::utils::Package::package().pack();
            vle::utils::Package::package().wait(std::cerr, std::cerr);
            stop = not vle::utils::Package::package().isSuccess();
        } else if (*it == "all") {
            std::cerr << "all is not yet implemented\n";
            stop = true;
        } else if (*it == "depends") {
            std::cerr << "Depends is not yet implemented\n";
            stop = true;
        } else if (*it == "list") {
            show_package_content();
        } else {
            break;
        }
    }

    int ret = EXIT_SUCCESS;

    if (stop)
        ret = EXIT_FAILURE;
    else if (it != end) {
#ifndef NDEBUG
        vle::devs::ExternalEvent::allocated = 0;
        vle::devs::ExternalEvent::deallocated = 0;
        vle::devs::InternalEvent::allocated = 0;
        vle::devs::InternalEvent::deallocated = 0;
        vle::value::Value::allocated = 0;
        vle::value::Value::deallocated = 0;
#endif
        if (manager)
            ret = run_manager(it, end, processor);
        else
            ret = run_simulation(it, end);

#ifndef NDEBUG
        std::cerr << vle::fmt(_("\n - Debug mode:\n"
                    "                       allocated   deallocated\n"
                    "   - External events: %=12d/%=12d\n"
                    "   - Internal events: %=12d/%=12d\n"
                    "   - Values         : %=12d/%=12d\n")) %
            vle::devs::ExternalEvent::allocated %
            vle::devs::ExternalEvent::deallocated %
            vle::devs::InternalEvent::allocated %
            vle::devs::InternalEvent::deallocated %
            vle::value::Value::allocated %
            vle::value::Value::deallocated;
#endif
    }

    return ret;
}
コード例 #16
0
ファイル: programSetUp.hpp プロジェクト: umass-bib/bibcpp
	/**@brief A function to find out if help is need or required, called with a
	 * minimum arguments parameter to indicated the num of args to print out if no
	 * help flag is indicated
	 * @param minAmountOfArgs Number of arguments to print help, defualts to one
	 * so if only the program name is given it indicates help is needed
	 * @return return true if a help message should be printed or false if no help
	 * is needed
	 */
	bool needsHelp(uint32_t minAmountOfArgs = 0) {
		return (commands_.hasFlagCaseInsen("--help")
				|| commands_.hasFlagCaseInsen("-h")
				|| commands_.numberOfCommands() <= minAmountOfArgs);
	}
コード例 #17
0
ファイル: programSetUp.hpp プロジェクト: umass-bib/bibcpp
	/**@brief Get a string formated run time in seconds rounded to the nearest
	 * hundreth
	 * @return A string wiht run time formated to tell time for hrs, minutes,
	 * seconds etc.
	 */
	std::string getRunTime() {
		return commands_.getProgramName() + " (" + timer_.totalTimeFormatted(2) + ")";
	}
コード例 #18
0
void CmdSystemEx::Cmd_Exec_f( const CmdArgs &args ) {
	String name = args.Argv(1);
	name.DefaultFileExtension(".cfg");
	Console::Print( Format( "Executing '$*'\n" ) << name );
	cmdSystem->ExecuteConfig( name.c_str() );
}
コード例 #19
0
ファイル: Screen.cpp プロジェクト: RenatoUtsch/clTracer
Screen::Screen(const CmdArgs &args)
    : _width(args.width()), _height(args.height()) {

    // Read the input file.
    std::string input = args.inputFilename();
    std::ifstream in(input);
    stop_if(!in.is_open(), "failed to open input file (%s).", input.c_str());

    Point camera, center;
    Vector up, right;
    float fovy;
    in >> camera.x >> camera.y >> camera.z;
    in >> center.x >> center.y >> center.z;
    in >> up.x >> up.y >> up.z;
    in >> fovy;

    // Camera direction to the center of the screen..
    Vector dir = (center - camera).normalize();

    // Make up orthogonal to the camera direction.
    up -= Vector::proj(dir, up);
    up.normalize();

    // Calculate the right direction.
    right = Vector::cross(dir, up);

    // Calculate the width and height of the screen.
    float d = Point::distance(center, camera);
    _heightSize = 2 * tan(toRads(fovy / 2.0f)) * d;
    _widthSize = (_heightSize * _width) / _height;

    // Save the top left pixel.
    Point topLeft = center - (right * (_widthSize / 2)) + (up * (_heightSize / 2));
    _topLeftPixelPos[0] = topLeft.x;
    _topLeftPixelPos[1] = topLeft.y;
    _topLeftPixelPos[2] = topLeft.z;
    _topLeftPixelPos[3] = 1.0f;

    _cameraPos[0] = camera.x;
    _cameraPos[1] = camera.y;
    _cameraPos[2] = camera.z;
    _cameraPos[3] = 1.0f;

    _upVector[0] = up.x;
    _upVector[1] = up.y;
    _upVector[2] = up.z;
    _upVector[3] = 0.0f;

    _rightVector[0] = right.x;
    _rightVector[1] = right.y;
    _rightVector[2] = right.z;
    _rightVector[3] = 0.0f;

    // If the distance from the camera to the center of the screen is d and
    // half the fovy is f, the maximum height of the screen is:
    // A schematic (from the side);
    //                            .
    //                         .  |
    //                     .      | <- h
    //                  .         |
    //               .  f         |
    // Camera -> .----------------. <- Screen center
    //               .     ^d     |
    //                  .         |
    //                     .      | <- h
    //                         .  |
    //                            .
    // tan(f) = h/d => h = tan(f) * d;
    // The height of the screen is h = tan(f) * d.
    //
    // The we know that if the screen has n pixels from top to low (2h), then
    // 2h ~ n
    // The width 2w of the screen, with m pixels, is:
    // 2w ~ m
    // Then 2w = (2h*m)/n
}
コード例 #20
0
void CmdSystemEx::Cmd_Echo_f( const CmdArgs &args ) {
	String result;
	args.Args( result );
	Console::Print( Format( "$*\n" ) << result );
}