Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayfunc.h
More file actions
Latest commit
194 lines (151 loc) · 6.28 KB
/
Copy patharrayfunc.h
File metadata and controls
194 lines (151 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/* arrayfunc.h -- declarations for miscellaneous array functions in arrayfunc.c */
/* Copyright (C) 2001-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Bash is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Bash. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined (_ARRAYFUNC_H_)
#define_ARRAYFUNC_H_
/* Must include variables.h before including this file. */
/* An object to encapsulate the state of an array element. It can describe
an array assignment A[KEY]=VALUE or a[IND]=VALUE depending on TYPE, or
for passing array subscript references around, where VALUE would be
${a[IND]} or ${A[KEY]}. This is not dependent on ARRAY_VARS so we can
use it in function parameters. */
/* values for `type' field */
#defineARRAY_INVALID -1
#defineARRAY_SCALAR 0
#defineARRAY_INDEXED 1
#defineARRAY_ASSOC 2
/* KEY will contain allocated memory if called through the assign_array_element
code path because of how assoc_insert works. */
typedefstructelement_state
{
shorttype; /* assoc or indexed, says which fields are valid */
shortsubtype; /* `*', `@', or something else */
arrayind_tind;
char*key; /* can be allocated memory */
char*value;
} array_eltstate_t;
#if defined (ARRAY_VARS)
/* This variable means to not expand associative or indexed array subscripts
more than once, when performing variable expansion. */
externintarray_expand_once;
/* Flags for array_value_internal and callers array_value/get_array_value; also
used by array_variable_name and array_variable_part. */
#defineAV_ALLOWALL 0x001 /* treat a[@] like $@ and a[*] like $* */
#defineAV_QUOTED 0x002
#defineAV_USEIND 0x004
#defineAV_USEVAL 0x008 /* XXX - should move this */
#defineAV_ASSIGNRHS 0x010 /* no splitting, special case ${a[@]} */
#defineAV_NOEXPAND 0x020 /* don't run assoc subscripts through word expansion */
#defineAV_ONEWORD 0x040 /* not used yet */
#defineAV_ATSTARKEYS 0x080 /* accept a[@] and a[*] but use them as keys, not special values */
/* Flags for valid_array_reference. Value 1 is reserved for skipsubscript().
Also used by unbind_array_element, which is currently the only function
that uses VA_ALLOWALL. */
#defineVA_NOEXPAND 0x001
#defineVA_ONEWORD 0x002
#defineVA_ALLOWALL 0x004 /* allow @ to mean all elements of the array */
externSHELL_VAR*convert_var_to_array (SHELL_VAR*);
externSHELL_VAR*convert_var_to_assoc (SHELL_VAR*);
externSHELL_VAR*arrayvar_copyval (SHELL_VAR*, SHELL_VAR*);
externchar*make_array_variable_value (SHELL_VAR*, arrayind_t, constchar*, constchar*, int);
externSHELL_VAR*bind_array_variable (constchar*, arrayind_t, constchar*, int);
externSHELL_VAR*bind_array_element (SHELL_VAR*, arrayind_t, char*, int);
externSHELL_VAR*assign_array_element (constchar*, constchar*, int, array_eltstate_t*);
externSHELL_VAR*bind_assoc_variable (SHELL_VAR*, constchar*, char*, constchar*, int);
externSHELL_VAR*find_or_make_array_variable (constchar*, int);
externSHELL_VAR*assign_array_from_string (constchar*, char*, int);
externSHELL_VAR*assign_array_var_from_word_list (SHELL_VAR*, WORD_LIST*, int);
externWORD_LIST*expand_compound_array_assignment (SHELL_VAR*, char*, int);
externintassign_compound_array_list (SHELL_VAR*, WORD_LIST*, int);
externSHELL_VAR*assign_array_var_from_string (SHELL_VAR*, char*, int);
externchar*expand_and_quote_assoc_word (char*, int);
externvoidquote_compound_array_list (WORD_LIST*, int);
externintkvpair_assignment_p (WORD_LIST*);
externchar*expand_and_quote_kvpair_word (constchar*);
externintunbind_array_element (SHELL_VAR*, char*, int);
externintskipsubscript (constchar*, int, int);
externvoidprint_array_assignment (SHELL_VAR*, int);
externvoidprint_assoc_assignment (SHELL_VAR*, int);
externarrayind_tarray_expand_index (SHELL_VAR*, constchar*, int, int);
externintvalid_array_reference (constchar*, int);
externinttokenize_array_reference (constchar*, int, char**);
externchar*array_value (constchar*, int, int, array_eltstate_t*);
externchar*get_array_value (constchar*, int, array_eltstate_t*);
externchar*array_keys (constchar*, int, int);
externchar*array_variable_name (constchar*, int, char**, int*);
externSHELL_VAR*array_variable_part (constchar*, int, char**, int*);
externvoidinit_eltstate (array_eltstate_t*);
externvoidflush_eltstate (array_eltstate_t*);
#else
#defineAV_ALLOWALL 0
#defineAV_QUOTED 0
#defineAV_USEIND 0
#defineAV_USEVAL 0
#defineAV_ASSIGNRHS 0
#defineAV_NOEXPAND 0
#defineAV_ONEWORD 0
#defineAV_ATSTARKEYS 0
#defineVA_NOEXPAND 0
#defineVA_ONEWORD 0
#defineVA_ALLOWALL 0
#endif
/* Functions to convert from other flag values to AV_ array variable flags */
#if defined (ASS_NOEXPAND)
staticinlineint
convert_assign_flags_to_arrayval_flags (intaflags)
{
intavflags;
avflags=0;
if (aflags&ASS_NOEXPAND)
avflags |= AV_NOEXPAND;
if (aflags&ASS_ONEWORD)
avflags |= AV_ONEWORD;
if (aflags&ASS_NOEVAL)
avflags |= AV_NOEXPAND;
if (aflags&ASS_ALLOWALLSUB)
avflags |= AV_ATSTARKEYS;
returnavflags;
}
#endif
#if defined (VA_NOEXPAND)
staticinlineint
convert_validarray_flags_to_arrayval_flags (intvflags)
{
intavflags;
avflags=0;
if (vflags&VA_NOEXPAND)
avflags |= AV_NOEXPAND;
if (vflags&VA_ONEWORD)
avflags |= AV_ONEWORD;
if (vflags&VA_ALLOWALL)
avflags |= AV_ATSTARKEYS;
returnavflags;
}
#endif
#if defined (ASS_NOEXPAND)
staticinlineint
convert_assign_flags_to_validarray_flags (intflags)
{
intvflags;
vflags=0;
if (flags&ASS_NOEXPAND)
vflags |= VA_NOEXPAND;
if (flags&ASS_ONEWORD)
vflags |= VA_ONEWORD;
if (flags&ASS_ALLOWALLSUB)
vflags |= VA_ALLOWALL;
returnvflags;
}
#endif
#endif/* !_ARRAYFUNC_H_ */