Files
MSYS2-packages/bash/0001-bash-4.4-cygwin.patch
Christoph Reiter 717ea7ce37 bash: Update to 5.3.008
* Remove all hunks which are included upstream now.
* Remove the hunk for the !BUFFERED_INPUT case, that code path/macro
  has been dropped upstream completely.
* Some minor refresh for the "set_minus_o_option" hunk
* Add "int" to "extern igncr;" due to stricter compiler checks
2025-11-30 15:27:48 +01:00

502 lines
16 KiB
Diff

diff --git a/bashline.c b/bashline.c
index c85b05b..8f69bc6 100644
--- a/bashline.c
+++ b/bashline.c
@@ -80,6 +80,16 @@
# include "pcomplete.h"
#endif
+#if __CYGWIN__
+# ifdef __x86_64__
+# define IMP(x) __imp_##x
+# else
+# define IMP(x) _imp__##x
+# endif
+#else
+# define IMP(x) x
+#endif
+
/* These should agree with the defines for emacs_mode and vi_mode in
rldefs.h, even though that's not a public readline header file. */
#ifndef EMACS_EDITING_MODE
@@ -290,6 +300,11 @@ int no_empty_command_completion;
are the only possible matches, even if FIGNORE says to. */
int force_fignore = 1;
+#if __CYGWIN__
+/* If set, shorten "foo.exe" to "foo" when they are the same file. */
+int completion_strip_exe;
+#endif /* __CYGWIN__ */
+
/* Perform spelling correction on directory names during word completion */
int dircomplete_spelling = 0;
@@ -536,11 +551,12 @@ initialize_readline ()
kseq[0] = CTRL('J');
kseq[1] = '\0';
func = rl_function_of_keyseq (kseq, emacs_meta_keymap, (int *)NULL);
- if (func == rl_vi_editing_mode)
+ extern rl_command_func_t *IMP(rl_vi_editing_mode);
+ if (func == rl_vi_editing_mode || func == IMP(rl_vi_editing_mode))
rl_unbind_key_in_map (CTRL('J'), emacs_meta_keymap);
kseq[0] = CTRL('M');
func = rl_function_of_keyseq (kseq, emacs_meta_keymap, (int *)NULL);
- if (func == rl_vi_editing_mode)
+ if (func == rl_vi_editing_mode || func == IMP(rl_vi_editing_mode))
rl_unbind_key_in_map (CTRL('M'), emacs_meta_keymap);
#if defined (VI_MODE)
kseq[0] = CTRL('E');
@@ -562,7 +578,8 @@ initialize_readline ()
kseq[0] = '~';
kseq[1] = '\0';
func = rl_function_of_keyseq (kseq, emacs_meta_keymap, (int *)NULL);
- if (func == 0 || func == rl_tilde_expand)
+ extern rl_command_func_t *IMP(rl_tilde_expand);
+ if (func == 0 || func == rl_tilde_expand || func == IMP(rl_tilde_expand))
rl_bind_keyseq_in_map (kseq, bash_complete_username, emacs_meta_keymap);
rl_bind_key_if_unbound_in_map ('~', bash_possible_username_completions, emacs_ctlx_keymap);
@@ -585,7 +602,8 @@ initialize_readline ()
kseq[0] = TAB;
kseq[1] = '\0';
func = rl_function_of_keyseq (kseq, emacs_meta_keymap, (int *)NULL);
- if (func == 0 || func == rl_tab_insert)
+ extern rl_command_func_t *IMP(rl_tab_insert);
+ if (func == 0 || func == rl_tab_insert || func == IMP(rl_tab_insert))
rl_bind_key_in_map (TAB, dynamic_complete_history, emacs_meta_keymap);
/* Tell the completer that we want a crack first. */
@@ -2377,6 +2395,21 @@ globword:
if (match && executable_completion ((searching_path ? val : cval), searching_path))
{
+#if __CYGWIN__
+ if (completion_strip_exe)
+ {
+ size_t val_len = strlen (val);
+ char *candidate;
+ if (val_len > 4 && !strcasecmp (&val[val_len - 4], ".exe")
+ && (candidate = strdup (val)))
+ {
+ candidate[val_len - 4] = '\0';
+ if (same_file (val, candidate, NULL, NULL))
+ temp[strlen (temp) - 4] = '\0';
+ free (candidate);
+ }
+ }
+#endif
if (cval != val)
free (cval);
free (val);
diff --git a/builtins/read.def b/builtins/read.def
index 3c38bc0..62a5e07 100644
--- a/builtins/read.def
+++ b/builtins/read.def
@@ -768,6 +763,14 @@ read_builtin (list)
if (c == '\0' && delim != '\0')
continue; /* skip NUL bytes in input */
+#ifdef __CYGWIN__
+ {
+ extern int igncr;
+ if (igncr && c == '\r' && delim != '\r')
+ continue; /* skip carriage return */
+ }
+#endif
+
if ((skip_ctlesc == 0 && c == CTLESC) || (skip_ctlnul == 0 && c == CTLNUL))
{
saw_escape++;
diff --git a/builtins/set.def b/builtins/set.def
index 44f1769..51f28d2 100644
--- a/builtins/set.def
+++ b/builtins/set.def
@@ -84,6 +84,9 @@ Options:
#endif /* BANG_HISTORY */
#if defined (HISTORY)
history enable command history
+#endif
+#ifdef __CYGWIN__
+ igncr on Cygwin, ignore \r in line endings
#endif
ignoreeof the shell will not exit upon reading EOF
interactive-comments
@@ -176,6 +179,14 @@ static const char * const off = "off";
static int previous_option_value;
+#ifdef __CYGWIN__
+extern int igncr;
+static int set_minus_o_option_maybe (int, const char *, int);
+# define INTERACTIVE_ONLY ,1
+#else
+# define INTERACTIVE_ONLY
+#endif
+
/* A struct used to match long options for set -o to the corresponding
option letter or internal variable. The functions can be called to
dynamically generate values. If you add a new variable name here
@@ -187,29 +198,39 @@ const struct {
int *variable;
setopt_set_func_t *set_func;
setopt_get_func_t *get_func;
+#ifdef __CYGWIN__
+ /* Cygwin users have taken to exporting SHELLOPTS for the cygwin-specific
+ igncr. As a result, we want to ensure SHELLOPTS parsing does not turn
+ on interactive options when exported from an interactive shell, but
+ parse in a non-interactive setting, so as not to break POSIX /bin/sh */
+ int interactive_only;
+#endif
} o_options[] = {
{ "allexport", 'a', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#if defined (BRACE_EXPANSION)
{ "braceexpand",'B', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#endif
#if defined (READLINE)
- { "emacs", '\0', (int *)NULL, set_edit_mode, get_edit_mode },
+ { "emacs", '\0', (int *)NULL, set_edit_mode, get_edit_mode INTERACTIVE_ONLY },
#endif
{ "errexit", 'e', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "errtrace", 'E', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "functrace", 'T', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "hashall", 'h', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#if defined (BANG_HISTORY)
- { "histexpand", 'H', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
+ { "histexpand", 'H', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL INTERACTIVE_ONLY },
#endif /* BANG_HISTORY */
#if defined (HISTORY)
- { "history", '\0', &enable_history_list, bash_set_history, (setopt_get_func_t *)NULL },
+ { "history", '\0', &enable_history_list, bash_set_history, (setopt_get_func_t *)NULL INTERACTIVE_ONLY },
+#endif
+#ifdef __CYGWIN__
+ { "igncr", '\0', &igncr, NULL, (setopt_get_func_t *)NULL },
#endif
{ "ignoreeof", '\0', &ignoreeof, set_ignoreeof, (setopt_get_func_t *)NULL },
{ "interactive-comments", '\0', &interactive_comments, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "keyword", 'k', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#if defined (JOB_CONTROL)
- { "monitor", 'm', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
+ { "monitor", 'm', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL INTERACTIVE_ONLY },
#endif
{ "noclobber", 'C', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "noexec", 'n', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
@@ -228,7 +249,7 @@ const struct {
{ "privileged", 'p', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{ "verbose", 'v', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#if defined (READLINE)
- { "vi", '\0', (int *)NULL, set_edit_mode, get_edit_mode },
+ { "vi", '\0', (int *)NULL, set_edit_mode, get_edit_mode INTERACTIVE_ONLY },
#endif
{ "xtrace", 'x', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{(char *)NULL, 0 , (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
@@ -474,6 +495,15 @@
int
set_minus_o_option (int on_or_off, char *option_name)
+#ifdef __CYGWIN__
+{
+ /* See Cygwin comments above. */
+ return set_minus_o_option_maybe (on_or_off, option_name, 0);
+}
+static int
+set_minus_o_option_maybe (int on_or_off, const char *option_name,
+ int avoid_interactive)
+#endif /* __CYGWIN__ */
{
register int i;
@@ -496,6 +526,10 @@ set_minus_o_option (on_or_off, option_name)
return (EX_USAGE);
}
+#ifdef __CYGWIN__
+ if (o_options[i].interactive_only && avoid_interactive)
+ return EXECUTION_SUCCESS;
+#endif
if (o_options[i].letter == 0)
{
previous_option_value = GET_BINARY_O_OPTION_VALUE (i, o_options[i].name);
@@ -616,7 +650,11 @@ parse_shellopts (value)
vptr = 0;
while (vname = extract_colon_unit (value, &vptr))
{
+#ifdef __CYGWIN__
+ set_minus_o_option_maybe (FLAG_ON, vname, !interactive_shell);
+#else
set_minus_o_option (FLAG_ON, vname);
+#endif
free (vname);
}
}
diff --git a/builtins/shopt.def b/builtins/shopt.def
index 33d61d4..21eff3b 100644
--- a/builtins/shopt.def
+++ b/builtins/shopt.def
@@ -98,6 +98,10 @@ extern int varassign_redir_autoclose;
extern int singlequote_translations;
extern int patsub_replacement;
+#ifdef __CYGWIN__
+extern int completion_strip_exe;
+#endif
+
#if defined (EXTENDED_GLOB)
extern int extended_glob;
#endif
@@ -191,6 +195,9 @@ static struct {
{ "compat42", &shopt_compat42, set_compatibility_level },
{ "compat43", &shopt_compat43, set_compatibility_level },
{ "compat44", &shopt_compat44, set_compatibility_level },
+#ifdef __CYGWIN__
+ { "completion_strip_exe", &completion_strip_exe, NULL },
+#endif
#if defined (READLINE)
{ "complete_fullquote", &complete_fullquote, (shopt_set_func_t *)NULL},
{ "direxpand", &dircomplete_expand, shopt_set_complete_direxpand },
diff --git a/config-top.h b/config-top.h
index db4ab6e..8720ec8 100644
--- a/config-top.h
+++ b/config-top.h
@@ -97,10 +97,10 @@
#define DEFAULT_BASHRC "~/.bashrc"
/* System-wide .bashrc file for interactive shells. */
-/* #define SYS_BASHRC "/etc/bash.bashrc" */
+#define SYS_BASHRC "/etc/bash.bashrc"
/* System-wide .bash_logout for login shells. */
-/* #define SYS_BASH_LOGOUT "/etc/bash.bash_logout" */
+#define SYS_BASH_LOGOUT "/etc/bash.bash_logout"
/* Define this to make non-interactive shells begun with argv[0][0] == '-'
run the startup files when not in posix mode. */
@@ -110,7 +110,7 @@
sshd and source the .bashrc if so (like the rshd behavior). This checks
for the presence of SSH_CLIENT or SSH2_CLIENT in the initial environment,
which can be fooled under certain not-uncommon circumstances. */
-/* #define SSH_SOURCE_BASHRC */
+#define SSH_SOURCE_BASHRC
/* Define if you want the case-toggling operators (~[~]) and the
`capcase' variable attribute (declare -c). */
diff --git a/doc/Makefile.in b/doc/Makefile.in
index 8bf775e..923c9c3 100644
--- a/doc/Makefile.in
+++ b/doc/Makefile.in
@@ -191,7 +191,7 @@ bashref.html: $(BASHREF_FILES) $(HSUSER) $(RLUSER)
bash.info: $(BASHREF_FILES) $(HSUSER) $(RLUSER)
$(RM) $@
- $(MAKEINFO) -o $@ --no-split -I$(TEXINPUTDIR) $(srcdir)/bashref.texi
+ $(MAKEINFO) -o $@ --no-split -I$(TEXINPUTDIR) bashref.texi
bash.txt: bash.1
bash.ps: bash.1
@@ -254,9 +254,9 @@ install: info installdirs
-$(INSTALL_DATA) $(srcdir)/bashbug.1 $(DESTDIR)$(man1dir)/bashbug${man1ext}
-$(INSTALL_DATA) $(OTHER_DOCS) $(DESTDIR)$(docdir)
# uncomment the next lines to install the builtins man page
-# sed 's:bash\.1:man1/&:' $(srcdir)/builtins.1 > $${TMPDIR:-/var/tmp}/builtins.1
-# -$(INSTALL_DATA) $${TMPDIR:-/var/tmp}/builtins.1 $(DESTDIR)$(man1dir)/bash_builtins${man1ext}
-# -$(RM) $${TMPDIR:-/var/tmp}/builtins.1
+ sed 's:bash\.1:man1/&:' $(srcdir)/builtins.1 > $${TMPDIR:-/var/tmp}/builtins.1
+ -$(INSTALL_DATA) $${TMPDIR:-/var/tmp}/builtins.1 $(DESTDIR)$(man1dir)/bash_builtins${man1ext}
+ -$(RM) $${TMPDIR:-/var/tmp}/builtins.1
-if test -f bash.info; then d=.; else d=$(srcdir); fi; \
$(INSTALL_DATA) $$d/bash.info $(DESTDIR)$(infodir)/bash.info
# run install-info if it is present to update the info directory
diff --git a/doc/bash.1 b/doc/bash.1
index 55c5622..18f9676 100644
--- a/doc/bash.1
+++ b/doc/bash.1
@@ -10359,6 +10359,10 @@ filenames.
This variable is set by default, which is the default bash behavior in
versions through 4.2.
.TP 8
+.B completion_strip_exe
+If set, whenever bash sees \fIfoo.exe\fP during completion, it checks if
+\fIfoo\fP is the same file and strips the suffix.
+.TP 8
.B direxpand
If set,
.B bash
diff --git a/doc/bashref.texi b/doc/bashref.texi
index b0dc2fa..3793830 100644
--- a/doc/bashref.texi
+++ b/doc/bashref.texi
@@ -5650,6 +5650,10 @@ filenames.
This variable is set by default, which is the default Bash behavior in
versions through 4.2.
+@item completion_strip_exe
+If set, whenever bash sees @file{foo.exe} during completion, it checks if
+@file{foo} is the same file and strips the suffix.
+
@item direxpand
If set, Bash
replaces directory names with the results of word expansion when performing
diff --git a/doc/builtins.1 b/doc/builtins.1
index 43d92a2..3824dd7 100644
--- a/doc/builtins.1
+++ b/doc/builtins.1
@@ -19,6 +19,6 @@ shift, shopt, source, suspend, test, times, trap, true, type, typeset,
ulimit, umask, unalias, unset, wait \- bash built-in commands, see \fBbash\fR(1)
.SH BASH BUILTIN COMMANDS
.nr zZ 1
-.so bash.1
+.so man1/bash.1
.SH SEE ALSO
bash(1), sh(1)
diff --git a/general.c b/general.c
index 85c5a8b..f4c2a2f 100644
--- a/general.c
+++ b/general.c
@@ -54,6 +54,10 @@
#include <tilde/tilde.h>
+#ifdef __CYGWIN__
+# include <sys/cygwin.h>
+#endif
+
#if !defined (errno)
extern int errno;
#endif /* !errno */
diff --git a/input.c b/input.c
index 7b439f8..3944585 100644
--- a/input.c
+++ b/input.c
@@ -41,6 +41,10 @@
#include "externs.h"
#include "trap.h"
+#ifdef __CYGWIN__
+int igncr;
+#endif
+
#if !defined (errno)
extern int errno;
#endif /* !errno */
@@ -572,6 +576,19 @@ buffered_getchar ()
if (bash_input.location.buffered_fd < 0 || buffers[bash_input.location.buffered_fd] == 0)
return EOF;
+#ifdef __CYGWIN__
+ /* shopt igncr discards carriage returns from the input stream.
+ If cr is the only character left in the buffer, recurse to pick
+ up the next byte; otherwise flatten the buffer. */
+ if (igncr)
+ {
+ int ch;
+ while ((ch = bufstream_getc (buffers[bash_input.location.buffered_fd]))
+ == '\r')
+ ;
+ return ch;
+ }
+#endif
#if !defined (DJGPP)
return (bufstream_getc (buffers[bash_input.location.buffered_fd]));
#else
diff --git a/lib/sh/pathphys.c b/lib/sh/pathphys.c
index 95b72f1..f7edbed 100644
--- a/lib/sh/pathphys.c
+++ b/lib/sh/pathphys.c
@@ -35,6 +35,7 @@
#include <stdio.h>
#include <chartypes.h>
#include <errno.h>
+#include <stdlib.h>
#include "shell.h"
@@ -76,6 +77,9 @@ sh_physpath (path, flags)
char *path;
int flags;
{
+#ifdef __CYGWIN__
+ return realpath (path, NULL);
+#endif
char tbuf[PATH_MAX+1], linkbuf[PATH_MAX+1];
char *result, *p, *q, *qsave, *qbase, *workpath;
int double_slash_path, linklen, nlink;
diff --git a/lib/sh/tmpfile.c b/lib/sh/tmpfile.c
index ef8b067..2c18ee3 100644
--- a/lib/sh/tmpfile.c
+++ b/lib/sh/tmpfile.c
@@ -101,7 +101,7 @@ get_tmpdir (flags)
if (tdir && (file_iswdir (tdir) == 0 || strlen (tdir) > PATH_MAX))
tdir = 0;
- if (tdir == 0)
+ if (tdir == 0 || !file_iswdir (tdir))
tdir = get_sys_tmpdir ();
#if defined (HAVE_PATHCONF) && defined (_PC_NAME_MAX)
diff --git a/parse.y b/parse.y
index d887eec..0ae3458 100644
--- a/parse.y
+++ b/parse.y
@@ -1620,14 +1620,20 @@ yy_string_get ()
string = bash_input.location.string;
/* If the string doesn't exist, or is empty, EOF found. */
- if (string && *string)
+ while (string && *string)
{
c = *string++;
bash_input.location.string = string;
+#ifdef __CYGWIN__
+ {
+ extern int igncr;
+ if (igncr && c == '\r')
+ continue;
+ }
+#endif
return (c);
}
- else
- return (EOF);
+ return (EOF);
}
static int
diff --git a/subst.c b/subst.c
index d9feabc..2001b4e 100644
--- a/subst.c
+++ b/subst.c
@@ -43,6 +43,7 @@
#include "posixstat.h"
#include "bashintl.h"
+#define NEED_SH_SETLINEBUF_DECL
#include "shell.h"
#include "parser.h"
#include "redir.h"
@@ -6821,6 +6822,13 @@ read_comsub (fd, quoted, flags, rflag)
#endif
continue;
}
+#ifdef __CYGWIN__
+ {
+ extern int igncr;
+ if (igncr && c == '\r')
+ continue;
+ }
+#endif
/* Add the character to ISTRING, possibly after resizing it. */
RESIZE_MALLOCED_BUFFER (istring, istring_index, mb_cur_max+1, istring_size, 512);
diff --git a/support/mkversion.sh b/support/mkversion.sh
index 5960a42..d72c44c 100755
--- a/support/mkversion.sh
+++ b/support/mkversion.sh
@@ -29,7 +29,7 @@ source_dir="."
while [ $# -gt 0 ]; do
case "$1" in
-o) shift; OUTFILE=$1; shift ;;
- -b) shift; inc_build=yes ;;
+ -b) shift; ;; # inc_build=yes ;; # hacked out for cygport
-s) shift; rel_status=$1; shift ;;
-p) shift; patch_level=$1; shift ;;
-d) shift; dist_version=$1; shift ;;