1 /* Keeping track of the flags that apply to a string extracted
2 in a certain context.
3 Copyright (C) 2001-2018, 2020, 2023 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 _XGETTEXT_ARGLIST_CONTEXT_H
19 #define _XGETTEXT_ARGLIST_CONTEXT_H
20
21 #include <stdbool.h>
22
23 #include "mem-hash-map.h"
24 #include "message.h"
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30
31 /* Context representing some flags. */
32 typedef struct flag_context_ty flag_context_ty;
33 struct flag_context_ty
34 {
35 /* Regarding the primary formatstring type. */
36 /*enum is_format*/ unsigned int is_format1 : 3;
37 /*bool*/ unsigned int pass_format1 : 1;
38 /* Regarding the secondary formatstring type. */
39 /*enum is_format*/ unsigned int is_format2 : 3;
40 /*bool*/ unsigned int pass_format2 : 1;
41 /* Regarding the tertiary formatstring type. */
42 /*enum is_format*/ unsigned int is_format3 : 3;
43 /*bool*/ unsigned int pass_format3 : 1;
44 /* Regarding the fourth-ranked formatstring type. */
45 /*enum is_format*/ unsigned int is_format4 : 3;
46 /*bool*/ unsigned int pass_format4 : 1;
47 };
48 /* Null context. */
49 extern flag_context_ty null_context;
50 /* Transparent context. */
51 extern flag_context_ty passthrough_context;
52 /* Compute an inherited context.
53 The outer_context is assumed to have all pass_format* flags = false.
54 The result will then also have all pass_format* flags = false. */
55 extern flag_context_ty
56 inherited_context (flag_context_ty outer_context,
57 flag_context_ty modifier_context);
58
59 /* Context representing some flags, for each possible argument number.
60 This is a linked list, sorted according to the argument number. */
61 typedef struct flag_context_list_ty flag_context_list_ty;
62 struct flag_context_list_ty
63 {
64 int argnum; /* current argument number, > 0 */
65 flag_context_ty flags; /* flags for current argument */
66 flag_context_list_ty *next;
67 };
68
69 /* Iterator through a flag_context_list_ty. */
70 typedef struct flag_context_list_iterator_ty flag_context_list_iterator_ty;
71 struct flag_context_list_iterator_ty
72 {
73 int argnum; /* current argument number, > 0 */
74 const flag_context_list_ty* head; /* tail of list */
75 };
76 extern flag_context_list_iterator_ty null_context_list_iterator;
77 extern flag_context_list_iterator_ty passthrough_context_list_iterator;
78 extern flag_context_list_iterator_ty
79 flag_context_list_iterator (flag_context_list_ty *list);
80 extern flag_context_ty
81 flag_context_list_iterator_advance (flag_context_list_iterator_ty *iter);
82
83 /* For nearly each backend, we have a separate table mapping a keyword to
84 a flag_context_list_ty *. */
85 typedef hash_table /* char[] -> flag_context_list_ty * */
86 flag_context_list_table_ty;
87 extern flag_context_list_ty *
88 flag_context_list_table_lookup (flag_context_list_table_ty *flag_table,
89 const void *key, size_t keylen);
90 /* Insert the pair (VALUE, PASS) as (is_formatX, pass_formatX) with X = INDEX+1
91 in the flags of the element numbered ARGNUM of the list corresponding to NAME
92 in the TABLE. */
93 extern void
94 flag_context_list_table_add (flag_context_list_table_ty *table,
95 unsigned int index,
96 const char *name_start, const char *name_end,
97 int argnum, enum is_format value, bool pass);
98
99
100 #ifdef __cplusplus
101 }
102 #endif
103
104
105 #endif /* _XGETTEXT_ARGLIST_CONTEXT_H */