js/src/editline/sysunix.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/editline/sysunix.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,148 @@
     1.4 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * Copyright 1992,1993 Simmule Turner and Rich Salz.  All rights reserved.
    1.11 + *
    1.12 + * This software is not subject to any license of the American Telephone
    1.13 + * and Telegraph Company or of the Regents of the University of California.
    1.14 + *
    1.15 + * Permission is granted to anyone to use this software for any purpose on
    1.16 + * any computer system, and to alter it and redistribute it freely, subject
    1.17 + * to the following restrictions:
    1.18 + * 1. The authors are not responsible for the consequences of use of this
    1.19 + *    software, no matter how awful, even if they arise from flaws in it.
    1.20 + * 2. The origin of this software must not be misrepresented, either by
    1.21 + *    explicit claim or by omission.  Since few users ever read sources,
    1.22 + *    credits must appear in the documentation.
    1.23 + * 3. Altered versions must be plainly marked as such, and must not be
    1.24 + *    misrepresented as being the original software.  Since few users
    1.25 + *    ever read sources, credits must appear in the documentation.
    1.26 + * 4. This notice may not be removed or altered.
    1.27 + */
    1.28 +
    1.29 +
    1.30 +/*
    1.31 +**  Unix system-dependant routines for editline library.
    1.32 +*/
    1.33 +#include "editline.h"
    1.34 +
    1.35 +#if	defined(HAVE_TCGETATTR)
    1.36 +#include <termios.h>
    1.37 +
    1.38 +void
    1.39 +rl_ttyset(Reset)
    1.40 +    int				Reset;
    1.41 +{
    1.42 +    static struct termios	old;
    1.43 +    struct termios		new;
    1.44 +
    1.45 +    if (Reset == 0) {
    1.46 +	(void)tcgetattr(0, &old);
    1.47 +	rl_erase = old.c_cc[VERASE];
    1.48 +	rl_kill = old.c_cc[VKILL];
    1.49 +	rl_eof = old.c_cc[VEOF];
    1.50 +	rl_intr = old.c_cc[VINTR];
    1.51 +	rl_quit = old.c_cc[VQUIT];
    1.52 +
    1.53 +	new = old;
    1.54 +	new.c_cc[VINTR] = -1;
    1.55 +	new.c_cc[VQUIT] = -1;
    1.56 +	new.c_lflag &= ~(ECHO | ICANON);
    1.57 +	new.c_iflag &= ~(ISTRIP | INPCK);
    1.58 +	new.c_cc[VMIN] = 1;
    1.59 +	new.c_cc[VTIME] = 0;
    1.60 +	(void)tcsetattr(0, TCSADRAIN, &new);
    1.61 +    }
    1.62 +    else
    1.63 +	(void)tcsetattr(0, TCSADRAIN, &old);
    1.64 +}
    1.65 +
    1.66 +#else
    1.67 +#if	defined(HAVE_TERMIO)
    1.68 +#include <termio.h>
    1.69 +
    1.70 +void
    1.71 +rl_ttyset(Reset)
    1.72 +    int				Reset;
    1.73 +{
    1.74 +    static struct termio	old;
    1.75 +    struct termio		new;
    1.76 +
    1.77 +    if (Reset == 0) {
    1.78 +	(void)ioctl(0, TCGETA, &old);
    1.79 +	rl_erase = old.c_cc[VERASE];
    1.80 +	rl_kill = old.c_cc[VKILL];
    1.81 +	rl_eof = old.c_cc[VEOF];
    1.82 +	rl_intr = old.c_cc[VINTR];
    1.83 +	rl_quit = old.c_cc[VQUIT];
    1.84 +
    1.85 +	new = old;
    1.86 +	new.c_cc[VINTR] = -1;
    1.87 +	new.c_cc[VQUIT] = -1;
    1.88 +	new.c_lflag &= ~(ECHO | ICANON);
    1.89 +	new.c_iflag &= ~(ISTRIP | INPCK);
    1.90 +	new.c_cc[VMIN] = 1;
    1.91 +	new.c_cc[VTIME] = 0;
    1.92 +	(void)ioctl(0, TCSETAW, &new);
    1.93 +    }
    1.94 +    else
    1.95 +	(void)ioctl(0, TCSETAW, &old);
    1.96 +}
    1.97 +
    1.98 +#else
    1.99 +#include <sgtty.h>
   1.100 +
   1.101 +void
   1.102 +rl_ttyset(Reset)
   1.103 +    int				Reset;
   1.104 +{
   1.105 +    static struct sgttyb	old_sgttyb;
   1.106 +    static struct tchars	old_tchars;
   1.107 +    struct sgttyb		new_sgttyb;
   1.108 +    struct tchars		new_tchars;
   1.109 +
   1.110 +    if (Reset == 0) {
   1.111 +	(void)ioctl(0, TIOCGETP, &old_sgttyb);
   1.112 +	rl_erase = old_sgttyb.sg_erase;
   1.113 +	rl_kill = old_sgttyb.sg_kill;
   1.114 +
   1.115 +	(void)ioctl(0, TIOCGETC, &old_tchars);
   1.116 +	rl_eof = old_tchars.t_eofc;
   1.117 +	rl_intr = old_tchars.t_intrc;
   1.118 +	rl_quit = old_tchars.t_quitc;
   1.119 +
   1.120 +	new_sgttyb = old_sgttyb;
   1.121 +	new_sgttyb.sg_flags &= ~ECHO;
   1.122 +	new_sgttyb.sg_flags |= RAW;
   1.123 +#if	defined(PASS8)
   1.124 +	new_sgttyb.sg_flags |= PASS8;
   1.125 +#endif	/* defined(PASS8) */
   1.126 +	(void)ioctl(0, TIOCSETP, &new_sgttyb);
   1.127 +
   1.128 +	new_tchars = old_tchars;
   1.129 +	new_tchars.t_intrc = -1;
   1.130 +	new_tchars.t_quitc = -1;
   1.131 +	(void)ioctl(0, TIOCSETC, &new_tchars);
   1.132 +    }
   1.133 +    else {
   1.134 +	(void)ioctl(0, TIOCSETP, &old_sgttyb);
   1.135 +	(void)ioctl(0, TIOCSETC, &old_tchars);
   1.136 +    }
   1.137 +}
   1.138 +#endif	/* defined(HAVE_TERMIO) */
   1.139 +#endif	/* defined(HAVE_TCGETATTR) */
   1.140 +
   1.141 +void
   1.142 +rl_add_slash(path, p)
   1.143 +    char	*path;
   1.144 +    char	*p;
   1.145 +{
   1.146 +    struct stat	Sb;
   1.147 +
   1.148 +    if (stat(path, &Sb) >= 0)
   1.149 +	(void)strcat(p, S_ISDIR(Sb.st_mode) ? "/" : " ");
   1.150 +}
   1.151 +

mercurial