diff options
author | Chet Ramey <chet.ramey@case.edu> | 2011-11-21 20:51:19 -0500 |
---|---|---|
committer | Chet Ramey <chet.ramey@case.edu> | 2011-11-21 20:51:19 -0500 |
commit | 0001803f0b9523c94fa2ede48eaecb047fef4524 (patch) | |
tree | f334332811e033ff966d94f6268f0629a94304b3 /builtins/mapfile.def | |
parent | 89a92869e56aba4e4cab2d639c00a86f0545c862 (diff) | |
download | android_external_bash-0001803f0b9523c94fa2ede48eaecb047fef4524.tar.gz android_external_bash-0001803f0b9523c94fa2ede48eaecb047fef4524.tar.bz2 android_external_bash-0001803f0b9523c94fa2ede48eaecb047fef4524.zip |
Bash-4.1 distribution source
Diffstat (limited to 'builtins/mapfile.def')
-rw-r--r-- | builtins/mapfile.def | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/builtins/mapfile.def b/builtins/mapfile.def index e37cd22..0946de3 100644 --- a/builtins/mapfile.def +++ b/builtins/mapfile.def @@ -24,11 +24,11 @@ $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 the standard input into an array variable. +Read lines from the standard input into an indexed 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 -the default ARRAY. +Read lines from the standard input into the indexed array variable ARRAY, or +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. @@ -50,7 +50,8 @@ If not supplied with an explicit origin, mapfile will clear ARRAY before assigning to it. Exit Status: -Returns success unless an invalid option is given or ARRAY is readonly. +Returns success unless an invalid option is given or ARRAY is readonly or +not an indexed array. $END $BUILTIN readarray @@ -71,6 +72,7 @@ $END #endif #include "bashansi.h" +#include "bashintl.h" #include <stdio.h> #include <errno.h> @@ -110,10 +112,10 @@ run_callback(callback, current_index) execlen += 2; execstr = xmalloc (execlen); - flags = 0; + flags = SEVAL_NOHIST; #if 0 if (interactive) - flags |= SEVAL_NOHIST|SEVAL_INTERACT; + flags |= SEVAL_INTERACT; #endif snprintf (execstr, execlen, "%s %d", callback, current_index); return parse_and_execute(execstr, NULL, flags); @@ -153,11 +155,17 @@ mapfile (fd, line_count_goal, origin, nskip, callback_quantum, callback, array_n entry = find_or_make_array_variable (array_name, 1); if (entry == 0 || readonly_p (entry) || noassign_p (entry)) { - if (readonly_p (entry)) + if (entry && readonly_p (entry)) err_readonly (array_name); return (EXECUTION_FAILURE); } + else if (array_p (entry) == 0) + { + builtin_error (_("%s: not an indexed array"), array_name); + return (EXECUTION_FAILURE); + } + if (flags & MAPF_CLEARARRAY) array_flush (array_cell (entry)); @@ -281,7 +289,7 @@ mapfile_builtin (list) break; case 'c': code = legal_number (list_optarg, &intval); - if (code == 0 || intval < 0 || intval != (unsigned)intval) + if (code == 0 || intval <= 0 || intval != (unsigned)intval) { builtin_error (_("%s: invalid callback quantum"), list_optarg); return (EXECUTION_FAILURE); |