1*9784ce3eSschwarze /* $OpenBSD: roff_int.h,v 1.20 2022/06/02 11:28:16 schwarze Exp $ */ 2fa2127f9Sschwarze /* 3cd14d642Sschwarze * Copyright (c) 2013-2015, 2017-2022 Ingo Schwarze <schwarze@openbsd.org> 4fa2127f9Sschwarze * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> 5fa2127f9Sschwarze * 6fa2127f9Sschwarze * Permission to use, copy, modify, and distribute this software for any 7fa2127f9Sschwarze * purpose with or without fee is hereby granted, provided that the above 8fa2127f9Sschwarze * copyright notice and this permission notice appear in all copies. 9fa2127f9Sschwarze * 10fa2127f9Sschwarze * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES 11fa2127f9Sschwarze * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12fa2127f9Sschwarze * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR 13fa2127f9Sschwarze * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14fa2127f9Sschwarze * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15fa2127f9Sschwarze * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16fa2127f9Sschwarze * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 176c530f1cSschwarze * 186c530f1cSschwarze * Parser internals shared by multiple parsers. 19fa2127f9Sschwarze */ 20fa2127f9Sschwarze 216b86842eSschwarze struct ohash; 226b86842eSschwarze struct roff_node; 236b86842eSschwarze struct roff_meta; 246b86842eSschwarze struct roff; 256b86842eSschwarze struct mdoc_arg; 266b86842eSschwarze 276b86842eSschwarze enum roff_next { 286b86842eSschwarze ROFF_NEXT_SIBLING = 0, 296b86842eSschwarze ROFF_NEXT_CHILD 306b86842eSschwarze }; 316b86842eSschwarze 326b86842eSschwarze struct roff_man { 336b86842eSschwarze struct roff_meta meta; /* Public parse results. */ 346b86842eSschwarze struct roff *roff; /* Roff parser state data. */ 356b86842eSschwarze struct ohash *mdocmac; /* Mdoc macro lookup table. */ 366b86842eSschwarze struct ohash *manmac; /* Man macro lookup table. */ 376b86842eSschwarze const char *os_s; /* Default operating system. */ 388055da74Sschwarze char *os_r; /* Operating system name at run time. */ 396b86842eSschwarze struct roff_node *last; /* The last node parsed. */ 406b86842eSschwarze struct roff_node *last_es; /* The most recent Es node. */ 416b86842eSschwarze int quick; /* Abort parse early. */ 426b86842eSschwarze int flags; /* Parse flags. */ 430438bfdfSschwarze #define ROFF_NOFILL (1 << 1) /* Fill mode switched off. */ 446b86842eSschwarze #define MDOC_PBODY (1 << 2) /* In the document body. */ 456b86842eSschwarze #define MDOC_NEWLINE (1 << 3) /* First macro/text in a line. */ 466b86842eSschwarze #define MDOC_PHRASE (1 << 4) /* In a Bl -column phrase. */ 476b86842eSschwarze #define MDOC_PHRASELIT (1 << 5) /* Literal within a phrase. */ 486b86842eSschwarze #define MDOC_FREECOL (1 << 6) /* `It' invocation should close. */ 496b86842eSschwarze #define MDOC_SYNOPSIS (1 << 7) /* SYNOPSIS-style formatting. */ 506b86842eSschwarze #define MDOC_KEEP (1 << 8) /* In a word keep. */ 516b86842eSschwarze #define MDOC_SMOFF (1 << 9) /* Spacing is off. */ 526b86842eSschwarze #define MDOC_NODELIMC (1 << 10) /* Disable closing delimiter handling. */ 536b86842eSschwarze #define MAN_ELINE (1 << 11) /* Next-line element scope. */ 546b86842eSschwarze #define MAN_BLINE (1 << 12) /* Next-line block scope. */ 556b86842eSschwarze #define MDOC_PHRASEQF (1 << 13) /* Quote first word encountered. */ 566b86842eSschwarze #define MDOC_PHRASEQL (1 << 14) /* Quote last word of this phrase. */ 576b86842eSschwarze #define MDOC_PHRASEQN (1 << 15) /* Quote first word of the next phrase. */ 5894a3c318Sschwarze #define ROFF_NONOFILL (1 << 16) /* Temporarily suspend no-fill mode. */ 596b86842eSschwarze #define MAN_NEWLINE MDOC_NEWLINE 606b86842eSschwarze enum roff_sec lastsec; /* Last section seen. */ 616b86842eSschwarze enum roff_sec lastnamed; /* Last standard section seen. */ 626b86842eSschwarze enum roff_next next; /* Where to put the next node. */ 63ee646987Sschwarze char filesec; /* Section digit in the file name. */ 646b86842eSschwarze }; 656b86842eSschwarze 666b86842eSschwarze 67fa2127f9Sschwarze struct roff_node *roff_node_alloc(struct roff_man *, int, int, 68fa2127f9Sschwarze enum roff_type, int); 69fa2127f9Sschwarze void roff_node_append(struct roff_man *, struct roff_node *); 7069c34eaaSschwarze void roff_word_alloc(struct roff_man *, int, int, const char *); 7169c34eaaSschwarze void roff_word_append(struct roff_man *, const char *); 72e32c44d4Sschwarze void roff_elem_alloc(struct roff_man *, int, int, int); 73e32c44d4Sschwarze struct roff_node *roff_block_alloc(struct roff_man *, int, int, int); 74fa2127f9Sschwarze struct roff_node *roff_head_alloc(struct roff_man *, int, int, int); 75fa2127f9Sschwarze struct roff_node *roff_body_alloc(struct roff_man *, int, int, int); 76fa2127f9Sschwarze void roff_node_unlink(struct roff_man *, struct roff_node *); 778251afdeSschwarze void roff_node_relink(struct roff_man *, struct roff_node *); 78fa2127f9Sschwarze void roff_node_free(struct roff_node *); 79fa2127f9Sschwarze void roff_node_delete(struct roff_man *, struct roff_node *); 80fa2127f9Sschwarze 816c530f1cSschwarze struct ohash *roffhash_alloc(enum roff_tok, enum roff_tok); 826c530f1cSschwarze enum roff_tok roffhash_find(struct ohash *, const char *, size_t); 836c530f1cSschwarze void roffhash_free(struct ohash *); 846c530f1cSschwarze 85cd14d642Sschwarze enum mandoc_esc roff_escape(const char *, const int, const int, 86*9784ce3eSschwarze int *, int *, int *, int *, int *); 8783d65a5aSschwarze void roff_state_reset(struct roff_man *); 886b86842eSschwarze void roff_validate(struct roff_man *); 896b86842eSschwarze 9069c34eaaSschwarze /* 9169c34eaaSschwarze * Functions called from roff.c need to be declared here, 9269c34eaaSschwarze * not in libmdoc.h or libman.h, even if they are specific 9369c34eaaSschwarze * to either the mdoc(7) or the man(7) parser. 9469c34eaaSschwarze */ 9569c34eaaSschwarze 9669c34eaaSschwarze void man_breakscope(struct roff_man *, int); 9769c34eaaSschwarze void mdoc_argv_free(struct mdoc_arg *); 98