fix problem with saving tty state after running a command with 'bind -x'; builtins that create associative arrays can now convert existing scalar variables to associative arrays

This commit is contained in:
Chet Ramey
2022-03-11 16:09:24 -05:00
parent b4e5e5505c
commit b6a567e7f1
10 changed files with 77 additions and 43 deletions
+7 -7
View File
@@ -39,9 +39,9 @@
element of array variable CSV, starting at index 0. The format of LINE is
as described in RFC 4180. */
static int
csvsplit (csv, line)
csvsplit (csv, line, dstring)
SHELL_VAR *csv;
char *line;
char *line, *dstring;
{
arrayind_t ind;
char *field, *prev, *buf, *xbuf;
@@ -67,7 +67,7 @@ csvsplit (csv, line)
buf[b++] = *field++; /* skip double quote */
else if (qstate == DQUOTE && *field == '"')
qstate = NQUOTE;
else if (qstate == NQUOTE && *field == ',')
else if (qstate == NQUOTE && *field == *dstring)
break;
else
/* This copies any text between a closing double quote and the
@@ -80,7 +80,7 @@ csvsplit (csv, line)
else
{
buf = prev;
field = prev + strcspn (prev, ",");
field = prev + strcspn (prev, dstring);
}
delim = *field;
@@ -91,10 +91,10 @@ csvsplit (csv, line)
*field = delim;
if (delim == ',')
if (delim == *dstring)
prev = field + 1;
}
while (delim == ',');
while (delim == *dstring);
if (xbuf)
free (xbuf);
@@ -165,7 +165,7 @@ csv_builtin (list)
if (csvstring == 0 || *csvstring == 0)
return (EXECUTION_SUCCESS);
opt = csvsplit (v, csvstring);
opt = csvsplit (v, csvstring, ",");
/* Maybe do something with OPT here, it's the number of fields */
return (rval);
+16 -6
View File
@@ -3,7 +3,7 @@
/* See Makefile for compilation details. */
/*
Copyright (C) 2016 Free Software Foundation, Inc.
Copyright (C) 2016,2022 Free Software Foundation, Inc.
This file is part of GNU Bash.
Bash is free software: you can redistribute it and/or modify
@@ -390,6 +390,12 @@ stat_builtin (list)
}
}
if (legal_identifier (aname) == 0)
{
sh_invalidid (aname);
return (EXECUTION_FAILURE);
}
list = loptend;
if (list == 0)
{
@@ -397,6 +403,10 @@ stat_builtin (list)
return (EX_USAGE);
}
#if 0
unbind_variable (aname);
#endif
fname = list->word->word;
if (getstat (fname, flags, &st) < 0)
@@ -405,8 +415,7 @@ stat_builtin (list)
return (EXECUTION_FAILURE);
}
unbind_variable (aname);
v = make_new_assoc_variable (aname);
v = find_or_make_array_variable (aname, 3);
if (v == 0)
{
builtin_error ("%s: cannot create variable", aname);
@@ -430,9 +439,10 @@ char *stat_doc[] = {
"",
"Take a filename and load the status information returned by a",
"stat(2) call on that file into the associative array specified",
"by the -A option. The default array name is STAT. If the -L",
"option is supplied, stat does not resolve symbolic links and",
"reports information about the link itself. The -l option results",
"by the -A option. The default array name is STAT.",
"",
"If the -L option is supplied, stat does not resolve symbolic links",
"and reports information about the link itself. The -l option results",
"in longer-form listings for some of the fields. When -l is used,",
"the -F option supplies a format string passed to strftime(3) to",
"display the file time information.",