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