1 1.1.1.4 wiz /* $OpenBSD: roff_int.h,v 1.16 2019/01/05 00:36:46 schwarze Exp $ */ 2 1.1 christos /* 3 1.1.1.4 wiz * Copyright (c) 2013-2015, 2017-2020 Ingo Schwarze <schwarze (at) openbsd.org> 4 1.1 christos * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps (at) bsd.lv> 5 1.1 christos * 6 1.1 christos * Permission to use, copy, modify, and distribute this software for any 7 1.1 christos * purpose with or without fee is hereby granted, provided that the above 8 1.1 christos * copyright notice and this permission notice appear in all copies. 9 1.1 christos * 10 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES 11 1.1 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 1.1 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR 13 1.1 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 1.1 christos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 1.1 christos * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 1.1.1.3 christos * 18 1.1.1.3 christos * Parser internals shared by multiple parsers. 19 1.1 christos */ 20 1.1 christos 21 1.1.1.3 christos struct ohash; 22 1.1.1.3 christos struct roff_node; 23 1.1.1.3 christos struct roff_meta; 24 1.1.1.3 christos struct roff; 25 1.1.1.3 christos struct mdoc_arg; 26 1.1.1.3 christos 27 1.1.1.3 christos enum roff_next { 28 1.1.1.3 christos ROFF_NEXT_SIBLING = 0, 29 1.1.1.3 christos ROFF_NEXT_CHILD 30 1.1.1.3 christos }; 31 1.1.1.3 christos 32 1.1.1.3 christos struct roff_man { 33 1.1.1.3 christos struct roff_meta meta; /* Public parse results. */ 34 1.1.1.3 christos struct roff *roff; /* Roff parser state data. */ 35 1.1.1.3 christos struct ohash *mdocmac; /* Mdoc macro lookup table. */ 36 1.1.1.3 christos struct ohash *manmac; /* Man macro lookup table. */ 37 1.1.1.3 christos const char *os_s; /* Default operating system. */ 38 1.1.1.3 christos struct roff_node *last; /* The last node parsed. */ 39 1.1.1.3 christos struct roff_node *last_es; /* The most recent Es node. */ 40 1.1.1.3 christos int quick; /* Abort parse early. */ 41 1.1.1.3 christos int flags; /* Parse flags. */ 42 1.1.1.3 christos #define ROFF_NOFILL (1 << 1) /* Fill mode switched off. */ 43 1.1.1.3 christos #define MDOC_PBODY (1 << 2) /* In the document body. */ 44 1.1.1.3 christos #define MDOC_NEWLINE (1 << 3) /* First macro/text in a line. */ 45 1.1.1.3 christos #define MDOC_PHRASE (1 << 4) /* In a Bl -column phrase. */ 46 1.1.1.3 christos #define MDOC_PHRASELIT (1 << 5) /* Literal within a phrase. */ 47 1.1.1.3 christos #define MDOC_FREECOL (1 << 6) /* `It' invocation should close. */ 48 1.1.1.3 christos #define MDOC_SYNOPSIS (1 << 7) /* SYNOPSIS-style formatting. */ 49 1.1.1.3 christos #define MDOC_KEEP (1 << 8) /* In a word keep. */ 50 1.1.1.3 christos #define MDOC_SMOFF (1 << 9) /* Spacing is off. */ 51 1.1.1.3 christos #define MDOC_NODELIMC (1 << 10) /* Disable closing delimiter handling. */ 52 1.1.1.3 christos #define MAN_ELINE (1 << 11) /* Next-line element scope. */ 53 1.1.1.3 christos #define MAN_BLINE (1 << 12) /* Next-line block scope. */ 54 1.1.1.3 christos #define MDOC_PHRASEQF (1 << 13) /* Quote first word encountered. */ 55 1.1.1.3 christos #define MDOC_PHRASEQL (1 << 14) /* Quote last word of this phrase. */ 56 1.1.1.3 christos #define MDOC_PHRASEQN (1 << 15) /* Quote first word of the next phrase. */ 57 1.1.1.3 christos #define ROFF_NONOFILL (1 << 16) /* Temporarily suspend no-fill mode. */ 58 1.1.1.3 christos #define MAN_NEWLINE MDOC_NEWLINE 59 1.1.1.3 christos enum roff_sec lastsec; /* Last section seen. */ 60 1.1.1.3 christos enum roff_sec lastnamed; /* Last standard section seen. */ 61 1.1.1.3 christos enum roff_next next; /* Where to put the next node. */ 62 1.1.1.4 wiz char filesec; /* Section digit in the file name. */ 63 1.1.1.3 christos }; 64 1.1.1.3 christos 65 1.1.1.3 christos 66 1.1 christos struct roff_node *roff_node_alloc(struct roff_man *, int, int, 67 1.1 christos enum roff_type, int); 68 1.1 christos void roff_node_append(struct roff_man *, struct roff_node *); 69 1.1 christos void roff_word_alloc(struct roff_man *, int, int, const char *); 70 1.1 christos void roff_word_append(struct roff_man *, const char *); 71 1.1 christos void roff_elem_alloc(struct roff_man *, int, int, int); 72 1.1 christos struct roff_node *roff_block_alloc(struct roff_man *, int, int, int); 73 1.1 christos struct roff_node *roff_head_alloc(struct roff_man *, int, int, int); 74 1.1 christos struct roff_node *roff_body_alloc(struct roff_man *, int, int, int); 75 1.1 christos void roff_node_unlink(struct roff_man *, struct roff_node *); 76 1.1.1.3 christos void roff_node_relink(struct roff_man *, struct roff_node *); 77 1.1 christos void roff_node_free(struct roff_node *); 78 1.1 christos void roff_node_delete(struct roff_man *, struct roff_node *); 79 1.1 christos 80 1.1.1.3 christos struct ohash *roffhash_alloc(enum roff_tok, enum roff_tok); 81 1.1.1.3 christos enum roff_tok roffhash_find(struct ohash *, const char *, size_t); 82 1.1.1.3 christos void roffhash_free(struct ohash *); 83 1.1.1.3 christos 84 1.1.1.3 christos void roff_state_reset(struct roff_man *); 85 1.1.1.3 christos void roff_validate(struct roff_man *); 86 1.1.1.3 christos 87 1.1 christos /* 88 1.1 christos * Functions called from roff.c need to be declared here, 89 1.1 christos * not in libmdoc.h or libman.h, even if they are specific 90 1.1 christos * to either the mdoc(7) or the man(7) parser. 91 1.1 christos */ 92 1.1 christos 93 1.1 christos void man_breakscope(struct roff_man *, int); 94 1.1 christos void mdoc_argv_free(struct mdoc_arg *); 95