📄 config.c
字号:
/* * 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. */#include "port.h"#include "minicom.h"#if _HAVE_MACROS/* Prefix a non-absolute file with the home directory. */static char *pfix_home(s)char *s;{#if defined(FILENAME_MAX) static char buf[FILENAME_MAX];#else static char buf[256];#endif if (s && *s != '/') { sprintf(buf, "%s/%s", homedir, s); return(buf); } return(s);}#endif/* Read in parameters. */void read_parms(){ FILE *fp; int f; char buf[64]; char *p; /* Read global parameters */ if ((fp = fopen(parfile, "r")) == (FILE *)NULL) { if (real_uid == 0) { fprintf(stderr, "minicom: WARNING: configuration file not found, using defaults\n"); sleep(2); return; } fprintf(stderr, "minicom: there is no global configuration file %s\n", parfile); fprintf(stderr, "Ask your sysadm to create one (with minicom -s).\n"); exit(1); } readpars(fp, 1); fclose(fp); /* Read personal parameters */ if ((fp = sfopen(pparfile, "r")) != (FILE *)NULL) { readpars(fp, 0); 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); #if _HAVE_MACROS /* 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... */#endif /* 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') { strcpy(buf, P_PNAME(f) - 2); strcpy(P_PNAME(f), buf); P_PIORED(f) = 'Y'; P_PFULL(f) = 'N'; } } p = mbasename(P_LOCK); if (strncmp(p, "LCK", 3) == 0) *p = 0;}/* * fmg - Convert color word to number */int Jcolor(s)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(s)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); } strcpy(buf, s); if((p = strrchr(buf, '/')) == (char *)NULL) strcpy(buf, "."); else *p = '\0'; if (access(buf, W_OK) == 0) return(XA_OK_NOTEXIST); return(-1);}#if _HAVE_MACROS/* * 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(w, x, y, s, len, maxl)WIN *w;int x, y;char *s;int len;int maxl;{ struct macs *m = (struct macs *)s; if ((m->flags & PRIVATE) && real_uid != 0) { werror("You are not allowed to change this parameter"); return; } wlocate(w, x, y); (void) wgets(w, s, len, maxl); m->flags |= CHANGED;}#endif/* * Read in a string, but first check to see if it's * allowed to do so. */static void pgets(w, x, y, s, len, maxl)WIN *w;int x, y;char *s;int len;int maxl;{ struct pars *p = (struct pars *)s; if ((p->flags & PRIVATE) && real_uid != 0) { werror("You are not allowed to change this parameter"); return; } wlocate(w, x, y); (void) wgets(w, s, len, maxl); p->flags |= CHANGED;}/* * Mark a variable as changed. */static void markch(s)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(s, w)char *s, *w;{ struct pars *p = (struct pars *)s; if ((p->flags & PRIVATE) && real_uid != 0) { werror("You are not allowed to change this parameter"); return; } strcpy(s, w); p->flags |= CHANGED;}/* * Get a a character from the keyboard. Translate lower * to uppercase and '\r' to '\n'. */static int rwxgetch(){ int c; c = wxgetch(); if (islower(c)) c = toupper(c); if (c == '\n' || c == '\r' || c == '\033') return('\n'); return(c);}static void dopath(){ WIN *w; int c; w = wopen(5, 5, 75, 11, BDOUBLE, stdattr, mfcolor, mbcolor, 0, 0, 1); wprintf(w, " A - Download directory : %.44s\n", P_DOWNDIR); wprintf(w, " B - Upload directory : %.44s\n", P_UPDIR); wprintf(w, " C - Script directory : %.44s\n", P_SCRIPTDIR); wprintf(w, " D - Script program : %.44s\n", P_SCRIPTPROG); wprintf(w, " E - Kermit program : %.44s\n", P_KERMIT); wlocate(w, 4, 7); wputs(w, "Change which setting? "); wredraw(w, 1); while(1) { wlocate(w, 26, 7); c = rwxgetch(); switch(c) { case '\n': wclose(w, 1); return; case 'A': pgets(w, 26, 0, P_DOWNDIR, 64, 64); break; case 'B': pgets(w, 26, 1, P_UPDIR, 64, 64); break; case 'C': pgets(w, 26, 2, P_SCRIPTDIR, 64, 64); break; case 'D': pgets(w, 26, 3, P_SCRIPTPROG, 64, 64); break; case 'E': pgets(w, 26, 4, P_KERMIT, 64, 64); break; default: break; } }}char *yesno(k)int k;{ return(k ? "Yes" : "No ");}/* * Input the definition of an up/download protocol. */static void inputproto(w, n)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); (void ) wgets(w, P_PNAME(n), 10, 64); pgets(w, 15, n+1, P_PPROG(n), 31, 64); do { wlocate(w, 48, 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, 56, 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, 64, 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, 72, 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');}static void doproto(){ WIN *w; int f, c; w = wopen(1, 4, 78, 19, BDOUBLE, stdattr, mfcolor, mbcolor, 0, 0, 1); wputs(w, " Name Program"); wlocate(w, 44, 0); wputs(w, "Need name Up/Down FullScr IO-Red."); 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", 'A' + f, P_PNAME(f), P_PPROG(f), P_PNN(f), P_PUD(f), P_PFULL(f), P_PIORED(f)); else wprintf(w, "%c -", 'A' + f); } wlocate(w, 1, 13); wprintf(w, "M Zmodem download string activates... %c", P_PAUTO[0]); wlocate(w, 3, 15); wputs(w, "Change which setting? (SPACE to delete) "); wredraw(w, 1); do { wlocate(w, 43, 15); c = rwxgetch(); if (c >= 'A' && c <= 'L') inputproto(w, c - 'A'); if (c == ' ') { wlocate(w, 3, 15); wputs(w, "Delete which protocol? "); wclreol(w); c = rwxgetch(); if (c >= 'A' && c <= 'L') { P_PNAME(c - 'A')[0] = '\0'; mpars[PROTO_BASE + (c - 'A')].flags |= CHANGED; wlocate(w, 3, c - 'A' + 1); wclreol(w); wputs(w, " -"); } wlocate(w, 3, 15); wputs(w, "Change which setting? (SPACE to delete) "); c = ' '; } if (c == 'M') { wlocate(w, 40, 13); wprintf(w, " \b"); c = rwxgetch(); if (c >= 'A' && c <= 'L') { P_PAUTO[0] = c; markch(P_PAUTO); wprintf(w, "%c", c); } else if (c == '\n' || c == ' ') { P_PAUTO[0] = ' '; markch(P_PAUTO); } else { wprintf(w, "%c", P_PAUTO[0]); } c = 0; } } while(c != '\n'); wclose(w, 1);}static void doserial(){ WIN *w; w = wopen(5, 4, 75, 12, BDOUBLE, stdattr, mfcolor, mbcolor, 0, 0, 1); wprintf(w, " A - Serial Device : %.41s\n", P_PORT); wprintf(w, " B - Lockfile Location : %.41s\n", P_LOCK); wprintf(w, " C - Callin Program : %.41s\n", P_CALLIN); wprintf(w, " D - Callout Program : %.41s\n", P_CALLOUT); wprintf(w, " E - Baud/Par/Bits : %s %s%s1\n", P_BAUDRATE, P_BITS, P_PARITY); wprintf(w, " F - Hardware Flow Control : %s\n", P_HASRTS); wprintf(w, " G - Software Flow Control : %s\n", P_HASXON); wlocate(w, 4, 8); wputs(w, "Change which setting? "); wredraw(w, 1); while(1) { wlocate(w, 26, 8); switch(rwxgetch()) { case '\n': wclose(w, 1); return; case 'A': pgets(w, 29, 0, P_PORT, 64, 64); break; case 'B': pgets(w, 29, 1, P_LOCK, 64, 64); break; case 'C': pgets(w, 29, 2, P_CALLIN, 64, 64); break; case 'D': pgets(w, 29, 3, P_CALLOUT, 64, 64); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -