]> code.delx.au - gnu-emacs/blobdiff - src/dosfns.c
Merge from emacs-24; up to 2012-05-04T19:17:01Z!monnier@iro.umontreal.ca
[gnu-emacs] / src / dosfns.c
index a979c542f51d933e95b79cb8783336deca333c02..21676f4b4f51c54932705e3a2ce7597a094d3125 100644 (file)
@@ -1,7 +1,6 @@
 /* MS-DOS specific Lisp utilities.  Coded by Manabu Higashida, 1991.
    Major changes May-July 1993 Morten Welinder (only 10% original code left)
-   Copyright (C) 1991, 1993, 1996, 1997, 1998, 2001, 2002, 2003, 2004,
-                 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+   Copyright (C) 1991, 1993, 1996-1998, 2001-2012 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -24,10 +23,16 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 /* The entire file is within this conditional */
 
 #include <stdio.h>
-#include <string.h>
+/* gettime and settime in dos.h clash with their namesakes from
+   gnulib, so we move out of our way the prototypes in dos.h.  */
+#define gettime dos_h_gettime_
+#define settime dos_h_settime_
 #include <dos.h>
+#undef gettime
+#undef settime
 #include <setjmp.h>
 #include "lisp.h"
+#include "character.h"
 #include "buffer.h"
 #include "termchar.h"
 #include "frame.h"
@@ -37,7 +42,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "dosfns.h"
 #include "msdos.h"
 #include "dispextern.h"
-#include "character.h"
 #include "coding.h"
 #include "process.h"
 #include <dpmi.h>
@@ -48,10 +52,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <grp.h>
 #include <crt0.h>
 
-#ifndef __DJGPP_MINOR__
-# define __tb _go32_info_block.linear_address_of_transfer_buffer;
-#endif
-
 DEFUN ("int86", Fint86, Sint86, 2, 2, 0,
        doc: /* Call specific MS-DOS interrupt number INTERRUPT with REGISTERS.
 Return the updated REGISTER vector.
@@ -59,41 +59,39 @@ Return the updated REGISTER vector.
 INTERRUPT should be an integer in the range 0 to 255.
 REGISTERS should be a vector produced by `make-register' and
 `set-register-value'.  */)
-     (interrupt, registers)
-     Lisp_Object interrupt, registers;
+  (Lisp_Object interrupt, Lisp_Object registers)
 {
   register int i;
   int no;
   union REGS inregs, outregs;
-  Lisp_Object val;
 
   CHECK_NUMBER (interrupt);
   no = (unsigned long) XINT (interrupt);
   CHECK_VECTOR (registers);
-  if (no < 0 || no > 0xff || XVECTOR (registers)-> size != 8)
+  if (no < 0 || no > 0xff || ASIZE (registers) != 8)
     return Qnil;
   for (i = 0; i < 8; i++)
-    CHECK_NUMBER (XVECTOR (registers)->contents[i]);
+    CHECK_NUMBER (AREF (registers, i));
 
-  inregs.x.ax    = (unsigned long) XFASTINT (XVECTOR (registers)->contents[0]);
-  inregs.x.bx    = (unsigned long) XFASTINT (XVECTOR (registers)->contents[1]);
-  inregs.x.cx    = (unsigned long) XFASTINT (XVECTOR (registers)->contents[2]);
-  inregs.x.dx    = (unsigned long) XFASTINT (XVECTOR (registers)->contents[3]);
-  inregs.x.si    = (unsigned long) XFASTINT (XVECTOR (registers)->contents[4]);
-  inregs.x.di    = (unsigned long) XFASTINT (XVECTOR (registers)->contents[5]);
-  inregs.x.cflag = (unsigned long) XFASTINT (XVECTOR (registers)->contents[6]);
-  inregs.x.flags = (unsigned long) XFASTINT (XVECTOR (registers)->contents[7]);
+  inregs.x.ax    = (unsigned long) XFASTINT (AREF (registers, 0));
+  inregs.x.bx    = (unsigned long) XFASTINT (AREF (registers, 1));
+  inregs.x.cx    = (unsigned long) XFASTINT (AREF (registers, 2));
+  inregs.x.dx    = (unsigned long) XFASTINT (AREF (registers, 3));
+  inregs.x.si    = (unsigned long) XFASTINT (AREF (registers, 4));
+  inregs.x.di    = (unsigned long) XFASTINT (AREF (registers, 5));
+  inregs.x.cflag = (unsigned long) XFASTINT (AREF (registers, 6));
+  inregs.x.flags = (unsigned long) XFASTINT (AREF (registers, 7));
 
   int86 (no, &inregs, &outregs);
 
-  XVECTOR (registers)->contents[0] = make_number (outregs.x.ax);
-  XVECTOR (registers)->contents[1] = make_number (outregs.x.bx);
-  XVECTOR (registers)->contents[2] = make_number (outregs.x.cx);
-  XVECTOR (registers)->contents[3] = make_number (outregs.x.dx);
-  XVECTOR (registers)->contents[4] = make_number (outregs.x.si);
-  XVECTOR (registers)->contents[5] = make_number (outregs.x.di);
-  XVECTOR (registers)->contents[6] = make_number (outregs.x.cflag);
-  XVECTOR (registers)->contents[7] = make_number (outregs.x.flags);
+  ASET (registers, 0, make_number (outregs.x.ax));
+  ASET (registers, 1, make_number (outregs.x.bx));
+  ASET (registers, 2, make_number (outregs.x.cx));
+  ASET (registers, 3, make_number (outregs.x.dx));
+  ASET (registers, 4, make_number (outregs.x.si));
+  ASET (registers, 5, make_number (outregs.x.di));
+  ASET (registers, 6, make_number (outregs.x.cflag));
+  ASET (registers, 7, make_number (outregs.x.flags));
 
   return registers;
 }
