LIBXO(3)

πŸ“¦
version 1.7.5 Β· 2 versions
, in epel 9, fedora 43, fedora 44, nixpkgs unstable

πŸ’– LIBXO(3) β€” the libxo manual page, section 3 (Library Functions Manual) πŸ’–

okay bestie, we're doing the libxo library pages and this one is about setting the field information data. it's giving "make your HTML data attributes slay" and honestly? iconic. let's get into it 🫢


✨ NAME ✨

xo_set_info β€” set the field information data for libxo

no cap, that's the whole job. one function, one mission. πŸ’…


πŸ“š LIBRARY πŸ“š

library β€œlibxo”


🌸 SYNOPSIS 🌸

#include <libxo/xo.h>

void
xo_set_info(xo_handle_t *handle, xo_info_t *info, int count);

three args, zero drama. okurrr. ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the vibe: HTML data can carry extra info in attributes that start with "data-". literally the little metadata besties. to make that happen, three things must occur β€” and yes, all three, we're not skipping steps. πŸ™ˆ

First, the application has to build an array of xo_info_t structures, one per tag. and the array must be sorted by name, because libxo uses a binary search to find the entry that matches names from format instructions. like, it's not scrolling the whole list, it's binary searching, so if you hand it unsorted data it will simply not find your stuff. bestie. sort it. 😭

the xo_info_t structure is defined in <libxo/xo.h>:

typedef struct xo_info_s {
    const char *xi_name;    /* Name of the element */
    const char *xi_type;    /* Type of field */
    const char *xi_help;    /* Description of field */
} xo_info_t;

name, type, help. that's the trio. πŸ‘‘

Second, the application must inform libxo about this information using the xo_set_info() call. and like other libxo calls, passing NULL for the handle tells libxo to use the default handle β€” so you don't gotta manage handles if you don't wanna.

now, about the count: if the count is -1, libxo will count the elements of info but there must be an empty element at the end. that's the deal, that's the rule. more typically tho, the number is known to the application:

xo_info_t info[] = {
    { "in-stock", "number", "Number of items in stock" },
    { "name", "string", "Name of the item" },
    { "on-order", "number", "Number of items on order" },
    { "sku", "string", "Stock Keeping Unit" },
    { "sold", "number", "Number of items sold" },
};
int info_count = (sizeof(info) / sizeof(info[0]));
...
xo_set_info(NULL, info, info_count);

look at that sizeof(info) / sizeof(info[0]) β€” the classic "how many things are in my array" move. we love a self-counting array. πŸŽ€

Third, the emission of info must be triggered with the XOF_INFO flag using either the xo_set_flags() function or the β€œ--libxo=info” command line argument. no flag, no data attributes. the info just sits there. vibes only, no output. πŸ’€

and the type and help values, if present, are emitted as the "data-type" and "data-help" attributes:

<div class="data" data-tag="sku" data-type="string"
     data-help="Stock Keeping Unit">GRO-000-533</div>

see how sku got matched up with "string" and "Stock Keeping Unit"?? that's the whole point bestie, that's the glow-up. ✨


πŸ”₯ SEE ALSO πŸ”₯

go read those next, i'm literally begging. πŸ₯Ί


πŸ“œ HISTORY πŸ“œ

The libxo library first appeared in FreeBSD 11.0. a whole era. 🌈


πŸ‘‘ AUTHORS πŸ‘‘

libxo was written by Phil Shafer <phil@freebsd.org>. king behavior, fr fr. πŸ’œ


πŸ“– ADDITIONAL DOCUMENTATION πŸ“–

FreeBSD uses libxo version 1.7.5. Complete documentation can be found on github:

https://juniper.github.io/libxo/1.7.5/html/index.html

libxo lives on github as:

https://github.com/Juniper/libxo

The latest release of libxo is available at:

https://github.com/Juniper/libxo/releases

three links, all the lore, go read. 🧚


πŸ“œ HISTORY πŸ“œ

The libxo library was added in FreeBSD 11.0.

yes bestie, this section really does show up twice in the original. i'm not merging them. we keep every detail in this house. πŸ’…

πŸ‘‘ AUTHOR πŸ‘‘

Phil Shafer


and that's the whole page, angel!! πŸŽ€ this one shipped as part of Debian, dated December 4, 2014, in the LIBXO(3) manual. mwah. go forth and set your info arrays β€” sorted, obviously. πŸ˜˜πŸ’–πŸ¦‹

πŸ“¦ where this page comes from