|
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* |
|
7 * Copyright 1992,1993 Simmule Turner and Rich Salz. All rights reserved. |
|
8 * |
|
9 * This software is not subject to any license of the American Telephone |
|
10 * and Telegraph Company or of the Regents of the University of California. |
|
11 * |
|
12 * Permission is granted to anyone to use this software for any purpose on |
|
13 * any computer system, and to alter it and redistribute it freely, subject |
|
14 * to the following restrictions: |
|
15 * 1. The authors are not responsible for the consequences of use of this |
|
16 * software, no matter how awful, even if they arise from flaws in it. |
|
17 * 2. The origin of this software must not be misrepresented, either by |
|
18 * explicit claim or by omission. Since few users ever read sources, |
|
19 * credits must appear in the documentation. |
|
20 * 3. Altered versions must be plainly marked as such, and must not be |
|
21 * misrepresented as being the original software. Since few users |
|
22 * ever read sources, credits must appear in the documentation. |
|
23 * 4. This notice may not be removed or altered. |
|
24 */ |
|
25 |
|
26 |
|
27 /* |
|
28 ** Unix system-dependant routines for editline library. |
|
29 */ |
|
30 #include "editline.h" |
|
31 |
|
32 #if defined(HAVE_TCGETATTR) |
|
33 #include <termios.h> |
|
34 |
|
35 void |
|
36 rl_ttyset(Reset) |
|
37 int Reset; |
|
38 { |
|
39 static struct termios old; |
|
40 struct termios new; |
|
41 |
|
42 if (Reset == 0) { |
|
43 (void)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 (void)tcsetattr(0, TCSADRAIN, &new); |
|
58 } |
|
59 else |
|
60 (void)tcsetattr(0, TCSADRAIN, &old); |
|
61 } |
|
62 |
|
63 #else |
|
64 #if defined(HAVE_TERMIO) |
|
65 #include <termio.h> |
|
66 |
|
67 void |
|
68 rl_ttyset(Reset) |
|
69 int Reset; |
|
70 { |
|
71 static struct termio old; |
|
72 struct termio new; |
|
73 |
|
74 if (Reset == 0) { |
|
75 (void)ioctl(0, TCGETA, &old); |
|
76 rl_erase = old.c_cc[VERASE]; |
|
77 rl_kill = old.c_cc[VKILL]; |
|
78 rl_eof = old.c_cc[VEOF]; |
|
79 rl_intr = old.c_cc[VINTR]; |
|
80 rl_quit = old.c_cc[VQUIT]; |
|
81 |
|
82 new = old; |
|
83 new.c_cc[VINTR] = -1; |
|
84 new.c_cc[VQUIT] = -1; |
|
85 new.c_lflag &= ~(ECHO | ICANON); |
|
86 new.c_iflag &= ~(ISTRIP | INPCK); |
|
87 new.c_cc[VMIN] = 1; |
|
88 new.c_cc[VTIME] = 0; |
|
89 (void)ioctl(0, TCSETAW, &new); |
|
90 } |
|
91 else |
|
92 (void)ioctl(0, TCSETAW, &old); |
|
93 } |
|
94 |
|
95 #else |
|
96 #include <sgtty.h> |
|
97 |
|
98 void |
|
99 rl_ttyset(Reset) |
|
100 int Reset; |
|
101 { |
|
102 static struct sgttyb old_sgttyb; |
|
103 static struct tchars old_tchars; |
|
104 struct sgttyb new_sgttyb; |
|
105 struct tchars new_tchars; |
|
106 |
|
107 if (Reset == 0) { |
|
108 (void)ioctl(0, TIOCGETP, &old_sgttyb); |
|
109 rl_erase = old_sgttyb.sg_erase; |
|
110 rl_kill = old_sgttyb.sg_kill; |
|
111 |
|
112 (void)ioctl(0, TIOCGETC, &old_tchars); |
|
113 rl_eof = old_tchars.t_eofc; |
|
114 rl_intr = old_tchars.t_intrc; |
|
115 rl_quit = old_tchars.t_quitc; |
|
116 |
|
117 new_sgttyb = old_sgttyb; |
|
118 new_sgttyb.sg_flags &= ~ECHO; |
|
119 new_sgttyb.sg_flags |= RAW; |
|
120 #if defined(PASS8) |
|
121 new_sgttyb.sg_flags |= PASS8; |
|
122 #endif /* defined(PASS8) */ |
|
123 (void)ioctl(0, TIOCSETP, &new_sgttyb); |
|
124 |
|
125 new_tchars = old_tchars; |
|
126 new_tchars.t_intrc = -1; |
|
127 new_tchars.t_quitc = -1; |
|
128 (void)ioctl(0, TIOCSETC, &new_tchars); |
|
129 } |
|
130 else { |
|
131 (void)ioctl(0, TIOCSETP, &old_sgttyb); |
|
132 (void)ioctl(0, TIOCSETC, &old_tchars); |
|
133 } |
|
134 } |
|
135 #endif /* defined(HAVE_TERMIO) */ |
|
136 #endif /* defined(HAVE_TCGETATTR) */ |
|
137 |
|
138 void |
|
139 rl_add_slash(path, p) |
|
140 char *path; |
|
141 char *p; |
|
142 { |
|
143 struct stat Sb; |
|
144 |
|
145 if (stat(path, &Sb) >= 0) |
|
146 (void)strcat(p, S_ISDIR(Sb.st_mode) ? "/" : " "); |
|
147 } |
|
148 |