@@ -101,51 +99,47 @@ REGISTERS should be a vector produced by `make-register' and
 DEFUN ("msdos-memget", Fdos_memget, Sdos_memget, 2, 2, 0,
        doc: /* Read DOS memory at offset ADDRESS into VECTOR.
 Return the updated VECTOR.  */)
-     (address, vector)
-     Lisp_Object address, vector;
+  (Lisp_Object address, Lisp_Object vector)
 {
   register int i;
   int offs, len;
   char *buf;
-  Lisp_Object val;
 
   CHECK_NUMBER (address);
   offs = (unsigned long) XINT (address);
   CHECK_VECTOR (vector);
-  len = XVECTOR (vector)-> size;
+  len = ASIZE (vector);
   if (len < 1 || len > 2048 || offs < 0 || offs > 0xfffff - len)
     return Qnil;
   buf = alloca (len);
   dosmemget (offs, len, buf);
 
   for (i = 0; i < len; i++)
-    XVECTOR (vector)->contents[i] = make_number (buf[i]);
+    ASET (vector, i, make_number (buf[i]));
 
   return vector;
 }
 
 DEFUN ("msdos-memput", Fdos_memput, Sdos_memput, 2, 2, 0,
        doc: /* Write DOS memory at offset ADDRESS from VECTOR.  */)
-     (address, vector)
-     Lisp_Object address, vector;
+  (Lisp_Object address, Lisp_Object vector)
 {
   register int i;
   int offs, len;
   char *buf;
-  Lisp_Object val;
 
   CHECK_NUMBER (address);
   offs = (unsigned long) XINT (address);
   CHECK_VECTOR (vector);
-  len = XVECTOR (vector)-> size;
+  len = ASIZE (vector);
   if (len < 1 || len > 2048 || offs < 0 || offs > 0xfffff - len)
     return Qnil;
   buf = alloca (len);
 
   for (i = 0; i < len; i++)
     {
-      CHECK_NUMBER (XVECTOR (vector)->contents[i]);
-      buf[i] = (unsigned char) XFASTINT (XVECTOR (vector)->contents[i]) & 0xFF;
+      CHECK_NUMBER (AREF (vector, i));
+      buf[i] = (unsigned char) XFASTINT (AREF (vector, i)) & 0xFF;
     }
 
   dosmemput (buf, len, offs);
@@ -157,8 +151,7 @@ DEFUN ("msdos-set-keyboard", Fmsdos_set_keyboard, Smsdos_set_keyboard, 1, 2, 0,
 If the optional argument ALLKEYS is non-nil, the keyboard is mapped for
 all keys; otherwise it is only used when the ALT key is pressed.
 The current keyboard layout is available in dos-keyboard-code.  */)
-     (country_code, allkeys)
-     Lisp_Object country_code, allkeys;
+  (Lisp_Object country_code, Lisp_Object allkeys)
 {
   CHECK_NUMBER (country_code);
   if (!dos_set_keyboard (XINT (country_code), !NILP (allkeys)))
@@ -172,7 +165,7 @@ The current keyboard layout is available in dos-keyboard-code.  */)
 
 DEFUN ("msdos-mouse-p", Fmsdos_mouse_p, Smsdos_mouse_p, 0, 0, 0,
        doc: /* Report whether a mouse is present.  */)
-     ()
+  (void)
 {
   if (have_mouse)
     return Qt;
@@ -183,7 +176,7 @@ DEFUN ("msdos-mouse-p", Fmsdos_mouse_p, Smsdos_mouse_p, 0, 0, 0,
 
 DEFUN ("msdos-mouse-init", Fmsdos_mouse_init, Smsdos_mouse_init, 0, 0, "",
        doc: /* Initialize and enable mouse if available.  */)
-     ()
+  (void)
 {
   if (have_mouse)
     {
@@ -196,7 +189,7 @@ DEFUN ("msdos-mouse-init", Fmsdos_mouse_init, Smsdos_mouse_init, 0, 0, "",
 
 DEFUN ("msdos-mouse-enable", Fmsdos_mouse_enable, Smsdos_mouse_enable, 0, 0, "",
        doc: /* Enable mouse if available.  */)
-     ()
+  (void)
 {
   if (have_mouse)
     {
@@ -208,7 +201,7 @@ DEFUN ("msdos-mouse-enable", Fmsdos_mouse_enable, Smsdos_mouse_enable, 0, 0, "",
 
 DEFUN ("msdos-mouse-disable", Fmsdos_mouse_disable, Smsdos_mouse_disable, 0, 0, "",
        doc: /* Disable mouse if available.  */)
-     ()
+  (void)
 {
   mouse_off ();
   if (have_mouse) have_mouse = -1;
@@ -218,7 +211,7 @@ DEFUN ("msdos-mouse-disable", Fmsdos_mouse_disable, Smsdos_mouse_disable, 0, 0,
 DEFUN ("insert-startup-screen", Finsert_startup_screen, Sinsert_startup_screen, 0, 0, "",
        doc: /* Insert copy of screen contents prior to starting Emacs.
 Return nil if startup screen is not available.  */)
-     ()
+  (void)
 {
   char *s;
   int rows, cols, i, j;
@@ -239,12 +232,6 @@ Return nil if startup screen is not available.  */)
   return Qt;
 }
 \f
-/* country info */
-EMACS_INT dos_country_code;
-EMACS_INT dos_codepage;
-EMACS_INT dos_timezone_offset;
-EMACS_INT dos_decimal_point;
-EMACS_INT dos_keyboard_layout;
 unsigned char dos_country_info[DOS_COUNTRY_INFO];
 static unsigned char usa_country_info[DOS_COUNTRY_INFO] = {
   0, 0,                                /* date format */
@@ -261,17 +248,8 @@ static unsigned char usa_country_info[DOS_COUNTRY_INFO] = {
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* reserved */
 };
 
-EMACS_INT dos_hyper_key;
-EMACS_INT dos_super_key;
-EMACS_INT dos_keypad_mode;
-
-Lisp_Object Vdos_version;
-Lisp_Object Vdos_display_scancodes;
-
 #ifndef HAVE_X_WINDOWS
 static unsigned dos_windows_version;
-Lisp_Object Vdos_windows_version;
-
 char parent_vm_title[50];      /* Ralf Brown says 30 is enough */
 int w95_set_virtual_machine_title (const char *);
 
@@ -287,13 +265,15 @@ restore_parent_vm_title (void)
 #endif /* !HAVE_X_WINDOWS */
 
 void
-init_dosfns ()
+init_dosfns (void)
 {
   union REGS regs;
   _go32_dpmi_registers dpmiregs;
   unsigned long xbuf = _go32_info_block.linear_address_of_transfer_buffer;
 
 #ifndef SYSTEM_MALLOC
+  extern void get_lim_data (void);
+
   get_lim_data (); /* why the hell isn't this called elsewhere? */
 #endif
 
@@ -369,13 +349,13 @@ init_dosfns ()
        {
          dpmiregs.x.ax = 0x168e;
          dpmiregs.x.dx = 3;    /* get VM title */
-         dpmiregs.x.cx = sizeof(parent_vm_title) - 1;
+         dpmiregs.x.cx = sizeof (parent_vm_title) - 1;
          dpmiregs.x.es = __tb >> 4;
          dpmiregs.x.di = __tb & 15;
          dpmiregs.x.sp = dpmiregs.x.ss = dpmiregs.x.flags = 0;
          _go32_dpmi_simulate_int (0x2f, &dpmiregs);
          if (dpmiregs.x.ax == 1)
-           dosmemget (__tb, sizeof(parent_vm_title), parent_vm_title);
+           dosmemget (__tb, sizeof (parent_vm_title), parent_vm_title);
        }
     }
   else
@@ -385,8 +365,6 @@ init_dosfns ()
     }
 #endif /* !HAVE_X_WINDOWS */
 
-#if __DJGPP__ >= 2
-
   /* Without this, we never see hidden files.
      Don't OR it with the previous value, so the value recorded at dump
      time, possibly with `preserve-case' flags set, won't get through.  */
