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

📄 rltty.c

📁 Linux下的MUD客户端程序
💻 C
📖 第 1 页 / 共 2 页
字号:
#if !defined (VTIME)#  define VTIME VEOL#endif#if defined (TERMIOS_TTY_DRIVER)#  define TIOTYPE struct termios#  define DRAIN_OUTPUT(fd)	tcdrain (fd)#  define GETATTR(tty, tiop)	(tcgetattr (tty, tiop))#  define SETATTR(tty, tiop)	(tcsetattr (tty, TCSANOW, tiop))#else#  define TIOTYPE struct termio#  define DRAIN_OUTPUT(fd)#  define GETATTR(tty, tiop)	(ioctl (tty, TCGETA, tiop))#  define SETATTR(tty, tiop)	(ioctl (tty, TCSETA, tiop))#endif /* !TERMIOS_TTY_DRIVER */static TIOTYPE otio;#if defined (FLUSHO)#  define OUTPUT_BEING_FLUSHED(tp)  (tp->c_lflag & FLUSHO)#else#  define OUTPUT_BEING_FLUSHED(tp)  0#endifstatic intget_tty_settings (tty, tiop)     int tty;     TIOTYPE *tiop;{#if !defined (SHELL) && defined (TIOCGWINSZ)  struct winsize w;  if (ioctl (tty, TIOCGWINSZ, &w) == 0)      (void) ioctl (tty, TIOCSWINSZ, &w);#endif  /* Keep looping if output is being flushed after a ^O (or whatever     the flush character is). */  while (GETATTR (tty, tiop) < 0 || OUTPUT_BEING_FLUSHED (tiop))    {      if (OUTPUT_BEING_FLUSHED (tiop))        continue;      if (errno != EINTR)	return -1;      errno = 0;    }  return 0;}static intset_tty_settings (tty, tiop)     int tty;     TIOTYPE *tiop;{  while (SETATTR (tty, tiop) < 0)    {      if (errno != EINTR)	return -1;      errno = 0;    }#if 0#if defined (TERMIOS_TTY_DRIVER)#  if defined (__ksr1__)  if (ksrflow)    {      ksrflow = 0;      tcflow (tty, TCOON);    }#  else /* !ksr1 */  tcflow (tty, TCOON);		/* Simulate a ^Q. */#  endif /* !ksr1 */#else  ioctl (tty, TCXONC, 1);	/* Simulate a ^Q. */#endif /* !TERMIOS_TTY_DRIVER */#endif  return 0;}static voidprepare_terminal_settings (meta_flag, otio, tiop)     int meta_flag;     TIOTYPE otio, *tiop;{  readline_echoing_p = (otio.c_lflag & ECHO);  tiop->c_lflag &= ~(ICANON | ECHO);  if ((unsigned char) otio.c_cc[VEOF] != (unsigned char) _POSIX_VDISABLE)    _rl_eof_char = otio.c_cc[VEOF];#if defined (USE_XON_XOFF)#if defined (IXANY)  tiop->c_iflag &= ~(IXON | IXOFF | IXANY);#else  /* `strict' Posix systems do not define IXANY. */  tiop->c_iflag &= ~(IXON | IXOFF);#endif /* IXANY */#endif /* USE_XON_XOFF */  /* Only turn this off if we are using all 8 bits. */  if (((tiop->c_cflag & CSIZE) == CS8) || meta_flag)    tiop->c_iflag &= ~(ISTRIP | INPCK);  /* Make sure we differentiate between CR and NL on input. */  tiop->c_iflag &= ~(ICRNL | INLCR);#if !defined (HANDLE_SIGNALS)  tiop->c_lflag &= ~ISIG;#else  tiop->c_lflag |= ISIG;#endif  tiop->c_cc[VMIN] = 1;  tiop->c_cc[VTIME] = 0;  if (tiop->c_lflag & FLUSHO)    {      output_was_flushed = 1;      tiop->c_lflag &= ~FLUSHO;      otio.c_lflag &= ~FLUSHO;    }  /* Turn off characters that we need on Posix systems with job control,     just to be sure.  This includes ^Y and ^V.  This should not really     be necessary.  */#if defined (TERMIOS_TTY_DRIVER) && defined (_POSIX_VDISABLE)#if defined (VLNEXT)  tiop->c_cc[VLNEXT] = _POSIX_VDISABLE;#endif#if defined (VDSUSP)  tiop->c_cc[VDSUSP] = _POSIX_VDISABLE;#endif#endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */}#endif  /* NEW_TTY_DRIVER *//* Put the terminal in CBREAK mode so that we can detect key presses. */voidrl_prep_terminal (meta_flag)     int meta_flag;{#if !defined (__GO32__)  int tty = fileno (rl_instream);  TIOTYPE tio;  if (terminal_prepped)    return;  /* Try to keep this function from being INTerrupted. */  block_sigint ();  if (get_tty_settings (tty, &tio) < 0)    {      release_sigint ();      return;    }  otio = tio;  prepare_terminal_settings (meta_flag, otio, &tio);  if (set_tty_settings (tty, &tio) < 0)    {      release_sigint ();      return;    }  if (output_was_flushed)    output_was_flushed = 0;  control_meta_key (1);  control_keypad (1);  fflush (rl_outstream);  terminal_prepped = 1;  release_sigint ();#endif /* !__GO32__ */}/* Restore the terminal's normal settings and modes. */voidrl_deprep_terminal (){#if !defined (__GO32__)  int tty = fileno (rl_instream);  if (!terminal_prepped)    return;  /* Try to keep this function from being INTerrupted. */  block_sigint ();  if (set_tty_settings (tty, &otio) < 0)    {      release_sigint ();      return;    }  control_meta_key (0);  control_keypad (0);  fflush (rl_outstream);  terminal_prepped = 0;  release_sigint ();#endif /* !__GO32__ */}/* **************************************************************** *//*								    *//*			Bogus Flow Control      		    *//*								    *//* **************************************************************** */rl_restart_output (count, key)     int count, key;{  int fildes = fileno (rl_outstream);#if defined (TIOCSTART)#if defined (apollo)  ioctl (&fildes, TIOCSTART, 0);#else  ioctl (fildes, TIOCSTART, 0);#endif /* apollo */#else /* !TIOCSTART */#  if defined (TERMIOS_TTY_DRIVER)#    if defined (__ksr1__)  if (ksrflow)    {      ksrflow = 0;      tcflow (fildes, TCOON);    }#    else /* !ksr1 */  tcflow (fildes, TCOON);		/* Simulate a ^Q. */#    endif /* !ksr1 */#  else /* !TERMIOS_TTY_DRIVER */#    if defined (TCXONC)  ioctl (fildes, TCXONC, TCOON);#    endif /* TCXONC */#  endif /* !TERMIOS_TTY_DRIVER */#endif /* !TIOCSTART */  return 0;}rl_stop_output (count, key)     int count, key;{  int fildes = fileno (rl_instream);#if defined (TIOCSTOP)# if defined (apollo)  ioctl (&fildes, TIOCSTOP, 0);# else  ioctl (fildes, TIOCSTOP, 0);# endif /* apollo */#else /* !TIOCSTOP */# if defined (TERMIOS_TTY_DRIVER)#  if defined (__ksr1__)  ksrflow = 1;#  endif /* ksr1 */  tcflow (fildes, TCOOFF);# else#   if defined (TCXONC)  ioctl (fildes, TCXONC, TCOON);#   endif /* TCXONC */# endif /* !TERMIOS_TTY_DRIVER */#endif /* !TIOCSTOP */  return 0;}/* **************************************************************** *//*								    *//*			Default Key Bindings			    *//*								    *//* **************************************************************** */voidrltty_set_default_bindings (kmap)     Keymap kmap;{  TIOTYPE ttybuff;  int tty = fileno (rl_instream);#if defined (NEW_TTY_DRIVER)#define SET_SPECIAL(sc, func) \  do \    { \      int ic; \      ic = sc; \      if (ic != -1 && kmap[ic].type == ISFUNC) \	kmap[ic].function = func; \    } \  while (0)  if (get_tty_settings (tty, &ttybuff) == 0)    {      if (ttybuff.flags & SGTTY_SET)	{	  SET_SPECIAL (ttybuff.sgttyb.sg_erase, rl_rubout);	  SET_SPECIAL (ttybuff.sgttyb.sg_kill, rl_unix_line_discard);	}#  if defined (TIOCGLTC)      if (ttybuff.flags & LTCHARS_SET)	{	  SET_SPECIAL (ttybuff.ltchars.t_werasc, rl_unix_word_rubout);	  SET_SPECIAL (ttybuff.ltchars.t_lnextc, rl_quoted_insert);	}#  endif /* TIOCGLTC */    }#else /* !NEW_TTY_DRIVER */#define SET_SPECIAL(sc, func) \  do \    { \      unsigned char uc; \      uc = ttybuff.c_cc[sc]; \      if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC) \	kmap[uc].function = func; \    } \  while (0)  if (get_tty_settings (tty, &ttybuff) == 0)    {      SET_SPECIAL (VERASE, rl_rubout);      SET_SPECIAL (VKILL, rl_unix_line_discard);#  if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER)      SET_SPECIAL (VLNEXT, rl_quoted_insert);#  endif /* VLNEXT && TERMIOS_TTY_DRIVER */#  if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER)      SET_SPECIAL (VWERASE, rl_unix_word_rubout);#  endif /* VWERASE && TERMIOS_TTY_DRIVER */    }#endif /* !NEW_TTY_DRIVER */}

⌨️ 快捷键说明

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