aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Colascione2012-09-17 03:57:03 -0800
committerDaniel Colascione2012-09-17 03:57:03 -0800
commitf701ab72dd55460d23c8b029550aa4d7ecef3cfa (patch)
tree102096ca8ca013f1f90f35154c78e78f9b40cc6c
parentefc3dd3ccceae28db0a3fde54ed00478ff77c2e2 (diff)
downloademacs-f701ab72dd55460d23c8b029550aa4d7ecef3cfa.tar.gz
emacs-f701ab72dd55460d23c8b029550aa4d7ecef3cfa.zip
Add files somehow forgotten by bzr git-apply.
-rw-r--r--lisp/w32-common-fns.el130
-rw-r--r--src/cygw32.c169
-rw-r--r--src/cygw32.h59
-rw-r--r--src/w32select.h30
4 files changed, 388 insertions, 0 deletions
diff --git a/lisp/w32-common-fns.el b/lisp/w32-common-fns.el
new file mode 100644
index 00000000000..fc045683394
--- /dev/null
+++ b/lisp/w32-common-fns.el
@@ -0,0 +1,130 @@
1;;; w32-common-fns.el --- Lisp routines for Windows and Cygwin-w32
2
3;; Copyright (C) 1994, 2001-2012 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
19
20;;; Commentary:
21;;;
22;;; This file contains functions that are used by both native NT Emacs
23;;; and Cygwin Emacs compiled to use the native Windows widget
24;;; library.
25
26(defun w32-version ()
27 "Return the MS-Windows version numbers.
28The value is a list of three integers: the major and minor version
29numbers, and the build number."
30 (x-server-version))
31
32(defun w32-using-nt ()
33 "Return non-nil if running on a Windows NT descendant.
34That includes all Windows systems except for 9X/Me."
35 (getenv "SystemRoot"))
36
37(declare-function w32-get-clipboard-data "w32select.c")
38(declare-function w32-set-clipboard-data "w32select.c")
39(declare-function x-server-version "w32fns.c" (&optional display))
40
41;;; Fix interface to (X-specific) mouse.el
42(defun x-set-selection (type data)
43 "Make an X selection of type TYPE and value DATA.
44The argument TYPE (nil means `PRIMARY') says which selection, and
45DATA specifies the contents. TYPE must be a symbol. \(It can also
46be a string, which stands for the symbol with that name, but this
47is considered obsolete.) DATA may be a string, a symbol, an
48integer (or a cons of two integers or list of two integers).
49
50The selection may also be a cons of two markers pointing to the same buffer,
51or an overlay. In these cases, the selection is considered to be the text
52between the markers *at whatever time the selection is examined*.
53Thus, editing done in the buffer after you specify the selection
54can alter the effective value of the selection.
55
56The data may also be a vector of valid non-vector selection values.
57
58The return value is DATA.
59
60Interactively, this command sets the primary selection. Without
61prefix argument, it reads the selection in the minibuffer. With
62prefix argument, it uses the text of the region as the selection value.
63
64Note that on MS-Windows, primary and secondary selections set by Emacs
65are not available to other programs."
66 (put 'x-selections (or type 'PRIMARY) data))
67
68(defun x-get-selection (&optional type _data-type)
69 "Return the value of an X Windows selection.
70The argument TYPE (default `PRIMARY') says which selection,
71and the argument DATA-TYPE (default `STRING') says
72how to convert the data.
73
74TYPE may be any symbol \(but nil stands for `PRIMARY'). However,
75only a few symbols are commonly used. They conventionally have
76all upper-case names. The most often used ones, in addition to
77`PRIMARY', are `SECONDARY' and `CLIPBOARD'.
78
79DATA-TYPE is usually `STRING', but can also be one of the symbols
80in `selection-converter-alist', which see."
81 (get 'x-selections (or type 'PRIMARY)))
82
83;; x-selection-owner-p is used in simple.el
84(defun x-selection-owner-p (&optional type)
85 (and (memq type '(nil PRIMARY SECONDARY))
86 (get 'x-selections (or type 'PRIMARY))))
87
88;; The "Windows" keys on newer keyboards bring up the Start menu
89;; whether you want it or not - make Emacs ignore these keystrokes
90;; rather than beep.
91(global-set-key [lwindow] 'ignore)
92(global-set-key [rwindow] 'ignore)
93
94(defvar w32-charset-info-alist) ; w32font.c
95
96
97;;;; Selections
98
99;; We keep track of the last text selected here, so we can check the
100;; current selection against it, and avoid passing back our own text
101;; from x-selection-value.
102(defvar x-last-selected-text nil)
103
104(defun x-get-selection-value ()
105 "Return the value of the current selection.
106Consult the selection. Treat empty strings as if they were unset."
107 (if x-select-enable-clipboard
108 (let (text)
109 ;; Don't die if x-get-selection signals an error.
110 (condition-case c
111 (setq text (w32-get-clipboard-data))
112 (error (message "w32-get-clipboard-data:%s" c)))
113 (if (string= text "") (setq text nil))
114 (cond
115 ((not text) nil)
116 ((eq text x-last-selected-text) nil)
117 ((string= text x-last-selected-text)
118 ;; Record the newer string, so subsequent calls can use the 'eq' test.
119 (setq x-last-selected-text text)
120 nil)
121 (t
122 (setq x-last-selected-text text))))))
123
124(defalias 'x-selection-value 'x-get-selection-value)
125
126;; Arrange for the kill and yank functions to set and check the clipboard.
127(setq interprogram-cut-function 'x-select-text)
128(setq interprogram-paste-function 'x-get-selection-value)
129
130(provide 'w32-common-fns)
diff --git a/src/cygw32.c b/src/cygw32.c
new file mode 100644
index 00000000000..065ab948118
--- /dev/null
+++ b/src/cygw32.c
@@ -0,0 +1,169 @@
1/* Cygwin support routines.
2 Copyright (C) 2011 Free Software Foundation, Inc.
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18
19
20#include "cygw32.h"
21#include "character.h"
22#include "buffer.h"
23#include <unistd.h>
24#include <fcntl.h>
25static Lisp_Object Qutf_16_le;
26
27static Lisp_Object
28fchdir_unwind (Lisp_Object dir_fd)
29{
30 (void) fchdir (XFASTINT (dir_fd));
31 (void) close (XFASTINT (dir_fd));
32 return Qnil;
33}
34
35static void
36chdir_to_default_directory ()
37{
38 Lisp_Object new_cwd;
39 int old_cwd_fd = open (".", O_RDONLY | O_DIRECTORY);
40
41 if (old_cwd_fd == -1)
42 error ("could not open current directory: %s", strerror (errno));
43
44 record_unwind_protect (fchdir_unwind, make_number (old_cwd_fd));
45
46 new_cwd = Funhandled_file_name_directory (
47 Fexpand_file_name (build_string ("."), Qnil));
48 if (!STRINGP (new_cwd))
49 new_cwd = build_string ("/");
50
51 if (chdir (SDATA (ENCODE_FILE (new_cwd))))
52 error ("could not chdir: %s", strerror (errno));
53}
54
55static Lisp_Object
56conv_filename_to_w32_unicode (Lisp_Object in, int absolute_p)
57{
58 ssize_t converted_len;
59 Lisp_Object converted;
60 unsigned flags;
61 int count = SPECPDL_INDEX ();
62
63 chdir_to_default_directory ();
64
65 flags = CCP_POSIX_TO_WIN_W;
66 if (!absolute_p) {
67 flags |= CCP_RELATIVE;
68 }
69
70 in = ENCODE_FILE (in);
71
72 converted_len = cygwin_conv_path (flags, SDATA (in), NULL, 0);
73 if (converted_len < 2)
74 error ("cygwin_conv_path: %s", strerror (errno));
75
76 converted = make_uninit_string (converted_len - 1);
77 if (cygwin_conv_path (flags, SDATA (in),
78 SDATA (converted), converted_len))
79 error ("cygwin_conv_path: %s", strerror (errno));
80
81 return unbind_to (count, converted);
82}
83
84static Lisp_Object
85conv_filename_from_w32_unicode (const wchar_t* in, int absolute_p)
86{
87 ssize_t converted_len;
88 Lisp_Object converted;
89 unsigned flags;
90 int count = SPECPDL_INDEX ();
91
92 chdir_to_default_directory ();
93
94 flags = CCP_WIN_W_TO_POSIX;
95 if (!absolute_p) {
96 flags |= CCP_RELATIVE;
97 }
98
99 converted_len = cygwin_conv_path (flags, in, NULL, 0);
100 if (converted_len < 1)
101 error ("cygwin_conv_path: %s", strerror (errno));
102
103 converted = make_uninit_string (converted_len - 1 /*subtract terminator*/);
104 if (cygwin_conv_path (flags, in, SDATA (converted), converted_len))
105 error ("cygwin_conv_path: %s", strerror (errno));
106
107 return unbind_to (count, DECODE_FILE (converted));
108}
109
110Lisp_Object
111from_unicode (Lisp_Object str)
112{
113 CHECK_STRING (str);
114 if (!STRING_MULTIBYTE (str) &&
115 SBYTES (str) & 1)
116 {
117 str = Fsubstring (str, make_number (0), make_number (-1));
118 }
119
120 return code_convert_string_norecord (str, Qutf_16_le, 0);
121}
122
123wchar_t *
124to_unicode (Lisp_Object str, Lisp_Object *buf)
125{
126 *buf = code_convert_string_norecord (str, Qutf_16_le, 1);
127 /* We need to make a another copy (in addition to the one made by
128 code_convert_string_norecord) to ensure that the final string is
129 _doubly_ zero terminated --- that is, that the string is
130 terminated by two zero bytes and one utf-16le null character.
131 Because strings are already terminated with a single zero byte,
132 we just add one additional zero. */
133 str = make_uninit_string (SBYTES (*buf) + 1);
134 memcpy (SDATA (str), SDATA (*buf), SBYTES (*buf));
135 SDATA (str) [SBYTES (*buf)] = '\0';
136 *buf = str;
137 return WCSDATA (*buf);
138}
139
140DEFUN ("cygwin-convert-path-to-windows",
141 Fcygwin_convert_path_to_windows, Scygwin_convert_path_to_windows,
142 1, 2, 0,
143 doc: /* Convert PATH to a Windows path. If ABSOLUTE-P if
144 non-nil, return an absolute path.*/)
145 (Lisp_Object path, Lisp_Object absolute_p)
146{
147 return from_unicode (
148 conv_filename_to_w32_unicode (path, absolute_p == Qnil ? 0 : 1));
149}
150
151DEFUN ("cygwin-convert-path-from-windows",
152 Fcygwin_convert_path_from_windows, Scygwin_convert_path_from_windows,
153 1, 2, 0,
154 doc: /* Convert a Windows path to a Cygwin path. If ABSOLUTE-P
155 if non-nil, return an absolute path.*/)
156 (Lisp_Object path, Lisp_Object absolute_p)
157{
158 return conv_filename_from_w32_unicode (to_unicode (path, &path),
159 absolute_p == Qnil ? 0 : 1);
160}
161
162void
163syms_of_cygw32 (void)
164{
165 /* No, not utf-16-le: that one has a BOM. */
166 DEFSYM (Qutf_16_le, "utf-16le");
167 defsubr (&Scygwin_convert_path_from_windows);
168 defsubr (&Scygwin_convert_path_to_windows);
169}
diff --git a/src/cygw32.h b/src/cygw32.h
new file mode 100644
index 00000000000..c63343c3f5a
--- /dev/null
+++ b/src/cygw32.h
@@ -0,0 +1,59 @@
1/* Header for Cygwin support routines.
2 Copyright (C) 2011 Free Software Foundation, Inc.
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18
19#ifndef CYGW32_H
20#define CYGW32_H
21#include <config.h>
22#include <windef.h>
23#include <sys/cygwin.h>
24#include <wchar.h>
25
26#include <signal.h>
27#include <stdio.h>
28#include <limits.h>
29#include <errno.h>
30#include <math.h>
31#include <setjmp.h>
32
33#include "lisp.h"
34#include "coding.h"
35
36/* *** Character conversion *** */
37
38/* Access the wide-character string stored in a Lisp string object. */
39#define WCSDATA(x) ((wchar_t *) SDATA (x))
40
41/* Convert the Emacs string in STR to UTF-16LE and store a new string
42 containing the encoded version of STR into *BUF. BUF may safely
43 point to STR on entry. */
44extern wchar_t *to_unicode (Lisp_Object str, Lisp_Object *buf);
45
46/* Convert STR, a UTF-16LE encoded string embedded in an Emacs string
47 object, to a normal Emacs string and return it. */
48extern Lisp_Object from_unicode (Lisp_Object str);
49
50/* *** Path conversion. *** */
51
52EXFUN (Fcygwin_convert_path_to_windows, 2);
53EXFUN (Fcygwin_convert_path_from_windows, 2);
54
55/* *** Misc *** */
56extern void syms_of_cygw32 (void);
57extern char * w32_strerror (int error_no);
58
59#endif /* CYGW32_H */
diff --git a/src/w32select.h b/src/w32select.h
new file mode 100644
index 00000000000..6924d4d51ae
--- /dev/null
+++ b/src/w32select.h
@@ -0,0 +1,30 @@
1/* Selection processing for Emacs on the Microsoft W32 API.
2
3Copyright (C) 1993-1994, 2001-2011 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20#ifndef W32SELECT_H
21#define W32SELECT_H
22#include <windows.h>
23
24#define HAVE_W32SELECT 1
25
26extern void syms_of_w32select (void);
27extern void globals_of_w32select (void);
28extern void term_w32select (void);
29
30#endif