1*ce7279d8Sjsg /* $OpenBSD: libmdoc.h,v 1.89 2024/05/21 05:00:48 jsg Exp $ */ 2f73abda9Skristaps /* 3a35fc07aSschwarze * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> 416fe0cfcSschwarze * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org> 5f73abda9Skristaps * 6f73abda9Skristaps * Permission to use, copy, modify, and distribute this software for any 7a6464425Sschwarze * purpose with or without fee is hereby granted, provided that the above 8a6464425Sschwarze * copyright notice and this permission notice appear in all copies. 9f73abda9Skristaps * 103a0d07afSschwarze * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES 11a6464425Sschwarze * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 123a0d07afSschwarze * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR 13a6464425Sschwarze * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14a6464425Sschwarze * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15a6464425Sschwarze * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16a6464425Sschwarze * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17f73abda9Skristaps */ 18f73abda9Skristaps 196b86842eSschwarze struct roff_node; 206b86842eSschwarze struct roff_man; 216b86842eSschwarze struct mdoc_arg; 226b86842eSschwarze 23ede1b9d0Sschwarze #define MACRO_PROT_ARGS struct roff_man *mdoc, \ 2414a309e3Sschwarze enum roff_tok tok, \ 259830bf9fSschwarze int line, \ 269830bf9fSschwarze int ppos, \ 279830bf9fSschwarze int *pos, \ 289830bf9fSschwarze char *buf 29f73abda9Skristaps 30f73abda9Skristaps struct mdoc_macro { 3107f8b160Sschwarze void (*fp)(MACRO_PROT_ARGS); 32f73abda9Skristaps int flags; 33f73abda9Skristaps #define MDOC_CALLABLE (1 << 0) 34f73abda9Skristaps #define MDOC_PARSED (1 << 1) 35f73abda9Skristaps #define MDOC_EXPLICIT (1 << 2) 36f73abda9Skristaps #define MDOC_PROLOGUE (1 << 3) 37f73abda9Skristaps #define MDOC_IGNDELIM (1 << 4) 38ec2beb53Sschwarze #define MDOC_JOIN (1 << 5) 39f73abda9Skristaps }; 40f73abda9Skristaps 41a4c002ecSschwarze enum margserr { 42a4c002ecSschwarze ARGS_ERROR, 43a5e11edeSschwarze ARGS_EOLN, /* end-of-line */ 44a5e11edeSschwarze ARGS_WORD, /* normal word */ 45e94357f9Sschwarze ARGS_ALLOC, /* normal word from roff_getarg() */ 46a5e11edeSschwarze ARGS_PUNCT, /* series of punctuation */ 47407d12bbSschwarze ARGS_PHRASE /* Bl -column phrase */ 48a4c002ecSschwarze }; 49a4c002ecSschwarze 50a35fc07aSschwarze /* 51a35fc07aSschwarze * A punctuation delimiter is opening, closing, or "middle mark" 52a35fc07aSschwarze * punctuation. These govern spacing. 53a35fc07aSschwarze * Opening punctuation (e.g., the opening parenthesis) suppresses the 54a35fc07aSschwarze * following space; closing punctuation (e.g., the closing parenthesis) 55a35fc07aSschwarze * suppresses the leading space; middle punctuation (e.g., the vertical 56a35fc07aSschwarze * bar) can do either. The middle punctuation delimiter bends the rules 57a35fc07aSschwarze * depending on usage. 58a35fc07aSschwarze */ 59a35fc07aSschwarze enum mdelim { 60a35fc07aSschwarze DELIM_NONE = 0, 61a35fc07aSschwarze DELIM_OPEN, 62a35fc07aSschwarze DELIM_MIDDLE, 63a35fc07aSschwarze DELIM_CLOSE, 64a35fc07aSschwarze DELIM_MAX 65a35fc07aSschwarze }; 66a35fc07aSschwarze 6716fe0cfcSschwarze const struct mdoc_macro *mdoc_macro(enum roff_tok); 68f73abda9Skristaps 69ede1b9d0Sschwarze void mdoc_elem_alloc(struct roff_man *, int, int, 7014a309e3Sschwarze enum roff_tok, struct mdoc_arg *); 71ede1b9d0Sschwarze struct roff_node *mdoc_block_alloc(struct roff_man *, int, int, 7214a309e3Sschwarze enum roff_tok, struct mdoc_arg *); 7314a309e3Sschwarze void mdoc_tail_alloc(struct roff_man *, int, int, 7414a309e3Sschwarze enum roff_tok); 7514a309e3Sschwarze struct roff_node *mdoc_endbody_alloc(struct roff_man *, int, int, 7614a309e3Sschwarze enum roff_tok, struct roff_node *); 77396853b5Sschwarze void mdoc_state(struct roff_man *, struct roff_node *); 78396853b5Sschwarze const char *mdoc_a2att(const char *); 79396853b5Sschwarze enum roff_sec mdoc_a2sec(const char *); 80396853b5Sschwarze const char *mdoc_a2st(const char *); 8114a309e3Sschwarze void mdoc_argv(struct roff_man *, int, enum roff_tok, 82f73abda9Skristaps struct mdoc_arg **, int *, char *); 83ede1b9d0Sschwarze enum margserr mdoc_args(struct roff_man *, int, 8414a309e3Sschwarze int *, char *, enum roff_tok, char **); 85a35fc07aSschwarze enum mdelim mdoc_isdelim(const char *); 86