Manual Page Search Parameters
libxo(3) library for emitting text, XML, JSON, or HTML output
xo_attr, libxo, xo_attr_h, xo_attr_hv(3) Add attribute name/value pairs to formatted output
xo_attr_h, libxo, xo_attr, xo_attr_hv(3) Add attribute name/value pairs to formatted output
xo_attr_hv, libxo, xo_attr, xo_attr_h(3) Add attribute name/value pairs to formatted output
xo_clear_flags, libxo, xo_set_flags(3) set operational flags for a libxo handle
xo_close_container, libxo, xo_open_container, xo_close_container_d, xo_close_container_h, xo_close_container_hd, xo_open_container_d, xo_open_container_h, xo_open_container_hd(3) open (and close) container constructs
xo_close_container_d, libxo, xo_open_container, xo_close_container, xo_close_container_h, xo_close_container_hd, xo_open_container_d, xo_open_container_h, xo_open_container_hd(3) open (and close) container constructs
xo_close_container_h, libxo, xo_open_container, xo_close_container, xo_close_container_d, xo_close_container_hd, xo_open_container_d, xo_open_container_h, xo_open_container_hd(3) open (and close) container constructs
xo_close_container_hd, libxo, xo_open_container, xo_close_container, xo_close_container_d, xo_close_container_h, xo_open_container_d, xo_open_container_h, xo_open_container_hd(3) open (and close) container constructs
xo_close_instance, libxo, xo_open_list, xo_close_instance_d, xo_close_instance_h, xo_close_instance_hd, xo_close_list, xo_close_list_d, xo_close_list_h, xo_close_list_hd, xo_open_instance, xo_open_instance_d, xo_open_instance_h, xo_open_instance_hd, xo_open_list_d, xo_open_list_h, xo_open_list_hd(3) open and close lists and instances
xo_close_instance_d, libxo, xo_open_list, xo_close_instance, xo_close_instance_h, xo_close_instance_hd, xo_close_list, xo_close_list_d, xo_close_list_h, xo_close_list_hd, xo_open_instance, xo_open_instance_d, xo_open_instance_h, xo_open_instance_hd, xo_open_list_d, xo_open_list_h, xo_open_list_hd(3) open and close lists and instances
xo_close_instance_h, libxo, xo_open_list, xo_close_instance, xo_close_instance_d, xo_close_instance_hd, xo_close_list, xo_close_list_d, xo_close_list_h, xo_close_list_hd, xo_open_instance, xo_open_instance_d, xo_open_instance_h, xo_open_instance_hd, xo_open_list_d, xo_open_list_h, xo_open_list_hd(3) open and close lists and instances
xo_close_instance_hd, libxo, xo_open_list, xo_close_instance, xo_close_instance_d, xo_close_instance_h, xo_close_list, xo_close_list_d, xo_close_list_h, xo_close_list_hd, xo_open_instance, xo_open_instance_d, xo_open_instance_h, xo_open_instance_hd, xo_open_list_d, xo_open_list_h, xo_open_list_hd(3) open and close lists and instances
xo_close_list, libxo, xo_open_list, xo_close_instance, xo_close_instance_d, xo_close_instance_h, xo_close_instance_hd, xo_close_list_d, xo_close_list_h, xo_close_list_hd, xo_open_instance, xo_open_instance_d, xo_open_instance_h, xo_open_instance_hd, xo_open_list_d, xo_open_list_h, xo_open_list_hd(3) open and close lists and instances
xo_close_list_d, libxo, xo_open_list, xo_close_instance, xo_close_instance_d, xo_close_instance_h, xo_close_instance_hd, xo_close_list, xo_close_list_h, xo_close_list_hd, xo_open_instance, xo_open_instance_d, xo_open_instance_h, xo_open_instance_hd, xo_open_list_d, xo_open_list_h, xo_open_list_hd(3) open and close lists and instances
xo_close_list_h, libxo, xo_open_list, xo_close_instance, xo_close_instance_d, xo_close_instance_h, xo_close_instance_hd, xo_close_list, xo_close_list_d, xo_close_list_hd, xo_open_instance, xo_open_instance_d, xo_open_instance_h, xo_open_instance_hd, xo_open_list_d, xo_open_list_h, xo_open_list_hd(3) open and close lists and instances
xo_close_list_hd, libxo, xo_open_list, xo_close_instance, xo_close_instance_d, xo_close_instance_h, xo_close_instance_hd, xo_close_list, xo_close_list_d, xo_close_list_h, xo_open_instance, xo_open_instance_d, xo_open_instance_h, xo_open_instance_hd, xo_open_list_d, xo_open_list_h, xo_open_list_hd(3) open and close lists and instances
xo_close_log, libxo, xo_syslog, xo_open_log, xo_set_logmask, xo_vsyslog(3) create SYSLOG (RFC5424) log records using libxo formatting
xo_close_marker, libxo, xo_open_marker, xo_close_marker_h, xo_open_marker_h(3) prevent and allow closing of open constructs
xo_close_marker_h, libxo, xo_open_marker, xo_close_marker, xo_open_marker_h(3) prevent and allow closing of open constructs
xo_create, libxo, xo_create_to_file, xo_destroy(3) create and destroy libxo output handles
xo_create_to_file, libxo, xo_create, xo_destroy(3) create and destroy libxo output handles
xo_destroy, libxo, xo_create, xo_create_to_file(3) create and destroy libxo output handles
xo_emit, libxo, xo_emit_h, xo_emit_hv(3) emit formatted output based on format string and arguments
xo_emit_err, libxo, xo_emit_errc, xo_emit_errx, xo_emit_warn, xo_emit_warn_c, xo_emit_warn_hc, xo_emit_warnx(3) emit errors and warnings in multiple output styles
xo_emit_errc, libxo, xo_emit_err, xo_emit_errx, xo_emit_warn, xo_emit_warn_c, xo_emit_warn_hc, xo_emit_warnx(3) emit errors and warnings in multiple output styles
xo_emit_errx, libxo, xo_emit_err, xo_emit_errc, xo_emit_warn, xo_emit_warn_c, xo_emit_warn_hc, xo_emit_warnx(3) emit errors and warnings in multiple output styles
xo_emit_h, libxo, xo_emit, xo_emit_hv(3) emit formatted output based on format string and arguments
xo_emit_hv, libxo, xo_emit, xo_emit_h(3) emit formatted output based on format string and arguments
xo_emit_warn, libxo, xo_emit_err, xo_emit_errc, xo_emit_errx, xo_emit_warn_c, xo_emit_warn_hc, xo_emit_warnx(3) emit errors and warnings in multiple output styles
xo_emit_warn_c, libxo, xo_emit_err, xo_emit_errc, xo_emit_errx, xo_emit_warn, xo_emit_warn_hc, xo_emit_warnx(3) emit errors and warnings in multiple output styles
xo_emit_warn_hc, libxo, xo_emit_err, xo_emit_errc, xo_emit_errx, xo_emit_warn, xo_emit_warn_c, xo_emit_warnx(3) emit errors and warnings in multiple output styles
xo_emit_warnx, libxo, xo_emit_err, xo_emit_errc, xo_emit_errx, xo_emit_warn, xo_emit_warn_c, xo_emit_warn_hc(3) emit errors and warnings in multiple output styles
xo_err, libxo, xo_errc, xo_errx, xo_warn, xo_warn_c, xo_warn_hc, xo_warnx(3) emit errors and warnings in multiple output styles
xo_errc, libxo, xo_err, xo_errx, xo_warn, xo_warn_c, xo_warn_hc, xo_warnx(3) emit errors and warnings in multiple output styles
xo_error, libxo(3) generate simple error messages in multiple output styles
xo_errx, libxo, xo_err, xo_errc, xo_warn, xo_warn_c, xo_warn_hc, xo_warnx(3) emit errors and warnings in multiple output styles
xo_finish, libxo, xo_finish_h(3) finish formatting output
xo_finish_h, libxo, xo_finish(3) finish formatting output
xo_flush, libxo, xo_flush_h(3) flush formatted output from libxo handle
xo_flush_h, libxo, xo_flush(3) flush formatted output from libxo handle
xo_format, libxo(3, 5) content of format descriptors for xo_emit
xo_message, libxo, xo_message_c, xo_message_hc, xo_message_hcv(3) emit messages in multiple output styles
xo_message_c, libxo, xo_message, xo_message_hc, xo_message_hcv(3) emit messages in multiple output styles
xo_message_hc, libxo, xo_message, xo_message_c, xo_message_hcv(3) emit messages in multiple output styles
xo_message_hcv, libxo, xo_message, xo_message_c, xo_message_hc(3) emit messages in multiple output styles
xo_no_setlocale, libxo(3) prevent implicit call to setlocale
xo_open_container, libxo, xo_close_container, xo_close_container_d, xo_close_container_h, xo_close_container_hd, xo_open_container_d, xo_open_container_h, xo_open_container_hd(3) open (and close) container constructs
xo_open_container_d, libxo, xo_open_container, xo_close_container, xo_close_container_d, xo_close_container_h, xo_close_container_hd, xo_open_container_h, xo_open_container_hd(3) open (and close) container constructs
xo_open_container_h, libxo, xo_open_container, xo_close_container, xo_close_container_d, xo_close_container_h, xo_close_container_hd, xo_open_container_d, xo_open_container_hd(3) open (and close) container constructs
xo_open_container_hd, libxo, xo_open_container, xo_close_container, xo_close_container_d, xo_close_container_h, xo_close_container_hd, xo_open_container_d, xo_open_container_h(3) open (and close) container constructs
xo_open_instance, libxo, xo_open_list, xo_close_instance, xo_close_instance_d, xo_close_instance_h, xo_close_instance_hd, xo_close_list, xo_close_list_d, xo_close_list_h, xo_close_list_hd, xo_open_instance_d, xo_open_instance_h, xo_open_instance_hd, xo_open_list_d, xo_open_list_h, xo_open_list_hd(3) open and close lists and instances
xo_open_instance_d, libxo, xo_open_list, xo_close_instance, xo_close_instance_d, xo_close_instance_h, xo_close_instance_hd, xo_close_list, xo_close_list_d, xo_close_list_h, xo_close_list_hd, xo_open_instance, xo_open_instance_h, xo_open_instance_hd, xo_open_list_d, xo_open_list_h, xo_open_list_hd(3) open and close lists and instances
xo_open_instance_h, libxo, xo_open_list, xo_close_instance, xo_close_instance_d, xo_close_instance_h, xo_close_instance_hd, xo_close_list, xo_close_list_d, xo_close_list_h, xo_close_list_hd, xo_open_instance, xo_open_instance_d, xo_open_instance_hd, xo_open_list_d, xo_open_list_h, xo_open_list_hd(3) open and close lists and instances
xo_open_instance_hd, libxo, xo_open_list, xo_close_instance, xo_close_instance_d, xo_close_instance_h, xo_close_instance_hd, xo_close_list, xo_close_list_d, xo_close_list_h, xo_close_list_hd, xo_open_instance, xo_open_instance_d, xo_open_instance_h, xo_open_list_d, xo_open_list_h, xo_open_list_hd(3) open and close lists and instances
xo_open_list, libxo, xo_close_instance, xo_close_instance_d, xo_close_instance_h, xo_close_instance_hd, xo_close_list, xo_close_list_d, xo_close_list_h, xo_close_list_hd, xo_open_instance, xo_open_instance_d, xo_open_instance_h, xo_open_instance_hd, xo_open_list_d, xo_open_list_h, xo_open_list_hd(3) open and close lists and instances
xo_open_list_d, libxo, xo_open_list, xo_close_instance, xo_close_instance_d, xo_close_instance_h, xo_close_instance_hd, xo_close_list, xo_close_list_d, xo_close_list_h, xo_close_list_hd, xo_open_instance, xo_open_instance_d, xo_open_instance_h, xo_open_instance_hd, xo_open_list_h, xo_open_list_hd(3) open and close lists and instances
xo_open_list_h, libxo, xo_open_list, xo_close_instance, xo_close_instance_d, xo_close_instance_h, xo_close_instance_hd, xo_close_list, xo_close_list_d, xo_close_list_h, xo_close_list_hd, xo_open_instance, xo_open_instance_d, xo_open_instance_h, xo_open_instance_hd, xo_open_list_d, xo_open_list_hd(3) open and close lists and instances
xo_open_list_hd, libxo, xo_open_list, xo_close_instance, xo_close_instance_d, xo_close_instance_h, xo_close_instance_hd, xo_close_list, xo_close_list_d, xo_close_list_h, xo_close_list_hd, xo_open_instance, xo_open_instance_d, xo_open_instance_h, xo_open_instance_hd, xo_open_list_d, xo_open_list_h(3) open and close lists and instances
xo_open_log, libxo, xo_syslog, xo_close_log, xo_set_logmask, xo_vsyslog(3) create SYSLOG (RFC5424) log records using libxo formatting
xo_open_marker, libxo, xo_close_marker, xo_close_marker_h, xo_open_marker_h(3) prevent and allow closing of open constructs
xo_open_marker_h, libxo, xo_open_marker, xo_close_marker, xo_close_marker_h(3) prevent and allow closing of open constructs
xo_options, libxo(3, 7) common options for libxo-based commands
xo_parse_args, libxo, xo_set_program(3) detect, parse, and remove arguments for libxo
xo_set_allocator, libxo(3) set allocation functions for libxo
xo_set_flags, libxo, xo_clear_flags(3) set operational flags for a libxo handle
xo_set_info, libxo(3) set the field information data for libxo
xo_set_logmask, libxo, xo_syslog, xo_close_log, xo_open_log, xo_vsyslog(3) create SYSLOG (RFC5424) log records using libxo formatting
xo_set_options, libxo(3) change options used by a libxo handle
xo_set_program, libxo, xo_parse_args(3) detect, parse, and remove arguments for libxo
xo_set_style, libxo, xo_set_style_name(3) set the output style for a libxo handle
xo_set_style_name, libxo, xo_set_style(3) set the output style for a libxo handle
xo_set_syslog_enterprise_id, libxo(3) Set the enterprise identifier for syslog content
xo_set_version, libxo, xo_set_version_h(3) record content-version information in encoded output
xo_set_version_h, libxo, xo_set_version(3) record content-version information in encoded output
xo_set_writer, libxo(3) set custom writer functions for a libxo handle
xo_syslog, libxo, xo_close_log, xo_open_log, xo_set_logmask, xo_vsyslog(3) create SYSLOG (RFC5424) log records using libxo formatting
xo_vsyslog, libxo, xo_syslog, xo_close_log, xo_open_log, xo_set_logmask(3) create SYSLOG (RFC5424) log records using libxo formatting
xo_warn, libxo, xo_err, xo_errc, xo_errx, xo_warn_c, xo_warn_hc, xo_warnx(3) emit errors and warnings in multiple output styles
xo_warn_c, libxo, xo_err, xo_errc, xo_errx, xo_warn, xo_warn_hc, xo_warnx(3) emit errors and warnings in multiple output styles
xo_warn_hc, libxo, xo_err, xo_errc, xo_errx, xo_warn, xo_warn_c, xo_warnx(3) emit errors and warnings in multiple output styles
xo_warnx, libxo, xo_err, xo_errc, xo_errx, xo_warn, xo_warn_c, xo_warn_hc(3) emit errors and warnings in multiple output styles

