Edinburgh Speech Tools  2.1-release
el_sys_unix.c
Go to the documentation of this file.
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 #define _POSIX_SOURCE
45 #include "editline.h"
46 
47 #include <unistd.h>
48 #include <sys/types.h>
49 #include <signal.h>
50 
51 extern CONST ECHAR el_NIL[];
52 
53 int el_user_intr = 0;
55 int el_Pushed=0;
57 
58 extern void TTYflush();
59 
60 #if defined(HAVE_TCGETATTR)
61 #include <termios.h>
62 
63 void rl_ttyset(int Reset)
64 {
65  static struct termios old;
66  struct termios new;
67 
68  if (Reset == 0) {
69  (void)tcgetattr(0, &old);
70  rl_erase = old.c_cc[VERASE];
71  rl_kill = old.c_cc[VKILL];
72  rl_eof = old.c_cc[VEOF];
73  rl_intr = old.c_cc[VINTR];
74  rl_quit = old.c_cc[VQUIT];
75 
76  new = old;
77  new.c_cc[VINTR] = -1;
78  new.c_cc[VQUIT] = -1;
79  new.c_lflag &= ~(ECHO | ICANON);
80  new.c_iflag &= ~(ISTRIP | INPCK);
81  new.c_cc[VMIN] = 1;
82  new.c_cc[VTIME] = 0;
83 #ifdef VDSUSP
84  /* On Solaris (non-posix) DSUSP is ^Y, cancel it (awb 30/12/98) */
85  new.c_cc[VDSUSP] = -1;
86 #endif
87 
88  (void)tcsetattr(0, TCSANOW, &new);
89  }
90  else
91  (void)tcsetattr(0, TCSANOW, &old);
92 }
93 
94 #else
95 #include <sgtty.h>
96 
97 void 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_TCGETATTR) */
133 
134 int TTYget()
135 {
136  ECHAR c;
137  int s;
138 
139  TTYflush();
140  if (el_Pushed) {
141  el_Pushed = 0;
142  return el_PushBack;
143  }
144  if (*el_Input)
145  return *el_Input++;
146  s = read(0, &c, (ESIZE_T)1) == 1 ? c : EOF;
147  return s;
148 }
149 
150 void rl_add_slash(char *path,char *p)
151 {
152  struct stat Sb;
153 
154  if (stat(path, &Sb) >= 0)
155  (void)strcat(p, S_ISDIR(Sb.st_mode) ? "/" : " ");
156 }
157 
158 int el_is_directory(char *path)
159 {
160  struct stat Sb;
161 
162  if ((stat(path, &Sb) >= 0) && S_ISDIR(Sb.st_mode))
163  return 1;
164  else
165  return 0;
166 }
167 
169 {
170  if (el_user_intr)
171  kill(getpid(),SIGINT);
172 }
#define S_ISDIR(m)
Definition: el_unix.h:63
CONST ECHAR * el_Input
Definition: el_sys_unix.c:56
void rl_ttyset(int Reset)
Definition: el_sys_unix.c:63
int el_PushBack
Definition: el_sys_unix.c:54
int rl_quit
Definition: editline.c:121
int rl_kill
Definition: editline.c:111
#define ESIZE_T
Definition: editline.h:80
CONST ECHAR el_NIL[]
Definition: editline.c:113
int el_user_intr
Definition: el_sys_unix.c:53
int rl_eof
Definition: editline.c:108
int rl_intr
Definition: editline.c:110
unsigned char ECHAR
Definition: editline.h:83
void TTYflush()
Definition: editline.c:237
#define CONST
Definition: editline.h:95
int el_is_directory(char *path)
Definition: el_sys_unix.c:158
void rl_add_slash(char *path, char *p)
Definition: el_sys_unix.c:150
int TTYget()
Definition: el_sys_unix.c:134
void do_user_intr()
Definition: el_sys_unix.c:168
int rl_erase
Definition: editline.c:109
int el_Pushed
Definition: el_sys_unix.c:55