1.\" $Id: mandoc_headers.3,v 1.35 2022/04/14 16:43:44 schwarze Exp $ 2.\" 3.\" Copyright (c) 2014-2022 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: April 14 2022 $ 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 the order shown in this manual page, 29and that no header is included more than 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.Pp 87When this header is included, the same file must not include 88.Qq Pa mandoc_dbg.h 89because 90.Qq Pa mandoc_aux.h 91automatically includes 92.Qq Pa mandoc_dbg.h 93if and only if the preprocessor symbol 94.Dv DEBUG_MEMORY 95is defined. 96.It Qq Pa mandoc_dbg.h 97Debugging utility functions and 98debugging wrappers around memory allocation functions. 99.Pp 100Requires 101.In sys/types.h 102for 103.Vt size_t . 104.Pp 105Provides the functions documented in 106.Xr mandoc_dbg_init 3 . 107.Pp 108This header must not be included unless the preprocessor symbol 109.Dv DEBUG_MEMORY 110is defined. 111When this header is included, the same file must not include 112.Qq Pa mandoc_aux.h . 113.It Qq Pa mandoc_ohash.h 114Hashing utility functions; can be used everywhere. 115.Pp 116Requires 117.In stddef.h 118for 119.Vt ptrdiff_t 120and 121.In stdint.h 122for 123.Vt uint32_t . 124.Pp 125Includes 126.In ohash.h 127and provides 128.Fn mandoc_ohash_init . 129.It Qq Pa mandoc.h 130Error handling, escape sequence, and character utilities; 131can be used everywhere. 132.Pp 133Requires 134.In sys/types.h 135for 136.Vt size_t 137and 138.In stdio.h 139for 140.Vt FILE . 141.Pp 142Provides 143.Vt enum mandoc_esc , 144.Vt enum mandocerr , 145.Vt enum mandoclevel , 146the function 147.Xr mandoc_escape 3 , 148the functions described in 149.Xr mchars_alloc 3 , 150and the 151.Fn mandoc_msg* 152functions. 153.It Qq Pa roff.h 154Common data types for all syntax trees and related functions; 155can be used everywhere. 156.Pp 157Provides 158.Vt enum mandoc_os , 159.Vt enum mdoc_endbody , 160.Vt enum roff_macroset , 161.Vt enum roff_sec , 162.Vt enum roff_tok , 163.Vt enum roff_type , 164.Vt struct roff_man , 165.Vt struct roff_meta , 166.Vt struct roff_node , 167the constant array 168.Va roff_name 169and the function 170.Fn deroff . 171.Pp 172Uses pointers to the types 173.Vt struct ohash 174from 175.Qq Pa mandoc_ohash.h , 176.Vt struct mdoc_arg 177and 178.Vt union mdoc_data 179from 180.Qq Pa mdoc.h , 181.Vt struct tbl_span 182from 183.Qq Pa tbl.h , 184and 185.Vt struct eqn_box 186from 187.Qq Pa eqn.h 188as opaque struct members. 189.It Qq Pa tbl.h 190Data structures for the 191.Xr tbl 7 192parse tree; can be used everywhere. 193.Pp 194Requires 195.In sys/types.h 196for 197.Vt size_t 198and 199.Qq Pa mandoc.h 200for 201.Vt enum mandoc_esc . 202.Pp 203Provides 204.Vt enum tbl_cellt , 205.Vt enum tbl_datt , 206.Vt enum tbl_spant , 207.Vt struct tbl_opts , 208.Vt struct tbl_cell , 209.Vt struct tbl_row , 210.Vt struct tbl_dat , 211and 212.Vt struct tbl_span . 213.It Qq Pa eqn.h 214Data structures for the 215.Xr eqn 7 216parse tree; can be used everywhere. 217.Pp 218Requires 219.In sys/types.h 220for 221.Vt size_t . 222.Pp 223Provides 224.Vt enum eqn_boxt , 225.Vt enum eqn_fontt , 226.Vt enum eqn_post , 227and 228.Vt struct eqn_box . 229.It Qq Pa mandoc_parse.h 230Top level parser interface, for use in the main program 231and in the main parser, but not in formatters. 232.Pp 233Requires 234.Qq Pa mandoc.h 235for 236.Vt enum mandocerr 237and 238.Vt enum mandoclevel 239and 240.Qq Pa roff.h 241for 242.Vt enum mandoc_os . 243.Pp 244Uses the opaque type 245.Vt struct mparse 246from 247.Pa read.c 248for function prototypes. 249Uses 250.Vt struct roff_meta 251from 252.Qq Pa roff.h 253as an opaque type for function prototypes. 254.It Qq Pa mandoc_xr.h 255Cross reference validation; intended for use in the main program 256and in parsers, but not in formatters. 257.Pp 258Provides 259.Vt struct mandoc_xr 260and the functions 261.Fn mandoc_xr_reset , 262.Fn mandoc_xr_add , 263.Fn mandoc_xr_get , 264and 265.Fn mandoc_xr_free . 266.It Qq Pa tag.h 267Internal interfaces to tag syntax tree nodes, 268for use by validation modules only. 269.Pp 270Requires 271.In limits.h 272for 273.Dv INT_MAX . 274.Pp 275Provides the functions 276.Fn tag_alloc , 277.Fn tag_put , 278.Fn tag_check , 279and 280.Fn tag_free 281and some 282.Dv TAG_* 283constants. 284.Pp 285Uses the type 286.Vt struct roff_node 287from 288.Qq Pa roff.h 289as an opaque type for function prototypes. 290.El 291.Pp 292The following two require 293.Qq Pa roff.h 294but no other mandoc headers. 295Afterwards, any other mandoc headers can be included as needed. 296.Bl -tag -width Ds 297.It Qq Pa mdoc.h 298Requires 299.In sys/types.h 300for 301.Vt size_t . 302.Pp 303Provides 304.Vt enum mdocargt , 305.Vt enum mdoc_auth , 306.Vt enum mdoc_disp , 307.Vt enum mdoc_font , 308.Vt enum mdoc_list , 309.Vt struct mdoc_argv , 310.Vt struct mdoc_arg , 311.Vt struct mdoc_an , 312.Vt struct mdoc_bd , 313.Vt struct mdoc_bf , 314.Vt struct mdoc_bl , 315.Vt struct mdoc_rs , 316.Vt union mdoc_data , 317and the functions 318.Fn mdoc_* 319described in 320.Xr mandoc 3 . 321.Pp 322Uses the types 323.Vt struct roff_node 324from 325.Qq Pa roff.h 326and 327.Vt struct roff_man 328from 329.Qq Pa roff_int.h 330as opaque types for function prototypes. 331.Pp 332When this header is included, the same file should not include 333internals of different parsers. 334.It Qq Pa man.h 335Provides the functions 336.Fn man_* 337described in 338.Xr mandoc 3 . 339.Pp 340Uses the type 341.Vt struct roff_man 342from 343.Qq Pa roff.h 344as an opaque type for function prototypes. 345.Pp 346When this header is included, the same file should not include 347internals of different parsers. 348.El 349.Ss Parser internals 350Most of the following headers require inclusion of a parser interface header 351before they can be included. 352All parser interface headers should precede all parser internal headers. 353When any parser internal headers are included, the same file should 354not include any formatter headers. 355.Bl -tag -width Ds 356.It Qq Pa libmandoc.h 357Requires 358.In sys/types.h 359for 360.Vt size_t 361and 362.Qq Pa mandoc.h 363for 364.Vt enum mandocerr . 365.Pp 366Provides 367.Vt struct buf , 368utility functions needed by multiple parsers, 369and the top-level functions to call the parsers. 370.Pp 371Uses the opaque type 372.Vt struct roff 373from 374.Pa roff.c 375for function prototypes. 376Uses the type 377.Vt struct roff_man 378from 379.Qq Pa roff.h 380as an opaque type for function prototypes. 381.It Qq Pa roff_int.h 382Parser internals shared by multiple parsers. 383Can be used in all parsers, but not in main programs or formatters. 384.Pp 385Requires 386.Qq Pa roff.h 387for 388.Vt enum roff_type 389and 390.Vt enum roff_tok . 391.Pp 392Provides 393.Vt enum roff_next , 394.Vt struct roff_man , 395functions named 396.Fn roff_* 397to handle roff nodes, 398.Fn roffhash_alloc , 399.Fn roffhash_find , 400.Fn roffhash_free , 401and 402.Fn roff_validate , 403and the two special functions 404.Fn man_breakscope 405and 406.Fn mdoc_argv_free 407because the latter two are needed by 408.Pa roff.c . 409.Pp 410Uses the types 411.Vt struct ohash 412from 413.Qq Pa mandoc_ohash.h , 414.Vt struct roff_node 415and 416.Vt struct roff_meta 417from 418.Qq Pa roff.h , 419.Vt struct roff 420from 421.Pa roff.c , 422and 423.Vt struct mdoc_arg 424from 425.Qq Pa mdoc.h 426as opaque types for function prototypes. 427.It Qq Pa libmdoc.h 428Requires 429.Qq Pa roff.h 430for 431.Vt enum roff_tok 432and 433.Vt enum roff_sec . 434.Pp 435Provides 436.Vt enum margserr , 437.Vt enum mdelim , 438.Vt struct mdoc_macro , 439and many functions internal to the 440.Xr mdoc 7 441parser. 442.Pp 443Uses the types 444.Vt struct roff_node 445from 446.Qq Pa roff.h , 447.Vt struct roff_man 448from 449.Qq Pa roff_int.h , 450and 451.Vt struct mdoc_arg 452from 453.Qq Pa mdoc.h 454as opaque types for function prototypes. 455.Pp 456When this header is included, the same file should not include 457interfaces of different parsers. 458.It Qq Pa libman.h 459Requires 460.Qq Pa roff.h 461for 462.Vt enum roff_tok . 463.Pp 464Provides 465.Vt struct man_macro 466and some functions internal to the 467.Xr man 7 468parser. 469.Pp 470Uses the types 471.Vt struct roff_node 472from 473.Qq Pa roff.h 474and 475.Vt struct roff_man 476from 477.Qq Pa roff_int.h 478as opaque types for function prototypes. 479.Pp 480When this header is included, the same file should not include 481interfaces of different parsers. 482.It Qq Pa eqn_parse.h 483External interface of the 484.Xr eqn 7 485parser, for use in the 486.Xr roff 7 487and 488.Xr eqn 7 489parsers only. 490.Pp 491Requires 492.In sys/types.h 493for 494.Vt size_t . 495.Pp 496Provides 497.Vt struct eqn_node 498and the functions 499.Fn eqn_alloc , 500.Fn eqn_box_new , 501.Fn eqn_box_free , 502.Fn eqn_free , 503.Fn eqn_parse , 504.Fn eqn_read , 505and 506.Fn eqn_reset . 507.Pp 508Uses the type 509.Vt struct eqn_box 510from 511.Qq Pa mandoc.h 512as an opaque type for function prototypes. 513Uses the types 514.Vt struct roff_node 515from 516.Qq Pa roff.h 517and 518.Vt struct eqn_def 519from 520.Pa eqn.c 521as opaque struct members. 522.Pp 523When this header is included, the same file should not include 524internals of different parsers. 525.It Qq Pa tbl_parse.h 526External interface of the 527.Xr tbl 7 528parser, for use in the 529.Xr roff 7 530and 531.Xr tbl 7 532parsers only. 533.Pp 534Provides the functions documented in 535.Xr tbl 3 . 536.Pp 537Uses the types 538.Vt struct tbl_span 539from 540.Qq Pa tbl.h 541and 542.Vt struct tbl_node 543from 544.Qq Pa tbl_int.h 545as opaque types for function prototypes. 546.Pp 547When this header is included, the same file should not include 548internals of different parsers. 549.It Qq Pa tbl_int.h 550Internal interfaces of the 551.Xr tbl 7 552parser, for use inside the 553.Xr tbl 7 554parser only. 555.Pp 556Requires 557.Qq Pa tbl.h 558for 559.Vt struct tbl_opts . 560.Pp 561Provides 562.Vt enum tbl_part , 563.Vt struct tbl_node , 564and the functions 565.Fn tbl_option , 566.Fn tbl_layout , 567.Fn tbl_data , 568.Fn tbl_cdata , 569and 570.Fn tbl_reset . 571.Pp 572When this header is included, the same file should not include 573interfaces of different parsers. 574.El 575.Ss Formatter interface 576These headers should be included after any parser interface headers. 577No parser internal headers should be included by the same file. 578.Bl -tag -width Ds 579.It Qq Pa out.h 580Requires 581.In sys/types.h 582for 583.Vt size_t . 584.Pp 585Provides 586.Vt enum roffscale , 587.Vt struct roffcol , 588.Vt struct roffsu , 589.Vt struct rofftbl , 590.Fn a2roffsu , 591and 592.Fn tblcalc . 593.Pp 594Uses 595.Vt struct tbl_span 596from 597.Qq Pa mandoc.h 598as an opaque type for function prototypes. 599.Pp 600When this header is included, the same file should not include 601.Qq Pa mansearch.h . 602.It Qq Pa term.h 603Requires 604.In sys/types.h 605for 606.Vt size_t 607and 608.Qq Pa out.h 609for 610.Vt struct roffsu 611and 612.Vt struct rofftbl . 613.Pp 614Provides 615.Vt enum termenc , 616.Vt enum termfont , 617.Vt enum termtype , 618.Vt struct termp_tbl , 619.Vt struct termp , 620.Fn roff_term_pre , 621and many terminal formatting functions. 622.Pp 623Uses the opaque type 624.Vt struct termp_ps 625from 626.Pa term_ps.c . 627Uses 628.Vt struct tbl_span 629and 630.Vt struct eqn_box 631from 632.Qq Pa mandoc.h 633and 634.Vt struct roff_meta 635and 636.Vt struct roff_node 637from 638.Qq Pa roff.h 639as opaque types 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 tag_term.h 646Requires 647.In sys/types.h 648for 649.Vt size_t 650and 651.In stdio.h 652for 653.Vt FILE . 654.Pp 655Provides an interface to generate 656.Xr ctags 1 657files for the 658.Ic :t 659functionality mentioned in 660.Xr man 1 . 661.Pp 662Uses the type 663.Vt struct roff_node 664from 665.Qq Pa roff.h 666as an opaque type for function prototypes. 667.Pp 668When this header is included, the same file should not include 669.Qq Pa html.h 670or 671.Qq Pa mansearch.h . 672.It Qq Pa html.h 673Requires 674.In sys/types.h 675for 676.Vt size_t , 677.Qq Pa mandoc.h 678for 679.Vt enum mandoc_esc , 680.Qq Pa roff.h 681for 682.Vt enum roff_tok , 683and 684.Qq Pa out.h 685for 686.Vt struct roffsu 687and 688.Vt struct rofftbl . 689.Pp 690Provides 691.Vt enum htmltag , 692.Vt enum htmlattr , 693.Vt enum htmlfont , 694.Vt struct tag , 695.Vt struct tagq , 696.Vt struct htmlpair , 697.Vt struct html , 698.Fn roff_html_pre , 699and many HTML formatting functions. 700.Pp 701Uses 702.Vt struct tbl_span 703and 704.Vt struct eqn_box 705from 706.Qq Pa mandoc.h 707and 708.Vt struct roff_node 709from 710.Qq Pa roff.h 711as opaque types for function prototypes. 712.Pp 713When this header is included, the same file should not include 714.Qq Pa term.h , 715.Qq Pa tab_term.h , 716or 717.Qq Pa mansearch.h . 718.It Qq Pa main.h 719Provides the top level steering functions for all formatters. 720.Pp 721Uses the type 722.Vt struct roff_meta 723from 724.Qq Pa roff.h 725as an opaque type for function prototypes. 726.It Qq Pa manconf.h 727Requires 728.In sys/types.h 729for 730.Vt size_t . 731.Pp 732Provides 733.Vt struct manconf , 734.Vt struct manpaths , 735.Vt struct manoutput , 736and the functions 737.Fn manconf_parse , 738.Fn manconf_output , 739.Fn manconf_free , 740and 741.Fn manpath_base . 742.It Qq Pa mansearch.h 743Requires 744.In sys/types.h 745for 746.Vt size_t 747and 748.In stdint.h 749for 750.Vt uint64_t . 751.Pp 752Provides 753.Vt enum argmode , 754.Vt struct manpage , 755.Vt struct mansearch , 756and the functions 757.Fn mansearch 758and 759.Fn mansearch_free . 760.Pp 761Uses 762.Vt struct manpaths 763from 764.Qq Pa manconf.h 765as an opaque type for function prototypes. 766.Pp 767When this header is included, the same file should not include 768.Qq Pa out.h , 769.Qq Pa term.h , 770.Qq Pa tab_term.h , 771or 772.Qq Pa html.h . 773.El 774