bash-5.1 distribution sources and documentation

This commit is contained in:
Chet Ramey
2020-12-06 15:51:17 -05:00
parent 36f2c406ff
commit 8868edaf22
828 changed files with 94641 additions and 56509 deletions

87
array.c
View File

@@ -9,7 +9,7 @@
* chet@ins.cwru.edu
*/
/* Copyright (C) 1997-2016 Free Software Foundation, Inc.
/* Copyright (C) 1997-2020 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -61,7 +61,7 @@
ae->next = new; \
} while (0)
static char *array_to_string_internal __P((ARRAY_ELEMENT *, ARRAY_ELEMENT *, char *, int));
static char *array_to_string_internal PARAMS((ARRAY_ELEMENT *, ARRAY_ELEMENT *, char *, int));
static char *spacesep = " ";
@@ -398,10 +398,10 @@ ARRAY *array;
* Since arrays are sparse, unset array elements are not counted.
*/
char *
array_subrange (a, start, nelem, starsub, quoted)
array_subrange (a, start, nelem, starsub, quoted, pflags)
ARRAY *a;
arrayind_t start, nelem;
int starsub, quoted;
int starsub, quoted, pflags;
{
ARRAY *a2;
ARRAY_ELEMENT *h, *p;
@@ -436,7 +436,7 @@ int starsub, quoted;
array_dispose(a2);
if (wl == 0)
return (char *)NULL;
t = string_list_pos_params(starsub ? '*' : '@', wl, quoted);
t = string_list_pos_params(starsub ? '*' : '@', wl, quoted, pflags); /* XXX */
dispose_words(wl);
return t;
@@ -449,7 +449,7 @@ char *pat, *rep;
int mflags;
{
char *t;
int pchar, qflags;
int pchar, qflags, pflags;
WORD_LIST *wl, *save;
if (a == 0 || array_head(a) == 0 || array_empty(a))
@@ -467,8 +467,9 @@ int mflags;
pchar = (mflags & MATCH_STARSUB) == MATCH_STARSUB ? '*' : '@';
qflags = (mflags & MATCH_QUOTED) == MATCH_QUOTED ? Q_DOUBLE_QUOTES : 0;
pflags = (mflags & MATCH_ASSIGNRHS) ? PF_ASSIGNRHS : 0;
t = string_list_pos_params (pchar, save, qflags);
t = string_list_pos_params (pchar, save, qflags, pflags);
dispose_words(save);
return t;
@@ -482,7 +483,7 @@ int modop;
int mflags;
{
char *t;
int pchar, qflags;
int pchar, qflags, pflags;
WORD_LIST *wl, *save;
if (a == 0 || array_head(a) == 0 || array_empty(a))
@@ -500,8 +501,9 @@ int mflags;
pchar = (mflags & MATCH_STARSUB) == MATCH_STARSUB ? '*' : '@';
qflags = (mflags & MATCH_QUOTED) == MATCH_QUOTED ? Q_DOUBLE_QUOTES : 0;
pflags = (mflags & MATCH_ASSIGNRHS) ? PF_ASSIGNRHS : 0;
t = string_list_pos_params (pchar, save, qflags);
t = string_list_pos_params (pchar, save, qflags, pflags);
dispose_words(save);
return t;
@@ -808,22 +810,29 @@ WORD_LIST *list;
}
char **
array_to_argv (a)
array_to_argv (a, countp)
ARRAY *a;
int *countp;
{
char **ret, *t;
int i;
ARRAY_ELEMENT *ae;
if (a == 0 || array_empty(a))
if (a == 0 || array_empty(a)) {
if (countp)
*countp = 0;
return ((char **)NULL);
}
ret = strvec_create (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;
if (t)
ret[i++] = savestring (t);
}
ret[i] = (char *)NULL;
if (countp)
*countp = i;
return (ret);
}
@@ -872,6 +881,60 @@ int quoted;
return(result);
}
char *
array_to_kvpair (a, quoted)
ARRAY *a;
int quoted;
{
char *result, *valstr, *is;
char indstr[INT_STRLEN_BOUND(intmax_t) + 1];
ARRAY_ELEMENT *ae;
int rsize, rlen, elen;
if (a == 0 || array_empty (a))
return((char *)NULL);
result = (char *)xmalloc (rsize = 128);
result[rlen = 0] = '\0';
for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae)) {
is = inttostr (element_index(ae), indstr, sizeof(indstr));
valstr = element_value (ae) ?
(ansic_shouldquote (element_value (ae)) ?
ansic_quote (element_value(ae), 0, (int *)0) :
sh_double_quote (element_value (ae)))
: (char *)NULL;
elen = STRLEN (is) + 8 + STRLEN (valstr);
RESIZE_MALLOCED_BUFFER (result, rlen, (elen + 1), rsize, rsize);
strcpy (result + rlen, is);
rlen += STRLEN (is);
result[rlen++] = ' ';
if (valstr) {
strcpy (result + rlen, valstr);
rlen += STRLEN (valstr);
} else {
strcpy (result + rlen, "\"\"");
rlen += 2;
}
if (element_forw(ae) != a->head)
result[rlen++] = ' ';
FREE (valstr);
}
RESIZE_MALLOCED_BUFFER (result, rlen, 1, rsize, 8);
result[rlen] = '\0';
if (quoted) {
/* This is not as efficient as it could be... */
valstr = sh_single_quote (result);
free (result);
result = valstr;
}
return(result);
}
char *
array_to_assign (a, quoted)
ARRAY *a;