1*f4432377Sschwarze /* $OpenBSD: libmandoc.h,v 1.66 2025/01/05 16:56:48 schwarze Exp $ */ 2f6854d5cSschwarze /* 3ea5923abSschwarze * Copyright (c) 2013-2015,2017,2018,2020 Ingo Schwarze <schwarze@openbsd.org> 46a6803e4Sschwarze * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> 5f6854d5cSschwarze * 6f6854d5cSschwarze * Permission to use, copy, modify, and distribute this software for any 7f6854d5cSschwarze * purpose with or without fee is hereby granted, provided that the above 8f6854d5cSschwarze * copyright notice and this permission notice appear in all copies. 9f6854d5cSschwarze * 10ede1b9d0Sschwarze * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES 11f6854d5cSschwarze * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12ede1b9d0Sschwarze * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR 13f6854d5cSschwarze * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14f6854d5cSschwarze * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15f6854d5cSschwarze * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16f6854d5cSschwarze * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 176a6803e4Sschwarze * 186a6803e4Sschwarze * Internal interfaces for parser utilities needed by multiple parsers 196a6803e4Sschwarze * and the top-level functions to call the mdoc, man, and roff parsers. 20f6854d5cSschwarze */ 21f6854d5cSschwarze 22b7f92c5fSschwarze /* 23b7f92c5fSschwarze * Return codes passed from the roff parser to the main parser. 24b7f92c5fSschwarze */ 25b7f92c5fSschwarze 26b7f92c5fSschwarze /* Main instruction: what to do with the returned line. */ 27b7f92c5fSschwarze #define ROFF_IGN 0x000 /* Don't do anything with it. */ 28b7f92c5fSschwarze #define ROFF_CONT 0x001 /* Give it to the high-level parser. */ 29b7f92c5fSschwarze #define ROFF_RERUN 0x002 /* Re-run the roff parser with an offset. */ 30b7f92c5fSschwarze #define ROFF_REPARSE 0x004 /* Recursively run the main parser on it. */ 31b7f92c5fSschwarze #define ROFF_SO 0x008 /* Include the named file. */ 32b7f92c5fSschwarze #define ROFF_MASK 0x00f /* Only one of these bits should be set. */ 33b7f92c5fSschwarze 34b7f92c5fSschwarze /* Options for further parsing, to be OR'ed with the above. */ 35b7f92c5fSschwarze #define ROFF_APPEND 0x010 /* Append the next line to this one. */ 36b7f92c5fSschwarze #define ROFF_USERCALL 0x020 /* Start execution of a new macro. */ 37b7f92c5fSschwarze #define ROFF_USERRET 0x040 /* Abort execution of the current macro. */ 38b7f92c5fSschwarze #define ROFF_WHILE 0x100 /* Start a new .while loop. */ 39b7f92c5fSschwarze #define ROFF_LOOPCONT 0x200 /* Iterate the current .while loop. */ 40b7f92c5fSschwarze #define ROFF_LOOPEXIT 0x400 /* Exit the current .while loop. */ 41b7f92c5fSschwarze #define ROFF_LOOPMASK 0xf00 42b7f92c5fSschwarze 43a35fc07aSschwarze 447232fc26Sschwarze struct buf { 457232fc26Sschwarze char *buf; 467232fc26Sschwarze size_t sz; 4741b72316Sschwarze struct buf *next; 487232fc26Sschwarze }; 497232fc26Sschwarze 50f6854d5cSschwarze 51a35fc07aSschwarze struct roff; 52ede1b9d0Sschwarze struct roff_man; 53ea5923abSschwarze struct roff_node; 54a35fc07aSschwarze 55ea5923abSschwarze char *mandoc_normdate(struct roff_node *, struct roff_node *); 56f29433e9Sschwarze int mandoc_eos(const char *, size_t); 57f8618d99Sschwarze int mandoc_strntoi(const char *, size_t, int); 5888ec69e3Sschwarze const char *mandoc_a2msec(const char*); 59a35fc07aSschwarze 60ede1b9d0Sschwarze int mdoc_parseln(struct roff_man *, int, char *, int); 61ede1b9d0Sschwarze void mdoc_endparse(struct roff_man *); 62a35fc07aSschwarze 63ede1b9d0Sschwarze int man_parseln(struct roff_man *, int, char *, int); 64ede1b9d0Sschwarze void man_endparse(struct roff_man *); 65a35fc07aSschwarze 66cdea9283Sschwarze int preconv_cue(const struct buf *, size_t); 674d57ce78Sschwarze int preconv_encode(const struct buf *, size_t *, 68cdea9283Sschwarze struct buf *, size_t *, int *); 697232fc26Sschwarze 70a35fc07aSschwarze void roff_free(struct roff *); 7191305757Sschwarze struct roff *roff_alloc(int); 72a35fc07aSschwarze void roff_reset(struct roff *); 73405987fcSschwarze void roff_man_free(struct roff_man *); 7491305757Sschwarze struct roff_man *roff_man_alloc(struct roff *, const char *, int); 75405987fcSschwarze void roff_man_reset(struct roff_man *); 76dd9cc97dSschwarze int roff_parseln(struct roff *, int, struct buf *, int *, size_t); 773dc5225dSschwarze void roff_userret(struct roff *); 78a35fc07aSschwarze void roff_endparse(struct roff *); 796a6803e4Sschwarze void roff_setreg(struct roff *, const char *, int, char); 809f6d70bcSschwarze int roff_getreg(struct roff *, const char *); 81*f4432377Sschwarze int roff_evalnum(int, const char *, int *, int *, char, int); 8204e980cbSschwarze char *roff_strdup(const struct roff *, const char *); 83e94357f9Sschwarze char *roff_getarg(struct roff *, char **, int, int *); 841e6d02e2Sschwarze int roff_getcontrol(const struct roff *, 851e6d02e2Sschwarze const char *, int *); 86f0d7487dSschwarze int roff_getformat(const struct roff *); 87