xref: /freebsd/contrib/mandoc/mandoc_headers.3 (revision c66ec88fed842fbaad62c30d510644ceb7bd2d71)
1.\"	$Id: mandoc_headers.3,v 1.31 2019/03/17 18:21:45 schwarze Exp $
2.\"
3.\" Copyright (c) 2014-2019 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: March 17 2019 $
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 .
171.Pp
172Provides
173.Vt enum tbl_cellt ,
174.Vt enum tbl_datt ,
175.Vt enum tbl_spant ,
176.Vt struct tbl_opts ,
177.Vt struct tbl_cell ,
178.Vt struct tbl_row ,
179.Vt struct tbl_dat ,
180and
181.Vt struct tbl_span .
182.It Qq Pa eqn.h
183Data structures for the
184.Xr eqn 7
185parse tree; can be used everywhere.
186.Pp
187Requires
188.In sys/types.h
189for
190.Vt size_t .
191.Pp
192Provides
193.Vt enum eqn_boxt ,
194.Vt enum eqn_fontt ,
195.Vt enum eqn_post ,
196and
197.Vt struct eqn_box .
198.It Qq Pa mandoc_parse.h
199Top level parser interface, for use in the main program
200and in the main parser, but not in formatters.
201.Pp
202Requires
203.Qq Pa mandoc.h
204for
205.Vt enum mandocerr
206and
207.Vt enum mandoclevel
208and
209.Qq Pa roff.h
210for
211.Vt enum mandoc_os .
212.Pp
213Uses the opaque type
214.Vt struct mparse
215from
216.Pa read.c
217for function prototypes.
218Uses
219.Vt struct roff_meta
220from
221.Qq Pa roff.h
222as an opaque type for function prototypes.
223.It Qq Pa mandoc_xr.h
224Cross reference validation; intended for use in the main program
225and in parsers, but not in formatters.
226.Pp
227Provides
228.Vt struct mandoc_xr
229and the functions
230.Fn mandoc_xr_reset ,
231.Fn mandoc_xr_add ,
232.Fn mandoc_xr_get ,
233and
234.Fn mandoc_xr_free .
235.El
236.Pp
237The following two require
238.Qq Pa roff.h
239but no other mandoc headers.
240Afterwards, any other mandoc headers can be included as needed.
241.Bl -tag -width Ds
242.It Qq Pa mdoc.h
243Requires
244.In sys/types.h
245for
246.Vt size_t .
247.Pp
248Provides
249.Vt enum mdocargt ,
250.Vt enum mdoc_auth ,
251.Vt enum mdoc_disp ,
252.Vt enum mdoc_font ,
253.Vt enum mdoc_list ,
254.Vt struct mdoc_argv ,
255.Vt struct mdoc_arg ,
256.Vt struct mdoc_an ,
257.Vt struct mdoc_bd ,
258.Vt struct mdoc_bf ,
259.Vt struct mdoc_bl ,
260.Vt struct mdoc_rs ,
261.Vt union mdoc_data ,
262and the functions
263.Fn mdoc_*
264described in
265.Xr mandoc 3 .
266.Pp
267Uses the types
268.Vt struct roff_node
269from
270.Qq Pa roff.h
271and
272.Vt struct roff_man
273from
274.Qq Pa roff_int.h
275as opaque types for function prototypes.
276.Pp
277When this header is included, the same file should not include
278internals of different parsers.
279.It Qq Pa man.h
280Provides the functions
281.Fn man_*
282described in
283.Xr mandoc 3 .
284.Pp
285Uses the type
286.Vt struct roff_man
287from
288.Qq Pa roff.h
289as an opaque type for function prototypes.
290.Pp
291When this header is included, the same file should not include
292internals of different parsers.
293.El
294.Ss Parser internals
295Most of the following headers require inclusion of a parser interface header
296before they can be included.
297All parser interface headers should precede all parser internal headers.
298When any parser internal headers are included, the same file should
299not include any formatter headers.
300.Bl -tag -width Ds
301.It Qq Pa libmandoc.h
302Requires
303.In sys/types.h
304for
305.Vt size_t
306and
307.Qq Pa mandoc.h
308for
309.Vt enum mandocerr .
310.Pp
311Provides
312.Vt struct buf ,
313utility functions needed by multiple parsers,
314and the top-level functions to call the parsers.
315.Pp
316Uses the opaque type
317.Vt struct roff
318from
319.Pa roff.c
320for function prototypes.
321Uses the type
322.Vt struct roff_man
323from
324.Qq Pa roff.h
325as an opaque type for function prototypes.
326.It Qq Pa roff_int.h
327Parser internals shared by multiple parsers.
328Can be used in all parsers, but not in main programs or formatters.
329.Pp
330Requires
331.Qq Pa roff.h
332for
333.Vt enum roff_type
334and
335.Vt enum roff_tok .
336.Pp
337Provides
338.Vt enum roff_next ,
339.Vt struct roff_man ,
340functions named
341.Fn roff_*
342to handle roff nodes,
343.Fn roffhash_alloc ,
344.Fn roffhash_find ,
345.Fn roffhash_free ,
346and
347.Fn roff_validate ,
348and the two special functions
349.Fn man_breakscope
350and
351.Fn mdoc_argv_free
352because the latter two are needed by
353.Pa roff.c .
354.Pp
355Uses the types
356.Vt struct ohash
357from
358.Qq Pa mandoc_ohash.h ,
359.Vt struct roff_node
360and
361.Vt struct roff_meta
362from
363.Qq Pa roff.h ,
364.Vt struct roff
365from
366.Pa roff.c ,
367and
368.Vt struct mdoc_arg
369from
370.Qq Pa mdoc.h
371as opaque types for function prototypes.
372.It Qq Pa libmdoc.h
373Requires
374.Qq Pa roff.h
375for
376.Vt enum roff_tok
377and
378.Vt enum roff_sec .
379.Pp
380Provides
381.Vt enum margserr ,
382.Vt enum mdelim ,
383.Vt struct mdoc_macro ,
384and many functions internal to the
385.Xr mdoc 7
386parser.
387.Pp
388Uses the types
389.Vt struct roff_node
390from
391.Qq Pa roff.h ,
392.Vt struct roff_man
393from
394.Qq Pa roff_int.h ,
395and
396.Vt struct mdoc_arg
397from
398.Qq Pa mdoc.h
399as opaque types for function prototypes.
400.Pp
401When this header is included, the same file should not include
402interfaces of different parsers.
403.It Qq Pa libman.h
404Requires
405.Qq Pa roff.h
406for
407.Vt enum roff_tok .
408.Pp
409Provides
410.Vt struct man_macro
411and some functions internal to the
412.Xr man 7
413parser.
414.Pp
415Uses the types
416.Vt struct roff_node
417from
418.Qq Pa roff.h
419and
420.Vt struct roff_man
421from
422.Qq Pa roff_int.h
423as opaque types for function prototypes.
424.Pp
425When this header is included, the same file should not include
426interfaces of different parsers.
427.It Qq Pa eqn_parse.h
428External interface of the
429.Xr eqn 7
430parser, for use in the
431.Xr roff 7
432and
433.Xr eqn 7
434parsers only.
435.Pp
436Requires
437.In sys/types.h
438for
439.Vt size_t .
440.Pp
441Provides
442.Vt struct eqn_node
443and the functions
444.Fn eqn_alloc ,
445.Fn eqn_box_new ,
446.Fn eqn_box_free ,
447.Fn eqn_free ,
448.Fn eqn_parse ,
449.Fn eqn_read ,
450and
451.Fn eqn_reset .
452.Pp
453Uses the type
454.Vt struct eqn_box
455from
456.Qq Pa mandoc.h
457as an opaque type for function prototypes.
458Uses the types
459.Vt struct roff_node
460from
461.Qq Pa roff.h
462and
463.Vt struct eqn_def
464from
465.Pa eqn.c
466as opaque struct members.
467.Pp
468When this header is included, the same file should not include
469internals of different parsers.
470.It Qq Pa tbl_parse.h
471External interface of the
472.Xr tbl 7
473parser, for use in the
474.Xr roff 7
475and
476.Xr tbl 7
477parsers only.
478.Pp
479Provides the functions documented in
480.Xr tbl 3 .
481.Pp
482Uses the types
483.Vt struct tbl_span
484from
485.Qq Pa tbl.h
486and
487.Vt struct tbl_node
488from
489.Qq Pa tbl_int.h
490as opaque types for function prototypes.
491.Pp
492When this header is included, the same file should not include
493internals of different parsers.
494.It Qq Pa tbl_int.h
495Internal interfaces of the
496.Xr tbl 7
497parser, for use inside the
498.Xr tbl 7
499parser only.
500.Pp
501Requires
502.Qq Pa tbl.h
503for
504.Vt struct tbl_opts .
505.Pp
506Provides
507.Vt enum tbl_part ,
508.Vt struct tbl_node ,
509and the functions
510.Fn tbl_option ,
511.Fn tbl_layout ,
512.Fn tbl_data ,
513.Fn tbl_cdata ,
514and
515.Fn tbl_reset .
516.Pp
517When this header is included, the same file should not include
518interfaces of different parsers.
519.El
520.Ss Formatter interface
521These headers should be included after any parser interface headers.
522No parser internal headers should be included by the same file.
523.Bl -tag -width Ds
524.It Qq Pa out.h
525Requires
526.In sys/types.h
527for
528.Vt size_t .
529.Pp
530Provides
531.Vt enum roffscale ,
532.Vt struct roffcol ,
533.Vt struct roffsu ,
534.Vt struct rofftbl ,
535.Fn a2roffsu ,
536and
537.Fn tblcalc .
538.Pp
539Uses
540.Vt struct tbl_span
541from
542.Qq Pa mandoc.h
543as an opaque type for function prototypes.
544.Pp
545When this header is included, the same file should not include
546.Qq Pa mansearch.h .
547.It Qq Pa term.h
548Requires
549.In sys/types.h
550for
551.Vt size_t
552and
553.Qq Pa out.h
554for
555.Vt struct roffsu
556and
557.Vt struct rofftbl .
558.Pp
559Provides
560.Vt enum termenc ,
561.Vt enum termfont ,
562.Vt enum termtype ,
563.Vt struct termp_tbl ,
564.Vt struct termp ,
565.Fn roff_term_pre ,
566and many terminal formatting functions.
567.Pp
568Uses the opaque type
569.Vt struct termp_ps
570from
571.Pa term_ps.c .
572Uses
573.Vt struct tbl_span
574and
575.Vt struct eqn_box
576from
577.Qq Pa mandoc.h
578and
579.Vt struct roff_meta
580and
581.Vt struct roff_node
582from
583.Qq Pa roff.h
584as opaque types for function prototypes.
585.Pp
586When this header is included, the same file should not include
587.Qq Pa html.h
588or
589.Qq Pa mansearch.h .
590.It Qq Pa html.h
591Requires
592.In sys/types.h
593for
594.Vt size_t ,
595.Qq Pa mandoc.h
596for
597.Vt enum mandoc_esc ,
598.Qq Pa roff.h
599for
600.Vt enum roff_tok ,
601and
602.Qq Pa out.h
603for
604.Vt struct roffsu
605and
606.Vt struct rofftbl .
607.Pp
608Provides
609.Vt enum htmltag ,
610.Vt enum htmlattr ,
611.Vt enum htmlfont ,
612.Vt struct tag ,
613.Vt struct tagq ,
614.Vt struct htmlpair ,
615.Vt struct html ,
616.Fn roff_html_pre ,
617and many HTML formatting functions.
618.Pp
619Uses
620.Vt struct tbl_span
621and
622.Vt struct eqn_box
623from
624.Qq Pa mandoc.h
625and
626.Vt struct roff_node
627from
628.Qq Pa roff.h
629as opaque types for function prototypes.
630.Pp
631When this header is included, the same file should not include
632.Qq Pa term.h
633or
634.Qq Pa mansearch.h .
635.It Qq Pa tag.h
636Requires
637.In sys/types.h
638for
639.Vt size_t .
640.Pp
641Provides an interface to generate
642.Xr ctags 1
643files for the
644.Ic :t
645functionality mentioned in
646.Xr man 1 .
647.It Qq Pa main.h
648Provides the top level steering functions for all formatters.
649.Pp
650Uses the type
651.Vt struct roff_meta
652from
653.Qq Pa roff.h
654as an opaque type for function prototypes.
655.It Qq Pa manconf.h
656Requires
657.In sys/types.h
658for
659.Vt size_t .
660.Pp
661Provides
662.Vt struct manconf ,
663.Vt struct manpaths ,
664.Vt struct manoutput ,
665and the functions
666.Fn manconf_parse ,
667.Fn manconf_output ,
668.Fn manconf_free ,
669and
670.Fn manpath_base .
671.It Qq Pa mansearch.h
672Requires
673.In sys/types.h
674for
675.Vt size_t
676and
677.In stdint.h
678for
679.Vt uint64_t .
680.Pp
681Provides
682.Vt enum argmode ,
683.Vt struct manpage ,
684.Vt struct mansearch ,
685and the functions
686.Fn mansearch
687and
688.Fn mansearch_free .
689.Pp
690Uses
691.Vt struct manpaths
692from
693.Qq Pa manconf.h
694as an opaque type for function prototypes.
695.Pp
696When this header is included, the same file should not include
697.Qq Pa out.h ,
698.Qq Pa term.h ,
699or
700.Qq Pa html.h .
701.El
702