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