/* Checks to see if multiple commands are use (? symbol). Because this function calls the userInput function, a value is returned whether or not multiple commands were used. If multiple commands are used, the calling userInput function will not continue and will instead be processed here. Removing the check at userInput will run the last command twice. If multiple commands are not used, then the original userInput function will continue as normal. */ int nshMulti(char* input){ int i,pos; //Checks to see if ? is used outside of a complex string if(strchr(input,'?') == NULL || nshComplex(input,'?') == 1) //multiple commands were not found return 0; //Used to hold split input char* start; char* end; //splits input into 2 strings at the first ? start = strtok(input,"?"); end = strtok(NULL,"\0"); //process the first string userInput(start); //process the second string userInput(end); //multiple commands were found return 1; }
int main() { int grid[9][9]; char path; //Initialize variable count = 0; initialize(grid); //Accept user I/P for starting parameters of grid printf("Enter custom puzzle (Y/N): "); while(path = toupper(getche()), (path != 'Y') && (path != 'N')); if(path == 'Y') userInput(grid); else test(grid); printGrid(grid); if(SudokuTime(grid) == 1) { printGrid(grid); printf("\n\nSolved in %ld steps\n", count); } else { printGrid(grid); printf("Sorry try again %ld", count); } return 0; }
void ModelViewGadgetWidget::mousePressEvent(QMouseEvent *e) { GLC_UserInput userInput(e->x(), e->y()); if (m_MoverController.hasActiveMover()) { return; } switch (e->button()) { case (Qt::LeftButton): m_MotionTimer.stop(); m_MoverController.setActiveMover(GLC_MoverController::TurnTable, userInput); updateGL(); break; case (Qt::RightButton): printf("VBO enabled: %s, VBO supported: %s, VBO used: %s\n", vboEnable ? "yes" : "no", GLC_State::vboSupported() ? "yes" : "no", GLC_State::vboUsed() ? "yes" : "no"); printf("Renderer - %s \n", (char *)glGetString(GL_RENDERER)); printf("Extensions - %s\n", (char *)glGetString(GL_EXTENSIONS)); break; default: break; } }
UserNameBox::UserNameBox(Device* d, QWidget* parent) : QWidget(parent) { d_ = d; input_line_ = new UserNameInputBox(d, this); button_box_ = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(button_box_, SIGNAL(accepted()), input_line_, SLOT(userInput())); connect(button_box_, SIGNAL(rejected()), parent, SLOT(close())); connect(input_line_, SIGNAL(done()), parent, SLOT(close())); connect(input_line_, SIGNAL(done()), this, SLOT(createColorBox())); QLabel* screen_name_label = new QLabel(this); screen_name_label->setText(tr("Your name:")); QVBoxLayout* main_layout = new QVBoxLayout; main_layout->addWidget(screen_name_label); main_layout->addWidget(input_line_); main_layout->addWidget(button_box_); main_layout->setSizeConstraint(QLayout::SetFixedSize); setLayout(main_layout); input_line_->setFocus(Qt::PopupFocusReason); }
void userInput(int grid[9][9]) { int x, y, data; for(y = 0; y < 9; ++y) for(x = 0; x < 9; ++x) { grid[x][y] = data = 10;//10 is used to tell the print function to print an X, it also ensures that the following loop will also always be entered printGrid(grid);//Print the grid, including the current location marker while(!((data >= 0) && (data <= 9))) { //get and clean the user input, note it does not require the enter key to be hit (++Bonus) data = digitConverter(getch()); } grid[x][y] = data;//Assign the coveted user input into its most holy of resting places } if(validity(grid) == 0) { printf("Try again!%c\n", 0x7); initialize(grid); userInput(grid); } return; }
void FlameDecider::train(const map<int, Target>& targets) { if (!mSampleEnough) { if (mFrameCount++ % FRAME_GAP == 0) { userInput(targets); } } else { svmStudy(); trainComplete = true; } }
void ModelViewGadgetWidget::mouseMoveEvent(QMouseEvent *e) { GLC_UserInput userInput(e->x(), e->y()); if (not m_MoverController.hasActiveMover()) { return; } m_MoverController.move(userInput); m_GlView.setDistMinAndMax(m_World.boundingBox()); updateGL(); }
//handles all user input userInput(){ //Clear input fields command = NULL; memset(&input,'\0',sizeof(input)); memset(&first,'\0',sizeof(first)); memset(&second,'\0',sizeof(second)); memset(&third,'\0',sizeof(third)); //Take input from user printf("nsh3_WesJos$ "); fgets(input,80,stdin); commentfilter(input);//removes the text after a comment but not inside a complex string from a command. //Split the input the user provides splitInput(input); //Make sure command or alias exists if ((nshFind(alias,first) == NULL) && (nshFind(native,first) == NULL)) { printf("\tCommand not found.\n"); userInput(); } else { //Checks if alias or native command passed fail test if (nshFind(alias,first) == NULL) command = nshFind(native,first); else { command = nshFind(alias,first); handleAlias(command->value); } //Check command if ((strcmp(command->value,"set")==0) || (strcmp(first,"set") == 0)) commandSet(&var,second,third); if ((strcmp(command->value,"alias")==0) || (strcmp(first,"alias") == 0)) commandSet(&alias,second,third); if ((strcmp(command->value,"tes") == 0) || (strcmp(first,"tes") == 0)) nshDelete(&var,second); if ((strcmp(command->value,"saila") == 0) || (strcmp(first,"saila") == 0)) nshDelete(&alias,second); if ((strcmp(command->value,"exit") == 0) || (strcmp(first,"exit") == 0)) cont = 0; } }
int main(int argc, char *argv[]) { std::cout << "Initializing Effect Master 3000..." << std::endl; signal(SIGINT, SignalHandler); EffectManager *mgr = EffectManager::getInstance(); Environment *env = mgr->getEnvironment(); env->loadConfig("effectmaster.conf"); if (!createWindow("Effect Master 3000", env->getScreenWidth(), env->getScreenHeight(), env->isFullscreen()) || !initOpenGL(env->getScreenWidth(), env->getScreenHeight())) { std::cout << "Error creating window!" << std::endl; exit(1); } GLenum err = glewInit(); if (GLEW_OK != err) {/* Problem: glewInit failed, something is seriously wrong. */ std::cout << "Error initializing GLEW: " << glewGetErrorString(err) << std::endl; exit(1); } int fps = env->getFps(); int msPerFrame = 1000/fps; int passedMS = msPerFrame; unsigned int frameStart = 0; int rest = 0; std::cout << "Initialization done!" << std::endl; mgr->init(); while(!done) { passedMS = SDL_GetTicks() - frameStart; frameStart = SDL_GetTicks(); mgr->animate(passedMS); mgr->draw(); SDL_GL_SwapBuffers(); userInput(); rest = msPerFrame - (SDL_GetTicks() - frameStart); if (rest < 0 ) rest = 0; SDL_Delay(rest); } std::cout << "Shutting down Effect Master 3000..." << std::endl; delete env; delete mgr; return 0; }
void KeyboardInput::operator()() { while (userInput.compare("quit")!=0){ const short bufsize = 1024; char buf[bufsize]; std::cin.getline(buf, bufsize); std::string userInput(buf); if(userInput.compare("QUIT")==0) _connectionHandler.close(); if (!_connectionHandler.sendLine(userInput)) { std::cout << "Disconnected. Exiting...\n" << std::endl; break; } } }
/** * * GPIO task that you create * * Parameters: * * @return void */ void gpio_run( void *pvParameters ) { const TickType_t xDelay = 500 / portTICK_PERIOD_MS; int user_input = userInput(); printf("Counting to: %d\n", user_input); int i; for(i=0; i<=user_input;i++) { *gpio_data_ptr = i; vTaskDelay(xDelay); } }
int main(int argc, char *argv[]) { char board[41][41] = {{'\0', '\0'}}; char tempBoard[41][41] = {{'\0', '\0'}}; if(argc == 1) { // if no other file in command line blankBoard(board, tempBoard); printBoard(board); while(userInput(board, tempBoard)); } else { // if file in command line fileInput(argv[1], board, tempBoard); } return 0; }
void EventHandler::customEvent(QEvent *e) { // Forward the event to the next in the chain forwardEvent(e); MClientEvent* me = static_cast<MClientEvent*>(e); if (me->dataTypes().contains("DisplayData") || me->dataTypes().contains("DisplayPrompt")) { emit displayData(me->payload()->toString()); } else if (me->dataTypes().contains("UserInput")) { emit userInput(me->payload()->toString()); } else if (me->dataTypes().contains("DoneLoading")) { emit displayData(QString("Type \033[1m#help\033[0m for help.\r\n")); } }
main() { //fill alias list for display nshInsert(&alias,"set","set"); nshInsert(&alias,"alias","alias"); nshInsert(&alias,"tes","tes"); nshInsert(&alias,"exit","exit"); nshInsert(&alias,"saila","saila"); //Create native commands setNative(); //Arguably an uneeded loop, but it keeps the program running. while(cont) { userInput(); } }
void mainMenu(Tree tree){ system("clear"); printf(" PROBLEM 2: AVL Trees\n\n"); printf(" MAIN MENU\n"); printf(" i XXX --- Insert value XXX into the data structre\n"); printf(" d XXX --- Delete value XXX from the data structure\n"); printf(" f XXX --- Find value XXX in the data stricture\n"); printf(" v --- Visualize the data structure using graphviz\n"); printf(" V --- Verify the correctness of the data structure\n"); printf(" b XXX --- Inject a fault of type XXX into the data structre\n"); printf(" p XXX --- Populate the tree with a set of integers from file XXX\n"); printf(" g XXX --- Generate XXX unique random numbers and populate the tree\n"); printf(" s --- Print statistics concerning the current state of the data structure\n"); printf(" l XXX --- List the elements in the data structe; XXX should specify the traversal\n"); printf(" c --- Clean up the screen\n"); printf(" e --- EXIT INTERPRETER\n"); while (1009) { userInput(tree); } }
int game() { int target[MAX]; char guess[MAX]; int red = 0, count =0,white=0; for (int i = 0; i < FOUR; i++) { target[i] = rand() % 10; } printf("\n"); while(red != FOUR) { userInput(guess); red = compare(red, white,target,guess); count +=1; } printf("You've won in %d guesses.\n",count); printf("Would you like to play again?\n"); return(0); }
void Game::play() { if (menu->GetMenuState()) { gameMenu(win); } else if (menu->GetSubMenuState()) { gameSubMenu(win); } else if (levelMenu) { intermission(win); } else { draw(); userInput(); update(); win->display(); } return; }
void Logic::gameRun() { gameInit(); printResult(); while(1) { setMoveDirection(userInput()); checkFinish(); if(bFinished || bWin) break; if(bChanged) generateRandom(); else cout<<"invalid move!"<<endl; bChanged = false; printResult(); } printResult(); goodGame(); }
int main(int argc, const char * argv[]) { unsigned int num_voters = 0, num_A = 0, num_B = 0; double spread = 0.0, error = 0.0; // handle user input userInput(num_voters, spread, error); splitVotes(num_A, num_B, spread, num_voters); std::cout << num_A << " " << num_B << std::endl; // conduct 500 trials int invalid_count = 0; for (int i = 0; i < 500; ++i) { if (!(isVotingValid(num_A, num_B, error))) { ++invalid_count; } } double err_chance = double(invalid_count / 5.0); std::cout << "Chance of an invalid election result after 500 trials = " << err_chance << std::endl; return 0; }
void SceneMenu::UpdateMenu() { if (Input == "Menu") { switch (choose) { case MenuShop::STARTGAME: color = "Red1"; menuIcon = 116; if (Application::IsKeyPressed(VK_RETURN)) { SharedData::GetInstance()->stateCheck = true; SharedData::GetInstance()->gameState = SharedData::GAME; } userInput(0); break; case MenuShop::OPTIONS: color = "Red2"; if (Application::IsKeyPressed(VK_RETURN)) { menuIcon = 105; Input = "Options"; c_option = MenuShop::O_SETTING; } userInput(0); break; case MenuShop::QUIT: color = "Red3"; if (Application::IsKeyPressed(VK_RETURN)) { SharedData::GetInstance()->gameState = SharedData::QUIT; } userInput(0); break; } } if (Input == "Options") { switch (c_option) { case MenuShop::O_SETTING: color = "Red4"; userInput(1); break; case MenuShop::O_QUIT: color = "Red5"; if (Application::IsKeyPressed(VK_RETURN)) { Input = "Menu"; choose = MenuShop::STARTGAME; while (Application::IsKeyPressed(VK_RETURN)) { Input = "Menu"; choose = menushop.STARTGAME; } } userInput(1); break; } } }
//display storyline string Opening::display() { //Loading success flag bool success = true; bool next = false; int textXpos = ((1*SCREEN_WIDTH)/7)-10; int textYpos = ((8*SCREEN_HEIGHT)/11)-8; SDL_Color textColor = { 0, 0, 0, 0xFF }; gTextTexture.setFont(gFont); SDL_Event e; SDL_RenderClear( gRenderer ); // Render Background if( !gTextTexture.loadFromRenderedTextWrapped( "Before the game starts, what is your gender? Male or Female?", textColor, 450 ) ) { printf( "Failed to render text texture!\n" ); } SDL_RenderClear( gRenderer ); while (!next && !(*quit)) { gBackgroundTexture.render(0,0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL); gTextTexture.render( textXpos, textYpos ); //Update screen SDL_RenderPresent( gRenderer ); next=continueText(e); } next = false; string gender = "N/A"; while (gender=="N/A" && !(*quit)) { gender = userInput(); //get the gender } for ( int j=0; j<gender.length(); j++ ) { gender[j] = ::toupper(gender[j]); //make the answer lower-case } if( !gTextTexture.loadFromRenderedTextWrapped( "Good morning! Today's the day for your picnic with your best friend, who also happens to be the ruler of the kingdom! You want to pack lunch for the two of you, but when you go check your fridge you don't have any food for the picnic.", textColor, 470 ) ) { printf( "Failed to render text texture!\n" ); } SDL_RenderClear( gRenderer ); while (!next && !(*quit)) { gBackgroundTexture.render(0,0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL); gTextTexture.render( textXpos, textYpos ); //Update screen SDL_RenderPresent( gRenderer ); next=continueText(e); } next = false; if( !gTextTexture.loadFromRenderedTextWrapped( "You should try going outside to see if there's any ingredients that you might be able to find along the way to the palace!", textColor, 470 ) ) { printf( "Failed to render text texture!\n" ); } SDL_RenderClear( gRenderer ); while (!next && !(*quit)) { gBackgroundTexture.render(0,0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL); gTextTexture.render( textXpos, textYpos ); //Update screen SDL_RenderPresent( gRenderer ); next=continueText(e); } next = false; return gender; }
void DarkSDK ( void ) { // entry point for the application //dbSetDir ( "media\\" ); // initial application set up dbSyncOn ( ); // turn sync on dbSyncRate ( 0 ); // set sync rate to 60 dbBackdropOn ( ); // switch backdrop off - no need to clear screen dbSetCameraRange ( 0.5f, 30000 ); // set the camera range PhysStart ( ); // floor dbMakeObjectBox ( 1, 100, 1, 100 ); dbPositionObject ( 1, 0, 0, 0 ); dbColorObject ( 1, dbRgb ( 100, 0, 0 ) ); PhysCreateStaticRigidBodyMesh ( 1 ); /* dbLoadObject ( "bin1.x", 2 ); //dbPositionObject ( 2, 0, 1 + dbObjectCollisionCenterY ( 2 ), 0 ); dbPositionObject ( 2, 0, 0, 0 ); //dbOffsetLimb ( 2, 0, dbObjectCollisionCenterX ( 2 ) * -1, dbObjectCollisionCenterY ( 2 ) * -1, dbObjectCollisionCenterZ ( 2 ) * -1 ); PhysCreateRigidBodyBox ( 2 ); dbMakeObjectCube ( 3, 5 ); dbPositionObject ( 3, 20, 10, 0 ); PhysCreateRigidBodyBox ( 3 ); */ const NxReal height = 0.3; const NxReal width = 2; const NxReal length = 4; //dbMakeObjectBox ( 5, length*0.65, height*0.85, width*0.65 ); dbMakeObjectBox ( 5, 3.5,3,4); dbPositionObject ( 5, 3.5,4,0 ); dbMakeObjectSphere ( 10, 0.8 ); dbMakeObjectSphere ( 11, 0.8 ); dbMakeObjectSphere ( 12, 0.8 ); dbMakeObjectSphere ( 13, 0.8 ); CreateTruck ( ); //dbLoadObject ( "corsa.x", 5 ); //dbPositionObject ( 5, 0, 1, 0 ); /* InitCar ( ); car = CreateCar(NxVec3(0,5,0)); */ dbPositionCamera ( 0, 20, -30 ); // PhysCreateRigidBodyBox ( 10 ); // loop round until escape key is pressed while ( LoopSDK ( ) ) { if ( dbEscapeKey ( ) ) return; if ( dbSpaceKey ( ) ) PhysSetVelocity ( 10, 0, 20, 0 ); UpdateTruck ( ); //if ( dbSpaceKey ( ) ) // PhysSetVelocity ( 3, -20, 0, 0 ); /* { bool bKey = false; if ( dbKeyState ( 17 ) == 1 ) { gMotorForce = gMaxMotorPower; bKey = true; } if ( dbKeyState ( 31 ) == 1 ) { gMotorForce = -gMaxMotorPower; bKey = true; } if ( dbKeyState ( 32 ) ) { if (gSteeringValue > (-1.0f + gSteeringDelta)) gSteeringValue -= gSteeringDelta; bKey = true; } if ( dbKeyState ( 30 ) ) { if (gSteeringValue < (1.0f - gSteeringDelta)) gSteeringValue += gSteeringDelta; bKey = true; } if ( !bKey ) { gMotorForce = 0.0f; gSteeringValue = 0.0f; } } TickCar ( ); */ // show the frame rate and handle user input showFPS ( ); userInput ( ); PhysRun ( ); PhysUpdate ( ); // render everything dbSync ( ); } }
/*MAIN*/ int main() { struct mossa *testa; /*Puntator to list's head*/ struct mossa *nuova; /*Puntator to list's tail*/ struct mossa *nuova_da_ordinare; /*Puntator to new move BEFORE is sorted*/ struct mossa *testa_da_ordinare; /*Puntator to tail's head to be sorted*/ struct mossa *temp; /*Puntator to temporary structure*/ struct mossa *puntatore_ad_array_struct; /*Puntator to structure's array*/ testa=NULL;/*Initializing head to NULL*/ testa_da_ordinare=NULL;/*Initializing head to be sorted to NULL*/ char name1[31], name2[31], *name, rigioca, deb[51]; char r4[201]=MENU; int i, controlli, sottoScacco=0, partita=1, player=0, numero_celle, contatore3=0; time_t prima_della_mossa=0; pedina pedine[33]; pedina *board[8][8], *testBoard[8][8], *toTest; posizione pos1, pos2; presentazione(); name=name1; daCapo(pedine, board, name1, name2, name, &numero_celle); /*----------*/ do { i=0, controlli=0; while (controlli==0) { printf("\n%s\n", r4); switch (userInput()) { case 'n': clear(); daCapo(pedine, board, name1, name2, name, &numero_celle); showBoard(board); player=0; continue; case 'q': uscita(); showBoard(board); continue; case 'h': help(); showBoard(board); continue; #ifndef _WIN32 case 'x': save(pedine, board, name1, name2, player, numero_celle, testa); continue; case 'c': testa = load(pedine, board, name1, name2, name, &player, &numero_celle); debug("Initializing head's test"); temp=testa; while(temp != NULL) { sprintf(deb, "player: %s\n", (temp->player==0)?name1:name2); debug(deb); sprintf(deb, "move: %s\n", temp->coordinate); debug(deb); sprintf(deb, "duration: %.2lf secs\n", temp->durata_mossa); debug(deb); temp=temp->next; contatore3++; } debug("End head's test"); continue; #endif case 's': stallo(); showBoard(board); continue; } showBoard(board); if(prima_della_mossa==0) { time(&prima_della_mossa); } if (getCoordinate(board, &pos1, &pos2, name, player) && pos1.loc->player==player && checkMove(pedine, board, &pos1, &pos2, player, 0)) { numero_celle=conteggio_celle(numero_celle); testa=newtime(player, testa, nuova, &pos1, &pos2, prima_della_mossa, numero_celle, name1, name2); prima_della_mossa=0; controlli = 1; } else { printf("\nWrong coordinates, re-enter\n"); } } toTest = (player==0)? pedine+27 : pedine+3; //Re avversario if (scacco(toTest->l, toTest->n, player, board, pedine, player)) {sottoScacco=1; printf("\nScacco al RE\n"); } if (sottoScacco) { debug("UNDER CHECK"); if(roundRe(toTest->l, toTest->n, player, board, pedine, player)) { debug("maybe mate??\n"); if(checkMatto(toTest->l, toTest->n, board, pedine, player)) { clear(); printf("\nCheck mate!!!!!\n"); rigioca=vittoria(player,name1,name2,testa,puntatore_ad_array_struct,numero_celle); if(rigioca=='y') { clear(); daCapo(pedine, board, name1, name2, name, &numero_celle); showBoard(board); player=0; continue; } else { printf("\nThank for playing! Have a nice day."); getch(); exit(0); } } else {debug("not mate..");} } } sprintf(deb, "%c --> moved=%d", pos1.loc->tipo, pos1.loc->moved); debug(deb); sprintf(deb, "%c (%d,%d) in %c (%d,%d)", pos1.loc->tipo, pos1.l+1, pos1.n+1, (*board[pos2.n][pos2.l]).tipo, pos2.l+1, pos2.n+1); debug(deb); sottoScacco=0; clear(); nexTurn(&player); name=(player==0)?name1:name2; } while(partita != 0); return 0; }
const JCharacter* JFSBindingList::Revert() { const JCharacter* userMsg = ""; // toss everything itsBindingList->CleanOut(); itsOverriddenList->CleanOut(); delete itsUserDefault; itsUserDefault = NULL; delete itsSystemDefault; itsSystemDefault = NULL; // read system bindings ifstream sysInput(kGlobalBindingsFile); if (sysInput.good()) { Load(sysInput, kJTrue); } sysInput.close(); // read user bindings JPrefsFile* file = NULL; if (!itsSignalFileName.IsEmpty() && (JPrefsFile::Create(kUserExtensionBindingRoot, &file, JFileArray::kDeleteIfWaitTimeout)).OK()) { if (file->IsEmpty()) { JString origUserFile; if (JExpandHomeDirShortcut(kOrigUserExtensionBindingFile, &origUserFile) && JFileReadable(origUserFile)) { ifstream userInput(origUserFile); if (userInput.good()) { Load(userInput, kJFalse); userMsg = JGetString("UpgradeFromVersion1::JFSBindingList"); } } } else { for (JFileVersion vers = kCurrentBindingVersion; kJTrue; vers--) { if (file->IDValid(vers)) { std::string data; file->GetData(vers, &data); std::istringstream input(data); Load(input, kJFalse); break; } if (vers == 0) { break; // check *before* decrement since unsigned } } } delete file; } if (IsEmpty()) // nothing loaded { #ifdef _J_OSX const JCharacter* data = JGetString("DefaultBindingList-OSX::JFSBindingList"); #else const JCharacter* data = JGetString("DefaultBindingList::JFSBindingList"); #endif const std::string s(data, strlen(data)); std::istringstream input(s); Load(input, kJFalse); } if (!itsSignalFileName.IsEmpty()) { JGetModificationTime(itsSignalFileName, &itsSignalModTime); } // ensure that GetDefaultCommand() will work if (itsUserDefault == NULL && itsSystemDefault == NULL) { SetDefaultCommand(kDefaultCmd, kDefaultCmdType, kDefaultSingleFile); } return userMsg; }
int CNFSMountGui::menuEntry(int nr) { char *dir, *local_dir, *username, *password, *options1, *options2, *mac; int *automount; int *type; char cmd[9]; char cmd2[9]; dir = g_settings.network_nfs_dir[nr]; local_dir = g_settings.network_nfs_local_dir[nr]; username = g_settings.network_nfs_username[nr]; password = g_settings.network_nfs_password[nr]; automount = &g_settings.network_nfs_automount[nr]; type = &g_settings.network_nfs_type[nr]; options1 = g_settings.network_nfs_mount_options1[nr]; options2 = g_settings.network_nfs_mount_options2[nr]; mac = g_settings.network_nfs_mac[nr]; sprintf(cmd, "domount%d", nr); sprintf(cmd2, "dir%d", nr); /* rewrite fstype in new entries */ if(strlen(local_dir) == 0) { if(m_cifs_sup != CFSMounter::FS_UNSUPPORTED && m_nfs_sup == CFSMounter::FS_UNSUPPORTED && m_lufs_sup == CFSMounter::FS_UNSUPPORTED && m_smbfs_sup == CFSMounter::FS_UNSUPPORTED) *type = (int) CFSMounter::CIFS; else if(m_lufs_sup != CFSMounter::FS_UNSUPPORTED && m_cifs_sup == CFSMounter::FS_UNSUPPORTED && m_nfs_sup == CFSMounter::FS_UNSUPPORTED && m_smbfs_sup == CFSMounter::FS_UNSUPPORTED) *type = (int) CFSMounter::LUFS; else if(m_smbfs_sup != CFSMounter::FS_UNSUPPORTED && m_cifs_sup == CFSMounter::FS_UNSUPPORTED && m_nfs_sup == CFSMounter::FS_UNSUPPORTED && m_lufs_sup == CFSMounter::FS_UNSUPPORTED) *type = (int) CFSMounter::SMBFS; } bool typeEnabled = (m_cifs_sup != CFSMounter::FS_UNSUPPORTED && m_nfs_sup != CFSMounter::FS_UNSUPPORTED && m_lufs_sup != CFSMounter::FS_UNSUPPORTED && m_smbfs_sup != CFSMounter::FS_UNSUPPORTED) || (m_cifs_sup != CFSMounter::FS_UNSUPPORTED && *type != (int)CFSMounter::CIFS) || (m_nfs_sup != CFSMounter::FS_UNSUPPORTED && *type != (int)CFSMounter::NFS) || (m_lufs_sup != CFSMounter::FS_UNSUPPORTED && *type != (int)CFSMounter::LUFS) || (m_smbfs_sup != CFSMounter::FS_UNSUPPORTED && *type != (int)CFSMounter::SMBFS); CMenuWidget mountMenuEntryW(LOCALE_NFS_MOUNT, NEUTRINO_ICON_NETWORK); mountMenuEntryW.disableMenuPosition(); // intros mountMenuEntryW.addItem(new CMenuForwarder(LOCALE_MENU_BACK, true, NULL, NULL, NULL, CRCInput::RC_nokey, NEUTRINO_ICON_BUTTON_LEFT)); mountMenuEntryW.addItem(new CMenuSeparator(CMenuSeparator::LINE)); // ip CIPInput ipInput(LOCALE_NFS_IP, g_settings.network_nfs_ip[nr], LOCALE_IPSETUP_HINT_1, LOCALE_IPSETUP_HINT_2); // dir CStringInputSMS dirInput(LOCALE_NFS_DIR, dir); // automount CMenuOptionChooser *automountInput= new CMenuOptionChooser(LOCALE_NFS_AUTOMOUNT, automount, MESSAGEBOX_NO_YES_OPTIONS, MESSAGEBOX_NO_YES_OPTION_COUNT, true); // option1 CStringInputSMS options1Input(LOCALE_NFS_MOUNT_OPTIONS, options1); CMenuForwarder *options1_fwd = new CMenuForwarder(LOCALE_NFS_MOUNT_OPTIONS, true, options1, &options1Input); // option2 CStringInputSMS options2Input(LOCALE_NFS_MOUNT_OPTIONS, options2); CMenuForwarder *options2_fwd = new CMenuForwarder(LOCALE_NFS_MOUNT_OPTIONS, true, options2, &options2Input); // username CStringInputSMS userInput(LOCALE_NFS_USERNAME, username); CMenuForwarder *username_fwd = new CMenuForwarder(LOCALE_NFS_USERNAME, (*type==CFSMounter::CIFS || CFSMounter::LUFS), username, &userInput); // password CStringInputSMS passInput(LOCALE_NFS_PASSWORD, password); CMenuForwarder *password_fwd = new CMenuForwarder(LOCALE_NFS_PASSWORD, (*type==CFSMounter::CIFS || CFSMounter::LUFS), NULL, &passInput); // mac CMACInput * macInput = new CMACInput(LOCALE_RECORDINGMENU_SERVER_MAC, g_settings.network_nfs_mac[nr], LOCALE_IPSETUP_HINT_1, LOCALE_IPSETUP_HINT_2); CMenuForwarder * macInput_fwd = new CMenuForwarder(LOCALE_RECORDINGMENU_SERVER_MAC, true, g_settings.network_nfs_mac[nr], macInput); CNFSMountGuiNotifier notifier(username_fwd, password_fwd, type); mountMenuEntryW.addItem(new CMenuOptionChooser(LOCALE_NFS_TYPE, type, NFS_TYPE_OPTIONS, NFS_TYPE_OPTION_COUNT, typeEnabled, ¬ifier)); mountMenuEntryW.addItem(new CMenuForwarder(LOCALE_NFS_IP, true, g_settings.network_nfs_ip[nr], &ipInput)); mountMenuEntryW.addItem(new CMenuForwarder(LOCALE_NFS_DIR, true, dir, &dirInput)); mountMenuEntryW.addItem(new CMenuForwarder(LOCALE_NFS_LOCALDIR, true, local_dir, this , cmd2)); mountMenuEntryW.addItem(automountInput); mountMenuEntryW.addItem(options1_fwd); mountMenuEntryW.addItem(options2_fwd); mountMenuEntryW.addItem(username_fwd); mountMenuEntryW.addItem(password_fwd); mountMenuEntryW.addItem(macInput_fwd); mountMenuEntryW.addItem(new CMenuForwarder(LOCALE_NFS_MOUNTNOW, true, NULL, this, cmd )); int ret = mountMenuEntryW.exec(this, ""); return ret; }
bool MainMenu(MultiSet * currentSet, int currentMode){ int menuDecision; //The decision that the user uses string tempString1 = ""; string tempString2; int tempInt = -1; //Temp variables used for input/output if(currentMode == 0){ // Normal Mode cout << ">"; } else if (currentMode == 1){ //Verbose Mode cout << "0. Exit\n1. Input File\n2. Union File\n3. Subtract File\n4. Difference File\n5. Intersect File\n6. Rest Current Multiset\n7. Output to File\n8. Print Current Set\n9. Find Item\n10. Insert Item\n11. Delete Item\n12. Reduce Item\n13. Verbose Output\n14. Normal Output\n15. Silent Output\n16. Help\n\n17. Maximum\n18. Toggle Autocorrect\n>"; } if(!userInput(menuDecision, tempString1, tempInt, 0)){ return true; } switch(menuDecision){ case 0: if(currentMode != 2){ cout << "\n\nThanks for using me!" << endl; } return false; break; case 1: if(tempString1 == ""){ if(currentMode != 2) cout << "\nPlease enter the input filename: "; while (!userInput(menuDecision, tempString1, tempInt, 2)) { } } currentSet->inputMultiSet(tempString1); break; case 2: if(tempString1 == ""){ if(currentMode != 2) cout << "\nPlease enter the filename to union: "; while (!userInput(menuDecision, tempString1, tempInt, 2)) { } } currentSet->unionMultiSet(tempString1); break; case 3: if(currentSet->GetSize() == 0){ if(currentMode != 2) cout << "\nHey! The multiset is currently empty!" << endl; break; } if(tempString1 == ""){ if(currentMode != 2) cout << "\nPlease enter the filename to subtract: "; while (!userInput(menuDecision, tempString1, tempInt, 2)) { } } currentSet->subtractMultiSet(tempString1); break; case 4: if(tempString1 == ""){ if(currentMode != 2) cout << "\nPlease enter the filename to difference: "; while (!userInput(menuDecision, tempString1, tempInt, 2)) { } } currentSet->differenceMultiSet(tempString1); break; case 5: if(currentSet->GetSize() == 0){ if(currentMode != 2) cout << "\nHey! The multiset is currently empty!" << endl; break; } if(tempString1 == ""){ if(currentMode != 2) cout << "\nPlease enter the filename to intersect: "; while (!userInput(menuDecision, tempString1, tempInt, 2)) { } } currentSet->intersectMultiset(tempString1); break; case 6: if(currentMode != 2) cout << "\n"; currentSet->resetMultiSet(); break; case 7: if(currentSet->GetSize() == 0){ if(currentMode != 2) cout << "\nHey! The multiset is currently empty!" << endl; break; } if(tempString1 == ""){ if(currentMode != 2) cout << "\nPlease enter the output filename: "; while (!userInput(menuDecision, tempString1, tempInt, 2)) { } } currentSet->outputMultiSet(tempString1); break; case 8: if(currentSet->GetSize() == 0){ if(currentMode != 2) cout << "\nHey! The multiset is currently empty!" << endl; break; } if(currentMode != 2) cout << "\n"; currentSet->printMultiSet(); break; case 9: if(currentSet->GetSize() == 0){ if(currentMode != 2) cout << "\nHey! The multiset is currently empty!" << endl; break; } if(tempString1 == ""){ if(currentMode != 2) cout << "\nPlease enter the item name: "; while (!userInput(menuDecision, tempString1, tempInt, 2)) { } } tempInt = currentSet->findMultiSet(tempString1).numberFound; if((tempInt = currentSet->findMultiSet(tempString1).numberFound) > 0){ if(currentSet->GetAutoCorrectMode() || currentSet->findMultiSet(tempString1).truncationsUsed == 0){ cout << "Item " << tempString1.substr(0,tempString1.size() - currentSet->findMultiSet(tempString1).truncationsUsed) << " found with count " << tempInt << endl; } else{ cout << "Item " << tempString1 << " not found. Did you mean \"" << currentSet->findMultiSet(tempString1).stringGuess << "\"?" << endl; } } else{ cout << "Item " << tempString1 << " not found" << endl; } break; case 10: if(tempString1 == ""){ if(currentMode != 2) cout << "\nPlease enter the item name and the number of the item you wish to add: "; while (!userInput(menuDecision, tempString1, tempInt, 3)) { } if(tempInt == -1){ cout << "\nPlease enter the number of " << tempString1 << " that you would like to add: "; while (!userInput(menuDecision, tempString1, tempInt, 1)) { } } } currentSet->insertMultiSet(tempString1, tempInt); break; case 11: if(currentSet->GetSize() == 0){ if(currentMode != 2) cout << "\nHey! The multiset is currently empty!" << endl; break; } if(tempString1 == ""){ if(currentMode != 2) cout << "\nPlease enter the item name: "; while (!userInput(menuDecision, tempString1, tempInt, 2)) { } } currentSet->deleteMultiSet(tempString1); break; case 12: if(currentSet->GetSize() == 0){ if(currentMode != 2) cout << "\nHey! The multiset is currently empty!" << endl; break; } if(tempString1 == ""){ if(currentMode != 2) cout << "\nPlease enter the item name and the number of the item you wish to reduce: "; while (!userInput(menuDecision, tempString1, tempInt, 3)) { } if(tempInt == -1){ cout << "\nPlease enter the number of " << tempString1 << " that you would like to reduce: "; while (!userInput(menuDecision, tempString1, tempInt, 1)) { } } } currentSet->reduceMultiSet(tempString1, tempInt); break; case 13: cout << "\nSwitched to Verbose Output!" << endl; currentMode = 1; currentSet->SetOutputMode(1); break; case 14: cout << "\nNormal Mode" << endl; currentMode = 0; currentSet->SetOutputMode(0); break; case 15: currentMode = 2; currentSet->SetOutputMode(2); break; case 16: currentSet->displayHelp(); break; case 17: if(tempString1 == ""){ if(currentMode != 2) cout << "\nPlease enter the filename: "; while (!userInput(menuDecision, tempString1, tempInt, 1)) { } } currentSet->maxMultiSet(tempString1); break; case 18: currentSet->toggleAutoCorrectMode(); break; default: cerr << "Error! Something went wrong; we're not supposed to be here..."; break; } return true; }
int CNFSMountGui::menuEntry(int nr) { char *dir,*local_dir, *username, *password, *options1, *options2, *mac; int* automount; int* type; char cmd[9]; char cmd2[9]; dir = g_settings.network_nfs_dir[nr]; local_dir = g_settings.network_nfs_local_dir[nr]; username = g_settings.network_nfs_username[nr]; password = g_settings.network_nfs_password[nr]; automount = &g_settings.network_nfs_automount[nr]; type = &g_settings.network_nfs_type[nr]; options1 = g_settings.network_nfs_mount_options1[nr]; options2 = g_settings.network_nfs_mount_options2[nr]; mac = g_settings.network_nfs_mac[nr]; sprintf(cmd,"domount%d",nr); sprintf(cmd2,"dir%d",nr); /* rewrite fstype in new entries */ if(strlen(local_dir)==0) { if(m_cifs_sup != CFSMounter::FS_UNSUPPORTED && m_nfs_sup == CFSMounter::FS_UNSUPPORTED && m_lufs_sup == CFSMounter::FS_UNSUPPORTED && m_smbfs_sup == CFSMounter::FS_UNSUPPORTED) *type = (int) CFSMounter::CIFS; else if(m_lufs_sup != CFSMounter::FS_UNSUPPORTED && m_cifs_sup == CFSMounter::FS_UNSUPPORTED && m_nfs_sup == CFSMounter::FS_UNSUPPORTED && m_smbfs_sup == CFSMounter::FS_UNSUPPORTED) *type = (int) CFSMounter::LUFS; else if(m_smbfs_sup != CFSMounter::FS_UNSUPPORTED && m_cifs_sup == CFSMounter::FS_UNSUPPORTED && m_nfs_sup == CFSMounter::FS_UNSUPPORTED && m_lufs_sup == CFSMounter::FS_UNSUPPORTED) *type = (int) CFSMounter::SMBFS; } bool typeEnabled = (m_cifs_sup != CFSMounter::FS_UNSUPPORTED && m_nfs_sup != CFSMounter::FS_UNSUPPORTED && m_lufs_sup != CFSMounter::FS_UNSUPPORTED && m_smbfs_sup != CFSMounter::FS_UNSUPPORTED) || (m_cifs_sup != CFSMounter::FS_UNSUPPORTED && *type != (int)CFSMounter::CIFS) || (m_nfs_sup != CFSMounter::FS_UNSUPPORTED && *type != (int)CFSMounter::NFS) || (m_lufs_sup != CFSMounter::FS_UNSUPPORTED && *type != (int)CFSMounter::LUFS) || (m_smbfs_sup != CFSMounter::FS_UNSUPPORTED && *type != (int)CFSMounter::SMBFS); CMenuWidget mountMenuEntryW(LOCALE_NFS_MOUNT, NEUTRINO_ICON_STREAMING,720); mountMenuEntryW.addIntroItems(); CIPInput ipInput(LOCALE_NFS_IP, g_settings.network_nfs_ip[nr], LOCALE_IPSETUP_HINT_1, LOCALE_IPSETUP_HINT_2); CStringInputSMS dirInput(LOCALE_NFS_DIR, dir, 30, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE,"abcdefghijklmnopqrstuvwxyz0123456789-_.,:|!?/ "); CMenuOptionChooser *automountInput= new CMenuOptionChooser(LOCALE_NFS_AUTOMOUNT, automount, MESSAGEBOX_NO_YES_OPTIONS, MESSAGEBOX_NO_YES_OPTION_COUNT, true); CStringInputSMS options1Input(LOCALE_NFS_MOUNT_OPTIONS, options1, 30, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, "abcdefghijklmnopqrstuvwxyz0123456789-_=.,:|!?/ "); CMenuForwarder *options1_fwd = new CMenuForwarder(LOCALE_NFS_MOUNT_OPTIONS, true, options1, &options1Input); CStringInputSMS options2Input(LOCALE_NFS_MOUNT_OPTIONS, options2, 30, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, "abcdefghijklmnopqrstuvwxyz0123456789-_=.,:|!?/ "); CMenuForwarder *options2_fwd = new CMenuForwarder(LOCALE_NFS_MOUNT_OPTIONS, true, options2, &options2Input); CStringInputSMS userInput(LOCALE_NFS_USERNAME, username, 30, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, "abcdefghijklmnopqrstuvwxyz0123456789-_.,:|!?/ "); CMenuForwarder *username_fwd = new CMenuForwarder(LOCALE_NFS_USERNAME, (*type != (int)CFSMounter::NFS), username, &userInput); CStringInputSMS passInput(LOCALE_NFS_PASSWORD, password, 30, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, "abcdefghijklmnopqrstuvwxyz0123456789-_.,:|!?/ "); CMenuForwarder *password_fwd = new CMenuForwarder(LOCALE_NFS_PASSWORD, (*type != (int)CFSMounter::NFS), NULL, &passInput); CMACInput macInput(LOCALE_RECORDINGMENU_SERVER_MAC, g_settings.network_nfs_mac[nr], LOCALE_IPSETUP_HINT_1, LOCALE_IPSETUP_HINT_2); CMenuForwarder * macInput_fwd = new CMenuForwarder(LOCALE_RECORDINGMENU_SERVER_MAC, true, g_settings.network_nfs_mac[nr], &macInput); CMenuForwarder *mountnow_fwd = new CMenuForwarder(LOCALE_NFS_MOUNTNOW, !(CFSMounter::isMounted(g_settings.network_nfs_local_dir[nr])), NULL, this, cmd); mountnow_fwd->setItemButton(NEUTRINO_ICON_BUTTON_OKAY, true); COnOffNotifier notifier(CFSMounter::NFS); notifier.addItem(username_fwd); notifier.addItem(password_fwd); mountMenuEntryW.addItem(new CMenuOptionChooser(LOCALE_NFS_TYPE, type, NFS_TYPE_OPTIONS, NFS_TYPE_OPTION_COUNT, typeEnabled, ¬ifier)); mountMenuEntryW.addItem(new CMenuForwarder(LOCALE_NFS_IP , true, g_settings.network_nfs_ip[nr], &ipInput )); mountMenuEntryW.addItem(new CMenuForwarder(LOCALE_NFS_DIR , true, dir , &dirInput )); mountMenuEntryW.addItem(new CMenuForwarder(LOCALE_NFS_LOCALDIR, true, local_dir , this , cmd2)); mountMenuEntryW.addItem(automountInput); mountMenuEntryW.addItem(options1_fwd); mountMenuEntryW.addItem(options2_fwd); mountMenuEntryW.addItem(username_fwd); mountMenuEntryW.addItem(password_fwd); mountMenuEntryW.addItem(macInput_fwd); mountMenuEntryW.addItem(mountnow_fwd); int ret = mountMenuEntryW.exec(this,""); return ret; }