main.c

来自「minicom的源码,linux下常用的串口程序.」· C语言 代码 · 共 779 行 · 第 1/2 页

C
779
字号
    if (use_status) {      ypos = LINES;      maxy = LINES - 1;    } else {      ypos = LINES - 1;      maxy = LINES - 2;    }    st = wopen(0, ypos, COLS - 1, ypos, BNONE,               st_attr, sfcolor, sbcolor, 1, 0, 1);    wredraw(st, 1);  }  /* MARK updated 02/17/95 - Customizable size for history buffer */  num_hist_lines = atoi(P_HISTSIZE);  if (num_hist_lines < 0)    num_hist_lines = 0;  if (num_hist_lines > 5000)    num_hist_lines = 5000;  /* Open a new main window, and define the configured history buffer size. */  us = wopen(0, 0, COLS - 1, maxy,              BNONE, XA_NORMAL, tfcolor, tbcolor, 1, num_hist_lines, 0);  if (x >= 0) {    wlocate(us, x, y);    wsetattr(us, attr);  }  us->autocr = 0;  us->wrap = wrapln;  terminal = type;  lines = LINES - (st != NULL);  cols = COLS;  /* Install and reset the terminal emulator. */  if (do_init) {    vt_install(do_output, kb_handler, us);    vt_init(type, tfcolor, tbcolor, us->wrap, addlf);  } else    vt_pinit(us, -1, -1);  if (st)    show_status();}/* * Locate the cursor at the correct position in * the user screen. */static void ret_csr(void){  wlocate(us, us->curx, us->cury);  wflush();}/* * Show baudrate, parity etc. */void mode_status(void){  if (st) { /* if swich off status line - NOT print !!! (vlk@st.simbirsk.su) */    wlocate(st, 20, 0);    if (portfd_is_socket) {      wprintf(st, "unix-socket");    } else {      if (P_SHOWSPD[0] == 'l')        wprintf(st, "%6ld %s%s%s", linespd, P_BITS, P_PARITY, P_STOPB);      else        wprintf(st, "%6.6s %s%s%s", P_BAUDRATE, P_BITS, P_PARITY, P_STOPB);    }    ret_csr();  }}/* * Show offline or online time. * If real dcd is not supported, Online and Offline will be * shown in capitals. */void time_status(void){  if (!st || disable_online_time)    return;  wlocate(st, 63, 0);  if (online < 0)    wprintf(st, " %12.12s ", P_HASDCD[0] == 'Y' ? _("Offline") : _("OFFLINE"));  else    wprintf(st, " %s %02ld:%02ld", P_HASDCD[0] == 'Y' ? _("Online") : _("ONLINE"),            online / 3600, (online / 60) % 60);  ret_csr();}/* * Show in which mode the cursor keys are (normal or application) */void curs_status(void){  wlocate(st, 33, 0);  wprintf(st, cursormode == NORMAL ? "NOR" : "APP");  ret_csr();}time_t old_online = -1;/* * Update the online time. */static void updtime(void){  if (old_online == online)    return;  if ((P_LOGCONN[0] == 'Y') && (old_online >= 0) && (online < 0)) {    do_log(_("Gone offline (%ld:%02ld:%02ld)"),           old_online / 3600, (old_online / 60) % 60, old_online % 60);  }  old_online = online;  if (st) {    time_status();    ret_csr();  }  wflush();}/* Update the timer display. This can also be called from updown.c */void timer_update(void){  static time_t t1, start;  int dcd_support = P_HASDCD[0] == 'Y';  /* See if we're online. */  if ((!dcd_support && bogus_dcd) || (dcd_support && m_getdcd(portfd))) {    /* We are online at the moment. */    if (online < 0) {      /* This was a transition from off to online */      time(&start);      t1 = start;      online = 0;      updtime();#ifdef _DCDFLOW      /* DCD has gotten high, we can turn on hw flow control */      if (P_HASRTS[0] == 'Y')        m_sethwf(portfd, 1);#endif    }  } else {    /* We are offline at the moment. */#ifdef _DCDFLOW    if (online >= 0) {      /* DCD has dropped, turn off hw flow control. */      m_sethwf(portfd, 0);    }#endif    if (online >= 0 && old_online >= 0) {      /* First update the timer for call duration.. */      time(&t1);      online = t1 - start;      updtime();    }    /* ..and THEN notify that we are now offline */    online = -1;    updtime();  }  /* Update online time */  if (online >= 0) {    time(&t1);    online = t1 - start;    if (online > (old_online + 59))      updtime();  }}/* * Show the status line  */void show_status(void){  st->direct = 0;  wlocate(st, 0, 0);  wprintf(st,          _(" %7.7sZ for help |           |     | Minicom %-6.6s |       | "),          esc_key(), VERSION);  mode_status();  time_status();  curs_status();  wlocate(st, 56, 0);  switch(terminal) {    case VT100:      wputs(st, "VT102");      break;    case ANSI:      wputs(st, "ANSI");      break;  }  wredraw(st, 1);  ret_csr();}/* * Show the name of the script running now. */void scriptname(const char *s){  if (st == NULL)    return;  wlocate(st, 39, 0);  if (*s == 0)    wprintf(st, "Minicom %-6.6s", VERSION);  else    wprintf(st, "script %-7.7s", s);  ret_csr();}/* * Show status line temporarily */static void showtemp(void){  if (st)    return;  st = wopen(0, LINES - 1, COLS - 1, LINES - 1,             BNONE, st_attr, sfcolor, sbcolor, 1, 0, 1);  show_status();  tempst = 1;}/* * The main terminal loop: *	- If there are characters recieved send them *	  to the screen via the appropriate translate function. */int do_terminal(void){  char buf[128];  char *ptr;  int c;  int x;  int blen;  int zauto = 0;  static const char zsig[] = "**\030B00";  int zpos = 0;  const char *s;  dirflush = 0;dirty_goto:  /* Show off or online time */  updtime();  /* If the status line was shown temporarily, delete it again. */  if (tempst) {    tempst = 0;    wclose(st, 1);    st = NULL;  }  /* Auto Zmodem? */  if (P_PAUTO[0] >= 'A' && P_PAUTO[0] <= 'Z')    zauto = P_PAUTO[0];  /* Set the terminal modes */  setcbreak(2); /* Raw, no echo */  keyboard(KSTART, 0);  /* Main loop */  while (1) {    /* See if window size changed */    if (size_changed) {      size_changed = 0;#if 1      /* I got the resize code going again! Yeah! */      wclose(us, 0);      us = NULL;      if (st)        wclose(st, 0);      st = NULL;      wclose(stdwin, 0);      if (win_init(tfcolor, tbcolor, XA_NORMAL) < 0)        leave(_("Could not re-initialize window system."));      /* Set the terminal modes */      setcbreak(2); /* Raw, no echo */      init_emul(terminal, 0);#else      werror(_("Resize not supported, screen may be messed up!"));#endif    }    /* Update the timer. */    timer_update();    /* Check for I/O or timer. */    x = check_io(portfd_connected, 0, 1000, buf, &blen);    /*  Send data from the modem to the screen. */    if ((x & 1) == 1) {      ptr = buf;      while (blen-- > 0) {        /* Auto zmodem detect */        if (zauto) {          if (zsig[zpos] == *ptr)            zpos++;          else            zpos = 0;        }        if (P_PARITY[0] == 'M' || P_PARITY[0] == 'S')          *ptr &= 0x7f;        vt_out(*ptr++);        if (zauto && zsig[zpos] == 0) {          dirflush = 1;          keyboard(KSTOP, 0);          updown('D', zauto - 'A');          dirflush = 0;          zpos = 0;          blen = 0;          goto dirty_goto;        }      }      wflush();    }    /* Read from the keyboard and send to modem. */    if ((x & 2) == 2) {      /* See which key was pressed. */      c = keyboard(KGETKEY, 0);      if (c < 0) /* XXX - shouldn't happen */        c += 256;      /* Was this a command key? */      if ((escape == 128 && c > 224 && c < 252) ||          (escape != 27 && c == escape) ||          (c > K_META)) {        /* Stop keyserv process if we have it. */        keyboard(KSTOP, 0);        /* Show status line temporarily */        showtemp();        if (c == escape) /* CTRL A */          c = keyboard(KGETKEY, 0);        /* Restore keyboard modes */        setcbreak(1); /* Cbreak, no echo */        if (c > K_META)          c -= K_META;        if (c > 128)          c -= 128;        if (c > ' ') {          dirflush = 1;          m_flush(0);          return c;        }        /* CTRLA - CTRLA means send one CTRLA */#if 0        write(portfd, &c, 1);#else        vt_send(c);#endif        goto dirty_goto;      }      /* No, just a key to be sent. */      if (c >= K_F1 && c <= K_F10 && P_MACENAB[0] == 'Y') {        s = "";        switch(c) {          case K_F1: s = P_MAC1; break;          case K_F2: s = P_MAC2; break;          case K_F3: s = P_MAC3; break;          case K_F4: s = P_MAC4; break;          case K_F5: s = P_MAC5; break;          case K_F6: s = P_MAC6; break;          case K_F7: s = P_MAC7; break;          case K_F8: s = P_MAC8; break;          case K_F9: s = P_MAC9; break;          case K_F10: s = P_MAC10; break;        }        if (*s)          mputs(s, 1);        else          vt_send(c);      } else        vt_send(c);    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?