Example #1
0
void main (void)
{
  int cs = 1;
  while (1)
    {
      /* Display current state on LED */

      if (cs == 10)
	leddisplay ('0');
      else
	leddisplay ('0' + cs);
      switch (cs)
	{
	case 1:
	  cs = state1 ();
	  break;
	case 2:
	  cs = state2 ();
	  break;
	case 3:
	  cs = state3 ();
	  break;
	case 4:
	  cs = state4 ();
	  break;
	case 5:
	  cs = state5 ();
	  break;
#if 0
	case 6:
	  cs = state6 ();
	  break;
#endif
	case 7:
	  cs = state7 ();
	  break;
	case 8:
	  cs = state8 ();
	  break;
#if 0
	case 9:
	  cs = state9 ();
	  break;
#endif
	case 10:
	  cs = state10 ();
	  break;
	default:
	  cs = 1;
	  break;
	}
    }
}
// Processes an event which drives a change in state.
void processEvent (char event) {
	int ProcessedCorrectly = 0;
	currentState = peek ();

	printf ("Processing event: %c for state: %c \n", event, currentState);

	switch(currentState) {
		case STATE0:
			ProcessedCorrectly = state0 (event);
			break;
		case STATE1:
			ProcessedCorrectly = state1 (event);
			break;
		case STATE2:
			ProcessedCorrectly = state2 (event);
			break;
		case STATE3:
			ProcessedCorrectly = state3 (event);
			break;
		case STATE4:
			ProcessedCorrectly = state4 (event);
			break;
		case STATE5:
			ProcessedCorrectly = state5 (event);
			break;
		case STATE6:
			ProcessedCorrectly = state6 (event);
			break;
		case STATE7:
			ProcessedCorrectly = state7 (event);
			break;
		case STATE8:
			ProcessedCorrectly = state8 (event);
			break;
		case STATE9:
			ProcessedCorrectly = state9 (event);
			break;
		case STATEA:
			ProcessedCorrectly = state10 (event);
			break;
		case STATEB:
			ProcessedCorrectly = state11 (event);
			break;
		default:
			printf ("Unknown state %d for event  %c \n", currentState, event);
			ProcessedCorrectly = 1;
		}
	if(ProcessedCorrectly == 1) {
		printf ("The Grammar Failed The Syntax Machine\n");
		exit (0);
		}
	}