@@ -398,7 +376,6 @@ init_dosfns ()
   if (!NILP (Fmsdos_long_file_names ()))
     __opendir_flags |= __OPENDIR_PRESERVE_CASE;
 #endif /* __DJGPP_MINOR__ == 0 */
-#endif /* __DJGPP__ >= 2 */
 }
 \f
 #ifndef HAVE_X_WINDOWS
@@ -488,9 +465,7 @@ w95_set_virtual_machine_title (const char *title_string)
    sets the name in the frame struct, but has no other effects.  */
 
 void
-x_set_title (f, name)
-     struct frame *f;
-     Lisp_Object name;
+x_set_title (struct frame *f, Lisp_Object name)
 {
   /* Don't change the title if it's already NAME.  */
   if (EQ (name, f->title))
@@ -498,7 +473,7 @@ x_set_title (f, name)
 
   update_mode_lines = 1;
 
-  f->title = name;
+  fset_title (f, name);
 
   if (NILP (name))
     name = f->name;
@@ -518,8 +493,7 @@ Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
 storage of the file system, FREE is the free storage, and AVAIL is the
 storage available to a non-superuser.  All 3 numbers are in bytes.
 If the underlying system call fails, value is nil.  */)
-     (filename)
-     Lisp_Object filename;
+  (Lisp_Object filename)
 {
   struct statfs stfs;
   Lisp_Object encoded, value;
@@ -543,7 +517,7 @@ If the underlying system call fails, value is nil.  */)
    (There are no other processes on DOS, right?)  */
 
 Lisp_Object
