This source file includes following definitions.
- DEFUN
- DEFUN
- DEFUN
- DEFUN
- DEFUN
- restore_parent_vm_title
- init_dosfns
- msdos_stdcolor_idx
- msdos_stdcolor_name
- ms_windows_version
- w95_set_virtual_machine_title
- x_set_title
- DEFUN
- list_system_processes
- system_process_attributes
- dos_memory_info
- dos_cleanup
- syms_of_dosfns
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include <config.h>
22
23 #ifdef MSDOS
24
25
26 #include <stdio.h>
27
28
29 #define gettime dos_h_gettime_
30 #define settime dos_h_settime_
31 #include <dos.h>
32 #undef gettime
33 #undef settime
34
35 #include "lisp.h"
36 #include "character.h"
37 #include "buffer.h"
38 #include "termchar.h"
39 #include "frame.h"
40 #include "termhooks.h"
41 #include "blockinput.h"
42 #include "window.h"
43 #include "dosfns.h"
44 #include "msdos.h"
45 #include "dispextern.h"
46 #include "coding.h"
47 #include "process.h"
48 #include <dpmi.h>
49 #include <go32.h>
50 #include <dirent.h>
51 #include <sys/vfs.h>
52 #include <unistd.h>
53 #include <grp.h>
54 #include <crt0.h>
55
56 DEFUN ("int86", Fint86, Sint86, 2, 2, 0,
57 doc:
58
59
60
61
62 )
63 (Lisp_Object interrupt, Lisp_Object registers)
64 {
65 register int i;
66 int no;
67 union REGS inregs, outregs;
68
69 CHECK_FIXNUM (interrupt);
70 no = (unsigned long) XFIXNUM (interrupt);
71 CHECK_VECTOR (registers);
72 if (no < 0 || no > 0xff || ASIZE (registers) != 8)
73 return Qnil;
74 for (i = 0; i < 8; i++)
75 CHECK_FIXNUM (AREF (registers, i));
76
77 inregs.x.ax = (unsigned long) XFIXNUM (AREF (registers, 0));
78 inregs.x.bx = (unsigned long) XFIXNUM (AREF (registers, 1));
79 inregs.x.cx = (unsigned long) XFIXNUM (AREF (registers, 2));
80 inregs.x.dx = (unsigned long) XFIXNUM (AREF (registers, 3));
81 inregs.x.si = (unsigned long) XFIXNUM (AREF (registers, 4));
82 inregs.x.di = (unsigned long) XFIXNUM (AREF (registers, 5));
83 inregs.x.cflag = (unsigned long) XFIXNUM (AREF (registers, 6));
84 inregs.x.flags = (unsigned long) XFIXNUM (AREF (registers, 7));
85
86 int86 (no, &inregs, &outregs);
87
88 ASET (registers, 0, make_fixnum (outregs.x.ax));
89 ASET (registers, 1, make_fixnum (outregs.x.bx));
90 ASET (registers, 2, make_fixnum (outregs.x.cx));
91 ASET (registers, 3, make_fixnum (outregs.x.dx));
92 ASET (registers, 4, make_fixnum (outregs.x.si));
93 ASET (registers, 5, make_fixnum (outregs.x.di));
94 ASET (registers, 6, make_fixnum (outregs.x.cflag));
95 ASET (registers, 7, make_fixnum (outregs.x.flags));
96
97 return registers;
98 }
99
100 DEFUN ("msdos-memget", Fdos_memget, Sdos_memget, 2, 2, 0,
101 doc:
102 )
103 (Lisp_Object address, Lisp_Object vector)
104 {
105 register int i;
106 int offs, len;
107 char *buf;
108
109 CHECK_FIXNUM (address);
110 offs = (unsigned long) XFIXNUM (address);
111 CHECK_VECTOR (vector);
112 len = ASIZE (vector);
113 if (len < 1 || len > 2048 || offs < 0 || offs > 0xfffff - len)
114 return Qnil;
115 buf = alloca (len);
116 dosmemget (offs, len, buf);
117
118 for (i = 0; i < len; i++)
119 ASET (vector, i, make_fixnum (buf[i]));
120
121 return vector;
122 }
123
124 DEFUN ("msdos-memput", Fdos_memput, Sdos_memput, 2, 2, 0,
125 doc: )
126 (Lisp_Object address, Lisp_Object vector)
127 {
128 register int i;
129 int offs, len;
130 char *buf;
131
132 CHECK_FIXNUM (address);
133 offs = (unsigned long) XFIXNUM (address);
134 CHECK_VECTOR (vector);
135 len = ASIZE (vector);
136 if (len < 1 || len > 2048 || offs < 0 || offs > 0xfffff - len)
137 return Qnil;
138 buf = alloca (len);
139
140 for (i = 0; i < len; i++)
141 {
142 CHECK_FIXNUM (AREF (vector, i));
143 buf[i] = (unsigned char) XFIXNUM (AREF (vector, i)) & 0xFF;
144 }
145
146 dosmemput (buf, len, offs);
147 return Qt;
148 }
149
150 DEFUN ("msdos-set-keyboard", Fmsdos_set_keyboard, Smsdos_set_keyboard, 1, 2, 0,
151 doc:
152
153
154 )
155 (Lisp_Object country_code, Lisp_Object allkeys)
156 {
157 CHECK_FIXNUM (country_code);
158 if (!dos_set_keyboard (XFIXNUM (country_code), !NILP (allkeys)))
159 return Qnil;
160 return Qt;
161 }
162
163 #ifndef HAVE_X_WINDOWS
164
165
166
167 DEFUN ("msdos-mouse-p", Fmsdos_mouse_p, Smsdos_mouse_p, 0, 0, 0,
168 doc: )
169 (void)
170 {
171 if (have_mouse)
172 return Qt;
173 else
174 return Qnil;
175 }
176 #endif
177
178 DEFUN ("msdos-mouse-init", Fmsdos_mouse_init, Smsdos_mouse_init, 0, 0, "",
179 doc: )
180 (void)
181 {
182 if (have_mouse)
183 {
184 have_mouse = 1;
185 mouse_init ();
186 return Qt;
187 }
188 return Qnil;
189 }
190
191 DEFUN ("msdos-mouse-enable", Fmsdos_mouse_enable, Smsdos_mouse_enable, 0, 0, "",
192 doc: )
193 (void)
194 {
195 if (have_mouse)
196 {
197 have_mouse = 1;
198 mouse_on ();
199 }
200 return have_mouse ? Qt : Qnil;
201 }
202
203 DEFUN ("msdos-mouse-disable", Fmsdos_mouse_disable, Smsdos_mouse_disable, 0, 0, "",
204 doc: )
205 (void)
206 {
207 mouse_off ();
208 if (have_mouse) have_mouse = -1;
209 return Qnil;
210 }
211
212 DEFUN ("insert-startup-screen", Finsert_startup_screen, Sinsert_startup_screen, 0, 0, "",
213 doc:
214 )
215 (void)
216 {
217 char *s;
218 int rows, cols, i, j;
219
220 if (!dos_get_saved_screen (&s, &rows, &cols))
221 return Qnil;
222
223 for (i = 0; i < rows; i++)
224 {
225 for (j = 0; j < cols; j++)
226 {
227 insert_char (*s);
228 s += 2;
229 }
230 insert_char ('\n');
231 }
232
233 return Qt;
234 }
235
236 unsigned char dos_country_info[DOS_COUNTRY_INFO];
237 static unsigned char usa_country_info[DOS_COUNTRY_INFO] = {
238 0, 0,
239 '$', 0, 0, 0, 0,
240 ',', 0,
241 '.', 0,
242 '/', 0,
243 ':', 0,
244 0,
245 2,
246 0,
247 0, 0, 0, 0,
248 ' ', 0,
249 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
250 };
251
252 #ifndef HAVE_X_WINDOWS
253 static unsigned dos_windows_version;
254 char parent_vm_title[50];
255 int w95_set_virtual_machine_title (const char *);
256
257 void
258 restore_parent_vm_title (void)
259 {
260 if (NILP (Vdos_windows_version))
261 return;
262 if ((dos_windows_version & 0xff) >= 4 && parent_vm_title[0])
263 w95_set_virtual_machine_title (parent_vm_title);
264 delay (50);
265 }
266 #endif
267
268 void
269 init_dosfns (void)
270 {
271 union REGS regs;
272 _go32_dpmi_registers dpmiregs;
273 unsigned long xbuf = _go32_info_block.linear_address_of_transfer_buffer;
274
275 #ifndef SYSTEM_MALLOC
276 extern void get_lim_data (void);
277
278 get_lim_data ();
279 #endif
280
281 regs.x.ax = 0x3000;
282 intdos (®s, ®s);
283 Vdos_version = Fcons (make_fixnum (regs.h.al), make_fixnum (regs.h.ah));
284
285
286 dpmiregs.x.ax = 0x3800;
287 dpmiregs.x.ds = xbuf >> 4;
288 dpmiregs.x.dx = 0;
289 dpmiregs.x.ss = dpmiregs.x.sp = dpmiregs.x.flags = 0;
290 _go32_dpmi_simulate_int (0x21, &dpmiregs);
291 if (dpmiregs.x.flags & 1)
292 {
293 dos_country_code = 1;
294 memcpy (dos_country_info, usa_country_info, DOS_COUNTRY_INFO);
295 }
296 else
297 {
298 dos_country_code = dpmiregs.x.bx;
299 dosmemget (xbuf, DOS_COUNTRY_INFO, dos_country_info);
300 }
301
302 dos_set_keyboard (dos_country_code, 0);
303
304 regs.x.ax = 0x6601;
305 intdos (®s, ®s);
306 if (regs.x.cflag)
307
308 switch (dos_country_code)
309 {
310 case 45:
311 case 47:
312 dos_codepage = 865;
313 break;
314 default:
315
316 dos_codepage = 437;
317 }
318 else
319 dos_codepage = regs.x.bx & 0xffff;
320
321 #ifndef HAVE_X_WINDOWS
322 parent_vm_title[0] = '\0';
323
324
325 dpmiregs.x.ax = 0x1600;
326 dpmiregs.x.ss = dpmiregs.x.sp = dpmiregs.x.flags = 0;
327 _go32_dpmi_simulate_int (0x2f, &dpmiregs);
328
329
330
331
332
333
334
335
336
337
338
339 if (dpmiregs.h.al > 2 && dpmiregs.h.al != 0x80 && dpmiregs.h.al != 0xff
340 && (dpmiregs.h.al > 3 || dpmiregs.h.ah > 0))
341 {
342 dos_windows_version = dpmiregs.x.ax;
343 Vdos_windows_version =
344 Fcons (make_fixnum (dpmiregs.h.al), make_fixnum (dpmiregs.h.ah));
345
346
347
348
349 if (dpmiregs.h.al >= 4)
350 {
351 dpmiregs.x.ax = 0x168e;
352 dpmiregs.x.dx = 3;
353 dpmiregs.x.cx = sizeof (parent_vm_title) - 1;
354 dpmiregs.x.es = __tb >> 4;
355 dpmiregs.x.di = __tb & 15;
356 dpmiregs.x.sp = dpmiregs.x.ss = dpmiregs.x.flags = 0;
357 _go32_dpmi_simulate_int (0x2f, &dpmiregs);
358 if (dpmiregs.x.ax == 1)
359 dosmemget (__tb, sizeof (parent_vm_title), parent_vm_title);
360 }
361 }
362 else
363 {
364 dos_windows_version = 0;
365 Vdos_windows_version = Qnil;
366 }
367 #endif
368
369
370
371
372 __opendir_flags = __OPENDIR_FIND_HIDDEN;
373 }
374
375 #ifndef HAVE_X_WINDOWS
376
377
378
379
380
381 static char *vga_colors[16] = {
382 "black", "blue", "green", "cyan", "red", "magenta", "brown",
383 "lightgray", "darkgray", "lightblue", "lightgreen", "lightcyan",
384 "lightred", "lightmagenta", "yellow", "white"
385 };
386
387
388
389
390
391
392
393 int
394 msdos_stdcolor_idx (const char *name)
395 {
396 int i;
397
398 for (i = 0; i < ARRAYELTS (vga_colors); i++)
399 if (xstrcasecmp (name, vga_colors[i]) == 0)
400 return i;
401
402 return
403 strcmp (name, unspecified_fg) == 0 ? FACE_TTY_DEFAULT_FG_COLOR
404 : strcmp (name, unspecified_bg) == 0 ? FACE_TTY_DEFAULT_BG_COLOR
405 : FACE_TTY_DEFAULT_COLOR;
406 }
407
408
409 Lisp_Object
410 msdos_stdcolor_name (int idx)
411 {
412 if (idx == FACE_TTY_DEFAULT_FG_COLOR)
413 return build_string (unspecified_fg);
414 else if (idx == FACE_TTY_DEFAULT_BG_COLOR)
415 return build_string (unspecified_bg);
416 else if (idx >= 0 && idx < ARRAYELTS (vga_colors))
417 return build_string (vga_colors[idx]);
418 else
419 return Qunspecified;
420 }
421
422
423
424 int
425 ms_windows_version (void)
426 {
427 return dos_windows_version;
428 }
429
430
431
432
433 int
434 w95_set_virtual_machine_title (const char *title_string)
435 {
436
437 if (!NILP (Vdos_windows_version)
438 && (dos_windows_version & 0xff) >= 4)
439 {
440 _go32_dpmi_registers regs;
441 dosmemput (title_string, strlen (title_string) + 1, __tb);
442 regs.x.ax = 0x168e;
443 regs.x.dx = 1;
444 regs.x.es = __tb >> 4;
445 regs.x.di = __tb & 15;
446 regs.x.sp = regs.x.ss = regs.x.flags = 0;
447 _go32_dpmi_simulate_int (0x2f, ®s);
448 return regs.x.ax == 1;
449 }
450 return 0;
451 }
452
453
454
455
456
457
458
459 void
460 x_set_title (struct frame *f, Lisp_Object name)
461 {
462
463 if (EQ (name, f->title))
464 return;
465
466 update_mode_lines = 13;
467
468 fset_title (f, name);
469
470 if (NILP (name))
471 name = f->name;
472
473 if (FRAME_MSDOS_P (f))
474 {
475 block_input ();
476 w95_set_virtual_machine_title (SDATA (name));
477 unblock_input ();
478 }
479 }
480 #endif
481
482 DEFUN ("file-system-info", Ffile_system_info, Sfile_system_info, 1, 1, 0,
483 doc: )
484 (Lisp_Object filename)
485 {
486 struct statfs stfs;
487 Lisp_Object encoded, value;
488
489 CHECK_STRING (filename);
490 filename = Fexpand_file_name (filename, Qnil);
491 encoded = ENCODE_FILE (filename);
492
493 if (statfs (SDATA (encoded), &stfs))
494 value = Qnil;
495 else
496 value = list3 (make_float ((double) stfs.f_bsize * stfs.f_blocks),
497 make_float ((double) stfs.f_bsize * stfs.f_bfree),
498 make_float ((double) stfs.f_bsize * stfs.f_bavail));
499
500 return value;
501 }
502
503
504
505
506
507 Lisp_Object
508 list_system_processes (void)
509 {
510 Lisp_Object proclist = Qnil;
511
512 proclist = Fcons (INT_TO_INTEGER (getpid ()), proclist);
513
514 return proclist;
515 }
516
517 Lisp_Object
518 system_process_attributes (Lisp_Object pid)
519 {
520 int proc_id;
521 Lisp_Object attrs = Qnil;
522
523 CHECK_NUMBER (pid);
524 proc_id = XFLOATINT (pid);
525
526 if (proc_id == getpid ())
527 {
528 EMACS_INT uid, gid;
529 char *usr;
530 struct group *gr;
531 char cmd[FILENAME_MAX];
532 char *cmdline = NULL, *p, *q;
533 size_t cmdline_size = 0;
534 int i;
535 Lisp_Object cmd_str, decoded_cmd, tem;
536 double pmem;
537 #ifndef SYSTEM_MALLOC
538 extern unsigned long ret_lim_data ();
539 #endif
540
541 uid = getuid ();
542 attrs = Fcons (Fcons (Qeuid, INT_TO_INTEGER (uid)), attrs);
543 usr = getlogin ();
544 if (usr)
545 attrs = Fcons (Fcons (Quser, build_string (usr)), attrs);
546 gid = getgid ();
547 attrs = Fcons (Fcons (Qegid, INT_TO_INTEGER (gid)), attrs);
548 gr = getgrgid (gid);
549 if (gr)
550 attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
551 strcpy (cmd, basename (__crt0_argv[0]));
552
553 cmd_str = build_unibyte_string (cmd);
554 decoded_cmd = code_convert_string_norecord (cmd_str,
555 Vlocale_coding_system, 0);
556 attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs);
557
558 attrs = Fcons (Fcons (Qppid, make_fixnum (0)), attrs);
559 attrs = Fcons (Fcons (Qpgrp, pid), attrs);
560 attrs = Fcons (Fcons (Qttname, build_string ("/dev/tty")), attrs);
561
562 tem = Fget_internal_run_time ();
563 attrs = Fcons (Fcons (Qtime, tem), attrs);
564 attrs = Fcons (Fcons (Qthcount, make_fixnum (1)), attrs);
565 attrs = Fcons (Fcons (Qstart,
566 Fsymbol_value (intern ("before-init-time"))),
567 attrs);
568 attrs = Fcons (Fcons (Qvsize,
569 INT_TO_INTEGER ((unsigned long) sbrk (0) / 1024)),
570 attrs);
571 attrs = Fcons (Fcons (Qetime, tem), attrs);
572 #ifndef SYSTEM_MALLOC
573
574
575 pmem = (double)((unsigned long) sbrk (0)) / ret_lim_data () * 100.0;
576 if (pmem > 100)
577 #endif
578 pmem = 100;
579 attrs = Fcons (Fcons (Qpmem, make_float (pmem)), attrs);
580
581 for (i = 0; i < __crt0_argc; i++)
582 {
583 cmdline_size += strlen (__crt0_argv[i]) + 1;
584 if (strpbrk (__crt0_argv[i], " \t\n\r\v\f"))
585 {
586 cmdline_size += 2;
587 for (p = __crt0_argv[i]; *p; p++)
588 {
589 if (*p == '"')
590 cmdline_size++;
591 }
592 }
593 }
594
595 cmdline = xmalloc (cmdline_size + 1);
596 for (i = 0, q = cmdline; i < __crt0_argc; i++)
597 {
598 if (strpbrk (__crt0_argv[i], " \t\n\r\v\f"))
599 {
600 *q++ = '"';
601 for (p = __crt0_argv[i]; *p; p++)
602 {
603 if (*p == '\"')
604 *q++ = '\\';
605 *q++ = *p;
606 }
607 *q++ = '"';
608 }
609 else
610 {
611 strcpy (q, __crt0_argv[i]);
612 q += strlen (__crt0_argv[i]);
613 }
614 *q++ = ' ';
615 }
616
617 if (q > cmdline)
618 q[-1] = '\0';
619
620
621 cmd_str = build_unibyte_string (cmdline);
622 decoded_cmd = code_convert_string_norecord (cmd_str,
623 Vlocale_coding_system, 0);
624 xfree (cmdline);
625 attrs = Fcons (Fcons (Qargs, decoded_cmd), attrs);
626 }
627
628 return attrs;
629 }
630
631
632 int
633 dos_memory_info (unsigned long *totalram, unsigned long *freeram,
634 unsigned long *totalswap, unsigned long *freeswap)
635 {
636 _go32_dpmi_meminfo info;
637 unsigned long mem1, mem2, freemem;
638
639 _go32_dpmi_get_free_memory_information (&info);
640
641
642
643
644 mem1 = info.available_memory;
645 mem2 = info.available_physical_pages;
646
647 if ((long)mem1 == -1L)
648 mem1 = 0;
649 if ((long)mem2 == -1L)
650 mem2 = 0;
651 else
652 mem2 *= 4096;
653
654
655 if (mem1 >= mem2)
656 freemem = mem1;
657 else
658 freemem = mem2;
659 *freeram = freemem;
660 *totalswap =
661 ((long)info.max_pages_in_paging_file == -1L)
662 ? 0
663 : info.max_pages_in_paging_file * 4096;
664 *totalram =
665 ((long)info.total_physical_pages == -1L)
666 ? (freemem + (unsigned long)sbrk (0) + *totalswap)
667 : info.total_physical_pages * 4096;
668 *freeswap = 0;
669 return 0;
670 }
671
672
673 void
674 dos_cleanup (void)
675 {
676 struct tty_display_info *tty;
677
678 #ifndef HAVE_X_WINDOWS
679 restore_parent_vm_title ();
680 #endif
681
682
683 if (FRAMEP (selected_frame))
684 {
685 struct frame *sf = XFRAME (selected_frame);
686
687 if (FRAME_LIVE_P (sf)
688 && (FRAME_MSDOS_P (sf) || FRAME_TERMCAP_P (sf)))
689 {
690 tty = CURTTY ();
691 if (tty->termscript)
692 {
693 fflush (tty->termscript);
694 fsync (fileno (tty->termscript));
695 }
696 }
697 }
698 }
699
700
701
702
703 void
704 syms_of_dosfns (void)
705 {
706 defsubr (&Sint86);
707 defsubr (&Sdos_memget);
708 defsubr (&Sdos_memput);
709 defsubr (&Smsdos_mouse_init);
710 defsubr (&Smsdos_mouse_enable);
711 defsubr (&Smsdos_set_keyboard);
712 defsubr (&Sinsert_startup_screen);
713 defsubr (&Smsdos_mouse_disable);
714 defsubr (&Sfile_system_info);
715 #ifndef HAVE_X_WINDOWS
716 defsubr (&Smsdos_mouse_p);
717 #endif
718
719 DEFVAR_INT ("dos-country-code", dos_country_code,
720 doc:
721 );
722
723 DEFVAR_INT ("dos-codepage", dos_codepage,
724 doc:
725
726
727
728
729
730
731
732
733 );
734
735 DEFVAR_INT ("dos-timezone-offset", dos_timezone_offset,
736 doc:
737 );
738
739 DEFVAR_LISP ("dos-version", Vdos_version,
740 doc: );
741
742 #ifndef HAVE_X_WINDOWS
743 DEFVAR_LISP ("dos-windows-version", Vdos_windows_version,
744 doc: );
745 #endif
746
747 DEFVAR_LISP ("dos-display-scancodes", Vdos_display_scancodes,
748 doc:
749
750
751 );
752
753 Vdos_display_scancodes = Qnil;
754
755 DEFVAR_INT ("dos-hyper-key", dos_hyper_key,
756 doc:
757 );
758 dos_hyper_key = 0;
759
760 DEFVAR_INT ("dos-super-key", dos_super_key,
761 doc:
762 );
763 dos_super_key = 0;
764
765 DEFVAR_INT ("dos-keypad-mode", dos_keypad_mode,
766 doc:
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786 );
787 dos_keypad_mode = 0x75;
788
789 DEFVAR_INT ("dos-keyboard-layout", dos_keyboard_layout,
790 doc:
791 );
792 dos_keyboard_layout = 1;
793
794 DEFVAR_INT ("dos-decimal-point", dos_decimal_point,
795 doc:
796
797
798 );
799 dos_decimal_point = 0;
800 }
801 #endif