1 /* Unicode character output to streams with locale dependent encoding.
2 
3    Copyright (C) 2000-2003, 2005, 2008-2018 Free Software Foundation, Inc.
4 
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
17 
18 #ifndef UNICODEIO_H
19 # define UNICODEIO_H
20 
21 # include <stddef.h>
22 # include <stdio.h>
23 
24 /* Converts the Unicode character CODE to its multibyte representation
25    in the current locale and calls the SUCCESS callback on the resulting
26    byte sequence.  If an error occurs, invokes the FAILURE callback instead,
27    passing it CODE and an English error string.
28    Returns whatever the callback returned.
29    Assumes that the locale doesn't change between two calls.  */
30 extern long unicode_to_mb (unsigned int code,
31                            long (*success) (const char *buf, size_t buflen,
32                                             void *callback_arg),
33                            long (*failure) (unsigned int code, const char *msg,
34                                             void *callback_arg),
35                            void *callback_arg);
36 
37 /* Outputs the Unicode character CODE to the output stream STREAM.
38    Upon failure, exit if exit_on_error is true, otherwise output a fallback
39    notation.  */
40 extern void print_unicode_char (FILE *stream, unsigned int code,
41                                 int exit_on_error);
42 
43 /* Simple success callback that outputs the converted string.
44    The STREAM is passed as callback_arg.  */
45 extern long fwrite_success_callback (const char *buf, size_t buflen,
46                                      void *callback_arg);
47 
48 #endif
49