예제 #1
0
파일: help.c 프로젝트: Jin-W-FS/microcom
/* handle a single escape character */
static void help_set_speed(struct ios_ops *ios, char c)
{
    speed_t speed[] = {
        B1200,
        B2400,
        B4800,
        B9600,
        B19200,
        B38400,
        B57600,
        B115200,
        B230400,
        B460800
    };


    if (c < 'a' && c > 'j') {
        if (c == '~') {
            help_speed();
            return;
        } else if (c == 'q') {
            in_escape = 0;
            help_state = 0;
        }
        write(ios->fd, &c, 1);
        return;
    }

    ios->set_speed(ios, speed[c - 'a']);

    in_escape = 0;
    help_state = 0;
    help_done();
}
예제 #2
0
파일: help.c 프로젝트: Jin-W-FS/microcom
/* process function for help_state=1 */
static void help_set_terminal(struct ios_ops *ios, char c)
{
    struct termios pts;	/* termios settings on port */
    tcgetattr(ios->fd, &pts);
    switch (c) {
    case 'm':		/* CR/NL mapping */
        in_escape = 0;	/* get it out from escape state */
        help_state = 0;
        if (crnl_mapping) {
            pts.c_oflag &= ~ONLCR;
            crnl_mapping = 0;
        } else {
            pts.c_oflag |= ONLCR;
            crnl_mapping = 1;
        }
        tcsetattr(ios->fd, TCSANOW, &pts);
        break;
    case 'p':		/* port speed */
        in_escape = 1;
        help_state = 2;
        help_speed();
        break;
    case 'h':		/* hardware flow control */
        in_escape = 0;	/* get it out from escape state */
        help_state = 0;
        ios->set_flow(ios, FLOW_HARD);
        /* hardware flow control */
        break;
    case 's':		/* software flow contrlol */
        in_escape = 0;	/* get it out from escape state */
        help_state = 0;
        ios->set_flow(ios, FLOW_SOFT);
        /* software flow control */
        break;
    case 'n':		/* no flow control */
        in_escape = 0;	/* get it out from escape state */
        help_state = 0;
        /* no flow control */
        ios->set_flow(ios, FLOW_NONE);
        break;
    case '~':
    case 'q':
        in_escape = 0;
        help_state = 0;
        break;
    default:
        /* pass the character through */
        /* "C-\ C-\" sends "C-\" */
        write(ios->fd, &c, 1);
        break;
    }

    if (in_escape == 0)
        help_done();

    return;
}
예제 #3
0
파일: help.c 프로젝트: checko/microcom
/* 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;
}
예제 #4
0
파일: help.c 프로젝트: checko/microcom
/* handle a single escape character */
static void help_set_speed(int fd, char c) { 
  struct  termios pts;  /* termios settings on port */
  speed_t speed[] = {
    B1200,
    B2400,
    B4800,
    B9600,
    B19200,
    B38400,
    B57600,
    B115200,
    B230400,
    B460800
  };

  if (c < 'a' && c > 'j') {
    if (c == '~') {
      help_speed();
      return;
    }
    else if (c == 'q') {
      in_escape = 0;
      help_state = 0;
    }
    write(fd, &c, 1);
    return;
  }

  tcgetattr(fd, &pts);
  cfsetospeed(&pts, speed[c - 'a']);
  cfsetispeed(&pts, speed[c - 'a']);
  tcsetattr(fd, TCSANOW, &pts);
  in_escape = 0;
  help_state = 0;
  help_done();
}
예제 #5
0
파일: help.c 프로젝트: checko/microcom
/* process function for help_state=1 */
static void help_set_terminal(int fd, char c) { 
  struct  termios pts;  /* termios settings on port */
  tcgetattr(fd, &pts);
  switch (c) {
  case 'm': /* CR/NL mapping */
    in_escape = 0; /* get it out from escape state */
    help_state = 0;
    if (crnl_mapping) {
      pts.c_oflag &= ~ONLCR;
      crnl_mapping = 0;      
    } else { 
      pts.c_oflag |= ONLCR;
      crnl_mapping = 1;
    }
    DEBUG_MSG("Map CarriageReturn to NewLine on output = %d",crnl_mapping);
    tcsetattr(fd, TCSANOW, &pts);
    break;
  case 'p': /* port speed */
    in_escape = 1;
    help_state = 2;
    help_speed();
    break;
  case 'h': /* hardware flow control */
    in_escape = 0; /* get it out from escape state */
    help_state = 0;
    /* hardware flow control */
    pts.c_cflag |= CRTSCTS;
    pts.c_iflag &= ~(IXON | IXOFF | IXANY);
    tcsetattr(fd, TCSANOW, &pts);
    break;
  case 's': /* software flow contrlol */
    in_escape = 0; /* get it out from escape state */
    help_state = 0;
    /* software flow control */
    pts.c_cflag &= ~CRTSCTS;
    pts.c_iflag |= IXON | IXOFF | IXANY;
    tcsetattr(fd, TCSANOW, &pts);
    break;
  case 'n': /* no flow control */
    in_escape = 0; /* get it out from escape state */
    help_state = 0;
    /* no flow control */
    pts.c_cflag &= ~CRTSCTS;
    pts.c_iflag &= ~(IXON | IXOFF | IXANY);
    tcsetattr(fd, TCSANOW, &pts);
    break;
  case '~':
  case 'q':
    in_escape = 0;
    help_state = 0;
    break;
  default:
    /* pass the character through */
    /* "C-\ C-\" sends "C-\" */
    write(fd, &c, 1);
    break;
  }

  if (in_escape == 0)
    help_done();

  return;
}
예제 #6
0
파일: help.c 프로젝트: Jin-W-FS/microcom
/* 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;
}