poke-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] Deal with --mi a little better.


From: Jose E. Marchesi
Subject: Re: [PATCH] Deal with --mi a little better.
Date: Sun, 10 May 2020 19:10:10 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hi John.

    This change reduces the number of conditional compilation switches
    to 1.   Doing so makes the code easier to understand (in my opinion),
    conforms better to GNU Coding Standards, and reduces the probability
    of bugs getting introduced which are hard to detect.

I like this approach.
OK for master.
Thanks!


    ---
     poke/poke.c | 33 ++++++++++++++++++++++-----------
     1 file changed, 22 insertions(+), 11 deletions(-)
    
    diff --git a/poke/poke.c b/poke/poke.c
    index 97608f52..cb7b82ec 100644
    --- a/poke/poke.c
    +++ b/poke/poke.c
    @@ -26,6 +26,7 @@
     #include <locale.h>
     #include <textstyle.h>
     #include "xalloc.h"
    +#include <assert.h>
     
     #ifdef HAVE_HSERVER
     #  include "pk-hserver.h"
    @@ -49,9 +50,17 @@ int poke_hserver_p;
     #endif
     
     /* The following global indicates whether the MI shall be used.  */
    -
     int poke_mi_p;
     
    +#ifdef POKE_MI
    +/* This build of poke supports mi if the user wants it.  */
    +static const int mi_supported_p = 1;
    +#else
    +/* This build of poke does not support mi.  */
    +static const int mi_supported_p = 0;
    +int pk_mi (void) {assert (0); return 0;}
    +#endif
    +
     /* The following global indicates whether poke should be as terse as
        possible in its output.  This is useful when running poke from
        other programs.  */
    @@ -284,11 +293,18 @@ parse_args_1 (int argc, char *argv[])
           c = ret;
           switch (c)
             {
    -#ifdef POKE_MI
             case MI_ARG:
    -          poke_mi_p = 1;
    +     if (!mi_supported_p)
    +       {
    +         fputs (_("MI is not built into this instance of poke\n"),
    +                stderr);
    +         exit (EXIT_FAILURE);
    +       }
    +     else
    +       {
    +         poke_mi_p = 1;
    +       }
               break;
    -#endif
             default:
               break;
             }
    @@ -351,11 +367,9 @@ parse_args_2 (int argc, char *argv[])
               /* -L is handled below.  */
             case 'L':
               break;
    -#ifdef POKE_MI
             case MI_ARG:
               /* These are handled in parse_args_1.  */
               break;
    -#endif
               /* libtextstyle arguments are handled in pk-term.c, not
                  here.   */
             case COLOR_ARG:
    @@ -572,16 +586,13 @@ main (int argc, char *argv[])
         initialize_user ();
     
       /* Enter the REPL or MI.  */
    -#ifdef POKE_MI
       if (poke_mi_p)
         {
           if (!pk_mi ())
             poke_exit_code = EXIT_FAILURE;
         }
    -  else
    -#endif
    -    if (poke_interactive_p)
    -      pk_repl ();
    +  else if (poke_interactive_p)
    +    pk_repl ();
     
       /* Cleanup.  */
       finalize ();



reply via email to

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