aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Colascione2012-10-29 09:24:29 -0800
committerDaniel Colascione2012-10-29 09:24:29 -0800
commitba11600816880f862a7a85899bfa3dc41c176273 (patch)
tree18f4f2ed554b2e93a1d2588a25e7df1d9339fbde /src
parentd7f9cc85284bc159166d1c600100b0080bfad494 (diff)
downloademacs-ba11600816880f862a7a85899bfa3dc41c176273.tar.gz
emacs-ba11600816880f862a7a85899bfa3dc41c176273.zip
2012-10-29 Daniel Colascione <dancol@dancol.org>
cygw32.h, cygw32.c (Qutf_16le, from_unicode, to_unicode): In preparation for fixing bug#12739, move these functions from here... * coding.h, coding.c: ... to here, and compile them only when WINDOWSNT or HAVE_NTGUI. Moving these functions out of cygw32 proper lets us write cygw32-agnostic code for the HAVE_NTGUI case.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog10
-rw-r--r--src/coding.c42
-rw-r--r--src/coding.h22
-rw-r--r--src/cygw32.c33
-rw-r--r--src/cygw32.h14
5 files changed, 74 insertions, 47 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index beec867d333..c76bbb5a260 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,13 @@
12012-10-29 Daniel Colascione <dancol@dancol.org>
2
3 * cygw32.h, cygw32.c (Qutf_16le, from_unicode, to_unicode): In
4 preparation for fixing bug#12739, move these functions from
5 here...
6
7 * coding.h, coding.c: ... to here, and compile them only when
8 WINDOWSNT or HAVE_NTGUI. Moving these functions out of cygw32
9 proper lets us write cygw32-agnostic code for the HAVE_NTGUI case.
10
12012-10-28 Eli Zaretskii <eliz@gnu.org> 112012-10-28 Eli Zaretskii <eliz@gnu.org>
2 12
3 * w32proc.c (TIMER_TICKS_PER_SEC): New macro. 13 * w32proc.c (TIMER_TICKS_PER_SEC): New macro.
diff --git a/src/coding.c b/src/coding.c
index 7628a9fbf2e..611f92ea152 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -343,6 +343,10 @@ Lisp_Object Qcoding_system_p, Qcoding_system_error;
343Lisp_Object Qemacs_mule, Qraw_text; 343Lisp_Object Qemacs_mule, Qraw_text;
344Lisp_Object Qutf_8_emacs; 344Lisp_Object Qutf_8_emacs;
345 345
346#if defined (WINDOWSNT) || defined (HAVE_NTGUI)
347static Lisp_Object Qutf_16le;
348#endif
349
346/* Coding-systems are handed between Emacs Lisp programs and C internal 350/* Coding-systems are handed between Emacs Lisp programs and C internal
347 routines by the following three variables. */ 351 routines by the following three variables. */
348/* Coding system to be used to encode text for terminal display when 352/* Coding system to be used to encode text for terminal display when
@@ -7971,6 +7975,39 @@ preferred_coding_system (void)
7971 return CODING_ID_NAME (id); 7975 return CODING_ID_NAME (id);
7972} 7976}
7973 7977
7978#if defined (WINDOWSNT) || defined (HAVE_NTGUI)
7979
7980Lisp_Object
7981from_unicode (Lisp_Object str)
7982{
7983 CHECK_STRING (str);
7984 if (!STRING_MULTIBYTE (str) &&
7985 SBYTES (str) & 1)
7986 {
7987 str = Fsubstring (str, make_number (0), make_number (-1));
7988 }
7989
7990 return code_convert_string_norecord (str, Qutf_16le, 0);
7991}
7992
7993wchar_t *
7994to_unicode (Lisp_Object str, Lisp_Object *buf)
7995{
7996 *buf = code_convert_string_norecord (str, Qutf_16le, 1);
7997 /* We need to make a another copy (in addition to the one made by
7998 code_convert_string_norecord) to ensure that the final string is
7999 _doubly_ zero terminated --- that is, that the string is
8000 terminated by two zero bytes and one utf-16le null character.
8001 Because strings are already terminated with a single zero byte,
8002 we just add one additional zero. */
8003 str = make_uninit_string (SBYTES (*buf) + 1);
8004 memcpy (SDATA (str), SDATA (*buf), SBYTES (*buf));
8005 SDATA (str) [SBYTES (*buf)] = '\0';
8006 *buf = str;
8007 return WCSDATA (*buf);
8008}
8009#endif /* WINDOWSNT || HAVE_NTGUI */
8010
7974 8011
7975#ifdef emacs 8012#ifdef emacs
7976/*** 8. Emacs Lisp library functions ***/ 8013/*** 8. Emacs Lisp library functions ***/
@@ -10284,6 +10321,11 @@ syms_of_coding (void)
10284 DEFSYM (Qutf_8, "utf-8"); 10321 DEFSYM (Qutf_8, "utf-8");
10285 DEFSYM (Qutf_8_emacs, "utf-8-emacs"); 10322 DEFSYM (Qutf_8_emacs, "utf-8-emacs");
10286 10323
10324#if defined (WINDOWSNT) || defined (HAVE_NTGUI)
10325 /* No, not utf-16-le: that one has a BOM. */
10326 DEFSYM (Qutf_16le, "utf-16le");
10327#endif
10328
10287 DEFSYM (Qutf_16, "utf-16"); 10329 DEFSYM (Qutf_16, "utf-16");
10288 DEFSYM (Qbig, "big"); 10330 DEFSYM (Qbig, "big");
10289 DEFSYM (Qlittle, "little"); 10331 DEFSYM (Qlittle, "little");
diff --git a/src/coding.h b/src/coding.h
index 989552bf667..6ba5f8e0e1e 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -701,6 +701,28 @@ extern void encode_coding_object (struct coding_system *,
701 Lisp_Object, ptrdiff_t, ptrdiff_t, 701 Lisp_Object, ptrdiff_t, ptrdiff_t,
702 ptrdiff_t, ptrdiff_t, Lisp_Object); 702 ptrdiff_t, ptrdiff_t, Lisp_Object);
703 703
704#if defined (WINDOWSNT) || defined (HAVE_NTGUI)
705
706/* These functions use Lisp string objects to store the UTF-16LE
707 strings that modern versions of Windows expect. These strings are
708 not particularly useful to Lisp, and all Lisp strings should be
709 native Emacs multibyte. */
710
711/* Access the wide-character string stored in a Lisp string object. */
712#define WCSDATA(x) ((wchar_t *) SDATA (x))
713
714/* Convert the multi-byte string in STR to UTF-16LE encoded unibyte
715 string, and store it in *BUF. BUF may safely point to STR on entry. */
716extern wchar_t *to_unicode (Lisp_Object str, Lisp_Object *buf);
717
718/* Convert STR, a UTF-16LE encoded string embedded in a unibyte string
719 object, to a multi-byte Emacs string and return it. This function
720 calls code_convert_string_norecord internally and has all its
721 failure modes. STR itself is not modified. */
722extern Lisp_Object from_unicode (Lisp_Object str);
723
724#endif /* WINDOWSNT || HAVE_NTGUI */
725
704/* Macros for backward compatibility. */ 726/* Macros for backward compatibility. */
705 727
706#define decode_coding_region(coding, from, to) \ 728#define decode_coding_region(coding, from, to) \
diff --git a/src/cygw32.c b/src/cygw32.c
index 8f63461da2a..54f2076a891 100644
--- a/src/cygw32.c
+++ b/src/cygw32.c
@@ -22,7 +22,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22#include "buffer.h" 22#include "buffer.h"
23#include <unistd.h> 23#include <unistd.h>
24#include <fcntl.h> 24#include <fcntl.h>
25static Lisp_Object Qutf_16le;
26 25
27static Lisp_Object 26static Lisp_Object
28fchdir_unwind (Lisp_Object dir_fd) 27fchdir_unwind (Lisp_Object dir_fd)
@@ -107,36 +106,6 @@ conv_filename_from_w32_unicode (const wchar_t* in, int absolute_p)
107 return unbind_to (count, DECODE_FILE (converted)); 106 return unbind_to (count, DECODE_FILE (converted));
108} 107}
109 108
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_16le, 0);
121}
122
123wchar_t *
124to_unicode (Lisp_Object str, Lisp_Object *buf)
125{
126 *buf = code_convert_string_norecord (str, Qutf_16le, 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", 109DEFUN ("cygwin-convert-path-to-windows",
141 Fcygwin_convert_path_to_windows, Scygwin_convert_path_to_windows, 110 Fcygwin_convert_path_to_windows, Scygwin_convert_path_to_windows,
142 1, 2, 0, 111 1, 2, 0,
@@ -162,8 +131,6 @@ DEFUN ("cygwin-convert-path-from-windows",
162void 131void
163syms_of_cygw32 (void) 132syms_of_cygw32 (void)
164{ 133{
165 /* No, not utf-16-le: that one has a BOM. */
166 DEFSYM (Qutf_16le, "utf-16le");
167 defsubr (&Scygwin_convert_path_from_windows); 134 defsubr (&Scygwin_convert_path_from_windows);
168 defsubr (&Scygwin_convert_path_to_windows); 135 defsubr (&Scygwin_convert_path_to_windows);
169} 136}
diff --git a/src/cygw32.h b/src/cygw32.h
index 78e77a9a141..51571913fd1 100644
--- a/src/cygw32.h
+++ b/src/cygw32.h
@@ -33,20 +33,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
33#include "lisp.h" 33#include "lisp.h"
34#include "coding.h" 34#include "coding.h"
35 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 multi-byte string in STR to UTF-16LE encoded unibyte
42 string, and store it in *BUF. BUF may safely point to STR on entry. */
43extern wchar_t *to_unicode (Lisp_Object str, Lisp_Object *buf);
44
45/* Convert STR, a UTF-16LE encoded string embedded in a unibyte string
46 object, to a multi-byte Emacs string, and return it. */
47extern Lisp_Object from_unicode (Lisp_Object str);
48
49/* *** Misc *** */
50extern void syms_of_cygw32 (void); 36extern void syms_of_cygw32 (void);
51extern char * w32_strerror (int error_no); 37extern char * w32_strerror (int error_no);
52 38