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