replace XTYPE calls in nextstep files
[bpt/emacs.git] / src / w16select.c
index 9e6e9f0..1e4d35b 100644 (file)
@@ -1,6 +1,6 @@
 /* 16-bit Windows Selection processing for emacs on MS-Windows
-   Copyright (C) 1996, 1997, 2001, 2002, 2003, 2004,
-                 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+
+Copyright (C) 1996-1997, 2001-2014 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -23,22 +23,20 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
    menus, and the Windows clipboard.  */
 
 /* Written by Dale P. Smith <dpsm@en.com>  */
-/* Adapted to DJGPP v1 by Eli Zaretskii <eliz@is.elta.co.il>  */
+/* Adapted to DJGPP by Eli Zaretskii <eliz@gnu.org>  */
 
 #ifdef MSDOS
 
 #include <config.h>
-#include <string.h>
 #include <dpmi.h>
 #include <go32.h>
 #include <sys/farptr.h>
-#include <setjmp.h>
 #include "lisp.h"
 #include "dispextern.h"        /* frame.h seems to want this */
 #include "frame.h"     /* Need this to get the X window of selected_frame */
 #include "blockinput.h"
-#include "buffer.h"
 #include "character.h"
+#include "buffer.h"
 #include "coding.h"
 #include "composite.h"
 
@@ -69,13 +67,6 @@ unsigned clipboard_compact (unsigned);
 
 Lisp_Object QCLIPBOARD, QPRIMARY;
 
