1 /* $Id: roff.h,v 1.74 2020/04/08 11:56:03 schwarze Exp $ */ 2 /* 3 * Copyright (c) 2013-2015, 2017-2020 Ingo Schwarze <schwarze@openbsd.org> 4 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 * 18 * Common data types for all syntax trees and related functions. 19 */ 20 21 struct ohash; 22 struct mdoc_arg; 23 union mdoc_data; 24 struct tbl_span; 25 struct eqn_box; 26 27 enum roff_macroset { 28 MACROSET_NONE = 0, 29 MACROSET_MDOC, 30 MACROSET_MAN 31 }; 32 33 enum roff_sec { 34 SEC_NONE = 0, 35 SEC_NAME, 36 SEC_LIBRARY, 37 SEC_SYNOPSIS, 38 SEC_DESCRIPTION, 39 SEC_CONTEXT, 40 SEC_IMPLEMENTATION, /* IMPLEMENTATION NOTES */ 41 SEC_RETURN_VALUES, 42 SEC_ENVIRONMENT, 43 SEC_FILES, 44 SEC_EXIT_STATUS, 45 SEC_EXAMPLES, 46 SEC_DIAGNOSTICS, 47 SEC_COMPATIBILITY, 48 SEC_ERRORS, 49 SEC_SEE_ALSO, 50 SEC_STANDARDS, 51 SEC_HISTORY, 52 SEC_AUTHORS, 53 SEC_CAVEATS, 54 SEC_BUGS, 55 SEC_SECURITY, 56 SEC_CUSTOM, 57 SEC__MAX 58 }; 59 60 enum roff_type { 61 ROFFT_ROOT, 62 ROFFT_BLOCK, 63 ROFFT_HEAD, 64 ROFFT_BODY, 65 ROFFT_TAIL, 66 ROFFT_ELEM, 67 ROFFT_TEXT, 68 ROFFT_COMMENT, 69 ROFFT_TBL, 70 ROFFT_EQN 71 }; 72 73 enum roff_tok { 74 ROFF_br = 0, 75 ROFF_ce, 76 ROFF_fi, 77 ROFF_ft, 78 ROFF_ll, 79 ROFF_mc, 80 ROFF_nf, 81 ROFF_po, 82 ROFF_rj, 83 ROFF_sp, 84 ROFF_ta, 85 ROFF_ti, 86 ROFF_MAX, 87 ROFF_ab, 88 ROFF_ad, 89 ROFF_af, 90 ROFF_aln, 91 ROFF_als, 92 ROFF_am, 93 ROFF_am1, 94 ROFF_ami, 95 ROFF_ami1, 96 ROFF_as, 97 ROFF_as1, 98 ROFF_asciify, 99 ROFF_backtrace, 100 ROFF_bd, 101 ROFF_bleedat, 102 ROFF_blm, 103 ROFF_box, 104 ROFF_boxa, 105 ROFF_bp, 106 ROFF_BP, 107 ROFF_break, 108 ROFF_breakchar, 109 ROFF_brnl, 110 ROFF_brp, 111 ROFF_brpnl, 112 ROFF_c2, 113 ROFF_cc, 114 ROFF_cf, 115 ROFF_cflags, 116 ROFF_ch, 117 ROFF_char, 118 ROFF_chop, 119 ROFF_class, 120 ROFF_close, 121 ROFF_CL, 122 ROFF_color, 123 ROFF_composite, 124 ROFF_continue, 125 ROFF_cp, 126 ROFF_cropat, 127 ROFF_cs, 128 ROFF_cu, 129 ROFF_da, 130 ROFF_dch, 131 ROFF_Dd, 132 ROFF_de, 133 ROFF_de1, 134 ROFF_defcolor, 135 ROFF_dei, 136 ROFF_dei1, 137 ROFF_device, 138 ROFF_devicem, 139 ROFF_di, 140 ROFF_do, 141 ROFF_ds, 142 ROFF_ds1, 143 ROFF_dwh, 144 ROFF_dt, 145 ROFF_ec, 146 ROFF_ecr, 147 ROFF_ecs, 148 ROFF_el, 149 ROFF_em, 150 ROFF_EN, 151 ROFF_eo, 152 ROFF_EP, 153 ROFF_EQ, 154 ROFF_errprint, 155 ROFF_ev, 156 ROFF_evc, 157 ROFF_ex, 158 ROFF_fallback, 159 ROFF_fam, 160 ROFF_fc, 161 ROFF_fchar, 162 ROFF_fcolor, 163 ROFF_fdeferlig, 164 ROFF_feature, 165 ROFF_fkern, 166 ROFF_fl, 167 ROFF_flig, 168 ROFF_fp, 169 ROFF_fps, 170 ROFF_fschar, 171 ROFF_fspacewidth, 172 ROFF_fspecial, 173 ROFF_ftr, 174 ROFF_fzoom, 175 ROFF_gcolor, 176 ROFF_hc, 177 ROFF_hcode, 178 ROFF_hidechar, 179 ROFF_hla, 180 ROFF_hlm, 181 ROFF_hpf, 182 ROFF_hpfa, 183 ROFF_hpfcode, 184 ROFF_hw, 185 ROFF_hy, 186 ROFF_hylang, 187 ROFF_hylen, 188 ROFF_hym, 189 ROFF_hypp, 190 ROFF_hys, 191 ROFF_ie, 192 ROFF_if, 193 ROFF_ig, 194 /* MAN_in; ignored in mdoc(7) */ 195 ROFF_index, 196 ROFF_it, 197 ROFF_itc, 198 ROFF_IX, 199 ROFF_kern, 200 ROFF_kernafter, 201 ROFF_kernbefore, 202 ROFF_kernpair, 203 ROFF_lc, 204 ROFF_lc_ctype, 205 ROFF_lds, 206 ROFF_length, 207 ROFF_letadj, 208 ROFF_lf, 209 ROFF_lg, 210 ROFF_lhang, 211 ROFF_linetabs, 212 ROFF_lnr, 213 ROFF_lnrf, 214 ROFF_lpfx, 215 ROFF_ls, 216 ROFF_lsm, 217 ROFF_lt, 218 ROFF_mediasize, 219 ROFF_minss, 220 ROFF_mk, 221 ROFF_mso, 222 ROFF_na, 223 ROFF_ne, 224 ROFF_nh, 225 ROFF_nhychar, 226 ROFF_nm, 227 ROFF_nn, 228 ROFF_nop, 229 ROFF_nr, 230 ROFF_nrf, 231 ROFF_nroff, 232 ROFF_ns, 233 ROFF_nx, 234 ROFF_open, 235 ROFF_opena, 236 ROFF_os, 237 ROFF_output, 238 ROFF_padj, 239 ROFF_papersize, 240 ROFF_pc, 241 ROFF_pev, 242 ROFF_pi, 243 ROFF_PI, 244 ROFF_pl, 245 ROFF_pm, 246 ROFF_pn, 247 ROFF_pnr, 248 ROFF_ps, 249 ROFF_psbb, 250 ROFF_pshape, 251 ROFF_pso, 252 ROFF_ptr, 253 ROFF_pvs, 254 ROFF_rchar, 255 ROFF_rd, 256 ROFF_recursionlimit, 257 ROFF_return, 258 ROFF_rfschar, 259 ROFF_rhang, 260 ROFF_rm, 261 ROFF_rn, 262 ROFF_rnn, 263 ROFF_rr, 264 ROFF_rs, 265 ROFF_rt, 266 ROFF_schar, 267 ROFF_sentchar, 268 ROFF_shc, 269 ROFF_shift, 270 ROFF_sizes, 271 ROFF_so, 272 ROFF_spacewidth, 273 ROFF_special, 274 ROFF_spreadwarn, 275 ROFF_ss, 276 ROFF_sty, 277 ROFF_substring, 278 ROFF_sv, 279 ROFF_sy, 280 ROFF_T_, 281 ROFF_tc, 282 ROFF_TE, 283 ROFF_TH, 284 ROFF_tkf, 285 ROFF_tl, 286 ROFF_tm, 287 ROFF_tm1, 288 ROFF_tmc, 289 ROFF_tr, 290 ROFF_track, 291 ROFF_transchar, 292 ROFF_trf, 293 ROFF_trimat, 294 ROFF_trin, 295 ROFF_trnt, 296 ROFF_troff, 297 ROFF_TS, 298 ROFF_uf, 299 ROFF_ul, 300 ROFF_unformat, 301 ROFF_unwatch, 302 ROFF_unwatchn, 303 ROFF_vpt, 304 ROFF_vs, 305 ROFF_warn, 306 ROFF_warnscale, 307 ROFF_watch, 308 ROFF_watchlength, 309 ROFF_watchn, 310 ROFF_wh, 311 ROFF_while, 312 ROFF_write, 313 ROFF_writec, 314 ROFF_writem, 315 ROFF_xflag, 316 ROFF_cblock, 317 ROFF_RENAMED, 318 ROFF_USERDEF, 319 TOKEN_NONE, 320 MDOC_Dd, 321 MDOC_Dt, 322 MDOC_Os, 323 MDOC_Sh, 324 MDOC_Ss, 325 MDOC_Pp, 326 MDOC_D1, 327 MDOC_Dl, 328 MDOC_Bd, 329 MDOC_Ed, 330 MDOC_Bl, 331 MDOC_El, 332 MDOC_It, 333 MDOC_Ad, 334 MDOC_An, 335 MDOC_Ap, 336 MDOC_Ar, 337 MDOC_Cd, 338 MDOC_Cm, 339 MDOC_Dv, 340 MDOC_Er, 341 MDOC_Ev, 342 MDOC_Ex, 343 MDOC_Fa, 344 MDOC_Fd, 345 MDOC_Fl, 346 MDOC_Fn, 347 MDOC_Ft, 348 MDOC_Ic, 349 MDOC_In, 350 MDOC_Li, 351 MDOC_Nd, 352 MDOC_Nm, 353 MDOC_Op, 354 MDOC_Ot, 355 MDOC_Pa, 356 MDOC_Rv, 357 MDOC_St, 358 MDOC_Va, 359 MDOC_Vt, 360 MDOC_Xr, 361 MDOC__A, 362 MDOC__B, 363 MDOC__D, 364 MDOC__I, 365 MDOC__J, 366 MDOC__N, 367 MDOC__O, 368 MDOC__P, 369 MDOC__R, 370 MDOC__T, 371 MDOC__V, 372 MDOC_Ac, 373 MDOC_Ao, 374 MDOC_Aq, 375 MDOC_At, 376 MDOC_Bc, 377 MDOC_Bf, 378 MDOC_Bo, 379 MDOC_Bq, 380 MDOC_Bsx, 381 MDOC_Bx, 382 MDOC_Db, 383 MDOC_Dc, 384 MDOC_Do, 385 MDOC_Dq, 386 MDOC_Ec, 387 MDOC_Ef, 388 MDOC_Em, 389 MDOC_Eo, 390 MDOC_Fx, 391 MDOC_Ms, 392 MDOC_No, 393 MDOC_Ns, 394 MDOC_Nx, 395 MDOC_Ox, 396 MDOC_Pc, 397 MDOC_Pf, 398 MDOC_Po, 399 MDOC_Pq, 400 MDOC_Qc, 401 MDOC_Ql, 402 MDOC_Qo, 403 MDOC_Qq, 404 MDOC_Re, 405 MDOC_Rs, 406 MDOC_Sc, 407 MDOC_So, 408 MDOC_Sq, 409 MDOC_Sm, 410 MDOC_Sx, 411 MDOC_Sy, 412 MDOC_Tn, 413 MDOC_Ux, 414 MDOC_Xc, 415 MDOC_Xo, 416 MDOC_Fo, 417 MDOC_Fc, 418 MDOC_Oo, 419 MDOC_Oc, 420 MDOC_Bk, 421 MDOC_Ek, 422 MDOC_Bt, 423 MDOC_Hf, 424 MDOC_Fr, 425 MDOC_Ud, 426 MDOC_Lb, 427 MDOC_Lp, 428 MDOC_Lk, 429 MDOC_Mt, 430 MDOC_Brq, 431 MDOC_Bro, 432 MDOC_Brc, 433 MDOC__C, 434 MDOC_Es, 435 MDOC_En, 436 MDOC_Dx, 437 MDOC__Q, 438 MDOC__U, 439 MDOC_Ta, 440 MDOC_Tg, 441 MDOC_MAX, 442 MAN_TH, 443 MAN_SH, 444 MAN_SS, 445 MAN_TP, 446 MAN_TQ, 447 MAN_LP, 448 MAN_PP, 449 MAN_P, 450 MAN_IP, 451 MAN_HP, 452 MAN_SM, 453 MAN_SB, 454 MAN_BI, 455 MAN_IB, 456 MAN_BR, 457 MAN_RB, 458 MAN_R, 459 MAN_B, 460 MAN_I, 461 MAN_IR, 462 MAN_RI, 463 MAN_RE, 464 MAN_RS, 465 MAN_DT, 466 MAN_UC, 467 MAN_PD, 468 MAN_AT, 469 MAN_in, 470 MAN_SY, 471 MAN_YS, 472 MAN_OP, 473 MAN_EX, 474 MAN_EE, 475 MAN_UR, 476 MAN_UE, 477 MAN_MT, 478 MAN_ME, 479 MAN_MAX 480 }; 481 482 /* 483 * Indicates that a BODY's formatting has ended, but 484 * the scope is still open. Used for badly nested blocks. 485 */ 486 enum mdoc_endbody { 487 ENDBODY_NOT = 0, 488 ENDBODY_SPACE /* Is broken: append a space. */ 489 }; 490 491 enum mandoc_os { 492 MANDOC_OS_OTHER = 0, 493 MANDOC_OS_NETBSD, 494 MANDOC_OS_OPENBSD 495 }; 496 497 struct roff_node { 498 struct roff_node *parent; /* Parent AST node. */ 499 struct roff_node *child; /* First child AST node. */ 500 struct roff_node *last; /* Last child AST node. */ 501 struct roff_node *next; /* Sibling AST node. */ 502 struct roff_node *prev; /* Prior sibling AST node. */ 503 struct roff_node *head; /* BLOCK */ 504 struct roff_node *body; /* BLOCK/ENDBODY */ 505 struct roff_node *tail; /* BLOCK */ 506 struct mdoc_arg *args; /* BLOCK/ELEM */ 507 union mdoc_data *norm; /* Normalized arguments. */ 508 char *string; /* TEXT */ 509 char *tag; /* For less(1) :t and HTML id=. */ 510 struct tbl_span *span; /* TBL */ 511 struct eqn_box *eqn; /* EQN */ 512 int line; /* Input file line number. */ 513 int pos; /* Input file column number. */ 514 int flags; 515 #define NODE_VALID (1 << 0) /* Has been validated. */ 516 #define NODE_ENDED (1 << 1) /* Gone past body end mark. */ 517 #define NODE_BROKEN (1 << 2) /* Must validate parent when ending. */ 518 #define NODE_LINE (1 << 3) /* First macro/text on line. */ 519 #define NODE_DELIMO (1 << 4) 520 #define NODE_DELIMC (1 << 5) 521 #define NODE_EOS (1 << 6) /* At sentence boundary. */ 522 #define NODE_SYNPRETTY (1 << 7) /* SYNOPSIS-style formatting. */ 523 #define NODE_NOFILL (1 << 8) /* Fill mode switched off. */ 524 #define NODE_NOSRC (1 << 9) /* Generated node, not in input file. */ 525 #define NODE_NOPRT (1 << 10) /* Shall not print anything. */ 526 #define NODE_ID (1 << 11) /* Target for deep linking. */ 527 #define NODE_HREF (1 << 12) /* Link to another place in this page. */ 528 int prev_font; /* Before entering this node. */ 529 int aux; /* Decoded node data, type-dependent. */ 530 enum roff_tok tok; /* Request or macro ID. */ 531 enum roff_type type; /* AST node type. */ 532 enum roff_sec sec; /* Current named section. */ 533 enum mdoc_endbody end; /* BODY */ 534 }; 535 536 struct roff_meta { 537 struct roff_node *first; /* The first node parsed. */ 538 char *msec; /* Manual section, usually a digit. */ 539 char *vol; /* Manual volume title. */ 540 char *os; /* Operating system. */ 541 char *arch; /* Machine architecture. */ 542 char *title; /* Manual title, usually CAPS. */ 543 char *name; /* Leading manual name. */ 544 char *date; /* Normalized date. */ 545 char *sodest; /* .so target file name or NULL. */ 546 int hasbody; /* Document is not empty. */ 547 int rcsids; /* Bits indexed by enum mandoc_os. */ 548 enum mandoc_os os_e; /* Operating system. */ 549 enum roff_macroset macroset; /* Kind of high-level macros used. */ 550 }; 551 552 extern const char *const *roff_name; 553 554 555 int arch_valid(const char *, enum mandoc_os); 556 void deroff(char **, const struct roff_node *); 557 struct roff_node *roff_node_child(struct roff_node *); 558 struct roff_node *roff_node_next(struct roff_node *); 559 struct roff_node *roff_node_prev(struct roff_node *); 560 int roff_node_transparent(struct roff_node *); 561 int roff_tok_transparent(enum roff_tok); 562