]>
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-2009 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 static char *array_to_string_internal
__P((ARRAY_ELEMENT
*, ARRAY_ELEMENT
*, char *, int));
58 /* lastref should be moved into the array structure so each array can be
59 optimized separately */
61 static ARRAY
*lastarray
= 0;
62 static ARRAY_ELEMENT
*lastref
= 0;
64 #define IS_LASTREF(a) (lastarray && (a) == lastarray)
66 #define LASTREF_START(a, i) \
67 (IS_LASTREF(a) && i >= element_index(lastref)) ? lastref \
68 : element_forw(a->head)
70 #define INVALIDATE_LASTREF(a) \
72 if ((a) == lastarray) { \
78 #define SET_LASTREF(a, e) \
84 #define UNSET_LASTREF() \
96 r
=(ARRAY
*)xmalloc(sizeof(ARRAY
));
97 r
->type
= array_indexed
;
100 head
= array_create_element(-1, (char *)NULL
); /* dummy head */
101 head
->prev
= head
->next
= head
;
110 register ARRAY_ELEMENT
*r
, *r1
;
114 for (r
= element_forw(a
->head
); r
!= a
->head
; ) {
115 r1
= element_forw(r
);
116 array_dispose_element(r
);
119 a
->head
->next
= a
->head
->prev
= a
->head
;
122 INVALIDATE_LASTREF(a
);
132 array_dispose_element(a
->head
);
141 ARRAY_ELEMENT
*ae
, *new;
144 return((ARRAY
*) NULL
);
147 a1
->max_index
= a
->max_index
;
148 a1
->num_elements
= a
->num_elements
;
149 for (ae
= element_forw(a
->head
); ae
!= a
->head
; ae
= element_forw(ae
)) {
150 new = array_create_element(element_index(ae
), element_value(ae
));
151 ADD_BEFORE(a1
->head
, new);
157 * Make and return a new array composed of the elements in array A from
161 array_slice(array
, s
, e
)
163 ARRAY_ELEMENT
*s
, *e
;
166 ARRAY_ELEMENT
*p
, *n
;
171 a
->type
= array
->type
;
173 for (mi
= 0, p
= s
, i
= 0; p
!= e
; p
= element_forw(p
), i
++) {
174 n
= array_create_element (element_index(p
), element_value(p
));
175 ADD_BEFORE(a
->head
, n
);
176 mi
= element_index(n
);
184 * Walk the array, calling FUNC once for each element, with the array
185 * element as the argument.
188 array_walk(a
, func
, udata
)
190 sh_ae_map_func_t
*func
;
193 register ARRAY_ELEMENT
*ae
;
195 if (a
== 0 || array_empty(a
))
197 for (ae
= element_forw(a
->head
); ae
!= a
->head
; ae
= element_forw(ae
))
198 if ((*func
)(ae
, udata
) < 0)
203 * Shift the array A N elements to the left. Delete the first N elements
204 * and subtract N from the indices of the remaining elements. If FLAGS
205 * does not include AS_DISPOSE, this returns a singly-linked null-terminated
206 * list of elements so the caller can dispose of the chain. If FLAGS
207 * includes AS_DISPOSE, this function disposes of the shifted-out elements
211 array_shift(a
, n
, flags
)
215 register ARRAY_ELEMENT
*ae
, *ret
;
218 if (a
== 0 || array_empty(a
) || n
<= 0)
219 return ((ARRAY_ELEMENT
*)NULL
);
221 INVALIDATE_LASTREF(a
);
222 for (i
= 0, ret
= ae
= element_forw(a
->head
); ae
!= a
->head
&& i
< n
; ae
= element_forw(ae
), i
++)
225 /* Easy case; shifting out all of the elements */
226 if (flags
& AS_DISPOSE
) {
228 return ((ARRAY_ELEMENT
*)NULL
);
230 for (ae
= ret
; element_forw(ae
) != a
->head
; ae
= element_forw(ae
))
232 element_forw(ae
) = (ARRAY_ELEMENT
*)NULL
;
233 a
->head
->next
= a
->head
->prev
= a
->head
;
239 * ae now points to the list of elements we want to retain.
240 * ret points to the list we want to either destroy or return.
242 ae
->prev
->next
= (ARRAY_ELEMENT
*)NULL
; /* null-terminate RET */
244 a
->head
->next
= ae
; /* slice RET out of the array */
247 for ( ; ae
!= a
->head
; ae
= element_forw(ae
))
248 element_index(ae
) -= n
; /* renumber retained indices */
250 a
->num_elements
-= n
; /* modify bookkeeping information */
251 a
->max_index
= element_index(a
->head
->prev
);
253 if (flags
& AS_DISPOSE
) {
254 for (ae
= ret
; ae
; ) {
255 ret
= element_forw(ae
);
256 array_dispose_element(ae
);
259 return ((ARRAY_ELEMENT
*)NULL
);
266 * Shift array A right N indices. If S is non-null, it becomes the value of
267 * the new element 0. Returns the number of elements in the array after the
271 array_rshift (a
, n
, s
)
276 register ARRAY_ELEMENT
*ae
, *new;
278 if (a
== 0 || (array_empty(a
) && s
== 0))
281 return (a
->num_elements
);
283 ae
= element_forw(a
->head
);
285 new = array_create_element(0, s
);
288 if (array_num_elements(a
) == 1) { /* array was empty */
295 * Renumber all elements in the array except the one we just added.
297 for ( ; ae
!= a
->head
; ae
= element_forw(ae
))
298 element_index(ae
) += n
;
300 a
->max_index
= element_index(a
->head
->prev
);
302 INVALIDATE_LASTREF(a
);
303 return (a
->num_elements
);
307 array_unshift_element(a
)
310 return (array_shift (a
, 1, 0));
314 array_shift_element(a
, v
)
318 return (array_rshift (a
, 1, v
));
328 if (array
== 0 || array_head(array
) == 0 || array_empty(array
))
329 return (ARRAY
*)NULL
;
330 for (a
= element_forw(array
->head
); a
!= array
->head
; a
= element_forw(a
)) {
331 t
= quote_string (a
->value
);
339 array_quote_escapes(array
)
345 if (array
== 0 || array_head(array
) == 0 || array_empty(array
))
346 return (ARRAY
*)NULL
;
347 for (a
= element_forw(array
->head
); a
!= array
->head
; a
= element_forw(a
)) {
348 t
= quote_escapes (a
->value
);
362 if (array
== 0 || array_head(array
) == 0 || array_empty(array
))
363 return (ARRAY
*)NULL
;
364 for (a
= element_forw(array
->head
); a
!= array
->head
; a
= element_forw(a
)) {
365 t
= dequote_string (a
->value
);
373 array_dequote_escapes(array
)
379 if (array
== 0 || array_head(array
) == 0 || array_empty(array
))
380 return (ARRAY
*)NULL
;
381 for (a
= element_forw(array
->head
); a
!= array
->head
; a
= element_forw(a
)) {
382 t
= dequote_escapes (a
->value
);
390 array_remove_quoted_nulls(array
)
396 if (array
== 0 || array_head(array
) == 0 || array_empty(array
))
397 return (ARRAY
*)NULL
;
398 for (a
= element_forw(array
->head
); a
!= array
->head
; a
= element_forw(a
))
399 a
->value
= remove_quoted_nulls (a
->value
);
404 * Return a string whose elements are the members of array A beginning at
405 * index START and spanning NELEM members. Null elements are counted.
406 * Since arrays are sparse, unset array elements are not counted.
409 array_subrange (a
, start
, nelem
, starsub
, quoted
)
411 arrayind_t start
, nelem
;
415 ARRAY_ELEMENT
*h
, *p
;
417 char *ifs
, *sifs
, *t
;
420 p
= a
? array_head (a
) : 0;
421 if (p
== 0 || array_empty (a
) || start
> array_max_index(a
))
422 return ((char *)NULL
);
425 * Find element with index START. If START corresponds to an unset
426 * element (arrays can be sparse), use the first element whose index
427 * is >= START. If START is < 0, we count START indices back from
428 * the end of A (not elements, even with sparse arrays -- START is an
431 for (p
= element_forw(p
); p
!= array_head(a
) && start
> element_index(p
); p
= element_forw(p
))
435 return ((char *)NULL
);
437 /* Starting at P, take NELEM elements, inclusive. */
438 for (i
= 0, h
= p
; p
!= a
->head
&& i
< nelem
; i
++, p
= element_forw(p
))
441 a2
= array_slice(a
, h
, p
);
443 if (quoted
& (Q_DOUBLE_QUOTES
|Q_HERE_DOCUMENT
))
446 array_quote_escapes(a2
);
448 if (starsub
&& (quoted
& (Q_DOUBLE_QUOTES
|Q_HERE_DOCUMENT
))) {
450 array_remove_quoted_nulls (a2
);
451 sifs
= ifs_firstchar ((int *)NULL
);
452 t
= array_to_string (a2
, sifs
, 0);
454 } else if (quoted
& (Q_DOUBLE_QUOTES
|Q_HERE_DOCUMENT
)) {
456 sifs
= ifs_firstchar (&slen
);
458 if (ifs
== 0 || *ifs
== 0) {
460 sifs
= xrealloc(sifs
, 2);
464 t
= array_to_string (a2
, sifs
, 0);
467 t
= array_to_string (a2
, " ", 0);
474 array_patsub (a
, pat
, rep
, mflags
)
481 char *t
, *sifs
, *ifs
;
484 if (a
== 0 || array_head(a
) == 0 || array_empty(a
))
485 return ((char *)NULL
);
488 for (e
= element_forw(a2
->head
); e
!= a2
->head
; e
= element_forw(e
)) {
489 t
= pat_subst(element_value(e
), pat
, rep
, mflags
);
490 FREE(element_value(e
));
494 if (mflags
& MATCH_QUOTED
)
497 array_quote_escapes(a2
);
499 if (mflags
& MATCH_STARSUB
) {
500 array_remove_quoted_nulls (a2
);
501 sifs
= ifs_firstchar((int *)NULL
);
502 t
= array_to_string (a2
, sifs
, 0);
504 } else if (mflags
& MATCH_QUOTED
) {
506 sifs
= ifs_firstchar (&slen
);
508 if (ifs
== 0 || *ifs
== 0) {
510 sifs
= xrealloc (sifs
, 2);
514 t
= array_to_string (a2
, sifs
, 0);
517 t
= array_to_string (a2
, " ", 0);
524 array_modcase (a
, pat
, modop
, mflags
)
532 char *t
, *sifs
, *ifs
;
535 if (a
== 0 || array_head(a
) == 0 || array_empty(a
))
536 return ((char *)NULL
);
539 for (e
= element_forw(a2
->head
); e
!= a2
->head
; e
= element_forw(e
)) {
540 t
= sh_modcase(element_value(e
), pat
, modop
);
541 FREE(element_value(e
));
545 if (mflags
& MATCH_QUOTED
)
548 array_quote_escapes(a2
);
550 if (mflags
& MATCH_STARSUB
) {
551 array_remove_quoted_nulls (a2
);
552 sifs
= ifs_firstchar((int *)NULL
);
553 t
= array_to_string (a2
, sifs
, 0);
555 } else if (mflags
& MATCH_QUOTED
) {
557 sifs
= ifs_firstchar (&slen
);
559 if (ifs
== 0 || *ifs
== 0) {
561 sifs
= xrealloc (sifs
, 2);
565 t
= array_to_string (a2
, sifs
, 0);
568 t
= array_to_string (a2
, " ", 0);
574 * Allocate and return a new array element with index INDEX and value
578 array_create_element(indx
, value
)
584 r
= (ARRAY_ELEMENT
*)xmalloc(sizeof(ARRAY_ELEMENT
));
586 r
->value
= value
? savestring(value
) : (char *)NULL
;
587 r
->next
= r
->prev
= (ARRAY_ELEMENT
*) NULL
;
591 #ifdef INCLUDE_UNUSED
593 array_copy_element(ae
)
596 return(ae
? array_create_element(element_index(ae
), element_value(ae
))
597 : (ARRAY_ELEMENT
*) NULL
);
602 array_dispose_element(ae
)
612 * Add a new element with index I and value V to array A (a[i] = v).
615 array_insert(a
, i
, v
)
620 register ARRAY_ELEMENT
*new, *ae
, *start
;
624 new = array_create_element(i
, v
);
625 if (i
> array_max_index(a
)) {
627 * Hook onto the end. This also works for an empty array.
628 * Fast path for the common case of allocating arrays
631 ADD_BEFORE(a
->head
, new);
637 #if OPTIMIZE_SEQUENTIAL_ARRAY_ASSIGNMENT
639 * Otherwise we search for the spot to insert it. The lastref
640 * handle optimizes the case of sequential or almost-sequential
641 * assignments that are not at the end of the array.
643 start
= LASTREF_START(a
, i
);
645 start
= element_forw(ae
->head
);
647 for (ae
= start
; ae
!= a
->head
; ae
= element_forw(ae
)) {
648 if (element_index(ae
) == i
) {
650 * Replacing an existing element.
652 array_dispose_element(new);
653 free(element_value(ae
));
654 ae
->value
= v
? savestring(v
) : (char *)NULL
;
657 } else if (element_index(ae
) > i
) {
664 array_dispose_element(new);
665 INVALIDATE_LASTREF(a
);
666 return (-1); /* problem */
670 * Delete the element with index I from array A and return it so the
671 * caller can dispose of it.
678 register ARRAY_ELEMENT
*ae
, *start
;
680 if (a
== 0 || array_empty(a
))
681 return((ARRAY_ELEMENT
*) NULL
);
682 start
= LASTREF_START(a
, i
);
683 for (ae
= start
; ae
!= a
->head
; ae
= element_forw(ae
))
684 if (element_index(ae
) == i
) {
685 ae
->next
->prev
= ae
->prev
;
686 ae
->prev
->next
= ae
->next
;
688 if (i
== array_max_index(a
))
689 a
->max_index
= element_index(ae
->prev
);
691 INVALIDATE_LASTREF(a
);
693 if (ae
->next
!= a
->head
)
694 SET_LASTREF(a
, ae
->next
);
695 else if (ae
->prev
!= a
->head
)
696 SET_LASTREF(a
, ae
->prev
);
698 INVALIDATE_LASTREF(a
);
702 return((ARRAY_ELEMENT
*) NULL
);
706 * Return the value of a[i].
709 array_reference(a
, i
)
713 register ARRAY_ELEMENT
*ae
, *start
;
715 if (a
== 0 || array_empty(a
))
716 return((char *) NULL
);
717 if (i
> array_max_index(a
))
718 return((char *)NULL
); /* Keep roving pointer into array to optimize sequential access */
719 start
= LASTREF_START(a
, i
);
720 for (ae
= start
; ae
!= a
->head
; ae
= element_forw(ae
))
721 if (element_index(ae
) == i
) {
723 return(element_value(ae
));
725 UNSET_LASTREF(); /* XXX SET_LASTREF(a, start) ? */
726 return((char *) NULL
);
729 /* Convenience routines for the shell to translate to and from the form used
730 by the rest of the code. */
733 array_to_word_list(a
)
739 if (a
== 0 || array_empty(a
))
740 return((WORD_LIST
*)NULL
);
741 list
= (WORD_LIST
*)NULL
;
742 for (ae
= element_forw(a
->head
); ae
!= a
->head
; ae
= element_forw(ae
))
743 list
= make_word_list (make_bare_word(element_value(ae
)), list
);
744 return (REVERSE_LIST(list
, WORD_LIST
*));
748 array_from_word_list (list
)
754 return((ARRAY
*)NULL
);
756 return (array_assign_list (a
, list
));
760 array_keys_to_word_list(a
)
767 if (a
== 0 || array_empty(a
))
768 return((WORD_LIST
*)NULL
);
769 list
= (WORD_LIST
*)NULL
;
770 for (ae
= element_forw(a
->head
); ae
!= a
->head
; ae
= element_forw(ae
)) {
771 t
= itos(element_index(ae
));
772 list
= make_word_list (make_bare_word(t
), list
);
775 return (REVERSE_LIST(list
, WORD_LIST
*));
779 array_assign_list (array
, list
)
783 register WORD_LIST
*l
;
784 register arrayind_t i
;
786 for (l
= list
, i
= 0; l
; l
= l
->next
, i
++)
787 array_insert(array
, i
, l
->word
->word
);
799 if (a
== 0 || array_empty(a
))
800 return ((char **)NULL
);
801 ret
= strvec_create (array_num_elements (a
) + 1);
803 for (ae
= element_forw(a
->head
); ae
!= a
->head
; ae
= element_forw(ae
)) {
804 t
= element_value (ae
);
805 ret
[i
++] = t
? savestring (t
) : (char *)NULL
;
807 ret
[i
] = (char *)NULL
;
812 * Return a string that is the concatenation of the elements in A from START
813 * to END, separated by SEP.
816 array_to_string_internal (start
, end
, sep
, quoted
)
817 ARRAY_ELEMENT
*start
, *end
;
823 int slen
, rsize
, rlen
, reg
;
825 if (start
== end
) /* XXX - should not happen */
826 return ((char *)NULL
);
830 for (rsize
= rlen
= 0, ae
= start
; ae
!= end
; ae
= element_forw(ae
)) {
832 result
= (char *)xmalloc (rsize
= 64);
833 if (element_value(ae
)) {
834 t
= quoted
? quote_string(element_value(ae
)) : element_value(ae
);
836 RESIZE_MALLOCED_BUFFER (result
, rlen
, (reg
+ slen
+ 2),
838 strcpy(result
+ rlen
, t
);
843 * Add a separator only after non-null elements.
845 if (element_forw(ae
) != end
) {
846 strcpy(result
+ rlen
, sep
);
852 result
[rlen
] = '\0'; /* XXX */
857 array_to_assign (a
, quoted
)
861 char *result
, *valstr
, *is
;
862 char indstr
[INT_STRLEN_BOUND(intmax_t) + 1];
864 int rsize
, rlen
, elen
;
866 if (a
== 0 || array_empty (a
))
867 return((char *)NULL
);
869 result
= (char *)xmalloc (rsize
= 128);
873 for (ae
= element_forw(a
->head
); ae
!= a
->head
; ae
= element_forw(ae
)) {
874 is
= inttostr (element_index(ae
), indstr
, sizeof(indstr
));
875 valstr
= element_value (ae
) ?
876 (ansic_shouldquote (element_value (ae
)) ?
877 ansic_quote (element_value(ae
), 0, (int *)0) :
878 sh_double_quote (element_value (ae
)))
880 elen
= STRLEN (is
) + 8 + STRLEN (valstr
);
881 RESIZE_MALLOCED_BUFFER (result
, rlen
, (elen
+ 1), rsize
, rsize
);
883 result
[rlen
++] = '[';
884 strcpy (result
+ rlen
, is
);
886 result
[rlen
++] = ']';
887 result
[rlen
++] = '=';
889 strcpy (result
+ rlen
, valstr
);
890 rlen
+= STRLEN (valstr
);
893 if (element_forw(ae
) != a
->head
)
894 result
[rlen
++] = ' ';
898 RESIZE_MALLOCED_BUFFER (result
, rlen
, 1, rsize
, 8);
899 result
[rlen
++] = ')';
902 /* This is not as efficient as it could be... */
903 valstr
= sh_single_quote (result
);
911 array_to_string (a
, sep
, quoted
)
917 return((char *)NULL
);
919 return(savestring(""));
920 return (array_to_string_internal (element_forw(a
->head
), a
->head
, sep
, quoted
));
923 #if defined (INCLUDE_UNUSED) || defined (TEST_ARRAY)
925 * Return an array consisting of elements in S, separated by SEP
928 array_from_string(s
, sep
)
935 return((ARRAY
*)NULL
);
936 w
= list_string (s
, sep
, 0);
938 return((ARRAY
*)NULL
);
939 a
= array_from_word_list (w
);
944 #if defined (TEST_ARRAY)
946 * To make a running version, compile -DTEST_ARRAY and link with:
947 * xmalloc.o syntax.o lib/malloc/libmalloc.a lib/sh/libsh.a
949 int interrupt_immediately
= 0;
959 fatal_error(const char *s
, ...)
961 fprintf(stderr
, "array_test: fatal memory error\n");
966 programming_error(const char *s
, ...)
968 fprintf(stderr
, "array_test: fatal programming error\n");
978 w
= (WORD_DESC
*)xmalloc(sizeof(WORD_DESC
));
979 w
->word
= s
? savestring(s
) : savestring ("");
991 w
= (WORD_LIST
*)xmalloc(sizeof(WORD_LIST
));
1006 return (WORD_LIST
*)NULL
;
1008 wl
= (WORD_LIST
*)NULL
;
1011 wl
= make_word_list (make_bare_word(a
), wl
);
1012 a
= strtok((char *)NULL
, t
);
1014 return (REVERSE_LIST (wl
, WORD_LIST
*));
1021 register GENERIC_LIST
*next
, *prev
;
1023 for (prev
= 0; list
; ) {
1033 pat_subst(s
, t
, u
, i
)
1037 return ((char *)NULL
);
1044 return savestring(s
);
1050 char lbuf
[INT_STRLEN_BOUND (intmax_t) + 1];
1052 printf("array[%s] = %s\n",
1053 inttostr (element_index(ae
), lbuf
, sizeof (lbuf
)),
1061 array_walk(a
, print_element
, (void *)NULL
);
1066 ARRAY
*a
, *new_a
, *copy_of_a
;
1067 ARRAY_ELEMENT
*ae
, *aew
;
1071 array_insert(a
, 1, "one");
1072 array_insert(a
, 7, "seven");
1073 array_insert(a
, 4, "four");
1074 array_insert(a
, 1029, "one thousand twenty-nine");
1075 array_insert(a
, 12, "twelve");
1076 array_insert(a
, 42, "forty-two");
1078 s
= array_to_string (a
, " ", 0);
1079 printf("s = %s\n", s
);
1080 copy_of_a
= array_from_string(s
, " ");
1081 printf("copy_of_a:");
1082 print_array(copy_of_a
);
1083 array_dispose(copy_of_a
);
1086 ae
= array_remove(a
, 4);
1087 array_dispose_element(ae
);
1088 ae
= array_remove(a
, 1029);
1089 array_dispose_element(ae
);
1090 array_insert(a
, 16, "sixteen");
1092 s
= array_to_string (a
, " ", 0);
1093 printf("s = %s\n", s
);
1094 copy_of_a
= array_from_string(s
, " ");
1095 printf("copy_of_a:");
1096 print_array(copy_of_a
);
1097 array_dispose(copy_of_a
);
1100 array_insert(a
, 2, "two");
1101 array_insert(a
, 1029, "new one thousand twenty-nine");
1102 array_insert(a
, 0, "zero");
1103 array_insert(a
, 134, "");
1105 s
= array_to_string (a
, ":", 0);
1106 printf("s = %s\n", s
);
1107 copy_of_a
= array_from_string(s
, ":");
1108 printf("copy_of_a:");
1109 print_array(copy_of_a
);
1110 array_dispose(copy_of_a
);
1113 new_a
= array_copy(a
);
1115 s
= array_to_string (new_a
, ":", 0);
1116 printf("s = %s\n", s
);
1117 copy_of_a
= array_from_string(s
, ":");
1119 printf("copy_of_a:");
1120 print_array(copy_of_a
);
1121 array_shift(copy_of_a
, 2, AS_DISPOSE
);
1122 printf("copy_of_a shifted by two:");
1123 print_array(copy_of_a
);
1124 ae
= array_shift(copy_of_a
, 2, 0);
1125 printf("copy_of_a shifted by two:");
1126 print_array(copy_of_a
);
1128 aew
= element_forw(ae
);
1129 array_dispose_element(ae
);
1132 array_rshift(copy_of_a
, 1, (char *)0);
1133 printf("copy_of_a rshift by 1:");
1134 print_array(copy_of_a
);
1135 array_rshift(copy_of_a
, 2, "new element zero");
1136 printf("copy_of_a rshift again by 2 with new element zero:");
1137 print_array(copy_of_a
);
1138 s
= array_to_assign(copy_of_a
, 0);
1139 printf("copy_of_a=%s\n", s
);
1141 ae
= array_shift(copy_of_a
, array_num_elements(copy_of_a
), 0);
1143 aew
= element_forw(ae
);
1144 array_dispose_element(ae
);
1147 array_dispose(copy_of_a
);
1150 array_dispose(new_a
);
1153 #endif /* TEST_ARRAY */
1154 #endif /* ARRAY_VARS */