Introduction
Introduction Statistics Contact Development Disclaimer Help
io.c - sam - An updated version of the sam text editor.
git clone git://vernunftzentrum.de/sam.git
Log
Files
Refs
LICENSE
---
io.c (3057B)
---
1 /* Copyright (c) 1998 Lucent Technologies - All rights reserved. */
2 #include <u.h>
3 #include <libg.h>
4 #include <frame.h>
5 #include "flayer.h"
6 #include "samterm.h"
7
8 int cursorfd;
9 int input;
10 int got;
11 int block;
12 Keystroke keystroke;
13 int reshaped;
14 uint8_t *hostp;
15 uint8_t *hoststop;
16 uint8_t *externbase;
17 uint8_t *externp;
18 uint8_t *externstop;
19 void panic(char*);
20
21 void
22 initio(void){
23 extern int exfd;
24
25 einit(Emouse|Ekeyboard);
26 estart(Ehost, 0, 0, false);
27 if (exfd >= 0)
28 estart(Eextern, exfd, 8192, true);
29 }
30
31 void
32 frgetmouse(void)
33 {
34 mouse = emouse();
35 }
36
37 void
38 mouseunblock(void)
39 {
40 got &= ~Emouse;
41 }
42
43 void
44 kbdblock(void)
45 { /* ca suffit */
46 block = Ekeyboard|Eextern;
47 }
48
49 int
50 button(int but)
51 {
52 frgetmouse();
53 return mouse.buttons&(1<<(but-1));
54 }
55
56 void
57 externload(Event *e)
58 {
59 externbase = malloc(e->n);
60 if(externbase == 0)
61 return;
62 memmove(externbase, e->data, e->n);
63 externp = externbase;
64 externstop = externbase + e->n;
65 got |= Eextern;
66 }
67
68 int
69 waitforio(void)
70 {
71 uint64_t type;
72 static Event e;
73
74 if(got & ~block)
75 return got & ~block;
76 type = eread(~(got|block), &e);
77 switch(type){
78 case Ehost:
79 hostp = e.data;
80 hoststop = hostp + e.n;
81 block = 0;
82 break;
83 case Eextern:
84 externload(&e);
85 break;
86 case Ekeyboard:
87 keystroke = e.keystroke;
88 break;
89 case Emouse:
90 mouse = e.mouse;
91 break;
92 }
93 got |= type;
94 return got;
95 }
96
97 int
98 rcvchar(void)
99 {
100 int c;
101
102 if(!(got & Ehost))
103 return -1;
104 c = *hostp++;
105 if(hostp == hoststop)
106 got &= ~Ehost;
107 return c;
108 }
109
110 char*
111 rcvstring(void)
112 {
113 *hoststop = 0;
114 got &= ~Ehost;
115 return (char*)hostp;
116 }
117
118 int
119 getch(void)
120 {
121 int c;
122
123 while((c = rcvchar()) == -1){
124 block = ~Ehost;
125 waitforio();
126 block = 0;
127 }
128 return c;
129 }
130
131 int
132 externchar(void)
133 {
134 wchar_t r;
135
136 loop:
137 if(got & (Eextern & ~block)){
138 externp += chartorune(&r, (char*)externp);
139 if(externp >= externstop){
140 got &= ~Eextern;
141 free(externbase);
142 }
143 if(r == 0)
144 goto loop;
145 return r;
146 }
147 return -1;
148 }
149
150 Keystroke
151 qpeekc(void)
152 {
153 return keystroke;
154 }
155
156 Keystroke
157 kbdchar(void)
158 {
159 Keystroke k = {0};
160 static Event e;
161
162 k.c = externchar();
163 if(k.c > 0)
164 return k;
165 if(got & Ekeyboard){
166 k = keystroke;
167 memset(&keystroke, 0, sizeof(keystroke));
168 got &= ~Ekeyboard;
169 return k;
170 }
171 while(ecanread(Eextern)){
172 eread(Eextern, &e);
173 externload(&e);
174 k.c = externchar();
175 if(k.c > 0)
176 return k;
177 }
178 if(!ecankbd()){
179 k.c = -1;
180 return k;
181 }
182 return ekbd();
183 }
184
185 void
186 ereshaped(Rectangle r)
187 {
188 reshaped = 1;
189 }
190
191 int
192 RESHAPED(void)
193 {
194 if(reshaped){
195 screen.r = bscreenrect(&screen.clipr);
196 reshaped = 0;
197 return 1;
198 }
199 return 0;
200 }
201
202 void
203 mouseexit(void)
204 {
205 exit(EXIT_SUCCESS);
206 }
You are viewing proxied material from vernunftzentrum.de. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.