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