chiark / gitweb /
struct/buf.3.in: Correct the type of `buf_put' in the synopsis.
[mLib] / utils / gprintf.h
index 0f06dd38ed4d01062e79e13283c34142f38be17f..bcef7bb2d3f63fff13738152454ef60c7090284a 100644 (file)
 
 #include <stdarg.h>
 
 
 #include <stdarg.h>
 
+#ifndef MLIB_ARENA_H
+#  include "arena.h"
+#endif
+
 #ifndef MLIB_MACROS_H
 #  include "macros.h"
 #endif
 #ifndef MLIB_MACROS_H
 #  include "macros.h"
 #endif
 struct gprintf_ops {
   int (*putch)(void */*out*/, int /*ch*/);
   int (*putm)(void */*out*/, const char */*p*/, size_t /*sz*/);
 struct gprintf_ops {
   int (*putch)(void */*out*/, int /*ch*/);
   int (*putm)(void */*out*/, const char */*p*/, size_t /*sz*/);
-  PRINTF_LIKE(3, 4) int (*nputf)
-    (void */*out*/, size_t /*maxsz*/, const char */*p*/, ...);
+  PRINTF_LIKE(3, 4)
+    int (*nputf)(void */*out*/, size_t /*maxsz*/, const char */*p*/, ...);
 };
 
 extern const struct gprintf_ops file_printops;
 
 /*----- Functions provided ------------------------------------------------*/
 
 };
 
 extern const struct gprintf_ops file_printops;
 
 /*----- Functions provided ------------------------------------------------*/
 
-/* --- @vgprintf@ --- *
- *
- * Arguments:  @const struct gprintf_ops *ops@ = output operations
- *             @void *out@ = context for output operations
- *             @const char *p@ = pointer to @printf@-style format string
- *             @va_list *ap@ = argument handle
- *
- * Returns:    The number of characters written to the string.
- *
- * Use:                As for @gprintf@, but takes a reified argument tail.
- */
-
-extern int vgprintf(const struct gprintf_ops */*ops*/, void */*out*/,
-                   const char */*p*/, va_list */*ap*/);
-
-/* --- @gprintf@ --- *
+/* --- @gprintf@, @vgprintf@ --- *
  *
  * Arguments:  @const struct gprintf_ops *ops@ = output operations
  *             @void *out@ = context for output operations
  *             @const char *p@ = pointer to @printf@-style format string
  *
  * Arguments:  @const struct gprintf_ops *ops@ = output operations
  *             @void *out@ = context for output operations
  *             @const char *p@ = pointer to @printf@-style format string
- *             @...@ = argument handle
+ *             @...@ = format arguments
+ *             @va_list *ap@ = captured format-arguments tail
  *
  * Returns:    The number of characters written to the string.
  *
  * Use:                Formats a @printf@-like message and writes the result using
  *             the given output operations.  This is the backend machinery
  *             for @dstr_putf@, for example.
  *
  * Returns:    The number of characters written to the string.
  *
  * Use:                Formats a @printf@-like message and writes the result using
  *             the given output operations.  This is the backend machinery
  *             for @dstr_putf@, for example.
+ *
+ *             The @gprintf@ function receives its format arguments as a
+ *             variable-length argument tail; the @vgprintf@ function
+ *             receives them as %%\emph{a pointer to}%% a captured argument
+ *             tail; it updates @*ap@, leaving it ready to read the next
+ *             unused argument.
  */
 
  */
 
-extern int PRINTF_LIKE(3, 4)
-  gprintf(const struct gprintf_ops */*ops*/, void */*out*/,
-         const char */*p*/, ...);
+extern PRINTF_LIKE(3, 4)
+  int gprintf(const struct gprintf_ops */*ops*/, void */*out*/,
+             const char */*p*/, ...);
+extern int vgprintf(const struct gprintf_ops */*ops*/, void */*out*/,
+                   const char */*p*/, va_list */*ap*/);
 
 /* --- @gprintf_memputf@ --- *
  *
 
 /* --- @gprintf_memputf@ --- *
  *
- * Arguments:  @char **buf_inout@ = address of output buffer pointer
+ * Arguments:  @arena *a@ = memory allocation arena
+ *             @char **buf_inout@ = address of output buffer pointer
  *             @size_t *sz_inout@ = address of buffer size
  *             @size_t maxsz@ = buffer size needed for this operation
  *             @const char *p@ = pointer to format string
  *             @size_t *sz_inout@ = address of buffer size
  *             @size_t maxsz@ = buffer size needed for this operation
  *             @const char *p@ = pointer to format string
@@ -106,10 +105,12 @@ extern int PRINTF_LIKE(3, 4)
  *             buffer, and the formatted string will have been written to
  *             the buffer.
  *
  *             buffer, and the formatted string will have been written to
  *             the buffer.
  *
- *             When the buffer is no longer required, free it using @xfree@.
+ *             When the buffer is no longer required, free it using
+ *             @x_free@.
  */
 
  */
 
-extern size_t gprintf_memputf(char **/*buf_inout*/, size_t */*sz_inout*/,
+extern size_t gprintf_memputf(arena */*a*/,
+                             char **/*buf_inout*/, size_t */*sz_inout*/,
                              size_t /*maxsz*/,
                              const char */*p*/, va_list /*ap*/);
 
                              size_t /*maxsz*/,
                              const char */*p*/, va_list /*ap*/);