* Chet Ramey
* chet@ins.cwru.edu
*/
+
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Bash; see the file COPYING. If not, write to the Free Software
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+
#include "config.h"
#if defined (ARRAY_VARS)
#if defined (HAVE_UNISTD_H)
+# ifdef _MINIX
+# include <sys/types.h>
+# endif
# include <unistd.h>
#endif
#include <stdio.h>
+#include "bashansi.h"
+
#include "shell.h"
#include "array.h"
#include "builtins/common.h"
return(a1);
}
+#ifdef INCLUDE_UNUSED
/*
* Make and return a new array composed of the elements in array A from
* S to E, inclusive.
a->num_elements = a->max_index = i;
return a;
}
+#endif
+#ifdef INCLUDE_UNUSED
ARRAY_ELEMENT *
copy_array_element(ae)
ARRAY_ELEMENT *ae;
return(ae ? new_array_element(element_index(ae), element_value(ae))
: (ARRAY_ELEMENT *) NULL);
}
+#endif
/*
* Add a new element with index I and value V to array A (a[i] = v).
return((char *) NULL);
}
+#ifdef TEST_ARRAY
/*
* Walk the array, calling FUNC once for each element, with the array
* element as the argument.
for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae))
(*func)(ae);
}
+#endif
/*
* Return a string that is the concatenation of all the elements in A,
for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae)) {
indstr = itos (element_index(ae));
- valstr = element_value (ae) ? double_quote (element_value(ae))
+ valstr = element_value (ae) ? sh_double_quote (element_value(ae))
: (char *)NULL;
elen = STRLEN (indstr) + 8 + STRLEN (valstr);
RESIZE_MALLOCED_BUFFER (result, rlen, (elen + 1), rsize, rsize);
if (sv == 0)
return ((char *)NULL);
- vstr = single_quote (sv);
+ vstr = sh_single_quote (sv);
free (sv);
return (vstr);
}
}
#endif
+#if defined (INCLUDE_UNUSED) || defined (TEST_ARRAY)
/*
* Return an array consisting of elements in S, separated by SEP
*/
a = word_list_to_array (w);
return (a);
}
+#endif
/* Convenience routines for the shell to translate to and from the form used
by the rest of the code. */
return (REVERSE_LIST(list, WORD_LIST *));
}
+char **
+array_to_argv (a)
+ARRAY *a;
+{
+ char **ret, *t;
+ int i;
+ ARRAY_ELEMENT *ae;
+
+ if (a == 0 || array_empty(a))
+ return ((char **)NULL);
+ ret = alloc_array (array_num_elements (a) + 1);
+ i = 0;
+ for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae)) {
+ t = element_value (ae);
+ ret[i++] = t ? savestring (t) : (char *)NULL;
+ }
+ ret[i] = (char *)NULL;
+ return (ret);
+}
+
ARRAY *
assign_word_list (array, list)
ARRAY *array;
array_add_element(a, 12, "twelve");
array_add_element(a, 42, "forty-two");
print_array(a);
- s = array_to_string (a, " ");
+ s = array_to_string (a, " ", 0);
printf("s = %s\n", s);
copy_of_a = string_to_array(s, " ");
printf("copy_of_a:");
destroy_array_element(ae);
array_add_element(a, 16, "sixteen");
print_array(a);
- s = array_to_string (a, " ");
+ s = array_to_string (a, " ", 0);
printf("s = %s\n", s);
copy_of_a = string_to_array(s, " ");
printf("copy_of_a:");
array_add_element(a, 0, "zero");
array_add_element(a, 134, "");
print_array(a);
- s = array_to_string (a, ":");
+ s = array_to_string (a, ":", 0);
printf("s = %s\n", s);
copy_of_a = string_to_array(s, ":");
printf("copy_of_a:");
free(s);
new_a = copy_array(a);
print_array(new_a);
- s = array_to_string (new_a, ":");
+ s = array_to_string (new_a, ":", 0);
printf("s = %s\n", s);
- copy_of_a = string_to_array(s, ":");
+ copy_of_a = string_to_array(s, ":", 0);
printf("copy_of_a:");
print_array(copy_of_a);
dispose_array(copy_of_a);