15e2a5648bfe860531285263707efa54f18e6689
[platform/upstream/bash.git] / array.h
1 /* array.h -- definitions for the interface exported by array.c that allows
2    the rest of the shell to manipulate array variables. */
3 #ifndef _ARRAY_H_
4 #define _ARRAY_H_
5
6 #include "stdc.h"
7
8 typedef int     arrayind_t;
9
10 enum atype {array_indexed, array_assoc};
11
12 typedef struct array {
13         enum atype      type;
14         arrayind_t      max_index, num_elements, max_size;
15         struct array_element *head;
16 } ARRAY;
17
18 typedef struct array_element {
19         arrayind_t      ind;
20         char    *value;
21         struct array_element *next, *prev;
22 } ARRAY_ELEMENT;
23
24 char    *array_reference __P((ARRAY *, arrayind_t));
25
26 extern int      array_add_element __P((ARRAY *, arrayind_t, char *));
27 extern ARRAY_ELEMENT *array_delete_element __P((ARRAY *, arrayind_t));
28
29 extern ARRAY_ELEMENT *new_array_element __P((arrayind_t, char *));
30 extern void     destroy_array_element __P((ARRAY_ELEMENT *));
31
32 extern ARRAY    *new_array __P((void));
33 extern void     empty_array __P((ARRAY *));
34 extern void     dispose_array __P((ARRAY *));
35 extern ARRAY    *dup_array __P((ARRAY *));
36 extern ARRAY    *dup_array_subrange __P((ARRAY *, ARRAY_ELEMENT *, ARRAY_ELEMENT *));
37 extern ARRAY_ELEMENT *new_array_element __P((arrayind_t, char *));
38 extern ARRAY_ELEMENT *copy_array_element __P((ARRAY_ELEMENT *));
39
40 extern WORD_LIST *array_to_word_list __P((ARRAY *));
41 extern ARRAY *word_list_to_array __P((WORD_LIST *));
42 extern ARRAY *assign_word_list __P((ARRAY *, WORD_LIST *));
43
44 extern char *array_to_assignment_string __P((ARRAY *));
45 extern char *quoted_array_assignment_string __P((ARRAY *));
46 extern char *array_to_string __P((ARRAY *, char *, int));
47 extern ARRAY *string_to_array __P((char *, char *));
48
49 extern char *array_subrange __P((ARRAY *, int, int, int));
50 extern char *array_pat_subst __P((ARRAY *, char *, char *, int));
51
52 extern ARRAY *array_quote __P((ARRAY *));
53
54 #define array_num_elements(a)   ((a)->num_elements)
55 #define array_max_index(a)      ((a)->max_index)
56 #define array_head(a)           ((a)->head)
57 #define array_empty(a)          ((a)->num_elements == 0)
58
59 #define element_value(ae)       ((ae)->value)
60 #define element_index(ae)       ((ae)->ind)
61 #define element_forw(ae)        ((ae)->next)
62 #define element_back(ae)        ((ae)->prev)
63
64 #define ALL_ELEMENT_SUB(c)      ((c) == '@' || (c) == '*')
65
66 #endif /* _ARRAY_H_ */