poke-devel
[Top][All Lists]
Advanced

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

Re: [PATCH v2] libpoke,poke,poked,pokefmt: add `pk_compiler' to terminal


From: Jose E. Marchesi
Subject: Re: [PATCH v2] libpoke,poke,poked,pokefmt: add `pk_compiler' to terminal interface
Date: Tue, 21 Nov 2023 02:44:27 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Wouldn't it be better to use gnulib's MAYBE_UNUSED?

Other than that, OK.
Thanks for working on this boring stuff :)

> This commit adds `pk_compiler' as the first parameter to all terminal
> interface functions.  In conjunction with `pk_{s,g}et_user_data'
> functions, users can share the same set of terminal interface functions
> in different compiler instances.
>
> 2023-11-18  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
>
>       * libpoke/libpoke.h (struct pk_term_if): Add `pk_compiler' parameter
>       to all function pointers.
>       * libpoke/libpoke.c (include "libpoke.h"): Move to the top.
>       (libpoke_term_if): Change the type to `struct pk_term_if_internal'.
>       (pk_compiler_new_with_flags): Populate `libpoke_term_if'.
>       * libpoke/pkt.h (PKT_IF): New macro to convey the terminal interface
>       function pointers.
>       (PK_PKC): New macro to convey the instance of current incremental
>       compiler.
>       (pk_*): Re-write the macro definitions to new paradigm.
>       (struct pk_term_if_internal): New data type.
>       (libpoke_term_if): Change the type of the variable.
>       * poke/pk-term.h (pk_puts): Define as a macro.
>       (pk_term_indent): Likewise.
>       (pk_term_class): Likewise.
>       (pk_term_end_class): Likewise.
>       (pk_term_hyperlink): Likewise.
>       (pk_term_end_hyperlink): Likewise.
>       (pk_term_get_color): Likewise.
>       (pk_term_get_bgcolor): Likewise.
>       (pk_term_set_color): Likewise.
>       (pk_term_set_bgcolor): Likewise.
>       (pk_term_flush_1): New terminal interface function with `pk_compiler'
>       parameter.
>       (pk_puts_1): Likewise.
>       (pk_printf_1): Likewise.
>       (pk_term_indent_1): Likewise.
>       (pk_term_class_1): Likewise.
>       (pk_term_end_class_1): Likewise.
>       (pk_term_hyperlink_1): Likewise.
>       (pk_term_end_hyperlink_1): Likewise.
>       (pk_term_get_color_1): Likewise.
>       (pk_term_get_bgcolor_1): Likewise.
>       (pk_term_set_color_1): Likewise.
>       (pk_term_set_bgcolor_1): Likewise.
>       * poke/pk-term.c (pk_term_flush_1): Likewise.
>       (pk_puts_1): Likewise.
>       (pk_printf_1): Likewise.
>       (pk_term_indent_1): Likewise.
>       (pk_term_class_1): Likewise.
>       (pk_term_end_class_1): Likewise.
>       (pk_term_hyperlink_1): Likewise.
>       (pk_term_end_hyperlink_1): Likewise.
>       (pk_term_get_color_1): Likewise.
>       (pk_term_get_bgcolor_1): Likewise.
>       (pk_term_set_color_1): Likewise.
>       (pk_term_set_bgcolor_1): Likewise.
>       (pk_term_flush_1): Likewise.
>       (pk_puts): Remove.
>       (pk_term_indent): Likewise.
>       (pk_term_class): Likewise.
>       (pk_term_end_class): Likewise.
>       (pk_term_hyperlink): Likewise.
>       (pk_term_end_hyperlink): Likewise.
>       (pk_term_get_color): Likewise.
>       (pk_term_get_bgcolor): Likewise.
>       (pk_term_set_color): Likewise.
>       (pk_term_set_bgcolor): Likewise.
>       * poked/poked.c (tif_flush): Add `pk_compiler' parameter.
>       (tif_puts): Likewise.
>       (tif_printf): Likewise.
>       (tif_indent): Likewise.
>       (tif_class): Likewise.
>       (tif_class_end): Likewise.
>       (tif_hlink): Likewise.
>       (tif_hlink_end): Likewise.
>       (tif_color): Likewise.
>       (tif_bgcolor): Likewise.
>       (tif_color_set): Likewise.
>       (tif_bgcolor_set): Likewise.
>       * pokefmt/pokefmt.l (tif_flush): Likewise.
>       (tif_puts): Likewise.
>       (tif_printf): Likewise.
>       (tif_indent): Likewise.
>       (tif_class): Likewise.
>       (tif_class_end): Likewise.
>       (tif_hlink): Likewise.
>       (tif_hlink_end): Likewise.
>       (tif_color): Likewise.
>       (tif_bgcolor): Likewise.
>       (tif_color_set): Likewise.
>       (tif_bgcolor_set): Likewise.
>       * testsutie/poke.libpoke/term-if.h (pk_term_flush): Likewise.
>       (pk_puts): Likewise.
>       (pk_printf): Likewise.
>       (pk_term_indent): Likewise.
>       (pk_term_class): Likewise.
>       (pk_term_end_class): Likewise.
>       (pk_term_hyperlink): Likewise.
>       (pk_term_end_hyperlink): Likewise.
>       (pk_term_get_color): Likewise.
>       (pk_term_get_bgcolor): Likewise.
>       (pk_term_set_color): Likewise.
>       (pk_term_set_bgcolor): Likewise.
> ---
>
> Hi Jose.
>
> On Mon, Nov 20, 2023 at 02:10:32PM +0100, Jose E. Marchesi wrote:
>> 
>> > On Sun, Nov 19, 2023 at 02:36:56AM +0100, Mohammad-Reza Nabipoor wrote:
>> >> > Hmm, the functions pk_printf and friends are defined by the poke app.
>> >> > 
>> >> > What about having pk_printf_1 versions that get the pk_compiler
>> >> > argument, and also the pk_printf versions that use the global
>> >> > poke_compiler?  We can then register the _1 variants in libpoke while
>> >> > continuing the shorter versions in the app.
>> >> 
>> >> 
>> >> Very good idea.
>> >> Implemented.
>> >
>> >
>> > We could also use macros in `poke/pk-term.h' which is even better.
>> > WDYT?
>> 
>> Can you elaborate?
>> 
>
> This patch is the elaboration :)
> Now you can choose between these two patches.
>
>
> Regards,
> Mohammad-Reza
>
>
>  ChangeLog                        | 97 ++++++++++++++++++++++++++++++++
>  libpoke/libpoke.c                |  7 ++-
>  libpoke/libpoke.h                | 24 ++++----
>  libpoke/pkt.h                    | 46 +++++++++------
>  poke/pk-term.c                   | 36 ++++++------
>  poke/pk-term.h                   | 46 ++++++++++-----
>  poke/poke.c                      | 24 ++++----
>  poked/poked.c                    | 26 +++++----
>  pokefmt/pokefmt.l                | 26 +++++----
>  testsuite/poke.libpoke/term-if.h | 36 ++++++------
>  10 files changed, 251 insertions(+), 117 deletions(-)
>
> diff --git a/ChangeLog b/ChangeLog
> index cc2aad80..2dea6cca 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,100 @@
> +2023-11-18  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
> +
> +     * libpoke/libpoke.h (struct pk_term_if): Add `pk_compiler' parameter
> +     to all function pointers.
> +     * libpoke/libpoke.c (include "libpoke.h"): Move to the top.
> +     (libpoke_term_if): Change the type to `struct pk_term_if_internal'.
> +     (pk_compiler_new_with_flags): Populate `libpoke_term_if'.
> +     * libpoke/pkt.h (PKT_IF): New macro to convey the terminal interface
> +     function pointers.
> +     (PK_PKC): New macro to convey the instance of current incremental
> +     compiler.
> +     (pk_*): Re-write the macro definitions to new paradigm.
> +     (struct pk_term_if_internal): New data type.
> +     (libpoke_term_if): Change the type of the variable.
> +     * poke/pk-term.h (pk_puts): Define as a macro.
> +     (pk_term_indent): Likewise.
> +     (pk_term_class): Likewise.
> +     (pk_term_end_class): Likewise.
> +     (pk_term_hyperlink): Likewise.
> +     (pk_term_end_hyperlink): Likewise.
> +     (pk_term_get_color): Likewise.
> +     (pk_term_get_bgcolor): Likewise.
> +     (pk_term_set_color): Likewise.
> +     (pk_term_set_bgcolor): Likewise.
> +     (pk_term_flush_1): New terminal interface function with `pk_compiler'
> +     parameter.
> +     (pk_puts_1): Likewise.
> +     (pk_printf_1): Likewise.
> +     (pk_term_indent_1): Likewise.
> +     (pk_term_class_1): Likewise.
> +     (pk_term_end_class_1): Likewise.
> +     (pk_term_hyperlink_1): Likewise.
> +     (pk_term_end_hyperlink_1): Likewise.
> +     (pk_term_get_color_1): Likewise.
> +     (pk_term_get_bgcolor_1): Likewise.
> +     (pk_term_set_color_1): Likewise.
> +     (pk_term_set_bgcolor_1): Likewise.
> +     * poke/pk-term.c (pk_term_flush_1): Likewise.
> +     (pk_puts_1): Likewise.
> +     (pk_printf_1): Likewise.
> +     (pk_term_indent_1): Likewise.
> +     (pk_term_class_1): Likewise.
> +     (pk_term_end_class_1): Likewise.
> +     (pk_term_hyperlink_1): Likewise.
> +     (pk_term_end_hyperlink_1): Likewise.
> +     (pk_term_get_color_1): Likewise.
> +     (pk_term_get_bgcolor_1): Likewise.
> +     (pk_term_set_color_1): Likewise.
> +     (pk_term_set_bgcolor_1): Likewise.
> +     (pk_term_flush_1): Likewise.
> +     (pk_puts): Remove.
> +     (pk_term_indent): Likewise.
> +     (pk_term_class): Likewise.
> +     (pk_term_end_class): Likewise.
> +     (pk_term_hyperlink): Likewise.
> +     (pk_term_end_hyperlink): Likewise.
> +     (pk_term_get_color): Likewise.
> +     (pk_term_get_bgcolor): Likewise.
> +     (pk_term_set_color): Likewise.
> +     (pk_term_set_bgcolor): Likewise.
> +     * poked/poked.c (tif_flush): Add `pk_compiler' parameter.
> +     (tif_puts): Likewise.
> +     (tif_printf): Likewise.
> +     (tif_indent): Likewise.
> +     (tif_class): Likewise.
> +     (tif_class_end): Likewise.
> +     (tif_hlink): Likewise.
> +     (tif_hlink_end): Likewise.
> +     (tif_color): Likewise.
> +     (tif_bgcolor): Likewise.
> +     (tif_color_set): Likewise.
> +     (tif_bgcolor_set): Likewise.
> +     * pokefmt/pokefmt.l (tif_flush): Likewise.
> +     (tif_puts): Likewise.
> +     (tif_printf): Likewise.
> +     (tif_indent): Likewise.
> +     (tif_class): Likewise.
> +     (tif_class_end): Likewise.
> +     (tif_hlink): Likewise.
> +     (tif_hlink_end): Likewise.
> +     (tif_color): Likewise.
> +     (tif_bgcolor): Likewise.
> +     (tif_color_set): Likewise.
> +     (tif_bgcolor_set): Likewise.
> +     * testsutie/poke.libpoke/term-if.h (pk_term_flush): Likewise.
> +     (pk_puts): Likewise.
> +     (pk_printf): Likewise.
> +     (pk_term_indent): Likewise.
> +     (pk_term_class): Likewise.
> +     (pk_term_end_class): Likewise.
> +     (pk_term_hyperlink): Likewise.
> +     (pk_term_end_hyperlink): Likewise.
> +     (pk_term_get_color): Likewise.
> +     (pk_term_get_bgcolor): Likewise.
> +     (pk_term_set_color): Likewise.
> +     (pk_term_set_bgcolor): Likewise.
> +
>  2023-11-18  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
>  
>       * common/pk-utils.h (PK_INTEGRAL_SUFFIX): New macro.
> diff --git a/libpoke/libpoke.c b/libpoke/libpoke.c
> index f1d896ae..5b58becb 100644
> --- a/libpoke/libpoke.c
> +++ b/libpoke/libpoke.c
> @@ -21,6 +21,7 @@
>  #include <string.h>
>  #include <stdlib.h>
>  
> +#include "libpoke.h"
>  #include "pk-utils.h"
>  #include "pkt.h"
>  #include "pkl.h"
> @@ -28,7 +29,6 @@
>  #include "pkl-env.h" /* XXX */
>  #include "pvm.h"
>  #include "pvm-val.h" /* XXX */
> -#include "libpoke.h"
>  #include "ios-dev.h" /* for struct ios_dev_if */
>  #include "configmake.h"
>  
> @@ -47,7 +47,7 @@ struct _pk_compiler
>    void *user_data;
>  };
>  
> -struct pk_term_if libpoke_term_if;
> +struct pk_term_if_internal libpoke_term_if;
>  
>  #define PK_RETURN(code) do { return pkc->status = (code); } while (0)
>  
> @@ -84,7 +84,8 @@ pk_compiler_new_with_flags (struct pk_term_if *term_if, 
> uint32_t flags)
>        if (libpoke_datadir == NULL)
>          libpoke_datadir = PKGDATADIR;
>  
> -      libpoke_term_if = *term_if;
> +      libpoke_term_if.term_if = *term_if;
> +      libpoke_term_if.pkc = pkc;
>  
>        pkc->vm = pvm_init ();
>        if (pkc->vm == NULL)
> diff --git a/libpoke/libpoke.h b/libpoke/libpoke.h
> index 0085b8e3..acced2e3 100644
> --- a/libpoke/libpoke.h
> +++ b/libpoke/libpoke.h
> @@ -83,46 +83,46 @@ struct pk_color
>  struct pk_term_if
>  {
>    /* Flush the output in the terminal.  */
> -  void (*flush_fn) (void);
> +  void (*flush_fn) (pk_compiler pkc);
>  
>    /* Output a NULL-terminated C string.  */
> -  void (*puts_fn) (const char *str);
> +  void (*puts_fn) (pk_compiler pkc, const char *str);
>  
>    /* Output a formatted string.  */
> -  void (*printf_fn) (const char *format, ...);
> +  void (*printf_fn) (pk_compiler pkc, const char *format, ...);
>  
>    /* Output LVL levels of indentation, using STEP white chars in each
>       indentation level.  */
> -  void (*indent_fn) (unsigned int lvl, unsigned int step);
> +  void (*indent_fn) (pk_compiler pkc, unsigned int lvl, unsigned int step);
>  
>    /* Mark the beginning of a styling class with name CLASS.  */
> -  void (*class_fn) (const char *aclass);
> +  void (*class_fn) (pk_compiler pkc, const char *aclass);
>  
>    /* Mark the end of a styling class with name CLASS.  This function
>       returns 0 if the given class is not active and therefore can't be
>       ended.  1 otherwise.  */
> -  int (*end_class_fn) (const char *aclass);
> +  int (*end_class_fn) (pk_compiler pkc, const char *aclass);
>  
>    /* Mark the beginning of an hyperlink with url URL and identifier
>       ID.  The identifier can be NULL.  */
> -  void (*hyperlink_fn) (const char *url, const char *id);
> +  void (*hyperlink_fn) (pk_compiler pkc, const char *url, const char *id);
>  
>    /* Mark the end of the current hyperlink.  This function returns 0
>       if there is no currently an hyperlink open to close.  1
>       otherwise.  */
> -  int (*end_hyperlink_fn) (void);
> +  int (*end_hyperlink_fn) (pk_compiler pkc);
>  
>    /* Get the current foreground color.  */
> -  struct pk_color (*get_color_fn) (void);
> +  struct pk_color (*get_color_fn) (pk_compiler pkc);
>  
>    /* Get the current background color.  */
> -  struct pk_color (*get_bgcolor_fn) (void);
> +  struct pk_color (*get_bgcolor_fn) (pk_compiler pkc);
>  
>    /* Set the foreground color.  */
> -  void (*set_color_fn) (struct pk_color color);
> +  void (*set_color_fn) (pk_compiler pkc, struct pk_color color);
>  
>    /* Set the background color.  */
> -  void (*set_bgcolor_fn) (struct pk_color color);
> +  void (*set_bgcolor_fn) (pk_compiler pkc, struct pk_color color);
>  };
>  
>  /* Create and return a new Poke incremental compiler.
> diff --git a/libpoke/pkt.h b/libpoke/pkt.h
> index 5be77f68..ac49ba29 100644
> --- a/libpoke/pkt.h
> +++ b/libpoke/pkt.h
> @@ -21,21 +21,35 @@
>  
>  #include <config.h>
>  
> -#include "libpoke.h"  /* For struct pk_term_if */
> -
> -extern struct pk_term_if libpoke_term_if;
> -
> -#define pk_puts libpoke_term_if.puts_fn
> -#define pk_printf libpoke_term_if.printf_fn
> -#define pk_term_flush libpoke_term_if.flush_fn
> -#define pk_term_indent libpoke_term_if.indent_fn
> -#define pk_term_class libpoke_term_if.class_fn
> -#define pk_term_end_class libpoke_term_if.end_class_fn
> -#define pk_term_hyperlink libpoke_term_if.hyperlink_fn
> -#define pk_term_end_hyperlink libpoke_term_if.end_hyperlink_fn
> -#define pk_term_get_color libpoke_term_if.get_color_fn
> -#define pk_term_set_color libpoke_term_if.set_color_fn
> -#define pk_term_get_bgcolor libpoke_term_if.get_bgcolor_fn
> -#define pk_term_set_bgcolor libpoke_term_if.set_bgcolor_fn
> +#include "libpoke.h"  /* For struct pk_term_if, pk_compiler.  */
> +
> +struct pk_term_if_internal
> +{
> +  struct pk_term_if term_if;
> +  pk_compiler pkc;
> +};
> +
> +extern struct pk_term_if_internal libpoke_term_if;
> +
> +#define PKT_IF (&libpoke_term_if.term_if)
> +#define PKT_PKC (libpoke_term_if.pkc)
> +
> +/* Terminal interface for Poke compiler.  */
> +
> +#define pk_puts(STR) (PKT_IF)->puts_fn ((PKT_PKC), (STR))
> +#define pk_printf(...) (PKT_IF)->printf_fn ((PKT_PKC), __VA_ARGS__)
> +#define pk_term_flush() (PKT_IF)->flush_fn (PKT_PKC)
> +#define pk_term_indent(LVL, STEP)                                            
>  \
> +  (PKT_IF)->indent_fn ((PKT_PKC), (LVL), (STEP))
> +#define pk_term_class(CLS) (PKT_IF)->class_fn ((PKT_PKC), (CLS))
> +#define pk_term_end_class(CLS) (PKT_IF)->end_class_fn ((PKT_PKC), (CLS))
> +#define pk_term_hyperlink(URL, ID)                                           
>  \
> +  (PKT_IF)->hyperlink_fn ((PKT_PKC), (URL), ID)
> +#define pk_term_end_hyperlink() (PKT_IF)->end_hyperlink_fn (PKT_PKC)
> +#define pk_term_get_color() (PKT_IF)->get_color_fn (PKT_PKC)
> +#define pk_term_set_color(COLOR) (PKT_IF)->set_color_fn ((PKT_PKC), (COLOR))
> +#define pk_term_get_bgcolor() (PKT_IF)->get_bgcolor_fn (PKT_PKC)
> +#define pk_term_set_bgcolor(COLOR)                                           
>  \
> +  (PKT_IF)->set_bgcolor_fn ((PKT_PKC), (COLOR))
>  
>  #endif /* ! PKT_H */
> diff --git a/poke/pk-term.c b/poke/pk-term.c
> index 71f83a7a..7c410792 100644
> --- a/poke/pk-term.c
> +++ b/poke/pk-term.c
> @@ -364,12 +364,11 @@ pk_term_shutdown ()
>  }
>  
>  void
> -pk_term_flush ()
> +pk_term_flush_1 (pk_compiler pkc __attribute__ ((unused)))
>  {
>    ostream_flush (pk_ostream, FLUSH_THIS_STREAM);
>  }
>  
> -
>  void
>  pk_term_start_pager (void)
>  {
> @@ -470,7 +469,7 @@ pk_puts_paged (const char *lines)
>  }
>  
>  void
> -pk_puts (const char *str)
> +pk_puts_1 (pk_compiler pkc __attribute__ ((unused)), const char *str)
>  {
>    if (pager_active_p)
>      pk_puts_paged (str);
> @@ -478,9 +477,9 @@ pk_puts (const char *str)
>      ostream_write_str (pk_ostream, str);
>  }
>  
> -__attribute__ ((__format__ (__printf__, 1, 2)))
> +__attribute__ ((__format__ (__printf__, 2, 3)))
>  void
> -pk_printf (const char *format, ...)
> +pk_printf_1 (pk_compiler pkc, const char *format, ...)
>  {
>    va_list ap;
>    char *str;
> @@ -491,7 +490,7 @@ pk_printf (const char *format, ...)
>    assert (r != -1);
>    va_end (ap);
>  
> -  pk_puts (str);
> +  pk_puts_1 (pkc, str);
>    free (str);
>  }
>  
> @@ -508,23 +507,21 @@ pk_vprintf (const char *format, va_list ap)
>    free (str);
>  }
>  
> -
>  void
> -pk_term_indent (unsigned int lvl,
> -                unsigned int step)
> +pk_term_indent_1 (pk_compiler pkc, unsigned int lvl, unsigned int step)
>  {
> -  pk_printf ("\n%*s", (step * lvl), "");
> +  pk_printf_1 (pkc, "\n%*s", (step * lvl), "");
>  }
>  
>  void
> -pk_term_class (const char *class)
> +pk_term_class_1 (pk_compiler pkc __attribute__ ((unused)), const char *class)
>  {
>    styled_ostream_begin_use_class (pk_ostream, class);
>    push_active_class (class);
>  }
>  
>  int
> -pk_term_end_class (const char *class)
> +pk_term_end_class_1 (pk_compiler pkc __attribute__ ((unused)), const char 
> *class)
>  {
>    if (!pop_active_class (class))
>      return 0;
> @@ -537,7 +534,8 @@ pk_term_end_class (const char *class)
>  static int hlcount = 0;
>  
>  void
> -pk_term_hyperlink (const char *url, const char *id)
> +pk_term_hyperlink_1 (pk_compiler pkc __attribute__ ((unused)),
> +                     const char *url, const char *id)
>  {
>  #ifdef HAVE_TEXTSTYLE_HYPERLINK_SUPPORT
>    styled_ostream_set_hyperlink (pk_ostream, url, id);
> @@ -546,7 +544,7 @@ pk_term_hyperlink (const char *url, const char *id)
>  }
>  
>  int
> -pk_term_end_hyperlink (void)
> +pk_term_end_hyperlink_1 (pk_compiler pkc __attribute__ ((unused)))
>  {
>  #ifdef HAVE_TEXTSTYLE_HYPERLINK_SUPPORT
>    if (hlcount == 0)
> @@ -568,7 +566,7 @@ pk_term_color_p (void)
>  }
>  
>  struct pk_color
> -pk_term_get_color (void)
> +pk_term_get_color_1 (pk_compiler pkc __attribute__ ((unused)))
>  {
>  #if defined HAVE_TEXTSTYLE_ACCESSORS_SUPPORT
>     if (color_mode != color_html
> @@ -591,7 +589,7 @@ pk_term_get_color (void)
>  }
>  
>  struct pk_color
> -pk_term_get_bgcolor ()
> +pk_term_get_bgcolor_1 (pk_compiler pkc __attribute__ ((unused)))
>  {
>  #if defined HAVE_TEXTSTYLE_ACCESSORS_SUPPORT
>    if (color_mode != color_html
> @@ -614,7 +612,8 @@ pk_term_get_bgcolor ()
>  }
>  
>  void
> -pk_term_set_color (struct pk_color color)
> +pk_term_set_color_1 (pk_compiler pkc __attribute__ ((unused)),
> +                     struct pk_color color)
>  {
>  #if defined HAVE_TEXTSTYLE_ACCESSORS_SUPPORT
>    if (color_mode != color_html)
> @@ -642,7 +641,8 @@ pk_term_set_color (struct pk_color color)
>  }
>  
>  void
> -pk_term_set_bgcolor (struct pk_color color)
> +pk_term_set_bgcolor_1 (pk_compiler pkc __attribute__ ((unused)),
> +                       struct pk_color color)
>  {
>  #if defined HAVE_TEXTSTYLE_ACCESSORS_SUPPORT
>    if (color_mode != color_html)
> diff --git a/poke/pk-term.h b/poke/pk-term.h
> index 8516dc30..205d1211 100644
> --- a/poke/pk-term.h
> +++ b/poke/pk-term.h
> @@ -23,6 +23,12 @@
>  
>  #include <textstyle.h>
>  
> +/* From libpoke.h.  */
> +typedef struct _pk_compiler *pk_compiler;
> +
> +/* Defined in poke.c.  */
> +extern pk_compiler poke_compiler;
> +
>  /* Initialize and finalize the terminal subsystem.  */
>  void pk_term_init (int argc, char *argv[]);
>  void pk_term_shutdown (void);
> @@ -32,33 +38,45 @@ void pk_term_shutdown (void);
>  extern int pk_term_color_p (void);
>  
>  /* Flush the terminal output.  */
> -extern void pk_term_flush (void);
> +extern void pk_term_flush_1 (pk_compiler pkc);
> +#define pk_term_flush() pk_term_flush_1 (poke_compiler)
>  
>  /* Print a string to the terminal.  */
> -extern void pk_puts (const char *str);
> +extern void pk_puts_1 (pk_compiler pkc, const char *str);
> +#define pk_puts(STR) pk_puts_1 (poke_compiler, (STR))
>  
>  /* Print a formatted string to the terminal.  */
> -extern void pk_printf (const char *format, ...)
> -  __attribute__ ((format (printf, 1, 2)));
> +extern void pk_printf_1 (pk_compiler pkc, const char *format, ...)
> +  __attribute__ ((format (printf, 2, 3)));
>  extern void pk_vprintf (const char *format, va_list ap);
> +#define pk_printf(...) pk_printf_1 (poke_compiler, __VA_ARGS__)
>  
>  /* Print indentation.  */
> -extern void pk_term_indent (unsigned int lvl,
> -                            unsigned int step);
> +extern void pk_term_indent_1 (pk_compiler pkc, unsigned int lvl,
> +                              unsigned int step);
> +#define pk_term_indent(LVL, STEP) pk_term_indent_1 (poke_compiler, (LVL), 
> (STEP))
>  
>  /* Class handling.  */
> -extern void pk_term_class (const char *class);
> -extern int pk_term_end_class (const char *class);
> +extern void pk_term_class_1 (pk_compiler pkc, const char *class);
> +extern int pk_term_end_class_1 (pk_compiler pkc, const char *class);
> +#define pk_term_class(CLS) pk_term_class_1 (poke_compiler, (CLS))
> +#define pk_term_end_class(CLS) pk_term_end_class_1 (poke_compiler, (CLS))
>  
>  /* Hyperlinks.  */
> -extern void pk_term_hyperlink (const char *url, const char *id);
> -extern int pk_term_end_hyperlink (void);
> +extern void pk_term_hyperlink_1 (pk_compiler pkc, const char *url, const 
> char *id);
> +extern int pk_term_end_hyperlink_1 (pk_compiler pkc);
> +#define pk_term_hyperlink(URL, ID) pk_term_hyperlink_1 (poke_compiler, 
> (URL), (ID))
> +#define pk_term_end_hyperlink() pk_term_end_hyperlink_1 (poke_compiler)
>  
>  /* Color handling.  */
> -extern struct pk_color pk_term_get_color (void);
> -extern struct pk_color pk_term_get_bgcolor (void);
> -extern void pk_term_set_color (struct pk_color color);
> -extern void pk_term_set_bgcolor (struct pk_color color);
> +extern struct pk_color pk_term_get_color_1 (pk_compiler pkc);
> +extern struct pk_color pk_term_get_bgcolor_1 (pk_compiler pkc);
> +extern void pk_term_set_color_1 (pk_compiler pkc, struct pk_color color);
> +extern void pk_term_set_bgcolor_1 (pk_compiler pkc, struct pk_color color);
> +#define pk_term_get_color() pk_term_get_color_1 (poke_compiler)
> +#define pk_term_get_bgcolor() pk_term_get_bgcolor_1 (poke_compiler)
> +#define pk_term_set_color(COLOR) pk_term_set_color_1 (COLOR)
> +#define pk_term_set_bgcolor(COLOR) pk_term_set_bgcolor_1 (COLOR)
>  
>  /* Paging.  */
>  extern void pk_term_start_pager (void);
> diff --git a/poke/poke.c b/poke/poke.c
> index ee3b2857..2e2e1c96 100644
> --- a/poke/poke.c
> +++ b/poke/poke.c
> @@ -296,18 +296,18 @@ finalize (void)
>  
>  static struct pk_term_if poke_term_if =
>    {
> -    .flush_fn = pk_term_flush,
> -    .puts_fn = pk_puts,
> -    .printf_fn = pk_printf,
> -    .indent_fn = pk_term_indent,
> -    .class_fn = pk_term_class,
> -    .end_class_fn = pk_term_end_class,
> -    .hyperlink_fn = pk_term_hyperlink,
> -    .end_hyperlink_fn = pk_term_end_hyperlink,
> -    .get_color_fn = pk_term_get_color,
> -    .set_color_fn = pk_term_set_color,
> -    .get_bgcolor_fn = pk_term_get_bgcolor,
> -    .set_bgcolor_fn = pk_term_set_bgcolor,
> +    .flush_fn = pk_term_flush_1,
> +    .puts_fn = pk_puts_1,
> +    .printf_fn = pk_printf_1,
> +    .indent_fn = pk_term_indent_1,
> +    .class_fn = pk_term_class_1,
> +    .end_class_fn = pk_term_end_class_1,
> +    .hyperlink_fn = pk_term_hyperlink_1,
> +    .end_hyperlink_fn = pk_term_end_hyperlink_1,
> +    .get_color_fn = pk_term_get_color_1,
> +    .set_color_fn = pk_term_set_color_1,
> +    .get_bgcolor_fn = pk_term_get_bgcolor_1,
> +    .set_bgcolor_fn = pk_term_set_bgcolor_1,
>    };
>  
>  const char *
> diff --git a/poked/poked.c b/poked/poked.c
> index 6320714d..18de8c47 100644
> --- a/poked/poked.c
> +++ b/poked/poked.c
> @@ -702,18 +702,18 @@ tifbuf_init(void)
>  #endif
>  
>  static void
> -tif_flush (void)
> +tif_flush (pk_compiler pkc __attribute__ ((unused)))
>  {
>  }
>  static void
> -tif_puts (const char *s)
> +tif_puts (pk_compiler pkc __attribute__ ((unused)), const char *s)
>  {
>    if (poked_options.debug_p)
>      printf (">(p) '%s'\n", s);
>    usock_out (srv, termout_chan, termout_cmdkind, s, strlen (s) + 1);
>  }
>  static void
> -tif_printf (const char *fmt, ...)
> +tif_printf (pk_compiler pkc __attribute__ ((unused)), const char *fmt, ...)
>  {
>    va_list ap;
>    char *data = NULL;
> @@ -731,7 +731,8 @@ tif_printf (const char *fmt, ...)
>    free (data);
>  }
>  static void
> -tif_indent (unsigned int level, unsigned int step)
> +tif_indent (pk_compiler pkc __attribute__ ((unused)), unsigned int level,
> +            unsigned int step)
>  {
>    size_t len = /*newline*/ 1u + step * level;
>    char *data;
> @@ -744,31 +745,32 @@ tif_indent (unsigned int level, unsigned int step)
>    free (data);
>  }
>  static void
> -tif_class (const char *name)
> +tif_class (pk_compiler pkc __attribute__ ((unused)), const char *name)
>  {
>    if (termout_chan == USOCK_CHAN_OUT_OUT)
>      usock_out (srv, termout_chan, OUTCMD_CLS_BEGIN, name, strlen (name) + 1);
>  }
>  static int
> -tif_class_end (const char *name)
> +tif_class_end (pk_compiler pkc __attribute__ ((unused)), const char *name)
>  {
>    if (termout_chan == USOCK_CHAN_OUT_OUT)
>      usock_out (srv, termout_chan, OUTCMD_CLS_END, name, strlen (name) + 1);
>    return 1;
>  }
>  static void
> -tif_hlink (const char *name, const char *id)
> +tif_hlink (pk_compiler pkc __attribute__ ((unused)), const char *name,
> +           const char *id)
>  {
>    (void)name;
>    (void)id;
>  }
>  static int
> -tif_hlink_end (void)
> +tif_hlink_end (pk_compiler pkc __attribute__ ((unused)))
>  {
>    return 1;
>  }
>  static struct pk_color
> -tif_color (void)
> +tif_color (pk_compiler pkc __attribute__ ((unused)))
>  {
>    static struct pk_color c = {
>      .red = 0,
> @@ -778,7 +780,7 @@ tif_color (void)
>    return c;
>  }
>  static struct pk_color
> -tif_bgcolor (void)
> +tif_bgcolor (pk_compiler pkc __attribute__ ((unused)))
>  {
>    static struct pk_color c = {
>      .red = 255,
> @@ -788,12 +790,12 @@ tif_bgcolor (void)
>    return c;
>  }
>  static void
> -tif_color_set (struct pk_color c)
> +tif_color_set (pk_compiler pkc __attribute__ ((unused)), struct pk_color c)
>  {
>    (void)c;
>  }
>  static void
> -tif_bgcolor_set (struct pk_color c)
> +tif_bgcolor_set (pk_compiler pkc __attribute__ ((unused)), struct pk_color c)
>  {
>    (void)c;
>  }
> diff --git a/pokefmt/pokefmt.l b/pokefmt/pokefmt.l
> index fe57fbf7..74505134 100644
> --- a/pokefmt/pokefmt.l
> +++ b/pokefmt/pokefmt.l
> @@ -362,17 +362,17 @@ pokefmt_opts_free ()
>  
>  // terminal IO functions
>  static void
> -tif_flush (void)
> +tif_flush (pk_compiler pkc __attribute__ ((unused)))
>  {
>    fflush (stdout);
>  }
>  static void
> -tif_puts (const char *s)
> +tif_puts (pk_compiler pkc __attribute__ ((unused)), const char *s)
>  {
>    printf ("%s", s);
>  }
>  static void
> -tif_printf (const char *fmt, ...)
> +tif_printf (pk_compiler pkc __attribute__ ((unused)), const char *fmt, ...)
>  {
>    va_list ap;
>  
> @@ -381,36 +381,38 @@ tif_printf (const char *fmt, ...)
>    va_end (ap);
>  }
>  static void
> -tif_indent (unsigned int level, unsigned int step)
> +tif_indent (pk_compiler pkc __attribute__ ((unused)), unsigned int level,
> +            unsigned int step)
>  {
>    putchar ('\n');
>    for (unsigned int i = 0; i < step * level; ++i)
>      putchar (' ');
>  }
>  static void
> -tif_class (const char *name)
> +tif_class (pk_compiler pkc __attribute__ ((unused)), const char *name)
>  {
>    (void)name;
>  }
>  static int
> -tif_class_end (const char *name)
> +tif_class_end (pk_compiler pkc __attribute__ ((unused)), const char *name)
>  {
>    (void)name;
>    return 1;
>  }
>  static void
> -tif_hlink (const char *name, const char *id)
> +tif_hlink (pk_compiler pkc __attribute__ ((unused)), const char *name,
> +           const char *id)
>  {
>    (void)name;
>    (void)id;
>  }
>  static int
> -tif_hlink_end (void)
> +tif_hlink_end (pk_compiler pkc __attribute__ ((unused)))
>  {
>    return 1;
>  }
>  static struct pk_color
> -tif_color (void)
> +tif_color (pk_compiler pkc __attribute__ ((unused)))
>  {
>    static struct pk_color c = {
>      .red = 0,
> @@ -420,7 +422,7 @@ tif_color (void)
>    return c;
>  }
>  static struct pk_color
> -tif_bgcolor (void)
> +tif_bgcolor (pk_compiler pkc __attribute__ ((unused)))
>  {
>    static struct pk_color c = {
>      .red = 255,
> @@ -430,12 +432,12 @@ tif_bgcolor (void)
>    return c;
>  }
>  static void
> -tif_color_set (struct pk_color c)
> +tif_color_set (pk_compiler pkc __attribute__ ((unused)), struct pk_color c)
>  {
>    (void)c;
>  }
>  static void
> -tif_bgcolor_set (struct pk_color c)
> +tif_bgcolor_set (pk_compiler pkc __attribute__ ((unused)), struct pk_color c)
>  {
>    (void)c;
>  }
> diff --git a/testsuite/poke.libpoke/term-if.h 
> b/testsuite/poke.libpoke/term-if.h
> index dfcece14..0f9d20e6 100644
> --- a/testsuite/poke.libpoke/term-if.h
> +++ b/testsuite/poke.libpoke/term-if.h
> @@ -20,19 +20,18 @@
>  #include <stdio.h>
>  
>  static void
> -pk_term_flush ()
> +pk_term_flush (pk_compiler pkc __attribute__ ((unused)))
>  {
>  }
>  
>  void
> -pk_puts (const char *str)
> +pk_puts (pk_compiler pkc __attribute__ ((unused)), const char *str)
>  {
>    printf ("%s", str);
>  }
>  
> -__attribute__ ((__format__ (__printf__, 1, 2)))
> -void
> -pk_printf (const char *format, ...)
> +__attribute__ ((__format__ (__printf__, 2, 3))) void
> +pk_printf (pk_compiler pkc __attribute__ ((unused)), const char *format, ...)
>  {
>    va_list ap;
>  
> @@ -42,58 +41,59 @@ pk_printf (const char *format, ...)
>  }
>  
>  void
> -pk_term_indent (unsigned int lvl,
> +pk_term_indent (pk_compiler pkc __attribute__ ((unused)), unsigned int lvl,
>                  unsigned int step)
>  {
>    printf ("\n%*s", (step * lvl), "");
>  }
>  
>  void
> -pk_term_class (const char *class)
> +pk_term_class (pk_compiler pkc __attribute__ ((unused)), const char *class)
>  {
>  }
>  
>  int
> -pk_term_end_class (const char *class)
> +pk_term_end_class (pk_compiler pkc __attribute__ ((unused)), const char 
> *class)
>  {
>    return 1;
>  }
>  
>  void
> -pk_term_hyperlink (const char *url, const char *id)
> +pk_term_hyperlink (pk_compiler pkc __attribute__ ((unused)), const char *url,
> +                   const char *id)
>  {
>  }
>  
>  int
> -pk_term_end_hyperlink (void)
> +pk_term_end_hyperlink (pk_compiler pkc __attribute__ ((unused)))
>  {
>    return 1;
>  }
>  
>  struct pk_color
> -pk_term_get_color (void)
> +pk_term_get_color (pk_compiler pkc __attribute__ ((unused)))
>  {
> -  struct pk_color inv = {-1,-1,-1};
> +  struct pk_color inv = { -1, -1, -1 };
>    return inv;
>  }
>  
>  struct pk_color
> -pk_term_get_bgcolor (void)
> +pk_term_get_bgcolor (pk_compiler pkc __attribute__ ((unused)))
>  {
> -  struct pk_color inv = {-1,-1,-1};
> +  struct pk_color inv = { -1, -1, -1 };
>    return inv;
>  }
>  
>  void
> -pk_term_set_color (struct pk_color color)
> +pk_term_set_color (pk_compiler pkc __attribute__ ((unused)),
> +                   struct pk_color color)
>  {
> -
>  }
>  
>  void
> -pk_term_set_bgcolor (struct pk_color color)
> +pk_term_set_bgcolor (pk_compiler pkc __attribute__ ((unused)),
> +                     struct pk_color color)
>  {
> -
>  }
>  
>  static struct pk_term_if poke_term_if =



reply via email to

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