Imported from ../bash-4.0.tar.gz.
This commit is contained in:
parent
3185942a52
commit
17345e5ad2
134 changed files with 74214 additions and 4584 deletions
|
@ -321,6 +321,16 @@ sh_wrerror ()
|
|||
builtin_error (_("write error: %s"), strerror (errno));
|
||||
}
|
||||
|
||||
void
|
||||
sh_ttyerror (set)
|
||||
int set;
|
||||
{
|
||||
if (set)
|
||||
builtin_error (_("error setting terminal attributes: %s"), strerror (errno));
|
||||
else
|
||||
builtin_error (_("error getting terminal attributes: %s"), strerror (errno));
|
||||
}
|
||||
|
||||
int
|
||||
sh_chkwrite (s)
|
||||
int s;
|
||||
|
|
|
@ -81,6 +81,7 @@ extern void sh_nojobs __P((char *));
|
|||
extern void sh_restricted __P((char *));
|
||||
extern void sh_notbuiltin __P((char *));
|
||||
extern void sh_wrerror __P((void));
|
||||
extern void sh_ttyerror __P((int));
|
||||
extern int sh_chkwrite __P((int));
|
||||
|
||||
extern char **make_builtin_argv __P((WORD_LIST *, int *));
|
||||
|
|
|
@ -266,10 +266,7 @@ parse_and_execute (string, from_file, flags)
|
|||
global_command = (COMMAND *)NULL;
|
||||
|
||||
if ((subshell_environment & SUBSHELL_COMSUB) && comsub_ignore_return)
|
||||
{
|
||||
command->flags |= CMD_IGNORE_RETURN;
|
||||
itrace("parse_and_execute: turned on CMD_IGNORE_RETURN from comsub_ignore_return");
|
||||
}
|
||||
|
||||
#if defined (ONESHOT)
|
||||
/*
|
||||
|
|
|
@ -24,7 +24,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]
|
||||
Read lines from a file into an array variable.
|
||||
Read lines from the standard input into an array variable.
|
||||
|
||||
Read lines from the standard input into the array variable ARRAY, or from
|
||||
file descriptor FD if the -u option is supplied. The variable MAPFILE is
|
||||
|
@ -42,7 +42,9 @@ Options:
|
|||
Arguments:
|
||||
ARRAY Array variable name to use for file data.
|
||||
|
||||
If -C is supplied without -c, the default quantum is 5000.
|
||||
If -C is supplied without -c, the default quantum is 5000. When
|
||||
CALLBACK is evaluated, it is supplied the index of the next array
|
||||
element to be assigned as an additional argument.
|
||||
|
||||
If not supplied with an explicit origin, mapfile will clear ARRAY before
|
||||
assigning to it.
|
||||
|
@ -51,6 +53,14 @@ Exit Status:
|
|||
Returns success unless an invalid option is given or ARRAY is readonly.
|
||||
$END
|
||||
|
||||
$BUILTIN readarray
|
||||
$FUNCTION mapfile_builtin
|
||||
$SHORT_DOC readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
|
||||
Read lines from a file into an array variable.
|
||||
|
||||
A synonym for `mapfile'.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "builtins.h"
|
||||
|
@ -70,7 +80,6 @@ $END
|
|||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
#endif
|
||||
|
@ -93,6 +102,7 @@ run_callback(callback, current_index)
|
|||
{
|
||||
unsigned int execlen;
|
||||
char *execstr;
|
||||
int flags;
|
||||
|
||||
execlen = strlen (callback) + 10;
|
||||
/* 1 for space between %s and %d,
|
||||
|
@ -100,8 +110,13 @@ run_callback(callback, current_index)
|
|||
execlen += 2;
|
||||
execstr = xmalloc (execlen);
|
||||
|
||||
flags = 0;
|
||||
#if 0
|
||||
if (interactive)
|
||||
flags |= SEVAL_NOHIST|SEVAL_INTERACT;
|
||||
#endif
|
||||
snprintf (execstr, execlen, "%s %d", callback, current_index);
|
||||
return parse_and_execute(execstr, NULL, 0);
|
||||
return parse_and_execute(execstr, NULL, flags);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -136,8 +151,13 @@ mapfile (fd, line_count_goal, origin, nskip, callback_quantum, callback, array_n
|
|||
here allows us to call bind_array_element instead of bind_array_variable
|
||||
and skip the variable lookup on every call. */
|
||||
entry = find_or_make_array_variable (array_name, 1);
|
||||
if (entry == 0)
|
||||
return (EXECUTION_FAILURE);
|
||||
if (entry == 0 || readonly_p (entry) || noassign_p (entry))
|
||||
{
|
||||
if (readonly_p (entry))
|
||||
err_readonly (array_name);
|
||||
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
if (flags & MAPF_CLEARARRAY)
|
||||
array_flush (array_cell (entry));
|
||||
|
||||
|
@ -147,19 +167,24 @@ mapfile (fd, line_count_goal, origin, nskip, callback_quantum, callback, array_n
|
|||
unbuffered_read = 1;
|
||||
#endif
|
||||
|
||||
zreset ();
|
||||
|
||||
/* Skip any lines at beginning of file? */
|
||||
for (line_count = 0; line_count < nskip; line_count++)
|
||||
zgetline(fd, &line, &line_length, unbuffered_read);
|
||||
if (zgetline (fd, &line, &line_length, unbuffered_read) < 0)
|
||||
break;
|
||||
|
||||
line = 0;
|
||||
line_length = 0;
|
||||
|
||||
/* Reset the buffer for bash own stream */
|
||||
for (array_index = origin, line_count = 0;
|
||||
zgetline(fd, &line, &line_length, unbuffered_read) != -1;
|
||||
interrupt_immediately++;
|
||||
for (array_index = origin, line_count = 1;
|
||||
zgetline (fd, &line, &line_length, unbuffered_read) != -1;
|
||||
array_index++, line_count++)
|
||||
{
|
||||
/* Have we exceeded # of lines to store? */
|
||||
if (line_count_goal != 0 && line_count >= line_count_goal)
|
||||
if (line_count_goal != 0 && line_count > line_count_goal)
|
||||
break;
|
||||
|
||||
/* Remove trailing newlines? */
|
||||
|
@ -184,6 +209,7 @@ mapfile (fd, line_count_goal, origin, nskip, callback_quantum, callback, array_n
|
|||
if (unbuffered_read == 0)
|
||||
zsyncfd (fd);
|
||||
|
||||
interrupt_immediately--;
|
||||
return EXECUTION_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -879,16 +879,18 @@ vbprintf (format, va_alist)
|
|||
|
||||
SH_VA_START (args, format);
|
||||
blen = vsnprintf (vbuf + vblen, vbsize - vblen, format, args);
|
||||
va_end (args);
|
||||
|
||||
nlen = vblen + blen + 1;
|
||||
if (nlen >= vbsize)
|
||||
{
|
||||
vbsize = ((nlen + 63) >> 6) << 6;
|
||||
vbuf = (char *)xrealloc (vbuf, vbsize);
|
||||
SH_VA_START (args, format);
|
||||
blen = vsnprintf (vbuf + vblen, vbsize - vblen, format, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
va_end (args);
|
||||
vblen += blen;
|
||||
vbuf[vblen] = '\0';
|
||||
|
||||
|
|
|
@ -290,9 +290,8 @@ read_builtin (list)
|
|||
}
|
||||
list = loptend;
|
||||
|
||||
/* `read -t 0 var' returns failure immediately. XXX - should it test
|
||||
whether input is available with select/FIONREAD, and fail if those
|
||||
are unavailable? */
|
||||
/* `read -t 0 var' tests whether input is available with select/FIONREAD,
|
||||
and fails if those are unavailable */
|
||||
if (have_timeout && tmsec == 0 && tmusec == 0)
|
||||
#if 0
|
||||
return (EXECUTION_FAILURE);
|
||||
|
@ -417,10 +416,9 @@ read_builtin (list)
|
|||
termsave.attrs = &ttattrs;
|
||||
|
||||
ttset = ttattrs;
|
||||
if (silent)
|
||||
ttfd_cbreak (fd, &ttset); /* ttcbreak () */
|
||||
else
|
||||
ttfd_onechar (fd, &ttset); /* ttonechar () */
|
||||
i = silent ? ttfd_cbreak (fd, &ttset) : ttfd_onechar (fd, &ttset);
|
||||
if (i < 0)
|
||||
sh_ttyerror (1);
|
||||
add_unwind_protect ((Function *)ttyrestore, (char *)&termsave);
|
||||
}
|
||||
}
|
||||
|
@ -432,7 +430,9 @@ read_builtin (list)
|
|||
termsave.attrs = &ttattrs;
|
||||
|
||||
ttset = ttattrs;
|
||||
ttfd_noecho (fd, &ttset); /* ttnoecho (); */
|
||||
i = ttfd_noecho (fd, &ttset); /* ttnoecho (); */
|
||||
if (i < 0)
|
||||
sh_ttyerror (1);
|
||||
|
||||
add_unwind_protect ((Function *)ttyrestore, (char *)&termsave);
|
||||
}
|
||||
|
|
|
@ -135,6 +135,19 @@ Exit Status:
|
|||
Returns the status of the last command executed.
|
||||
$END
|
||||
|
||||
$BUILTIN coproc
|
||||
$SHORT_DOC coproc [NAME] command [redirections]
|
||||
Create a coprocess named NAME.
|
||||
|
||||
Execute COMMAND asynchronously, with the standard output and standard
|
||||
input of the command connected via a pipe to file descriptors assigned
|
||||
to indices 0 and 1 of an array variable NAME in the executing shell.
|
||||
The default NAME is "COPROC".
|
||||
|
||||
Exit Status:
|
||||
Returns the exit status of COMMAND.
|
||||
$END
|
||||
|
||||
$BUILTIN function
|
||||
$SHORT_DOC function name { COMMANDS ; } or name () { COMMANDS ; }
|
||||
Define shell function.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue