Please use the bprintf package from Meta-HTML (metahtml-5.09.tar.gz).
It can be found in metahtml-5.09/libutils/bprintf.

Here's a synopsis:

       BPRINTF_BUFFER *b = bprintf_create_buffer ();

       bprintf (b, "Hello %02x Hex\n", 345);
       bprintf (b, ....);
       printf ("%s", b->buffer);
       bprintf_free (b);

There are many more calls in the API, including bprintf_insert,
delete, word_wrap, and so forth.

/* bprintf.h: Declarations of functions defined in bprintf.c. */

/* Author: Brian J. Fox ([EMAIL PROTECTED]) Thu Apr 20 19:34:51 1995.

   This file is part of <Meta-HTML>(tm), a system for the rapid deployment
   of Internet and Intranet applications via the use of the Meta-HTML
   language.

   Copyright (c) 1995, 1996, Brian J. Fox ([EMAIL PROTECTED]).
   Copyright (c) 1996, Universal Access Inc. (http://www.ua.com).

   Meta-HTML is free software; you can redistribute it and/or modify
   it under the terms of the UAI Free Software License as published
   by Universal Access Inc.; either version 1, or (at your option) any
   later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   UAI Free Software License for more details.

   You should have received a copy of the UAI Free Software License
   along with this program; if you have not, you may obtain one by
   writing to:

   Universal Access Inc.
   129 El Paseo Court
   Santa Barbara, CA
   93101  */

#if !defined (_BPRINTF_H_)
#define _BPRINTF_H_

#if defined (__cplusplus)
extern "C"
{
#endif

/* A structure used to hold onto a dynamically created buffer of text. */
typedef struct {
  char *buffer;
  int bindex;
  int bsize;
  void *attachment;             /* Anything you want to put here. */
} BPRINTF_BUFFER;

/* Create a new empty output buffer. */
extern BPRINTF_BUFFER *bprintf_create_buffer (void);

/* Create a new buffer which is a copy of INPUT. */
extern BPRINTF_BUFFER *bprintf_copy_buffer (BPRINTF_BUFFER *input);

/* Free the contents of a bprintf buffer. */
extern void bprintf_free_buffer (BPRINTF_BUFFER *buffer);

/* The main function in this library.  Print to BUFFER with FORMAT and
   any additional args. */
extern void bprintf (BPRINTF_BUFFER *buffer, char *format, ...);

/* Like bprintf, but after the va_list has been started. */
extern void vbprintf (BPRINTF_BUFFER *buffer, char *format, va_list args);

/* A few helpful functions for manipulating the insides of bprintf buffers. */

/* Delete the characters from START to END from buffer.  The END'th
   character is not deleted, but the START'th character is.
   Return the number of characters deleted. */
extern int bprintf_delete_range (BPRINTF_BUFFER *buffer, int start, int end);

/* Insert into BUFFER at POINT the results of printing FORMAT with args.
   Return the number of characters inserted, or -1 if there was an error. */
extern int bprintf_insert (BPRINTF_BUFFER *buffer, int point, char *fmt, ...);

/* Insert info BUFFER at POINT LEN bytes of DATA. */
extern void bprintf_insert_binary (BPRINTF_BUFFER *buffer, int point,
                                   char *data, int len);

/* Insert into BUFFER at POINT the string TEXT.
   Return the number of characters inserted, or -1 if there was an error. */
extern int bprintf_insert_text (BPRINTF_BUFFER *buffer, int point, char *text);

/* Word wrap the text in BUFFER making lines no longer than WIDTH. */
extern void bprintf_word_wrap (BPRINTF_BUFFER *buffer, int width);

#if defined (__cplusplus)
}
#endif

#endif /* ! _BPRINTF_H_ */


   Date: Tue, 21 Dec 1999 19:41:26 +0100
   From: Josip Rodin <[EMAIL PROTECTED]>

   ----- Forwarded message from Fumitoshi UKAI <[EMAIL PROTECTED]> -----

   Subject: Bug#53221: info does not care position parameter in format string
   Reply-To: Fumitoshi UKAI <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
   X-Debian-PR-Message: report 53221
   X-Debian-PR-Package: info
   Date: Wed, 22 Dec 1999 01:17:51 +0900
   From: Fumitoshi UKAI <[EMAIL PROTECTED]>
   To: [EMAIL PROTECTED]
   User-Agent: Wanderlust/2.2.12 (Joyride) SEMI/1.13.7 (Awazu) FLIM/1.13.2 (Kasanui) 
Emacs/20.4 (i386-debian-linux-gnu) MULE/4.0 (HANANOEN)
   Organization: Debian JP Project

   Package: info
   Version: 4.0-2

   In window.c, build_message_buffer() format strings, but it doesn't 
   care position parameter in format string like `%1$s'.  This kind of
   position parameter is necessary for translated messages.
   At least, /usr/share/locales/ja/LC_MESSAGES/texinfo.mo (in ja-trans
   package) cause segmentation fault when we invoke info againt unknown node
   like:

    % info hogehoge

   This evil patch fixes this problem, but I think it's better to
   use asprintf(3) or something like that.

   --- window.c~        Sat Jun 26 06:57:40 1999
   +++ window.c Wed Dec 22 01:10:25 1999
   @@ -1326,7 +1326,9 @@
              char *fmt_start = format + i;
              char *fmt;
              int fmt_len, formatted_len;
   +      int paramed = 0;

   +    format_again:
              i++;
              while (format[i] && strchr ("-. +0123456789", format[i]))
                i++;
   @@ -1335,18 +1337,38 @@
              if (c == '\0')
                abort ();

   +      if (c == '$') {
   +        /* position parameter parameter */
   +        arg_index = atoi(fmt_start + 1) - 1;
   +        if (arg_index < 0)
   +          arg_index = 0;
   +        if (arg_index >= 2)
   +          arg_index = 1;
   +        paramed = 1;
   +        goto format_again;
   +      }
   +
              fmt_len = format + i - fmt_start + 1;
              fmt = (char *) xmalloc (fmt_len + 1);
              strncpy (fmt, fmt_start, fmt_len);
              fmt[fmt_len] = '\0';

   +      if (paramed) {
   +        /* removed positioned parameter */
   +        char *p;
   +        for (p = fmt + 1; *p && *p != '$'; p++) {
   +          ;
   +        }
   +        strcpy(fmt + 1, p + 1);
   +      }
   +
              /* If we have "%-98s", maybe 98 calls for a longer string.  */
              if (fmt_len > 2)
                {
                  int j;

   -              for (j = 0; j < fmt_len; j++)
   -                if (isdigit (fmt[j]))
   +              for (j = fmt_len - 2; j >= 0; j--)
   +                if (isdigit (fmt[j]) || fmt[j] == '$')
                      break;

                  formatted_len = atoi (fmt + j);


   Thanks,
   Fumitoshi UKAI

   ----- End forwarded message -----

   -- 
   enJoy -*/\*- don't even try to pronounce my first name





-- 
== The Difference Between Cultures: ==
    Einigkeit und Recht und Freiheit
    Liberte', E'galite', Fraternite'
    Sex, drugs and rock'n'roll

Reply via email to