]>
Commit | Line | Data |
---|---|---|
f73dda09 JA |
1 | /* arrayfunc.h -- declarations for miscellaneous array functions in arrayfunc.c */ |
2 | ||
b2613ad1 | 3 | /* Copyright (C) 2001-2023 Free Software Foundation, Inc. |
f73dda09 JA |
4 | |
5 | This file is part of GNU Bash, the Bourne Again SHell. | |
6 | ||
2e4498b3 CR |
7 | Bash is free software: you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation, either version 3 of the License, or | |
10 | (at your option) any later version. | |
f73dda09 | 11 | |
2e4498b3 CR |
12 | Bash is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
f73dda09 JA |
16 | |
17 | You should have received a copy of the GNU General Public License | |
2e4498b3 CR |
18 | along with Bash. If not, see <http://www.gnu.org/licenses/>. |
19 | */ | |
f73dda09 JA |
20 | |
21 | #if !defined (_ARRAYFUNC_H_) | |
22 | #define _ARRAYFUNC_H_ | |
23 | ||
24 | /* Must include variables.h before including this file. */ | |
25 | ||
b2b78a63 CR |
26 | /* An object to encapsulate the state of an array element. It can describe |
27 | an array assignment A[KEY]=VALUE or a[IND]=VALUE depending on TYPE, or | |
28 | for passing array subscript references around, where VALUE would be | |
29 | ${a[IND]} or ${A[KEY]}. This is not dependent on ARRAY_VARS so we can | |
30 | use it in function parameters. */ | |
31 | ||
32 | /* values for `type' field */ | |
33 | #define ARRAY_INVALID -1 | |
34 | #define ARRAY_SCALAR 0 | |
35 | #define ARRAY_INDEXED 1 | |
36 | #define ARRAY_ASSOC 2 | |
37 | ||
38 | /* KEY will contain allocated memory if called through the assign_array_element | |
39 | code path because of how assoc_insert works. */ | |
40 | typedef struct element_state | |
41 | { | |
42 | short type; /* assoc or indexed, says which fields are valid */ | |
43 | short subtype; /* `*', `@', or something else */ | |
44 | arrayind_t ind; | |
45 | char *key; /* can be allocated memory */ | |
46 | char *value; | |
47 | } array_eltstate_t; | |
48 | ||
f73dda09 JA |
49 | #if defined (ARRAY_VARS) |
50 | ||
76112093 CR |
51 | /* This variable means to not expand associative or indexed array subscripts |
52 | more than once, when performing variable expansion. */ | |
ec157dfe CR |
53 | extern int array_expand_once; |
54 | ||
1d17c604 CR |
55 | /* Flags for array_value_internal and callers array_value/get_array_value; also |
56 | used by array_variable_name and array_variable_part. */ | |
a30f513f | 57 | #define AV_ALLOWALL 0x001 /* treat a[@] like $@ and a[*] like $* */ |
5f8cde23 CR |
58 | #define AV_QUOTED 0x002 |
59 | #define AV_USEIND 0x004 | |
06c3a575 | 60 | #define AV_USEVAL 0x008 /* XXX - should move this */ |
13eae87b | 61 | #define AV_ASSIGNRHS 0x010 /* no splitting, special case ${a[@]} */ |
a57ed9e9 | 62 | #define AV_NOEXPAND 0x020 /* don't run assoc subscripts through word expansion */ |
a30f513f CR |
63 | #define AV_ONEWORD 0x040 /* not used yet */ |
64 | #define AV_ATSTARKEYS 0x080 /* accept a[@] and a[*] but use them as keys, not special values */ | |
5f8cde23 | 65 | |
0e513453 | 66 | /* Flags for valid_array_reference. Value 1 is reserved for skipsubscript(). |
fb4ddc2d CR |
67 | Also used by unbind_array_element, which is currently the only function |
68 | that uses VA_ALLOWALL. */ | |
5fab8dbf CR |
69 | #define VA_NOEXPAND 0x001 |
70 | #define VA_ONEWORD 0x002 | |
0e513453 | 71 | #define VA_ALLOWALL 0x004 /* allow @ to mean all elements of the array */ |
5fab8dbf | 72 | |
81e3a4fb CR |
73 | extern SHELL_VAR *convert_var_to_array (SHELL_VAR *); |
74 | extern SHELL_VAR *convert_var_to_assoc (SHELL_VAR *); | |
f73dda09 | 75 | |
4e4cebb6 CR |
76 | extern SHELL_VAR *arrayvar_copyval (SHELL_VAR *, SHELL_VAR *); |
77 | ||
b2613ad1 | 78 | extern char *make_array_variable_value (SHELL_VAR *, arrayind_t, const char *, const char *, int); |
861a1900 | 79 | |
b2613ad1 | 80 | extern SHELL_VAR *bind_array_variable (const char *, arrayind_t, const char *, int); |
81e3a4fb | 81 | extern SHELL_VAR *bind_array_element (SHELL_VAR *, arrayind_t, char *, int); |
b2613ad1 | 82 | extern SHELL_VAR *assign_array_element (const char *, const char *, int, array_eltstate_t *); |
f73dda09 | 83 | |
b2613ad1 | 84 | extern SHELL_VAR *bind_assoc_variable (SHELL_VAR *, const char *, char *, const char *, int); |
a3143574 | 85 | |
b2613ad1 | 86 | extern SHELL_VAR *find_or_make_array_variable (const char *, int); |
f73dda09 | 87 | |
b2613ad1 | 88 | extern SHELL_VAR *assign_array_from_string (const char *, char *, int); |
81e3a4fb | 89 | extern SHELL_VAR *assign_array_var_from_word_list (SHELL_VAR *, WORD_LIST *, int); |
d3ad40de | 90 | |
81e3a4fb | 91 | extern WORD_LIST *expand_compound_array_assignment (SHELL_VAR *, char *, int); |
6cca378e | 92 | extern int assign_compound_array_list (SHELL_VAR *, WORD_LIST *, int); |
81e3a4fb | 93 | extern SHELL_VAR *assign_array_var_from_string (SHELL_VAR *, char *, int); |
f73dda09 | 94 | |
81e3a4fb CR |
95 | extern char *expand_and_quote_assoc_word (char *, int); |
96 | extern void quote_compound_array_list (WORD_LIST *, int); | |
fdf670ea | 97 | |
81e3a4fb | 98 | extern int kvpair_assignment_p (WORD_LIST *); |
b2613ad1 | 99 | extern char *expand_and_quote_kvpair_word (const char *); |
11262b0b | 100 | |
81e3a4fb CR |
101 | extern int unbind_array_element (SHELL_VAR *, char *, int); |
102 | extern int skipsubscript (const char *, int, int); | |
f73dda09 | 103 | |
81e3a4fb CR |
104 | extern void print_array_assignment (SHELL_VAR *, int); |
105 | extern void print_assoc_assignment (SHELL_VAR *, int); | |
f73dda09 | 106 | |
b2613ad1 | 107 | extern arrayind_t array_expand_index (SHELL_VAR *, const char *, int, int); |
81e3a4fb | 108 | extern int valid_array_reference (const char *, int); |
b2613ad1 | 109 | extern int tokenize_array_reference (const char *, int, char **); |
4657c040 | 110 | |
81e3a4fb CR |
111 | extern char *array_value (const char *, int, int, array_eltstate_t *); |
112 | extern char *get_array_value (const char *, int, array_eltstate_t *); | |
d3a24ed2 | 113 | |
b2613ad1 | 114 | extern char *array_keys (const char *, int, int); |
c6c7ae81 | 115 | |
81e3a4fb CR |
116 | extern char *array_variable_name (const char *, int, char **, int *); |
117 | extern SHELL_VAR *array_variable_part (const char *, int, char **, int *); | |
f73dda09 | 118 | |
b2b78a63 CR |
119 | extern void init_eltstate (array_eltstate_t *); |
120 | extern void flush_eltstate (array_eltstate_t *); | |
121 | ||
c31d56a7 CR |
122 | #else |
123 | ||
124 | #define AV_ALLOWALL 0 | |
125 | #define AV_QUOTED 0 | |
126 | #define AV_USEIND 0 | |
a30f513f | 127 | #define AV_USEVAL 0 |
13eae87b | 128 | #define AV_ASSIGNRHS 0 |
a30f513f CR |
129 | #define AV_NOEXPAND 0 |
130 | #define AV_ONEWORD 0 | |
131 | #define AV_ATSTARKEYS 0 | |
c31d56a7 | 132 | |
0e513453 | 133 | #define VA_NOEXPAND 0 |
5fab8dbf | 134 | #define VA_ONEWORD 0 |
0e513453 | 135 | #define VA_ALLOWALL 0 |
5fab8dbf | 136 | |
f73dda09 JA |
137 | #endif |
138 | ||
76112093 CR |
139 | /* Functions to convert from other flag values to AV_ array variable flags */ |
140 | ||
141 | #if defined (ASS_NOEXPAND) | |
142 | static inline int | |
143 | convert_assign_flags_to_arrayval_flags (int aflags) | |
144 | { | |
145 | int avflags; | |
146 | ||
147 | avflags = 0; | |
148 | if (aflags & ASS_NOEXPAND) | |
149 | avflags |= AV_NOEXPAND; | |
150 | if (aflags & ASS_ONEWORD) | |
151 | avflags |= AV_ONEWORD; | |
152 | if (aflags & ASS_NOEVAL) | |
153 | avflags |= AV_NOEXPAND; | |
154 | if (aflags & ASS_ALLOWALLSUB) | |
155 | avflags |= AV_ATSTARKEYS; | |
156 | return avflags; | |
157 | } | |
158 | #endif | |
159 | ||
160 | #if defined (VA_NOEXPAND) | |
161 | static inline int | |
162 | convert_validarray_flags_to_arrayval_flags (int vflags) | |
163 | { | |
164 | int avflags; | |
165 | ||
81f7b445 | 166 | avflags = 0; |
76112093 CR |
167 | if (vflags & VA_NOEXPAND) |
168 | avflags |= AV_NOEXPAND; | |
169 | if (vflags & VA_ONEWORD) | |
170 | avflags |= AV_ONEWORD; | |
171 | if (vflags & VA_ALLOWALL) | |
172 | avflags |= AV_ATSTARKEYS; | |
173 | return avflags; | |
174 | } | |
175 | #endif | |
176 | ||
177 | #if defined (ASS_NOEXPAND) | |
178 | static inline int | |
179 | convert_assign_flags_to_validarray_flags (int flags) | |
180 | { | |
181 | int vflags; | |
182 | ||
183 | vflags = 0; | |
184 | if (flags & ASS_NOEXPAND) | |
185 | vflags |= VA_NOEXPAND; | |
186 | if (flags & ASS_ONEWORD) | |
187 | vflags |= VA_ONEWORD; | |
188 | if (flags & ASS_ALLOWALLSUB) | |
189 | vflags |= VA_ALLOWALL; | |
190 | return vflags; | |
191 | } | |
192 | #endif | |
193 | ||
f73dda09 | 194 | #endif /* !_ARRAYFUNC_H_ */ |