| 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(int Reset) |
| 37 |
{ |
| 38 |
static struct termios old; |
| 39 |
struct termios new; |
| 40 |
|
| 41 |
if (Reset == 0) { |
| 42 |
(void)tcgetattr(0, &old); |
| 43 |
rl_erase = old.c_cc[VERASE]; |
| 44 |
rl_kill = old.c_cc[VKILL]; |
| 45 |
rl_eof = old.c_cc[VEOF]; |
| 46 |
rl_intr = old.c_cc[VINTR]; |
| 47 |
rl_quit = old.c_cc[VQUIT]; |
| 48 |
|
| 49 |
new = old; |
| 50 |
new.c_cc[VINTR] = -1; |
| 51 |
new.c_cc[VQUIT] = -1; |
| 52 |
new.c_lflag &= ~(ECHO | ICANON); |
| 53 |
new.c_iflag &= ~(ISTRIP | INPCK); |
| 54 |
new.c_cc[VMIN] = 1; |
| 55 |
new.c_cc[VTIME] = 0; |
| 56 |
(void)tcsetattr(0, TCSADRAIN, &new); |
| 57 |
} |
| 58 |
else |
| 59 |
(void)tcsetattr(0, TCSADRAIN, &old); |
| 60 |
} |
| 61 |
|
| 62 |
#else |
| 63 |
#if defined(HAVE_TERMIO) |
| 64 |
#include <termio.h> |
| 65 |
|
| 66 |
void |
| 67 |
rl_ttyset(int Reset) |
| 68 |
{ |
| 69 |
static struct termio old; |
| 70 |
struct termio new; |
| 71 |
|
| 72 |
if (Reset == 0) { |
| 73 |
(void)ioctl(0, TCGETA, &old); |
| 74 |
rl_erase = old.c_cc[VERASE]; |
| 75 |
rl_kill = old.c_cc[VKILL]; |
| 76 |
rl_eof = old.c_cc[VEOF]; |
| 77 |
rl_intr = old.c_cc[VINTR]; |
| 78 |
rl_quit = old.c_cc[VQUIT]; |
| 79 |
|
| 80 |
new = old; |
| 81 |
new.c_cc[VINTR] = -1; |
| 82 |
new.c_cc[VQUIT] = -1; |
| 83 |
new.c_lflag &= ~(ECHO | ICANON); |
| 84 |
new.c_iflag &= ~(ISTRIP | INPCK); |
| 85 |
new.c_cc[VMIN] = 1; |
| 86 |
new.c_cc[VTIME] = 0; |
| 87 |
(void)ioctl(0, TCSETAW, &new); |
| 88 |
} |
| 89 |
else |
| 90 |
(void)ioctl(0, TCSETAW, &old); |
| 91 |
} |
| 92 |
|
| 93 |
#else |
| 94 |
#include <sgtty.h> |
| 95 |
|
| 96 |
void |
| 97 |
rl_ttyset(int Reset) |
| 98 |
{ |
| 99 |
static struct sgttyb old_sgttyb; |
| 100 |
static struct tchars old_tchars; |
| 101 |
struct sgttyb new_sgttyb; |
| 102 |
struct tchars new_tchars; |
| 103 |
|
| 104 |
if (Reset == 0) { |
| 105 |
(void)ioctl(0, TIOCGETP, &old_sgttyb); |
| 106 |
rl_erase = old_sgttyb.sg_erase; |
| 107 |
rl_kill = old_sgttyb.sg_kill; |
| 108 |
|
| 109 |
(void)ioctl(0, TIOCGETC, &old_tchars); |
| 110 |
rl_eof = old_tchars.t_eofc; |
| 111 |
rl_intr = old_tchars.t_intrc; |
| 112 |
rl_quit = old_tchars.t_quitc; |
| 113 |
|
| 114 |
new_sgttyb = old_sgttyb; |
| 115 |
new_sgttyb.sg_flags &= ~ECHO; |
| 116 |
new_sgttyb.sg_flags |= RAW; |
| 117 |
#if defined(PASS8) |
| 118 |
new_sgttyb.sg_flags |= PASS8; |
| 119 |
#endif /* defined(PASS8) */ |
| 120 |
(void)ioctl(0, TIOCSETP, &new_sgttyb); |
| 121 |
|
| 122 |
new_tchars = old_tchars; |
| 123 |
new_tchars.t_intrc = -1; |
| 124 |
new_tchars.t_quitc = -1; |
| 125 |
(void)ioctl(0, TIOCSETC, &new_tchars); |
| 126 |
} |
| 127 |
else { |
| 128 |
(void)ioctl(0, TIOCSETP, &old_sgttyb); |
| 129 |
(void)ioctl(0, TIOCSETC, &old_tchars); |
| 130 |
} |
| 131 |
} |
| 132 |
#endif /* defined(HAVE_TERMIO) */ |
| 133 |
#endif /* defined(HAVE_TCGETATTR) */ |
| 134 |
|
| 135 |
void |
| 136 |
rl_add_slash(char *path, char *p) |
| 137 |
{ |
| 138 |
struct stat Sb; |
| 139 |
|
| 140 |
if (stat(path, &Sb) >= 0) |
| 141 |
(void)strcat(p, S_ISDIR(Sb.st_mode) ? "/" : " "); |
| 142 |
} |
| 143 |
|