michael@0: /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * Copyright 1992,1993 Simmule Turner and Rich Salz. All rights reserved. michael@0: * michael@0: * This software is not subject to any license of the American Telephone michael@0: * and Telegraph Company or of the Regents of the University of California. michael@0: * michael@0: * Permission is granted to anyone to use this software for any purpose on michael@0: * any computer system, and to alter it and redistribute it freely, subject michael@0: * to the following restrictions: michael@0: * 1. The authors are not responsible for the consequences of use of this michael@0: * software, no matter how awful, even if they arise from flaws in it. michael@0: * 2. The origin of this software must not be misrepresented, either by michael@0: * explicit claim or by omission. Since few users ever read sources, michael@0: * credits must appear in the documentation. michael@0: * 3. Altered versions must be plainly marked as such, and must not be michael@0: * misrepresented as being the original software. Since few users michael@0: * ever read sources, credits must appear in the documentation. michael@0: * 4. This notice may not be removed or altered. michael@0: */ michael@0: michael@0: michael@0: /* michael@0: ** Unix system-dependant routines for editline library. michael@0: */ michael@0: #include "editline.h" michael@0: michael@0: #if defined(HAVE_TCGETATTR) michael@0: #include michael@0: michael@0: void michael@0: rl_ttyset(Reset) michael@0: int Reset; michael@0: { michael@0: static struct termios old; michael@0: struct termios new; michael@0: michael@0: if (Reset == 0) { michael@0: (void)tcgetattr(0, &old); michael@0: rl_erase = old.c_cc[VERASE]; michael@0: rl_kill = old.c_cc[VKILL]; michael@0: rl_eof = old.c_cc[VEOF]; michael@0: rl_intr = old.c_cc[VINTR]; michael@0: rl_quit = old.c_cc[VQUIT]; michael@0: michael@0: new = old; michael@0: new.c_cc[VINTR] = -1; michael@0: new.c_cc[VQUIT] = -1; michael@0: new.c_lflag &= ~(ECHO | ICANON); michael@0: new.c_iflag &= ~(ISTRIP | INPCK); michael@0: new.c_cc[VMIN] = 1; michael@0: new.c_cc[VTIME] = 0; michael@0: (void)tcsetattr(0, TCSADRAIN, &new); michael@0: } michael@0: else michael@0: (void)tcsetattr(0, TCSADRAIN, &old); michael@0: } michael@0: michael@0: #else michael@0: #if defined(HAVE_TERMIO) michael@0: #include michael@0: michael@0: void michael@0: rl_ttyset(Reset) michael@0: int Reset; michael@0: { michael@0: static struct termio old; michael@0: struct termio new; michael@0: michael@0: if (Reset == 0) { michael@0: (void)ioctl(0, TCGETA, &old); michael@0: rl_erase = old.c_cc[VERASE]; michael@0: rl_kill = old.c_cc[VKILL]; michael@0: rl_eof = old.c_cc[VEOF]; michael@0: rl_intr = old.c_cc[VINTR]; michael@0: rl_quit = old.c_cc[VQUIT]; michael@0: michael@0: new = old; michael@0: new.c_cc[VINTR] = -1; michael@0: new.c_cc[VQUIT] = -1; michael@0: new.c_lflag &= ~(ECHO | ICANON); michael@0: new.c_iflag &= ~(ISTRIP | INPCK); michael@0: new.c_cc[VMIN] = 1; michael@0: new.c_cc[VTIME] = 0; michael@0: (void)ioctl(0, TCSETAW, &new); michael@0: } michael@0: else michael@0: (void)ioctl(0, TCSETAW, &old); michael@0: } michael@0: michael@0: #else michael@0: #include michael@0: michael@0: void michael@0: rl_ttyset(Reset) michael@0: int Reset; michael@0: { michael@0: static struct sgttyb old_sgttyb; michael@0: static struct tchars old_tchars; michael@0: struct sgttyb new_sgttyb; michael@0: struct tchars new_tchars; michael@0: michael@0: if (Reset == 0) { michael@0: (void)ioctl(0, TIOCGETP, &old_sgttyb); michael@0: rl_erase = old_sgttyb.sg_erase; michael@0: rl_kill = old_sgttyb.sg_kill; michael@0: michael@0: (void)ioctl(0, TIOCGETC, &old_tchars); michael@0: rl_eof = old_tchars.t_eofc; michael@0: rl_intr = old_tchars.t_intrc; michael@0: rl_quit = old_tchars.t_quitc; michael@0: michael@0: new_sgttyb = old_sgttyb; michael@0: new_sgttyb.sg_flags &= ~ECHO; michael@0: new_sgttyb.sg_flags |= RAW; michael@0: #if defined(PASS8) michael@0: new_sgttyb.sg_flags |= PASS8; michael@0: #endif /* defined(PASS8) */ michael@0: (void)ioctl(0, TIOCSETP, &new_sgttyb); michael@0: michael@0: new_tchars = old_tchars; michael@0: new_tchars.t_intrc = -1; michael@0: new_tchars.t_quitc = -1; michael@0: (void)ioctl(0, TIOCSETC, &new_tchars); michael@0: } michael@0: else { michael@0: (void)ioctl(0, TIOCSETP, &old_sgttyb); michael@0: (void)ioctl(0, TIOCSETC, &old_tchars); michael@0: } michael@0: } michael@0: #endif /* defined(HAVE_TERMIO) */ michael@0: #endif /* defined(HAVE_TCGETATTR) */ michael@0: michael@0: void michael@0: rl_add_slash(path, p) michael@0: char *path; michael@0: char *p; michael@0: { michael@0: struct stat Sb; michael@0: michael@0: if (stat(path, &Sb) >= 0) michael@0: (void)strcat(p, S_ISDIR(Sb.st_mode) ? "/" : " "); michael@0: } michael@0: