VOID Display::init() { struct sigaction action_quit; initscr(); noecho(); m_dispIntvl = Config::getInstance()->getDisplayRefreshTimer(); m_pStats = Stats::getInstance(); getTimeStr(m_timeStr); m_startTime = getMilliSeconds() / 1000; m_remPort = Config::getInstance()->getRemoteGtpcPort(); STRCPY(m_remIpAddrStr, (Config::getInstance()->\ getRemIpAddrStr()).c_str()); m_pMsgVec = &(Scenario::getInstance()->m_msgVec); m_msgVecLen = m_pMsgVec->size(); /* Map exit handlers to curses reset procedure */ memset(&action_quit, 0, sizeof(action_quit)); (*(void **)(&(action_quit.sa_handler))) = (VOID *)screen_exit; sigaction(SIGTERM, &action_quit, NULL); sigaction(SIGINT, &action_quit, NULL); sigaction(SIGKILL, &action_quit, NULL); CLEAR_SCREEN(); }
//添加学生的函数 void addstudent() { struct student stu; int flag; while(1) { flag = 0; CLEAR_SCREEN(); struct list *find; printf("\033[33m\033[2;50H%s\033[0m","请输入以下信息"); printf("\033[33m\033[4;50H%s\033[0m","请输入学生的ID:"); scanf("%s",stu.id); find = list_find(list_student, &stu, comp_id_stu); if(find != NULL) { printf("\033[33m\033[6;50H%s\033[0m","帐号已注册,请按任意键重试。\n"); getchar(); getchar(); } else { flag = 1; } if(flag == 1) { break; } } printf("\033[33m\033[5;50H%s\033[0m","请输入学生的密码:"); scanf("%s",stu.pass); printf("\033[33m\033[6;50H%s\033[0m","请输入学生的姓名:"); scanf("%s",stu.name); printf("\033[33m\033[7;50H%s\033[0m","请输入学生的年龄:"); scanf("%d",&stu.age); printf("\033[33m\033[8;50H%s\033[0m","请输入学生的班级:"); scanf("%s",stu.class); printf("\033[33m\033[9;50H%s\033[0m","请输入学生的语文成绩:"); scanf("%d",&stu.grade[0]); printf("\033[33m\033[10;50H%s\033[0m","请输入学生的数学成绩:"); scanf("%d",&stu.grade[1]); printf("\033[33m\033[11;50H%s\033[0m","请输入学生的C语言成绩:"); scanf("%d",&stu.grade[2]); stu.average = (stu.grade[0]+stu.grade[1]+stu.grade[2])/3; //将stu插到链表中去 if(list_addtail(list_student,&stu) == 0) { printf("\033[33m\033[12;50H%s\033[0m","添加学生数据成功!\n"); getchar(); getchar(); } else { printf("\033[33m\033[12;50H%s\033[0m","添加学生数据失败!\n"); getchar(); getchar(); } }
void einkfb_shim_power_off_screen(void) { POWER_OVERRIDE_BEGIN(); CLEAR_SCREEN(); einkfb_shim_suspend_resume_hook(EINKFB_SUSPEND); POWER_OVERRIDE_END(); }
//打印当前学生的信息 void print_loginstudent() { CLEAR_SCREEN(); printf("\033[33m\033[2;54H%s\033[0m","您的学生信息如下:\n"); printf("\033[33m\033[4;10H%s\033[0m","学生ID\t\t学生姓名\t学生年龄\t学生班级\t语文成绩\t数学成绩\tC语言成绩\t平均成绩\n"); print_student(stulogin->dat); getchar(); getchar(); }
void print_allstu() { CLEAR_SCREEN(); printf("\033[33m\033[2;54H%s\033[0m","学生信息如下:\n"); printf("\033[33m\033[4;10H%s\033[0m","学生ID\t\t学生姓名\t学生年龄\t学生班级\t语文成绩\t数学成绩\tC语言成绩\t平均成绩\n"); list_print(list_student, print_student); getchar(); getchar(); }
/******************************************************************* * FUNCTION: CommandBegin * AUTHOR = TRAMPAS STERN * FILE = command.c * DATE = 1/25/2004 3:43:22 PM * * PARAMETERS: * * DESCRIPTION: Starts up the serial command line * * RETURNS: * * *******************************************************************/ UINT CommandBegin() { UBYTE data; CHAR buffer[MAX_STRING]; UBYTE buffIndex; //first clear the screen and push command prompt CLEAR_SCREEN(); printf(CMD_PROMPT); //now spin reading command and waiting on CR CommandExit=0; buffIndex=0; buffer[0]=0; while(!CommandExit) { if(kbhit()) { data=getch2(); //echo the data putch(data); //if the data is the CR we need to process buffer if (data==0x0D) { putch(0x0A); if (strlen(buffer)>0) CommandParse(buffer); printf("\n\r"); printf(CMD_PROMPT); buffIndex=0; buffer[buffIndex]=0; } if (data != 0x0A && data !=0x0D) { buffer[buffIndex++]=data; buffer[buffIndex]=0; } if (buffIndex>=(MAX_STRING-1)) { printf("\n\rERROR: Command buffer overflow\n\r"); buffIndex=0; buffer[0]=0; printf(CMD_PROMPT); } } } return 0; }
//删除学生 void delstudent() { struct student stu; CLEAR_SCREEN(); printf("\033[33m\033[2;50H%s\033[0m","删除学生界面"); printf("\033[33m\033[4;50H%s\033[0m","请输入学生的ID:"); scanf("%s",stu.id); if(list_find(list_student, &stu, comp_id_stu) != NULL) { list_del(list_student, &stu, comp_id_stu); printf("\033[33m\033[8;50H%s\033[0m","删除学生数据成功!\n"); getchar(); getchar(); } else { printf("\033[33m\033[8;50H%s\033[0m","对不起没有找到该学生!\n"); getchar(); getchar(); } }
void clearScreen() { CLEAR_SCREEN(); }
void CPnet::CPMenu(void) { int selection; while(selection != 8) { cout << "=================================================================\n"; cout << "\tPerceptron Neural Net using Perceptron learning rule\n"; cout << "=================================================================\n\n"; cout << "[1]. Create a new Neural Net" << endl; cout << "[2]. Train the current Neural Net" << endl; cout << "[3]. Load a Neural Net from file" << endl; cout << "[4]. Test Neural Net" << endl; cout << "[5]. Save the current Net" << endl; cout << "[6]. Set training display" << endl; cout << "[7]. Display Neural Net Info" << endl; cout << "[8]. Quit the program" << endl << endl; cout << "selection: "; selection = getche() - '0'; WAIT(0.5*SECOND); CLEAR_SCREEN(); switch(selection) { case 1: SaveCurrentData(); cout << "\nCreating Neural Net..."; WAIT(1*SECOND); CreateNet(); break; case 2: if (bNeuralNetCreated) { cout << "\nTraining \"" << szNeuralNetName << "\" function..." << endl; WAIT(0.7*SECOND); cout << "Enter Learning rate: "; cin >> LEARNING_RATE; WAIT(0.7*SECOND); cout << "Enter number of epochs: "; cin >> CPN_ITER; NormalizeInput(); NormalizeTarget(); CLEAR_SCREEN(); WAIT(0.7*SECOND); cout << "\nTraining \"" << szNeuralNetName << "\" function..." << endl; WAIT(2*SECOND); CLEAR_SCREEN(); TrainNetwork(); } else { UpdateScreen(); } break; case 3: SaveCurrentData(); cout << "\n\nLoading Neural Net..." << endl; WAIT(0.85*SECOND); cout << "\nEnter the name of the Neural Net or the complete path where " << "the Net data can be found\n: "; cin.sync(); cin.getline(szNeuralNetName, MAX_PATH); LoadNet(); WAIT(1.5*SECOND); CLEAR_SCREEN(); cout << "\n\n\n\n\n\n\n\n\n\t\t\tNeural Net loaded successfuly!" << endl; UpdateScreen(); break; case 4: if (bNeuralNetTrained) { cout << "\nTesting \"" << szNeuralNetName << "\" function..." << endl; cout << "1. default test" << endl; cout << "2. selective test" << endl; cout << "\nselection: "; int nNumOfPattern; int sel = getche(); CLEAR_SCREEN(); WAIT(0.7*SECOND); DeNormalizeInput(); DeNormalizeTarget(); switch(sel) { case '1': TestNetwork(); break; case '2': cout << "\nEnter the number of patterns to be tested: "; cin >> nNumOfPattern; SelectiveTest(nNumOfPattern); UpdateScreen(); break; default: cout << "\nunknown selection." << endl; UpdateScreen(); } } else { UpdateScreen(); } break; case 5: if (bNeuralNetCreated) { if (fExist(szNeuralNetName)) { CLEAR_SCREEN(); WAIT(0.5*SECOND); cout << "\n\"" << szNeuralNetName << "\""; cout << ": this file already exist,do you want to overwrite it?" << endl; cout << "Yes(y) No(n): "; char response; cin >> response; response = tolower(response); if(response == 'y') { SaveNet(); } else { WAIT(0.5*SECOND); cout << "\nPlease enter a new name or a complete file path where the " << "Neural Net will be saved\n: "; cin.sync(); cin.getline(szNeuralNetName, MAX_PATH); SaveNet(); } } else { SaveNet(); } CLEAR_SCREEN(); WAIT(1.5*SECOND); cout << "\n\n\n\n\n\n\n\n\n\t\t\tThe Neural Net was saved successfuly!" << endl; }
void deletar_game() { int escolha_id = 0; FILE *arquivo; GAME jogo; if(file_exists("locadora.dtb") == false) { printf("\nO ARQUIVO NAO EXISTE!\n"); printf("\nDESEJA CRIAR O ARQUIVO? [s/n]: \n"); scanf("%s", escolha); if( (strcmp(escolha, "s") == 0) || (strcmp(escolha, "S") == 0) ) { arquivo = abrir_arquivo("locadora.dtb", "r+b"); fclose(arquivo); menu(); } return; } else { arquivo = abrir_arquivo("locadora.dtb", "r+b"); init_game(&jogo); mostra_dados(); rewind(arquivo); printf("\nDigite o ID que deseja deletar: "); scanf("%d", &escolha_id); while(1) { fread(&jogo, sizeof(GAME), 1, arquivo); if(feof(arquivo) == 0) { if(jogo.id == escolha_id) { jogo.deletable = true; break; } else { continue; } } else { printf("\nO ID NAO FOI ENCONTRADO!\n"); printf("\nDESEJA VOLTAR AO MENU PRINCIPAL? [s/n]: \n"); scanf("%s", escolha); if( (strcmp(escolha, "s") == 0) || (strcmp(escolha, "S") == 0) ) { menu(); } else { return; } } } fseek(arquivo, (-1 * sizeof(GAME)), SEEK_CUR); size_t result = fwrite(&jogo, sizeof(GAME), 1, arquivo); if(result == 1) { CLEAR_SCREEN(); printf("\nJOGO DELETADO COM SUCESSO!"); printf("\nDeseja deletar mais algum jogo? [s/n]: "); scanf("%s", escolha); if( (strcmp(escolha, "s") == 0) || (strcmp(escolha, "S") == 0) ) { fclose(arquivo); CLEAR_SCREEN(); deletar_game(); } else { fclose(arquivo); CLEAR_SCREEN(); menu(); } } else { fclose(arquivo); CLEAR_SCREEN(); printf("\nOCORREU UM ERRO AO TENTAR DELETAR O JOGO!\n"); menu(); } } }
void editar_game() { int escolha_id = 0; GAME jogo, tmp_jogo; FILE *arquivo = NULL; if(file_exists("locadora.dtb") == false) { printf("\nO ARQUIVO NAO EXISTE!\n"); printf("\nDESEJA CRIAR O ARQUIVO? [s/n]: \n"); scanf("%s", escolha); if( (strcmp(escolha, "s") == 0) || (strcmp(escolha, "S") == 0) ) { arquivo = abrir_arquivo("locadora.dtb", "r+b"); fclose(arquivo); menu(); } return; } else { arquivo = abrir_arquivo("locadora.dtb", "r+b"); } mostra_dados(); rewind(arquivo); printf("\nDigite o ID que deseja editar: "); scanf("%d", &escolha_id); while(1) { fread(&jogo, sizeof(GAME), 1, arquivo); if(feof(arquivo) == 0) { if(escolha_id == jogo.id ) { tmp_jogo = jogo; fseek(arquivo, (-1 * sizeof(GAME)), SEEK_CUR); // ANDA ATE A POSICAO INICIAL DO DADO ESCOLHIDO break; } else { continue; } } else { printf("\nO ID NAO FOI ENCONTRADO!\n"); printf("\nDESEJA VOLTAR AO MENU PRINCIPAL? [s/n]: \n"); scanf("%s", escolha); if( (strcmp(escolha, "s") == 0) || (strcmp(escolha, "S") == 0) ) { menu(); } else { return; } } } CLEAR_SCREEN(); printf("####################################################\n"); printf("####################################################\n"); printf("# \t\t\t\t\t\t #"); printf("\n#\t\tDADOS DO ID ESCOLHIDO \t\t #\n# \t\t\t\t\t\t #\n"); printf("####################################################\n"); printf("####################################################\n"); printf("\n[1] NOME: %s", tmp_jogo.nome); printf("\n[2] GENERO: %s", tmp_jogo.genero); printf("\nQUAL DADO DESEJA EDITAR?\n"); printf("-> "); scanf("%d", &escolha_id); if(escolha_id == 1) { CLEAR_SCREEN(); printf("\nDigite o novo nome do jogo: "); scanf(" %[^\n]s", tmp_jogo.nome); fwrite(&tmp_jogo, sizeof(GAME), 1, arquivo); } else { CLEAR_SCREEN(); printf("\nDigite o novo genero do jogo: "); scanf(" %[^\n]s", tmp_jogo.genero); fwrite(&tmp_jogo, sizeof(GAME), 1, arquivo); } fclose(arquivo); printf("\nDESEJA EDITAR MAIS ALGUM REGISTRO? [s/n]: \n"); scanf("%s", escolha); if( (strcmp(escolha, "s") == 0) || (strcmp(escolha, "S") == 0) ) { CLEAR_SCREEN(); editar_game(); } else { menu(); } }
void inserir_game() // INSERE DADOS NO ARQUIVO BINÁRIO. { FILE *arquivo = NULL; GAME jogo, tmp_jogo; init_game(&jogo); init_game(&tmp_jogo); arquivo = abrir_arquivo("locadora.dtb", "a+b"); rewind(arquivo); fseek(arquivo, (-1 * sizeof(GAME)), SEEK_END); // ANDA ATÉ A POSIÇÃO N-1 BYTES fread(&jogo, sizeof(GAME), 1, arquivo); // PEGA O ÚLTIMO BLOCO DO TAMANHO DE "GAME" rewind(arquivo); // VOLTA O INDICADOR DA POSIÇÃO DO ARQUIVO NO COMEÇO // FUNCAO AUTO INCREMENT if(jogo.id == 0) { jogo.id = 1; // SE NÃO HOUVER UM "GAME" CADASTRADO ADICIONA O PRIMEIRO ID COM O VALOR DE "1" } else { jogo.id += 1; // CASO CONTRÁRIO ADICIONA +1 NO ID DO "GAME" QUE SERÁ CADASTRADO } CLEAR_SCREEN(); printf("\nDigite o nome do jogo: "); scanf(" %[^\n]s", jogo.nome); printf("\nDigite o genero do jogo: "); scanf(" %[^\n]s", jogo.genero); while(1) { fread(&tmp_jogo, sizeof(GAME), 1, arquivo); if(feof(arquivo) != 0) { rewind(arquivo); fclose(arquivo); arquivo = abrir_arquivo("locadora.dtb", "a+b"); break; } else { if(tmp_jogo.deletable == true) { fclose(arquivo); arquivo = abrir_arquivo("locadora.dtb", "r+b"); jogo.id = tmp_jogo.id; fseek(arquivo, (-1 * sizeof(GAME)), SEEK_CUR); break; } else { continue; } } } size_t result = fwrite(&jogo, sizeof(GAME), 1, arquivo); if(result == 1) { CLEAR_SCREEN(); printf("\nDADOS INSERIDOS COM SUCESSO!"); printf("\nDeseja inserir mais dados? [s/n]: "); scanf("%s", escolha); if( (strcmp(escolha, "s") == 0) || (strcmp(escolha, "S") == 0) ) { fclose(arquivo); CLEAR_SCREEN(); inserir_game(); } else { fclose(arquivo); CLEAR_SCREEN(); menu(); } } else { fclose(arquivo); CLEAR_SCREEN(); printf("\nOCORREU UM ERRO AO TENTAR INSERIR OS DADOS!\n"); menu(); } }
VOID Display::disp() { static BOOL firTime = TRUE; CLEAR_SCREEN(); if (firTime) { firTime = FALSE; fprintf(stdout, "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"\ "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); } PRINT_SEPERATOR(); fprintf(stdout, "Start: %s ", m_timeStr); Time_t runTime = (getMilliSeconds() / 1000) - m_startTime; fprintf(stdout, "Run-Time: %us ", (U32)runTime); fprintf(stdout, "Remote-Host: %s:%d \r\n", m_remIpAddrStr, m_remPort); Counter ssnCreated = getStats(GSIM_STAT_NUM_SESSIONS_CREATED); Counter ssnSucc = getStats(GSIM_STAT_NUM_SESSIONS_SUCC); Counter ssnFail = getStats(GSIM_STAT_NUM_SESSIONS_FAIL); fprintf(stdout, "Total-Sessions: %u \r\n", ssnCreated); fprintf(stdout, "Session-Completed: %u \r\n", ssnSucc); fprintf(stdout, "Session-Aborted: %u \r\n", ssnFail); PRINT_SEPERATOR(); fprintf(stdout," "\ "Messages Retrans Timeout Unexpected-Msg\r\n"); for (U32 i = 0; i < m_msgVecLen; i++) { MsgTask *pMsgTask = (*m_pMsgVec)[i]; fprintf(stdout, "%s ", pMsgTask->m_msgName); if (pMsgTask->type() == MSG_TASK_SEND) { fprintf(stdout, "\t--->"); fprintf(stdout, " \t%9d", pMsgTask->m_numSnd); fprintf(stdout, "%9d", pMsgTask->m_numSndRetrans); fprintf(stdout, " %9d", pMsgTask->m_numTimeOut); fprintf(stdout, ENDLINE); } else if (pMsgTask->type() == MSG_TASK_RECV) { fprintf(stdout, " \t<---"); fprintf(stdout, "\t%9d", pMsgTask->m_numRcv); fprintf(stdout, "%9d", pMsgTask->m_numRcvRetrans); fprintf(stdout, " %9d", pMsgTask->m_numUnexp); fprintf(stdout, ENDLINE); } else { fprintf(stdout, "[Wait %5d]\r\n", 0); fprintf(stdout, ENDLINE); } } PRINT_BLANK_LINE(); if (KB_KEY_PAUSE_TRAFFIC == Keyboard::key) { PRINT_END_SEPERATOR_RESUME(); } else { PRINT_END_SEPERATOR_PAUSE(); } fflush(stdout); }