LIBXO(3) MidnightBSD Library Functions Manual LIBXO(3)

libxolibrary for emitting text, XML, JSON, or HTML output

Text, XML, JSON, and HTML Output Emission Library (libxo, -lxo)

#include <libxo/xo.h>

The functions defined in libxo are used to generate a choice of , , , or output. A common set of functions are used, with command line switches passed to the library to control the details of the output.

Most commands emit text output aimed at humans. It is designed to be parsed and understood by a user. Humans are gifted at extracting details and pattern matching. Often programmers need to extract information from this human-oriented output. Programmers use tools like grep(1), awk(1), and regular expressions to ferret out the pieces of information they need. Such solutions are fragile and require updates when output contents change or evolve, requiring testing and validation.

Modern tool developers favor encoding schemes like XML and JSON, which allow trivial parsing and extraction of data. Such formats are simple, well understood, hierarchical, easily parsed, and often integrate easier with common tools and environments.

In addition, modern reality means that more output ends up in web browsers than in terminals, making HTML output valuable.

libxo allows a single set of function calls in source code to generate traditional text output, as well as XML and JSON formatted data. HTML can also be generated; "<div>" elements surround the traditional text output, with attributes that detail how to render the data.

There are four encoding styles supported by libxo:

In general, XML and JSON are suitable for encoding data, while TEXT is suited for terminal output and HTML is suited for display in a web browser (see xohtml(1) ).

