int Lexer::getNextToken() { /* check EOF or new line character from previous invocation */ if (LastChar == EOF) { LastChar = ' '; // dirty trick: will be eaten by the next while return tok_eof; } if (LastChar == '\n') { LastChar = ' '; // dirty trick: will be eaten by the next while return tok_newline; } /* now I can skip any white-space character: space, form feed, new * line, carriage return, horizontal tab or vertical tab */ while (isspace(LastChar)) LastChar = getInputChar(); CurString = LastChar; // parse a C-valid identifier or special command for the VM if (isalpha(LastChar) || (LastChar == '_')) { while (isalnum((LastChar = getInputChar())) || (LastChar == '_')) CurString += LastChar; std::string command = CurString; std::transform(command.begin(), command.end(), command.begin(), ::toupper); if (command == "HELP") return tok_help; if (command == "QUIT") return tok_quit; if (command == "LOAD_IR") return tok_load_IR; if (command == "BEGIN") return tok_begin; if (command == "INSERT_OSR") return tok_insert_osr; if (command == "CFG") return tok_cfg; if (command == "CFG_FULL") return tok_cfg_full; if (command == "DUMP") return tok_dump; if (command == "OPT_CFG") return tok_opt_cfg; if (command == "OPT_FULL") return tok_opt_full; if (command == "TRACK_ASM") return tok_track_asm; if (command == "SHOW_ASM") return tok_show_asm; if (command == "REPEAT") return tok_repeat; if (command == "SHOW_MODS") return tok_show_mods; if (command == "SHOW_ADDR") return tok_show_addr; if (command == "SHOW_FUNS") return tok_show_funs; if (command == "SHOW_LINE_IDS") return tok_show_lids; if (command == "LOAD_LIB") return tok_load_lib; if (command == "VERBOSE") return tok_verbose; return tok_identifier; } if (isdigit(LastChar)) { while (isdigit((LastChar = getInputChar()))) CurString += LastChar; return tok_integer; } // LastChar is not an alphanumeric or underscore character switch (LastChar) { case EOF: return tok_eof; case '\n': LastChar = getInputChar(); return tok_newline; default: int ret = LastChar; LastChar = getInputChar(); return ret; } }
std::string* Lexer::getLine() { // trim any initial white-space while (isspace(LastChar)) LastChar = getInputChar(); if (LastChar == EOF) return nullptr; std::string *line = new std::string(""); do { *line += LastChar; LastChar = getInputChar(); } while (LastChar != '\n' && LastChar != EOF); return line; }
void sigfunc(int sig) { if(sig != SIGINT) return; else { if (cancel == 0) { cancel = 1; printf("press ctrl+c again to pause program\n"); } else if (cancel == 1) { cancel = 2; int laser=laserOn; setLaser(POW_OFF); printf("press 'e' to end program\n"); printf("press any other key to resume program\n"); int input = getInputChar(); if (input=='e') exit (0); setLaser(laser); cancel=0; } else { printf("Thanks for flying plotd\n"); setLaser(POW_OFF); pfio_write_output(0x00); pfio_deinit(); exit (0); } } }
void DemoApp::keyInput( const OIS::KeyEvent &arg ) { if(mTrayMgr->getTrayContainer(OgreBites::TL_BOTTOMLEFT)->isVisible() == false) //if chatbox is open, only typing is allowed { switch (arg.key) { case OIS::KC_A: //switch between AI and player control if(playerControlled == -1) //if no tanks are player-controlled { for(int i = 0; i < TANK_LIMIT; i++) //find selected tank { if(tanks.at(i).selected == true) //control the tank (if multiple selected, control the last one selected) { playerControlled = i; //the tank being controlled shutDown(tanks.at(playerControlled)); //turn off the tank's AI } } } else //a tank is already being controlled { prevPlayerControlled = playerControlled; //prevents the retoggle of the same tank tanks.at(playerControlled).currentState = -1; //set the tank to the idle state think(tanks.at(playerControlled)); //turn on the tank's AI playerControlled = -1; //all tanks are AI-controlled for(int i = 0; i < TANK_LIMIT; i++) //look for a selected tank if there is one { if(tanks.at(i).selected == true && prevPlayerControlled != i) //control the tank (if multiple selected, control the last one selected) { playerControlled = i; //the tank being controlled shutDown(tanks.at(playerControlled)); //turn off the tank's AI } } prevPlayerControlled = -1; } break; case OIS::KC_C: //show/hide controls if(mTrayMgr->getTrayContainer(OgreBites::TL_CENTER)->isVisible() == false) { if(mTrayMgr->getTrayContainer(OgreBites::TL_TOPRIGHT)->isVisible() == false) { mTrayMgr->getTrayContainer(OgreBites::TL_TOPRIGHT)->show(); controlsWasOpen = true; } else { mTrayMgr->getTrayContainer(OgreBites::TL_TOPRIGHT)->hide(); controlsWasOpen = false; } } break; case OIS::KC_H: //show/hide hp bars //show/hide hp bars break; case OIS::KC_P: //print map to console for(int j=0;j<TOTAL_NODES;j++) { printf("%i,",pathFindingGraph->getContent(j)); if((j+1)% GRID_DIMENSION ==0 && j!=0) printf("\n"); } printf("\n"); printf("\n"); break; case OIS::KC_Q: //click to activate special bullet //2x damage or 2x splash radius break; case OIS::KC_R: //reset camera //lookAtDest=Ogre::Vector3(0,0,0); camNode->setPosition(Ogre::Vector3(0,10,-10)); //mCamera->setPosition(camNode->getPosition()); //mCamera->setOrientation(Ogre::Quaternion()); camNode->setOrientation(Ogre::Quaternion()); //camNode->lookAt(Ogre::Vector3(0,10,0),Ogre::Node::TS_PARENT,Ogre::Vector3::NEGATIVE_UNIT_Z); break; case OIS::KC_T: //show/hide tank information if(mTrayMgr->getTrayContainer(OgreBites::TL_CENTER)->isVisible() == false) { if(mTrayMgr->getTrayContainer(OgreBites::TL_TOPLEFT)->isVisible() == false) { mTrayMgr->getTrayContainer(OgreBites::TL_TOPLEFT)->show(); tankInfoWasOpen = true; } else { mTrayMgr->getTrayContainer(OgreBites::TL_TOPLEFT)->hide(); tankInfoWasOpen = false; } } break; case OIS::KC_W: //use powerup //use powerup break; case OIS::KC_SPACE: //hold to charge shooting power for (int i = 0; i < tanks.size(); i++) if (tanks.at(i).selected == true) if (isEnemyVisible(tanks.at(i)) == true) fight(tanks.at(i)); break; case OIS::KC_EQUALS: //spawn another tank if(TANK_LIMIT < 10 && mTrayMgr->getTrayContainer(OgreBites::TL_CENTER)->isVisible() == false) //hard limit of tanks allowed { TANK_LIMIT++; //increases the amount of tanks in the program createTank(namesAllocated); //create another tank respawnTank(namesAllocated - 1); //spawns the tank that was just created based on its team } break; case OIS::KC_MINUS: //destroy the last tank if (TANK_LIMIT>0) { destroyTank(TANK_LIMIT - 1); printf("After destroy \n"); TANK_LIMIT--; namesAllocated--; } /* TANK_LIMIT--; //decreases the amount of tanks in the program namesAllocated--; //frees up the name of the tank being deleted tanks.pop_back();//destroy tank */ break; case OIS::KC_TAB: //show/hide scoreboard if(mTrayMgr->getTrayContainer(OgreBites::TL_CENTER)->isVisible() == false) { updateScoreboard(); //update the scoreboard toggleOtherPanels(); mTrayMgr->getTrayContainer(OgreBites::TL_CENTER)->show(); } else { toggleOtherPanels(); mTrayMgr->getTrayContainer(OgreBites::TL_CENTER)->hide(); } break; case OIS::KC_BACK: //force tank respawn //kill the tank //edit score -1 //respawn tank break; /* case OIS::KC_LSHIFT: //hold for speed boost //give tank 2x speed //drain tank's nitros bar break;*/ case OIS::KC_RETURN: //open chatbox if(mTrayMgr->getTrayContainer(OgreBites::TL_CENTER)->isVisible() == false) { mTrayMgr->getTrayContainer(OgreBites::TL_BOTTOMLEFT)->show(); } break; case OIS::KC_ESCAPE: //exit program mShutDown = true; break; default: break; } } else //chat { if(arg.key == OIS::KC_RETURN) //close chat. { mTrayMgr->getTrayContainer(OgreBites::TL_BOTTOMLEFT)->hide(); chatWasOpen = false; } else { if(chatWasOpen == false) //start a new chat line { chatBox->appendText("\nPlayer: "); chatWasOpen = true; } char temp = getInputChar(arg); std::stringstream ss; std::string s; ss << temp; Ogre::DisplayString tempChar = ss.str();//std::to_string((temp)); //stores a char if(tempChar != "`"); //an invalid key was pressed chatBox->appendText(tempChar); //put the char pressed into the chatbox } } }
int manualControl(void) { int input; do { printf("\n"); input = getInputChar(); switch (input) { case 'w': moveUp(JUMP); break; case 'x': moveDown(JUMP); break; case 'd': moveRight(JUMP); break; case 'a': moveLeft(JUMP); break; case 'z': setZero(JUMP); break; case 'm': getMax(JUMP); break; case 'p': printf("Current position X:%d, Y:%d\n",posX,posY); break; case 'r': printf("Parsing input.nc\n"); readGCodeFile("input.nc"); break; case 'o': do { printf("Set offset to:\n"); printf("0) none (default)\n"); printf("1) A4\n"); input=getInputChar(); } while (input<'0'||input>'1'); if(input=='0') { setZero(JUMP); } else { setZero(JUMP); printf("Set offset to A4\n"); move2pos(47, 0, JUMP); posX = 0; posY = 0; printf("offset reached\n"); } break; break; case 'l': do { printf("Set laser output power to:\n"); printf("1) low\n"); printf("2) medium (default)\n"); printf("3) high\n"); printf("4) maximum\n"); input=getInputChar(); } while (input<'1'||input>'4'); if(input=='4') { laserPower=POW_MAX; printf("Setting laser to maximum output power\n"); } else if(input=='3') { laserPower=POW_HI; printf("Setting laser to high output power\n"); } else if(input=='2') { laserPower=POW_MED; printf("Setting laser to medium output power\n"); } else { laserPower=POW_LOW; printf("Setting laser to low output power\n"); } break; case 's': do { printf("Set speed to:\n"); printf("0) auto (default)\n"); printf("1) SNAIL\n"); printf("2) XSLOW\n"); printf("3) SLOW\n"); printf("4) MEDIUM\n"); printf("5) FAST\n"); input=getInputChar(); } while (input<'0'||input>'5'); if(input=='5') { autoSpeed=FALSE; manSpeed = FAST; printf("Setting speed to FAST\n"); } else if(input=='4') { autoSpeed=FALSE; manSpeed = MEDIUM; printf("Setting speed to MEDIUM\n"); } else if(input=='3') { autoSpeed=FALSE; manSpeed = SLOW; printf("Setting speed to SLOW\n"); } else if(input=='2') { autoSpeed=FALSE; manSpeed = XSLOW; printf("Setting speed to XSLOW\n"); } else if(input=='1') { autoSpeed=FALSE; manSpeed = SNAIL; printf("Setting speed to SNAIL\n"); } else { autoSpeed=TRUE; printf("Setting speed to auto\n"); } break; case 'b': initImageIn(); parseImage(); drawImage(); break; case 'q': exit(0); break; default: printf("available functions:\n"); printf("w move up\n"); printf("x move down\n"); printf("d move right\n"); printf("a move left\n"); printf("z move to pos 0/0 and reset step counter\n"); printf("m move to max position\n"); printf("l set power of laser\n"); printf("s set speed\n"); printf("o set offset\n"); printf("p print current position\n"); printf("r read and plot file\n"); printf("h show this help\n"); printf("q quit\n"); printf("b read bitmap\n"); printf("b set lines to skip\n");// todo break; } setLaser(POW_OFF); pfio_write_output(0x00); } while (input != 'q'); return OK; }