0
|
1 /* MS-DOS specific C utilities.
|
|
2 Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: FSF 19.30. */
|
|
22
|
|
23 /* Contributed by Morten Welinder */
|
|
24 /* New display, keyboard, and mouse control by Kim F. Storm */
|
|
25
|
|
26 /* Note: some of the stuff here was taken from end of sysdep.c in demacs. */
|
|
27
|
|
28 #define DONT_ENCAPSULATE
|
|
29
|
|
30 #include <config.h>
|
|
31
|
|
32 #ifdef MSDOS
|
|
33 #include <sys/param.h>
|
|
34 #include <sys/time.h>
|
|
35 #include <dos.h>
|
|
36 #include "lisp.h"
|
|
37 #include "dosfns.h"
|
|
38 #include "msdos.h"
|
|
39 #include "redisplay.h"
|
|
40 #include "systime.h"
|
|
41 #include "termhooks.h"
|
|
42 #include "frame.h"
|
|
43 #include "window.h"
|
|
44 #include <go32.h>
|
|
45 #include <pc.h>
|
|
46
|
|
47 static unsigned long
|
|
48 event_timestamp (void)
|
|
49 {
|
|
50 struct time t;
|
|
51 unsigned long s;
|
173
|
52
|
0
|
53 gettime (&t);
|
|
54 s = t.ti_min;
|
|
55 s *= 60;
|
|
56 s += t.ti_sec;
|
|
57 s *= 1000;
|
|
58 s += t.ti_hund * 10;
|
173
|
59
|
0
|
60 return s;
|
|
61 }
|
|
62
|
|
63
|
|
64 /* ------------------------ Mouse control ---------------------------
|
|
65 *
|
|
66 * Coordinates are in screen positions and zero based.
|
|
67 * Mouse buttons are numbered from left to right and also zero based.
|
|
68 */
|
|
69
|
|
70 int have_mouse; /* 0: no, 1: enabled, -1: disabled */
|
|
71 static int mouse_visible;
|
|
72
|
|
73 static int mouse_last_x;
|
|
74 static int mouse_last_y;
|
|
75
|
|
76 static int mouse_button_translate[NUM_MOUSE_BUTTONS];
|
|
77 static int mouse_button_count;
|
|
78
|
|
79 void
|
|
80 mouse_on (void)
|
|
81 {
|
|
82 union REGS regs;
|
|
83
|
|
84 if (have_mouse > 0 && !mouse_visible)
|
|
85 {
|
|
86 if (termscript)
|
|
87 fprintf (termscript, "<M_ON>");
|
|
88 regs.x.ax = 0x0001;
|
|
89 int86 (0x33, ®s, ®s);
|
|
90 mouse_visible = 1;
|
|
91 }
|
|
92 }
|
|
93
|
|
94 void
|
|
95 mouse_off (void)
|
|
96 {
|
|
97 union REGS regs;
|
|
98
|
|
99 if (have_mouse > 0 && mouse_visible)
|
|
100 {
|
|
101 if (termscript)
|
|
102 fprintf (termscript, "<M_OFF>");
|
|
103 regs.x.ax = 0x0002;
|
|
104 int86 (0x33, ®s, ®s);
|
|
105 mouse_visible = 0;
|
|
106 }
|
|
107 }
|
|
108
|
|
109 void
|
|
110 mouse_moveto (int x, int y)
|
|
111 {
|
|
112 union REGS regs;
|
|
113
|
|
114 if (termscript)
|
|
115 fprintf (termscript, "<M_XY=%dx%d>", x, y);
|
|
116 regs.x.ax = 0x0004;
|
|
117 mouse_last_x = regs.x.cx = x * 8;
|
|
118 mouse_last_y = regs.x.dx = y * 8;
|
|
119 int86 (0x33, ®s, ®s);
|
|
120 }
|
|
121
|
|
122 static int
|
|
123 mouse_pressed (int b, int *xp, int *yp)
|
|
124 {
|
|
125 union REGS regs;
|
|
126
|
|
127 if (b >= mouse_button_count)
|
|
128 return 0;
|
|
129 regs.x.ax = 0x0005;
|
|
130 regs.x.bx = mouse_button_translate[b];
|
|
131 int86 (0x33, ®s, ®s);
|
|
132 if (regs.x.bx)
|
|
133 *xp = regs.x.cx / 8, *yp = regs.x.dx / 8;
|
|
134 return (regs.x.bx != 0);
|
|
135 }
|
|
136
|
|
137 static int
|
|
138 mouse_released (int b, int *xp, int *yp)
|
|
139 {
|
|
140 union REGS regs;
|
|
141
|
|
142 if (b >= mouse_button_count)
|
|
143 return 0;
|
|
144 regs.x.ax = 0x0006;
|
|
145 regs.x.bx = mouse_button_translate[b];
|
|
146 int86 (0x33, ®s, ®s);
|
|
147 if (regs.x.bx)
|
|
148 *xp = regs.x.cx / 8, *yp = regs.x.dx / 8;
|
|
149 return (regs.x.bx != 0);
|
|
150 }
|
|
151
|
|
152 static void
|
|
153 mouse_get_xy (int *x, int *y)
|
|
154 {
|
|
155 union REGS regs;
|
|
156
|
|
157 regs.x.ax = 0x0003;
|
|
158 int86 (0x33, ®s, ®s);
|
|
159 *x = regs.x.cx / 8;
|
|
160 *y = regs.x.dx / 8;
|
|
161 }
|
|
162
|
|
163 void
|
|
164 mouse_get_pos (FRAME_PTR *f, int insist, Lisp_Object *bar_window,
|
|
165 Lisp_Object *x, Lisp_Object *y, enum scroll_bar_part *part,
|
|
166 unsigned long *time)
|
|
167 {
|
|
168 int ix, iy;
|
|
169 union REGS regs;
|
|
170
|
|
171 regs.x.ax = 0x0003;
|
|
172 int86 (0x33, ®s, ®s);
|
|
173 *f = selected_frame;
|
|
174 *bar_window = Qnil;
|
|
175 mouse_get_xy (&ix, &iy);
|
|
176 selected_frame->mouse_moved = 0;
|
|
177 *x = make_int (ix);
|
|
178 *y = make_int (iy);
|
|
179 *time = event_timestamp ();
|
|
180 }
|
|
181
|
|
182 static void
|
|
183 mouse_check_moved (void)
|
|
184 {
|
|
185 int x, y;
|
|
186
|
|
187 mouse_get_xy (&x, &y);
|
|
188 selected_frame->mouse_moved |= (x != mouse_last_x || y != mouse_last_y);
|
|
189 mouse_last_x = x;
|
|
190 mouse_last_y = y;
|
|
191 }
|
|
192
|
|
193 void
|
|
194 mouse_init (void)
|
|
195 {
|
|
196 union REGS regs;
|
|
197
|
|
198 if (termscript)
|
|
199 fprintf (termscript, "<M_INIT>");
|
|
200
|
|
201 regs.x.ax = 0x0021;
|
|
202 int86 (0x33, ®s, ®s);
|
|
203
|
|
204 regs.x.ax = 0x0007;
|
|
205 regs.x.cx = 0;
|
|
206 regs.x.dx = 8 * (ScreenCols () - 1);
|
|
207 int86 (0x33, ®s, ®s);
|
|
208
|
|
209 regs.x.ax = 0x0008;
|
|
210 regs.x.cx = 0;
|
|
211 regs.x.dx = 8 * (ScreenRows () - 1);
|
|
212 int86 (0x33, ®s, ®s);
|
|
213
|
|
214 mouse_moveto (0, 0);
|
|
215 mouse_visible = 0;
|
|
216 }
|
|
217
|
|
218 /* ------------------------- Screen control ----------------------
|
|
219 *
|
|
220 */
|
|
221
|
|
222 static int internal_terminal = 0;
|
|
223
|
|
224 #ifndef HAVE_X_WINDOWS
|
|
225 extern unsigned char ScreenAttrib;
|
|
226 static int screen_face;
|
|
227 static int highlight;
|
|
228
|
|
229 static int screen_size_X;
|
|
230 static int screen_size_Y;
|
|
231 static int screen_size;
|
|
232
|
|
233 static int current_pos_X;
|
|
234 static int current_pos_Y;
|
|
235 static int new_pos_X;
|
|
236 static int new_pos_Y;
|
|
237
|
|
238 static void *startup_screen_buffer;
|
|
239 static int startup_screen_size_X;
|
|
240 static int startup_screen_size_Y;
|
|
241 static int startup_pos_X;
|
|
242 static int startup_pos_Y;
|
|
243
|
|
244 static int term_setup_done;
|
|
245
|
|
246 /* Similar to the_only_frame. */
|
|
247 struct x_output the_only_x_display;
|
|
248
|
|
249 /* This is never dereferenced. */
|
|
250 Display *x_current_display;
|
|
251
|
|
252
|
|
253 #define SCREEN_SET_CURSOR() \
|
|
254 if (current_pos_X != new_pos_X || current_pos_Y != new_pos_Y) \
|
|
255 ScreenSetCursor (current_pos_Y = new_pos_Y, current_pos_X = new_pos_X)
|
|
256
|
|
257 static
|
|
258 dos_direct_output (int y, int x, char *buf, int len)
|
|
259 {
|
|
260 int t = (int) ScreenPrimary + 2 * (x + y * screen_size_X);
|
173
|
261
|
0
|
262 while (--len >= 0) {
|
|
263 dosmemput (buf++, 1, t);
|
|
264 t += 2;
|
|
265 }
|
|
266 }
|
|
267 #endif
|
|
268
|
|
269 /* Flash the screen as a substitute for BEEPs. */
|
|
270
|
|
271 #if (__DJGPP__ < 2)
|
|
272 static void
|
|
273 do_visible_bell (unsigned char xorattr)
|
|
274 {
|
|
275 asm volatile
|
|
276 (" movb $1,%%dl
|
|
277 visible_bell_0:
|
|
278 movl _ScreenPrimary,%%eax
|
|
279 call dosmemsetup
|
|
280 movl %%eax,%%ebx
|
|
281 movl %1,%%ecx
|
|
282 movb %0,%%al
|
|
283 incl %%ebx
|
|
284 visible_bell_1:
|
|
285 xorb %%al,%%gs:(%%ebx)
|
|
286 addl $2,%%ebx
|
|
287 decl %%ecx
|
|
288 jne visible_bell_1
|
|
289 decb %%dl
|
|
290 jne visible_bell_3
|
|
291 visible_bell_2:
|
|
292 movzwl %%ax,%%eax
|
|
293 movzwl %%ax,%%eax
|
|
294 movzwl %%ax,%%eax
|
|
295 movzwl %%ax,%%eax
|
|
296 decw %%cx
|
|
297 jne visible_bell_2
|
|
298 jmp visible_bell_0
|
|
299 visible_bell_3:"
|
|
300 : /* no output */
|
|
301 : "m" (xorattr), "g" (screen_size)
|
|
302 : "%eax", "%ebx", /* "%gs",*/ "%ecx", "%edx");
|
|
303 }
|
|
304
|
|
305 static void
|
|
306 ScreenVisualBell (void)
|
|
307 {
|
|
308 /* This creates an xor-mask that will swap the default fore- and
|
|
309 background colors. */
|
|
310 do_visible_bell (((the_only_x_display.foreground_pixel
|
|
311 ^ the_only_x_display.background_pixel)
|
|
312 * 0x11) & 0x7f);
|
|
313 }
|
|
314 #endif
|
|
315
|
|
316 #ifndef HAVE_X_WINDOWS
|
|
317
|
|
318 /*
|
|
319 * If we write a character in the position where the mouse is,
|
|
320 * the mouse cursor may need to be refreshed.
|
|
321 */
|
|
322
|
|
323 static void
|
|
324 mouse_off_maybe (void)
|
|
325 {
|
|
326 int x, y;
|
173
|
327
|
0
|
328 if (!mouse_visible)
|
|
329 return;
|
173
|
330
|
0
|
331 mouse_get_xy (&x, &y);
|
|
332 if (y != new_pos_Y || x < new_pos_X)
|
|
333 return;
|
173
|
334
|
0
|
335 mouse_off ();
|
|
336 }
|
|
337
|
|
338 static
|
|
339 IT_ring_bell (void)
|
|
340 {
|
|
341 if (visible_bell)
|
|
342 {
|
|
343 mouse_off ();
|
|
344 ScreenVisualBell ();
|
|
345 }
|
|
346 else
|
|
347 {
|
|
348 union REGS inregs, outregs;
|
|
349 inregs.h.ah = 2;
|
|
350 inregs.h.dl = 7;
|
|
351 intdos (&inregs, &outregs);
|
|
352 }
|
|
353 }
|
|
354
|
|
355 static void
|
|
356 IT_set_face (int face)
|
|
357 {
|
|
358 struct face *fp;
|
|
359 extern struct face *intern_face (/* FRAME_PTR, struct face * */);
|
|
360
|
|
361 if (face == 1 || (face == 0 && highlight))
|
|
362 fp = FRAME_MODE_LINE_FACE (foo);
|
|
363 else if (face <= 0 || face >= FRAME_N_COMPUTED_FACES (foo))
|
|
364 fp = FRAME_DEFAULT_FACE (foo);
|
|
365 else
|
|
366 fp = intern_face (selected_frame, FRAME_COMPUTED_FACES (foo)[face]);
|
|
367 if (termscript)
|
|
368 fprintf (termscript, "<FACE:%d:%d>", FACE_FOREGROUND (fp), FACE_BACKGROUND (fp));
|
|
369 screen_face = face;
|
|
370 ScreenAttrib = (FACE_BACKGROUND (fp) << 4) | FACE_FOREGROUND (fp);
|
|
371 }
|
|
372
|
|
373 static
|
|
374 IT_write_glyphs (GLYPH *str, int len)
|
|
375 {
|
|
376 int newface;
|
|
377 int ch, l = len;
|
|
378 unsigned char *buf, *bp;
|
|
379
|
|
380 if (len == 0) return;
|
173
|
381
|
0
|
382 buf = bp = alloca (len * 2);
|
173
|
383
|
0
|
384 while (--l >= 0)
|
|
385 {
|
|
386 newface = FAST_GLYPH_FACE (*str);
|
|
387 if (newface != screen_face)
|
|
388 IT_set_face (newface);
|
|
389 ch = FAST_GLYPH_CHAR (*str);
|
|
390 *bp++ = (unsigned char)ch;
|
|
391 *bp++ = ScreenAttrib;
|
173
|
392
|
0
|
393 if (termscript)
|
|
394 fputc (ch, termscript);
|
|
395 str++;
|
|
396 }
|
|
397
|
|
398 mouse_off_maybe ();
|
173
|
399 dosmemput (buf, 2 * len,
|
0
|
400 (int)ScreenPrimary + 2 * (new_pos_X + screen_size_X * new_pos_Y));
|
|
401 new_pos_X += len;
|
|
402 }
|
|
403
|
|
404 static
|
|
405 IT_clear_end_of_line (int first_unused)
|
|
406 {
|
|
407 char *spaces, *sp;
|
|
408 int i, j;
|
|
409
|
|
410 IT_set_face (0);
|
|
411 if (termscript)
|
|
412 fprintf (termscript, "<CLR:EOL>");
|
|
413 i = (j = screen_size_X - new_pos_X) * 2;
|
|
414 spaces = sp = alloca (i);
|
173
|
415
|
0
|
416 while (--j >= 0)
|
|
417 {
|
|
418 *sp++ = ' ';
|
|
419 *sp++ = ScreenAttrib;
|
|
420 }
|
|
421
|
|
422 mouse_off_maybe ();
|
173
|
423 dosmemput (spaces, i,
|
0
|
424 (int)ScreenPrimary + 2 * (new_pos_X + screen_size_X * new_pos_Y));
|
|
425 }
|
|
426
|
|
427 static
|
|
428 IT_clear_screen (void)
|
|
429 {
|
|
430 if (termscript)
|
|
431 fprintf (termscript, "<CLR:SCR>");
|
|
432 IT_set_face (0);
|
|
433 mouse_off ();
|
|
434 ScreenClear ();
|
|
435 new_pos_X = new_pos_Y = 0;
|
|
436 }
|
|
437
|
|
438 static
|
|
439 IT_clear_to_end (void)
|
|
440 {
|
|
441 if (termscript)
|
|
442 fprintf (termscript, "<CLR:EOS>");
|
|
443
|
|
444 while (new_pos_Y < screen_size_Y) {
|
|
445 new_pos_X = 0;
|
|
446 IT_clear_end_of_line (0);
|
|
447 new_pos_Y++;
|
|
448 }
|
|
449 }
|
|
450
|
|
451 static
|
|
452 IT_cursor_to (int y, int x)
|
|
453 {
|
|
454 if (termscript)
|
|
455 fprintf (termscript, "\n<XY=%dx%d>", x, y);
|
|
456 new_pos_X = x;
|
|
457 new_pos_Y = y;
|
|
458 }
|
|
459
|
|
460 static
|
|
461 IT_reassert_line_highlight (int new, int vpos)
|
|
462 {
|
|
463 highlight = new;
|
|
464 IT_set_face (0); /* To possibly clear the highlighting. */
|
|
465 }
|
|
466
|
|
467 static
|
|
468 IT_change_line_highlight (int new_highlight, int vpos, int first_unused_hpos)
|
|
469 {
|
|
470 highlight = new_highlight;
|
|
471 IT_set_face (0); /* To possibly clear the highlighting. */
|
|
472 IT_cursor_to (vpos, 0);
|
|
473 IT_clear_end_of_line (first_unused_hpos);
|
|
474 }
|
|
475
|
|
476 static
|
|
477 IT_update_begin (void)
|
|
478 {
|
|
479 highlight = 0;
|
|
480 IT_set_face (0); /* To possibly clear the highlighting. */
|
|
481 screen_face = -1;
|
|
482 }
|
|
483
|
|
484 static
|
|
485 IT_update_end (void)
|
|
486 {
|
|
487 }
|
|
488
|
|
489 /* This was more or less copied from xterm.c */
|
|
490 static void
|
|
491 IT_set_menu_bar_lines (Lisp_Object window, int n)
|
|
492 {
|
|
493 struct window *w = XWINDOW (window);
|
|
494
|
|
495 XSETINT (w->last_modified, 0);
|
|
496 XSETINT (w->top, XINT (w->top) + n);
|
|
497 XSETINT (w->height, XINT (w->height) - n);
|
|
498
|
|
499 /* Handle just the top child in a vertical split. */
|
|
500 if (!NILP (w->vchild))
|
|
501 IT_set_menu_bar_lines (w->vchild, n);
|
|
502
|
|
503 /* Adjust all children in a horizontal split. */
|
|
504 for (window = w->hchild; !NILP (window); window = w->next)
|
|
505 {
|
|
506 w = XWINDOW (window);
|
|
507 IT_set_menu_bar_lines (window, n);
|
|
508 }
|
|
509 }
|
|
510
|
|
511 /*
|
|
512 * IT_set_terminal_modes is called when emacs is started,
|
|
513 * resumed, and whenever the screen is redrawn!
|
|
514 */
|
|
515
|
|
516 static
|
|
517 IT_set_terminal_modes (void)
|
|
518 {
|
|
519 char *colors;
|
|
520 FRAME_PTR f;
|
|
521 struct face *fp;
|
|
522
|
|
523 if (termscript)
|
|
524 fprintf (termscript, "\n<SET_TERM>");
|
|
525 highlight = 0;
|
|
526
|
|
527 screen_size_X = ScreenCols ();
|
|
528 screen_size_Y = ScreenRows ();
|
|
529 screen_size = screen_size_X * screen_size_Y;
|
173
|
530
|
0
|
531 new_pos_X = new_pos_Y = 0;
|
|
532 current_pos_X = current_pos_Y = -1;
|
|
533
|
|
534 if (term_setup_done)
|
|
535 return;
|
|
536 term_setup_done = 1;
|
173
|
537
|
0
|
538 startup_screen_size_X = screen_size_X;
|
|
539 startup_screen_size_Y = screen_size_Y;
|
|
540
|
|
541 ScreenGetCursor (&startup_pos_Y, &startup_pos_X);
|
|
542 ScreenRetrieve (startup_screen_buffer = xmalloc (screen_size * 2));
|
|
543
|
|
544 if (termscript)
|
|
545 fprintf (termscript, "<SCREEN SAVED>\n");
|
|
546 }
|
|
547
|
|
548 /*
|
|
549 * IT_reset_terminal_modes is called when emacs is
|
|
550 * suspended or killed.
|
|
551 */
|
|
552
|
|
553 static
|
|
554 IT_reset_terminal_modes (void)
|
|
555 {
|
|
556 if (termscript)
|
|
557 fprintf (termscript, "\n<RESET_TERM>");
|
|
558
|
|
559 highlight = 0;
|
|
560
|
|
561 if (!term_setup_done)
|
|
562 return;
|
173
|
563
|
0
|
564 ScreenUpdate (startup_screen_buffer);
|
|
565 ScreenSetCursor (startup_pos_Y, startup_pos_X);
|
|
566 xfree (startup_screen_buffer);
|
|
567
|
|
568 if (termscript)
|
|
569 fprintf (termscript, "<SCREEN RESTORED>\n");
|
|
570
|
|
571 term_setup_done = 0;
|
|
572 }
|
|
573
|
|
574 static
|
|
575 IT_set_terminal_window (void)
|
|
576 {
|
|
577 }
|
|
578
|
|
579 void
|
|
580 IT_set_frame_parameters (FRAME_PTR frame, Lisp_Object alist)
|
|
581 {
|
|
582 Lisp_Object tail;
|
|
583 int redraw;
|
|
584 extern unsigned long load_color ();
|
|
585 FRAME_PTR f = (FRAME_PTR) &the_only_frame;
|
|
586
|
|
587 redraw = 0;
|
|
588 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
|
|
589 {
|
|
590 Lisp_Object elt, prop, val;
|
|
591
|
|
592 elt = Fcar (tail);
|
|
593 prop = Fcar (elt);
|
|
594 val = Fcdr (elt);
|
|
595 CHECK_SYMBOL (prop);
|
|
596
|
|
597 if (EQ (prop, intern ("foreground-color")))
|
|
598 {
|
|
599 unsigned long new_color = load_color (f, val);
|
|
600 if (new_color != ~0)
|
|
601 {
|
|
602 FRAME_FOREGROUND_PIXEL (f) = new_color;
|
|
603 redraw = 1;
|
|
604 }
|
|
605 }
|
|
606 else if (EQ (prop, intern ("background-color")))
|
|
607 {
|
|
608 unsigned long new_color = load_color (f, val);
|
|
609 if (new_color != ~0)
|
|
610 {
|
|
611 FRAME_BACKGROUND_PIXEL (f) = new_color & ~8;
|
|
612 redraw = 1;
|
|
613 }
|
|
614 }
|
|
615 else if (EQ (prop, intern ("menu-bar-lines")))
|
|
616 {
|
|
617 int new;
|
|
618 int old = FRAME_MENU_BAR_LINES (the_only_frame);
|
|
619
|
|
620 if (INTEGERP (val))
|
|
621 new = XINT (val);
|
|
622 else
|
|
623 new = 0;
|
|
624 FRAME_MENU_BAR_LINES (f) = new;
|
|
625 IT_set_menu_bar_lines (the_only_frame.root_window, new - old);
|
|
626 }
|
|
627 }
|
|
628
|
|
629 if (redraw)
|
|
630 {
|
|
631 recompute_basic_faces (f);
|
|
632 Fredraw_frame (Fselected_frame (Qnil), Qnil);
|
|
633 }
|
|
634 }
|
|
635
|
|
636 #endif /* !HAVE_X_WINDOWS */
|
|
637
|
|
638
|
|
639 /* Do we need the internal terminal? */
|
|
640 void
|
|
641 internal_terminal_init (void)
|
|
642 {
|
|
643 char *term = getenv ("TERM");
|
|
644 char *colors;
|
|
645
|
|
646 #ifdef HAVE_X_WINDOWS
|
|
647 if (!inhibit_window_system)
|
|
648 return;
|
|
649 #endif
|
|
650
|
|
651 internal_terminal
|
|
652 = (!noninteractive) && term && !strcmp (term, "internal");
|
|
653
|
|
654 if (getenv ("EMACSTEST"))
|
|
655 termscript = fopen (getenv ("EMACSTEST"), "wt");
|
173
|
656
|
0
|
657 #ifndef HAVE_X_WINDOWS
|
|
658 if (!internal_terminal || inhibit_window_system)
|
|
659 {
|
|
660 the_only_frame.output_method = output_termcap;
|
|
661 return;
|
|
662 }
|
|
663
|
|
664 Vwindow_system = intern ("pc");
|
173
|
665
|
0
|
666 bzero (&the_only_x_display, sizeof the_only_x_display);
|
|
667 the_only_x_display.background_pixel = 7; /* White */
|
|
668 the_only_x_display.foreground_pixel = 0; /* Black */
|
|
669 colors = getenv ("EMACSCOLORS");
|
|
670 if (colors && strlen (colors) >= 2)
|
|
671 {
|
|
672 the_only_x_display.foreground_pixel = colors[0] & 0x07;
|
|
673 the_only_x_display.background_pixel = colors[1] & 0x07;
|
|
674 }
|
|
675 the_only_x_display.line_height = 1;
|
|
676 the_only_frame.output_data.x = &the_only_x_display;
|
|
677 the_only_frame.output_method = output_msdos_raw;
|
|
678 the_only_x_display.font = (XFontStruct *)1; /* must *not* be zero */
|
|
679
|
|
680 init_frame_faces ((FRAME_PTR) &the_only_frame);
|
|
681
|
|
682 ring_bell_hook = IT_ring_bell;
|
|
683 write_glyphs_hook = IT_write_glyphs;
|
|
684 cursor_to_hook = raw_cursor_to_hook = IT_cursor_to;
|
|
685 clear_to_end_hook = IT_clear_to_end;
|
|
686 clear_end_of_line_hook = IT_clear_end_of_line;
|
|
687 clear_frame_hook = IT_clear_screen;
|
|
688 change_line_highlight_hook = IT_change_line_highlight;
|
|
689 update_begin_hook = IT_update_begin;
|
|
690 update_end_hook = IT_update_end;
|
|
691 reassert_line_highlight_hook = IT_reassert_line_highlight;
|
|
692
|
|
693 /* These hooks are called by term.c without being checked. */
|
|
694 set_terminal_modes_hook = IT_set_terminal_modes;
|
|
695 reset_terminal_modes_hook = IT_reset_terminal_modes;
|
|
696 set_terminal_window_hook = IT_set_terminal_window;
|
|
697 #endif
|
|
698 }
|
|
699
|
|
700 dos_get_saved_screen (char **screen, int *rows, int *cols)
|
|
701 {
|
|
702 #ifndef HAVE_X_WINDOWS
|
|
703 *screen = startup_screen_buffer;
|
|
704 *cols = startup_screen_size_X;
|
|
705 *rows = startup_screen_size_Y;
|
|
706 return 1;
|
|
707 #else
|
|
708 return 0;
|
173
|
709 #endif
|
0
|
710 }
|
|
711
|
|
712
|
|
713
|
|
714 /* ----------------------- Keyboard control ----------------------
|
|
715 *
|
|
716 * Keymaps reflect the following keyboard layout:
|
|
717 *
|
|
718 * 0 1 2 3 4 5 6 7 8 9 10 11 12 BS
|
|
719 * TAB 15 16 17 18 19 20 21 22 23 24 25 26 (41)
|
|
720 * CLOK 30 31 32 33 34 35 36 37 38 39 40 (41) RET
|
|
721 * SH () 45 46 47 48 49 50 51 52 53 54 SHIFT
|
|
722 * SPACE
|
|
723 */
|
|
724
|
|
725 static int extended_kbd; /* 101 (102) keyboard present. */
|
|
726
|
|
727 struct dos_keyboard_map
|
|
728 {
|
|
729 char *unshifted;
|
|
730 char *shifted;
|
|
731 char *alt_gr;
|
|
732 };
|
|
733
|
|
734
|
|
735 static struct dos_keyboard_map us_keyboard = {
|
|
736 /* 0 1 2 3 4 5 */
|
|
737 /* 01234567890123456789012345678901234567890 12345678901234 */
|
|
738 "`1234567890-= qwertyuiop[] asdfghjkl;'\\ zxcvbnm,./ ",
|
|
739 /* 0123456789012345678901234567890123456789 012345678901234 */
|
|
740 "~!@#$%^&*()_+ QWERTYUIOP{} ASDFGHJKL:\"| ZXCVBNM<>? ",
|
|
741 0 /* no Alt-Gr key */
|
|
742 };
|
|
743
|
|
744 static struct dos_keyboard_map fr_keyboard = {
|
|
745 /* 0 1 2 3 4 5 */
|
|
746 /* 012 3456789012345678901234567890123456789012345678901234 */
|
|
747 "ý&‚\",(-Š_€…)= azertyuiop^$ qsdfghjklm—* wxcvbnm;:! ",
|
|
748 /* 0123456789012345678901234567890123456789012345678901234 */
|
|
749 " 1234567890ø+ AZERTYUIOPùœ QSDFGHJKLM%æ WXCVBN?./õ ",
|
|
750 /* 01234567 89012345678901234567890123456789012345678901234 */
|
|
751 " ~#{[|`\\^@]} Ï "
|
|
752 };
|
|
753
|
|
754 static struct dos_keyboard_map dk_keyboard = {
|
|
755 /* 0 1 2 3 4 5 */
|
|
756 /* 0123456789012345678901234567890123456789012345678901234 */
|
|
757 "«1234567890+| qwertyuiop†~ asdfghjkl‘›' zxcvbnm,.- ",
|
|
758 /* 01 23456789012345678901234567890123456789012345678901234 */
|
|
759 "õ!\"#$%&/()=?` QWERTYUIOP^ ASDFGHJKL’* ZXCVBNM;:_ ",
|
|
760 /* 0123456789012345678901234567890123456789012345678901234 */
|
|
761 " @œ$ {[]} | "
|
|
762 };
|
|
763
|
|
764 static struct keyboard_layout_list
|
|
765 {
|
|
766 int country_code;
|
|
767 struct dos_keyboard_map *keyboard_map;
|
|
768 } keyboard_layout_list[] =
|
|
769 {
|
|
770 1, &us_keyboard,
|
|
771 33, &fr_keyboard,
|
|
772 45, &dk_keyboard
|
|
773 };
|
|
774
|
|
775 static struct dos_keyboard_map *keyboard;
|
|
776 static int keyboard_map_all;
|
|
777
|
|
778 int
|
|
779 dos_set_keyboard (int code, int always)
|
|
780 {
|
|
781 int i;
|
|
782
|
|
783 /* Initialize to US settings, for countries that don't have their own. */
|
|
784 keyboard = keyboard_layout_list[0].keyboard_map;
|
|
785 keyboard_map_all = always;
|
|
786 dos_keyboard_layout = 1;
|
173
|
787
|
0
|
788 for (i = 0; i < (sizeof (keyboard_layout_list)/sizeof (struct keyboard_layout_list)); i++)
|
|
789 if (code == keyboard_layout_list[i].country_code)
|
|
790 {
|
|
791 keyboard = keyboard_layout_list[i].keyboard_map;
|
|
792 keyboard_map_all = always;
|
|
793 dos_keyboard_layout = code;
|
|
794 return 1;
|
|
795 }
|
|
796 return 0;
|
|
797 }
|
|
798
|
|
799 #define Ignore 0x0000
|
|
800 #define Normal 0x0000 /* normal key - alt changes scan-code */
|
|
801 #define FctKey 0x1000 /* func key if c == 0, else c */
|
|
802 #define Special 0x2000 /* func key even if c != 0 */
|
|
803 #define ModFct 0x3000 /* special if mod-keys, else 'c' */
|
|
804 #define Map 0x4000 /* alt scan-code, map to unshift/shift key */
|
|
805 #define KeyPad 0x5000 /* map to insert/kp-0 depending on c == 0xe0 */
|
|
806 #define Grey 0x6000 /* Grey keypad key */
|
|
807
|
|
808 #define Alt 0x0100 /* alt scan-code */
|
|
809 #define Ctrl 0x0200 /* ctrl scan-code */
|
|
810 #define Shift 0x0400 /* shift scan-code */
|
|
811
|
|
812 static struct
|
|
813 {
|
|
814 unsigned char char_code; /* normal code */
|
|
815 unsigned char meta_code; /* M- code */
|
|
816 unsigned char keypad_code; /* keypad code */
|
|
817 unsigned char editkey_code; /* edit key */
|
|
818 } keypad_translate_map[] = {
|
|
819 '0', '0', 0xb0, /* kp-0 */ 0x63, /* insert */
|
|
820 '1', '1', 0xb1, /* kp-1 */ 0x57, /* end */
|
|
821 '2', '2', 0xb2, /* kp-2 */ 0x54, /* down */
|
|
822 '3', '3', 0xb3, /* kp-3 */ 0x56, /* next */
|
|
823 '4', '4', 0xb4, /* kp-4 */ 0x51, /* left */
|
|
824 '5', '5', 0xb5, /* kp-5 */ 0xb5, /* kp-5 */
|
|
825 '6', '6', 0xb6, /* kp-6 */ 0x53, /* right */
|
|
826 '7', '7', 0xb7, /* kp-7 */ 0x50, /* home */
|
|
827 '8', '8', 0xb8, /* kp-8 */ 0x52, /* up */
|
|
828 '9', '9', 0xb9, /* kp-9 */ 0x55, /* prior */
|
|
829 '.', '-', 0xae, /* kp-decimal */ 0xff /* delete */
|
|
830 };
|
|
831
|
|
832 static struct
|
|
833 {
|
|
834 unsigned char char_code; /* normal code */
|
|
835 unsigned char keypad_code; /* keypad code */
|
|
836 } grey_key_translate_map[] = {
|
|
837 '/', 0xaf, /* kp-decimal */
|
|
838 '*', 0xaa, /* kp-multiply */
|
|
839 '-', 0xad, /* kp-subtract */
|
|
840 '+', 0xab, /* kp-add */
|
|
841 '\r', 0x8d /* kp-enter */
|
|
842 };
|
|
843
|
|
844 static unsigned short
|
|
845 ibmpc_translate_map[] =
|
|
846 {
|
|
847 /* --------------- 00 to 0f --------------- */
|
|
848 Normal | 0xff, /* Ctrl Break + Alt-NNN */
|
|
849 Alt | ModFct | 0x1b, /* Escape */
|
|
850 Normal | 1, /* '1' */
|
|
851 Normal | 2, /* '2' */
|
|
852 Normal | 3, /* '3' */
|
|
853 Normal | 4, /* '4' */
|
|
854 Normal | 5, /* '5' */
|
|
855 Normal | 6, /* '6' */
|
|
856 Normal | 7, /* '7' */
|
|
857 Normal | 8, /* '8' */
|
|
858 Normal | 9, /* '9' */
|
|
859 Normal | 10, /* '0' */
|
|
860 Normal | 11, /* '-' */
|
|
861 Normal | 12, /* '=' */
|
|
862 Special | 0x08, /* Backspace */
|
|
863 ModFct | 0x74, /* Tab/Backtab */
|
|
864
|
|
865 /* --------------- 10 to 1f --------------- */
|
|
866 Map | 15, /* 'q' */
|
|
867 Map | 16, /* 'w' */
|
|
868 Map | 17, /* 'e' */
|
|
869 Map | 18, /* 'r' */
|
|
870 Map | 19, /* 't' */
|
|
871 Map | 20, /* 'y' */
|
|
872 Map | 21, /* 'u' */
|
|
873 Map | 22, /* 'i' */
|
|
874 Map | 23, /* 'o' */
|
|
875 Map | 24, /* 'p' */
|
|
876 Map | 25, /* '[' */
|
173
|
877 Map | 26, /* ']' */
|
0
|
878 ModFct | 0x0d, /* Return */
|
|
879 Ignore, /* Ctrl */
|
|
880 Map | 30, /* 'a' */
|
|
881 Map | 31, /* 's' */
|
|
882
|
|
883 /* --------------- 20 to 2f --------------- */
|
|
884 Map | 32, /* 'd' */
|
|
885 Map | 33, /* 'f' */
|
|
886 Map | 34, /* 'g' */
|
|
887 Map | 35, /* 'h' */
|
|
888 Map | 36, /* 'j' */
|
|
889 Map | 37, /* 'k' */
|
|
890 Map | 38, /* 'l' */
|
|
891 Map | 39, /* ';' */
|
|
892 Map | 40, /* '\'' */
|
|
893 Map | 0, /* '`' */
|
|
894 Ignore, /* Left shift */
|
|
895 Map | 41, /* '\\' */
|
|
896 Map | 45, /* 'z' */
|
|
897 Map | 46, /* 'x' */
|
|
898 Map | 47, /* 'c' */
|
|
899 Map | 48, /* 'v' */
|
|
900
|
|
901 /* --------------- 30 to 3f --------------- */
|
|
902 Map | 49, /* 'b' */
|
|
903 Map | 50, /* 'n' */
|
|
904 Map | 51, /* 'm' */
|
|
905 Map | 52, /* ',' */
|
|
906 Map | 53, /* '.' */
|
|
907 Map | 54, /* '/' */
|
|
908 Ignore, /* Right shift */
|
|
909 Grey | 1, /* Grey * */
|
|
910 Ignore, /* Alt */
|
|
911 Normal | ' ', /* ' ' */
|
|
912 Ignore, /* Caps Lock */
|
|
913 FctKey | 0xbe, /* F1 */
|
|
914 FctKey | 0xbf, /* F2 */
|
|
915 FctKey | 0xc0, /* F3 */
|
|
916 FctKey | 0xc1, /* F4 */
|
|
917 FctKey | 0xc2, /* F5 */
|
|
918
|
|
919 /* --------------- 40 to 4f --------------- */
|
|
920 FctKey | 0xc3, /* F6 */
|
|
921 FctKey | 0xc4, /* F7 */
|
|
922 FctKey | 0xc5, /* F8 */
|
|
923 FctKey | 0xc6, /* F9 */
|
|
924 FctKey | 0xc7, /* F10 */
|
|
925 Ignore, /* Num Lock */
|
|
926 Ignore, /* Scroll Lock */
|
|
927 KeyPad | 7, /* Home */
|
|
928 KeyPad | 8, /* Up */
|
|
929 KeyPad | 9, /* Page Up */
|
|
930 Grey | 2, /* Grey - */
|
|
931 KeyPad | 4, /* Left */
|
|
932 KeyPad | 5, /* Keypad 5 */
|
|
933 KeyPad | 6, /* Right */
|
|
934 Grey | 3, /* Grey + */
|
|
935 KeyPad | 1, /* End */
|
|
936
|
|
937 /* --------------- 50 to 5f --------------- */
|
|
938 KeyPad | 2, /* Down */
|
|
939 KeyPad | 3, /* Page Down */
|
|
940 KeyPad | 0, /* Insert */
|
|
941 KeyPad | 10, /* Delete */
|
|
942 Shift | FctKey | 0xbe, /* (Shift) F1 */
|
|
943 Shift | FctKey | 0xbf, /* (Shift) F2 */
|
|
944 Shift | FctKey | 0xc0, /* (Shift) F3 */
|
|
945 Shift | FctKey | 0xc1, /* (Shift) F4 */
|
|
946 Shift | FctKey | 0xc2, /* (Shift) F5 */
|
|
947 Shift | FctKey | 0xc3, /* (Shift) F6 */
|
|
948 Shift | FctKey | 0xc4, /* (Shift) F7 */
|
|
949 Shift | FctKey | 0xc5, /* (Shift) F8 */
|
|
950 Shift | FctKey | 0xc6, /* (Shift) F9 */
|
|
951 Shift | FctKey | 0xc7, /* (Shift) F10 */
|
|
952 Ctrl | FctKey | 0xbe, /* (Ctrl) F1 */
|
|
953 Ctrl | FctKey | 0xbf, /* (Ctrl) F2 */
|
|
954
|
|
955 /* --------------- 60 to 6f --------------- */
|
|
956 Ctrl | FctKey | 0xc0, /* (Ctrl) F3 */
|
|
957 Ctrl | FctKey | 0xc1, /* (Ctrl) F4 */
|
|
958 Ctrl | FctKey | 0xc2, /* (Ctrl) F5 */
|
|
959 Ctrl | FctKey | 0xc3, /* (Ctrl) F6 */
|
|
960 Ctrl | FctKey | 0xc4, /* (Ctrl) F7 */
|
|
961 Ctrl | FctKey | 0xc5, /* (Ctrl) F8 */
|
|
962 Ctrl | FctKey | 0xc6, /* (Ctrl) F9 */
|
|
963 Ctrl | FctKey | 0xc7, /* (Ctrl) F10 */
|
|
964 Alt | FctKey | 0xbe, /* (Alt) F1 */
|
|
965 Alt | FctKey | 0xbf, /* (Alt) F2 */
|
|
966 Alt | FctKey | 0xc0, /* (Alt) F3 */
|
|
967 Alt | FctKey | 0xc1, /* (Alt) F4 */
|
|
968 Alt | FctKey | 0xc2, /* (Alt) F5 */
|
|
969 Alt | FctKey | 0xc3, /* (Alt) F6 */
|
|
970 Alt | FctKey | 0xc4, /* (Alt) F7 */
|
|
971 Alt | FctKey | 0xc5, /* (Alt) F8 */
|
|
972
|
|
973 /* --------------- 70 to 7f --------------- */
|
|
974 Alt | FctKey | 0xc6, /* (Alt) F9 */
|
|
975 Alt | FctKey | 0xc7, /* (Alt) F10 */
|
|
976 Ctrl | FctKey | 0x6d, /* (Ctrl) Sys Rq */
|
|
977 Ctrl | KeyPad | 4, /* (Ctrl) Left */
|
|
978 Ctrl | KeyPad | 6, /* (Ctrl) Right */
|
|
979 Ctrl | KeyPad | 1, /* (Ctrl) End */
|
|
980 Ctrl | KeyPad | 3, /* (Ctrl) Page Down */
|
|
981 Ctrl | KeyPad | 7, /* (Ctrl) Home */
|
|
982 Alt | Map | 1, /* '1' */
|
|
983 Alt | Map | 2, /* '2' */
|
|
984 Alt | Map | 3, /* '3' */
|
|
985 Alt | Map | 4, /* '4' */
|
|
986 Alt | Map | 5, /* '5' */
|
|
987 Alt | Map | 6, /* '6' */
|
|
988 Alt | Map | 7, /* '7' */
|
|
989 Alt | Map | 8, /* '8' */
|
|
990
|
|
991 /* --------------- 80 to 8f --------------- */
|
|
992 Alt | Map | 9, /* '9' */
|
|
993 Alt | Map | 10, /* '0' */
|
|
994 Alt | Map | 11, /* '-' */
|
|
995 Alt | Map | 12, /* '=' */
|
|
996 Ctrl | KeyPad | 9, /* (Ctrl) Page Up */
|
|
997 FctKey | 0xc8, /* F11 */
|
|
998 FctKey | 0xc9, /* F12 */
|
|
999 Shift | FctKey | 0xc8, /* (Shift) F11 */
|
|
1000 Shift | FctKey | 0xc9, /* (Shift) F12 */
|
|
1001 Ctrl | FctKey | 0xc8, /* (Ctrl) F11 */
|
|
1002 Ctrl | FctKey | 0xc9, /* (Ctrl) F12 */
|
|
1003 Alt | FctKey | 0xc8, /* (Alt) F11 */
|
|
1004 Alt | FctKey | 0xc9, /* (Alt) F12 */
|
|
1005 Ctrl | KeyPad | 8, /* (Ctrl) Up */
|
|
1006 Ctrl | Grey | 2, /* (Ctrl) Grey - */
|
|
1007 Ctrl | KeyPad | 5, /* (Ctrl) Keypad 5 */
|
|
1008
|
|
1009 /* --------------- 90 to 9f --------------- */
|
|
1010 Ctrl | Grey | 3, /* (Ctrl) Grey + */
|
|
1011 Ctrl | KeyPad | 2, /* (Ctrl) Down */
|
|
1012 Ctrl | KeyPad | 0, /* (Ctrl) Insert */
|
|
1013 Ctrl | KeyPad | 10, /* (Ctrl) Delete */
|
|
1014 Ctrl | FctKey | 0x09, /* (Ctrl) Tab */
|
|
1015 Ctrl | Grey | 0, /* (Ctrl) Grey / */
|
|
1016 Ctrl | Grey | 1, /* (Ctrl) Grey * */
|
|
1017 Alt | FctKey | 0x50, /* (Alt) Home */
|
|
1018 Alt | FctKey | 0x52, /* (Alt) Up */
|
|
1019 Alt | FctKey | 0x55, /* (Alt) Page Up */
|
|
1020 Ignore, /* NO KEY */
|
|
1021 Alt | FctKey | 0x51, /* (Alt) Left */
|
|
1022 Ignore, /* NO KEY */
|
|
1023 Alt | FctKey | 0x53, /* (Alt) Right */
|
|
1024 Ignore, /* NO KEY */
|
|
1025 Alt | FctKey | 0x57, /* (Alt) End */
|
|
1026
|
|
1027 /* --------------- a0 to af --------------- */
|
|
1028 Alt | KeyPad | 2, /* (Alt) Down */
|
|
1029 Alt | KeyPad | 3, /* (Alt) Page Down */
|
|
1030 Alt | KeyPad | 0, /* (Alt) Insert */
|
|
1031 Alt | KeyPad | 10, /* (Alt) Delete */
|
|
1032 Alt | Grey | 0, /* (Alt) Grey / */
|
|
1033 Alt | FctKey | 0x09, /* (Alt) Tab */
|
|
1034 Alt | Grey | 4 /* (Alt) Keypad Enter */
|
|
1035 };
|
|
1036
|
|
1037 /* These bit-positions corresponds to values returned by BIOS */
|
|
1038 #define SHIFT_P 0x0003 /* two bits! */
|
|
1039 #define CTRL_P 0x0004
|
|
1040 #define ALT_P 0x0008
|
|
1041 #define SCRLOCK_P 0x0010
|
|
1042 #define NUMLOCK_P 0x0020
|
|
1043 #define CAPSLOCK_P 0x0040
|
|
1044 #define ALT_GR_P 0x0800
|
|
1045 #define SUPER_P 0x4000 /* pseudo */
|
|
1046 #define HYPER_P 0x8000 /* pseudo */
|
|
1047
|
|
1048 static int
|
|
1049 dos_get_modifiers (int *keymask)
|
|
1050 {
|
|
1051 union REGS regs;
|
|
1052 int mask;
|
|
1053 int modifiers = 0;
|
173
|
1054
|
0
|
1055 /* Calculate modifier bits */
|
|
1056 regs.h.ah = extended_kbd ? 0x12 : 0x02;
|
|
1057 int86 (0x16, ®s, ®s);
|
|
1058
|
|
1059 if (!extended_kbd)
|
|
1060 {
|
173
|
1061 mask = regs.h.al & (SHIFT_P | CTRL_P | ALT_P |
|
0
|
1062 SCRLOCK_P | NUMLOCK_P | CAPSLOCK_P);
|
|
1063 }
|
|
1064 else
|
|
1065 {
|
|
1066 mask = regs.h.al & (SHIFT_P |
|
|
1067 SCRLOCK_P | NUMLOCK_P | CAPSLOCK_P);
|
173
|
1068
|
0
|
1069 /* Do not break international keyboard support. */
|
|
1070 /* When Keyb.Com is loaded, the right Alt key is */
|
|
1071 /* used for accessing characters like { and } */
|
|
1072 if (regs.h.ah & 2) /* Left ALT pressed ? */
|
|
1073 mask |= ALT_P;
|
|
1074
|
|
1075 if ((regs.h.ah & 8) != 0) /* Right ALT pressed ? */
|
|
1076 {
|
|
1077 mask |= ALT_GR_P;
|
|
1078 if (dos_hyper_key == 1)
|
|
1079 {
|
|
1080 mask |= HYPER_P;
|
|
1081 modifiers |= hyper_modifier;
|
|
1082 }
|
|
1083 else if (dos_super_key == 1)
|
|
1084 {
|
|
1085 mask |= SUPER_P;
|
|
1086 modifiers |= super_modifier;
|
|
1087 }
|
|
1088 }
|
173
|
1089
|
0
|
1090 if (regs.h.ah & 1) /* Left CTRL pressed
|
|
1091 mask |= CTRL_P;
|
|
1092
|
|
1093 if (regs.h.ah & 4) /* Right CTRL pressed ? */
|
|
1094 {
|
|
1095 if (dos_hyper_key == 2)
|
|
1096 {
|
|
1097 mask |= HYPER_P;
|
|
1098 modifiers |= hyper_modifier;
|
|
1099 }
|
|
1100 else if (dos_super_key == 2)
|
|
1101 {
|
|
1102 mask |= SUPER_P;
|
|
1103 modifiers |= super_modifier;
|
|
1104 }
|
|
1105 else
|
|
1106 mask |= CTRL_P;
|
|
1107 }
|
|
1108 }
|
|
1109
|
|
1110 if (mask & SHIFT_P)
|
|
1111 modifiers |= shift_modifier;
|
|
1112 if (mask & CTRL_P)
|
|
1113 modifiers |= ctrl_modifier;
|
|
1114 if (mask & ALT_P)
|
|
1115 modifiers |= meta_modifier;
|
|
1116
|
|
1117 if (keymask)
|
|
1118 *keymask = mask;
|
|
1119 return modifiers;
|
|
1120 }
|
|
1121
|
|
1122 #define NUM_RECENT_DOSKEYS (100)
|
|
1123 int recent_doskeys_index; /* Index for storing next element into recent_doskeys */
|
|
1124 int total_doskeys; /* Total number of elements stored into recent_doskeys */
|
|
1125 Lisp_Object recent_doskeys; /* A vector, holding the last 100 keystrokes */
|
|
1126
|
20
|
1127 DEFUN ("recent-doskeys", Frecent_doskeys, 0, 0, 0, /*
|
203
|
1128 Return vector of last 100 keyboard input values seen in dos_rawgetc.
|
|
1129 Each input key receives two values in this vector: first the ASCII code,
|
20
|
1130 and then the scan code.
|
|
1131 */
|
|
1132 ())
|
0
|
1133 {
|
173
|
1134 Lisp_Object *keys = XVECTOR_DATA (recent_doskeys);
|
0
|
1135 Lisp_Object val;
|
|
1136
|
|
1137 if (total_doskeys < NUM_RECENT_DOSKEYS)
|
|
1138 return Fvector (total_doskeys, keys);
|
|
1139 else
|
|
1140 {
|
|
1141 val = Fvector (NUM_RECENT_DOSKEYS, keys);
|
|
1142 bcopy (keys + recent_doskeys_index,
|
173
|
1143 XVECTOR_DATA (val),
|
0
|
1144 (NUM_RECENT_DOSKEYS - recent_doskeys_index) * sizeof (Lisp_Object));
|
|
1145 bcopy (keys,
|
173
|
1146 XVECTOR_DATA (val) + NUM_RECENT_DOSKEYS - recent_doskeys_index,
|
0
|
1147 recent_doskeys_index * sizeof (Lisp_Object));
|
|
1148 return val;
|
|
1149 }
|
|
1150 }
|
|
1151
|
|
1152 /* Get a char from keyboard. Function keys are put into the event queue. */
|
|
1153 static int
|
|
1154 dos_rawgetc (void)
|
|
1155 {
|
|
1156 struct input_event event;
|
|
1157 union REGS regs;
|
173
|
1158
|
0
|
1159 #ifndef HAVE_X_WINDOWS
|
|
1160 SCREEN_SET_CURSOR ();
|
|
1161 if (!mouse_visible) mouse_on ();
|
|
1162 #endif
|
173
|
1163
|
0
|
1164 /* The following condition is equivalent to `kbhit ()', except that
|
|
1165 it uses the bios to do its job. This pleases DESQview/X. */
|
|
1166 while ((regs.h.ah = extended_kbd ? 0x11 : 0x01),
|
|
1167 int86 (0x16, ®s, ®s),
|
|
1168 (regs.x.flags & 0x40) == 0)
|
|
1169 {
|
|
1170 union REGS regs;
|
|
1171 REGISTER unsigned char c;
|
|
1172 int sc, code, mask, kp_mode;
|
|
1173 int modifiers;
|
|
1174
|
|
1175 regs.h.ah = extended_kbd ? 0x10 : 0x00;
|
|
1176 int86 (0x16, ®s, ®s);
|
|
1177 c = regs.h.al;
|
|
1178 sc = regs.h.ah;
|
|
1179
|
|
1180 total_doskeys += 2;
|
173
|
1181 XVECTOR_DATA (recent_doskeys)[recent_doskeys_index++] = make_int (c);
|
0
|
1182 if (recent_doskeys_index == NUM_RECENT_DOSKEYS)
|
|
1183 recent_doskeys_index = 0;
|
173
|
1184 XVECTOR_DATA (recent_doskeys)[recent_doskeys_index++] = make_int (sc);
|
0
|
1185 if (recent_doskeys_index == NUM_RECENT_DOSKEYS)
|
|
1186 recent_doskeys_index = 0;
|
|
1187
|
|
1188 modifiers = dos_get_modifiers (&mask);
|
173
|
1189
|
0
|
1190 #ifndef HAVE_X_WINDOWS
|
|
1191 if (!NILP (Vdos_display_scancodes))
|
|
1192 {
|
|
1193 char buf[10];
|
|
1194 sprintf (buf, "%02x:%02x*%04x",
|
|
1195 (unsigned) (sc&0xff), (unsigned) c, mask);
|
|
1196 dos_direct_output (screen_size_Y - 2, screen_size_X - 12, buf, 10);
|
|
1197 }
|
|
1198 #endif
|
|
1199
|
|
1200 if (sc == 0xe0)
|
|
1201 {
|
|
1202 switch (c)
|
|
1203 {
|
|
1204 case 10: /* Ctrl Grey Enter */
|
|
1205 code = Ctrl | Grey | 4;
|
|
1206 break;
|
|
1207 case 13: /* Grey Enter */
|
|
1208 code = Grey | 4;
|
|
1209 break;
|
|
1210 case '/': /* Grey / */
|
|
1211 code = Grey | 0;
|
|
1212 break;
|
|
1213 default:
|
|
1214 continue;
|
|
1215 };
|
|
1216 c = 0;
|
|
1217 }
|
|
1218 else
|
|
1219 {
|
|
1220 if (sc >= (sizeof (ibmpc_translate_map) / sizeof (short)))
|
|
1221 continue;
|
|
1222 if ((code = ibmpc_translate_map[sc]) == Ignore)
|
|
1223 continue;
|
|
1224 }
|
173
|
1225
|
0
|
1226 if (c == 0)
|
|
1227 {
|
|
1228 if (code & Alt)
|
|
1229 modifiers |= meta_modifier;
|
|
1230 if (code & Ctrl)
|
|
1231 modifiers |= ctrl_modifier;
|
|
1232 if (code & Shift)
|
|
1233 modifiers |= shift_modifier;
|
|
1234 }
|
173
|
1235
|
0
|
1236 switch (code & 0xf000)
|
|
1237 {
|
|
1238 case ModFct:
|
|
1239 if (c && !(mask & (SHIFT_P | ALT_P | CTRL_P | HYPER_P | SUPER_P)))
|
|
1240 return c;
|
|
1241 c = 0; /* Special */
|
173
|
1242
|
0
|
1243 case FctKey:
|
|
1244 if (c != 0)
|
|
1245 return c;
|
173
|
1246
|
0
|
1247 case Special:
|
|
1248 code |= 0xff00;
|
|
1249 break;
|
173
|
1250
|
0
|
1251 case Normal:
|
|
1252 if (sc == 0)
|
|
1253 {
|
|
1254 if (c == 0) /* ctrl-break */
|
|
1255 continue;
|
|
1256 return c; /* ALT-nnn */
|
|
1257 }
|
|
1258 if (!keyboard_map_all)
|
|
1259 {
|
|
1260 if (c != ' ')
|
|
1261 return c;
|
|
1262 code = c;
|
|
1263 break;
|
|
1264 }
|
173
|
1265
|
0
|
1266 case Map:
|
|
1267 if (c && !(mask & ALT_P) && !((mask & SHIFT_P) && (mask & CTRL_P)))
|
|
1268 if (!keyboard_map_all)
|
|
1269 return c;
|
|
1270
|
|
1271 code &= 0xff;
|
|
1272 if (mask & ALT_P && code <= 10 && code > 0 && dos_keypad_mode & 0x200)
|
|
1273 mask |= SHIFT_P; /* ALT-1 => M-! etc. */
|
173
|
1274
|
0
|
1275 if (mask & SHIFT_P)
|
|
1276 {
|
|
1277 code = keyboard->shifted[code];
|
|
1278 mask -= SHIFT_P;
|
|
1279 modifiers &= ~shift_modifier;
|
|
1280 }
|
|
1281 else
|
|
1282 if ((mask & ALT_GR_P) && keyboard->alt_gr && keyboard->alt_gr[code] != ' ')
|
|
1283 code = keyboard->alt_gr[code];
|
|
1284 else
|
|
1285 code = keyboard->unshifted[code];
|
|
1286 break;
|
|
1287
|
|
1288 case KeyPad:
|
|
1289 code &= 0xff;
|
|
1290 if (c == 0xe0) /* edit key */
|
|
1291 kp_mode = 3;
|
|
1292 else
|
|
1293 if ((mask & (NUMLOCK_P|CTRL_P|SHIFT_P|ALT_P)) == NUMLOCK_P) /* numlock on */
|
|
1294 kp_mode = dos_keypad_mode & 0x03;
|
|
1295 else
|
|
1296 kp_mode = (dos_keypad_mode >> 4) & 0x03;
|
173
|
1297
|
0
|
1298 switch (kp_mode)
|
|
1299 {
|
|
1300 case 0:
|
|
1301 if (code == 10 && dos_decimal_point)
|
|
1302 return dos_decimal_point;
|
|
1303 return keypad_translate_map[code].char_code;
|
|
1304
|
|
1305 case 1:
|
|
1306 code = 0xff00 | keypad_translate_map[code].keypad_code;
|
|
1307 break;
|
|
1308
|
|
1309 case 2:
|
|
1310 code = keypad_translate_map[code].meta_code;
|
|
1311 modifiers = meta_modifier;
|
|
1312 break;
|
173
|
1313
|
0
|
1314 case 3:
|
|
1315 code = 0xff00 | keypad_translate_map[code].editkey_code;
|
|
1316 break;
|
|
1317 }
|
|
1318 break;
|
173
|
1319
|
0
|
1320 case Grey:
|
|
1321 code &= 0xff;
|
|
1322 kp_mode = ((mask & (NUMLOCK_P|CTRL_P|SHIFT_P|ALT_P)) == NUMLOCK_P) ? 0x04 : 0x40;
|
|
1323 if (dos_keypad_mode & kp_mode)
|
|
1324 code = 0xff00 | grey_key_translate_map[code].keypad_code;
|
|
1325 else
|
|
1326 code = grey_key_translate_map[code].char_code;
|
|
1327 break;
|
|
1328 }
|
173
|
1329
|
0
|
1330 make_event:
|
|
1331 if (code == 0)
|
|
1332 continue;
|
173
|
1333
|
0
|
1334 if (code >= 0x100)
|
|
1335 event.kind = non_ascii_keystroke;
|
|
1336 else
|
|
1337 event.kind = ascii_keystroke;
|
|
1338 event.code = code;
|
|
1339 event.modifiers = modifiers;
|
|
1340 XSETFRAME (event.frame_or_window, selected_frame);
|
|
1341 event.timestamp = event_timestamp ();
|
|
1342 kbd_buffer_store_event (&event);
|
|
1343 }
|
|
1344
|
|
1345 if (have_mouse > 0)
|
|
1346 {
|
|
1347 int but, press, x, y, ok;
|
|
1348
|
|
1349 /* Check for mouse movement *before* buttons. */
|
|
1350 mouse_check_moved ();
|
|
1351
|
|
1352 for (but = 0; but < NUM_MOUSE_BUTTONS; but++)
|
|
1353 for (press = 0; press < 2; press++)
|
|
1354 {
|
|
1355 if (press)
|
|
1356 ok = mouse_pressed (but, &x, &y);
|
|
1357 else
|
|
1358 ok = mouse_released (but, &x, &y);
|
|
1359 if (ok)
|
|
1360 {
|
|
1361 event.kind = mouse_click;
|
|
1362 event.code = but;
|
|
1363 event.modifiers = dos_get_modifiers (0)
|
|
1364 | (press ? down_modifier : up_modifier);
|
|
1365 event.x = x;
|
|
1366 event.y = y;
|
|
1367 XSETFRAME (event.frame_or_window, selected_frame);
|
|
1368 event.timestamp = event_timestamp ();
|
|
1369 kbd_buffer_store_event (&event);
|
|
1370 }
|
|
1371 }
|
|
1372 }
|
|
1373
|
|
1374 return -1;
|
|
1375 }
|
|
1376
|
|
1377 static int prev_get_char = -1;
|
|
1378
|
|
1379 /* Return 1 if a key is ready to be read without suspending execution. */
|
|
1380 dos_keysns (void)
|
|
1381 {
|
|
1382 if (prev_get_char != -1)
|
|
1383 return 1;
|
|
1384 else
|
|
1385 return ((prev_get_char = dos_rawgetc ()) != -1);
|
|
1386 }
|
|
1387
|
|
1388 /* Read a key. Return -1 if no key is ready. */
|
|
1389 dos_keyread (void)
|
|
1390 {
|
|
1391 if (prev_get_char != -1)
|
|
1392 {
|
|
1393 int c = prev_get_char;
|
|
1394 prev_get_char = -1;
|
|
1395 return c;
|
|
1396 }
|
|
1397 else
|
|
1398 return dos_rawgetc ();
|
|
1399 }
|
|
1400
|
|
1401 #ifndef HAVE_X_WINDOWS
|
|
1402 /* See xterm.c for more info. */
|
|
1403 void
|
|
1404 pixel_to_glyph_coords (FRAME_PTR f, REGISTER int pix_x, REGISTER int pix_y,
|
|
1405 REGISTER int *x, REGISTER int *y,
|
|
1406 void /* XRectangle */ *bounds,
|
|
1407 int noclip)
|
|
1408 {
|
|
1409 if (bounds) abort ();
|
|
1410
|
|
1411 /* Ignore clipping. */
|
|
1412
|
|
1413 *x = pix_x;
|
|
1414 *y = pix_y;
|
|
1415 }
|
|
1416
|
|
1417 void
|
|
1418 glyph_to_pixel_coords (FRAME_PTR f, REGISTER int x, REGISTER int y,
|
|
1419 REGISTER int *pix_x, REGISTER int *pix_y)
|
|
1420 {
|
|
1421 *pix_x = x;
|
|
1422 *pix_y = y;
|
|
1423 }
|
|
1424
|
|
1425 /* Simulation of X's menus. Nothing too fancy here -- just make it work
|
|
1426 for now.
|
|
1427
|
|
1428 Actually, I don't know the meaning of all the parameters of the functions
|
|
1429 here -- I only know how they are called by xmenu.c. I could of course
|
|
1430 grab the nearest Xlib manual (down the hall, second-to-last door on the
|
|
1431 left), but I don't think it's worth the effort. */
|
|
1432
|
|
1433 static XMenu *
|
|
1434 IT_menu_create (void)
|
|
1435 {
|
|
1436 XMenu *menu;
|
|
1437
|
|
1438 menu = (XMenu *) xmalloc (sizeof (XMenu));
|
|
1439 menu->allocated = menu->count = menu->panecount = menu->width = 0;
|
|
1440 return menu;
|
|
1441 }
|
|
1442
|
|
1443 /* Allocate some (more) memory for MENU ensuring that there is room for one
|
|
1444 for item. */
|
|
1445
|
|
1446 static void
|
|
1447 IT_menu_make_room (XMenu *menu)
|
|
1448 {
|
|
1449 if (menu->allocated == 0)
|
|
1450 {
|
|
1451 int count = menu->allocated = 10;
|
|
1452 menu->text = (char **) xmalloc (count * sizeof (char *));
|
|
1453 menu->submenu = (XMenu **) xmalloc (count * sizeof (XMenu *));
|
|
1454 menu->panenumber = (int *) xmalloc (count * sizeof (int));
|
|
1455 }
|
|
1456 else if (menu->allocated == menu->count)
|
|
1457 {
|
|
1458 int count = menu->allocated = menu->allocated + 10;
|
|
1459 menu->text
|
|
1460 = (char **) xrealloc (menu->text, count * sizeof (char *));
|
|
1461 menu->submenu
|
|
1462 = (XMenu **) xrealloc (menu->submenu, count * sizeof (XMenu *));
|
|
1463 menu->panenumber
|
|
1464 = (int *) xrealloc (menu->panenumber, count * sizeof (int));
|
|
1465 }
|
|
1466 }
|
|
1467
|
|
1468 /* Search the given menu structure for a given pane number. */
|
|
1469
|
|
1470 static XMenu *
|
|
1471 IT_menu_search_pane (XMenu *menu, int pane)
|
|
1472 {
|
|
1473 int i;
|
|
1474 XMenu *try;
|
|
1475
|
|
1476 for (i = 0; i < menu->count; i++)
|
|
1477 if (menu->submenu[i])
|
|
1478 {
|
|
1479 if (pane == menu->panenumber[i])
|
|
1480 return menu->submenu[i];
|
|
1481 if ((try = IT_menu_search_pane (menu->submenu[i], pane)))
|
|
1482 return try;
|
|
1483 }
|
|
1484 return (XMenu *) 0;
|
|
1485 }
|
|
1486
|
|
1487 /* Determine how much screen space a given menu needs. */
|
|
1488
|
|
1489 static void
|
|
1490 IT_menu_calc_size (XMenu *menu, int *width, int *height)
|
|
1491 {
|
|
1492 int i, h2, w2, maxsubwidth, maxheight;
|
|
1493
|
|
1494 maxsubwidth = 0;
|
|
1495 maxheight = menu->count;
|
|
1496 for (i = 0; i < menu->count; i++)
|
|
1497 {
|
|
1498 if (menu->submenu[i])
|
|
1499 {
|
|
1500 IT_menu_calc_size (menu->submenu[i], &w2, &h2);
|
|
1501 if (w2 > maxsubwidth) maxsubwidth = w2;
|
|
1502 if (i + h2 > maxheight) maxheight = i + h2;
|
|
1503 }
|
|
1504 }
|
|
1505 *width = menu->width + maxsubwidth;
|
|
1506 *height = maxheight;
|
|
1507 }
|
|
1508
|
|
1509 /* Display MENU at (X,Y) using FACES. */
|
|
1510
|
|
1511 static void
|
|
1512 IT_menu_display (XMenu *menu, int y, int x, int *faces)
|
|
1513 {
|
|
1514 int i, j, face, width;
|
|
1515 GLYPH *text, *p;
|
|
1516 char *q;
|
|
1517 int mx, my;
|
|
1518 int enabled, mousehere;
|
|
1519 int row, col;
|
|
1520
|
|
1521 width = menu->width;
|
|
1522 text = (GLYPH *) xmalloc ((width + 2) * sizeof (GLYPH));
|
|
1523 ScreenGetCursor (&row, &col);
|
|
1524 mouse_get_xy (&mx, &my);
|
|
1525 IT_update_begin ();
|
|
1526 for (i = 0; i < menu->count; i++)
|
|
1527 {
|
|
1528 IT_cursor_to (y + i, x);
|
|
1529 enabled
|
|
1530 = (!menu->submenu[i] && menu->panenumber[i]) || (menu->submenu[i]);
|
|
1531 mousehere = (y + i == my && x <= mx && mx < x + width + 2);
|
|
1532 face = faces[enabled + mousehere * 2];
|
|
1533 p = text;
|
|
1534 *p++ = FAST_MAKE_GLYPH (' ', face);
|
|
1535 for (j = 0, q = menu->text[i]; *q; j++)
|
|
1536 *p++ = FAST_MAKE_GLYPH (*q++, face);
|
|
1537 for (; j < width; j++)
|
|
1538 *p++ = FAST_MAKE_GLYPH (' ', face);
|
|
1539 *p++ = FAST_MAKE_GLYPH (menu->submenu[i] ? 16 : ' ', face);
|
|
1540 IT_write_glyphs (text, width + 2);
|
|
1541 }
|
|
1542 IT_update_end ();
|
|
1543 IT_cursor_to (row, col);
|
|
1544 xfree (text);
|
|
1545 }
|
|
1546
|
|
1547 /* --------------------------- X Menu emulation ---------------------- */
|
|
1548
|
|
1549 /* Create a brand new menu structure. */
|
|
1550
|
|
1551 XMenu *
|
|
1552 XMenuCreate (Display *foo1, Window foo2, char *foo3)
|
|
1553 {
|
|
1554 return IT_menu_create ();
|
|
1555 }
|
|
1556
|
|
1557 /* Create a new pane and place it on the outer-most level. It is not
|
|
1558 clear that it should be placed out there, but I don't know what else
|
|
1559 to do. */
|
|
1560
|
|
1561 int
|
|
1562 XMenuAddPane (Display *foo, XMenu *menu, char *txt, int enable)
|
|
1563 {
|
|
1564 int len;
|
|
1565
|
|
1566 if (!enable)
|
|
1567 abort ();
|
|
1568
|
|
1569 IT_menu_make_room (menu);
|
|
1570 menu->submenu[menu->count] = IT_menu_create ();
|
|
1571 menu->text[menu->count] = txt;
|
|
1572 menu->panenumber[menu->count] = ++menu->panecount;
|
|
1573 menu->count++;
|
|
1574 if ((len = strlen (txt)) > menu->width)
|
|
1575 menu->width = len;
|
|
1576 return menu->panecount;
|
|
1577 }
|
|
1578
|
|
1579 /* Create a new item in a menu pane. */
|
|
1580
|
|
1581 int
|
|
1582 XMenuAddSelection (Display *bar, XMenu *menu, int pane,
|
|
1583 int foo, char *txt, int enable)
|
|
1584 {
|
|
1585 int len;
|
|
1586
|
|
1587 if (pane)
|
|
1588 if (!(menu = IT_menu_search_pane (menu, pane)))
|
|
1589 return XM_FAILURE;
|
|
1590 IT_menu_make_room (menu);
|
|
1591 menu->submenu[menu->count] = (XMenu *) 0;
|
|
1592 menu->text[menu->count] = txt;
|
|
1593 menu->panenumber[menu->count] = enable;
|
|
1594 menu->count++;
|
|
1595 if ((len = strlen (txt)) > menu->width)
|
|
1596 menu->width = len;
|
|
1597 return XM_SUCCESS;
|
|
1598 }
|
|
1599
|
|
1600 /* Decide where the menu would be placed if requested at (X,Y). */
|
|
1601
|
|
1602 void
|
|
1603 XMenuLocate (Display *foo0, XMenu *menu, int foo1, int foo2, int x, int y,
|
|
1604 int *ulx, int *uly, int *width, int *height)
|
|
1605 {
|
|
1606 if (menu->count == 1 && menu->submenu[0])
|
|
1607 /* Special case: the menu consists of only one pane. */
|
|
1608 IT_menu_calc_size (menu->submenu[0], width, height);
|
|
1609 else
|
|
1610 IT_menu_calc_size (menu, width, height);
|
|
1611 *ulx = x + 1;
|
|
1612 *uly = y;
|
|
1613 *width += 2;
|
|
1614 }
|
|
1615
|
|
1616 struct IT_menu_state
|
|
1617 {
|
|
1618 void *screen_behind;
|
|
1619 XMenu *menu;
|
|
1620 int pane;
|
|
1621 int x, y;
|
|
1622 };
|
|
1623
|
|
1624
|
|
1625 /* Display menu, wait for user's response, and return that response. */
|
|
1626
|
|
1627 int
|
|
1628 XMenuActivate (Display *foo, XMenu *menu, int *pane, int *selidx,
|
|
1629 int x0, int y0, unsigned ButtonMask, char **txt)
|
|
1630 {
|
|
1631 struct IT_menu_state *state;
|
|
1632 int statecount;
|
|
1633 int x, y, i, b;
|
|
1634 int screensize;
|
|
1635 int faces[4], selectface;
|
|
1636 int leave, result, onepane;
|
|
1637
|
|
1638 /* Just in case we got here without a mouse present... */
|
|
1639 if (have_mouse <= 0)
|
|
1640 return XM_IA_SELECT;
|
|
1641
|
185
|
1642 state = alloca_array (struct IT_menu_state, menu->panecount);
|
0
|
1643 screensize = screen_size * 2;
|
|
1644 faces[0]
|
|
1645 = compute_glyph_face (&the_only_frame,
|
|
1646 face_name_id_number
|
|
1647 (&the_only_frame,
|
|
1648 intern ("msdos-menu-passive-face")),
|
|
1649 0);
|
|
1650 faces[1]
|
|
1651 = compute_glyph_face (&the_only_frame,
|
|
1652 face_name_id_number
|
|
1653 (&the_only_frame,
|
|
1654 intern ("msdos-menu-active-face")),
|
|
1655 0);
|
|
1656 selectface
|
|
1657 = face_name_id_number (&the_only_frame, intern ("msdos-menu-select-face"));
|
|
1658 faces[2] = compute_glyph_face (&the_only_frame, selectface, faces[0]);
|
|
1659 faces[3] = compute_glyph_face (&the_only_frame, selectface, faces[1]);
|
|
1660
|
|
1661 statecount = 1;
|
|
1662 state[0].menu = menu;
|
|
1663 mouse_off ();
|
|
1664 ScreenRetrieve (state[0].screen_behind = xmalloc (screensize));
|
|
1665 if ((onepane = menu->count == 1 && menu->submenu[0]))
|
|
1666 {
|
|
1667 menu->width = menu->submenu[0]->width;
|
|
1668 state[0].menu = menu->submenu[0];
|
|
1669 }
|
|
1670 else
|
|
1671 {
|
|
1672 state[0].menu = menu;
|
|
1673 }
|
|
1674 state[0].x = x0 - 1;
|
|
1675 state[0].y = y0;
|
|
1676 state[0].pane = onepane;
|
|
1677
|
|
1678 mouse_last_x = -1; /* A hack that forces display. */
|
|
1679 leave = 0;
|
|
1680 while (!leave)
|
|
1681 {
|
|
1682 if (!mouse_visible) mouse_on ();
|
|
1683 mouse_check_moved ();
|
|
1684 if (selected_frame->mouse_moved)
|
|
1685 {
|
|
1686 selected_frame->mouse_moved = 0;
|
|
1687 result = XM_IA_SELECT;
|
|
1688 mouse_get_xy (&x, &y);
|
|
1689 for (i = 0; i < statecount; i++)
|
|
1690 if (state[i].x <= x && x < state[i].x + state[i].menu->width + 2)
|
|
1691 {
|
|
1692 int dy = y - state[i].y;
|
|
1693 if (0 <= dy && dy < state[i].menu->count)
|
|
1694 {
|
|
1695 if (!state[i].menu->submenu[dy])
|
|
1696 if (state[i].menu->panenumber[dy])
|
|
1697 result = XM_SUCCESS;
|
|
1698 else
|
|
1699 result = XM_IA_SELECT;
|
|
1700 *pane = state[i].pane - 1;
|
|
1701 *selidx = dy;
|
|
1702 /* We hit some part of a menu, so drop extra menues that
|
|
1703 have been opened. That does not include an open and
|
|
1704 active submenu. */
|
|
1705 if (i != statecount - 2
|
|
1706 || state[i].menu->submenu[dy] != state[i+1].menu)
|
|
1707 while (i != statecount - 1)
|
|
1708 {
|
|
1709 statecount--;
|
|
1710 mouse_off ();
|
|
1711 ScreenUpdate (state[statecount].screen_behind);
|
|
1712 xfree (state[statecount].screen_behind);
|
|
1713 }
|
|
1714 if (i == statecount - 1 && state[i].menu->submenu[dy])
|
|
1715 {
|
|
1716 IT_menu_display (state[i].menu,
|
|
1717 state[i].y,
|
|
1718 state[i].x,
|
|
1719 faces);
|
|
1720 state[statecount].menu = state[i].menu->submenu[dy];
|
|
1721 state[statecount].pane = state[i].menu->panenumber[dy];
|
|
1722 mouse_off ();
|
|
1723 ScreenRetrieve (state[statecount].screen_behind
|
|
1724 = xmalloc (screensize));
|
|
1725 state[statecount].x
|
|
1726 = state[i].x + state[i].menu->width + 2;
|
|
1727 state[statecount].y = y;
|
173
|
1728 statecount++;
|
0
|
1729 }
|
|
1730 }
|
|
1731 }
|
|
1732 IT_menu_display (state[statecount - 1].menu,
|
|
1733 state[statecount - 1].y,
|
|
1734 state[statecount - 1].x,
|
|
1735 faces);
|
|
1736 }
|
|
1737 for (b = 0; b < mouse_button_count; b++)
|
|
1738 {
|
|
1739 (void) mouse_pressed (b, &x, &y);
|
|
1740 if (mouse_released (b, &x, &y))
|
|
1741 leave = 1;
|
|
1742 }
|
|
1743 }
|
|
1744
|
|
1745 mouse_off ();
|
|
1746 ScreenUpdate (state[0].screen_behind);
|
|
1747 while (statecount--)
|
|
1748 xfree (state[statecount].screen_behind);
|
|
1749 return result;
|
|
1750 }
|
|
1751
|
|
1752 /* Dispose of a menu. */
|
|
1753
|
|
1754 void
|
|
1755 XMenuDestroy (Display *foo, XMenu *menu)
|
|
1756 {
|
|
1757 int i;
|
|
1758 if (menu->allocated)
|
|
1759 {
|
|
1760 for (i = 0; i < menu->count; i++)
|
|
1761 if (menu->submenu[i])
|
|
1762 XMenuDestroy (foo, menu->submenu[i]);
|
|
1763 xfree (menu->text);
|
|
1764 xfree (menu->submenu);
|
|
1765 xfree (menu->panenumber);
|
|
1766 }
|
|
1767 xfree (menu);
|
|
1768 }
|
|
1769
|
|
1770 int
|
|
1771 x_pixel_width (struct frame *f)
|
|
1772 {
|
|
1773 return FRAME_WIDTH (f);
|
|
1774 }
|
|
1775
|
|
1776 int
|
|
1777 x_pixel_height (struct frame *f)
|
|
1778 {
|
|
1779 return FRAME_HEIGHT (f);
|
|
1780 }
|
|
1781 #endif /* !HAVE_X_WINDOWS */
|
|
1782
|
|
1783
|
|
1784 /* ----------------------- DOS / UNIX conversion --------------------- */
|
|
1785
|
|
1786 /* Destructively turn backslashes into slashes. */
|
|
1787
|
|
1788 void
|
|
1789 dostounix_filename (REGISTER char *p)
|
|
1790 {
|
|
1791 while (*p)
|
|
1792 {
|
|
1793 if (*p == '\\')
|
|
1794 *p = '/';
|
|
1795 p++;
|
|
1796 }
|
|
1797 }
|
|
1798
|
|
1799 /* Destructively turn slashes into backslashes. */
|
|
1800
|
|
1801 void
|
|
1802 unixtodos_filename (REGISTER char *p)
|
|
1803 {
|
|
1804 while (*p)
|
|
1805 {
|
|
1806 if (*p == '/')
|
|
1807 *p = '\\';
|
|
1808 p++;
|
|
1809 }
|
|
1810 }
|
|
1811
|
|
1812 /* Get the default directory for a given drive. 0=def, 1=A, 2=B, ... */
|
|
1813
|
|
1814 int
|
|
1815 getdefdir (int drive, char *dst)
|
|
1816 {
|
|
1817 union REGS regs;
|
|
1818
|
|
1819 *dst++ = '/';
|
|
1820 regs.h.dl = drive;
|
|
1821 regs.x.si = (int) dst;
|
|
1822 regs.h.ah = 0x47;
|
|
1823 intdos (®s, ®s);
|
|
1824 return !regs.x.cflag;
|
|
1825 }
|
|
1826
|
|
1827 /* Remove all CR's that are followed by a LF. */
|
|
1828
|
|
1829 int
|
|
1830 crlf_to_lf (REGISTER int n, REGISTER unsigned char *buf)
|
|
1831 {
|
|
1832 unsigned char *np = buf;
|
|
1833 unsigned char *startp = buf;
|
|
1834 unsigned char *endp = buf + n;
|
|
1835 unsigned char c;
|
|
1836
|
|
1837 if (n == 0)
|
|
1838 return n;
|
|
1839 while (buf < endp - 1)
|
|
1840 {
|
|
1841 if (*buf == 0x0d)
|
|
1842 {
|
|
1843 if (*(++buf) != 0x0a)
|
|
1844 *np++ = 0x0d;
|
|
1845 }
|
|
1846 else
|
|
1847 *np++ = *buf++;
|
|
1848 }
|
|
1849 if (buf < endp)
|
|
1850 *np++ = *buf++;
|
|
1851 return np - startp;
|
|
1852 }
|
|
1853
|
|
1854 /* The Emacs root directory as determined by init_environment. */
|
|
1855
|
|
1856 static char emacsroot[MAXPATHLEN];
|
|
1857
|
|
1858 char *
|
|
1859 rootrelativepath (char *rel)
|
|
1860 {
|
|
1861 static char result[MAXPATHLEN + 10];
|
|
1862
|
|
1863 strcpy (result, emacsroot);
|
|
1864 strcat (result, "/");
|
|
1865 strcat (result, rel);
|
|
1866 return result;
|
|
1867 }
|
|
1868
|
|
1869 /* Define a lot of environment variables if not already defined. Don't
|
|
1870 remove anything unless you know what you're doing -- lots of code will
|
|
1871 break if one or more of these are missing. */
|
|
1872
|
|
1873 void
|
|
1874 init_environment (int argc, char **argv, int skip_args)
|
|
1875 {
|
|
1876 char *s, *t, *root;
|
|
1877 int len;
|
|
1878
|
|
1879 if (!initialized)
|
|
1880 return;
|
|
1881
|
|
1882 /* Find our root from argv[0]. Assuming argv[0] is, say,
|
|
1883 "c:/emacs/bin/emacs.exe" our root will be "c:/emacs". */
|
|
1884 root = alloca (MAXPATHLEN + 20);
|
|
1885 _fixpath (argv[0], root);
|
|
1886 strlwr (root);
|
|
1887 len = strlen (root);
|
|
1888 while (len > 0 && root[len] != '/' && root[len] != ':')
|
|
1889 len--;
|
|
1890 root[len] = '\0';
|
|
1891 if (len > 4 && strcmp (root + len - 4, "/bin") == 0)
|
|
1892 root[len - 4] = '\0';
|
|
1893 else
|
|
1894 strcpy (root, "c:/emacs"); /* Only under debuggers, I think. */
|
|
1895 len = strlen (root);
|
|
1896 strcpy (emacsroot, root);
|
|
1897
|
|
1898 /* We default HOME to our root. */
|
|
1899 setenv ("HOME", root, 0);
|
|
1900
|
|
1901 /* We default EMACSPATH to root + "/bin". */
|
|
1902 strcpy (root + len, "/bin");
|
|
1903 setenv ("EMACSPATH", root, 0);
|
|
1904
|
|
1905 /* I don't expect anybody to ever use other terminals so the internal
|
|
1906 terminal is the default. */
|
|
1907 setenv ("TERM", "internal", 0);
|
|
1908
|
|
1909 #ifdef HAVE_X_WINDOWS
|
|
1910 /* Emacs expects DISPLAY to be set. */
|
|
1911 setenv ("DISPLAY", "unix:0.0", 0);
|
|
1912 #endif
|
|
1913
|
|
1914 /* SHELL is a bit tricky -- COMSPEC is the closest we come, but we must
|
|
1915 downcase it and mirror the backslashes. */
|
|
1916 s = getenv ("COMSPEC");
|
|
1917 if (!s) s = "c:/command.com";
|
|
1918 t = alloca (strlen (s) + 1);
|
|
1919 strcpy (t, s);
|
|
1920 strlwr (t);
|
|
1921 dostounix_filename (t);
|
|
1922 setenv ("SHELL", t, 0);
|
|
1923
|
|
1924 /* PATH is also downcased and backslashes mirrored. */
|
|
1925 s = getenv ("PATH");
|
|
1926 if (!s) s = "";
|
|
1927 t = alloca (strlen (s) + 3);
|
|
1928 /* Current directory is always considered part of MsDos's path but it is
|
|
1929 not normally mentioned. Now it is. */
|
|
1930 strcat (strcpy (t, ".;"), s);
|
|
1931 strlwr (t);
|
|
1932 dostounix_filename (t); /* Not a single file name, but this should work. */
|
|
1933 setenv ("PATH", t, 1);
|
|
1934
|
|
1935 /* In some sense all dos users have root privileges, so... */
|
|
1936 setenv ("USER", "root", 0);
|
|
1937 setenv ("NAME", getenv ("USER"), 0);
|
|
1938
|
|
1939 /* Time zone determined from country code. To make this possible, the
|
|
1940 country code may not span more than one time zone. In other words,
|
|
1941 in the USA, you lose. */
|
|
1942 if (!getenv ("TZ"))
|
|
1943 switch (dos_country_code)
|
|
1944 {
|
|
1945 case 31: /* Belgium */
|
|
1946 case 32: /* The Netherlands */
|
|
1947 case 33: /* France */
|
|
1948 case 34: /* Spain */
|
|
1949 case 36: /* Hungary */
|
|
1950 case 38: /* Yugoslavia (or what's left of it?) */
|
|
1951 case 39: /* Italy */
|
|
1952 case 41: /* Switzerland */
|
|
1953 case 42: /* Tjekia */
|
|
1954 case 45: /* Denmark */
|
|
1955 case 46: /* Sweden */
|
|
1956 case 47: /* Norway */
|
|
1957 case 48: /* Poland */
|
|
1958 case 49: /* Germany */
|
|
1959 /* Daylight saving from last Sunday in March to last Sunday in
|
|
1960 September, both at 2AM. */
|
|
1961 setenv ("TZ", "MET-01METDST-02,M3.5.0/02:00,M9.5.0/02:00", 0);
|
|
1962 break;
|
|
1963 case 44: /* United Kingdom */
|
|
1964 case 351: /* Portugal */
|
|
1965 case 354: /* Iceland */
|
|
1966 setenv ("TZ", "GMT+00", 0);
|
|
1967 break;
|
|
1968 case 81: /* Japan */
|
|
1969 case 82: /* Korea */
|
|
1970 setenv ("TZ", "JST-09", 0);
|
|
1971 break;
|
|
1972 case 90: /* Turkey */
|
|
1973 case 358: /* Finland */
|
|
1974 setenv ("TZ", "EET-02", 0);
|
|
1975 break;
|
|
1976 case 972: /* Israel */
|
|
1977 /* This is an approximation. (For exact rules, use the
|
|
1978 `zoneinfo/israel' file which comes with DJGPP, but you need
|
|
1979 to install it in `/usr/share/zoneinfo/' directory first.) */
|
|
1980 setenv ("TZ", "IST-02IDT-03,M4.1.6/00:00,M9.5.6/01:00", 0);
|
|
1981 break;
|
|
1982 }
|
|
1983 init_gettimeofday ();
|
|
1984 }
|
|
1985
|
|
1986
|
|
1987
|
|
1988 static int break_stat; /* BREAK check mode status. */
|
|
1989 static int stdin_stat; /* stdin IOCTL status. */
|
|
1990
|
|
1991 /* These must be global. */
|
|
1992 static _go32_dpmi_seginfo ctrl_break_vector;
|
|
1993 static _go32_dpmi_registers ctrl_break_regs;
|
|
1994 static int ctrlbreakinstalled = 0;
|
|
1995
|
|
1996 /* Interrupt level detection of Ctrl-Break. Don't do anything fancy here! */
|
|
1997
|
|
1998 void
|
|
1999 ctrl_break_func (_go32_dpmi_registers *regs)
|
|
2000 {
|
|
2001 Vquit_flag = Qt;
|
|
2002 }
|
|
2003
|
|
2004 void
|
|
2005 install_ctrl_break_check (void)
|
|
2006 {
|
|
2007 if (!ctrlbreakinstalled)
|
|
2008 {
|
|
2009 /* Don't press Ctrl-Break if you don't have either DPMI or Emacs
|
|
2010 was compiler with Djgpp 1.11 maintenance level 5 or later! */
|
|
2011 ctrlbreakinstalled = 1;
|
|
2012 ctrl_break_vector.pm_offset = (int) ctrl_break_func;
|
|
2013 _go32_dpmi_allocate_real_mode_callback_iret (&ctrl_break_vector,
|
|
2014 &ctrl_break_regs);
|
|
2015 _go32_dpmi_set_real_mode_interrupt_vector (0x1b, &ctrl_break_vector);
|
|
2016 }
|
|
2017 }
|
|
2018
|
|
2019 /*
|
|
2020 * Turn off Dos' Ctrl-C checking and inhibit interpretation of
|
|
2021 * control chars by Dos.
|
|
2022 * Determine the keyboard type.
|
|
2023 */
|
|
2024
|
|
2025 int
|
|
2026 dos_ttraw (void)
|
|
2027 {
|
|
2028 union REGS inregs, outregs;
|
|
2029 static int first_time = 1;
|
173
|
2030
|
0
|
2031 break_stat = getcbrk ();
|
|
2032 setcbrk (0);
|
|
2033 install_ctrl_break_check ();
|
|
2034
|
|
2035 if (first_time)
|
|
2036 {
|
|
2037 inregs.h.ah = 0xc0;
|
|
2038 int86 (0x15, &inregs, &outregs);
|
|
2039 extended_kbd = (!outregs.x.cflag) && (outregs.h.ah == 0);
|
173
|
2040
|
0
|
2041 have_mouse = 0;
|
|
2042
|
|
2043 if (internal_terminal
|
|
2044 #ifdef HAVE_X_WINDOWS
|
|
2045 && inhibit_window_system
|
|
2046 #endif
|
|
2047 )
|
|
2048 {
|
|
2049 inregs.x.ax = 0x0021;
|
|
2050 int86 (0x33, &inregs, &outregs);
|
|
2051 have_mouse = (outregs.x.ax & 0xffff) == 0xffff;
|
|
2052 if (!have_mouse)
|
|
2053 {
|
|
2054 /* Reportedly, the above doesn't work for some mouse drivers. There
|
|
2055 is an additional detection method that should work, but might be
|
|
2056 a little slower. Use that as an alternative. */
|
|
2057 inregs.x.ax = 0x0000;
|
|
2058 int86 (0x33, &inregs, &outregs);
|
|
2059 have_mouse = (outregs.x.ax & 0xffff) == 0xffff;
|
|
2060 }
|
|
2061
|
|
2062 if (have_mouse)
|
|
2063 {
|
|
2064 have_mouse = 1; /* enable mouse */
|
|
2065 mouse_visible = 0;
|
173
|
2066
|
0
|
2067 if (outregs.x.bx == 3)
|
|
2068 {
|
|
2069 mouse_button_count = 3;
|
|
2070 mouse_button_translate[0] = 0; /* Left */
|
|
2071 mouse_button_translate[1] = 2; /* Middle */
|
|
2072 mouse_button_translate[2] = 1; /* Right */
|
|
2073 }
|
|
2074 else
|
|
2075 {
|
|
2076 mouse_button_count = 2;
|
|
2077 mouse_button_translate[0] = 0;
|
|
2078 mouse_button_translate[1] = 1;
|
|
2079 }
|
|
2080 mouse_position_hook = &mouse_get_pos;
|
|
2081 mouse_init ();
|
|
2082 }
|
|
2083 }
|
173
|
2084
|
0
|
2085 first_time = 0;
|
|
2086 }
|
|
2087
|
|
2088 inregs.x.ax = 0x4400; /* Get IOCTL status. */
|
|
2089 inregs.x.bx = 0x00; /* 0 = stdin. */
|
|
2090 intdos (&inregs, &outregs);
|
|
2091 stdin_stat = outregs.h.dl;
|
|
2092
|
|
2093 inregs.x.dx = stdin_stat | 0x0020; /* raw mode */
|
|
2094 inregs.x.ax = 0x4401; /* Set IOCTL status */
|
|
2095 intdos (&inregs, &outregs);
|
|
2096 return !outregs.x.cflag;
|
|
2097 }
|
|
2098
|
|
2099 /* Restore status of standard input and Ctrl-C checking. */
|
|
2100 int
|
|
2101 dos_ttcooked (void)
|
|
2102 {
|
|
2103 union REGS inregs, outregs;
|
|
2104
|
|
2105 setcbrk (break_stat);
|
|
2106 mouse_off ();
|
|
2107
|
|
2108 inregs.x.ax = 0x4401; /* Set IOCTL status. */
|
|
2109 inregs.x.bx = 0x00; /* 0 = stdin. */
|
|
2110 inregs.x.dx = stdin_stat;
|
|
2111 intdos (&inregs, &outregs);
|
|
2112 return !outregs.x.cflag;
|
|
2113 }
|
|
2114
|
|
2115
|
|
2116 /* Run command as specified by ARGV in directory DIR.
|
|
2117 The command is run with input from TEMPIN and output to file TEMPOUT. */
|
|
2118 int
|
|
2119 run_msdos_command (unsigned char **argv, Lisp_Object dir,
|
|
2120 int tempin, int tempout)
|
|
2121 {
|
|
2122 char *saveargv1, *saveargv2, **envv;
|
|
2123 char oldwd[MAXPATHLEN + 1]; /* Fixed size is safe on MSDOS. */
|
|
2124 int msshell, result = -1;
|
|
2125 int in, out, inbak, outbak, errbak;
|
|
2126 int x, y;
|
|
2127 Lisp_Object cmd;
|
|
2128
|
|
2129 /* Get current directory as MSDOS cwd is not per-process. */
|
|
2130 getwd (oldwd);
|
|
2131
|
|
2132 cmd = Ffile_name_nondirectory (build_string (argv[0]));
|
|
2133 msshell = !NILP (Fmember (cmd, Fsymbol_value (intern ("msdos-shells"))))
|
|
2134 && !strcmp ("-c", argv[1]);
|
|
2135 if (msshell)
|
|
2136 {
|
|
2137 saveargv1 = argv[1];
|
|
2138 saveargv2 = argv[2];
|
|
2139 argv[1] = "/c";
|
|
2140 if (argv[2])
|
|
2141 {
|
|
2142 char *p = alloca (strlen (argv[2]) + 1);
|
|
2143
|
|
2144 strcpy (argv[2] = p, saveargv2);
|
|
2145 while (*p && isspace ((unsigned char) *p))
|
|
2146 p++;
|
|
2147 while (*p && !isspace ((unsigned char) *p))
|
|
2148 if (*p == '/')
|
|
2149 *p++ = '\\';
|
|
2150 else
|
|
2151 p++;
|
|
2152 }
|
|
2153 }
|
|
2154
|
|
2155 /* Build the environment array. */
|
|
2156 {
|
|
2157 extern Lisp_Object Vprocess_environment;
|
|
2158 Lisp_Object tmp, lst;
|
|
2159 int i, len;
|
|
2160
|
|
2161 lst = Vprocess_environment;
|
|
2162 len = XINT (Flength (lst));
|
|
2163
|
185
|
2164 envv = alloca_array (char *, len + 1);
|
0
|
2165 for (i = 0; i < len; i++)
|
|
2166 {
|
|
2167 tmp = Fcar (lst);
|
|
2168 lst = Fcdr (lst);
|
|
2169 CHECK_STRING (tmp);
|
16
|
2170 envv[i] = alloca (XSTRING_LENGTH (tmp) + 1);
|
|
2171 strcpy (envv[i], XSTRING_DATA (tmp));
|
0
|
2172 }
|
|
2173 envv[len] = (char *) 0;
|
|
2174 }
|
|
2175
|
|
2176 if (STRINGP (dir))
|
16
|
2177 chdir (XSTRING_DATA (dir));
|
0
|
2178 inbak = dup (0);
|
|
2179 outbak = dup (1);
|
|
2180 errbak = dup (2);
|
|
2181 if (inbak < 0 || outbak < 0 || errbak < 0)
|
|
2182 goto done; /* Allocation might fail due to lack of descriptors. */
|
|
2183
|
|
2184 if (have_mouse > 0)
|
|
2185 mouse_get_xy (&x, &y);
|
|
2186
|
|
2187 dos_ttcooked (); /* do it here while 0 = stdin */
|
173
|
2188
|
0
|
2189 dup2 (tempin, 0);
|
|
2190 dup2 (tempout, 1);
|
|
2191 dup2 (tempout, 2);
|
|
2192
|
|
2193 result = spawnve (P_WAIT, argv[0], argv, envv);
|
173
|
2194
|
0
|
2195 dup2 (inbak, 0);
|
|
2196 dup2 (outbak, 1);
|
|
2197 dup2 (errbak, 2);
|
|
2198 close (inbak);
|
|
2199 close (outbak);
|
|
2200 close (errbak);
|
|
2201
|
|
2202 dos_ttraw ();
|
|
2203 if (have_mouse > 0)
|
|
2204 {
|
|
2205 mouse_init ();
|
|
2206 mouse_moveto (x, y);
|
|
2207 }
|
173
|
2208
|
0
|
2209 done:
|
|
2210 chdir (oldwd);
|
|
2211 if (msshell)
|
|
2212 {
|
|
2213 argv[1] = saveargv1;
|
|
2214 argv[2] = saveargv2;
|
|
2215 }
|
|
2216 return result;
|
|
2217 }
|
|
2218
|
|
2219 croak (char *badfunc)
|
|
2220 {
|
|
2221 stderr_out ("%s not yet implemented\r\n", badfunc);
|
|
2222 reset_sys_modes ();
|
|
2223 exit (1);
|
|
2224 }
|
|
2225
|
|
2226
|
|
2227 /* ------------------------- Compatibility functions -------------------
|
|
2228 * gethostname
|
|
2229 * gettimeofday
|
|
2230 */
|
|
2231
|
|
2232 /*
|
|
2233 * Hostnames for a pc are not really funny,
|
|
2234 * but they are used in change log so we emulate the best we can.
|
|
2235 */
|
|
2236
|
|
2237 gethostname (char *p, int size)
|
|
2238 {
|
|
2239 char *q = egetenv ("HOSTNAME");
|
|
2240
|
|
2241 if (!q) q = "pc";
|
|
2242 strcpy (p, q);
|
|
2243 return 0;
|
|
2244 }
|
|
2245
|
|
2246 /* When time zones are set from Ms-Dos too many C-libraries are playing
|
|
2247 tricks with time values. We solve this by defining our own version
|
|
2248 of `gettimeofday' bypassing GO32. Our version needs to be initialized
|
173
|
2249 once and after each call to `tzset' with TZ changed. That is
|
0
|
2250 accomplished by aliasing tzset to init_gettimeofday. */
|
|
2251
|
|
2252 static struct tm time_rec;
|
|
2253
|
|
2254 int
|
|
2255 gettimeofday (struct timeval *tp, struct timezone *tzp)
|
|
2256 {
|
|
2257 if (tp)
|
|
2258 {
|
|
2259 struct time t;
|
|
2260 struct tm tm;
|
173
|
2261
|
0
|
2262 gettime (&t);
|
|
2263 if (t.ti_hour < time_rec.tm_hour) /* midnight wrap */
|
|
2264 {
|
|
2265 struct date d;
|
|
2266 getdate (&d);
|
|
2267 time_rec.tm_year = d.da_year - 1900;
|
|
2268 time_rec.tm_mon = d.da_mon - 1;
|
|
2269 time_rec.tm_mday = d.da_day;
|
|
2270 }
|
173
|
2271
|
0
|
2272 time_rec.tm_hour = t.ti_hour;
|
|
2273 time_rec.tm_min = t.ti_min;
|
|
2274 time_rec.tm_sec = t.ti_sec;
|
|
2275
|
|
2276 tm = time_rec;
|
|
2277 tm.tm_gmtoff = dos_timezone_offset;
|
173
|
2278
|
0
|
2279 tp->tv_sec = mktime (&tm); /* may modify tm */
|
|
2280 tp->tv_usec = t.ti_hund * (1000000 / 100);
|
|
2281 }
|
|
2282 /* Ignore tzp; it's obsolescent. */
|
|
2283 return 0;
|
|
2284 }
|
|
2285
|
|
2286
|
|
2287 /*
|
|
2288 * A list of unimplemented functions that we silently ignore.
|
|
2289 */
|
|
2290
|
|
2291 unsigned alarm (unsigned int s) {}
|
|
2292 fork (void) { return 0; }
|
|
2293 int kill (int x, int y) { return -1; }
|
|
2294 nice (int p) {}
|
|
2295 void volatile pause (void) {}
|
|
2296 request_sigio (void) {}
|
|
2297 setpgrp (void) {return 0; }
|
|
2298 setpriority (int x, int y, int z) { return 0; }
|
|
2299 sigsetmask (int x) { return 0; }
|
|
2300 unrequest_sigio (void) {}
|
|
2301
|
|
2302 int run_dos_timer_hooks = 0;
|
|
2303
|
|
2304 #ifndef HAVE_SELECT
|
|
2305 #include "sysselect.h"
|
|
2306
|
|
2307 static int last_ti_sec = -1;
|
|
2308 static int dos_menubar_clock_displayed = 0;
|
|
2309
|
|
2310 static void
|
|
2311 check_timer (struct time *t)
|
|
2312 {
|
|
2313 gettime (t);
|
173
|
2314
|
0
|
2315 if (t->ti_sec == last_ti_sec)
|
|
2316 return;
|
|
2317 last_ti_sec = t->ti_sec;
|
|
2318
|
|
2319 if (!NILP (Vdos_menubar_clock))
|
|
2320 {
|
|
2321 char clock_str[16];
|
|
2322 int len;
|
|
2323 int min = t->ti_min;
|
|
2324 int hour = t->ti_hour;
|
|
2325
|
|
2326 if (dos_timezone_offset)
|
|
2327 {
|
|
2328 int tz = dos_timezone_offset;
|
|
2329 min -= tz % 60;
|
|
2330 if (min < 0)
|
|
2331 min += 60, hour--;
|
|
2332 else
|
|
2333 if (min >= 60)
|
|
2334 min -= 60, hour++;
|
173
|
2335
|
0
|
2336 if ((hour -= (tz / 60)) < 0)
|
|
2337 hour += 24;
|
|
2338 else
|
|
2339 hour %= 24;
|
|
2340 }
|
173
|
2341
|
0
|
2342 if ((dos_country_info[0x11] & 0x01) == 0) /* 12 hour clock */
|
|
2343 {
|
|
2344 hour %= 12;
|
|
2345 if (hour == 0) hour = 12;
|
|
2346 }
|
|
2347
|
|
2348 len = sprintf (clock_str, "%2d.%02d.%02d", hour, min, t->ti_sec);
|
|
2349 dos_direct_output (0, screen_size_X - len - 1, clock_str, len);
|
|
2350 dos_menubar_clock_displayed = 1;
|
|
2351 }
|
|
2352 else if (dos_menubar_clock_displayed)
|
|
2353 {
|
|
2354 /* Erase last displayed time. */
|
|
2355 dos_direct_output (0, screen_size_X - 9, " ", 8);
|
|
2356 dos_menubar_clock_displayed = 0;
|
|
2357 }
|
173
|
2358
|
0
|
2359 if (!NILP (Vdos_timer_hooks))
|
|
2360 run_dos_timer_hooks++;
|
|
2361 }
|
|
2362
|
|
2363 /* Only event queue is checked. */
|
|
2364 int
|
|
2365 sys_select (int nfds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
|
|
2366 EMACS_TIME *timeout)
|
|
2367 {
|
|
2368 int check_input;
|
|
2369 long timeoutval, clnow, cllast;
|
|
2370 struct time t;
|
|
2371
|
|
2372 check_input = 0;
|
|
2373 if (rfds)
|
|
2374 {
|
|
2375 check_input = FD_ISSET (0, rfds);
|
|
2376 FD_ZERO (rfds);
|
|
2377 }
|
|
2378 if (wfds)
|
|
2379 FD_ZERO (wfds);
|
|
2380 if (efds)
|
|
2381 FD_ZERO (efds);
|
|
2382
|
|
2383 if (nfds != 1)
|
|
2384 abort ();
|
173
|
2385
|
0
|
2386 /* If we are looking only for the terminal, with no timeout,
|
|
2387 just read it and wait -- that's more efficient. */
|
|
2388 if (!timeout)
|
|
2389 {
|
|
2390 while (! detect_input_pending ())
|
|
2391 check_timer (&t);
|
|
2392 }
|
|
2393 else
|
|
2394 {
|
|
2395 timeoutval = EMACS_SECS (*timeout) * 100 + EMACS_USECS (*timeout) / 10000;
|
|
2396 check_timer (&t);
|
|
2397 cllast = t.ti_sec * 100 + t.ti_hund;
|
|
2398
|
|
2399 while (!check_input || !detect_input_pending ())
|
|
2400 {
|
|
2401 check_timer (&t);
|
|
2402 clnow = t.ti_sec * 100 + t.ti_hund;
|
|
2403 if (clnow < cllast) /* time wrap */
|
|
2404 timeoutval -= clnow + 6000 - cllast;
|
|
2405 else
|
|
2406 timeoutval -= clnow - cllast;
|
|
2407 if (timeoutval <= 0) /* Stop on timer being cleared */
|
|
2408 return 0;
|
|
2409 cllast = clnow;
|
|
2410 }
|
|
2411 }
|
173
|
2412
|
0
|
2413 FD_SET (0, rfds);
|
|
2414 return 1;
|
|
2415 }
|
|
2416 #endif
|
|
2417
|
|
2418 /*
|
|
2419 * Define overlayed functions:
|
|
2420 *
|
|
2421 * chdir -> sys_chdir
|
|
2422 * tzset -> init_gettimeofday
|
|
2423 * abort -> dos_abort
|
|
2424 */
|
|
2425
|
|
2426 #ifdef chdir
|
|
2427 #undef chdir
|
|
2428 extern int chdir (CONST char *);
|
|
2429
|
|
2430 int
|
|
2431 sys_chdir (CONST char* path)
|
|
2432 {
|
|
2433 int len = strlen (path);
|
|
2434 char *tmp = (char *)path;
|
|
2435
|
|
2436 if (*tmp && tmp[1] == ':')
|
|
2437 {
|
|
2438 if (getdisk () != tolower (tmp[0]) - 'a')
|
|
2439 setdisk (tolower (tmp[0]) - 'a');
|
|
2440 tmp += 2; /* strip drive: KFS 1995-07-06 */
|
|
2441 len -= 2;
|
|
2442 }
|
173
|
2443
|
0
|
2444 if (len > 1 && (tmp[len - 1] == '/'))
|
|
2445 {
|
|
2446 char *tmp1 = (char *) alloca (len + 1);
|
|
2447 strcpy (tmp1, tmp);
|
|
2448 tmp1[len - 1] = 0;
|
|
2449 tmp = tmp1;
|
|
2450 }
|
|
2451 return chdir (tmp);
|
|
2452 }
|
|
2453 #endif
|
|
2454
|
|
2455 #ifdef tzset
|
|
2456 #undef tzset
|
|
2457 extern void tzset (void);
|
|
2458
|
|
2459 void
|
|
2460 init_gettimeofday (void)
|
|
2461 {
|
|
2462 time_t ltm, gtm;
|
|
2463 struct tm *lstm;
|
|
2464
|
|
2465 tzset ();
|
|
2466 ltm = gtm = time (NULL);
|
|
2467 ltm = mktime (lstm = localtime (<m));
|
|
2468 gtm = mktime (gmtime (>m));
|
|
2469 time_rec.tm_hour = 99; /* force gettimeofday to get date */
|
|
2470 time_rec.tm_isdst = lstm->tm_isdst;
|
|
2471 dos_timezone_offset = time_rec.tm_gmtoff = (int)(gtm - ltm) / 60;
|
|
2472 }
|
|
2473 #endif
|
|
2474
|
|
2475 #ifdef abort
|
|
2476 #undef abort
|
|
2477 void
|
|
2478 dos_abort (char *file, int line)
|
|
2479 {
|
|
2480 char buffer1[200], buffer2[400];
|
|
2481 int i, j;
|
173
|
2482
|
0
|
2483 sprintf (buffer1, "<EMACS FATAL ERROR IN %s LINE %d>", file, line);
|
|
2484 for (i = j = 0; buffer1[i]; i++) {
|
|
2485 buffer2[j++] = buffer1[i];
|
|
2486 buffer2[j++] = 0x70;
|
|
2487 }
|
|
2488 dosmemput (buffer2, j, (int)ScreenPrimary);
|
|
2489 ScreenSetCursor (2, 0);
|
|
2490 abort ();
|
|
2491 }
|
|
2492 #endif
|
|
2493
|
|
2494 void
|
|
2495 syms_of_msdos (void)
|
|
2496 {
|
20
|
2497 DEFSUBR (Frecent_doskeys);
|
0
|
2498 }
|
|
2499
|
|
2500 void
|
|
2501 vars_of_msdos (void)
|
|
2502 {
|
|
2503 recent_doskeys = Fmake_vector (make_int (NUM_RECENT_DOSKEYS), Qnil);
|
|
2504 staticpro (&recent_doskeys);
|
|
2505
|
|
2506 }
|
|
2507
|
|
2508 #endif /* MSDOS */
|