poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] poke: disable termios and sigaction code on Windows


From: Jose E. Marchesi
Subject: Re: [PATCH] poke: disable termios and sigaction code on Windows
Date: Wed, 15 Feb 2023 22:04:51 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Hi Hannes.

Thanks for the patch.

I am wondering, if these facilities are commented out, what happens in
Windows when:

1) You are in the (poke) prompt and you press Ctrl-C
2) You execute `while (1);' from the prompt, then you press Ctrl-C

?

> 2023-02-15  Hannes Domani  <ssbssa@yahoo.de>
>
>       * poke/pk-repl.c: Disable sigaction code on Windows.
>       * poke/pk-term.c: Disable termios code on Windows.
> ---
>  poke/pk-repl.c | 10 ++++++++++
>  poke/pk-term.c |  6 ++++++
>  2 files changed, 16 insertions(+)
>
> diff --git a/poke/pk-repl.c b/poke/pk-repl.c
> index 4f4413ed..4cf20fe0 100644
> --- a/poke/pk-repl.c
> +++ b/poke/pk-repl.c
> @@ -39,6 +39,7 @@
>  #include "pk-utils.h"
>  #include "pk-map.h"
>  
> +#if ! defined _WIN32 || defined __CYGWIN__
>  /* The thread that contains the non-local entry point for reentering
>     the REPL.  */
>  static pthread_t volatile ctrlc_thread;
> @@ -46,6 +47,7 @@ static pthread_t volatile ctrlc_thread;
>  static sigjmp_buf /*volatile*/ ctrlc_buf;
>  /* When nonzero, ctrlc_thread and ctrlc_buf contain valid values.  */
>  static int volatile ctrlc_buf_valid;
> +#endif
>  
>  /* This function is called repeatedly by the readline library, when
>     generating potential command line completions.
> @@ -210,6 +212,7 @@ banner (void)
>  
>  }
>  
> +#if ! defined _WIN32 || defined __CYGWIN__
>  static _GL_ASYNC_SAFE void
>  poke_sigint_handler (int sig)
>  {
> @@ -253,6 +256,7 @@ poke_sigint_handler (int sig)
>        raise (SIGINT);
>      }
>  }
> +#endif
>  
>  /* Return a copy of TEXT, with every instance of the space character
>     prepended with the backslash character.   The caller is responsible
> @@ -333,6 +337,7 @@ pk_repl (void)
>    /* Let the inputrc parser know who we are.  */
>    rl_readline_name = "gnupoke";
>  
> +#if ! defined _WIN32 || defined __CYGWIN__
>    /* Arrange for the current line to be cancelled on SIGINT.
>       Since some library code is also interested in SIGINT
>       (GNU libtextstyle, via gnulib module fatal-signal), it is better
> @@ -344,6 +349,7 @@ pk_repl (void)
>    sa.sa_flags = 0;
>    sigemptyset (&sa.sa_mask);
>    sigaction (SIGINT, &sa, NULL);
> +#endif
>  
>  #if defined HAVE_READLINE_HISTORY_H
>    char *poke_history = NULL;
> @@ -367,9 +373,11 @@ pk_repl (void)
>    rl_filename_quote_characters = " ";
>    rl_filename_quoting_function = escape_metacharacters;
>  
> +#if ! defined _WIN32 || defined __CYGWIN__
>    ctrlc_thread = pthread_self ();
>    sigsetjmp (ctrlc_buf, 1);
>    ctrlc_buf_valid = 1;
> +#endif
>  
>    while (!poke_exit_p)
>      {
> @@ -418,7 +426,9 @@ pk_repl (void)
>    }
>  #endif
>  
> +#if ! defined _WIN32 || defined __CYGWIN__
>    ctrlc_buf_valid = 0;
> +#endif
>  }
>  
>  static int saved_point;
> diff --git a/poke/pk-term.c b/poke/pk-term.c
> index 71d33ac8..039cfa10 100644
> --- a/poke/pk-term.c
> +++ b/poke/pk-term.c
> @@ -407,14 +407,17 @@ pk_puts_paged (const char *lines)
>  
>      if (nlines >= screen_lines)
>        {
> +#if ! defined _WIN32 || defined __CYGWIN__
>          struct termios old_termios;
>          struct termios new_termios;
> +#endif
>  
>          styled_ostream_begin_use_class (pk_ostream, "pager-more");
>          ostream_write_str (pk_ostream, "--More--");
>          styled_ostream_end_use_class (pk_ostream, "pager-more");
>          ostream_flush (pk_ostream, FLUSH_THIS_STREAM);
>  
> +#if ! defined _WIN32 || defined __CYGWIN__
>          /* Set stdin in non-buffered mode.  */
>          tcgetattr (0, &old_termios);
>          memcpy (&new_termios, &old_termios, sizeof (struct termios));
> @@ -422,6 +425,7 @@ pk_puts_paged (const char *lines)
>          new_termios.c_cc[VTIME] = 0;
>          new_termios.c_cc[VMIN] = 1;
>          tcsetattr (0, TCSANOW, &new_termios);
> +#endif
>  
>          /* Wait for a key and process it.  */
>          while (1)
> @@ -448,8 +452,10 @@ pk_puts_paged (const char *lines)
>              fprintf (stderr, "\007");
>            }
>  
> +#if ! defined _WIN32 || defined __CYGWIN__
>          /* Restore stdin to buffered-mode.  */
>          tcsetattr (0, TCSANOW, &old_termios);
> +#endif
>  
>          if (erase_line_str)
>            {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]