コード例 #1
0
ファイル: Shell.cpp プロジェクト: sensal/FreeNOS
int Shell::execute(char *command)
{
    char *argv[MAX_ARGV];
    char tmp[128];
    ShellCommand *cmd;
    Size argc;
    int pid, status;

    /* Valid argument? */
    if (!strlen(command))
    {
	return EXIT_SUCCESS;
    }
    /* Attempt to extract arguments. */
    argc = parse(command, argv, MAX_ARGV);

    /* Ignore comments */
    if (argv[0][0] == '#')
        return EXIT_SUCCESS;

    /* Do we have a matching ShellCommand? */
    if (!(cmd = ShellCommand::byName(argv[0])))
    {
	/* If not, try to execute it as a file directly. */
	if ((pid = forkexec(argv[0], (const char **) argv)) != -1)
	{
	    waitpid(pid, &status, 0);
	    return status;
	}
	/* Try to find it on the livecd filesystem. (temporary hardcoded PATH) */
	else if (snprintf(tmp, sizeof(tmp), "/bin/%s", argv[0]) &&
	        (pid = forkexec(tmp, (const char **) argv)) != -1)
	{
	    waitpid(pid, &status, 0);
	    return status;
	}
	else
	    printf("forkexec '%s' failed: %s\r\n", argv[0],
		    strerror(errno));
    }
    /* Enough arguments given? */
    else if (argc - 1 < cmd->getMinimumParams())
    {
	printf("%s: not enough arguments (%u required)\r\n",
		cmd->getName(), cmd->getMinimumParams());
    }
    /* Execute it. */
    else
    {
	return cmd->execute(argc - 1, argv + 1);
    }
    /* Not successful. */
    return EXIT_FAILURE;
}
コード例 #2
0
ファイル: commandsmodel.cpp プロジェクト: Acce0ss/shellex
void CommandsModel::removeAt(int index)
{
    if(index >= 0 && index < m_commands.length())
    {
        ShellCommand* temp = m_commands.at(index);
        beginRemoveRows(QModelIndex(), index, index);
        m_commands.removeAt(index);
        endRemoveRows();
        if(temp != NULL)
        {
            temp->deleteLater();
        }
    }
}
コード例 #3
0
ファイル: commandsmodel.cpp プロジェクト: Acce0ss/shellex
ShellCommand *CommandsModel::findCommandByName(QString command)
{
    for(int i = 0; i < rowCount(); i++)
    {

        ShellCommand* temp = m_commands.at(i);
        if(temp != NULL)
        {
            if(temp->name() == command)
            {
                return temp;
            }
        }
    }

    return NULL;
}
コード例 #4
0
ファイル: shell.cpp プロジェクト: penguin138/parallel_project
void Shell::start() {
  std::string commandWithArgs;
  out << PROMPT;
  while(std::getline(in, commandWithArgs, '\n')) {
    if (!commandWithArgs.empty() && !isSpaces(commandWithArgs)) {
      ShellCommand* cmd = commands[getCommandName(commandWithArgs)];
      if (cmd == NULL) {
        out << "command not found" << std::endl;
      } else {
        cmd->run(commandWithArgs);
        if (cmd->getName() == "quit") {
          break;
        }
      }
    }
    out << PROMPT;
  }
}
コード例 #5
0
ファイル: commandsmodel.cpp プロジェクト: Acce0ss/shellex
ShellCommand *CommandsModel::findCommandById(unsigned int id)
{

    for(int i = 0; i < rowCount(); i++)
    {

        ShellCommand* temp = m_commands.at(i);
        if(temp != NULL)
        {
            if(temp->id() == id)
            {
                return temp;
            }
        }
    }

    return NULL;

}
コード例 #6
0
ファイル: Shell.cpp プロジェクト: kanbang/Colt
bool Shell::mainLoop(std::istream &in, Environment &env) const
{
	InputParser iParser;
	ShellCommand::Args args;
	
	const Shell *oldShell = env.shell();
	env.shell() = this;
	
	bool success = true;
	do {
		if(env.interactive()) cout << endl << "dbxml> ";
		env.lineNo() += iParser.parse(in, args);
		string command = args.empty() ? string("") : args.front();
		try {
			ShellCommand *cmd = findCommand(command);
			if (cmd)
				cmd->execute(args, env);
			else if(!args.empty()) {
				throw CommandException("Unknown command");
			}
		}
		//catches XmlException
		catch(exception &e) {
			cerr << env.streamName() << ":" << env.lineNo() <<
				": " << command << " failed, ";
			cerr << e.what() << endl;
			success = false;
			if(!env.interactive() && !env.ignoreErrors())
				env.quit() = true;
		}
		catch(...) {
			cerr << env.streamName() << ":" << env.lineNo() <<
				": " << command << " failed" << endl;
			success = false;
			if(!env.interactive() && !env.ignoreErrors())
				env.quit() = true;
		}
	} while(!env.quit() && !in.eof() && !env.sigBlock().isInterrupted());
	
	env.shell() = oldShell;
	return success;
}
コード例 #7
0
ファイル: vcscommandpage.cpp プロジェクト: DuinoDu/qt-creator
void VcsCommandPage::delayedInitialize()
{
    auto wiz = qobject_cast<JsonWizard *>(wizard());
    QTC_ASSERT(wiz, return);

    const QString vcsId = wiz->expander()->expand(m_vcsId);
    IVersionControl *vc = VcsManager::versionControl(Id::fromString(vcsId));
    if (!vc) {
        qWarning() << QCoreApplication::translate("VcsBase::VcsCommandPage",
                                                  "\"%1\" (%2) not found.")
                      .arg(QLatin1String(VCSCOMMAND_VCSID), vcsId);
        return;
    }
    if (!vc->isConfigured()) {
        qWarning() << QCoreApplication::translate("VcsBase::VcsCommandPage",
                                                  "Version control \"%1\" is not configured.")
                      .arg(vcsId);
        return;
    }
    if (!vc->supportsOperation(IVersionControl::InitialCheckoutOperation)) {
        qWarning() << QCoreApplication::translate("VcsBase::VcsCommandPage",
                                                  "Version control \"%1\" does not support initial checkouts.")
                      .arg(vcsId);
        return;
    }

    const QString repo = wiz->expander()->expand(m_repository);
    if (repo.isEmpty()) {
        qWarning() << QCoreApplication::translate("VcsBase::VcsCommandPage",
                                                  "\"%1\" is empty when trying to run checkout.")
                      .arg(QLatin1String(VCSCOMMAND_REPO));
        return;
    }

    const QString base = wiz->expander()->expand(m_directory);
    if (!QDir(base).exists()) {
        qWarning() << QCoreApplication::translate("VcsBase::VcsCommandPage",
                                                  "\"%1\" (%2) does not exist.")
                      .arg(QLatin1String(VCSCOMMAND_DIR), base);
        return;
    }

    const QString name = wiz->expander()->expand(m_name);
    if (name.isEmpty()) {
        qWarning() << QCoreApplication::translate("VcsBase::VcsCommandPage",
                                                  "\"%1\" is empty when trying to run checkout.")
                      .arg(QLatin1String(VCSCOMMAND_CHECKOUTNAME));
        return;
    }

    const QString runMessage = wiz->expander()->expand(m_runMessage);
    if (!runMessage.isEmpty())
        setStartedStatus(runMessage);

    QStringList extraArgs;
    foreach (const QString &in, m_arguments) {
        const QString tmp = wiz->expander()->expand(in);
        if (tmp.isEmpty())
           continue;
        if (tmp == QStringLiteral("\"\""))
            extraArgs << QString();
        extraArgs << tmp;
    }

    ShellCommand *command
            = vc->createInitialCheckoutCommand(repo, Utils::FileName::fromString(base),
                                               name, extraArgs);

    foreach (const JobData &job, m_additionalJobs) {
        QTC_ASSERT(!job.job.isEmpty(), continue);

        if (!JsonWizard::boolFromVariant(job.condition, wiz->expander()))
            continue;

        QString commandString = wiz->expander()->expand(job.job.at(0));
        if (commandString.isEmpty())
            continue;

        QStringList args;
        for (int i = 1; i < job.job.count(); ++i) {
            const QString tmp = wiz->expander()->expand(job.job.at(i));
            if (tmp.isEmpty() && job.skipEmptyArguments)
                continue;
            args << tmp;
        }

        const QString dir = wiz->expander()->expand(job.workDirectory);
        const int timeoutS = command->defaultTimeoutS() * job.timeOutFactor;
        command->addJob(Utils::FileName::fromUserInput(commandString), args, timeoutS, dir);
    }