@@ -386,19 +386,18 @@ xo_destroy
386386Emitting Content (xo_emit)
387387--------------------------
388388
389- The functions in this section are used to emit output.
390-
391- The "fmt" argument is a string containing field descriptors as
392- specified in :ref:`format-strings`. The use of a handle is optional and
393- `NULL` can be passed to access the internal "default" handle. See
389+ The functions in this section are used to emit output. They use a
390+ `format` string containing field descriptors as specified in
391+ :ref:`format-strings`. The use of a handle is optional and `NULL` can
392+ be passed to access the internal "default" handle. See
394393:ref:`handles`.
395394
396395The remaining arguments to `xo_emit` and `xo_emit_h` are a set of
397396arguments corresponding to the fields in the format string. Care must
398397be taken to ensure the argument types match the fields in the format
399- string, since an inappropriate cast can ruin your day. The vap
400- argument to `xo_emit_hv` points to a variable argument list that can
401- be used to retrieve arguments via `va_arg`.
398+ string, since an inappropriate or missing argument can ruin your day.
399+ The `vap` argument to `xo_emit_hv` points to a variable argument list
400+ that can be used to retrieve arguments via `va_arg`.
402401
403402.. c:function:: xo_ssize_t xo_emit (const char *fmt, ...)
404403
@@ -428,19 +427,40 @@ be used to retrieve arguments via `va_arg`.
428427Single Field Emitting Functions (xo_emit_field)
429428~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
430429
431- The functions in this section can also make output, but only make a
432- single field at a time. These functions are intended to avoid the
433- scenario where one would otherwise need to compose a format
434- descriptors using `snprintf`. The individual parts of the format
435- descriptor are passed in distinctly.
436-
437- .. c:function:: xo_ssize_t xo_emit_field (const char *rolmod, const char *contents, const char *fmt, const char *efmt, ...)
430+ The functions in this section emit formatted output similar to
431+ `xo_emit` but where `xo_emit` uses a single string argument containing
432+ the description for multiple fields, `xo_emit_field` emits a single
433+ field using multiple ar- guments to contain the field description.
434+ `xo_emit_field_h` adds an ex- plicit handle to use instead of the
435+ default handle, while `xo_emit_field_hv` accepts a va_list for
436+ additional flexibility.
437+
438+ The arguments `rolmod`, `content`, `fmt`, and `efmt` are detailed in
439+ :ref:`field-formatting`. Using distinct arguments allows callers to
440+ pass the field description in pieces, rather than having to use
441+ something like `snprintf` to build the format string required by
442+ `xo_emit`. The arguments are each NUL-terminated strings. The `rolmod`
443+ argument contains the `role` and `modifier` portions of the field
444+ description, the `content` argument contains the `content` portion, and
445+ the `fmt` and `efmt` contain the `field-format` and `encoding-format` por-
446+ tions, respectively.
447+
448+ As with `xo_emit`, the `fmt` and `efmt` values are both optional,
449+ since the `field-format` string defaults to "%s", and the
450+ `encoding-format`'s default value is derived from the `field-format`
451+ per :ref:`field-formatting`. However, care must be taken to avoid
452+ using a value directly as the format, since characters like '{', '%',
453+ and '}' will be interpreted as formatting directives, and may cause
454+ xo_emit_field to dereference arbitrary values off the stack, leading
455+ to bugs, core files, and gnashing of teeth.
456+
457+ .. c:function:: xo_ssize_t xo_emit_field (const char *rolmod, const char *content, const char *fmt, const char *efmt, ...)
438458
439459 :param rolmod: A comma-separated list of field roles and field modifiers
440460 :type rolmod: const char *
441- :param contents : The "contents " portion of the field description string
442- :type contents : const char *
443- :param fmt: Content format string
461+ :param content : The "content " portion of the field description string
462+ :type content : const char *
463+ :param fmt: Contents format string
444464 :type fmt: const char *
445465 :param efmt: Encoding format string, followed by additional arguments
446466 :type efmt: const char *
@@ -450,8 +470,11 @@ descriptor are passed in distinctly.
450470 ::
451471
452472 EXAMPLE::
473+ xo_emit_field("T", title, NULL, NULL, NULL);
453474 xo_emit_field("T", "Host name is ", NULL, NULL);
454475 xo_emit_field("V", "host-name", NULL, NULL, host-name);
476+ xo_emit_field(",leaf-list,quotes", "sku", "%s-%u", "%s-000-%u",
477+ "gum", 1412);
455478
456479.. c:function:: xo_ssize_t xo_emit_field_h (xo_handle_t *xop, const char *rolmod, const char *contents, const char *fmt, const char *efmt, ...)
457480
0 commit comments