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

📄 config.c

📁 minicom的源码,linux下常用的串口程序.
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * config.c	Read and write the configuration file(s). * *		This file is part of the minicom communications package, *		Copyright 1991-1995 Miquel van Smoorenburg. * *		This program is free software; you can redistribute it and/or *		modify it under the terms of the GNU General Public License *		as published by the Free Software Foundation; either version *		2 of the License, or (at your option) any later version. * * // fmg 12/20/93 - Added color selection to Screen & Keyboard menu * // fmg 2/15/94 - Added macro filename & Macro define selection to *                  Screen & Keyboard menu. Added window for macro *                  definition. * // jl 04.09.97 - Added configuring the character conversion tables * // jl 09.09.97 - Save conversion table filename in the config file and *                  read the table at startup * // jl 22.02.98 - Setting for filename selection window * // acme 25.02.98 - i18n * // jl 05.04.98 - Handling the P_MUL option *    jl 06.07.98 - the P_CONVCAP option *    jl 10.07.98 - moved functions pfix_home and do_log to file common.c *    jl 29.11.98 - the P_SHOWSPD option *    jl 05.04.99 - logging options menu *    er 18-Apr-99 - the P_MULTILINE option *    jl 11.02.2000 - the P_STOPB option */#ifdef HAVE_CONFIG_H#include <config.h>#endif#include "rcsid.h"RCSID("$Id: config.c,v 1.22 2006/04/02 09:52:30 al-guest Exp $")#include "port.h"#include "minicom.h"#include "intl.h"void doconv(void);   /* jl 04.09.97 *//* Read in parameters. */void read_parms(void){  FILE *fp;  int f;  char buf[64];  char *p;  /* Read global parameters */  if ((fp = fopen(parfile, "r")) == NULL) {    if (real_uid == 0) {      fputs(_("minicom: WARNING: configuration file not found, using defaults\n"),stderr);      sleep(2);      return;    }    fprintf(stderr,            _("minicom: there is no global configuration file %s\n"), parfile);    fputs(_("Ask your sysadmin to create one (with minicom -s).\n"), stderr);    exit(1);  }  readpars(fp, CONFIG_GLOBAL);  fclose(fp);  /* Read personal parameters */  if ((fp = sfopen(pparfile, "r")) != NULL) {    readpars(fp, CONFIG_PERSONAL);    fclose(fp);  }  /* fmg - set colors from readin values (Jcolor Xlates name to #) */  mfcolor = Jcolor(P_MFG); mbcolor = Jcolor(P_MBG);  tfcolor = Jcolor(P_TFG); tbcolor = Jcolor(P_TBG);  sfcolor = Jcolor(P_SFG); sbcolor = Jcolor(P_SBG);  /* fmg - Read personal macros */  if (P_MACROS[0] != 0) { /* fmg - null length? */    if ((fp = sfopen(pfix_home(P_MACROS), "r")) == NULL) {      if (errno != ENOENT) {        fprintf(stderr,                _("minicom: cannot open macro file %s\n"), pfix_home(P_MACROS));        sleep(1); /* fmg - give the "slow" ones time to read :-) */      }    } else {      readmacs(fp, 0);      fclose(fp);    }  } /* fmg - but it's perfectly OK if macros file name is NULL... */  if (P_CONVF[0] != 0) { /* jl 09.09.97 */    loadconv(P_CONVF);  }  /* This code is to use old configuration files. */  for (f = PROTO_BASE; f < MAXPROTO; f++) {    if (P_PNAME(f)[0] && P_PIORED(f) != 'Y' && P_PIORED(f) != 'N') {      strncpy(buf, P_PNAME(f) - 2, sizeof(buf));      strcpy(P_PNAME(f), buf);      P_PIORED(f) = 'Y';      P_PFULL(f) = 'N';    }  }  if ((p = strrchr(P_LOCK, '/')) != NULL && strncmp(p, "/LCK", 4) == 0)    *p = 0;}/* * fmg - Convert color word to number */int Jcolor(char *s){  char c1, c3;  c1 = toupper(s[0]); /* fmg - it's already up but why tempt it? */  c3 = toupper(s[2]);  switch (c1)  {    case 'G': return GREEN;    case 'Y': return YELLOW;    case 'W': return WHITE;    case 'R': return RED;    case 'M': return MAGENTA;    case 'C': return CYAN;    case 'B': if (c3 == 'A')                return BLACK;              if (c3 == 'U')                return BLUE;              else                break;  }  return -1; /* fmg - should never get here */} /* * See if we have write access to a file. * If it is not there, see if the directory is writable. */int waccess(char *s){  char *p;  char buf[128];  struct stat stt;  /* We use stat instead of access(s, F_OK) because I couldn't get   * that to work under BSD 4.3 ...   */  if (stat(s, &stt) == 0) {    if (access(s, W_OK) == 0)      return(XA_OK_EXIST);    return -1;  }  strncpy(buf, s, sizeof(buf)-1);  buf[sizeof(buf)-1] = 0;  if ((p = strrchr(buf, '/')) == (char *)NULL)    strcpy(buf, ".");  else    *p = '\0';  if (access(buf, W_OK) == 0)    return XA_OK_NOTEXIST;  return -1;}/* * fmg - Read in a macro, but first check to see if it's * allowed to do so. * * TODO: have System macros and user macros (in theory it's already there * since user can specify their own macros file (unless root makes it * private... that's silly) ... anyways, you know what I mean...) */static void mgets(WIN *w, int x, int y, char *s, int len, int maxl){  struct macs *m = (struct macs *)s;  wlocate(w, x, y);  wgets(w, s, len, maxl);  m->flags |= CHANGED;}/* * Read in a string, but first check to see if it's * allowed to do so. */static void pgets(WIN *w, int x, int y, char *s, int len, unsigned int maxl){  struct pars *p = (struct pars *)s;  char *home = NULL;  wlocate(w, x, y);  wgets(w, s, len, maxl);  if (s[0] == '~' && (s[1] == '/' || s[1] == 0) &&      (home = getenv("HOME")) && strlen(s) + strlen(home) <= maxl) {    int i = 0;    memmove(s + strlen(home), s + 1, strlen(s));    memcpy(s, home, strlen(home));    wlocate(w, x, y);    for (i = 0; i < (len >= w->xs - x ? w->xs - x - 1 : len) && *s; i++) {      wchar_t wc;      s += one_mbtowc(&wc, s, MB_LEN_MAX);      wputc(w, wc);    }    wflush();  }  p->flags |= CHANGED;}/* * Mark a variable as changed. */static void markch(char *s){  struct pars *p = (struct pars *)s;  p->flags |= CHANGED;}/* * Set a string to a given value, but only if we're allowed to. */static void psets(char *s, const char *w){  struct pars *p = (struct pars *)s;  strcpy(s, w);  p->flags |= CHANGED;}/* * Get a a character from the keyboard. Translate lower * to uppercase and '\r' to '\n'. */static int rwxgetch(void){  int c = wxgetch();  if (islower(c))    c = toupper(c);  if (c == '\n' || c == '\r' || c == '\033')    return '\n';  return c;}#ifdef LOGFILEstatic void dologopt(void){  WIN *w;  int c;  char *logfnstr = _(" A - File name (empty=disable) :");  char *logconn  = _(" B - Log connects and hangups  :");  char *logxfer  = _(" C - Log file transfers        :");  char *question = _("Change which setting?");  w = wopen(5, 4, 75, 8, BDOUBLE, stdattr, mfcolor, mbcolor, 0, 0, 1);  wtitle(w, TMID, _("Logging options"));  wprintf(w, "%s %s\n", logfnstr, P_LOGFNAME);  wprintf(w, "%s %s\n", logconn, _(P_LOGCONN));  wprintf(w, "%s %s\n", logxfer, _(P_LOGXFER));  wlocate(w, 4, 4);  wputs(w, question);  wredraw(w, 1);  while(1) {    wlocate(w, mbslen(question) + 5, 5);    c = rwxgetch();    switch(c) {      case '\n':        wclose(w, 1);        return;      case 'A':        pgets(w, mbslen(logfnstr) + 1, 0,              P_LOGFNAME, PARS_VAL_LEN, PARS_VAL_LEN);        strcpy(logfname,P_LOGFNAME);        break;      case 'B':        strcpy(P_LOGCONN, yesno(P_LOGCONN[0] == 'N'));        wlocate(w, mbslen(logconn) + 1, 1);        wprintf(w, "%s  ", _(P_LOGCONN));        markch(P_LOGCONN);        break;      case 'C':        strcpy(P_LOGXFER, yesno(P_LOGXFER[0] == 'N'));        wlocate(w, mbslen(logxfer) + 1, 2);        wprintf(w, "%s  ", _(P_LOGXFER));        markch(P_LOGXFER);        break;      default:        break;    }  }}#endifstatic void dopath(void){  WIN *w;  int c;  char *download_directory = _(" A - Download directory :");  char *upload_directory   = _(" B - Upload directory   :");  char *script_directory   = _(" C - Script directory   :");  char *script_program     = _(" D - Script program     :");  char *kermit_program     = _(" E - Kermit program     :");#ifdef LOGFILE  char *log_settings       = _(" F - Logging options");#endif  char *question           = _("Change which setting?");  w = wopen(5, 5, 75, 12, BDOUBLE, stdattr, mfcolor, mbcolor, 0, 0, 1);  wprintf(w, "%s %.44s\n", download_directory, P_DOWNDIR);  wprintf(w, "%s %.44s\n", upload_directory, P_UPDIR);  wprintf(w, "%s %.44s\n", script_directory, P_SCRIPTDIR);  wprintf(w, "%s %.44s\n", script_program, P_SCRIPTPROG);  wprintf(w, "%s %.44s\n", kermit_program, P_KERMIT);#ifdef LOGFILE  wprintf(w, "%s\n", log_settings);#endif  wlocate(w, 4, 8);  wputs(w, question);  wredraw(w, 1);  while(1) {    wlocate(w, mbslen (question) + 5, 8);    c = rwxgetch();    switch(c) {      case '\n':        wclose(w, 1);        return;      case 'A':        pgets(w, mbslen (download_directory) + 1, 0, P_DOWNDIR, 64, 64);        init_dir('d');        break;      case 'B':        pgets(w, mbslen (upload_directory) + 1, 1, P_UPDIR, 64, 64);        init_dir('u');        break;      case 'C':        pgets(w, mbslen (script_directory) + 1, 2, P_SCRIPTDIR, 64, 64);        break;      case 'D':        pgets(w, mbslen (script_program) + 1, 3, P_SCRIPTPROG, 64, 64);        break;      case 'E':        pgets(w, mbslen (kermit_program) + 1, 4, P_KERMIT, 64, 64);        break;#ifdef LOGFILE      case 'F':        dologopt();        break;#endif      default:        break;    }  }}const char *yesno(int k){  return(k ? N_("Yes") : N_("No "));}/* * Input the definition of an up/download protocol. */static void inputproto(WIN *w, int n){  int c = 0;  mpars[PROTO_BASE + n].flags |= CHANGED;  if (P_PNAME(n)[0] == '\0') {    P_PNN(n) = 'Y';    P_PUD(n) = 'U';    P_PFULL(n) = 'N';    P_PPROG(n)[0] = 0;    P_PIORED(n) = 'Y';    wlocate(w, 4, n+1);    wputs(w, "       ");  }  wlocate(w, 4, n + 1);  wgets(w, P_PNAME(n), 10, 64);  pgets(w, 15, n+1, P_PPROG(n), 31, 64);  do {    wlocate(w, 47, n + 1);    wprintf(w, "%c", P_PNN(n));    c = rwxgetch();    if (c == 'Y')      P_PNN(n) = 'Y';    if (c == 'N')      P_PNN(n) = 'N';  } while (c != '\r' && c != '\n');  do {    wlocate(w, 52, n + 1);    wprintf(w, "%c", P_PUD(n));    c = rwxgetch();    if (c == 'U')      P_PUD(n) = 'U';    if (c == 'D')      P_PUD(n) = 'D';  } while (c != '\r' && c != '\n');  do {    wlocate(w, 57, n + 1);    wprintf(w, "%c", P_PFULL(n));    c = rwxgetch();    if (c == 'Y')      P_PFULL(n) = 'Y';    if (c == 'N')      P_PFULL(n) = 'N';  } while (c != '\r' && c != '\n');  do {    wlocate(w, 65, n + 1);    wprintf(w, "%c", P_PIORED(n));    c = rwxgetch();    if (c == 'Y')      P_PIORED(n) = 'Y';    if (c == 'N')      P_PIORED(n) = 'N';  } while (c != '\r' && c != '\n');  do {    wlocate(w, 73, n + 1);    wprintf(w, "%c", P_MUL(n));    c = rwxgetch();    if (c == 'Y')      P_MUL(n) = 'Y';    if (c == 'N')      P_MUL(n) = 'N';  } while (c != '\r' && c != '\n');}static void doproto(void){  WIN *w;  int f, c;  char *zmodem_download        = _("M  Zmodem download string activates...");  char *use_filename_selection = _("N  Use filename selection window......");  char *prompt_downdir         = _("O  Prompt for download directory......");  char *question               = _("Change which setting? (SPACE to delete)");  w = wopen(1, 3, 78, 20, BDOUBLE, stdattr, mfcolor, mbcolor, 0, 0, 1);  wputs(w, _("     Name             Program"));  wlocate(w, 46, 0);  wputs(w,        /* TRANSLATORS:	 * Name: Protocol sends filename internally	 * U/D: Command is used for upload or download	 * FullScr: Command runs fullscreen	 * IO-Red: Redirect output of commands to logfile	 * Multi: Protocol can transfer multiple files at once */        _("Name U/D FullScr IO-Red. Multi"));  for (f = 0; f < 12; f++) {    wlocate(w, 1, f + 1);    if (P_PNAME(f)[0])      wprintf(w, "%c  %-10.10s %-31.31s %c    %c    %c       %c       %c",              'A' + f,              P_PNAME(f), P_PPROG(f),              P_PNN(f), P_PUD(f),              P_PFULL(f), P_PIORED(f),              P_MUL(f));    else      wprintf(w, "%c    -", 'A' + f);

⌨️ 快捷键说明

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