Update copyright year to 2015
[emacs.git] / src / dosfns.c
blob8c0fed2230fc74ea8340a1ea0fbba042238826c0
1 /* MS-DOS specific Lisp utilities. Coded by Manabu Higashida, 1991.
2 Major changes May-July 1993 Morten Welinder (only 10% original code left)
3 Copyright (C) 1991, 1993, 1996-1998, 2001-2015 Free Software
4 Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 #include <config.h>
23 #ifdef MSDOS
24 /* The entire file is within this conditional */
26 #include <stdio.h>
27 /* gettime and settime in dos.h clash with their namesakes from
28 gnulib, so we move out of our way the prototypes in dos.h. */
29 #define gettime dos_h_gettime_
30 #define settime dos_h_settime_
31 #include <dos.h>
32 #undef gettime
33 #undef settime
35 #include "lisp.h"
36 #include "character.h"
37 #include "buffer.h"
38 #include "termchar.h"
39 #include "frame.h"
40 #include "termhooks.h"
41 #include "blockinput.h"
42 #include "window.h"
43 #include "dosfns.h"
44 #include "msdos.h"
45 #include "dispextern.h"
46 #include "coding.h"
47 #include "process.h"
48 #include <dpmi.h>
49 #include <go32.h>
50 #include <dirent.h>
51 #include <sys/vfs.h>
52 #include <unistd.h>
53 #include <grp.h>
54 #include <crt0.h>
56 DEFUN ("int86", Fint86, Sint86, 2, 2, 0,
57 doc: /* Call specific MS-DOS interrupt number INTERRUPT with REGISTERS.
58 Return the updated REGISTER vector.
60 INTERRUPT should be an integer in the range 0 to 255.
61 REGISTERS should be a vector produced by `make-register' and
62 `set-register-value'. */)
63 (Lisp_Object interrupt, Lisp_Object registers)
65 register int i;
66 int no;
67 union REGS inregs, outregs;
69 CHECK_NUMBER (interrupt);
70 no = (unsigned long) XINT (interrupt);
71 CHECK_VECTOR (registers);
72 if (no < 0 || no > 0xff || ASIZE (registers) != 8)
73 return Qnil;
74 for (i = 0; i < 8; i++)
75 CHECK_NUMBER (AREF (registers, i));
77 inregs.x.ax = (unsigned long) XFASTINT (AREF (registers, 0));
78 inregs.x.bx = (unsigned long) XFASTINT (AREF (registers, 1));
79 inregs.x.cx = (unsigned long) XFASTINT (AREF (registers, 2));
80 inregs.x.dx = (unsigned long) XFASTINT (AREF (registers, 3));
81 inregs.x.si = (unsigned long) XFASTINT (AREF (registers, 4));
82 inregs.x.di = (unsigned long) XFASTINT (AREF (registers, 5));
83 inregs.x.cflag = (unsigned long) XFASTINT (AREF (registers, 6));
84 inregs.x.flags = (unsigned long) XFASTINT (AREF (registers, 7));
86 int86 (no, &inregs, &outregs);
88 ASET (registers, 0, make_number (outregs.x.ax));
89 ASET (registers, 1, make_number (outregs.x.bx));
90 ASET (registers, 2, make_number (outregs.x.cx));
91 ASET (registers, 3, make_number (outregs.x.dx));
92 ASET (registers, 4, make_number (outregs.x.si));
93 ASET (registers, 5, make_number (outregs.x.di));
94 ASET (registers, 6, make_number (outregs.x.cflag));
95 ASET (registers, 7, make_number (outregs.x.flags));
97 return registers;
100 DEFUN ("msdos-memget", Fdos_memget, Sdos_memget, 2, 2, 0,
101 doc: /* Read DOS memory at offset ADDRESS into VECTOR.
102 Return the updated VECTOR. */)
103 (Lisp_Object address, Lisp_Object vector)
105 register int i;
106 int offs, len;
107 char *buf;
109 CHECK_NUMBER (address);
110 offs = (unsigned long) XINT (address);
111 CHECK_VECTOR (vector);
112 len = ASIZE (vector);
113 if (len < 1 || len > 2048 || offs < 0 || offs > 0xfffff - len)
114 return Qnil;
115 buf = alloca (len);
116 dosmemget (offs, len, buf);
118 for (i = 0; i < len; i++)
119 ASET (vector, i, make_number (buf[i]));
121 return vector;
124 DEFUN ("msdos-memput", Fdos_memput, Sdos_memput, 2, 2, 0,
125 doc: /* Write DOS memory at offset ADDRESS from VECTOR. */)
126 (Lisp_Object address, Lisp_Object vector)
128 register int i;
129 int offs, len;
130 char *buf;
132 CHECK_NUMBER (address);
133 offs = (unsigned long) XINT (address);
134 CHECK_VECTOR (vector);
135 len = ASIZE (vector);
136 if (len < 1 || len > 2048 || offs < 0 || offs > 0xfffff - len)
137 return Qnil;
138 buf = alloca (len);
140 for (i = 0; i < len; i++)
142 CHECK_NUMBER (AREF (vector, i));
143 buf[i] = (unsigned char) XFASTINT (AREF (vector, i)) & 0xFF;
146 dosmemput (buf, len, offs);
147 return Qt;
150 DEFUN ("msdos-set-keyboard", Fmsdos_set_keyboard, Smsdos_set_keyboard, 1, 2, 0,
151 doc: /* Set keyboard layout according to COUNTRY-CODE.
152 If the optional argument ALLKEYS is non-nil, the keyboard is mapped for
153 all keys; otherwise it is only used when the ALT key is pressed.
154 The current keyboard layout is available in dos-keyboard-code. */)
155 (Lisp_Object country_code, Lisp_Object allkeys)
157 CHECK_NUMBER (country_code);
158 if (!dos_set_keyboard (XINT (country_code), !NILP (allkeys)))
159 return Qnil;
160 return Qt;
163 #ifndef HAVE_X_WINDOWS
164 /* Later we might want to control the mouse interface with this function,
165 e.g., with respect to non-80 column screen modes. */
167 DEFUN ("msdos-mouse-p", Fmsdos_mouse_p, Smsdos_mouse_p, 0, 0, 0,
168 doc: /* Report whether a mouse is present. */)
169 (void)
171 if (have_mouse)
172 return Qt;
173 else
174 return Qnil;
176 #endif
178 DEFUN ("msdos-mouse-init", Fmsdos_mouse_init, Smsdos_mouse_init, 0, 0, "",
179 doc: /* Initialize and enable mouse if available. */)
180 (void)
182 if (have_mouse)
184 have_mouse = 1;
185 mouse_init ();
186 return Qt;
188 return Qnil;
191 DEFUN ("msdos-mouse-enable", Fmsdos_mouse_enable, Smsdos_mouse_enable, 0, 0, "",
192 doc: /* Enable mouse if available. */)
193 (void)
195 if (have_mouse)
197 have_mouse = 1;
198 mouse_on ();
200 return have_mouse ? Qt : Qnil;
203 DEFUN ("msdos-mouse-disable", Fmsdos_mouse_disable, Smsdos_mouse_disable, 0, 0, "",
204 doc: /* Disable mouse if available. */)
205 (void)
207 mouse_off ();
208 if (have_mouse) have_mouse = -1;
209 return Qnil;
212 DEFUN ("insert-startup-screen", Finsert_startup_screen, Sinsert_startup_screen, 0, 0, "",
213 doc: /* Insert copy of screen contents prior to starting Emacs.
214 Return nil if startup screen is not available. */)
215 (void)
217 char *s;
218 int rows, cols, i, j;
220 if (!dos_get_saved_screen (&s, &rows, &cols))
221 return Qnil;
223 for (i = 0; i < rows; i++)
225 for (j = 0; j < cols; j++)
227 insert_char (*s);
228 s += 2;
230 insert_char ('\n');
233 return Qt;
236 unsigned char dos_country_info[DOS_COUNTRY_INFO];
237 static unsigned char usa_country_info[DOS_COUNTRY_INFO] = {
238 0, 0, /* date format */
239 '$', 0, 0, 0, 0, /* currency string */
240 ',', 0, /* thousands separator */
241 '.', 0, /* decimal separator */
242 '/', 0, /* date separator */
243 ':', 0, /* time separator */
244 0, /* currency format */
245 2, /* digits after decimal in currency */
246 0, /* time format */
247 0, 0, 0, 0, /* address of case map routine, GPF if used */
248 ' ', 0, /* data-list separator (?) */
249 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* reserved */
252 #ifndef HAVE_X_WINDOWS
253 static unsigned dos_windows_version;
254 char parent_vm_title[50]; /* Ralf Brown says 30 is enough */
255 int w95_set_virtual_machine_title (const char *);
257 void
258 restore_parent_vm_title (void)
260 if (NILP (Vdos_windows_version))
261 return;
262 if ((dos_windows_version & 0xff) >= 4 && parent_vm_title[0])
263 w95_set_virtual_machine_title (parent_vm_title);
264 delay (50);
266 #endif /* !HAVE_X_WINDOWS */
268 void
269 init_dosfns (void)
271 union REGS regs;
272 _go32_dpmi_registers dpmiregs;
273 unsigned long xbuf = _go32_info_block.linear_address_of_transfer_buffer;
275 #ifndef SYSTEM_MALLOC
276 extern void get_lim_data (void);
278 get_lim_data (); /* why the hell isn't this called elsewhere? */
279 #endif
281 regs.x.ax = 0x3000;
282 intdos (&regs, &regs);
283 Vdos_version = Fcons (make_number (regs.h.al), make_number (regs.h.ah));
285 /* Obtain the country code via DPMI, use DJGPP transfer buffer. */
286 dpmiregs.x.ax = 0x3800;
287 dpmiregs.x.ds = xbuf >> 4;
288 dpmiregs.x.dx = 0;
289 dpmiregs.x.ss = dpmiregs.x.sp = dpmiregs.x.flags = 0;
290 _go32_dpmi_simulate_int (0x21, &dpmiregs);
291 if (dpmiregs.x.flags & 1)
293 dos_country_code = 1; /* assume USA if 213800 failed */
294 memcpy (dos_country_info, usa_country_info, DOS_COUNTRY_INFO);
296 else
298 dos_country_code = dpmiregs.x.bx;
299 dosmemget (xbuf, DOS_COUNTRY_INFO, dos_country_info);
302 dos_set_keyboard (dos_country_code, 0);
304 regs.x.ax = 0x6601;
305 intdos (&regs, &regs);
306 if (regs.x.cflag)
307 /* Estimate code page from country code */
308 switch (dos_country_code)
310 case 45: /* Denmark */
311 case 47: /* Norway */
312 dos_codepage = 865;
313 break;
314 default:
315 /* US */
316 dos_codepage = 437;
318 else
319 dos_codepage = regs.x.bx & 0xffff;
321 #ifndef HAVE_X_WINDOWS
322 parent_vm_title[0] = '\0';
324 /* If we are running from DOS box on MS-Windows, get Windows version. */
325 dpmiregs.x.ax = 0x1600; /* enhanced mode installation check */
326 dpmiregs.x.ss = dpmiregs.x.sp = dpmiregs.x.flags = 0;
327 _go32_dpmi_simulate_int (0x2f, &dpmiregs);
328 /* We only support Windows-specific features when we run on Windows 9X
329 or on Windows 3.X/enhanced mode.
331 Int 2Fh/AX=1600h returns:
333 AL = 00: no Windows at all;
334 AL = 01: Windows/386 2.x;
335 AL = 80h: Windows 3.x in mode other than enhanced;
336 AL = FFh: Windows/386 2.x
338 We also check AH > 0 (Windows 3.1 or later), in case AL tricks us. */
339 if (dpmiregs.h.al > 2 && dpmiregs.h.al != 0x80 && dpmiregs.h.al != 0xff
340 && (dpmiregs.h.al > 3 || dpmiregs.h.ah > 0))
342 dos_windows_version = dpmiregs.x.ax;
343 Vdos_windows_version =
344 Fcons (make_number (dpmiregs.h.al), make_number (dpmiregs.h.ah));
346 /* Save the current title of this virtual machine, so we can restore
347 it before exiting. Otherwise, Windows 95 will continue to use
348 the title we set even after we are history, stupido... */
349 if (dpmiregs.h.al >= 4)
351 dpmiregs.x.ax = 0x168e;
352 dpmiregs.x.dx = 3; /* get VM title */
353 dpmiregs.x.cx = sizeof (parent_vm_title) - 1;
354 dpmiregs.x.es = __tb >> 4;
355 dpmiregs.x.di = __tb & 15;
356 dpmiregs.x.sp = dpmiregs.x.ss = dpmiregs.x.flags = 0;
357 _go32_dpmi_simulate_int (0x2f, &dpmiregs);
358 if (dpmiregs.x.ax == 1)
359 dosmemget (__tb, sizeof (parent_vm_title), parent_vm_title);
362 else
364 dos_windows_version = 0;
365 Vdos_windows_version = Qnil;
367 #endif /* !HAVE_X_WINDOWS */
369 /* Without this, we never see hidden files.
370 Don't OR it with the previous value, so the value recorded at dump
371 time, possibly with `preserve-case' flags set, won't get through. */
372 __opendir_flags = __OPENDIR_FIND_HIDDEN;
375 #ifndef HAVE_X_WINDOWS
377 /* Emulation of some X window features from xfns.c and xfaces.c. */
379 /* Standard VGA colors, in the order of their standard numbering
380 in the default VGA palette. */
381 static char *vga_colors[16] = {
382 "black", "blue", "green", "cyan", "red", "magenta", "brown",
383 "lightgray", "darkgray", "lightblue", "lightgreen", "lightcyan",
384 "lightred", "lightmagenta", "yellow", "white"
387 /* Given a color name, return its index, or -1 if not found. Note
388 that this only performs case-insensitive comparison against the
389 standard names. For anything more sophisticated, like matching
390 "gray" with "grey" or translating X color names into their MSDOS
391 equivalents, call the Lisp function Qtty_color_desc (defined
392 on lisp/term/tty-colors.el). */
394 msdos_stdcolor_idx (const char *name)
396 int i;
398 for (i = 0; i < ARRAYELTS (vga_colors); i++)
399 if (xstrcasecmp (name, vga_colors[i]) == 0)
400 return i;
402 return
403 strcmp (name, unspecified_fg) == 0 ? FACE_TTY_DEFAULT_FG_COLOR
404 : strcmp (name, unspecified_bg) == 0 ? FACE_TTY_DEFAULT_BG_COLOR
405 : FACE_TTY_DEFAULT_COLOR;
408 /* Given a color index, return its standard name. */
409 Lisp_Object
410 msdos_stdcolor_name (int idx)
412 extern Lisp_Object Qunspecified;
414 if (idx == FACE_TTY_DEFAULT_FG_COLOR)
415 return build_string (unspecified_fg);
416 else if (idx == FACE_TTY_DEFAULT_BG_COLOR)
417 return build_string (unspecified_bg);
418 else if (idx >= 0 && idx < ARRAYELTS (vga_colors))
419 return build_string (vga_colors[idx]);
420 else
421 return Qunspecified; /* meaning the default */
424 /* Support for features that are available when we run in a DOS box
425 on MS-Windows. */
427 ms_windows_version (void)
429 return dos_windows_version;
432 /* Set the title of the current virtual machine, to appear on
433 the caption bar of that machine's window. */
436 w95_set_virtual_machine_title (const char *title_string)
438 /* Only Windows 9X (version 4 and higher) support this function. */
439 if (!NILP (Vdos_windows_version)
440 && (dos_windows_version & 0xff) >= 4)
442 _go32_dpmi_registers regs;
443 dosmemput (title_string, strlen (title_string) + 1, __tb);
444 regs.x.ax = 0x168e;
445 regs.x.dx = 1;
446 regs.x.es = __tb >> 4;
447 regs.x.di = __tb & 15;
448 regs.x.sp = regs.x.ss = regs.x.flags = 0;
449 _go32_dpmi_simulate_int (0x2f, &regs);
450 return regs.x.ax == 1;
452 return 0;
455 /* Change the title of frame F to NAME.
456 If NAME is nil, use the frame name as the title.
458 If Emacs is not run from a DOS box on Windows 9X, this only
459 sets the name in the frame struct, but has no other effects. */
461 void
462 x_set_title (struct frame *f, Lisp_Object name)
464 /* Don't change the title if it's already NAME. */
465 if (EQ (name, f->title))
466 return;
468 update_mode_lines = 13;
470 fset_title (f, name);
472 if (NILP (name))
473 name = f->name;
475 if (FRAME_MSDOS_P (f))
477 block_input ();
478 w95_set_virtual_machine_title (SDATA (name));
479 unblock_input ();
482 #endif /* !HAVE_X_WINDOWS */
484 DEFUN ("file-system-info", Ffile_system_info, Sfile_system_info, 1, 1, 0,
485 doc: /* Return storage information about the file system FILENAME is on.
486 Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
487 storage of the file system, FREE is the free storage, and AVAIL is the
488 storage available to a non-superuser. All 3 numbers are in bytes.
489 If the underlying system call fails, value is nil. */)
490 (Lisp_Object filename)
492 struct statfs stfs;
493 Lisp_Object encoded, value;
495 CHECK_STRING (filename);
496 filename = Fexpand_file_name (filename, Qnil);
497 encoded = ENCODE_FILE (filename);
499 if (statfs (SDATA (encoded), &stfs))
500 value = Qnil;
501 else
502 value = list3 (make_float ((double) stfs.f_bsize * stfs.f_blocks),
503 make_float ((double) stfs.f_bsize * stfs.f_bfree),
504 make_float ((double) stfs.f_bsize * stfs.f_bavail));
506 return value;
509 /* System depended enumeration of and access to system processes a-la
510 ps(1). Here, we only return info about the running Emacs process.
511 (There are no other processes on DOS, right?) */
513 Lisp_Object
514 list_system_processes (void)
516 Lisp_Object proclist = Qnil;
518 proclist = Fcons (make_fixnum_or_float (getpid ()), proclist);
520 return proclist;
523 Lisp_Object
524 system_process_attributes (Lisp_Object pid)
526 int proc_id;
527 Lisp_Object attrs = Qnil;
529 CHECK_NUMBER_OR_FLOAT (pid);
530 proc_id = FLOATP (pid) ? XFLOAT_DATA (pid) : XINT (pid);
532 if (proc_id == getpid ())
534 EMACS_INT uid, gid;
535 char *usr;
536 struct group *gr;
537 char cmd[FILENAME_MAX];
538 char *cmdline = NULL, *p, *q;
539 size_t cmdline_size = 0;
540 int i;
541 Lisp_Object cmd_str, decoded_cmd, tem;
542 double pmem;
543 #ifndef SYSTEM_MALLOC
544 extern unsigned long ret_lim_data ();
545 #endif
547 uid = getuid ();
548 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs);
549 usr = getlogin ();
550 if (usr)
551 attrs = Fcons (Fcons (Quser, build_string (usr)), attrs);
552 gid = getgid ();
553 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs);
554 gr = getgrgid (gid);
555 if (gr)
556 attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
557 strcpy (cmd, basename (__crt0_argv[0]));
558 /* Command name is encoded in locale-coding-system; decode it. */
559 cmd_str = build_unibyte_string (cmd);
560 decoded_cmd = code_convert_string_norecord (cmd_str,
561 Vlocale_coding_system, 0);
562 attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs);
563 /* Pretend we have 0 as PPID. */
564 attrs = Fcons (Fcons (Qppid, make_number (0)), attrs);
565 attrs = Fcons (Fcons (Qpgrp, pid), attrs);
566 attrs = Fcons (Fcons (Qttname, build_string ("/dev/tty")), attrs);
567 /* We are never idle! */
568 tem = Fget_internal_run_time ();
569 attrs = Fcons (Fcons (Qtime, tem), attrs);
570 attrs = Fcons (Fcons (Qthcount, make_number (1)), attrs);
571 attrs = Fcons (Fcons (Qstart,
572 Fsymbol_value (intern ("before-init-time"))),
573 attrs);
574 attrs = Fcons (Fcons (Qvsize,
575 make_fixnum_or_float ((unsigned long)sbrk (0)/1024)),
576 attrs);
577 attrs = Fcons (Fcons (Qetime, tem), attrs);
578 #ifndef SYSTEM_MALLOC
579 /* ret_lim_data is on vm-limit.c, which is not compiled in under
580 SYSTEM_MALLOC. */
581 pmem = (double)((unsigned long) sbrk (0)) / ret_lim_data () * 100.0;
582 if (pmem > 100)
583 #endif
584 pmem = 100;
585 attrs = Fcons (Fcons (Qpmem, make_float (pmem)), attrs);
586 /* Pass 1: Count how much storage we need. */
587 for (i = 0; i < __crt0_argc; i++)
589 cmdline_size += strlen (__crt0_argv[i]) + 1; /* +1 for blank delim */
590 if (strpbrk (__crt0_argv[i], " \t\n\r\v\f"))
592 cmdline_size += 2;
593 for (p = __crt0_argv[i]; *p; p++)
595 if (*p == '"')
596 cmdline_size++;
600 /* Pass 2: Allocate storage and concatenate argv[]. */
601 cmdline = xmalloc (cmdline_size + 1);
602 for (i = 0, q = cmdline; i < __crt0_argc; i++)
604 if (strpbrk (__crt0_argv[i], " \t\n\r\v\f"))
606 *q++ = '"';
607 for (p = __crt0_argv[i]; *p; p++)
609 if (*p == '\"')
610 *q++ = '\\';
611 *q++ = *p;
613 *q++ = '"';
615 else
617 strcpy (q, __crt0_argv[i]);
618 q += strlen (__crt0_argv[i]);
620 *q++ = ' ';
622 /* Remove the trailing blank. */
623 if (q > cmdline)
624 q[-1] = '\0';
626 /* Command line is encoded in locale-coding-system; decode it. */
627 cmd_str = build_unibyte_string (cmdline);
628 decoded_cmd = code_convert_string_norecord (cmd_str,
629 Vlocale_coding_system, 0);
630 xfree (cmdline);
631 attrs = Fcons (Fcons (Qargs, decoded_cmd), attrs);
634 return attrs;
637 /* Support for memory-info. */
639 dos_memory_info (unsigned long *totalram, unsigned long *freeram,
640 unsigned long *totalswap, unsigned long *freeswap)
642 _go32_dpmi_meminfo info;
643 unsigned long mem1, mem2, freemem;
645 _go32_dpmi_get_free_memory_information (&info);
646 /* DPMI server of Windows NT and its descendants reports in
647 info.available_memory a much lower amount that is really
648 available, which causes bogus "past 95% of memory limit"
649 warnings. Try to overcome that via circumstantial evidence. */
650 mem1 = info.available_memory;
651 mem2 = info.available_physical_pages;
652 /* DPMI Spec: "Fields that are unavailable will hold -1." */
653 if ((long)mem1 == -1L)
654 mem1 = 0;
655 if ((long)mem2 == -1L)
656 mem2 = 0;
657 else
658 mem2 *= 4096;
659 /* Surely, the available memory is at least what we have physically
660 available, right? */
661 if (mem1 >= mem2)
662 freemem = mem1;
663 else
664 freemem = mem2;
665 *freeram = freemem;
666 *totalswap =
667 ((long)info.max_pages_in_paging_file == -1L)
669 : info.max_pages_in_paging_file * 4096;
670 *totalram =
671 ((long)info.total_physical_pages == -1L)
672 ? (freemem + (unsigned long)sbrk (0) + *totalswap)
673 : info.total_physical_pages * 4096;
674 *freeswap = 0;
675 return 0;
679 void
680 dos_cleanup (void)
682 struct tty_display_info *tty;
684 #ifndef HAVE_X_WINDOWS
685 restore_parent_vm_title ();
686 #endif
687 /* Make sure the termscript file is committed, in case we are
688 crashing and some vital info was written there. */
689 if (FRAMEP (selected_frame))
691 struct frame *sf = XFRAME (selected_frame);
693 if (FRAME_LIVE_P (sf)
694 && (FRAME_MSDOS_P (sf) || FRAME_TERMCAP_P (sf)))
696 tty = CURTTY ();
697 if (tty->termscript)
699 fflush (tty->termscript);
700 fsync (fileno (tty->termscript));
707 * Define everything
709 void
710 syms_of_dosfns (void)
712 defsubr (&Sint86);
713 defsubr (&Sdos_memget);
714 defsubr (&Sdos_memput);
715 defsubr (&Smsdos_mouse_init);
716 defsubr (&Smsdos_mouse_enable);
717 defsubr (&Smsdos_set_keyboard);
718 defsubr (&Sinsert_startup_screen);
719 defsubr (&Smsdos_mouse_disable);
720 defsubr (&Sfile_system_info);
721 #ifndef HAVE_X_WINDOWS
722 defsubr (&Smsdos_mouse_p);
723 #endif
725 DEFVAR_INT ("dos-country-code", dos_country_code,
726 doc: /* The country code returned by Dos when Emacs was started.
727 Usually this is the international telephone prefix. */);
729 DEFVAR_INT ("dos-codepage", dos_codepage,
730 doc: /* The codepage active when Emacs was started.
731 The following are known:
732 437 United States
733 850 Multilingual (Latin I)
734 852 Slavic (Latin II)
735 857 Turkish
736 860 Portugal
737 861 Iceland
738 863 Canada (French)
739 865 Norway/Denmark */);
741 DEFVAR_INT ("dos-timezone-offset", dos_timezone_offset,
742 doc: /* The current timezone offset to UTC in minutes.
743 Implicitly modified when the TZ variable is changed. */);
745 DEFVAR_LISP ("dos-version", Vdos_version,
746 doc: /* The (MAJOR . MINOR) Dos version (subject to modification with setver). */);
748 #ifndef HAVE_X_WINDOWS
749 DEFVAR_LISP ("dos-windows-version", Vdos_windows_version,
750 doc: /* The (MAJOR . MINOR) Windows version for DOS session on MS-Windows. */);
751 #endif
753 DEFVAR_LISP ("dos-display-scancodes", Vdos_display_scancodes,
754 doc: /* Whether DOS raw keyboard events are displayed as you type.
755 When non-nil, the keyboard scan-codes are displayed at the bottom right
756 corner of the display (typically at the end of the mode line).
757 The output format is: scan code:char code*modifiers. */);
759 Vdos_display_scancodes = Qnil;
761 DEFVAR_INT ("dos-hyper-key", dos_hyper_key,
762 doc: /* If set to 1, use right ALT key as hyper key.
763 If set to 2, use right CTRL key as hyper key. */);
764 dos_hyper_key = 0;
766 DEFVAR_INT ("dos-super-key", dos_super_key,
767 doc: /* If set to 1, use right ALT key as super key.
768 If set to 2, use right CTRL key as super key. */);
769 dos_super_key = 0;
771 DEFVAR_INT ("dos-keypad-mode", dos_keypad_mode,
772 doc: /* Controls what key code is returned by a key in the numeric keypad.
773 The `numlock ON' action is only taken if no modifier keys are pressed.
774 The value is an integer constructed by adding the following bits together:
776 0x00 Digit key returns digit (if numlock ON)
777 0x01 Digit key returns kp-digit (if numlock ON)
778 0x02 Digit key returns M-digit (if numlock ON)
779 0x03 Digit key returns edit key (if numlock ON)
781 0x00 Grey key returns char (if numlock ON)
782 0x04 Grey key returns kp-key (if numlock ON)
784 0x00 Digit key returns digit (if numlock OFF)
785 0x10 Digit key returns kp-digit (if numlock OFF)
786 0x20 Digit key returns M-digit (if numlock OFF)
787 0x30 Digit key returns edit key (if numlock OFF)
789 0x00 Grey key returns char (if numlock OFF)
790 0x40 Grey key returns kp-key (if numlock OFF)
792 0x200 ALT-0..ALT-9 in top-row produces shifted codes. */);
793 dos_keypad_mode = 0x75;
795 DEFVAR_INT ("dos-keyboard-layout", dos_keyboard_layout,
796 doc: /* Contains the country code for the current keyboard layout.
797 Use msdos-set-keyboard to select another keyboard layout. */);
798 dos_keyboard_layout = 1; /* US */
800 DEFVAR_INT ("dos-decimal-point", dos_decimal_point,
801 doc: /* The character to produce when kp-decimal key is pressed.
802 If non-zero, this variable contains the character to be returned when the
803 decimal point key in the numeric keypad is pressed when Num Lock is on.
804 If zero, the decimal point key returns the country code specific value. */);
805 dos_decimal_point = 0;
807 #endif /* MSDOS */