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

📄 minicom.c

📁 VT100终端程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * minicom.c	Main program. The main loop of the terminal emulator *		itself is in main.c. (Yeah yeah it's confusing). * *		This file is part of the minicom communications package, *		Copyright 1991-1996 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 1/11/94 colors * */#define EXTERN#include "port.h"#include "minicom.h"#include "patchlevel.h"#define RESET 1#define NORESET 2#ifdef _SVR2extern struct passwd *getpwuid();#endif#ifdef DEBUG/* Show signals when debug is on. */static void signore(sig)int sig;{  if (stdwin != NIL_WIN)	werror("Got signal %d", sig);  else	printf("Got signal %d\r\n", sig);}#endif/* * Sub - menu's. */static char *c1[] = { "   Yes  ", "   No   ", CNULL };static char *c2[] = { "  Close ", " Pause  ", "  Exit  ", CNULL };static char *c3[] = { "  Close ", " Unpause", "  Exit  ", CNULL };static char *c7[] = { "   Yes  ", "   No   ", CNULL };/* Initialize modem port. */void port_init(){  m_setparms(portfd, P_BAUDRATE, P_PARITY, P_BITS, P_HASRTS[0] == 'Y',	P_HASXON[0] == 'Y');}static void do_hang(askit)int askit;{  int c = 0;   if (askit) c = ask("Hang-up line?", c7);  if (c == 0) hangup();}/* * We've got the hangup or term signal. */static void hangsig(sig)int sig;{  if (stdwin != NIL_WIN)	werror("Killed by signal %d !\n", sig);  if (capfp != (FILE *)0) fclose(capfp);  keyboard(KUNINSTALL, 0);  hangup();  modemreset();  leave("\n");}/* * Jump to a shell */#ifdef SIGTSTP/*ARGSUSED*/static void shjump(sig)int sig;{  extern int use_status;  wleave();  signal(SIGTSTP, SIG_DFL);  printf("Suspended. Type \"fg\" to resume.\n");  kill(getpid(), SIGTSTP);  signal(SIGTSTP, shjump);  wreturn();  if (use_status) show_status();}#else/*ARGSUSED*/static void shjump(dummy)int dummy;{  extern int use_status;  char *sh;  int pid;  int status;  int f;  sh = getenv("SHELL");  if (sh == CNULL) {  	werror("SHELL variable not set");  	return;  }  if ((pid = fork()) == -1) {  	werror("Out of memory: could not fork()");  	return;  }  if (pid != 0) wleave();  if (pid == 0) {	for(f = 1; f < _NSIG; f++) signal(f, SIG_DFL);  	for(f = 3; f < 20; f++) close(f);	set_privs();	setgid((gid_t)real_gid);  	setuid((uid_t)real_uid);	printf("Shelled out. Type \"exit\" to return.\n");  	execl(sh, sh, CNULL);  	exit(1);  }  (void) m_wait(&status);  wreturn();  if (use_status) show_status();}#endif #if HISTORY/* Get a line from either window or scroll back buffer. */static ELM *getline(w, no)WIN *w;int no;{  int i;  if (no < us->histlines) {	/* Get a line from the history buffer. */	i = no + us->histline /*- 1*/;	if (i >= us->histlines) i -= us->histlines;	if (i < 0) i = us->histlines - 1;	return(us->histbuf + (i * us->xs));  }  /* Get a line from the "us" window. */  no -= us->histlines;  if (no >= w->ys) no = w->ys - 1;  return(w->map + (no * us->xs));}/* Redraw the window. */static void drawhist(w, y, r)WIN *w;int y;int r;{  int f;  w->direct = 0;  for(f = 0; f < w->ys; f++)	wdrawelm(w, f, getline(w, y++));  if (r) wredraw(w, 1);  w->direct = 1;}/* Scroll back */static void scrollback(){  int y;  WIN *b_us, *b_st;  int c;  char hline[128];  /* Find out how big a window we must open. */  y = us->y2;  if (st == (WIN *)0 || (st && tempst)) y--;  /* Open a window. */   b_us = wopen(0, 0, us->x2, y, 0, us->attr, COLFG(us->color),		COLBG(us->color), 0, 0, 0);  wcursor(b_us, CNONE);  /* Open a help line window. */  b_st = wopen(0, y+1, us->x2, y+1, 0, st_attr, sfcolor, sbcolor, 0, 0, 1);  b_st->doscroll = 0;  b_st->wrap = 0;  /* Make sure help line is as wide as window. */  strcpy(hline, "   SCROLL MODE    U=up D=down F=page-forward B=page-backward ESC=exit                    ");  if (b_st->xs < 127) hline[b_st->xs] = 0;  wprintf(b_st, hline);  wredraw(b_st, 1);  wflush();  /* And do the job. */  y = us->histlines;  drawhist(b_us, y, 0);  while((c = wxgetch()) != K_ESC) {	switch(c) {	  case 'u':	  case K_UP:		if (y <= 0) break;		y--;		wscroll(b_us, S_DOWN);		wdrawelm(b_us, 0, getline(b_us, y));		wflush();		break;	  case 'd':	  case K_DN:		if (y >= us->histlines) break;		y++;		wscroll(b_us, S_UP);		wdrawelm(b_us, b_us->ys - 1, getline(b_us, y + b_us->ys - 1));		wflush();		break;	  case 'b':	  case K_PGUP:		if (y <= 0) break;		y -= b_us->ys;		if (y < 0) y = 0;		drawhist(b_us, y, 1);		break;	  case 'f':	  case K_PGDN:		if (y >= us->histlines) break;		y += b_us->ys;		if (y > us->histlines) y = us->histlines;		drawhist(b_us, y, 1);		break;	}  }  /* Cleanup. */  wclose(b_us, y == us->histlines ? 0 : 1);  wclose(b_st, 1);  wlocate(us, us->curx, us->cury);  wflush();}#endif#ifdef SIGWINCH/* The window size has changed. Re-initialize. */static void change_size(sig)int sig;{  (void)sig;  size_changed = 1;  signal(SIGWINCH, change_size);}#endif/* * Read a word from strings 's' and advance pointer. */static char *getword(s)char **s;{  char *begin;  /* Skip space */  while(**s == ' ' || **s == '\t') (*s)++;  /* End of line? */  if (**s == '\0' || **s == '\n') return((char *)0);    begin = *s;  /* Skip word */  while(**s != ' ' && **s != '\t' && **s != '\n' && **s) (*s)++;  /* End word with '\0' */  if (**s) {  	**s = 0;  	(*s)++;  }  return(begin);}static char *bletch =   "Usage: minicom [-somlz] [-c on] [-a on] [-t TERM] [-d entry] [-p ttyp] [configuration]\n";static void usage(env_args, optind, mc)int env_args, optind;char *mc;{  if (env_args >= optind && mc)  	fprintf(stderr, "Wrong option in environment MINICOM=%s\n", mc);  fprintf(stderr, bletch);  fprintf(stderr, "Type \"minicom -h\" for help.\n");  exit(1);}/* Give some help information */static void helpthem(){  char *mc = getenv("MINICOM");  printf("\n%s", Version);#ifdef __DATE__  printf(" (compiled %s)", __DATE__);#endif  printf("(c) Miquel van Smoorenburg\n\n%s\n", bletch);  printf("  -s             : enter setup mode (only as root)\n");  printf("  -o             : do not initialize modem & lockfiles at startup\n");  printf("  -m             : use meta or alt key for commands\n");  printf("  -l             : literal ; assume screen uses the IBM-PC character set\n");  /* printf("  -L             : Ditto, but assume screen uses ISO8859\n"); */  printf("  -z             : try to use terminal's status line\n");  printf("  -c [on | off]  : ANSI style color usage on or off\n");  printf("  -a [on | off]  : use reverse or highlight attributes on or off\n");  printf("  -t term        : override TERM environment variable\n");  printf("  -d entry       : dial `entry' from the dialing directory\n");  printf("  -p ttyp..      : connect to pseudo terminal\n");  printf("  configuration  : configuration file to use\n\n");  printf("These options can also be specified in the MINICOM environment variable.\n");  printf("This variable is currently %s%s.\n", mc ? "set to " : "unset",	mc ? mc : "");  printf("The LIBDIR to find the configuration files and the\n");  printf("access file minicom.users is compiled as %s.\n\n", LIBDIR);#if 0  /* More than 24 lines.. */  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");#endif}int main(argc, argv)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 */  extern int getopt(), optind;  extern char *optarg;		/* From getopt (3) package */  extern int use_status;	/* Use status line. */  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;			/* Type of alt key */  char pseudo[64];  /* Initialize global variables */  portfd = -1;  capfp = (FILE *)NULL;  docap = 0;  online = -1;  stdattr = XA_NORMAL;  us = NIL_WIN;  addlf = 0;#ifdef _SELECT  local_echo = 0;#endif  strcpy(capname, "minicom.cap");  lockfile[0] = 0;  tempst = 0;  st = NIL_WIN;  us = NIL_WIN;  bogus_dcd = 0;  usecolor = 0;  screen_ibmpc = 0;  screen_iso = 0;  useattr = 1;  strcpy(termtype, getenv("TERM") ? getenv("TERM") : "dumb");  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;  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;  /* 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")) != CNULL) { 	strncpy(buf, mc, 80); 	bufp = buf; 	buf[79] = 0; 	while(isspace(*bufp)) bufp++; 	while(*bufp) { 		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; c++) args[argk++] = argv[c];  args[argk] = CNULL;  do {

⌨️ 快捷键说明

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