1 /* Keeping track of the encoding of strings to be extracted.
2 Copyright (C) 2001-2023 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 #include "string-desc.h"
27
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33
34 /* Context while building up lexical tokens. */
35 typedef enum
36 {
37 lc_outside, /* Initial context: outside of comments and strings. */
38 lc_comment, /* Inside a comment. */
39 lc_string, /* Inside a string literal. */
40
41 /* For embedded XML in programming code, like E4X in JavaScript. */
42 lc_xml_open_tag, /* Inside an opening tag of an XML element. */
43 lc_xml_close_tag, /* Inside a closing tag of an XML element. */
44 lc_xml_content /* Inside an XML text node. */
45 }
46 lexical_context_ty;
47
48 /* Error message about non-ASCII character in a specific lexical context. */
49 extern char *non_ascii_error_message (lexical_context_ty lcontext,
50 const char *file_name,
51 size_t line_number);
52
53
54 /* Canonicalized encoding name for all input files.
55 It can be NULL when the --from-code option has not been specified. In this
56 case, the default (ASCII or UTF-8) depends on the programming language. */
57 extern const char *xgettext_global_source_encoding;
58
59 #if HAVE_ICONV
60 /* Converter from xgettext_global_source_encoding to UTF-8 (except from
61 ASCII or UTF-8, when this conversion is a no-op). */
62 extern iconv_t xgettext_global_source_iconv;
63 #endif
64
65 /* Canonicalized encoding name for the current input file. */
66 extern const char *xgettext_current_source_encoding;
67
68 #if HAVE_ICONV
69 /* Converter from xgettext_current_source_encoding to UTF-8 (except from
70 ASCII or UTF-8, when this conversion is a no-op). */
71 extern iconv_t xgettext_current_source_iconv;
72 #endif
73
74 /* Convert the given string from xgettext_current_source_encoding to
75 the output file encoding (i.e. ASCII or UTF-8).
76 The resulting string is either the argument string, or freshly allocated.
77 The lcontext, file_name and line_number are only used for error message
78 purposes. */
79 extern char *from_current_source_encoding (const char *string,
80 lexical_context_ty lcontext,
81 const char *file_name,
82 size_t line_number);
83
84 /* Like from_current_source_encoding, for a string that may contain NULs. */
85 extern string_desc_t
86 string_desc_from_current_source_encoding (string_desc_t string,
87 lexical_context_ty lcontext,
88 const char *file_name,
89 size_t line_number);
90
91
92 #ifdef __cplusplus
93 }
94 #endif
95
96
97 #endif /* _XGETTEXT_ENCODING_H */