bool ConsoleRoboCupCtrl::compile()
{
  std::string fileName = application->getFilePath().
#ifdef WINDOWS
                         toLatin1
#else
                         toUtf8
#endif
                         ().constData();
  std::string::size_type p = fileName.find_last_of("\\/");
  std::string::size_type p2 = fileName.find_last_of(".");
  if(p2 > p)
    fileName = fileName.substr(0, p2);
  executeFile("", fileName, false, nullptr, true);

  if(!RoboCupCtrl::compile())
    return false;

  if(!robots.empty())
    selected.push_back((*robots.begin())->getRobotProcess());

  start();
  Global::theStreamHandler = &streamHandler;

  executeFile("", fileName, false, nullptr, false);

  for(Robot* robot : robots)
    robot->getRobotProcess()->handleConsole("endOfStartScript");
  for(RemoteRobot* remoteRobot : remoteRobots)
    remoteRobot->handleConsole("endOfStartScript");
  Global::theStreamHandler = &streamHandler;
  return true;
}
Beispiel #2
0
void ScriptToolKit::init( Value initParam )
{
	m_pLuaState = luaL_newstate();
	luaL_openlibs( m_pLuaState );
	
	//Load Pulsar definitions
	//luaL_dofile( m_pLuaState, "pulsar_defs.lua" );
	executeFile( "pulsar_defs.lua" );
	
	//Get Pulsar-*
	lua_getglobal( m_pLuaState, "Pulsar" );
	
	//Set Pulsar.TickScripts = {}
	lua_newtable( m_pLuaState );
	lua_setfield( m_pLuaState, -2, "TickScripts" );
	
	//Set Pulsar.executeTickScripts() = ...
	luaL_loadstring( m_pLuaState,
		"if next( Pulsar.TickScripts ) then \
		for y, x in pairs( Pulsar.TickScripts ) do x() end end" );
	lua_setfield( m_pLuaState, -2, "executeTickScripts" );
	
	//Pop Pulsar.*
	lua_pop( m_pLuaState, 1 );
	
	LuaBinding::registerAll();
	
	m_pConsoleWindow = PulsarEngine::getInstance()->getConsoleWindow();
}
Beispiel #3
0
valBool executeRexxCls::parseAndExecuteNewFile(fCallContCls &tt)
{
 valBool vb1;
 vb1.b=false;
 char nameF1[MAX_FILE_NAME];
 tt.getName().get_p(nameF1);
 strcat(nameF1,".rex");
 nameF1[MAX_FILE_NAME-1]=NULL;
 bool bb12=false;
 fileParserCls *exfcc= new fileParserCls(nameF1);
 containFileCls *cfc1;
 if((cfc1=exfcc->run(nameF1)))
 {
	if(errorReportCls::noError)  exitProgram(0);
	cfc1->print();
	delete exfcc;
	bb12=true;
 }
 else exitProgram(0);
 if(bb12)
 {
	nameOfFiles[tt.getName()]=noOfFileCompiled;
	listOfFiles[noOfFileCompiled]=cfc1;
	noOfFileCompiled++;
	vb1=executeFile(noOfFileCompiled-1);
 }
 return vb1;
}
Beispiel #4
0
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        printf(help_string);
        exit(0);
    }
    char *file_to_execute = argv[1];
    printf("Executing file %s\n", file_to_execute);
    executeFile(RAM, file_to_execute);
    while (!processing_halted_flag)
    {
        tCode code = readCodeFromRAM (RAM, regValue[IP]);
        tCommandWithOperands cmd = makeCommandWithOperands(code);

        commandAction[cmd.cmd.type][cmd.cmd.index](cmd);

        if (command_did_jump)
            command_did_jump = 0;
        else
            regValue[IP] += code.size * WORD_SIZE;
        free(code.words);
    }
    saveMemoryToFile(RAM, final_memory_state_filename);
    return 0;
}
int SC_TerminalClient::run(int argc, char** argv)
{
	Options& opt = mOptions;

	if (!parseOptions(argc, argv, opt)) {
		return mReturnCode;
	}

	// finish argv processing
	const char* codeFile = 0;

	if (argc > 0) {
		codeFile = argv[0];
		opt.mDaemon = true;
		argv++; argc--;
	}

	opt.mArgc = argc;
	opt.mArgv = argv;

	// read library configuration file
	if (opt.mLibraryConfigFile) {
		int argLength = strlen(opt.mLibraryConfigFile);
		SC_LanguageConfig::readLibraryConfigYAML(opt.mLibraryConfigFile);
	} else
		SC_LanguageConfig::readDefaultLibraryConfig();

	// initialize runtime
	initRuntime(opt);

	// startup library
	mShouldBeRunning = true;
	compileLibrary();

	// enter main loop
	if (codeFile) executeFile(codeFile);
	if (opt.mCallRun) runMain();

	if (opt.mDaemon) {
		daemonLoop();
	}
	else {
		initInput();
		if( shouldBeRunning() ) startInput();
		if( shouldBeRunning() ) commandLoop();
		endInput();
		cleanupInput();
	}

	if (opt.mCallStop) stopMain();

	// shutdown library
	shutdownLibrary();
	flush();

	shutdownRuntime();

	return mReturnCode;
}
Beispiel #6
0
int main(int argc, char** argv)
{
	if (argc >2) 
		write(1, "usage: rash [file]",18);	
	if (argc == 1) 
		interactive();
	if (argc == 2)
		executeFile(*(argv+1));
	return 0;
}
void ConsoleRoboCupCtrl::executeConsoleCommand(std::string command, RobotConsole* console, bool scenarioAndLocationOnly)
{
  if(!scenarioAndLocationOnly)
    showInputDialog(command);
  std::string buffer;
  InConfigMemory stream(command.c_str(), command.size());
  stream >> buffer;
  if(buffer == "call")
  {
    std::string optionalFile;
    stream >> buffer >> optionalFile;
    executeFile(optionalFile, buffer, true, console, scenarioAndLocationOnly);
  }
Beispiel #8
0
 // Here we set default commands, they do nothing since we quit with them
 // Quitting behaviour is hardcoded in readLine()
 Console::Console(std::string const& greeting)
     : pimpl_{ new Impl{ greeting } }
 {
     // Init readline basics
     rl_attempted_completion_function = &Console::getCommandCompletions;
     // These are other two hardcoded commands, but they are more readable
     // here rather than in the initialization list.
     // Help command lists available commands.
     pimpl_->commands_["help"] = [this](const std::vector<std::string>&){
         auto commands = getRegisteredCommands();
         std::cout << "Available commands are:\n";
         for ( auto & command : commands ) std::cout << "\t" << command << "\n";
         return 0;
     };
     // Run command executes all commands in an external file.
     pimpl_->commands_["run"] =  [this](const std::vector<std::string>& input) {
         if ( input.size() < 2 ) { std::cout << "Usage: " << input[0] << " script_filename\n"; return 1; }
         return executeFile(input[1]);
     };
 }
Beispiel #9
0
valBool executeRexxCls::callExternalFunction(fCallContCls &tt)
{
 int i1=0;
 valBool ret1;

 if((i1=isInListOfExternal(tt)))
 {ret1=executeFile(i1-1);}
 else if(canOpenNewFile(tt))
	ret1=parseAndExecuteNewFile(tt);
 else
	{
	char sss12[50];
	getNameFile(sss12);
  cout<<" error in file   "<<sss12<<endl;
	getNameProc(sss12);
	 cout<<" error in procedure   "<<sss12<<endl;
	  cout<<" LINE OF ERROR "<<getCurNoLine()<<endl;
	  cout <<" name function is not found     " <<tt.getName()<<endl;
	  myDebugKey(0,"can not execute function ");
	  exitProgram(0);

	}
 return ret1;
}
Beispiel #10
0
FileBrowser::FileBrowser(LiteApi::IApplication *app, QObject *parent) :
    QObject(parent),
    m_liteApp(app)
{
    m_widget = new QWidget;
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->setMargin(0);
    mainLayout->setSpacing(0);

    QDir::Filters filters = QDir::AllDirs | QDir::Files | QDir::Drives
                            | QDir::Readable| QDir::Writable
                            | QDir::Executable /*| QDir::Hidden*/
                            | QDir::NoDotAndDotDot;

    bool bShowHiddenFiles = m_liteApp->settings()->value(FILEBROWSER_SHOW_HIDDEN_FILES,false).toBool();
    if (bShowHiddenFiles) {
        filters |= QDir::Hidden;
    }

#ifdef Q_OS_WIN // Symlinked directories can cause file watcher warnings on Win32.
    filters |= QDir::NoSymLinks;
#endif
    //create filter toolbar
    //m_filterToolBar = new QToolBar(m_widget);
    //m_filterToolBar->setIconSize(QSize(16,16));

    m_syncAct = new QAction(QIcon("icon:images/sync.png"),tr("Synchronize with editor"),this);
    m_syncAct->setCheckable(true);

    m_reloadAct = new QAction(QIcon("icon:filebrowser/images/reload.png"),tr("Reload Folder"),this);

    m_showHideFilesAct = new QAction(tr("Show Hidden Files"),this);
    m_showHideFilesAct->setCheckable(true);
    if (bShowHiddenFiles) {
        m_showHideFilesAct->setChecked(true);
    }
    connect(m_showHideFilesAct,SIGNAL(triggered(bool)),this,SLOT(showHideFiles(bool)));

    m_executeFileAct = new QAction(tr("Execute File"),this);
    connect(m_executeFileAct,SIGNAL(triggered()),this,SLOT(executeFile()));

//    m_filterCombo = new QComboBox;
//    m_filterCombo->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
//    m_filterCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
//    m_filterCombo->setEditable(true);
//    m_filterCombo->addItem("*");
//    m_filterCombo->addItem("Makefile;*.go;*.cgo;*.s;*.goc;*.y;*.e64;*.pro");
//    m_filterCombo->addItem("*.sh;Makefile;*.go;*.cgo;*.s;*.goc;*.y;*.*.c;*.cpp;*.h;*.hpp;*.e64;*.pro");

    //m_filterToolBar->addAction(m_syncAct);
    //m_filterToolBar->addSeparator();
    //m_filterToolBar->addWidget(m_filterCombo);

    //create root toolbar
    m_rootToolBar = new QToolBar(m_widget);
    m_rootToolBar->setIconSize(QSize(16,16));

    m_cdupAct = new QAction(QIcon("icon:filebrowser/images/cdup.png"),tr("Open Parent"),this);

    m_rootCombo = new QComboBox;
    m_rootCombo->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
    m_rootCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
    m_rootCombo->setEditable(false);

    m_rootToolBar->addAction(m_cdupAct);
    m_rootToolBar->addAction(m_reloadAct);
    m_rootToolBar->addSeparator();
    m_rootToolBar->addWidget(m_rootCombo);

#ifdef Q_OS_MAC
    m_folderView = new FolderView(true,m_liteApp);
#else
    m_folderView = new FolderView(false,m_liteApp);
#endif
    m_folderView->setRootIsDecorated(true);
    m_folderView->setFilter(filters);
    //mainLayout->addWidget(m_filterToolBar);
    mainLayout->addWidget(m_rootToolBar);
    mainLayout->addWidget(m_folderView);

    m_widget->setLayout(mainLayout);

    m_setRootAct = new QAction(tr("Set As Root Folder"),this);
    m_openFolderInNewWindowAct = new QAction(tr("Open Folder in New Window"),this);
    m_addToFoldersAct = new QAction(tr("Add to Folders"),this);

    connect(m_setRootAct,SIGNAL(triggered()),this,SLOT(setFolderToRoot()));
    connect(m_cdupAct,SIGNAL(triggered()),this,SLOT(cdUp()));
    connect(m_openFolderInNewWindowAct,SIGNAL(triggered()),this,SLOT(openFolderInNewWindow()));
    connect(m_addToFoldersAct,SIGNAL(triggered()),this,SLOT(addToFolders()));

    QList<QAction*> actions;
    m_filterMenu = new QMenu(tr("Filter"));
    m_filterMenu->setIcon(QIcon("icon:images/filter.png"));
    m_filterMenu->addAction(m_showHideFilesAct);
    actions << m_filterMenu->menuAction() << m_syncAct;

    m_toolWindowAct = m_liteApp->toolWindowManager()->addToolWindow(Qt::LeftDockWidgetArea,m_widget,"filesystem",tr("File System"),true,actions);
    connect(m_toolWindowAct,SIGNAL(toggled(bool)),this,SLOT(visibilityChanged(bool)));
    //connect(m_filterCombo,SIGNAL(activated(QString)),this,SLOT(activatedFilter(QString)));
    connect(m_rootCombo,SIGNAL(activated(QString)),this,SLOT(activatedRoot(QString)));
    connect(m_syncAct,SIGNAL(triggered(bool)),this,SLOT(syncFileModel(bool)));
    connect(m_reloadAct,SIGNAL(triggered()),this,SLOT(reloadFileModel()));
    connect(m_liteApp->editorManager(),SIGNAL(currentEditorChanged(LiteApi::IEditor*)),this,SLOT(currentEditorChanged(LiteApi::IEditor*)));
    connect(m_folderView,SIGNAL(aboutToShowContextMenu(QMenu*,LiteApi::FILESYSTEM_CONTEXT_FLAG,QFileInfo)),this,SLOT(aboutToShowContextMenu(QMenu*,LiteApi::FILESYSTEM_CONTEXT_FLAG,QFileInfo)));
    //connect(m_folderView,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(openEditor(QModelIndex)));
    connect(m_folderView,SIGNAL(activated(QModelIndex)),this,SLOT(activatedFolderView(QModelIndex)));

    QString root = m_liteApp->settings()->value("FileBrowser/root","").toString();
    if (!root.isEmpty()) {
        addFolderToRoot(root);
    }
    bool b = m_liteApp->settings()->value("FileBrowser/synceditor",true).toBool();
    if (b) {
        m_syncAct->setChecked(true);
    }
}
Beispiel #11
0
bool Engine::executeFile(FILE *file,HttpServerRequest &httpRequest,HttpServerResponse &httpResponse)
{
	JSContext *cx = NULL;
	JSObject *obj = NULL;

	m_mutex.acquire_write();

	// pop any available context
	if ( !m_contexts.empty() ) {
		cx = m_contexts.top();
		m_contexts.pop();
	}

	m_mutex.release();

	if ( cx==NULL )
	{
		// create new context
		cx = JS_NewContext(m_runtime,8192);
		if ( cx==NULL ) {
			LogManager::getInstance()->warning(LOGGER_CLASSNAME,"Could not create context. Engine is unavailable.");
			return false;
		}

		JS_SetErrorReporter(cx,reportError);

		if ( LogManager::getInstance()->isDebug() ) {
			LogManager::getInstance()->debug(LOGGER_CLASSNAME,"Created new context");
		}
	}

	bool result = false;

	// begin request (requires js_threadsafe compilation)
	JS_SetContextThread(cx);
	JS_BeginRequest(cx);

	// create global object
	obj = JS_NewObject(cx,&globalClass,0,0);
	if ( obj==NULL ) {
		LogManager::getInstance()->warning(LOGGER_CLASSNAME,"Could not create global object");
	}
	else
	{
		// initialize standard classes on global object
		if ( JS_InitStandardClasses(cx,obj)==JS_FALSE ) {
			LogManager::getInstance()->warning(LOGGER_CLASSNAME,"Could not init standard classes");
		}
		else
		{
			// initialize custom classes on global object
			if ( !initCustomClasses(cx,obj) ) {
				LogManager::getInstance()->warning(LOGGER_CLASSNAME,"Could not init custom classes");
			}
			else
			{
				// create predefined objects on global object
				createPredefinedObjects(cx,obj,httpRequest);

				// create context private
				ContextPrivate *cxPrivate = new ContextPrivate(this,httpRequest,httpResponse);
				JS_SetContextPrivate(cx,cxPrivate);

				// execute script in the context
				result = executeFile(file,cx,obj);

				// cleanup predefined objects on context object
				// note: this one might not be needed, remove later if ok
				cleanupPredefinedObjects(cx,obj);

				delete cxPrivate;
			}
		}
	}
	
	JS_GC(cx); // force garbage collection

	// end request (requires js_threadsafe)
	JS_EndRequest(cx);
	JS_ClearContextThread(cx);

	// return context to js engine
	m_mutex.acquire_write();
	m_contexts.push(cx);
	m_mutex.release();

	return result;
}
Beispiel #12
0
int main(int argc, char** argv){
	//Setting the signal interrupt to its default function. 
	signal(SIGINT, handler);

	//get the pid of the current process
	pid = getpid();

	//Allocating space to store the previous commands.
	int numCmds = 0;
	char **cmds = (char **)malloc(1000 * sizeof(char *));

	int printDollar = 1;

	char input[MAXLINE];
	char** tokens;

	int notEOF = 1;
	int i;

	FILE* stream = stdin;

	while(notEOF) { 
		if (printDollar == 1){ 
			printf("$ "); // the prompt
			fflush(stdin);
		}

		char *in = fgets(input, MAXLINE, stream); //taking input one line at a time

		//Checking for EOF
		if (in == NULL){
			if (DEBUG) printf("EOF found\n");
			exit(0);
		}

		//add the command to the command list.
		cmds[numCmds] = (char *)malloc(sizeof(input));
		strcpy(cmds[numCmds++], input); 

		// Calling the tokenizer function on the input line    
		tokens = tokenize(input);

		// check tokens and execute corresponding command
		if(tokens[0] == NULL){
			printf("");
		}
		else if( is_equal(tokens[0], "run\0") ) {
    			runCommand(tokens[1]);
		}
		else if(is_equal(tokens[0], "cd\0")){
			cdCommand(tokens[1]);
		}
		else if(is_equal(tokens[0], "cron\0")){
			cronCommand(tokens[1]);
		}
		else if(is_equal(tokens[0], "parallel\0")){
			parallelCommand(tokens);
		}
		else{
			executeFile(tokens);
		} 
	}
  
  
	printf("Print and deallocate %s\n", tokens[0]);
	// Freeing the allocated memory	
	for(i=0;tokens[i]!=NULL;i++){
		free(tokens[i]);
	}
	free(tokens);
	return 0;
}
Beispiel #13
0
/*the operation of the run command, takes one argument*/
void runCommand(char * s){
	FILE * fp;
	char** command;
	char** tokens;
    char * line = NULL;
    char *infilename, *outfilename;
  	size_t len = 0;
   	ssize_t read;
	int status;
   	fp = fopen(s, "r");
   	if(fp == NULL){
   		perror("");

   	}
   	else{
	    while ((read = getline(&line, &len, fp)) != -1) {
			//read the next line from the file and executing it
	    	tokens = tokenize(line);
	    	// Calling the tokenizer function on the input line    
			command = (char **) malloc(MAXLINE*sizeof(char**));
			//Check for input and output redirection
			int inCounter=0 , outCounter=0, pipeCounter = 0, appendFlag=0;
			int k=0;
			int flag = 1;
			int pipeFlag = 0;
			for(k=0;tokens[k]!=NULL;k++){
				if( is_equal(tokens[k], "<\0")){
					inCounter++;
					if(inCounter == 1){
						infilename = tokens[k + 1];
					}
					flag = 0;
				}
				if( is_equal(tokens[k], ">\0")){
					outCounter++;
					if(outCounter == 1){
						if(is_equal(tokens[k+1], ">\0")){
							appendFlag=1;
							outfilename=tokens[k + 2];
							outCounter++;
							k++;
						}
						else
							outfilename = tokens[k + 1];
					}
					
					flag = 0;
				}
				if(is_equal(tokens[k], "|\0")){
					pipeFlag = 1;
				}
				if(flag == 1){
					command[k] = tokens[k];
				}
			}
			if(pipeFlag == 1){
				pipeCommand(tokens);
			}
			else{
				executeFile(command, inCounter, infilename, outCounter, outfilename, appendFlag);
			}
			inCounter=0;
			outCounter=0;
			pipeCounter = 0;
			appendFlag=0;	
		}	
		fclose(fp);
	}
	int i = 0;
	//Free up the memory
	for(i=0;command[i]!=NULL;i++){
		free(command[i]);
	}
	free(command);
	for(i=0;tokens[i]!=NULL;i++){
		free(tokens[i]);
	}
	free(tokens);
}
Beispiel #14
0
int main(int argc, char** argv){
	//Setting the signal interrupt to its default function. 
	signal(SIGINT, handler);
	signal(SIGCHLD, sigchldHandler);

	children = (pid_t *)malloc(1000*sizeof(pid_t));
	children[0] = -1;

	//get the pid of the current process
	pid = getpid();

	ready = 1;

	//Allocating space to store the previous commands.
	int numCmds = 0;
	char **cmds = (char **)malloc(1000 * sizeof(char *));

	char input[MAXLINE];
	char** tokens;
	char** command;

	int notEOF = 1;
	int i;

	//variables to store information about I/O redirection
	int inCounter=0 , outCounter=0, pipeCounter = 0, appendFlag=0;
	char * infilename;
	char * outfilename;

	FILE* stream = stdin;
	
	
	while(notEOF) { 
		if (ready == 1){ 
			printf("$ "); // the prompt
			fflush(stdin);
		}

		char *in = fgets(input, MAXLINE, stream); //taking input one line at a time

		//Checking for EOF
		if (in == NULL){
			if (DEBUG) printf("EOF found\n");
			exit(0);
		}

		//add the command to the command list.
		cmds[numCmds] = (char *)malloc(sizeof(input));
		strcpy(cmds[numCmds++], input); 

		// Calling the tokenizer function on the input line    
		tokens = tokenize(input);
		command = (char **) malloc(MAXLINE*sizeof(char**));

		//Check for input and output redirection
		int k=0;
		int flag = 1;
		int pipeFlag = 0;
		for(k=0;tokens[k]!=NULL;k++){
			if( is_equal(tokens[k], "<\0")){
				inCounter++;
				if(inCounter == 1){
					infilename = tokens[k + 1];
				}
				flag = 0;
			}
			if( is_equal(tokens[k], ">\0")){
				outCounter++;
				if(outCounter == 1){
					if(is_equal(tokens[k+1], ">\0")){
						//if appending is done while output redirection
						appendFlag=1;
						outfilename=tokens[k + 2];
						outCounter++;
						k++;
					}
					else
						outfilename = tokens[k + 1];
				}
				
				flag = 0;
			}
			if(is_equal(tokens[k], "|\0")){
				pipeFlag = 1;
			}
			if(flag == 1){
				command[k] = tokens[k];
			}
		}
		
		//if piping is used
		if(pipeFlag == 1){
			pipeCommand(tokens);
		}

		else {
			if(inCounter > 1){
				perror("More than one input redirections.");
			}
			else if(outCounter > 2 || (appendFlag == 0 && outCounter == 2)){
				perror("More than one output redirections.");
			}
			else{
				// check tokens and execute corresponding command
				if(tokens[0] == NULL){
					printf("");
				}
				else if( is_equal(tokens[0], "run\0") ) {
					runCommand(tokens[1]);
				}
				else if(is_equal(tokens[0], "cd\0")){
					cdCommand(tokens[1]);
				}
				else if(is_equal(tokens[0], "cron\0")){
					cronCommand(tokens[1]);
				}
				else if(is_equal(tokens[0], "parallel\0")){
					parallelCommand(command);
				}
				else if(is_equal(tokens[0], "exit\0")){
					exitCommand();
				}
				else{
					executeFile(command, inCounter, infilename, outCounter, outfilename, appendFlag);
				}
			}
		}
		inCounter = 0;
		outCounter = 0;
		appendFlag = 0;
	}
  
  
	printf("Print and deallocate %s\n", tokens[0]);
	// Freeing the allocated memory	
	for(i=0;tokens[i]!=NULL;i++){
		free(tokens[i]);
	}
	free(tokens);
	for(i=0;command[i]!=NULL;i++){
		free(command[i]);
	}
	free(command);
	return 0;
}