~ubuntu-branches/ubuntu/saucy/mozjs17/saucy

« back to all changes in this revision

Viewing changes to js/src/editline/sysunix.c

  • Committer: Package Import Robot
  • Author(s): Rico Tzschichholz
  • Date: 2013-05-25 12:24:23 UTC
  • Revision ID: package-import@ubuntu.com-20130525122423-zmxucrhtensw90xy
Tags: upstream-17.0.0
ImportĀ upstreamĀ versionĀ 17.0.0

Show diffs side-by-side

added added

removed removed

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