From ba11600816880f862a7a85899bfa3dc41c176273 Mon Sep 17 00:00:00 2001 From: Daniel Colascione Date: Mon, 29 Oct 2012 09:24:29 -0800 Subject: 2012-10-29 Daniel Colascione 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. --- src/coding.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/coding.c') 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; Lisp_Object Qemacs_mule, Qraw_text; Lisp_Object Qutf_8_emacs; +#if defined (WINDOWSNT) || defined (HAVE_NTGUI) +static Lisp_Object Qutf_16le; +#endif + /* Coding-systems are handed between Emacs Lisp programs and C internal routines by the following three variables. */ /* Coding system to be used to encode text for terminal display when @@ -7971,6 +7975,39 @@ preferred_coding_system (void) return CODING_ID_NAME (id); } +#if defined (WINDOWSNT) || defined (HAVE_NTGUI) + +Lisp_Object +from_unicode (Lisp_Object str) +{ + CHECK_STRING (str); + if (!STRING_MULTIBYTE (str) && + SBYTES (str) & 1) + { + str = Fsubstring (str, make_number (0), make_number (-1)); + } + + return code_convert_string_norecord (str, Qutf_16le, 0); +} + +wchar_t * +to_unicode (Lisp_Object str, Lisp_Object *buf) +{ + *buf = code_convert_string_norecord (str, Qutf_16le, 1); + /* We need to make a another copy (in addition to the one made by + code_convert_string_norecord) to ensure that the final string is + _doubly_ zero terminated --- that is, that the string is + terminated by two zero bytes and one utf-16le null character. + Because strings are already terminated with a single zero byte, + we just add one additional zero. */ + str = make_uninit_string (SBYTES (*buf) + 1); + memcpy (SDATA (str), SDATA (*buf), SBYTES (*buf)); + SDATA (str) [SBYTES (*buf)] = '\0'; + *buf = str; + return WCSDATA (*buf); +} +#endif /* WINDOWSNT || HAVE_NTGUI */ + #ifdef emacs /*** 8. Emacs Lisp library functions ***/ @@ -10284,6 +10321,11 @@ syms_of_coding (void) DEFSYM (Qutf_8, "utf-8"); DEFSYM (Qutf_8_emacs, "utf-8-emacs"); +#if defined (WINDOWSNT) || defined (HAVE_NTGUI) + /* No, not utf-16-le: that one has a BOM. */ + DEFSYM (Qutf_16le, "utf-16le"); +#endif + DEFSYM (Qutf_16, "utf-16"); DEFSYM (Qbig, "big"); DEFSYM (Qlittle, "little"); -- cgit v1.2.1 From 7f590b0c3b25602499432bf986e7b593fc158c0b Mon Sep 17 00:00:00 2001 From: Daniel Colascione Date: Mon, 29 Oct 2012 17:56:38 -0800 Subject: Fix build break in non-Cygw32 Cygwin builds introduced in 2012-10-29T17:24:29Z!dancol@dancol.org. --- src/coding.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 611f92ea152..97268e0dcd8 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7975,7 +7975,7 @@ preferred_coding_system (void) return CODING_ID_NAME (id); } -#if defined (WINDOWSNT) || defined (HAVE_NTGUI) +#if defined (WINDOWSNT) || defined (CYGWIN) Lisp_Object from_unicode (Lisp_Object str) @@ -8006,7 +8006,8 @@ to_unicode (Lisp_Object str, Lisp_Object *buf) *buf = str; return WCSDATA (*buf); } -#endif /* WINDOWSNT || HAVE_NTGUI */ + +#endif /* WINDOWSNT || CYGWIN */ #ifdef emacs @@ -10321,7 +10322,7 @@ syms_of_coding (void) DEFSYM (Qutf_8, "utf-8"); DEFSYM (Qutf_8_emacs, "utf-8-emacs"); -#if defined (WINDOWSNT) || defined (HAVE_NTGUI) +#if defined (WINDOWSNT) || defined (CYGWIN) /* No, not utf-16-le: that one has a BOM. */ DEFSYM (Qutf_16le, "utf-16le"); #endif -- cgit v1.2.1 From 53372c278e7e79b97aed97b159a00bde45de3a80 Mon Sep 17 00:00:00 2001 From: Daniel Colascione Date: Mon, 29 Oct 2012 19:10:52 -0800 Subject: Complete fix for build break --- src/coding.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 97268e0dcd8..56202e4861d 100644 --- a/src/coding.c +++ b/src/coding.c @@ -343,7 +343,7 @@ Lisp_Object Qcoding_system_p, Qcoding_system_error; Lisp_Object Qemacs_mule, Qraw_text; Lisp_Object Qutf_8_emacs; -#if defined (WINDOWSNT) || defined (HAVE_NTGUI) +#if defined (WINDOWSNT) || defined (CYGWIN) static Lisp_Object Qutf_16le; #endif -- cgit v1.2.1