1 /* Keeping track of the encoding of strings to be extracted.
2    Copyright (C) 2001-2019 Free Software Foundation, Inc.
3 
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3 of the License, or
7    (at your option) any later version.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
16 
17 #ifndef _XGETTEXT_ENCODING_H
18 #define _XGETTEXT_ENCODING_H
19 
20 #include <stddef.h>
21 
22 #if HAVE_ICONV
23 #include <iconv.h>
24 #endif
25 
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 
32 /* Context while building up lexical tokens.  */
33 typedef enum
34   {
35     lc_outside, /* Initial context: outside of comments and strings.  */
36     lc_comment, /* Inside a comment.  */
37     lc_string,  /* Inside a string literal.  */
38 
39     /* For embedded XML in programming code, like E4X in JavaScript.  */
40     lc_xml_open_tag,   /* Inside an opening tag of an XML element.  */
41     lc_xml_close_tag,  /* Inside a closing tag of an XML element.  */
42     lc_xml_content     /* Inside an XML text node.  */
43   }
44 lexical_context_ty;
45 
46 /* Error message about non-ASCII character in a specific lexical context.  */
47 extern char *non_ascii_error_message (lexical_context_ty lcontext,
48                                       const char *file_name,
49                                       size_t line_number);
50 
51 
52 /* Canonicalized encoding name for all input files.
53    It can be NULL when the --from-code option has not been specified.  In this
54    case, the default (ASCII or UTF-8) depends on the programming language.  */
55 extern const char *xgettext_global_source_encoding;
56 
57 #if HAVE_ICONV
58 /* Converter from xgettext_global_source_encoding to UTF-8 (except from
59    ASCII or UTF-8, when this conversion is a no-op).  */
60 extern iconv_t xgettext_global_source_iconv;
61 #endif
62 
63 /* Canonicalized encoding name for the current input file.  */
64 extern const char *xgettext_current_source_encoding;
65 
66 #if HAVE_ICONV
67 /* Converter from xgettext_current_source_encoding to UTF-8 (except from
68    ASCII or UTF-8, when this conversion is a no-op).  */
69 extern iconv_t xgettext_current_source_iconv;
70 #endif
71 
72 /* Convert the given string from xgettext_current_source_encoding to
73    the output file encoding (i.e. ASCII or UTF-8).
74    The resulting string is either the argument string, or freshly allocated.
75    The lcontext, file_name and line_number are only used for error message
76    purposes.  */
77 extern char *from_current_source_encoding (const char *string,
78                                            lexical_context_ty lcontext,
79                                            const char *file_name,
80                                            size_t line_number);
81 
82 
83 #ifdef __cplusplus
84 }
85 #endif
86 
87 
88 #endif /* _XGETTEXT_ENCODING_H */
89