diff options
| author | Daniel Colascione | 2012-09-17 03:57:03 -0800 |
|---|---|---|
| committer | Daniel Colascione | 2012-09-17 03:57:03 -0800 |
| commit | f701ab72dd55460d23c8b029550aa4d7ecef3cfa (patch) | |
| tree | 102096ca8ca013f1f90f35154c78e78f9b40cc6c /src | |
| parent | efc3dd3ccceae28db0a3fde54ed00478ff77c2e2 (diff) | |
| download | emacs-f701ab72dd55460d23c8b029550aa4d7ecef3cfa.tar.gz emacs-f701ab72dd55460d23c8b029550aa4d7ecef3cfa.zip | |
Add files somehow forgotten by bzr git-apply.
Diffstat (limited to 'src')
| -rw-r--r-- | src/cygw32.c | 169 | ||||
| -rw-r--r-- | src/cygw32.h | 59 | ||||
| -rw-r--r-- | src/w32select.h | 30 |
3 files changed, 258 insertions, 0 deletions
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 | |||
| 4 | This file is part of GNU Emacs. | ||
| 5 | |||
| 6 | GNU Emacs is free software: you can redistribute it and/or modify | ||
| 7 | it under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation, either version 3 of the License, or | ||
| 9 | (at your option) any later version. | ||
| 10 | |||
| 11 | GNU Emacs is distributed in the hope that it will be useful, | ||
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along 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> | ||
| 25 | static Lisp_Object Qutf_16_le; | ||
| 26 | |||
| 27 | static Lisp_Object | ||
| 28 | fchdir_unwind (Lisp_Object dir_fd) | ||
| 29 | { | ||
| 30 | (void) fchdir (XFASTINT (dir_fd)); | ||
| 31 | (void) close (XFASTINT (dir_fd)); | ||
| 32 | return Qnil; | ||
| 33 | } | ||
| 34 | |||
| 35 | static void | ||
| 36 | chdir_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 | |||
| 55 | static Lisp_Object | ||
| 56 | conv_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 | |||
| 84 | static Lisp_Object | ||
| 85 | conv_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 | |||
| 110 | Lisp_Object | ||
| 111 | from_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 | |||
| 123 | wchar_t * | ||
| 124 | to_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 | |||
| 140 | DEFUN ("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 | |||
| 151 | DEFUN ("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 | |||
| 162 | void | ||
| 163 | syms_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 | |||
| 4 | This file is part of GNU Emacs. | ||
| 5 | |||
| 6 | GNU Emacs is free software: you can redistribute it and/or modify | ||
| 7 | it under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation, either version 3 of the License, or | ||
| 9 | (at your option) any later version. | ||
| 10 | |||
| 11 | GNU Emacs is distributed in the hope that it will be useful, | ||
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along 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. */ | ||
| 44 | extern 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. */ | ||
| 48 | extern Lisp_Object from_unicode (Lisp_Object str); | ||
| 49 | |||
| 50 | /* *** Path conversion. *** */ | ||
| 51 | |||
| 52 | EXFUN (Fcygwin_convert_path_to_windows, 2); | ||
| 53 | EXFUN (Fcygwin_convert_path_from_windows, 2); | ||
| 54 | |||
| 55 | /* *** Misc *** */ | ||
| 56 | extern void syms_of_cygw32 (void); | ||
| 57 | extern 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 | |||
| 3 | Copyright (C) 1993-1994, 2001-2011 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 | #ifndef W32SELECT_H | ||
| 21 | #define W32SELECT_H | ||
| 22 | #include <windows.h> | ||
| 23 | |||
| 24 | #define HAVE_W32SELECT 1 | ||
| 25 | |||
| 26 | extern void syms_of_w32select (void); | ||
| 27 | extern void globals_of_w32select (void); | ||
| 28 | extern void term_w32select (void); | ||
| 29 | |||
| 30 | #endif | ||