Commit | Line | Data |
---|---|---|
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) | |
0b5538bd | 3 | Copyright (C) 1991, 1993, 1996, 1997, 1998, 2001, 2002, 2003, 2004, |
114f9c96 | 4 | 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
1b94449f RS |
5 | |
6 | This file is part of GNU Emacs. | |
7 | ||
9ec0b715 | 8 | GNU Emacs is free software: you can redistribute it and/or modify |
1b94449f | 9 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. | |
1b94449f RS |
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 | |
9ec0b715 | 19 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
1b94449f | 20 | |
48984716 | 21 | #include <config.h> |
1b94449f RS |
22 | |
23 | #ifdef MSDOS | |
24 | /* The entire file is within this conditional */ | |
25 | ||
26 | #include <stdio.h> | |
e4441df0 | 27 | #include <string.h> |
1b94449f | 28 | #include <dos.h> |
d7306fe6 | 29 | #include <setjmp.h> |
1b94449f RS |
30 | #include "lisp.h" |
31 | #include "buffer.h" | |
32 | #include "termchar.h" | |
1b94449f | 33 | #include "frame.h" |
c06981c0 | 34 | #include "termhooks.h" |
838a94b8 EZ |
35 | #include "blockinput.h" |
36 | #include "window.h" | |
1b94449f RS |
37 | #include "dosfns.h" |
38 | #include "msdos.h" | |
e4441df0 | 39 | #include "dispextern.h" |
83be827a | 40 | #include "character.h" |
76a76a57 | 41 | #include "coding.h" |
e5c9f94c | 42 | #include "process.h" |
838a94b8 | 43 | #include <dpmi.h> |
5f08dc78 | 44 | #include <go32.h> |
50666766 | 45 | #include <dirent.h> |
76a76a57 | 46 | #include <sys/vfs.h> |
e5c9f94c EZ |
47 | #include <unistd.h> |
48 | #include <grp.h> | |
49 | #include <crt0.h> | |
1b94449f | 50 | |
1b94449f | 51 | DEFUN ("int86", Fint86, Sint86, 2, 2, 0, |
8fc29035 | 52 | doc: /* Call specific MS-DOS interrupt number INTERRUPT with REGISTERS. |
7363986a PJ |
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'. */) | |
5842a27b | 58 | (Lisp_Object interrupt, Lisp_Object registers) |
1b94449f RS |
59 | { |
60 | register int i; | |
61 | int no; | |
62 | union REGS inregs, outregs; | |
63 | Lisp_Object val; | |
64 | ||
b7826503 | 65 | CHECK_NUMBER (interrupt); |
e20104ba | 66 | no = (unsigned long) XINT (interrupt); |
b7826503 | 67 | CHECK_VECTOR (registers); |
b058cb36 | 68 | if (no < 0 || no > 0xff || XVECTOR (registers)-> size != 8) |
1b94449f RS |
69 | return Qnil; |
70 | for (i = 0; i < 8; i++) | |
b7826503 | 71 | CHECK_NUMBER (XVECTOR (registers)->contents[i]); |
1b94449f | 72 | |
e20104ba EN |
73 | inregs.x.ax = (unsigned long) XFASTINT (XVECTOR (registers)->contents[0]); |
74 | inregs.x.bx = (unsigned long) XFASTINT (XVECTOR (registers)->contents[1]); | |
75 | inregs.x.cx = (unsigned long) XFASTINT (XVECTOR (registers)->contents[2]); | |
76 | inregs.x.dx = (unsigned long) XFASTINT (XVECTOR (registers)->contents[3]); | |
77 | inregs.x.si = (unsigned long) XFASTINT (XVECTOR (registers)->contents[4]); | |
78 | inregs.x.di = (unsigned long) XFASTINT (XVECTOR (registers)->contents[5]); | |
79 | inregs.x.cflag = (unsigned long) XFASTINT (XVECTOR (registers)->contents[6]); | |
80 | inregs.x.flags = (unsigned long) XFASTINT (XVECTOR (registers)->contents[7]); | |
1b94449f RS |
81 | |
82 | int86 (no, &inregs, &outregs); | |
83 | ||
e20104ba EN |
84 | XVECTOR (registers)->contents[0] = make_number (outregs.x.ax); |
85 | XVECTOR (registers)->contents[1] = make_number (outregs.x.bx); | |
86 | XVECTOR (registers)->contents[2] = make_number (outregs.x.cx); | |
87 | XVECTOR (registers)->contents[3] = make_number (outregs.x.dx); | |
88 | XVECTOR (registers)->contents[4] = make_number (outregs.x.si); | |
89 | XVECTOR (registers)->contents[5] = make_number (outregs.x.di); | |
90 | XVECTOR (registers)->contents[6] = make_number (outregs.x.cflag); | |
91 | XVECTOR (registers)->contents[7] = make_number (outregs.x.flags); | |
1b94449f | 92 | |
e20104ba | 93 | return registers; |
1b94449f RS |
94 | } |
95 | ||
5f08dc78 | 96 | DEFUN ("msdos-memget", Fdos_memget, Sdos_memget, 2, 2, 0, |
7363986a PJ |
97 | doc: /* Read DOS memory at offset ADDRESS into VECTOR. |
98 | Return the updated VECTOR. */) | |
5842a27b | 99 | (Lisp_Object address, Lisp_Object vector) |
5f08dc78 KS |
100 | { |
101 | register int i; | |
102 | int offs, len; | |
103 | char *buf; | |
104 | Lisp_Object val; | |
105 | ||
b7826503 | 106 | CHECK_NUMBER (address); |
e20104ba | 107 | offs = (unsigned long) XINT (address); |
b7826503 | 108 | CHECK_VECTOR (vector); |
e20104ba | 109 | len = XVECTOR (vector)-> size; |
238a44a8 | 110 | if (len < 1 || len > 2048 || offs < 0 || offs > 0xfffff - len) |
5f08dc78 KS |
111 | return Qnil; |
112 | buf = alloca (len); | |
113 | dosmemget (offs, len, buf); | |
b058cb36 | 114 | |
5f08dc78 | 115 | for (i = 0; i < len; i++) |
e20104ba | 116 | XVECTOR (vector)->contents[i] = make_number (buf[i]); |
5f08dc78 | 117 | |
e20104ba | 118 | return vector; |
5f08dc78 KS |
119 | } |
120 | ||
121 | DEFUN ("msdos-memput", Fdos_memput, Sdos_memput, 2, 2, 0, | |
7363986a | 122 | doc: /* Write DOS memory at offset ADDRESS from VECTOR. */) |
5842a27b | 123 | (Lisp_Object address, Lisp_Object vector) |
5f08dc78 KS |
124 | { |
125 | register int i; | |
126 | int offs, len; | |
127 | char *buf; | |
128 | Lisp_Object val; | |
129 | ||
b7826503 | 130 | CHECK_NUMBER (address); |
e20104ba | 131 | offs = (unsigned long) XINT (address); |
b7826503 | 132 | CHECK_VECTOR (vector); |
e20104ba | 133 | len = XVECTOR (vector)-> size; |
238a44a8 | 134 | if (len < 1 || len > 2048 || offs < 0 || offs > 0xfffff - len) |
5f08dc78 KS |
135 | return Qnil; |
136 | buf = alloca (len); | |
137 | ||
138 | for (i = 0; i < len; i++) | |
139 | { | |
b7826503 | 140 | CHECK_NUMBER (XVECTOR (vector)->contents[i]); |
e20104ba | 141 | buf[i] = (unsigned char) XFASTINT (XVECTOR (vector)->contents[i]) & 0xFF; |
5f08dc78 KS |
142 | } |
143 | ||
144 | dosmemput (buf, len, offs); | |
145 | return Qt; | |
146 | } | |
147 | ||
148 | DEFUN ("msdos-set-keyboard", Fmsdos_set_keyboard, Smsdos_set_keyboard, 1, 2, 0, | |
7363986a PJ |
149 | doc: /* Set keyboard layout according to COUNTRY-CODE. |
150 | If the optional argument ALLKEYS is non-nil, the keyboard is mapped for | |
151 | all keys; otherwise it is only used when the ALT key is pressed. | |
152 | The current keyboard layout is available in dos-keyboard-code. */) | |
5842a27b | 153 | (Lisp_Object country_code, Lisp_Object allkeys) |
5f08dc78 | 154 | { |
b7826503 | 155 | CHECK_NUMBER (country_code); |
5f08dc78 KS |
156 | if (!dos_set_keyboard (XINT (country_code), !NILP (allkeys))) |
157 | return Qnil; | |
158 | return Qt; | |
159 | } | |
160 | ||
87485d6f MW |
161 | #ifndef HAVE_X_WINDOWS |
162 | /* Later we might want to control the mouse interface with this function, | |
163 | e.g., with respect to non-80 column screen modes. */ | |
164 | ||
7363986a PJ |
165 | DEFUN ("msdos-mouse-p", Fmsdos_mouse_p, Smsdos_mouse_p, 0, 0, 0, |
166 | doc: /* Report whether a mouse is present. */) | |
5842a27b | 167 | (void) |
87485d6f MW |
168 | { |
169 | if (have_mouse) | |
170 | return Qt; | |
171 | else | |
172 | return Qnil; | |
173 | } | |
87485d6f MW |
174 | #endif |
175 | ||
ac3b0279 | 176 | DEFUN ("msdos-mouse-init", Fmsdos_mouse_init, Smsdos_mouse_init, 0, 0, "", |
7363986a | 177 | doc: /* Initialize and enable mouse if available. */) |
5842a27b | 178 | (void) |
ac3b0279 | 179 | { |
5f08dc78 KS |
180 | if (have_mouse) |
181 | { | |
182 | have_mouse = 1; | |
183 | mouse_init (); | |
184 | return Qt; | |
185 | } | |
ac3b0279 RS |
186 | return Qnil; |
187 | } | |
188 | ||
189 | DEFUN ("msdos-mouse-enable", Fmsdos_mouse_enable, Smsdos_mouse_enable, 0, 0, "", | |
7363986a | 190 | doc: /* Enable mouse if available. */) |
5842a27b | 191 | (void) |
ac3b0279 RS |
192 | { |
193 | if (have_mouse) | |
194 | { | |
5f08dc78 KS |
195 | have_mouse = 1; |
196 | mouse_on (); | |
ac3b0279 RS |
197 | } |
198 | return have_mouse ? Qt : Qnil; | |
199 | } | |
200 | ||
201 | DEFUN ("msdos-mouse-disable", Fmsdos_mouse_disable, Smsdos_mouse_disable, 0, 0, "", | |
7363986a | 202 | doc: /* Disable mouse if available. */) |
5842a27b | 203 | (void) |
ac3b0279 RS |
204 | { |
205 | mouse_off (); | |
206 | if (have_mouse) have_mouse = -1; | |
207 | return Qnil; | |
208 | } | |
209 | ||
7363986a | 210 | DEFUN ("insert-startup-screen", Finsert_startup_screen, Sinsert_startup_screen, 0, 0, "", |
cd53fb50 | 211 | doc: /* Insert copy of screen contents prior to starting Emacs. |
7363986a | 212 | Return nil if startup screen is not available. */) |
5842a27b | 213 | (void) |
5f08dc78 KS |
214 | { |
215 | char *s; | |
b058cb36 EZ |
216 | int rows, cols, i, j; |
217 | ||
5f08dc78 KS |
218 | if (!dos_get_saved_screen (&s, &rows, &cols)) |
219 | return Qnil; | |
b058cb36 | 220 | |
5f08dc78 KS |
221 | for (i = 0; i < rows; i++) |
222 | { | |
223 | for (j = 0; j < cols; j++) | |
224 | { | |
65788bc2 | 225 | insert_char (*s); |
5f08dc78 KS |
226 | s += 2; |
227 | } | |
65788bc2 | 228 | insert_char ('\n'); |
5f08dc78 KS |
229 | } |
230 | ||
231 | return Qt; | |
232 | } | |
87485d6f | 233 | \f |
5f08dc78 | 234 | /* country info */ |
31ade731 SM |
235 | EMACS_INT dos_country_code; |
236 | EMACS_INT dos_codepage; | |
237 | EMACS_INT dos_timezone_offset; | |
238 | EMACS_INT dos_decimal_point; | |
239 | EMACS_INT dos_keyboard_layout; | |
5f08dc78 | 240 | unsigned char dos_country_info[DOS_COUNTRY_INFO]; |
e089dc62 RS |
241 | static unsigned char usa_country_info[DOS_COUNTRY_INFO] = { |
242 | 0, 0, /* date format */ | |
243 | '$', 0, 0, 0, 0, /* currency string */ | |
244 | ',', 0, /* thousands separator */ | |
245 | '.', 0, /* decimal separator */ | |
246 | '/', 0, /* date separator */ | |
247 | ':', 0, /* time separator */ | |
248 | 0, /* currency format */ | |
249 | 2, /* digits after decimal in currency */ | |
250 | 0, /* time format */ | |
251 | 0, 0, 0, 0, /* address of case map routine, GPF if used */ | |
252 | ' ', 0, /* data-list separator (?) */ | |
253 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* reserved */ | |
254 | }; | |
5f08dc78 | 255 | |
31ade731 SM |
256 | EMACS_INT dos_hyper_key; |
257 | EMACS_INT dos_super_key; | |
258 | EMACS_INT dos_keypad_mode; | |
1b94449f | 259 | |
5f08dc78 KS |
260 | Lisp_Object Vdos_version; |
261 | Lisp_Object Vdos_display_scancodes; | |
838a94b8 EZ |
262 | |
263 | #ifndef HAVE_X_WINDOWS | |
264 | static unsigned dos_windows_version; | |
265 | Lisp_Object Vdos_windows_version; | |
266 | ||
267 | char parent_vm_title[50]; /* Ralf Brown says 30 is enough */ | |
268 | int w95_set_virtual_machine_title (const char *); | |
269 | ||
270 | void | |
271 | restore_parent_vm_title (void) | |
272 | { | |
273 | if (NILP (Vdos_windows_version)) | |
274 | return; | |
275 | if ((dos_windows_version & 0xff) >= 4 && parent_vm_title[0]) | |
276 | w95_set_virtual_machine_title (parent_vm_title); | |
277 | delay (50); | |
278 | } | |
279 | #endif /* !HAVE_X_WINDOWS */ | |
b058cb36 | 280 | |
1b94449f | 281 | void |
3a8ce822 | 282 | init_dosfns (void) |
1b94449f RS |
283 | { |
284 | union REGS regs; | |
1b94449f | 285 | _go32_dpmi_registers dpmiregs; |
e089dc62 | 286 | unsigned long xbuf = _go32_info_block.linear_address_of_transfer_buffer; |
1b94449f | 287 | |
87485d6f | 288 | #ifndef SYSTEM_MALLOC |
1b94449f | 289 | get_lim_data (); /* why the hell isn't this called elsewhere? */ |
87485d6f | 290 | #endif |
1b94449f RS |
291 | |
292 | regs.x.ax = 0x3000; | |
293 | intdos (®s, ®s); | |
294 | Vdos_version = Fcons (make_number (regs.h.al), make_number (regs.h.ah)); | |
295 | ||
e089dc62 RS |
296 | /* Obtain the country code via DPMI, use DJGPP transfer buffer. */ |
297 | dpmiregs.x.ax = 0x3800; | |
7a2fd369 | 298 | dpmiregs.x.ds = xbuf >> 4; |
e089dc62 RS |
299 | dpmiregs.x.dx = 0; |
300 | dpmiregs.x.ss = dpmiregs.x.sp = dpmiregs.x.flags = 0; | |
301 | _go32_dpmi_simulate_int (0x21, &dpmiregs); | |
302 | if (dpmiregs.x.flags & 1) | |
303 | { | |
304 | dos_country_code = 1; /* assume USA if 213800 failed */ | |
305 | memcpy (dos_country_info, usa_country_info, DOS_COUNTRY_INFO); | |
306 | } | |
1b94449f RS |
307 | else |
308 | { | |
1b94449f | 309 | dos_country_code = dpmiregs.x.bx; |
e089dc62 | 310 | dosmemget (xbuf, DOS_COUNTRY_INFO, dos_country_info); |
1b94449f | 311 | } |
e089dc62 | 312 | |
5f08dc78 | 313 | dos_set_keyboard (dos_country_code, 0); |
1b94449f RS |
314 | |
315 | regs.x.ax = 0x6601; | |
316 | intdos (®s, ®s); | |
317 | if (regs.x.cflag) | |
318 | /* Estimate code page from country code */ | |
b058cb36 | 319 | switch (dos_country_code) |
1b94449f RS |
320 | { |
321 | case 45: /* Denmark */ | |
322 | case 47: /* Norway */ | |
323 | dos_codepage = 865; | |
324 | break; | |
325 | default: | |
326 | /* US */ | |
327 | dos_codepage = 437; | |
328 | } | |
329 | else | |
330 | dos_codepage = regs.x.bx & 0xffff; | |
50666766 | 331 | |
838a94b8 EZ |
332 | #ifndef HAVE_X_WINDOWS |
333 | parent_vm_title[0] = '\0'; | |
334 | ||
335 | /* If we are running from DOS box on MS-Windows, get Windows version. */ | |
336 | dpmiregs.x.ax = 0x1600; /* enhanced mode installation check */ | |
337 | dpmiregs.x.ss = dpmiregs.x.sp = dpmiregs.x.flags = 0; | |
338 | _go32_dpmi_simulate_int (0x2f, &dpmiregs); | |
339 | /* We only support Windows-specific features when we run on Windows 9X | |
340 | or on Windows 3.X/enhanced mode. | |
341 | ||
342 | Int 2Fh/AX=1600h returns: | |
343 | ||
344 | AL = 00: no Windows at all; | |
345 | AL = 01: Windows/386 2.x; | |
346 | AL = 80h: Windows 3.x in mode other than enhanced; | |
347 | AL = FFh: Windows/386 2.x | |
348 | ||
349 | We also check AH > 0 (Windows 3.1 or later), in case AL tricks us. */ | |
350 | if (dpmiregs.h.al > 2 && dpmiregs.h.al != 0x80 && dpmiregs.h.al != 0xff | |
351 | && (dpmiregs.h.al > 3 || dpmiregs.h.ah > 0)) | |
352 | { | |
353 | dos_windows_version = dpmiregs.x.ax; | |
354 | Vdos_windows_version = | |
355 | Fcons (make_number (dpmiregs.h.al), make_number (dpmiregs.h.ah)); | |
356 | ||
357 | /* Save the current title of this virtual machine, so we can restore | |
358 | it before exiting. Otherwise, Windows 95 will continue to use | |
359 | the title we set even after we are history, stupido... */ | |
360 | if (dpmiregs.h.al >= 4) | |
361 | { | |
362 | dpmiregs.x.ax = 0x168e; | |
363 | dpmiregs.x.dx = 3; /* get VM title */ | |
364 | dpmiregs.x.cx = sizeof(parent_vm_title) - 1; | |
365 | dpmiregs.x.es = __tb >> 4; | |
366 | dpmiregs.x.di = __tb & 15; | |
367 | dpmiregs.x.sp = dpmiregs.x.ss = dpmiregs.x.flags = 0; | |
368 | _go32_dpmi_simulate_int (0x2f, &dpmiregs); | |
369 | if (dpmiregs.x.ax == 1) | |
370 | dosmemget (__tb, sizeof(parent_vm_title), parent_vm_title); | |
371 | } | |
372 | } | |
373 | else | |
374 | { | |
375 | dos_windows_version = 0; | |
376 | Vdos_windows_version = Qnil; | |
377 | } | |
378 | #endif /* !HAVE_X_WINDOWS */ | |
379 | ||
459f4042 RS |
380 | /* Without this, we never see hidden files. |
381 | Don't OR it with the previous value, so the value recorded at dump | |
382 | time, possibly with `preserve-case' flags set, won't get through. */ | |
383 | __opendir_flags = __OPENDIR_FIND_HIDDEN; | |
384 | ||
385 | #if __DJGPP_MINOR__ == 0 | |
386 | /* Under LFN, preserve the case of files as recorded in the directory | |
387 | (in DJGPP 2.01 and later this is automagically done by the library). */ | |
50666766 RS |
388 | if (!NILP (Fmsdos_long_file_names ())) |
389 | __opendir_flags |= __OPENDIR_PRESERVE_CASE; | |
459f4042 | 390 | #endif /* __DJGPP_MINOR__ == 0 */ |
1b94449f RS |
391 | } |
392 | \f | |
838a94b8 | 393 | #ifndef HAVE_X_WINDOWS |
e4441df0 EZ |
394 | |
395 | /* Emulation of some X window features from xfns.c and xfaces.c. */ | |
396 | ||
397 | /* Standard VGA colors, in the order of their standard numbering | |
398 | in the default VGA palette. */ | |
399 | static char *vga_colors[16] = { | |
400 | "black", "blue", "green", "cyan", "red", "magenta", "brown", | |
401 | "lightgray", "darkgray", "lightblue", "lightgreen", "lightcyan", | |
402 | "lightred", "lightmagenta", "yellow", "white" | |
403 | }; | |
404 | ||
405 | /* Given a color name, return its index, or -1 if not found. Note | |
406 | that this only performs case-insensitive comparison against the | |
407 | standard names. For anything more sophisticated, like matching | |
408 | "gray" with "grey" or translating X color names into their MSDOS | |
2d764c78 EZ |
409 | equivalents, call the Lisp function Qtty_color_desc (defined |
410 | on lisp/term/tty-colors.el). */ | |
e4441df0 EZ |
411 | int |
412 | msdos_stdcolor_idx (const char *name) | |
413 | { | |
414 | int i; | |
415 | ||
416 | for (i = 0; i < sizeof (vga_colors) / sizeof (vga_colors[0]); i++) | |
05131107 | 417 | if (xstrcasecmp (name, vga_colors[i]) == 0) |
e4441df0 EZ |
418 | return i; |
419 | ||
f9d2fdc4 | 420 | return |
24480d5b EZ |
421 | strcmp (name, unspecified_fg) == 0 ? FACE_TTY_DEFAULT_FG_COLOR |
422 | : strcmp (name, unspecified_bg) == 0 ? FACE_TTY_DEFAULT_BG_COLOR | |
f9d2fdc4 | 423 | : FACE_TTY_DEFAULT_COLOR; |
e4441df0 EZ |
424 | } |
425 | ||
426 | /* Given a color index, return its standard name. */ | |
2d764c78 | 427 | Lisp_Object |
e4441df0 EZ |
428 | msdos_stdcolor_name (int idx) |
429 | { | |
24480d5b EZ |
430 | extern Lisp_Object Qunspecified; |
431 | ||
432 | if (idx == FACE_TTY_DEFAULT_FG_COLOR) | |
433 | return build_string (unspecified_fg); | |
434 | else if (idx == FACE_TTY_DEFAULT_BG_COLOR) | |
435 | return build_string (unspecified_bg); | |
436 | else if (idx >= 0 && idx < sizeof (vga_colors) / sizeof (vga_colors[0])) | |
437 | return build_string (vga_colors[idx]); | |
438 | else | |
439 | return Qunspecified; /* meaning the default */ | |
e4441df0 EZ |
440 | } |
441 | ||
838a94b8 EZ |
442 | /* Support for features that are available when we run in a DOS box |
443 | on MS-Windows. */ | |
444 | int | |
445 | ms_windows_version (void) | |
446 | { | |
447 | return dos_windows_version; | |
448 | } | |
449 | ||
450 | /* Set the title of the current virtual machine, to appear on | |
451 | the caption bar of that machine's window. */ | |
452 | ||
453 | int | |
454 | w95_set_virtual_machine_title (const char *title_string) | |
455 | { | |
456 | /* Only Windows 9X (version 4 and higher) support this function. */ | |
457 | if (!NILP (Vdos_windows_version) | |
458 | && (dos_windows_version & 0xff) >= 4) | |
459 | { | |
460 | _go32_dpmi_registers regs; | |
461 | dosmemput (title_string, strlen (title_string) + 1, __tb); | |
462 | regs.x.ax = 0x168e; | |
463 | regs.x.dx = 1; | |
464 | regs.x.es = __tb >> 4; | |
465 | regs.x.di = __tb & 15; | |
466 | regs.x.sp = regs.x.ss = regs.x.flags = 0; | |
467 | _go32_dpmi_simulate_int (0x2f, ®s); | |
468 | return regs.x.ax == 1; | |
469 | } | |
470 | return 0; | |
471 | } | |
472 | ||
473 | /* Change the title of frame F to NAME. | |
474 | If NAME is nil, use the frame name as the title. | |
475 | ||
476 | If Emacs is not run from a DOS box on Windows 9X, this only | |
477 | sets the name in the frame struct, but has no other effects. */ | |
478 | ||
479 | void | |
3a8ce822 | 480 | x_set_title (struct frame *f, Lisp_Object name) |
838a94b8 EZ |
481 | { |
482 | /* Don't change the title if it's already NAME. */ | |
483 | if (EQ (name, f->title)) | |
484 | return; | |
485 | ||
486 | update_mode_lines = 1; | |
487 | ||
488 | f->title = name; | |
489 | ||
490 | if (NILP (name)) | |
491 | name = f->name; | |
492 | ||
493 | if (FRAME_MSDOS_P (f)) | |
494 | { | |
495 | BLOCK_INPUT; | |
d5db4077 | 496 | w95_set_virtual_machine_title (SDATA (name)); |
838a94b8 EZ |
497 | UNBLOCK_INPUT; |
498 | } | |
499 | } | |
500 | #endif /* !HAVE_X_WINDOWS */ | |
501 | \f | |
76a76a57 | 502 | DEFUN ("file-system-info", Ffile_system_info, Sfile_system_info, 1, 1, 0, |
7363986a PJ |
503 | doc: /* Return storage information about the file system FILENAME is on. |
504 | Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total | |
505 | storage of the file system, FREE is the free storage, and AVAIL is the | |
506 | storage available to a non-superuser. All 3 numbers are in bytes. | |
507 | If the underlying system call fails, value is nil. */) | |
5842a27b | 508 | (Lisp_Object filename) |
76a76a57 EZ |
509 | { |
510 | struct statfs stfs; | |
511 | Lisp_Object encoded, value; | |
512 | ||
b7826503 | 513 | CHECK_STRING (filename); |
76a76a57 EZ |
514 | filename = Fexpand_file_name (filename, Qnil); |
515 | encoded = ENCODE_FILE (filename); | |
516 | ||
d5db4077 | 517 | if (statfs (SDATA (encoded), &stfs)) |
76a76a57 EZ |
518 | value = Qnil; |
519 | else | |
520 | value = list3 (make_float ((double) stfs.f_bsize * stfs.f_blocks), | |
521 | make_float ((double) stfs.f_bsize * stfs.f_bfree), | |
522 | make_float ((double) stfs.f_bsize * stfs.f_bavail)); | |
523 | ||
524 | return value; | |
525 | } | |
526 | \f | |
e5c9f94c EZ |
527 | /* System depended enumeration of and access to system processes a-la |
528 | ps(1). Here, we only return info about the running Emacs process. | |
529 | (There are no other processes on DOS, right?) */ | |
530 | ||
531 | Lisp_Object | |
3a8ce822 | 532 | list_system_processes (void) |
e5c9f94c EZ |
533 | { |
534 | Lisp_Object proclist = Qnil; | |
535 | ||
536 | proclist = Fcons (make_fixnum_or_float (getpid ()), proclist); | |
537 | ||
538 | return proclist; | |
539 | } | |
540 | ||
541 | Lisp_Object | |
542 | system_process_attributes (Lisp_Object pid) | |
543 | { | |
544 | int proc_id; | |
545 | Lisp_Object attrs = Qnil; | |
546 | ||
547 | CHECK_NUMBER_OR_FLOAT (pid); | |
548 | proc_id = FLOATP (pid) ? XFLOAT_DATA (pid) : XINT (pid); | |
549 | ||
550 | if (proc_id == getpid ()) | |
551 | { | |
552 | EMACS_INT uid, gid; | |
553 | char *usr; | |
554 | struct group *gr; | |
555 | char cmd[FILENAME_MAX]; | |
556 | char *cmdline = NULL, *p, *q; | |
557 | size_t cmdline_size = 0; | |
558 | int i; | |
559 | Lisp_Object cmd_str, decoded_cmd, tem; | |
560 | double pmem; | |
693a2698 | 561 | #ifndef SYSTEM_MALLOC |
e5c9f94c | 562 | extern unsigned long ret_lim_data (); |
693a2698 | 563 | #endif |
e5c9f94c EZ |
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); | |
693a2698 EZ |
596 | #ifndef SYSTEM_MALLOC |
597 | /* ret_lim_data is on vm-limit.c, which is not compiled in under | |
598 | SYSTEM_MALLOC. */ | |
e5c9f94c EZ |
599 | pmem = (double)((unsigned long) sbrk (0)) / ret_lim_data () * 100.0; |
600 | if (pmem > 100) | |
693a2698 | 601 | #endif |
e5c9f94c EZ |
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 | |
838a94b8 EZ |
655 | void |
656 | dos_cleanup (void) | |
657 | { | |
c06981c0 EZ |
658 | struct tty_display_info *tty; |
659 | ||
838a94b8 EZ |
660 | #ifndef HAVE_X_WINDOWS |
661 | restore_parent_vm_title (); | |
662 | #endif | |
6f855d64 EZ |
663 | /* Make sure the termscript file is committed, in case we are |
664 | crashing and some vital info was written there. */ | |
c06981c0 | 665 | if (FRAMEP (selected_frame)) |
6f855d64 | 666 | { |
c06981c0 EZ |
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 | } | |
6f855d64 | 679 | } |
838a94b8 EZ |
680 | } |
681 | ||
1b94449f RS |
682 | /* |
683 | * Define everything | |
684 | */ | |
3a8ce822 EZ |
685 | void |
686 | syms_of_dosfns (void) | |
1b94449f | 687 | { |
1b94449f | 688 | defsubr (&Sint86); |
5f08dc78 KS |
689 | defsubr (&Sdos_memget); |
690 | defsubr (&Sdos_memput); | |
ac3b0279 RS |
691 | defsubr (&Smsdos_mouse_init); |
692 | defsubr (&Smsdos_mouse_enable); | |
5f08dc78 KS |
693 | defsubr (&Smsdos_set_keyboard); |
694 | defsubr (&Sinsert_startup_screen); | |
ac3b0279 | 695 | defsubr (&Smsdos_mouse_disable); |
76a76a57 | 696 | defsubr (&Sfile_system_info); |
87485d6f MW |
697 | #ifndef HAVE_X_WINDOWS |
698 | defsubr (&Smsdos_mouse_p); | |
87485d6f | 699 | #endif |
1b94449f RS |
700 | |
701 | DEFVAR_INT ("dos-country-code", &dos_country_code, | |
7363986a PJ |
702 | doc: /* The country code returned by Dos when Emacs was started. |
703 | Usually this is the international telephone prefix. */); | |
1b94449f RS |
704 | |
705 | DEFVAR_INT ("dos-codepage", &dos_codepage, | |
7363986a PJ |
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 */); | |
1b94449f | 716 | |
5f08dc78 | 717 | DEFVAR_INT ("dos-timezone-offset", &dos_timezone_offset, |
7363986a PJ |
718 | doc: /* The current timezone offset to UTC in minutes. |
719 | Implicitly modified when the TZ variable is changed. */); | |
b058cb36 | 720 | |
1b94449f | 721 | DEFVAR_LISP ("dos-version", &Vdos_version, |
7363986a | 722 | doc: /* The (MAJOR . MINOR) Dos version (subject to modification with setver). */); |
5f08dc78 | 723 | |
838a94b8 EZ |
724 | #ifndef HAVE_X_WINDOWS |
725 | DEFVAR_LISP ("dos-windows-version", &Vdos_windows_version, | |
7363986a | 726 | doc: /* The (MAJOR . MINOR) Windows version for DOS session on MS-Windows. */); |
838a94b8 EZ |
727 | #endif |
728 | ||
5f08dc78 | 729 | DEFVAR_LISP ("dos-display-scancodes", &Vdos_display_scancodes, |
7363986a PJ |
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 | ||
5f08dc78 | 735 | Vdos_display_scancodes = Qnil; |
b058cb36 | 736 | |
5f08dc78 | 737 | DEFVAR_INT ("dos-hyper-key", &dos_hyper_key, |
7363986a PJ |
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. */); | |
5f08dc78 | 740 | dos_hyper_key = 0; |
b058cb36 | 741 | |
5f08dc78 | 742 | DEFVAR_INT ("dos-super-key", &dos_super_key, |
7363986a PJ |
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. */); | |
5f08dc78 | 745 | dos_super_key = 0; |
b058cb36 | 746 | |
5f08dc78 | 747 | DEFVAR_INT ("dos-keypad-mode", &dos_keypad_mode, |
7363986a PJ |
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. */); | |
b3d5621c | 769 | dos_keypad_mode = 0x75; |
b058cb36 | 770 | |
5f08dc78 | 771 | DEFVAR_INT ("dos-keyboard-layout", &dos_keyboard_layout, |
7363986a PJ |
772 | doc: /* Contains the country code for the current keyboard layout. |
773 | Use msdos-set-keyboard to select another keyboard layout. */); | |
5f08dc78 | 774 | dos_keyboard_layout = 1; /* US */ |
b058cb36 | 775 | |
5f08dc78 | 776 | DEFVAR_INT ("dos-decimal-point", &dos_decimal_point, |
7363986a PJ |
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. */); | |
5f08dc78 | 781 | dos_decimal_point = 0; |
1b94449f RS |
782 | } |
783 | #endif /* MSDOS */ | |
6b61353c KH |
784 | |
785 | /* arch-tag: f5ea8847-a014-42c9-83f5-7738ad640b17 | |
786 | (do not change this comment) */ |