Exemple #1
0
void
ttopen(void)
{
    vl_save_tty();

#if !DISP_X11
#ifdef HAVE_SETVBUF
# ifdef SETVBUF_REVERSED
    setvbuf(stdout, _IOFBF, tobuf, TBUFSIZ);
# else
    setvbuf(stdout, tobuf, _IOFBF, (size_t) TBUFSIZ);
# endif
#else /* !HAVE_SETVBUF */
    setbuffer(stdout, tobuf, TBUFSIZ);
#endif /* !HAVE_SETVBUF */
#endif /* !DISP_X11 */

    /* this could probably be done more POSIX'ish? */
#if OPT_SHELL && defined(SIGTSTP) && defined(SIGCONT)
    setup_handler(SIGTSTP, SIG_DFL);	/* set signals so that we can */
    setup_handler(SIGCONT, rtfrmshell);		/* suspend & restart */
#endif
#ifdef SIGTTOU
    setup_handler(SIGTTOU, SIG_IGN);	/* ignore output prevention */
#endif

#if ! DISP_X11
    ntermios = otermios;

    /* new input settings: turn off crnl mapping, cr-ignoring,
     * case-conversion, and allow BREAK
     */
    ntermios.c_iflag = BRKINT | (otermios.c_iflag &
				 (ULONG) ~ (INLCR | IGNCR | ICRNL
#ifdef IUCLC
					    | IUCLC
#endif
				 ));

    ntermios.c_oflag = 0;
    ntermios.c_lflag = ISIG;
    ntermios.c_cc[VMIN] = 1;
    ntermios.c_cc[VTIME] = 0;
#ifdef	VSWTCH
    ntermios.c_cc[VSWTCH] = VDISABLE;
#endif
    ntermios.c_cc[VSUSP] = VDISABLE;
#if defined (VDSUSP) && defined(NCCS) && VDSUSP < NCCS
    ntermios.c_cc[VDSUSP] = VDISABLE;
#endif
    ntermios.c_cc[VSTART] = VDISABLE;
    ntermios.c_cc[VSTOP] = VDISABLE;
#endif /* ! DISP_X11 */

    ttmiscinit();

    term.unclean();
}
Exemple #2
0
void
set_signals (bool reset)
{
  int i;
#if HAVE_SIGACTION
  struct sigaction initial_act, fatal_act;
  fatal_act.sa_handler = fatal_exit;
  sigemptyset (&fatal_act.sa_mask);
  fatal_act.sa_flags = 0;
#define setup_handler(sig) sigaction (sig, &fatal_act, (struct sigaction *) 0)
#else
#define setup_handler(sig) signal (sig, fatal_exit_handler)
#endif

  if (!reset)
    {
#ifdef SIGCHLD
      /* System V fork+wait does not work if SIGCHLD is ignored.  */
      signal (SIGCHLD, SIG_DFL);
#endif
      sigemptyset (&signals_to_block);
      for (i = 0;  i < NUM_SIGS;  i++)
	{
	  bool ignoring_signal;
#if HAVE_SIGACTION
	  if (sigaction (sigs[i], (struct sigaction *) 0, &initial_act) != 0)
	    continue;
	  ignoring_signal = initial_act.sa_handler == SIG_IGN;
#else
	  ignoring_signal = signal (sigs[i], SIG_IGN) == SIG_IGN;
#endif
	  if (! ignoring_signal)
	    {
	      sigaddset (&signals_to_block, sigs[i]);
	      setup_handler (sigs[i]);
	    }
	}
    }
  else
    {
      /* Undo the effect of ignore_signals.  */
#if HAVE_SIGPROCMASK || HAVE_SIGSETMASK
      sigprocmask (SIG_SETMASK, &initial_signal_mask, (sigset_t *) 0);
#else
      for (i = 0;  i < NUM_SIGS;  i++)
	if (sigismember (&signals_to_block, sigs[i]))
	  setup_handler (sigs[i]);
#endif
    }
}
bool setTimer(size_t interval_secs_, size_t interval_usecs_, void(*timer_proc_)())
{
    if(timer_proc_ != NULL){
        if(setup_handler(true) && setup_timer(interval_secs_, interval_usecs_)){
            timer_proc = timer_proc_;
            return true;
        }
    }else{
        if(setup_handler(false) && setup_timer(0, 0)){
            timer_proc = timer_proc_;
            return true;
        }
    }
    return false;
}
Exemple #4
0
void
ttopen(void)
{
    vl_save_tty();

#if ! DISP_X11
    nstate = ostate;
    nstate.sg_flags |= CBREAK;
    nstate.sg_flags &= ~(ECHO | CRMOD);		/* no echo for now... */
    ioctl(0, TIOCSETN, (char *) &nstate);	/* set new state */
#endif

    rnstate = nstate;
    rnstate.sg_flags &= ~CBREAK;
    rnstate.sg_flags |= RAW;

#if ! DISP_X11
    ntchars = otchars;
    ntchars.t_brkc = -1;
    ntchars.t_eofc = -1;
    ntchars.t_startc = -1;
    ntchars.t_stopc = -1;
    ioctl(0, TIOCSETC, (char *) &ntchars);	/* Place new character into K */
    ioctl(0, TIOCSLTC, (char *) &nltchars);	/* Place new character into K */

#ifdef	TIOCLGET
    nlstate = olstate;
    nlstate |= LLITOUT;
    ioctl(0, TIOCLSET, (char *) &nlstate);
#endif

#if OPT_SHELL
    setup_handler(SIGTSTP, SIG_DFL);	/* set signals so that we can */
    setup_handler(SIGCONT, rtfrmshell);		/* suspend & restart */
#endif
    setup_handler(SIGTTOU, SIG_IGN);	/* ignore output prevention */
#endif

#if USE_FIONREAD
    setbuffer(stdout, tobuf, TBUFSIZ);
#endif
    ttmiscinit();
}
Exemple #5
0
void create_new_request(test_baton_t *tb,
                        handler_baton_t *handler_ctx,
                        const char *method, const char *path,
                        int req_id)
{
    setup_handler(tb, handler_ctx, method, path, req_id, NULL);
    serf_connection_request_create(tb->connection,
                                   setup_request,
                                   handler_ctx);
}
Exemple #6
0
void
ttopen(void)
{
    vl_save_tty();

#if defined(HAVE_SETBUFFER) && !DISP_X11
    setbuffer(stdout, tobuf, TBUFSIZ);
#endif

#if SIGTSTP
/* be careful here -- VSUSP is sometimes out of the range of the c_cc array */
#ifdef V_SUSP
    ntermio.c_cc[V_SUSP] = -1;
#endif
#ifdef V_DSUSP
    ntermio.c_cc[V_DSUSP] = -1;
#endif

#if OPT_SHELL
    setup_handler(SIGTSTP, SIG_DFL);	/* set signals so that we can */
    setup_handler(SIGCONT, rtfrmshell);		/* suspend & restart */
#endif
    setup_handler(SIGTTOU, SIG_IGN);	/* ignore output prevention */
#endif

#if ! DISP_X11
    ntermio = otermio;

    /* setup new settings, allow BREAK */
    ntermio.c_iflag = BRKINT;
    ntermio.c_oflag = 0;
    ntermio.c_lflag = ISIG;
    ntermio.c_cc[VMIN] = 1;
    ntermio.c_cc[VTIME] = 0;
#ifdef	VSWTCH
    ntermio.c_cc[VSWTCH] = -1;
#endif
#endif

    ttmiscinit();
    term.unclean();
}
Exemple #7
0
int main(void)
{
  char c;
  char *sen[10];
  int should_run=1;
  int usless;
  
  setup_handler(maxints);
//this one handles "^C" for 3 times
 jump:
  while(should_run){
    fflush(stdout);
    printf("Jingning > ");
  for(int i=0;i<10;i++)
    sen[i]=malloc(100*sizeof(char));
  int i=0;
  int j=0;
  
  //get token starts here:
  c=getchar();
  while(c!='\n')
    {
      if(c=='\n'){
	break;
      }
      else if(c==' '){
      	j=0;
	i++;
      }
      else if(c=='|'||c=='&'||c=='<'||c=='>'){
	i++;j=0;sen[i][j]=c;
	i++;
      }
      else{
	sen[i][j]=c;
	j++;
      }
      c=getchar();
      if(should_run==2){
	should_run=1;
	goto jump;
      }
    }//put the tokens into an array sen[]
  // all token are ready
  usless = pipexec();
  //  redirect1();  
  
  /* for(int k=0;k<=i;k++)
    {
      printf("here is token \n %s\n",sen[k]);
    }*/
  }//Everything in this bracket
  
}
Exemple #8
0
void
create_new_request_with_resp_hdlr(test_baton_t *tb,
                                  handler_baton_t *handler_ctx,
                                  const char *method, const char *path,
                                  int req_id,
                                  serf_response_handler_t handler)
{
    setup_handler(tb, handler_ctx, method, path, req_id, handler);
    serf_connection_request_create(tb->connection,
                                   setup_request,
                                   handler_ctx);
}
Exemple #9
0
static timer_t
make_timer()
{
  timer_t timerid = 0;
  struct sigevent sev;

  setup_handler();

  sev.sigev_notify = SIGEV_SIGNAL;
  sev.sigev_signo = g_sig_num;
  sev.sigev_value.sival_ptr = &timerid;
  if (timer_create(CLOCKID, &sev, &timerid) == -1) {
    handleError("timer_create");
  }

  return timerid;
}
/*ARGSUSED*/
SIGT
rtfrmshell(int ACTUAL_SIG_ARGS)
{
#if SYS_UNIX && defined(SIGTSTP)
# if ! DISP_X11
	ttunclean();
	sgarbf = TRUE;
#  if SYS_APOLLO
	(void)TTgetc();		/* have to skip a character */
	ttunclean();		/* ...so that I can finally suppress echo */
#  endif
	TTkopen();
	setup_handler(SIGCONT,rtfrmshell); /* suspend & restart */
	(void)update(TRUE);
# endif
#endif
#ifdef	MDCHK_MODTIME
	(void)check_visible_modtimes();
#endif
	SIGRET;
}
Exemple #11
0
int main(int argc, char *argv[])
{
    char c;
    int status = 0;
    
    printf("Hello World, I'm game!\n");
    
    status = init_display();
    if (status != 0)
    {
        printf("Error: Failed to init display\n");
        return status;
    }
    
    status = init_driver();
    if (status != 0)
    {
        printf("Error: Failed to init driver\n");
        destroy_display();
        return status;
    }
    
    status = setup_handler();
    if (status != 0)
    {
        printf("Error: Failed to init signal handler\n");
        destroy_display();
        close(file_gamepad_driver);
        return status;
    }
    time_handler();
    
    /* Intializes random number generator */
    srand((unsigned) time(&t));
    
    sigset_t myset;
    (void) sigemptyset(&myset);

    while(1)
    {
        clear_LCD();       
        draw_game();
        draw_score(p1_score, p2_score);
        redraw();
        
        waitForButton();      
        printf("start game\n");
        
        while((p1_score < 5) && (p2_score < 5))
        {
            random_timer = (rand() % 3) + 2;
            startTimer(random_timer);
            waitForTimer();
            
            random_button = (rand() % 4);
            
            draw_button(random_button, true, RED);
            redraw();
            
            gettimeofday(&time_button_appears, NULL);

            // start timer
            startTimer(3);
            buf = 0;
            while((playerButtonPressed(random_button) == 0) && (timer_expired == false))
            {
                waitForButton(); 
            }
            
            stopTimer();
            if (timer_expired == false)
            {
                time_elapsed = getGameTime();
                draw_time(time_elapsed, BLUE);
                redraw();
            }
      
            if (playerButtonPressed(random_button) == P1)
            {
                p1_score++;
                p1_time += time_elapsed;
                
            }
            else if (playerButtonPressed(random_button) == P2)
            {
                p2_score++;    
                p2_time += time_elapsed;
            }
                
            draw_score(p1_score, p2_score);    
            reset_button(random_button);
            redraw();
            
        }
        // draw winner
        button_pressed = 0;
        if (p1_score == 5)
        {
            winner = P1;
            winner_time = p1_time;
        }
        else if (p2_score == 5)
        {
            winner = P2;
            winner_time = p2_time;
        }
        
        while(button_pressed == 0)
        {
            startTimer(1);
            winner_blink(winner, winner_time);
            waitForTimer();
        }
               
        // print waiting
        waitForButton();
        p1_score = 0;
        p1_time = 0;
        p2_score = 0;
        p2_time = 0;
    }

}