MCHARS_ALLOC(3)
π MCHARS_ALLOC π β the character table for mandoc, bestie
okay so this is a page from the Library Functions Manual, and it's all about the little glyph-translation squad that lives in mandoc. Pull up a chair, we're decoding characters together π¦
β¨ NAME β¨
mchars_alloc, mchars_free, mchars_num2char, mchars_num2uc, mchars_spec2cp, mchars_spec2str, mchars_uc2str β the character table for mandoc, and yes that's a whole friend group, they come as a set π
πΈ SYNOPSIS πΈ
#include <sys/types.h>
#include <mandoc.h>
void
mchars_alloc(void);
void
mchars_free(void);
char
mchars_num2char(const char *decimal, size_t sz);
int
mchars_num2uc(const char *hexadecimal, size_t sz);
int
mchars_spec2cp(const char *name, size_t sz);
const char *
mchars_spec2str(const char *name, size_t sz, size_t *rsz);
const char *
mchars_uc2str(int codepoint);
π DESCRIPTION π
So here's the vibe: these functions take Unicode character numbers and roff(7) character names and turn them into actual glyphs. If you want the full list of roff(7) special characters, go look at mandoc_char(7) β she has the receipts π
These functions are meant for external use by programs that format mdoc(7) and man(7) pages for output. We're talking the mandoc(1) output formatter modules, and makewhatis(8), stuff like that. And the decimal, hexadecimal, name, and sz input arguments? They usually come straight from the mandoc_escape(3) parser function. Teamwork, honestly π«Ά
mchars_num2char() β takes a decimal string representation of a character number that's sz digits long, and converts it into a printable ASCII character. Now listen: if the input string is non-numeric, or it doesn't represent a printable ASCII character, you get the NUL character ('\0') back. That's the deal. For example, the mandoc(1) -Tascii, -Tutf8, and -Thtml output modules use this function to render roff(7) \N escape sequences β¨
mchars_num2uc() β takes a hexadecimal string representation of a Unicode codepoint that's sz digits long, and converts it into an integer representation. If the input string is non-numeric or represents an ASCII character, the NUL character ('\0') is returned. For example, the mandoc(1) -Tutf8 and -Thtml output modules use this function to render roff(7) \[uXXXX] and \C'uXXXX' escape sequences π₯
mchars_alloc() β initializes a static struct ohash object for subsequent use by the following two lookup functions. When you don't need it anymore, that object can be destroyed with mchars_free(). Clean up after yourself, bestie, it's giving self-care π§
mchars_spec2cp() β looks up a roff(7) special character name that's sz characters long and returns the corresponding Unicode codepoint. If the name isn't recognized? -1. That's it, that's the answer. For example, the mandoc(1) -Tutf8 and -Thtml output modules use this function to render roff(7) \[name] and \C'name' escape sequences π
mchars_spec2str() β looks up a roff(7) special character name that's sz characters long and returns an ASCII string representation. The length of that representation gets handed back to you in rsz. And okay, real talk: in a lot of cases the meaning of these ASCII representations is not quite obvious, so using roff(7) special characters in documents intended for ASCII rendering is usually a bad idea. Noted, we've all been there π If the name isn't recognized, NULL is returned. For example, makewhatis(8) and the mandoc(1) -Tascii output module use this function to render roff(7) \[name] and \C'name' escape sequences π
mchars_uc2str() β does a reverse lookup of the Unicode codepoint and returns an ASCII string representation, or the string "<?>" if none is available. She's doing her best, and honestly? Iconic.
π FILES π
These functions are implemented in the file chars.c.
π SEE ALSO π
mandoc(1), mandoc_escape(3), ohash_init(3), mandoc_char(7), roff(7)
β HISTORY β
These functions and their predecessors have been available since the following mandoc versions β so basically, a whole family tree π³
mchars_alloc()β since1.11.3, predecessorascii2htab()since1.5.3mchars_free()β since1.11.2, predecessorasciifree()since1.6.0mchars_num2char()β since1.11.2, predecessorchars_num2char()since1.10.10mchars_num2uc()β since1.11.3, predecessorβsinceβmchars_spec2cp()β since1.11.2, predecessorchars_spec2cp()since1.10.5mchars_spec2str()β since1.11.2, predecessora2ascii()since1.5.3mchars_uc2str()β since1.13.2, predecessorβsinceβ
π AUTHORS π
- Kristaps Dzonsons
<kristaps@bsd.lv> - Ingo Schwarze
<schwarze@openbsd.org>
and that's the whole page, bestie π shoutout to the Debian crew β this one's dated July 7, 2016, and yeah it still says MCHARS_ALLOC(3) at the bottom like a little signature. periodt π
β¨
π¦ where this page comes from
- alpine 3.22: mandoc-doc 1.14.6-r13 Β· ISC
- alpine 3.23: mandoc-doc 1.14.6-r14 Β· ISC
- alpine 3.24: mandoc-doc 1.14.6-r15 Β· ISC
- debian trixie: libmandoc-dev 1.14.6-4 Β· ISC
- epel 10: libmandoc-devel 1.14.6-11.el10_1 Β· ISC AND BSD-2-Clause AND BSD-3-Clause
- epel 9: libmandoc-devel 1.14.6-2.el9 Β· ISC
- fedora 43: libmandoc-devel 1.14.6-12.fc43 Β· ISC AND BSD-2-Clause AND BSD-3-Clause
- fedora 43: libmandoc-devel 1.14.6-12.fc43 Β· ISC AND BSD-2-Clause AND BSD-3-Clause
- fedora 44: libmandoc-devel 1.14.6-13.fc44 Β· ISC AND BSD-2-Clause AND BSD-3-Clause
- fedora 44: libmandoc-devel 1.14.6-13.fc44 Β· ISC AND BSD-2-Clause AND BSD-3-Clause
- ubuntu questing: libmandoc-dev 1.14.6-4
- ubuntu resolute: libmandoc-dev 1.14.6-4build1 Β· ISC
- ubuntu stonking: libmandoc-dev 1.14.6-4build1 Β· ISC
- Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms