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