1 /* MS-DOS specific C utilities. -*- coding: raw-text -*-
2 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* Contributed by Morten Welinder */
24 /* New display, keyboard, and mouse control by Kim F. Storm */
26 /* Note: some of the stuff here was taken from end of sysdep.c in demacs. */
35 #include <sys/param.h>
39 #include <string.h> /* for bzero and string functions */
40 #include <sys/stat.h> /* for _fixpath */
41 #include <unistd.h> /* for chdir, dup, dup2, etc. */
42 #include <dir.h> /* for getdisk */
44 #pragma pack(0) /* dir.h does a pack(4), which isn't GCC's default */
46 #include <io.h> /* for setmode */
47 #include <dpmi.h> /* for __dpmi_xxx stuff */
48 #include <sys/farptr.h> /* for _farsetsel, _farnspokeb */
49 #include <libc/dosio.h> /* for _USE_LFN */
50 #include <conio.h> /* for cputs */
55 #include "termhooks.h"
57 #include "dispextern.h"
60 #include "character.h"
67 #include "blockinput.h"
69 #include "intervals.h"
73 /* #include <process.h> */
74 /* Damn that local process.h! Instead we can define P_WAIT ourselves. */
82 #define _dos_ds _go32_info_block.selector_for_linear_memory
88 #include "syssignal.h"
94 /* If other `malloc' than ours is used, force our `sbrk' behave like
95 Unix programs expect (resize memory blocks to keep them contiguous).
96 If `sbrk' from `ralloc.c' is NOT used, also zero-out sbrk'ed memory,
97 because that's what `gmalloc' expects to get. */
101 int _crt0_startup_flags
= _CRT0_FLAG_UNIX_SBRK
;
102 #else /* not REL_ALLOC */
103 int _crt0_startup_flags
= (_CRT0_FLAG_UNIX_SBRK
| _CRT0_FLAG_FILL_SBRK_MEMORY
);
104 #endif /* not REL_ALLOC */
105 #endif /* GNU_MALLOC */
107 #endif /* not SYSTEM_MALLOC */
108 #endif /* __DJGPP__ > 1 */
127 /* ------------------------ Mouse control ---------------------------
129 * Coordinates are in screen positions and zero based.
130 * Mouse buttons are numbered from left to right and also zero based.
133 /* This used to be in termhooks.h, but mainstream Emacs code no longer
134 uses it, and it was removed... */
135 #define NUM_MOUSE_BUTTONS (5)
137 int have_mouse
; /* 0: no, 1: enabled, -1: disabled */
138 static int mouse_visible
;
140 static int mouse_last_x
;
141 static int mouse_last_y
;
143 static int mouse_button_translate
[NUM_MOUSE_BUTTONS
];
144 static int mouse_button_count
;
151 if (have_mouse
> 0 && !mouse_visible
)
154 fprintf (termscript
, "<M_ON>");
156 int86 (0x33, ®s
, ®s
);
166 if (have_mouse
> 0 && mouse_visible
)
169 fprintf (termscript
, "<M_OFF>");
171 int86 (0x33, ®s
, ®s
);
177 mouse_setup_buttons (int n_buttons
)
181 mouse_button_count
= 3;
182 mouse_button_translate
[0] = 0; /* Left */
183 mouse_button_translate
[1] = 2; /* Middle */
184 mouse_button_translate
[2] = 1; /* Right */
186 else /* two, what else? */
188 mouse_button_count
= 2;
189 mouse_button_translate
[0] = 0;
190 mouse_button_translate
[1] = 1;
194 DEFUN ("msdos-set-mouse-buttons", Fmsdos_set_mouse_buttons
, Smsdos_set_mouse_buttons
,
195 1, 1, "NSet number of mouse buttons to: ",
196 doc
: /* Set the number of mouse buttons to use by Emacs.
197 This is useful with mice that report the number of buttons inconsistently,
198 e.g., if the number of buttons is reported as 3, but Emacs only sees 2 of
199 them. This happens with wheeled mice on Windows 9X, for example. */)
201 Lisp_Object nbuttons
;
205 CHECK_NUMBER (nbuttons
);
208 xsignal2 (Qargs_out_of_range
,
209 build_string ("only 2 or 3 mouse buttons are supported"),
211 mouse_setup_buttons (n
);
216 mouse_get_xy (int *x
, int *y
)
221 int86 (0x33, ®s
, ®s
);
233 fprintf (termscript
, "<M_XY=%dx%d>", x
, y
);
235 mouse_last_x
= regs
.x
.cx
= x
* 8;
236 mouse_last_y
= regs
.x
.dx
= y
* 8;
237 int86 (0x33, ®s
, ®s
);
241 mouse_pressed (b
, xp
, yp
)
246 if (b
>= mouse_button_count
)
249 regs
.x
.bx
= mouse_button_translate
[b
];
250 int86 (0x33, ®s
, ®s
);
252 *xp
= regs
.x
.cx
/ 8, *yp
= regs
.x
.dx
/ 8;
253 return (regs
.x
.bx
!= 0);
257 mouse_released (b
, xp
, yp
)
262 if (b
>= mouse_button_count
)
265 regs
.x
.bx
= mouse_button_translate
[b
];
266 int86 (0x33, ®s
, ®s
);
268 *xp
= regs
.x
.cx
/ 8, *yp
= regs
.x
.dx
/ 8;
269 return (regs
.x
.bx
!= 0);
273 mouse_button_depressed (b
, xp
, yp
)
278 if (b
>= mouse_button_count
)
281 int86 (0x33, ®s
, ®s
);
282 if ((regs
.x
.bx
& (1 << mouse_button_translate
[b
])) != 0)
292 mouse_get_pos (f
, insist
, bar_window
, part
, x
, y
, time
)
295 Lisp_Object
*bar_window
, *x
, *y
;
296 enum scroll_bar_part
*part
;
300 Lisp_Object frame
, tail
;
302 /* Clear the mouse-moved flag for every frame on this display. */
303 FOR_EACH_FRAME (tail
, frame
)
304 XFRAME (frame
)->mouse_moved
= 0;
306 *f
= SELECTED_FRAME();
308 mouse_get_xy (&ix
, &iy
);
309 *time
= event_timestamp ();
310 *x
= make_number (mouse_last_x
= ix
);
311 *y
= make_number (mouse_last_y
= iy
);
319 mouse_get_xy (&x
, &y
);
320 SELECTED_FRAME()->mouse_moved
|= (x
!= mouse_last_x
|| y
!= mouse_last_y
);
325 /* Force the mouse driver to ``forget'' about any button clicks until
328 mouse_clear_clicks (void)
332 for (b
= 0; b
< mouse_button_count
; b
++)
334 int dummy_x
, dummy_y
;
336 (void) mouse_pressed (b
, &dummy_x
, &dummy_y
);
337 (void) mouse_released (b
, &dummy_x
, &dummy_y
);
347 fprintf (termscript
, "<M_INIT>");
350 int86 (0x33, ®s
, ®s
);
352 /* Reset the mouse last press/release info. It seems that Windows
353 doesn't do that automatically when function 21h is called, which
354 causes Emacs to ``remember'' the click that switched focus to the
355 window just before Emacs was started from that window. */
356 mouse_clear_clicks ();
360 regs
.x
.dx
= 8 * (ScreenCols () - 1);
361 int86 (0x33, ®s
, ®s
);
365 regs
.x
.dx
= 8 * (ScreenRows () - 1);
366 int86 (0x33, ®s
, ®s
);
372 /* ------------------------- Screen control ----------------------
376 static int internal_terminal
= 0;
378 #ifndef HAVE_X_WINDOWS
379 extern unsigned char ScreenAttrib
;
380 static int screen_face
;
382 static int screen_size_X
;
383 static int screen_size_Y
;
384 static int screen_size
;
386 static int current_pos_X
;
387 static int current_pos_Y
;
388 static int new_pos_X
;
389 static int new_pos_Y
;
391 static void *startup_screen_buffer
;
392 static int startup_screen_size_X
;
393 static int startup_screen_size_Y
;
394 static int startup_pos_X
;
395 static int startup_pos_Y
;
396 static unsigned char startup_screen_attrib
;
398 static clock_t startup_time
;
400 static int term_setup_done
;
402 static unsigned short outside_cursor
;
404 /* Similar to the_only_frame. */
405 struct x_output the_only_x_display
;
407 /* Support for DOS/V (allows Japanese characters to be displayed on
408 standard, non-Japanese, ATs). Only supported for DJGPP v2 and later. */
410 /* Holds the address of the text-mode screen buffer. */
411 static unsigned long screen_old_address
= 0;
412 /* Segment and offset of the virtual screen. If 0, DOS/V is NOT loaded. */
413 static unsigned short screen_virtual_segment
= 0;
414 static unsigned short screen_virtual_offset
= 0;
415 /* A flag to control how to display unibyte 8-bit characters. */
416 extern int unibyte_display_via_language_environment
;
418 extern Lisp_Object Qcursor_type
;
419 extern Lisp_Object Qbar
, Qhbar
;
421 /* The screen colors of the current frame, which serve as the default
422 colors for newly-created frames. */
423 static int initial_screen_colors
[2];
426 /* Update the screen from a part of relocated DOS/V screen buffer which
427 begins at OFFSET and includes COUNT characters. */
429 dosv_refresh_virtual_screen (int offset
, int count
)
433 if (offset
< 0 || count
< 0) /* paranoia; invalid values crash DOS/V */
436 regs
.h
.ah
= 0xff; /* update relocated screen */
437 regs
.x
.es
= screen_virtual_segment
;
438 regs
.x
.di
= screen_virtual_offset
+ offset
;
440 __dpmi_int (0x10, ®s
);
445 dos_direct_output (y
, x
, buf
, len
)
450 int t0
= 2 * (x
+ y
* screen_size_X
);
451 int t
= t0
+ (int) ScreenPrimary
;
456 dosmemput (buf
++, 1, t
);
460 /* This is faster. */
461 for (_farsetsel (_dos_ds
); --len
>= 0; t
+= 2, buf
++)
462 _farnspokeb (t
, *buf
);
464 if (screen_virtual_segment
)
465 dosv_refresh_virtual_screen (t0
, l0
);
470 /* Flash the screen as a substitute for BEEPs. */
474 do_visible_bell (xorattr
)
475 unsigned char xorattr
;
480 movl _ScreenPrimary,%%eax \n\
487 xorb %%al,%%gs:(%%ebx) \n\
490 jne visible_bell_1 \n\
492 jne visible_bell_3 \n\
494 movzwl %%ax,%%eax \n\
495 movzwl %%ax,%%eax \n\
496 movzwl %%ax,%%eax \n\
497 movzwl %%ax,%%eax \n\
499 jne visible_bell_2 \n\
500 jmp visible_bell_0 \n\
503 : "m" (xorattr
), "g" (screen_size
)
504 : "%eax", "%ebx", /* "%gs",*/ "%ecx", "%edx");
508 ScreenVisualBell (void)
510 /* This creates an xor-mask that will swap the default fore- and
511 background colors. */
512 do_visible_bell (((FRAME_FOREGROUND_PIXEL (SELECTED_FRAME ())
513 ^ FRAME_BACKGROUND_PIXEL (SELECTED_FRAME ()))
518 #ifndef HAVE_X_WINDOWS
520 static int blink_bit
= -1; /* the state of the blink bit at startup */
522 /* Enable bright background colors. */
528 /* Remember the original state of the blink/bright-background bit.
529 It is stored at 0040:0065h in the BIOS data area. */
531 blink_bit
= (_farpeekb (_dos_ds
, 0x465) & 0x20) == 0x20;
535 int86 (0x10, ®s
, ®s
);
538 /* Disable bright background colors (and enable blinking) if we found
539 the video system in that state at startup. */
541 maybe_enable_blinking (void)
549 int86 (0x10, ®s
, ®s
);
553 /* Return non-zero if the system has a VGA adapter. */
560 int86 (0x10, ®s
, ®s
);
561 if (regs
.h
.al
== 0x1a && regs
.h
.bl
> 5 && regs
.h
.bl
< 13)
566 /* Set the screen dimensions so that it can show no less than
567 ROWS x COLS frame. */
570 dos_set_window_size (rows
, cols
)
575 Lisp_Object video_mode
;
576 int video_mode_value
, have_vga
= 0;
577 int current_rows
= ScreenRows (), current_cols
= ScreenCols ();
579 if (*rows
== current_rows
&& *cols
== current_cols
)
583 have_vga
= vga_installed ();
585 /* If the user specified a special video mode for these dimensions,
587 sprintf (video_name
, "screen-dimensions-%dx%d", *rows
, *cols
);
588 video_mode
= XSYMBOL (Fintern_soft (build_string (video_name
),
591 if (INTEGERP (video_mode
)
592 && (video_mode_value
= XINT (video_mode
)) > 0)
594 regs
.x
.ax
= video_mode_value
;
595 int86 (0x10, ®s
, ®s
);
599 /* Must hardware-reset the mouse, or else it won't update
600 its notion of screen dimensions for some non-standard
601 video modes. This is *painfully* slow... */
603 int86 (0x33, ®s
, ®s
);
607 /* Find one of the dimensions supported by standard EGA/VGA
608 which gives us at least the required dimensions. */
616 } std_dimension
[] = {
626 while (i
< sizeof (std_dimension
) / sizeof (std_dimension
[0]))
628 if (std_dimension
[i
].need_vga
<= have_vga
629 && std_dimension
[i
].rows
>= *rows
)
631 if (std_dimension
[i
].rows
!= current_rows
632 || *cols
!= current_cols
)
633 _set_screen_lines (std_dimension
[i
].rows
);
640 #else /* not __DJGPP__ > 1 */
642 else if (*rows
<= 25)
644 if (current_rows
!= 25 || current_cols
!= 80)
647 int86 (0x10, ®s
, ®s
);
650 int86 (0x10, ®s
, ®s
);
653 int86 (0x10, ®s
, ®s
);
655 int86 (0x10, ®s
, ®s
);
658 else if (*rows
<= 50)
659 if (have_vga
&& (current_rows
!= 50 || current_cols
!= 80)
660 || *rows
<= 43 && (current_rows
!= 43 || current_cols
!= 80))
663 int86 (0x10, ®s
, ®s
);
666 int86 (0x10, ®s
, ®s
);
669 int86 (0x10, ®s
, ®s
);
672 int86 (0x10, ®s
, ®s
);
674 #endif /* not __DJGPP__ > 1 */
682 /* Tell the caller what dimensions have been REALLY set. */
683 *rows
= ScreenRows ();
684 *cols
= ScreenCols ();
686 /* Update Emacs' notion of screen dimensions. */
687 screen_size_X
= *cols
;
688 screen_size_Y
= *rows
;
689 screen_size
= *cols
* *rows
;
692 /* If the dimensions changed, the mouse highlight info is invalid. */
693 if (current_rows
!= *rows
|| current_cols
!= *cols
)
695 struct frame
*f
= SELECTED_FRAME();
696 struct display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
697 Lisp_Object window
= dpyinfo
->mouse_face_window
;
699 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
701 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
702 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
703 dpyinfo
->mouse_face_window
= Qnil
;
708 /* Enable bright background colors. */
711 /* FIXME: I'm not sure the above will run at all on DOS/V. But let's
712 be defensive anyway. */
713 if (screen_virtual_segment
)
714 dosv_refresh_virtual_screen (0, *cols
* *rows
);
717 /* If we write a character in the position where the mouse is,
718 the mouse cursor may need to be refreshed. */
728 mouse_get_xy (&x
, &y
);
729 if (y
!= new_pos_Y
|| x
< new_pos_X
)
735 #define DEFAULT_CURSOR_START (-1)
736 #define DEFAULT_CURSOR_WIDTH (-1)
737 #define BOX_CURSOR_WIDTH (-32)
739 /* Set cursor to begin at scan line START_LINE in the character cell
740 and extend for WIDTH scan lines. Scan lines are counted from top
741 of the character cell, starting from zero. */
743 msdos_set_cursor_shape (struct frame
*f
, int start_line
, int width
)
746 unsigned desired_cursor
;
748 int max_line
, top_line
, bot_line
;
750 /* Avoid the costly BIOS call if F isn't the currently selected
751 frame. Allow for NULL as unconditionally meaning the selected
753 if (f
&& f
!= SELECTED_FRAME())
757 fprintf (termscript
, "\nCURSOR SHAPE=(%d,%d)", start_line
, width
);
759 /* The character cell size in scan lines is stored at 40:85 in the
761 max_line
= _farpeekw (_dos_ds
, 0x485) - 1;
764 default: /* this relies on CGA cursor emulation being ON! */
781 if (width
== BOX_CURSOR_WIDTH
)
786 else if (start_line
!= DEFAULT_CURSOR_START
)
788 top_line
= start_line
;
789 bot_line
= top_line
- width
- 1;
791 else if (width
!= DEFAULT_CURSOR_WIDTH
)
794 bot_line
= -1 - width
;
797 top_line
= bot_line
+ 1;
801 /* [31, 0] seems to DTRT for all screen sizes. */
805 else /* WIDTH is positive */
807 if (start_line
!= DEFAULT_CURSOR_START
)
808 bot_line
= start_line
;
809 top_line
= bot_line
- (width
- 1);
812 /* If the current cursor shape is already what they want, we are
814 desired_cursor
= ((top_line
& 0x1f) << 8) | (bot_line
& 0x1f);
815 if (desired_cursor
== _farpeekw (_dos_ds
, 0x460))
819 regs
.x
.cx
= desired_cursor
;
820 __dpmi_int (0x10, ®s
);
821 #endif /* __DJGPP__ > 1 */
825 IT_set_cursor_type (struct frame
*f
, Lisp_Object cursor_type
)
827 if (EQ (cursor_type
, Qbar
) || EQ (cursor_type
, Qhbar
))
829 /* Just BAR means the normal EGA/VGA cursor. */
830 msdos_set_cursor_shape (f
, DEFAULT_CURSOR_START
, DEFAULT_CURSOR_WIDTH
);
832 else if (CONSP (cursor_type
)
833 && (EQ (XCAR (cursor_type
), Qbar
)
834 || EQ (XCAR (cursor_type
), Qhbar
)))
836 Lisp_Object bar_parms
= XCDR (cursor_type
);
839 if (INTEGERP (bar_parms
))
841 /* Feature: negative WIDTH means cursor at the top
842 of the character cell, zero means invisible cursor. */
843 width
= XINT (bar_parms
);
844 msdos_set_cursor_shape (f
, width
>= 0 ? DEFAULT_CURSOR_START
: 0,
847 else if (CONSP (bar_parms
)
848 && INTEGERP (XCAR (bar_parms
))
849 && INTEGERP (XCDR (bar_parms
)))
851 int start_line
= XINT (XCDR (bar_parms
));
853 width
= XINT (XCAR (bar_parms
));
854 msdos_set_cursor_shape (f
, start_line
, width
);
859 /* Treat anything unknown as "box cursor". This includes nil, so
860 that a frame which doesn't specify a cursor type gets a box,
861 which is the default in Emacs. */
862 msdos_set_cursor_shape (f
, 0, BOX_CURSOR_WIDTH
);
876 union REGS inregs
, outregs
;
879 intdos (&inregs
, &outregs
);
883 /* Given a face id FACE, extract the face parameters to be used for
884 display until the face changes. The face parameters (actually, its
885 color) are used to construct the video attribute byte for each
886 glyph during the construction of the buffer that is then blitted to
889 IT_set_face (int face
)
891 struct frame
*sf
= SELECTED_FRAME();
892 struct face
*fp
= FACE_FROM_ID (sf
, face
);
893 struct face
*dfp
= FACE_FROM_ID (sf
, DEFAULT_FACE_ID
);
894 unsigned long fg
, bg
, dflt_fg
, dflt_bg
;
899 /* The default face for the frame should always be realized and
907 dflt_fg
= dfp
->foreground
;
908 dflt_bg
= dfp
->background
;
910 /* Don't use invalid colors. In particular, FACE_TTY_DEFAULT_* colors
911 mean use the colors of the default face. Note that we assume all
912 16 colors to be available for the background, since Emacs switches
913 on this mode (and loses the blinking attribute) at startup. */
914 if (fg
== FACE_TTY_DEFAULT_COLOR
|| fg
== FACE_TTY_DEFAULT_FG_COLOR
)
915 fg
= FRAME_FOREGROUND_PIXEL (sf
);
916 else if (fg
== FACE_TTY_DEFAULT_BG_COLOR
)
917 fg
= FRAME_BACKGROUND_PIXEL (sf
);
918 if (bg
== FACE_TTY_DEFAULT_COLOR
|| bg
== FACE_TTY_DEFAULT_BG_COLOR
)
919 bg
= FRAME_BACKGROUND_PIXEL (sf
);
920 else if (bg
== FACE_TTY_DEFAULT_FG_COLOR
)
921 bg
= FRAME_FOREGROUND_PIXEL (sf
);
923 /* Make sure highlighted lines really stand out, come what may. */
924 if (fp
->tty_reverse_p
&& (fg
== dflt_fg
&& bg
== dflt_bg
))
926 unsigned long tem
= fg
;
931 /* If the user requested inverse video, obey. */
934 unsigned long tem2
= fg
;
940 fprintf (termscript
, "<FACE %d: %d/%d[FG:%d/BG:%d]>", face
,
941 fp
->foreground
, fp
->background
, fg
, bg
);
942 if (fg
>= 0 && fg
< 16)
944 ScreenAttrib
&= 0xf0;
947 if (bg
>= 0 && bg
< 16)
949 ScreenAttrib
&= 0x0f;
950 ScreenAttrib
|= ((bg
& 0x0f) << 4);
954 Lisp_Object Vdos_unsupported_char_glyph
;
957 IT_write_glyphs (struct glyph
*str
, int str_len
)
959 unsigned char *screen_buf
, *screen_bp
, *screen_buf_end
, *bp
;
960 int unsupported_face
= 0;
961 unsigned unsupported_char
= '\177';
962 int offset
= 2 * (new_pos_X
+ screen_size_X
* new_pos_Y
);
963 register int sl
= str_len
;
964 register int tlen
= GLYPH_TABLE_LENGTH
;
965 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
967 /* If terminal_coding does any conversion, use it, otherwise use
968 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
969 because it always returns 1 if terminal_coding.src_multibyte is 1. */
970 struct coding_system
*coding
=
971 (terminal_coding
.common_flags
& CODING_REQUIRE_ENCODING_MASK
973 : &safe_terminal_coding
);
976 /* Do we need to consider conversion of unibyte characters to
978 int convert_unibyte_characters
979 = (NILP (current_buffer
->enable_multibyte_characters
)
980 && unibyte_display_via_language_environment
);
982 unsigned char conversion_buffer
[256];
983 int conversion_buffer_size
= sizeof conversion_buffer
;
985 if (str_len
<= 0) return;
987 /* Set up the unsupported character glyph */
988 if (!NILP (Vdos_unsupported_char_glyph
))
990 unsupported_char
= FAST_GLYPH_CHAR (XINT (Vdos_unsupported_char_glyph
));
991 unsupported_face
= FAST_GLYPH_FACE (XINT (Vdos_unsupported_char_glyph
));
994 screen_buf
= screen_bp
= alloca (str_len
* 2);
995 screen_buf_end
= screen_buf
+ str_len
* 2;
996 sf
= SELECTED_FRAME();
998 /* Since faces get cached and uncached behind our back, we can't
999 rely on their indices in the cache being consistent across
1000 invocations. So always reset the screen face to the default
1001 face of the frame, before writing glyphs, and let the glyphs
1002 set the right face if it's different from the default. */
1003 IT_set_face (DEFAULT_FACE_ID
);
1005 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
1007 terminal_coding
.mode
&= ~CODING_MODE_LAST_BLOCK
;
1010 int cf
, chlen
, enclen
;
1011 unsigned char workbuf
[MAX_MULTIBYTE_LENGTH
], *buf
;
1014 /* Glyphs with GLYPH_MASK_PADDING bit set are actually there
1015 only for the redisplay code to know how many columns does
1016 this character occupy on the screen. Skip padding glyphs. */
1017 if (CHAR_GLYPH_PADDING_P (*str
))
1024 register GLYPH g
= GLYPH_FROM_CHAR_GLYPH (*str
);
1025 int glyph_not_in_table
= 0;
1027 /* If g is negative, it means we have a multibyte character
1028 in *str. That's what GLYPH_FROM_CHAR_GLYPH returns for
1029 multibyte characters. */
1030 if (g
< 0 || g
>= tlen
)
1032 /* This glyph doesn't have an entry in Vglyph_table. */
1034 glyph_not_in_table
= 1;
1038 /* This glyph has an entry in Vglyph_table, so process
1039 any aliases before testing for simpleness. */
1040 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
1041 ch
= FAST_GLYPH_CHAR (g
);
1044 /* Convert the character code to multibyte, if they
1045 requested display via language environment. We only want
1046 to convert unibyte characters to multibyte in unibyte
1047 buffers! Otherwise, the 8-bit value in CH came from the
1048 display table set up to display foreign characters. */
1049 if (SINGLE_BYTE_CHAR_P (ch
) && convert_unibyte_characters
1051 || (ch
>= 0200 && !NILP (Vnonascii_translation_table
))))
1052 ch
= unibyte_char_to_multibyte (ch
);
1054 /* Invalid characters are displayed with a special glyph. */
1055 if (! CHAR_VALID_P (ch
, 0))
1057 g
= !NILP (Vdos_unsupported_char_glyph
)
1058 ? XINT (Vdos_unsupported_char_glyph
)
1059 : MAKE_GLYPH (sf
, '\177', GLYPH_FACE (sf
, g
));
1060 ch
= FAST_GLYPH_CHAR (g
);
1063 /* If the face of this glyph is different from the current
1064 screen face, update the screen attribute byte. */
1066 if (cf
!= screen_face
)
1067 IT_set_face (cf
); /* handles invalid faces gracefully */
1069 if (glyph_not_in_table
|| GLYPH_SIMPLE_P (tbase
, tlen
, g
))
1071 /* We generate the multi-byte form of CH in WORKBUF. */
1072 chlen
= CHAR_STRING (ch
, workbuf
);
1077 /* We have a string in Vglyph_table. */
1078 chlen
= GLYPH_LENGTH (tbase
, g
);
1079 buf
= GLYPH_STRING (tbase
, g
);
1082 /* If the character is not multibyte, don't bother converting it. */
1085 *conversion_buffer
= (unsigned char)ch
;
1091 coding
->src_multibyte
= 1;
1092 encode_coding (coding
, buf
, conversion_buffer
, chlen
,
1093 conversion_buffer_size
);
1094 chlen
-= coding
->consumed
;
1095 enclen
= coding
->produced
;
1097 /* Replace glyph codes that cannot be converted by
1098 terminal_coding with Vdos_unsupported_char_glyph. */
1099 if (*conversion_buffer
== '?')
1101 unsigned char *cbp
= conversion_buffer
;
1103 while (cbp
< conversion_buffer
+ enclen
&& *cbp
== '?')
1104 *cbp
++ = unsupported_char
;
1105 if (unsupported_face
!= screen_face
)
1106 IT_set_face (unsupported_face
);
1110 if (enclen
+ chlen
> screen_buf_end
- screen_bp
)
1112 /* The allocated buffer for screen writes is too small.
1113 Flush it and loop again without incrementing STR, so
1114 that the next loop will begin with the same glyph. */
1115 int nbytes
= screen_bp
- screen_buf
;
1118 dosmemput (screen_buf
, nbytes
, (int)ScreenPrimary
+ offset
);
1119 if (screen_virtual_segment
)
1120 dosv_refresh_virtual_screen (offset
, nbytes
/ 2);
1121 new_pos_X
+= nbytes
/ 2;
1124 /* Prepare to reuse the same buffer again. */
1125 screen_bp
= screen_buf
;
1129 /* There's enough place in the allocated buffer to add
1130 the encoding of this glyph. */
1132 /* First, copy the encoded bytes. */
1133 for (bp
= conversion_buffer
; enclen
--; bp
++)
1135 *screen_bp
++ = (unsigned char)*bp
;
1136 *screen_bp
++ = ScreenAttrib
;
1138 fputc (*bp
, termscript
);
1141 /* Now copy the bytes not consumed by the encoding. */
1144 buf
+= coding
->consumed
;
1148 fputc (*buf
, termscript
);
1149 *screen_bp
++ = (unsigned char)*buf
++;
1150 *screen_bp
++ = ScreenAttrib
;
1154 /* Update STR and its remaining length. */
1161 /* Dump whatever is left in the screen buffer. */
1163 dosmemput (screen_buf
, screen_bp
- screen_buf
, (int)ScreenPrimary
+ offset
);
1164 if (screen_virtual_segment
)
1165 dosv_refresh_virtual_screen (offset
, (screen_bp
- screen_buf
) / 2);
1166 new_pos_X
+= (screen_bp
- screen_buf
) / 2;
1168 /* We may have to output some codes to terminate the writing. */
1169 if (CODING_REQUIRE_FLUSHING (coding
))
1171 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
1172 encode_coding (coding
, "", conversion_buffer
, 0, conversion_buffer_size
);
1173 if (coding
->produced
> 0)
1175 screen_buf
= alloca (coding
->produced
* 2);
1176 for (screen_bp
= screen_buf
, bp
= conversion_buffer
;
1177 coding
->produced
--; bp
++)
1179 *screen_bp
++ = (unsigned char)*bp
;
1180 *screen_bp
++ = ScreenAttrib
;
1182 fputc (*bp
, termscript
);
1184 offset
+= screen_bp
- screen_buf
;
1186 dosmemput (screen_buf
, screen_bp
- screen_buf
,
1187 (int)ScreenPrimary
+ offset
);
1188 if (screen_virtual_segment
)
1189 dosv_refresh_virtual_screen (offset
, (screen_bp
- screen_buf
) / 2);
1190 new_pos_X
+= (screen_bp
- screen_buf
) / 2;
1195 /************************************************************************
1196 Mouse Highlight (and friends..)
1197 ************************************************************************/
1199 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
1200 static Lisp_Object last_mouse_window
;
1202 static int mouse_preempted
= 0; /* non-zero when XMenu gobbles mouse events */
1204 /* Set the mouse pointer shape according to whether it is in the
1205 area where the mouse highlight is in effect. */
1207 IT_set_mouse_pointer (int mode
)
1209 /* A no-op for now. DOS text-mode mouse pointer doesn't offer too
1210 many possibilities to change its shape, and the available
1211 functionality pretty much sucks (e.g., almost every reasonable
1212 shape will conceal the character it is on). Since the color of
1213 the pointer changes in the highlighted area, it is not clear to
1214 me whether anything else is required, anyway. */
1217 /* Display the active region described by mouse_face_*
1218 in its mouse-face if HL > 0, in its normal face if HL = 0. */
1220 show_mouse_face (struct display_info
*dpyinfo
, int hl
)
1222 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
1223 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1228 /* If window is in the process of being destroyed, don't bother
1230 if (w
->current_matrix
== NULL
)
1231 goto set_cursor_shape
;
1233 /* Recognize when we are called to operate on rows that don't exist
1234 anymore. This can happen when a window is split. */
1235 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
1236 goto set_cursor_shape
;
1238 /* There's no sense to do anything if the mouse face isn't realized. */
1241 if (dpyinfo
->mouse_face_hidden
)
1242 goto set_cursor_shape
;
1244 fp
= FACE_FROM_ID (SELECTED_FRAME(), dpyinfo
->mouse_face_face_id
);
1246 goto set_cursor_shape
;
1249 /* Note that mouse_face_beg_row etc. are window relative. */
1250 for (i
= dpyinfo
->mouse_face_beg_row
;
1251 i
<= dpyinfo
->mouse_face_end_row
;
1254 int start_hpos
, end_hpos
;
1255 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
1257 /* Don't do anything if row doesn't have valid contents. */
1258 if (!row
->enabled_p
)
1261 /* For all but the first row, the highlight starts at column 0. */
1262 if (i
== dpyinfo
->mouse_face_beg_row
)
1263 start_hpos
= dpyinfo
->mouse_face_beg_col
;
1267 if (i
== dpyinfo
->mouse_face_end_row
)
1268 end_hpos
= dpyinfo
->mouse_face_end_col
;
1270 end_hpos
= row
->used
[TEXT_AREA
];
1272 if (end_hpos
<= start_hpos
)
1274 /* Record that some glyphs of this row are displayed in
1276 row
->mouse_face_p
= hl
> 0;
1279 int vpos
= row
->y
+ WINDOW_TOP_EDGE_Y (w
);
1280 int kstart
= start_hpos
+ WINDOW_LEFT_EDGE_X (w
);
1281 int nglyphs
= end_hpos
- start_hpos
;
1282 int offset
= ScreenPrimary
+ 2*(vpos
*screen_size_X
+ kstart
) + 1;
1283 int start_offset
= offset
;
1286 fprintf (termscript
, "\n<MH+ %d-%d:%d>",
1287 kstart
, kstart
+ nglyphs
- 1, vpos
);
1290 IT_set_face (dpyinfo
->mouse_face_face_id
);
1291 /* Since we are going to change only the _colors_ of the
1292 displayed text, there's no need to go through all the
1293 pain of generating and encoding the text from the glyphs.
1294 Instead, we simply poke the attribute byte of each
1295 affected position in video memory with the colors
1296 computed by IT_set_face! */
1297 _farsetsel (_dos_ds
);
1300 _farnspokeb (offset
, ScreenAttrib
);
1303 if (screen_virtual_segment
)
1304 dosv_refresh_virtual_screen (start_offset
, end_hpos
- start_hpos
);
1309 /* We are removing a previously-drawn mouse highlight. The
1310 safest way to do so is to redraw the glyphs anew, since
1311 all kinds of faces and display tables could have changed
1313 int nglyphs
= end_hpos
- start_hpos
;
1314 int save_x
= new_pos_X
, save_y
= new_pos_Y
;
1316 if (end_hpos
>= row
->used
[TEXT_AREA
])
1317 nglyphs
= row
->used
[TEXT_AREA
] - start_hpos
;
1319 /* IT_write_glyphs writes at cursor position, so we need to
1320 temporarily move cursor coordinates to the beginning of
1321 the highlight region. */
1322 new_pos_X
= start_hpos
+ WINDOW_LEFT_EDGE_X (w
);
1323 new_pos_Y
= row
->y
+ WINDOW_TOP_EDGE_Y (w
);
1326 fprintf (termscript
, "<MH- %d-%d:%d>",
1327 new_pos_X
, new_pos_X
+ nglyphs
- 1, new_pos_Y
);
1328 IT_write_glyphs (row
->glyphs
[TEXT_AREA
] + start_hpos
, nglyphs
);
1330 fputs ("\n", termscript
);
1337 /* Change the mouse pointer shape. */
1338 IT_set_mouse_pointer (hl
);
1341 /* Clear out the mouse-highlighted active region.
1342 Redraw it un-highlighted first. */
1344 clear_mouse_face (struct display_info
*dpyinfo
)
1346 if (!dpyinfo
->mouse_face_hidden
&& ! NILP (dpyinfo
->mouse_face_window
))
1347 show_mouse_face (dpyinfo
, 0);
1349 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
1350 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
1351 dpyinfo
->mouse_face_window
= Qnil
;
1354 /* Find the glyph matrix position of buffer position POS in window W.
1355 *HPOS and *VPOS are set to the positions found. W's current glyphs
1356 must be up to date. If POS is above window start return (0, 0).
1357 If POS is after end of W, return end of last line in W. */
1359 fast_find_position (struct window
*w
, int pos
, int *hpos
, int *vpos
)
1361 int i
, lastcol
, line_start_position
, maybe_next_line_p
= 0;
1362 int yb
= window_text_bottom_y (w
);
1363 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0), *best_row
= row
;
1367 if (row
->used
[TEXT_AREA
])
1368 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
1370 line_start_position
= 0;
1372 if (line_start_position
> pos
)
1374 /* If the position sought is the end of the buffer,
1375 don't include the blank lines at the bottom of the window. */
1376 else if (line_start_position
== pos
1377 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
1379 maybe_next_line_p
= 1;
1382 else if (line_start_position
> 0)
1385 /* Don't overstep the last matrix row, lest we get into the
1386 never-never land... */
1387 if (row
->y
+ 1 >= yb
)
1393 /* Find the right column within BEST_ROW. */
1396 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
1398 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + i
;
1401 charpos
= glyph
->charpos
;
1408 else if (charpos
> pos
)
1410 else if (charpos
> 0)
1414 /* If we're looking for the end of the buffer,
1415 and we didn't find it in the line we scanned,
1416 use the start of the following line. */
1417 if (maybe_next_line_p
)
1424 *hpos
= lastcol
+ 1;
1428 /* Take proper action when mouse has moved to the mode or top line of
1429 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
1430 mode line. X is relative to the start of the text display area of
1431 W, so the width of fringes and scroll bars must be subtracted
1432 to get a position relative to the start of the mode line. */
1434 IT_note_mode_line_highlight (struct window
*w
, int x
, int mode_line_p
)
1436 struct frame
*f
= XFRAME (w
->frame
);
1437 struct display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1438 struct glyph_row
*row
;
1441 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
1443 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
1447 extern Lisp_Object Qhelp_echo
;
1448 struct glyph
*glyph
, *end
;
1449 Lisp_Object help
, map
;
1451 /* Find the glyph under X. */
1452 glyph
= (row
->glyphs
[TEXT_AREA
]
1454 /* in case someone implements scroll bars some day... */
1455 - WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
));
1456 end
= glyph
+ row
->used
[TEXT_AREA
];
1458 && STRINGP (glyph
->object
)
1459 && STRING_INTERVALS (glyph
->object
)
1460 && glyph
->charpos
>= 0
1461 && glyph
->charpos
< SCHARS (glyph
->object
))
1463 /* If we're on a string with `help-echo' text property,
1464 arrange for the help to be displayed. This is done by
1465 setting the global variable help_echo to the help string. */
1466 help
= Fget_text_property (make_number (glyph
->charpos
),
1467 Qhelp_echo
, glyph
->object
);
1470 help_echo_string
= help
;
1471 XSETWINDOW (help_echo_window
, w
);
1472 help_echo_object
= glyph
->object
;
1473 help_echo_pos
= glyph
->charpos
;
1479 /* Take proper action when the mouse has moved to position X, Y on
1480 frame F as regards highlighting characters that have mouse-face
1481 properties. Also de-highlighting chars where the mouse was before.
1482 X and Y can be negative or out of range. */
1484 IT_note_mouse_highlight (struct frame
*f
, int x
, int y
)
1486 struct display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1487 enum window_part part
= ON_NOTHING
;
1491 /* When a menu is active, don't highlight because this looks odd. */
1492 if (mouse_preempted
)
1495 if (NILP (Vmouse_highlight
)
1496 || !f
->glyphs_initialized_p
)
1499 dpyinfo
->mouse_face_mouse_x
= x
;
1500 dpyinfo
->mouse_face_mouse_y
= y
;
1501 dpyinfo
->mouse_face_mouse_frame
= f
;
1503 if (dpyinfo
->mouse_face_defer
)
1508 dpyinfo
->mouse_face_deferred_gc
= 1;
1512 /* Which window is that in? */
1513 window
= window_from_coordinates (f
, x
, y
, &part
, &x
, &y
, 0);
1515 /* If we were displaying active text in another window, clear that. */
1516 if (! EQ (window
, dpyinfo
->mouse_face_window
))
1517 clear_mouse_face (dpyinfo
);
1519 /* Not on a window -> return. */
1520 if (!WINDOWP (window
))
1523 /* Convert to window-relative coordinates. */
1524 w
= XWINDOW (window
);
1526 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
)
1528 /* Mouse is on the mode or top line. */
1529 IT_note_mode_line_highlight (w
, x
, part
== ON_MODE_LINE
);
1533 IT_set_mouse_pointer (0);
1535 /* Are we in a window whose display is up to date?
1536 And verify the buffer's text has not changed. */
1538 && EQ (w
->window_end_valid
, w
->buffer
)
1539 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
1540 && (XFASTINT (w
->last_overlay_modified
)
1541 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
1543 int pos
, i
, nrows
= w
->current_matrix
->nrows
;
1544 struct glyph_row
*row
;
1545 struct glyph
*glyph
;
1547 /* Find the glyph under X/Y. */
1549 if (y
>= 0 && y
< nrows
)
1551 row
= MATRIX_ROW (w
->current_matrix
, y
);
1552 /* Give up if some row before the one we are looking for is
1554 for (i
= 0; i
<= y
; i
++)
1555 if (!MATRIX_ROW (w
->current_matrix
, i
)->enabled_p
)
1557 if (i
> y
/* all rows upto and including the one at Y are enabled */
1558 && row
->displays_text_p
1559 && x
< window_box_width (w
, TEXT_AREA
))
1561 glyph
= row
->glyphs
[TEXT_AREA
];
1562 if (x
>= row
->used
[TEXT_AREA
])
1567 if (!BUFFERP (glyph
->object
))
1573 /* Clear mouse face if X/Y not over text. */
1576 clear_mouse_face (dpyinfo
);
1580 if (!BUFFERP (glyph
->object
))
1582 pos
= glyph
->charpos
;
1584 /* Check for mouse-face and help-echo. */
1586 extern Lisp_Object Qmouse_face
;
1587 Lisp_Object mouse_face
, overlay
, position
, *overlay_vec
;
1588 int noverlays
, obegv
, ozv
;
1589 struct buffer
*obuf
;
1591 /* If we get an out-of-range value, return now; avoid an error. */
1592 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
1595 /* Make the window's buffer temporarily current for
1596 overlays_at and compute_char_face. */
1597 obuf
= current_buffer
;
1598 current_buffer
= XBUFFER (w
->buffer
);
1604 /* Is this char mouse-active or does it have help-echo? */
1605 XSETINT (position
, pos
);
1607 /* Put all the overlays we want in a vector in overlay_vec. */
1608 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
1609 /* Sort overlays into increasing priority order. */
1610 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
1612 /* Check mouse-face highlighting. */
1613 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
1614 && y
>= dpyinfo
->mouse_face_beg_row
1615 && y
<= dpyinfo
->mouse_face_end_row
1616 && (y
> dpyinfo
->mouse_face_beg_row
1617 || x
>= dpyinfo
->mouse_face_beg_col
)
1618 && (y
< dpyinfo
->mouse_face_end_row
1619 || x
< dpyinfo
->mouse_face_end_col
1620 || dpyinfo
->mouse_face_past_end
)))
1622 /* Clear the display of the old active region, if any. */
1623 clear_mouse_face (dpyinfo
);
1625 /* Find highest priority overlay that has a mouse-face prop. */
1627 for (i
= noverlays
- 1; i
>= 0; --i
)
1629 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
1630 if (!NILP (mouse_face
))
1632 overlay
= overlay_vec
[i
];
1637 /* If no overlay applies, get a text property. */
1639 mouse_face
= Fget_text_property (position
, Qmouse_face
,
1642 /* Handle the overlay case. */
1643 if (! NILP (overlay
))
1645 /* Find the range of text around this char that
1646 should be active. */
1647 Lisp_Object before
, after
;
1650 before
= Foverlay_start (overlay
);
1651 after
= Foverlay_end (overlay
);
1652 /* Record this as the current active region. */
1653 fast_find_position (w
, XFASTINT (before
),
1654 &dpyinfo
->mouse_face_beg_col
,
1655 &dpyinfo
->mouse_face_beg_row
);
1656 dpyinfo
->mouse_face_past_end
1657 = !fast_find_position (w
, XFASTINT (after
),
1658 &dpyinfo
->mouse_face_end_col
,
1659 &dpyinfo
->mouse_face_end_row
);
1660 dpyinfo
->mouse_face_window
= window
;
1661 dpyinfo
->mouse_face_face_id
1662 = face_at_buffer_position (w
, pos
, 0, 0,
1664 !dpyinfo
->mouse_face_hidden
);
1666 /* Display it as active. */
1667 show_mouse_face (dpyinfo
, 1);
1669 /* Handle the text property case. */
1670 else if (! NILP (mouse_face
))
1672 /* Find the range of text around this char that
1673 should be active. */
1674 Lisp_Object before
, after
, beginning
, end
;
1677 beginning
= Fmarker_position (w
->start
);
1678 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
1679 - XFASTINT (w
->window_end_pos
)));
1681 = Fprevious_single_property_change (make_number (pos
+ 1),
1683 w
->buffer
, beginning
);
1685 = Fnext_single_property_change (position
, Qmouse_face
,
1687 /* Record this as the current active region. */
1688 fast_find_position (w
, XFASTINT (before
),
1689 &dpyinfo
->mouse_face_beg_col
,
1690 &dpyinfo
->mouse_face_beg_row
);
1691 dpyinfo
->mouse_face_past_end
1692 = !fast_find_position (w
, XFASTINT (after
),
1693 &dpyinfo
->mouse_face_end_col
,
1694 &dpyinfo
->mouse_face_end_row
);
1695 dpyinfo
->mouse_face_window
= window
;
1696 dpyinfo
->mouse_face_face_id
1697 = face_at_buffer_position (w
, pos
, 0, 0,
1699 !dpyinfo
->mouse_face_hidden
);
1701 /* Display it as active. */
1702 show_mouse_face (dpyinfo
, 1);
1706 /* Look for a `help-echo' property. */
1709 extern Lisp_Object Qhelp_echo
;
1711 /* Check overlays first. */
1713 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
1715 overlay
= overlay_vec
[i
];
1716 help
= Foverlay_get (overlay
, Qhelp_echo
);
1721 help_echo_string
= help
;
1722 help_echo_window
= window
;
1723 help_echo_object
= overlay
;
1724 help_echo_pos
= pos
;
1726 /* Try text properties. */
1727 else if (NILP (help
)
1728 && ((STRINGP (glyph
->object
)
1729 && glyph
->charpos
>= 0
1730 && glyph
->charpos
< SCHARS (glyph
->object
))
1731 || (BUFFERP (glyph
->object
)
1732 && glyph
->charpos
>= BEGV
1733 && glyph
->charpos
< ZV
)))
1735 help
= Fget_text_property (make_number (glyph
->charpos
),
1736 Qhelp_echo
, glyph
->object
);
1739 help_echo_string
= help
;
1740 help_echo_window
= window
;
1741 help_echo_object
= glyph
->object
;
1742 help_echo_pos
= glyph
->charpos
;
1749 current_buffer
= obuf
;
1755 IT_clear_end_of_line (int first_unused
)
1758 int i
, j
, offset
= 2 * (new_pos_X
+ screen_size_X
* new_pos_Y
);
1759 extern int fatal_error_in_progress
;
1761 if (new_pos_X
>= first_unused
|| fatal_error_in_progress
)
1765 i
= (j
= first_unused
- new_pos_X
) * 2;
1767 fprintf (termscript
, "<CLR:EOL[%d..%d)>", new_pos_X
, first_unused
);
1768 spaces
= sp
= alloca (i
);
1773 *sp
++ = ScreenAttrib
;
1777 dosmemput (spaces
, i
, (int)ScreenPrimary
+ offset
);
1778 if (screen_virtual_segment
)
1779 dosv_refresh_virtual_screen (offset
, i
/ 2);
1781 /* clear_end_of_line_raw on term.c leaves the cursor at first_unused.
1782 Let's follow their lead, in case someone relies on this. */
1783 new_pos_X
= first_unused
;
1787 IT_clear_screen (void)
1790 fprintf (termscript
, "<CLR:SCR>");
1791 /* We are sometimes called (from clear_garbaged_frames) when a new
1792 frame is being created, but its faces are not yet realized. In
1793 such a case we cannot call IT_set_face, since it will fail to find
1794 any valid faces and will abort. Instead, use the initial screen
1795 colors; that should mimic what a Unix tty does, which simply clears
1796 the screen with whatever default colors are in use. */
1797 if (FACE_FROM_ID (SELECTED_FRAME (), DEFAULT_FACE_ID
) == NULL
)
1798 ScreenAttrib
= (initial_screen_colors
[0] << 4) | initial_screen_colors
[1];
1803 if (screen_virtual_segment
)
1804 dosv_refresh_virtual_screen (0, screen_size
);
1805 new_pos_X
= new_pos_Y
= 0;
1809 IT_clear_to_end (void)
1812 fprintf (termscript
, "<CLR:EOS>");
1814 while (new_pos_Y
< screen_size_Y
) {
1816 IT_clear_end_of_line (screen_size_X
);
1822 IT_cursor_to (int y
, int x
)
1825 fprintf (termscript
, "\n<XY=%dx%d>", x
, y
);
1830 static int cursor_cleared
;
1833 IT_display_cursor (int on
)
1836 fprintf (termscript
, "\nCURSOR %s", on
? "ON" : "OFF");
1837 if (on
&& cursor_cleared
)
1839 ScreenSetCursor (current_pos_Y
, current_pos_X
);
1842 else if (!on
&& !cursor_cleared
)
1844 ScreenSetCursor (-1, -1);
1849 /* Emacs calls cursor-movement functions a lot when it updates the
1850 display (probably a legacy of old terminals where you cannot
1851 update a screen line without first moving the cursor there).
1852 However, cursor movement is expensive on MSDOS (it calls a slow
1853 BIOS function and requires 2 mode switches), while actual screen
1854 updates access the video memory directly and don't depend on
1855 cursor position. To avoid slowing down the redisplay, we cheat:
1856 all functions that move the cursor only set internal variables
1857 which record the cursor position, whereas the cursor is only
1858 moved to its final position whenever screen update is complete.
1860 `IT_cmgoto' is called from the keyboard reading loop and when the
1861 frame update is complete. This means that we are ready for user
1862 input, so we update the cursor position to show where the point is,
1863 and also make the mouse pointer visible.
1865 Special treatment is required when the cursor is in the echo area,
1866 to put the cursor at the end of the text displayed there. */
1869 IT_cmgoto (FRAME_PTR f
)
1871 /* Only set the cursor to where it should be if the display is
1872 already in sync with the window contents. */
1873 int update_cursor_pos
= 1; /* MODIFF == unchanged_modified; */
1875 /* FIXME: This needs to be rewritten for the new redisplay, or
1878 static int previous_pos_X
= -1;
1880 update_cursor_pos
= 1; /* temporary!!! */
1882 /* If the display is in sync, forget any previous knowledge about
1883 cursor position. This is primarily for unexpected events like
1884 C-g in the minibuffer. */
1885 if (update_cursor_pos
&& previous_pos_X
>= 0)
1886 previous_pos_X
= -1;
1887 /* If we are in the echo area, put the cursor at the
1888 end of the echo area message. */
1889 if (!update_cursor_pos
1890 && WINDOW_TOP_EDGE_LINE (XWINDOW (FRAME_MINIBUF_WINDOW (f
))) <= new_pos_Y
)
1892 int tem_X
= current_pos_X
, dummy
;
1894 if (echo_area_glyphs
)
1896 tem_X
= echo_area_glyphs_length
;
1897 /* Save current cursor position, to be restored after the
1898 echo area message is erased. Only remember one level
1899 of previous cursor position. */
1900 if (previous_pos_X
== -1)
1901 ScreenGetCursor (&dummy
, &previous_pos_X
);
1903 else if (previous_pos_X
>= 0)
1905 /* We wind up here after the echo area message is erased.
1906 Restore the cursor position we remembered above. */
1907 tem_X
= previous_pos_X
;
1908 previous_pos_X
= -1;
1911 if (current_pos_X
!= tem_X
)
1914 update_cursor_pos
= 1;
1919 if (update_cursor_pos
1920 && (current_pos_X
!= new_pos_X
|| current_pos_Y
!= new_pos_Y
))
1922 ScreenSetCursor (current_pos_Y
= new_pos_Y
, current_pos_X
= new_pos_X
);
1924 fprintf (termscript
, "\n<CURSOR:%dx%d>", current_pos_X
, current_pos_Y
);
1927 /* Maybe cursor is invisible, so make it visible. */
1928 IT_display_cursor (1);
1930 /* Mouse pointer should be always visible if we are waiting for
1937 IT_update_begin (struct frame
*f
)
1939 struct display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
1940 struct frame
*mouse_face_frame
= display_info
->mouse_face_mouse_frame
;
1944 if (f
&& f
== mouse_face_frame
)
1946 /* Don't do highlighting for mouse motion during the update. */
1947 display_info
->mouse_face_defer
= 1;
1949 /* If F needs to be redrawn, simply forget about any prior mouse
1951 if (FRAME_GARBAGED_P (f
))
1952 display_info
->mouse_face_window
= Qnil
;
1954 /* Can we tell that this update does not affect the window
1955 where the mouse highlight is? If so, no need to turn off.
1956 Likewise, don't do anything if none of the enabled rows
1957 contains glyphs highlighted in mouse face. */
1958 if (!NILP (display_info
->mouse_face_window
)
1959 && WINDOWP (display_info
->mouse_face_window
))
1961 struct window
*w
= XWINDOW (display_info
->mouse_face_window
);
1964 /* If the mouse highlight is in the window that was deleted
1965 (e.g., if it was popped by completion), clear highlight
1967 if (NILP (w
->buffer
))
1968 display_info
->mouse_face_window
= Qnil
;
1971 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
1972 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
)
1973 && MATRIX_ROW (w
->current_matrix
, i
)->mouse_face_p
)
1977 if (NILP (w
->buffer
) || i
< w
->desired_matrix
->nrows
)
1978 clear_mouse_face (display_info
);
1981 else if (mouse_face_frame
&& !FRAME_LIVE_P (mouse_face_frame
))
1983 /* If the frame with mouse highlight was deleted, invalidate the
1985 display_info
->mouse_face_beg_row
= display_info
->mouse_face_beg_col
= -1;
1986 display_info
->mouse_face_end_row
= display_info
->mouse_face_end_col
= -1;
1987 display_info
->mouse_face_window
= Qnil
;
1988 display_info
->mouse_face_deferred_gc
= 0;
1989 display_info
->mouse_face_mouse_frame
= NULL
;
1996 IT_update_end (struct frame
*f
)
1998 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
2002 IT_frame_up_to_date (struct frame
*f
)
2004 struct display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2005 Lisp_Object new_cursor
, frame_desired_cursor
;
2008 if (dpyinfo
->mouse_face_deferred_gc
2009 || (f
&& f
== dpyinfo
->mouse_face_mouse_frame
))
2012 if (dpyinfo
->mouse_face_mouse_frame
)
2013 IT_note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
2014 dpyinfo
->mouse_face_mouse_x
,
2015 dpyinfo
->mouse_face_mouse_y
);
2016 dpyinfo
->mouse_face_deferred_gc
= 0;
2020 /* Set the cursor type to whatever they wanted. In a minibuffer
2021 window, we want the cursor to appear only if we are reading input
2022 from this window, and we want the cursor to be taken from the
2023 frame parameters. For the selected window, we use either its
2024 buffer-local value or the value from the frame parameters if the
2025 buffer doesn't define its local value for the cursor type. */
2026 sw
= XWINDOW (f
->selected_window
);
2027 frame_desired_cursor
= Fcdr (Fassq (Qcursor_type
, f
->param_alist
));
2028 if (cursor_in_echo_area
2029 && FRAME_HAS_MINIBUF_P (f
)
2030 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
)
2031 && sw
== XWINDOW (echo_area_window
))
2032 new_cursor
= frame_desired_cursor
;
2035 struct buffer
*b
= XBUFFER (sw
->buffer
);
2037 if (EQ (b
->cursor_type
, Qt
))
2038 new_cursor
= frame_desired_cursor
;
2039 else if (NILP (b
->cursor_type
)) /* nil means no cursor */
2040 new_cursor
= Fcons (Qbar
, make_number (0));
2042 new_cursor
= b
->cursor_type
;
2045 IT_set_cursor_type (f
, new_cursor
);
2047 IT_cmgoto (f
); /* position cursor when update is done */
2050 /* Copy LEN glyphs displayed on a single line whose vertical position
2051 is YPOS, beginning at horizontal position XFROM to horizontal
2052 position XTO, by moving blocks in the video memory. Used by
2053 functions that insert and delete glyphs. */
2055 IT_copy_glyphs (int xfrom
, int xto
, size_t len
, int ypos
)
2057 /* The offsets of source and destination relative to the
2058 conventional memorty selector. */
2059 int from
= 2 * (xfrom
+ screen_size_X
* ypos
) + ScreenPrimary
;
2060 int to
= 2 * (xto
+ screen_size_X
* ypos
) + ScreenPrimary
;
2062 if (from
== to
|| len
<= 0)
2065 _farsetsel (_dos_ds
);
2067 /* The source and destination might overlap, so we need to move
2068 glyphs non-destructively. */
2071 for ( ; len
; from
+= 2, to
+= 2, len
--)
2072 _farnspokew (to
, _farnspeekw (from
));
2076 from
+= (len
- 1) * 2;
2077 to
+= (len
- 1) * 2;
2078 for ( ; len
; from
-= 2, to
-= 2, len
--)
2079 _farnspokew (to
, _farnspeekw (from
));
2081 if (screen_virtual_segment
)
2082 dosv_refresh_virtual_screen (ypos
* screen_size_X
* 2, screen_size_X
);
2085 /* Insert and delete glyphs. */
2087 IT_insert_glyphs (start
, len
)
2088 register struct glyph
*start
;
2091 int shift_by_width
= screen_size_X
- (new_pos_X
+ len
);
2093 /* Shift right the glyphs from the nominal cursor position to the
2094 end of this line. */
2095 IT_copy_glyphs (new_pos_X
, new_pos_X
+ len
, shift_by_width
, new_pos_Y
);
2097 /* Now write the glyphs to be inserted. */
2098 IT_write_glyphs (start
, len
);
2102 IT_delete_glyphs (n
)
2108 /* set-window-configuration on window.c needs this. */
2110 x_set_menu_bar_lines (f
, value
, oldval
)
2112 Lisp_Object value
, oldval
;
2114 set_menu_bar_lines (f
, value
, oldval
);
2117 /* This was copied from xfaces.c */
2119 extern Lisp_Object Qbackground_color
;
2120 extern Lisp_Object Qforeground_color
;
2121 Lisp_Object Qreverse
;
2122 extern Lisp_Object Qtitle
;
2124 /* IT_set_terminal_modes is called when emacs is started,
2125 resumed, and whenever the screen is redrawn! */
2128 IT_set_terminal_modes (void)
2131 fprintf (termscript
, "\n<SET_TERM>");
2133 screen_size_X
= ScreenCols ();
2134 screen_size_Y
= ScreenRows ();
2135 screen_size
= screen_size_X
* screen_size_Y
;
2137 new_pos_X
= new_pos_Y
= 0;
2138 current_pos_X
= current_pos_Y
= -1;
2140 if (term_setup_done
)
2142 term_setup_done
= 1;
2144 startup_screen_size_X
= screen_size_X
;
2145 startup_screen_size_Y
= screen_size_Y
;
2146 startup_screen_attrib
= ScreenAttrib
;
2149 /* Is DOS/V (or any other RSIS software which relocates
2150 the screen) installed? */
2152 unsigned short es_value
;
2155 regs
.h
.ah
= 0xfe; /* get relocated screen address */
2156 if (ScreenPrimary
== 0xb0000UL
|| ScreenPrimary
== 0xb8000UL
)
2157 regs
.x
.es
= (ScreenPrimary
>> 4) & 0xffff;
2158 else if (screen_old_address
) /* already switched to Japanese mode once */
2159 regs
.x
.es
= (screen_old_address
>> 4) & 0xffff;
2161 regs
.x
.es
= ScreenMode () == 7 ? 0xb000 : 0xb800;
2163 es_value
= regs
.x
.es
;
2164 __dpmi_int (0x10, ®s
);
2166 if (regs
.x
.es
!= es_value
)
2168 /* screen_old_address is only set if ScreenPrimary does NOT
2169 already point to the relocated buffer address returned by
2170 the Int 10h/AX=FEh call above. DJGPP v2.02 and later sets
2171 ScreenPrimary to that address at startup under DOS/V. */
2172 if (regs
.x
.es
!= (ScreenPrimary
>> 4) & 0xffff)
2173 screen_old_address
= ScreenPrimary
;
2174 screen_virtual_segment
= regs
.x
.es
;
2175 screen_virtual_offset
= regs
.x
.di
;
2176 ScreenPrimary
= (screen_virtual_segment
<< 4) + screen_virtual_offset
;
2179 #endif /* __DJGPP__ > 1 */
2181 ScreenGetCursor (&startup_pos_Y
, &startup_pos_X
);
2182 ScreenRetrieve (startup_screen_buffer
= xmalloc (screen_size
* 2));
2185 fprintf (termscript
, "<SCREEN SAVED (dimensions=%dx%d)>\n",
2186 screen_size_X
, screen_size_Y
);
2191 /* IT_reset_terminal_modes is called when emacs is
2192 suspended or killed. */
2195 IT_reset_terminal_modes (void)
2197 int display_row_start
= (int) ScreenPrimary
;
2198 int saved_row_len
= startup_screen_size_X
* 2;
2199 int update_row_len
= ScreenCols () * 2, current_rows
= ScreenRows ();
2200 int to_next_row
= update_row_len
;
2201 unsigned char *saved_row
= startup_screen_buffer
;
2202 int cursor_pos_X
= ScreenCols () - 1, cursor_pos_Y
= ScreenRows () - 1;
2205 fprintf (termscript
, "\n<RESET_TERM>");
2207 if (!term_setup_done
)
2212 /* Leave the video system in the same state as we found it,
2213 as far as the blink/bright-background bit is concerned. */
2214 maybe_enable_blinking ();
2216 /* We have a situation here.
2217 We cannot just do ScreenUpdate(startup_screen_buffer) because
2218 the luser could have changed screen dimensions inside Emacs
2219 and failed (or didn't want) to restore them before killing
2220 Emacs. ScreenUpdate() uses the *current* screen dimensions and
2221 thus will happily use memory outside what was allocated for
2222 `startup_screen_buffer'.
2223 Thus we only restore as much as the current screen dimensions
2224 can hold, and clear the rest (if the saved screen is smaller than
2225 the current) with the color attribute saved at startup. The cursor
2226 is also restored within the visible dimensions. */
2228 ScreenAttrib
= startup_screen_attrib
;
2230 /* Don't restore the screen if we are exiting less than 2 seconds
2231 after startup: we might be crashing, and the screen might show
2232 some vital clues to what's wrong. */
2233 if (clock () - startup_time
>= 2*CLOCKS_PER_SEC
)
2236 if (screen_virtual_segment
)
2237 dosv_refresh_virtual_screen (0, screen_size
);
2239 if (update_row_len
> saved_row_len
)
2240 update_row_len
= saved_row_len
;
2241 if (current_rows
> startup_screen_size_Y
)
2242 current_rows
= startup_screen_size_Y
;
2245 fprintf (termscript
, "<SCREEN RESTORED (dimensions=%dx%d)>\n",
2246 update_row_len
/ 2, current_rows
);
2248 while (current_rows
--)
2250 dosmemput (saved_row
, update_row_len
, display_row_start
);
2251 if (screen_virtual_segment
)
2252 dosv_refresh_virtual_screen (display_row_start
- ScreenPrimary
,
2253 update_row_len
/ 2);
2254 saved_row
+= saved_row_len
;
2255 display_row_start
+= to_next_row
;
2258 if (startup_pos_X
< cursor_pos_X
)
2259 cursor_pos_X
= startup_pos_X
;
2260 if (startup_pos_Y
< cursor_pos_Y
)
2261 cursor_pos_Y
= startup_pos_Y
;
2263 ScreenSetCursor (cursor_pos_Y
, cursor_pos_X
);
2264 xfree (startup_screen_buffer
);
2266 term_setup_done
= 0;
2270 IT_set_terminal_window (int foo
)
2274 /* Remember the screen colors of the curent frame, to serve as the
2275 default colors for newly-created frames. */
2276 DEFUN ("msdos-remember-default-colors", Fmsdos_remember_default_colors
,
2277 Smsdos_remember_default_colors
, 1, 1, 0,
2278 doc
: /* Remember the screen colors of the current frame. */)
2284 CHECK_FRAME (frame
);
2287 /* This function is called after applying default-frame-alist to the
2288 initial frame. At that time, if reverse-colors option was
2289 specified in default-frame-alist, it was already applied, and
2290 frame colors are reversed. We need to account for that. */
2291 if (EQ (Fcdr (Fassq (Qreverse
, f
->param_alist
)), Qt
))
2293 initial_screen_colors
[0] = FRAME_BACKGROUND_PIXEL (f
);
2294 initial_screen_colors
[1] = FRAME_FOREGROUND_PIXEL (f
);
2298 initial_screen_colors
[0] = FRAME_FOREGROUND_PIXEL (f
);
2299 initial_screen_colors
[1] = FRAME_BACKGROUND_PIXEL (f
);
2304 IT_set_frame_parameters (f
, alist
)
2309 int i
, j
, length
= XINT (Flength (alist
));
2311 = (Lisp_Object
*) alloca (length
* sizeof (Lisp_Object
));
2313 = (Lisp_Object
*) alloca (length
* sizeof (Lisp_Object
));
2314 /* Do we have to reverse the foreground and background colors? */
2315 int reverse
= EQ (Fcdr (Fassq (Qreverse
, f
->param_alist
)), Qt
);
2316 int need_to_reverse
, was_reverse
= reverse
;
2317 int redraw
= 0, fg_set
= 0, bg_set
= 0;
2318 unsigned long orig_fg
, orig_bg
;
2319 Lisp_Object frame_bg
, frame_fg
;
2320 extern Lisp_Object Qdefault
, QCforeground
, QCbackground
;
2322 /* If we are creating a new frame, begin with the original screen colors
2323 used for the initial frame. */
2324 if (EQ (alist
, Vdefault_frame_alist
)
2325 && initial_screen_colors
[0] != -1 && initial_screen_colors
[1] != -1)
2327 FRAME_FOREGROUND_PIXEL (f
) = initial_screen_colors
[0];
2328 FRAME_BACKGROUND_PIXEL (f
) = initial_screen_colors
[1];
2330 orig_fg
= FRAME_FOREGROUND_PIXEL (f
);
2331 orig_bg
= FRAME_BACKGROUND_PIXEL (f
);
2332 frame_fg
= Fcdr (Fassq (Qforeground_color
, f
->param_alist
));
2333 frame_bg
= Fcdr (Fassq (Qbackground_color
, f
->param_alist
));
2334 /* frame_fg and frame_bg could be nil if, for example,
2335 f->param_alist is nil, e.g. if we are called from
2336 Fmake_terminal_frame. */
2337 if (NILP (frame_fg
))
2338 frame_fg
= build_string (unspecified_fg
);
2339 if (NILP (frame_bg
))
2340 frame_bg
= build_string (unspecified_bg
);
2342 /* Extract parm names and values into those vectors. */
2344 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
2349 parms
[i
] = Fcar (elt
);
2350 CHECK_SYMBOL (parms
[i
]);
2351 values
[i
] = Fcdr (elt
);
2357 for (i
= 0; i
< j
; i
++)
2359 Lisp_Object prop
, val
;
2364 if (EQ (prop
, Qreverse
))
2365 reverse
= EQ (val
, Qt
);
2368 need_to_reverse
= reverse
&& !was_reverse
;
2369 if (termscript
&& need_to_reverse
)
2370 fprintf (termscript
, "<INVERSE-VIDEO>\n");
2372 /* Now process the alist elements in reverse of specified order. */
2373 for (i
--; i
>= 0; i
--)
2375 Lisp_Object prop
, val
, frame
;
2380 if (EQ (prop
, Qforeground_color
))
2382 unsigned long new_color
= load_color (f
, NULL
, val
, need_to_reverse
2383 ? LFACE_BACKGROUND_INDEX
2384 : LFACE_FOREGROUND_INDEX
);
2385 if (new_color
!= FACE_TTY_DEFAULT_COLOR
2386 && new_color
!= FACE_TTY_DEFAULT_FG_COLOR
2387 && new_color
!= FACE_TTY_DEFAULT_BG_COLOR
)
2389 FRAME_FOREGROUND_PIXEL (f
) = new_color
;
2390 /* Make sure the foreground of the default face for this
2391 frame is changed as well. */
2392 XSETFRAME (frame
, f
);
2393 if (need_to_reverse
)
2395 Finternal_set_lisp_face_attribute (Qdefault
, QCbackground
,
2397 prop
= Qbackground_color
;
2402 Finternal_set_lisp_face_attribute (Qdefault
, QCforeground
,
2408 fprintf (termscript
, "<FGCOLOR %lu>\n", new_color
);
2411 else if (EQ (prop
, Qbackground_color
))
2413 unsigned long new_color
= load_color (f
, NULL
, val
, need_to_reverse
2414 ? LFACE_FOREGROUND_INDEX
2415 : LFACE_BACKGROUND_INDEX
);
2416 if (new_color
!= FACE_TTY_DEFAULT_COLOR
2417 && new_color
!= FACE_TTY_DEFAULT_FG_COLOR
2418 && new_color
!= FACE_TTY_DEFAULT_BG_COLOR
)
2420 FRAME_BACKGROUND_PIXEL (f
) = new_color
;
2421 /* Make sure the background of the default face for this
2422 frame is changed as well. */
2423 XSETFRAME (frame
, f
);
2424 if (need_to_reverse
)
2426 Finternal_set_lisp_face_attribute (Qdefault
, QCforeground
,
2428 prop
= Qforeground_color
;
2433 Finternal_set_lisp_face_attribute (Qdefault
, QCbackground
,
2439 fprintf (termscript
, "<BGCOLOR %lu>\n", new_color
);
2442 else if (EQ (prop
, Qtitle
))
2444 x_set_title (f
, val
);
2446 fprintf (termscript
, "<TITLE: %s>\n", SDATA (val
));
2448 else if (EQ (prop
, Qcursor_type
))
2450 IT_set_cursor_type (f
, val
);
2452 fprintf (termscript
, "<CTYPE: %s>\n",
2453 EQ (val
, Qbar
) || EQ (val
, Qhbar
)
2454 || CONSP (val
) && (EQ (XCAR (val
), Qbar
)
2455 || EQ (XCAR (val
), Qhbar
))
2458 store_frame_param (f
, prop
, val
);
2461 /* If they specified "reverse", but not the colors, we need to swap
2462 the current frame colors. */
2463 if (need_to_reverse
)
2469 XSETFRAME (frame
, f
);
2470 Finternal_set_lisp_face_attribute (Qdefault
, QCforeground
,
2471 tty_color_name (f
, orig_bg
),
2477 XSETFRAME (frame
, f
);
2478 Finternal_set_lisp_face_attribute (Qdefault
, QCbackground
,
2479 tty_color_name (f
, orig_fg
),
2487 face_change_count
++; /* forces xdisp.c to recompute basic faces */
2488 if (f
== SELECTED_FRAME())
2493 extern void init_frame_faces (FRAME_PTR
);
2495 #endif /* !HAVE_X_WINDOWS */
2498 /* Do we need the internal terminal? */
2501 internal_terminal_init ()
2503 char *term
= getenv ("TERM"), *colors
;
2504 struct frame
*sf
= SELECTED_FRAME();
2506 #ifdef HAVE_X_WINDOWS
2507 if (!inhibit_window_system
)
2512 = (!noninteractive
) && term
&& !strcmp (term
, "internal");
2514 if (getenv ("EMACSTEST"))
2515 termscript
= fopen (getenv ("EMACSTEST"), "wt");
2517 #ifndef HAVE_X_WINDOWS
2518 if (!internal_terminal
|| inhibit_window_system
)
2520 sf
->output_method
= output_termcap
;
2524 Vwindow_system
= intern ("pc");
2525 Vwindow_system_version
= make_number (1);
2526 sf
->output_method
= output_msdos_raw
;
2528 /* If Emacs was dumped on DOS/V machine, forget the stale VRAM address. */
2529 screen_old_address
= 0;
2531 /* Forget the stale screen colors as well. */
2532 initial_screen_colors
[0] = initial_screen_colors
[1] = -1;
2534 bzero (&the_only_x_display
, sizeof the_only_x_display
);
2535 FRAME_BACKGROUND_PIXEL (SELECTED_FRAME ()) = 7; /* White */
2536 FRAME_FOREGROUND_PIXEL (SELECTED_FRAME ()) = 0; /* Black */
2538 colors
= getenv ("EMACSCOLORS");
2539 if (colors
&& strlen (colors
) >= 2)
2541 /* The colors use 4 bits each (we enable bright background). */
2542 if (isdigit (colors
[0]))
2544 else if (isxdigit (colors
[0]))
2545 colors
[0] -= (isupper (colors
[0]) ? 'A' : 'a') - 10;
2546 if (colors
[0] >= 0 && colors
[0] < 16)
2547 FRAME_FOREGROUND_PIXEL (SELECTED_FRAME ()) = colors
[0];
2548 if (isdigit (colors
[1]))
2550 else if (isxdigit (colors
[1]))
2551 colors
[1] -= (isupper (colors
[1]) ? 'A' : 'a') - 10;
2552 if (colors
[1] >= 0 && colors
[1] < 16)
2553 FRAME_BACKGROUND_PIXEL (SELECTED_FRAME ()) = colors
[1];
2555 the_only_x_display
.font
= (XFontStruct
*)1; /* must *not* be zero */
2556 the_only_x_display
.display_info
.mouse_face_mouse_frame
= NULL
;
2557 the_only_x_display
.display_info
.mouse_face_deferred_gc
= 0;
2558 the_only_x_display
.display_info
.mouse_face_beg_row
=
2559 the_only_x_display
.display_info
.mouse_face_beg_col
= -1;
2560 the_only_x_display
.display_info
.mouse_face_end_row
=
2561 the_only_x_display
.display_info
.mouse_face_end_col
= -1;
2562 the_only_x_display
.display_info
.mouse_face_face_id
= DEFAULT_FACE_ID
;
2563 the_only_x_display
.display_info
.mouse_face_window
= Qnil
;
2564 the_only_x_display
.display_info
.mouse_face_mouse_x
=
2565 the_only_x_display
.display_info
.mouse_face_mouse_y
= 0;
2566 the_only_x_display
.display_info
.mouse_face_defer
= 0;
2567 the_only_x_display
.display_info
.mouse_face_hidden
= 0;
2569 init_frame_faces (sf
);
2571 ring_bell_hook
= IT_ring_bell
;
2572 insert_glyphs_hook
= IT_insert_glyphs
;
2573 delete_glyphs_hook
= IT_delete_glyphs
;
2574 write_glyphs_hook
= IT_write_glyphs
;
2575 cursor_to_hook
= raw_cursor_to_hook
= IT_cursor_to
;
2576 clear_to_end_hook
= IT_clear_to_end
;
2577 clear_end_of_line_hook
= IT_clear_end_of_line
;
2578 clear_frame_hook
= IT_clear_screen
;
2579 update_begin_hook
= IT_update_begin
;
2580 update_end_hook
= IT_update_end
;
2581 frame_up_to_date_hook
= IT_frame_up_to_date
;
2583 /* These hooks are called by term.c without being checked. */
2584 set_terminal_modes_hook
= IT_set_terminal_modes
;
2585 reset_terminal_modes_hook
= IT_reset_terminal_modes
;
2586 set_terminal_window_hook
= IT_set_terminal_window
;
2587 TTY_CHAR_INS_DEL_OK (CURTTY ()) = 0;
2591 dos_get_saved_screen (screen
, rows
, cols
)
2596 #ifndef HAVE_X_WINDOWS
2597 *screen
= startup_screen_buffer
;
2598 *cols
= startup_screen_size_X
;
2599 *rows
= startup_screen_size_Y
;
2600 return *screen
!= (char *)0;
2606 #ifndef HAVE_X_WINDOWS
2608 /* We are not X, but we can emulate it well enough for our needs... */
2612 if (! FRAME_MSDOS_P (SELECTED_FRAME()))
2613 error ("Not running under a window system");
2619 /* ----------------------- Keyboard control ----------------------
2621 * Keymaps reflect the following keyboard layout:
2623 * 0 1 2 3 4 5 6 7 8 9 10 11 12 BS
2624 * TAB 15 16 17 18 19 20 21 22 23 24 25 26 (41)
2625 * CLOK 30 31 32 33 34 35 36 37 38 39 40 (41) RET
2626 * SH () 45 46 47 48 49 50 51 52 53 54 SHIFT
2630 #define Ignore 0x0000
2631 #define Normal 0x0000 /* normal key - alt changes scan-code */
2632 #define FctKey 0x1000 /* func key if c == 0, else c */
2633 #define Special 0x2000 /* func key even if c != 0 */
2634 #define ModFct 0x3000 /* special if mod-keys, else 'c' */
2635 #define Map 0x4000 /* alt scan-code, map to unshift/shift key */
2636 #define KeyPad 0x5000 /* map to insert/kp-0 depending on c == 0xe0 */
2637 #define Grey 0x6000 /* Grey keypad key */
2639 #define Alt 0x0100 /* alt scan-code */
2640 #define Ctrl 0x0200 /* ctrl scan-code */
2641 #define Shift 0x0400 /* shift scan-code */
2643 static int extended_kbd
; /* 101 (102) keyboard present. */
2645 struct kbd_translate
{
2648 unsigned short code
;
2651 struct dos_keyboard_map
2656 struct kbd_translate
*translate_table
;
2660 static struct dos_keyboard_map us_keyboard
= {
2662 /* 01234567890123456789012345678901234567890 12345678901234 */
2663 "`1234567890-= qwertyuiop[] asdfghjkl;'\\ zxcvbnm,./ ",
2664 /* 0123456789012345678901234567890123456789 012345678901234 */
2665 "~!@#$%^&*()_+ QWERTYUIOP{} ASDFGHJKL:\"| ZXCVBNM<>? ",
2666 0, /* no Alt-Gr key */
2667 0 /* no translate table */
2670 static struct dos_keyboard_map fr_keyboard
= {
2672 /* 012 3456789012345678901234567890123456789012345678901234 */
2673 "ý&‚\",(-Š_€…)= azertyuiop^$ qsdfghjklm—* wxcvbnm;:! ",
2674 /* 0123456789012345678901234567890123456789012345678901234 */
2675 " 1234567890ø+ AZERTYUIOPùœ QSDFGHJKLM%æ WXCVBN?./õ ",
2676 /* 01234567 89012345678901234567890123456789012345678901234 */
2678 0 /* no translate table */
2682 * Italian keyboard support, country code 39.
2685 * added also {,},` as, respectively, AltGr-8, AltGr-9, AltGr-'
2686 * Donated by Stefano Brozzi <brozzis@mag00.cedi.unipr.it>
2689 static struct kbd_translate it_kbd_translate_table
[] = {
2690 { 0x56, 0x3c, Normal
| 13 },
2691 { 0x56, 0x3e, Normal
| 27 },
2694 static struct dos_keyboard_map it_keyboard
= {
2696 /* 0 123456789012345678901234567890123456789012345678901234 */
2697 "\\1234567890'�< qwertyuiopŠ+> asdfghjkl•…— zxcvbnm,.- ",
2698 /* 01 23456789012345678901234567890123456789012345678901234 */
2699 "|!\"œ$%&/()=?^> QWERTYUIOP‚* ASDFGHJKL‡øõ ZXCVBNM;:_ ",
2700 /* 0123456789012345678901234567890123456789012345678901234 */
2702 it_kbd_translate_table
2705 static struct dos_keyboard_map dk_keyboard
= {
2707 /* 0123456789012345678901234567890123456789012345678901234 */
2708 "«1234567890+| qwertyuiop†~ asdfghjkl‘›' zxcvbnm,.- ",
2709 /* 01 23456789012345678901234567890123456789012345678901234 */
2710 "õ!\"#$%&/()=?` QWERTYUIOP�^ ASDFGHJKL’�* ZXCVBNM;:_ ",
2711 /* 0123456789012345678901234567890123456789012345678901234 */
2713 0 /* no translate table */
2716 static struct kbd_translate jp_kbd_translate_table
[] = {
2717 { 0x73, 0x5c, Normal
| 0 },
2718 { 0x73, 0x5f, Normal
| 0 },
2719 { 0x73, 0x1c, Map
| 0 },
2720 { 0x7d, 0x5c, Normal
| 13 },
2721 { 0x7d, 0x7c, Normal
| 13 },
2722 { 0x7d, 0x1c, Map
| 13 },
2725 static struct dos_keyboard_map jp_keyboard
= {
2727 /* 0123456789012 345678901234567890123456789012345678901234 */
2728 "\\1234567890-^\\ qwertyuiop@[ asdfghjkl;:] zxcvbnm,./ ",
2729 /* 01 23456789012345678901234567890123456789012345678901234 */
2730 "_!\"#$%&'()~=~| QWERTYUIOP`{ ASDFGHJKL+*} ZXCVBNM<>? ",
2731 0, /* no Alt-Gr key */
2732 jp_kbd_translate_table
2735 static struct keyboard_layout_list
2738 struct dos_keyboard_map
*keyboard_map
;
2739 } keyboard_layout_list
[] =
2748 static struct dos_keyboard_map
*keyboard
;
2749 static int keyboard_map_all
;
2750 static int international_keyboard
;
2753 dos_set_keyboard (code
, always
)
2758 _go32_dpmi_registers regs
;
2760 /* See if Keyb.Com is installed (for international keyboard support).
2761 Note: calling Int 2Fh via int86 wedges the DOS box on some versions
2762 of Windows 9X! So don't do that! */
2764 regs
.x
.ss
= regs
.x
.sp
= regs
.x
.flags
= 0;
2765 _go32_dpmi_simulate_int (0x2f, ®s
);
2766 if (regs
.h
.al
== 0xff)
2767 international_keyboard
= 1;
2769 /* Initialize to US settings, for countries that don't have their own. */
2770 keyboard
= keyboard_layout_list
[0].keyboard_map
;
2771 keyboard_map_all
= always
;
2772 dos_keyboard_layout
= 1;
2774 for (i
= 0; i
< (sizeof (keyboard_layout_list
)/sizeof (struct keyboard_layout_list
)); i
++)
2775 if (code
== keyboard_layout_list
[i
].country_code
)
2777 keyboard
= keyboard_layout_list
[i
].keyboard_map
;
2778 keyboard_map_all
= always
;
2779 dos_keyboard_layout
= code
;
2787 unsigned char char_code
; /* normal code */
2788 unsigned char meta_code
; /* M- code */
2789 unsigned char keypad_code
; /* keypad code */
2790 unsigned char editkey_code
; /* edit key */
2791 } keypad_translate_map
[] = {
2792 '0', '0', 0xb0, /* kp-0 */ 0x63, /* insert */
2793 '1', '1', 0xb1, /* kp-1 */ 0x57, /* end */
2794 '2', '2', 0xb2, /* kp-2 */ 0x54, /* down */
2795 '3', '3', 0xb3, /* kp-3 */ 0x56, /* next */
2796 '4', '4', 0xb4, /* kp-4 */ 0x51, /* left */
2797 '5', '5', 0xb5, /* kp-5 */ 0xb5, /* kp-5 */
2798 '6', '6', 0xb6, /* kp-6 */ 0x53, /* right */
2799 '7', '7', 0xb7, /* kp-7 */ 0x50, /* home */
2800 '8', '8', 0xb8, /* kp-8 */ 0x52, /* up */
2801 '9', '9', 0xb9, /* kp-9 */ 0x55, /* prior */
2802 '.', '-', 0xae, /* kp-decimal */ 0xff /* delete */
2807 unsigned char char_code
; /* normal code */
2808 unsigned char keypad_code
; /* keypad code */
2809 } grey_key_translate_map
[] = {
2810 '/', 0xaf, /* kp-decimal */
2811 '*', 0xaa, /* kp-multiply */
2812 '-', 0xad, /* kp-subtract */
2813 '+', 0xab, /* kp-add */
2814 '\r', 0x8d /* kp-enter */
2817 static unsigned short
2818 ibmpc_translate_map
[] =
2820 /* --------------- 00 to 0f --------------- */
2821 Normal
| 0xff, /* Ctrl Break + Alt-NNN */
2822 Alt
| ModFct
| 0x1b, /* Escape */
2823 Normal
| 1, /* '1' */
2824 Normal
| 2, /* '2' */
2825 Normal
| 3, /* '3' */
2826 Normal
| 4, /* '4' */
2827 Normal
| 5, /* '5' */
2828 Normal
| 6, /* '6' */
2829 Normal
| 7, /* '7' */
2830 Normal
| 8, /* '8' */
2831 Normal
| 9, /* '9' */
2832 Normal
| 10, /* '0' */
2833 Normal
| 11, /* '-' */
2834 Normal
| 12, /* '=' */
2835 Special
| 0x08, /* Backspace */
2836 ModFct
| 0x74, /* Tab/Backtab */
2838 /* --------------- 10 to 1f --------------- */
2851 ModFct
| 0x0d, /* Return */
2856 /* --------------- 20 to 2f --------------- */
2865 Map
| 40, /* '\'' */
2867 Ignore
, /* Left shift */
2868 Map
| 41, /* '\\' */
2874 /* --------------- 30 to 3f --------------- */
2881 Ignore
, /* Right shift */
2882 Grey
| 1, /* Grey * */
2884 Normal
| 55, /* ' ' */
2885 Ignore
, /* Caps Lock */
2886 FctKey
| 0xbe, /* F1 */
2887 FctKey
| 0xbf, /* F2 */
2888 FctKey
| 0xc0, /* F3 */
2889 FctKey
| 0xc1, /* F4 */
2890 FctKey
| 0xc2, /* F5 */
2892 /* --------------- 40 to 4f --------------- */
2893 FctKey
| 0xc3, /* F6 */
2894 FctKey
| 0xc4, /* F7 */
2895 FctKey
| 0xc5, /* F8 */
2896 FctKey
| 0xc6, /* F9 */
2897 FctKey
| 0xc7, /* F10 */
2898 Ignore
, /* Num Lock */
2899 Ignore
, /* Scroll Lock */
2900 KeyPad
| 7, /* Home */
2901 KeyPad
| 8, /* Up */
2902 KeyPad
| 9, /* Page Up */
2903 Grey
| 2, /* Grey - */
2904 KeyPad
| 4, /* Left */
2905 KeyPad
| 5, /* Keypad 5 */
2906 KeyPad
| 6, /* Right */
2907 Grey
| 3, /* Grey + */
2908 KeyPad
| 1, /* End */
2910 /* --------------- 50 to 5f --------------- */
2911 KeyPad
| 2, /* Down */
2912 KeyPad
| 3, /* Page Down */
2913 KeyPad
| 0, /* Insert */
2914 KeyPad
| 10, /* Delete */
2915 Shift
| FctKey
| 0xbe, /* (Shift) F1 */
2916 Shift
| FctKey
| 0xbf, /* (Shift) F2 */
2917 Shift
| FctKey
| 0xc0, /* (Shift) F3 */
2918 Shift
| FctKey
| 0xc1, /* (Shift) F4 */
2919 Shift
| FctKey
| 0xc2, /* (Shift) F5 */
2920 Shift
| FctKey
| 0xc3, /* (Shift) F6 */
2921 Shift
| FctKey
| 0xc4, /* (Shift) F7 */
2922 Shift
| FctKey
| 0xc5, /* (Shift) F8 */
2923 Shift
| FctKey
| 0xc6, /* (Shift) F9 */
2924 Shift
| FctKey
| 0xc7, /* (Shift) F10 */
2925 Ctrl
| FctKey
| 0xbe, /* (Ctrl) F1 */
2926 Ctrl
| FctKey
| 0xbf, /* (Ctrl) F2 */
2928 /* --------------- 60 to 6f --------------- */
2929 Ctrl
| FctKey
| 0xc0, /* (Ctrl) F3 */
2930 Ctrl
| FctKey
| 0xc1, /* (Ctrl) F4 */
2931 Ctrl
| FctKey
| 0xc2, /* (Ctrl) F5 */
2932 Ctrl
| FctKey
| 0xc3, /* (Ctrl) F6 */
2933 Ctrl
| FctKey
| 0xc4, /* (Ctrl) F7 */
2934 Ctrl
| FctKey
| 0xc5, /* (Ctrl) F8 */
2935 Ctrl
| FctKey
| 0xc6, /* (Ctrl) F9 */
2936 Ctrl
| FctKey
| 0xc7, /* (Ctrl) F10 */
2937 Alt
| FctKey
| 0xbe, /* (Alt) F1 */
2938 Alt
| FctKey
| 0xbf, /* (Alt) F2 */
2939 Alt
| FctKey
| 0xc0, /* (Alt) F3 */
2940 Alt
| FctKey
| 0xc1, /* (Alt) F4 */
2941 Alt
| FctKey
| 0xc2, /* (Alt) F5 */
2942 Alt
| FctKey
| 0xc3, /* (Alt) F6 */
2943 Alt
| FctKey
| 0xc4, /* (Alt) F7 */
2944 Alt
| FctKey
| 0xc5, /* (Alt) F8 */
2946 /* --------------- 70 to 7f --------------- */
2947 Alt
| FctKey
| 0xc6, /* (Alt) F9 */
2948 Alt
| FctKey
| 0xc7, /* (Alt) F10 */
2949 Ctrl
| FctKey
| 0x6d, /* (Ctrl) Sys Rq */
2950 Ctrl
| KeyPad
| 4, /* (Ctrl) Left */
2951 Ctrl
| KeyPad
| 6, /* (Ctrl) Right */
2952 Ctrl
| KeyPad
| 1, /* (Ctrl) End */
2953 Ctrl
| KeyPad
| 3, /* (Ctrl) Page Down */
2954 Ctrl
| KeyPad
| 7, /* (Ctrl) Home */
2955 Alt
| Map
| 1, /* '1' */
2956 Alt
| Map
| 2, /* '2' */
2957 Alt
| Map
| 3, /* '3' */
2958 Alt
| Map
| 4, /* '4' */
2959 Alt
| Map
| 5, /* '5' */
2960 Alt
| Map
| 6, /* '6' */
2961 Alt
| Map
| 7, /* '7' */
2962 Alt
| Map
| 8, /* '8' */
2964 /* --------------- 80 to 8f --------------- */
2965 Alt
| Map
| 9, /* '9' */
2966 Alt
| Map
| 10, /* '0' */
2967 Alt
| Map
| 11, /* '-' */
2968 Alt
| Map
| 12, /* '=' */
2969 Ctrl
| KeyPad
| 9, /* (Ctrl) Page Up */
2970 FctKey
| 0xc8, /* F11 */
2971 FctKey
| 0xc9, /* F12 */
2972 Shift
| FctKey
| 0xc8, /* (Shift) F11 */
2973 Shift
| FctKey
| 0xc9, /* (Shift) F12 */
2974 Ctrl
| FctKey
| 0xc8, /* (Ctrl) F11 */
2975 Ctrl
| FctKey
| 0xc9, /* (Ctrl) F12 */
2976 Alt
| FctKey
| 0xc8, /* (Alt) F11 */
2977 Alt
| FctKey
| 0xc9, /* (Alt) F12 */
2978 Ctrl
| KeyPad
| 8, /* (Ctrl) Up */
2979 Ctrl
| Grey
| 2, /* (Ctrl) Grey - */
2980 Ctrl
| KeyPad
| 5, /* (Ctrl) Keypad 5 */
2982 /* --------------- 90 to 9f --------------- */
2983 Ctrl
| Grey
| 3, /* (Ctrl) Grey + */
2984 Ctrl
| KeyPad
| 2, /* (Ctrl) Down */
2985 Ctrl
| KeyPad
| 0, /* (Ctrl) Insert */
2986 Ctrl
| KeyPad
| 10, /* (Ctrl) Delete */
2987 Ctrl
| FctKey
| 0x09, /* (Ctrl) Tab */
2988 Ctrl
| Grey
| 0, /* (Ctrl) Grey / */
2989 Ctrl
| Grey
| 1, /* (Ctrl) Grey * */
2990 Alt
| FctKey
| 0x50, /* (Alt) Home */
2991 Alt
| FctKey
| 0x52, /* (Alt) Up */
2992 Alt
| FctKey
| 0x55, /* (Alt) Page Up */
2993 Ignore
, /* NO KEY */
2994 Alt
| FctKey
| 0x51, /* (Alt) Left */
2995 Ignore
, /* NO KEY */
2996 Alt
| FctKey
| 0x53, /* (Alt) Right */
2997 Ignore
, /* NO KEY */
2998 Alt
| FctKey
| 0x57, /* (Alt) End */
3000 /* --------------- a0 to af --------------- */
3001 Alt
| KeyPad
| 2, /* (Alt) Down */
3002 Alt
| KeyPad
| 3, /* (Alt) Page Down */
3003 Alt
| KeyPad
| 0, /* (Alt) Insert */
3004 Alt
| KeyPad
| 10, /* (Alt) Delete */
3005 Alt
| Grey
| 0, /* (Alt) Grey / */
3006 Alt
| FctKey
| 0x09, /* (Alt) Tab */
3007 Alt
| Grey
| 4 /* (Alt) Keypad Enter */
3010 /* These bit-positions corresponds to values returned by BIOS */
3011 #define SHIFT_P 0x0003 /* two bits! */
3012 #define CTRL_P 0x0004
3013 #define ALT_P 0x0008
3014 #define SCRLOCK_P 0x0010
3015 #define NUMLOCK_P 0x0020
3016 #define CAPSLOCK_P 0x0040
3017 #define ALT_GR_P 0x0800
3018 #define SUPER_P 0x4000 /* pseudo */
3019 #define HYPER_P 0x8000 /* pseudo */
3022 dos_get_modifiers (keymask
)
3026 int mask
, modifiers
= 0;
3028 /* Calculate modifier bits */
3029 regs
.h
.ah
= extended_kbd
? 0x12 : 0x02;
3030 int86 (0x16, ®s
, ®s
);
3034 mask
= regs
.h
.al
& (SHIFT_P
| CTRL_P
| ALT_P
|
3035 SCRLOCK_P
| NUMLOCK_P
| CAPSLOCK_P
);
3039 mask
= regs
.h
.al
& (SHIFT_P
|
3040 SCRLOCK_P
| NUMLOCK_P
| CAPSLOCK_P
);
3042 /* Do not break international keyboard support. */
3043 /* When Keyb.Com is loaded, the right Alt key is */
3044 /* used for accessing characters like { and } */
3045 if (regs
.h
.ah
& 2) /* Left ALT pressed ? */
3048 if ((regs
.h
.ah
& 8) != 0) /* Right ALT pressed ? */
3051 if (dos_hyper_key
== 1)
3054 modifiers
|= hyper_modifier
;
3056 else if (dos_super_key
== 1)
3059 modifiers
|= super_modifier
;
3061 else if (!international_keyboard
)
3063 /* If Keyb.Com is NOT installed, let Right Alt behave
3064 like the Left Alt. */
3070 if (regs
.h
.ah
& 1) /* Left CTRL pressed ? */
3073 if (regs
.h
.ah
& 4) /* Right CTRL pressed ? */
3075 if (dos_hyper_key
== 2)
3078 modifiers
|= hyper_modifier
;
3080 else if (dos_super_key
== 2)
3083 modifiers
|= super_modifier
;
3091 modifiers
|= shift_modifier
;
3093 modifiers
|= ctrl_modifier
;
3095 modifiers
|= meta_modifier
;
3102 #define NUM_RECENT_DOSKEYS (100)
3103 int recent_doskeys_index
; /* Index for storing next element into recent_doskeys */
3104 int total_doskeys
; /* Total number of elements stored into recent_doskeys */
3105 Lisp_Object recent_doskeys
; /* A vector, holding the last 100 keystrokes */
3107 DEFUN ("recent-doskeys", Frecent_doskeys
, Srecent_doskeys
, 0, 0, 0,
3108 doc
: /* Return vector of last 100 keyboard input values seen in dos_rawgetc.
3109 Each input key receives two values in this vector: first the ASCII code,
3110 and then the scan code. */)
3113 Lisp_Object val
, *keys
= XVECTOR (recent_doskeys
)->contents
;
3115 if (total_doskeys
< NUM_RECENT_DOSKEYS
)
3116 return Fvector (total_doskeys
, keys
);
3119 val
= Fvector (NUM_RECENT_DOSKEYS
, keys
);
3120 bcopy (keys
+ recent_doskeys_index
,
3121 XVECTOR (val
)->contents
,
3122 (NUM_RECENT_DOSKEYS
- recent_doskeys_index
) * sizeof (Lisp_Object
));
3124 XVECTOR (val
)->contents
+ NUM_RECENT_DOSKEYS
- recent_doskeys_index
,
3125 recent_doskeys_index
* sizeof (Lisp_Object
));
3130 /* Get a char from keyboard. Function keys are put into the event queue. */
3134 struct input_event event
;
3136 struct display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (SELECTED_FRAME());
3139 #ifndef HAVE_X_WINDOWS
3140 /* Maybe put the cursor where it should be. */
3141 IT_cmgoto (SELECTED_FRAME());
3144 /* The following condition is equivalent to `kbhit ()', except that
3145 it uses the bios to do its job. This pleases DESQview/X. */
3146 while ((regs
.h
.ah
= extended_kbd
? 0x11 : 0x01),
3147 int86 (0x16, ®s
, ®s
),
3148 (regs
.x
.flags
& 0x40) == 0)
3151 register unsigned char c
;
3152 int modifiers
, sc
, code
= -1, mask
, kp_mode
;
3154 regs
.h
.ah
= extended_kbd
? 0x10 : 0x00;
3155 int86 (0x16, ®s
, ®s
);
3160 XVECTOR (recent_doskeys
)->contents
[recent_doskeys_index
++]
3162 if (recent_doskeys_index
== NUM_RECENT_DOSKEYS
)
3163 recent_doskeys_index
= 0;
3164 XVECTOR (recent_doskeys
)->contents
[recent_doskeys_index
++]
3166 if (recent_doskeys_index
== NUM_RECENT_DOSKEYS
)
3167 recent_doskeys_index
= 0;
3169 modifiers
= dos_get_modifiers (&mask
);
3171 #ifndef HAVE_X_WINDOWS
3172 if (!NILP (Vdos_display_scancodes
))
3175 sprintf (buf
, "%02x:%02x*%04x",
3176 (unsigned) (sc
&0xff), (unsigned) c
, mask
);
3177 dos_direct_output (screen_size_Y
- 2, screen_size_X
- 12, buf
, 10);
3185 case 10: /* Ctrl Grey Enter */
3186 code
= Ctrl
| Grey
| 4;
3188 case 13: /* Grey Enter */
3191 case '/': /* Grey / */
3201 /* Try the keyboard-private translation table first. */
3202 if (keyboard
->translate_table
)
3204 struct kbd_translate
*p
= keyboard
->translate_table
;
3208 if (p
->sc
== sc
&& p
->ch
== c
)
3216 /* If the private table didn't translate it, use the general
3220 if (sc
>= (sizeof (ibmpc_translate_map
) / sizeof (short)))
3222 if ((code
= ibmpc_translate_map
[sc
]) == Ignore
)
3229 /* We only look at the keyboard Ctrl/Shift/Alt keys when
3230 Emacs is ready to read a key. Therefore, if they press
3231 `Alt-x' when Emacs is busy, by the time we get to
3232 `dos_get_modifiers', they might have already released the
3233 Alt key, and Emacs gets just `x', which is BAD.
3234 However, for keys with the `Map' property set, the ASCII
3235 code returns zero only if Alt is pressed. So, when we DON'T
3236 have to support international_keyboard, we don't have to
3237 distinguish between the left and right Alt keys, and we
3238 can set the META modifier for any keys with the `Map'
3239 property if they return zero ASCII code (c = 0). */
3241 || ( (code
& 0xf000) == Map
&& !international_keyboard
))
3242 modifiers
|= meta_modifier
;
3244 modifiers
|= ctrl_modifier
;
3246 modifiers
|= shift_modifier
;
3249 switch (code
& 0xf000)
3252 if (c
&& !(mask
& (SHIFT_P
| ALT_P
| CTRL_P
| HYPER_P
| SUPER_P
)))
3254 c
= 0; /* Special */
3267 if (c
== 0) /* ctrl-break */
3269 return c
; /* ALT-nnn */
3271 if (!keyboard_map_all
)
3280 if (c
&& !(mask
& ALT_P
) && !((mask
& SHIFT_P
) && (mask
& CTRL_P
)))
3281 if (!keyboard_map_all
)
3285 if (mask
& ALT_P
&& code
<= 10 && code
> 0 && dos_keypad_mode
& 0x200)
3286 mask
|= SHIFT_P
; /* ALT-1 => M-! etc. */
3290 code
= keyboard
->shifted
[code
];
3292 modifiers
&= ~shift_modifier
;
3295 if ((mask
& ALT_GR_P
) && keyboard
->alt_gr
&& keyboard
->alt_gr
[code
] != ' ')
3296 code
= keyboard
->alt_gr
[code
];
3298 code
= keyboard
->unshifted
[code
];
3303 if (c
== 0xe0) /* edit key */
3306 if ((mask
& (NUMLOCK_P
|CTRL_P
|SHIFT_P
|ALT_P
)) == NUMLOCK_P
) /* numlock on */
3307 kp_mode
= dos_keypad_mode
& 0x03;
3309 kp_mode
= (dos_keypad_mode
>> 4) & 0x03;
3314 if (code
== 10 && dos_decimal_point
)
3315 return dos_decimal_point
;
3316 return keypad_translate_map
[code
].char_code
;
3319 code
= 0xff00 | keypad_translate_map
[code
].keypad_code
;
3323 code
= keypad_translate_map
[code
].meta_code
;
3324 modifiers
= meta_modifier
;
3328 code
= 0xff00 | keypad_translate_map
[code
].editkey_code
;
3335 kp_mode
= ((mask
& (NUMLOCK_P
|CTRL_P
|SHIFT_P
|ALT_P
)) == NUMLOCK_P
) ? 0x04 : 0x40;
3336 if (dos_keypad_mode
& kp_mode
)
3337 code
= 0xff00 | grey_key_translate_map
[code
].keypad_code
;
3339 code
= grey_key_translate_map
[code
].char_code
;
3347 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
))
3349 clear_mouse_face (dpyinfo
);
3350 dpyinfo
->mouse_face_hidden
= 1;
3354 event
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
3356 event
.kind
= ASCII_KEYSTROKE_EVENT
;
3358 event
.modifiers
= modifiers
;
3359 event
.frame_or_window
= selected_frame
;
3361 event
.timestamp
= event_timestamp ();
3362 kbd_buffer_store_event (&event
);
3365 if (have_mouse
> 0 && !mouse_preempted
)
3367 int but
, press
, x
, y
, ok
;
3368 int mouse_prev_x
= mouse_last_x
, mouse_prev_y
= mouse_last_y
;
3369 Lisp_Object mouse_window
= Qnil
;
3371 /* Check for mouse movement *before* buttons. */
3372 mouse_check_moved ();
3374 /* If the mouse moved from the spot of its last sighting, we
3375 might need to update mouse highlight. */
3376 if (mouse_last_x
!= mouse_prev_x
|| mouse_last_y
!= mouse_prev_y
)
3378 if (dpyinfo
->mouse_face_hidden
)
3380 dpyinfo
->mouse_face_hidden
= 0;
3381 clear_mouse_face (dpyinfo
);
3384 /* Generate SELECT_WINDOW_EVENTs when needed. */
3385 if (!NILP (Vmouse_autoselect_window
))
3387 mouse_window
= window_from_coordinates (SELECTED_FRAME(),
3391 /* A window will be selected only when it is not
3392 selected now, and the last mouse movement event was
3393 not in it. A minibuffer window will be selected iff
3395 if (WINDOWP (mouse_window
)
3396 && !EQ (mouse_window
, last_mouse_window
)
3397 && !EQ (mouse_window
, selected_window
))
3399 event
.kind
= SELECT_WINDOW_EVENT
;
3400 event
.frame_or_window
= mouse_window
;
3402 event
.timestamp
= event_timestamp ();
3403 kbd_buffer_store_event (&event
);
3405 last_mouse_window
= mouse_window
;
3408 last_mouse_window
= Qnil
;
3410 previous_help_echo_string
= help_echo_string
;
3411 help_echo_string
= help_echo_object
= help_echo_window
= Qnil
;
3413 IT_note_mouse_highlight (SELECTED_FRAME(),
3414 mouse_last_x
, mouse_last_y
);
3415 /* If the contents of the global variable help_echo has
3416 changed, generate a HELP_EVENT. */
3417 if (!NILP (help_echo_string
) || !NILP (previous_help_echo_string
))
3419 event
.kind
= HELP_EVENT
;
3420 event
.frame_or_window
= selected_frame
;
3421 event
.arg
= help_echo_object
;
3422 event
.x
= WINDOWP (help_echo_window
)
3423 ? help_echo_window
: selected_frame
;
3424 event
.y
= help_echo_string
;
3425 event
.timestamp
= event_timestamp ();
3426 event
.code
= help_echo_pos
;
3427 kbd_buffer_store_event (&event
);
3431 for (but
= 0; but
< NUM_MOUSE_BUTTONS
; but
++)
3432 for (press
= 0; press
< 2; press
++)
3434 int button_num
= but
;
3437 ok
= mouse_pressed (but
, &x
, &y
);
3439 ok
= mouse_released (but
, &x
, &y
);
3442 /* Allow a simultaneous press/release of Mouse-1 and
3443 Mouse-2 to simulate Mouse-3 on two-button mice. */
3444 if (mouse_button_count
== 2 && but
< 2)
3446 int x2
, y2
; /* don't clobber original coordinates */
3448 /* If only one button is pressed, wait 100 msec and
3449 check again. This way, Speedy Gonzales isn't
3450 punished, while the slow get their chance. */
3451 if (press
&& mouse_pressed (1-but
, &x2
, &y2
)
3452 || !press
&& mouse_released (1-but
, &x2
, &y2
))
3457 if (press
&& mouse_pressed (1-but
, &x2
, &y2
)
3458 || !press
&& mouse_released (1-but
, &x2
, &y2
))
3463 event
.kind
= MOUSE_CLICK_EVENT
;
3464 event
.code
= button_num
;
3465 event
.modifiers
= dos_get_modifiers (0)
3466 | (press
? down_modifier
: up_modifier
);
3467 event
.x
= make_number (x
);
3468 event
.y
= make_number (y
);
3469 event
.frame_or_window
= selected_frame
;
3471 event
.timestamp
= event_timestamp ();
3472 kbd_buffer_store_event (&event
);
3480 static int prev_get_char
= -1;
3482 /* Return 1 if a key is ready to be read without suspending execution. */
3486 if (prev_get_char
!= -1)
3489 return ((prev_get_char
= dos_rawgetc ()) != -1);
3492 /* Read a key. Return -1 if no key is ready. */
3496 if (prev_get_char
!= -1)
3498 int c
= prev_get_char
;
3503 return dos_rawgetc ();
3506 #ifndef HAVE_X_WINDOWS
3508 /* Simulation of X's menus. Nothing too fancy here -- just make it work
3511 Actually, I don't know the meaning of all the parameters of the functions
3512 here -- I only know how they are called by xmenu.c. I could of course
3513 grab the nearest Xlib manual (down the hall, second-to-last door on the
3514 left), but I don't think it's worth the effort. */
3516 /* These hold text of the current and the previous menu help messages. */
3517 static char *menu_help_message
, *prev_menu_help_message
;
3518 /* Pane number and item number of the menu item which generated the
3519 last menu help message. */
3520 static int menu_help_paneno
, menu_help_itemno
;
3527 menu
= (XMenu
*) xmalloc (sizeof (XMenu
));
3528 menu
->allocated
= menu
->count
= menu
->panecount
= menu
->width
= 0;
3532 /* Allocate some (more) memory for MENU ensuring that there is room for one
3536 IT_menu_make_room (XMenu
*menu
)
3538 if (menu
->allocated
== 0)
3540 int count
= menu
->allocated
= 10;
3541 menu
->text
= (char **) xmalloc (count
* sizeof (char *));
3542 menu
->submenu
= (XMenu
**) xmalloc (count
* sizeof (XMenu
*));
3543 menu
->panenumber
= (int *) xmalloc (count
* sizeof (int));
3544 menu
->help_text
= (char **) xmalloc (count
* sizeof (char *));
3546 else if (menu
->allocated
== menu
->count
)
3548 int count
= menu
->allocated
= menu
->allocated
+ 10;
3550 = (char **) xrealloc (menu
->text
, count
* sizeof (char *));
3552 = (XMenu
**) xrealloc (menu
->submenu
, count
* sizeof (XMenu
*));
3554 = (int *) xrealloc (menu
->panenumber
, count
* sizeof (int));
3556 = (char **) xrealloc (menu
->help_text
, count
* sizeof (char *));
3560 /* Search the given menu structure for a given pane number. */
3563 IT_menu_search_pane (XMenu
*menu
, int pane
)
3568 for (i
= 0; i
< menu
->count
; i
++)
3569 if (menu
->submenu
[i
])
3571 if (pane
== menu
->panenumber
[i
])
3572 return menu
->submenu
[i
];
3573 if ((try = IT_menu_search_pane (menu
->submenu
[i
], pane
)))
3579 /* Determine how much screen space a given menu needs. */
3582 IT_menu_calc_size (XMenu
*menu
, int *width
, int *height
)
3584 int i
, h2
, w2
, maxsubwidth
, maxheight
;
3587 maxheight
= menu
->count
;
3588 for (i
= 0; i
< menu
->count
; i
++)
3590 if (menu
->submenu
[i
])
3592 IT_menu_calc_size (menu
->submenu
[i
], &w2
, &h2
);
3593 if (w2
> maxsubwidth
) maxsubwidth
= w2
;
3594 if (i
+ h2
> maxheight
) maxheight
= i
+ h2
;
3597 *width
= menu
->width
+ maxsubwidth
;
3598 *height
= maxheight
;
3601 /* Display MENU at (X,Y) using FACES. */
3604 IT_menu_display (XMenu
*menu
, int y
, int x
, int pn
, int *faces
, int disp_help
)
3606 int i
, j
, face
, width
, mx
, my
, enabled
, mousehere
, row
, col
;
3607 struct glyph
*text
, *p
;
3609 struct frame
*sf
= SELECTED_FRAME();
3611 menu_help_message
= NULL
;
3613 width
= menu
->width
;
3614 text
= (struct glyph
*) xmalloc ((width
+ 2) * sizeof (struct glyph
));
3615 ScreenGetCursor (&row
, &col
);
3616 mouse_get_xy (&mx
, &my
);
3617 IT_update_begin (sf
);
3618 for (i
= 0; i
< menu
->count
; i
++)
3620 int max_width
= width
+ 2;
3622 IT_cursor_to (y
+ i
, x
);
3624 = (!menu
->submenu
[i
] && menu
->panenumber
[i
]) || (menu
->submenu
[i
]);
3625 mousehere
= (y
+ i
== my
&& x
<= mx
&& mx
< x
+ width
+ 2);
3626 face
= faces
[enabled
+ mousehere
* 2];
3627 /* The following if clause means that we display the menu help
3628 strings even if the menu item is currently disabled. */
3629 if (disp_help
&& enabled
+ mousehere
* 2 >= 2)
3631 menu_help_message
= menu
->help_text
[i
];
3632 menu_help_paneno
= pn
- 1;
3633 menu_help_itemno
= i
;
3636 SET_CHAR_GLYPH (*p
, ' ', face
, 0);
3638 for (j
= 0, q
= menu
->text
[i
]; *q
; j
++)
3642 SET_CHAR_GLYPH (*p
, *q
++, face
, 0);
3645 else /* make '^x' */
3647 SET_CHAR_GLYPH (*p
, '^', face
, 0);
3650 SET_CHAR_GLYPH (*p
, *q
++ + 64, face
, 0);
3654 /* Don't let the menu text overflow into the next screen row. */
3655 if (x
+ max_width
> screen_size_X
)
3657 max_width
= screen_size_X
- x
;
3658 text
[max_width
- 1].u
.ch
= '$'; /* indicate it's truncated */
3660 for (; j
< max_width
- 2; j
++, p
++)
3661 SET_CHAR_GLYPH (*p
, ' ', face
, 0);
3663 SET_CHAR_GLYPH (*p
, menu
->submenu
[i
] ? 16 : ' ', face
, 0);
3665 IT_write_glyphs (text
, max_width
);
3668 IT_cursor_to (row
, col
);
3672 /* --------------------------- X Menu emulation ---------------------- */
3674 /* Report availability of menus. */
3677 have_menus_p () { return 1; }
3679 /* Create a brand new menu structure. */
3682 XMenuCreate (Display
*foo1
, Window foo2
, char *foo3
)
3684 return IT_menu_create ();
3687 /* Create a new pane and place it on the outer-most level. It is not
3688 clear that it should be placed out there, but I don't know what else
3692 XMenuAddPane (Display
*foo
, XMenu
*menu
, char *txt
, int enable
)
3700 IT_menu_make_room (menu
);
3701 menu
->submenu
[menu
->count
] = IT_menu_create ();
3702 menu
->text
[menu
->count
] = txt
;
3703 menu
->panenumber
[menu
->count
] = ++menu
->panecount
;
3704 menu
->help_text
[menu
->count
] = NULL
;
3707 /* Adjust length for possible control characters (which will
3708 be written as ^x). */
3709 for (len
= strlen (txt
), p
= txt
; *p
; p
++)
3713 if (len
> menu
->width
)
3716 return menu
->panecount
;
3719 /* Create a new item in a menu pane. */
3722 XMenuAddSelection (Display
*bar
, XMenu
*menu
, int pane
,
3723 int foo
, char *txt
, int enable
, char *help_text
)
3729 if (!(menu
= IT_menu_search_pane (menu
, pane
)))
3731 IT_menu_make_room (menu
);
3732 menu
->submenu
[menu
->count
] = (XMenu
*) 0;
3733 menu
->text
[menu
->count
] = txt
;
3734 menu
->panenumber
[menu
->count
] = enable
;
3735 menu
->help_text
[menu
->count
] = help_text
;
3738 /* Adjust length for possible control characters (which will
3739 be written as ^x). */
3740 for (len
= strlen (txt
), p
= txt
; *p
; p
++)
3744 if (len
> menu
->width
)
3750 /* Decide where the menu would be placed if requested at (X,Y). */
3753 XMenuLocate (Display
*foo0
, XMenu
*menu
, int foo1
, int foo2
, int x
, int y
,
3754 int *ulx
, int *uly
, int *width
, int *height
)
3756 IT_menu_calc_size (menu
, width
, height
);
3762 struct IT_menu_state
3764 void *screen_behind
;
3771 /* Display menu, wait for user's response, and return that response. */
3774 XMenuActivate (Display
*foo
, XMenu
*menu
, int *pane
, int *selidx
,
3775 int x0
, int y0
, unsigned ButtonMask
, char **txt
,
3776 void (*help_callback
)(char *, int, int))
3778 struct IT_menu_state
*state
;
3779 int statecount
, x
, y
, i
, b
, screensize
, leave
, result
, onepane
;
3780 int title_faces
[4]; /* face to display the menu title */
3781 int faces
[4], buffers_num_deleted
= 0;
3782 struct frame
*sf
= SELECTED_FRAME();
3783 Lisp_Object saved_echo_area_message
, selectface
;
3785 /* Just in case we got here without a mouse present... */
3786 if (have_mouse
<= 0)
3787 return XM_IA_SELECT
;
3788 /* Don't allow non-positive x0 and y0, lest the menu will wrap
3789 around the display. */
3795 /* We will process all the mouse events directly, so we had
3796 better prevent dos_rawgetc from stealing them from us. */
3799 state
= alloca (menu
->panecount
* sizeof (struct IT_menu_state
));
3800 screensize
= screen_size
* 2;
3802 = lookup_derived_face (sf
, intern ("msdos-menu-passive-face"),
3803 DEFAULT_FACE_ID
, 1);
3805 = lookup_derived_face (sf
, intern ("msdos-menu-active-face"),
3806 DEFAULT_FACE_ID
, 1);
3807 selectface
= intern ("msdos-menu-select-face");
3808 faces
[2] = lookup_derived_face (sf
, selectface
,
3810 faces
[3] = lookup_derived_face (sf
, selectface
,
3813 /* Make sure the menu title is always displayed with
3814 `msdos-menu-active-face', no matter where the mouse pointer is. */
3815 for (i
= 0; i
< 4; i
++)
3816 title_faces
[i
] = faces
[3];
3820 /* Don't let the title for the "Buffers" popup menu include a
3821 digit (which is ugly).
3823 This is a terrible kludge, but I think the "Buffers" case is
3824 the only one where the title includes a number, so it doesn't
3825 seem to be necessary to make this more general. */
3826 if (strncmp (menu
->text
[0], "Buffers 1", 9) == 0)
3828 menu
->text
[0][7] = '\0';
3829 buffers_num_deleted
= 1;
3832 /* We need to save the current echo area message, so that we could
3833 restore it below, before we exit. See the commentary below,
3834 before the call to message_with_string. */
3835 saved_echo_area_message
= Fcurrent_message ();
3836 state
[0].menu
= menu
;
3838 ScreenRetrieve (state
[0].screen_behind
= xmalloc (screensize
));
3840 /* Turn off the cursor. Otherwise it shows through the menu
3841 panes, which is ugly. */
3842 IT_display_cursor (0);
3844 /* Display the menu title. */
3845 IT_menu_display (menu
, y0
- 1, x0
- 1, 1, title_faces
, 0);
3846 if (buffers_num_deleted
)
3847 menu
->text
[0][7] = ' ';
3848 if ((onepane
= menu
->count
== 1 && menu
->submenu
[0]))
3850 menu
->width
= menu
->submenu
[0]->width
;
3851 state
[0].menu
= menu
->submenu
[0];
3855 state
[0].menu
= menu
;
3857 state
[0].x
= x0
- 1;
3859 state
[0].pane
= onepane
;
3861 mouse_last_x
= -1; /* A hack that forces display. */
3865 if (!mouse_visible
) mouse_on ();
3866 mouse_check_moved ();
3867 if (sf
->mouse_moved
)
3869 sf
->mouse_moved
= 0;
3870 result
= XM_IA_SELECT
;
3871 mouse_get_xy (&x
, &y
);
3872 for (i
= 0; i
< statecount
; i
++)
3873 if (state
[i
].x
<= x
&& x
< state
[i
].x
+ state
[i
].menu
->width
+ 2)
3875 int dy
= y
- state
[i
].y
;
3876 if (0 <= dy
&& dy
< state
[i
].menu
->count
)
3878 if (!state
[i
].menu
->submenu
[dy
])
3879 if (state
[i
].menu
->panenumber
[dy
])
3880 result
= XM_SUCCESS
;
3882 result
= XM_IA_SELECT
;
3883 *pane
= state
[i
].pane
- 1;
3885 /* We hit some part of a menu, so drop extra menus that
3886 have been opened. That does not include an open and
3888 if (i
!= statecount
- 2
3889 || state
[i
].menu
->submenu
[dy
] != state
[i
+1].menu
)
3890 while (i
!= statecount
- 1)
3894 ScreenUpdate (state
[statecount
].screen_behind
);
3895 if (screen_virtual_segment
)
3896 dosv_refresh_virtual_screen (0, screen_size
);
3897 xfree (state
[statecount
].screen_behind
);
3899 if (i
== statecount
- 1 && state
[i
].menu
->submenu
[dy
])
3901 IT_menu_display (state
[i
].menu
,
3906 state
[statecount
].menu
= state
[i
].menu
->submenu
[dy
];
3907 state
[statecount
].pane
= state
[i
].menu
->panenumber
[dy
];
3909 ScreenRetrieve (state
[statecount
].screen_behind
3910 = xmalloc (screensize
));
3912 = state
[i
].x
+ state
[i
].menu
->width
+ 2;
3913 state
[statecount
].y
= y
;
3918 IT_menu_display (state
[statecount
- 1].menu
,
3919 state
[statecount
- 1].y
,
3920 state
[statecount
- 1].x
,
3921 state
[statecount
- 1].pane
,
3926 if ((menu_help_message
|| prev_menu_help_message
)
3927 && menu_help_message
!= prev_menu_help_message
)
3929 help_callback (menu_help_message
,
3930 menu_help_paneno
, menu_help_itemno
);
3931 IT_display_cursor (0);
3932 prev_menu_help_message
= menu_help_message
;
3934 /* We are busy-waiting for the mouse to move, so let's be nice
3935 to other Windows applications by releasing our time slice. */
3938 for (b
= 0; b
< mouse_button_count
&& !leave
; b
++)
3940 /* Only leave if user both pressed and released the mouse, and in
3941 that order. This avoids popping down the menu pane unless
3942 the user is really done with it. */
3943 if (mouse_pressed (b
, &x
, &y
))
3945 while (mouse_button_depressed (b
, &x
, &y
))
3949 (void) mouse_released (b
, &x
, &y
);
3954 ScreenUpdate (state
[0].screen_behind
);
3955 if (screen_virtual_segment
)
3956 dosv_refresh_virtual_screen (0, screen_size
);
3958 /* We have a situation here. ScreenUpdate has just restored the
3959 screen contents as it was before we started drawing this menu.
3960 That includes any echo area message that could have been
3961 displayed back then. (In reality, that echo area message will
3962 almost always be the ``keystroke echo'' that echoes the sequence
3963 of menu items chosen by the user.) However, if the menu had some
3964 help messages, then displaying those messages caused Emacs to
3965 forget about the original echo area message. So when
3966 ScreenUpdate restored it, it created a discrepancy between the
3967 actual screen contents and what Emacs internal data structures
3970 To avoid this conflict, we force Emacs to restore the original
3971 echo area message as we found it when we entered this function.
3972 The irony of this is that we then erase the restored message
3973 right away, so the only purpose of restoring it is so that
3974 erasing it works correctly... */
3975 if (! NILP (saved_echo_area_message
))
3976 message_with_string ("%s", saved_echo_area_message
, 0);
3978 while (statecount
--)
3979 xfree (state
[statecount
].screen_behind
);
3980 IT_display_cursor (1); /* turn cursor back on */
3981 /* Clean up any mouse events that are waiting inside Emacs event queue.
3982 These events are likely to be generated before the menu was even
3983 displayed, probably because the user pressed and released the button
3984 (which invoked the menu) too quickly. If we don't remove these events,
3985 Emacs will process them after we return and surprise the user. */
3986 discard_mouse_events ();
3987 mouse_clear_clicks ();
3988 if (!kbd_buffer_events_waiting (1))
3989 clear_input_pending ();
3990 /* Allow mouse events generation by dos_rawgetc. */
3995 /* Dispose of a menu. */
3998 XMenuDestroy (Display
*foo
, XMenu
*menu
)
4001 if (menu
->allocated
)
4003 for (i
= 0; i
< menu
->count
; i
++)
4004 if (menu
->submenu
[i
])
4005 XMenuDestroy (foo
, menu
->submenu
[i
]);
4007 xfree (menu
->submenu
);
4008 xfree (menu
->panenumber
);
4009 xfree (menu
->help_text
);
4012 menu_help_message
= prev_menu_help_message
= NULL
;
4016 x_pixel_width (struct frame
*f
)
4018 return FRAME_COLS (f
);
4022 x_pixel_height (struct frame
*f
)
4024 return FRAME_LINES (f
);
4026 #endif /* !HAVE_X_WINDOWS */
4028 /* ----------------------- DOS / UNIX conversion --------------------- */
4030 void msdos_downcase_filename (unsigned char *);
4032 /* Destructively turn backslashes into slashes. */
4035 dostounix_filename (p
)
4038 msdos_downcase_filename (p
);
4048 /* Destructively turn slashes into backslashes. */
4051 unixtodos_filename (p
)
4054 if (p
[1] == ':' && *p
>= 'A' && *p
<= 'Z')
4068 /* Get the default directory for a given drive. 0=def, 1=A, 2=B, ... */
4071 getdefdir (drive
, dst
)
4075 char in_path
[4], *p
= in_path
, e
= errno
;
4077 /* Generate "X:." (when drive is X) or "." (when drive is 0). */
4080 *p
++ = drive
+ 'A' - 1;
4087 _fixpath (in_path
, dst
);
4088 /* _fixpath can set errno to ENOSYS on non-LFN systems because
4089 it queries the LFN support, so ignore that error. */
4090 if ((errno
&& errno
!= ENOSYS
) || *dst
== '\0')
4093 msdos_downcase_filename (dst
);
4100 emacs_root_dir (void)
4102 static char root_dir
[4];
4104 sprintf (root_dir
, "%c:/", 'A' + getdisk ());
4105 root_dir
[0] = tolower (root_dir
[0]);
4109 /* Remove all CR's that are followed by a LF. */
4114 register unsigned char *buf
;
4116 unsigned char *np
= buf
, *startp
= buf
, *endp
= buf
+ n
;
4120 while (buf
< endp
- 1)
4124 if (*(++buf
) != 0x0a)
4135 #if defined(__DJGPP__) && __DJGPP__ == 2 && __DJGPP_MINOR__ == 0
4137 /* In DJGPP v2.0, library `write' can call `malloc', which might
4138 cause relocation of the buffer whose address we get in ADDR.
4139 Here is a version of `write' that avoids calling `malloc',
4140 to serve us until such time as the library is fixed.
4141 Actually, what we define here is called `__write', because
4142 `write' is a stub that just jmp's to `__write' (to be
4143 POSIXLY-correct with respect to the global name-space). */
4145 #include <io.h> /* for _write */
4146 #include <libc/dosio.h> /* for __file_handle_modes[] */
4148 static char xbuf
[64 * 1024]; /* DOS cannot write more in one chunk */
4150 #define XBUF_END (xbuf + sizeof (xbuf) - 1)
4153 __write (int handle
, const void *buffer
, size_t count
)
4158 if(__file_handle_modes
[handle
] & O_BINARY
)
4159 return _write (handle
, buffer
, count
);
4163 const char *bp
= buffer
;
4164 int total_written
= 0;
4165 int nmoved
= 0, ncr
= 0;
4169 /* The next test makes sure there's space for at least 2 more
4170 characters in xbuf[], so both CR and LF can be put there. */
4182 if (xbp
>= XBUF_END
|| !count
)
4184 size_t to_write
= nmoved
+ ncr
;
4185 int written
= _write (handle
, xbuf
, to_write
);
4190 total_written
+= nmoved
; /* CRs aren't counted in ret value */
4192 /* If some, but not all were written (disk full?), return
4193 an estimate of the total written bytes not counting CRs. */
4194 if (written
< to_write
)
4195 return total_written
- (to_write
- written
) * nmoved
/to_write
;
4202 return total_written
;
4206 /* A low-level file-renaming function which works around Windows 95 bug.
4207 This is pulled directly out of DJGPP v2.01 library sources, and only
4208 used when you compile with DJGPP v2.0. */
4212 int _rename(const char *old
, const char *new)
4215 int olen
= strlen(old
) + 1;
4217 int use_lfn
= _USE_LFN
;
4218 char tempfile
[FILENAME_MAX
];
4219 const char *orig
= old
;
4222 r
.x
.dx
= __tb_offset
;
4223 r
.x
.di
= __tb_offset
+ olen
;
4224 r
.x
.ds
= r
.x
.es
= __tb_segment
;
4228 /* Windows 95 bug: for some filenames, when you rename
4229 file -> file~ (as in Emacs, to leave a backup), the
4230 short 8+3 alias doesn't change, which effectively
4231 makes OLD and NEW the same file. We must rename
4232 through a temporary file to work around this. */
4234 char *pbase
= 0, *p
;
4235 static char try_char
[] = "abcdefghijklmnopqrstuvwxyz012345789";
4236 int idx
= sizeof(try_char
) - 1;
4238 /* Generate a temporary name. Can't use `tmpnam', since $TMPDIR
4239 might point to another drive, which will fail the DOS call. */
4240 strcpy(tempfile
, old
);
4241 for (p
= tempfile
; *p
; p
++) /* ensure temporary is on the same drive */
4242 if (*p
== '/' || *p
== '\\' || *p
== ':')
4248 strcpy(pbase
, "X$$djren$$.$$temp$$");
4254 *pbase
= try_char
[--idx
];
4255 } while (_chmod(tempfile
, 0) != -1);
4258 _put_path2(tempfile
, olen
);
4260 __dpmi_int(0x21, &r
);
4263 errno
= __doserr_to_errno(r
.x
.ax
);
4267 /* Now create a file with the original name. This will
4268 ensure that NEW will always have a 8+3 alias
4269 different from that of OLD. (Seems to be required
4270 when NameNumericTail in the Registry is set to 0.) */
4271 lfn_fd
= _creat(old
, 0);
4273 olen
= strlen(tempfile
) + 1;
4275 r
.x
.di
= __tb_offset
+ olen
;
4284 _put_path2(new, olen
);
4286 __dpmi_int(0x21, &r
);
4289 if (r
.x
.ax
== 5 && i
== 0) /* access denied */
4290 remove(new); /* and try again */
4293 errno
= __doserr_to_errno(r
.x
.ax
);
4295 /* Restore to original name if we renamed it to temporary. */
4303 _put_path2(orig
, olen
);
4304 _put_path(tempfile
);
4306 __dpmi_int(0x21, &r
);
4315 /* Success. Delete the file possibly created to work
4316 around the Windows 95 bug. */
4318 return (_close (lfn_fd
) == 0) ? remove (orig
) : -1;
4322 #endif /* __DJGPP__ == 2 && __DJGPP_MINOR__ == 0 */
4324 DEFUN ("msdos-long-file-names", Fmsdos_long_file_names
, Smsdos_long_file_names
,
4326 doc
: /* Return non-nil if long file names are supported on MSDOS. */)
4329 return (_USE_LFN
? Qt
: Qnil
);
4332 /* Convert alphabetic characters in a filename to lower-case. */
4335 msdos_downcase_filename (p
)
4336 register unsigned char *p
;
4338 /* Always lower-case drive letters a-z, even if the filesystem
4339 preserves case in filenames.
4340 This is so MSDOS filenames could be compared by string comparison
4341 functions that are case-sensitive. Even case-preserving filesystems
4342 do not distinguish case in drive letters. */
4343 if (p
[1] == ':' && *p
>= 'A' && *p
<= 'Z')
4349 /* Under LFN we expect to get pathnames in their true case. */
4350 if (NILP (Fmsdos_long_file_names ()))
4352 if (*p
>= 'A' && *p
<= 'Z')
4356 DEFUN ("msdos-downcase-filename", Fmsdos_downcase_filename
, Smsdos_downcase_filename
,
4358 doc
: /* Convert alphabetic characters in FILENAME to lower case and return that.
4359 When long filenames are supported, doesn't change FILENAME.
4360 If FILENAME is not a string, returns nil.
4361 The argument object is never altered--the value is a copy. */)
4363 Lisp_Object filename
;
4367 if (! STRINGP (filename
))
4370 tem
= Fcopy_sequence (filename
);
4371 msdos_downcase_filename (SDATA (tem
));
4375 /* The Emacs root directory as determined by init_environment. */
4377 static char emacsroot
[MAXPATHLEN
];
4380 rootrelativepath (rel
)
4383 static char result
[MAXPATHLEN
+ 10];
4385 strcpy (result
, emacsroot
);
4386 strcat (result
, "/");
4387 strcat (result
, rel
);
4391 /* Define a lot of environment variables if not already defined. Don't
4392 remove anything unless you know what you're doing -- lots of code will
4393 break if one or more of these are missing. */
4396 init_environment (argc
, argv
, skip_args
)
4403 static const char * const tempdirs
[] = {
4404 "$TMPDIR", "$TEMP", "$TMP", "c:/"
4406 const int imax
= sizeof (tempdirs
) / sizeof (tempdirs
[0]);
4408 /* Make sure they have a usable $TMPDIR. Many Emacs functions use
4409 temporary files and assume "/tmp" if $TMPDIR is unset, which
4410 will break on DOS/Windows. Refuse to work if we cannot find
4411 a directory, not even "c:/", usable for that purpose. */
4412 for (i
= 0; i
< imax
; i
++)
4414 const char *tmp
= tempdirs
[i
];
4415 char buf
[FILENAME_MAX
];
4421 tmp
= getenv (tmp
+ 1);
4425 /* Some lusers set TMPDIR=e:, probably because some losing
4426 programs cannot handle multiple slashes if they use e:/.
4427 e: fails in `access' below, so we interpret e: as e:/. */
4428 tmp_len
= strlen(tmp
);
4429 if (tmp
[tmp_len
- 1] != '/' && tmp
[tmp_len
- 1] != '\\')
4432 buf
[tmp_len
++] = '/', buf
[tmp_len
] = 0;
4437 /* Note that `access' can lie to us if the directory resides on a
4438 read-only filesystem, like CD-ROM or a write-protected floppy.
4439 The only way to be really sure is to actually create a file and
4440 see if it succeeds. But I think that's too much to ask. */
4441 if (tmp
&& access (tmp
, D_OK
) == 0)
4443 setenv ("TMPDIR", tmp
, 1);
4450 Fcons (build_string ("no usable temporary directories found!!"),
4452 "While setting TMPDIR: ");
4454 /* Note the startup time, so we know not to clear the screen if we
4455 exit immediately; see IT_reset_terminal_modes.
4456 (Yes, I know `clock' returns zero the first time it's called, but
4457 I do this anyway, in case some wiseguy changes that at some point.) */
4458 startup_time
= clock ();
4460 /* Find our root from argv[0]. Assuming argv[0] is, say,
4461 "c:/emacs/bin/emacs.exe" our root will be "c:/emacs". */
4462 root
= alloca (MAXPATHLEN
+ 20);
4463 _fixpath (argv
[0], root
);
4464 msdos_downcase_filename (root
);
4465 len
= strlen (root
);
4466 while (len
> 0 && root
[len
] != '/' && root
[len
] != ':')
4470 && (strcmp (root
+ len
- 4, "/bin") == 0
4471 || strcmp (root
+ len
- 4, "/src") == 0)) /* under a debugger */
4472 root
[len
- 4] = '\0';
4474 strcpy (root
, "c:/emacs"); /* let's be defensive */
4475 len
= strlen (root
);
4476 strcpy (emacsroot
, root
);
4478 /* We default HOME to our root. */
4479 setenv ("HOME", root
, 0);
4481 /* We default EMACSPATH to root + "/bin". */
4482 strcpy (root
+ len
, "/bin");
4483 setenv ("EMACSPATH", root
, 0);
4485 /* I don't expect anybody to ever use other terminals so the internal
4486 terminal is the default. */
4487 setenv ("TERM", "internal", 0);
4489 #ifdef HAVE_X_WINDOWS
4490 /* Emacs expects DISPLAY to be set. */
4491 setenv ("DISPLAY", "unix:0.0", 0);
4494 /* SHELL is a bit tricky -- COMSPEC is the closest we come, but we must
4495 downcase it and mirror the backslashes. */
4496 s
= getenv ("COMSPEC");
4497 if (!s
) s
= "c:/command.com";
4498 t
= alloca (strlen (s
) + 1);
4500 dostounix_filename (t
);
4501 setenv ("SHELL", t
, 0);
4503 /* PATH is also downcased and backslashes mirrored. */
4504 s
= getenv ("PATH");
4506 t
= alloca (strlen (s
) + 3);
4507 /* Current directory is always considered part of MsDos's path but it is
4508 not normally mentioned. Now it is. */
4509 strcat (strcpy (t
, ".;"), s
);
4510 dostounix_filename (t
); /* Not a single file name, but this should work. */
4511 setenv ("PATH", t
, 1);
4513 /* In some sense all dos users have root privileges, so... */
4514 setenv ("USER", "root", 0);
4515 setenv ("NAME", getenv ("USER"), 0);
4517 /* Time zone determined from country code. To make this possible, the
4518 country code may not span more than one time zone. In other words,
4519 in the USA, you lose. */
4521 switch (dos_country_code
)
4523 case 31: /* Belgium */
4524 case 32: /* The Netherlands */
4525 case 33: /* France */
4526 case 34: /* Spain */
4527 case 36: /* Hungary */
4528 case 38: /* Yugoslavia (or what's left of it?) */
4529 case 39: /* Italy */
4530 case 41: /* Switzerland */
4531 case 42: /* Tjekia */
4532 case 45: /* Denmark */
4533 case 46: /* Sweden */
4534 case 47: /* Norway */
4535 case 48: /* Poland */
4536 case 49: /* Germany */
4537 /* Daylight saving from last Sunday in March to last Sunday in
4538 September, both at 2AM. */
4539 setenv ("TZ", "MET-01METDST-02,M3.5.0/02:00,M9.5.0/02:00", 0);
4541 case 44: /* United Kingdom */
4542 case 351: /* Portugal */
4543 case 354: /* Iceland */
4544 setenv ("TZ", "GMT+00", 0);
4546 case 81: /* Japan */
4547 case 82: /* Korea */
4548 setenv ("TZ", "JST-09", 0);
4550 case 90: /* Turkey */
4551 case 358: /* Finland */
4552 setenv ("TZ", "EET-02", 0);
4554 case 972: /* Israel */
4555 /* This is an approximation. (For exact rules, use the
4556 `zoneinfo/israel' file which comes with DJGPP, but you need
4557 to install it in `/usr/share/zoneinfo/' directory first.) */
4558 setenv ("TZ", "IST-02IDT-03,M4.1.6/00:00,M9.5.6/01:00", 0);
4566 static int break_stat
; /* BREAK check mode status. */
4567 static int stdin_stat
; /* stdin IOCTL status. */
4571 /* These must be global. */
4572 static _go32_dpmi_seginfo ctrl_break_vector
;
4573 static _go32_dpmi_registers ctrl_break_regs
;
4574 static int ctrlbreakinstalled
= 0;
4576 /* Interrupt level detection of Ctrl-Break. Don't do anything fancy here! */
4579 ctrl_break_func (regs
)
4580 _go32_dpmi_registers
*regs
;
4586 install_ctrl_break_check ()
4588 if (!ctrlbreakinstalled
)
4590 /* Don't press Ctrl-Break if you don't have either DPMI or Emacs
4591 was compiler with Djgpp 1.11 maintenance level 5 or later! */
4592 ctrlbreakinstalled
= 1;
4593 ctrl_break_vector
.pm_offset
= (int) ctrl_break_func
;
4594 _go32_dpmi_allocate_real_mode_callback_iret (&ctrl_break_vector
,
4596 _go32_dpmi_set_real_mode_interrupt_vector (0x1b, &ctrl_break_vector
);
4600 #endif /* __DJGPP__ < 2 */
4602 /* Turn off Dos' Ctrl-C checking and inhibit interpretation of
4603 control chars by DOS. Determine the keyboard type. */
4608 union REGS inregs
, outregs
;
4609 static int first_time
= 1;
4611 break_stat
= getcbrk ();
4614 install_ctrl_break_check ();
4620 int86 (0x15, &inregs
, &outregs
);
4621 extended_kbd
= (!outregs
.x
.cflag
) && (outregs
.h
.ah
== 0);
4625 if (internal_terminal
4626 #ifdef HAVE_X_WINDOWS
4627 && inhibit_window_system
4631 inregs
.x
.ax
= 0x0021;
4632 int86 (0x33, &inregs
, &outregs
);
4633 have_mouse
= (outregs
.x
.ax
& 0xffff) == 0xffff;
4636 /* Reportedly, the above doesn't work for some mouse drivers. There
4637 is an additional detection method that should work, but might be
4638 a little slower. Use that as an alternative. */
4639 inregs
.x
.ax
= 0x0000;
4640 int86 (0x33, &inregs
, &outregs
);
4641 have_mouse
= (outregs
.x
.ax
& 0xffff) == 0xffff;
4646 have_mouse
= 1; /* enable mouse */
4648 mouse_setup_buttons (outregs
.x
.bx
);
4649 mouse_position_hook
= &mouse_get_pos
;
4653 #ifndef HAVE_X_WINDOWS
4655 /* Save the cursor shape used outside Emacs. */
4656 outside_cursor
= _farpeekw (_dos_ds
, 0x460);
4665 stdin_stat
= setmode (fileno (stdin
), O_BINARY
);
4666 return (stdin_stat
!= -1);
4669 return (setmode (fileno (stdin
), O_BINARY
) != -1);
4671 #else /* __DJGPP__ < 2 */
4675 /* I think it is wrong to overwrite `stdin_stat' every time
4676 but the first one this function is called, but I don't
4677 want to change the way it used to work in v1.x.--EZ */
4679 inregs
.x
.ax
= 0x4400; /* Get IOCTL status. */
4680 inregs
.x
.bx
= 0x00; /* 0 = stdin. */
4681 intdos (&inregs
, &outregs
);
4682 stdin_stat
= outregs
.h
.dl
;
4684 inregs
.x
.dx
= stdin_stat
| 0x0020; /* raw mode */
4685 inregs
.x
.ax
= 0x4401; /* Set IOCTL status */
4686 intdos (&inregs
, &outregs
);
4687 return !outregs
.x
.cflag
;
4689 #endif /* __DJGPP__ < 2 */
4692 /* Restore status of standard input and Ctrl-C checking. */
4697 union REGS inregs
, outregs
;
4699 setcbrk (break_stat
);
4704 #ifndef HAVE_X_WINDOWS
4705 /* Restore the cursor shape we found on startup. */
4709 inregs
.x
.cx
= outside_cursor
;
4710 int86 (0x10, &inregs
, &outregs
);
4714 return (setmode (fileno (stdin
), stdin_stat
) != -1);
4716 #else /* not __DJGPP__ >= 2 */
4718 inregs
.x
.ax
= 0x4401; /* Set IOCTL status. */
4719 inregs
.x
.bx
= 0x00; /* 0 = stdin. */
4720 inregs
.x
.dx
= stdin_stat
;
4721 intdos (&inregs
, &outregs
);
4722 return !outregs
.x
.cflag
;
4724 #endif /* not __DJGPP__ >= 2 */
4728 /* Run command as specified by ARGV in directory DIR.
4729 The command is run with input from TEMPIN, output to
4730 file TEMPOUT and stderr to TEMPERR. */
4733 run_msdos_command (argv
, working_dir
, tempin
, tempout
, temperr
, envv
)
4734 unsigned char **argv
;
4735 const char *working_dir
;
4736 int tempin
, tempout
, temperr
;
4739 char *saveargv1
, *saveargv2
, *lowcase_argv0
, *pa
, *pl
;
4740 char oldwd
[MAXPATHLEN
+ 1]; /* Fixed size is safe on MSDOS. */
4741 int msshell
, result
= -1, inbak
, outbak
, errbak
, x
, y
;
4744 /* Get current directory as MSDOS cwd is not per-process. */
4747 /* If argv[0] is the shell, it might come in any lettercase.
4748 Since `Fmember' is case-sensitive, we need to downcase
4749 argv[0], even if we are on case-preserving filesystems. */
4750 lowcase_argv0
= alloca (strlen (argv
[0]) + 1);
4751 for (pa
= argv
[0], pl
= lowcase_argv0
; *pa
; pl
++)
4754 if (*pl
>= 'A' && *pl
<= 'Z')
4759 cmd
= Ffile_name_nondirectory (build_string (lowcase_argv0
));
4760 msshell
= !NILP (Fmember (cmd
, Fsymbol_value (intern ("msdos-shells"))))
4761 && !strcmp ("-c", argv
[1]);
4764 saveargv1
= argv
[1];
4765 saveargv2
= argv
[2];
4767 /* We only need to mirror slashes if a DOS shell will be invoked
4768 not via `system' (which does the mirroring itself). Yes, that
4769 means DJGPP v1.x will lose here. */
4770 if (argv
[2] && argv
[3])
4772 char *p
= alloca (strlen (argv
[2]) + 1);
4774 strcpy (argv
[2] = p
, saveargv2
);
4775 while (*p
&& isspace (*p
))
4787 chdir (working_dir
);
4791 if (inbak
< 0 || outbak
< 0 || errbak
< 0)
4792 goto done
; /* Allocation might fail due to lack of descriptors. */
4795 mouse_get_xy (&x
, &y
);
4797 dos_ttcooked (); /* do it here while 0 = stdin */
4805 if (msshell
&& !argv
[3])
4807 /* MS-DOS native shells are too restrictive. For starters, they
4808 cannot grok commands longer than 126 characters. In DJGPP v2
4809 and later, `system' is much smarter, so we'll call it instead. */
4813 /* A shell gets a single argument--its full command
4814 line--whose original was saved in `saveargv2'. */
4816 /* Don't let them pass empty command lines to `system', since
4817 with some shells it will try to invoke an interactive shell,
4818 which will hang Emacs. */
4819 for (cmnd
= saveargv2
; *cmnd
&& isspace (*cmnd
); cmnd
++)
4823 extern char **environ
;
4824 char **save_env
= environ
;
4825 int save_system_flags
= __system_flags
;
4827 /* Request the most powerful version of `system'. We need
4828 all the help we can get to avoid calling stock DOS shells. */
4829 __system_flags
= (__system_redirect
4830 | __system_use_shell
4831 | __system_allow_multiple_cmds
4832 | __system_allow_long_cmds
4833 | __system_handle_null_commands
4834 | __system_emulate_chdir
);
4837 result
= system (cmnd
);
4838 __system_flags
= save_system_flags
;
4842 result
= 0; /* emulate Unixy shell behavior with empty cmd line */
4846 #endif /* __DJGPP__ > 1 */
4848 result
= spawnve (P_WAIT
, argv
[0], argv
, envv
);
4853 emacs_close (inbak
);
4854 emacs_close (outbak
);
4855 emacs_close (errbak
);
4861 mouse_moveto (x
, y
);
4864 /* Some programs might change the meaning of the highest bit of the
4865 text attribute byte, so we get blinking characters instead of the
4866 bright background colors. Restore that. */
4873 argv
[1] = saveargv1
;
4874 argv
[2] = saveargv2
;
4883 fprintf (stderr
, "%s not yet implemented\r\n", badfunc
);
4884 reset_all_sys_modes ();
4890 /* ------------------------- Compatibility functions -------------------
4895 /* Hostnames for a pc are not really funny,
4896 but they are used in change log so we emulate the best we can. */
4898 gethostname (p
, size
)
4902 char *q
= egetenv ("HOSTNAME");
4909 /* When time zones are set from Ms-Dos too many C-libraries are playing
4910 tricks with time values. We solve this by defining our own version
4911 of `gettimeofday' bypassing GO32. Our version needs to be initialized
4912 once and after each call to `tzset' with TZ changed. That is
4913 accomplished by aliasing tzset to init_gettimeofday. */
4915 static struct tm time_rec
;
4918 gettimeofday (struct timeval
*tp
, struct timezone
*tzp
)
4926 if (t
.ti_hour
< time_rec
.tm_hour
) /* midnight wrap */
4930 time_rec
.tm_year
= d
.da_year
- 1900;
4931 time_rec
.tm_mon
= d
.da_mon
- 1;
4932 time_rec
.tm_mday
= d
.da_day
;
4935 time_rec
.tm_hour
= t
.ti_hour
;
4936 time_rec
.tm_min
= t
.ti_min
;
4937 time_rec
.tm_sec
= t
.ti_sec
;
4940 tm
.tm_gmtoff
= dos_timezone_offset
;
4942 tp
->tv_sec
= mktime (&tm
); /* may modify tm */
4943 tp
->tv_usec
= t
.ti_hund
* (1000000 / 100);
4945 /* Ignore tzp; it's obsolescent. */
4949 #endif /* __DJGPP__ < 2 */
4952 * A list of unimplemented functions that we silently ignore.
4956 unsigned alarm (s
) unsigned s
; {}
4957 fork () { return 0; }
4958 int kill (x
, y
) int x
, y
; { return -1; }
4960 void volatile pause () {}
4961 sigsetmask (x
) int x
; { return 0; }
4962 sigblock (mask
) int mask
; { return 0; }
4965 void request_sigio (void) {}
4966 setpgrp () {return 0; }
4967 setpriority (x
,y
,z
) int x
,y
,z
; { return 0; }
4968 void unrequest_sigio (void) {}
4971 #if __DJGPP_MINOR__ < 2
4973 #ifdef POSIX_SIGNALS
4975 /* Augment DJGPP library POSIX signal functions. This is needed
4976 as of DJGPP v2.01, but might be in the library in later releases. */
4978 #include <libc/bss.h>
4980 /* A counter to know when to re-initialize the static sets. */
4981 static int sigprocmask_count
= -1;
4983 /* Which signals are currently blocked (initially none). */
4984 static sigset_t current_mask
;
4986 /* Which signals are pending (initially none). */
4987 static sigset_t pending_signals
;
4989 /* Previous handlers to restore when the blocked signals are unblocked. */
4990 typedef void (*sighandler_t
)(int);
4991 static sighandler_t prev_handlers
[320];
4993 /* A signal handler which just records that a signal occurred
4994 (it will be raised later, if and when the signal is unblocked). */
4996 sig_suspender (signo
)
4999 sigaddset (&pending_signals
, signo
);
5003 sigprocmask (how
, new_set
, old_set
)
5005 const sigset_t
*new_set
;
5011 /* If called for the first time, initialize. */
5012 if (sigprocmask_count
!= __bss_count
)
5014 sigprocmask_count
= __bss_count
;
5015 sigemptyset (&pending_signals
);
5016 sigemptyset (¤t_mask
);
5017 for (signo
= 0; signo
< 320; signo
++)
5018 prev_handlers
[signo
] = SIG_ERR
;
5022 *old_set
= current_mask
;
5027 if (how
!= SIG_BLOCK
&& how
!= SIG_UNBLOCK
&& how
!= SIG_SETMASK
)
5033 sigemptyset (&new_mask
);
5035 /* DJGPP supports upto 320 signals. */
5036 for (signo
= 0; signo
< 320; signo
++)
5038 if (sigismember (¤t_mask
, signo
))
5039 sigaddset (&new_mask
, signo
);
5040 else if (sigismember (new_set
, signo
) && how
!= SIG_UNBLOCK
)
5042 sigaddset (&new_mask
, signo
);
5044 /* SIGKILL is silently ignored, as on other platforms. */
5045 if (signo
!= SIGKILL
&& prev_handlers
[signo
] == SIG_ERR
)
5046 prev_handlers
[signo
] = signal (signo
, sig_suspender
);
5048 if (( how
== SIG_UNBLOCK
5049 && sigismember (&new_mask
, signo
)
5050 && sigismember (new_set
, signo
))
5051 || (how
== SIG_SETMASK
5052 && sigismember (&new_mask
, signo
)
5053 && !sigismember (new_set
, signo
)))
5055 sigdelset (&new_mask
, signo
);
5056 if (prev_handlers
[signo
] != SIG_ERR
)
5058 signal (signo
, prev_handlers
[signo
]);
5059 prev_handlers
[signo
] = SIG_ERR
;
5061 if (sigismember (&pending_signals
, signo
))
5063 sigdelset (&pending_signals
, signo
);
5068 current_mask
= new_mask
;
5072 #else /* not POSIX_SIGNALS */
5074 sigsetmask (x
) int x
; { return 0; }
5075 sigblock (mask
) int mask
; { return 0; }
5077 #endif /* not POSIX_SIGNALS */
5078 #endif /* not __DJGPP_MINOR__ < 2 */
5079 #endif /* __DJGPP__ > 1 */
5082 #include "sysselect.h"
5084 #ifndef EMACS_TIME_ZERO_OR_NEG_P
5085 #define EMACS_TIME_ZERO_OR_NEG_P(time) \
5086 ((long)(time).tv_sec < 0 \
5087 || ((time).tv_sec == 0 \
5088 && (long)(time).tv_usec <= 0))
5091 /* This yields the rest of the current time slice to the task manager.
5092 It should be called by any code which knows that it has nothing
5093 useful to do except idle.
5095 I don't use __dpmi_yield here, since versions of library before 2.02
5096 called Int 2Fh/AX=1680h there in a way that would wedge the DOS box
5097 on some versions of Windows 9X. */
5100 dos_yield_time_slice (void)
5102 _go32_dpmi_registers r
;
5105 r
.x
.ss
= r
.x
.sp
= r
.x
.flags
= 0;
5106 _go32_dpmi_simulate_int (0x2f, &r
);
5111 /* Only event queue is checked. */
5112 /* We don't have to call timer_check here
5113 because wait_reading_process_output takes care of that. */
5115 sys_select (nfds
, rfds
, wfds
, efds
, timeout
)
5117 SELECT_TYPE
*rfds
, *wfds
, *efds
;
5118 EMACS_TIME
*timeout
;
5126 check_input
= FD_ISSET (0, rfds
);
5137 /* If we are looking only for the terminal, with no timeout,
5138 just read it and wait -- that's more efficient. */
5141 while (!detect_input_pending ())
5143 dos_yield_time_slice ();
5148 EMACS_TIME clnow
, cllast
, cldiff
;
5151 EMACS_SET_SECS_USECS (cllast
, t
.ti_sec
, t
.ti_hund
* 10000L);
5153 while (!check_input
|| !detect_input_pending ())
5156 EMACS_SET_SECS_USECS (clnow
, t
.ti_sec
, t
.ti_hund
* 10000L);
5157 EMACS_SUB_TIME (cldiff
, clnow
, cllast
);
5159 /* When seconds wrap around, we assume that no more than
5160 1 minute passed since last `gettime'. */
5161 if (EMACS_TIME_NEG_P (cldiff
))
5162 EMACS_SET_SECS (cldiff
, EMACS_SECS (cldiff
) + 60);
5163 EMACS_SUB_TIME (*timeout
, *timeout
, cldiff
);
5165 /* Stop when timeout value crosses zero. */
5166 if (EMACS_TIME_ZERO_OR_NEG_P (*timeout
))
5169 dos_yield_time_slice ();
5179 * Define overlaid functions:
5181 * chdir -> sys_chdir
5182 * tzset -> init_gettimeofday
5183 * abort -> dos_abort
5188 extern int chdir ();
5194 int len
= strlen (path
);
5195 char *tmp
= (char *)path
;
5197 if (*tmp
&& tmp
[1] == ':')
5199 if (getdisk () != tolower (tmp
[0]) - 'a')
5200 setdisk (tolower (tmp
[0]) - 'a');
5201 tmp
+= 2; /* strip drive: KFS 1995-07-06 */
5205 if (len
> 1 && (tmp
[len
- 1] == '/'))
5207 char *tmp1
= (char *) alloca (len
+ 1);
5218 extern void tzset (void);
5221 init_gettimeofday ()
5227 ltm
= gtm
= time (NULL
);
5228 ltm
= mktime (lstm
= localtime (<m
));
5229 gtm
= mktime (gmtime (>m
));
5230 time_rec
.tm_hour
= 99; /* force gettimeofday to get date */
5231 time_rec
.tm_isdst
= lstm
->tm_isdst
;
5232 dos_timezone_offset
= time_rec
.tm_gmtoff
= (int)(gtm
- ltm
) / 60;
5239 dos_abort (file
, line
)
5243 char buffer1
[200], buffer2
[400];
5246 sprintf (buffer1
, "<EMACS FATAL ERROR IN %s LINE %d>", file
, line
);
5247 for (i
= j
= 0; buffer1
[i
]; i
++) {
5248 buffer2
[j
++] = buffer1
[i
];
5249 buffer2
[j
++] = 0x70;
5251 dosmemput (buffer2
, j
, (int)ScreenPrimary
);
5252 ScreenSetCursor (2, 0);
5260 ScreenSetCursor (10, 0);
5261 cputs ("\r\n\nEmacs aborted!\r\n");
5263 #if __DJGPP__ == 2 && __DJGPP_MINOR__ < 2
5264 if (screen_virtual_segment
)
5265 dosv_refresh_virtual_screen (2 * 10 * screen_size_X
, 4 * screen_size_X
);
5266 /* Generate traceback, so we could tell whodunit. */
5267 signal (SIGINT
, SIG_DFL
);
5268 __asm__
__volatile__ ("movb $0x1b,%al;call ___djgpp_hw_exception");
5269 #else /* __DJGPP_MINOR__ >= 2 */
5271 #endif /* __DJGPP_MINOR__ >= 2 */
5277 /* The following variables are required so that cus-start.el won't
5278 complain about unbound variables. */
5279 #ifndef subprocesses
5280 /* Nonzero means delete a process right away if it exits (process.c). */
5281 static int delete_exited_processes
;
5286 recent_doskeys
= Fmake_vector (make_number (NUM_RECENT_DOSKEYS
), Qnil
);
5287 staticpro (&recent_doskeys
);
5289 #ifndef HAVE_X_WINDOWS
5291 /* The following two are from xfns.c: */
5292 Qreverse
= intern ("reverse");
5293 staticpro (&Qreverse
);
5295 DEFVAR_LISP ("dos-unsupported-char-glyph", &Vdos_unsupported_char_glyph
,
5296 doc
: /* *Glyph to display instead of chars not supported by current codepage.
5297 This variable is used only by MSDOS terminals. */);
5298 Vdos_unsupported_char_glyph
= make_number ('\177');
5301 #ifndef subprocesses
5302 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes
,
5303 doc
: /* *Non-nil means delete processes immediately when they exit.
5304 A value of nil means don't delete them until `list-processes' is run. */);
5305 delete_exited_processes
= 0;
5308 defsubr (&Srecent_doskeys
);
5309 defsubr (&Smsdos_long_file_names
);
5310 defsubr (&Smsdos_downcase_filename
);
5311 defsubr (&Smsdos_remember_default_colors
);
5312 defsubr (&Smsdos_set_mouse_buttons
);
5317 /* arch-tag: db404e92-52a5-475f-9eb2-1cb78dd05f30
5318 (do not change this comment) */