forked from msys2/MSYS2-packages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0005-bash-4.3-msys2-fix-lineendings.patch
213 lines (201 loc) · 4.9 KB
/
0005-bash-4.3-msys2-fix-lineendings.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
diff --git a/bashline.c b/bashline.c
index 8f69bc6..6d285c5 100644
--- a/bashline.c
+++ b/bashline.c
@@ -822,7 +822,11 @@ snarf_hosts_from_file (filename)
char *temp, buffer[256], name[256];
register int i, start;
- file = fopen (filename, "r");
+#ifdef __MSYS__
+ file = fopen (filename, "rt");
+#else
+ file = fopen (filename, "r");
+#endif
if (file == 0)
return;
diff --git a/builtins/fc.def b/builtins/fc.def
index 9b8a997..5be93bd 100644
--- a/builtins/fc.def
+++ b/builtins/fc.def
@@ -681,6 +681,10 @@ fc_readline (stream)
FILE *stream;
{
register int c;
+#ifdef __MSYS__
+ register int d;
+#endif
+
int line_len = 0, lindex = 0;
char *line = (char *)NULL;
@@ -691,12 +695,19 @@ fc_readline (stream)
if (c == '\n')
{
+#ifdef __MSYS__
+ if (d == '\r')
+ lindex--;
+#endif
line[lindex++] = '\n';
line[lindex++] = '\0';
return (line);
}
else
line[lindex++] = c;
+#ifdef __MSYS__
+ d = c;
+#endif
}
if (!lindex)
diff --git a/general.c b/general.c
index f4c2a2f..0ae74ca 100644
--- a/general.c
+++ b/general.c
@@ -818,7 +818,8 @@ int
absolute_program (string)
const char *string;
{
- return ((char *)mbschr (string, '/') != (char *)NULL);
+ return ((char *)mbschr (string, '/') != (char *)NULL ||
+ (char *)mbschr (string, '\\') != (char *)NULL);
}
/* **************************************************************** */
diff --git a/lib/readline/display.c b/lib/readline/display.c
index c1135ec..b388af6 100644
--- a/lib/readline/display.c
+++ b/lib/readline/display.c
@@ -529,7 +529,10 @@ expand_prompt (char *pmt, int flags, int *lp, int *lip, int *niflp, int *vlp)
if (lp)
*lp = rl;
if (lip)
- *lip = last;
+ /* Hack: faking that the last character is invisible seems to work around
+ prompt display bugs. I wish I knew what the real bug was... */
+ *lip = r - ret;
+/* *lip = last; */
if (niflp)
*niflp = invfl;
if (vlp)
diff --git a/parse.y b/parse.y
index 0ae3458..c6e9520 100644
--- a/parse.y
+++ b/parse.y
@@ -1459,7 +1459,13 @@ yy_input_name ()
static int
yy_getc ()
{
- return (*(bash_input.getter)) ();
+#ifdef __MSYS__
+ int c;
+ while ((c = (*(bash_input.getter)) ()) == '\r');
+ return c;
+#else
+ return (*(bash_input.getter)) ();
+#endif
}
/* Call this to unget C. That is, to make C the next character
diff --git a/shell.c b/shell.c
index ee9d445..8f25726 100644
--- a/shell.c
+++ b/shell.c
@@ -1696,7 +1696,11 @@ open_shell_script (script_name)
default_buffered_input = fd;
SET_CLOSE_ON_EXEC (default_buffered_input);
#else /* !BUFFERED_INPUT */
- default_input = fdopen (fd, "r");
+#ifdef __MSYS__
+ default_input = fdopen (fd, "rt");
+#else
+ default_input = fdopen (fd, "r");
+#endif
if (default_input == 0)
{
diff --git a/stringlib.c b/stringlib.c
index 7330496..8623fa6 100644
--- a/stringlib.c
+++ b/stringlib.c
@@ -278,7 +278,15 @@ strip_trailing (string, len, newlines_only)
{
if ((newlines_only && string[len] == '\n') ||
(!newlines_only && whitespace (string[len])))
+ {
len--;
+#ifdef __MSYS__
+ if (newlines_only && string[len + 1] == '\n' && string[len] == '\r')
+ {
+ len--;
+ }
+#endif
+ }
else
break;
}
diff --git a/subst.c b/subst.c
index 2001b4e..3ba2029 100644
--- a/subst.c
+++ b/subst.c
@@ -6895,6 +6895,15 @@ read_comsub (fd, quoted, flags, rflag)
/* If the newline was quoted, remove the quoting char. */
if (istring[istring_index - 1] == CTLESC)
--istring_index;
+
+ if (istring_index > 0 && istring[istring_index - 1] == '\r')
+ {
+ --istring_index;
+
+ /* If the caret return was quoted, remove the quoting char. */
+ if (istring[istring_index - 1] == CTLESC)
+ --istring_index;
+ }
}
else
break;
diff --git a/variables.c b/variables.c
index 028667c..a10594d 100644
--- a/variables.c
+++ b/variables.c
@@ -2593,6 +2593,20 @@ set_if_not (name, value)
{
SHELL_VAR *v;
+#if defined (__MSYS__)
+ /* Remove trailing \r from value */
+ {
+ char *tpos;
+ if (value && *value)
+ {
+ tpos = strchr (value, '\0');
+ tpos--;
+ if (*tpos == '\r')
+ *tpos = '\0';
+ }
+ }
+#endif
+
if (shell_variables == 0)
create_variable_tables ();
diff --git a/y.tab.c b/y.tab.c
index 32b4c7c..ac70820 100644
--- a/y.tab.c
+++ b/y.tab.c
@@ -3770,7 +3770,13 @@ yy_input_name ()
static int
yy_getc ()
{
- return (*(bash_input.getter)) ();
+#ifdef __MSYS__
+ int c;
+ while ((c = (*(bash_input.getter)) ()) == '\r');
+ return c;
+#else
+ return (*(bash_input.getter)) ();
+#endif
}
/* Call this to unget C. That is, to make C the next character
@@ -4746,6 +4752,10 @@ shell_getc (remove_quoted_newline)
else
RESIZE_MALLOCED_BUFFER (shell_input_line, i, 2, shell_input_line_size, 256);
+#ifdef __MSYS__
+ if (c == '\r')
+ continue;
+#endif
if (c == EOF)
{
if (bash_input.type == st_stream)