int main(){ int prio; int fork_exit_pid[FORK_EXIT_CHILD],get_ioprio_pid[GET_IOPRIO_CHILD],fack_ioprio_pid[FACK_IOPRIO_CHILD]; int pipe_fd[2]; int i,val; if(pipe(pipe_fd) == -1){ perror("pipe"); return -1; } read_fd = pipe_fd[0]; write_fd = pipe_fd[1]; _ioprio_set(IOPRIO_WHO_PROCESS,0,0x6000); for(i = 0; i < FORK_EXIT_CHILD; i++) fork_exit_pid[i] = fork_and_run(FORK_EXIT_LOOP); for(i = 0; i < GET_IOPRIO_CHILD; i++) get_ioprio_pid[i] = fork_and_run(GET_IOPRIO_LOOP); for(i = 0; i < FACK_IOPRIO_CHILD; i++) fack_ioprio_pid[i] = fork_and_run(FACK_IOPRIO_LOOP); if(fork()==0){ time_control(); } read(read_fd,&val,sizeof(val)); printf("read pipe %d\n",val); if(val == 1){ printf("done! vul\n"); }else if(val == -1){ printf("done! no vul\n"); } for(i = 0; i < FORK_EXIT_CHILD; i++) kill(fork_exit_pid[i],SIGKILL); for(i = 0; i < GET_IOPRIO_CHILD; i++) kill(get_ioprio_pid[i],SIGKILL); for(i = 0; i < FACK_IOPRIO_CHILD; i++) kill(fack_ioprio_pid[i],SIGKILL); sleep(1); close(read_fd); close(write_fd); return 0; }
void advanced_level(int file_no,int MINUTE, int angleINCREASE){ FILE *file; file= fopen(file_name[file_no],"r"); char choice[2],comp; // line & i will keep track wid total lines and chars respectively int i=0,chars=0, file_pointer,line,z,char_x,char_y,dummy_choice; int j1,ch1,x1,y1,time_up; prev= -1; time_interval=0, min=0, sec=0, eff=0, err=0, speed=0; pressed=0, correct= 0, wrong= 0, cpm=0, correction=0; minute=MINUTE, INCREASE= angleINCREASE,second=0; tutorial_window(); hideMouse(); file_pointer=0; choice[1]='\0'; setcolor(4); settextstyle(0,0,1); outtextxy(542,50,"0"); outtextxy(562,50,":"); outtextxy(574,50,"00"); show_number(minute,550,50,4,0,1); user_response(250,130,1,3); time(&start_time); settextstyle(2,0,5); color_text(535,76,"ESC to",3); color_text(536,76,"ESC to",3); color_text(524,92,"quit/pause",3); color_text(525,92,"quit/pause",3); dummy_choice= 'A'; //just to initialize the drawing of a key increase=0, angle=89; file_open4_screen(file,173,72,36,1,6,30,0); while(!feof(file)){ i=0;char_x=173;char_y=90; line=0; chars=0; rewind(file); fseek(file,file_pointer,0); while(line<6){ if(feof(file)){ summary_content(); end_lesson(min,sec,eff,err,speed); return; //break; } gettime (&new_time); time_up= time_control(); if(time_up) return ; if(i>=0){ color_text(char_x+8*i,(char_y+36*line)+1,"_",4); color_text(char_x+8*i,(char_y+36*line)-23,"^",4); } if(kbhit()){ check_kb_up_down(dummy_choice,0); choice[0]= getch(); // user input dummy_choice= choice[0]; pressed++; check_kb_up_down(choice[0],1); if(chars>29){ color_text((char_x+i*8),(char_y+36*line)+1,"_",15); color_text((char_x+i*8),(char_y+36*line)-23,"^",15); i=0; line++; chars=0; } if(choice[0]==27 ) // ESC { pressed--; make_sound(2000,100); if(i>0) summary_content(); z = continue_close(min,sec,eff,err,speed); if(z) return; else continue; } if(choice[0]==0){ // error checking for function keys int ch1=getch(); if(ch1==80||ch1==72||ch1==75||ch1==77) //error checking to avoide right,left,up continue; } else if(choice[0]==9) continue; //error checking for tab else if(choice[0]==8){ //BACKSPACE correction++; if(i>0 || line>0){ if(i>0){ file_pointer--; fseek(file,-1,SEEK_CUR); setfillstyle(1,15); bar(char_x+i*8,char_y+36*line,char_x+(i*8)-8,char_y+7+36*line); color_text((char_x+i*8)-8,(char_y+36*line)+1,"_",4); color_text(char_x+i*8,(char_y+36*line)+1,"_",15); color_text((char_x+i*8)-8,(char_y+36*line)-23,"^",4); color_text(char_x+i*8,(char_y+36*line)-23,"^",15); i--; chars--; } if(i>29){ line++; i=0;chars=0; } } make_sound(1000,100); } else{ file_pointer++; correct++; fscanf(file,"%c",&comp); setcolor(4); if(comp=='\n'){ i=0; chars=1; line++; continue; } if(comp!=choice[0] && choice[0]==' ') { char choice1 = '-'; //when space is pressed instead of any key, print dash print_lesson(char_x+i*8,char_y+36*line,choice1,9); make_sound(500,100); wrong++; correct--; } else if(comp != choice[0]){ wrong++; correct--; setcolor(9); make_sound(500,100); outtextxy(char_x+i*8,char_y+36*line,choice); } else outtextxy(char_x+i*8,char_y+36*line,choice); color_text((char_x+i*8)+8,(char_y+36*line)-23,"^",4); color_text(char_x+i*8,(char_y+36*line)-23,"^",15); color_text((char_x+i*8)+8,(char_y+36*line)+1,"_",4); color_text(char_x+i*8,(char_y+36*line)+1,"_",15); i++; chars++; } } } if(feof(file)) break; setfillstyle(1,15); bar(165,56,417,300); undr_line(165,81,12,250,18,7); file_open4_screen(file,173,72,36,1,6,30,file_pointer); } fclose(file); closegraph(); }
void lesson_practice(int lesson_no,int num,int MINUTE,int angleINCREASE) { /* INCREASE= will control time, MINUTE= given time limit of typing */ int j1,ch1,x1,y1,time_up; int char_x, char_y,i,choice,dummy_choice,line,z; int rndm,store; /* 'store' is used to store chars serially in store array */ prev= -1; time_interval=0, min=0, sec=0, eff=0, err=0, speed=0; pressed=0, correct= 0, wrong= 0, cpm=0, correction=0; minute=MINUTE, INCREASE= angleINCREASE, second=0; char_x = 173; char_y = 72; tutorial_window(); run_info_window(); hideMouse(); if(!num) LETTER= 4; else if(!lesson_no) LETTER=20; line = 1; for(i=1,store=0; line<MAX ;i++,store++) { rndm = random(LETTER); // randomly seeks chars if(!num){ store_chars[store]= lesson[lesson_no-1][rndm]; print_lesson(char_x, char_y, lesson[lesson_no-1][rndm],1); } else if(!lesson_no){ store_chars[store]= numeric[num-1][rndm]; print_lesson(char_x, char_y, numeric[num-1][rndm],1); } char_x +=8; //for next character if(i%4==0) // GIVING SPACE AFTER EVERY 4 CHARS { char_x +=8; store++; store_chars[store]=' '; } if(char_x >405) // NEXT LINE { char_x = 173; char_y+= 36; line++; } } setcolor(4); outtextxy(542,50,"0"); outtextxy(562,50,":"); outtextxy(574,50,"00"); show_number(minute,550,50,4,0,1); run_info(pressed,correct,wrong,correction); user_response(250,130,1,3); time(&start_time); settextstyle(2,0,5); color_text(535,76,"ESC to",3); color_text(536,76,"ESC to",3); color_text(524,92,"quit/pause",3); color_text(525,92,"quit/pause",3); char_x= 173; char_y= 90; line =1; i=0; dummy_choice= 'A'; //just to initialize the drawing of a key increase=0, angle=89; while(1) { gettime (&new_time); time_up= time_control(); if(time_up) return; if(line<7){ color_text(char_x,char_y+1,"_",4); color_text(char_x,char_y-23,"^",4); } if(kbhit()) { check_kb_up_down(dummy_choice,0); choice= getch(); // ASSIGN USER INPUT TO 'CHOICE' dummy_choice= choice; pressed++; check_kb_up_down(choice,1); if(line>6) { summary_content(); end_lesson(min,sec,eff,err,speed); return; } if(choice==27 ) // ESC { pressed--; make_sound(2000,100); if(i>0) summary_content(); z = continue_close(min,sec,eff,err,speed); if(z) return; else continue; } else if(choice==0) // error checking for function keys { ch1=getch(); if(ch1==80||ch1==72||ch1==75||ch1==77) //error checking to avoide right,left,up continue; } else if(choice==9) continue; //error checking for tab else if(choice==8) // BACKSPACE { if(i>0) { correction++; if(char_x<=173){ setfillstyle(1,15); bar(char_x+233,char_y-36,char_x+243,char_y-29); color_text(char_x,char_y+1,"_",15); color_text(char_x,char_y-23,"^",15); char_y-=36; char_x+=240; color_text(char_x-8,char_y+1,"_",4); color_text(char_x-8,char_y-23,"^",4); } else{ setfillstyle(1,15); bar(char_x-8, char_y, char_x,char_y+7); color_text(char_x,char_y+1,"_",15); color_text(char_x-8,char_y+1,"_",4); color_text(char_x,char_y-23,"^",15); color_text(char_x-8,char_y-23,"^",4); } --i; char_x-=8; sound(1000); delay(100); nosound(); } } else{ if(choice==store_chars[i]){ //letter is ok! print_lesson(char_x,char_y,choice,4); correct++; } else if(store_chars[i] !=choice && choice==' ') { char choice1 = '-'; //when space is pressed instead of any key, print dash print_lesson(char_x,char_y,choice1,9); make_sound(500,100); wrong++; } else { print_lesson(char_x, char_y,choice,9); make_sound(500,100); wrong++; } color_text(char_x+8,char_y-23,"^",4); color_text(char_x,char_y-23,"^",15); color_text(char_x+8,char_y+1,"_",4); color_text(char_x,char_y+1,"_",15); char_x +=8; if(char_x > 405) { color_text(char_x,char_y+1,"_",15); color_text(char_x,char_y-23,"^",15); char_x = 173; char_y +=36; line++; } i++; } // end of else or default typing run_info(pressed,correct,wrong,correction); } // end of the initial 'if' } // end of while }