The libxo library allows an application to generate text, XML, JSON, and HTML output using a common set of function calls. The application decides at run time which output style should be produced. The application calls a function xo_emit(3) to product output that is described in a format string. A “field descriptor” tells libxo what the field is and what it means. Each field descriptor is placed in braces with a printf-like format string:

    xo_emit(" {:lines/%7ju} {:words/%7ju} "
            "{:characters/%7ju}{d:filename/%s}\n",
            linect, wordct, charct, file);

Each field can have a role, with the 'value' role being the default, and the role tells libxo how and when to render that field, as well as a printf(3)-like format string.

Output can then be generated in various style, using the "--libxo" option.

Handles give an abstraction for libxo that encapsulates the state of a stream of output. Handles have the data type "xo_handle_t" and are opaque to the caller.

The library has a default handle that is automatically initialized. By default, this handle will send text style output to standard output. The xo_set_style(3) and xo_set_flags(3) functions can be used to change this behavior.

Many libxo functions take a handle as their first parameter; most that do not use the default handle. Any function taking a handle can be passed NULL to access the default handle.

For the typical command that is generating output on standard output, there is no need to create an explicit handle, but they are available when needed, e.g., for daemons that generate multiple streams of output.

The libxo library includes the following functions:

 
()
 
()
 
()
Allows the caller to emit XML attributes with the next open element.
()
 
