]> code.delx.au - gnu-emacs/blobdiff - src/w32select.c
Fix minor module problems found by static checking
[gnu-emacs] / src / w32select.c
index e3225c3f996d349a08ded5c90a0d0468b6011ec8..3962ac6cbed7599312fc0fceda55d97d8a4fb787 100644 (file)
@@ -1,6 +1,6 @@
-/* Selection processing for Emacs on the Microsoft W32 API.
+/* Selection processing for Emacs on the Microsoft Windows API.
 
-Copyright (C) 1993-1994, 2001-201 Free Software Foundation, Inc.
+Copyright (C) 1993-1994, 2001-2015 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -39,7 +39,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
  *
  * When copying or cutting (sending data to the OS), the data is
  * announced and stored internally, but only actually rendered on
- * request.  The requester determines the format provided.  The
+ * request.  The requestor determines the format provided.  The
  * {next-}selection-coding-system is only used, when its corresponding
  * clipboard type matches the type requested.
  *
@@ -73,15 +73,18 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
  */
 
 #include <config.h>
-#include <setjmp.h>
 #include "lisp.h"
+#include "w32common.h" /* os_subtype */
 #include "w32term.h"   /* for all of the w32 includes */
-#include "w32heap.h"   /* os_subtype */
+#include "keyboard.h"  /* for waiting_for_input */
 #include "blockinput.h"
-#include "charset.h"
 #include "coding.h"
-#include "composite.h"
 
+#ifdef CYGWIN
+#include <string.h>
+#include <stdio.h>
+#define _memccpy memccpy
+#endif
 
 static HGLOBAL convert_to_handle_as_ascii (void);
 static HGLOBAL convert_to_handle_as_coded (Lisp_Object coding_system);
@@ -90,8 +93,8 @@ static Lisp_Object render_locale (void);
 static Lisp_Object render_all (Lisp_Object ignore);
 static void run_protected (Lisp_Object (*code) (Lisp_Object), Lisp_Object arg);
 static Lisp_Object lisp_error_handler (Lisp_Object error);
-static LRESULT CALLBACK owner_callback (HWND win, UINT msg,
-                                       WPARAM wp, LPARAM lp);
+static LRESULT CALLBACK ALIGN_STACK owner_callback (HWND win, UINT msg,
+                                                   WPARAM wp, LPARAM lp);
 static HWND create_owner (void);
 
 static void setup_config (void);
@@ -102,17 +105,11 @@ static Lisp_Object validate_coding_system (Lisp_Object coding_system);
 static void setup_windows_coding_system (Lisp_Object coding_system,
                                         struct coding_system * coding);
 
-
-/* A remnant from X11: Symbol for the CLIPBORD selection type.  Other
-   selections are not used on Windows, so we don't need symbols for
-   PRIMARY and SECONDARY.  */
-Lisp_Object QCLIPBOARD;
-
 /* Internal pseudo-constants, initialized in globals_of_w32select()
    based on current system parameters. */
 static LCID DEFAULT_LCID;
 static UINT ANSICP, OEMCP;
-static Lisp_Object QUNICODE, QANSICP, QOEMCP;
+static Lisp_Object QANSICP, QOEMCP;
 
 /* A hidden window just for the clipboard management. */
 static HWND clipboard_owner;
@@ -216,7 +213,7 @@ convert_to_handle_as_coded (Lisp_Object coding_system)
 
   setup_windows_coding_system (coding_system, &coding);
   coding.dst_bytes = SBYTES (current_text) * 2;
-  coding.destination = (unsigned char *) xmalloc (coding.dst_bytes);
+  coding.destination = xmalloc (coding.dst_bytes);
   encode_coding_object (&coding, current_text, 0, 0,
                        SCHARS (current_text), SBYTES (current_text), Qnil);
 
@@ -335,7 +332,7 @@ render_all (Lisp_Object ignore)
 
   OpenClipboard (NULL);
 
-  /* There is no usefull means to report errors here, there are none
+  /* There is no useful means to report errors here, there are none
      expected anyway, and even if there were errors, they wouldn't do
      any harm.  So we just go ahead and do what has to be done without
      bothering with error handling.  */
@@ -389,12 +386,11 @@ run_protected (Lisp_Object (*code) (Lisp_Object), Lisp_Object arg)
      with global variables and calling strange looking functions.  Is
      this really the right way to run Lisp callbacks?  */
 
-  extern int waiting_for_input; /* from keyboard.c */
   int owfi;
 
-  BLOCK_INPUT;
+  block_input ();
 
-  /* Fsignal calls abort() if it sees that waiting_for_input is
+  /* Fsignal calls emacs_abort () if it sees that waiting_for_input is
      set.  */
   owfi = waiting_for_input;
   waiting_for_input = 0;
