Exemple #1
0
/* process function for help_state=0 */
static void help_send_escape(int fd, char c) { 
  struct  termios pts;  /* termios settings on port */

  in_escape = 0;
  help_state = 0;
  
  switch (c) {
  case 'x':
    /* restore termios settings and exit */
    write(STDOUT_FILENO, "\n", 1);
    cleanup_termios(0);
    break;
  case 'q': /* quit help */
    break;
  case 'l': /* log on/off */    
    if (flog == 0) { /* open log file */
      open_logFile(log_file);
    }
    else { /* close log file */
      close_logFile();
    }
    break;
  case 's': /* script active/inactive */
    script_init(scr_name);
    script = (script)? 0: 1;
    break;
  case 'b': /* send break */
    /* send a break */
    tcsendbreak(fd, 0);
    break;
  case 't': /* set terminal */
    help_state = 1;
    help_terminal();
    in_escape = 1;
    break;
  case '~': /* display it again */
    help_escape();
    break;
  default:
    /* pass the character through */
    /* "C-\ C-\" sends "C-\" */
    write(fd, &c, 1);
    break;
  }

  if (in_escape == 0)
    help_done();

  return;
}
Exemple #2
0
/* handle escape characters, writing to output */
void cook_buf(int fd, char *buf, int num) { 
  int current = 0;
  
  if (in_escape) {
    /* cook_buf last called with an incomplete escape sequence */
    switch (help_state) {
    case 0:
      help_send_escape(fd, buf[0]);
      break;
    case 1:
      help_set_terminal(fd, buf[0]);
      break;
    default:
      help_set_speed(fd, buf[0]);
    }
    num--; /* advance to the next character in the buffer */
    buf++; 
  }

  while (current < num) { /* big while loop, to process all the charactes in buffer */

    /* look for the next escape character '~' */
    while ((current < num) && (buf[current] != 0x7e)) current++;
    /* and write the sequence before esc char to the comm port */
    if (current) {
      DEBUG_DUMP_MEMORY(buf,current);
      const ssize_t written = write (fd, buf, current);
      if (written == -1) {
	const int error = errno;
	ERROR_MSG("error writting to device %d (%m)",error);
      } else if (written != current) {
	ERROR_MSG("error writting to device only %d bytes written",written);
      }
    }

    if (current < num) { /* process an escape sequence */
      /* found an escape character */
      if (help_state == 0) {
	help_escape();
      }
      current++;
      if (current >= num) {
	/* interpret first character of next sequence */
	in_escape = 1;
	return;
      }

      switch (help_state) {
      case 0:
	help_send_escape(fd, buf[current]);
	break;
      case 1:
	help_set_terminal(fd, buf[current]);
	break;
      default:
 	help_set_speed(fd, buf[current]);
      } /* end switch */
      current++;
      if (current >= num)
	return;
    } /* if - end of processing escape sequence */
    num -= current;
    buf += current;
    current = 0;
  } /* while - end of processing all the charactes in the buffer */
  return;
}
Exemple #3
0
/* handle escape characters, writing to output */
void cook_buf(struct ios_ops *ios, unsigned char *buf, int num)
{
    int current = 0;

    if (in_escape) {
        /* cook_buf last called with an incomplete escape sequence */
        switch (help_state) {
        case 0:
            help_send_escape(ios, buf[0]);
            break;
        case 1:
            help_set_terminal(ios, buf[0]);
            break;
        default:
            help_set_speed(ios, buf[0]);
        }
        num--;		/* advance to the next character in the buffer */
        buf++;
    }

    while (current < num) {	/* big while loop, to process all the charactes in buffer */

        /* look for the next escape character '~' */
        while ((current < num) && (buf[current] != 28))
            current++;
        /* and write the sequence befor esc char to the comm port */
        if (current)
        {
            if (in_echo)
            {
                write(STDOUT_FILENO, buf, current);	/* echo */
            }

            if (!in_line)
                write(ios->fd, buf, current);
            else
                writeline(ios->fd, buf, current);
        }

        if (current < num) {	/* process an escape sequence */
            /* flush buffers */
            fflush(stdout);
            if (in_line)
                flushline(ios->fd);
            /* found an escape character */
            if (help_state == 0)
                help_escape();
            current++;
            if (current >= num) {
                /* interpret first character of next sequence */
                in_escape = 1;
                return;
            }

            switch (help_state) {
            case 0:
                help_send_escape(ios, buf[current]);
                break;
            case 1:
                help_set_terminal(ios, buf[current]);
                break;
            default:
                help_set_speed(ios, buf[current]);
            }	/* end switch */
            current++;
            if (current >= num)
                return;
        }		/* if - end of processing escape sequence */
        num -= current;
        buf += current;
        current = 0;
    }			/* while - end of processing all the charactes in the buffer */
    return;
}
Exemple #4
0
/* process function for help_state=0 */
static void help_send_escape(struct ios_ops *ios, char c)
{
    struct winsize win;
    char buf[100];
    int sz;

    in_escape = 0;
    help_state = 0;

    switch (c) {
    case 'q':		/* quit help */
    case 'x':
        /* restore termios settings and exit */
        write(STDOUT_FILENO, "\n", 1);
        microcom_exit(0);
        break;
    case 'l':		/* log on/off */
        dolog = (dolog == 0) ? 1 : 0;
        if (dolog) {	/* open log file */
            if ((flog = fopen("microcom.log", "a")) == (FILE *) 0) {
                write(STDOUT_FILENO,
                      "Cannot open microcom.log \n", 26);
                dolog = 0;
            }
        } else {	/* cloase log file */
            fflush(flog);
            fclose(flog);
        }
        break;
    case 'b':		/* send break */
        /* send a break */
        tcsendbreak(ios->fd, 0);
        break;
    case 't':		/* set terminal */
        help_state = 1;
        help_terminal();
        in_escape = 1;
        break;
    case 'o':		/* echo mode */
        in_echo = !in_echo;
        if (in_echo)
            printf("echo mode ON\n");
        else
            printf("echo mode OFF\n");
        break;
    case 'i':		/* input line mode */
        in_line = !in_line;
        if (in_line)
            printf("line mode ON\n");
        else
            printf("line mode OFF\n");
        break;
    case 'h':		/* output hex mode */
        out_hex = !out_hex;
        if (out_hex)
            printf("hex mode ON\n");
        else
            printf("hex mode OFF\n");
        break;
    case '~':		/* display it again */
        help_escape();
        break;
    case 'w':
        if(ioctl(0, TIOCGWINSZ, &win))
            break;

        sz = sprintf(buf, "stty rows %d cols %d\n", win.ws_row, win.ws_col);
        write(ios->fd, &buf, sz);
        break;
    case 'e':
        break;
    default:
        printf("unknown command '%c'\n",c);
        break;
    }

    if (in_escape == 0)
        help_done();

    return;
}