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