⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 updown.c

📁 minicom的源码,linux下常用的串口程序.
💻 C
📖 第 1 页 / 共 2 页
字号:
    } else      sleep(1);#else    /* MARK updated 02/17/94 - If there was no VC_MUSIC capability, */    /* then at least make some beeps! */    if (P_SOUND[0] == 'Y')      wprintf(win, "\007\007\007");    sleep(1);#endif  }  if (win)    wclose(win, 1);}/* * Run kermit. Used to do this in the main window, but newer * versions of kermit are too intelligent and just want a tty * for themselves or they won't function ok. Shame. */void kermit(void){  int status;  int pid, n;  char buf[81];  int fd;  /* Clear screen, set keyboard modes etc. */  wleave();  switch (pid = fork()) {    case -1:      wreturn();      werror(_("Out of memory: could not fork()"));      return;    case 0: /* Child */      /* Remove lockfile */      set_privs();      if (lockfile[0])        unlink(lockfile);      setgid((gid_t)real_gid);      setuid((uid_t)real_uid);      for (n = 0; n < _NSIG; n++)        signal(n, SIG_DFL);      fastexec(translate(P_KERMIT));      exit(1);    default: /* Parent */      break;  }  m_wait(&status);  /* Restore screen and keyboard modes */  wreturn();  /* Re-create lockfile */  if (lockfile[0]) {    set_privs();    n = umask(022);    /* Create lockfile compatible with UUCP-1.2 */    if ((fd = open(lockfile, O_WRONLY | O_CREAT | O_EXCL, 0666)) < 0) {      werror(_("Cannot re-create lockfile!"));    } else {      chown(lockfile, (uid_t)real_uid, (gid_t)real_gid);      snprintf(buf, sizeof(buf),  "%05d minicom %.20s\n", (int)getpid(), username);      write(fd, buf, strlen(buf));      close(fd);    }    umask(n);    drop_privs();  }  m_flush(portfd);  port_init();}/* ============ Here begins the setenv function ============= *//* * Compare two strings up to '=' */static int varcmp(const char *s1, const char *s2){  while (*s1 && *s2) {    if (*s1 == '=' && *s2 == '=')      return 1;    if (*s1++ != *s2++)      return 0;  }  return 1;}/* * Generate a name=value string. */static char *makenv(const char *name, const char *value){  char *p;  if ((p = malloc(strlen(name) + strlen(value) + 3)) == NULL)    return p;  sprintf(p, "%s=%s", name, value);  return p;}/* * Set a environment variable. */int mc_setenv(const char *name, const char *value){  static int init = 0;  char *p, **e, **newe;  int count = 0;  if ((p = makenv(name, value)) == NULL)    return -1;  for (e = environ; *e; e++) {    count++;    if (varcmp(p, *e)) {      *e = p;      return 0;    }  }  count += 2;  if ((newe = (char **)malloc(sizeof(char *) * count)) == (char **)0) {    free(p);    return -1;  }  memcpy((char *)newe, (char *)environ , (int) (count * sizeof(char *)));  if (init)    free((char *)environ);  init = 1;  environ = newe;  for(e = environ; *e; e++)    ;  *e++ = p;  *e = NULL;  return 0;}/* ============ This is the end of the setenv function ============= *//* * Run an external script. * ask = 1 if first ask for confirmation. * s = scriptname, l=loginname, p=password. */void runscript(int ask, const char *s, const char *l, const char *p){  int status;  int n;  int pipefd[2];  char buf[81];  char scr_lines[5];  char cmdline[128];  char *ptr;  WIN *w;  int done = 0;  char *msg = _("Same as last");  char *username = _(" A -   Username        :"),       *password = _(" B -   Password        :"),       *name_of_script = _(" C -   Name of script  :"),       *question = _("Change which setting?     (Return to run, ESC to stop)");  if (ask) {    w = wopen(10, 5, 70, 10, BDOUBLE, stdattr, mfcolor, mbcolor, 0, 0, 1);    wtitle(w, TMID, _("Run a script"));    wputs(w, "\n");    wprintf(w, "%s %s\n", username, scr_user[0] ? msg : "");    wprintf(w, "%s %s\n", password, scr_passwd[0] ? msg : "");    wprintf(w, "%s %s\n", name_of_script, scr_name);    wlocate(w, 4, 5);    wputs(w, question);    wredraw(w, 1);    while (!done) {      wlocate(w, mbslen (question) + 5, 5);      n = wxgetch();      if (islower(n))        n = toupper(n);      switch (n) {        case '\r':        case '\n':          if (scr_name[0] == '\0') {            wbell();            break;          }          wclose(w, 1);          done = 1;          break;        case 27: /* ESC */          wclose(w, 1);          return;        case 'A':          wlocate(w, mbslen (username) + 1, 1);          wclreol(w);          scr_user[0] = 0;          wgets(w, scr_user, 32, 32);          break;        case 'B':          wlocate(w, mbslen (password) + 1, 2);          wclreol(w);          scr_passwd[0] = 0;          wgets(w, scr_passwd, 32, 32);          break;        case 'C':          wlocate(w, mbslen (name_of_script) + 1, 3);          wgets(w, scr_name, 32, 32);          break;        default:          break;      }    }  } else {    strncpy(scr_user, l, sizeof(scr_user));    strncpy(scr_name, s, sizeof(scr_name));    strncpy(scr_passwd, p, sizeof(scr_passwd));  }  sprintf(scr_lines, "%d", (int) lines);  /* jl 13.09.97 */  /* Throw away status line if temporary */  if (tempst) {    wclose(st, 1);    tempst = 0;    st = NULL;  }  scriptname(scr_name);    pipe(pipefd);  if (mcd(P_SCRIPTDIR) < 0)    return;  snprintf(cmdline, sizeof(cmdline), "%s %s %s %s",           P_SCRIPTPROG, scr_name, logfname, logfname[0]==0? "": homedir);  switch (udpid = fork()) {    case -1:      werror(_("Out of memory: could not fork()"));      close(pipefd[0]);      close(pipefd[1]);      mcd("");      return;    case 0: /* Child */      dup2(portfd, 0);      dup2(portfd, 1);      dup2(pipefd[1], 2);      close(pipefd[0]);      close(pipefd[1]);      for (n = 1; n < _NSIG; n++)	signal(n, SIG_DFL);      set_privs();      setgid((gid_t)real_gid);      setuid((uid_t)real_uid);      mc_setenv("LOGIN", scr_user);      mc_setenv("PASS", scr_passwd);      mc_setenv("TERMLIN", scr_lines);	/* jl 13.09.97 */      fastexec(translate(cmdline));      exit(1);    default: /* Parent */      break;  }  setcbreak(1); /* Cbreak, no echo */  enab_sig(1, 0);	       /* But enable SIGINT */  signal(SIGINT, udcatch);  close(pipefd[1]);    /* pipe output from "runscript" program to terminal emulator */  while ((n = read(pipefd[0], buf, 80)) > 0) {    ptr = buf;    while (n--)      vt_out(*ptr++);    timer_update();    wflush();  }    /* Collect status, and clean up. */  m_wait(&status);  enab_sig(0, 0);  signal(SIGINT, SIG_IGN);  setcbreak(2); /* Raw, no echo */  close(pipefd[0]);  scriptname("");  mcd("");}/** Paste text file to console/serial line. Avoid ascii-xfer problem of * swallowing up status messages returned via the serial line.* This is especially useful for Embedded Microprocessor Development Kits* that use raw file transfer mode (no protocols) to download text encoded* executable files (eg., in S-Record or Intel Hex formats)** TC Wan <tcwan@cs.usm.my> 2003-10-18*/int paste_file(void){  FILE *fp;  char line[1024];  char *s;  const int dotrans = 0;  const int ldelay = 1;      /* hardcoded 1 ms */  char buf[128] = "";  char *ptr;  int blen;  unsigned long bdone = 0;  int x;  if ((s = filedir(1, 0)) == NULL)    return 0;  if ((fp = fopen(s, "r")) == NULL) {    perror(s);    return -1;  }  while (fgets(line, sizeof(line), fp)) {    /* 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)) {      ptr = buf;      while (blen-- > 0) {	if (P_PARITY[0] == 'M' || P_PARITY[0] == 'S')	  *ptr &= 0x7f;	vt_out(*ptr++);      }      wflush();    }    if (dotrans && (s = strrchr(line, '\n')) != NULL) {      if (s > line && *(s - 1) == '\r')	s--;      *s = 0;      s = line;      for (s = line; *s; s++)	vt_send(*s);      vt_send('\r');      vt_send('\n');      bdone += strlen(line) + 2;    } else {      for (s = line; *s; s++)	vt_send(*s);      bdone += strlen(s);    }    if (ldelay) {#ifdef HAVE_USLEEP      usleep(ldelay * 1000);#endif    }  }  fclose(fp);  return 0;}

⌨️ 快捷键说明

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