diff options
author | cvpcs <root@cvpcs.org> | 2010-06-03 02:20:07 -0500 |
---|---|---|
committer | cvpcs <root@cvpcs.org> | 2010-06-03 02:20:07 -0500 |
commit | a013d4e66d2545c04e2599aa2e4a4fc50468153d (patch) | |
tree | 415d0a5af06f28f3e3b6b389ff6818e3ee774ff8 /builtins/shift.c | |
parent | 772f20abb0a3a0979c440114bf3a1cff5b3cef03 (diff) | |
download | external_bash-a013d4e66d2545c04e2599aa2e4a4fc50468153d.zip external_bash-a013d4e66d2545c04e2599aa2e4a4fc50468153d.tar.gz external_bash-a013d4e66d2545c04e2599aa2e4a4fc50468153d.tar.bz2 |
first successful build of bash-4.1
Diffstat (limited to 'builtins/shift.c')
-rw-r--r-- | builtins/shift.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/builtins/shift.c b/builtins/shift.c new file mode 100644 index 0000000..e07e8e9 --- /dev/null +++ b/builtins/shift.c @@ -0,0 +1,72 @@ +/* shift.c, created from shift.def. */ +#line 22 "./shift.def" + +#include <config.h> + +#if defined (HAVE_UNISTD_H) +# ifdef _MINIX +# include <sys/types.h> +# endif +# include <unistd.h> +#endif + +#include "../bashansi.h" +#include "../bashintl.h" + +#include "../shell.h" +#include "common.h" + +#line 49 "./shift.def" + +int print_shift_error; + +/* Shift the arguments ``left''. Shift DOLLAR_VARS down then take one + off of REST_OF_ARGS and place it into DOLLAR_VARS[9]. If LIST has + anything in it, it is a number which says where to start the + shifting. Return > 0 if `times' > $#, otherwise 0. */ +int +shift_builtin (list) + WORD_LIST *list; +{ + intmax_t times; + register int count; + WORD_LIST *temp; + + if (get_numeric_arg (list, 0, ×) == 0) + return (EXECUTION_FAILURE); + + if (times == 0) + return (EXECUTION_SUCCESS); + else if (times < 0) + { + sh_erange (list ? list->word->word : NULL, _("shift count")); + return (EXECUTION_FAILURE); + } + else if (times > number_of_args ()) + { + if (print_shift_error) + sh_erange (list ? list->word->word : NULL, _("shift count")); + return (EXECUTION_FAILURE); + } + + while (times-- > 0) + { + if (dollar_vars[1]) + free (dollar_vars[1]); + + for (count = 1; count < 9; count++) + dollar_vars[count] = dollar_vars[count + 1]; + + if (rest_of_args) + { + temp = rest_of_args; + dollar_vars[9] = savestring (temp->word->word); + rest_of_args = rest_of_args->next; + temp->next = (WORD_LIST *)NULL; + dispose_words (temp); + } + else + dollar_vars[9] = (char *)NULL; + } + return (EXECUTION_SUCCESS); +} |