xref: /freebsd/contrib/mandoc/mandoc_headers.3 (revision f4f56ff43dbd30930f4b018e39ba2b9abf84551f)
1.\"	$Id: mandoc_headers.3,v 1.34 2021/08/10 12:55:03 schwarze Exp $
2.\"
3.\" Copyright (c) 2014-2021 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: August 10 2021 $
18.Dt MANDOC_HEADERS 3
19.Os
20.Sh NAME
21.Nm mandoc_headers
22.Nd ordering of mandoc include files
23.Sh DESCRIPTION
24To support a cleaner coding style, the mandoc header files do not
25contain any include directives and do not guard against multiple
26inclusion.
27The application developer has to make sure that the headers are
28included in a proper order, and that no header is included more
29than once.
30.Pp
31The headers and functions form three major groups:
32.Sx Parser interface ,
33.Sx Parser internals ,
34and
35.Sx Formatter interface .
36.Pp
37Various rules are given below prohibiting the inclusion of certain
38combinations of headers into the same file.
39The intention is to keep the following functional components
40separate from each other:
41.Pp
42.Bl -dash -offset indent -compact
43.It
44.Xr roff 7
45parser
46.It
47.Xr mdoc 7
48parser
49.It
50.Xr man 7
51parser
52.It
53.Xr tbl 7
54parser
55.It
56.Xr eqn 7
57parser
58.It
59terminal formatters
60.It
61HTML formatters
62.It
63search tools
64.It
65main programs
66.El
67.Pp
68Note that mere usage of an opaque struct type does
69.Em not
70require inclusion of the header where that type is defined.
71.Ss Parser interface
72Each of the following headers can be included without including
73any other mandoc header.
74These headers should be included before any other mandoc headers.
75.Bl -tag -width Ds
76.It Qq Pa mandoc_aux.h
77Memory allocation utility functions; can be used everywhere.
78.Pp
79Requires
80.In sys/types.h
81for
82.Vt size_t .
83.Pp
84Provides the functions documented in
85.Xr mandoc_malloc 3 .
86.It Qq Pa mandoc_ohash.h
87Hashing utility functions; can be used everywhere.
88.Pp
89Requires
90.In stddef.h
91for
92.Vt ptrdiff_t
93and
94.In stdint.h
95for
96.Vt uint32_t .
97.Pp
98Includes
99.In ohash.h
100and provides
101.Fn mandoc_ohash_init .
102.It Qq Pa mandoc.h
103Error handling, escape sequence, and character utilities;
104can be used everywhere.
105.Pp
106Requires
107.In sys/types.h
108for
109.Vt size_t
110and
111.In stdio.h
112for
113.Vt FILE .
114.Pp
115Provides
116.Vt enum mandoc_esc ,
117.Vt enum mandocerr ,
118.Vt enum mandoclevel ,
119the function
120.Xr mandoc_escape 3 ,
121the functions described in
122.Xr mchars_alloc 3 ,
123and the
124.Fn mandoc_msg*
125functions.
126.It Qq Pa roff.h
127Common data types for all syntax trees and related functions;
128can be used everywhere.
129.Pp
130Provides
131.Vt enum mandoc_os ,
132.Vt enum mdoc_endbody ,
133.Vt enum roff_macroset ,
134.Vt enum roff_sec ,
135.Vt enum roff_tok ,
136.Vt enum roff_type ,
137.Vt struct roff_man ,
138.Vt struct roff_meta ,
139.Vt struct roff_node ,
140the constant array
141.Va roff_name
142and the function
143.Fn deroff .
144.Pp
145Uses pointers to the types
146.Vt struct ohash
147from
148.Qq Pa mandoc_ohash.h ,
149.Vt struct mdoc_arg
150and
151.Vt union mdoc_data
152from
153.Qq Pa mdoc.h ,
154.Vt struct tbl_span
155from
156.Qq Pa tbl.h ,
157and
158.Vt struct eqn_box
159from
160.Qq Pa eqn.h
161as opaque struct members.
162.It Qq Pa tbl.h
163Data structures for the
164.Xr tbl 7
165parse tree; can be used everywhere.
166.Pp
167Requires
168.In sys/types.h
169for
170.Vt size_t
171and
172.Qq Pa mandoc.h
173for
174.Vt enum mandoc_esc .
175.Pp
176Provides
177.Vt enum tbl_cellt ,
178.Vt enum tbl_datt ,
179.Vt enum tbl_spant ,
180.Vt struct tbl_opts ,
181.Vt struct tbl_cell ,
182.Vt struct tbl_row ,
183.Vt struct tbl_dat ,
184and
185.Vt struct tbl_span .
186.It Qq Pa eqn.h
187Data structures for the
188.Xr eqn 7
189parse tree; can be used everywhere.
190.Pp
191Requires
192.In sys/types.h
193for
194.Vt size_t .
195.Pp
196Provides
197.Vt enum eqn_boxt ,
198.Vt enum eqn_fontt ,
199.Vt enum eqn_post ,
200and
201.Vt struct eqn_box .
202.It Qq Pa mandoc_parse.h
203Top level parser interface, for use in the main program
204and in the main parser, but not in formatters.
205.Pp
206Requires
207.Qq Pa mandoc.h
208for
209.Vt enum mandocerr
210and
211.Vt enum mandoclevel
212and
213.Qq Pa roff.h
214for
215.Vt enum mandoc_os .
216.Pp
217Uses the opaque type
218.Vt struct mparse
219from
220.Pa read.c
221for function prototypes.
222Uses
223.Vt struct roff_meta
224from
225.Qq Pa roff.h
226as an opaque type for function prototypes.
227.It Qq Pa mandoc_xr.h
228Cross reference validation; intended for use in the main program
229and in parsers, but not in formatters.
230.Pp
231Provides
232.Vt struct mandoc_xr
233and the functions
234.Fn mandoc_xr_reset ,
235.Fn mandoc_xr_add ,
236.Fn mandoc_xr_get ,
237and
238.Fn mandoc_xr_free .
239.It Qq Pa tag.h
240Internal interfaces to tag syntax tree nodes,
241for use by validation modules only.
242.Pp
243Requires
244.In limits.h
245for
246.Dv INT_MAX .
247.Pp
248Provides the functions
249.Fn tag_alloc ,
250.Fn tag_put ,
251.Fn tag_check ,
252and
253.Fn tag_free
254and some
255.Dv TAG_*
256constants.
257.Pp
258Uses the type
259.Vt struct roff_node
260from
261.Qq Pa roff.h
262as an opaque type for function prototypes.
263.El
264.Pp
265The following two require
266.Qq Pa roff.h
267but no other mandoc headers.
268Afterwards, any other mandoc headers can be included as needed.
269.Bl -tag -width Ds
270.It Qq Pa mdoc.h
271Requires
272.In sys/types.h
273for
274.Vt size_t .
275.Pp
276Provides
277.Vt enum mdocargt ,
278.Vt enum mdoc_auth ,
279.Vt enum mdoc_disp ,
280.Vt enum mdoc_font ,
281.Vt enum mdoc_list ,
282.Vt struct mdoc_argv ,
283.Vt struct mdoc_arg ,
284.Vt struct mdoc_an ,
285.Vt struct mdoc_bd ,
286.Vt struct mdoc_bf ,
287.Vt struct mdoc_bl ,
288.Vt struct mdoc_rs ,
289.Vt union mdoc_data ,
290and the functions
291.Fn mdoc_*
292described in
293.Xr mandoc 3 .
294.Pp
295Uses the types
296.Vt struct roff_node
297from
298.Qq Pa roff.h
299and
300.Vt struct roff_man
301from
302.Qq Pa roff_int.h
303as opaque types for function prototypes.
304.Pp
305When this header is included, the same file should not include
306internals of different parsers.
307.It Qq Pa man.h
308Provides the functions
309.Fn man_*
310described in
311.Xr mandoc 3 .
312.Pp
313Uses the type
314.Vt struct roff_man
315from
316.Qq Pa roff.h
317as an opaque type for function prototypes.
318.Pp
319When this header is included, the same file should not include
320internals of different parsers.
321.El
322.Ss Parser internals
323Most of the following headers require inclusion of a parser interface header
324before they can be included.
325All parser interface headers should precede all parser internal headers.
326When any parser internal headers are included, the same file should
327not include any formatter headers.
328.Bl -tag -width Ds
329.It Qq Pa libmandoc.h
330Requires
331.In sys/types.h
332for
333.Vt size_t
334and
335.Qq Pa mandoc.h
336for
337.Vt enum mandocerr .
338.Pp
339Provides
340.Vt struct buf ,
341utility functions needed by multiple parsers,
342and the top-level functions to call the parsers.
343.Pp
344Uses the opaque type
345.Vt struct roff
346from
347.Pa roff.c
348for function prototypes.
349Uses the type
350.Vt struct roff_man
351from
352.Qq Pa roff.h
353as an opaque type for function prototypes.
354.It Qq Pa roff_int.h
355Parser internals shared by multiple parsers.
356Can be used in all parsers, but not in main programs or formatters.
357.Pp
358Requires
359.Qq Pa roff.h
360for
361.Vt enum roff_type
362and
363.Vt enum roff_tok .
364.Pp
365Provides
366.Vt enum roff_next ,
367.Vt struct roff_man ,
368functions named
369.Fn roff_*
370to handle roff nodes,
371.Fn roffhash_alloc ,
372.Fn roffhash_find ,
373.Fn roffhash_free ,
374and
375.Fn roff_validate ,
376and the two special functions
377.Fn man_breakscope
378and
379.Fn mdoc_argv_free
380because the latter two are needed by
381.Pa roff.c .
382.Pp
383Uses the types
384.Vt struct ohash
385from
386.Qq Pa mandoc_ohash.h ,
387.Vt struct roff_node
388and
389.Vt struct roff_meta
390from
391.Qq Pa roff.h ,
392.Vt struct roff
393from
394.Pa roff.c ,
395and
396.Vt struct mdoc_arg
397from
398.Qq Pa mdoc.h
399as opaque types for function prototypes.
400.It Qq Pa libmdoc.h
401Requires
402.Qq Pa roff.h
403for
404.Vt enum roff_tok
405and
406.Vt enum roff_sec .
407.Pp
408Provides
409.Vt enum margserr ,
410.Vt enum mdelim ,
411.Vt struct mdoc_macro ,
412and many functions internal to the
413.Xr mdoc 7
414parser.
415.Pp
416Uses the types
417.Vt struct roff_node
418from
419.Qq Pa roff.h ,
420.Vt struct roff_man
421from
422.Qq Pa roff_int.h ,
423and
424.Vt struct mdoc_arg
425from
426.Qq Pa mdoc.h
427as opaque types for function prototypes.
428.Pp
429When this header is included, the same file should not include
430interfaces of different parsers.
431.It Qq Pa libman.h
432Requires
433.Qq Pa roff.h
434for
435.Vt enum roff_tok .
436.Pp
437Provides
438.Vt struct man_macro
439and some functions internal to the
440.Xr man 7
441parser.
442.Pp
443Uses the types
444.Vt struct roff_node
445from
446.Qq Pa roff.h
447and
448.Vt struct roff_man
449from
450.Qq Pa roff_int.h
451as opaque types for function prototypes.
452.Pp
453When this header is included, the same file should not include
454interfaces of different parsers.
455.It Qq Pa eqn_parse.h
456External interface of the
457.Xr eqn 7
458parser, for use in the
459.Xr roff 7
460and
461.Xr eqn 7
462parsers only.
463.Pp
464Requires
465.In sys/types.h
466for
467.Vt size_t .
468.Pp
469Provides
470.Vt struct eqn_node
471and the functions
472.Fn eqn_alloc ,
473.Fn eqn_box_new ,
474.Fn eqn_box_free ,
475.Fn eqn_free ,
476.Fn eqn_parse ,
477.Fn eqn_read ,
478and
479.Fn eqn_reset .
480.Pp
481Uses the type
482.Vt struct eqn_box
483from
484.Qq Pa mandoc.h
485as an opaque type for function prototypes.
486Uses the types
487.Vt struct roff_node
488from
489.Qq Pa roff.h
490and
491.Vt struct eqn_def
492from
493.Pa eqn.c
494as opaque struct members.
495.Pp
496When this header is included, the same file should not include
497internals of different parsers.
498.It Qq Pa tbl_parse.h
499External interface of the
500.Xr tbl 7
501parser, for use in the
502.Xr roff 7
503and
504.Xr tbl 7
505parsers only.
506.Pp
507Provides the functions documented in
508.Xr tbl 3 .
509.Pp
510Uses the types
511.Vt struct tbl_span
512from
513.Qq Pa tbl.h
514and
515.Vt struct tbl_node
516from
517.Qq Pa tbl_int.h
518as opaque types for function prototypes.
519.Pp
520When this header is included, the same file should not include
521internals of different parsers.
522.It Qq Pa tbl_int.h
523Internal interfaces of the
524.Xr tbl 7
525parser, for use inside the
526.Xr tbl 7
527parser only.
528.Pp
529Requires
530.Qq Pa tbl.h
531for
532.Vt struct tbl_opts .
533.Pp
534Provides
535.Vt enum tbl_part ,
536.Vt struct tbl_node ,
537and the functions
538.Fn tbl_option ,
539.Fn tbl_layout ,
540.Fn tbl_data ,
541.Fn tbl_cdata ,
542and
543.Fn tbl_reset .
544.Pp
545When this header is included, the same file should not include
546interfaces of different parsers.
547.El
548.Ss Formatter interface
549These headers should be included after any parser interface headers.
550No parser internal headers should be included by the same file.
551.Bl -tag -width Ds
552.It Qq Pa out.h
553Requires
554.In sys/types.h
555for
556.Vt size_t .
557.Pp
558Provides
559.Vt enum roffscale ,
560.Vt struct roffcol ,
561.Vt struct roffsu ,
562.Vt struct rofftbl ,
563.Fn a2roffsu ,
564and
565.Fn tblcalc .
566.Pp
567Uses
568.Vt struct tbl_span
569from
570.Qq Pa mandoc.h
571as an opaque type for function prototypes.
572.Pp
573When this header is included, the same file should not include
574.Qq Pa mansearch.h .
575.It Qq Pa term.h
576Requires
577.In sys/types.h
578for
579.Vt size_t
580and
581.Qq Pa out.h
582for
583.Vt struct roffsu
584and
585.Vt struct rofftbl .
586.Pp
587Provides
588.Vt enum termenc ,
589.Vt enum termfont ,
590.Vt enum termtype ,
591.Vt struct termp_tbl ,
592.Vt struct termp ,
593.Fn roff_term_pre ,
594and many terminal formatting functions.
595.Pp
596Uses the opaque type
597.Vt struct termp_ps
598from
599.Pa term_ps.c .
600Uses
601.Vt struct tbl_span
602and
603.Vt struct eqn_box
604from
605.Qq Pa mandoc.h
606and
607.Vt struct roff_meta
608and
609.Vt struct roff_node
610from
611.Qq Pa roff.h
612as opaque types for function prototypes.
613.Pp
614When this header is included, the same file should not include
615.Qq Pa html.h
616or
617.Qq Pa mansearch.h .
618.It Qq Pa tag_term.h
619Requires
620.In sys/types.h
621for
622.Vt size_t
623and
624.In stdio.h
625for
626.Vt FILE .
627.Pp
628Provides an interface to generate
629.Xr ctags 1
630files for the
631.Ic :t
632functionality mentioned in
633.Xr man 1 .
634.Pp
635Uses the type
636.Vt struct roff_node
637from
638.Qq Pa roff.h
639as an opaque type for function prototypes.
640.Pp
641When this header is included, the same file should not include
642.Qq Pa html.h
643or
644.Qq Pa mansearch.h .
645.It Qq Pa html.h
646Requires
647.In sys/types.h
648for
649.Vt size_t ,
650.Qq Pa mandoc.h
651for
652.Vt enum mandoc_esc ,
653.Qq Pa roff.h
654for
655.Vt enum roff_tok ,
656and
657.Qq Pa out.h
658for
659.Vt struct roffsu
660and
661.Vt struct rofftbl .
662.Pp
663Provides
664.Vt enum htmltag ,
665.Vt enum htmlattr ,
666.Vt enum htmlfont ,
667.Vt struct tag ,
668.Vt struct tagq ,
669.Vt struct htmlpair ,
670.Vt struct html ,
671.Fn roff_html_pre ,
672and many HTML formatting functions.
673.Pp
674Uses
675.Vt struct tbl_span
676and
677.Vt struct eqn_box
678from
679.Qq Pa mandoc.h
680and
681.Vt struct roff_node
682from
683.Qq Pa roff.h
684as opaque types for function prototypes.
685.Pp
686When this header is included, the same file should not include
687.Qq Pa term.h ,
688.Qq Pa tab_term.h ,
689or
690.Qq Pa mansearch.h .
691.It Qq Pa main.h
692Provides the top level steering functions for all formatters.
693.Pp
694Uses the type
695.Vt struct roff_meta
696from
697.Qq Pa roff.h
698as an opaque type for function prototypes.
699.It Qq Pa manconf.h
700Requires
701.In sys/types.h
702for
703.Vt size_t .
704.Pp
705Provides
706.Vt struct manconf ,
707.Vt struct manpaths ,
708.Vt struct manoutput ,
709and the functions
710.Fn manconf_parse ,
711.Fn manconf_output ,
712.Fn manconf_free ,
713and
714.Fn manpath_base .
715.It Qq Pa mansearch.h
716Requires
717.In sys/types.h
718for
719.Vt size_t
720and
721.In stdint.h
722for
723.Vt uint64_t .
724.Pp
725Provides
726.Vt enum argmode ,
727.Vt struct manpage ,
728.Vt struct mansearch ,
729and the functions
730.Fn mansearch
731and
732.Fn mansearch_free .
733.Pp
734Uses
735.Vt struct manpaths
736from
737.Qq Pa manconf.h
738as an opaque type for function prototypes.
739.Pp
740When this header is included, the same file should not include
741.Qq Pa out.h ,
742.Qq Pa term.h ,
743.Qq Pa tab_term.h ,
744or
745.Qq Pa html.h .
746.El
747