📄 minicom.c
字号:
#endif printf("\n"); printf(_("Copyright (C) Miquel van Smoorenburg.\n\n")); printf("This program is free software; you can redistribute it and/or\n" "modify it under the terms of the GNU General Public License\n" "as published by the Free Software Foundation; either version\n" "2 of the License, or (at your option) any later version.\n\n"); exit(1); break; case 's': /* setup */ if (real_uid != 0 && real_uid != eff_uid) { fprintf(stderr, _("minicom: -s switch needs root privilige\n")); exit(1); } dosetup = 1; break; case 'h': helpthem(); exit(1); break; case 'p': /* Pseudo terminal to use. */ if (strncmp(optarg, "/dev/", 5) == 0) optarg += 5; if (((strncmp(optarg, "tty", 3) != 0) /* /dev/pts support --misiek. */ && (strncmp(optarg, "pts", 3) != 0) /* /dev/pty support --jl. */ && (strncmp(optarg, "pty", 3) != 0)) || !strchr("pqrstuvwxyz/", optarg[3])) { fprintf(stderr, _("minicom: argument to -p must be a pty\n")); exit(1); } snprintf(pseudo, sizeof(pseudo), "/dev/%s", optarg); dial_tty = pseudo; /* Drop priviliges. */ drop_all_privs(); break; case 'm': /* ESC prefix metakey */ alt_override++; alt_code = 27; break; case 'M': /* 8th bit metakey. */ alt_override++; alt_code = 128; break; case 'l': /* Don't assume literal ANSI chars */ screen_ibmpc = 0; break; case 'L': /* Don't assume literal ISO8859 chars */ screen_iso = 0; break; case 't': /* Terminal type */ strncpy(termtype, optarg, sizeof(termtype));#ifdef __GLIBC__ /* Bug in older libc's (< 4.5.26 I think) */ if ((s = getenv("TERMCAP")) != NULL && *s != '/') unsetenv("TERMCAP");#endif break; case 'o': /* DON'T initialize */ doinit = 0; break; case 'c': /* Color on/off */ if (strcmp("on", optarg) == 0) { usecolor = 1; stdattr = XA_BOLD; break; } if (strcmp("off", optarg) == 0) { usecolor = 0; stdattr = XA_NORMAL; break; } usage(env_args, optind - 1, mc); break; case 'a': /* Attributes on/off */ if (strcmp("on", optarg) == 0) { useattr = 1; break; } if (strcmp("off", optarg) == 0) { useattr = 0; break; } usage(env_args, optind - 1, mc); break; case 'd': /* Dial from the command line. */ cmd_dial = optarg; break; case 'z': /* Enable status line. */ use_status = 1; break; case 'C': /* Capturing */ capfp = sfopen(optarg, "a"); if (capfp == NULL) { werror(_("Cannot open capture file")); exit(1); } docap = 1; vt_set(addlf, -1, docap, -1, -1, -1, -1); break; case 'S': /* start Script */ strncpy(scr_name, optarg, 33); break; case '7': /* 7bit fallback mode */ screen_ibmpc = screen_iso = 0; break; case '8': /* force 8bit mode */ screen_ibmpc = screen_iso = 1; break; case 'w': /* Linewrap on */ wrapln = 1; break; case 'T': /* disable online time */ disable_online_time = 1; break; default: usage(env_args, optind, mc); break; } /* Now, get portname if mentioned. Stop at end or '-'. */ while (optind < argk && args[optind][0] != '-') use_port = args[optind++]; /* Loop again if more options */ } while (optind < argk); if (screen_iso && screen_ibmpc) /* init VT */ vt_set(-1, -1, -1, -1, -1, -1, 1);#ifdef SVR4_LOCKS if (real_uid == 0 && dosetup == 0) { fprintf(stderr, "%s", _("minicom: WARNING: please don't run minicom as root when not maintaining\n" " it (with the -s switch) since all changes to the\n" " configuration will be GLOBAL !.\n")); sleep(5); }#endif /* Avoid fraude ! */ for (s = use_port; *s; s++) if (*s == '/') *s = '_'; snprintf(parfile, sizeof(parfile), "%s/minirc.%s", CONFDIR, use_port); /* Get password file information of this user. */ if ((pwd = getpwuid(real_uid)) == (struct passwd *)0) { fputs(_("You don't exist. Go away.\n"), stderr); exit(1); } /* Remember home directory and username. */ if ((s = getenv("HOME")) == NULL) strncpy(homedir, pwd->pw_dir, sizeof(homedir)); else strncpy(homedir, s, sizeof(homedir)); strncpy(username, pwd->pw_name, sizeof(username)); /* Get personal parameter file */ snprintf(pparfile, sizeof(pparfile), "%s/.minirc.%s", homedir, use_port); /* Check this user in the USERFILE */ if (real_uid != 0 && real_uid != eff_uid) { snprintf(userfile, sizeof(userfile), "%s/minicom.users", CONFDIR); if ((fp = fopen(userfile, "r")) != (FILE *)0) { while (fgets(buf, 70, fp) != NULL && !userok) { /* Read first word */ bufp = buf; s = getword(&bufp); /* See if the "use_port" matches */ if (s && (!strcmp(pwd->pw_name, s) || strcmp("ALL", s) == 0)) { if ((s = getword(&bufp)) == NULL) userok = 1; else do { if (!strcmp(s, use_port)) { userok = 1; break; } } while ((s = getword(&bufp)) != NULL); } } fclose(fp); if (!userok) { fprintf(stderr, _("Sorry %s. You are not allowed to use configuration %s.\n"), pwd->pw_name, use_port); fprintf(stderr, _("Ask your sysadmin to add your name to %s\n"), userfile); exit(1); } } } buf[0] = 0; read_parms(); num_hist_lines = atoi(P_HISTSIZE); strcpy(logfname,P_LOGFNAME); /* Set default terminal behaviour */ addlf = strcasecmp(P_ADDLINEFEED, "yes") == 0; local_echo = strcasecmp(P_LOCALECHO, "yes") == 0; stdwin = NULL; /* It better be! */ /* Reset colors if we don't use 'em. */ if (!usecolor) { mfcolor = tfcolor = sfcolor = WHITE; mbcolor = tbcolor = sbcolor = BLACK; st_attr = XA_REVERSE; } if (dial_tty == NULL) { if (!dosetup) { while ((dial_tty = get_port(P_PORT)) != NULL && open_term(doinit, 1) < 0) ; if (dial_tty == NULL) exit(1); } } else { if (!dosetup && open_term(doinit, 1) < 0) exit(1); } mc_setenv("TERM", termtype); if (win_init(tfcolor, tbcolor, XA_NORMAL) < 0) leave(""); if (COLS < 40 || LINES < 10) leave(_("Sorry. Your screen is too small.\n")); if (dosetup) { if (config(1)) { mc_wclose(stdwin, 1); exit(0); } while ((dial_tty = get_port(P_PORT)) != NULL && open_term(doinit, 1) < 0) ; if (dial_tty == NULL) exit(1); } /* Signal handling */ signal(SIGTERM, hangsig); signal(SIGHUP, hangsig); signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGPIPE, SIG_IGN);#ifdef SIGTSTP signal(SIGTSTP, shjump); signal(SIGTTIN, SIG_IGN); signal(SIGTTOU, SIG_IGN);#endif#ifdef SIGTINT signal(SIGTINT, SIG_IGN);#endif#ifdef SIGWINCH signal(SIGWINCH, change_size);#endif#ifdef DEBUG for(c = 1; c < _NSIG; c++) { if (c == SIGTERM) continue; /* Saviour when hung */ signal(c, signore); }#endif keyboard(KINSTALL, 0); if (strcmp(P_BACKSPACE, "BS") != 0) keyboard(KSETBS, P_BACKSPACE[0] == 'B' ? 8 : 127); if (alt_override) keyboard(KSETESC, alt_code); else if (strcmp(P_ESCAPE, "^A") != 0) { switch (P_ESCAPE[0]) { case '^': c = P_ESCAPE[1] & 31; break; case 'E': c = 27; break; default: c = 128; break; } keyboard(KSETESC, c); } st = NULL; us = NULL; init_emul(VT100, 1); if (doinit) modeminit(); mc_wprintf(us, "\n%s %s\r\n", _("Welcome to minicom"), VERSION); mc_wprintf(us, "\n%s: %s\r\n", _("OPTIONS"), option_string);#if defined (__DATE__) && defined (__TIME__) mc_wprintf(us, "%s %s, %s.\r\n",_("Compiled on"), __DATE__,__TIME__);#endif mc_wprintf(us, "Port %s\n", P_PORT); mc_wprintf(us, _("\nPress %sZ for help on special keys%c\n\n"),esc_key(),'\r'); /* Now that all initialization is done, drop our priviliges. */ drop_privs(); readdialdir(); if (scr_name[0]) runscript (0, scr_name, "", ""); if (cmd_dial) dialone(cmd_dial); /* The main loop calls do_terminal and gets a function key back. */ while (!quit) { c = do_terminal();dirty_goto: switch (c + 32 *(c >= 'A' && c <= 'Z')) { case 'a': /* Add line feed */ toggle_addlf(); s = addlf ? _("Add linefeed ON") : _("Add linefeed OFF"); werror("%s", s); break; case 'e': /* Local echo on/off. */ toggle_local_echo(); s = local_echo ? _("Local echo ON") : _("Local echo OFF"); werror("%s", s); break; case 'z': /* Help */ c = help(); if (c != 'z') goto dirty_goto; break; case 'c': /* Clear screen */ mc_winclr(us); break; case 'f': /* Send break */ sendbreak(); break; case 'b': /* Scroll back */ scrollback(); break; case 'm': /* Initialize modem */ if (P_HASDCD[0]=='Y' && online >= 0) { c = ask(_("You are online. Really initialize?"), c1); if (c != 0) break; } modeminit(); break; case 'q': /* Exit without resetting */ c = ask(_("Leave without reset?"), c1); if (c == 0) quit = NORESET; if (!strcmp(P_MACCHG,"CHANGED")) { c = ask (_("Save macros?"),c1); if (c == 0) if (dodflsave() < 0) { /* fmg - error */ c = 'O'; /* hehe */ quit = 0; goto dirty_goto; } } break; case 'x': /* Exit Minicom */ c = ask(_("Leave Minicom?"), c1); if (c == 0) { quit = RESET; if(online >= 0) do_hang(0); modemreset(); } if (!strcmp(P_MACCHG,"CHANGED")) { c = ask (_("Save macros?"), c1); if (c == 0) if (dodflsave() < 0) { /* fmg - error */ c = 'O'; /* hehe */ quit = 0; goto dirty_goto; } } break; case 'l': /* Capture file */ if (capfp == (FILE *)0 && !docap) { s = input(_("Capture to which file? "), capname); if (s == NULL || *s == 0) break; if ((capfp = sfopen(s, "a")) == (FILE *)NULL) { werror(_("Cannot open capture file")); break; } docap = 1; } else if (capfp != (FILE *)0 && !docap) { c = ask(_("Capture file"), c3); if (c == 0) { fclose(capfp); capfp = (FILE *)NULL; docap = 0; } if (c == 1) docap = 1; } else if (capfp != (FILE *)0 && docap) { c = ask(_("Capture file"), c2); if (c == 0) { fclose(capfp); capfp = (FILE *)NULL; docap = 0; } if (c == 1) docap = 0; } vt_set(addlf, -1, docap, -1, -1, -1, -1); break; case 'p': /* Set parameters */ get_bbp(P_BAUDRATE, P_BITS, P_PARITY, P_STOPB, 0); port_init(); if (st) mode_status(); quit = 0; break; case 'k': /* Run kermit */ kermit(); break; case 'h': /* Hang up */ do_hang(1); break; case 'd': /* Dial */ dialdir(); break; case 't': /* Terminal emulation */ c = dotermmenu(); if (c > 0) init_emul(c, 1); break; case 'w': /* Line wrap on-off */ c = (!us->wrap); vt_set(addlf, c, docap, -1, -1, -1, -1); s = c ? _("Linewrap ON") : _("Linewrap OFF"); werror("%s", s); break; case 'o': /* Configure Minicom */ (void) config(0); break; case 's': /* Upload */ updown('U', 0); break; case 'r': /* Download */ updown('D', 0); break; case 'j': /* Jump to a shell */ shjump(0); break; case 'g': /* Run script */ runscript(1, "", "", ""); break; case 'i': /* Re-init, re-open portfd. */ cursormode = (cursormode == NORMAL) ? APPL : NORMAL; keyboard(cursormode == NORMAL ? KCURST : KCURAPP, 0); if (st) curs_status(); break; case 'y': /* Paste file */ paste_file(); break; default: break; } }; /* Reset parameters */ if (quit != NORESET) m_restorestate(portfd); else { if (P_LOGCONN[0] == 'Y' && online > 0) do_log("%s", _("Quit without reset while online.")); m_hupcl(portfd, 0); } signal(SIGTERM, SIG_IGN); signal(SIGHUP, SIG_IGN);#ifdef SIGTSTP signal(SIGTSTP, SIG_DFL);#endif signal(SIGQUIT, SIG_DFL); if (capfp != (FILE *)0) fclose(capfp); mc_wclose(us, 0); mc_wclose(st, 0); mc_wclose(stdwin, 1); set_privs(); keyboard(KUNINSTALL, 0); if (lockfile[0]) unlink(lockfile); close(portfd); /* Please - if your system doesn't have uid_t and/or gid_t, define 'em * conditionally in "port.h". */ chown(dial_tty, (uid_t)portuid, (gid_t)portgid); if (quit != NORESET && P_CALLIN[0]) fastsystem(P_CALLIN, NULL, NULL, NULL); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -