Skip to content

Commit f1be666

Browse files
committed
Imported from ../bash-3.2.48.tar.gz.
1 parent 0628567 commit f1be666

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+702
-158
lines changed

array.c

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ ARRAY *a;
120120
return(a1);
121121
}
122122

123-
#ifdef INCLUDE_UNUSED
124123
/*
125124
* Make and return a new array composed of the elements in array A from
126125
* S to E, inclusive.
@@ -141,13 +140,12 @@ ARRAY_ELEMENT *s, *e;
141140
for (p = s, i = 0; p != e; p = element_forw(p), i++) {
142141
n = array_create_element (element_index(p), element_value(p));
143142
ADD_BEFORE(a->head, n);
144-
mi = element_index(ae);
143+
mi = element_index(n);
145144
}
146145
a->num_elements = i;
147146
a->max_index = mi;
148147
return a;
149148
}
150-
#endif
151149

152150
/*
153151
* Walk the array, calling FUNC once for each element, with the array
@@ -300,6 +298,23 @@ ARRAY *array;
300298
return array;
301299
}
302300

301+
ARRAY *
302+
array_quote_escapes(array)
303+
ARRAY *array;
304+
{
305+
ARRAY_ELEMENT *a;
306+
char *t;
307+
308+
if (array == 0 || array_head(array) == 0 || array_empty(array))
309+
return (ARRAY *)NULL;
310+
for (a = element_forw(array->head); a != array->head; a = element_forw(a)) {
311+
t = quote_escapes (a->value);
312+
FREE(a->value);
313+
a->value = t;
314+
}
315+
return array;
316+
}
317+
303318
/*
304319
* Return a string whose elements are the members of array A beginning at
305320
* index START and spanning NELEM members. Null elements are counted.
@@ -311,9 +326,10 @@ ARRAY *a;
311326
arrayind_t start, nelem;
312327
int starsub, quoted;
313328
{
329+
ARRAY *a2;
314330
ARRAY_ELEMENT *h, *p;
315331
arrayind_t i;
316-
char *ifs, sep[2];
332+
char *ifs, sep[2], *t;
317333

318334
p = a ? array_head (a) : 0;
319335
if (p == 0 || array_empty (a) || start > array_max_index(a))
@@ -336,14 +352,24 @@ int starsub, quoted;
336352
for (i = 0, h = p; p != a->head && i < nelem; i++, p = element_forw(p))
337353
;
338354

355+
a2 = array_slice(a, h, p);
356+
357+
if (quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT))
358+
array_quote(a2);
359+
else
360+
array_quote_escapes(a2);
361+
339362
if (starsub && (quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT))) {
340363
ifs = getifs();
341364
sep[0] = ifs ? *ifs : '\0';
342365
} else
343366
sep[0] = ' ';
344367
sep[1] = '\0';
345368

346-
return (array_to_string_internal (h, p, sep, quoted));
369+
t = array_to_string (a2, sep, 0);
370+
array_dispose(a2);
371+
372+
return t;
347373
}
348374

349375
char *
@@ -367,7 +393,9 @@ int mflags;
367393
}
368394

369395
if (mflags & MATCH_QUOTED)
370-
array_quote (a2);
396+
array_quote(a2);
397+
else
398+
array_quote_escapes(a2);
371399
if (mflags & MATCH_STARSUB) {
372400
ifs = getifs();
373401
sifs[0] = ifs ? *ifs : '\0';
@@ -655,7 +683,7 @@ int quoted;
655683
is = inttostr (element_index(ae), indstr, sizeof(indstr));
656684
valstr = element_value (ae) ? sh_double_quote (element_value(ae))
657685
: (char *)NULL;
658-
elen = STRLEN (indstr) + 8 + STRLEN (valstr);
686+
elen = STRLEN (is) + 8 + STRLEN (valstr);
659687
RESIZE_MALLOCED_BUFFER (result, rlen, (elen + 1), rsize, rsize);
660688

661689
result[rlen++] = '[';

array.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ extern int array_rshift __P((ARRAY *, int, char *));
5555
extern ARRAY_ELEMENT *array_unshift_element __P((ARRAY *));
5656
extern int array_shift_element __P((ARRAY *, char *));
5757
extern ARRAY *array_quote __P((ARRAY *));
58+
extern ARRAY *array_quote_escapes __P((ARRAY *));
5859

5960
extern char *array_subrange __P((ARRAY *, arrayind_t, arrayind_t, int, int));
6061
extern char *array_patsub __P((ARRAY *, char *, char *, int));

arrayfunc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,8 @@ array_expand_index (s, len)
618618
if (expok == 0)
619619
{
620620
last_command_exit_value = EXECUTION_FAILURE;
621+
622+
top_level_cleanup ();
621623
jump_to_top_level (DISCARD);
622624
}
623625
return val;
@@ -720,7 +722,7 @@ array_value_internal (s, quoted, allow_all, rtype)
720722
if (ALL_ELEMENT_SUB (t[0]) && t[1] == ']')
721723
{
722724
if (rtype)
723-
*rtype = 1;
725+
*rtype = (t[0] == '*') ? 1 : 2;
724726
if (allow_all == 0)
725727
{
726728
err_badarraysub (s);

bashhist.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ static struct ignorevar histignore =
8080
list. This is different than the user-controlled behaviour; this
8181
becomes zero when we read lines from a file, for example. */
8282
int remember_on_history = 1;
83+
int enable_history_list = 1; /* value for `set -o history' */
8384