()
Allow the caller to create a new handle. Note that libxo has a default handle that allows the caller to avoid use of an explicitly created handle. Only callers writing to files other than stdout would need to call xo_create().
()
Frees any resources associated with the handle, including the handle itself.
()
 
()
 
()
Emit formatted output. The fmt string controls the conversion of the remaining arguments into formatted output. See xo_format(5) for details.
()
 
()
 
()
 
()
 
()
 
()
 
()
These functions are mildly compatible with their standard libc namesakes, but use the format string defined in xo_format(5). While there is an increased cost for converting the strings, the output provided can be richer and more useful. See also xo_err(3)
()
 
()
 
()
 
()
 
()
 
()
 
()
 
()
 
()
 
()
 
()
These functions are meant to be compatible with their standard libc namesakes.
()
 
()
Flush output, close open construct, and complete any pending operations.
()
 
()
Allow the caller to flush any pending output for a handle.
()
Direct libxo to avoid initializing the locale. This function should be called before any other libxo function is called.
()
 
()
 
()
 
()
 
()
 
()
 
()
 
()
Containers a singleton levels of hierarchy, typically used to organize related content.
()
 
()
 
()
 
()
 
()
 
()
 
()
 
()
 
()
 
()
 
()
 
()
 
()
 
()
 
()
 
