xref: /netbsd-src/external/bsd/mdocml/dist/mchars_alloc.3 (revision 9ff1f2ac944731963b1d62cde605dabb5cb29a3a)
1*9ff1f2acSchristos.\"	Id: mchars_alloc.3,v 1.4 2016/07/07 19:19:01 schwarze Exp
2fec65c98Schristos.\"
3fec65c98Schristos.\" Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
4fec65c98Schristos.\"
5fec65c98Schristos.\" Permission to use, copy, modify, and distribute this software for any
6fec65c98Schristos.\" purpose with or without fee is hereby granted, provided that the above
7fec65c98Schristos.\" copyright notice and this permission notice appear in all copies.
8fec65c98Schristos.\"
9fec65c98Schristos.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10fec65c98Schristos.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11fec65c98Schristos.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12fec65c98Schristos.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13fec65c98Schristos.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14fec65c98Schristos.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15fec65c98Schristos.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16fec65c98Schristos.\"
17*9ff1f2acSchristos.Dd July 7, 2016
18fec65c98Schristos.Dt MCHARS_ALLOC 3
19fec65c98Schristos.Os
20fec65c98Schristos.Sh NAME
21fec65c98Schristos.Nm mchars_alloc ,
22fec65c98Schristos.Nm mchars_free ,
23fec65c98Schristos.Nm mchars_num2char ,
24fec65c98Schristos.Nm mchars_num2uc ,
25fec65c98Schristos.Nm mchars_spec2cp ,
26*9ff1f2acSchristos.Nm mchars_spec2str ,
27*9ff1f2acSchristos.Nm mchars_uc2str
28fec65c98Schristos.Nd character table for mandoc
29fec65c98Schristos.Sh SYNOPSIS
30fec65c98Schristos.In sys/types.h
31fec65c98Schristos.In mandoc.h
32fec65c98Schristos.Ft void
33*9ff1f2acSchristos.Fn mchars_alloc void
34*9ff1f2acSchristos.Ft void
35*9ff1f2acSchristos.Fn mchars_free void
36fec65c98Schristos.Ft char
37fec65c98Schristos.Fo mchars_num2char
38fec65c98Schristos.Fa "const char *decimal"
39fec65c98Schristos.Fa "size_t sz"
40fec65c98Schristos.Fc
41fec65c98Schristos.Ft int
42fec65c98Schristos.Fo mchars_num2uc
43fec65c98Schristos.Fa "const char *hexadecimal"
44fec65c98Schristos.Fa "size_t sz"
45fec65c98Schristos.Fc
46fec65c98Schristos.Ft int
47fec65c98Schristos.Fo mchars_spec2cp
48fec65c98Schristos.Fa "const char *name"
49fec65c98Schristos.Fa "size_t sz"
50fec65c98Schristos.Fc
51fec65c98Schristos.Ft "const char *"
52fec65c98Schristos.Fo mchars_spec2str
53fec65c98Schristos.Fa "const char *name"
54fec65c98Schristos.Fa "size_t sz"
55fec65c98Schristos.Fa "size_t *rsz"
56fec65c98Schristos.Fc
57fec65c98Schristos.Ft "const char *"
58fec65c98Schristos.Fn mchars_uc2str "int codepoint"
59fec65c98Schristos.Sh DESCRIPTION
60fec65c98SchristosThese functions translate Unicode character numbers and
61fec65c98Schristos.Xr roff 7
62fec65c98Schristoscharacter names into glyphs.
63fec65c98SchristosSee
64fec65c98Schristos.Xr mandoc_char 7
65fec65c98Schristosfor a list of
66fec65c98Schristos.Xr roff 7
67fec65c98Schristosspecial characters.
68fec65c98SchristosThese functions are intended for external use by programs formatting
69fec65c98Schristos.Xr mdoc 7
70fec65c98Schristosand
71fec65c98Schristos.Xr man 7
72fec65c98Schristospages for output, for example the
73fec65c98Schristos.Xr mandoc 1
74fec65c98Schristosoutput formatter modules and
75fec65c98Schristos.Xr makewhatis 8 .
76fec65c98SchristosThe
77fec65c98Schristos.Fa decimal ,
78fec65c98Schristos.Fa hexadecimal ,
79fec65c98Schristos.Fa name ,
80fec65c98Schristosand
81fec65c98Schristos.Fa size
82fec65c98Schristosinput arguments are usually obtained from the
83fec65c98Schristos.Xr mandoc_escape 3
84fec65c98Schristosparser function.
85fec65c98Schristos.Pp
86fec65c98SchristosThe function
87fec65c98Schristos.Fn mchars_num2char
88fec65c98Schristosconverts a
89fec65c98Schristos.Fa decimal
90fec65c98Schristosstring representation of a character number consisting of
91fec65c98Schristos.Fa sz
92fec65c98Schristosdigits into a printable ASCII character.
93fec65c98SchristosIf the input string is non-numeric or does not represent a printable
94fec65c98SchristosASCII character, the NUL character
95fec65c98Schristos.Pq Sq \e0
96fec65c98Schristosis returned.
97fec65c98SchristosFor example, the
98fec65c98Schristos.Xr mandoc 1
99fec65c98Schristos.Fl Tascii ,
100fec65c98Schristos.Fl Tutf8 ,
101fec65c98Schristosand
102fec65c98Schristos.Fl Thtml
103fec65c98Schristosoutput modules use this function to render
104fec65c98Schristos.Xr roff 7
105fec65c98Schristos.Ic \eN
106fec65c98Schristosescape sequences.
107fec65c98Schristos.Pp
108fec65c98SchristosThe function
109fec65c98Schristos.Fn mchars_num2uc
110fec65c98Schristosconverts a
111fec65c98Schristos.Fa hexadecimal
112fec65c98Schristosstring representation of a Unicode codepoint consisting of
113fec65c98Schristos.Fa sz
114fec65c98Schristosdigits into an integer representation.
115fec65c98SchristosIf the input string is non-numeric or represents an ASCII character,
116fec65c98Schristosthe NUL character
117fec65c98Schristos.Pq Sq \e0
118fec65c98Schristosis returned.
119fec65c98SchristosFor example, the
120fec65c98Schristos.Xr mandoc 1
121fec65c98Schristos.Fl Tutf8
122fec65c98Schristosand
123fec65c98Schristos.Fl Thtml
124fec65c98Schristosoutput modules use this function to render
125fec65c98Schristos.Xr roff 7
126fec65c98Schristos.Ic \e[u Ns Ar XXXX Ns Ic \&]
127fec65c98Schristosand
128fec65c98Schristos.Ic \eC\(aqu Ns Ar XXXX Ns Ic \(aq
129fec65c98Schristosescape sequences.
130fec65c98Schristos.Pp
131fec65c98SchristosThe function
132fec65c98Schristos.Fn mchars_alloc
133*9ff1f2acSchristosinitializes a static
134*9ff1f2acSchristos.Vt "struct ohash"
135*9ff1f2acSchristosobject for subsequent use by the following two lookup functions.
136fec65c98SchristosWhen no longer needed, this object can be destroyed with
137fec65c98Schristos.Fn mchars_free .
138fec65c98Schristos.Pp
139fec65c98SchristosThe function
140fec65c98Schristos.Fn mchars_spec2cp
141fec65c98Schristoslooks up a
142fec65c98Schristos.Xr roff 7
143fec65c98Schristosspecial character
144fec65c98Schristos.Fa name
145fec65c98Schristosconsisting of
146fec65c98Schristos.Fa sz
147*9ff1f2acSchristoscharacters and returns the corresponding Unicode codepoint.
148fec65c98SchristosIf the
149fec65c98Schristos.Ar name
150fec65c98Schristosis not recognized, \-1 is returned.
151fec65c98SchristosFor example, the
152fec65c98Schristos.Xr mandoc 1
153fec65c98Schristos.Fl Tutf8
154fec65c98Schristosand
155fec65c98Schristos.Fl Thtml
156fec65c98Schristosoutput modules use this function to render
157fec65c98Schristos.Xr roff 7
158fec65c98Schristos.Ic \e[ Ns Ar name Ns Ic \&]
159fec65c98Schristosand
160fec65c98Schristos.Ic \eC\(aq Ns Ar name Ns Ic \(aq
161fec65c98Schristosescape sequences.
162fec65c98Schristos.Pp
163fec65c98SchristosThe function
164fec65c98Schristos.Fn mchars_spec2str
165fec65c98Schristoslooks up a
166fec65c98Schristos.Xr roff 7
167fec65c98Schristosspecial character
168fec65c98Schristos.Fa name
169fec65c98Schristosconsisting of
170fec65c98Schristos.Fa sz
171*9ff1f2acSchristoscharacters and returns an ASCII string representation.
172fec65c98SchristosThe length of the representation is returned in
173fec65c98Schristos.Fa rsz .
174fec65c98SchristosIn many cases, the meaning of such ASCII representations
175fec65c98Schristosis not quite obvious, so using
176fec65c98Schristos.Xr roff 7
177fec65c98Schristosspecial characters in documents intended for ASCII rendering
178fec65c98Schristosis usually a bad idea.
179fec65c98SchristosIf the
180fec65c98Schristos.Ar name
181fec65c98Schristosis not recognized,
182fec65c98Schristos.Dv NULL
183fec65c98Schristosis returned.
184fec65c98SchristosFor example,
185fec65c98Schristos.Xr makewhatis 8
186fec65c98Schristosand the
187fec65c98Schristos.Xr mandoc 1
188fec65c98Schristos.Fl Tascii
189fec65c98Schristosoutput module use this function to render
190fec65c98Schristos.Xr roff 7
191fec65c98Schristos.Ic \e[ Ns Ar name Ns Ic \&]
192fec65c98Schristosand
193fec65c98Schristos.Ic \eC\(aq Ns Ar name Ns Ic \(aq
194fec65c98Schristosescape sequences.
195fec65c98Schristos.Pp
196fec65c98SchristosThe function
197fec65c98Schristos.Fn mchars_uc2str
198fec65c98Schristosperforms a reverse lookup of the Unicode
199fec65c98Schristos.Fa codepoint
200fec65c98Schristosand returns an ASCII string representation, or the string
201fec65c98Schristos.Qq <?>
202fec65c98Schristosif none is available.
203fec65c98Schristos.Sh FILES
204fec65c98SchristosThese funtions are implemented in the file
205fec65c98Schristos.Pa chars.c .
206fec65c98Schristos.Sh SEE ALSO
207fec65c98Schristos.Xr mandoc 1 ,
208fec65c98Schristos.Xr mandoc_escape 3 ,
209*9ff1f2acSchristos.Xr ohash_init 3 ,
210fec65c98Schristos.Xr mandoc_char 7 ,
211fec65c98Schristos.Xr roff 7
212fec65c98Schristos.Sh HISTORY
213fec65c98SchristosThese functions and their predecessors have been available since the
214fec65c98Schristosfollowing mandoc versions:
215fec65c98Schristos.Bl -column "mchars_num2char()" "1.11.3" "chars_num2char()" "1.10.10"
216fec65c98Schristos.It Sy function Ta since Ta Sy predecessor Ta since
217fec65c98Schristos.It Fn mchars_alloc Ta 1.11.3 Ta Fn ascii2htab Ta 1.5.3
218fec65c98Schristos.It Fn mchars_free Ta 1.11.2 Ta Fn asciifree Ta 1.6.0
219fec65c98Schristos.It Fn mchars_num2char Ta 1.11.2 Ta Fn chars_num2char Ta 1.10.10
220fec65c98Schristos.It Fn mchars_num2uc Ta 1.11.3 Ta \(em Ta \(em
221fec65c98Schristos.It Fn mchars_spec2cp Ta 1.11.2 Ta Fn chars_spec2cp Ta 1.10.5
222fec65c98Schristos.It Fn mchars_spec2str Ta 1.11.2 Ta Fn a2ascii Ta 1.5.3
223fec65c98Schristos.It Fn mchars_uc2str Ta 1.13.2 Ta \(em Ta \(em
224fec65c98Schristos.El
225fec65c98Schristos.Sh AUTHORS
226fec65c98Schristos.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
227fec65c98Schristos.An Ingo Schwarze Aq Mt schwarze@openbsd.org
228