-list_system_processes ()
+list_system_processes (void)
 {
   Lisp_Object proclist = Qnil;
 
@@ -588,7 +562,7 @@ system_process_attributes (Lisp_Object pid)
        attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
       strcpy (cmd, basename (__crt0_argv[0]));
       /* Command name is encoded in locale-coding-system; decode it.  */
-      cmd_str = make_unibyte_string (cmd, strlen (cmd));
+      cmd_str = build_unibyte_string (cmd);
       decoded_cmd = code_convert_string_norecord (cmd_str,
                                                  Vlocale_coding_system, 0);
       attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs);
@@ -604,7 +578,7 @@ system_process_attributes (Lisp_Object pid)
                            Fsymbol_value (intern ("before-init-time"))),
                     attrs);
       attrs = Fcons (Fcons (Qvsize,
-                           make_fixnum_or_float ((unsigned long)sbrk(0)/1024)),
+                           make_fixnum_or_float ((unsigned long)sbrk (0)/1024)),
                     attrs);
       attrs = Fcons (Fcons (Qetime, tem), attrs);
 #ifndef SYSTEM_MALLOC
@@ -656,7 +630,7 @@ system_process_attributes (Lisp_Object pid)
        q[-1] = '\0';
 
       /* Command line is encoded in locale-coding-system; decode it.  */
-      cmd_str = make_unibyte_string (cmdline, strlen (cmdline));
+      cmd_str = build_unibyte_string (cmdline);
       decoded_cmd = code_convert_string_norecord (cmd_str,
                                                  Vlocale_coding_system, 0);
       xfree (cmdline);
@@ -696,7 +670,8 @@ dos_cleanup (void)
 /*
  *     Define everything
  */
