xref: /freebsd/contrib/mandoc/roff_int.h (revision 6d38604f)
1*6d38604fSBaptiste Daroussin /* $OpenBSD: roff_int.h,v 1.16 2019/01/05 00:36:46 schwarze Exp $	*/
261d06d6bSBaptiste Daroussin /*
3*6d38604fSBaptiste Daroussin  * Copyright (c) 2013-2015, 2017-2020 Ingo Schwarze <schwarze@openbsd.org>
461d06d6bSBaptiste Daroussin  * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
561d06d6bSBaptiste Daroussin  *
661d06d6bSBaptiste Daroussin  * Permission to use, copy, modify, and distribute this software for any
761d06d6bSBaptiste Daroussin  * purpose with or without fee is hereby granted, provided that the above
861d06d6bSBaptiste Daroussin  * copyright notice and this permission notice appear in all copies.
961d06d6bSBaptiste Daroussin  *
1061d06d6bSBaptiste Daroussin  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
1161d06d6bSBaptiste Daroussin  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1261d06d6bSBaptiste Daroussin  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
1361d06d6bSBaptiste Daroussin  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1461d06d6bSBaptiste Daroussin  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1561d06d6bSBaptiste Daroussin  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1661d06d6bSBaptiste Daroussin  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
177295610fSBaptiste Daroussin  *
187295610fSBaptiste Daroussin  * Parser internals shared by multiple parsers.
1961d06d6bSBaptiste Daroussin  */
2061d06d6bSBaptiste Daroussin 
217295610fSBaptiste Daroussin struct	ohash;
227295610fSBaptiste Daroussin struct	roff_node;
237295610fSBaptiste Daroussin struct	roff_meta;
247295610fSBaptiste Daroussin struct	roff;
257295610fSBaptiste Daroussin struct	mdoc_arg;
267295610fSBaptiste Daroussin 
277295610fSBaptiste Daroussin enum	roff_next {
287295610fSBaptiste Daroussin 	ROFF_NEXT_SIBLING = 0,
297295610fSBaptiste Daroussin 	ROFF_NEXT_CHILD
307295610fSBaptiste Daroussin };
317295610fSBaptiste Daroussin 
327295610fSBaptiste Daroussin struct	roff_man {
337295610fSBaptiste Daroussin 	struct roff_meta  meta;    /* Public parse results. */
347295610fSBaptiste Daroussin 	struct roff	 *roff;    /* Roff parser state data. */
357295610fSBaptiste Daroussin 	struct ohash	 *mdocmac; /* Mdoc macro lookup table. */
367295610fSBaptiste Daroussin 	struct ohash	 *manmac;  /* Man macro lookup table. */
377295610fSBaptiste Daroussin 	const char	 *os_s;    /* Default operating system. */
387295610fSBaptiste Daroussin 	struct roff_node *last;    /* The last node parsed. */
397295610fSBaptiste Daroussin 	struct roff_node *last_es; /* The most recent Es node. */
407295610fSBaptiste Daroussin 	int		  quick;   /* Abort parse early. */
417295610fSBaptiste Daroussin 	int		  flags;   /* Parse flags. */
427295610fSBaptiste Daroussin #define	ROFF_NOFILL	 (1 << 1)  /* Fill mode switched off. */
437295610fSBaptiste Daroussin #define	MDOC_PBODY	 (1 << 2)  /* In the document body. */
447295610fSBaptiste Daroussin #define	MDOC_NEWLINE	 (1 << 3)  /* First macro/text in a line. */
457295610fSBaptiste Daroussin #define	MDOC_PHRASE	 (1 << 4)  /* In a Bl -column phrase. */
467295610fSBaptiste Daroussin #define	MDOC_PHRASELIT	 (1 << 5)  /* Literal within a phrase. */
477295610fSBaptiste Daroussin #define	MDOC_FREECOL	 (1 << 6)  /* `It' invocation should close. */
487295610fSBaptiste Daroussin #define	MDOC_SYNOPSIS	 (1 << 7)  /* SYNOPSIS-style formatting. */
497295610fSBaptiste Daroussin #define	MDOC_KEEP	 (1 << 8)  /* In a word keep. */
507295610fSBaptiste Daroussin #define	MDOC_SMOFF	 (1 << 9)  /* Spacing is off. */
517295610fSBaptiste Daroussin #define	MDOC_NODELIMC	 (1 << 10) /* Disable closing delimiter handling. */
527295610fSBaptiste Daroussin #define	MAN_ELINE	 (1 << 11) /* Next-line element scope. */
537295610fSBaptiste Daroussin #define	MAN_BLINE	 (1 << 12) /* Next-line block scope. */
547295610fSBaptiste Daroussin #define	MDOC_PHRASEQF	 (1 << 13) /* Quote first word encountered. */
557295610fSBaptiste Daroussin #define	MDOC_PHRASEQL	 (1 << 14) /* Quote last word of this phrase. */
567295610fSBaptiste Daroussin #define	MDOC_PHRASEQN	 (1 << 15) /* Quote first word of the next phrase. */
577295610fSBaptiste Daroussin #define	ROFF_NONOFILL	 (1 << 16) /* Temporarily suspend no-fill mode. */
587295610fSBaptiste Daroussin #define	MAN_NEWLINE	  MDOC_NEWLINE
597295610fSBaptiste Daroussin 	enum roff_sec	  lastsec; /* Last section seen. */
607295610fSBaptiste Daroussin 	enum roff_sec	  lastnamed; /* Last standard section seen. */
617295610fSBaptiste Daroussin 	enum roff_next	  next;    /* Where to put the next node. */
62*6d38604fSBaptiste Daroussin 	char		  filesec; /* Section digit in the file name. */
637295610fSBaptiste Daroussin };
647295610fSBaptiste Daroussin 
657295610fSBaptiste Daroussin 
6661d06d6bSBaptiste Daroussin struct roff_node *roff_node_alloc(struct roff_man *, int, int,
6761d06d6bSBaptiste Daroussin 			enum roff_type, int);
6861d06d6bSBaptiste Daroussin void		  roff_node_append(struct roff_man *, struct roff_node *);
6961d06d6bSBaptiste Daroussin void		  roff_word_alloc(struct roff_man *, int, int, const char *);
7061d06d6bSBaptiste Daroussin void		  roff_word_append(struct roff_man *, const char *);
7161d06d6bSBaptiste Daroussin void		  roff_elem_alloc(struct roff_man *, int, int, int);
7261d06d6bSBaptiste Daroussin struct roff_node *roff_block_alloc(struct roff_man *, int, int, int);
7361d06d6bSBaptiste Daroussin struct roff_node *roff_head_alloc(struct roff_man *, int, int, int);
7461d06d6bSBaptiste Daroussin struct roff_node *roff_body_alloc(struct roff_man *, int, int, int);
7561d06d6bSBaptiste Daroussin void		  roff_node_unlink(struct roff_man *, struct roff_node *);
767295610fSBaptiste Daroussin void		  roff_node_relink(struct roff_man *, struct roff_node *);
7761d06d6bSBaptiste Daroussin void		  roff_node_free(struct roff_node *);
7861d06d6bSBaptiste Daroussin void		  roff_node_delete(struct roff_man *, struct roff_node *);
7961d06d6bSBaptiste Daroussin 
807295610fSBaptiste Daroussin struct ohash	 *roffhash_alloc(enum roff_tok, enum roff_tok);
817295610fSBaptiste Daroussin enum roff_tok	  roffhash_find(struct ohash *, const char *, size_t);
827295610fSBaptiste Daroussin void		  roffhash_free(struct ohash *);
837295610fSBaptiste Daroussin 
847295610fSBaptiste Daroussin void		  roff_state_reset(struct roff_man *);
857295610fSBaptiste Daroussin void		  roff_validate(struct roff_man *);
867295610fSBaptiste Daroussin 
8761d06d6bSBaptiste Daroussin /*
8861d06d6bSBaptiste Daroussin  * Functions called from roff.c need to be declared here,
8961d06d6bSBaptiste Daroussin  * not in libmdoc.h or libman.h, even if they are specific
9061d06d6bSBaptiste Daroussin  * to either the mdoc(7) or the man(7) parser.
9161d06d6bSBaptiste Daroussin  */
9261d06d6bSBaptiste Daroussin 
9361d06d6bSBaptiste Daroussin void		  man_breakscope(struct roff_man *, int);
9461d06d6bSBaptiste Daroussin void		  mdoc_argv_free(struct mdoc_arg *);
95