1 /* MS-DOS specific C utilities. -*- coding: raw-text -*-
2 Copyright (C) 1993, 94, 95, 96, 97, 1999 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Contributed by Morten Welinder */
22 /* New display, keyboard, and mouse control by Kim F. Storm */
24 /* Note: some of the stuff here was taken from end of sysdep.c in demacs. */
33 #include <sys/param.h>
37 #include <string.h> /* for bzero and string functions */
38 #include <sys/stat.h> /* for _fixpath */
39 #include <unistd.h> /* for chdir, dup, dup2, etc. */
42 #include <io.h> /* for setmode */
43 #include <dpmi.h> /* for __dpmi_xxx stuff */
44 #include <sys/farptr.h> /* for _farsetsel, _farnspokeb */
45 #include <libc/dosio.h> /* for _USE_LFN */
46 #include <conio.h> /* for cputs */
51 #include "termhooks.h"
53 #include "dispextern.h"
63 #include "blockinput.h"
67 /* #include <process.h> */
68 /* Damn that local process.h! Instead we can define P_WAIT ourselves. */
76 #define _dos_ds _go32_info_block.selector_for_linear_memory
82 #include "syssignal.h"
88 /* If other `malloc' than ours is used, force our `sbrk' behave like
89 Unix programs expect (resize memory blocks to keep them contiguous).
90 If `sbrk' from `ralloc.c' is NOT used, also zero-out sbrk'ed memory,
91 because that's what `gmalloc' expects to get. */
95 int _crt0_startup_flags
= _CRT0_FLAG_UNIX_SBRK
;
96 #else /* not REL_ALLOC */
97 int _crt0_startup_flags
= (_CRT0_FLAG_UNIX_SBRK
| _CRT0_FLAG_FILL_SBRK_MEMORY
);
98 #endif /* not REL_ALLOC */
99 #endif /* GNU_MALLOC */
101 #endif /* not SYSTEM_MALLOC */
102 #endif /* __DJGPP__ > 1 */
121 /* ------------------------ Mouse control ---------------------------
123 * Coordinates are in screen positions and zero based.
124 * Mouse buttons are numbered from left to right and also zero based.
127 int have_mouse
; /* 0: no, 1: enabled, -1: disabled */
128 static int mouse_visible
;
130 static int mouse_last_x
;
131 static int mouse_last_y
;
133 static int mouse_button_translate
[NUM_MOUSE_BUTTONS
];
134 static int mouse_button_count
;
141 if (have_mouse
> 0 && !mouse_visible
)
144 fprintf (termscript
, "<M_ON>");
146 int86 (0x33, ®s
, ®s
);
156 if (have_mouse
> 0 && mouse_visible
)
159 fprintf (termscript
, "<M_OFF>");
161 int86 (0x33, ®s
, ®s
);
167 mouse_get_xy (int *x
, int *y
)
172 int86 (0x33, ®s
, ®s
);
184 fprintf (termscript
, "<M_XY=%dx%d>", x
, y
);
186 mouse_last_x
= regs
.x
.cx
= x
* 8;
187 mouse_last_y
= regs
.x
.dx
= y
* 8;
188 int86 (0x33, ®s
, ®s
);
192 mouse_pressed (b
, xp
, yp
)
197 if (b
>= mouse_button_count
)
200 regs
.x
.bx
= mouse_button_translate
[b
];
201 int86 (0x33, ®s
, ®s
);
203 *xp
= regs
.x
.cx
/ 8, *yp
= regs
.x
.dx
/ 8;
204 return (regs
.x
.bx
!= 0);
208 mouse_released (b
, xp
, yp
)
213 if (b
>= mouse_button_count
)
216 regs
.x
.bx
= mouse_button_translate
[b
];
217 int86 (0x33, ®s
, ®s
);
219 *xp
= regs
.x
.cx
/ 8, *yp
= regs
.x
.dx
/ 8;
220 return (regs
.x
.bx
!= 0);
224 mouse_button_depressed (b
, xp
, yp
)
229 if (b
>= mouse_button_count
)
232 int86 (0x33, ®s
, ®s
);
233 if ((regs
.x
.bx
& (1 << mouse_button_translate
[b
])) != 0)
243 mouse_get_pos (f
, insist
, bar_window
, part
, x
, y
, time
)
246 Lisp_Object
*bar_window
, *x
, *y
;
247 enum scroll_bar_part
*part
;
251 Lisp_Object frame
, tail
;
253 /* Clear the mouse-moved flag for every frame on this display. */
254 FOR_EACH_FRAME (tail
, frame
)
255 XFRAME (frame
)->mouse_moved
= 0;
257 *f
= SELECTED_FRAME();
259 mouse_get_xy (&ix
, &iy
);
260 *time
= event_timestamp ();
261 *x
= make_number (mouse_last_x
= ix
);
262 *y
= make_number (mouse_last_y
= iy
);
270 mouse_get_xy (&x
, &y
);
271 SELECTED_FRAME()->mouse_moved
|= (x
!= mouse_last_x
|| y
!= mouse_last_y
);
283 fprintf (termscript
, "<M_INIT>");
286 int86 (0x33, ®s
, ®s
);
288 /* Reset the mouse last press/release info. It seems that Windows
289 doesn't do that automatically when function 21h is called, which
290 causes Emacs to ``remember'' the click that switched focus to the
291 window just before Emacs was started from that window. */
292 for (b
= 0; b
< mouse_button_count
; b
++)
294 int dummy_x
, dummy_y
;
296 (void) mouse_pressed (b
, &dummy_x
, &dummy_y
);
297 (void) mouse_released (b
, &dummy_x
, &dummy_y
);
302 regs
.x
.dx
= 8 * (ScreenCols () - 1);
303 int86 (0x33, ®s
, ®s
);
307 regs
.x
.dx
= 8 * (ScreenRows () - 1);
308 int86 (0x33, ®s
, ®s
);
314 /* ------------------------- Screen control ----------------------
318 static int internal_terminal
= 0;
320 #ifndef HAVE_X_WINDOWS
321 extern unsigned char ScreenAttrib
;
322 static int screen_face
;
323 static int highlight
;
325 static int screen_size_X
;
326 static int screen_size_Y
;
327 static int screen_size
;
329 static int current_pos_X
;
330 static int current_pos_Y
;
331 static int new_pos_X
;
332 static int new_pos_Y
;
334 static void *startup_screen_buffer
;
335 static int startup_screen_size_X
;
336 static int startup_screen_size_Y
;
337 static int startup_pos_X
;
338 static int startup_pos_Y
;
339 static unsigned char startup_screen_attrib
;
341 static clock_t startup_time
;
343 static int term_setup_done
;
345 /* Similar to the_only_frame. */
346 struct x_output the_only_x_display
;
348 /* Support for DOS/V (allows Japanese characters to be displayed on
349 standard, non-Japanese, ATs). Only supported for DJGPP v2 and later. */
351 /* Holds the address of the text-mode screen buffer. */
352 static unsigned long screen_old_address
= 0;
353 /* Segment and offset of the virtual screen. If 0, DOS/V is NOT loaded. */
354 static unsigned short screen_virtual_segment
= 0;
355 static unsigned short screen_virtual_offset
= 0;
356 /* A flag to control how to display unibyte 8-bit characters. */
357 extern int unibyte_display_via_language_environment
;
360 /* Update the screen from a part of relocated DOS/V screen buffer which
361 begins at OFFSET and includes COUNT characters. */
363 dosv_refresh_virtual_screen (int offset
, int count
)
367 if (offset
< 0 || count
< 0) /* paranoia; illegal values crash DOS/V */
370 regs
.h
.ah
= 0xff; /* update relocated screen */
371 regs
.x
.es
= screen_virtual_segment
;
372 regs
.x
.di
= screen_virtual_offset
+ offset
;
374 __dpmi_int (0x10, ®s
);
379 dos_direct_output (y
, x
, buf
, len
)
385 int t0
= 2 * (x
+ y
* screen_size_X
);
386 int t
= t0
+ (int) ScreenPrimary
;
391 dosmemput (buf
++, 1, t
);
395 /* This is faster. */
396 for (_farsetsel (_dos_ds
); --len
>= 0; t
+= 2, buf
++)
397 _farnspokeb (t
, *buf
);
399 if (screen_virtual_segment
)
400 dosv_refresh_virtual_screen (t0
, l0
);
405 /* Flash the screen as a substitute for BEEPs. */
409 do_visible_bell (xorattr
)
410 unsigned char xorattr
;
415 movl _ScreenPrimary,%%eax
422 xorb %%al,%%gs:(%%ebx)
438 : "m" (xorattr
), "g" (screen_size
)
439 : "%eax", "%ebx", /* "%gs",*/ "%ecx", "%edx");
443 ScreenVisualBell (void)
445 /* This creates an xor-mask that will swap the default fore- and
446 background colors. */
447 do_visible_bell (((the_only_x_display
.foreground_pixel
448 ^ the_only_x_display
.background_pixel
)
453 #ifndef HAVE_X_WINDOWS
455 static int blink_bit
= -1; /* the state of the blink bit at startup */
457 /* Enable bright background colors. */
463 /* Remember the original state of the blink/bright-background bit.
464 It is stored at 0040:0065h in the BIOS data area. */
466 blink_bit
= (_farpeekb (_dos_ds
, 0x465) & 0x20) == 0x20;
470 int86 (0x10, ®s
, ®s
);
473 /* Disable bright background colors (and enable blinking) if we found
474 the video system in that state at startup. */
476 maybe_enable_blinking (void)
484 int86 (0x10, ®s
, ®s
);
488 /* Set the screen dimensions so that it can show no less than
489 ROWS x COLS frame. */
492 dos_set_window_size (rows
, cols
)
496 Lisp_Object video_mode
;
497 int video_mode_value
;
500 int current_rows
= ScreenRows (), current_cols
= ScreenCols ();
502 if (*rows
== current_rows
&& *cols
== current_cols
)
505 /* Do we have a VGA? */
507 int86 (0x10, ®s
, ®s
);
508 if (regs
.h
.al
== 0x1a && regs
.h
.bl
> 5 && regs
.h
.bl
< 13)
513 /* If the user specified a special video mode for these dimensions,
515 sprintf (video_name
, "screen-dimensions-%dx%d", *rows
, *cols
);
516 video_mode
= XSYMBOL (Fintern_soft (build_string (video_name
),
519 if (INTEGERP (video_mode
)
520 && (video_mode_value
= XINT (video_mode
)) > 0)
522 regs
.x
.ax
= video_mode_value
;
523 int86 (0x10, ®s
, ®s
);
527 /* Must hardware-reset the mouse, or else it won't update
528 its notion of screen dimensions for some non-standard
529 video modes. This is *painfully* slow... */
531 int86 (0x33, ®s
, ®s
);
535 /* Find one of the dimensions supported by standard EGA/VGA
536 which gives us at least the required dimensions. */
545 } std_dimension
[] = {
555 while (i
< sizeof (std_dimension
) / sizeof (std_dimension
[0]))
557 if (std_dimension
[i
].need_vga
<= have_vga
558 && std_dimension
[i
].rows
>= *rows
)
560 if (std_dimension
[i
].rows
!= current_rows
561 || *cols
!= current_cols
)
562 _set_screen_lines (std_dimension
[i
].rows
);
569 #else /* not __DJGPP__ > 1 */
571 else if (*rows
<= 25)
573 if (current_rows
!= 25 || current_cols
!= 80)
576 int86 (0x10, ®s
, ®s
);
579 int86 (0x10, ®s
, ®s
);
582 int86 (0x10, ®s
, ®s
);
584 int86 (0x10, ®s
, ®s
);
587 else if (*rows
<= 50)
588 if (have_vga
&& (current_rows
!= 50 || current_cols
!= 80)
589 || *rows
<= 43 && (current_rows
!= 43 || current_cols
!= 80))
592 int86 (0x10, ®s
, ®s
);
595 int86 (0x10, ®s
, ®s
);
598 int86 (0x10, ®s
, ®s
);
601 int86 (0x10, ®s
, ®s
);
603 #endif /* not __DJGPP__ > 1 */
611 /* Tell the caller what dimensions have been REALLY set. */
612 *rows
= ScreenRows ();
613 *cols
= ScreenCols ();
616 /* If the dimensions changed, the mouse highlight info is invalid. */
617 if (current_rows
!= *rows
|| current_cols
!= *cols
)
619 struct frame
*f
= SELECTED_FRAME();
620 struct display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
621 Lisp_Object window
= dpyinfo
->mouse_face_window
;
623 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
625 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
626 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
627 dpyinfo
->mouse_face_window
= Qnil
;
632 /* Enable bright background colors. */
635 /* FIXME: I'm not sure the above will run at all on DOS/V. But let's
636 be defensive anyway. */
637 if (screen_virtual_segment
)
638 dosv_refresh_virtual_screen (0, *cols
* *rows
);
641 /* If we write a character in the position where the mouse is,
642 the mouse cursor may need to be refreshed. */
652 mouse_get_xy (&x
, &y
);
653 if (y
!= new_pos_Y
|| x
< new_pos_X
)
669 union REGS inregs
, outregs
;
672 intdos (&inregs
, &outregs
);
676 /* Given a face id FACE, extract the face parameters to be used for
677 display until the face changes. The face parameters (actually, its
678 color) are used to construct the video attribute byte for each
679 glyph during the construction of the buffer that is then blitted to
682 IT_set_face (int face
)
684 struct frame
*sf
= SELECTED_FRAME();
685 struct face
*fp
= FACE_FROM_ID (sf
, face
);
686 unsigned long fg
, bg
;
690 fp
= FACE_FROM_ID (sf
, DEFAULT_FACE_ID
);
691 /* The default face for the frame should always be realized and
700 /* Don't use invalid colors. In particular, FACE_TTY_DEFAULT_*
701 colors mean use the colors of the default face, except that if
702 highlight is on, invert the foreground and the background. Note
703 that we assume all 16 colors to be available for the background,
704 since Emacs switches on this mode (and loses the blinking
705 attribute) at startup. */
706 if (fg
== FACE_TTY_DEFAULT_COLOR
|| fg
== FACE_TTY_DEFAULT_FG_COLOR
)
707 fg
= FRAME_FOREGROUND_PIXEL (sf
);
708 else if (fg
== FACE_TTY_DEFAULT_BG_COLOR
)
709 fg
= FRAME_BACKGROUND_PIXEL (sf
);
710 if (bg
== FACE_TTY_DEFAULT_COLOR
|| bg
== FACE_TTY_DEFAULT_BG_COLOR
)
711 bg
= FRAME_BACKGROUND_PIXEL (sf
);
712 else if (bg
== FACE_TTY_DEFAULT_FG_COLOR
)
713 bg
= FRAME_FOREGROUND_PIXEL (sf
);
715 /* Make sure highlighted lines really stand out, come what may. */
716 if ((highlight
|| fp
->tty_reverse_p
)
717 && (fg
== FRAME_FOREGROUND_PIXEL (sf
)
718 && bg
== FRAME_BACKGROUND_PIXEL (sf
)))
720 unsigned long tem
= fg
;
726 fprintf (termscript
, "<FACE %d%s: %d/%d[FG:%d/BG:%d]>", face
,
727 highlight
? "H" : "", fp
->foreground
, fp
->background
, fg
, bg
);
728 if (fg
>= 0 && fg
< 16)
730 ScreenAttrib
&= 0xf0;
733 if (bg
>= 0 && bg
< 16)
735 ScreenAttrib
&= 0x0f;
736 ScreenAttrib
|= ((bg
& 0x0f) << 4);
740 Lisp_Object Vdos_unsupported_char_glyph
;
743 IT_write_glyphs (struct glyph
*str
, int str_len
)
745 unsigned char *screen_buf
, *screen_bp
, *screen_buf_end
, *bp
;
746 int unsupported_face
= FAST_GLYPH_FACE (Vdos_unsupported_char_glyph
);
747 unsigned unsupported_char
= FAST_GLYPH_CHAR (Vdos_unsupported_char_glyph
);
748 int offset
= 2 * (new_pos_X
+ screen_size_X
* new_pos_Y
);
749 register int sl
= str_len
;
750 register int tlen
= GLYPH_TABLE_LENGTH
;
751 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
753 struct coding_system
*coding
= (CODING_REQUIRE_ENCODING (&terminal_coding
)
755 : &safe_terminal_coding
);
758 /* Do we need to consider conversion of unibyte characters to
760 int convert_unibyte_characters
761 = (NILP (current_buffer
->enable_multibyte_characters
)
762 && unibyte_display_via_language_environment
);
764 if (str_len
<= 0) return;
766 screen_buf
= screen_bp
= alloca (str_len
* 2);
767 screen_buf_end
= screen_buf
+ str_len
* 2;
768 sf
= SELECTED_FRAME();
770 /* Since faces get cached and uncached behind our back, we can't
771 rely on their indices in the cache being consistent across
772 invocations. So always reset the screen face to the default
773 face of the frame, before writing glyphs, and let the glyphs
774 set the right face if it's different from the default. */
775 IT_set_face (DEFAULT_FACE_ID
);
777 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
779 terminal_coding
.mode
&= ~CODING_MODE_LAST_BLOCK
;
782 int cf
, chlen
, enclen
;
783 unsigned char workbuf
[MAX_MULTIBYTE_LENGTH
], *buf
;
786 /* Glyphs with GLYPH_MASK_PADDING bit set are actually there
787 only for the redisplay code to know how many columns does
788 this character occupy on the screen. Skip padding glyphs. */
789 if (CHAR_GLYPH_PADDING_P (*str
))
796 register GLYPH g
= GLYPH_FROM_CHAR_GLYPH (*str
);
797 int glyph_not_in_table
= 0;
799 if (g
< 0 || g
>= tlen
)
801 /* This glyph doesn't have an entry in Vglyph_table. */
803 glyph_not_in_table
= 1;
807 /* This glyph has an entry in Vglyph_table, so process
808 any aliases before testing for simpleness. */
809 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
810 ch
= FAST_GLYPH_CHAR (g
);
813 /* Convert the character code to multibyte, if they
814 requested display via language environment. We only want
815 to convert unibyte characters to multibyte in unibyte
816 buffers! Otherwise, the 8-bit value in CH came from the
817 display table set up to display foreign characters. */
818 if (SINGLE_BYTE_CHAR_P (ch
) && convert_unibyte_characters
820 || (ch
>= 0200 && !NILP (Vnonascii_translation_table
))))
821 ch
= unibyte_char_to_multibyte (ch
);
823 /* Invalid characters are displayed with a special glyph. */
824 if (! CHAR_VALID_P (ch
, 0))
826 g
= !NILP (Vdos_unsupported_char_glyph
)
827 ? Vdos_unsupported_char_glyph
828 : MAKE_GLYPH (sf
, '\177', GLYPH_FACE (sf
, g
));
829 ch
= FAST_GLYPH_CHAR (g
);
832 /* If the face of this glyph is different from the current
833 screen face, update the screen attribute byte. */
834 cf
= FAST_GLYPH_FACE (g
);
835 if (cf
!= screen_face
)
836 IT_set_face (cf
); /* handles invalid faces gracefully */
838 if (glyph_not_in_table
|| GLYPH_SIMPLE_P (tbase
, tlen
, g
))
840 /* We generate the multi-byte form of CH in WORKBUF. */
841 chlen
= CHAR_STRING (ch
, workbuf
);
846 /* We have a string in Vglyph_table. */
847 chlen
= GLYPH_LENGTH (tbase
, g
);
848 buf
= GLYPH_STRING (tbase
, g
);
851 /* If the character is not multibyte, don't bother converting it. */
854 *conversion_buffer
= (unsigned char)ch
;
860 encode_coding (coding
, buf
, conversion_buffer
, chlen
,
861 conversion_buffer_size
);
862 chlen
-= coding
->consumed
;
863 enclen
= coding
->produced
;
865 /* Replace glyph codes that cannot be converted by
866 terminal_coding with Vdos_unsupported_char_glyph. */
867 if (*conversion_buffer
== '?')
869 char *cbp
= conversion_buffer
;
871 while (cbp
< conversion_buffer
+ enclen
&& *cbp
== '?')
872 *cbp
++ = unsupported_char
;
873 if (unsupported_face
!= screen_face
)
874 IT_set_face (unsupported_face
);
878 if (enclen
+ chlen
> screen_buf_end
- screen_bp
)
880 /* The allocated buffer for screen writes is too small.
881 Flush it and loop again without incrementing STR, so
882 that the next loop will begin with the same glyph. */
883 int nbytes
= screen_bp
- screen_buf
;
886 dosmemput (screen_buf
, nbytes
, (int)ScreenPrimary
+ offset
);
887 if (screen_virtual_segment
)
888 dosv_refresh_virtual_screen (offset
, nbytes
/ 2);
889 new_pos_X
+= nbytes
/ 2;
892 /* Prepare to reuse the same buffer again. */
893 screen_bp
= screen_buf
;
897 /* There's enough place in the allocated buffer to add
898 the encoding of this glyph. */
900 /* First, copy the encoded bytes. */
901 for (bp
= conversion_buffer
; enclen
--; bp
++)
903 *screen_bp
++ = (unsigned char)*bp
;
904 *screen_bp
++ = ScreenAttrib
;
906 fputc (*bp
, termscript
);
909 /* Now copy the bytes not consumed by the encoding. */
912 buf
+= coding
->consumed
;
916 fputc (*buf
, termscript
);
917 *screen_bp
++ = (unsigned char)*buf
++;
918 *screen_bp
++ = ScreenAttrib
;
922 /* Update STR and its remaining length. */
929 /* Dump whatever is left in the screen buffer. */
931 dosmemput (screen_buf
, screen_bp
- screen_buf
, (int)ScreenPrimary
+ offset
);
932 if (screen_virtual_segment
)
933 dosv_refresh_virtual_screen (offset
, (screen_bp
- screen_buf
) / 2);
934 new_pos_X
+= (screen_bp
- screen_buf
) / 2;
936 /* We may have to output some codes to terminate the writing. */
937 if (CODING_REQUIRE_FLUSHING (coding
))
939 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
940 encode_coding (coding
, "", conversion_buffer
, 0, conversion_buffer_size
);
941 if (coding
->produced
> 0)
943 for (screen_bp
= screen_buf
, bp
= conversion_buffer
;
944 coding
->produced
--; bp
++)
946 *screen_bp
++ = (unsigned char)*bp
;
947 *screen_bp
++ = ScreenAttrib
;
949 fputc (*bp
, termscript
);
951 offset
+= screen_bp
- screen_buf
;
953 dosmemput (screen_buf
, screen_bp
- screen_buf
,
954 (int)ScreenPrimary
+ offset
);
955 if (screen_virtual_segment
)
956 dosv_refresh_virtual_screen (offset
, (screen_bp
- screen_buf
) / 2);
957 new_pos_X
+= (screen_bp
- screen_buf
) / 2;
962 /************************************************************************
963 Mouse Highlight (and friends..)
964 ************************************************************************/
966 /* This is used for debugging, to turn off note_mouse_highlight. */
967 int disable_mouse_highlight
;
969 /* If a string, dos_rawgetc generates an event to display that string.
970 (The display is done in keyboard.c:read_char.) */
971 static Lisp_Object help_echo
;
972 static Lisp_Object previous_help_echo
; /* a helper temporary variable */
974 static int mouse_preempted
= 0; /* non-zero when XMenu gobbles mouse events */
976 /* Set the mouse pointer shape according to whether it is in the
977 area where the mouse highlight is in effect. */
979 IT_set_mouse_pointer (int mode
)
981 /* A no-op for now. DOS text-mode mouse pointer doesn't offer too
982 many possibilities to change its shape, and the available
983 functionality pretty much sucks (e.g., almost every reasonable
984 shape will conceal the character it is on). Since the color of
985 the pointer changes in the highlighted area, it is not clear to
986 me whether anything else is required, anyway. */
989 /* Display the active region described by mouse_face_*
990 in its mouse-face if HL > 0, in its normal face if HL = 0. */
992 show_mouse_face (struct display_info
*dpyinfo
, int hl
)
994 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
995 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1000 /* If window is in the process of being destroyed, don't bother
1002 if (w
->current_matrix
== NULL
)
1003 goto set_cursor_shape
;
1005 /* Recognize when we are called to operate on rows that don't exist
1006 anymore. This can happen when a window is split. */
1007 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
1008 goto set_cursor_shape
;
1010 /* There's no sense to do anything if the mouse face isn't realized. */
1013 fp
= FACE_FROM_ID (SELECTED_FRAME(), dpyinfo
->mouse_face_face_id
);
1015 goto set_cursor_shape
;
1018 /* Note that mouse_face_beg_row etc. are window relative. */
1019 for (i
= dpyinfo
->mouse_face_beg_row
;
1020 i
<= dpyinfo
->mouse_face_end_row
;
1023 int start_hpos
, end_hpos
;
1024 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
1026 /* Don't do anything if row doesn't have valid contents. */
1027 if (!row
->enabled_p
)
1030 /* For all but the first row, the highlight starts at column 0. */
1031 if (i
== dpyinfo
->mouse_face_beg_row
)
1032 start_hpos
= dpyinfo
->mouse_face_beg_col
;
1036 if (i
== dpyinfo
->mouse_face_end_row
)
1037 end_hpos
= dpyinfo
->mouse_face_end_col
;
1039 end_hpos
= row
->used
[TEXT_AREA
];
1041 if (end_hpos
<= start_hpos
)
1045 int vpos
= row
->y
+ WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w
);
1046 int kstart
= start_hpos
+ WINDOW_DISPLAY_LEFT_EDGE_PIXEL_X (w
);
1047 int nglyphs
= end_hpos
- start_hpos
;
1048 int offset
= ScreenPrimary
+ 2*(vpos
*screen_size_X
+ kstart
) + 1;
1049 int start_offset
= offset
;
1052 fprintf (termscript
, "\n<MH+ %d-%d:%d>",
1053 kstart
, kstart
+ nglyphs
- 1, vpos
);
1056 IT_set_face (dpyinfo
->mouse_face_face_id
);
1057 /* Since we are going to change only the _colors_ of the
1058 displayed text, there's no need to go through all the
1059 pain of generating and encoding the text from the glyphs.
1060 Instead, we simply poke the attribute byte of each
1061 affected position in video memory with the colors
1062 computed by IT_set_face! */
1063 _farsetsel (_dos_ds
);
1066 _farnspokeb (offset
, ScreenAttrib
);
1069 if (screen_virtual_segment
)
1070 dosv_refresh_virtual_screen (start_offset
, end_hpos
- start_hpos
);
1075 /* We are removing a previously-drawn mouse highlight. The
1076 safest way to do so is to redraw the glyphs anew, since
1077 all kinds of faces and display tables could have changed
1079 int nglyphs
= end_hpos
- start_hpos
;
1080 int save_x
= new_pos_X
, save_y
= new_pos_Y
;
1082 if (end_hpos
>= row
->used
[TEXT_AREA
])
1083 nglyphs
= row
->used
[TEXT_AREA
] - start_hpos
;
1085 /* IT_write_glyphs writes at cursor position, so we need to
1086 temporarily move cursor coordinates to the beginning of
1087 the highlight region. */
1088 new_pos_X
= start_hpos
+ WINDOW_DISPLAY_LEFT_EDGE_PIXEL_X (w
);
1089 new_pos_Y
= row
->y
+ WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w
);
1092 fprintf (termscript
, "<MH- %d-%d:%d>",
1093 new_pos_X
, new_pos_X
+ nglyphs
- 1, new_pos_Y
);
1094 IT_write_glyphs (row
->glyphs
[TEXT_AREA
] + start_hpos
, nglyphs
);
1096 fputs ("\n", termscript
);
1104 /* Change the mouse pointer shape. */
1105 IT_set_mouse_pointer (hl
);
1108 /* Clear out the mouse-highlighted active region.
1109 Redraw it un-highlighted first. */
1111 clear_mouse_face (struct display_info
*dpyinfo
)
1113 if (! NILP (dpyinfo
->mouse_face_window
))
1114 show_mouse_face (dpyinfo
, 0);
1116 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
1117 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
1118 dpyinfo
->mouse_face_window
= Qnil
;
1121 /* Find the glyph matrix position of buffer position POS in window W.
1122 *HPOS and *VPOS are set to the positions found. W's current glyphs
1123 must be up to date. If POS is above window start return (0, 0).
1124 If POS is after end of W, return end of last line in W. */
1126 fast_find_position (struct window
*w
, int pos
, int *hpos
, int *vpos
)
1130 int maybe_next_line_p
= 0;
1131 int line_start_position
;
1132 int yb
= window_text_bottom_y (w
);
1133 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0);
1134 struct glyph_row
*best_row
= row
;
1138 if (row
->used
[TEXT_AREA
])
1139 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
1141 line_start_position
= 0;
1143 if (line_start_position
> pos
)
1145 /* If the position sought is the end of the buffer,
1146 don't include the blank lines at the bottom of the window. */
1147 else if (line_start_position
== pos
1148 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
1150 maybe_next_line_p
= 1;
1153 else if (line_start_position
> 0)
1159 /* Find the right column within BEST_ROW. */
1162 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
1164 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + i
;
1167 charpos
= glyph
->charpos
;
1174 else if (charpos
> pos
)
1176 else if (charpos
> 0)
1180 /* If we're looking for the end of the buffer,
1181 and we didn't find it in the line we scanned,
1182 use the start of the following line. */
1183 if (maybe_next_line_p
)
1190 *hpos
= lastcol
+ 1;
1194 /* Take proper action when mouse has moved to the mode or top line of
1195 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
1196 mode line. X is relative to the start of the text display area of
1197 W, so the width of bitmap areas and scroll bars must be subtracted
1198 to get a position relative to the start of the mode line. */
1200 IT_note_mode_line_highlight (struct window
*w
, int x
, int mode_line_p
)
1202 struct frame
*f
= XFRAME (w
->frame
);
1203 struct display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1204 struct glyph_row
*row
;
1207 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
1209 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
1213 extern Lisp_Object Qhelp_echo
;
1214 struct glyph
*glyph
, *end
;
1215 Lisp_Object help
, map
;
1217 /* Find the glyph under X. */
1218 glyph
= row
->glyphs
[TEXT_AREA
]
1219 + x
- FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
1220 end
= glyph
+ row
->used
[TEXT_AREA
];
1222 && STRINGP (glyph
->object
)
1223 && XSTRING (glyph
->object
)->intervals
1224 && glyph
->charpos
>= 0
1225 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
1227 /* If we're on a string with `help-echo' text property,
1228 arrange for the help to be displayed. This is done by
1229 setting the global variable help_echo to the help string. */
1230 help
= Fget_text_property (make_number (glyph
->charpos
),
1231 Qhelp_echo
, glyph
->object
);
1238 /* Take proper action when the mouse has moved to position X, Y on
1239 frame F as regards highlighting characters that have mouse-face
1240 properties. Also de-highlighting chars where the mouse was before.
1241 X and Y can be negative or out of range. */
1243 IT_note_mouse_highlight (struct frame
*f
, int x
, int y
)
1245 struct display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1250 /* When a menu is active, don't highlight because this looks odd. */
1251 if (mouse_preempted
)
1254 if (disable_mouse_highlight
)
1257 dpyinfo
->mouse_face_mouse_x
= x
;
1258 dpyinfo
->mouse_face_mouse_y
= y
;
1259 dpyinfo
->mouse_face_mouse_frame
= f
;
1261 if (dpyinfo
->mouse_face_defer
)
1266 dpyinfo
->mouse_face_deferred_gc
= 1;
1270 /* Which window is that in? */
1271 window
= window_from_coordinates (f
, x
, y
, &portion
, 0);
1273 /* If we were displaying active text in another window, clear that. */
1274 if (! EQ (window
, dpyinfo
->mouse_face_window
))
1275 clear_mouse_face (dpyinfo
);
1277 /* Not on a window -> return. */
1278 if (!WINDOWP (window
))
1281 /* Convert to window-relative coordinates. */
1282 w
= XWINDOW (window
);
1283 x
-= WINDOW_DISPLAY_LEFT_EDGE_PIXEL_X (w
);
1284 y
-= WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w
);
1286 if (portion
== 1 || portion
== 3)
1288 /* Mouse is on the mode or top line. */
1289 IT_note_mode_line_highlight (w
, x
, portion
== 1);
1293 IT_set_mouse_pointer (0);
1295 /* Are we in a window whose display is up to date?
1296 And verify the buffer's text has not changed. */
1297 if (/* Within text portion of the window. */
1299 && EQ (w
->window_end_valid
, w
->buffer
)
1300 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
1301 && (XFASTINT (w
->last_overlay_modified
)
1302 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
1305 struct glyph_row
*row
;
1306 struct glyph
*glyph
;
1308 /* Find the glyph under X/Y. */
1310 if (y
< w
->current_matrix
->nrows
)
1312 row
= MATRIX_ROW (w
->current_matrix
, y
);
1314 && row
->displays_text_p
1315 && x
< window_box_width (w
, TEXT_AREA
))
1317 glyph
= row
->glyphs
[TEXT_AREA
];
1318 if (x
>= row
->used
[TEXT_AREA
])
1323 if (!BUFFERP (glyph
->object
))
1329 /* Clear mouse face if X/Y not over text. */
1332 clear_mouse_face (dpyinfo
);
1336 if (!BUFFERP (glyph
->object
))
1338 pos
= glyph
->charpos
;
1340 /* Check for mouse-face and help-echo. */
1342 extern Lisp_Object Qmouse_face
;
1343 Lisp_Object mouse_face
, overlay
, position
;
1344 Lisp_Object
*overlay_vec
;
1346 struct buffer
*obuf
;
1349 /* If we get an out-of-range value, return now; avoid an error. */
1350 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
1353 /* Make the window's buffer temporarily current for
1354 overlays_at and compute_char_face. */
1355 obuf
= current_buffer
;
1356 current_buffer
= XBUFFER (w
->buffer
);
1362 /* Is this char mouse-active or does it have help-echo? */
1363 XSETINT (position
, pos
);
1365 /* Put all the overlays we want in a vector in overlay_vec.
1366 Store the length in len. If there are more than 10, make
1367 enough space for all, and try again. */
1369 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
1370 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
);
1371 if (noverlays
> len
)
1374 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
1375 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
);
1378 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
1380 /* Check mouse-face highlighting. */
1381 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
1382 && y
>= dpyinfo
->mouse_face_beg_row
1383 && y
<= dpyinfo
->mouse_face_end_row
1384 && (y
> dpyinfo
->mouse_face_beg_row
1385 || x
>= dpyinfo
->mouse_face_beg_col
)
1386 && (y
< dpyinfo
->mouse_face_end_row
1387 || x
< dpyinfo
->mouse_face_end_col
1388 || dpyinfo
->mouse_face_past_end
)))
1390 /* Clear the display of the old active region, if any. */
1391 clear_mouse_face (dpyinfo
);
1393 /* Find highest priority overlay that has a mouse-face prop. */
1395 for (i
= 0; i
< noverlays
; i
++)
1397 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
1398 if (!NILP (mouse_face
))
1400 overlay
= overlay_vec
[i
];
1405 /* If no overlay applies, get a text property. */
1407 mouse_face
= Fget_text_property (position
, Qmouse_face
,
1410 /* Handle the overlay case. */
1411 if (! NILP (overlay
))
1413 /* Find the range of text around this char that
1414 should be active. */
1415 Lisp_Object before
, after
;
1418 before
= Foverlay_start (overlay
);
1419 after
= Foverlay_end (overlay
);
1420 /* Record this as the current active region. */
1421 fast_find_position (w
, XFASTINT (before
),
1422 &dpyinfo
->mouse_face_beg_col
,
1423 &dpyinfo
->mouse_face_beg_row
);
1424 dpyinfo
->mouse_face_past_end
1425 = !fast_find_position (w
, XFASTINT (after
),
1426 &dpyinfo
->mouse_face_end_col
,
1427 &dpyinfo
->mouse_face_end_row
);
1428 dpyinfo
->mouse_face_window
= window
;
1429 dpyinfo
->mouse_face_face_id
1430 = face_at_buffer_position (w
, pos
, 0, 0,
1431 &ignore
, pos
+ 1, 1);
1433 /* Display it as active. */
1434 show_mouse_face (dpyinfo
, 1);
1436 /* Handle the text property case. */
1437 else if (! NILP (mouse_face
))
1439 /* Find the range of text around this char that
1440 should be active. */
1441 Lisp_Object before
, after
, beginning
, end
;
1444 beginning
= Fmarker_position (w
->start
);
1445 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
1446 - XFASTINT (w
->window_end_pos
)));
1448 = Fprevious_single_property_change (make_number (pos
+ 1),
1450 w
->buffer
, beginning
);
1452 = Fnext_single_property_change (position
, Qmouse_face
,
1454 /* Record this as the current active region. */
1455 fast_find_position (w
, XFASTINT (before
),
1456 &dpyinfo
->mouse_face_beg_col
,
1457 &dpyinfo
->mouse_face_beg_row
);
1458 dpyinfo
->mouse_face_past_end
1459 = !fast_find_position (w
, XFASTINT (after
),
1460 &dpyinfo
->mouse_face_end_col
,
1461 &dpyinfo
->mouse_face_end_row
);
1462 dpyinfo
->mouse_face_window
= window
;
1463 dpyinfo
->mouse_face_face_id
1464 = face_at_buffer_position (w
, pos
, 0, 0,
1465 &ignore
, pos
+ 1, 1);
1467 /* Display it as active. */
1468 show_mouse_face (dpyinfo
, 1);
1472 /* Look for a `help-echo' property. */
1475 extern Lisp_Object Qhelp_echo
;
1477 /* Check overlays first. */
1479 for (i
= 0; i
< noverlays
&& !STRINGP (help
); ++i
)
1480 help
= Foverlay_get (overlay_vec
[i
], Qhelp_echo
);
1482 /* Try text properties. */
1484 && ((STRINGP (glyph
->object
)
1485 && glyph
->charpos
>= 0
1486 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
1487 || (BUFFERP (glyph
->object
)
1488 && glyph
->charpos
>= BEGV
1489 && glyph
->charpos
< ZV
)))
1490 help
= Fget_text_property (make_number (glyph
->charpos
),
1491 Qhelp_echo
, glyph
->object
);
1499 current_buffer
= obuf
;
1505 IT_clear_end_of_line (int first_unused
)
1509 int offset
= 2 * (new_pos_X
+ screen_size_X
* new_pos_Y
);
1510 extern int fatal_error_in_progress
;
1512 if (new_pos_X
>= first_unused
|| fatal_error_in_progress
)
1517 fprintf (termscript
, "<CLR:EOL>");
1518 i
= (j
= first_unused
- new_pos_X
) * 2;
1519 spaces
= sp
= alloca (i
);
1524 *sp
++ = ScreenAttrib
;
1528 dosmemput (spaces
, i
, (int)ScreenPrimary
+ offset
);
1529 if (screen_virtual_segment
)
1530 dosv_refresh_virtual_screen (offset
, i
/ 2);
1532 /* clear_end_of_line_raw on term.c leaves the cursor at first_unused.
1533 Let's follow their lead, in case someone relies on this. */
1534 new_pos_X
= first_unused
;
1538 IT_clear_screen (void)
1541 fprintf (termscript
, "<CLR:SCR>");
1545 if (screen_virtual_segment
)
1546 dosv_refresh_virtual_screen (0, screen_size
);
1547 new_pos_X
= new_pos_Y
= 0;
1551 IT_clear_to_end (void)
1554 fprintf (termscript
, "<CLR:EOS>");
1556 while (new_pos_Y
< screen_size_Y
) {
1558 IT_clear_end_of_line (0);
1564 IT_cursor_to (int y
, int x
)
1567 fprintf (termscript
, "\n<XY=%dx%d>", x
, y
);
1572 static int cursor_cleared
;
1575 IT_display_cursor (int on
)
1577 if (on
&& cursor_cleared
)
1579 ScreenSetCursor (current_pos_Y
, current_pos_X
);
1582 else if (!on
&& !cursor_cleared
)
1584 ScreenSetCursor (-1, -1);
1589 /* Emacs calls cursor-movement functions a lot when it updates the
1590 display (probably a legacy of old terminals where you cannot
1591 update a screen line without first moving the cursor there).
1592 However, cursor movement is expensive on MSDOS (it calls a slow
1593 BIOS function and requires 2 mode switches), while actual screen
1594 updates access the video memory directly and don't depend on
1595 cursor position. To avoid slowing down the redisplay, we cheat:
1596 all functions that move the cursor only set internal variables
1597 which record the cursor position, whereas the cursor is only
1598 moved to its final position whenever screen update is complete.
1600 `IT_cmgoto' is called from the keyboard reading loop and when the
1601 frame update is complete. This means that we are ready for user
1602 input, so we update the cursor position to show where the point is,
1603 and also make the mouse pointer visible.
1605 Special treatment is required when the cursor is in the echo area,
1606 to put the cursor at the end of the text displayed there. */
1609 IT_cmgoto (FRAME_PTR f
)
1611 /* Only set the cursor to where it should be if the display is
1612 already in sync with the window contents. */
1613 int update_cursor_pos
= 1; /* MODIFF == unchanged_modified; */
1615 /* FIXME: This needs to be rewritten for the new redisplay, or
1618 static int previous_pos_X
= -1;
1620 update_cursor_pos
= 1; /* temporary!!! */
1622 /* If the display is in sync, forget any previous knowledge about
1623 cursor position. This is primarily for unexpected events like
1624 C-g in the minibuffer. */
1625 if (update_cursor_pos
&& previous_pos_X
>= 0)
1626 previous_pos_X
= -1;
1627 /* If we are in the echo area, put the cursor at the
1628 end of the echo area message. */
1629 if (!update_cursor_pos
1630 && XFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f
))->top
) <= new_pos_Y
)
1632 int tem_X
= current_pos_X
, dummy
;
1634 if (echo_area_glyphs
)
1636 tem_X
= echo_area_glyphs_length
;
1637 /* Save current cursor position, to be restored after the
1638 echo area message is erased. Only remember one level
1639 of previous cursor position. */
1640 if (previous_pos_X
== -1)
1641 ScreenGetCursor (&dummy
, &previous_pos_X
);
1643 else if (previous_pos_X
>= 0)
1645 /* We wind up here after the echo area message is erased.
1646 Restore the cursor position we remembered above. */
1647 tem_X
= previous_pos_X
;
1648 previous_pos_X
= -1;
1651 if (current_pos_X
!= tem_X
)
1654 update_cursor_pos
= 1;
1659 if (update_cursor_pos
1660 && (current_pos_X
!= new_pos_X
|| current_pos_Y
!= new_pos_Y
))
1662 ScreenSetCursor (current_pos_Y
= new_pos_Y
, current_pos_X
= new_pos_X
);
1664 fprintf (termscript
, "\n<CURSOR:%dx%d>", current_pos_X
, current_pos_Y
);
1667 /* Maybe cursor is invisible, so make it visible. */
1668 IT_display_cursor (1);
1670 /* Mouse pointer should be always visible if we are waiting for
1677 IT_reassert_line_highlight (int new, int vpos
)
1683 IT_change_line_highlight (int new_highlight
, int y
, int vpos
, int first_unused_hpos
)
1685 highlight
= new_highlight
;
1686 IT_cursor_to (vpos
, 0);
1687 IT_clear_end_of_line (first_unused_hpos
);
1691 IT_update_begin (struct frame
*f
)
1693 struct display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
1699 if (f
== display_info
->mouse_face_mouse_frame
)
1701 /* Don't do highlighting for mouse motion during the update. */
1702 display_info
->mouse_face_defer
= 1;
1704 /* If F needs to be redrawn, simply forget about any prior mouse
1706 if (FRAME_GARBAGED_P (f
))
1707 display_info
->mouse_face_window
= Qnil
;
1709 /* Can we tell that this update does not affect the window
1710 where the mouse highlight is? If so, no need to turn off.
1711 Likewise, don't do anything if the frame is garbaged;
1712 in that case, the frame's current matrix that we would use
1713 is all wrong, and we will redisplay that line anyway. */
1714 if (!NILP (display_info
->mouse_face_window
))
1716 struct window
*w
= XWINDOW (display_info
->mouse_face_window
);
1719 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
1720 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
1723 if (i
< w
->desired_matrix
->nrows
)
1724 clear_mouse_face (display_info
);
1727 else if (!FRAME_LIVE_P (display_info
->mouse_face_mouse_frame
))
1729 /* If the frame with mouse highlight was deleted, invalidate the
1731 display_info
->mouse_face_beg_row
= display_info
->mouse_face_beg_col
= -1;
1732 display_info
->mouse_face_end_row
= display_info
->mouse_face_end_col
= -1;
1733 display_info
->mouse_face_window
= Qnil
;
1734 display_info
->mouse_face_deferred_gc
= 0;
1735 display_info
->mouse_face_mouse_frame
= NULL
;
1742 IT_update_end (struct frame
*f
)
1745 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
1749 IT_frame_up_to_date (struct frame
*f
)
1751 struct display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1753 if (dpyinfo
->mouse_face_deferred_gc
1754 || f
== dpyinfo
->mouse_face_mouse_frame
)
1757 if (dpyinfo
->mouse_face_mouse_frame
)
1758 IT_note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
1759 dpyinfo
->mouse_face_mouse_x
,
1760 dpyinfo
->mouse_face_mouse_y
);
1761 dpyinfo
->mouse_face_deferred_gc
= 0;
1765 IT_cmgoto (f
); /* position cursor when update is done */
1768 /* Copy LEN glyphs displayed on a single line whose vertical position
1769 is YPOS, beginning at horizontal position XFROM to horizontal
1770 position XTO, by moving blocks in the video memory. Used by
1771 functions that insert and delete glyphs. */
1773 IT_copy_glyphs (int xfrom
, int xto
, size_t len
, int ypos
)
1775 /* The offsets of source and destination relative to the
1776 conventional memorty selector. */
1777 int from
= 2 * (xfrom
+ screen_size_X
* ypos
) + ScreenPrimary
;
1778 int to
= 2 * (xto
+ screen_size_X
* ypos
) + ScreenPrimary
;
1780 if (from
== to
|| len
<= 0)
1783 _farsetsel (_dos_ds
);
1785 /* The source and destination might overlap, so we need to move
1786 glyphs non-destructively. */
1789 for ( ; len
; from
+= 2, to
+= 2, len
--)
1790 _farnspokew (to
, _farnspeekw (from
));
1794 from
+= (len
- 1) * 2;
1795 to
+= (len
- 1) * 2;
1796 for ( ; len
; from
-= 2, to
-= 2, len
--)
1797 _farnspokew (to
, _farnspeekw (from
));
1799 if (screen_virtual_segment
)
1800 dosv_refresh_virtual_screen (ypos
* screen_size_X
* 2, screen_size_X
);
1803 /* Insert and delete glyphs. */
1805 IT_insert_glyphs (start
, len
)
1806 register struct glyph
*start
;
1809 int shift_by_width
= screen_size_X
- (new_pos_X
+ len
);
1811 /* Shift right the glyphs from the nominal cursor position to the
1812 end of this line. */
1813 IT_copy_glyphs (new_pos_X
, new_pos_X
+ len
, shift_by_width
, new_pos_Y
);
1815 /* Now write the glyphs to be inserted. */
1816 IT_write_glyphs (start
, len
);
1820 IT_delete_glyphs (n
)
1826 /* set-window-configuration on window.c needs this. */
1828 x_set_menu_bar_lines (f
, value
, oldval
)
1830 Lisp_Object value
, oldval
;
1832 set_menu_bar_lines (f
, value
, oldval
);
1835 /* This was copied from xfns.c */
1837 Lisp_Object Qbackground_color
;
1838 Lisp_Object Qforeground_color
;
1839 extern Lisp_Object Qtitle
;
1841 /* IT_set_terminal_modes is called when emacs is started,
1842 resumed, and whenever the screen is redrawn! */
1845 IT_set_terminal_modes (void)
1848 fprintf (termscript
, "\n<SET_TERM>");
1851 screen_size_X
= ScreenCols ();
1852 screen_size_Y
= ScreenRows ();
1853 screen_size
= screen_size_X
* screen_size_Y
;
1855 new_pos_X
= new_pos_Y
= 0;
1856 current_pos_X
= current_pos_Y
= -1;
1858 if (term_setup_done
)
1860 term_setup_done
= 1;
1862 startup_screen_size_X
= screen_size_X
;
1863 startup_screen_size_Y
= screen_size_Y
;
1864 startup_screen_attrib
= ScreenAttrib
;
1867 /* Is DOS/V (or any other RSIS software which relocates
1868 the screen) installed? */
1870 unsigned short es_value
;
1873 regs
.h
.ah
= 0xfe; /* get relocated screen address */
1874 if (ScreenPrimary
== 0xb0000UL
|| ScreenPrimary
== 0xb8000UL
)
1875 regs
.x
.es
= (ScreenPrimary
>> 4) & 0xffff;
1876 else if (screen_old_address
) /* already switched to Japanese mode once */
1877 regs
.x
.es
= (screen_old_address
>> 4) & 0xffff;
1879 regs
.x
.es
= ScreenMode () == 7 ? 0xb000 : 0xb800;
1881 es_value
= regs
.x
.es
;
1882 __dpmi_int (0x10, ®s
);
1884 if (regs
.x
.es
!= es_value
)
1886 /* screen_old_address is only set if ScreenPrimary does NOT
1887 already point to the relocated buffer address returned by
1888 the Int 10h/AX=FEh call above. DJGPP v2.02 and later sets
1889 ScreenPrimary to that address at startup under DOS/V. */
1890 if (regs
.x
.es
!= (ScreenPrimary
>> 4) & 0xffff)
1891 screen_old_address
= ScreenPrimary
;
1892 screen_virtual_segment
= regs
.x
.es
;
1893 screen_virtual_offset
= regs
.x
.di
;
1894 ScreenPrimary
= (screen_virtual_segment
<< 4) + screen_virtual_offset
;
1897 #endif /* __DJGPP__ > 1 */
1899 ScreenGetCursor (&startup_pos_Y
, &startup_pos_X
);
1900 ScreenRetrieve (startup_screen_buffer
= xmalloc (screen_size
* 2));
1903 fprintf (termscript
, "<SCREEN SAVED (dimensions=%dx%d)>\n",
1904 screen_size_X
, screen_size_Y
);
1909 /* IT_reset_terminal_modes is called when emacs is
1910 suspended or killed. */
1913 IT_reset_terminal_modes (void)
1915 int display_row_start
= (int) ScreenPrimary
;
1916 int saved_row_len
= startup_screen_size_X
* 2;
1917 int update_row_len
= ScreenCols () * 2;
1918 int current_rows
= ScreenRows ();
1919 int to_next_row
= update_row_len
;
1920 unsigned char *saved_row
= startup_screen_buffer
;
1921 int cursor_pos_X
= ScreenCols () - 1;
1922 int cursor_pos_Y
= ScreenRows () - 1;
1925 fprintf (termscript
, "\n<RESET_TERM>");
1929 if (!term_setup_done
)
1934 /* Leave the video system in the same state as we found it,
1935 as far as the blink/bright-background bit is concerned. */
1936 maybe_enable_blinking ();
1938 /* We have a situation here.
1939 We cannot just do ScreenUpdate(startup_screen_buffer) because
1940 the luser could have changed screen dimensions inside Emacs
1941 and failed (or didn't want) to restore them before killing
1942 Emacs. ScreenUpdate() uses the *current* screen dimensions and
1943 thus will happily use memory outside what was allocated for
1944 `startup_screen_buffer'.
1945 Thus we only restore as much as the current screen dimensions
1946 can hold, and clear the rest (if the saved screen is smaller than
1947 the current) with the color attribute saved at startup. The cursor
1948 is also restored within the visible dimensions. */
1950 ScreenAttrib
= startup_screen_attrib
;
1952 /* Don't restore the screen if we are exiting less than 2 seconds
1953 after startup: we might be crashing, and the screen might show
1954 some vital clues to what's wrong. */
1955 if (clock () - startup_time
>= 2*CLOCKS_PER_SEC
)
1958 if (screen_virtual_segment
)
1959 dosv_refresh_virtual_screen (0, screen_size
);
1961 if (update_row_len
> saved_row_len
)
1962 update_row_len
= saved_row_len
;
1963 if (current_rows
> startup_screen_size_Y
)
1964 current_rows
= startup_screen_size_Y
;
1967 fprintf (termscript
, "<SCREEN RESTORED (dimensions=%dx%d)>\n",
1968 update_row_len
/ 2, current_rows
);
1970 while (current_rows
--)
1972 dosmemput (saved_row
, update_row_len
, display_row_start
);
1973 if (screen_virtual_segment
)
1974 dosv_refresh_virtual_screen (display_row_start
- ScreenPrimary
,
1975 update_row_len
/ 2);
1976 saved_row
+= saved_row_len
;
1977 display_row_start
+= to_next_row
;
1980 if (startup_pos_X
< cursor_pos_X
)
1981 cursor_pos_X
= startup_pos_X
;
1982 if (startup_pos_Y
< cursor_pos_Y
)
1983 cursor_pos_Y
= startup_pos_Y
;
1985 ScreenSetCursor (cursor_pos_Y
, cursor_pos_X
);
1986 xfree (startup_screen_buffer
);
1988 term_setup_done
= 0;
1992 IT_set_terminal_window (int foo
)
1996 /* Remember the screen colors of the curent frame, to serve as the
1997 default colors for newly-created frames. */
1999 static int initial_screen_colors
[2];
2001 DEFUN ("msdos-remember-default-colors", Fmsdos_remember_default_colors
,
2002 Smsdos_remember_default_colors
, 1, 1, 0,
2003 "Remember the screen colors of the current frame.")
2010 CHECK_FRAME (frame
, 0);
2012 reverse
= EQ (Fcdr (Fassq (intern ("reverse"), f
->param_alist
)), Qt
);
2014 initial_screen_colors
[0]
2015 = reverse
? FRAME_BACKGROUND_PIXEL (f
) : FRAME_FOREGROUND_PIXEL (f
);
2016 initial_screen_colors
[1]
2017 = reverse
? FRAME_FOREGROUND_PIXEL (f
) : FRAME_BACKGROUND_PIXEL (f
);
2021 IT_set_frame_parameters (f
, alist
)
2026 int length
= XINT (Flength (alist
));
2029 = (Lisp_Object
*) alloca (length
* sizeof (Lisp_Object
));
2031 = (Lisp_Object
*) alloca (length
* sizeof (Lisp_Object
));
2032 Lisp_Object qreverse
= intern ("reverse");
2033 /* Do we have to reverse the foreground and background colors? */
2034 int reverse
= EQ (Fcdr (Fassq (qreverse
, f
->param_alist
)), Qt
);
2035 int was_reverse
= reverse
;
2036 int redraw
= 0, fg_set
= 0, bg_set
= 0;
2037 unsigned long orig_fg
;
2038 unsigned long orig_bg
;
2040 /* If we are creating a new frame, begin with the original screen colors
2041 used for the initial frame. */
2042 if (alist
== Vdefault_frame_alist
2043 && initial_screen_colors
[0] != -1 && initial_screen_colors
[1] != -1)
2045 FRAME_FOREGROUND_PIXEL (f
) = initial_screen_colors
[0];
2046 FRAME_BACKGROUND_PIXEL (f
) = initial_screen_colors
[1];
2048 orig_fg
= FRAME_FOREGROUND_PIXEL (f
);
2049 orig_bg
= FRAME_BACKGROUND_PIXEL (f
);
2051 /* Extract parm names and values into those vectors. */
2053 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
2058 parms
[i
] = Fcar (elt
);
2059 CHECK_SYMBOL (parms
[i
], 1);
2060 values
[i
] = Fcdr (elt
);
2066 for (i
= 0; i
< j
; i
++)
2068 Lisp_Object prop
= parms
[i
];
2069 Lisp_Object val
= values
[i
];
2071 if (EQ (prop
, qreverse
))
2072 reverse
= EQ (val
, Qt
);
2075 if (termscript
&& reverse
&& !was_reverse
)
2076 fprintf (termscript
, "<INVERSE-VIDEO>\n");
2078 /* Now process the alist elements in reverse of specified order. */
2079 for (i
--; i
>= 0; i
--)
2081 Lisp_Object prop
= parms
[i
];
2082 Lisp_Object val
= values
[i
];
2084 if (EQ (prop
, Qforeground_color
))
2086 unsigned long new_color
= load_color (f
, NULL
, val
, reverse
2087 ? LFACE_BACKGROUND_INDEX
2088 : LFACE_FOREGROUND_INDEX
);
2089 if (new_color
!= FACE_TTY_DEFAULT_COLOR
2090 && new_color
!= FACE_TTY_DEFAULT_FG_COLOR
2091 && new_color
!= FACE_TTY_DEFAULT_BG_COLOR
)
2094 /* FIXME: should the fore-/background of the default
2095 face change here as well? */
2096 FRAME_BACKGROUND_PIXEL (f
) = new_color
;
2098 FRAME_FOREGROUND_PIXEL (f
) = new_color
;
2102 fprintf (termscript
, "<FGCOLOR %lu>\n", new_color
);
2105 else if (EQ (prop
, Qbackground_color
))
2107 unsigned long new_color
= load_color (f
, NULL
, val
, reverse
2108 ? LFACE_FOREGROUND_INDEX
2109 : LFACE_BACKGROUND_INDEX
);
2110 if (new_color
!= FACE_TTY_DEFAULT_COLOR
2111 && new_color
!= FACE_TTY_DEFAULT_FG_COLOR
2112 && new_color
!= FACE_TTY_DEFAULT_BG_COLOR
)
2115 FRAME_FOREGROUND_PIXEL (f
) = new_color
;
2117 FRAME_BACKGROUND_PIXEL (f
) = new_color
;
2121 fprintf (termscript
, "<BGCOLOR %lu>\n", new_color
);
2124 else if (EQ (prop
, Qtitle
))
2126 x_set_title (f
, val
);
2128 fprintf (termscript
, "<TITLE: %s>\n", XSTRING (val
)->data
);
2130 store_frame_param (f
, prop
, val
);
2133 /* If they specified "reverse", but not the colors, we need to swap
2134 the current frame colors. */
2135 if (reverse
&& !was_reverse
)
2139 FRAME_BACKGROUND_PIXEL (f
) = orig_fg
;
2144 FRAME_FOREGROUND_PIXEL (f
) = orig_bg
;
2151 face_change_count
++; /* forces xdisp.c to recompute basic faces */
2152 if (f
== SELECTED_FRAME())
2157 extern void init_frame_faces (FRAME_PTR
);
2159 #endif /* !HAVE_X_WINDOWS */
2162 /* Do we need the internal terminal? */
2165 internal_terminal_init ()
2167 char *term
= getenv ("TERM");
2169 struct frame
*sf
= SELECTED_FRAME();
2171 #ifdef HAVE_X_WINDOWS
2172 if (!inhibit_window_system
)
2177 = (!noninteractive
) && term
&& !strcmp (term
, "internal");
2179 if (getenv ("EMACSTEST"))
2180 termscript
= fopen (getenv ("EMACSTEST"), "wt");
2182 #ifndef HAVE_X_WINDOWS
2183 if (!internal_terminal
|| inhibit_window_system
)
2185 sf
->output_method
= output_termcap
;
2189 Vwindow_system
= intern ("pc");
2190 Vwindow_system_version
= make_number (1);
2191 sf
->output_method
= output_msdos_raw
;
2193 /* If Emacs was dumped on DOS/V machine, forget the stale VRAM address. */
2194 screen_old_address
= 0;
2196 /* Forget the stale screen colors as well. */
2197 initial_screen_colors
[0] = initial_screen_colors
[1] = -1;
2199 bzero (&the_only_x_display
, sizeof the_only_x_display
);
2200 the_only_x_display
.background_pixel
= 7; /* White */
2201 the_only_x_display
.foreground_pixel
= 0; /* Black */
2203 colors
= getenv ("EMACSCOLORS");
2204 if (colors
&& strlen (colors
) >= 2)
2206 /* The colors use 4 bits each (we enable bright background). */
2207 if (isdigit (colors
[0]))
2209 else if (isxdigit (colors
[0]))
2210 colors
[0] -= (isupper (colors
[0]) ? 'A' : 'a') - 10;
2211 if (colors
[0] >= 0 && colors
[0] < 16)
2212 the_only_x_display
.foreground_pixel
= colors
[0];
2213 if (isdigit (colors
[1]))
2215 else if (isxdigit (colors
[1]))
2216 colors
[1] -= (isupper (colors
[1]) ? 'A' : 'a') - 10;
2217 if (colors
[1] >= 0 && colors
[1] < 16)
2218 the_only_x_display
.background_pixel
= colors
[1];
2220 the_only_x_display
.line_height
= 1;
2221 the_only_x_display
.font
= (XFontStruct
*)1; /* must *not* be zero */
2222 the_only_x_display
.display_info
.mouse_face_mouse_frame
= NULL
;
2223 the_only_x_display
.display_info
.mouse_face_deferred_gc
= 0;
2224 the_only_x_display
.display_info
.mouse_face_beg_row
=
2225 the_only_x_display
.display_info
.mouse_face_beg_col
= -1;
2226 the_only_x_display
.display_info
.mouse_face_end_row
=
2227 the_only_x_display
.display_info
.mouse_face_end_col
= -1;
2228 the_only_x_display
.display_info
.mouse_face_face_id
= DEFAULT_FACE_ID
;
2229 the_only_x_display
.display_info
.mouse_face_window
= Qnil
;
2230 the_only_x_display
.display_info
.mouse_face_mouse_x
=
2231 the_only_x_display
.display_info
.mouse_face_mouse_y
= 0;
2232 the_only_x_display
.display_info
.mouse_face_defer
= 0;
2234 init_frame_faces (sf
);
2236 ring_bell_hook
= IT_ring_bell
;
2237 insert_glyphs_hook
= IT_insert_glyphs
;
2238 delete_glyphs_hook
= IT_delete_glyphs
;
2239 write_glyphs_hook
= IT_write_glyphs
;
2240 cursor_to_hook
= raw_cursor_to_hook
= IT_cursor_to
;
2241 clear_to_end_hook
= IT_clear_to_end
;
2242 clear_end_of_line_hook
= IT_clear_end_of_line
;
2243 clear_frame_hook
= IT_clear_screen
;
2244 change_line_highlight_hook
= IT_change_line_highlight
;
2245 update_begin_hook
= IT_update_begin
;
2246 update_end_hook
= IT_update_end
;
2247 reassert_line_highlight_hook
= IT_reassert_line_highlight
;
2248 frame_up_to_date_hook
= IT_frame_up_to_date
;
2250 /* These hooks are called by term.c without being checked. */
2251 set_terminal_modes_hook
= IT_set_terminal_modes
;
2252 reset_terminal_modes_hook
= IT_reset_terminal_modes
;
2253 set_terminal_window_hook
= IT_set_terminal_window
;
2254 char_ins_del_ok
= 0;
2258 dos_get_saved_screen (screen
, rows
, cols
)
2263 #ifndef HAVE_X_WINDOWS
2264 *screen
= startup_screen_buffer
;
2265 *cols
= startup_screen_size_X
;
2266 *rows
= startup_screen_size_Y
;
2267 return *screen
!= (char *)0;
2273 #ifndef HAVE_X_WINDOWS
2275 /* We are not X, but we can emulate it well enough for our needs... */
2279 if (! FRAME_MSDOS_P (SELECTED_FRAME()))
2280 error ("Not running under a window system");
2286 /* ----------------------- Keyboard control ----------------------
2288 * Keymaps reflect the following keyboard layout:
2290 * 0 1 2 3 4 5 6 7 8 9 10 11 12 BS
2291 * TAB 15 16 17 18 19 20 21 22 23 24 25 26 (41)
2292 * CLOK 30 31 32 33 34 35 36 37 38 39 40 (41) RET
2293 * SH () 45 46 47 48 49 50 51 52 53 54 SHIFT
2297 #define Ignore 0x0000
2298 #define Normal 0x0000 /* normal key - alt changes scan-code */
2299 #define FctKey 0x1000 /* func key if c == 0, else c */
2300 #define Special 0x2000 /* func key even if c != 0 */
2301 #define ModFct 0x3000 /* special if mod-keys, else 'c' */
2302 #define Map 0x4000 /* alt scan-code, map to unshift/shift key */
2303 #define KeyPad 0x5000 /* map to insert/kp-0 depending on c == 0xe0 */
2304 #define Grey 0x6000 /* Grey keypad key */
2306 #define Alt 0x0100 /* alt scan-code */
2307 #define Ctrl 0x0200 /* ctrl scan-code */
2308 #define Shift 0x0400 /* shift scan-code */
2310 static int extended_kbd
; /* 101 (102) keyboard present. */
2312 struct kbd_translate
{
2315 unsigned short code
;
2318 struct dos_keyboard_map
2323 struct kbd_translate
*translate_table
;
2327 static struct dos_keyboard_map us_keyboard
= {
2329 /* 01234567890123456789012345678901234567890 12345678901234 */
2330 "`1234567890-= qwertyuiop[] asdfghjkl;'\\ zxcvbnm,./ ",
2331 /* 0123456789012345678901234567890123456789 012345678901234 */
2332 "~!@#$%^&*()_+ QWERTYUIOP{} ASDFGHJKL:\"| ZXCVBNM<>? ",
2333 0, /* no Alt-Gr key */
2334 0 /* no translate table */
2337 static struct dos_keyboard_map fr_keyboard
= {
2339 /* 012 3456789012345678901234567890123456789012345678901234 */
2340 "ý&\82\",(-\8a_\80\85)= azertyuiop^$ qsdfghjklm\97* wxcvbnm;:! ",
2341 /* 0123456789012345678901234567890123456789012345678901234 */
2342 " 1234567890ø+ AZERTYUIOPù\9c QSDFGHJKLM%æ WXCVBN?./õ ",
2343 /* 01234567 89012345678901234567890123456789012345678901234 */
2345 0 /* no translate table */
2349 * Italian keyboard support, country code 39.
2352 * added also {,},` as, respectively, AltGr-8, AltGr-9, AltGr-'
2353 * Donated by Stefano Brozzi <brozzis@mag00.cedi.unipr.it>
2356 static struct kbd_translate it_kbd_translate_table
[] = {
2357 { 0x56, 0x3c, Normal
| 13 },
2358 { 0x56, 0x3e, Normal
| 27 },
2361 static struct dos_keyboard_map it_keyboard
= {
2363 /* 0 123456789012345678901234567890123456789012345678901234 */
2364 "\\1234567890'\8d< qwertyuiop\8a+> asdfghjkl\95\85\97 zxcvbnm,.- ",
2365 /* 01 23456789012345678901234567890123456789012345678901234 */
2366 "|!\"\9c$%&/()=?^> QWERTYUIOP\82* ASDFGHJKL\87øõ ZXCVBNM;:_ ",
2367 /* 0123456789012345678901234567890123456789012345678901234 */
2369 it_kbd_translate_table
2372 static struct dos_keyboard_map dk_keyboard
= {
2374 /* 0123456789012345678901234567890123456789012345678901234 */
2375 "«1234567890+| qwertyuiop\86~ asdfghjkl\91\9b' zxcvbnm,.- ",
2376 /* 01 23456789012345678901234567890123456789012345678901234 */
2377 "õ!\"#$%&/()=?` QWERTYUIOP\8f^ ASDFGHJKL\92\9d* ZXCVBNM;:_ ",
2378 /* 0123456789012345678901234567890123456789012345678901234 */
2380 0 /* no translate table */
2383 static struct kbd_translate jp_kbd_translate_table
[] = {
2384 { 0x73, 0x5c, Normal
| 0 },
2385 { 0x73, 0x5f, Normal
| 0 },
2386 { 0x73, 0x1c, Map
| 0 },
2387 { 0x7d, 0x5c, Normal
| 13 },
2388 { 0x7d, 0x7c, Normal
| 13 },
2389 { 0x7d, 0x1c, Map
| 13 },
2392 static struct dos_keyboard_map jp_keyboard
= {
2394 /* 0123456789012 345678901234567890123456789012345678901234 */
2395 "\\1234567890-^\\ qwertyuiop@[ asdfghjkl;:] zxcvbnm,./ ",
2396 /* 01 23456789012345678901234567890123456789012345678901234 */
2397 "_!\"#$%&'()~=~| QWERTYUIOP`{ ASDFGHJKL+*} ZXCVBNM<>? ",
2398 0, /* no Alt-Gr key */
2399 jp_kbd_translate_table
2402 static struct keyboard_layout_list
2405 struct dos_keyboard_map
*keyboard_map
;
2406 } keyboard_layout_list
[] =
2415 static struct dos_keyboard_map
*keyboard
;
2416 static int keyboard_map_all
;
2417 static int international_keyboard
;
2420 dos_set_keyboard (code
, always
)
2425 _go32_dpmi_registers regs
;
2427 /* See if Keyb.Com is installed (for international keyboard support).
2428 Note: calling Int 2Fh via int86 wedges the DOS box on some versions
2429 of Windows 9X! So don't do that! */
2431 regs
.x
.ss
= regs
.x
.sp
= regs
.x
.flags
= 0;
2432 _go32_dpmi_simulate_int (0x2f, ®s
);
2433 if (regs
.h
.al
== 0xff)
2434 international_keyboard
= 1;
2436 /* Initialize to US settings, for countries that don't have their own. */
2437 keyboard
= keyboard_layout_list
[0].keyboard_map
;
2438 keyboard_map_all
= always
;
2439 dos_keyboard_layout
= 1;
2441 for (i
= 0; i
< (sizeof (keyboard_layout_list
)/sizeof (struct keyboard_layout_list
)); i
++)
2442 if (code
== keyboard_layout_list
[i
].country_code
)
2444 keyboard
= keyboard_layout_list
[i
].keyboard_map
;
2445 keyboard_map_all
= always
;
2446 dos_keyboard_layout
= code
;
2454 unsigned char char_code
; /* normal code */
2455 unsigned char meta_code
; /* M- code */
2456 unsigned char keypad_code
; /* keypad code */
2457 unsigned char editkey_code
; /* edit key */
2458 } keypad_translate_map
[] = {
2459 '0', '0', 0xb0, /* kp-0 */ 0x63, /* insert */
2460 '1', '1', 0xb1, /* kp-1 */ 0x57, /* end */
2461 '2', '2', 0xb2, /* kp-2 */ 0x54, /* down */
2462 '3', '3', 0xb3, /* kp-3 */ 0x56, /* next */
2463 '4', '4', 0xb4, /* kp-4 */ 0x51, /* left */
2464 '5', '5', 0xb5, /* kp-5 */ 0xb5, /* kp-5 */
2465 '6', '6', 0xb6, /* kp-6 */ 0x53, /* right */
2466 '7', '7', 0xb7, /* kp-7 */ 0x50, /* home */
2467 '8', '8', 0xb8, /* kp-8 */ 0x52, /* up */
2468 '9', '9', 0xb9, /* kp-9 */ 0x55, /* prior */
2469 '.', '-', 0xae, /* kp-decimal */ 0xff /* delete */
2474 unsigned char char_code
; /* normal code */
2475 unsigned char keypad_code
; /* keypad code */
2476 } grey_key_translate_map
[] = {
2477 '/', 0xaf, /* kp-decimal */
2478 '*', 0xaa, /* kp-multiply */
2479 '-', 0xad, /* kp-subtract */
2480 '+', 0xab, /* kp-add */
2481 '\r', 0x8d /* kp-enter */
2484 static unsigned short
2485 ibmpc_translate_map
[] =
2487 /* --------------- 00 to 0f --------------- */
2488 Normal
| 0xff, /* Ctrl Break + Alt-NNN */
2489 Alt
| ModFct
| 0x1b, /* Escape */
2490 Normal
| 1, /* '1' */
2491 Normal
| 2, /* '2' */
2492 Normal
| 3, /* '3' */
2493 Normal
| 4, /* '4' */
2494 Normal
| 5, /* '5' */
2495 Normal
| 6, /* '6' */
2496 Normal
| 7, /* '7' */
2497 Normal
| 8, /* '8' */
2498 Normal
| 9, /* '9' */
2499 Normal
| 10, /* '0' */
2500 Normal
| 11, /* '-' */
2501 Normal
| 12, /* '=' */
2502 Special
| 0x08, /* Backspace */
2503 ModFct
| 0x74, /* Tab/Backtab */
2505 /* --------------- 10 to 1f --------------- */
2518 ModFct
| 0x0d, /* Return */
2523 /* --------------- 20 to 2f --------------- */
2532 Map
| 40, /* '\'' */
2534 Ignore
, /* Left shift */
2535 Map
| 41, /* '\\' */
2541 /* --------------- 30 to 3f --------------- */
2548 Ignore
, /* Right shift */
2549 Grey
| 1, /* Grey * */
2551 Normal
| 55, /* ' ' */
2552 Ignore
, /* Caps Lock */
2553 FctKey
| 0xbe, /* F1 */
2554 FctKey
| 0xbf, /* F2 */
2555 FctKey
| 0xc0, /* F3 */
2556 FctKey
| 0xc1, /* F4 */
2557 FctKey
| 0xc2, /* F5 */
2559 /* --------------- 40 to 4f --------------- */
2560 FctKey
| 0xc3, /* F6 */
2561 FctKey
| 0xc4, /* F7 */
2562 FctKey
| 0xc5, /* F8 */
2563 FctKey
| 0xc6, /* F9 */
2564 FctKey
| 0xc7, /* F10 */
2565 Ignore
, /* Num Lock */
2566 Ignore
, /* Scroll Lock */
2567 KeyPad
| 7, /* Home */
2568 KeyPad
| 8, /* Up */
2569 KeyPad
| 9, /* Page Up */
2570 Grey
| 2, /* Grey - */
2571 KeyPad
| 4, /* Left */
2572 KeyPad
| 5, /* Keypad 5 */
2573 KeyPad
| 6, /* Right */
2574 Grey
| 3, /* Grey + */
2575 KeyPad
| 1, /* End */
2577 /* --------------- 50 to 5f --------------- */
2578 KeyPad
| 2, /* Down */
2579 KeyPad
| 3, /* Page Down */
2580 KeyPad
| 0, /* Insert */
2581 KeyPad
| 10, /* Delete */
2582 Shift
| FctKey
| 0xbe, /* (Shift) F1 */
2583 Shift
| FctKey
| 0xbf, /* (Shift) F2 */
2584 Shift
| FctKey
| 0xc0, /* (Shift) F3 */
2585 Shift
| FctKey
| 0xc1, /* (Shift) F4 */
2586 Shift
| FctKey
| 0xc2, /* (Shift) F5 */
2587 Shift
| FctKey
| 0xc3, /* (Shift) F6 */
2588 Shift
| FctKey
| 0xc4, /* (Shift) F7 */
2589 Shift
| FctKey
| 0xc5, /* (Shift) F8 */
2590 Shift
| FctKey
| 0xc6, /* (Shift) F9 */
2591 Shift
| FctKey
| 0xc7, /* (Shift) F10 */
2592 Ctrl
| FctKey
| 0xbe, /* (Ctrl) F1 */
2593 Ctrl
| FctKey
| 0xbf, /* (Ctrl) F2 */
2595 /* --------------- 60 to 6f --------------- */
2596 Ctrl
| FctKey
| 0xc0, /* (Ctrl) F3 */
2597 Ctrl
| FctKey
| 0xc1, /* (Ctrl) F4 */
2598 Ctrl
| FctKey
| 0xc2, /* (Ctrl) F5 */
2599 Ctrl
| FctKey
| 0xc3, /* (Ctrl) F6 */
2600 Ctrl
| FctKey
| 0xc4, /* (Ctrl) F7 */
2601 Ctrl
| FctKey
| 0xc5, /* (Ctrl) F8 */
2602 Ctrl
| FctKey
| 0xc6, /* (Ctrl) F9 */
2603 Ctrl
| FctKey
| 0xc7, /* (Ctrl) F10 */
2604 Alt
| FctKey
| 0xbe, /* (Alt) F1 */
2605 Alt
| FctKey
| 0xbf, /* (Alt) F2 */
2606 Alt
| FctKey
| 0xc0, /* (Alt) F3 */
2607 Alt
| FctKey
| 0xc1, /* (Alt) F4 */
2608 Alt
| FctKey
| 0xc2, /* (Alt) F5 */
2609 Alt
| FctKey
| 0xc3, /* (Alt) F6 */
2610 Alt
| FctKey
| 0xc4, /* (Alt) F7 */
2611 Alt
| FctKey
| 0xc5, /* (Alt) F8 */
2613 /* --------------- 70 to 7f --------------- */
2614 Alt
| FctKey
| 0xc6, /* (Alt) F9 */
2615 Alt
| FctKey
| 0xc7, /* (Alt) F10 */
2616 Ctrl
| FctKey
| 0x6d, /* (Ctrl) Sys Rq */
2617 Ctrl
| KeyPad
| 4, /* (Ctrl) Left */
2618 Ctrl
| KeyPad
| 6, /* (Ctrl) Right */
2619 Ctrl
| KeyPad
| 1, /* (Ctrl) End */
2620 Ctrl
| KeyPad
| 3, /* (Ctrl) Page Down */
2621 Ctrl
| KeyPad
| 7, /* (Ctrl) Home */
2622 Alt
| Map
| 1, /* '1' */
2623 Alt
| Map
| 2, /* '2' */
2624 Alt
| Map
| 3, /* '3' */
2625 Alt
| Map
| 4, /* '4' */
2626 Alt
| Map
| 5, /* '5' */
2627 Alt
| Map
| 6, /* '6' */
2628 Alt
| Map
| 7, /* '7' */
2629 Alt
| Map
| 8, /* '8' */
2631 /* --------------- 80 to 8f --------------- */
2632 Alt
| Map
| 9, /* '9' */
2633 Alt
| Map
| 10, /* '0' */
2634 Alt
| Map
| 11, /* '-' */
2635 Alt
| Map
| 12, /* '=' */
2636 Ctrl
| KeyPad
| 9, /* (Ctrl) Page Up */
2637 FctKey
| 0xc8, /* F11 */
2638 FctKey
| 0xc9, /* F12 */
2639 Shift
| FctKey
| 0xc8, /* (Shift) F11 */
2640 Shift
| FctKey
| 0xc9, /* (Shift) F12 */
2641 Ctrl
| FctKey
| 0xc8, /* (Ctrl) F11 */
2642 Ctrl
| FctKey
| 0xc9, /* (Ctrl) F12 */
2643 Alt
| FctKey
| 0xc8, /* (Alt) F11 */
2644 Alt
| FctKey
| 0xc9, /* (Alt) F12 */
2645 Ctrl
| KeyPad
| 8, /* (Ctrl) Up */
2646 Ctrl
| Grey
| 2, /* (Ctrl) Grey - */
2647 Ctrl
| KeyPad
| 5, /* (Ctrl) Keypad 5 */
2649 /* --------------- 90 to 9f --------------- */
2650 Ctrl
| Grey
| 3, /* (Ctrl) Grey + */
2651 Ctrl
| KeyPad
| 2, /* (Ctrl) Down */
2652 Ctrl
| KeyPad
| 0, /* (Ctrl) Insert */
2653 Ctrl
| KeyPad
| 10, /* (Ctrl) Delete */
2654 Ctrl
| FctKey
| 0x09, /* (Ctrl) Tab */
2655 Ctrl
| Grey
| 0, /* (Ctrl) Grey / */
2656 Ctrl
| Grey
| 1, /* (Ctrl) Grey * */
2657 Alt
| FctKey
| 0x50, /* (Alt) Home */
2658 Alt
| FctKey
| 0x52, /* (Alt) Up */
2659 Alt
| FctKey
| 0x55, /* (Alt) Page Up */
2660 Ignore
, /* NO KEY */
2661 Alt
| FctKey
| 0x51, /* (Alt) Left */
2662 Ignore
, /* NO KEY */
2663 Alt
| FctKey
| 0x53, /* (Alt) Right */
2664 Ignore
, /* NO KEY */
2665 Alt
| FctKey
| 0x57, /* (Alt) End */
2667 /* --------------- a0 to af --------------- */
2668 Alt
| KeyPad
| 2, /* (Alt) Down */
2669 Alt
| KeyPad
| 3, /* (Alt) Page Down */
2670 Alt
| KeyPad
| 0, /* (Alt) Insert */
2671 Alt
| KeyPad
| 10, /* (Alt) Delete */
2672 Alt
| Grey
| 0, /* (Alt) Grey / */
2673 Alt
| FctKey
| 0x09, /* (Alt) Tab */
2674 Alt
| Grey
| 4 /* (Alt) Keypad Enter */
2677 /* These bit-positions corresponds to values returned by BIOS */
2678 #define SHIFT_P 0x0003 /* two bits! */
2679 #define CTRL_P 0x0004
2680 #define ALT_P 0x0008
2681 #define SCRLOCK_P 0x0010
2682 #define NUMLOCK_P 0x0020
2683 #define CAPSLOCK_P 0x0040
2684 #define ALT_GR_P 0x0800
2685 #define SUPER_P 0x4000 /* pseudo */
2686 #define HYPER_P 0x8000 /* pseudo */
2689 dos_get_modifiers (keymask
)
2696 /* Calculate modifier bits */
2697 regs
.h
.ah
= extended_kbd
? 0x12 : 0x02;
2698 int86 (0x16, ®s
, ®s
);
2702 mask
= regs
.h
.al
& (SHIFT_P
| CTRL_P
| ALT_P
|
2703 SCRLOCK_P
| NUMLOCK_P
| CAPSLOCK_P
);
2707 mask
= regs
.h
.al
& (SHIFT_P
|
2708 SCRLOCK_P
| NUMLOCK_P
| CAPSLOCK_P
);
2710 /* Do not break international keyboard support. */
2711 /* When Keyb.Com is loaded, the right Alt key is */
2712 /* used for accessing characters like { and } */
2713 if (regs
.h
.ah
& 2) /* Left ALT pressed ? */
2716 if ((regs
.h
.ah
& 8) != 0) /* Right ALT pressed ? */
2719 if (dos_hyper_key
== 1)
2722 modifiers
|= hyper_modifier
;
2724 else if (dos_super_key
== 1)
2727 modifiers
|= super_modifier
;
2729 else if (!international_keyboard
)
2731 /* If Keyb.Com is NOT installed, let Right Alt behave
2732 like the Left Alt. */
2738 if (regs
.h
.ah
& 1) /* Left CTRL pressed ? */
2741 if (regs
.h
.ah
& 4) /* Right CTRL pressed ? */
2743 if (dos_hyper_key
== 2)
2746 modifiers
|= hyper_modifier
;
2748 else if (dos_super_key
== 2)
2751 modifiers
|= super_modifier
;
2759 modifiers
|= shift_modifier
;
2761 modifiers
|= ctrl_modifier
;
2763 modifiers
|= meta_modifier
;
2770 #define NUM_RECENT_DOSKEYS (100)
2771 int recent_doskeys_index
; /* Index for storing next element into recent_doskeys */
2772 int total_doskeys
; /* Total number of elements stored into recent_doskeys */
2773 Lisp_Object recent_doskeys
; /* A vector, holding the last 100 keystrokes */
2775 DEFUN ("recent-doskeys", Frecent_doskeys
, Srecent_doskeys
, 0, 0, 0,
2776 "Return vector of last 100 keyboard input values seen in dos_rawgetc.\n\
2777 Each input key receives two values in this vector: first the ASCII code,\n\
2778 and then the scan code.")
2781 Lisp_Object
*keys
= XVECTOR (recent_doskeys
)->contents
;
2784 if (total_doskeys
< NUM_RECENT_DOSKEYS
)
2785 return Fvector (total_doskeys
, keys
);
2788 val
= Fvector (NUM_RECENT_DOSKEYS
, keys
);
2789 bcopy (keys
+ recent_doskeys_index
,
2790 XVECTOR (val
)->contents
,
2791 (NUM_RECENT_DOSKEYS
- recent_doskeys_index
) * sizeof (Lisp_Object
));
2793 XVECTOR (val
)->contents
+ NUM_RECENT_DOSKEYS
- recent_doskeys_index
,
2794 recent_doskeys_index
* sizeof (Lisp_Object
));
2799 /* Get a char from keyboard. Function keys are put into the event queue. */
2801 extern void kbd_buffer_store_event (struct input_event
*);
2806 struct input_event event
;
2809 #ifndef HAVE_X_WINDOWS
2810 /* Maybe put the cursor where it should be. */
2811 IT_cmgoto (SELECTED_FRAME());
2814 /* The following condition is equivalent to `kbhit ()', except that
2815 it uses the bios to do its job. This pleases DESQview/X. */
2816 while ((regs
.h
.ah
= extended_kbd
? 0x11 : 0x01),
2817 int86 (0x16, ®s
, ®s
),
2818 (regs
.x
.flags
& 0x40) == 0)
2821 register unsigned char c
;
2822 int sc
, code
= -1, mask
, kp_mode
;
2825 regs
.h
.ah
= extended_kbd
? 0x10 : 0x00;
2826 int86 (0x16, ®s
, ®s
);
2831 XVECTOR (recent_doskeys
)->contents
[recent_doskeys_index
++]
2833 if (recent_doskeys_index
== NUM_RECENT_DOSKEYS
)
2834 recent_doskeys_index
= 0;
2835 XVECTOR (recent_doskeys
)->contents
[recent_doskeys_index
++]
2837 if (recent_doskeys_index
== NUM_RECENT_DOSKEYS
)
2838 recent_doskeys_index
= 0;
2840 modifiers
= dos_get_modifiers (&mask
);
2842 #ifndef HAVE_X_WINDOWS
2843 if (!NILP (Vdos_display_scancodes
))
2846 sprintf (buf
, "%02x:%02x*%04x",
2847 (unsigned) (sc
&0xff), (unsigned) c
, mask
);
2848 dos_direct_output (screen_size_Y
- 2, screen_size_X
- 12, buf
, 10);
2856 case 10: /* Ctrl Grey Enter */
2857 code
= Ctrl
| Grey
| 4;
2859 case 13: /* Grey Enter */
2862 case '/': /* Grey / */
2872 /* Try the keyboard-private translation table first. */
2873 if (keyboard
->translate_table
)
2875 struct kbd_translate
*p
= keyboard
->translate_table
;
2879 if (p
->sc
== sc
&& p
->ch
== c
)
2887 /* If the private table didn't translate it, use the general
2891 if (sc
>= (sizeof (ibmpc_translate_map
) / sizeof (short)))
2893 if ((code
= ibmpc_translate_map
[sc
]) == Ignore
)
2900 /* We only look at the keyboard Ctrl/Shift/Alt keys when
2901 Emacs is ready to read a key. Therefore, if they press
2902 `Alt-x' when Emacs is busy, by the time we get to
2903 `dos_get_modifiers', they might have already released the
2904 Alt key, and Emacs gets just `x', which is BAD.
2905 However, for keys with the `Map' property set, the ASCII
2906 code returns zero iff Alt is pressed. So, when we DON'T
2907 have to support international_keyboard, we don't have to
2908 distinguish between the left and right Alt keys, and we
2909 can set the META modifier for any keys with the `Map'
2910 property if they return zero ASCII code (c = 0). */
2912 || ( (code
& 0xf000) == Map
&& !international_keyboard
))
2913 modifiers
|= meta_modifier
;
2915 modifiers
|= ctrl_modifier
;
2917 modifiers
|= shift_modifier
;
2920 switch (code
& 0xf000)
2923 if (c
&& !(mask
& (SHIFT_P
| ALT_P
| CTRL_P
| HYPER_P
| SUPER_P
)))
2925 c
= 0; /* Special */
2938 if (c
== 0) /* ctrl-break */
2940 return c
; /* ALT-nnn */
2942 if (!keyboard_map_all
)
2951 if (c
&& !(mask
& ALT_P
) && !((mask
& SHIFT_P
) && (mask
& CTRL_P
)))
2952 if (!keyboard_map_all
)
2956 if (mask
& ALT_P
&& code
<= 10 && code
> 0 && dos_keypad_mode
& 0x200)
2957 mask
|= SHIFT_P
; /* ALT-1 => M-! etc. */
2961 code
= keyboard
->shifted
[code
];
2963 modifiers
&= ~shift_modifier
;
2966 if ((mask
& ALT_GR_P
) && keyboard
->alt_gr
&& keyboard
->alt_gr
[code
] != ' ')
2967 code
= keyboard
->alt_gr
[code
];
2969 code
= keyboard
->unshifted
[code
];
2974 if (c
== 0xe0) /* edit key */
2977 if ((mask
& (NUMLOCK_P
|CTRL_P
|SHIFT_P
|ALT_P
)) == NUMLOCK_P
) /* numlock on */
2978 kp_mode
= dos_keypad_mode
& 0x03;
2980 kp_mode
= (dos_keypad_mode
>> 4) & 0x03;
2985 if (code
== 10 && dos_decimal_point
)
2986 return dos_decimal_point
;
2987 return keypad_translate_map
[code
].char_code
;
2990 code
= 0xff00 | keypad_translate_map
[code
].keypad_code
;
2994 code
= keypad_translate_map
[code
].meta_code
;
2995 modifiers
= meta_modifier
;
2999 code
= 0xff00 | keypad_translate_map
[code
].editkey_code
;
3006 kp_mode
= ((mask
& (NUMLOCK_P
|CTRL_P
|SHIFT_P
|ALT_P
)) == NUMLOCK_P
) ? 0x04 : 0x40;
3007 if (dos_keypad_mode
& kp_mode
)
3008 code
= 0xff00 | grey_key_translate_map
[code
].keypad_code
;
3010 code
= grey_key_translate_map
[code
].char_code
;
3019 event
.kind
= non_ascii_keystroke
;
3021 event
.kind
= ascii_keystroke
;
3023 event
.modifiers
= modifiers
;
3024 event
.frame_or_window
= selected_frame
;
3025 event
.timestamp
= event_timestamp ();
3026 kbd_buffer_store_event (&event
);
3029 if (have_mouse
> 0 && !mouse_preempted
)
3031 int but
, press
, x
, y
, ok
;
3032 int mouse_prev_x
= mouse_last_x
, mouse_prev_y
= mouse_last_y
;
3034 /* Check for mouse movement *before* buttons. */
3035 mouse_check_moved ();
3037 /* If the mouse moved from the spot of its last sighting, we
3038 might need to update mouse highlight. */
3039 if (mouse_last_x
!= mouse_prev_x
|| mouse_last_y
!= mouse_prev_y
)
3041 previous_help_echo
= help_echo
;
3043 IT_note_mouse_highlight (SELECTED_FRAME(),
3044 mouse_last_x
, mouse_last_y
);
3045 /* If the contents of the global variable help_echo has
3046 changed, generate a HELP_EVENT. */
3047 if (STRINGP (help_echo
) || STRINGP (previous_help_echo
))
3049 event
.kind
= HELP_EVENT
;
3050 event
.frame_or_window
= Fcons (selected_frame
, help_echo
);
3051 event
.timestamp
= event_timestamp ();
3052 kbd_buffer_store_event (&event
);
3056 for (but
= 0; but
< NUM_MOUSE_BUTTONS
; but
++)
3057 for (press
= 0; press
< 2; press
++)
3059 int button_num
= but
;
3062 ok
= mouse_pressed (but
, &x
, &y
);
3064 ok
= mouse_released (but
, &x
, &y
);
3067 /* Allow a simultaneous press/release of Mouse-1 and
3068 Mouse-2 to simulate Mouse-3 on two-button mice. */
3069 if (mouse_button_count
== 2 && but
< 2)
3071 int x2
, y2
; /* don't clobber original coordinates */
3073 /* If only one button is pressed, wait 100 msec and
3074 check again. This way, Speedy Gonzales isn't
3075 punished, while the slow get their chance. */
3076 if (press
&& mouse_pressed (1-but
, &x2
, &y2
)
3077 || !press
&& mouse_released (1-but
, &x2
, &y2
))
3082 if (press
&& mouse_pressed (1-but
, &x2
, &y2
)
3083 || !press
&& mouse_released (1-but
, &x2
, &y2
))
3088 event
.kind
= mouse_click
;
3089 event
.code
= button_num
;
3090 event
.modifiers
= dos_get_modifiers (0)
3091 | (press
? down_modifier
: up_modifier
);
3094 event
.frame_or_window
= selected_frame
;
3095 event
.timestamp
= event_timestamp ();
3096 kbd_buffer_store_event (&event
);
3104 static int prev_get_char
= -1;
3106 /* Return 1 if a key is ready to be read without suspending execution. */
3110 if (prev_get_char
!= -1)
3113 return ((prev_get_char
= dos_rawgetc ()) != -1);
3116 /* Read a key. Return -1 if no key is ready. */
3120 if (prev_get_char
!= -1)
3122 int c
= prev_get_char
;
3127 return dos_rawgetc ();
3130 #ifndef HAVE_X_WINDOWS
3131 /* See xterm.c for more info. */
3133 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
3135 register int pix_x
, pix_y
;
3136 register int *x
, *y
;
3140 if (bounds
) abort ();
3142 /* Ignore clipping. */
3149 glyph_to_pixel_coords (f
, x
, y
, pix_x
, pix_y
)
3152 register int *pix_x
, *pix_y
;
3158 /* Simulation of X's menus. Nothing too fancy here -- just make it work
3161 Actually, I don't know the meaning of all the parameters of the functions
3162 here -- I only know how they are called by xmenu.c. I could of course
3163 grab the nearest Xlib manual (down the hall, second-to-last door on the
3164 left), but I don't think it's worth the effort. */
3171 menu
= (XMenu
*) xmalloc (sizeof (XMenu
));
3172 menu
->allocated
= menu
->count
= menu
->panecount
= menu
->width
= 0;
3176 /* Allocate some (more) memory for MENU ensuring that there is room for one
3180 IT_menu_make_room (XMenu
*menu
)
3182 if (menu
->allocated
== 0)
3184 int count
= menu
->allocated
= 10;
3185 menu
->text
= (char **) xmalloc (count
* sizeof (char *));
3186 menu
->submenu
= (XMenu
**) xmalloc (count
* sizeof (XMenu
*));
3187 menu
->panenumber
= (int *) xmalloc (count
* sizeof (int));
3189 else if (menu
->allocated
== menu
->count
)
3191 int count
= menu
->allocated
= menu
->allocated
+ 10;
3193 = (char **) xrealloc (menu
->text
, count
* sizeof (char *));
3195 = (XMenu
**) xrealloc (menu
->submenu
, count
* sizeof (XMenu
*));
3197 = (int *) xrealloc (menu
->panenumber
, count
* sizeof (int));
3201 /* Search the given menu structure for a given pane number. */
3204 IT_menu_search_pane (XMenu
*menu
, int pane
)
3209 for (i
= 0; i
< menu
->count
; i
++)
3210 if (menu
->submenu
[i
])
3212 if (pane
== menu
->panenumber
[i
])
3213 return menu
->submenu
[i
];
3214 if ((try = IT_menu_search_pane (menu
->submenu
[i
], pane
)))
3220 /* Determine how much screen space a given menu needs. */
3223 IT_menu_calc_size (XMenu
*menu
, int *width
, int *height
)
3225 int i
, h2
, w2
, maxsubwidth
, maxheight
;
3228 maxheight
= menu
->count
;
3229 for (i
= 0; i
< menu
->count
; i
++)
3231 if (menu
->submenu
[i
])
3233 IT_menu_calc_size (menu
->submenu
[i
], &w2
, &h2
);
3234 if (w2
> maxsubwidth
) maxsubwidth
= w2
;
3235 if (i
+ h2
> maxheight
) maxheight
= i
+ h2
;
3238 *width
= menu
->width
+ maxsubwidth
;
3239 *height
= maxheight
;
3242 /* Display MENU at (X,Y) using FACES. */
3245 IT_menu_display (XMenu
*menu
, int y
, int x
, int *faces
)
3247 int i
, j
, face
, width
;
3248 struct glyph
*text
, *p
;
3251 int enabled
, mousehere
;
3253 struct frame
*sf
= SELECTED_FRAME();
3255 width
= menu
->width
;
3256 text
= (struct glyph
*) xmalloc ((width
+ 2) * sizeof (struct glyph
));
3257 ScreenGetCursor (&row
, &col
);
3258 mouse_get_xy (&mx
, &my
);
3259 IT_update_begin (sf
);
3260 for (i
= 0; i
< menu
->count
; i
++)
3262 IT_cursor_to (y
+ i
, x
);
3264 = (!menu
->submenu
[i
] && menu
->panenumber
[i
]) || (menu
->submenu
[i
]);
3265 mousehere
= (y
+ i
== my
&& x
<= mx
&& mx
< x
+ width
+ 2);
3266 face
= faces
[enabled
+ mousehere
* 2];
3268 SET_CHAR_GLYPH (*p
, ' ', face
, 0);
3270 for (j
= 0, q
= menu
->text
[i
]; *q
; j
++)
3274 SET_CHAR_GLYPH (*p
, *q
++, face
, 0);
3277 else /* make '^x' */
3279 SET_CHAR_GLYPH (*p
, '^', face
, 0);
3282 SET_CHAR_GLYPH (*p
, *q
++ + 64, face
, 0);
3287 for (; j
< width
; j
++, p
++)
3288 SET_CHAR_GLYPH (*p
, ' ', face
, 0);
3290 SET_CHAR_GLYPH (*p
, menu
->submenu
[i
] ? 16 : ' ', face
, 0);
3292 IT_write_glyphs (text
, width
+ 2);
3295 IT_cursor_to (row
, col
);
3299 /* --------------------------- X Menu emulation ---------------------- */
3301 /* Report availability of menus. */
3309 /* Create a brand new menu structure. */
3312 XMenuCreate (Display
*foo1
, Window foo2
, char *foo3
)
3314 return IT_menu_create ();
3317 /* Create a new pane and place it on the outer-most level. It is not
3318 clear that it should be placed out there, but I don't know what else
3322 XMenuAddPane (Display
*foo
, XMenu
*menu
, char *txt
, int enable
)
3330 IT_menu_make_room (menu
);
3331 menu
->submenu
[menu
->count
] = IT_menu_create ();
3332 menu
->text
[menu
->count
] = txt
;
3333 menu
->panenumber
[menu
->count
] = ++menu
->panecount
;
3336 /* Adjust length for possible control characters (which will
3337 be written as ^x). */
3338 for (len
= strlen (txt
), p
= txt
; *p
; p
++)
3342 if (len
> menu
->width
)
3345 return menu
->panecount
;
3348 /* Create a new item in a menu pane. */
3351 XMenuAddSelection (Display
*bar
, XMenu
*menu
, int pane
,
3352 int foo
, char *txt
, int enable
)
3358 if (!(menu
= IT_menu_search_pane (menu
, pane
)))
3360 IT_menu_make_room (menu
);
3361 menu
->submenu
[menu
->count
] = (XMenu
*) 0;
3362 menu
->text
[menu
->count
] = txt
;
3363 menu
->panenumber
[menu
->count
] = enable
;
3366 /* Adjust length for possible control characters (which will
3367 be written as ^x). */
3368 for (len
= strlen (txt
), p
= txt
; *p
; p
++)
3372 if (len
> menu
->width
)
3378 /* Decide where the menu would be placed if requested at (X,Y). */
3381 XMenuLocate (Display
*foo0
, XMenu
*menu
, int foo1
, int foo2
, int x
, int y
,
3382 int *ulx
, int *uly
, int *width
, int *height
)
3384 IT_menu_calc_size (menu
, width
, height
);
3390 struct IT_menu_state
3392 void *screen_behind
;
3399 /* Display menu, wait for user's response, and return that response. */
3402 XMenuActivate (Display
*foo
, XMenu
*menu
, int *pane
, int *selidx
,
3403 int x0
, int y0
, unsigned ButtonMask
, char **txt
)
3405 struct IT_menu_state
*state
;
3410 Lisp_Object selectface
;
3411 int leave
, result
, onepane
;
3412 int title_faces
[4]; /* face to display the menu title */
3413 int buffers_num_deleted
= 0;
3414 struct frame
*sf
= SELECTED_FRAME();
3416 /* Just in case we got here without a mouse present... */
3417 if (have_mouse
<= 0)
3418 return XM_IA_SELECT
;
3419 /* Don't allow non-positive x0 and y0, lest the menu will wrap
3420 around the display. */
3426 /* We will process all the mouse events directly, so we had
3427 better prevented dos_rawgetc from stealing them from us. */
3430 state
= alloca (menu
->panecount
* sizeof (struct IT_menu_state
));
3431 screensize
= screen_size
* 2;
3433 = lookup_derived_face (sf
, intern ("msdos-menu-passive-face"),
3434 CHARSET_ASCII
, DEFAULT_FACE_ID
);
3436 = lookup_derived_face (sf
, intern ("msdos-menu-active-face"),
3437 CHARSET_ASCII
, DEFAULT_FACE_ID
);
3438 selectface
= intern ("msdos-menu-select-face");
3439 faces
[2] = lookup_derived_face (sf
, selectface
,
3440 CHARSET_ASCII
, faces
[0]);
3441 faces
[3] = lookup_derived_face (sf
, selectface
,
3442 CHARSET_ASCII
, faces
[1]);
3444 /* Make sure the menu title is always displayed with
3445 `msdos-menu-active-face', no matter where the mouse pointer is. */
3446 for (i
= 0; i
< 4; i
++)
3447 title_faces
[i
] = faces
[3];
3451 /* Don't let the title for the "Buffers" popup menu include a
3452 digit (which is ugly).
3454 This is a terrible kludge, but I think the "Buffers" case is
3455 the only one where the title includes a number, so it doesn't
3456 seem to be necessary to make this more general. */
3457 if (strncmp (menu
->text
[0], "Buffers 1", 9) == 0)
3459 menu
->text
[0][7] = '\0';
3460 buffers_num_deleted
= 1;
3462 state
[0].menu
= menu
;
3464 ScreenRetrieve (state
[0].screen_behind
= xmalloc (screensize
));
3466 /* Turn off the cursor. Otherwise it shows through the menu
3467 panes, which is ugly. */
3468 IT_display_cursor (0);
3470 IT_menu_display (menu
, y0
- 1, x0
- 1, title_faces
); /* display menu title */
3471 if (buffers_num_deleted
)
3472 menu
->text
[0][7] = ' ';
3473 if ((onepane
= menu
->count
== 1 && menu
->submenu
[0]))
3475 menu
->width
= menu
->submenu
[0]->width
;
3476 state
[0].menu
= menu
->submenu
[0];
3480 state
[0].menu
= menu
;
3482 state
[0].x
= x0
- 1;
3484 state
[0].pane
= onepane
;
3486 mouse_last_x
= -1; /* A hack that forces display. */
3490 if (!mouse_visible
) mouse_on ();
3491 mouse_check_moved ();
3492 if (sf
->mouse_moved
)
3494 sf
->mouse_moved
= 0;
3495 result
= XM_IA_SELECT
;
3496 mouse_get_xy (&x
, &y
);
3497 for (i
= 0; i
< statecount
; i
++)
3498 if (state
[i
].x
<= x
&& x
< state
[i
].x
+ state
[i
].menu
->width
+ 2)
3500 int dy
= y
- state
[i
].y
;
3501 if (0 <= dy
&& dy
< state
[i
].menu
->count
)
3503 if (!state
[i
].menu
->submenu
[dy
])
3504 if (state
[i
].menu
->panenumber
[dy
])
3505 result
= XM_SUCCESS
;
3507 result
= XM_IA_SELECT
;
3508 *pane
= state
[i
].pane
- 1;
3510 /* We hit some part of a menu, so drop extra menus that
3511 have been opened. That does not include an open and
3513 if (i
!= statecount
- 2
3514 || state
[i
].menu
->submenu
[dy
] != state
[i
+1].menu
)
3515 while (i
!= statecount
- 1)
3519 ScreenUpdate (state
[statecount
].screen_behind
);
3520 if (screen_virtual_segment
)
3521 dosv_refresh_virtual_screen (0, screen_size
);
3522 xfree (state
[statecount
].screen_behind
);
3524 if (i
== statecount
- 1 && state
[i
].menu
->submenu
[dy
])
3526 IT_menu_display (state
[i
].menu
,
3530 state
[statecount
].menu
= state
[i
].menu
->submenu
[dy
];
3531 state
[statecount
].pane
= state
[i
].menu
->panenumber
[dy
];
3533 ScreenRetrieve (state
[statecount
].screen_behind
3534 = xmalloc (screensize
));
3536 = state
[i
].x
+ state
[i
].menu
->width
+ 2;
3537 state
[statecount
].y
= y
;
3542 IT_menu_display (state
[statecount
- 1].menu
,
3543 state
[statecount
- 1].y
,
3544 state
[statecount
- 1].x
,
3548 /* We are busy-waiting for the mouse to move, so let's be nice
3549 to other Windows applications by releasing our time slice. */
3551 for (b
= 0; b
< mouse_button_count
&& !leave
; b
++)
3553 /* Only leave if user both pressed and released the mouse, and in
3554 that order. This avoids popping down the menu pane unless
3555 the user is really done with it. */
3556 if (mouse_pressed (b
, &x
, &y
))
3558 while (mouse_button_depressed (b
, &x
, &y
))
3562 (void) mouse_released (b
, &x
, &y
);
3567 ScreenUpdate (state
[0].screen_behind
);
3568 if (screen_virtual_segment
)
3569 dosv_refresh_virtual_screen (0, screen_size
);
3570 while (statecount
--)
3571 xfree (state
[statecount
].screen_behind
);
3572 IT_display_cursor (1); /* turn cursor back on */
3573 /* Clean up any mouse events that are waiting inside Emacs event queue.
3574 These events are likely to be generated before the menu was even
3575 displayed, probably because the user pressed and released the button
3576 (which invoked the menu) too quickly. If we don't remove these events,
3577 Emacs will process them after we return and surprise the user. */
3578 discard_mouse_events ();
3579 /* Allow mouse events generation by dos_rawgetc. */
3584 /* Dispose of a menu. */
3587 XMenuDestroy (Display
*foo
, XMenu
*menu
)
3590 if (menu
->allocated
)
3592 for (i
= 0; i
< menu
->count
; i
++)
3593 if (menu
->submenu
[i
])
3594 XMenuDestroy (foo
, menu
->submenu
[i
]);
3596 xfree (menu
->submenu
);
3597 xfree (menu
->panenumber
);
3603 x_pixel_width (struct frame
*f
)
3605 return FRAME_WIDTH (f
);
3609 x_pixel_height (struct frame
*f
)
3611 return FRAME_HEIGHT (f
);
3613 #endif /* !HAVE_X_WINDOWS */
3615 /* ----------------------- DOS / UNIX conversion --------------------- */
3617 void msdos_downcase_filename (unsigned char *);
3619 /* Destructively turn backslashes into slashes. */
3622 dostounix_filename (p
)
3625 msdos_downcase_filename (p
);
3635 /* Destructively turn slashes into backslashes. */
3638 unixtodos_filename (p
)
3641 if (p
[1] == ':' && *p
>= 'A' && *p
<= 'Z')
3655 /* Get the default directory for a given drive. 0=def, 1=A, 2=B, ... */
3658 getdefdir (drive
, dst
)
3662 char in_path
[4], *p
= in_path
;
3665 /* Generate "X:." (when drive is X) or "." (when drive is 0). */
3668 *p
++ = drive
+ 'A' - 1;
3675 _fixpath (in_path
, dst
);
3676 /* _fixpath can set errno to ENOSYS on non-LFN systems because
3677 it queries the LFN support, so ignore that error. */
3678 if ((errno
&& errno
!= ENOSYS
) || *dst
== '\0')
3681 msdos_downcase_filename (dst
);
3687 /* Remove all CR's that are followed by a LF. */
3692 register unsigned char *buf
;
3694 unsigned char *np
= buf
;
3695 unsigned char *startp
= buf
;
3696 unsigned char *endp
= buf
+ n
;
3700 while (buf
< endp
- 1)
3704 if (*(++buf
) != 0x0a)
3715 #if defined(__DJGPP__) && __DJGPP__ == 2 && __DJGPP_MINOR__ == 0
3717 /* In DJGPP v2.0, library `write' can call `malloc', which might
3718 cause relocation of the buffer whose address we get in ADDR.
3719 Here is a version of `write' that avoids calling `malloc',
3720 to serve us until such time as the library is fixed.
3721 Actually, what we define here is called `__write', because
3722 `write' is a stub that just jmp's to `__write' (to be
3723 POSIXLY-correct with respect to the global name-space). */
3725 #include <io.h> /* for _write */
3726 #include <libc/dosio.h> /* for __file_handle_modes[] */
3728 static char xbuf
[64 * 1024]; /* DOS cannot write more in one chunk */
3730 #define XBUF_END (xbuf + sizeof (xbuf) - 1)
3733 __write (int handle
, const void *buffer
, size_t count
)
3738 if(__file_handle_modes
[handle
] & O_BINARY
)
3739 return _write (handle
, buffer
, count
);
3743 const char *bp
= buffer
;
3744 int total_written
= 0;
3745 int nmoved
= 0, ncr
= 0;
3749 /* The next test makes sure there's space for at least 2 more
3750 characters in xbuf[], so both CR and LF can be put there. */
3762 if (xbp
>= XBUF_END
|| !count
)
3764 size_t to_write
= nmoved
+ ncr
;
3765 int written
= _write (handle
, xbuf
, to_write
);
3770 total_written
+= nmoved
; /* CRs aren't counted in ret value */
3772 /* If some, but not all were written (disk full?), return
3773 an estimate of the total written bytes not counting CRs. */
3774 if (written
< to_write
)
3775 return total_written
- (to_write
- written
) * nmoved
/to_write
;
3782 return total_written
;
3786 /* A low-level file-renaming function which works around Windows 95 bug.
3787 This is pulled directly out of DJGPP v2.01 library sources, and only
3788 used when you compile with DJGPP v2.0. */
3792 int _rename(const char *old
, const char *new)
3795 int olen
= strlen(old
) + 1;
3797 int use_lfn
= _USE_LFN
;
3798 char tempfile
[FILENAME_MAX
];
3799 const char *orig
= old
;
3802 r
.x
.dx
= __tb_offset
;
3803 r
.x
.di
= __tb_offset
+ olen
;
3804 r
.x
.ds
= r
.x
.es
= __tb_segment
;
3808 /* Windows 95 bug: for some filenames, when you rename
3809 file -> file~ (as in Emacs, to leave a backup), the
3810 short 8+3 alias doesn't change, which effectively
3811 makes OLD and NEW the same file. We must rename
3812 through a temporary file to work around this. */
3814 char *pbase
= 0, *p
;
3815 static char try_char
[] = "abcdefghijklmnopqrstuvwxyz012345789";
3816 int idx
= sizeof(try_char
) - 1;
3818 /* Generate a temporary name. Can't use `tmpnam', since $TMPDIR
3819 might point to another drive, which will fail the DOS call. */
3820 strcpy(tempfile
, old
);
3821 for (p
= tempfile
; *p
; p
++) /* ensure temporary is on the same drive */
3822 if (*p
== '/' || *p
== '\\' || *p
== ':')
3828 strcpy(pbase
, "X$$djren$$.$$temp$$");
3834 *pbase
= try_char
[--idx
];
3835 } while (_chmod(tempfile
, 0) != -1);
3838 _put_path2(tempfile
, olen
);
3840 __dpmi_int(0x21, &r
);
3843 errno
= __doserr_to_errno(r
.x
.ax
);
3847 /* Now create a file with the original name. This will
3848 ensure that NEW will always have a 8+3 alias
3849 different from that of OLD. (Seems to be required
3850 when NameNumericTail in the Registry is set to 0.) */
3851 lfn_fd
= _creat(old
, 0);
3853 olen
= strlen(tempfile
) + 1;
3855 r
.x
.di
= __tb_offset
+ olen
;
3864 _put_path2(new, olen
);
3866 __dpmi_int(0x21, &r
);
3869 if (r
.x
.ax
== 5 && i
== 0) /* access denied */
3870 remove(new); /* and try again */
3873 errno
= __doserr_to_errno(r
.x
.ax
);
3875 /* Restore to original name if we renamed it to temporary. */
3883 _put_path2(orig
, olen
);
3884 _put_path(tempfile
);
3886 __dpmi_int(0x21, &r
);
3895 /* Success. Delete the file possibly created to work
3896 around the Windows 95 bug. */
3898 return (_close (lfn_fd
) == 0) ? remove (orig
) : -1;
3902 #endif /* __DJGPP__ == 2 && __DJGPP_MINOR__ == 0 */
3904 DEFUN ("msdos-long-file-names", Fmsdos_long_file_names
, Smsdos_long_file_names
,
3906 "Return non-nil if long file names are supported on MSDOS.")
3909 return (_USE_LFN
? Qt
: Qnil
);
3912 /* Convert alphabetic characters in a filename to lower-case. */
3915 msdos_downcase_filename (p
)
3916 register unsigned char *p
;
3918 /* Always lower-case drive letters a-z, even if the filesystem
3919 preserves case in filenames.
3920 This is so MSDOS filenames could be compared by string comparison
3921 functions that are case-sensitive. Even case-preserving filesystems
3922 do not distinguish case in drive letters. */
3923 if (p
[1] == ':' && *p
>= 'A' && *p
<= 'Z')
3929 /* Under LFN we expect to get pathnames in their true case. */
3930 if (NILP (Fmsdos_long_file_names ()))
3932 if (*p
>= 'A' && *p
<= 'Z')
3936 DEFUN ("msdos-downcase-filename", Fmsdos_downcase_filename
, Smsdos_downcase_filename
,
3938 "Convert alphabetic characters in FILENAME to lower case and return that.\n\
3939 When long filenames are supported, doesn't change FILENAME.\n\
3940 If FILENAME is not a string, returns nil.\n\
3941 The argument object is never altered--the value is a copy.")
3943 Lisp_Object filename
;
3947 if (! STRINGP (filename
))
3950 tem
= Fcopy_sequence (filename
);
3951 msdos_downcase_filename (XSTRING (tem
)->data
);
3955 /* The Emacs root directory as determined by init_environment. */
3957 static char emacsroot
[MAXPATHLEN
];
3960 rootrelativepath (rel
)
3963 static char result
[MAXPATHLEN
+ 10];
3965 strcpy (result
, emacsroot
);
3966 strcat (result
, "/");
3967 strcat (result
, rel
);
3971 /* Define a lot of environment variables if not already defined. Don't
3972 remove anything unless you know what you're doing -- lots of code will
3973 break if one or more of these are missing. */
3976 init_environment (argc
, argv
, skip_args
)
3983 static const char * const tempdirs
[] = {
3984 "$TMPDIR", "$TEMP", "$TMP", "c:/"
3987 const int imax
= sizeof (tempdirs
) / sizeof (tempdirs
[0]);
3989 /* Make sure they have a usable $TMPDIR. Many Emacs functions use
3990 temporary files and assume "/tmp" if $TMPDIR is unset, which
3991 will break on DOS/Windows. Refuse to work if we cannot find
3992 a directory, not even "c:/", usable for that purpose. */
3993 for (i
= 0; i
< imax
; i
++)
3995 const char *tmp
= tempdirs
[i
];
3998 tmp
= getenv (tmp
+ 1);
3999 /* Note that `access' can lie to us if the directory resides on a
4000 read-only filesystem, like CD-ROM or a write-protected floppy.
4001 The only way to be really sure is to actually create a file and
4002 see if it succeeds. But I think that's too much to ask. */
4003 if (tmp
&& access (tmp
, D_OK
) == 0)
4005 setenv ("TMPDIR", tmp
, 1);
4012 Fcons (build_string ("no usable temporary directories found!!"),
4014 "While setting TMPDIR: ");
4016 /* Note the startup time, so we know not to clear the screen if we
4017 exit immediately; see IT_reset_terminal_modes.
4018 (Yes, I know `clock' returns zero the first time it's called, but
4019 I do this anyway, in case some wiseguy changes that at some point.) */
4020 startup_time
= clock ();
4022 /* Find our root from argv[0]. Assuming argv[0] is, say,
4023 "c:/emacs/bin/emacs.exe" our root will be "c:/emacs". */
4024 root
= alloca (MAXPATHLEN
+ 20);
4025 _fixpath (argv
[0], root
);
4026 msdos_downcase_filename (root
);
4027 len
= strlen (root
);
4028 while (len
> 0 && root
[len
] != '/' && root
[len
] != ':')
4032 && (strcmp (root
+ len
- 4, "/bin") == 0
4033 || strcmp (root
+ len
- 4, "/src") == 0)) /* under a debugger */
4034 root
[len
- 4] = '\0';
4036 strcpy (root
, "c:/emacs"); /* let's be defensive */
4037 len
= strlen (root
);
4038 strcpy (emacsroot
, root
);
4040 /* We default HOME to our root. */
4041 setenv ("HOME", root
, 0);
4043 /* We default EMACSPATH to root + "/bin". */
4044 strcpy (root
+ len
, "/bin");
4045 setenv ("EMACSPATH", root
, 0);
4047 /* I don't expect anybody to ever use other terminals so the internal
4048 terminal is the default. */
4049 setenv ("TERM", "internal", 0);
4051 #ifdef HAVE_X_WINDOWS
4052 /* Emacs expects DISPLAY to be set. */
4053 setenv ("DISPLAY", "unix:0.0", 0);
4056 /* SHELL is a bit tricky -- COMSPEC is the closest we come, but we must
4057 downcase it and mirror the backslashes. */
4058 s
= getenv ("COMSPEC");
4059 if (!s
) s
= "c:/command.com";
4060 t
= alloca (strlen (s
) + 1);
4062 dostounix_filename (t
);
4063 setenv ("SHELL", t
, 0);
4065 /* PATH is also downcased and backslashes mirrored. */
4066 s
= getenv ("PATH");
4068 t
= alloca (strlen (s
) + 3);
4069 /* Current directory is always considered part of MsDos's path but it is
4070 not normally mentioned. Now it is. */
4071 strcat (strcpy (t
, ".;"), s
);
4072 dostounix_filename (t
); /* Not a single file name, but this should work. */
4073 setenv ("PATH", t
, 1);
4075 /* In some sense all dos users have root privileges, so... */
4076 setenv ("USER", "root", 0);
4077 setenv ("NAME", getenv ("USER"), 0);
4079 /* Time zone determined from country code. To make this possible, the
4080 country code may not span more than one time zone. In other words,
4081 in the USA, you lose. */
4083 switch (dos_country_code
)
4085 case 31: /* Belgium */
4086 case 32: /* The Netherlands */
4087 case 33: /* France */
4088 case 34: /* Spain */
4089 case 36: /* Hungary */
4090 case 38: /* Yugoslavia (or what's left of it?) */
4091 case 39: /* Italy */
4092 case 41: /* Switzerland */
4093 case 42: /* Tjekia */
4094 case 45: /* Denmark */
4095 case 46: /* Sweden */
4096 case 47: /* Norway */
4097 case 48: /* Poland */
4098 case 49: /* Germany */
4099 /* Daylight saving from last Sunday in March to last Sunday in
4100 September, both at 2AM. */
4101 setenv ("TZ", "MET-01METDST-02,M3.5.0/02:00,M9.5.0/02:00", 0);
4103 case 44: /* United Kingdom */
4104 case 351: /* Portugal */
4105 case 354: /* Iceland */
4106 setenv ("TZ", "GMT+00", 0);
4108 case 81: /* Japan */
4109 case 82: /* Korea */
4110 setenv ("TZ", "JST-09", 0);
4112 case 90: /* Turkey */
4113 case 358: /* Finland */
4114 setenv ("TZ", "EET-02", 0);
4116 case 972: /* Israel */
4117 /* This is an approximation. (For exact rules, use the
4118 `zoneinfo/israel' file which comes with DJGPP, but you need
4119 to install it in `/usr/share/zoneinfo/' directory first.) */
4120 setenv ("TZ", "IST-02IDT-03,M4.1.6/00:00,M9.5.6/01:00", 0);
4128 static int break_stat
; /* BREAK check mode status. */
4129 static int stdin_stat
; /* stdin IOCTL status. */
4133 /* These must be global. */
4134 static _go32_dpmi_seginfo ctrl_break_vector
;
4135 static _go32_dpmi_registers ctrl_break_regs
;
4136 static int ctrlbreakinstalled
= 0;
4138 /* Interrupt level detection of Ctrl-Break. Don't do anything fancy here! */
4141 ctrl_break_func (regs
)
4142 _go32_dpmi_registers
*regs
;
4148 install_ctrl_break_check ()
4150 if (!ctrlbreakinstalled
)
4152 /* Don't press Ctrl-Break if you don't have either DPMI or Emacs
4153 was compiler with Djgpp 1.11 maintenance level 5 or later! */
4154 ctrlbreakinstalled
= 1;
4155 ctrl_break_vector
.pm_offset
= (int) ctrl_break_func
;
4156 _go32_dpmi_allocate_real_mode_callback_iret (&ctrl_break_vector
,
4158 _go32_dpmi_set_real_mode_interrupt_vector (0x1b, &ctrl_break_vector
);
4162 #endif /* __DJGPP__ < 2 */
4164 /* Turn off Dos' Ctrl-C checking and inhibit interpretation of
4165 control chars by DOS. Determine the keyboard type. */
4170 union REGS inregs
, outregs
;
4171 static int first_time
= 1;
4173 break_stat
= getcbrk ();
4176 install_ctrl_break_check ();
4182 int86 (0x15, &inregs
, &outregs
);
4183 extended_kbd
= (!outregs
.x
.cflag
) && (outregs
.h
.ah
== 0);
4187 if (internal_terminal
4188 #ifdef HAVE_X_WINDOWS
4189 && inhibit_window_system
4193 inregs
.x
.ax
= 0x0021;
4194 int86 (0x33, &inregs
, &outregs
);
4195 have_mouse
= (outregs
.x
.ax
& 0xffff) == 0xffff;
4198 /* Reportedly, the above doesn't work for some mouse drivers. There
4199 is an additional detection method that should work, but might be
4200 a little slower. Use that as an alternative. */
4201 inregs
.x
.ax
= 0x0000;
4202 int86 (0x33, &inregs
, &outregs
);
4203 have_mouse
= (outregs
.x
.ax
& 0xffff) == 0xffff;
4208 have_mouse
= 1; /* enable mouse */
4211 if (outregs
.x
.bx
== 3)
4213 mouse_button_count
= 3;
4214 mouse_button_translate
[0] = 0; /* Left */
4215 mouse_button_translate
[1] = 2; /* Middle */
4216 mouse_button_translate
[2] = 1; /* Right */
4220 mouse_button_count
= 2;
4221 mouse_button_translate
[0] = 0;
4222 mouse_button_translate
[1] = 1;
4224 mouse_position_hook
= &mouse_get_pos
;
4233 stdin_stat
= setmode (fileno (stdin
), O_BINARY
);
4234 return (stdin_stat
!= -1);
4237 return (setmode (fileno (stdin
), O_BINARY
) != -1);
4239 #else /* __DJGPP__ < 2 */
4243 /* I think it is wrong to overwrite `stdin_stat' every time
4244 but the first one this function is called, but I don't
4245 want to change the way it used to work in v1.x.--EZ */
4247 inregs
.x
.ax
= 0x4400; /* Get IOCTL status. */
4248 inregs
.x
.bx
= 0x00; /* 0 = stdin. */
4249 intdos (&inregs
, &outregs
);
4250 stdin_stat
= outregs
.h
.dl
;
4252 inregs
.x
.dx
= stdin_stat
| 0x0020; /* raw mode */
4253 inregs
.x
.ax
= 0x4401; /* Set IOCTL status */
4254 intdos (&inregs
, &outregs
);
4255 return !outregs
.x
.cflag
;
4257 #endif /* __DJGPP__ < 2 */
4260 /* Restore status of standard input and Ctrl-C checking. */
4265 union REGS inregs
, outregs
;
4267 setcbrk (break_stat
);
4272 return (setmode (fileno (stdin
), stdin_stat
) != -1);
4274 #else /* not __DJGPP__ >= 2 */
4276 inregs
.x
.ax
= 0x4401; /* Set IOCTL status. */
4277 inregs
.x
.bx
= 0x00; /* 0 = stdin. */
4278 inregs
.x
.dx
= stdin_stat
;
4279 intdos (&inregs
, &outregs
);
4280 return !outregs
.x
.cflag
;
4282 #endif /* not __DJGPP__ >= 2 */
4286 /* Run command as specified by ARGV in directory DIR.
4287 The command is run with input from TEMPIN, output to
4288 file TEMPOUT and stderr to TEMPERR. */
4291 run_msdos_command (argv
, working_dir
, tempin
, tempout
, temperr
, envv
)
4292 unsigned char **argv
;
4293 const char *working_dir
;
4294 int tempin
, tempout
, temperr
;
4297 char *saveargv1
, *saveargv2
, *lowcase_argv0
, *pa
, *pl
;
4298 char oldwd
[MAXPATHLEN
+ 1]; /* Fixed size is safe on MSDOS. */
4299 int msshell
, result
= -1;
4300 int inbak
, outbak
, errbak
;
4304 /* Get current directory as MSDOS cwd is not per-process. */
4307 /* If argv[0] is the shell, it might come in any lettercase.
4308 Since `Fmember' is case-sensitive, we need to downcase
4309 argv[0], even if we are on case-preserving filesystems. */
4310 lowcase_argv0
= alloca (strlen (argv
[0]) + 1);
4311 for (pa
= argv
[0], pl
= lowcase_argv0
; *pa
; pl
++)
4314 if (*pl
>= 'A' && *pl
<= 'Z')
4319 cmd
= Ffile_name_nondirectory (build_string (lowcase_argv0
));
4320 msshell
= !NILP (Fmember (cmd
, Fsymbol_value (intern ("msdos-shells"))))
4321 && !strcmp ("-c", argv
[1]);
4324 saveargv1
= argv
[1];
4325 saveargv2
= argv
[2];
4329 char *p
= alloca (strlen (argv
[2]) + 1);
4331 strcpy (argv
[2] = p
, saveargv2
);
4332 while (*p
&& isspace (*p
))
4334 while (*p
&& !isspace (*p
))
4342 chdir (working_dir
);
4346 if (inbak
< 0 || outbak
< 0 || errbak
< 0)
4347 goto done
; /* Allocation might fail due to lack of descriptors. */
4350 mouse_get_xy (&x
, &y
);
4352 dos_ttcooked (); /* do it here while 0 = stdin */
4360 if (msshell
&& !argv
[3])
4362 /* MS-DOS native shells are too restrictive. For starters, they
4363 cannot grok commands longer than 126 characters. In DJGPP v2
4364 and later, `system' is much smarter, so we'll call it instead. */
4368 /* A shell gets a single argument--its full command
4369 line--whose original was saved in `saveargv2'. */
4371 /* Don't let them pass empty command lines to `system', since
4372 with some shells it will try to invoke an interactive shell,
4373 which will hang Emacs. */
4374 for (cmnd
= saveargv2
; *cmnd
&& isspace (*cmnd
); cmnd
++)
4378 extern char **environ
;
4379 int save_system_flags
= __system_flags
;
4381 /* Request the most powerful version of `system'. We need
4382 all the help we can get to avoid calling stock DOS shells. */
4383 __system_flags
= (__system_redirect
4384 | __system_use_shell
4385 | __system_allow_multiple_cmds
4386 | __system_allow_long_cmds
4387 | __system_handle_null_commands
4388 | __system_emulate_chdir
);
4391 result
= system (cmnd
);
4392 __system_flags
= save_system_flags
;
4395 result
= 0; /* emulate Unixy shell behavior with empty cmd line */
4399 #endif /* __DJGPP__ > 1 */
4401 result
= spawnve (P_WAIT
, argv
[0], argv
, envv
);
4406 emacs_close (inbak
);
4407 emacs_close (outbak
);
4408 emacs_close (errbak
);
4414 mouse_moveto (x
, y
);
4417 /* Some programs might change the meaning of the highest bit of the
4418 text attribute byte, so we get blinking characters instead of the
4419 bright background colors. Restore that. */
4426 argv
[1] = saveargv1
;
4427 argv
[2] = saveargv2
;
4435 fprintf (stderr
, "%s not yet implemented\r\n", badfunc
);
4442 /* ------------------------- Compatibility functions -------------------
4447 /* Hostnames for a pc are not really funny,
4448 but they are used in change log so we emulate the best we can. */
4450 gethostname (p
, size
)
4454 char *q
= egetenv ("HOSTNAME");
4461 /* When time zones are set from Ms-Dos too many C-libraries are playing
4462 tricks with time values. We solve this by defining our own version
4463 of `gettimeofday' bypassing GO32. Our version needs to be initialized
4464 once and after each call to `tzset' with TZ changed. That is
4465 accomplished by aliasing tzset to init_gettimeofday. */
4467 static struct tm time_rec
;
4470 gettimeofday (struct timeval
*tp
, struct timezone
*tzp
)
4478 if (t
.ti_hour
< time_rec
.tm_hour
) /* midnight wrap */
4482 time_rec
.tm_year
= d
.da_year
- 1900;
4483 time_rec
.tm_mon
= d
.da_mon
- 1;
4484 time_rec
.tm_mday
= d
.da_day
;
4487 time_rec
.tm_hour
= t
.ti_hour
;
4488 time_rec
.tm_min
= t
.ti_min
;
4489 time_rec
.tm_sec
= t
.ti_sec
;
4492 tm
.tm_gmtoff
= dos_timezone_offset
;
4494 tp
->tv_sec
= mktime (&tm
); /* may modify tm */
4495 tp
->tv_usec
= t
.ti_hund
* (1000000 / 100);
4497 /* Ignore tzp; it's obsolescent. */
4501 #endif /* __DJGPP__ < 2 */
4504 * A list of unimplemented functions that we silently ignore.
4508 unsigned alarm (s
) unsigned s
; {}
4509 fork () { return 0; }
4510 int kill (x
, y
) int x
, y
; { return -1; }
4512 void volatile pause () {}
4513 sigsetmask (x
) int x
; { return 0; }
4514 sigblock (mask
) int mask
; { return 0; }
4517 void request_sigio (void) {}
4518 setpgrp () {return 0; }
4519 setpriority (x
,y
,z
) int x
,y
,z
; { return 0; }
4520 void unrequest_sigio (void) {}
4524 #ifdef POSIX_SIGNALS
4526 /* Augment DJGPP library POSIX signal functions. This is needed
4527 as of DJGPP v2.01, but might be in the library in later releases. */
4529 #include <libc/bss.h>
4531 /* A counter to know when to re-initialize the static sets. */
4532 static int sigprocmask_count
= -1;
4534 /* Which signals are currently blocked (initially none). */
4535 static sigset_t current_mask
;
4537 /* Which signals are pending (initially none). */
4538 static sigset_t pending_signals
;
4540 /* Previous handlers to restore when the blocked signals are unblocked. */
4541 typedef void (*sighandler_t
)(int);
4542 static sighandler_t prev_handlers
[320];
4544 /* A signal handler which just records that a signal occured
4545 (it will be raised later, if and when the signal is unblocked). */
4547 sig_suspender (signo
)
4550 sigaddset (&pending_signals
, signo
);
4554 sigprocmask (how
, new_set
, old_set
)
4556 const sigset_t
*new_set
;
4562 /* If called for the first time, initialize. */
4563 if (sigprocmask_count
!= __bss_count
)
4565 sigprocmask_count
= __bss_count
;
4566 sigemptyset (&pending_signals
);
4567 sigemptyset (¤t_mask
);
4568 for (signo
= 0; signo
< 320; signo
++)
4569 prev_handlers
[signo
] = SIG_ERR
;
4573 *old_set
= current_mask
;
4578 if (how
!= SIG_BLOCK
&& how
!= SIG_UNBLOCK
&& how
!= SIG_SETMASK
)
4584 sigemptyset (&new_mask
);
4586 /* DJGPP supports upto 320 signals. */
4587 for (signo
= 0; signo
< 320; signo
++)
4589 if (sigismember (¤t_mask
, signo
))
4590 sigaddset (&new_mask
, signo
);
4591 else if (sigismember (new_set
, signo
) && how
!= SIG_UNBLOCK
)
4593 sigaddset (&new_mask
, signo
);
4595 /* SIGKILL is silently ignored, as on other platforms. */
4596 if (signo
!= SIGKILL
&& prev_handlers
[signo
] == SIG_ERR
)
4597 prev_handlers
[signo
] = signal (signo
, sig_suspender
);
4599 if (( how
== SIG_UNBLOCK
4600 && sigismember (&new_mask
, signo
)
4601 && sigismember (new_set
, signo
))
4602 || (how
== SIG_SETMASK
4603 && sigismember (&new_mask
, signo
)
4604 && !sigismember (new_set
, signo
)))
4606 sigdelset (&new_mask
, signo
);
4607 if (prev_handlers
[signo
] != SIG_ERR
)
4609 signal (signo
, prev_handlers
[signo
]);
4610 prev_handlers
[signo
] = SIG_ERR
;
4612 if (sigismember (&pending_signals
, signo
))
4614 sigdelset (&pending_signals
, signo
);
4619 current_mask
= new_mask
;
4623 #else /* not POSIX_SIGNALS */
4625 sigsetmask (x
) int x
; { return 0; }
4626 sigblock (mask
) int mask
; { return 0; }
4628 #endif /* not POSIX_SIGNALS */
4629 #endif /* __DJGPP__ > 1 */
4632 #include "sysselect.h"
4634 #ifndef EMACS_TIME_ZERO_OR_NEG_P
4635 #define EMACS_TIME_ZERO_OR_NEG_P(time) \
4636 ((long)(time).tv_sec < 0 \
4637 || ((time).tv_sec == 0 \
4638 && (long)(time).tv_usec <= 0))
4641 /* This yields the rest of the current time slice to the task manager.
4642 It should be called by any code which knows that it has nothing
4643 useful to do except idle.
4645 I don't use __dpmi_yield here, since versions of library before 2.02
4646 called Int 2Fh/AX=1680h there in a way that would wedge the DOS box
4647 on some versions of Windows 9X. */
4650 dos_yield_time_slice (void)
4652 _go32_dpmi_registers r
;
4655 r
.x
.ss
= r
.x
.sp
= r
.x
.flags
= 0;
4656 _go32_dpmi_simulate_int (0x2f, &r
);
4661 /* Only event queue is checked. */
4662 /* We don't have to call timer_check here
4663 because wait_reading_process_input takes care of that. */
4665 sys_select (nfds
, rfds
, wfds
, efds
, timeout
)
4667 SELECT_TYPE
*rfds
, *wfds
, *efds
;
4668 EMACS_TIME
*timeout
;
4676 check_input
= FD_ISSET (0, rfds
);
4687 /* If we are looking only for the terminal, with no timeout,
4688 just read it and wait -- that's more efficient. */
4691 while (!detect_input_pending ())
4693 dos_yield_time_slice ();
4698 EMACS_TIME clnow
, cllast
, cldiff
;
4701 EMACS_SET_SECS_USECS (cllast
, t
.ti_sec
, t
.ti_hund
* 10000L);
4703 while (!check_input
|| !detect_input_pending ())
4706 EMACS_SET_SECS_USECS (clnow
, t
.ti_sec
, t
.ti_hund
* 10000L);
4707 EMACS_SUB_TIME (cldiff
, clnow
, cllast
);
4709 /* When seconds wrap around, we assume that no more than
4710 1 minute passed since last `gettime'. */
4711 if (EMACS_TIME_NEG_P (cldiff
))
4712 EMACS_SET_SECS (cldiff
, EMACS_SECS (cldiff
) + 60);
4713 EMACS_SUB_TIME (*timeout
, *timeout
, cldiff
);
4715 /* Stop when timeout value crosses zero. */
4716 if (EMACS_TIME_ZERO_OR_NEG_P (*timeout
))
4719 dos_yield_time_slice ();
4729 * Define overlaid functions:
4731 * chdir -> sys_chdir
4732 * tzset -> init_gettimeofday
4733 * abort -> dos_abort
4738 extern int chdir ();
4744 int len
= strlen (path
);
4745 char *tmp
= (char *)path
;
4747 if (*tmp
&& tmp
[1] == ':')
4749 if (getdisk () != tolower (tmp
[0]) - 'a')
4750 setdisk (tolower (tmp
[0]) - 'a');
4751 tmp
+= 2; /* strip drive: KFS 1995-07-06 */
4755 if (len
> 1 && (tmp
[len
- 1] == '/'))
4757 char *tmp1
= (char *) alloca (len
+ 1);
4768 extern void tzset (void);
4771 init_gettimeofday ()
4777 ltm
= gtm
= time (NULL
);
4778 ltm
= mktime (lstm
= localtime (<m
));
4779 gtm
= mktime (gmtime (>m
));
4780 time_rec
.tm_hour
= 99; /* force gettimeofday to get date */
4781 time_rec
.tm_isdst
= lstm
->tm_isdst
;
4782 dos_timezone_offset
= time_rec
.tm_gmtoff
= (int)(gtm
- ltm
) / 60;
4789 dos_abort (file
, line
)
4793 char buffer1
[200], buffer2
[400];
4796 sprintf (buffer1
, "<EMACS FATAL ERROR IN %s LINE %d>", file
, line
);
4797 for (i
= j
= 0; buffer1
[i
]; i
++) {
4798 buffer2
[j
++] = buffer1
[i
];
4799 buffer2
[j
++] = 0x70;
4801 dosmemput (buffer2
, j
, (int)ScreenPrimary
);
4802 ScreenSetCursor (2, 0);
4810 ScreenSetCursor (10, 0);
4811 cputs ("\r\n\nEmacs aborted!\r\n");
4813 #if __DJGPP__ == 2 && __DJGPP_MINOR__ < 2
4814 if (screen_virtual_segment
)
4815 dosv_refresh_virtual_screen (2 * 10 * screen_size_X
, 4 * screen_size_X
);
4816 /* Generate traceback, so we could tell whodunit. */
4817 signal (SIGINT
, SIG_DFL
);
4818 __asm__
__volatile__ ("movb $0x1b,%al;call ___djgpp_hw_exception");
4819 #else /* __DJGPP_MINOR__ >= 2 */
4821 #endif /* __DJGPP_MINOR__ >= 2 */
4827 /* The following variables are required so that cus-start.el won't
4828 complain about unbound variables. */
4829 #ifndef HAVE_X_WINDOWS
4830 /* Search path for bitmap files (xfns.c). */
4831 Lisp_Object Vx_bitmap_file_path
;
4832 int x_stretch_cursor_p
;
4834 #ifndef subprocesses
4835 /* Nonzero means delete a process right away if it exits (process.c). */
4836 static int delete_exited_processes
;
4841 recent_doskeys
= Fmake_vector (make_number (NUM_RECENT_DOSKEYS
), Qnil
);
4842 staticpro (&recent_doskeys
);
4843 #ifndef HAVE_X_WINDOWS
4844 staticpro (&help_echo
);
4846 staticpro (&previous_help_echo
);
4847 previous_help_echo
= Qnil
;
4849 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
4850 "List of directories to search for bitmap files for X.");
4851 Vx_bitmap_file_path
= decode_env_path ((char *) 0, ".");
4853 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
4854 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
4855 For example, if a block cursor is over a tab, it will be drawn as\n\
4856 wide as that tab on the display. (No effect on MS-DOS.)");
4857 x_stretch_cursor_p
= 0;
4859 /* The following three are from xfns.c: */
4860 Qbackground_color
= intern ("background-color");
4861 staticpro (&Qbackground_color
);
4862 Qforeground_color
= intern ("foreground-color");
4863 staticpro (&Qforeground_color
);
4865 DEFVAR_LISP ("dos-unsupported-char-glyph", &Vdos_unsupported_char_glyph
,
4866 "*Glyph to display instead of chars not supported by current codepage.\n\
4868 This variable is used only by MSDOS terminals.");
4869 Vdos_unsupported_char_glyph
= '\177';
4871 #ifndef subprocesses
4872 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes
,
4873 "*Non-nil means delete processes immediately when they exit.\n\
4874 nil means don't delete them until `list-processes' is run.");
4875 delete_exited_processes
= 0;
4878 defsubr (&Srecent_doskeys
);
4879 defsubr (&Smsdos_long_file_names
);
4880 defsubr (&Smsdos_downcase_filename
);
4881 defsubr (&Smsdos_remember_default_colors
);