Example #3
0
void vt_out(struct term_t *pwin, unsigned int ch)
{
  int f;
  unsigned char c;
  int go_on = 0;
  wchar_t wc;
  term_t *win;

  win = (term_t *)pwin;
  if (!ch)
    return;


  c = (unsigned char)ch;

  if (win->state.vt_docap == 2) /* Literal. */
    fputc(c, win->state.capfp);

  /* Process <31 chars first, even in an escape sequence. */
  switch (c) {
    case '\r': /* Carriage return */
      term_wputc(win, c);
      if (win->state.vt_addlf) {
        term_wputc(win, '\n');
        if (win->state.vt_docap == 1)
          fputc('\n', win->state.capfp);
      }
      break;
    case '\t': /* Non - destructive TAB */
//      printf("tab pants\n");
      /* Find next tab stop. */
      for (f = win->cursor_x + 1; f < 160; f++)
        if (win->state.vt_tabs[f / 32] & (1 << f % 32))
          break;
      if (f >= win->W)
        f = win->W - 1;
      term_wlocate(win, f, win->cursor_y);
      if (win->state.vt_docap == 1)
        fputc(c, win->state.capfp);
      break;
    case 013: /* Old Minix: CTRL-K = up */
      term_wlocate(win, win->cursor_x, win->cursor_y - 1);
      break;
    case '\f': /* Form feed: clear screen. */
      term_winclr(win);
      term_wlocate(win, 0, 0);
      break;
    case 14:
      break;
    case 15:
      break;
    case 24:
    case 26:  /* Cancel escape sequence. */
      esc_s = 0;
      break;
    case ESC: /* Begin escape sequence */
      esc_s = 1;
      break;
    case 128+ESC: /* Begin ESC [ sequence. */
      esc_s = 2;
      break;
    case '\n':
    case '\b':
    case 7: /* Bell */
      term_wputc(win, c);
      if (win->state.vt_docap == 1)
        fputc(c, win->state.capfp);
      break;
    default:
      go_on = 1;
      break;
  }
  if (!go_on)
    return;
 

  /* Now see which state we are in. */
  switch (esc_s) {
    case 0: /* Normal character */
      /* XXX:mappers */
      c&=0xff;

      if (!win->state.enable_iconv) {
        one_mbtowc ((char *)&wc, (char *)&c, 1); 
        if (win->state.vt_insert)
          term_winschar(win, wc, 1);
        else
          term_wputc(win, wc);
      } else 
        term_wputc(win, c);
     
      break;
    case 1: /* ESC seen */
      state1(win, c);
      break;
    case 2: /* ESC [ ... seen */
      state2(win, c);
      break;
    case 3:
      state3(win, c);
      break;
    case 4:
      state4(win, c);
      break;
    case 5:
      state5(win, c);
      break;
    case 6:
      state6(win, c);
      break;
    case 7:
      state7(win,c);
      break;
  }

}
Example #4
0
void vt_out(int ch)
{
  static unsigned char last_ch;
  int f;
  unsigned char c;
  int go_on = 0;
  wchar_t wc;

  if (!ch)
    return;

  if (last_ch == '\n'
      && vt_line_timestamp != TIMESTAMP_LINE_OFF)
    {
      struct timeval tmstmp_now;
      static time_t tmstmp_last;
      char s[36];
      struct tm tmstmp_tm;

      gettimeofday(&tmstmp_now, NULL);
      if ((   vt_line_timestamp == TIMESTAMP_LINE_PER_SECOND
           && tmstmp_now.tv_sec != tmstmp_last)
          || vt_line_timestamp == TIMESTAMP_LINE_SIMPLE
          || vt_line_timestamp == TIMESTAMP_LINE_EXTENDED)
        {
          if (   localtime_r(&tmstmp_now.tv_sec, &tmstmp_tm)
              && strftime(s, sizeof(s), "[%F %T", &tmstmp_tm))
            {
              output_s(s);
              switch (vt_line_timestamp)
                {
                case TIMESTAMP_LINE_SIMPLE:
                  output_s("] ");
                  break;
                case TIMESTAMP_LINE_EXTENDED:
                  snprintf(s, sizeof(s), ".%03ld] ", tmstmp_now.tv_usec / 1000);
                  output_s(s);
                  break;
                case TIMESTAMP_LINE_PER_SECOND:
                  output_s("\r\n");
                  break;
                };
            }
          tmstmp_last = tmstmp_now.tv_sec;
        }
    }

  c = (unsigned char)ch;
  last_ch = c;

  if (vt_docap == 2) /* Literal. */
    fputc(c, capfp);

  /* Process <31 chars first, even in an escape sequence. */
  switch (c) {
    case 5: /* AnswerBack for vt100's */
      if (vt_type != VT100) {
        go_on = 1;
        break;
      }
      v_termout(P_ANSWERBACK, 0);
      break;
    case '\r': /* Carriage return */
      mc_wputc(vt_win, c);
      if (vt_addlf)
        output_c('\n');
      break;
    case '\t': /* Non - destructive TAB */
      /* Find next tab stop. */
      for (f = vt_win->curx + 1; f < 160; f++)
        if (vt_tabs[f / 32] & (1 << f % 32))
          break;
      if (f >= vt_win->xs)
        f = vt_win->xs - 1;
      mc_wlocate(vt_win, f, vt_win->cury);
      if (vt_docap == 1)
        fputc(c, capfp);
      break;
    case 013: /* Old Minix: CTRL-K = up */
      mc_wlocate(vt_win, vt_win->curx, vt_win->cury - 1);
      break;
    case '\f': /* Form feed: clear screen. */
      mc_winclr(vt_win);
      mc_wlocate(vt_win, 0, 0);
      break;
#if !TRANSLATE
    case 14:
    case 15:  /* Change character set. Not supported. */
      break;
#else
    case 14:
      vt_charset = 1;
      break;
    case 15:
      vt_charset = 0;
      break;
#endif
    case 24:
    case 26:  /* Cancel escape sequence. */
      esc_s = 0;
      break;
    case ESC: /* Begin escape sequence */
      esc_s = 1;
      break;
    case 128+ESC: /* Begin ESC [ sequence. */
      esc_s = 2;
      break;
    case '\n':
      if(vt_addcr)
        mc_wputc(vt_win, '\r');
      output_c(c);
	  break;
    case '\b':
    case 7: /* Bell */
      output_c(c);
      break;
    default:
      go_on = 1;
      break;
  }
  if (!go_on)
    return;

  /* Now see which state we are in. */
  switch (esc_s) {
    case 0: /* Normal character */
      if (vt_docap == 1)
        fputc(P_CONVCAP[0] == 'Y' ? vt_inmap[c] : c, capfp);
      if (!using_iconv()) {
        c = vt_inmap[c];    /* conversion 04.09.97 / jl */
#if TRANSLATE
        if (vt_type == VT100 && vt_trans[vt_charset] && vt_asis == 0)
          c = vt_trans[vt_charset][c];
#endif
      }
      /* FIXME: This is wrong, but making it right would require
       * removing all the 8-bit mapping features. Assuming the locale
       * is 8-bit, the character should not be changed by mapping to
       * wchar and back; if the locale is multibyte, there is no hope
       * of getting it right anyway. */
      if (!using_iconv()) {
        one_mbtowc (&wc, (char *)&c, 1); /* returns 1 */
        if (vt_insert)
          mc_winschar2(vt_win, wc, 1);
        else
          mc_wputc(vt_win, wc);
      } else {
        mc_wputc(vt_win, c);
      }
      break;
    case 1: /* ESC seen */
      state1(c);
      break;
    case 2: /* ESC [ ... seen */
      state2(c);
      break;
    case 3:
      state3(c);
      break;
    case 4:
      state4(c);
      break;
    case 5:
      state5(c);
      break;
    case 6:
      state6(c);
      break;
    case 7:
      state7(c);
      break;
  }

  /* Flush output to capture file so that all output is visible there
   * immediately. Causes a write syscall for every call though. */
  if (capfp)
    fflush(capfp);
}