Bash-4.4 distribution sources and documentation

This commit is contained in:
Chet Ramey 2016-09-15 16:59:08 -04:00
commit a0c0a00fc4
588 changed files with 130746 additions and 80164 deletions

View file

@ -2,7 +2,7 @@ This file is mapfile.def, from which is created mapfile.c.
It implements the builtin "mapfile" in Bash.
Copyright (C) 2005-2006 Rocky Bernstein for Free Software Foundation, Inc.
Copyright (C) 2008-2012 Free Software Foundation, Inc.
Copyright (C) 2008-2016 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -23,7 +23,7 @@ $PRODUCES mapfile.c
$BUILTIN mapfile
$FUNCTION mapfile_builtin
$SHORT_DOC mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
$SHORT_DOC mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
Read lines from the standard input into an indexed array variable.
Read lines from the standard input into the indexed array variable ARRAY, or
@ -31,16 +31,18 @@ from file descriptor FD if the -u option is supplied. The variable MAPFILE
is the default ARRAY.
Options:
-n count Copy at most COUNT lines. If COUNT is 0, all lines are copied.
-O origin Begin assigning to ARRAY at index ORIGIN. The default index is 0.
-s count Discard the first COUNT lines read.
-t Remove a trailing newline from each line read.
-u fd Read lines from file descriptor FD instead of the standard input.
-C callback Evaluate CALLBACK each time QUANTUM lines are read.
-c quantum Specify the number of lines read between each call to CALLBACK.
-d delim Use DELIM to terminate lines, instead of newline
-n count Copy at most COUNT lines. If COUNT is 0, all lines are copied
-O origin Begin assigning to ARRAY at index ORIGIN. The default index is 0
-s count Discard the first COUNT lines read
-t Remove a trailing DELIM from each line read (default newline)
-u fd Read lines from file descriptor FD instead of the standard input
-C callback Evaluate CALLBACK each time QUANTUM lines are read
-c quantum Specify the number of lines read between each call to
CALLBACK
Arguments:
ARRAY Array variable name to use for file data.
ARRAY Array variable name to use for file data
If -C is supplied without -c, the default quantum is 5000. When
CALLBACK is evaluated, it is supplied the index of the next array
@ -101,6 +103,8 @@ static int run_callback __P((const char *, unsigned int, const char *));
#define MAPF_CLEARARRAY 0x01
#define MAPF_CHOP 0x02
static int delim;
static int
run_callback (callback, curindex, curline)
const char *callback;
@ -129,21 +133,23 @@ run_callback (callback, curindex, curline)
}
static void
do_chop(line)
char * line;
do_chop(line, delim)
char *line;
unsigned char delim;
{
int length;
length = strlen (line);
if (length && line[length-1] == '\n')
if (length && line[length-1] == delim)
line[length-1] = '\0';
}
static int
mapfile (fd, line_count_goal, origin, nskip, callback_quantum, callback, array_name, flags)
mapfile (fd, line_count_goal, origin, nskip, callback_quantum, callback, array_name, delim, flags)
int fd;
long line_count_goal, origin, nskip, callback_quantum;
char *callback, *array_name;
int delim;
int flags;
{
char *line;
@ -184,11 +190,14 @@ mapfile (fd, line_count_goal, origin, nskip, callback_quantum, callback, array_n
unbuffered_read = 1;
#endif
if (delim != '\n')
unbuffered_read = 1;
zreset ();
/* Skip any lines at beginning of file? */
for (line_count = 0; line_count < nskip; line_count++)
if (zgetline (fd, &line, &line_length, unbuffered_read) < 0)
if (zgetline (fd, &line, &line_length, delim, unbuffered_read) < 0)
break;
line = 0;
@ -196,12 +205,12 @@ mapfile (fd, line_count_goal, origin, nskip, callback_quantum, callback, array_n
/* Reset the buffer for bash own stream */
for (array_index = origin, line_count = 1;
zgetline (fd, &line, &line_length, unbuffered_read) != -1;
zgetline (fd, &line, &line_length, delim, unbuffered_read) != -1;
array_index++)
{
/* Remove trailing newlines? */
if (flags & MAPF_CHOP)
do_chop (line);
do_chop (line, delim);
/* Has a callback been registered and if so is it time to call it? */
if (callback && line_count && (line_count % callback_quantum) == 0)
@ -246,12 +255,16 @@ mapfile_builtin (list)
flags = MAPF_CLEARARRAY;
callback_quantum = DEFAULT_QUANTUM;
callback = 0;
delim = '\n';
reset_internal_getopt ();
while ((opt = internal_getopt (list, "u:n:O:tC:c:s:")) != -1)
while ((opt = internal_getopt (list, "d:u:n:O:tC:c:s:")) != -1)
{
switch (opt)
{
case 'd':
delim = *list_optarg;
break;
case 'u':
code = legal_number (list_optarg, &intval);
if (code == 0 || intval < 0 || intval != (int)intval)
@ -317,6 +330,7 @@ mapfile_builtin (list)
else
nskip = intval;
break;
CASE_HELPOPT;
default:
builtin_usage ();
return (EX_USAGE);
@ -339,13 +353,13 @@ mapfile_builtin (list)
else
array_name = list->word->word;
if (legal_identifier (array_name) == 0 && valid_array_reference (array_name) == 0)
if (legal_identifier (array_name) == 0)
{
sh_invalidid (array_name);
return (EXECUTION_FAILURE);
}
return mapfile (fd, lines, origin, nskip, callback_quantum, callback, array_name, flags);
return mapfile (fd, lines, origin, nskip, callback_quantum, callback, array_name, delim, flags);
}
#else