-/* Coding system for communicating with other Windows programs via the
-   clipboard.  */
-static Lisp_Object Vselection_coding_system;
-
-/* Coding system for the next communicating with other Windows programs.  */
-static Lisp_Object Vnext_selection_coding_system;
-
 /* The segment address and the size of the buffer in low
    memory used to move data between us and WinOldAp module.  */
 static struct {
@@ -94,25 +85,6 @@ static unsigned char *last_clipboard_text;
 /* The size of allocated storage for storing the clipboard data.  */
 static size_t clipboard_storage_size;
 \f
-/* Emulation of `__dpmi_int' and friends for DJGPP v1.x  */
-
-#if __DJGPP__ < 2
-
-typedef _go32_dpmi_registers __dpmi_regs;
-#define __tb      _go32_info_block.linear_address_of_transfer_buffer
-#define _dos_ds          _go32_info_block.selector_for_linear_memory
-
-static int
-__dpmi_int (intno, regs)
-     int intno;
-     __dpmi_regs *regs;
-{
-  regs->x.ss = regs->x.sp = regs->x.flags = 0;
-  return _go32_dpmi_simulate_int (intno, regs);
-}
-
-#endif /* __DJGPP__ < 2 */
-\f
 /* C functions to access the Windows 3.1x clipboard from DOS apps.
 
    The information was obtained from the Microsoft Knowledge Base,
@@ -128,7 +100,7 @@ __dpmi_int (intno, regs)
 
 /* Return the WinOldAp support version, or 0x1700 if not supported.  */
 unsigned
-identify_winoldap_version ()
+identify_winoldap_version (void)
 {
   __dpmi_regs regs;
 
@@ -137,13 +109,13 @@ identify_winoldap_version ()
                         <> 1700H: AL = Major version number
                                  AH = Minor version number */
   regs.x.ax = 0x1700;
-  __dpmi_int(0x2f, &regs);
+  __dpmi_int (0x2f, &regs);
   return regs.x.ax;
 }
 
-/* Open the clipboard, return non-zero if successfull.  */
+/* Open the clipboard, return non-zero if successful.  */
 unsigned
-open_clipboard ()
+open_clipboard (void)
 {
   __dpmi_regs regs;
 
@@ -160,13 +132,13 @@ open_clipboard ()
      Return Values   AX == 0: Clipboard already open
                        <> 0: Clipboard opened */
   regs.x.ax = 0x1701;
-  __dpmi_int(0x2f, &regs);
+  __dpmi_int (0x2f, &regs);
   return regs.x.ax;
 }
 
-/* Empty clipboard, return non-zero if successfull.  */
+/* Empty clipboard, return non-zero if successful.  */
 unsigned
-empty_clipboard ()
+empty_clipboard (void)
 {
   __dpmi_regs regs;
 
@@ -174,15 +146,14 @@ empty_clipboard ()
      Return Values   AX == 0: Error occurred
                        <> 0: OK, Clipboard emptied */
   regs.x.ax = 0x1702;
-  __dpmi_int(0x2f, &regs);
+  __dpmi_int (0x2f, &regs);
   return regs.x.ax;
 }
 
 /* Ensure we have a buffer in low memory with enough memory for data
    of size WANT_SIZE.  Return the linear address of the buffer.  */
 static unsigned long
-alloc_xfer_buf (want_size)
-     unsigned want_size;
+alloc_xfer_buf (unsigned want_size)
 {
   __dpmi_regs regs;
 
@@ -219,7 +190,7 @@ alloc_xfer_buf (want_size)
    The clipboard buffer tends to be large in size, because for small
    clipboard data sizes we use the DJGPP transfer buffer.  */
 static void
-free_xfer_buf ()
+free_xfer_buf (void)
 {
   /* If the size is 0, we used DJGPP transfer buffer, so don't free.  */
   if (clipboard_xfer_buf_info.size)
@@ -235,13 +206,9 @@ free_xfer_buf ()
     }
 }
 
-/* Copy data into the clipboard, return zero if successfull.  */
+/* Copy data into the clipboard, return zero if successful.  */
 unsigned
-set_clipboard_data (Format, Data, Size, Raw)
-     unsigned Format;
-     void *Data;
-     unsigned Size;
-     int Raw;
+set_clipboard_data (unsigned Format, void *Data, unsigned Size, int Raw)
 {
   __dpmi_regs regs;
   unsigned truelen;
@@ -326,7 +293,7 @@ set_clipboard_data (Format, Data, Size, Raw)
   regs.x.cx = truelen & 0xffff;
   regs.x.es = xbuf_addr >> 4;
   regs.x.bx = xbuf_addr & 15;
-  __dpmi_int(0x2f, &regs);
+  __dpmi_int (0x2f, &regs);
 
   free_xfer_buf ();
 
@@ -340,8 +307,7 @@ set_clipboard_data (Format, Data, Size, Raw)
 
 /* Return the size of the clipboard data of format FORMAT.  */
 unsigned
-get_clipboard_data_size (Format)
-     unsigned Format;
+get_clipboard_data_size (unsigned Format)
 {
   __dpmi_regs regs;
 
@@ -353,7 +319,7 @@ get_clipboard_data_size (Format)
                           the clipboard.  */
   regs.x.ax = 0x1704;
   regs.x.dx = Format;
-  __dpmi_int(0x2f, &regs);
+  __dpmi_int (0x2f, &regs);
   return ( (((unsigned)regs.x.dx) << 16) | regs.x.ax);
 }
 
@@ -361,11 +327,7 @@ get_clipboard_data_size (Format)
    Warning: this doesn't check whether DATA has enough space to hold
    SIZE bytes.  */
 unsigned
-get_clipboard_data (Format, Data, Size, Raw)
-     unsigned Format;
-     void *Data;
-     unsigned Size;
-     int Raw;
+get_clipboard_data (unsigned Format, void *Data, unsigned Size, int Raw)
 {
   __dpmi_regs regs;
   unsigned long xbuf_addr;
@@ -390,7 +352,7 @@ get_clipboard_data (Format, Data, Size, Raw)
   regs.x.dx = Format;
   regs.x.es = xbuf_addr >> 4;
   regs.x.bx = xbuf_addr & 15;
-  __dpmi_int(0x2f, &regs);
+  __dpmi_int (0x2f, &regs);
   if (regs.x.ax != 0)
     {
       unsigned char null_char = '\0';
@@ -442,9 +404,9 @@ get_clipboard_data (Format, Data, Size, Raw)
   return (unsigned) (dp - (unsigned char *)Data - 1);
 }
 
-/* Close clipboard, return non-zero if successfull.  */
+/* Close clipboard, return non-zero if successful.  */
 unsigned
-close_clipboard ()
+close_clipboard (void)
 {
   __dpmi_regs regs;
 
@@ -452,14 +414,13 @@ close_clipboard ()
      Return Values   AX == 0: Error occurred
                         <> 0: OK */
   regs.x.ax = 0x1708;
-  __dpmi_int(0x2f, &regs);
+  __dpmi_int (0x2f, &regs);
   return regs.x.ax;
 }
 
 /* Compact clipboard data so that at least SIZE bytes is available.  */
 unsigned
-clipboard_compact (Size)
-     unsigned Size;
+clipboard_compact (unsigned Size)
 {
   __dpmi_regs regs;
 
@@ -470,7 +431,7 @@ clipboard_compact (Size)
   regs.x.ax = 0x1709;
   regs.x.si = Size >> 16;
   regs.x.cx = Size & 0xffff;
-  __dpmi_int(0x2f, &regs);
+  __dpmi_int (0x2f, &regs);
   return ((unsigned)regs.x.dx << 16) | regs.x.ax;
 }
 \f
@@ -483,23 +444,18 @@ static char system_error_msg[] =
 
 DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_data, 1, 2, 0,
        doc: /* This sets the clipboard data to the given text.  */)
-     (string, frame)
-     Lisp_Object string, frame;
+  (Lisp_Object string, Lisp_Object frame)
 {
   unsigned ok = 1, put_status = 0;
-  int nbytes, charset_info, no_crlf_conversion;
+  int nbytes, no_crlf_conversion;
   unsigned char *src, *dst = NULL;
 
   CHECK_STRING (string);
 
-  if (NILP (frame))
-    frame = Fselected_frame ();
-
-  CHECK_LIVE_FRAME (frame);
-  if ( !FRAME_MSDOS_P (XFRAME (frame)))
+  if (!FRAME_MSDOS_P (decode_live_frame (frame)))
     goto done;
 
-  BLOCK_INPUT;
+  block_input ();
 
   if (!open_clipboard ())
     goto error;
@@ -525,16 +481,14 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
     {
       /* We must encode contents of STRING according to what
         clipboard-coding-system specifies.  */
-      int bufsize;
       struct coding_system coding;
-      unsigned char *htext2;
       Lisp_Object coding_system =
        NILP (Vnext_selection_coding_system) ?
        Vselection_coding_system : Vnext_selection_coding_system;
 
       setup_coding_system (Fcheck_coding_system (coding_system), &coding);
       coding.dst_bytes = nbytes * 4;
-      coding.destination = (unsigned char *) xmalloc (coding.dst_bytes);
+      coding.destination = xmalloc (coding.dst_bytes);
       Vnext_selection_coding_system = Qnil;
       coding.mode |= CODING_MODE_LAST_BLOCK;
       dst = coding.destination;
@@ -562,7 +516,7 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
 
  unblock:
   xfree (dst);
-  UNBLOCK_INPUT;
+  unblock_input ();
 
   /* Notify user if the text is too large to fit into DOS memory.
      (This will happen somewhere after 600K bytes (470K in DJGPP v1.x),
@@ -574,13 +528,13 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
       switch (put_status)
        {
          case 1:
-           message2 (no_mem_msg, sizeof (no_mem_msg) - 1, 0);
+           message3 (make_unibyte_string (no_mem_msg, sizeof (no_mem_msg) - 1));
            break;
          case 2:
-           message2 (binary_msg, sizeof (binary_msg) - 1, 0);
+           message3 (make_unibyte_string (binary_msg, sizeof (binary_msg) - 1));
            break;
          case 3:
-           message2 (system_error_msg, sizeof (system_error_msg) - 1, 0);
+           message3 (make_unibyte_string (system_error_msg, sizeof (system_error_msg) - 1));
            break;
        }
       sit_for (make_number (2), 0, 2);
@@ -593,28 +547,23 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
 
 DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_data, 0, 1, 0,
        doc: /* This gets the clipboard data in text format.  */)
-     (frame)
-     Lisp_Object frame;
+  (Lisp_Object frame)
 {
   unsigned data_size, truelen;
   unsigned char *htext = NULL;
   Lisp_Object ret = Qnil;
-  int no_crlf_conversion, require_decoding = 0;
-
-  if (NILP (frame))
-    frame = Fselected_frame ();
+  int require_decoding = 0;
 
-  CHECK_LIVE_FRAME (frame);
-  if ( !FRAME_MSDOS_P (XFRAME (frame)))
+  if (!FRAME_MSDOS_P (decode_live_frame (frame)))
     goto done;
 
-  BLOCK_INPUT;
+  block_input ();
 
   if (!open_clipboard ())
     goto unblock;
 
   if ((data_size = get_clipboard_data_size (CF_OEMTEXT)) == 0 ||
-      (htext = (unsigned char *)xmalloc (data_size)) == 0)
+      (htext = xmalloc (data_size)) == 0)
     goto closeclip;
 
   /* need to know final size after '\r' chars are removed because
@@ -640,8 +589,6 @@ DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_dat
   }
   if (require_decoding)
     {
-      int bufsize;
-      unsigned char *buf;
       struct coding_system coding;
       Lisp_Object coding_system = Vnext_selection_coding_system;
 
@@ -671,7 +618,7 @@ DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_dat
   close_clipboard ();
 
  unblock:
-  UNBLOCK_INPUT;
+  unblock_input ();
 
  done:
 
@@ -681,15 +628,17 @@ DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_dat
 /* Support checking for a clipboard selection. */
 
 DEFUN ("x-selection-exists-p", Fx_selection_exists_p, Sx_selection_exists_p,
-       0, 1, 0,
-       doc: /* Whether there is an owner for the given X Selection.
-The arg should be the name of the selection in question, typically one of
-the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
-\(Those are literal upper-case symbol names, since that's what X expects.)
-For convenience, the symbol nil is the same as `PRIMARY',
-and t is the same as `SECONDARY'.  */)
-     (selection)
-     Lisp_Object selection;
+       0, 2, 0,
+       doc: /* Whether there is an owner for the given X selection.
+SELECTION should be the name of the selection in question, typically
+one of the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.  (X expects
+these literal upper-case names.)  The symbol nil is the same as
+`PRIMARY', and t is the same as `SECONDARY'.
+
+TERMINAL should be a terminal object or a frame specifying the X
+server to query.  If omitted or nil, that stands for the selected
+frame's display, or the first available X display.  */)
+  (Lisp_Object selection, Lisp_Object terminal)
 {
   CHECK_SYMBOL (selection);
 
@@ -704,8 +653,8 @@ and t is the same as `SECONDARY'.  */)
      into the clipboard if we run under Windows, so we cannot check
      the clipboard alone.)  */
   if ((EQ (selection, Qnil) || EQ (selection, QPRIMARY))
-      && ! NILP (SYMBOL_VALUE (Fintern_soft (build_string ("kill-ring"),
-                                            Qnil))))
+      && ! NILP (Fsymbol_value (Fintern_soft (build_string ("kill-ring"),
+                                             Qnil))))
     return Qt;
 
   if (EQ (selection, QCLIPBOARD))
@@ -724,25 +673,50 @@ and t is the same as `SECONDARY'.  */)
 }
 
 void
-syms_of_win16select ()
+syms_of_win16select (void)
 {
   defsubr (&Sw16_set_clipboard_data);
   defsubr (&Sw16_get_clipboard_data);
   defsubr (&Sx_selection_exists_p);
 
-  DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system,
-              doc: /* Coding system for communicating with other X clients.
-When sending or receiving text via cut_buffer, selection, and clipboard,
-the text is encoded or decoded by this coding system.
-The default value is `iso-latin-1-dos'.  */);
+  DEFVAR_LISP ("selection-coding-system", Vselection_coding_system,
+              doc: /* Coding system for communicating with other programs.
+
+For MS-Windows and MS-DOS:
+When sending or receiving text via selection and clipboard, the text
+is encoded or decoded by this coding system.  The default value is
+the current system default encoding on 9x/Me, `utf-16le-dos'
+\(Unicode) on NT/W2K/XP, and `iso-latin-1-dos' on MS-DOS.
+
+For X Windows:
+When sending text via selection and clipboard, if the target
+data-type matches with the type of this coding system, it is used
+for encoding the text.  Otherwise (including the case that this
+variable is nil), a proper coding system is used as below:
+
+data-type      coding system
+---------      -------------
+UTF8_STRING    utf-8
+COMPOUND_TEXT  compound-text-with-extensions
+STRING         iso-latin-1
+C_STRING       no-conversion
+
+When receiving text, if this coding system is non-nil, it is used
+for decoding regardless of the data-type.  If this is nil, a
+proper coding system is used according to the data-type as above.
+
+See also the documentation of the variable `x-select-request-type' how
+to control which data-type to request for receiving text.
+
+The default value is nil.  */);
   Vselection_coding_system = intern ("iso-latin-1-dos");
 
-  DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system,
-              doc: /* Coding system for the next communication with other X clients.
+  DEFVAR_LISP ("next-selection-coding-system", Vnext_selection_coding_system,
+              doc: /* Coding system for the next communication with other programs.
 Usually, `selection-coding-system' is used for communicating with
-other X clients.  But, if this variable is set, it is used for the
-next communication only.  After the communication, this variable is
-set to nil.  */);
+other programs (X Windows clients or MS Windows programs).  But, if this
+variable is set, it is used for the next communication only.
+After the communication, this variable is set to nil.  */);
   Vnext_selection_coding_system = Qnil;
 
   QPRIMARY   = intern ("PRIMARY");     staticpro (&QPRIMARY);
@@ -750,6 +724,3 @@ set to nil.  */);
 }
 
 #endif /* MSDOS */
-
-/* arch-tag: 085a22c8-7324-436e-a6da-102464ce95d8
-   (do not change this comment) */