Пример #1
0
void Console::showCommands(Command *command, int indentLevel) {
	while (command) {
		showIndent(indentLevel);
		debugPrintf("%s\n", convertToASCII(command->debugString()).c_str());

		if (SeqCommand *const seqCmd = dynamic_cast<SeqCommand *>(command)) {
			command = seqCmd->next();
		} else if (ConditionalCommand *const condCmd = dynamic_cast<ConditionalCommand *>(command)) {
			showCommands(condCmd->getTrueCommand(), indentLevel + 1);
			showIndent(indentLevel);
			debugPrintf("ELSE\n");
			showCommands(condCmd->getFalseCommand(), indentLevel + 1);
			command = nullptr;
		} else if (CallMacroCommand *const callMacroCmd = dynamic_cast<CallMacroCommand *>(command)) {
			command = callMacroCmd->getReturnCommand();
		} else if (RandomCommand *const randomCmd = dynamic_cast<RandomCommand *>(command)) {
			const RandomCommand::Choices &choices = randomCmd->getChoices();
			for (RandomCommand::Choices::size_type i = 0; i < choices.size(); ++i) {
				showIndent(indentLevel + 1);
				debugPrintf("CASE %u\n", i);
				showCommands(choices[i], indentLevel + 2);
			}
			command = nullptr;
		} else {
			command = nullptr;
		}
	}
}
Пример #2
0
bool Console::cmd_showmacro(int argc, const char **argv) {
	if (argc == 3) {
		Script *script = nullptr;
		if (strcmp(argv[1], "G") == 0) {
			script = _vm->getGame().getGlobalScript();
		} else if (strcmp(argv[1], "L") == 0) {
			script = _vm->getGame().getLocalScript();
		}
		if (!script) {
			debugPrintf("Choose 'G' (global) or 'L' (local) script.\n");
		} else {
			const Macros &macros = script->getMacros();
			Macros::const_iterator itMacro = macros.find(argv[2]);
			if (itMacro != macros.end()) {
				if (itMacro->_value) {
					showCommands(itMacro->_value);
				}
			} else {
				debugPrintf("Macro not found.\n");
			}
		}
	} else {
		debugPrintf("showmacro <G|L> <macroname>\n");
	}

	return true;
}
Пример #3
0
bool Console::cmd_showsection(int argc, const char **argv) {
	if (argc >= 4) {
		Script *const script = getScriptFromArg(argv[1]);
		if (script) {
			Command *command = nullptr;
			ActionInfo::Action action = ActionInfo::Look;
			bool correctAction = true;
			bool found = false;

			if (strcmp(argv[2], "L") == 0) {
				action = ActionInfo::Look;
			} else if (strcmp(argv[2], "W") == 0) {
				action = ActionInfo::Walk;
			} else if (strcmp(argv[2], "T") == 0) {
				action = ActionInfo::Talk;
			} else if (strcmp(argv[2], "U") == 0) {
				action = ActionInfo::Use;
			} else if (strcmp(argv[2], "P") == 0) {
				action = ActionInfo::PickUp;
			} else {
				debugPrintf("Choose 'L' (look), 'W' (walk), 'T' (talk), 'U' (use) or 'P' (pick up).\n");
				correctAction = false;
			}

			if (correctAction) {
				const ActionInfos &actionInfos = script->getActionInfos(action);
				for (ActionInfos::const_iterator it = actionInfos.begin(); it != actionInfos.end(); ++it) {
					const ActionInfo &actionInfo = *it;
					if (convertToASCII(actionInfo._entity1Name) == argv[3] && (action != ActionInfo::Use || ((argc == 4 && actionInfo._entity2Name.empty()) || (argc > 4 && convertToASCII(actionInfo._entity2Name) == argv[4])))) {
						found = true;
						command = actionInfo._command;
						break;
					}
				}

				if (found) {
					if (command) {
						showCommands(command);
					}
				} else {
					debugPrintf("Section not found.\n");
				}
			}
		}
	} else {
		debugPrintf("showsection <G|L> <L|W|T|U|P> <sectionname>\n");
	}

	return true;
}
Пример #4
0
bool Console::cmd_showstartup(int argc, const char **argv) {
	if (argc == 3) {
		Script *const script = getScriptFromArg(argv[1]);
		if (script) {
			const Startups &startups = script->getStartups();
			Startups::const_iterator itMacro = startups.find(static_cast<uint8>(atoi(argv[2])));
			if (itMacro != startups.end()) {
				if (itMacro->_value) {
					showCommands(itMacro->_value);
				}
			} else {
				debugPrintf("Startup not found.\n");
			}
		}
	} else {
		debugPrintf("showstartup <G|L> <startupid>\n");
	}

	return true;
}
Пример #5
0
/*MAIN MENU
 * Displays main menu choices*/
