View | Details | Raw Unified | Return to bug 16603
Collapse All | Expand All

(-)R-devel/src/unix/sys-std.c (+55 lines)
Lines 427-437 Link Here
427
typedef void rl_vcpfunc_t (char *);
427
typedef void rl_vcpfunc_t (char *);
428
#  endif /* _RL_FUNCTION_TYPEDEF */
428
#  endif /* _RL_FUNCTION_TYPEDEF */
429
# else
429
# else
430
/*
431
  I would recommend removing this block. Recent versions of R (at
432
  least since 3.1.3) would not compile without readline.h anyway,
433
  because "rl_readline_name" was missing from the following list of
434
  declarations. If nobody reported that as a bug, it hints that
435
  everyone had readline.h.
436
437
  Trying to work around the presence of readline.h prevents us from
438
  conditioning on RL_READLINE_VERSION.
439
  
440
  Frederick Eaton 02 May 2016
441
 */
430
typedef void rl_vcpfunc_t (char *);
442
typedef void rl_vcpfunc_t (char *);
431
extern void rl_callback_handler_install(const char *, rl_vcpfunc_t *);
443
extern void rl_callback_handler_install(const char *, rl_vcpfunc_t *);
432
extern void rl_callback_handler_remove(void);
444
extern void rl_callback_handler_remove(void);
433
extern void rl_callback_read_char(void);
445
extern void rl_callback_read_char(void);
434
extern char *tilde_expand (const char *);
446
extern char *tilde_expand (const char *);
447
extern const char *rl_readline_name;
448
extern void rl_free_line_state (void);
449
extern void rl_cleanup_after_signal (void);
450
#define RL_UNSETSTATE(x)	(rl_readline_state &= ~(x))
451
extern char *rl_line_buffer;
452
extern unsigned long rl_readline_state;
453
#define RL_STATE_ISEARCH	0x0000080	/* doing incremental search */
454
#define RL_STATE_NSEARCH	0x0000100	/* doing non-inc search */
455
#define RL_STATE_VIMOTION	0x0100000	/* reading vi motion arg */
456
#define RL_STATE_NUMERICARG	0x0000400	/* reading numeric argument */
457
#define RL_STATE_MULTIKEY	0x0200000	/* reading multiple-key command */
458
extern int rl_point;
459
extern int rl_end;
460
extern int rl_mark;
435
# endif
461
# endif
436
462
437
attribute_hidden
463
attribute_hidden
Lines 529-540 Link Here
529
}
555
}
530
556
531
/*
557
/*
558
  This function was created to fix the incremental-search-SIGINT bug,
559
  https://bugs.r-project.org/bugzilla/show_bug.cgi?id=16603
560
561
  The Readline interface is somewhat messy. Readline contains the
562
  function rl_free_line_state(), which its internal SIGINT handler
563
  calls. However, rl_free_line_state only cancels keyboard macros and
564
  certain other things. It does not clear the line. Also, Readline's
565
  SIGINT handler is no longer triggered during our select() loop since
566
  rl_callback_handler_install() no longer installs signal handlers as
567
  of Readline 6.3. So we have to catch the signal and do all the work
568
  ourselves to get Bash-like behavior on ^C. If Readline ever moves to
569
  a cleaner interface, we should clean this up too.
570
 */
571
static void resetReadline(void)
572
{
573
    rl_free_line_state ();
574
#if defined(RL_READLINE_VERSION) && RL_READLINE_VERSION >= 0x0700
575
    rl_callback_sigcleanup();
576
#endif
577
    rl_cleanup_after_signal ();
578
    RL_UNSETSTATE(RL_STATE_ISEARCH|RL_STATE_NSEARCH|RL_STATE_VIMOTION|RL_STATE_NUMERICARG|RL_STATE_MULTIKEY);
579
    /* The following two lines should be equivalent, but doing both
580
       won't hurt: */
581
    rl_line_buffer[rl_point = rl_end = rl_mark = 0] = 0;
582
    rl_done = 1;
583
}
584
585
/*
532
  Unregister the current readline handler and pop it from R's readline
586
  Unregister the current readline handler and pop it from R's readline
533
  stack, followed by re-registering the previous one.
587
  stack, followed by re-registering the previous one.
534
*/
588
*/
535
static void popReadline(void)
589
static void popReadline(void)
536
{
590
{
537
  if(ReadlineStack.current > -1) {
591
  if(ReadlineStack.current > -1) {
592
     resetReadline();
538
     rl_callback_handler_remove();
593
     rl_callback_handler_remove();
539
     ReadlineStack.fun[ReadlineStack.current--] = NULL;
594
     ReadlineStack.fun[ReadlineStack.current--] = NULL;
540
     if(ReadlineStack.current > -1 && ReadlineStack.fun[ReadlineStack.current])
595
     if(ReadlineStack.current > -1 && ReadlineStack.fun[ReadlineStack.current])

Return to bug 16603