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