-syms_of_dosfns ()
+void
+syms_of_dosfns (void)
 {
   defsubr (&Sint86);
   defsubr (&Sdos_memget);
@@ -711,11 +686,11 @@ syms_of_dosfns ()
   defsubr (&Smsdos_mouse_p);
 #endif
 
-  DEFVAR_INT ("dos-country-code", &dos_country_code,
+  DEFVAR_INT ("dos-country-code", dos_country_code,
              doc: /* The country code returned by Dos when Emacs was started.
 Usually this is the international telephone prefix.  */);
 
-  DEFVAR_INT ("dos-codepage", &dos_codepage,
+  DEFVAR_INT ("dos-codepage", dos_codepage,
              doc: /* The codepage active when Emacs was started.
 The following are known:
        437     United States
@@ -727,38 +702,38 @@ The following are known:
        863     Canada (French)
        865     Norway/Denmark  */);
 
-  DEFVAR_INT ("dos-timezone-offset", &dos_timezone_offset,
+  DEFVAR_INT ("dos-timezone-offset", dos_timezone_offset,
              doc: /* The current timezone offset to UTC in minutes.
 Implicitly modified when the TZ variable is changed.  */);
 
-  DEFVAR_LISP ("dos-version", &Vdos_version,
+  DEFVAR_LISP ("dos-version", Vdos_version,
               doc: /* The (MAJOR . MINOR) Dos version (subject to modification with setver).  */);
 
 #ifndef HAVE_X_WINDOWS
-  DEFVAR_LISP ("dos-windows-version", &Vdos_windows_version,
+  DEFVAR_LISP ("dos-windows-version", Vdos_windows_version,
               doc: /* The (MAJOR . MINOR) Windows version for DOS session on MS-Windows.  */);
 #endif
 
-  DEFVAR_LISP ("dos-display-scancodes", &Vdos_display_scancodes,
-              doc: /* *Controls whether DOS raw keyboard events are displayed as you type.
+  DEFVAR_LISP ("dos-display-scancodes", Vdos_display_scancodes,
+              doc: /* Whether DOS raw keyboard events are displayed as you type.
 When non-nil, the keyboard scan-codes are displayed at the bottom right
 corner of the display (typically at the end of the mode line).
 The output format is: scan code:char code*modifiers.  */);
 
   Vdos_display_scancodes = Qnil;
 
-  DEFVAR_INT ("dos-hyper-key", &dos_hyper_key,
-             doc: /* *If set to 1, use right ALT key as hyper key.
+  DEFVAR_INT ("dos-hyper-key", dos_hyper_key,
+             doc: /* If set to 1, use right ALT key as hyper key.
 If set to 2, use right CTRL key as hyper key.  */);
   dos_hyper_key = 0;
 
-  DEFVAR_INT ("dos-super-key", &dos_super_key,
-             doc: /* *If set to 1, use right ALT key as super key.
+  DEFVAR_INT ("dos-super-key", dos_super_key,
+             doc: /* If set to 1, use right ALT key as super key.
 If set to 2, use right CTRL key as super key.  */);
   dos_super_key = 0;
 
-  DEFVAR_INT ("dos-keypad-mode", &dos_keypad_mode,
-             doc: /* *Controls what key code is returned by a key in the numeric keypad.
+  DEFVAR_INT ("dos-keypad-mode", dos_keypad_mode,
+             doc: /* Controls what key code is returned by a key in the numeric keypad.
 The `numlock ON' action is only taken if no modifier keys are pressed.
 The value is an integer constructed by adding the following bits together:
 
@@ -781,12 +756,12 @@ The value is an integer constructed by adding the following bits together:
   0x200        ALT-0..ALT-9 in top-row produces shifted codes.  */);
   dos_keypad_mode = 0x75;
 
-  DEFVAR_INT ("dos-keyboard-layout", &dos_keyboard_layout,
+  DEFVAR_INT ("dos-keyboard-layout", dos_keyboard_layout,
              doc: /* Contains the country code for the current keyboard layout.
 Use msdos-set-keyboard to select another keyboard layout.  */);
   dos_keyboard_layout = 1;     /* US */
 
-  DEFVAR_INT ("dos-decimal-point", &dos_decimal_point,
+  DEFVAR_INT ("dos-decimal-point", dos_decimal_point,
              doc: /* The character to produce when kp-decimal key is pressed.
 If non-zero, this variable contains the character to be returned when the
 decimal point key in the numeric keypad is pressed when Num Lock is on.
@@ -794,6 +769,3 @@ If zero, the decimal point key returns the country code specific value.  */);
   dos_decimal_point = 0;
 }
 #endif /* MSDOS */
-
-/* arch-tag: f5ea8847-a014-42c9-83f5-7738ad640b17
-   (do not change this comment) */