Edinburgh Speech Tools 2.4-release
el_sys_unix.c
1/****************************************************************************/
2/* */
3/* Copyright 1992 Simmule Turner and Rich Salz. All rights reserved. */
4/* */
5/* This software is not subject to any license of the American Telephone */
6/* and Telegraph Company or of the Regents of the University of California. */
7/* */
8/* Permission is granted to anyone to use this software for any purpose on */
9/* any computer system, and to alter it and redistribute it freely, subject */
10/* to the following restrictions: */
11/* 1. The authors are not responsible for the consequences of use of this */
12/* software, no matter how awful, even if they arise from flaws in it. */
13/* 2. The origin of this software must not be misrepresented, either by */
14/* explicit claim or by omission. Since few users ever read sources, */
15/* credits must appear in the documentation. */
16/* 3. Altered versions must be plainly marked as such, and must not be */
17/* misrepresented as being the original software. Since few users */
18/* ever read sources, credits must appear in the documentation. */
19/* 4. This notice may not be removed or altered. */
20/* */
21/****************************************************************************/
22/* */
23/* This is a line-editing library, it can be linked into almost any */
24/* program to provide command-line editing and recall. */
25/* */
26/* Posted to comp.sources.misc Sun, 2 Aug 1992 03:05:27 GMT */
27/* by rsalz@osf.org (Rich $alz) */
28/* */
29/****************************************************************************/
30/* */
31/* The version contained here has some modifications by awb@cstr.ed.ac.uk */
32/* (Alan W Black) in order to integrate it with the Edinburgh Speech Tools */
33/* library and Scheme-in-one-defun in particular. All modifications to */
34/* to this work are continued with the same copyright above. That is */
35/* this version of editline does not have the "no commercial use" */
36/* restriction that some of the rest of the EST library may have */
37/* awb Dec 30 1998 */
38/* */
39/****************************************************************************/
40/* $Revision: 1.2 $
41**
42** Unix system-dependant routines for editline library.
43*/
44#include "editline.h"
45
46#include <unistd.h>
47#include <sys/types.h>
48#include <signal.h>
49
50extern CONST ECHAR el_NIL[];
51
52int el_user_intr = 0;
53int el_PushBack=0;
54int el_Pushed=0;
55CONST ECHAR *el_Input = el_NIL;
56
57extern void TTYflush();
58
59#if defined(HAVE_TCGETATTR)
60#include <termios.h>
61
62void rl_ttyset(int Reset)
63{
64 static struct termios old;
65 struct termios new;
66
67 if (Reset == 0) {
68 (void)tcgetattr(0, &old);
69 rl_erase = old.c_cc[VERASE];
70 rl_kill = old.c_cc[VKILL];
71 rl_eof = old.c_cc[VEOF];
72 rl_intr = old.c_cc[VINTR];
73 rl_quit = old.c_cc[VQUIT];
74
75 new = old;
76 new.c_cc[VINTR] = -1;
77 new.c_cc[VQUIT] = -1;
78 new.c_lflag &= ~(ECHO | ICANON);
79 new.c_iflag &= ~(ISTRIP | INPCK);
80 new.c_cc[VMIN] = 1;
81 new.c_cc[VTIME] = 0;
82#ifdef VDSUSP
83 /* On Solaris (non-posix) DSUSP is ^Y, cancel it (awb 30/12/98) */
84 new.c_cc[VDSUSP] = -1;
85#endif
86
87 (void)tcsetattr(0, TCSANOW, &new);
88 }
89 else
90 (void)tcsetattr(0, TCSANOW, &old);
91}
92
93#else
94#include <sgtty.h>
95
96void rl_ttyset(int Reset)
97{
98 static struct sgttyb old_sgttyb;
99 static struct tchars old_tchars;
100 struct sgttyb new_sgttyb;
101 struct tchars new_tchars;
102
103 if (Reset == 0) {
104 (void)ioctl(0, TIOCGETP, &old_sgttyb);
105 rl_erase = old_sgttyb.sg_erase;
106 rl_kill = old_sgttyb.sg_kill;
107
108 (void)ioctl(0, TIOCGETC, &old_tchars);
109 rl_eof = old_tchars.t_eofc;
110 rl_intr = old_tchars.t_intrc;
111 rl_quit = old_tchars.t_quitc;
112
113 new_sgttyb = old_sgttyb;
114 new_sgttyb.sg_flags &= ~ECHO;
115 new_sgttyb.sg_flags |= RAW;
116#if defined(PASS8)
117 new_sgttyb.sg_flags |= PASS8;
118#endif /* defined(PASS8) */
119 (void)ioctl(0, TIOCSETP, &new_sgttyb);
120
121 new_tchars = old_tchars;
122 new_tchars.t_intrc = -1;
123 new_tchars.t_quitc = -1;
124 (void)ioctl(0, TIOCSETC, &new_tchars);
125 }
126 else {
127 (void)ioctl(0, TIOCSETP, &old_sgttyb);
128 (void)ioctl(0, TIOCSETC, &old_tchars);
129 }
130}
131#endif /* defined(HAVE_TCGETATTR) */
132
133unsigned int TTYget()
134{
135 ECHAR c;
136 int s;
137
138 TTYflush();
139 if (el_Pushed) {
140 el_Pushed = 0;
141 return el_PushBack;
142 }
143 if (*el_Input)
144 return *el_Input++;
145 s = read(0, &c, (ESIZE_T)1) == 1 ? c : EOF;
146 return s;
147}
148
149void rl_add_slash(char *path,char *p)
150{
151 struct stat Sb;
152
153 if (stat(path, &Sb) >= 0)
154 (void)strcat(p, S_ISDIR(Sb.st_mode) ? "/" : " ");
155}
156
157int el_is_directory(char *path)
158{
159 struct stat Sb;
160
161 if ((stat(path, &Sb) >= 0) && S_ISDIR(Sb.st_mode))
162 return 1;
163 else
164 return 0;
165}
166
167void do_user_intr()
168{
169 if (el_user_intr)
170 kill(getpid(),SIGINT);
171}