From c1e37901fc8486c9960d7290e521ba51e292e94b Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 18 Apr 2006 21:55:01 +0000 Subject: updated for version 7.0e02 --- src/gui.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/gui.h') diff --git a/src/gui.h b/src/gui.h index f221c2981..36156f9dd 100644 --- a/src/gui.h +++ b/src/gui.h @@ -504,3 +504,46 @@ typedef enum # define FRD_WHOLE_WORD 0x08 /* match whole word only */ # define FRD_MATCH_CASE 0x10 /* match case */ #endif + +#ifdef HAVE_GTK2 +/* + * Convenience macros to convert from 'encoding' to 'termencoding' and + * vice versa. If no conversion is necessary the passed-in pointer is + * returned as is, without allocating any memory. Thus additional _FREE() + * macros are provided. The _FREE() macros also set the pointer to NULL, + * in order to avoid bugs due to illegal memory access only happening if + * 'encoding' != utf-8... + * + * Defining these macros as pure expressions looks a bit tricky but + * avoids depending on the context of the macro expansion. One of the + * rare occasions where the comma operator comes in handy :) + * + * Note: Do NOT keep the result around when handling control back to + * the main Vim! The user could change 'encoding' at any time. + */ +# define CONVERT_TO_UTF8(String) \ + ((output_conv.vc_type == CONV_NONE || (String) == NULL) \ + ? (String) \ + : string_convert(&output_conv, (String), NULL)) + +# define CONVERT_TO_UTF8_FREE(String) \ + ((String) = ((output_conv.vc_type == CONV_NONE) \ + ? (char_u *)NULL \ + : (vim_free(String), (char_u *)NULL))) + +# define CONVERT_FROM_UTF8(String) \ + ((input_conv.vc_type == CONV_NONE || (String) == NULL) \ + ? (String) \ + : string_convert(&input_conv, (String), NULL)) + +# define CONVERT_FROM_UTF8_FREE(String) \ + ((String) = ((input_conv.vc_type == CONV_NONE) \ + ? (char_u *)NULL \ + : (vim_free(String), (char_u *)NULL))) + +#else +# define CONVERT_TO_UTF8(String) (String) +# define CONVERT_TO_UTF8_FREE(String) ((String) = (char_u *)NULL) +# define CONVERT_FROM_UTF8(String) (String) +# define CONVERT_FROM_UTF8_FREE(String) ((String) = (char_u *)NULL) +#endif /* HAVE_GTK2 */ -- cgit v1.2.1