/** * @key: Pressed key. * * Handles key presses from user. */ void scores_key_handler(gametime_t time, const int key) { if ('r' == key) { game_save_scores(); /* uninitialize to previous game */ game_initialized = 0; gamemode_enter(mode_game); } else if ('q' == key) { game_save_scores(); mode_exit(); } }
/** * Handle a command callback. This callback will receive notification * of all syntactically correct command lines. It should return false * if there are any errors. */ bool TestBaseCli::handle_command(ParseLineResult* r) { // Look for builtin commands if (r->line_words_.size() > 0) { if (r->line_words_[0] == "exit" ) { RW_BCLI_ARGC_CHECK(r,1); mode_exit(); return true; } if (r->line_words_[0] == "end" ) { RW_BCLI_ARGC_CHECK(r,1); mode_end_even_if_root(); return true; } if (r->line_words_[0] == "quit" ) { RW_BCLI_ARGC_CHECK(r,1); interactive_quit(); return true; } if (r->line_words_[0] == "start-cli" ) { RW_BCLI_ARGC_CHECK(r,1); rw_status_t rs = interactive(); RW_BCLI_RW_STATUS_CHECK(rs); return true; } } std::cout << "Parsing tree:" << std::endl; r->parse_tree_->print_tree(4,std::cout); std::cout << "Result tree:" << std::endl; r->result_tree_->print_tree(4,std::cout); std::cout << "Unrecognized command" << std::endl; return false; }
int cmd_mode_exec(t_hydra_console *con, t_tokenline_parsed *p) { uint32_t usec; int t, tokens_used, factor, ret; bool done; ret = TRUE; done = FALSE; for (t = 0; !done && p->tokens[t]; t++) { switch (p->tokens[t]) { case T_CS_ON: case T_START: case T_LEFT_SQ: con->mode->proto.wwr = 0; MAYBE_CALL(con->mode->exec->start); break; case T_LEFT_CURLY: con->mode->proto.wwr = 1; MAYBE_CALL(con->mode->exec->start); break; case T_CS_OFF: case T_STOP: case T_RIGHT_SQ: case T_RIGHT_CURLY: con->mode->proto.wwr = 0; MAYBE_CALL(con->mode->exec->stop); break; case T_SLASH: MAYBE_CALL(con->mode->exec->clkh); break; case T_BACKSLASH: MAYBE_CALL(con->mode->exec->clkl); break; case T_MINUS: MAYBE_CALL(con->mode->exec->dath); break; case T_UNDERSCORE: MAYBE_CALL(con->mode->exec->datl); break; case T_EXCLAMATION: MAYBE_CALL(con->mode->exec->dats); break; case T_CARET: MAYBE_CALL(con->mode->exec->clk); break; case T_DOT: MAYBE_CALL(con->mode->exec->bitr); break; case T_AMPERSAND: case T_PERCENT: if (p->tokens[t] == T_PERCENT) factor = 1000; else factor = 1; if (p->tokens[t + 1] == T_ARG_TOKEN_SUFFIX_INT) { t += 2; memcpy(&usec, p->buf + p->tokens[t], sizeof(int)); } else { usec = 1; } usec *= factor; DelayUs(usec); break; case T_READ: t += hydrabus_mode_read(con, p, t); break; case T_WRITE: tokens_used = hydrabus_mode_write(con, p, t + 1); if (!tokens_used) done = TRUE; else t += tokens_used; break; case T_TILDE: case T_ARG_UINT: case T_ARG_STRING: tokens_used = hydrabus_mode_write(con, p, t); if (!tokens_used) done = TRUE; else /* * Less one because we didn't start on a "real" * token, and the t++ at the end of this loop * needs to take us to the next token. */ t += tokens_used - 1; break; case T_EXIT: MAYBE_CALL(con->mode->exec->cleanup); mode_exit(con, p); break; default: /* Mode-specific commands. */ tokens_used = con->mode->exec->exec(con, p, t); if (!tokens_used) done = TRUE; else /* * The module dispatcher considers itself to have * used this token, but so does this loop. Subtract * 1 to get back to it. */ t += tokens_used - 1; } } return ret; }