void showMenu() {
    Cell board[BOARD_HEIGHT][BOARD_WIDTH];
    while (TRUE) {
        int choice;
        printf("\n");
        printf("Welcome to Car Board \n");
        printf("-------------------- \n");
        printf("1. Play game \n");
        printf("2. Show student's information \n");
        printf("3. Quit \n\n");
        choice = validateNumber();
        if (choice == 1) {

            showCommands();
            initialiseBoard(board);
            displayBoard(board, NULL);

            printf("load <g>\n");
            printf("quit\n\n");

            initialiseGame();
        }

        if (choice == 2) {

            showStudentInformation();
        }

        if (choice == 3) {

            printf("\n");
            printf("Good Bye!\n\n");

            break;

        }
    }
}
Пример #6
0
void * command_input_thread(void * arg){
	char inputBuffer[512] = "";
	char command[512] = "";
	char name[512] = "";

	ThreadInputPtr inputPtr = ((ThreadInputPtr)arg);
	int * sockPtr = inputPtr->sockNoPtr;
	int sockNo = *sockPtr;

	free(inputPtr->sockNoPtr);
	free(arg);


	showCommands();

	while(1){
		memset(&inputBuffer, 0, sizeof(inputBuffer));
		memset(&command, 0, sizeof(command));
		memset(&name, 0, sizeof(name));
		printf("Enter Input: ");
		scanf("%[^\n]%*c", inputBuffer);
		if(sscanf(inputBuffer,"%s %s", command, name) > 0){
			printf("\n");
			printf("You're sending command: <%s>. name: <%s> to the server\n", command, name);
			write(sockNo, inputBuffer, sizeof(inputBuffer));
			sleep(2); //wait 2 seconds to enter next command
		}else{
			printerr("reading input failed, try again");
			continue;
		}
	}

	pthread_exit(pthread_self);

	return NULL;
}
Пример #7
0
int main(){

/*					*/
/* BEGIN INITIALIZE */
/*					*/
	bool loop = true;
	cout << "MAGIC SQUARE CONSTRUCTION PROGRAM \nBUILD VERSION "
		 << LATEST_VERSION
		 << "\nLAST REVISED "
		 << REVISION_DATE
		 << "\nCOPYRIGHT "
		 << AUTHOR
		 << "\n\n\n";
/* END INITIALIZE */


	while(loop){
		cout << "Enter command (or type 'help' for command list): ";
		string str;
		getline(cin, str);
		for(unsigned int z = 0; z < str.length(); z++)
			str[z] = tolower(str[z]);
		cout << endl;


/*						  */
/* BEGIN CHECK USER INPUT */
/*						  */
		if(str == "help")
			showCommands();

		else if(str == "exit" || str == "quit")
			loop = false;

		else if(str == "generate squares"){
			int remaining[NSQ];
			STDMatrix builder;
			for(int i = 0; i < NSQ; i++)
				remaining[i] = 0;
			cout << "Generating Order-" << N << " squares. . . \n\n";
			generateOrder4(remaining, builder, 1);
			cout << "All squares built.";
		}

		else if(str.find("output square ") != -1){
			if(magics.size() == 0)
				throwException(1);
			else{
				unsigned int a = atoi(str.substr(14).c_str()) - 1;
				if(a <= magics.size() - 1 && a >= 0)
					magics[a].print();
				else
					throwException(2);
			}
		}

		else if(str.find("output squares ") != -1){
			if(magics.size() == 0)
				throwException(1);
			else{
				int pos = str.find("to") - 1;
				unsigned int a = atoi(str.substr(15, pos-2).c_str()) - 1;
				unsigned int b = atoi(str.substr(pos+3).c_str()) - 1;
				while(a <= b){
					if(a <= magics.size() - 1 && a >= 0){
						magics[a].print();
						if(a != b)
							cout << "\n\n\n";
						a++;
					}
					else{
						throwException(2);
						break;
					}
				}
			}
		}

		else if(str.find("output type ") != -1){
			if(magics.size() == 0)
				throwException(1);
			else{
				unsigned int a = atoi(str.substr(12).c_str());
				for(unsigned int i = 0; i < magics.size(); i++){
					if(magics[i].getType() == a){
						magics[i].print();
						cout << "\n\n\n";
					}
				}
			}
		}

		else if(str == "permute upper triangular"){
			if(magics.size() == 0)
				throwException(1);
			else{
				cout << "Permuting squares as upper triangular. . .\n\n";
				permuteUT();
				cout << "Permutation complete.";
			}
		}

		else if(str == "check square equality"){
			if(magics.size() == 0)
				throwException(1);
			else{
				cout << "Finding unique squares after tests for equality. . .\n\n";
				findUnique_Comparison();
				cout << "Unique squares found.";
			}
		}

		else if(str == "classify squares"){
			if(magics.size() == 0)
				throwException(1);
			else{
				cout << "Classifying squares as Dudeney Types. . .\n\n";
				classify4();
				cout << "Classification complete." << endl << "Remember to reclassify squares after any operation!";
			}
		}

		else if(str == "sort squares"){
			if(magics.size() == 0)
				throwException(1);
			else{
				cout << "Sorting squares from least to greatest. . .\n\n";
				sortLinearCompare();
				cout << "Sorting complete.";
			}
		}

		else if(str == "find unique squares"){
			if(magics.size() == 0)
				throwException(1);
			else{
				cout << "Finding unique squares after tests for permutations. . .\n\n";
				findUnique_Permute();
				cout << "\nUnique squares found.";
			}
		}

		else if(str == "analysis"){
			if(magics.size() == 0){
				cout << "There are currently 0 squares created." << endl
					 << "Generate squares for further details.";
			}
			else{
				cout << "There are currently " << magics.size() << " squares created." << endl;
				if(magics[0].getType() == -1)
					cout << "Classify squares for further details.";
				else
					classList();
			}
		}

		else if(str == "run program")
			runProg();

		else
			cout << "Unknown Command '" << str << "'";
/* END CHECK USER INPUT */


		cout << endl << endl;
	}
	return 0;
}
Пример #8
0
char *
getConsoleInput(Client c, const char *prompt, int linemode, int exit_on_error)
{
	char *line = NULL;
	char *buf = NULL;
	size_t length;
	(void) exit_on_error;
	(void) linemode;

	do {
#ifdef HAVE_LIBREADLINE
		if (prompt) {

			if (buf)
				free(buf);
			buf = readline(prompt);
			/* add a newline to the end since that makes
			   further processing easier */
			if (buf) {
				add_history(buf);
				length = strlen(buf);
				buf = realloc(buf, length + 2);
				if( buf == NULL){
					GDKerror("getConsoleInput: " MAL_MALLOC_FAIL);
					return NULL;
				}
				buf[length++] = '\n';
				buf[length] = 0;
			}
			line = buf;
		} else
#endif
		{
#ifndef HAVE_LIBREADLINE
			if (prompt) {
				fputs(prompt, stdout);
				fflush(stdout);
			}
#endif
			if (buf == NULL) {
				buf= malloc(BUFSIZ);
				if( buf == NULL){
					GDKerror("getConsoleInput: " MAL_MALLOC_FAIL);
					return NULL;
				}
			}
			line = fgets(buf, BUFSIZ, stdin);
		}

		if (line == NULL) {
			/* end of file */
			if (buf)
				free(buf);
			return NULL;
		} else
			length = strlen(line);

		if (length > 0 ) {
			/* test for special commands */
			while (length > 0 &&
			       (*line & ~0x7F) == 0 &&
			       isspace((int) *line)) {
				line++;
				length--;
			}
			/* in the switch, use continue if the line was
			   processed, use break to send to parser */
			switch (*line) {
			case '\0':
				/* empty line */
				break;
			case '\\':
				switch (line[1]) {
				case 'q':
					free(buf);
					return NULL;
				default:
					break;
				}
				line= NULL;
				break;
			case '<':
				/* read commands from file */
				if (line[length - 1] == '\n')
					line[--length] = 0;
				if (line[length - 1] == '\r')
					line[--length] = 0;
				/* doFile(mid, line + 1, 0);*/
				line= NULL;
				continue;
			case '>':
				/* redirect output to file */
				line++;
				length--;
				if (line[length - 1] == '\n')
					line[--length] = 0;
				if (line[length - 1] == '\r')
					line[--length] = 0;

				if (c->fdout && c->fdout != GDKout && c->fdout != GDKerr){
					close_stream(c->fdout);
					c->fdout= 0;
				}
				if (length == 0 || strcmp(line, "stdout") == 0)
					c->fdout = GDKout;
				else if (strcmp(line, "stderr") == 0)
					c->fdout = GDKerr;
				else if ((c->fdout = open_wastream(line)) == NULL) {
					c->fdout = GDKout;
					mnstr_printf(GDKerr, "Cannot open %s\n", line);
				}
				line = NULL;
				continue;
#ifdef HAVE_LIBREADLINE
			case '!':
				{ char *nl;
				  int i;
					if(line[1]=='\n') {
						for(i=0; i< history_length; i++){
							nl= history_get(i)? history_get(i)->line:0;
							if( nl)
							mnstr_printf(c->fdout, "%d %s\n", i, nl);
						}
						line = NULL;
					} else
					if( history_expand(line,&nl) ==1  ) {
						mnstr_printf(c->fdout,"#%s",nl);
						line= nl;
					} else line= NULL;
				}
				continue;
#endif
			case '?':
				if( line[1] && line[1]!='\n'){
					showHelp( c->nspace,line+1, c->fdout);
				} else
					showCommands();
				line= NULL;
				continue;
			}
			/* make sure we return a pointer that can (and should) be freed by the caller */
			if (line)
				line = buf;
		}
	} while (line == NULL);
	return line;
}
Пример #9
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    core(new QRCore()),
    ui(new Ui::MainWindow),
    webserverThread(core, this)
{
    ui->setupUi(this);

    doLock = false;

    // Add custom font
    QFontDatabase::addApplicationFont(":/new/prefix1/fonts/Anonymous Pro.ttf");

    /*
    * Toolbar
    */
    // Hide central tab widget tabs
    QTabBar *centralbar = ui->centralTabWidget->tabBar();
    centralbar->setVisible(false);
    // Adjust console lineedit
    ui->consoleInputLineEdit->setTextMargins(10, 0, 0, 0);
    /*
    ui->consoleOutputTextEdit->setFont(QFont("Monospace", 8));
    ui->consoleOutputTextEdit->setStyleSheet("background-color:black;color:gray;");
    ui->consoleInputLineEdit->setStyleSheet("background-color:black;color:gray;");
    */

    // Adjust text margins of consoleOutputTextEdit
    QTextDocument *console_docu = ui->consoleOutputTextEdit->document();
    console_docu->setDocumentMargin(10);

    // Sepparator between back/forward and undo/redo buttons
    QWidget* spacer4 = new QWidget();
    spacer4->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
    spacer4->setMinimumSize(10, 10);
    ui->mainToolBar->insertWidget(ui->actionForward, spacer4);

    // Popup menu on theme toolbar button
    QToolButton *backButton = new QToolButton(this);
    backButton->setIcon(QIcon(":/new/prefix1/img/icons/arrow_left.png"));
    //backButton->setPopupMode(QToolButton::DelayedPopup);
    ui->mainToolBar->insertWidget(ui->actionForward, backButton);
    connect(backButton, SIGNAL(clicked()), this, SLOT(on_backButton_clicked()));

    // Sepparator between undo/redo and goto lineEdit
    QWidget* spacer3 = new QWidget();
    spacer3->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    spacer3->setMinimumSize(20, 20);
    spacer3->setMaximumWidth(300);
    ui->mainToolBar->insertWidget(ui->actionShow_Hide_mainsidebar, spacer3);

    // Omnibar LineEdit
    this->omnibar = new Omnibar(this);
    ui->mainToolBar->insertWidget(ui->actionShow_Hide_mainsidebar, this->omnibar);

    // Add special sepparators to the toolbar that expand to separate groups of elements
    QWidget* spacer2 = new QWidget();
    spacer2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    spacer2->setMinimumSize(10, 10);
    spacer2->setMaximumWidth(300);
    ui->mainToolBar->insertWidget(ui->actionShow_Hide_mainsidebar, spacer2);

    // Sepparator between back/forward and undo/redo buttons
    QWidget* spacer = new QWidget();
    spacer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
    spacer->setMinimumSize(20, 20);
    ui->mainToolBar->addWidget(spacer);

    // codeGraphics tool bar
    this->graphicsBar = new GraphicsBar(this);
    this->graphicsBar->setMovable(false);
    addToolBarBreak(Qt::TopToolBarArea);
    addToolBar(graphicsBar);

    // Fix output panel font
    QHelpers *help = new QHelpers();
    help->normalizeFont(ui->consoleOutputTextEdit);

    /*
     * Dock Widgets
     */

    // Add Memory DockWidget
    this->memoryDock = new MemoryWidget(this);
    this->dockList << this->memoryDock;
    // To use in the future when we handle more than one memory views
    // this->memoryDock->setAttribute(Qt::WA_DeleteOnClose);
    // this->add_debug_output( QString::number(this->dockList.length()) );

    // Add Sections dock panel
    this->sectionsWidget = new SectionsWidget(this);
    this->sectionsDock = new QDockWidget("Sections");
    this->sectionsDock->setObjectName("sectionsDock");
    this->sectionsDock->setAllowedAreas(Qt::AllDockWidgetAreas);
    this->sectionsDock->setWidget(this->sectionsWidget);
    this->sectionsWidget->setContentsMargins(0,0,0,5);
    this->sectionsDock->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    this->sectionsDock->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(this->sectionsDock, SIGNAL(customContextMenuRequested(const QPoint &)),
            this, SLOT(showSectionsContextMenu(const QPoint &)));

    // Add functions DockWidget
    this->functionsDock = new FunctionsWidget(this);

    // Add imports DockWidget
    this->importsDock = new ImportsWidget(this);

    // Add symbols DockWidget
    this->symbolsDock = new SymbolsWidget(this);

    // Add relocs DockWidget
    this->relocsDock = new RelocsWidget(this);

    // Add comments DockWidget
    this->commentsDock = new CommentsWidget(this);

    // Add strings DockWidget
    this->stringsDock = new StringsWidget(this);

    // Add flags DockWidget
    this->flagsDock = new FlagsWidget(this);

    // Add Notepad Dock panel
    this->notepadDock = new Notepad(this);

    //Add Dashboard Dock panel
    this->dashboardDock = new Dashboard(this);

    // Set up dock widgets default layout
    restoreDocks();
    hideAllDocks();
    showDefaultDocks();

    // Restore saved settings
    this->readSettings();
    // TODO: Allow the user to select this option visually in the GUI settings
    // Adjust the DockWidget areas
    setCorner( Qt::TopLeftCorner, Qt::LeftDockWidgetArea );
    //setCorner( Qt::TopRightCorner, Qt::RightDockWidgetArea );
    setCorner( Qt::BottomLeftCorner, Qt::LeftDockWidgetArea );
    //setCorner( Qt::BottomRightCorner, Qt::RightDockWidgetArea );

    this->flagsDock->flagsTreeWidget->clear();

    // Set omnibar completer for flags
    this->omnibar->setupCompleter();

    // Set console output context menu
    ui->consoleOutputTextEdit->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(ui->consoleOutputTextEdit, SIGNAL(customContextMenuRequested(const QPoint &)),
            this, SLOT(showConsoleContextMenu(const QPoint &)));

    // Hide dummy columns so we can reorder the rest
    hideDummyColumns();

    // Setup and hide sidebar by default
    this->sideBar = new SideBar(this);
    this->sidebar_action = ui->sideToolBar->addWidget(this->sideBar);
    ui->sideToolBar->hide();

    // Show dashboard by default
    this->dashboardDock->raise();

    //qDebug() << "FOLDER: " << QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
    /*
     *  Some global shortcuts
     */
    // Period goes to command entry
    QShortcut* cmd_shortcut = new QShortcut(QKeySequence(Qt::Key_Period), this);
    connect(cmd_shortcut, SIGNAL(activated()), ui->consoleInputLineEdit, SLOT(setFocus()));

    // G and S goes to goto entry
    QShortcut* goto_shortcut = new QShortcut(QKeySequence(Qt::Key_G), this);
    connect(goto_shortcut, SIGNAL(activated()), this->omnibar, SLOT(setFocus()));
    QShortcut* seek_shortcut = new QShortcut(QKeySequence(Qt::Key_S), this);
    connect(seek_shortcut, SIGNAL(activated()), this->omnibar, SLOT(setFocus()));

    // : goes to goto entry
    QShortcut* commands_shortcut = new QShortcut(QKeySequence(Qt::Key_Colon), this);
    connect(commands_shortcut, SIGNAL(activated()), this->omnibar, SLOT(showCommands()));

    connect(&webserverThread, SIGNAL(finished()), this, SLOT(webserverThreadFinished()));
}