1 #define LED_NUM_LOCK 0x1 \
2  \
3 
4 /*2:*/
5 #line 60 "oemacs.w"
6 
7 /*3:*/
8 #line 92 "oemacs.w"
9 
10 #include <string.h>
11 #include <stdio.h>
12 #include <xview/xview.h>
13 
14 /*:3*//*5:*/
15 #line 128 "oemacs.w"
16 
17 #include <xview/cms.h>
18 
19 /*:5*//*10:*/
20 #line 311 "oemacs.w"
21 
22 #include <xview/tty.h>
23 
24 /*:10*//*14:*/
25 #line 362 "oemacs.w"
26 
27 #include <xview/cursor.h>
28 
29 /*:14*//*19:*/
30 #line 430 "oemacs.w"
31 
32 #include <xview/font.h>
33 
34 /*:19*//*33:*/
35 #line 764 "oemacs.w"
36 
37 #include <sys/file.h>
38 #include <sundev/kbio.h>
39 
40 /*:33*/
41 #line 61 "oemacs.w"
42 
43 
44 Frame frame;
45 /*7:*/
46 #line 144 "oemacs.w"
47 
48 unsigned short icon_bits[]= {
49 0x0000,0x0000,0x0000,0x1E00,
50 0x0000,0x0000,0x0000,0x0900,
51 0x001E,0x0000,0x0000,0x0880,
52 0x0064,0x0000,0x0000,0x0440,
53 0x0088,0x0000,0x0000,0x0420,
54 0x0110,0x0000,0x0000,0x0210,
55 0x0220,0x0000,0x0000,0x0210,
56 0x0420,0x0FCF,0x01C0,0x0108,
57 0x0840,0x1030,0x8620,0x0088,
58 0x1080,0x00C0,0x5810,0x0084,
59 0x1080,0x1F00,0x2008,0x0044,
60 0x2100,0xE200,0x1004,0x0044,
61 0x4103,0x0400,0x0002,0x0042,
62 0x4204,0x080E,0x0001,0x0042,
63 0x8200,0x7830,0x0020,0x8082,
64 0x8203,0x9040,0x0018,0x4102,
65 0x8204,0x2080,0x07C6,0x3E04,
66 0x8108,0x410C,0x0021,0x8004,
67 0x8080,0x8210,0x03D0,0x6008,
68 0x4041,0x0420,0x0008,0x1810,
69 0x403E,0x0820,0x0FFC,0x0620,
70 0x2000,0x1040,0x0002,0x01C0,
71 0x1000,0x608C,0x0FFF,0x0060,
72 0x0801,0x8110,0x0080,0x8118,
73 0x0406,0x0220,0x1FFF,0x66E0,
74 0x0238,0x044F,0x0000,0xD800,
75 0x01C0,0x0890,0x8FFF,0x4000,
76 0x0300,0x10A6,0x4041,0x6000,
77 0x1C00,0x2026,0x4FFF,0x6000,
78 0x60CC,0x4026,0x4001,0x6000,
79 0x1F33,0x8010,0x8FFF,0x4000,
80 0x0012,0x000F,0x0040,0xC000,
81 0x0022,0x4000,0x07FF,0x4000,
82 0x0024,0x4000,0x0000,0x2000,
83 0x0024,0x4818,0x8FFF,0xE000,
84 0x0024,0x4907,0x0040,0x2000,
85 0x0044,0x4900,0x1FFF,0xE000,
86 0x0044,0x4900,0x0000,0x2000,
87 0x0044,0x4900,0x07FF,0xE000,
88 0x0044,0x4880,0x0020,0x2000,
89 0x0044,0x4880,0x07FF,0xE000,
90 0x0044,0x4840,0x0000,0x2000,
91 0x0044,0x2A20,0x07FF,0xE000,
92 0x0044,0x2410,0x0020,0x2000,
93 0x0042,0x2448,0x0FFF,0xE000,
94 0x0042,0x2948,0x0000,0x2000,
95 0x0041,0x1144,0x07FF,0xA000,
96 0x0041,0x1144,0x2010,0x1000,
97 0x0021,0x1126,0x20FA,0x1000,
98 0x0024,0x8925,0x2600,0x1000,
99 0x0014,0x8924,0xA138,0x7000,
100 0x0016,0x88A4,0x9090,0x6000,
101 0x000A,0x44A4,0x4880,0xA000,
102 0x0002,0x44A2,0x4401,0x2000,
103 0x0003,0x4492,0x2001,0x4000,
104 0x0001,0x2451,0x3002,0x8000,
105 0x0000,0xA251,0x1E05,0x0000,
106 0x0000,0x2248,0xA1F9,0x8000,
107 0x0000,0x1648,0x9002,0x8000,
108 0x0000,0x1A28,0x4C02,0x8000,
109 0x0000,0x1220,0x43FC,0x8000,
110 0x0000,0x0120,0x2000,0x8000,
111 0x0000,0x0120,0x2003,0x0000,
112 0x0000,0x0150,0x1FFC,0x0000
113 };
114 unsigned short mask_bits[]= {
115 0x0000,0x0000,0x0000,0x1E00,
116 0x0000,0x0000,0x0000,0x0F00,
117 0x001E,0x0000,0x0000,0x0F80,
118 0x007C,0x0000,0x0000,0x07C0,
119 0x00F8,0x0000,0x0000,0x07E0,
120 0x01F0,0x0000,0x0000,0x03F0,
121 0x03E0,0x0000,0x0000,0x03F0,
122 0x07E0,0x0FCF,0x01C0,0x01F8,
123 0x0FC0,0x103F,0x87F0,0x00F8,
124 0x1F80,0x00FF,0xDFF0,0x00FC,
125 0x1F80,0x1FFF,0xFFF8,0x007C,
126 0x3F00,0xE3FF,0xFFFC,0x007C,
127 0x7F03,0x07FF,0xFFFE,0x007E,
128 0x7E04,0x0FFF,0xFFFF,0x007E,
129 0xFE00,0x7FFF,0xFFFF,0x80FE,
130 0xFE03,0x9FFF,0xFFFF,0xC1FE,
131 0xFE04,0x3FFF,0xFFFF,0xFFFC,
132 0xFF08,0x7FFF,0xFFFF,0xFFFC,
133 0xFF80,0xFFFF,0xFFFF,0xFFF8,
134 0x7FC1,0xFFFF,0xFFFF,0xFFF0,
135 0x7FFF,0xFFFF,0xFFFF,0xFFE0,
136 0x3FFF,0xFFFF,0xFFFF,0xFFC0,
137 0x1FFF,0xFFFF,0xFFFF,0xFFE0,
138 0x0FFF,0xFFFF,0xFFFF,0xFFF8,
139 0x07FF,0xFFFF,0xFFFF,0xFEE0,
140 0x03FF,0xFFFF,0xFFFF,0xF800,
141 0x01FF,0xFFFF,0xFFFF,0xE000,
142 0x03FF,0xFFFF,0xFFFF,0xE000,
143 0x1FFF,0xFFFF,0xFFFF,0xE000,
144 0x7FFF,0xFFFF,0xFFFF,0xE000,
145 0x1F7F,0xFFFF,0xFFFF,0xC000,
146 0x001F,0xFFFF,0xFFFF,0xC000,
147 0x003F,0xFFFF,0xFFFF,0xC000,
148 0x003F,0xFFFF,0xFFFF,0xE000,
149 0x003F,0xFFFF,0xFFFF,0xE000,
150 0x003F,0xFFFF,0xFFFF,0xE000,
151 0x007F,0xFFFF,0xFFFF,0xE000,
152 0x007F,0xFFFF,0xFFFF,0xE000,
153 0x007F,0xFFFF,0xFFFF,0xE000,
154 0x007F,0xFFFF,0xFFFF,0xE000,
155 0x007F,0xFFFF,0xFFFF,0xE000,
156 0x007F,0xFFFF,0xFFFF,0xE000,
157 0x007F,0xFFFF,0xFFFF,0xE000,
158 0x007F,0xFFFF,0xFFFF,0xE000,
159 0x007F,0xFFFF,0xFFFF,0xE000,
160 0x007F,0xFFFF,0xFFFF,0xE000,
161 0x007F,0xFFFF,0xFFFF,0xE000,
162 0x007F,0xFFFF,0xFFFF,0xF000,
163 0x003F,0xFFFF,0xFFFF,0xF000,
164 0x003F,0xFFFF,0xFFFF,0xF000,
165 0x001F,0xFFFF,0xFFFF,0xF000,
166 0x001F,0xFFFF,0xFFFF,0xE000,
167 0x000B,0xFFFF,0xFFFF,0xE000,
168 0x0003,0xFFFF,0xFFFF,0xE000,
169 0x0003,0xFFFF,0xFFFF,0xC000,
170 0x0001,0xFFFF,0xFFFF,0x8000,
171 0x0000,0xBFF1,0xFFFF,0x0000,
172 0x0000,0x3FF8,0xFFFF,0x8000,
173 0x0000,0x1FF8,0xFFFF,0x8000,
174 0x0000,0x1FF8,0x7FFF,0x8000,
175 0x0000,0x13E0,0x7FFF,0x8000,
176 0x0000,0x01E0,0x3FFF,0x8000,
177 0x0000,0x01E0,0x3FFF,0x0000,
178 0x0000,0x0150,0x1FFC,0x0000
179 };
180 
181 /*:7*//*9:*/
182 #line 308 "oemacs.w"
183 
184 Tty tty;
185 
186 /*:9*//*12:*/
187 #line 340 "oemacs.w"
188 
189 Xv_window window;
190 
191 /*:12*//*16:*/
192 #line 375 "oemacs.w"
193 
194 int rv;
195 
196 /*:16*//*18:*/
197 #line 427 "oemacs.w"
198 
199 int char_width,char_height;
200 
201 /*:18*//*30:*/
202 #line 733 "oemacs.w"
203 
204 char buf[]= "\030*??\021";
205 
206 /*:30*//*32:*/
207 #line 759 "oemacs.w"
208 
209 int num_lock_state;
210 char turnon[]= "\370turn-numlock-on\r",turnoff[]= "\370turn-numlock-off\r";
211 int keyboard;
212 
213 /*:32*//*37:*/
214 #line 843 "oemacs.w"
215 
216 char mouse_buf[24]= "\030";
217 
218 /*:37*//*39:*/
219 #line 866 "oemacs.w"
220 
221 struct timeval prev_mouse_time;
222 
223 /*:39*/
224 #line 64 "oemacs.w"
225 
226 
227 /*21:*/
228 #line 490 "oemacs.w"
229 
filter(window,event,arg,type)230 Notify_value filter(window,event,arg,type)
231 Xv_window window;
232 Event*event;
233 Notify_arg arg;
234 Notify_event_type type;
235 {register int id= event_id(event);
236 #ifdef DEBUG
237 printf("event %d%s, action %d, shift %x, mouse(%d,%d)\n",
238 event_id(event),event_is_up(event)?"UP":"DOWN",event->action,
239 event_shiftmask(event),event_x(event),event_y(event));
240 #endif
241 /*34:*/
242 #line 771 "oemacs.w"
243 
244 {char leds;
245 ioctl(keyboard,KIOCGLED,&leds);
246 if((leds&LED_NUM_LOCK)!=num_lock_state){
247 num_lock_state= leds&LED_NUM_LOCK;
248 if(num_lock_state)ttysw_input(window,turnon,17);
249 else ttysw_input(window,turnoff,18);
250 }
251 }
252 
253 /*:34*/
254 #line 502 "oemacs.w"
255 ;
256 if(id==LOC_WINENTER)/*22:*/
257 #line 514 "oemacs.w"
258 
259 {
260 win_set_kbd_focus(window,xv_get(window,XV_XID));
261 return NOTIFY_DONE;
262 }
263 
264 /*:22*/
265 #line 503 "oemacs.w"
266 ;
267 if(event_is_button(event))/*36:*/
268 #line 828 "oemacs.w"
269 
270 {register int button_code,elapsed_time;
271 button_code= (id==MS_LEFT?1:id==MS_MIDDLE?2:4);
272 if(event_shift_is_down(event))button_code+= 8;
273 if(event_ctrl_is_down(event))button_code+= 16;
274 if(event_meta_is_down(event))button_code+= 32;
275 if(event_is_up(event))button_code+= 128;
276 /*38:*/
277 #line 853 "oemacs.w"
278 
279 {struct timeval now;
280 long delta_sec,delta_usec;
281 
282 now= event_time(event);
283 delta_sec= now.tv_sec-prev_mouse_time.tv_sec;
284 delta_usec= now.tv_usec-prev_mouse_time.tv_usec;
285 if(delta_usec<0)delta_usec+= 1000000,delta_sec--;
286 if(delta_sec>=10)elapsed_time= 9999;
287 else elapsed_time= (delta_sec*1000)+(delta_usec/1000);
288 prev_mouse_time= now;
289 }
290 
291 /*:38*/
292 #line 835 "oemacs.w"
293 ;
294 sprintf(mouse_buf+2,"(%d %d %d %d)\r",button_code,
295 event_x(event)/char_width,event_y(event)/char_height,
296 elapsed_time);
297 ttysw_input(window,mouse_buf,12+strlen(mouse_buf+12));
298 return NOTIFY_DONE;
299 }
300 
301 /*:36*/
302 #line 504 "oemacs.w"
303 ;
304 if(event_is_up(event))return NOTIFY_DONE;
305 /*26:*/
306 #line 678 "oemacs.w"
307 
308 {register int bank= 'b';
309 register int n;
310 if(id>=KEY_LEFT(1))/*27:*/
311 #line 696 "oemacs.w"
312 
313 {
314 if(id<KEY_RIGHT(1)){
315 bank= 'l';n= id-KEY_LEFT(0);
316 }else if(id<KEY_TOP(1)){
317 bank= 'r';n= id-KEY_RIGHT(0);
318 }else if(id<KEY_BOTTOM(1)){
319 bank= 't';n= id-KEY_TOP(0);
320 }else n= id-KEY_BOTTOM(0);
321 goto emit_function_key;
322 }
323 
324 /*:27*/
325 #line 681 "oemacs.w"
326 
327 else if(id>=256)/*28:*/
328 #line 711 "oemacs.w"
329 
330 if(id==SHIFT_ALT){
331 n= 2;goto emit_function_key;
332 }else if(id==SHIFT_ALTG){
333 n= 3;goto emit_function_key;
334 }else goto non_function;
335 
336 /*:28*/
337 #line 682 "oemacs.w"
338 
339 else if(id>=128)
340 /*31:*/
341 #line 736 "oemacs.w"
342 
343 switch(id){
344 case 190:bank= 'r';n= 2;goto emit_function_key;
345 case 189:n= 8;goto emit_function_key;
346 case 188:n= 7;goto emit_function_key;
347 case 179:n= 6;goto emit_function_key;
348 case 178:n= 5;goto emit_function_key;
349 case 185:n= 4;goto emit_function_key;
350 default:buf[5]= id;
351 ttysw_input(window,buf+4,2);
352 return NOTIFY_DONE;
353 }
354 
355 /*:31*/
356 #line 684 "oemacs.w"
357 
358 else if(id> 0||
359 (event_action(event)==0&&event_shiftmask(event)==CTRLMASK))
360 goto non_function;
361 else n= 1;
362 emit_function_key:/*29:*/
363 #line 722 "oemacs.w"
364 
365 {
366 if(event_shift_is_down(event))bank-= 32;
367 if(event_ctrl_is_down(event))bank-= 64;
368 if(event_meta_is_down(event))bank+= 128;
369 buf[2]= n+'a'-1;
370 buf[3]= bank;
371 ttysw_input(window,buf,4);
372 return NOTIFY_DONE;
373 }
374 
375 /*:29*/
376 #line 689 "oemacs.w"
377 ;
378 non_function:;
379 }
380 
381 /*:26*/
382 #line 506 "oemacs.w"
383 ;
384 /*23:*/
385 #line 530 "oemacs.w"
386 
387 if(id<128)
388 if(event_meta_is_down(event))event_set_id(event,id+128);
389 else event_set_action(event,ACTION_NULL_EVENT);
390 
391 /*:23*/
392 #line 507 "oemacs.w"
393 ;
394 return notify_next_event_func(window,event,arg,type);
395 }
396 
397 /*:21*/
398 #line 66 "oemacs.w"
399 
400 
main(argc,argv)401 main(argc,argv)
402 int argc;char*argv[];
403 {
404 /*35:*/
405 #line 785 "oemacs.w"
406 
407 keyboard= open("/dev/kbd",O_RDWR);
408 if(keyboard<0){
409 fprintf(stderr,"%s: Can't open /dev/kbd!\n",argv[0]);
410 exit(1);
411 }
412 
413 /*:35*/
414 #line 71 "oemacs.w"
415 ;
416 /*20:*/
417 #line 446 "oemacs.w"
418 
419 /*15:*/
420 #line 368 "oemacs.w"
421 
422 rv= 0;
423 {int k= argc;
424 while(--k> 0)if(strcmp(argv[k],"-rv")==0||
425 strcmp(argv[k],"-reverse")==0)rv= 1;
426 }
427 
428 /*:15*/
429 #line 447 "oemacs.w"
430 ;
431 xv_init(XV_INIT_ARGC_PTR_ARGV,&argc,argv,NULL);
432 
433 /*4:*/
434 #line 115 "oemacs.w"
435 
436 {Server_image icon_image= (Server_image)xv_create(NULL,SERVER_IMAGE,
437 XV_WIDTH,64,XV_HEIGHT,64,SERVER_IMAGE_BITS,icon_bits,NULL);
438 Server_image mask_image= (Server_image)xv_create(NULL,SERVER_IMAGE,
439 XV_WIDTH,64,XV_HEIGHT,64,SERVER_IMAGE_BITS,mask_bits,NULL);
440 Cms cms= (Cms)xv_create(NULL,CMS,CMS_SIZE,2,
441 CMS_NAMED_COLORS,"yellow","black",NULL,NULL);
442 Icon icon= (Icon)xv_create(NULL,ICON,
443 ICON_IMAGE,icon_image,ICON_MASK_IMAGE,mask_image,
444 WIN_CMS,cms,NULL);
445 frame= xv_create(NULL,FRAME,FRAME_ICON,icon,NULL);
446 }
447 
448 /*:4*/
449 #line 450 "oemacs.w"
450 ;
451 /*6:*/
452 #line 136 "oemacs.w"
453 
454 if(xv_get(frame,XV_LABEL)==NULL)
455 xv_set(frame,FRAME_SHOW_HEADER,FALSE,XV_LABEL,"OEMACS",NULL);
456 
457 /*:6*/
458 #line 451 "oemacs.w"
459 ;
460 /*8:*/
461 #line 301 "oemacs.w"
462 
463 argv[0]= "emacs";
464 putenv("TERM=sun");
465 tty= (Tty)xv_create(frame,TTY,WIN_IS_CLIENT_PANE,
466 TTY_QUIT_ON_CHILD_DEATH,TRUE,
467 TTY_ARGV,argv,NULL);
468 
469 /*:8*/
470 #line 452 "oemacs.w"
471 ;
472 /*11:*/
473 #line 336 "oemacs.w"
474 
475 window= (Xv_window)xv_get(tty,OPENWIN_NTH_VIEW,0);
476 xv_set(window,WIN_CONSUME_EVENT,LOC_WINENTER,NULL);
477 
478 /*:11*/
479 #line 453 "oemacs.w"
480 ;
481 /*13:*/
482 #line 351 "oemacs.w"
483 
484 if(rv){Xv_singlecolor white,black;
485 Xv_cursor cursor;
486 white.red= white.green= white.blue= 255;
487 black.red= black.green= black.blue= 0;
488 cursor= (Xv_cursor)xv_create(NULL,CURSOR,
489 CURSOR_SRC_CHAR,OLC_BASIC_PTR,CURSOR_MASK_CHAR,OLC_BASIC_MASK_PTR,
490 CURSOR_FOREGROUND_COLOR,&white,CURSOR_BACKGROUND_COLOR,&black,NULL);
491 xv_set(window,WIN_CURSOR,cursor,NULL);
492 }
493 
494 /*:13*/
495 #line 454 "oemacs.w"
496 ;
497 /*17:*/
498 #line 411 "oemacs.w"
499 
500 {
501 Xv_font font= (Xv_font)xv_get(frame,XV_FONT);
502 Xv_font dfont= (Xv_font)xv_find(NULL,FONT,FONT_FAMILY,
503 FONT_FAMILY_DEFAULT,NULL);
504 if(strcmp((char*)xv_get(font,FONT_NAME),
505 (char*)xv_get(dfont,FONT_NAME))==0){
506 
507 dfont= (Xv_font)xv_find(NULL,FONT,FONT_FAMILY,
508 FONT_FAMILY_DEFAULT_FIXEDWIDTH,NULL);
509 
510 }else dfont= font;
511 char_width= (int)xv_get(dfont,FONT_DEFAULT_CHAR_WIDTH);
512 char_height= (int)xv_get(dfont,FONT_DEFAULT_CHAR_HEIGHT);
513 }
514 
515 /*:17*/
516 #line 455 "oemacs.w"
517 ;
518 notify_interpose_event_func(window,filter,NOTIFY_SAFE);
519 
520 /*:20*/
521 #line 72 "oemacs.w"
522 ;
523 xv_main_loop(frame);
524 exit(0);
525 }
526 
527 /*:2*/
528