source: trunk/third/bash/array.h @ 18290

Revision 18290, 3.2 KB checked in by zacheiss, 21 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18289, which included commits to RCS files with non-trunk default branches.
Line 
1/* array.h -- definitions for the interface exported by array.c that allows
2   the rest of the shell to manipulate array variables. */
3
4/* Copyright (C) 1997 Free Software Foundation, Inc.
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
22#ifndef _ARRAY_H_
23#define _ARRAY_H_
24
25#include "stdc.h"
26
27typedef intmax_t        arrayind_t;
28
29enum atype {array_indexed, array_assoc};
30
31typedef struct array {
32        enum atype      type;
33        arrayind_t      max_index, num_elements;
34        struct array_element *head;
35} ARRAY;
36
37typedef struct array_element {
38        arrayind_t      ind;
39        char    *value;
40        struct array_element *next, *prev;
41} ARRAY_ELEMENT;
42
43typedef int sh_ae_map_func_t __P((ARRAY_ELEMENT *));
44
45/* Basic operations on entire arrays */
46extern ARRAY    *array_create __P((void));
47extern void     array_flush __P((ARRAY *));
48extern void     array_dispose __P((ARRAY *));
49extern ARRAY    *array_copy __P((ARRAY *));
50extern ARRAY    *array_slice __P((ARRAY *, ARRAY_ELEMENT *, ARRAY_ELEMENT *));
51extern void     array_walk __P((ARRAY   *, sh_ae_map_func_t *));
52
53extern ARRAY_ELEMENT *array_shift __P((ARRAY *, int, int));
54extern int      array_rshift __P((ARRAY *, int, char *));
55extern ARRAY    *array_quote __P((ARRAY *));
56
57extern char     *array_subrange __P((ARRAY *, arrayind_t, arrayind_t, int));
58extern char     *array_patsub __P((ARRAY *, char *, char *, int));
59
60/* Basic operations on array elements. */
61extern ARRAY_ELEMENT *array_create_element __P((arrayind_t, char *));
62extern ARRAY_ELEMENT *array_copy_element __P((ARRAY_ELEMENT *));
63extern void     array_dispose_element __P((ARRAY_ELEMENT *));
64
65extern int      array_insert __P((ARRAY *, arrayind_t, char *));
66extern ARRAY_ELEMENT *array_remove __P((ARRAY *, arrayind_t));
67extern char     *array_reference __P((ARRAY *, arrayind_t));
68
69/* Converting to and from arrays */
70extern WORD_LIST *array_to_word_list __P((ARRAY *));
71extern ARRAY *array_from_word_list __P((WORD_LIST *));
72extern ARRAY *array_assign_list __P((ARRAY *, WORD_LIST *));
73
74extern char **array_to_argv __P((ARRAY *));
75
76extern char *array_to_assign __P((ARRAY *, int));
77extern char *array_to_string __P((ARRAY *, char *, int));
78extern ARRAY *array_from_string __P((char *, char *));
79
80/* Flags for array_shift */
81#define AS_DISPOSE      0x01
82
83#define array_num_elements(a)   ((a)->num_elements)
84#define array_max_index(a)      ((a)->max_index)
85#define array_head(a)           ((a)->head)
86#define array_empty(a)          ((a)->num_elements == 0)
87
88#define element_value(ae)       ((ae)->value)
89#define element_index(ae)       ((ae)->ind)
90#define element_forw(ae)        ((ae)->next)
91#define element_back(ae)        ((ae)->prev)
92
93#define ALL_ELEMENT_SUB(c)      ((c) == '@' || (c) == '*')
94
95#endif /* _ARRAY_H_ */
Note: See TracBrowser for help on using the repository browser.