[480230bc] | 1 | Submitted By: William Harrington (kb0iic at cross-lfs dot org)
|
---|
| 2 | Date: 09-26-2014
|
---|
| 3 | Initial Package Version: 4.3
|
---|
| 4 | Origin: Upstream
|
---|
| 5 | Upstream Status: Applied
|
---|
| 6 | Description: Contains all upstream patches up to 4.3-026
|
---|
| 7 |
|
---|
| 8 | diff -Naur bash-4.3.orig/arrayfunc.c bash-4.3/arrayfunc.c
|
---|
| 9 | --- bash-4.3.orig/arrayfunc.c 2013-08-02 20:19:59.000000000 +0000
|
---|
| 10 | +++ bash-4.3/arrayfunc.c 2014-09-26 23:58:55.592973170 +0000
|
---|
| 11 | @@ -179,6 +179,7 @@
|
---|
| 12 | array_insert (array_cell (entry), ind, newval);
|
---|
| 13 | FREE (newval);
|
---|
| 14 |
|
---|
| 15 | + VUNSETATTR (entry, att_invisible); /* no longer invisible */
|
---|
| 16 | return (entry);
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | @@ -597,6 +598,11 @@
|
---|
| 20 | if (assoc_p (var))
|
---|
| 21 | {
|
---|
| 22 | val = expand_assignment_string_to_string (val, 0);
|
---|
| 23 | + if (val == 0)
|
---|
| 24 | + {
|
---|
| 25 | + val = (char *)xmalloc (1);
|
---|
| 26 | + val[0] = '\0'; /* like do_assignment_internal */
|
---|
| 27 | + }
|
---|
| 28 | free_val = 1;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | diff -Naur bash-4.3.orig/bashline.c bash-4.3/bashline.c
|
---|
| 32 | --- bash-4.3.orig/bashline.c 2014-02-10 00:56:58.000000000 +0000
|
---|
| 33 | +++ bash-4.3/bashline.c 2014-09-26 23:58:55.579639869 +0000
|
---|
| 34 | @@ -4167,9 +4167,16 @@
|
---|
| 35 | int qc;
|
---|
| 36 |
|
---|
| 37 | qc = rl_dispatching ? rl_completion_quote_character : 0;
|
---|
| 38 | - dfn = bash_dequote_filename ((char *)text, qc);
|
---|
| 39 | + /* If rl_completion_found_quote != 0, rl_completion_matches will call the
|
---|
| 40 | + filename dequoting function, causing the directory name to be dequoted
|
---|
| 41 | + twice. */
|
---|
| 42 | + if (rl_dispatching && rl_completion_found_quote == 0)
|
---|
| 43 | + dfn = bash_dequote_filename ((char *)text, qc);
|
---|
| 44 | + else
|
---|
| 45 | + dfn = (char *)text;
|
---|
| 46 | m1 = rl_completion_matches (dfn, rl_filename_completion_function);
|
---|
| 47 | - free (dfn);
|
---|
| 48 | + if (dfn != text)
|
---|
| 49 | + free (dfn);
|
---|
| 50 |
|
---|
| 51 | if (m1 == 0 || m1[0] == 0)
|
---|
| 52 | return m1;
|
---|
| 53 | diff -Naur bash-4.3.orig/builtins/common.h bash-4.3/builtins/common.h
|
---|
| 54 | --- bash-4.3.orig/builtins/common.h 2013-07-08 20:54:47.000000000 +0000
|
---|
| 55 | +++ bash-4.3/builtins/common.h 2014-09-26 23:58:55.622973097 +0000
|
---|
| 56 | @@ -33,6 +33,8 @@
|
---|
| 57 | #define SEVAL_RESETLINE 0x010
|
---|
| 58 | #define SEVAL_PARSEONLY 0x020
|
---|
| 59 | #define SEVAL_NOLONGJMP 0x040
|
---|
| 60 | +#define SEVAL_FUNCDEF 0x080 /* only allow function definitions */
|
---|
| 61 | +#define SEVAL_ONECMD 0x100 /* only allow a single command */
|
---|
| 62 |
|
---|
| 63 | /* Flags for describe_command, shared between type.def and command.def */
|
---|
| 64 | #define CDESC_ALL 0x001 /* type -a */
|
---|
| 65 | diff -Naur bash-4.3.orig/builtins/evalstring.c bash-4.3/builtins/evalstring.c
|
---|
| 66 | --- bash-4.3.orig/builtins/evalstring.c 2014-02-11 14:42:10.000000000 +0000
|
---|
| 67 | +++ bash-4.3/builtins/evalstring.c 2014-09-26 23:58:55.626306422 +0000
|
---|
| 68 | @@ -308,6 +308,14 @@
|
---|
| 69 | {
|
---|
| 70 | struct fd_bitmap *bitmap;
|
---|
| 71 |
|
---|
| 72 | + if ((flags & SEVAL_FUNCDEF) && command->type != cm_function_def)
|
---|
| 73 | + {
|
---|
| 74 | + internal_warning ("%s: ignoring function definition attempt", from_file);
|
---|
| 75 | + should_jump_to_top_level = 0;
|
---|
| 76 | + last_result = last_command_exit_value = EX_BADUSAGE;
|
---|
| 77 | + break;
|
---|
| 78 | + }
|
---|
| 79 | +
|
---|
| 80 | bitmap = new_fd_bitmap (FD_BITMAP_SIZE);
|
---|
| 81 | begin_unwind_frame ("pe_dispose");
|
---|
| 82 | add_unwind_protect (dispose_fd_bitmap, bitmap);
|
---|
| 83 | @@ -368,6 +376,9 @@
|
---|
| 84 | dispose_command (command);
|
---|
| 85 | dispose_fd_bitmap (bitmap);
|
---|
| 86 | discard_unwind_frame ("pe_dispose");
|
---|
| 87 | +
|
---|
| 88 | + if (flags & SEVAL_ONECMD)
|
---|
| 89 | + break;
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 | else
|
---|
| 93 | diff -Naur bash-4.3.orig/builtins/read.def bash-4.3/builtins/read.def
|
---|
| 94 | --- bash-4.3.orig/builtins/read.def 2013-09-02 15:54:00.000000000 +0000
|
---|
| 95 | +++ bash-4.3/builtins/read.def 2014-09-26 23:58:55.596306495 +0000
|
---|
| 96 | @@ -442,7 +442,10 @@
|
---|
| 97 | add_unwind_protect (reset_alarm, (char *)NULL);
|
---|
| 98 | #if defined (READLINE)
|
---|
| 99 | if (edit)
|
---|
| 100 | - add_unwind_protect (reset_attempted_completion_function, (char *)NULL);
|
---|
| 101 | + {
|
---|
| 102 | + add_unwind_protect (reset_attempted_completion_function, (char *)NULL);
|
---|
| 103 | + add_unwind_protect (bashline_reset_event_hook, (char *)NULL);
|
---|
| 104 | + }
|
---|
| 105 | #endif
|
---|
| 106 | falarm (tmsec, tmusec);
|
---|
| 107 | }
|
---|
| 108 | @@ -1021,6 +1024,7 @@
|
---|
| 109 |
|
---|
| 110 | old_attempted_completion_function = rl_attempted_completion_function;
|
---|
| 111 | rl_attempted_completion_function = (rl_completion_func_t *)NULL;
|
---|
| 112 | + bashline_set_event_hook ();
|
---|
| 113 | if (itext)
|
---|
| 114 | {
|
---|
| 115 | old_startup_hook = rl_startup_hook;
|
---|
| 116 | @@ -1032,6 +1036,7 @@
|
---|
| 117 |
|
---|
| 118 | rl_attempted_completion_function = old_attempted_completion_function;
|
---|
| 119 | old_attempted_completion_function = (rl_completion_func_t *)NULL;
|
---|
| 120 | + bashline_reset_event_hook ();
|
---|
| 121 |
|
---|
| 122 | if (ret == 0)
|
---|
| 123 | return ret;
|
---|
| 124 | diff -Naur bash-4.3.orig/execute_cmd.c bash-4.3/execute_cmd.c
|
---|
| 125 | --- bash-4.3.orig/execute_cmd.c 2014-01-31 15:54:52.000000000 +0000
|
---|
| 126 | +++ bash-4.3/execute_cmd.c 2014-09-26 23:58:55.609639796 +0000
|
---|
| 127 | @@ -2409,7 +2409,16 @@
|
---|
| 128 | #endif
|
---|
| 129 | lstdin = wait_for (lastpid);
|
---|
| 130 | #if defined (JOB_CONTROL)
|
---|
| 131 | - exec_result = job_exit_status (lastpipe_jid);
|
---|
| 132 | + /* If wait_for removes the job from the jobs table, use result of last
|
---|
| 133 | + command as pipeline's exit status as usual. The jobs list can get
|
---|
| 134 | + frozen and unfrozen at inconvenient times if there are multiple pipelines
|
---|
| 135 | + running simultaneously. */
|
---|
| 136 | + if (INVALID_JOB (lastpipe_jid) == 0)
|
---|
| 137 | + exec_result = job_exit_status (lastpipe_jid);
|
---|
| 138 | + else if (pipefail_opt)
|
---|
| 139 | + exec_result = exec_result | lstdin; /* XXX */
|
---|
| 140 | + /* otherwise we use exec_result */
|
---|
| 141 | +
|
---|
| 142 | #endif
|
---|
| 143 | unfreeze_jobs_list ();
|
---|
| 144 | }
|
---|
| 145 | diff -Naur bash-4.3.orig/externs.h bash-4.3/externs.h
|
---|
| 146 | --- bash-4.3.orig/externs.h 2014-01-02 19:58:20.000000000 +0000
|
---|
| 147 | +++ bash-4.3/externs.h 2014-09-26 23:58:55.556306592 +0000
|
---|
| 148 | @@ -324,6 +324,7 @@
|
---|
| 149 | extern char *sh_backslash_quote __P((char *, const char *, int));
|
---|
| 150 | extern char *sh_backslash_quote_for_double_quotes __P((char *));
|
---|
| 151 | extern int sh_contains_shell_metas __P((char *));
|
---|
| 152 | +extern int sh_contains_quotes __P((char *));
|
---|
| 153 |
|
---|
| 154 | /* declarations for functions defined in lib/sh/spell.c */
|
---|
| 155 | extern int spname __P((char *, char *));
|
---|
| 156 | diff -Naur bash-4.3.orig/jobs.c bash-4.3/jobs.c
|
---|
| 157 | --- bash-4.3.orig/jobs.c 2014-01-10 14:05:34.000000000 +0000
|
---|
| 158 | +++ bash-4.3/jobs.c 2014-09-26 23:58:55.566306568 +0000
|
---|
| 159 | @@ -3597,6 +3597,7 @@
|
---|
| 160 | unwind_protect_int (jobs_list_frozen);
|
---|
| 161 | unwind_protect_pointer (the_pipeline);
|
---|
| 162 | unwind_protect_pointer (subst_assign_varlist);
|
---|
| 163 | + unwind_protect_pointer (this_shell_builtin);
|
---|
| 164 |
|
---|
| 165 | /* We have to add the commands this way because they will be run
|
---|
| 166 | in reverse order of adding. We don't want maybe_set_sigchld_trap ()
|
---|
| 167 | @@ -4374,7 +4375,7 @@
|
---|
| 168 | void
|
---|
| 169 | end_job_control ()
|
---|
| 170 | {
|
---|
| 171 | - if (interactive_shell) /* XXX - should it be interactive? */
|
---|
| 172 | + if (interactive_shell || job_control) /* XXX - should it be just job_control? */
|
---|
| 173 | {
|
---|
| 174 | terminate_stopped_jobs ();
|
---|
| 175 |
|
---|
| 176 | diff -Naur bash-4.3.orig/lib/glob/glob.c bash-4.3/lib/glob/glob.c
|
---|
| 177 | --- bash-4.3.orig/lib/glob/glob.c 2014-02-01 02:43:51.000000000 +0000
|
---|
| 178 | +++ bash-4.3/lib/glob/glob.c 2014-09-26 23:58:55.582973194 +0000
|
---|
| 179 | @@ -123,6 +123,8 @@
|
---|
| 180 | extern char *glob_patscan __P((char *, char *, int));
|
---|
| 181 | extern wchar_t *glob_patscan_wc __P((wchar_t *, wchar_t *, int));
|
---|
| 182 |
|
---|
| 183 | +extern char *glob_dirscan __P((char *, int));
|
---|
| 184 | +
|
---|
| 185 | /* Compile `glob_loop.c' for single-byte characters. */
|
---|
| 186 | #define CHAR unsigned char
|
---|
| 187 | #define INT int
|
---|
| 188 | @@ -179,42 +181,53 @@
|
---|
| 189 | char *pat, *dname;
|
---|
| 190 | int flags;
|
---|
| 191 | {
|
---|
| 192 | - char *pp, *pe, *t;
|
---|
| 193 | - int n, r;
|
---|
| 194 | + char *pp, *pe, *t, *se;
|
---|
| 195 | + int n, r, negate;
|
---|
| 196 |
|
---|
| 197 | + negate = *pat == '!';
|
---|
| 198 | pp = pat + 2;
|
---|
| 199 | - pe = pp + strlen (pp) - 1; /*(*/
|
---|
| 200 | - if (*pe != ')')
|
---|
| 201 | + se = pp + strlen (pp) - 1; /* end of string */
|
---|
| 202 | + pe = glob_patscan (pp, se, 0); /* end of extglob pattern (( */
|
---|
| 203 | + /* we should check for invalid extglob pattern here */
|
---|
| 204 | + if (pe == 0)
|
---|
| 205 | return 0;
|
---|
| 206 | - if ((t = strchr (pp, '|')) == 0) /* easy case first */
|
---|
| 207 | +
|
---|
| 208 | + /* if pe != se we have more of the pattern at the end of the extglob
|
---|
| 209 | + pattern. Check the easy case first ( */
|
---|
| 210 | + if (pe == se && *pe == ')' && (t = strchr (pp, '|')) == 0)
|
---|
| 211 | {
|
---|
| 212 | *pe = '\0';
|
---|
| 213 | +#if defined (HANDLE_MULTIBYTE)
|
---|
| 214 | + r = mbskipname (pp, dname, flags);
|
---|
| 215 | +#else
|
---|
| 216 | r = skipname (pp, dname, flags); /*(*/
|
---|
| 217 | +#endif
|
---|
| 218 | *pe = ')';
|
---|
| 219 | return r;
|
---|
| 220 | }
|
---|
| 221 | +
|
---|
| 222 | + /* check every subpattern */
|
---|
| 223 | while (t = glob_patscan (pp, pe, '|'))
|
---|
| 224 | {
|
---|
| 225 | n = t[-1];
|
---|
| 226 | t[-1] = '\0';
|
---|
| 227 | +#if defined (HANDLE_MULTIBYTE)
|
---|
| 228 | + r = mbskipname (pp, dname, flags);
|
---|
| 229 | +#else
|
---|
| 230 | r = skipname (pp, dname, flags);
|
---|
| 231 | +#endif
|
---|
| 232 | t[-1] = n;
|
---|
| 233 | if (r == 0) /* if any pattern says not skip, we don't skip */
|
---|
| 234 | return r;
|
---|
| 235 | pp = t;
|
---|
| 236 | } /*(*/
|
---|
| 237 |
|
---|
| 238 | - if (pp == pe) /* glob_patscan might find end of pattern */
|
---|
| 239 | + /* glob_patscan might find end of pattern */
|
---|
| 240 | + if (pp == se)
|
---|
| 241 | return r;
|
---|
| 242 |
|
---|
| 243 | - *pe = '\0';
|
---|
| 244 | -# if defined (HANDLE_MULTIBYTE)
|
---|
| 245 | - r = mbskipname (pp, dname, flags); /*(*/
|
---|
| 246 | -# else
|
---|
| 247 | - r = skipname (pp, dname, flags); /*(*/
|
---|
| 248 | -# endif
|
---|
| 249 | - *pe = ')';
|
---|
| 250 | - return r;
|
---|
| 251 | + /* but if it doesn't then we didn't match a leading dot */
|
---|
| 252 | + return 0;
|
---|
| 253 | }
|
---|
| 254 | #endif
|
---|
| 255 |
|
---|
| 256 | @@ -277,20 +290,23 @@
|
---|
| 257 | int flags;
|
---|
| 258 | {
|
---|
| 259 | #if EXTENDED_GLOB
|
---|
| 260 | - wchar_t *pp, *pe, *t, n;
|
---|
| 261 | - int r;
|
---|
| 262 | + wchar_t *pp, *pe, *t, n, *se;
|
---|
| 263 | + int r, negate;
|
---|
| 264 |
|
---|
| 265 | + negate = *pat == L'!';
|
---|
| 266 | pp = pat + 2;
|
---|
| 267 | - pe = pp + wcslen (pp) - 1; /*(*/
|
---|
| 268 | - if (*pe != L')')
|
---|
| 269 | - return 0;
|
---|
| 270 | - if ((t = wcschr (pp, L'|')) == 0)
|
---|
| 271 | + se = pp + wcslen (pp) - 1; /*(*/
|
---|
| 272 | + pe = glob_patscan_wc (pp, se, 0);
|
---|
| 273 | +
|
---|
| 274 | + if (pe == se && *pe == ')' && (t = wcschr (pp, L'|')) == 0)
|
---|
| 275 | {
|
---|
| 276 | *pe = L'\0';
|
---|
| 277 | r = wchkname (pp, dname); /*(*/
|
---|
| 278 | *pe = L')';
|
---|
| 279 | return r;
|
---|
| 280 | }
|
---|
| 281 | +
|
---|
| 282 | + /* check every subpattern */
|
---|
| 283 | while (t = glob_patscan_wc (pp, pe, '|'))
|
---|
| 284 | {
|
---|
| 285 | n = t[-1];
|
---|
| 286 | @@ -305,10 +321,8 @@
|
---|
| 287 | if (pp == pe) /* glob_patscan_wc might find end of pattern */
|
---|
| 288 | return r;
|
---|
| 289 |
|
---|
| 290 | - *pe = L'\0';
|
---|
| 291 | - r = wchkname (pp, dname); /*(*/
|
---|
| 292 | - *pe = L')';
|
---|
| 293 | - return r;
|
---|
| 294 | + /* but if it doesn't then we didn't match a leading dot */
|
---|
| 295 | + return 0;
|
---|
| 296 | #else
|
---|
| 297 | return (wchkname (pat, dname));
|
---|
| 298 | #endif
|
---|
| 299 | @@ -1006,7 +1020,7 @@
|
---|
| 300 | {
|
---|
| 301 | char **result;
|
---|
| 302 | unsigned int result_size;
|
---|
| 303 | - char *directory_name, *filename, *dname;
|
---|
| 304 | + char *directory_name, *filename, *dname, *fn;
|
---|
| 305 | unsigned int directory_len;
|
---|
| 306 | int free_dirname; /* flag */
|
---|
| 307 | int dflags;
|
---|
| 308 | @@ -1022,6 +1036,18 @@
|
---|
| 309 |
|
---|
| 310 | /* Find the filename. */
|
---|
| 311 | filename = strrchr (pathname, '/');
|
---|
| 312 | +#if defined (EXTENDED_GLOB)
|
---|
| 313 | + if (filename && extended_glob)
|
---|
| 314 | + {
|
---|
| 315 | + fn = glob_dirscan (pathname, '/');
|
---|
| 316 | +#if DEBUG_MATCHING
|
---|
| 317 | + if (fn != filename)
|
---|
| 318 | + fprintf (stderr, "glob_filename: glob_dirscan: fn (%s) != filename (%s)\n", fn ? fn : "(null)", filename);
|
---|
| 319 | +#endif
|
---|
| 320 | + filename = fn;
|
---|
| 321 | + }
|
---|
| 322 | +#endif
|
---|
| 323 | +
|
---|
| 324 | if (filename == NULL)
|
---|
| 325 | {
|
---|
| 326 | filename = pathname;
|
---|
| 327 | diff -Naur bash-4.3.orig/lib/glob/gmisc.c bash-4.3/lib/glob/gmisc.c
|
---|
| 328 | --- bash-4.3.orig/lib/glob/gmisc.c 2013-10-28 18:45:25.000000000 +0000
|
---|
| 329 | +++ bash-4.3/lib/glob/gmisc.c 2014-09-26 23:58:55.582973194 +0000
|
---|
| 330 | @@ -42,6 +42,8 @@
|
---|
| 331 | #define WLPAREN L'('
|
---|
| 332 | #define WRPAREN L')'
|
---|
| 333 |
|
---|
| 334 | +extern char *glob_patscan __P((char *, char *, int));
|
---|
| 335 | +
|
---|
| 336 | /* Return 1 of the first character of WSTRING could match the first
|
---|
| 337 | character of pattern WPAT. Wide character version. */
|
---|
| 338 | int
|
---|
| 339 | @@ -210,6 +212,7 @@
|
---|
| 340 | case '+':
|
---|
| 341 | case '!':
|
---|
| 342 | case '@':
|
---|
| 343 | + case '?':
|
---|
| 344 | return (pat[1] == LPAREN);
|
---|
| 345 | default:
|
---|
| 346 | return 0;
|
---|
| 347 | @@ -374,3 +377,34 @@
|
---|
| 348 |
|
---|
| 349 | return matlen;
|
---|
| 350 | }
|
---|
| 351 | +
|
---|
| 352 | +/* Skip characters in PAT and return the final occurrence of DIRSEP. This
|
---|
| 353 | + is only called when extended_glob is set, so we have to skip over extglob
|
---|
| 354 | + patterns x(...) */
|
---|
| 355 | +char *
|
---|
| 356 | +glob_dirscan (pat, dirsep)
|
---|
| 357 | + char *pat;
|
---|
| 358 | + int dirsep;
|
---|
| 359 | +{
|
---|
| 360 | + char *p, *d, *pe, *se;
|
---|
| 361 | +
|
---|
| 362 | + d = pe = se = 0;
|
---|
| 363 | + for (p = pat; p && *p; p++)
|
---|
| 364 | + {
|
---|
| 365 | + if (extglob_pattern_p (p))
|
---|
| 366 | + {
|
---|
| 367 | + if (se == 0)
|
---|
| 368 | + se = p + strlen (p) - 1;
|
---|
| 369 | + pe = glob_patscan (p + 2, se, 0);
|
---|
| 370 | + if (pe == 0)
|
---|
| 371 | + continue;
|
---|
| 372 | + else if (*pe == 0)
|
---|
| 373 | + break;
|
---|
| 374 | + p = pe - 1; /* will do increment above */
|
---|
| 375 | + continue;
|
---|
| 376 | + }
|
---|
| 377 | + if (*p == dirsep)
|
---|
| 378 | + d = p;
|
---|
| 379 | + }
|
---|
| 380 | + return d;
|
---|
| 381 | +}
|
---|
| 382 | diff -Naur bash-4.3.orig/lib/readline/display.c bash-4.3/lib/readline/display.c
|
---|
| 383 | --- bash-4.3.orig/lib/readline/display.c 2013-12-27 18:10:56.000000000 +0000
|
---|
| 384 | +++ bash-4.3/lib/readline/display.c 2014-09-26 23:58:55.569639893 +0000
|
---|
| 385 | @@ -1637,7 +1637,7 @@
|
---|
| 386 | /* If we are changing the number of invisible characters in a line, and
|
---|
| 387 | the spot of first difference is before the end of the invisible chars,
|
---|
| 388 | lendiff needs to be adjusted. */
|
---|
| 389 | - if (current_line == 0 && !_rl_horizontal_scroll_mode &&
|
---|
| 390 | + if (current_line == 0 && /* !_rl_horizontal_scroll_mode && */
|
---|
| 391 | current_invis_chars != visible_wrap_offset)
|
---|
| 392 | {
|
---|
| 393 | if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
|
---|
| 394 | @@ -1825,8 +1825,13 @@
|
---|
| 395 | else
|
---|
| 396 | _rl_last_c_pos += bytes_to_insert;
|
---|
| 397 |
|
---|
| 398 | + /* XXX - we only want to do this if we are at the end of the line
|
---|
| 399 | + so we move there with _rl_move_cursor_relative */
|
---|
| 400 | if (_rl_horizontal_scroll_mode && ((oe-old) > (ne-new)))
|
---|
| 401 | - goto clear_rest_of_line;
|
---|
| 402 | + {
|
---|
| 403 | + _rl_move_cursor_relative (ne-new, new);
|
---|
| 404 | + goto clear_rest_of_line;
|
---|
| 405 | + }
|
---|
| 406 | }
|
---|
| 407 | }
|
---|
| 408 | /* Otherwise, print over the existing material. */
|
---|
| 409 | @@ -2677,7 +2682,8 @@
|
---|
| 410 | {
|
---|
| 411 | if (_rl_echoing_p)
|
---|
| 412 | {
|
---|
| 413 | - _rl_move_vert (_rl_vis_botlin);
|
---|
| 414 | + if (_rl_vis_botlin > 0) /* minor optimization plus bug fix */
|
---|
| 415 | + _rl_move_vert (_rl_vis_botlin);
|
---|
| 416 | _rl_vis_botlin = 0;
|
---|
| 417 | fflush (rl_outstream);
|
---|
| 418 | rl_restart_output (1, 0);
|
---|
| 419 | diff -Naur bash-4.3.orig/lib/readline/input.c bash-4.3/lib/readline/input.c
|
---|
| 420 | --- bash-4.3.orig/lib/readline/input.c 2014-01-10 20:07:08.000000000 +0000
|
---|
| 421 | +++ bash-4.3/lib/readline/input.c 2014-09-26 23:58:55.592973170 +0000
|
---|
| 422 | @@ -534,8 +534,16 @@
|
---|
| 423 | return (RL_ISSTATE (RL_STATE_READCMD) ? READERR : EOF);
|
---|
| 424 | else if (_rl_caught_signal == SIGHUP || _rl_caught_signal == SIGTERM)
|
---|
| 425 | return (RL_ISSTATE (RL_STATE_READCMD) ? READERR : EOF);
|
---|
| 426 | + /* keyboard-generated signals of interest */
|
---|
| 427 | else if (_rl_caught_signal == SIGINT || _rl_caught_signal == SIGQUIT)
|
---|
| 428 | RL_CHECK_SIGNALS ();
|
---|
| 429 | + /* non-keyboard-generated signals of interest */
|
---|
| 430 | + else if (_rl_caught_signal == SIGALRM
|
---|
| 431 | +#if defined (SIGVTALRM)
|
---|
| 432 | + || _rl_caught_signal == SIGVTALRM
|
---|
| 433 | +#endif
|
---|
| 434 | + )
|
---|
| 435 | + RL_CHECK_SIGNALS ();
|
---|
| 436 |
|
---|
| 437 | if (rl_signal_event_hook)
|
---|
| 438 | (*rl_signal_event_hook) ();
|
---|
| 439 | diff -Naur bash-4.3.orig/lib/readline/misc.c bash-4.3/lib/readline/misc.c
|
---|
| 440 | --- bash-4.3.orig/lib/readline/misc.c 2012-09-01 22:03:11.000000000 +0000
|
---|
| 441 | +++ bash-4.3/lib/readline/misc.c 2014-09-26 23:58:55.606306471 +0000
|
---|
| 442 | @@ -461,6 +461,7 @@
|
---|
| 443 | saved_undo_list = 0;
|
---|
| 444 | /* Set up rl_line_buffer and other variables from history entry */
|
---|
| 445 | rl_replace_from_history (entry, 0); /* entry->line is now current */
|
---|
| 446 | + entry->data = 0; /* entry->data is now current undo list */
|
---|
| 447 | /* Undo all changes to this history entry */
|
---|
| 448 | while (rl_undo_list)
|
---|
| 449 | rl_do_undo ();
|
---|
| 450 | @@ -468,7 +469,6 @@
|
---|
| 451 | the timestamp. */
|
---|
| 452 | FREE (entry->line);
|
---|
| 453 | entry->line = savestring (rl_line_buffer);
|
---|
| 454 | - entry->data = 0;
|
---|
| 455 | }
|
---|
| 456 | entry = previous_history ();
|
---|
| 457 | }
|
---|
| 458 | diff -Naur bash-4.3.orig/lib/readline/readline.c bash-4.3/lib/readline/readline.c
|
---|
| 459 | --- bash-4.3.orig/lib/readline/readline.c 2013-10-28 18:58:06.000000000 +0000
|
---|
| 460 | +++ bash-4.3/lib/readline/readline.c 2014-09-26 23:58:55.516306690 +0000
|
---|
| 461 | @@ -744,7 +744,8 @@
|
---|
| 462 | r = _rl_subseq_result (r, cxt->oldmap, cxt->okey, (cxt->flags & KSEQ_SUBSEQ));
|
---|
| 463 |
|
---|
| 464 | RL_CHECK_SIGNALS ();
|
---|
| 465 | - if (r == 0) /* success! */
|
---|
| 466 | + /* We only treat values < 0 specially to simulate recursion. */
|
---|
| 467 | + if (r >= 0 || (r == -1 && (cxt->flags & KSEQ_SUBSEQ) == 0)) /* success! or failure! */
|
---|
| 468 | {
|
---|
| 469 | _rl_keyseq_chain_dispose ();
|
---|
| 470 | RL_UNSETSTATE (RL_STATE_MULTIKEY);
|
---|
| 471 | @@ -964,7 +965,7 @@
|
---|
| 472 | #if defined (VI_MODE)
|
---|
| 473 | if (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap &&
|
---|
| 474 | key != ANYOTHERKEY &&
|
---|
| 475 | - rl_key_sequence_length == 1 && /* XXX */
|
---|
| 476 | + _rl_dispatching_keymap == vi_movement_keymap &&
|
---|
| 477 | _rl_vi_textmod_command (key))
|
---|
| 478 | _rl_vi_set_last (key, rl_numeric_arg, rl_arg_sign);
|
---|
| 479 | #endif
|
---|
| 480 | diff -Naur bash-4.3.orig/lib/readline/readline.c.orig bash-4.3/lib/readline/readline.c.orig
|
---|
| 481 | --- bash-4.3.orig/lib/readline/readline.c.orig 1970-01-01 00:00:00.000000000 +0000
|
---|
| 482 | +++ bash-4.3/lib/readline/readline.c.orig 2014-09-26 23:58:55.512973365 +0000
|
---|
| 483 | @@ -0,0 +1,1364 @@
|
---|
| 484 | +/* readline.c -- a general facility for reading lines of input
|
---|
| 485 | + with emacs style editing and completion. */
|
---|
| 486 | +
|
---|
| 487 | +/* Copyright (C) 1987-2013 Free Software Foundation, Inc.
|
---|
| 488 | +
|
---|
| 489 | + This file is part of the GNU Readline Library (Readline), a library
|
---|
| 490 | + for reading lines of text with interactive input and history editing.
|
---|
| 491 | +
|
---|
| 492 | + Readline is free software: you can redistribute it and/or modify
|
---|
| 493 | + it under the terms of the GNU General Public License as published by
|
---|
| 494 | + the Free Software Foundation, either version 3 of the License, or
|
---|
| 495 | + (at your option) any later version.
|
---|
| 496 | +
|
---|
| 497 | + Readline is distributed in the hope that it will be useful,
|
---|
| 498 | + but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 499 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 500 | + GNU General Public License for more details.
|
---|
| 501 | +
|
---|
| 502 | + You should have received a copy of the GNU General Public License
|
---|
| 503 | + along with Readline. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 504 | +*/
|
---|
| 505 | +
|
---|
| 506 | +#define READLINE_LIBRARY
|
---|
| 507 | +
|
---|
| 508 | +#if defined (HAVE_CONFIG_H)
|
---|
| 509 | +# include <config.h>
|
---|
| 510 | +#endif
|
---|
| 511 | +
|
---|
| 512 | +#include <sys/types.h>
|
---|
| 513 | +#include "posixstat.h"
|
---|
| 514 | +#include <fcntl.h>
|
---|
| 515 | +#if defined (HAVE_SYS_FILE_H)
|
---|
| 516 | +# include <sys/file.h>
|
---|
| 517 | +#endif /* HAVE_SYS_FILE_H */
|
---|
| 518 | +
|
---|
| 519 | +#if defined (HAVE_UNISTD_H)
|
---|
| 520 | +# include <unistd.h>
|
---|
| 521 | +#endif /* HAVE_UNISTD_H */
|
---|
| 522 | +
|
---|
| 523 | +#if defined (HAVE_STDLIB_H)
|
---|
| 524 | +# include <stdlib.h>
|
---|
| 525 | +#else
|
---|
| 526 | +# include "ansi_stdlib.h"
|
---|
| 527 | +#endif /* HAVE_STDLIB_H */
|
---|
| 528 | +
|
---|
| 529 | +#if defined (HAVE_LOCALE_H)
|
---|
| 530 | +# include <locale.h>
|
---|
| 531 | +#endif
|
---|
| 532 | +
|
---|
| 533 | +#include <stdio.h>
|
---|
| 534 | +#include "posixjmp.h"
|
---|
| 535 | +#include <errno.h>
|
---|
| 536 | +
|
---|
| 537 | +#if !defined (errno)
|
---|
| 538 | +extern int errno;
|
---|
| 539 | +#endif /* !errno */
|
---|
| 540 | +
|
---|
| 541 | +/* System-specific feature definitions and include files. */
|
---|
| 542 | +#include "rldefs.h"
|
---|
| 543 | +#include "rlmbutil.h"
|
---|
| 544 | +
|
---|
| 545 | +#if defined (__EMX__)
|
---|
| 546 | +# define INCL_DOSPROCESS
|
---|
| 547 | +# include <os2.h>
|
---|
| 548 | +#endif /* __EMX__ */
|
---|
| 549 | +
|
---|
| 550 | +/* Some standard library routines. */
|
---|
| 551 | +#include "readline.h"
|
---|
| 552 | +#include "history.h"
|
---|
| 553 | +
|
---|
| 554 | +#include "rlprivate.h"
|
---|
| 555 | +#include "rlshell.h"
|
---|
| 556 | +#include "xmalloc.h"
|
---|
| 557 | +
|
---|
| 558 | +#ifndef RL_LIBRARY_VERSION
|
---|
| 559 | +# define RL_LIBRARY_VERSION "5.1"
|
---|
| 560 | +#endif
|
---|
| 561 | +
|
---|
| 562 | +#ifndef RL_READLINE_VERSION
|
---|
| 563 | +# define RL_READLINE_VERSION 0x0501
|
---|
| 564 | +#endif
|
---|
| 565 | +
|
---|
| 566 | +extern void _rl_free_history_entry PARAMS((HIST_ENTRY *));
|
---|
| 567 | +
|
---|
| 568 | +#if defined (COLOR_SUPPORT)
|
---|
| 569 | +extern void _rl_parse_colors PARAMS((void)); /* XXX */
|
---|
| 570 | +#endif
|
---|
| 571 | +
|
---|
| 572 | +
|
---|
| 573 | +/* Forward declarations used in this file. */
|
---|
| 574 | +static char *readline_internal PARAMS((void));
|
---|
| 575 | +static void readline_initialize_everything PARAMS((void));
|
---|
| 576 | +
|
---|
| 577 | +static void bind_arrow_keys_internal PARAMS((Keymap));
|
---|
| 578 | +static void bind_arrow_keys PARAMS((void));
|
---|
| 579 | +
|
---|
| 580 | +static void readline_default_bindings PARAMS((void));
|
---|
| 581 | +static void reset_default_bindings PARAMS((void));
|
---|
| 582 | +
|
---|
| 583 | +static int _rl_subseq_result PARAMS((int, Keymap, int, int));
|
---|
| 584 | +static int _rl_subseq_getchar PARAMS((int));
|
---|
| 585 | +
|
---|
| 586 | +/* **************************************************************** */
|
---|
| 587 | +/* */
|
---|
| 588 | +/* Line editing input utility */
|
---|
| 589 | +/* */
|
---|
| 590 | +/* **************************************************************** */
|
---|
| 591 | +
|
---|
| 592 | +const char *rl_library_version = RL_LIBRARY_VERSION;
|
---|
| 593 | +
|
---|
| 594 | +int rl_readline_version = RL_READLINE_VERSION;
|
---|
| 595 | +
|
---|
| 596 | +/* True if this is `real' readline as opposed to some stub substitute. */
|
---|
| 597 | +int rl_gnu_readline_p = 1;
|
---|
| 598 | +
|
---|
| 599 | +/* A pointer to the keymap that is currently in use.
|
---|
| 600 | + By default, it is the standard emacs keymap. */
|
---|
| 601 | +Keymap _rl_keymap = emacs_standard_keymap;
|
---|
| 602 | +
|
---|
| 603 | +/* The current style of editing. */
|
---|
| 604 | +int rl_editing_mode = emacs_mode;
|
---|
| 605 | +
|
---|
| 606 | +/* The current insert mode: input (the default) or overwrite */
|
---|
| 607 | +int rl_insert_mode = RL_IM_DEFAULT;
|
---|
| 608 | +
|
---|
| 609 | +/* Non-zero if we called this function from _rl_dispatch(). It's present
|
---|
| 610 | + so functions can find out whether they were called from a key binding
|
---|
| 611 | + or directly from an application. */
|
---|
| 612 | +int rl_dispatching;
|
---|
| 613 | +
|
---|
| 614 | +/* Non-zero if the previous command was a kill command. */
|
---|
| 615 | +int _rl_last_command_was_kill = 0;
|
---|
| 616 | +
|
---|
| 617 | +/* The current value of the numeric argument specified by the user. */
|
---|
| 618 | +int rl_numeric_arg = 1;
|
---|
| 619 | +
|
---|
| 620 | +/* Non-zero if an argument was typed. */
|
---|
| 621 | +int rl_explicit_arg = 0;
|
---|
| 622 | +
|
---|
| 623 | +/* Temporary value used while generating the argument. */
|
---|
| 624 | +int rl_arg_sign = 1;
|
---|
| 625 | +
|
---|
| 626 | +/* Non-zero means we have been called at least once before. */
|
---|
| 627 | +static int rl_initialized;
|
---|
| 628 | +
|
---|
| 629 | +#if 0
|
---|
| 630 | +/* If non-zero, this program is running in an EMACS buffer. */
|
---|
| 631 | +static int running_in_emacs;
|
---|
| 632 | +#endif
|
---|
| 633 | +
|
---|
| 634 | +/* Flags word encapsulating the current readline state. */
|
---|
| 635 | +int rl_readline_state = RL_STATE_NONE;
|
---|
| 636 | +
|
---|
| 637 | +/* The current offset in the current input line. */
|
---|
| 638 | +int rl_point;
|
---|
| 639 | +
|
---|
| 640 | +/* Mark in the current input line. */
|
---|
| 641 | +int rl_mark;
|
---|
| 642 | +
|
---|
| 643 | +/* Length of the current input line. */
|
---|
| 644 | +int rl_end;
|
---|
| 645 | +
|
---|
| 646 | +/* Make this non-zero to return the current input_line. */
|
---|
| 647 | +int rl_done;
|
---|
| 648 | +
|
---|
| 649 | +/* The last function executed by readline. */
|
---|
| 650 | +rl_command_func_t *rl_last_func = (rl_command_func_t *)NULL;
|
---|
| 651 | +
|
---|
| 652 | +/* Top level environment for readline_internal (). */
|
---|
| 653 | +procenv_t _rl_top_level;
|
---|
| 654 | +
|
---|
| 655 | +/* The streams we interact with. */
|
---|
| 656 | +FILE *_rl_in_stream, *_rl_out_stream;
|
---|
| 657 | +
|
---|
| 658 | +/* The names of the streams that we do input and output to. */
|
---|
| 659 | +FILE *rl_instream = (FILE *)NULL;
|
---|
| 660 | +FILE *rl_outstream = (FILE *)NULL;
|
---|
| 661 | +
|
---|
| 662 | +/* Non-zero means echo characters as they are read. Defaults to no echo;
|
---|
| 663 | + set to 1 if there is a controlling terminal, we can get its attributes,
|
---|
| 664 | + and the attributes include `echo'. Look at rltty.c:prepare_terminal_settings
|
---|
| 665 | + for the code that sets it. */
|
---|
| 666 | +int _rl_echoing_p = 0;
|
---|
| 667 | +
|
---|
| 668 | +/* Current prompt. */
|
---|
| 669 | +char *rl_prompt = (char *)NULL;
|
---|
| 670 | +int rl_visible_prompt_length = 0;
|
---|
| 671 | +
|
---|
| 672 | +/* Set to non-zero by calling application if it has already printed rl_prompt
|
---|
| 673 | + and does not want readline to do it the first time. */
|
---|
| 674 | +int rl_already_prompted = 0;
|
---|
| 675 | +
|
---|
| 676 | +/* The number of characters read in order to type this complete command. */
|
---|
| 677 | +int rl_key_sequence_length = 0;
|
---|
| 678 | +
|
---|
| 679 | +/* If non-zero, then this is the address of a function to call just
|
---|
| 680 | + before readline_internal_setup () prints the first prompt. */
|
---|
| 681 | +rl_hook_func_t *rl_startup_hook = (rl_hook_func_t *)NULL;
|
---|
| 682 | +
|
---|
| 683 | +/* If non-zero, this is the address of a function to call just before
|
---|
| 684 | + readline_internal_setup () returns and readline_internal starts
|
---|
| 685 | + reading input characters. */
|
---|
| 686 | +rl_hook_func_t *rl_pre_input_hook = (rl_hook_func_t *)NULL;
|
---|
| 687 | +
|
---|
| 688 | +/* What we use internally. You should always refer to RL_LINE_BUFFER. */
|
---|
| 689 | +static char *the_line;
|
---|
| 690 | +
|
---|
| 691 | +/* The character that can generate an EOF. Really read from
|
---|
| 692 | + the terminal driver... just defaulted here. */
|
---|
| 693 | +int _rl_eof_char = CTRL ('D');
|
---|
| 694 | +
|
---|
| 695 | +/* Non-zero makes this the next keystroke to read. */
|
---|
| 696 | +int rl_pending_input = 0;
|
---|
| 697 | +
|
---|
| 698 | +/* Pointer to a useful terminal name. */
|
---|
| 699 | +const char *rl_terminal_name = (const char *)NULL;
|
---|
| 700 | +
|
---|
| 701 | +/* Non-zero means to always use horizontal scrolling in line display. */
|
---|
| 702 | +int _rl_horizontal_scroll_mode = 0;
|
---|
| 703 | +
|
---|
| 704 | +/* Non-zero means to display an asterisk at the starts of history lines
|
---|
| 705 | + which have been modified. */
|
---|
| 706 | +int _rl_mark_modified_lines = 0;
|
---|
| 707 | +
|
---|
| 708 | +/* The style of `bell' notification preferred. This can be set to NO_BELL,
|
---|
| 709 | + AUDIBLE_BELL, or VISIBLE_BELL. */
|
---|
| 710 | +int _rl_bell_preference = AUDIBLE_BELL;
|
---|
| 711 | +
|
---|
| 712 | +/* String inserted into the line by rl_insert_comment (). */
|
---|
| 713 | +char *_rl_comment_begin;
|
---|
| 714 | +
|
---|
| 715 | +/* Keymap holding the function currently being executed. */
|
---|
| 716 | +Keymap rl_executing_keymap;
|
---|
| 717 | +
|
---|
| 718 | +/* Keymap we're currently using to dispatch. */
|
---|
| 719 | +Keymap _rl_dispatching_keymap;
|
---|
| 720 | +
|
---|
| 721 | +/* Non-zero means to erase entire line, including prompt, on empty input lines. */
|
---|
| 722 | +int rl_erase_empty_line = 0;
|
---|
| 723 | +
|
---|
| 724 | +/* Non-zero means to read only this many characters rather than up to a
|
---|
| 725 | + character bound to accept-line. */
|
---|
| 726 | +int rl_num_chars_to_read;
|
---|
| 727 | +
|
---|
| 728 | +/* Line buffer and maintenance. */
|
---|
| 729 | +char *rl_line_buffer = (char *)NULL;
|
---|
| 730 | +int rl_line_buffer_len = 0;
|
---|
| 731 | +
|
---|
| 732 | +/* Key sequence `contexts' */
|
---|
| 733 | +_rl_keyseq_cxt *_rl_kscxt = 0;
|
---|
| 734 | +
|
---|
| 735 | +int rl_executing_key;
|
---|
| 736 | +char *rl_executing_keyseq = 0;
|
---|
| 737 | +int _rl_executing_keyseq_size = 0;
|
---|
| 738 | +
|
---|
| 739 | +/* Timeout (specified in milliseconds) when reading characters making up an
|
---|
| 740 | + ambiguous multiple-key sequence */
|
---|
| 741 | +int _rl_keyseq_timeout = 500;
|
---|
| 742 | +
|
---|
| 743 | +#define RESIZE_KEYSEQ_BUFFER() \
|
---|
| 744 | + do \
|
---|
| 745 | + { \
|
---|
| 746 | + if (rl_key_sequence_length + 2 >= _rl_executing_keyseq_size) \
|
---|
| 747 | + { \
|
---|
| 748 | + _rl_executing_keyseq_size += 16; \
|
---|
| 749 | + rl_executing_keyseq = xrealloc (rl_executing_keyseq, _rl_executing_keyseq_size); \
|
---|
| 750 | + } \
|
---|
| 751 | + } \
|
---|
| 752 | + while (0);
|
---|
| 753 | +
|
---|
| 754 | +/* Forward declarations used by the display, termcap, and history code. */
|
---|
| 755 | +
|
---|
| 756 | +/* **************************************************************** */
|
---|
| 757 | +/* */
|
---|
| 758 | +/* `Forward' declarations */
|
---|
| 759 | +/* */
|
---|
| 760 | +/* **************************************************************** */
|
---|
| 761 | +
|
---|
| 762 | +/* Non-zero means do not parse any lines other than comments and
|
---|
| 763 | + parser directives. */
|
---|
| 764 | +unsigned char _rl_parsing_conditionalized_out = 0;
|
---|
| 765 | +
|
---|
| 766 | +/* Non-zero means to convert characters with the meta bit set to
|
---|
| 767 | + escape-prefixed characters so we can indirect through
|
---|
| 768 | + emacs_meta_keymap or vi_escape_keymap. */
|
---|
| 769 | +int _rl_convert_meta_chars_to_ascii = 1;
|
---|
| 770 | +
|
---|
| 771 | +/* Non-zero means to output characters with the meta bit set directly
|
---|
| 772 | + rather than as a meta-prefixed escape sequence. */
|
---|
| 773 | +int _rl_output_meta_chars = 0;
|
---|
| 774 | +
|
---|
| 775 | +/* Non-zero means to look at the termios special characters and bind
|
---|
| 776 | + them to equivalent readline functions at startup. */
|
---|
| 777 | +int _rl_bind_stty_chars = 1;
|
---|
| 778 | +
|
---|
| 779 | +/* Non-zero means to go through the history list at every newline (or
|
---|
| 780 | + whenever rl_done is set and readline returns) and revert each line to
|
---|
| 781 | + its initial state. */
|
---|
| 782 | +int _rl_revert_all_at_newline = 0;
|
---|
| 783 | +
|
---|
| 784 | +/* Non-zero means to honor the termios ECHOCTL bit and echo control
|
---|
| 785 | + characters corresponding to keyboard-generated signals. */
|
---|
| 786 | +int _rl_echo_control_chars = 1;
|
---|
| 787 | +
|
---|
| 788 | +/* Non-zero means to prefix the displayed prompt with a character indicating
|
---|
| 789 | + the editing mode: @ for emacs, : for vi-command, + for vi-insert. */
|
---|
| 790 | +int _rl_show_mode_in_prompt = 0;
|
---|
| 791 | +
|
---|
| 792 | +/* **************************************************************** */
|
---|
| 793 | +/* */
|
---|
| 794 | +/* Top Level Functions */
|
---|
| 795 | +/* */
|
---|
| 796 | +/* **************************************************************** */
|
---|
| 797 | +
|
---|
| 798 | +/* Non-zero means treat 0200 bit in terminal input as Meta bit. */
|
---|
| 799 | +int _rl_meta_flag = 0; /* Forward declaration */
|
---|
| 800 | +
|
---|
| 801 | +/* Set up the prompt and expand it. Called from readline() and
|
---|
| 802 | + rl_callback_handler_install (). */
|
---|
| 803 | +int
|
---|
| 804 | +rl_set_prompt (prompt)
|
---|
| 805 | + const char *prompt;
|
---|
| 806 | +{
|
---|
| 807 | + FREE (rl_prompt);
|
---|
| 808 | + rl_prompt = prompt ? savestring (prompt) : (char *)NULL;
|
---|
| 809 | + rl_display_prompt = rl_prompt ? rl_prompt : "";
|
---|
| 810 | +
|
---|
| 811 | + rl_visible_prompt_length = rl_expand_prompt (rl_prompt);
|
---|
| 812 | + return 0;
|
---|
| 813 | +}
|
---|
| 814 | +
|
---|
| 815 | +/* Read a line of input. Prompt with PROMPT. An empty PROMPT means
|
---|
| 816 | + none. A return value of NULL means that EOF was encountered. */
|
---|
| 817 | +char *
|
---|
| 818 | +readline (prompt)
|
---|
| 819 | + const char *prompt;
|
---|
| 820 | +{
|
---|
| 821 | + char *value;
|
---|
| 822 | +#if 0
|
---|
| 823 | + int in_callback;
|
---|
| 824 | +#endif
|
---|
| 825 | +
|
---|
| 826 | + /* If we are at EOF return a NULL string. */
|
---|
| 827 | + if (rl_pending_input == EOF)
|
---|
| 828 | + {
|
---|
| 829 | + rl_clear_pending_input ();
|
---|
| 830 | + return ((char *)NULL);
|
---|
| 831 | + }
|
---|
| 832 | +
|
---|
| 833 | +#if 0
|
---|
| 834 | + /* If readline() is called after installing a callback handler, temporarily
|
---|
| 835 | + turn off the callback state to avoid ensuing messiness. Patch supplied
|
---|
| 836 | + by the gdb folks. XXX -- disabled. This can be fooled and readline
|
---|
| 837 | + left in a strange state by a poorly-timed longjmp. */
|
---|
| 838 | + if (in_callback = RL_ISSTATE (RL_STATE_CALLBACK))
|
---|
| 839 | + RL_UNSETSTATE (RL_STATE_CALLBACK);
|
---|
| 840 | +#endif
|
---|
| 841 | +
|
---|
| 842 | + rl_set_prompt (prompt);
|
---|
| 843 | +
|
---|
| 844 | + rl_initialize ();
|
---|
| 845 | + if (rl_prep_term_function)
|
---|
| 846 | + (*rl_prep_term_function) (_rl_meta_flag);
|
---|
| 847 | +
|
---|
| 848 | +#if defined (HANDLE_SIGNALS)
|
---|
| 849 | + rl_set_signals ();
|
---|
| 850 | +#endif
|
---|
| 851 | +
|
---|
| 852 | + value = readline_internal ();
|
---|
| 853 | + if (rl_deprep_term_function)
|
---|
| 854 | + (*rl_deprep_term_function) ();
|
---|
| 855 | +
|
---|
| 856 | +#if defined (HANDLE_SIGNALS)
|
---|
| 857 | + rl_clear_signals ();
|
---|
| 858 | +#endif
|
---|
| 859 | +
|
---|
| 860 | +#if 0
|
---|
| 861 | + if (in_callback)
|
---|
| 862 | + RL_SETSTATE (RL_STATE_CALLBACK);
|
---|
| 863 | +#endif
|
---|
| 864 | +
|
---|
| 865 | +#if HAVE_DECL_AUDIT_TTY && defined (ENABLE_TTY_AUDIT_SUPPORT)
|
---|
| 866 | + if (value)
|
---|
| 867 | + _rl_audit_tty (value);
|
---|
| 868 | +#endif
|
---|
| 869 | +
|
---|
| 870 | + return (value);
|
---|
| 871 | +}
|
---|
| 872 | +
|
---|
| 873 | +#if defined (READLINE_CALLBACKS)
|
---|
| 874 | +# define STATIC_CALLBACK
|
---|
| 875 | +#else
|
---|
| 876 | +# define STATIC_CALLBACK static
|
---|
| 877 | +#endif
|
---|
| 878 | +
|
---|
| 879 | +STATIC_CALLBACK void
|
---|
| 880 | +readline_internal_setup ()
|
---|
| 881 | +{
|
---|
| 882 | + char *nprompt;
|
---|
| 883 | +
|
---|
| 884 | + _rl_in_stream = rl_instream;
|
---|
| 885 | + _rl_out_stream = rl_outstream;
|
---|
| 886 | +
|
---|
| 887 | + /* Enable the meta key only for the duration of readline(), if this
|
---|
| 888 | + terminal has one and the terminal has been initialized */
|
---|
| 889 | + if (_rl_enable_meta & RL_ISSTATE (RL_STATE_TERMPREPPED))
|
---|
| 890 | + _rl_enable_meta_key ();
|
---|
| 891 | +
|
---|
| 892 | + if (rl_startup_hook)
|
---|
| 893 | + (*rl_startup_hook) ();
|
---|
| 894 | +
|
---|
| 895 | +#if defined (VI_MODE)
|
---|
| 896 | + if (rl_editing_mode == vi_mode)
|
---|
| 897 | + rl_vi_insertion_mode (1, 'i'); /* don't want to reset last */
|
---|
| 898 | +#endif /* VI_MODE */
|
---|
| 899 | +
|
---|
| 900 | + /* If we're not echoing, we still want to at least print a prompt, because
|
---|
| 901 | + rl_redisplay will not do it for us. If the calling application has a
|
---|
| 902 | + custom redisplay function, though, let that function handle it. */
|
---|
| 903 | + if (_rl_echoing_p == 0 && rl_redisplay_function == rl_redisplay)
|
---|
| 904 | + {
|
---|
| 905 | + if (rl_prompt && rl_already_prompted == 0)
|
---|
| 906 | + {
|
---|
| 907 | + nprompt = _rl_strip_prompt (rl_prompt);
|
---|
| 908 | + fprintf (_rl_out_stream, "%s", nprompt);
|
---|
| 909 | + fflush (_rl_out_stream);
|
---|
| 910 | + xfree (nprompt);
|
---|
| 911 | + }
|
---|
| 912 | + }
|
---|
| 913 | + else
|
---|
| 914 | + {
|
---|
| 915 | + if (rl_prompt && rl_already_prompted)
|
---|
| 916 | + rl_on_new_line_with_prompt ();
|
---|
| 917 | + else
|
---|
| 918 | + rl_on_new_line ();
|
---|
| 919 | + (*rl_redisplay_function) ();
|
---|
| 920 | + }
|
---|
| 921 | +
|
---|
| 922 | + if (rl_pre_input_hook)
|
---|
| 923 | + (*rl_pre_input_hook) ();
|
---|
| 924 | +
|
---|
| 925 | + RL_CHECK_SIGNALS ();
|
---|
| 926 | +}
|
---|
| 927 | +
|
---|
| 928 | +STATIC_CALLBACK char *
|
---|
| 929 | +readline_internal_teardown (eof)
|
---|
| 930 | + int eof;
|
---|
| 931 | +{
|
---|
| 932 | + char *temp;
|
---|
| 933 | + HIST_ENTRY *entry;
|
---|
| 934 | +
|
---|
| 935 | + RL_CHECK_SIGNALS ();
|
---|
| 936 | +
|
---|
| 937 | + /* Restore the original of this history line, iff the line that we
|
---|
| 938 | + are editing was originally in the history, AND the line has changed. */
|
---|
| 939 | + entry = current_history ();
|
---|
| 940 | +
|
---|
| 941 | + if (entry && rl_undo_list)
|
---|
| 942 | + {
|
---|
| 943 | + temp = savestring (the_line);
|
---|
| 944 | + rl_revert_line (1, 0);
|
---|
| 945 | + entry = replace_history_entry (where_history (), the_line, (histdata_t)NULL);
|
---|
| 946 | + _rl_free_history_entry (entry);
|
---|
| 947 | +
|
---|
| 948 | + strcpy (the_line, temp);
|
---|
| 949 | + xfree (temp);
|
---|
| 950 | + }
|
---|
| 951 | +
|
---|
| 952 | + if (_rl_revert_all_at_newline)
|
---|
| 953 | + _rl_revert_all_lines ();
|
---|
| 954 | +
|
---|
| 955 | + /* At any rate, it is highly likely that this line has an undo list. Get
|
---|
| 956 | + rid of it now. */
|
---|
| 957 | + if (rl_undo_list)
|
---|
| 958 | + rl_free_undo_list ();
|
---|
| 959 | +
|
---|
| 960 | + /* Disable the meta key, if this terminal has one and we were told to use it.
|
---|
| 961 | + The check whether or not we sent the enable string is in
|
---|
| 962 | + _rl_disable_meta_key(); the flag is set in _rl_enable_meta_key */
|
---|
| 963 | + _rl_disable_meta_key ();
|
---|
| 964 | +
|
---|
| 965 | + /* Restore normal cursor, if available. */
|
---|
| 966 | + _rl_set_insert_mode (RL_IM_INSERT, 0);
|
---|
| 967 | +
|
---|
| 968 | + return (eof ? (char *)NULL : savestring (the_line));
|
---|
| 969 | +}
|
---|
| 970 | +
|
---|
| 971 | +void
|
---|
| 972 | +_rl_internal_char_cleanup ()
|
---|
| 973 | +{
|
---|
| 974 | +#if defined (VI_MODE)
|
---|
| 975 | + /* In vi mode, when you exit insert mode, the cursor moves back
|
---|
| 976 | + over the previous character. We explicitly check for that here. */
|
---|
| 977 | + if (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap)
|
---|
| 978 | + rl_vi_check ();
|
---|
| 979 | +#endif /* VI_MODE */
|
---|
| 980 | +
|
---|
| 981 | + if (rl_num_chars_to_read && rl_end >= rl_num_chars_to_read)
|
---|
| 982 | + {
|
---|
| 983 | + (*rl_redisplay_function) ();
|
---|
| 984 | + _rl_want_redisplay = 0;
|
---|
| 985 | + rl_newline (1, '\n');
|
---|
| 986 | + }
|
---|
| 987 | +
|
---|
| 988 | + if (rl_done == 0)
|
---|
| 989 | + {
|
---|
| 990 | + (*rl_redisplay_function) ();
|
---|
| 991 | + _rl_want_redisplay = 0;
|
---|
| 992 | + }
|
---|
| 993 | +
|
---|
| 994 | + /* If the application writer has told us to erase the entire line if
|
---|
| 995 | + the only character typed was something bound to rl_newline, do so. */
|
---|
| 996 | + if (rl_erase_empty_line && rl_done && rl_last_func == rl_newline &&
|
---|
| 997 | + rl_point == 0 && rl_end == 0)
|
---|
| 998 | + _rl_erase_entire_line ();
|
---|
| 999 | +}
|
---|
| 1000 | +
|
---|
| 1001 | +STATIC_CALLBACK int
|
---|
| 1002 | +#if defined (READLINE_CALLBACKS)
|
---|
| 1003 | +readline_internal_char ()
|
---|
| 1004 | +#else
|
---|
| 1005 | +readline_internal_charloop ()
|
---|
| 1006 | +#endif
|
---|
| 1007 | +{
|
---|
| 1008 | + static int lastc, eof_found;
|
---|
| 1009 | + int c, code, lk;
|
---|
| 1010 | +
|
---|
| 1011 | + lastc = -1;
|
---|
| 1012 | + eof_found = 0;
|
---|
| 1013 | +
|
---|
| 1014 | +#if !defined (READLINE_CALLBACKS)
|
---|
| 1015 | + while (rl_done == 0)
|
---|
| 1016 | + {
|
---|
| 1017 | +#endif
|
---|
| 1018 | + lk = _rl_last_command_was_kill;
|
---|
| 1019 | +
|
---|
| 1020 | +#if defined (HAVE_POSIX_SIGSETJMP)
|
---|
| 1021 | + code = sigsetjmp (_rl_top_level, 0);
|
---|
| 1022 | +#else
|
---|
| 1023 | + code = setjmp (_rl_top_level);
|
---|
| 1024 | +#endif
|
---|
| 1025 | +
|
---|
| 1026 | + if (code)
|
---|
| 1027 | + {
|
---|
| 1028 | + (*rl_redisplay_function) ();
|
---|
| 1029 | + _rl_want_redisplay = 0;
|
---|
| 1030 | + /* If we get here, we're not being called from something dispatched
|
---|
| 1031 | + from _rl_callback_read_char(), which sets up its own value of
|
---|
| 1032 | + _rl_top_level (saving and restoring the old, of course), so
|
---|
| 1033 | + we can just return here. */
|
---|
| 1034 | + if (RL_ISSTATE (RL_STATE_CALLBACK))
|
---|
| 1035 | + return (0);
|
---|
| 1036 | + }
|
---|
| 1037 | +
|
---|
| 1038 | + if (rl_pending_input == 0)
|
---|
| 1039 | + {
|
---|
| 1040 | + /* Then initialize the argument and number of keys read. */
|
---|
| 1041 | + _rl_reset_argument ();
|
---|
| 1042 | + rl_key_sequence_length = 0;
|
---|
| 1043 | + rl_executing_keyseq[0] = 0;
|
---|
| 1044 | + }
|
---|
| 1045 | +
|
---|
| 1046 | + RL_SETSTATE(RL_STATE_READCMD);
|
---|
| 1047 | + c = rl_read_key ();
|
---|
| 1048 | + RL_UNSETSTATE(RL_STATE_READCMD);
|
---|
| 1049 | +
|
---|
| 1050 | + /* look at input.c:rl_getc() for the circumstances under which this will
|
---|
| 1051 | + be returned; punt immediately on read error without converting it to
|
---|
| 1052 | + a newline; assume that rl_read_key has already called the signal
|
---|
| 1053 | + handler. */
|
---|
| 1054 | + if (c == READERR)
|
---|
| 1055 | + {
|
---|
| 1056 | +#if defined (READLINE_CALLBACKS)
|
---|
| 1057 | + RL_SETSTATE(RL_STATE_DONE);
|
---|
| 1058 | + return (rl_done = 1);
|
---|
| 1059 | +#else
|
---|
| 1060 | + eof_found = 1;
|
---|
| 1061 | + break;
|
---|
| 1062 | +#endif
|
---|
| 1063 | + }
|
---|
| 1064 | +
|
---|
| 1065 | + /* EOF typed to a non-blank line is a <NL>. If we want to change this,
|
---|
| 1066 | + to force any existing line to be ignored when read(2) reads EOF,
|
---|
| 1067 | + for example, this is the place to change. */
|
---|
| 1068 | + if (c == EOF && rl_end)
|
---|
| 1069 | + c = NEWLINE;
|
---|
| 1070 | +
|
---|
| 1071 | + /* The character _rl_eof_char typed to blank line, and not as the
|
---|
| 1072 | + previous character is interpreted as EOF. */
|
---|
| 1073 | + if (((c == _rl_eof_char && lastc != c) || c == EOF) && !rl_end)
|
---|
| 1074 | + {
|
---|
| 1075 | +#if defined (READLINE_CALLBACKS)
|
---|
| 1076 | + RL_SETSTATE(RL_STATE_DONE);
|
---|
| 1077 | + return (rl_done = 1);
|
---|
| 1078 | +#else
|
---|
| 1079 | + eof_found = 1;
|
---|
| 1080 | + break;
|
---|
| 1081 | +#endif
|
---|
| 1082 | + }
|
---|
| 1083 | +
|
---|
| 1084 | + lastc = c;
|
---|
| 1085 | + _rl_dispatch ((unsigned char)c, _rl_keymap);
|
---|
| 1086 | + RL_CHECK_SIGNALS ();
|
---|
| 1087 | +
|
---|
| 1088 | + /* If there was no change in _rl_last_command_was_kill, then no kill
|
---|
| 1089 | + has taken place. Note that if input is pending we are reading
|
---|
| 1090 | + a prefix command, so nothing has changed yet. */
|
---|
| 1091 | + if (rl_pending_input == 0 && lk == _rl_last_command_was_kill)
|
---|
| 1092 | + _rl_last_command_was_kill = 0;
|
---|
| 1093 | +
|
---|
| 1094 | + _rl_internal_char_cleanup ();
|
---|
| 1095 | +
|
---|
| 1096 | +#if defined (READLINE_CALLBACKS)
|
---|
| 1097 | + return 0;
|
---|
| 1098 | +#else
|
---|
| 1099 | + }
|
---|
| 1100 | +
|
---|
| 1101 | + return (eof_found);
|
---|
| 1102 | +#endif
|
---|
| 1103 | +}
|
---|
| 1104 | +
|
---|
| 1105 | +#if defined (READLINE_CALLBACKS)
|
---|
| 1106 | +static int
|
---|
| 1107 | +readline_internal_charloop ()
|
---|
| 1108 | +{
|
---|
| 1109 | + int eof = 1;
|
---|
| 1110 | +
|
---|
| 1111 | + while (rl_done == 0)
|
---|
| 1112 | + eof = readline_internal_char ();
|
---|
| 1113 | + return (eof);
|
---|
| 1114 | +}
|
---|
| 1115 | +#endif /* READLINE_CALLBACKS */
|
---|
| 1116 | +
|
---|
| 1117 | +/* Read a line of input from the global rl_instream, doing output on
|
---|
| 1118 | + the global rl_outstream.
|
---|
| 1119 | + If rl_prompt is non-null, then that is our prompt. */
|
---|
| 1120 | +static char *
|
---|
| 1121 | +readline_internal ()
|
---|
| 1122 | +{
|
---|
| 1123 | + int eof;
|
---|
| 1124 | +
|
---|
| 1125 | + readline_internal_setup ();
|
---|
| 1126 | + eof = readline_internal_charloop ();
|
---|
| 1127 | + return (readline_internal_teardown (eof));
|
---|
| 1128 | +}
|
---|
| 1129 | +
|
---|
| 1130 | +void
|
---|
| 1131 | +_rl_init_line_state ()
|
---|
| 1132 | +{
|
---|
| 1133 | + rl_point = rl_end = rl_mark = 0;
|
---|
| 1134 | + the_line = rl_line_buffer;
|
---|
| 1135 | + the_line[0] = 0;
|
---|
| 1136 | +}
|
---|
| 1137 | +
|
---|
| 1138 | +void
|
---|
| 1139 | +_rl_set_the_line ()
|
---|
| 1140 | +{
|
---|
| 1141 | + the_line = rl_line_buffer;
|
---|
| 1142 | +}
|
---|
| 1143 | +
|
---|
| 1144 | +#if defined (READLINE_CALLBACKS)
|
---|
| 1145 | +_rl_keyseq_cxt *
|
---|
| 1146 | +_rl_keyseq_cxt_alloc ()
|
---|
| 1147 | +{
|
---|
| 1148 | + _rl_keyseq_cxt *cxt;
|
---|
| 1149 | +
|
---|
| 1150 | + cxt = (_rl_keyseq_cxt *)xmalloc (sizeof (_rl_keyseq_cxt));
|
---|
| 1151 | +
|
---|
| 1152 | + cxt->flags = cxt->subseq_arg = cxt->subseq_retval = 0;
|
---|
| 1153 | +
|
---|
| 1154 | + cxt->okey = 0;
|
---|
| 1155 | + cxt->ocxt = _rl_kscxt;
|
---|
| 1156 | + cxt->childval = 42; /* sentinel value */
|
---|
| 1157 | +
|
---|
| 1158 | + return cxt;
|
---|
| 1159 | +}
|
---|
| 1160 | +
|
---|
| 1161 | +void
|
---|
| 1162 | +_rl_keyseq_cxt_dispose (cxt)
|
---|
| 1163 | + _rl_keyseq_cxt *cxt;
|
---|
| 1164 | +{
|
---|
| 1165 | + xfree (cxt);
|
---|
| 1166 | +}
|
---|
| 1167 | +
|
---|
| 1168 | +void
|
---|
| 1169 | +_rl_keyseq_chain_dispose ()
|
---|
| 1170 | +{
|
---|
| 1171 | + _rl_keyseq_cxt *cxt;
|
---|
| 1172 | +
|
---|
| 1173 | + while (_rl_kscxt)
|
---|
| 1174 | + {
|
---|
| 1175 | + cxt = _rl_kscxt;
|
---|
| 1176 | + _rl_kscxt = _rl_kscxt->ocxt;
|
---|
| 1177 | + _rl_keyseq_cxt_dispose (cxt);
|
---|
| 1178 | + }
|
---|
| 1179 | +}
|
---|
| 1180 | +#endif
|
---|
| 1181 | +
|
---|
| 1182 | +static int
|
---|
| 1183 | +_rl_subseq_getchar (key)
|
---|
| 1184 | + int key;
|
---|
| 1185 | +{
|
---|
| 1186 | + int k;
|
---|
| 1187 | +
|
---|
| 1188 | + if (key == ESC)
|
---|
| 1189 | + RL_SETSTATE(RL_STATE_METANEXT);
|
---|
| 1190 | + RL_SETSTATE(RL_STATE_MOREINPUT);
|
---|
| 1191 | + k = rl_read_key ();
|
---|
| 1192 | + RL_UNSETSTATE(RL_STATE_MOREINPUT);
|
---|
| 1193 | + if (key == ESC)
|
---|
| 1194 | + RL_UNSETSTATE(RL_STATE_METANEXT);
|
---|
| 1195 | +
|
---|
| 1196 | + return k;
|
---|
| 1197 | +}
|
---|
| 1198 | +
|
---|
| 1199 | +#if defined (READLINE_CALLBACKS)
|
---|
| 1200 | +int
|
---|
| 1201 | +_rl_dispatch_callback (cxt)
|
---|
| 1202 | + _rl_keyseq_cxt *cxt;
|
---|
| 1203 | +{
|
---|
| 1204 | + int nkey, r;
|
---|
| 1205 | +
|
---|
| 1206 | + /* For now */
|
---|
| 1207 | + /* The first time this context is used, we want to read input and dispatch
|
---|
| 1208 | + on it. When traversing the chain of contexts back `up', we want to use
|
---|
| 1209 | + the value from the next context down. We're simulating recursion using
|
---|
| 1210 | + a chain of contexts. */
|
---|
| 1211 | + if ((cxt->flags & KSEQ_DISPATCHED) == 0)
|
---|
| 1212 | + {
|
---|
| 1213 | + nkey = _rl_subseq_getchar (cxt->okey);
|
---|
| 1214 | + if (nkey < 0)
|
---|
| 1215 | + {
|
---|
| 1216 | + _rl_abort_internal ();
|
---|
| 1217 | + return -1;
|
---|
| 1218 | + }
|
---|
| 1219 | + r = _rl_dispatch_subseq (nkey, cxt->dmap, cxt->subseq_arg);
|
---|
| 1220 | + cxt->flags |= KSEQ_DISPATCHED;
|
---|
| 1221 | + }
|
---|
| 1222 | + else
|
---|
| 1223 | + r = cxt->childval;
|
---|
| 1224 | +
|
---|
| 1225 | + /* For now */
|
---|
| 1226 | + if (r != -3) /* don't do this if we indicate there will be other matches */
|
---|
| 1227 | + r = _rl_subseq_result (r, cxt->oldmap, cxt->okey, (cxt->flags & KSEQ_SUBSEQ));
|
---|
| 1228 | +
|
---|
| 1229 | + RL_CHECK_SIGNALS ();
|
---|
| 1230 | + /* We only treat values < 0 specially to simulate recursion. */
|
---|
| 1231 | + if (r >= 0 || (r == -1 && (cxt->flags & KSEQ_SUBSEQ) == 0)) /* success! or failure! */
|
---|
| 1232 | + {
|
---|
| 1233 | + _rl_keyseq_chain_dispose ();
|
---|
| 1234 | + RL_UNSETSTATE (RL_STATE_MULTIKEY);
|
---|
| 1235 | + return r;
|
---|
| 1236 | + }
|
---|
| 1237 | +
|
---|
| 1238 | + if (r != -3) /* magic value that says we added to the chain */
|
---|
| 1239 | + _rl_kscxt = cxt->ocxt;
|
---|
| 1240 | + if (_rl_kscxt)
|
---|
| 1241 | + _rl_kscxt->childval = r;
|
---|
| 1242 | + if (r != -3)
|
---|
| 1243 | + _rl_keyseq_cxt_dispose (cxt);
|
---|
| 1244 | +
|
---|
| 1245 | + return r;
|
---|
| 1246 | +}
|
---|
| 1247 | +#endif /* READLINE_CALLBACKS */
|
---|
| 1248 | +
|
---|
| 1249 | +/* Do the command associated with KEY in MAP.
|
---|
| 1250 | + If the associated command is really a keymap, then read
|
---|
| 1251 | + another key, and dispatch into that map. */
|
---|
| 1252 | +int
|
---|
| 1253 | +_rl_dispatch (key, map)
|
---|
| 1254 | + register int key;
|
---|
| 1255 | + Keymap map;
|
---|
| 1256 | +{
|
---|
| 1257 | + _rl_dispatching_keymap = map;
|
---|
| 1258 | + return _rl_dispatch_subseq (key, map, 0);
|
---|
| 1259 | +}
|
---|
| 1260 | +
|
---|
| 1261 | +int
|
---|
| 1262 | +_rl_dispatch_subseq (key, map, got_subseq)
|
---|
| 1263 | + register int key;
|
---|
| 1264 | + Keymap map;
|
---|
| 1265 | + int got_subseq;
|
---|
| 1266 | +{
|
---|
| 1267 | + int r, newkey;
|
---|
| 1268 | + char *macro;
|
---|
| 1269 | + rl_command_func_t *func;
|
---|
| 1270 | +#if defined (READLINE_CALLBACKS)
|
---|
| 1271 | + _rl_keyseq_cxt *cxt;
|
---|
| 1272 | +#endif
|
---|
| 1273 | +
|
---|
| 1274 | + if (META_CHAR (key) && _rl_convert_meta_chars_to_ascii)
|
---|
| 1275 | + {
|
---|
| 1276 | + if (map[ESC].type == ISKMAP)
|
---|
| 1277 | + {
|
---|
| 1278 | + if (RL_ISSTATE (RL_STATE_MACRODEF))
|
---|
| 1279 | + _rl_add_macro_char (ESC);
|
---|
| 1280 | + RESIZE_KEYSEQ_BUFFER ();
|
---|
| 1281 | + rl_executing_keyseq[rl_key_sequence_length++] = ESC;
|
---|
| 1282 | + map = FUNCTION_TO_KEYMAP (map, ESC);
|
---|
| 1283 | + key = UNMETA (key);
|
---|
| 1284 | + return (_rl_dispatch (key, map));
|
---|
| 1285 | + }
|
---|
| 1286 | + else
|
---|
| 1287 | + rl_ding ();
|
---|
| 1288 | + return 0;
|
---|
| 1289 | + }
|
---|
| 1290 | +
|
---|
| 1291 | + if (RL_ISSTATE (RL_STATE_MACRODEF))
|
---|
| 1292 | + _rl_add_macro_char (key);
|
---|
| 1293 | +
|
---|
| 1294 | + r = 0;
|
---|
| 1295 | + switch (map[key].type)
|
---|
| 1296 | + {
|
---|
| 1297 | + case ISFUNC:
|
---|
| 1298 | + func = map[key].function;
|
---|
| 1299 | + if (func)
|
---|
| 1300 | + {
|
---|
| 1301 | + /* Special case rl_do_lowercase_version (). */
|
---|
| 1302 | + if (func == rl_do_lowercase_version)
|
---|
| 1303 | + /* Should we do anything special if key == ANYOTHERKEY? */
|
---|
| 1304 | + return (_rl_dispatch (_rl_to_lower (key), map));
|
---|
| 1305 | +
|
---|
| 1306 | + rl_executing_keymap = map;
|
---|
| 1307 | + rl_executing_key = key;
|
---|
| 1308 | +
|
---|
| 1309 | + RESIZE_KEYSEQ_BUFFER();
|
---|
| 1310 | + rl_executing_keyseq[rl_key_sequence_length++] = key;
|
---|
| 1311 | + rl_executing_keyseq[rl_key_sequence_length] = '\0';
|
---|
| 1312 | +
|
---|
| 1313 | + rl_dispatching = 1;
|
---|
| 1314 | + RL_SETSTATE(RL_STATE_DISPATCHING);
|
---|
| 1315 | + r = (*func) (rl_numeric_arg * rl_arg_sign, key);
|
---|
| 1316 | + RL_UNSETSTATE(RL_STATE_DISPATCHING);
|
---|
| 1317 | + rl_dispatching = 0;
|
---|
| 1318 | +
|
---|
| 1319 | + /* If we have input pending, then the last command was a prefix
|
---|
| 1320 | + command. Don't change the state of rl_last_func. Otherwise,
|
---|
| 1321 | + remember the last command executed in this variable. */
|
---|
| 1322 | + if (rl_pending_input == 0 && map[key].function != rl_digit_argument)
|
---|
| 1323 | + rl_last_func = map[key].function;
|
---|
| 1324 | +
|
---|
| 1325 | + RL_CHECK_SIGNALS ();
|
---|
| 1326 | + }
|
---|
| 1327 | + else if (map[ANYOTHERKEY].function)
|
---|
| 1328 | + {
|
---|
| 1329 | + /* OK, there's no function bound in this map, but there is a
|
---|
| 1330 | + shadow function that was overridden when the current keymap
|
---|
| 1331 | + was created. Return -2 to note that. */
|
---|
| 1332 | + if (RL_ISSTATE (RL_STATE_MACROINPUT))
|
---|
| 1333 | + _rl_prev_macro_key ();
|
---|
| 1334 | + else
|
---|
| 1335 | + _rl_unget_char (key);
|
---|
| 1336 | + return -2;
|
---|
| 1337 | + }
|
---|
| 1338 | + else if (got_subseq)
|
---|
| 1339 | + {
|
---|
| 1340 | + /* Return -1 to note that we're in a subsequence, but we don't
|
---|
| 1341 | + have a matching key, nor was one overridden. This means
|
---|
| 1342 | + we need to back up the recursion chain and find the last
|
---|
| 1343 | + subsequence that is bound to a function. */
|
---|
| 1344 | + if (RL_ISSTATE (RL_STATE_MACROINPUT))
|
---|
| 1345 | + _rl_prev_macro_key ();
|
---|
| 1346 | + else
|
---|
| 1347 | + _rl_unget_char (key);
|
---|
| 1348 | + return -1;
|
---|
| 1349 | + }
|
---|
| 1350 | + else
|
---|
| 1351 | + {
|
---|
| 1352 | +#if defined (READLINE_CALLBACKS)
|
---|
| 1353 | + RL_UNSETSTATE (RL_STATE_MULTIKEY);
|
---|
| 1354 | + _rl_keyseq_chain_dispose ();
|
---|
| 1355 | +#endif
|
---|
| 1356 | + _rl_abort_internal ();
|
---|
| 1357 | + return -1;
|
---|
| 1358 | + }
|
---|
| 1359 | + break;
|
---|
| 1360 | +
|
---|
| 1361 | + case ISKMAP:
|
---|
| 1362 | + if (map[key].function != 0)
|
---|
| 1363 | + {
|
---|
| 1364 | +#if defined (VI_MODE)
|
---|
| 1365 | + /* The only way this test will be true is if a subsequence has been
|
---|
| 1366 | + bound starting with ESC, generally the arrow keys. What we do is
|
---|
| 1367 | + check whether there's input in the queue, which there generally
|
---|
| 1368 | + will be if an arrow key has been pressed, and, if there's not,
|
---|
| 1369 | + just dispatch to (what we assume is) rl_vi_movement_mode right
|
---|
| 1370 | + away. This is essentially an input test with a zero timeout (by
|
---|
| 1371 | + default) or a timeout determined by the value of `keyseq-timeout' */
|
---|
| 1372 | + /* _rl_keyseq_timeout specified in milliseconds; _rl_input_queued
|
---|
| 1373 | + takes microseconds, so multiply by 1000 */
|
---|
| 1374 | + if (rl_editing_mode == vi_mode && key == ESC && map == vi_insertion_keymap
|
---|
| 1375 | + && _rl_input_queued ((_rl_keyseq_timeout > 0) ? _rl_keyseq_timeout*1000 : 0) == 0)
|
---|
| 1376 | + return (_rl_dispatch (ANYOTHERKEY, FUNCTION_TO_KEYMAP (map, key)));
|
---|
| 1377 | +#endif
|
---|
| 1378 | +
|
---|
| 1379 | + RESIZE_KEYSEQ_BUFFER ();
|
---|
| 1380 | + rl_executing_keyseq[rl_key_sequence_length++] = key;
|
---|
| 1381 | + _rl_dispatching_keymap = FUNCTION_TO_KEYMAP (map, key);
|
---|
| 1382 | +
|
---|
| 1383 | + /* Allocate new context here. Use linked contexts (linked through
|
---|
| 1384 | + cxt->ocxt) to simulate recursion */
|
---|
| 1385 | +#if defined (READLINE_CALLBACKS)
|
---|
| 1386 | + if (RL_ISSTATE (RL_STATE_CALLBACK))
|
---|
| 1387 | + {
|
---|
| 1388 | + /* Return 0 only the first time, to indicate success to
|
---|
| 1389 | + _rl_callback_read_char. The rest of the time, we're called
|
---|
| 1390 | + from _rl_dispatch_callback, so we return -3 to indicate
|
---|
| 1391 | + special handling is necessary. */
|
---|
| 1392 | + r = RL_ISSTATE (RL_STATE_MULTIKEY) ? -3 : 0;
|
---|
| 1393 | + cxt = _rl_keyseq_cxt_alloc ();
|
---|
| 1394 | +
|
---|
| 1395 | + if (got_subseq)
|
---|
| 1396 | + cxt->flags |= KSEQ_SUBSEQ;
|
---|
| 1397 | + cxt->okey = key;
|
---|
| 1398 | + cxt->oldmap = map;
|
---|
| 1399 | + cxt->dmap = _rl_dispatching_keymap;
|
---|
| 1400 | + cxt->subseq_arg = got_subseq || cxt->dmap[ANYOTHERKEY].function;
|
---|
| 1401 | +
|
---|
| 1402 | + RL_SETSTATE (RL_STATE_MULTIKEY);
|
---|
| 1403 | + _rl_kscxt = cxt;
|
---|
| 1404 | +
|
---|
| 1405 | + return r; /* don't indicate immediate success */
|
---|
| 1406 | + }
|
---|
| 1407 | +#endif
|
---|
| 1408 | +
|
---|
| 1409 | + /* Tentative inter-character timeout for potential multi-key
|
---|
| 1410 | + sequences? If no input within timeout, abort sequence and
|
---|
| 1411 | + act as if we got non-matching input. */
|
---|
| 1412 | + /* _rl_keyseq_timeout specified in milliseconds; _rl_input_queued
|
---|
| 1413 | + takes microseconds, so multiply by 1000 */
|
---|
| 1414 | + if (_rl_keyseq_timeout > 0 &&
|
---|
| 1415 | + (RL_ISSTATE (RL_STATE_INPUTPENDING|RL_STATE_MACROINPUT) == 0) &&
|
---|
| 1416 | + _rl_pushed_input_available () == 0 &&
|
---|
| 1417 | + _rl_dispatching_keymap[ANYOTHERKEY].function &&
|
---|
| 1418 | + _rl_input_queued (_rl_keyseq_timeout*1000) == 0)
|
---|
| 1419 | + return (_rl_subseq_result (-2, map, key, got_subseq));
|
---|
| 1420 | +
|
---|
| 1421 | + newkey = _rl_subseq_getchar (key);
|
---|
| 1422 | + if (newkey < 0)
|
---|
| 1423 | + {
|
---|
| 1424 | + _rl_abort_internal ();
|
---|
| 1425 | + return -1;
|
---|
| 1426 | + }
|
---|
| 1427 | +
|
---|
| 1428 | + r = _rl_dispatch_subseq (newkey, _rl_dispatching_keymap, got_subseq || map[ANYOTHERKEY].function);
|
---|
| 1429 | + return _rl_subseq_result (r, map, key, got_subseq);
|
---|
| 1430 | + }
|
---|
| 1431 | + else
|
---|
| 1432 | + {
|
---|
| 1433 | + _rl_abort_internal ();
|
---|
| 1434 | + return -1;
|
---|
| 1435 | + }
|
---|
| 1436 | + break;
|
---|
| 1437 | +
|
---|
| 1438 | + case ISMACR:
|
---|
| 1439 | + if (map[key].function != 0)
|
---|
| 1440 | + {
|
---|
| 1441 | + rl_executing_keyseq[rl_key_sequence_length] = '\0';
|
---|
| 1442 | + macro = savestring ((char *)map[key].function);
|
---|
| 1443 | + _rl_with_macro_input (macro);
|
---|
| 1444 | + return 0;
|
---|
| 1445 | + }
|
---|
| 1446 | + break;
|
---|
| 1447 | + }
|
---|
| 1448 | +#if defined (VI_MODE)
|
---|
| 1449 | + if (rl_editing_mode == vi_mode && _rl_keymap == vi_movement_keymap &&
|
---|
| 1450 | + key != ANYOTHERKEY &&
|
---|
| 1451 | + rl_key_sequence_length == 1 && /* XXX */
|
---|
| 1452 | + _rl_vi_textmod_command (key))
|
---|
| 1453 | + _rl_vi_set_last (key, rl_numeric_arg, rl_arg_sign);
|
---|
| 1454 | +#endif
|
---|
| 1455 | +
|
---|
| 1456 | + return (r);
|
---|
| 1457 | +}
|
---|
| 1458 | +
|
---|
| 1459 | +static int
|
---|
| 1460 | +_rl_subseq_result (r, map, key, got_subseq)
|
---|
| 1461 | + int r;
|
---|
| 1462 | + Keymap map;
|
---|
| 1463 | + int key, got_subseq;
|
---|
| 1464 | +{
|
---|
| 1465 | + Keymap m;
|
---|
| 1466 | + int type, nt;
|
---|
| 1467 | + rl_command_func_t *func, *nf;
|
---|
| 1468 | +
|
---|
| 1469 | + if (r == -2)
|
---|
| 1470 | + /* We didn't match anything, and the keymap we're indexed into
|
---|
| 1471 | + shadowed a function previously bound to that prefix. Call
|
---|
| 1472 | + the function. The recursive call to _rl_dispatch_subseq has
|
---|
| 1473 | + already taken care of pushing any necessary input back onto
|
---|
| 1474 | + the input queue with _rl_unget_char. */
|
---|
| 1475 | + {
|
---|
| 1476 | + m = _rl_dispatching_keymap;
|
---|
| 1477 | + type = m[ANYOTHERKEY].type;
|
---|
| 1478 | + func = m[ANYOTHERKEY].function;
|
---|
| 1479 | + if (type == ISFUNC && func == rl_do_lowercase_version)
|
---|
| 1480 | + r = _rl_dispatch (_rl_to_lower (key), map);
|
---|
| 1481 | + else if (type == ISFUNC && func == rl_insert)
|
---|
| 1482 | + {
|
---|
| 1483 | + /* If the function that was shadowed was self-insert, we
|
---|
| 1484 | + somehow need a keymap with map[key].func == self-insert.
|
---|
| 1485 | + Let's use this one. */
|
---|
| 1486 | + nt = m[key].type;
|
---|
| 1487 | + nf = m[key].function;
|
---|
| 1488 | +
|
---|
| 1489 | + m[key].type = type;
|
---|
| 1490 | + m[key].function = func;
|
---|
| 1491 | + r = _rl_dispatch (key, m);
|
---|
| 1492 | + m[key].type = nt;
|
---|
| 1493 | + m[key].function = nf;
|
---|
| 1494 | + }
|
---|
| 1495 | + else
|
---|
| 1496 | + r = _rl_dispatch (ANYOTHERKEY, m);
|
---|
| 1497 | + }
|
---|
| 1498 | + else if (r && map[ANYOTHERKEY].function)
|
---|
| 1499 | + {
|
---|
| 1500 | + /* We didn't match (r is probably -1), so return something to
|
---|
| 1501 | + tell the caller that it should try ANYOTHERKEY for an
|
---|
| 1502 | + overridden function. */
|
---|
| 1503 | + if (RL_ISSTATE (RL_STATE_MACROINPUT))
|
---|
| 1504 | + _rl_prev_macro_key ();
|
---|
| 1505 | + else
|
---|
| 1506 | + _rl_unget_char (key);
|
---|
| 1507 | + _rl_dispatching_keymap = map;
|
---|
| 1508 | + return -2;
|
---|
| 1509 | + }
|
---|
| 1510 | + else if (r && got_subseq)
|
---|
| 1511 | + {
|
---|
| 1512 | + /* OK, back up the chain. */
|
---|
| 1513 | + if (RL_ISSTATE (RL_STATE_MACROINPUT))
|
---|
| 1514 | + _rl_prev_macro_key ();
|
---|
| 1515 | + else
|
---|
| 1516 | + _rl_unget_char (key);
|
---|
| 1517 | + _rl_dispatching_keymap = map;
|
---|
| 1518 | + return -1;
|
---|
| 1519 | + }
|
---|
| 1520 | +
|
---|
| 1521 | + return r;
|
---|
| 1522 | +}
|
---|
| 1523 | +
|
---|
| 1524 | +/* **************************************************************** */
|
---|
| 1525 | +/* */
|
---|
| 1526 | +/* Initializations */
|
---|
| 1527 | +/* */
|
---|
| 1528 | +/* **************************************************************** */
|
---|
| 1529 | +
|
---|
| 1530 | +/* Initialize readline (and terminal if not already). */
|
---|
| 1531 | +int
|
---|
| 1532 | +rl_initialize ()
|
---|
| 1533 | +{
|
---|
| 1534 | + /* If we have never been called before, initialize the
|
---|
| 1535 | + terminal and data structures. */
|
---|
| 1536 | + if (!rl_initialized)
|
---|
| 1537 | + {
|
---|
| 1538 | + RL_SETSTATE(RL_STATE_INITIALIZING);
|
---|
| 1539 | + readline_initialize_everything ();
|
---|
| 1540 | + RL_UNSETSTATE(RL_STATE_INITIALIZING);
|
---|
| 1541 | + rl_initialized++;
|
---|
| 1542 | + RL_SETSTATE(RL_STATE_INITIALIZED);
|
---|
| 1543 | + }
|
---|
| 1544 | +
|
---|
| 1545 | + /* Initialize the current line information. */
|
---|
| 1546 | + _rl_init_line_state ();
|
---|
| 1547 | +
|
---|
| 1548 | + /* We aren't done yet. We haven't even gotten started yet! */
|
---|
| 1549 | + rl_done = 0;
|
---|
| 1550 | + RL_UNSETSTATE(RL_STATE_DONE);
|
---|
| 1551 | +
|
---|
| 1552 | + /* Tell the history routines what is going on. */
|
---|
| 1553 | + _rl_start_using_history ();
|
---|
| 1554 | +
|
---|
| 1555 | + /* Make the display buffer match the state of the line. */
|
---|
| 1556 | + rl_reset_line_state ();
|
---|
| 1557 | +
|
---|
| 1558 | + /* No such function typed yet. */
|
---|
| 1559 | + rl_last_func = (rl_command_func_t *)NULL;
|
---|
| 1560 | +
|
---|
| 1561 | + /* Parsing of key-bindings begins in an enabled state. */
|
---|
| 1562 | + _rl_parsing_conditionalized_out = 0;
|
---|
| 1563 | +
|
---|
| 1564 | +#if defined (VI_MODE)
|
---|
| 1565 | + if (rl_editing_mode == vi_mode)
|
---|
| 1566 | + _rl_vi_initialize_line ();
|
---|
| 1567 | +#endif
|
---|
| 1568 | +
|
---|
| 1569 | + /* Each line starts in insert mode (the default). */
|
---|
| 1570 | + _rl_set_insert_mode (RL_IM_DEFAULT, 1);
|
---|
| 1571 | +
|
---|
| 1572 | + return 0;
|
---|
| 1573 | +}
|
---|
| 1574 | +
|
---|
| 1575 | +#if 0
|
---|
| 1576 | +#if defined (__EMX__)
|
---|
| 1577 | +static void
|
---|
| 1578 | +_emx_build_environ ()
|
---|
| 1579 | +{
|
---|
| 1580 | + TIB *tibp;
|
---|
| 1581 | + PIB *pibp;
|
---|
| 1582 | + char *t, **tp;
|
---|
| 1583 | + int c;
|
---|
| 1584 | +
|
---|
| 1585 | + DosGetInfoBlocks (&tibp, &pibp);
|
---|
| 1586 | + t = pibp->pib_pchenv;
|
---|
| 1587 | + for (c = 1; *t; c++)
|
---|
| 1588 | + t += strlen (t) + 1;
|
---|
| 1589 | + tp = environ = (char **)xmalloc ((c + 1) * sizeof (char *));
|
---|
| 1590 | + t = pibp->pib_pchenv;
|
---|
| 1591 | + while (*t)
|
---|
| 1592 | + {
|
---|
| 1593 | + *tp++ = t;
|
---|
| 1594 | + t += strlen (t) + 1;
|
---|
| 1595 | + }
|
---|
| 1596 | + *tp = 0;
|
---|
| 1597 | +}
|
---|
| 1598 | +#endif /* __EMX__ */
|
---|
| 1599 | +#endif
|
---|
| 1600 | +
|
---|
| 1601 | +/* Initialize the entire state of the world. */
|
---|
| 1602 | +static void
|
---|
| 1603 | +readline_initialize_everything ()
|
---|
| 1604 | +{
|
---|
| 1605 | +#if 0
|
---|
| 1606 | +#if defined (__EMX__)
|
---|
| 1607 | + if (environ == 0)
|
---|
| 1608 | + _emx_build_environ ();
|
---|
| 1609 | +#endif
|
---|
| 1610 | +#endif
|
---|
| 1611 | +
|
---|
| 1612 | +#if 0
|
---|
| 1613 | + /* Find out if we are running in Emacs -- UNUSED. */
|
---|
| 1614 | + running_in_emacs = sh_get_env_value ("EMACS") != (char *)0;
|
---|
| 1615 | +#endif
|
---|
| 1616 | +
|
---|
| 1617 | + /* Set up input and output if they are not already set up. */
|
---|
| 1618 | + if (!rl_instream)
|
---|
| 1619 | + rl_instream = stdin;
|
---|
| 1620 | +
|
---|
| 1621 | + if (!rl_outstream)
|
---|
| 1622 | + rl_outstream = stdout;
|
---|
| 1623 | +
|
---|
| 1624 | + /* Bind _rl_in_stream and _rl_out_stream immediately. These values
|
---|
| 1625 | + may change, but they may also be used before readline_internal ()
|
---|
| 1626 | + is called. */
|
---|
| 1627 | + _rl_in_stream = rl_instream;
|
---|
| 1628 | + _rl_out_stream = rl_outstream;
|
---|
| 1629 | +
|
---|
| 1630 | + /* Allocate data structures. */
|
---|
| 1631 | + if (rl_line_buffer == 0)
|
---|
| 1632 | + rl_line_buffer = (char *)xmalloc (rl_line_buffer_len = DEFAULT_BUFFER_SIZE);
|
---|
| 1633 | +
|
---|
| 1634 | + /* Initialize the terminal interface. */
|
---|
| 1635 | + if (rl_terminal_name == 0)
|
---|
| 1636 | + rl_terminal_name = sh_get_env_value ("TERM");
|
---|
| 1637 | + _rl_init_terminal_io (rl_terminal_name);
|
---|
| 1638 | +
|
---|
| 1639 | + /* Bind tty characters to readline functions. */
|
---|
| 1640 | + readline_default_bindings ();
|
---|
| 1641 | +
|
---|
| 1642 | + /* Initialize the function names. */
|
---|
| 1643 | + rl_initialize_funmap ();
|
---|
| 1644 | +
|
---|
| 1645 | + /* Decide whether we should automatically go into eight-bit mode. */
|
---|
| 1646 | + _rl_init_eightbit ();
|
---|
| 1647 | +
|
---|
| 1648 | + /* Read in the init file. */
|
---|
| 1649 | + rl_read_init_file ((char *)NULL);
|
---|
| 1650 | +
|
---|
| 1651 | + /* XXX */
|
---|
| 1652 | + if (_rl_horizontal_scroll_mode && _rl_term_autowrap)
|
---|
| 1653 | + {
|
---|
| 1654 | + _rl_screenwidth--;
|
---|
| 1655 | + _rl_screenchars -= _rl_screenheight;
|
---|
| 1656 | + }
|
---|
| 1657 | +
|
---|
| 1658 | + /* Override the effect of any `set keymap' assignments in the
|
---|
| 1659 | + inputrc file. */
|
---|
| 1660 | + rl_set_keymap_from_edit_mode ();
|
---|
| 1661 | +
|
---|
| 1662 | + /* Try to bind a common arrow key prefix, if not already bound. */
|
---|
| 1663 | + bind_arrow_keys ();
|
---|
| 1664 | +
|
---|
| 1665 | + /* If the completion parser's default word break characters haven't
|
---|
| 1666 | + been set yet, then do so now. */
|
---|
| 1667 | + if (rl_completer_word_break_characters == (char *)NULL)
|
---|
| 1668 | + rl_completer_word_break_characters = (char *)rl_basic_word_break_characters;
|
---|
| 1669 | +
|
---|
| 1670 | +#if defined (COLOR_SUPPORT)
|
---|
| 1671 | + if (_rl_colored_stats)
|
---|
| 1672 | + _rl_parse_colors ();
|
---|
| 1673 | +#endif
|
---|
| 1674 | +
|
---|
| 1675 | + rl_executing_keyseq = malloc (_rl_executing_keyseq_size = 16);
|
---|
| 1676 | + if (rl_executing_keyseq)
|
---|
| 1677 | + rl_executing_keyseq[0] = '\0';
|
---|
| 1678 | +}
|
---|
| 1679 | +
|
---|
| 1680 | +/* If this system allows us to look at the values of the regular
|
---|
| 1681 | + input editing characters, then bind them to their readline
|
---|
| 1682 | + equivalents, iff the characters are not bound to keymaps. */
|
---|
| 1683 | +static void
|
---|
| 1684 | +readline_default_bindings ()
|
---|
| 1685 | +{
|
---|
| 1686 | + if (_rl_bind_stty_chars)
|
---|
| 1687 | + rl_tty_set_default_bindings (_rl_keymap);
|
---|
| 1688 | +}
|
---|
| 1689 | +
|
---|
| 1690 | +/* Reset the default bindings for the terminal special characters we're
|
---|
| 1691 | + interested in back to rl_insert and read the new ones. */
|
---|
| 1692 | +static void
|
---|
| 1693 | +reset_default_bindings ()
|
---|
| 1694 | +{
|
---|
| 1695 | + if (_rl_bind_stty_chars)
|
---|
| 1696 | + {
|
---|
| 1697 | + rl_tty_unset_default_bindings (_rl_keymap);
|
---|
| 1698 | + rl_tty_set_default_bindings (_rl_keymap);
|
---|
| 1699 | + }
|
---|
| 1700 | +}
|
---|
| 1701 | +
|
---|
| 1702 | +/* Bind some common arrow key sequences in MAP. */
|
---|
| 1703 | +static void
|
---|
| 1704 | +bind_arrow_keys_internal (map)
|
---|
| 1705 | + Keymap map;
|
---|
| 1706 | +{
|
---|
| 1707 | + Keymap xkeymap;
|
---|
| 1708 | +
|
---|
| 1709 | + xkeymap = _rl_keymap;
|
---|
| 1710 | + _rl_keymap = map;
|
---|
| 1711 | +
|
---|
| 1712 | +#if defined (__MSDOS__)
|
---|
| 1713 | + rl_bind_keyseq_if_unbound ("\033[0A", rl_get_previous_history);
|
---|
| 1714 | + rl_bind_keyseq_if_unbound ("\033[0B", rl_backward_char);
|
---|
| 1715 | + rl_bind_keyseq_if_unbound ("\033[0C", rl_forward_char);
|
---|
| 1716 | + rl_bind_keyseq_if_unbound ("\033[0D", rl_get_next_history);
|
---|
| 1717 | +#endif
|
---|
| 1718 | +
|
---|
| 1719 | + rl_bind_keyseq_if_unbound ("\033[A", rl_get_previous_history);
|
---|
| 1720 | + rl_bind_keyseq_if_unbound ("\033[B", rl_get_next_history);
|
---|
| 1721 | + rl_bind_keyseq_if_unbound ("\033[C", rl_forward_char);
|
---|
| 1722 | + rl_bind_keyseq_if_unbound ("\033[D", rl_backward_char);
|
---|
| 1723 | + rl_bind_keyseq_if_unbound ("\033[H", rl_beg_of_line);
|
---|
| 1724 | + rl_bind_keyseq_if_unbound ("\033[F", rl_end_of_line);
|
---|
| 1725 | +
|
---|
| 1726 | + rl_bind_keyseq_if_unbound ("\033OA", rl_get_previous_history);
|
---|
| 1727 | + rl_bind_keyseq_if_unbound ("\033OB", rl_get_next_history);
|
---|
| 1728 | + rl_bind_keyseq_if_unbound ("\033OC", rl_forward_char);
|
---|
| 1729 | + rl_bind_keyseq_if_unbound ("\033OD", rl_backward_char);
|
---|
| 1730 | + rl_bind_keyseq_if_unbound ("\033OH", rl_beg_of_line);
|
---|
| 1731 | + rl_bind_keyseq_if_unbound ("\033OF", rl_end_of_line);
|
---|
| 1732 | +
|
---|
| 1733 | +#if defined (__MINGW32__)
|
---|
| 1734 | + rl_bind_keyseq_if_unbound ("\340H", rl_get_previous_history);
|
---|
| 1735 | + rl_bind_keyseq_if_unbound ("\340P", rl_get_next_history);
|
---|
| 1736 | + rl_bind_keyseq_if_unbound ("\340M", rl_forward_char);
|
---|
| 1737 | + rl_bind_keyseq_if_unbound ("\340K", rl_backward_char);
|
---|
| 1738 | + rl_bind_keyseq_if_unbound ("\340G", rl_beg_of_line);
|
---|
| 1739 | + rl_bind_keyseq_if_unbound ("\340O", rl_end_of_line);
|
---|
| 1740 | + rl_bind_keyseq_if_unbound ("\340S", rl_delete);
|
---|
| 1741 | + rl_bind_keyseq_if_unbound ("\340R", rl_overwrite_mode);
|
---|
| 1742 | +
|
---|
| 1743 | + /* These may or may not work because of the embedded NUL. */
|
---|
| 1744 | + rl_bind_keyseq_if_unbound ("\\000H", rl_get_previous_history);
|
---|
| 1745 | + rl_bind_keyseq_if_unbound ("\\000P", rl_get_next_history);
|
---|
| 1746 | + rl_bind_keyseq_if_unbound ("\\000M", rl_forward_char);
|
---|
| 1747 | + rl_bind_keyseq_if_unbound ("\\000K", rl_backward_char);
|
---|
| 1748 | + rl_bind_keyseq_if_unbound ("\\000G", rl_beg_of_line);
|
---|
| 1749 | + rl_bind_keyseq_if_unbound ("\\000O", rl_end_of_line);
|
---|
| 1750 | + rl_bind_keyseq_if_unbound ("\\000S", rl_delete);
|
---|
| 1751 | + rl_bind_keyseq_if_unbound ("\\000R", rl_overwrite_mode);
|
---|
| 1752 | +#endif
|
---|
| 1753 | +
|
---|
| 1754 | + _rl_keymap = xkeymap;
|
---|
| 1755 | +}
|
---|
| 1756 | +
|
---|
| 1757 | +/* Try and bind the common arrow key prefixes after giving termcap and
|
---|
| 1758 | + the inputrc file a chance to bind them and create `real' keymaps
|
---|
| 1759 | + for the arrow key prefix. */
|
---|
| 1760 | +static void
|
---|
| 1761 | +bind_arrow_keys ()
|
---|
| 1762 | +{
|
---|
| 1763 | + bind_arrow_keys_internal (emacs_standard_keymap);
|
---|
| 1764 | +
|
---|
| 1765 | +#if defined (VI_MODE)
|
---|
| 1766 | + bind_arrow_keys_internal (vi_movement_keymap);
|
---|
| 1767 | + /* Unbind vi_movement_keymap[ESC] to allow users to repeatedly hit ESC
|
---|
| 1768 | + in vi command mode while still allowing the arrow keys to work. */
|
---|
| 1769 | + if (vi_movement_keymap[ESC].type == ISKMAP)
|
---|
| 1770 | + rl_bind_keyseq_in_map ("\033", (rl_command_func_t *)NULL, vi_movement_keymap);
|
---|
| 1771 | + bind_arrow_keys_internal (vi_insertion_keymap);
|
---|
| 1772 | +#endif
|
---|
| 1773 | +}
|
---|
| 1774 | +
|
---|
| 1775 | +/* **************************************************************** */
|
---|
| 1776 | +/* */
|
---|
| 1777 | +/* Saving and Restoring Readline's state */
|
---|
| 1778 | +/* */
|
---|
| 1779 | +/* **************************************************************** */
|
---|
| 1780 | +
|
---|
| 1781 | +int
|
---|
| 1782 | +rl_save_state (sp)
|
---|
| 1783 | + struct readline_state *sp;
|
---|
| 1784 | +{
|
---|
| 1785 | + if (sp == 0)
|
---|
| 1786 | + return -1;
|
---|
| 1787 | +
|
---|
| 1788 | + sp->point = rl_point;
|
---|
| 1789 | + sp->end = rl_end;
|
---|
| 1790 | + sp->mark = rl_mark;
|
---|
| 1791 | + sp->buffer = rl_line_buffer;
|
---|
| 1792 | + sp->buflen = rl_line_buffer_len;
|
---|
| 1793 | + sp->ul = rl_undo_list;
|
---|
| 1794 | + sp->prompt = rl_prompt;
|
---|
| 1795 | +
|
---|
| 1796 | + sp->rlstate = rl_readline_state;
|
---|
| 1797 | + sp->done = rl_done;
|
---|
| 1798 | + sp->kmap = _rl_keymap;
|
---|
| 1799 | +
|
---|
| 1800 | + sp->lastfunc = rl_last_func;
|
---|
| 1801 | + sp->insmode = rl_insert_mode;
|
---|
| 1802 | + sp->edmode = rl_editing_mode;
|
---|
| 1803 | + sp->kseqlen = rl_key_sequence_length;
|
---|
| 1804 | + sp->inf = rl_instream;
|
---|
| 1805 | + sp->outf = rl_outstream;
|
---|
| 1806 | + sp->pendingin = rl_pending_input;
|
---|
| 1807 | + sp->macro = rl_executing_macro;
|
---|
| 1808 | +
|
---|
| 1809 | + sp->catchsigs = rl_catch_signals;
|
---|
| 1810 | + sp->catchsigwinch = rl_catch_sigwinch;
|
---|
| 1811 | +
|
---|
| 1812 | + return (0);
|
---|
| 1813 | +}
|
---|
| 1814 | +
|
---|
| 1815 | +int
|
---|
| 1816 | +rl_restore_state (sp)
|
---|
| 1817 | + struct readline_state *sp;
|
---|
| 1818 | +{
|
---|
| 1819 | + if (sp == 0)
|
---|
| 1820 | + return -1;
|
---|
| 1821 | +
|
---|
| 1822 | + rl_point = sp->point;
|
---|
| 1823 | + rl_end = sp->end;
|
---|
| 1824 | + rl_mark = sp->mark;
|
---|
| 1825 | + the_line = rl_line_buffer = sp->buffer;
|
---|
| 1826 | + rl_line_buffer_len = sp->buflen;
|
---|
| 1827 | + rl_undo_list = sp->ul;
|
---|
| 1828 | + rl_prompt = sp->prompt;
|
---|
| 1829 | +
|
---|
| 1830 | + rl_readline_state = sp->rlstate;
|
---|
| 1831 | + rl_done = sp->done;
|
---|
| 1832 | + _rl_keymap = sp->kmap;
|
---|
| 1833 | +
|
---|
| 1834 | + rl_last_func = sp->lastfunc;
|
---|
| 1835 | + rl_insert_mode = sp->insmode;
|
---|
| 1836 | + rl_editing_mode = sp->edmode;
|
---|
| 1837 | + rl_key_sequence_length = sp->kseqlen;
|
---|
| 1838 | + rl_instream = sp->inf;
|
---|
| 1839 | + rl_outstream = sp->outf;
|
---|
| 1840 | + rl_pending_input = sp->pendingin;
|
---|
| 1841 | + rl_executing_macro = sp->macro;
|
---|
| 1842 | +
|
---|
| 1843 | + rl_catch_signals = sp->catchsigs;
|
---|
| 1844 | + rl_catch_sigwinch = sp->catchsigwinch;
|
---|
| 1845 | +
|
---|
| 1846 | + return (0);
|
---|
| 1847 | +}
|
---|
| 1848 | diff -Naur bash-4.3.orig/lib/sh/shquote.c bash-4.3/lib/sh/shquote.c
|
---|
| 1849 | --- bash-4.3.orig/lib/sh/shquote.c 2013-04-01 01:53:32.000000000 +0000
|
---|
| 1850 | +++ bash-4.3/lib/sh/shquote.c 2014-09-26 23:58:55.556306592 +0000
|
---|
| 1851 | @@ -311,3 +311,17 @@
|
---|
| 1852 |
|
---|
| 1853 | return (0);
|
---|
| 1854 | }
|
---|
| 1855 | +
|
---|
| 1856 | +int
|
---|
| 1857 | +sh_contains_quotes (string)
|
---|
| 1858 | + char *string;
|
---|
| 1859 | +{
|
---|
| 1860 | + char *s;
|
---|
| 1861 | +
|
---|
| 1862 | + for (s = string; s && *s; s++)
|
---|
| 1863 | + {
|
---|
| 1864 | + if (*s == '\'' || *s == '"' || *s == '\\')
|
---|
| 1865 | + return 1;
|
---|
| 1866 | + }
|
---|
| 1867 | + return 0;
|
---|
| 1868 | +}
|
---|
| 1869 | diff -Naur bash-4.3.orig/parse.y bash-4.3/parse.y
|
---|
| 1870 | --- bash-4.3.orig/parse.y 2014-02-11 14:42:10.000000000 +0000
|
---|
| 1871 | +++ bash-4.3/parse.y 2014-09-26 23:58:55.632973072 +0000
|
---|
| 1872 | @@ -2424,7 +2424,7 @@
|
---|
| 1873 | not already end in an EOF character. */
|
---|
| 1874 | if (shell_input_line_terminator != EOF)
|
---|
| 1875 | {
|
---|
| 1876 | - if (shell_input_line_size < SIZE_MAX && shell_input_line_len > shell_input_line_size - 3)
|
---|
| 1877 | + if (shell_input_line_size < SIZE_MAX-3 && (shell_input_line_len+3 > shell_input_line_size))
|
---|
| 1878 | shell_input_line = (char *)xrealloc (shell_input_line,
|
---|
| 1879 | 1 + (shell_input_line_size += 2));
|
---|
| 1880 |
|
---|
| 1881 | @@ -2642,7 +2642,7 @@
|
---|
| 1882 | int r;
|
---|
| 1883 |
|
---|
| 1884 | r = 0;
|
---|
| 1885 | - while (need_here_doc)
|
---|
| 1886 | + while (need_here_doc > 0)
|
---|
| 1887 | {
|
---|
| 1888 | parser_state |= PST_HEREDOC;
|
---|
| 1889 | make_here_document (redir_stack[r++], line_number);
|
---|
| 1890 | @@ -2953,6 +2953,8 @@
|
---|
| 1891 | FREE (word_desc_to_read);
|
---|
| 1892 | word_desc_to_read = (WORD_DESC *)NULL;
|
---|
| 1893 |
|
---|
| 1894 | + eol_ungetc_lookahead = 0;
|
---|
| 1895 | +
|
---|
| 1896 | current_token = '\n'; /* XXX */
|
---|
| 1897 | last_read_token = '\n';
|
---|
| 1898 | token_to_read = '\n';
|
---|
| 1899 | @@ -3398,7 +3400,7 @@
|
---|
| 1900 | within a double-quoted ${...} construct "an even number of
|
---|
| 1901 | unescaped double-quotes or single-quotes, if any, shall occur." */
|
---|
| 1902 | /* This was changed in Austin Group Interp 221 */
|
---|
| 1903 | - if MBTEST(posixly_correct && shell_compatibility_level > 41 && dolbrace_state != DOLBRACE_QUOTE && (flags & P_DQUOTE) && (flags & P_DOLBRACE) && ch == '\'')
|
---|
| 1904 | + if MBTEST(posixly_correct && shell_compatibility_level > 41 && dolbrace_state != DOLBRACE_QUOTE && dolbrace_state != DOLBRACE_QUOTE2 && (flags & P_DQUOTE) && (flags & P_DOLBRACE) && ch == '\'')
|
---|
| 1905 | continue;
|
---|
| 1906 |
|
---|
| 1907 | /* Could also check open == '`' if we want to parse grouping constructs
|
---|
| 1908 | @@ -6075,6 +6077,7 @@
|
---|
| 1909 |
|
---|
| 1910 | ps->expand_aliases = expand_aliases;
|
---|
| 1911 | ps->echo_input_at_read = echo_input_at_read;
|
---|
| 1912 | + ps->need_here_doc = need_here_doc;
|
---|
| 1913 |
|
---|
| 1914 | ps->token = token;
|
---|
| 1915 | ps->token_buffer_size = token_buffer_size;
|
---|
| 1916 | @@ -6123,6 +6126,7 @@
|
---|
| 1917 |
|
---|
| 1918 | expand_aliases = ps->expand_aliases;
|
---|
| 1919 | echo_input_at_read = ps->echo_input_at_read;
|
---|
| 1920 | + need_here_doc = ps->need_here_doc;
|
---|
| 1921 |
|
---|
| 1922 | FREE (token);
|
---|
| 1923 | token = ps->token;
|
---|
| 1924 | diff -Naur bash-4.3.orig/patchlevel.h bash-4.3/patchlevel.h
|
---|
| 1925 | --- bash-4.3.orig/patchlevel.h 2012-12-29 15:47:57.000000000 +0000
|
---|
| 1926 | +++ bash-4.3/patchlevel.h 2014-09-26 23:58:55.636306397 +0000
|
---|
| 1927 | @@ -25,6 +25,6 @@
|
---|
| 1928 | regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
|
---|
| 1929 | looks for to find the patch level (for the sccs version string). */
|
---|
| 1930 |
|
---|
| 1931 | -#define PATCHLEVEL 0
|
---|
| 1932 | +#define PATCHLEVEL 26
|
---|
| 1933 |
|
---|
| 1934 | #endif /* _PATCHLEVEL_H_ */
|
---|
| 1935 | diff -Naur bash-4.3.orig/pcomplete.c bash-4.3/pcomplete.c
|
---|
| 1936 | --- bash-4.3.orig/pcomplete.c 2013-08-26 19:23:45.000000000 +0000
|
---|
| 1937 | +++ bash-4.3/pcomplete.c 2014-09-26 23:58:55.559639918 +0000
|
---|
| 1938 | @@ -183,6 +183,7 @@
|
---|
| 1939 |
|
---|
| 1940 | COMPSPEC *pcomp_curcs;
|
---|
| 1941 | const char *pcomp_curcmd;
|
---|
| 1942 | +const char *pcomp_curtxt;
|
---|
| 1943 |
|
---|
| 1944 | #ifdef DEBUG
|
---|
| 1945 | /* Debugging code */
|
---|
| 1946 | @@ -753,6 +754,32 @@
|
---|
| 1947 | quoted strings. */
|
---|
| 1948 | dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
|
---|
| 1949 | }
|
---|
| 1950 | + /* Intended to solve a mismatched assumption by bash-completion. If
|
---|
| 1951 | + the text to be completed is empty, but bash-completion turns it into
|
---|
| 1952 | + a quoted string ('') assuming that this code will dequote it before
|
---|
| 1953 | + calling readline, do the dequoting. */
|
---|
| 1954 | + else if (iscompgen && iscompleting &&
|
---|
| 1955 | + pcomp_curtxt && *pcomp_curtxt == 0 &&
|
---|
| 1956 | + text && (*text == '\'' || *text == '"') && text[1] == text[0] && text[2] == 0 &&
|
---|
| 1957 | + rl_filename_dequoting_function)
|
---|
| 1958 | + dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
|
---|
| 1959 | + /* Another mismatched assumption by bash-completion. If compgen is being
|
---|
| 1960 | + run as part of bash-completion, and the argument to compgen is not
|
---|
| 1961 | + the same as the word originally passed to the programmable completion
|
---|
| 1962 | + code, dequote the argument if it has quote characters. It's an
|
---|
| 1963 | + attempt to detect when bash-completion is quoting its filename
|
---|
| 1964 | + argument before calling compgen. */
|
---|
| 1965 | + /* We could check whether gen_shell_function_matches is in the call
|
---|
| 1966 | + stack by checking whether the gen-shell-function-matches tag is in
|
---|
| 1967 | + the unwind-protect stack, but there's no function to do that yet.
|
---|
| 1968 | + We could simply check whether we're executing in a function by
|
---|
| 1969 | + checking variable_context, and may end up doing that. */
|
---|
| 1970 | + else if (iscompgen && iscompleting && rl_filename_dequoting_function &&
|
---|
| 1971 | + pcomp_curtxt && text &&
|
---|
| 1972 | + STREQ (pcomp_curtxt, text) == 0 &&
|
---|
| 1973 | + variable_context &&
|
---|
| 1974 | + sh_contains_quotes (text)) /* guess */
|
---|
| 1975 | + dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
|
---|
| 1976 | else
|
---|
| 1977 | dfn = savestring (text);
|
---|
| 1978 | }
|
---|
| 1979 | @@ -1522,7 +1549,7 @@
|
---|
| 1980 | COMPSPEC **lastcs;
|
---|
| 1981 | {
|
---|
| 1982 | COMPSPEC *cs, *oldcs;
|
---|
| 1983 | - const char *oldcmd;
|
---|
| 1984 | + const char *oldcmd, *oldtxt;
|
---|
| 1985 | STRINGLIST *ret;
|
---|
| 1986 |
|
---|
| 1987 | cs = progcomp_search (ocmd);
|
---|
| 1988 | @@ -1545,14 +1572,17 @@
|
---|
| 1989 |
|
---|
| 1990 | oldcs = pcomp_curcs;
|
---|
| 1991 | oldcmd = pcomp_curcmd;
|
---|
| 1992 | + oldtxt = pcomp_curtxt;
|
---|
| 1993 |
|
---|
| 1994 | pcomp_curcs = cs;
|
---|
| 1995 | pcomp_curcmd = cmd;
|
---|
| 1996 | + pcomp_curtxt = word;
|
---|
| 1997 |
|
---|
| 1998 | ret = gen_compspec_completions (cs, cmd, word, start, end, foundp);
|
---|
| 1999 |
|
---|
| 2000 | pcomp_curcs = oldcs;
|
---|
| 2001 | pcomp_curcmd = oldcmd;
|
---|
| 2002 | + pcomp_curtxt = oldtxt;
|
---|
| 2003 |
|
---|
| 2004 | /* We need to conditionally handle setting *retryp here */
|
---|
| 2005 | if (retryp)
|
---|
| 2006 | diff -Naur bash-4.3.orig/shell.h bash-4.3/shell.h
|
---|
| 2007 | --- bash-4.3.orig/shell.h 2012-12-26 02:11:01.000000000 +0000
|
---|
| 2008 | +++ bash-4.3/shell.h 2014-09-26 23:58:55.596306495 +0000
|
---|
| 2009 | @@ -168,7 +168,8 @@
|
---|
| 2010 | /* flags state affecting the parser */
|
---|
| 2011 | int expand_aliases;
|
---|
| 2012 | int echo_input_at_read;
|
---|
| 2013 | -
|
---|
| 2014 | + int need_here_doc;
|
---|
| 2015 | +
|
---|
| 2016 | } sh_parser_state_t;
|
---|
| 2017 |
|
---|
| 2018 | typedef struct _sh_input_line_state_t {
|
---|
| 2019 | diff -Naur bash-4.3.orig/subst.c bash-4.3/subst.c
|
---|
| 2020 | --- bash-4.3.orig/subst.c 2014-01-23 21:26:37.000000000 +0000
|
---|
| 2021 | +++ bash-4.3/subst.c 2014-09-26 23:58:55.629639747 +0000
|
---|
| 2022 | @@ -1192,12 +1192,18 @@
|
---|
| 2023 | Start extracting at (SINDEX) as if we had just seen "<(".
|
---|
| 2024 | Make (SINDEX) get the position of the matching ")". */ /*))*/
|
---|
| 2025 | char *
|
---|
| 2026 | -extract_process_subst (string, starter, sindex)
|
---|
| 2027 | +extract_process_subst (string, starter, sindex, xflags)
|
---|
| 2028 | char *string;
|
---|
| 2029 | char *starter;
|
---|
| 2030 | int *sindex;
|
---|
| 2031 | + int xflags;
|
---|
| 2032 | {
|
---|
| 2033 | +#if 0
|
---|
| 2034 | return (extract_delimited_string (string, sindex, starter, "(", ")", SX_COMMAND));
|
---|
| 2035 | +#else
|
---|
| 2036 | + xflags |= (no_longjmp_on_fatal_error ? SX_NOLONGJMP : 0);
|
---|
| 2037 | + return (xparse_dolparen (string, string+*sindex, sindex, xflags));
|
---|
| 2038 | +#endif
|
---|
| 2039 | }
|
---|
| 2040 | #endif /* PROCESS_SUBSTITUTION */
|
---|
| 2041 |
|
---|
| 2042 | @@ -1785,7 +1791,7 @@
|
---|
| 2043 | si = i + 2;
|
---|
| 2044 | if (string[si] == '\0')
|
---|
| 2045 | CQ_RETURN(si);
|
---|
| 2046 | - temp = extract_process_subst (string, (c == '<') ? "<(" : ">(", &si);
|
---|
| 2047 | + temp = extract_process_subst (string, (c == '<') ? "<(" : ">(", &si, 0);
|
---|
| 2048 | free (temp); /* no SX_ALLOC here */
|
---|
| 2049 | i = si;
|
---|
| 2050 | if (string[i] == '\0')
|
---|
| 2051 | @@ -3248,8 +3254,10 @@
|
---|
| 2052 | if (w->word == 0 || w->word[0] == '\0')
|
---|
| 2053 | return ((char *)NULL);
|
---|
| 2054 |
|
---|
| 2055 | + expand_no_split_dollar_star = 1;
|
---|
| 2056 | w->flags |= W_NOSPLIT2;
|
---|
| 2057 | l = call_expand_word_internal (w, 0, 0, (int *)0, (int *)0);
|
---|
| 2058 | + expand_no_split_dollar_star = 0;
|
---|
| 2059 | if (l)
|
---|
| 2060 | {
|
---|
| 2061 | if (special == 0) /* LHS */
|
---|
| 2062 | @@ -7366,7 +7374,13 @@
|
---|
| 2063 | }
|
---|
| 2064 |
|
---|
| 2065 | if (want_indir)
|
---|
| 2066 | - tdesc = parameter_brace_expand_indir (name + 1, var_is_special, quoted, quoted_dollar_atp, contains_dollar_at);
|
---|
| 2067 | + {
|
---|
| 2068 | + tdesc = parameter_brace_expand_indir (name + 1, var_is_special, quoted, quoted_dollar_atp, contains_dollar_at);
|
---|
| 2069 | + /* Turn off the W_ARRAYIND flag because there is no way for this function
|
---|
| 2070 | + to return the index we're supposed to be using. */
|
---|
| 2071 | + if (tdesc && tdesc->flags)
|
---|
| 2072 | + tdesc->flags &= ~W_ARRAYIND;
|
---|
| 2073 | + }
|
---|
| 2074 | else
|
---|
| 2075 | tdesc = parameter_brace_expand_word (name, var_is_special, quoted, PF_IGNUNBOUND|(pflags&(PF_NOSPLIT2|PF_ASSIGNRHS)), &ind);
|
---|
| 2076 |
|
---|
| 2077 | @@ -7847,6 +7861,10 @@
|
---|
| 2078 | We also want to make sure that splitting is done no matter what --
|
---|
| 2079 | according to POSIX.2, this expands to a list of the positional
|
---|
| 2080 | parameters no matter what IFS is set to. */
|
---|
| 2081 | + /* XXX - what to do when in a context where word splitting is not
|
---|
| 2082 | + performed? Even when IFS is not the default, posix seems to imply
|
---|
| 2083 | + that we behave like unquoted $* ? Maybe we should use PF_NOSPLIT2
|
---|
| 2084 | + here. */
|
---|
| 2085 | temp = string_list_dollar_at (list, (pflags & PF_ASSIGNRHS) ? (quoted|Q_DOUBLE_QUOTES) : quoted);
|
---|
| 2086 |
|
---|
| 2087 | tflag |= W_DOLLARAT;
|
---|
| 2088 | @@ -8029,7 +8047,9 @@
|
---|
| 2089 |
|
---|
| 2090 | goto return0;
|
---|
| 2091 | }
|
---|
| 2092 | - else if (var = find_variable_last_nameref (temp1))
|
---|
| 2093 | + else if (var && (invisible_p (var) || var_isset (var) == 0))
|
---|
| 2094 | + temp = (char *)NULL;
|
---|
| 2095 | + else if ((var = find_variable_last_nameref (temp1)) && var_isset (var) && invisible_p (var) == 0)
|
---|
| 2096 | {
|
---|
| 2097 | temp = nameref_cell (var);
|
---|
| 2098 | #if defined (ARRAY_VARS)
|
---|
| 2099 | @@ -8243,7 +8263,7 @@
|
---|
| 2100 | else
|
---|
| 2101 | t_index = sindex + 1; /* skip past both '<' and LPAREN */
|
---|
| 2102 |
|
---|
| 2103 | - temp1 = extract_process_subst (string, (c == '<') ? "<(" : ">(", &t_index); /*))*/
|
---|
| 2104 | + temp1 = extract_process_subst (string, (c == '<') ? "<(" : ">(", &t_index, 0); /*))*/
|
---|
| 2105 | sindex = t_index;
|
---|
| 2106 |
|
---|
| 2107 | /* If the process substitution specification is `<()', we want to
|
---|
| 2108 | @@ -8816,6 +8836,7 @@
|
---|
| 2109 | else
|
---|
| 2110 | {
|
---|
| 2111 | char *ifs_chars;
|
---|
| 2112 | + char *tstring;
|
---|
| 2113 |
|
---|
| 2114 | ifs_chars = (quoted_dollar_at || has_dollar_at) ? ifs_value : (char *)NULL;
|
---|
| 2115 |
|
---|
| 2116 | @@ -8830,11 +8851,36 @@
|
---|
| 2117 | regardless of what else has happened to IFS since the expansion. */
|
---|
| 2118 | if (split_on_spaces)
|
---|
| 2119 | list = list_string (istring, " ", 1); /* XXX quoted == 1? */
|
---|
| 2120 | + /* If we have $@ (has_dollar_at != 0) and we are in a context where we
|
---|
| 2121 | + don't want to split the result (W_NOSPLIT2), and we are not quoted,
|
---|
| 2122 | + we have already separated the arguments with the first character of
|
---|
| 2123 | + $IFS. In this case, we want to return a list with a single word
|
---|
| 2124 | + with the separator possibly replaced with a space (it's what other
|
---|
| 2125 | + shells seem to do).
|
---|
| 2126 | + quoted_dollar_at is internal to this function and is set if we are
|
---|
| 2127 | + passed an argument that is unquoted (quoted == 0) but we encounter a
|
---|
| 2128 | + double-quoted $@ while expanding it. */
|
---|
| 2129 | + else if (has_dollar_at && quoted_dollar_at == 0 && ifs_chars && quoted == 0 && (word->flags & W_NOSPLIT2))
|
---|
| 2130 | + {
|
---|
| 2131 | + /* Only split and rejoin if we have to */
|
---|
| 2132 | + if (*ifs_chars && *ifs_chars != ' ')
|
---|
| 2133 | + {
|
---|
| 2134 | + list = list_string (istring, *ifs_chars ? ifs_chars : " ", 1);
|
---|
| 2135 | + tstring = string_list (list);
|
---|
| 2136 | + }
|
---|
| 2137 | + else
|
---|
| 2138 | + tstring = istring;
|
---|
| 2139 | + tword = make_bare_word (tstring);
|
---|
| 2140 | + if (tstring != istring)
|
---|
| 2141 | + free (tstring);
|
---|
| 2142 | + goto set_word_flags;
|
---|
| 2143 | + }
|
---|
| 2144 | else if (has_dollar_at && ifs_chars)
|
---|
| 2145 | list = list_string (istring, *ifs_chars ? ifs_chars : " ", 1);
|
---|
| 2146 | else
|
---|
| 2147 | {
|
---|
| 2148 | tword = make_bare_word (istring);
|
---|
| 2149 | +set_word_flags:
|
---|
| 2150 | if ((quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT)) || (quoted_state == WHOLLY_QUOTED))
|
---|
| 2151 | tword->flags |= W_QUOTED;
|
---|
| 2152 | if (word->flags & W_ASSIGNMENT)
|
---|
| 2153 | diff -Naur bash-4.3.orig/subst.h bash-4.3/subst.h
|
---|
| 2154 | --- bash-4.3.orig/subst.h 2014-01-12 02:02:27.000000000 +0000
|
---|
| 2155 | +++ bash-4.3/subst.h 2014-09-26 23:58:55.612973121 +0000
|
---|
| 2156 | @@ -82,7 +82,7 @@
|
---|
| 2157 | /* Extract the <( or >( construct in STRING, and return a new string.
|
---|
| 2158 | Start extracting at (SINDEX) as if we had just seen "<(".
|
---|
| 2159 | Make (SINDEX) get the position just after the matching ")". */
|
---|
| 2160 | -extern char *extract_process_subst __P((char *, char *, int *));
|
---|
| 2161 | +extern char *extract_process_subst __P((char *, char *, int *, int));
|
---|
| 2162 | #endif /* PROCESS_SUBSTITUTION */
|
---|
| 2163 |
|
---|
| 2164 | /* Extract the name of the variable to bind to from the assignment string. */
|
---|
| 2165 | diff -Naur bash-4.3.orig/test.c bash-4.3/test.c
|
---|
| 2166 | --- bash-4.3.orig/test.c 2014-02-04 21:52:58.000000000 +0000
|
---|
| 2167 | +++ bash-4.3/test.c 2014-09-26 23:58:55.506306714 +0000
|
---|
| 2168 | @@ -646,8 +646,8 @@
|
---|
| 2169 | return (v && invisible_p (v) == 0 && var_isset (v) ? TRUE : FALSE);
|
---|
| 2170 |
|
---|
| 2171 | case 'R':
|
---|
| 2172 | - v = find_variable (arg);
|
---|
| 2173 | - return (v && invisible_p (v) == 0 && var_isset (v) && nameref_p (v) ? TRUE : FALSE);
|
---|
| 2174 | + v = find_variable_noref (arg);
|
---|
| 2175 | + return ((v && invisible_p (v) == 0 && var_isset (v) && nameref_p (v)) ? TRUE : FALSE);
|
---|
| 2176 | }
|
---|
| 2177 |
|
---|
| 2178 | /* We can't actually get here, but this shuts up gcc. */
|
---|
| 2179 | @@ -723,6 +723,7 @@
|
---|
| 2180 | case 'o': case 'p': case 'r': case 's': case 't':
|
---|
| 2181 | case 'u': case 'v': case 'w': case 'x': case 'z':
|
---|
| 2182 | case 'G': case 'L': case 'O': case 'S': case 'N':
|
---|
| 2183 | + case 'R':
|
---|
| 2184 | return (1);
|
---|
| 2185 | }
|
---|
| 2186 |
|
---|
| 2187 | diff -Naur bash-4.3.orig/trap.c bash-4.3/trap.c
|
---|
| 2188 | --- bash-4.3.orig/trap.c 2014-02-05 15:03:21.000000000 +0000
|
---|
| 2189 | +++ bash-4.3/trap.c 2014-09-26 23:58:55.509640040 +0000
|
---|
| 2190 | @@ -920,7 +920,8 @@
|
---|
| 2191 | subst_assign_varlist = 0;
|
---|
| 2192 |
|
---|
| 2193 | #if defined (JOB_CONTROL)
|
---|
| 2194 | - save_pipeline (1); /* XXX only provides one save level */
|
---|
| 2195 | + if (sig != DEBUG_TRAP) /* run_debug_trap does this */
|
---|
| 2196 | + save_pipeline (1); /* XXX only provides one save level */
|
---|
| 2197 | #endif
|
---|
| 2198 |
|
---|
| 2199 | /* If we're in a function, make sure return longjmps come here, too. */
|
---|
| 2200 | @@ -940,7 +941,8 @@
|
---|
| 2201 | trap_exit_value = last_command_exit_value;
|
---|
| 2202 |
|
---|
| 2203 | #if defined (JOB_CONTROL)
|
---|
| 2204 | - restore_pipeline (1);
|
---|
| 2205 | + if (sig != DEBUG_TRAP) /* run_debug_trap does this */
|
---|
| 2206 | + restore_pipeline (1);
|
---|
| 2207 | #endif
|
---|
| 2208 |
|
---|
| 2209 | subst_assign_varlist = save_subst_varlist;
|
---|
| 2210 | diff -Naur bash-4.3.orig/variables.c bash-4.3/variables.c
|
---|
| 2211 | --- bash-4.3.orig/variables.c 2014-02-14 16:55:12.000000000 +0000
|
---|
| 2212 | +++ bash-4.3/variables.c 2014-09-26 23:58:55.626306422 +0000
|
---|
| 2213 | @@ -358,13 +358,11 @@
|
---|
| 2214 | temp_string[char_index] = ' ';
|
---|
| 2215 | strcpy (temp_string + char_index + 1, string);
|
---|
| 2216 |
|
---|
| 2217 | - if (posixly_correct == 0 || legal_identifier (name))
|
---|
| 2218 | - parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST);
|
---|
| 2219 | -
|
---|
| 2220 | - /* Ancient backwards compatibility. Old versions of bash exported
|
---|
| 2221 | - functions like name()=() {...} */
|
---|
| 2222 | - if (name[char_index - 1] == ')' && name[char_index - 2] == '(')
|
---|
| 2223 | - name[char_index - 2] = '\0';
|
---|
| 2224 | + /* Don't import function names that are invalid identifiers from the
|
---|
| 2225 | + environment, though we still allow them to be defined as shell
|
---|
| 2226 | + variables. */
|
---|
| 2227 | + if (legal_identifier (name))
|
---|
| 2228 | + parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD);
|
---|
| 2229 |
|
---|
| 2230 | if (temp_var = find_function (name))
|
---|
| 2231 | {
|
---|
| 2232 | @@ -381,10 +379,6 @@
|
---|
| 2233 | last_command_exit_value = 1;
|
---|
| 2234 | report_error (_("error importing function definition for `%s'"), name);
|
---|
| 2235 | }
|
---|
| 2236 | -
|
---|
| 2237 | - /* ( */
|
---|
| 2238 | - if (name[char_index - 1] == ')' && name[char_index - 2] == '\0')
|
---|
| 2239 | - name[char_index - 2] = '('; /* ) */
|
---|
| 2240 | }
|
---|
| 2241 | #if defined (ARRAY_VARS)
|
---|
| 2242 | # if ARRAY_EXPORT
|
---|
| 2243 | @@ -2197,10 +2191,7 @@
|
---|
| 2244 | /* local foo; local foo; is a no-op. */
|
---|
| 2245 | old_var = find_variable (name);
|
---|
| 2246 | if (old_var && local_p (old_var) && old_var->context == variable_context)
|
---|
| 2247 | - {
|
---|
| 2248 | - VUNSETATTR (old_var, att_invisible); /* XXX */
|
---|
| 2249 | - return (old_var);
|
---|
| 2250 | - }
|
---|
| 2251 | + return (old_var);
|
---|
| 2252 |
|
---|
| 2253 | was_tmpvar = old_var && tempvar_p (old_var);
|
---|
| 2254 | /* If we're making a local variable in a shell function, the temporary env
|
---|
| 2255 | diff -Naur bash-4.3.orig/y.tab.c bash-4.3/y.tab.c
|
---|
| 2256 | --- bash-4.3.orig/y.tab.c 2014-02-11 15:57:47.000000000 +0000
|
---|
| 2257 | +++ bash-4.3/y.tab.c 2014-09-26 23:58:55.636306397 +0000
|
---|
| 2258 | @@ -4736,7 +4736,7 @@
|
---|
| 2259 | not already end in an EOF character. */
|
---|
| 2260 | if (shell_input_line_terminator != EOF)
|
---|
| 2261 | {
|
---|
| 2262 | - if (shell_input_line_size < SIZE_MAX && shell_input_line_len > shell_input_line_size - 3)
|
---|
| 2263 | + if (shell_input_line_size < SIZE_MAX-3 && (shell_input_line_len+3 > shell_input_line_size))
|
---|
| 2264 | shell_input_line = (char *)xrealloc (shell_input_line,
|
---|
| 2265 | 1 + (shell_input_line_size += 2));
|
---|
| 2266 |
|
---|
| 2267 | @@ -4954,7 +4954,7 @@
|
---|
| 2268 | int r;
|
---|
| 2269 |
|
---|
| 2270 | r = 0;
|
---|
| 2271 | - while (need_here_doc)
|
---|
| 2272 | + while (need_here_doc > 0)
|
---|
| 2273 | {
|
---|
| 2274 | parser_state |= PST_HEREDOC;
|
---|
| 2275 | make_here_document (redir_stack[r++], line_number);
|
---|
| 2276 | @@ -5265,6 +5265,8 @@
|
---|
| 2277 | FREE (word_desc_to_read);
|
---|
| 2278 | word_desc_to_read = (WORD_DESC *)NULL;
|
---|
| 2279 |
|
---|
| 2280 | + eol_ungetc_lookahead = 0;
|
---|
| 2281 | +
|
---|
| 2282 | current_token = '\n'; /* XXX */
|
---|
| 2283 | last_read_token = '\n';
|
---|
| 2284 | token_to_read = '\n';
|
---|
| 2285 | @@ -5710,7 +5712,7 @@
|
---|
| 2286 | within a double-quoted ${...} construct "an even number of
|
---|
| 2287 | unescaped double-quotes or single-quotes, if any, shall occur." */
|
---|
| 2288 | /* This was changed in Austin Group Interp 221 */
|
---|
| 2289 | - if MBTEST(posixly_correct && shell_compatibility_level > 41 && dolbrace_state != DOLBRACE_QUOTE && (flags & P_DQUOTE) && (flags & P_DOLBRACE) && ch == '\'')
|
---|
| 2290 | + if MBTEST(posixly_correct && shell_compatibility_level > 41 && dolbrace_state != DOLBRACE_QUOTE && dolbrace_state != DOLBRACE_QUOTE2 && (flags & P_DQUOTE) && (flags & P_DOLBRACE) && ch == '\'')
|
---|
| 2291 | continue;
|
---|
| 2292 |
|
---|
| 2293 | /* Could also check open == '`' if we want to parse grouping constructs
|
---|
| 2294 | @@ -8387,6 +8389,7 @@
|
---|
| 2295 |
|
---|
| 2296 | ps->expand_aliases = expand_aliases;
|
---|
| 2297 | ps->echo_input_at_read = echo_input_at_read;
|
---|
| 2298 | + ps->need_here_doc = need_here_doc;
|
---|
| 2299 |
|
---|
| 2300 | ps->token = token;
|
---|
| 2301 | ps->token_buffer_size = token_buffer_size;
|
---|
| 2302 | @@ -8435,6 +8438,7 @@
|
---|
| 2303 |
|
---|
| 2304 | expand_aliases = ps->expand_aliases;
|
---|
| 2305 | echo_input_at_read = ps->echo_input_at_read;
|
---|
| 2306 | + need_here_doc = ps->need_here_doc;
|
---|
| 2307 |
|
---|
| 2308 | FREE (token);
|
---|
| 2309 | token = ps->token;
|
---|
| 2310 | @@ -8537,4 +8541,3 @@
|
---|
| 2311 | }
|
---|
| 2312 | }
|
---|
| 2313 | #endif /* HANDLE_MULTIBYTE */
|
---|
| 2314 | -
|
---|