annotate linux/getch2.c @ 887:1e30c5b55cdb

prints kernel, gcc and binutils version
author arpi_esp
date Sat, 26 May 2001 21:26:03 +0000
parents 3b5f5d1c5041
children 162a78d3cc08
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 /* GyS-TermIO v2.0 (for GySmail v3) (C) 1999 A'rpi/ESP-team */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 #include "../config.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 //#define USE_TERMCAP
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 #define USE_IOCTL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 #define MAX_KEYS 64
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 #define BUF_LEN 256
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 #include <stdio.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 #include <stdlib.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 #include <string.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 #include <sys/time.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 #include <sys/types.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 #ifdef USE_IOCTL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 #include <sys/ioctl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 #include <sys/termios.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 #include <unistd.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 #include "keycodes.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 static struct termios tio_orig;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 static int getch2_len=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 static char getch2_buf[BUF_LEN];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 int screen_width=80;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 int screen_height=24;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 typedef struct {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 int len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 int code;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 char chars[8];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 } keycode_st;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 static keycode_st getch2_keys[MAX_KEYS];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 static int getch2_key_db=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 #ifdef USE_TERMCAP
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 #include <termcap.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 extern int tgetent (char *BUFFER, char *TERMTYPE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 extern int tgetnum (char *NAME);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 extern int tgetflag (char *NAME);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 extern char *tgetstr (char *NAME, char **AREA);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 static char term_buffer[4096];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 static char term_buffer2[4096];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 static char *term_p=term_buffer2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 static void termcap_add(char *id,int code){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 char *p=tgetstr(id,&term_p);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 if(!p) return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 if(getch2_key_db>=MAX_KEYS) return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 getch2_keys[getch2_key_db].len=strlen(p);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 strncpy(getch2_keys[getch2_key_db].chars,p,8);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 getch2_keys[getch2_key_db].code=code;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 ++getch2_key_db;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 /* printf("%s=%s\n",id,p); */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 static int success=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 int load_termcap(char *termtype){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 if(!termtype) termtype=getenv("TERM");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 success=tgetent(term_buffer, termtype);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 if(success<0){ printf("Could not access the 'termcap' data base.\n"); return 0; }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 if(success==0){ printf("Terminal type `%s' is not defined.\n", termtype);return 0;}
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 screen_width=tgetnum("co");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 screen_height=tgetnum("li");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 if(screen_width<1 || screen_width>255) screen_width=80;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 if(screen_height<1 || screen_height>255) screen_height=24;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 termcap_add("kP",KEY_PGUP);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 termcap_add("kN",KEY_PGDWN);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 termcap_add("kh",KEY_HOME);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 termcap_add("kH",KEY_END);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 termcap_add("kI",KEY_INS);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 termcap_add("kD",KEY_DEL);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 termcap_add("kb",KEY_BS);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 termcap_add("kl",KEY_LEFT);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 termcap_add("kd",KEY_DOWN);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 termcap_add("ku",KEY_UP);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 termcap_add("kr",KEY_RIGHT);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 termcap_add("k0",KEY_F+0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 termcap_add("k1",KEY_F+1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 termcap_add("k2",KEY_F+2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 termcap_add("k3",KEY_F+3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 termcap_add("k4",KEY_F+4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 termcap_add("k5",KEY_F+5);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 termcap_add("k6",KEY_F+6);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 termcap_add("k7",KEY_F+7);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 termcap_add("k8",KEY_F+8);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 termcap_add("k9",KEY_F+9);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 termcap_add("k;",KEY_F+10);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 return getch2_key_db;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 void get_screen_size(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 #ifdef USE_IOCTL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 struct winsize ws;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 if (ioctl(0, TIOCGWINSZ, &ws) < 0 || !ws.ws_row || !ws.ws_col) return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 /* printf("Using IOCTL\n"); */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 screen_width=ws.ws_col;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 screen_height=ws.ws_row;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 int getch2(int time){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 int len=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 int code=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 int i=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 while(!getch2_len || (getch2_len==1 && getch2_buf[0]==27)){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 fd_set rfds;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 struct timeval tv;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 int retval;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 /* Watch stdin (fd 0) to see when it has input. */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 FD_ZERO(&rfds); FD_SET(0,&rfds);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 /* Wait up to 'time' microseconds. */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 tv.tv_sec=time/1000; tv.tv_usec = (time%1000)*1000;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 retval=select(1, &rfds, NULL, NULL, &tv);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 if(!retval) return -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 /* Data is available now. */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 retval=read(0,&getch2_buf[getch2_len],BUF_LEN-getch2_len);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 if(retval<1) return -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 getch2_len+=retval;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 /* First find in the TERMCAP database: */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 for(i=0;i<getch2_key_db;i++){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 if((len=getch2_keys[i].len)<=getch2_len)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 if(memcmp(getch2_keys[i].chars,getch2_buf,len)==0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 code=getch2_keys[i].code; goto found;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 len=1;code=getch2_buf[0];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 /* Check the well-known codes... */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 if(code!=27){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 if(code=='A'-64){ code=KEY_HOME; goto found;}
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 if(code=='E'-64){ code=KEY_END; goto found;}
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 if(code=='D'-64){ code=KEY_DEL; goto found;}
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 if(code=='H'-64){ code=KEY_BS; goto found;}
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 if(code=='U'-64){ code=KEY_PGUP; goto found;}
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 if(code=='V'-64){ code=KEY_PGDWN; goto found;}
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 if(code==8 || code==127){ code=KEY_BS; goto found;}
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 if(code==10 || code==13){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 if(getch2_len>1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 int c=getch2_buf[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156 if(c==10 || c==13) if(c!=code) len=2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 code=KEY_ENTER;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 goto found;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 } else if(getch2_len>1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 int c=getch2_buf[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 if(c==27){ code=KEY_ESC; len=2; goto found;}
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 if(c>='0' && c<='9'){ code=c-'0'+KEY_F; len=2; goto found;}
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 if(getch2_len>=4 && c=='[' && getch2_buf[2]=='['){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166 int c=getch2_buf[3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 if(c>='A' && c<'A'+12){ code=KEY_F+1+c-'A';len=4;goto found;}
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 if(c=='[' || c=='O') if(getch2_len>=3){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 int c=getch2_buf[2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 static short int ctable[]={ KEY_UP,KEY_DOWN,KEY_RIGHT,KEY_LEFT,0,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 KEY_END,KEY_PGDWN,KEY_HOME,KEY_PGUP,0,0,KEY_INS,0,0,0,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 KEY_F+1,KEY_F+2,KEY_F+3,KEY_F+4};
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 if(c>='A' && c<='S')
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 if(ctable[c-'A']){ code=ctable[c-'A']; len=3; goto found;}
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177 if(getch2_len>=4 && c=='[' && getch2_buf[3]=='~'){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178 int c=getch2_buf[2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 int ctable[8]={KEY_HOME,KEY_INS,KEY_DEL,KEY_END,KEY_PGUP,KEY_PGDWN,KEY_HOME,KEY_END};
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 if(c>='1' && c<='8'){ code=ctable[c-'1']; len=4; goto found;}
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 if(getch2_len>=5 && c=='[' && getch2_buf[4]=='~'){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 int i=getch2_buf[2]-'0';
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 int j=getch2_buf[3]-'0';
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 if(i>=0 && i<=9 && j>=0 && j<=9){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 static short int ftable[20]={
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 11,12,13,14,15, 17,18,19,20,21,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 23,24,25,26,28, 29,31,32,33,34 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189 int a=i*10+j;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 for(i=0;i<20;i++) if(ftable[i]==a){ code=KEY_F+1+i;len=5;goto found;}
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194 found:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 if((getch2_len-=len)>0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
196 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197 for(i=0;i<getch2_len;i++) getch2_buf[i]=getch2_buf[len+i];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199 return code;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
201
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 void getch2_enable(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 struct termios tio_new;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 ioctl(0,TCGETS,&tio_orig); /* tcgetattr(0,&tio_orig); */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 tio_new=tio_orig;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 tio_new.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207 tio_new.c_cc[VMIN] = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 tio_new.c_cc[VTIME] = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 ioctl(0,TCSETS,&tio_new); /* tcsetattr(0,TCSANOW,&tio_new); */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 void getch2_disable(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213 ioctl(0,TCSETS,&tio_orig); /* tcsetattr(0,TCSANOW,&tio_orig); */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215