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

📄 minicom.c

📁 minicom的源码,linux下常用的串口程序.
💻 C
📖 第 1 页 / 共 3 页
字号:
        wlocate(b_st, 0, 0); /* move back to column 0! */        wprintf(b_st, hline); /* and show the above-defined hline */        wredraw(b_st, 1); /* again... */        /* highlight any matches */        if (wcslen(look_for) > 1) {          hit = find_next(us, b_us, y, look_for, case_matters);          if (hit == -1) {            wbell();            wflush();            hit = 0;            break;          }          drawhist_look(b_us, hit, 1, look_for, case_matters);          y = hit;        } else {          wbell();          break;        }        wflush();        break;        /*         * fmg 8/22/97         * Take care of the Next Hit key...         * Popup an error window if no previous... why not start a new         * search? How do we know which case-importance they wanted?         */      case 'n':      case 'N':        /* highlight NEXT match */        if (citemode)          break;        if (wcslen(look_for) > 1) {          hit = find_next(us, b_us, y, look_for, case_matters);          if (hit == -1) {            wbell();            wflush();            hit = 0;            break;          }          drawhist_look(b_us, hit, 1, look_for, case_matters);          y = hit;        } else	{ /* no search pattern... */          wbell();          werror(_("No previous search!\n  Please 's' or 'S' first!"));        }        wflush();        break;      case 'u':      case 'U':      case K_UP:        if (citemode && cite_y) {          cite_y--;          if (cite_ystart != 1000000) {            cite_yend = y + cite_y;            drawcite(b_us, cite_y+1, y, cite_ystart, cite_yend);            drawcite(b_us, cite_y, y, cite_ystart, cite_yend);          }          wlocate(b_us, 0, cite_y);          break;        }        if (y <= 0)          break;        y--;        if (cite_ystart != 1000000)          cite_yend = y + cite_y;        wscroll(b_us, S_DOWN);        /*         * fmg 8/20/97         * This is needed so that the movement in window will HIGHLIGHT         * the lines that have the pattern we wanted... it's just nice.         * This almost beggs for a function :-)         */        if (citemode) {          inverse = (y+cite_y >= cite_ystart && y+cite_y <= cite_yend);        } else {          tmp_e = getline(b_us, y);          if (wcslen(look_for) > 1) {            /* quick scan for pattern match */            wdrawelm_var(b_us, tmp_e, tmp_line);            inverse = (wcslen(tmp_line)>1 &&                         StrStr(tmp_line, look_for, case_matters));          } else            inverse = 0;        }        if (inverse)          wdrawelm_inverse(b_us, 0, getline(b_us, y));        else          wdrawelm(b_us, 0, getline(b_us, y));        if (citemode)          wlocate(b_us, 0, cite_y);        wflush();        break;      case 'd':      case 'D':      case K_DN:        if (citemode && cite_y < b_us->ys-1) {          cite_y++;          if (cite_ystart != 1000000) {            cite_yend = y + cite_y;            drawcite(b_us, cite_y-1, y, cite_ystart, cite_yend);            drawcite(b_us, cite_y, y, cite_ystart, cite_yend);          }          wlocate(b_us, 0, cite_y);          break;        }        if (y >= us->histlines)          break;        y++;        if (cite_ystart != 1000000)          cite_yend = y + cite_y;        wscroll(b_us, S_UP);        /*         * fmg 8/20/97         * This is needed so that the movement in window will HIGHLIGHT         * the lines that have the pattern we wanted... it's just nice.         * This almost beggs for a function :-)         */        if (citemode) {          inverse = (y+cite_y >= cite_ystart && y+cite_y <= cite_yend);        } else {          tmp_e = getline(b_us, y + b_us->ys - 1);          if (wcslen(look_for) > 1) {            /* quick scan for pattern match */            wdrawelm_var(b_us, tmp_e, tmp_line);            inverse = (wcslen(tmp_line)>1 &&                         StrStr(tmp_line, look_for, case_matters));          } else            inverse = 0;        }        if (inverse)          wdrawelm_inverse(b_us, b_us->ys - 1,                           getline(b_us, y + b_us->ys - 1));        else          wdrawelm(b_us, b_us->ys - 1,                   getline(b_us, y + b_us->ys - 1));        if (citemode)          wlocate(b_us, 0, cite_y);        wflush();        break;      case 'b':      case 'B':      case K_PGUP:        if (y <= 0)          break;        y -= b_us->ys;        if (y < 0)          y = 0;        if (cite_ystart != 1000000)          cite_yend = y + cite_y;        /*         * fmg 8/20/97         * This is needed so that the movement in window will HIGHLIGHT         * the lines that have the pattern we wanted... it's just nice.         * Highlight any matches         */        if (wcslen(look_for) > 1 && us->histline)          drawhist_look(b_us, y, 1, look_for, case_matters);        else          drawhist(b_us, y, 1);        if (citemode)          wlocate(b_us, 0, cite_y);        break;      case 'f':      case 'F':      case ' ': /* filipg: space bar will go page-down... pager-like */      case K_PGDN:        if (y >= us->histlines)          break;        y += b_us->ys;        if (y > us->histlines)          y=us->histlines;        if (cite_ystart != 1000000)          cite_yend = y + cite_y;        /*         * fmg 8/20/97         * This is needed so that the movement in window will HIGHLIGHT         * the lines that have the pattern we wanted... it's just nice.         * Highlight any matches         */        if (wcslen(look_for) > 1 && us->histline)          drawhist_look(b_us, y, 1, look_for, case_matters);        else          drawhist(b_us, y, 1);        if (citemode)          wlocate(b_us, 0, cite_y);        break;      case 'C': case 'c': /* start citation mode */        if (citemode ^= 1) {          cite_y = 0;          cite_ystart = 1000000;          cite_yend = -1;          strcpy(hline1, _("  CITATION: ENTER=select start line ESC=exit                               "));          if (b_st->xs < 127)            hline1[b_st->xs]=0;          hline = hline1;        } else {          hline = hline0;        }        wlocate(b_st, 0, 0);        wprintf(b_st, hline);        wredraw(b_st, 1);        if (citemode)          wlocate(b_us, 0, cite_y);        break;      case 10: case 13:        if (!citemode) break;        if (cite_ystart == 1000000) {          cite_yend = cite_ystart = y + cite_y;          strcpy(hline1, _("  CITATION: ENTER=select end line ESC=exit                                 "));          if (b_st->xs < 127)            hline1[b_st->xs]=0;        } else {          if (cite_ystart > cite_yend)            break;          drawcite_whole(b_us, y, 1000000, -1);          loop = 0;          break;        }        wlocate(b_st, 0, 0);        wprintf(b_st, hline);        wredraw(b_st, 1);        wdrawelm_inverse(b_us, cite_y, getline(b_us, cite_ystart));        wlocate(b_us, 0, cite_y);        break;      case K_ESC:        if (!citemode) {          loop = 0;          break;        }        if (cite_ystart == 1000000) {          citemode = 0;          hline = hline0;        } else {          cite_ystart = 1000000;          strcpy(hline1, _("  CITATION: ENTER=select start line ESC=exit                               "));        }        drawcite_whole(b_us, y, cite_ystart, cite_yend);        wlocate(b_st, 0, 0);        wprintf(b_st, hline);        wredraw(b_st, 1);        if (citemode)          wlocate(b_us, 0, cite_y);        break;    }  }  /* Cleanup. */  if (citemode)    do_cite(b_us, cite_ystart, cite_yend);  wclose(b_us, y == us->histlines ? 0 : 1);  wclose(b_st, 1);  wlocate(us, us->curx, us->cury);  wflush();  wredraw(us, 1);}#ifdef SIGWINCH/* The window size has changed. Re-initialize. */static void change_size(int sig){  (void)sig;  size_changed = 1;  signal(SIGWINCH, change_size);}#endif /*SIGWINCH*//* * Read a word from strings 's' and advance pointer. */static char *getword(char **s){  char *begin;  /* Skip space */  while (**s == ' ' || **s == '\t')    (*s)++;  /* End of line? */  if (**s == '\0' || **s == '\n')    return NULL;  begin = *s;  /* Skip word */  while (**s != ' ' && **s != '\t' && **s != '\n' && **s)    (*s)++;  /* End word with '\0' */  if (**s) {    **s = 0;    (*s)++;  }  return begin;}static void usage(int env_args, int optind, char *mc){  if (env_args >= optind && mc)    fprintf(stderr, _("Wrong option in environment MINICOM=\"%s\"\n"), mc);  fprintf(stderr, _("Type \"minicom %s\" for help.\n"), "--help");  exit(1);}/* Give some help information */static void helpthem(void){  char *mc = getenv("MINICOM");  printf(_(    "Usage: %s [OPTION]... [configuration]\n"    "A terminal program for Linux and other unix-like systems.\n\n"    "  -s, --setup            : enter setup mode (only as root)\n"    "  -o, --noinit           : do not initialize modem & lockfiles at startup\n"    "  -m, --metakey          : use meta or alt key for commands\n"    "  -M, --metakey8         : use 8bit meta key for commands\n"    "  -l, --ansi             : literal; assume screen uses non IBM-PC character set\n"    "  -L, --iso              : don't assume screen uses ISO8859\n"    "  -w, --wrap             : Linewrap on\n"    "  -z, --statline         : try to use terminal's status line\n"    "  -7, --7bit             : force 7bit mode\n"    "  -8, --8bit             : force 8bit mode\n"    "  -c, --color=on/off     : ANSI style color usage on or off\n"    "  -a, --attrib=on/off    : use reverse or highlight attributes on or off\n"    "  -t, --term=TERM        : override TERM environment variable\n"    "  -S, --script=SCRIPT    : run SCRIPT at startup\n"    "  -d, --dial=ENTRY       : dial ENTRY from the dialing directory\n"    "  -p, --ptty=TTYP        : connect to pseudo terminal\n"    "  -C, --capturefile=FILE : start capturing to FILE\n"    "  -T, --disabletime      : disable display of online time\n"    "  -v, --version          : output version information and exit\n"    "  configuration          : configuration file to use\n\n"    "These options can also be specified in the MINICOM environment variable.\n"),    PACKAGE);  if (mc) {    printf(_("This variable is currently set to \"%s\".\n"), mc);  } else {    printf(_("This variable is currently unset.\n"));  }  printf(_(    "The configuration directory for the access file and the configurations\n"    "is compiled to %s.\n\n"    "Report bugs to <minicom-devel@lists.alioth.debian.org>.\n"), CONFDIR);}/* Toggle linefeed addition.  Can be called through the menu, or by a macro. */void toggle_addlf(void){  addlf = !addlf;  vt_set(addlf, -1, NULL, -1, -1, -1, -1, -1);}/* Toggle local echo.  Can be called through the menu, or by a macro. */void toggle_local_echo(void){  local_echo = !local_echo;  vt_set(-1, -1, NULL, -1, -1, local_echo, -1 ,-1);}int main(int argc, char **argv){  int c;			/* Command character */  int quit = 0;			/* 'q' or 'x' pressed */  char *s, *bufp;		/* Scratch pointers */  int dosetup = 0, doinit = 1;	/* -o and -s options */  char buf[80];			/* Keyboard input buffer */  char capname[128];		/* Name of capture file */  struct passwd *pwd;		/* To look up user name */  int userok = 0;		/* Scratch variables */  FILE *fp;			/* Scratch file pointer */  char userfile[256];		/* Locate user file */  char *use_port;		/* Name of initialization file */  char *args[20];		/* New argv pointer */  int argk = 1;			/* New argc */  char *mc;			/* For 'MINICOM' env. variable */  int env_args;			/* Number of args in env. variable */  char *cmd_dial;		/* Entry from the command line. */  int alt_code = 0;		/* Type of alt key */  char pseudo[64];  /* char* console_encoding = getenv ("LC_CTYPE"); */  static struct option long_options[] =  {    { "setup",       no_argument,       NULL, 's' },    { "help",        no_argument,       NULL, 'h' },    { "ptty",        required_argument, NULL, 'p' },    { "metakey",     no_argument,       NULL, 'm' },    { "metakey8",    no_argument,       NULL, 'M' },    { "ansi",        no_argument,       NULL, 'l' },    { "iso",         no_argument,       NULL, 'L' },    { "term",        required_argument, NULL, 't' },    { "noinit",      no_argument,       NULL, 'o' },    { "color",       required_argument, NULL, 'c' },    { "attrib",      required_argument, NULL, 'a' },    { "dial",        required_argument, NULL, 'd' },    { "statline",    no_argument,       NULL, 'z' },    { "capturefile", required_argument, NULL, 'C' },    { "script",      required_argument, NULL, 'S' },    { "7bit",        no_argument,       NULL, '7' },    { "8bit",        no_argument,       NULL, '8' },    { "version",     no_argument,       NULL, 'v' },    { "wrap",        no_argument,       NULL, 'w' },    { "disabletime", no_argument,       NULL, 'T' },    { NULL, 0, NULL, 0 }  };  /* initialize locale support */  setlocale(LC_ALL, "");  bindtextdomain(PACKAGE, LOCALEDIR);  textdomain(PACKAGE);  /* Initialize global variables */  portfd =  -1;  capfp = NULL;  docap = 0;  online = -1;  linespd = 0;  stdattr = XA_NORMAL;  us = NULL;  addlf = 0;  wrapln = 0;  disable_online_time = 0;  local_echo = 0;  strcpy(capname, "minicom.cap");  lockfile[0] = 0;  tempst = 0;  st = NULL;  us = NULL;  bogus_dcd = 0;  usecolor = 0;  screen_ibmpc = screen_iso = 1;  useattr = 1;  strncpy(termtype, getenv("TERM") ? getenv("TERM") : "dumb", sizeof(termtype));  stdattr = XA_NORMAL;  use_port = "dfl";  alt_override = 0;  scr_name[0] = 0;  scr_user[0] = 0;  scr_passwd[0] = 0;  dial_name = (char *)NULL;  dial_number = (char *)NULL;  dial_user = (char *)NULL;  dial_pass = (char *)NULL;  size_changed = 0;  escape = 1;  cmd_dial = NULL;  real_uid = getuid();  real_gid = getgid();  eff_uid  = geteuid();  eff_gid  = getegid();  /* fmg 1/11/94 colors (set defaults) */  /* MARK updated 02/17/95 to be more similiar to TELIX */  mfcolor = YELLOW;  mbcolor = BLUE;  tfcolor = WHITE;  tbcolor = BLACK;  sfcolor = WHITE;  sbcolor = RED;  st_attr = XA_NORMAL;  /* If no LANG or LC_ALL is set, fall back to 7bit mode   * since in 8bit mode we can't have fancy window borders... */  {    char *e1 = getenv("LANG"), *e2 = getenv("LC_ALL");    if ((!e1 || !strcmp("C", e1) || !strcmp("POSIX", e1)) &&	(!e2 || !strcmp("C", e2) || !strcmp("POSIX", e2)))      screen_ibmpc = screen_iso = 0;  }  /* MARK updated 02/17/95 default history buffer size */  num_hist_lines = 256;  /* fmg - but we reset these to F=WHITE, B=BLACK if -b flag found */  /* Before processing the options, first add options   * from the environment variable 'MINICOM'.   */  args[0] = "minicom";  if ((mc = getenv("MINICOM")) != NULL) {    strncpy(buf, mc, 80);    bufp = buf;    buf[79] = 0;    while (isspace(*bufp))      bufp++;    while (*bufp && argk < 19) {      for (s = bufp; !isspace(*bufp) && *bufp; bufp++)	;      args[argk++] = s;      while (isspace(*bufp))	*bufp++ = 0;    }  }  env_args = argk;  /* Add command - line options */  for(c = 1; c < argc && argk < 19; c++)    args[argk++] = argv[c];  args[argk] = NULL;  do {    /* Process options with getopt */    while ((c = getopt_long(argk, args, "v78zhlLsomMbwTc:a:t:d:p:C:S:",                            long_options, NULL)) != EOF)      switch(c) {	case 'v':	  printf(_("%s version %s"), PACKAGE, VERSION);

⌨️ 快捷键说明

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