8485
/* The number of lines that Bash has added to this history session. The
8586
difference between the number of the top element in the history list
@@ -234,7 +235,7 @@ bash_history_reinit (interact)
234235
history_expansion = interact != 0;
235236
history_expansion_inhibited = 1;
236237
#endif
237-
remember_on_history = interact != 0;
238+
remember_on_history = enable_history_list = interact != 0;
238239
history_inhibit_expansion_function = bash_history_inhibit_expansion;
239240
}
240241

bashhist.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#define HC_IGNBOTH (HC_IGNSPACE|HC_IGNDUPS)
3232

3333
extern int remember_on_history;
34+
extern int enable_history_list; /* value for `set -o history' */
35+
extern int literal_history; /* controlled by `shopt lithist' */
36+
extern int force_append_history;
3437
extern int history_lines_this_session;
3538
extern int history_lines_in_file;
3639
extern int history_expansion;

bashline.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2357,7 +2357,7 @@ bash_directory_completion_hook (dirname)
23572357
if (should_expand_dirname)
23582358
{
23592359
new_dirname = savestring (local_dirname);
2360-
wl = expand_prompt_string (new_dirname, 0); /* does the right thing */
2360+
wl = expand_prompt_string (new_dirname, 0, W_NOCOMSUB); /* does the right thing */
23612361
if (wl)
23622362
{
23632363
*dirname = string_list (wl);

builtins/common.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
1+
/* Copyright (C) 1987-2007 Free Software Foundation, Inc.
22
33
This file is part of GNU Bash, the Bourne Again SHell.
44
@@ -131,6 +131,7 @@ no_args (list)
131131
if (list)
132132
{
133133
builtin_error (_("too many arguments"));
134+
top_level_cleanup ();
134135
jump_to_top_level (DISCARD);
135136
}
136137
}
@@ -395,7 +396,10 @@ get_numeric_arg (list, fatal)
395396
if (fatal)
396397
throw_to_top_level ();
397398
else
398-
jump_to_top_level (DISCARD);
399+
{
400+
top_level_cleanup ();
401+
jump_to_top_level (DISCARD);
402+
}
399403
}
400404
no_args (list->next);
401405
}
@@ -475,7 +479,11 @@ get_working_directory (for_whom)
475479

476480
if (the_current_working_directory == 0)
477481
{
482+
#if defined (GETCWD_BROKEN)
483+
the_current_working_directory = getcwd (0, PATH_MAX);
484+
#else
478485
the_current_working_directory = getcwd (0, 0);
486+
#endif
479487
if (the_current_working_directory == 0)
480488
{
481489
fprintf (stderr, _("%s: error retrieving current directory: %s: %s\n"),

builtins/evalstring.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ int parse_and_execute_level = 0;
6767

6868
static int cat_file __P((REDIRECT *));
6969

70+
#if defined (HISTORY)
71+
static void
72+
set_history_remembering ()
73+
{
74+
remember_on_history = enable_history_list;
75+
}
76+
#endif
77+
7078
/* How to force parse_and_execute () to clean up after itself. */
7179
void
7280
parse_and_execute_cleanup ()
@@ -115,7 +123,10 @@ parse_and_execute (string, from_file, flags)
115123
lreset = flags & SEVAL_RESETLINE;
116124

117125
#if defined (HISTORY)
118-
unwind_protect_int (remember_on_history); /* can be used in scripts */
126+
if (parse_and_execute_level == 0)
127+
add_unwind_protect (set_history_remembering, (char *)NULL);
128+
else
129+
unwind_protect_int (remember_on_history); /* can be used in scripts */
119130
# if defined (BANG_HISTORY)
120131
if (interactive_shell)
121132
{
@@ -237,6 +248,7 @@ parse_and_execute (string, from_file, flags)
237248
* parse_and_execute has not been called recursively AND
238249
* we're not running a trap AND
239250
* we have parsed the full command (string == '\0') AND
251+
* we're not going to run the exit trap AND
240252
* we have a simple command without redirections AND
241253
* the command is not being timed AND
242254
* the command's return status is not being inverted
@@ -247,7 +259,8 @@ parse_and_execute (string, from_file, flags)
247259
running_trap == 0 &&
248260
*bash_input.location.string == '\0' &&
249261
command->type == cm_simple &&
250-
!command->redirects && !command->value.Simple->redirects &&
262+
signal_is_trapped (EXIT_TRAP) == 0 &&
263+
command->redirects == 0 && command->value.Simple->redirects == 0 &&
251264
((command->flags & CMD_TIME_PIPELINE) == 0) &&
252265
((command->flags & CMD_INVERT_RETURN) == 0))
253266
{

builtins/printf.def

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
This file is printf.def, from which is created printf.c.
22
It implements the builtin "printf" in Bash.
33

4-
Copyright (C) 1997-2005 Free Software Foundation, Inc.
4+
Copyright (C) 1997-2007 Free Software Foundation, Inc.
55

66
This file is part of GNU Bash, the Bourne Again SHell.
77

@@ -49,6 +49,12 @@ $END
4949
# define INT_MIN (-2147483647-1)
5050
#endif
5151

52+
#if defined (PREFER_STDARG)
53+
# include <stdarg.h>
54+
#else
55+
# include <varargs.h>
56+
#endif
57+
5258
#include <stdio.h>
5359
#include <chartypes.h>
5460

@@ -64,6 +70,10 @@ $END
6470
#include "bashgetopt.h"
6571
#include "common.h"
6672

73+
#if defined (PRI_MACROS_BROKEN)
74+
# undef PRIdMAX
75+
#endif
76+
6777
#if !defined (PRIdMAX)
6878
# if HAVE_LONG_LONG
6979
# define PRIdMAX "lld"
@@ -151,6 +161,10 @@ extern int errno;
151161
#define SKIP1 "#'-+ 0"
152162
#define LENMODS "hjlLtz"
153163

164+
#ifndef HAVE_ASPRINTF
165+
extern int asprintf __P((char **, const char *, ...)) __attribute__((__format__ (printf, 2, 3)));
166+
#endif
167+
154168
static void printf_erange __P((char *));
155169
static int printstr __P((char *, char *, int, int, int));
156170
static int tescape __P((char *, char *, int *));

builtins/read.def

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@ read_builtin (list)
127127
WORD_LIST *list;
128128
{
129129
register char *varname;
130-
int size, i, nr, pass_next, saw_escape, eof, opt, retval, code;
131-
int input_is_tty, input_is_pipe, unbuffered_read;
130+
int size, i, nr, pass_next, saw_escape, eof, opt, retval, code, print_ps2;
131+
int input_is_tty, input_is_pipe, unbuffered_read, skip_ctlesc, skip_ctlnul;
132132
int raw, edit, nchars, silent, have_timeout, fd;
133133
unsigned int tmout;
134134
intmax_t intval;
135135
char c;
136136
char *input_string, *orig_input_string, *ifs_chars, *prompt, *arrayname;
137-
char *e, *t, *t1;
137+
char *e, *t, *t1, *ps2, *tofree;
138138
struct stat tsb;
139139
SHELL_VAR *var;
140140
#if defined (ARRAY_VARS)
@@ -148,6 +148,7 @@ read_builtin (list)
148148
USE_VAR(size);
149149
USE_VAR(i);
150150
USE_VAR(pass_next);
151+
USE_VAR(print_ps2);
151152
USE_VAR(saw_escape);
152153
USE_VAR(input_is_pipe);
153154
/* USE_VAR(raw); */
@@ -163,6 +164,7 @@ read_builtin (list)
163164
USE_VAR(rlind);
164165
#endif
165166
USE_VAR(list);
167+
USE_VAR(ps2);
166168

167169
i = 0; /* Index into the string that we are reading. */
168170
raw = edit = 0; /* Not reading raw input by default. */
@@ -386,7 +388,8 @@ read_builtin (list)
386388
setmode (0, O_TEXT);
387389
#endif
388390

389-
for (eof = retval = 0;;)
391+
ps2 = 0;
392+
for (print_ps2 = eof = retval = 0;;)
390393
{
391394
#if defined (READLINE)
392395
if (edit)
@@ -412,6 +415,15 @@ read_builtin (list)
412415
{
413416
#endif
414417

418+
if (print_ps2)
419+
{
420+
if (ps2 == 0)
421+
ps2 = get_string_value ("PS2");
422+
fprintf (stderr, "%s", ps2 ? ps2 : "");
423+
fflush (stderr);
424+
print_ps2 = 0;
425+
}
426+
415427
if (unbuffered_read)
416428
retval = zread (fd, &c, 1);
417429
else
@@ -440,7 +452,11 @@ read_builtin (list)
440452
{
441453
pass_next = 0;
442454
if (c == '\n')
443-
i--; /* back up over the CTLESC */
455+
{
456+
i--; /* back up over the CTLESC */
457+
if (interactive && input_is_tty && raw == 0)
458+
print_ps2 = 1;
459+
}
444460
else
445461
goto add_char;
446462
continue;
@@ -658,12 +674,13 @@ add_char:
658674
#else
659675
/* Check whether or not the number of fields is exactly the same as the
660676
number of variables. */
677+
tofree = NULL;
661678
if (*input_string)
662679
{
663680
t1 = input_string;
664681
t = get_word_from_string (&input_string, ifs_chars, &e);
665682
if (*input_string == 0)
666-
input_string = t;
683+
tofree = input_string = t;
667684
else
668685
input_string = strip_trailing_ifs_whitespace (t1, ifs_chars, saw_escape);
669686
}
@@ -678,6 +695,8 @@ add_char:
678695
else
679696
var = bind_read_variable (list->word->word, input_string);
680697
stupidly_hack_special_variables (list->word->word);
698+
FREE (tofree);
699+
681700
if (var)
682701
VUNSETATTR (var, att_invisible);
683702
xfree (orig_input_string);

0 commit comments

Comments
 (0)