()
Lists are levels of hierarchy that can appear multiple times within the same parent. Two calls are needed to encapsulate them, one for the list and one for each instance of that list. Typically xo_open_list() and xo_close_list() are called outside a for-loop, where xo_open_instance() it called at the top of the loop, and xo_close_instance() is called at the bottom of the loop.
()
Inspects command line arguments for directions to libxo. This function should be called before argv is inspected by the application.
()
Instructs libxo to use an alternative memory allocator and deallocator.
()
 
()
Change the flags set for a handle.
()
Provides additional information about elements for use with HTML rendering.
()
Changes formatting options used by handle.
()
 
()
Changes the output style used by a handle.
()
Instructs libxo to use an alternative set of low-level output functions.

xo(1), xolint(1), xo_attr(3), xo_create(3), xo_emit(3), xo_emit_err(3), xo_err(3), xo_finish(3), xo_flush(3), xo_no_setlocale(3), xo_open_container(3), xo_open_list(3), xo_parse_args(3), xo_set_allocator(3), xo_set_flags(3), xo_set_info(3), xo_set_options(3), xo_set_style(3), xo_set_writer(3), xo_format(5)

The libxo library first appeared in FreeBSD 11.0.

libxo was written by Phil Shafer <phil@freebsd.org>.

December 8, 2014 midnightbsd-3.1