commit bash-20200323 snapshot

This commit is contained in:
Chet Ramey
2020-03-27 10:30:38 -04:00
parent 0b39c3bcd3
commit 5f49ef47d1
50 changed files with 6699 additions and 5944 deletions
+55 -1
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.
@@ -874,6 +874,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;