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