Esempio n. 1
0
int main(){
	
	//Signal handling:
	signal(SIGINT, signalHandler);
	
	char** argv;
	int numOfArgs = 0;
	std::vector<std::string> cmdHistory = {};
	std::string command = "";
	std::chrono::duration<double> totalTimeInChildProcesses(0);
	
	char ptime[] = "ptime";
	char carat[] = "^";
	char pwd[] = "pwd";
	char history[] = "history";
	char cd[] = "cd";
	
	while ((command=commandPrompt()) != "exit"){
		//Try if there are things in the command.
		try{
			checkIfBlank(command);
			//Store every Command.
			storeCommand(cmdHistory, command);
			//Parse the commands
			numOfArgs = parseCommand(command, argv);
			
			if (strcmp(carat, argv[0]) == 0){
				if (numOfArgs == 3){
					runNthCmdInHistory(cmdHistory, argv, command);
				}else{
					std::string error = "Error: incorrect number of arguments for '^ <history item>'.";
					throw error;
				}
			}
			if (strcmp(ptime, argv[0]) == 0){
				std::cout<<"Time spent executing child processes: " << totalTimeInChildProcesses.count() <<"seconds\n";
			}else if (strcmp(history, argv[0]) == 0){
				listHistory(cmdHistory);
			}else if(strcmp(cd, argv[0]) == 0){
				if (numOfArgs == 3){
					changeDir(argv);
				}else{
					std::string error = "Error: incorrect number of arguments for 'cd <directory>'.";
					throw error;
				}
			}else if(strcmp(pwd, argv[0]) == 0){
				std::cout<<get_current_dir_name()<<std::endl;
			}else if(isPipeCmd(command)){
				pipe(command, totalTimeInChildProcesses);	
			}else{
				runAndTimeChildProcess(argv[0], argv, totalTimeInChildProcesses);
			}
		}catch(std::string e){
			std::cout<<e<<std::endl;
		}
	}
	return 0;
}
Esempio n. 2
0
void ChatClient::history(const QStringList &args)
{
    if (args.isEmpty())
        return;

    if (m_conn->status() != QtJsonDb::QJsonDbConnection::Connected) {
        fprintf(stderr, "Not connected to JSONDB\n");
        return;
    }

    QtJsonDb::QJsonDbReadRequest *request = new QtJsonDb::QJsonDbReadRequest(this);
    connect(request, SIGNAL(finished()), this, SLOT(listHistory()));
    connect(request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
            this, SLOT(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
    request->setQuery(QLatin1String("[?_type=\"ChatMessage\"][?to=%self | to=%friend][?from=%self | from=%friend][\\time]"));
    request->bindValue(QLatin1String("self"), m_username);
    request->bindValue(QLatin1String("friend"), args.first());

    m_conn->send(request);
}
Esempio n. 3
0
void VListUE::processCommand(int p_id, const QString &p_cmd)
{
    Q_UNUSED(p_id);

    init();

    clear(-1);

    switch (p_id) {
    case ID::History:
        listHistory(p_cmd);
        break;

    default:
        break;
    }

    m_listWidget->updateGeometry();
    emit widgetUpdated();
    emit stateUpdated(State::Success);
}