mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-06-27 07:43:07 +02:00
Bash-5.3-alpha release
This commit is contained in:
+31
-51
@@ -1,6 +1,6 @@
|
||||
/* stringvec.c - functions for managing arrays of strings. */
|
||||
|
||||
/* Copyright (C) 2000-2002 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 2000-2002,2022-2023 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#endif
|
||||
|
||||
#include <bashansi.h>
|
||||
#include <stdckdint.h>
|
||||
#include <stdio.h>
|
||||
#include <chartypes.h>
|
||||
|
||||
@@ -34,42 +35,35 @@
|
||||
|
||||
/* Allocate an array of strings with room for N members. */
|
||||
char **
|
||||
strvec_create (n)
|
||||
int n;
|
||||
strvec_create (size_t n)
|
||||
{
|
||||
return ((char **)xmalloc ((n) * sizeof (char *)));
|
||||
return ((char **)xreallocarray (NULL, n, sizeof (char *)));
|
||||
}
|
||||
|
||||
/* Allocate an array of strings with room for N members. */
|
||||
char **
|
||||
strvec_mcreate (n)
|
||||
int n;
|
||||
strvec_mcreate (size_t n)
|
||||
{
|
||||
return ((char **)malloc ((n) * sizeof (char *)));
|
||||
return ((char **)reallocarray (NULL, n, sizeof (char *)));
|
||||
}
|
||||
|
||||
char **
|
||||
strvec_resize (array, nsize)
|
||||
char **array;
|
||||
int nsize;
|
||||
strvec_resize (char **array, size_t nsize)
|
||||
{
|
||||
return ((char **)xrealloc (array, nsize * sizeof (char *)));
|
||||
return ((char **)xreallocarray (array, nsize, sizeof (char *)));
|
||||
}
|
||||
|
||||
char **
|
||||
strvec_mresize (array, nsize)
|
||||
char **array;
|
||||
int nsize;
|
||||
strvec_mresize (char **array, size_t nsize)
|
||||
{
|
||||
return ((char **)realloc (array, nsize * sizeof (char *)));
|
||||
return ((char **)reallocarray (array, nsize, sizeof (char *)));
|
||||
}
|
||||
|
||||
/* Return the length of ARRAY, a NULL terminated array of char *. */
|
||||
int
|
||||
strvec_len (array)
|
||||
char **array;
|
||||
size_t
|
||||
strvec_len (char * const *array)
|
||||
{
|
||||
register int i;
|
||||
register size_t i;
|
||||
|
||||
for (i = 0; array[i]; i++);
|
||||
return (i);
|
||||
@@ -77,10 +71,9 @@ strvec_len (array)
|
||||
|
||||
/* Free the contents of ARRAY, a NULL terminated array of char *. */
|
||||
void
|
||||
strvec_flush (array)
|
||||
char **array;
|
||||
strvec_flush (char **array)
|
||||
{
|
||||
register int i;
|
||||
register size_t i;
|
||||
|
||||
if (array == 0)
|
||||
return;
|
||||
@@ -90,8 +83,7 @@ strvec_flush (array)
|
||||
}
|
||||
|
||||
void
|
||||
strvec_dispose (array)
|
||||
char **array;
|
||||
strvec_dispose (char **array)
|
||||
{
|
||||
if (array == 0)
|
||||
return;
|
||||
@@ -101,10 +93,9 @@ strvec_dispose (array)
|
||||
}
|
||||
|
||||
int
|
||||
strvec_remove (array, name)
|
||||
char **array, *name;
|
||||
strvec_remove (char **array, const char *name)
|
||||
{
|
||||
register int i, j;
|
||||
size_t i, j;
|
||||
char *x;
|
||||
|
||||
if (array == 0)
|
||||
@@ -124,11 +115,10 @@ strvec_remove (array, name)
|
||||
|
||||
/* Find NAME in ARRAY. Return the index of NAME, or -1 if not present.
|
||||
ARRAY should be NULL terminated. */
|
||||
int
|
||||
strvec_search (array, name)
|
||||
char **array, *name;
|
||||
ptrdiff_t
|
||||
strvec_search (char **array, const char *name)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; array[i]; i++)
|
||||
if (STREQ (name, array[i]))
|
||||
@@ -139,11 +129,9 @@ strvec_search (array, name)
|
||||
|
||||
/* Allocate and return a new copy of ARRAY and its contents. */
|
||||
char **
|
||||
strvec_copy (array)
|
||||
char **array;
|
||||
strvec_copy (char * const *array)
|
||||
{
|
||||
register int i;
|
||||
int len;
|
||||
size_t i, len;
|
||||
char **ret;
|
||||
|
||||
len = strvec_len (array);
|
||||
@@ -161,8 +149,7 @@ strvec_copy (array)
|
||||
|
||||
Perform a bytewise comparison if *S1 and *S2 collate equally. */
|
||||
int
|
||||
strvec_posixcmp (s1, s2)
|
||||
register char **s1, **s2;
|
||||
strvec_posixcmp (char **s1, char **s2)
|
||||
{
|
||||
int result;
|
||||
|
||||
@@ -181,8 +168,7 @@ strvec_posixcmp (s1, s2)
|
||||
/* Comparison routine for use with qsort() on arrays of strings. Uses
|
||||
strcoll(3) if available, otherwise it uses strcmp(3). */
|
||||
int
|
||||
strvec_strcmp (s1, s2)
|
||||
register char **s1, **s2;
|
||||
strvec_strcmp (char **s1, char **s2)
|
||||
{
|
||||
#if defined (HAVE_STRCOLL)
|
||||
return (strcoll (*s1, *s2));
|
||||
@@ -198,9 +184,7 @@ strvec_strcmp (s1, s2)
|
||||
|
||||
/* Sort ARRAY, a null terminated array of pointers to strings. */
|
||||
void
|
||||
strvec_sort (array, posix)
|
||||
char **array;
|
||||
int posix;
|
||||
strvec_sort (char **array, int posix)
|
||||
{
|
||||
if (posix)
|
||||
qsort (array, strvec_len (array), sizeof (char *), (QSFUNC *)strvec_posixcmp);
|
||||
@@ -217,14 +201,12 @@ strvec_sort (array, posix)
|
||||
space at the beginning of the array. */
|
||||
|
||||
char **
|
||||
strvec_from_word_list (list, alloc, starting_index, ip)
|
||||
WORD_LIST *list;
|
||||
int alloc, starting_index, *ip;
|
||||
strvec_from_word_list (WORD_LIST *list, int alloc, int starting_index, int *ip)
|
||||
{
|
||||
int count;
|
||||
size_t count;
|
||||
char **array;
|
||||
|
||||
count = list_length (list);
|
||||
count = list_length ((GENERIC_LIST *)list);
|
||||
array = (char **)xmalloc ((1 + count + starting_index) * sizeof (char *));
|
||||
|
||||
for (count = 0; count < starting_index; count++)
|
||||
@@ -244,13 +226,11 @@ strvec_from_word_list (list, alloc, starting_index, ip)
|
||||
in ARRAY to begin. */
|
||||
|
||||
WORD_LIST *
|
||||
strvec_to_word_list (array, alloc, starting_index)
|
||||
char **array;
|
||||
int alloc, starting_index;
|
||||
strvec_to_word_list (char **array, int alloc, int starting_index)
|
||||
{
|
||||
WORD_LIST *list;
|
||||
WORD_DESC *w;
|
||||
int i, count;
|
||||
size_t i, count;
|
||||
|
||||
if (array == 0 || array[0] == 0)
|
||||
return (WORD_LIST *)NULL;
|
||||
|
||||
Reference in New Issue
Block a user