]>
git.ipfire.org Git - thirdparty/bash.git/blob - array.c
2 * array.c - functions to create, destroy, access, and manipulate arrays
5 * Arrays are sparse doubly-linked lists. An element's index is stored
12 /* Copyright (C) 1997-2016 Free Software Foundation, Inc.
14 This file is part of GNU Bash, the Bourne Again SHell.
16 Bash is free software: you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation, either version 3 of the License, or
19 (at your option) any later version.
21 Bash is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with Bash. If not, see <http://www.gnu.org/licenses/>.
32 #if defined (ARRAY_VARS)
34 #if defined (HAVE_UNISTD_H)
36 # include <sys/types.h>
46 #include "builtins/common.h"
48 #define ADD_BEFORE(ae, new) \
50 ae->prev->next = new; \
51 new->prev = ae->prev; \
56 #define ADD_AFTER(ae, new) \
58 ae->next->prev = new; \
59 new->next = ae->next; \
64 static char *array_to_string_internal
__P((ARRAY_ELEMENT
*, ARRAY_ELEMENT
*, char *, int));
66 static char *spacesep
= " ";
68 #define IS_LASTREF(a) (a->lastref)
70 #define LASTREF_START(a, i) \
71 (IS_LASTREF(a) && i >= element_index(a->lastref)) ? a->lastref \
72 : element_forw(a->head)
74 #define LASTREF(a) (a->lastref ? a->lastref : element_forw(a->head))
76 #define INVALIDATE_LASTREF(a) a->lastref = 0
77 #define SET_LASTREF(a, e) a->lastref = (e)
78 #define UNSET_LASTREF(a) a->lastref = 0;
86 r
= (ARRAY
*)xmalloc(sizeof(ARRAY
));
87 r
->type
= array_indexed
;
90 r
->lastref
= (ARRAY_ELEMENT
*)0;
91 head
= array_create_element(-1, (char *)NULL
); /* dummy head */
92 head
->prev
= head
->next
= head
;
101 register ARRAY_ELEMENT
*r
, *r1
;
105 for (r
= element_forw(a
->head
); r
!= a
->head
; ) {
106 r1
= element_forw(r
);
107 array_dispose_element(r
);
110 a
->head
->next
= a
->head
->prev
= a
->head
;
113 INVALIDATE_LASTREF(a
);
123 array_dispose_element(a
->head
);
132 ARRAY_ELEMENT
*ae
, *new;
135 return((ARRAY
*) NULL
);
138 a1
->max_index
= a
->max_index
;
139 a1
->num_elements
= a
->num_elements
;
140 for (ae
= element_forw(a
->head
); ae
!= a
->head
; ae
= element_forw(ae
)) {
141 new = array_create_element(element_index(ae
), element_value(ae
));
142 ADD_BEFORE(a1
->head
, new);
143 if (ae
== LASTREF(a
))
144 SET_LASTREF(a1
, new);
150 * Make and return a new array composed of the elements in array A from
154 array_slice(array
, s
, e
)
156 ARRAY_ELEMENT
*s
, *e
;
159 ARRAY_ELEMENT
*p
, *n
;
164 a
->type
= array
->type
;
166 for (mi
= 0, p
= s
, i
= 0; p
!= e
; p
= element_forw(p
), i
++) {
167 n
= array_create_element (element_index(p
), element_value(p
));
168 ADD_BEFORE(a
->head
, n
);
169 mi
= element_index(n
);
177 * Walk the array, calling FUNC once for each element, with the array
178 * element as the argument.
181 array_walk(a
, func
, udata
)
183 sh_ae_map_func_t
*func
;
186 register ARRAY_ELEMENT
*ae
;
188 if (a
== 0 || array_empty(a
))
190 for (ae
= element_forw(a
->head
); ae
!= a
->head
; ae
= element_forw(ae
))
191 if ((*func
)(ae
, udata
) < 0)
196 * Shift the array A N elements to the left. Delete the first N elements
197 * and subtract N from the indices of the remaining elements. If FLAGS
198 * does not include AS_DISPOSE, this returns a singly-linked null-terminated
199 * list of elements so the caller can dispose of the chain. If FLAGS
200 * includes AS_DISPOSE, this function disposes of the shifted-out elements
204 array_shift(a
, n
, flags
)
208 register ARRAY_ELEMENT
*ae
, *ret
;
211 if (a
== 0 || array_empty(a
) || n
<= 0)
212 return ((ARRAY_ELEMENT
*)NULL
);
214 INVALIDATE_LASTREF(a
);
215 for (i
= 0, ret
= ae
= element_forw(a
->head
); ae
!= a
->head
&& i
< n
; ae
= element_forw(ae
), i
++)
218 /* Easy case; shifting out all of the elements */
219 if (flags
& AS_DISPOSE
) {
221 return ((ARRAY_ELEMENT
*)NULL
);
223 for (ae
= ret
; element_forw(ae
) != a
->head
; ae
= element_forw(ae
))
225 element_forw(ae
) = (ARRAY_ELEMENT
*)NULL
;
226 a
->head
->next
= a
->head
->prev
= a
->head
;
232 * ae now points to the list of elements we want to retain.
233 * ret points to the list we want to either destroy or return.
235 ae
->prev
->next
= (ARRAY_ELEMENT
*)NULL
; /* null-terminate RET */
237 a
->head
->next
= ae
; /* slice RET out of the array */
240 for ( ; ae
!= a
->head
; ae
= element_forw(ae
))
241 element_index(ae
) -= n
; /* renumber retained indices */
243 a
->num_elements
-= n
; /* modify bookkeeping information */
244 a
->max_index
= element_index(a
->head
->prev
);
246 if (flags
& AS_DISPOSE
) {
247 for (ae
= ret
; ae
; ) {
248 ret
= element_forw(ae
);
249 array_dispose_element(ae
);
252 return ((ARRAY_ELEMENT
*)NULL
);
259 * Shift array A right N indices. If S is non-null, it becomes the value of
260 * the new element 0. Returns the number of elements in the array after the
264 array_rshift (a
, n
, s
)
269 register ARRAY_ELEMENT
*ae
, *new;
271 if (a
== 0 || (array_empty(a
) && s
== 0))
274 return (a
->num_elements
);
276 ae
= element_forw(a
->head
);
278 new = array_create_element(0, s
);
281 if (array_num_elements(a
) == 1) { /* array was empty */
288 * Renumber all elements in the array except the one we just added.
290 for ( ; ae
!= a
->head
; ae
= element_forw(ae
))
291 element_index(ae
) += n
;
293 a
->max_index
= element_index(a
->head
->prev
);
295 INVALIDATE_LASTREF(a
);
296 return (a
->num_elements
);
300 array_unshift_element(a
)
303 return (array_shift (a
, 1, 0));
307 array_shift_element(a
, v
)
311 return (array_rshift (a
, 1, v
));
321 if (array
== 0 || array_head(array
) == 0 || array_empty(array
))
322 return (ARRAY
*)NULL
;
323 for (a
= element_forw(array
->head
); a
!= array
->head
; a
= element_forw(a
)) {
324 t
= quote_string (a
->value
);
332 array_quote_escapes(array
)
338 if (array
== 0 || array_head(array
) == 0 || array_empty(array
))
339 return (ARRAY
*)NULL
;
340 for (a
= element_forw(array
->head
); a
!= array
->head
; a
= element_forw(a
)) {
341 t
= quote_escapes (a
->value
);
355 if (array
== 0 || array_head(array
) == 0 || array_empty(array
))
356 return (ARRAY
*)NULL
;
357 for (a
= element_forw(array
->head
); a
!= array
->head
; a
= element_forw(a
)) {
358 t
= dequote_string (a
->value
);
366 array_dequote_escapes(array
)
372 if (array
== 0 || array_head(array
) == 0 || array_empty(array
))
373 return (ARRAY
*)NULL
;
374 for (a
= element_forw(array
->head
); a
!= array
->head
; a
= element_forw(a
)) {
375 t
= dequote_escapes (a
->value
);
383 array_remove_quoted_nulls(array
)
388 if (array
== 0 || array_head(array
) == 0 || array_empty(array
))
389 return (ARRAY
*)NULL
;
390 for (a
= element_forw(array
->head
); a
!= array
->head
; a
= element_forw(a
))
391 a
->value
= remove_quoted_nulls (a
->value
);
396 * Return a string whose elements are the members of array A beginning at
397 * index START and spanning NELEM members. Null elements are counted.
398 * Since arrays are sparse, unset array elements are not counted.
401 array_subrange (a
, start
, nelem
, starsub
, quoted
)
403 arrayind_t start
, nelem
;
407 ARRAY_ELEMENT
*h
, *p
;
412 p
= a
? array_head (a
) : 0;
413 if (p
== 0 || array_empty (a
) || start
> array_max_index(a
))
414 return ((char *)NULL
);
417 * Find element with index START. If START corresponds to an unset
418 * element (arrays can be sparse), use the first element whose index
419 * is >= START. If START is < 0, we count START indices back from
420 * the end of A (not elements, even with sparse arrays -- START is an
423 for (p
= element_forw(p
); p
!= array_head(a
) && start
> element_index(p
); p
= element_forw(p
))
427 return ((char *)NULL
);
429 /* Starting at P, take NELEM elements, inclusive. */
430 for (i
= 0, h
= p
; p
!= a
->head
&& i
< nelem
; i
++, p
= element_forw(p
))
433 a2
= array_slice(a
, h
, p
);
435 wl
= array_to_word_list(a2
);
439 t
= string_list_pos_params(starsub
? '*' : '@', wl
, quoted
);
446 array_patsub (a
, pat
, rep
, mflags
)
453 WORD_LIST
*wl
, *save
;
455 if (a
== 0 || array_head(a
) == 0 || array_empty(a
))
456 return ((char *)NULL
);
458 wl
= array_to_word_list(a
);
462 for (save
= wl
; wl
; wl
= wl
->next
) {
463 t
= pat_subst (wl
->word
->word
, pat
, rep
, mflags
);
464 FREE (wl
->word
->word
);
468 pchar
= (mflags
& MATCH_STARSUB
) == MATCH_STARSUB
? '*' : '@';
469 qflags
= (mflags
& MATCH_QUOTED
) == MATCH_QUOTED
? Q_DOUBLE_QUOTES
: 0;
471 t
= string_list_pos_params (pchar
, save
, qflags
);
478 array_modcase (a
, pat
, modop
, mflags
)
486 WORD_LIST
*wl
, *save
;
488 if (a
== 0 || array_head(a
) == 0 || array_empty(a
))
489 return ((char *)NULL
);
491 wl
= array_to_word_list(a
);
493 return ((char *)NULL
);
495 for (save
= wl
; wl
; wl
= wl
->next
) {
496 t
= sh_modcase(wl
->word
->word
, pat
, modop
);
497 FREE(wl
->word
->word
);
501 pchar
= (mflags
& MATCH_STARSUB
) == MATCH_STARSUB
? '*' : '@';
502 qflags
= (mflags
& MATCH_QUOTED
) == MATCH_QUOTED
? Q_DOUBLE_QUOTES
: 0;
504 t
= string_list_pos_params (pchar
, save
, qflags
);
511 * Allocate and return a new array element with index INDEX and value
515 array_create_element(indx
, value
)
521 r
= (ARRAY_ELEMENT
*)xmalloc(sizeof(ARRAY_ELEMENT
));
523 r
->value
= value
? savestring(value
) : (char *)NULL
;
524 r
->next
= r
->prev
= (ARRAY_ELEMENT
*) NULL
;
528 #ifdef INCLUDE_UNUSED
530 array_copy_element(ae
)
533 return(ae
? array_create_element(element_index(ae
), element_value(ae
))
534 : (ARRAY_ELEMENT
*) NULL
);
539 array_dispose_element(ae
)
549 * Add a new element with index I and value V to array A (a[i] = v).
552 array_insert(a
, i
, v
)
557 register ARRAY_ELEMENT
*new, *ae
, *start
;
563 new = array_create_element(i
, v
);
564 if (i
> array_max_index(a
)) {
566 * Hook onto the end. This also works for an empty array.
567 * Fast path for the common case of allocating arrays
570 ADD_BEFORE(a
->head
, new);
575 } else if (i
< array_first_index(a
)) {
576 /* Hook at the beginning */
577 ADD_AFTER(a
->head
, new);
582 #if OPTIMIZE_SEQUENTIAL_ARRAY_ASSIGNMENT
584 * Otherwise we search for the spot to insert it. The lastref
585 * handle optimizes the case of sequential or almost-sequential
586 * assignments that are not at the end of the array.
589 /* Use same strategy as array_reference to avoid paying large penalty
590 for semi-random assignment pattern. */
591 startind
= element_index(start
);
592 if (i
< startind
/2) {
593 start
= element_forw(a
->head
);
594 startind
= element_index(start
);
596 } else if (i
>= startind
) {
602 start
= element_forw(ae
->head
);
603 startind
= element_index(start
);
606 for (ae
= start
; ae
!= a
->head
; ) {
607 if (element_index(ae
) == i
) {
609 * Replacing an existing element.
611 free(element_value(ae
));
612 /* Just swap in the new value */
613 ae
->value
= new->value
;
615 array_dispose_element(new);
618 } else if (direction
== 1 && element_index(ae
) > i
) {
623 } else if (direction
== -1 && element_index(ae
) < i
) {
629 ae
= direction
== 1 ? element_forw(ae
) : element_back(ae
);
631 array_dispose_element(new);
632 INVALIDATE_LASTREF(a
);
633 return (-1); /* problem */
637 * Delete the element with index I from array A and return it so the
638 * caller can dispose of it.
645 register ARRAY_ELEMENT
*ae
, *start
;
649 if (a
== 0 || array_empty(a
))
650 return((ARRAY_ELEMENT
*) NULL
);
651 if (i
> array_max_index(a
) || i
< array_first_index(a
))
652 return((ARRAY_ELEMENT
*)NULL
); /* Keep roving pointer into array to optimize sequential access */
654 /* Use same strategy as array_reference to avoid paying large penalty
655 for semi-random assignment pattern. */
656 startind
= element_index(start
);
657 if (i
< startind
/2) {
658 start
= element_forw(a
->head
);
659 startind
= element_index(start
);
661 } else if (i
>= startind
) {
666 for (ae
= start
; ae
!= a
->head
; ) {
667 if (element_index(ae
) == i
) {
668 ae
->next
->prev
= ae
->prev
;
669 ae
->prev
->next
= ae
->next
;
671 if (i
== array_max_index(a
))
672 a
->max_index
= element_index(ae
->prev
);
674 INVALIDATE_LASTREF(a
);
676 if (ae
->next
!= a
->head
)
677 SET_LASTREF(a
, ae
->next
);
678 else if (ae
->prev
!= a
->head
)
679 SET_LASTREF(a
, ae
->prev
);
681 INVALIDATE_LASTREF(a
);
685 ae
= (direction
== 1) ? element_forw(ae
) : element_back(ae
);
686 if (direction
== 1 && element_index(ae
) > i
)
688 else if (direction
== -1 && element_index(ae
) < i
)
691 return((ARRAY_ELEMENT
*) NULL
);
695 * Return the value of a[i].
698 array_reference(a
, i
)
702 register ARRAY_ELEMENT
*ae
, *start
;
706 if (a
== 0 || array_empty(a
))
707 return((char *) NULL
);
708 if (i
> array_max_index(a
) || i
< array_first_index(a
))
709 return((char *)NULL
); /* Keep roving pointer into array to optimize sequential access */
710 start
= LASTREF(a
); /* lastref pointer */
711 startind
= element_index(start
);
712 if (i
< startind
/2) { /* XXX - guess */
713 start
= element_forw(a
->head
);
714 startind
= element_index(start
);
716 } else if (i
>= startind
) {
721 for (ae
= start
; ae
!= a
->head
; ) {
722 if (element_index(ae
) == i
) {
724 return(element_value(ae
));
726 ae
= (direction
== 1) ? element_forw(ae
) : element_back(ae
);
727 /* Take advantage of index ordering to short-circuit */
728 /* If we don't find it, set the lastref pointer to the element
729 that's `closest', assuming that the unsuccessful reference
730 will quickly be followed by an assignment. No worse than
731 not changing it from the previous value or resetting it. */
732 if (direction
== 1 && element_index(ae
) > i
) {
733 start
= ae
; /* use for SET_LASTREF below */
735 } else if (direction
== -1 && element_index(ae
) < i
) {
736 start
= ae
; /* use for SET_LASTREF below */
743 SET_LASTREF(a
, start
);
745 return((char *) NULL
);
748 /* Convenience routines for the shell to translate to and from the form used
749 by the rest of the code. */
752 array_to_word_list(a
)
758 if (a
== 0 || array_empty(a
))
759 return((WORD_LIST
*)NULL
);
760 list
= (WORD_LIST
*)NULL
;
761 for (ae
= element_forw(a
->head
); ae
!= a
->head
; ae
= element_forw(ae
))
762 list
= make_word_list (make_bare_word(element_value(ae
)), list
);
763 return (REVERSE_LIST(list
, WORD_LIST
*));
767 array_from_word_list (list
)
773 return((ARRAY
*)NULL
);
775 return (array_assign_list (a
, list
));
779 array_keys_to_word_list(a
)
786 if (a
== 0 || array_empty(a
))
787 return((WORD_LIST
*)NULL
);
788 list
= (WORD_LIST
*)NULL
;
789 for (ae
= element_forw(a
->head
); ae
!= a
->head
; ae
= element_forw(ae
)) {
790 t
= itos(element_index(ae
));
791 list
= make_word_list (make_bare_word(t
), list
);
794 return (REVERSE_LIST(list
, WORD_LIST
*));
798 array_assign_list (array
, list
)
802 register WORD_LIST
*l
;
803 register arrayind_t i
;
805 for (l
= list
, i
= 0; l
; l
= l
->next
, i
++)
806 array_insert(array
, i
, l
->word
->word
);
818 if (a
== 0 || array_empty(a
))
819 return ((char **)NULL
);
820 ret
= strvec_create (array_num_elements (a
) + 1);
822 for (ae
= element_forw(a
->head
); ae
!= a
->head
; ae
= element_forw(ae
)) {
823 t
= element_value (ae
);
824 ret
[i
++] = t
? savestring (t
) : (char *)NULL
;
826 ret
[i
] = (char *)NULL
;
831 * Return a string that is the concatenation of the elements in A from START
832 * to END, separated by SEP.
835 array_to_string_internal (start
, end
, sep
, quoted
)
836 ARRAY_ELEMENT
*start
, *end
;
842 int slen
, rsize
, rlen
, reg
;
844 if (start
== end
) /* XXX - should not happen */
845 return ((char *)NULL
);
849 for (rsize
= rlen
= 0, ae
= start
; ae
!= end
; ae
= element_forw(ae
)) {
851 result
= (char *)xmalloc (rsize
= 64);
852 if (element_value(ae
)) {
853 t
= quoted
? quote_string(element_value(ae
)) : element_value(ae
);
855 RESIZE_MALLOCED_BUFFER (result
, rlen
, (reg
+ slen
+ 2),
857 strcpy(result
+ rlen
, t
);
862 * Add a separator only after non-null elements.
864 if (element_forw(ae
) != end
) {
865 strcpy(result
+ rlen
, sep
);
871 result
[rlen
] = '\0'; /* XXX */
876 array_to_assign (a
, quoted
)
880 char *result
, *valstr
, *is
;
881 char indstr
[INT_STRLEN_BOUND(intmax_t) + 1];
883 int rsize
, rlen
, elen
;
885 if (a
== 0 || array_empty (a
))
886 return((char *)NULL
);
888 result
= (char *)xmalloc (rsize
= 128);
892 for (ae
= element_forw(a
->head
); ae
!= a
->head
; ae
= element_forw(ae
)) {
893 is
= inttostr (element_index(ae
), indstr
, sizeof(indstr
));
894 valstr
= element_value (ae
) ?
895 (ansic_shouldquote (element_value (ae
)) ?
896 ansic_quote (element_value(ae
), 0, (int *)0) :
897 sh_double_quote (element_value (ae
)))
899 elen
= STRLEN (is
) + 8 + STRLEN (valstr
);
900 RESIZE_MALLOCED_BUFFER (result
, rlen
, (elen
+ 1), rsize
, rsize
);
902 result
[rlen
++] = '[';
903 strcpy (result
+ rlen
, is
);
905 result
[rlen
++] = ']';
906 result
[rlen
++] = '=';
908 strcpy (result
+ rlen
, valstr
);
909 rlen
+= STRLEN (valstr
);
912 if (element_forw(ae
) != a
->head
)
913 result
[rlen
++] = ' ';
917 RESIZE_MALLOCED_BUFFER (result
, rlen
, 1, rsize
, 8);
918 result
[rlen
++] = ')';
921 /* This is not as efficient as it could be... */
922 valstr
= sh_single_quote (result
);
930 array_to_string (a
, sep
, quoted
)
936 return((char *)NULL
);
938 return(savestring(""));
939 return (array_to_string_internal (element_forw(a
->head
), a
->head
, sep
, quoted
));
942 #if defined (INCLUDE_UNUSED) || defined (TEST_ARRAY)
944 * Return an array consisting of elements in S, separated by SEP
947 array_from_string(s
, sep
)
954 return((ARRAY
*)NULL
);
955 w
= list_string (s
, sep
, 0);
957 return((ARRAY
*)NULL
);
958 a
= array_from_word_list (w
);
963 #if defined (TEST_ARRAY)
965 * To make a running version, compile -DTEST_ARRAY and link with:
966 * xmalloc.o syntax.o lib/malloc/libmalloc.a lib/sh/libsh.a
968 int interrupt_immediately
= 0;
978 fatal_error(const char *s
, ...)
980 fprintf(stderr
, "array_test: fatal memory error\n");
985 programming_error(const char *s
, ...)
987 fprintf(stderr
, "array_test: fatal programming error\n");
997 w
= (WORD_DESC
*)xmalloc(sizeof(WORD_DESC
));
998 w
->word
= s
? savestring(s
) : savestring ("");
1004 make_word_list(x
, l
)
1010 w
= (WORD_LIST
*)xmalloc(sizeof(WORD_LIST
));
1017 list_string(s
, t
, i
)
1025 return (WORD_LIST
*)NULL
;
1027 wl
= (WORD_LIST
*)NULL
;
1030 wl
= make_word_list (make_bare_word(a
), wl
);
1031 a
= strtok((char *)NULL
, t
);
1033 return (REVERSE_LIST (wl
, WORD_LIST
*));
1040 register GENERIC_LIST
*next
, *prev
;
1042 for (prev
= 0; list
; ) {
1052 pat_subst(s
, t
, u
, i
)
1056 return ((char *)NULL
);
1063 return savestring(s
);
1069 char lbuf
[INT_STRLEN_BOUND (intmax_t) + 1];
1071 printf("array[%s] = %s\n",
1072 inttostr (element_index(ae
), lbuf
, sizeof (lbuf
)),
1080 array_walk(a
, print_element
, (void *)NULL
);
1085 ARRAY
*a
, *new_a
, *copy_of_a
;
1086 ARRAY_ELEMENT
*ae
, *aew
;
1090 array_insert(a
, 1, "one");
1091 array_insert(a
, 7, "seven");
1092 array_insert(a
, 4, "four");
1093 array_insert(a
, 1029, "one thousand twenty-nine");
1094 array_insert(a
, 12, "twelve");
1095 array_insert(a
, 42, "forty-two");
1097 s
= array_to_string (a
, " ", 0);
1098 printf("s = %s\n", s
);
1099 copy_of_a
= array_from_string(s
, " ");
1100 printf("copy_of_a:");
1101 print_array(copy_of_a
);
1102 array_dispose(copy_of_a
);
1105 ae
= array_remove(a
, 4);
1106 array_dispose_element(ae
);
1107 ae
= array_remove(a
, 1029);
1108 array_dispose_element(ae
);
1109 array_insert(a
, 16, "sixteen");
1111 s
= array_to_string (a
, " ", 0);
1112 printf("s = %s\n", s
);
1113 copy_of_a
= array_from_string(s
, " ");
1114 printf("copy_of_a:");
1115 print_array(copy_of_a
);
1116 array_dispose(copy_of_a
);
1119 array_insert(a
, 2, "two");
1120 array_insert(a
, 1029, "new one thousand twenty-nine");
1121 array_insert(a
, 0, "zero");
1122 array_insert(a
, 134, "");
1124 s
= array_to_string (a
, ":", 0);
1125 printf("s = %s\n", s
);
1126 copy_of_a
= array_from_string(s
, ":");
1127 printf("copy_of_a:");
1128 print_array(copy_of_a
);
1129 array_dispose(copy_of_a
);
1132 new_a
= array_copy(a
);
1134 s
= array_to_string (new_a
, ":", 0);
1135 printf("s = %s\n", s
);
1136 copy_of_a
= array_from_string(s
, ":");
1138 printf("copy_of_a:");
1139 print_array(copy_of_a
);
1140 array_shift(copy_of_a
, 2, AS_DISPOSE
);
1141 printf("copy_of_a shifted by two:");
1142 print_array(copy_of_a
);
1143 ae
= array_shift(copy_of_a
, 2, 0);
1144 printf("copy_of_a shifted by two:");
1145 print_array(copy_of_a
);
1147 aew
= element_forw(ae
);
1148 array_dispose_element(ae
);
1151 array_rshift(copy_of_a
, 1, (char *)0);
1152 printf("copy_of_a rshift by 1:");
1153 print_array(copy_of_a
);
1154 array_rshift(copy_of_a
, 2, "new element zero");
1155 printf("copy_of_a rshift again by 2 with new element zero:");
1156 print_array(copy_of_a
);
1157 s
= array_to_assign(copy_of_a
, 0);
1158 printf("copy_of_a=%s\n", s
);
1160 ae
= array_shift(copy_of_a
, array_num_elements(copy_of_a
), 0);
1162 aew
= element_forw(ae
);
1163 array_dispose_element(ae
);
1166 array_dispose(copy_of_a
);
1169 array_dispose(new_a
);
1172 #endif /* TEST_ARRAY */
1173 #endif /* ARRAY_VARS */