openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

sysunix.c (4335B)


      1 /*  $Revision: 1.5 $
      2 **
      3 **  Unix system-dependant routines for editline library.
      4 */
      5 
      6 #if defined(SYS_UNIX) && defined(INCLUDE_EDITLINE)
      7 
      8 #include "editline.h"
      9 
     10 /*
     11  Controls if changes need to ocur. . If we've already transitioned into the 
     12  requested mode do nothing. This allows for synchronous and asynchronous
     13  modes to work.
     14 
     15  sal_readline, synchronous editline, makes sure to put the tty back into
     16  cooked mode prior to exit. Asynchronous mode need to keep the tty in raw
     17  mode until an asynchronous exit from the shell.
     18 
     19  Values are:
     20   -1 Default initialize value which can not be 0 or 1. This is neccessary so 
     21      that when Reset is called the first time with either 0 or 1 that 
     22      actions will be taken.
     23   0 put device into raw mode. Disable echo so that editline can control it.
     24   1 restore device back to mode prior to raw mode.
     25 */
     26 static int sRESET_CURRENT = -1;
     27 
     28 #if	defined(HAVE_TCGETATTR)
     29 #include <termios.h>
     30 
     31 void
     32 rl_ttyset(Reset)
     33     int				Reset;
     34 {
     35     static struct termios old;
     36     struct termios		  new;
     37 
     38     if (Reset != sRESET_CURRENT) {
     39       sRESET_CURRENT = Reset;
     40       if (Reset == 0) {
     41 	    if (tcgetattr(0, &old) < 0) {
     42           perror("tcgetattr");
     43         }
     44 	    rl_erase = old.c_cc[VERASE];
     45 	    rl_kill = old.c_cc[VKILL];
     46 	    rl_eof = old.c_cc[VEOF];
     47 	    rl_intr = old.c_cc[VINTR];
     48 	    rl_quit = old.c_cc[VQUIT];
     49 #if	defined(DO_SIGTSTP)
     50 	    rl_susp = old.c_cc[VSUSP];
     51 #endif	/* defined(DO_SIGTSTP) */
     52 
     53 	    new = old;
     54 #if 0
     55 	    new.c_lflag &= ~(ECHO | ICANON | ISIG);
     56 #else
     57 	    new.c_lflag &= ~(ECHO | ICANON);
     58 #endif
     59 	    new.c_iflag &= ~(ISTRIP | INPCK);
     60 	    new.c_cc[VMIN] = 1;
     61 	    new.c_cc[VTIME] = 0;
     62 	    if (tcsetattr(0, TCSADRAIN, &new) < 0) {
     63           perror("tcsetattr");
     64         }
     65       } else {
     66         /* Reset must be 1. */
     67 	    (void)tcsetattr(0, TCSADRAIN, &old);
     68       }
     69     }
     70 }
     71 
     72 #else
     73 #if	defined(HAVE_TERMIO)
     74 #include <termio.h>
     75 
     76 void
     77 rl_ttyset(Reset)
     78     int				Reset;
     79 {
     80     static struct termio old;
     81     struct termio		 new;
     82 
     83     if (Reset != sRESET_CURRENT) {
     84       sRESET_CURRENT = Reset;
     85       if (Reset == 0) {
     86         (void)ioctl(0, TCGETA, &old);
     87 	    rl_erase = old.c_cc[VERASE];
     88 	    rl_kill = old.c_cc[VKILL];
     89 	    rl_eof = old.c_cc[VEOF];
     90 	    rl_intr = old.c_cc[VINTR];
     91 	    rl_quit = old.c_cc[VQUIT];
     92 #if	defined(DO_SIGTSTP)
     93 	    rl_susp = old.c_cc[VSUSP];
     94 #endif	/* defined(DO_SIGTSTP) */
     95 
     96 	    new = old;
     97 #if 0
     98 	    new.c_lflag &= ~(ECHO | ICANON | ISIG);
     99 #else
    100 	    new.c_lflag &= ~(ECHO | ICANON);
    101 #endif
    102 	    new.c_iflag &= ~(ISTRIP | INPCK);
    103 	    new.c_cc[VMIN] = 1;
    104 	    new.c_cc[VTIME] = 0;
    105 	    (void)ioctl(0, TCSETAW, &new);
    106       } else {
    107         (void)ioctl(0, TCSETAW, &old);
    108       }
    109     }
    110 }
    111 
    112 #else
    113 #include <sgtty.h>
    114 
    115 void
    116 rl_ttyset(Reset)
    117     int				Reset;
    118 {
    119     static struct sgttyb	old_sgttyb;
    120     static struct tchars	old_tchars;
    121     struct sgttyb		new_sgttyb;
    122     struct tchars		new_tchars;
    123 #if	defined(DO_SIGTSTP)
    124     struct ltchars		old_ltchars;
    125 #endif	/* defined(DO_SIGTSTP) */
    126 
    127     if (Reset != sRESET_CURRENT) {
    128       sRESET_CURRENT = Reset;
    129       if (Reset == 0) {
    130 	    (void)ioctl(0, TIOCGETP, &old_sgttyb);
    131 	    rl_erase = old_sgttyb.sg_erase;
    132 	    rl_kill = old_sgttyb.sg_kill;
    133 
    134 	    (void)ioctl(0, TIOCGETC, &old_tchars);
    135 	    rl_eof = old_tchars.t_eofc;
    136 	    rl_intr = old_tchars.t_intrc;
    137 	    rl_quit = old_tchars.t_quitc;
    138 
    139 #if	defined(DO_SIGTSTP)
    140 	    (void)ioctl(0, TIOCGLTC, &old_ltchars);
    141 	    rl_susp = old_ltchars.t_suspc;
    142 #endif	/* defined(DO_SIGTSTP) */
    143 
    144 	    new_sgttyb = old_sgttyb;
    145 	    new_sgttyb.sg_flags &= ~ECHO;
    146 	    new_sgttyb.sg_flags |= RAW;
    147 #if	defined(PASS8)
    148 	    new_sgttyb.sg_flags |= PASS8;
    149 #endif	/* defined(PASS8) */
    150 	    (void)ioctl(0, TIOCSETP, &new_sgttyb);
    151   
    152 	    new_tchars = old_tchars;
    153 	    new_tchars.t_intrc = -1;
    154 	    new_tchars.t_quitc = -1;
    155 	  (void)ioctl(0, TIOCSETC, &new_tchars);
    156       } else { (void)ioctl(0, TIOCSETP, &old_sgttyb);
    157         (void)ioctl(0, TIOCSETC, &old_tchars);
    158       }
    159     }
    160 }
    161 #endif	/* defined(HAVE_TERMIO) */
    162 #endif	/* defined(HAVE_TCGETATTR) */
    163 
    164 void
    165 rl_add_slash(path, p)
    166     char	*path;
    167     char	*p;
    168 {
    169 #if     defined(USE_POSIX_COMPLETION)
    170     struct stat	Sb;
    171 
    172     if (stat(path, &Sb) >= 0)
    173 	(void)strcat(p, S_ISDIR(Sb.st_mode) ? "/" : " ");
    174 #endif
    175 }
    176 
    177 #endif /* defined(SYS_UNIX) && defined(INCLUDE_EDITLINE) */
    178 
    179 int _bcm_diag_editline_sysunix_not_empty;