Merge from vendor branch HEIMDAL:
[dragonfly.git] / crypto / heimdal-0.6.3 / lib / editline / sysunix.c
1 /*  Copyright 1992 Simmule Turner and Rich Salz.  All rights reserved. 
2  *
3  *  This software is not subject to any license of the American Telephone 
4  *  and Telegraph Company or of the Regents of the University of California. 
5  *
6  *  Permission is granted to anyone to use this software for any purpose on
7  *  any computer system, and to alter it and redistribute it freely, subject
8  *  to the following restrictions:
9  *  1. The authors are not responsible for the consequences of use of this
10  *     software, no matter how awful, even if they arise from flaws in it.
11  *  2. The origin of this software must not be misrepresented, either by
12  *     explicit claim or by omission.  Since few users ever read sources,
13  *     credits must appear in the documentation.
14  *  3. Altered versions must be plainly marked as such, and must not be
15  *     misrepresented as being the original software.  Since few users
16  *     ever read sources, credits must appear in the documentation.
17  *  4. This notice may not be removed or altered.
18  */
19
20 /*
21 **  Unix system-dependant routines for editline library.
22 */
23 #include <config.h>
24 #include "editline.h"
25
26 #ifdef HAVE_TERMIOS_H
27 #include <termios.h>
28 #else
29 #include <sgtty.h>
30 #endif
31
32 RCSID("$Id: sysunix.c,v 1.4 1999/04/08 13:08:24 joda Exp $");
33
34 #ifdef HAVE_TERMIOS_H
35
36 void
37 rl_ttyset(int Reset)
38 {
39     static struct termios       old;
40     struct termios              new;
41     
42     if (Reset == 0) {
43         tcgetattr(0, &old);
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
50         new = old;
51         new.c_cc[VINTR] = -1;
52         new.c_cc[VQUIT] = -1;
53         new.c_lflag &= ~(ECHO | ICANON);
54         new.c_iflag &= ~(ISTRIP | INPCK);
55         new.c_cc[VMIN] = 1;
56         new.c_cc[VTIME] = 0;
57         tcsetattr(0, TCSANOW, &new);
58     }
59     else
60         tcsetattr(0, TCSANOW, &old);
61 }
62
63 #else /* !HAVE_TERMIOS_H */
64
65 void
66 rl_ttyset(int Reset)
67 {
68        static struct sgttyb old;
69        struct sgttyb new;
70
71        if (Reset == 0) {
72                ioctl(0, TIOCGETP, &old);
73                rl_erase = old.sg_erase;
74                rl_kill = old.sg_kill;
75                new = old;
76                new.sg_flags &= ~(ECHO | ICANON);
77                new.sg_flags &= ~(ISTRIP | INPCK);
78                ioctl(0, TIOCSETP, &new);
79        } else {
80                ioctl(0, TIOCSETP, &old);
81        }
82 }
83 #endif /* HAVE_TERMIOS_H */
84
85 void
86 rl_add_slash(char *path, char *p)
87 {
88     struct stat Sb;
89     
90     if (stat(path, &Sb) >= 0)
91         strcat(p, S_ISDIR(Sb.st_mode) ? "/" : " ");
92 }