@@ -403,7 +399,7 @@ run_protected (Lisp_Object (*code) (Lisp_Object), Lisp_Object arg)
 
   waiting_for_input = owfi;
 
-  UNBLOCK_INPUT;
+  unblock_input ();
 }
 
 static Lisp_Object
@@ -416,7 +412,7 @@ lisp_error_handler (Lisp_Object error)
 }
 
 
-static LRESULT CALLBACK
+static LRESULT CALLBACK ALIGN_STACK
 owner_callback (HWND win, UINT msg, WPARAM wp, LPARAM lp)
 {
   switch (msg)
@@ -475,7 +471,10 @@ term_w32select (void)
 {
   /* This is needed to trigger WM_RENDERALLFORMATS. */
   if (clipboard_owner != NULL)
-    DestroyWindow (clipboard_owner);
+    {
+      DestroyWindow (clipboard_owner);
+      clipboard_owner = NULL;
+    }
 }
 
 static void
@@ -512,7 +511,7 @@ setup_config (void)
   cfg_clipboard_type = CF_TEXT;
 
   /* Interpret the coding system symbol name */
-  coding_name = SDATA (SYMBOL_NAME (cfg_coding_system));
+  coding_name = SSDATA (SYMBOL_NAME (cfg_coding_system));
 
   /* "(.*-)?utf-16.*" -> CF_UNICODETEXT */
   cp = strstr (coding_name, "utf-16");
@@ -663,7 +662,7 @@ setup_windows_coding_system (Lisp_Object coding_system,
      which both apply to ISO6429 only.  We don't know if these really
      need to be unset on Windows, but it probably doesn't hurt
      either.  */
-  coding->mode &= ~CODING_ANNOTATION_MASK;
+  coding->common_flags &= ~CODING_ANNOTATION_MASK;
   coding->mode |= CODING_MODE_LAST_BLOCK | CODING_MODE_SAFE_ENCODING;
 }
 
@@ -695,7 +694,7 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data,
   current_num_nls = 0;
   current_requires_encoding = 0;
 
-  BLOCK_INPUT;
+  block_input ();
 
   /* Check for non-ASCII characters.  While we are at it, count the
      number of LFs, so we know how many CRs we will have to add later
@@ -750,7 +749,7 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data,
       else
        {
          /* Advertise all supported formats so that whatever the
-            requester chooses, only one encoding step needs to be
+            requestor chooses, only one encoding step needs to be
             made.  This is intentionally different from what we do in
             the handler for WM_RENDERALLFORMATS.  */
          SetClipboardData (CF_UNICODETEXT, NULL);
@@ -783,7 +782,7 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data,
   current_coding_system = Qnil;
 
  done:
-  UNBLOCK_INPUT;
+  unblock_input ();
 
   return (ok ? string : Qnil);
 }
@@ -811,7 +810,7 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data,
   setup_config ();
   actual_clipboard_type = cfg_clipboard_type;
 
-  BLOCK_INPUT;
+  block_input ();
 
   if (!OpenClipboard (clipboard_owner))
     goto done;
@@ -856,7 +855,7 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data,
       {
        int i;
 
-       nbytes = strlen (src);
+       nbytes = strlen ((char *)src);
 
        for (i = 0; i < nbytes; i++)
          {
@@ -1001,27 +1000,30 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data,
   CloseClipboard ();
 
  done:
-  UNBLOCK_INPUT;
+  unblock_input ();
 
   return (ret);
 }
 
-/* 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'.  */)
-  (Lisp_Object selection)
+/* Support checking for a clipboard selection.  */
+
+DEFUN ("w32-selection-exists-p", Fw32_selection_exists_p, Sw32_selection_exists_p,
+       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);
 
   /* Return nil for PRIMARY and SECONDARY selections; for CLIPBOARD, check
-     if the clipboard currently has valid text format contents. */
+     if the clipboard currently has valid text format contents.  */
 
   if (EQ (selection, QCLIPBOARD))
     {
@@ -1050,14 +1052,14 @@ and t is the same as `SECONDARY'.  */)
 }
 
 /* One-time init.  Called in the un-dumped Emacs, but not in the
-   dumped version. */
+   dumped version.  */
 
 void
 syms_of_w32select (void)
 {
   defsubr (&Sw32_set_clipboard_data);
   defsubr (&Sw32_get_clipboard_data);
-  defsubr (&Sx_selection_exists_p);
+  defsubr (&Sw32_selection_exists_p);
 
   DEFVAR_LISP ("selection-coding-system", Vselection_coding_system,
               doc: /* Coding system for communicating with other programs.
@@ -1138,4 +1140,3 @@ globals_of_w32select (void)
 
   clipboard_owner = create_owner ();
 }
-