LIBXO(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’… LIBXO(3) β€” like, the whole vibe

okay so this is the manual page for libxo(3), straight out of the Library Functions Manual, and it's all about three little functions that literally carry formatted output for the entire library. bestie, this is the main character page. let's go 🫢


✨ NAME ✨

xo_emit, xo_emit_h, xo_emit_hv β€” emit formatted output based on format string and arguments πŸ’–

like yes, that's it, that's the whole job, and they ate.


πŸ“š LIBRARY πŸ“š

library β€œlibxo” β€” that's the one, that's the icon.


πŸŽ€ SYNOPSIS πŸŽ€

#include <libxo/xo.h>

xo_ssize_t
xo_emit(const char *fmt, ...);

xo_ssize_t
xo_emit_h(xo_handle_t *xop, const char *fmt, ...);

xo_ssize_t
xo_emit_hv(xo_handle_t *xop, const char *fmt, va_list vap);

three functions, one header, no notes. slay. πŸ’…


🌸 DESCRIPTION 🌸

okay so the way this works: xo_emit() emits formatted output using the description inside a format string, plus a set of zero or more arguments. it's giving printf(3) energy β€” but the format description string is way more complex, and it's all spelled out in xo_format(5) (go read that one, iykyk). ✨

here's the tea on the differences between the three:

  • xo_emit() uses the default output handle, the one described over in libxo(3). it's the low-effort, high-reward one.
  • xo_emit_h() is the same but with an explicit handle (xop) β€” you're the main character choosing your own destination.
  • xo_emit_hv() accepts a va_list (vap) for additional flexibility. it's for when you've already got your args bundled up and you're not about to unpack them. πŸ¦‹

literally the same core vibe, just different levels of control. pick your fighter.


πŸ”₯ EXAMPLES πŸ”₯

okay this example is iconic so let's actually walk through it. a set of four values gets emitted with this source code:

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

then output can be generated in various styles using the --libxo option. watch this:

% wc /etc/motd
      25     165    1140 /etc/motd

classic. no notes. but thenβ€”

% wc --libxo xml,pretty,warn /etc/motd
<wc>
  <file>
    <lines>25</lines>
    <words>165</words>
    <characters>1140</characters>
    <filename>/etc/motd</filename>
  </file>
</wc>

look at those nested tags. structured. gorgeous. 😭

% wc --libxo json,pretty,warn /etc/motd
{
  "wc": {
    "file": [
      {
        "lines": 25,
        "words": 165,
        "characters": 1140,
        "filename": "/etc/motd"
      }
    ]
  }
}

json version is giving main character energy fr fr. πŸ”₯

% wc --libxo html,pretty,warn /etc/motd
<div class="line">
  <div class="text"> </div>
  <div class="data" data-tag="lines">     25</div>
  <div class="text"> </div>
  <div class="data" data-tag="words">    165</div>
  <div class="text"> </div>
  <div class="data" data-tag="characters">   1140</div>
  <div class="text"> </div>
  <div class="data" data-tag="filename">/etc/motd</div>
</div>

and html! with data-tag attributes and everything. one format string, three whole aesthetics. obsessed. πŸ’œ


πŸ‘‘ RETURN CODE πŸ‘‘

xo_emit returns a negative value on error. that's the bad timeline, avoid it.

but here's the cute part: if the XOF_COLUMNS flag has been turned on for the specific handle using xo_set_flags(3), then the number of display columns consumed by the output gets returned instead. so you're not just emitting, you're measuring. ✨

ngl, the flag is per-handle, so don't assume it's on just because it's on somewhere else. check your handle, bestie. πŸ™ˆ

🌈 SEE ALSO 🌈

this section is genuinely empty in the original β€” no references listed, no cross-links, nothing. so like… that's the list. it's a vibe. πŸ’€


and that's the page!! πŸŽ€

cute little sign-off: this one lives in the Library Functions Manual for libxo(3), and the footer is just the title LIBXO(3) and the manual name Library Functions Manual mirrored right back at you β€” no date, no version, nothing extra. so consider this the official wrap. periodt. πŸ¦‹β­

πŸ“¦ where this page comes from