1 /****************************************************************/
5 /* Processing input from the "de" user. */
7 /****************************************************************/
8 /* origination 1989-Jan-15 Terrence W. Holm */
9 /****************************************************************/
12 #include <sys/types.h>
18 #include <minix/config.h>
19 #include <minix/const.h>
20 #include "../../servers/mfs/const.h"
21 #include "../../servers/mfs/inode.h"
25 FORWARD
_PROTOTYPE(int Timed_Get_Char
, (int time
));
26 FORWARD
_PROTOTYPE(void Timed_Out
, (int sig
));
31 /****************************************************************/
35 /* Save the current terminal characteristics. */
40 /* Set up the terminal characteristics. */
45 /* Restore the terminal characteristics. */
47 /****************************************************************/
50 static struct termios saved_term
;
56 tcgetattr( 0, &saved_term
);
70 /* No tab expansion, no echo, don't map ^M to ^J, cbreak mode */
72 term
.c_iflag
&= ~ICRNL
;
73 term
.c_oflag
&= ~OPOST
;
74 term
.c_lflag
&= ~ICANON
& ~ECHO
;
77 /* Change the interrupt character to ^C */
79 term
.c_cc
[VINTR
] = '\003';
81 tcsetattr( 0, TCSANOW
, &term
);
90 tcsetattr( 0, TCSANOW
, &saved_term
);
98 /****************************************************************/
102 /* Return the next input character. Escape */
103 /* sequences are mapped to special codes. */
105 /****************************************************************/
111 static int unget_char
= EOF
;
114 /* Flush the output to the screen before waiting */
115 /* for input from the user. */
119 if ( unget_char
== EOF
)
121 while ( (c
= Timed_Get_Char( 60 * 60 )) < EOF
)
122 printf( "%c", BELL
);
136 if ( (c
= Timed_Get_Char( 1 )) <= EOF
)
145 if ( (c
= Timed_Get_Char( 1 )) <= EOF
)
151 return( c
| 0x80 ); /* Flag ESC [ x */
159 int Timed_Get_Char( time
)
166 signal( SIGALRM
, Timed_Out
);
169 count
= read( 0, &c
, 1 );
173 return( EOF
+ count
);
183 /****************************************************************/
187 /* Read a line from the user. Returns a pointer */
188 /* to a local buffer, or NULL if DEL or a non- */
189 /* ASCII character was typed. Processes ^H and */
190 /* ^U. ^M terminates the input. */
192 /****************************************************************/
200 static char line
[ MAX_STRING
+ 1 ];
202 for ( i
= 0; i
<= MAX_STRING
; ++i
)
206 if ( c
== EOF
|| c
== DEL
|| (c
& 0x80) )
218 else if ( c
== CTRL_U
)
220 for ( --i
; i
>= 0; --i
)
224 else if ( c
== '\r' )
230 else if ( i
< MAX_STRING
)
236 else /* Line buffer is full, don't add any more to it. */
243 Error( "Internal fault (line buffer overflow)" );
254 /****************************************************************/
256 /* Arrow_Esc( char ) */
258 /* If the keyboard does not generate Ansi escape */
259 /* codes for the arrow keys, but does generate */
260 /* single byte control codes, then map these */
261 /* codes to the special characters we are using */
262 /* to denote the Ansi escape codes. */
264 /****************************************************************/
267 extern char Kup
; /* (ku) - Up arrow key */
268 extern char Kdown
; /* (kd) - Down arrow key */
269 extern char Kleft
; /* (kl) - Left arrow key */
270 extern char Kright
; /* (kr) - Right arrow key */
297 * $PchHeader: /mount/hd2/minix/sys/cmd/de/RCS/de_stdin.c,v 1.3 1995/02/10 08:01:30 philip Exp $