1 /* xgettext common functions.
2 Copyright (C) 2001-2003 Free Software Foundation, Inc.
3 Written by Peter Miller <millerp@canb.auug.org.au>
4 and Bruno Haible <haible@clisp.cons.org>, 2001.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
34 /* Declare 'line_comment' and 'input_syntax'. */
43 /* If true, omit the header entry.
44 If false, keep the header entry present in the input. */
45 extern int xgettext_omit_header
;
47 extern bool substring_match
;
50 /* Split keyword spec into keyword, argnum1, argnum2. */
51 extern void split_keywordspec (const char *spec
, const char **endp
,
52 int *argnum1p
, int *argnum2p
);
55 /* Context representing some flags. */
56 typedef struct flag_context_ty flag_context_ty
;
57 struct flag_context_ty
59 /* Regarding the primary formatstring type. */
60 /*enum is_format*/ unsigned int is_format1
: 3;
61 /*bool*/ unsigned int pass_format1
: 1;
62 /* Regarding the secondary formatstring type. */
63 /*enum is_format*/ unsigned int is_format2
: 3;
64 /*bool*/ unsigned int pass_format2
: 1;
67 extern flag_context_ty null_context
;
68 /* Transparent context. */
69 extern flag_context_ty passthrough_context
;
70 /* Compute an inherited context.
71 The outer_context is assumed to have all pass_format* flags = false.
72 The result will then also have all pass_format* flags = false. */
73 extern flag_context_ty
74 inherited_context (flag_context_ty outer_context
,
75 flag_context_ty modifier_context
);
77 /* Context representing some flags, for each possible argument number.
78 This is a linked list, sorted according to the argument number. */
79 typedef struct flag_context_list_ty flag_context_list_ty
;
80 struct flag_context_list_ty
82 int argnum
; /* current argument number, > 0 */
83 flag_context_ty flags
; /* flags for current argument */
84 flag_context_list_ty
*next
;
87 /* Iterator through a flag_context_list_ty. */
88 typedef struct flag_context_list_iterator_ty flag_context_list_iterator_ty
;
89 struct flag_context_list_iterator_ty
91 int argnum
; /* current argument number, > 0 */
92 const flag_context_list_ty
* head
; /* tail of list */
94 extern flag_context_list_iterator_ty null_context_list_iterator
;
95 extern flag_context_list_iterator_ty passthrough_context_list_iterator
;
96 extern flag_context_list_iterator_ty
97 flag_context_list_iterator (flag_context_list_ty
*list
);
98 extern flag_context_ty
99 flag_context_list_iterator_advance (flag_context_list_iterator_ty
*iter
);
101 /* For nearly each backend, we have a separate table mapping a keyword to
102 a flag_context_list_ty *. */
103 typedef hash_table
/* char[] -> flag_context_list_ty * */
104 flag_context_list_table_ty
;
105 extern flag_context_list_ty
*
106 flag_context_list_table_lookup (flag_context_list_table_ty
*flag_table
,
107 const void *key
, size_t keylen
);
108 /* Record a flag in the appropriate backend's table. */
109 extern void xgettext_record_flag (const char *optionstring
);
112 /* Canonicalized encoding name for all input files. */
113 extern const char *xgettext_global_source_encoding
;
116 /* Converter from xgettext_global_source_encoding to UTF-8 (except from
117 ASCII or UTF-8, when this conversion is a no-op). */
118 extern iconv_t xgettext_global_source_iconv
;
121 /* Canonicalized encoding name for the current input file. */
122 extern const char *xgettext_current_source_encoding
;
125 /* Converter from xgettext_current_source_encoding to UTF-8 (except from
126 ASCII or UTF-8, when this conversion is a no-op). */
127 extern iconv_t xgettext_current_source_iconv
;
130 /* Convert the given string from xgettext_current_source_encoding to
131 the output file encoding (i.e. ASCII or UTF-8).
132 The resulting string is either the argument string, or freshly allocated.
133 The file_name and line_number are only used for error message purposes. */
134 extern char *from_current_source_encoding (const char *string
,
135 const char *file_name
,
139 /* List of messages whose msgids must not be extracted, or NULL.
140 Used by remember_a_message(). */
141 extern message_list_ty
*exclude
;
144 /* Comment handling: There is a list of automatic comments that may be appended
145 to the next message. Used by remember_a_message(). */
146 extern void xgettext_comment_add (const char *str
);
147 extern const char *xgettext_comment (size_t n
);
148 extern void xgettext_comment_reset (void);
151 /* Comment handling for backends which support combining adjacent strings
153 In these backends we cannot use the xgettext_comment* functions directly,
154 because in multiline string expressions like
157 the newline between "string1" and "string2" would cause a call to
158 xgettext_comment_reset(), thus destroying the accumulated comments
159 that we need a little later, when we have concatenated the two strings
160 and pass them to remember_a_message().
161 Instead, we do the bookkeeping of the accumulated comments directly,
162 and save a pointer to the accumulated comments when we read "string1".
163 In order to avoid excessive copying of strings, we use reference
166 typedef struct refcounted_string_list_ty refcounted_string_list_ty
;
167 struct refcounted_string_list_ty
169 unsigned int refcount
;
170 struct string_list_ty contents
;
173 static inline refcounted_string_list_ty
*
174 add_reference (refcounted_string_list_ty
*rslp
)
182 drop_reference (refcounted_string_list_ty
*rslp
)
186 if (rslp
->refcount
> 1)
190 string_list_destroy (&rslp
->contents
);
196 extern refcounted_string_list_ty
*savable_comment
;
197 extern void savable_comment_add (const char *str
);
198 extern void savable_comment_reset (void);
199 extern void savable_comment_to_xgettext_comment (refcounted_string_list_ty
*rslp
);
202 /* Add a message to the list of extracted messages.
203 string must be malloc()ed string; its ownership is passed to the callee.
204 pos->file_name must be allocated with indefinite extent. */
205 extern message_ty
*remember_a_message (message_list_ty
*mlp
,
207 flag_context_ty context
,
209 /* Add an msgid_plural to a message previously returned by
211 string must be malloc()ed string; its ownership is passed to the callee.
212 pos->file_name must be allocated with indefinite extent. */
213 extern void remember_a_message_plural (message_ty
*mp
,
215 flag_context_ty context
,
224 #endif /* _XGETTEXT_H */