]>
Commit | Line | Data |
---|---|---|
ccc6cda3 JA |
1 | /* array.h -- definitions for the interface exported by array.c that allows |
2 | the rest of the shell to manipulate array variables. */ | |
bb70624e | 3 | |
3185942a | 4 | /* Copyright (C) 1997-2009 Free Software Foundation, Inc. |
bb70624e JA |
5 | |
6 | This file is part of GNU Bash, the Bourne Again SHell. | |
7 | ||
3185942a JA |
8 | Bash is free software: you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation, either version 3 of the License, or | |
11 | (at your option) any later version. | |
bb70624e | 12 | |
3185942a JA |
13 | Bash is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with Bash. If not, see <http://www.gnu.org/licenses/>. | |
20 | */ | |
bb70624e | 21 | |
bb70624e | 22 | |
ccc6cda3 JA |
23 | #ifndef _ARRAY_H_ |
24 | #define _ARRAY_H_ | |
25 | ||
26 | #include "stdc.h" | |
27 | ||
7117c2d2 | 28 | typedef intmax_t arrayind_t; |
ccc6cda3 JA |
29 | |
30 | enum atype {array_indexed, array_assoc}; | |
31 | ||
32 | typedef struct array { | |
33 | enum atype type; | |
7117c2d2 | 34 | arrayind_t max_index, num_elements; |
ccc6cda3 JA |
35 | struct array_element *head; |
36 | } ARRAY; | |
37 | ||
38 | typedef struct array_element { | |
39 | arrayind_t ind; | |
40 | char *value; | |
41 | struct array_element *next, *prev; | |
42 | } ARRAY_ELEMENT; | |
43 | ||
b80f6443 | 44 | typedef int sh_ae_map_func_t __P((ARRAY_ELEMENT *, void *)); |
f73dda09 | 45 | |
7117c2d2 JA |
46 | /* Basic operations on entire arrays */ |
47 | extern ARRAY *array_create __P((void)); | |
48 | extern void array_flush __P((ARRAY *)); | |
49 | extern void array_dispose __P((ARRAY *)); | |
50 | extern ARRAY *array_copy __P((ARRAY *)); | |
51 | extern ARRAY *array_slice __P((ARRAY *, ARRAY_ELEMENT *, ARRAY_ELEMENT *)); | |
b80f6443 | 52 | extern void array_walk __P((ARRAY *, sh_ae_map_func_t *, void *)); |
ccc6cda3 | 53 | |
7117c2d2 JA |
54 | extern ARRAY_ELEMENT *array_shift __P((ARRAY *, int, int)); |
55 | extern int array_rshift __P((ARRAY *, int, char *)); | |
b80f6443 JA |
56 | extern ARRAY_ELEMENT *array_unshift_element __P((ARRAY *)); |
57 | extern int array_shift_element __P((ARRAY *, char *)); | |
3185942a | 58 | |
7117c2d2 | 59 | extern ARRAY *array_quote __P((ARRAY *)); |
f1be666c | 60 | extern ARRAY *array_quote_escapes __P((ARRAY *)); |
3185942a JA |
61 | extern ARRAY *array_dequote __P((ARRAY *)); |
62 | extern ARRAY *array_dequote_escapes __P((ARRAY *)); | |
63 | extern ARRAY *array_remove_quoted_nulls __P((ARRAY *)); | |
ccc6cda3 | 64 | |
b80f6443 | 65 | extern char *array_subrange __P((ARRAY *, arrayind_t, arrayind_t, int, int)); |
7117c2d2 | 66 | extern char *array_patsub __P((ARRAY *, char *, char *, int)); |
3185942a | 67 | extern char *array_modcase __P((ARRAY *, char *, int, int)); |
ccc6cda3 | 68 | |
7117c2d2 JA |
69 | /* Basic operations on array elements. */ |
70 | extern ARRAY_ELEMENT *array_create_element __P((arrayind_t, char *)); | |
71 | extern ARRAY_ELEMENT *array_copy_element __P((ARRAY_ELEMENT *)); | |
72 | extern void array_dispose_element __P((ARRAY_ELEMENT *)); | |
ccc6cda3 | 73 | |
7117c2d2 JA |
74 | extern int array_insert __P((ARRAY *, arrayind_t, char *)); |
75 | extern ARRAY_ELEMENT *array_remove __P((ARRAY *, arrayind_t)); | |
76 | extern char *array_reference __P((ARRAY *, arrayind_t)); | |
77 | ||
78 | /* Converting to and from arrays */ | |
ccc6cda3 | 79 | extern WORD_LIST *array_to_word_list __P((ARRAY *)); |
7117c2d2 | 80 | extern ARRAY *array_from_word_list __P((WORD_LIST *)); |
b80f6443 JA |
81 | extern WORD_LIST *array_keys_to_word_list __P((ARRAY *)); |
82 | ||
7117c2d2 | 83 | extern ARRAY *array_assign_list __P((ARRAY *, WORD_LIST *)); |
ccc6cda3 | 84 | |
bb70624e JA |
85 | extern char **array_to_argv __P((ARRAY *)); |
86 | ||
7117c2d2 | 87 | extern char *array_to_assign __P((ARRAY *, int)); |
ccc6cda3 | 88 | extern char *array_to_string __P((ARRAY *, char *, int)); |
7117c2d2 | 89 | extern ARRAY *array_from_string __P((char *, char *)); |
ccc6cda3 | 90 | |
7117c2d2 JA |
91 | /* Flags for array_shift */ |
92 | #define AS_DISPOSE 0x01 | |
ccc6cda3 JA |
93 | |
94 | #define array_num_elements(a) ((a)->num_elements) | |
95 | #define array_max_index(a) ((a)->max_index) | |
96 | #define array_head(a) ((a)->head) | |
97 | #define array_empty(a) ((a)->num_elements == 0) | |
98 | ||
99 | #define element_value(ae) ((ae)->value) | |
100 | #define element_index(ae) ((ae)->ind) | |
101 | #define element_forw(ae) ((ae)->next) | |
102 | #define element_back(ae) ((ae)->prev) | |
103 | ||
b80f6443 JA |
104 | /* Convenience */ |
105 | #define array_push(a,v) \ | |
106 | do { array_rshift ((a), 1, (v)); } while (0) | |
107 | #define array_pop(a) \ | |
108 | do { array_dispose_element (array_shift ((a), 1, 0)); } while (0) | |
109 | ||
110 | #define GET_ARRAY_FROM_VAR(n, v, a) \ | |
111 | do { \ | |
112 | (v) = find_variable (n); \ | |
113 | (a) = ((v) && array_p ((v))) ? array_cell (v) : (ARRAY *)0; \ | |
114 | } while (0) | |
115 | ||
ccc6cda3 JA |
116 | #define ALL_ELEMENT_SUB(c) ((c) == '@' || (c) == '*') |
117 | ||
118 | #endif /* _ARRAY_H_ */ |