xref: /titanic_44/usr/src/cmd/mandoc/libmdoc.h (revision 698f87a48e2e945bfe5493ce168e0d0ae1cedd5c)
1*698f87a4SGarrett D'Amore /*	$Id: libmdoc.h,v 1.82 2013/10/21 23:47:58 schwarze Exp $ */
295c635efSGarrett D'Amore /*
395c635efSGarrett D'Amore  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4*698f87a4SGarrett D'Amore  * Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org>
595c635efSGarrett D'Amore  *
695c635efSGarrett D'Amore  * Permission to use, copy, modify, and distribute this software for any
795c635efSGarrett D'Amore  * purpose with or without fee is hereby granted, provided that the above
895c635efSGarrett D'Amore  * copyright notice and this permission notice appear in all copies.
995c635efSGarrett D'Amore  *
1095c635efSGarrett D'Amore  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1195c635efSGarrett D'Amore  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1295c635efSGarrett D'Amore  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1395c635efSGarrett D'Amore  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1495c635efSGarrett D'Amore  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1595c635efSGarrett D'Amore  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1695c635efSGarrett D'Amore  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1795c635efSGarrett D'Amore  */
1895c635efSGarrett D'Amore #ifndef LIBMDOC_H
1995c635efSGarrett D'Amore #define LIBMDOC_H
2095c635efSGarrett D'Amore 
2195c635efSGarrett D'Amore enum	mdoc_next {
2295c635efSGarrett D'Amore 	MDOC_NEXT_SIBLING = 0,
2395c635efSGarrett D'Amore 	MDOC_NEXT_CHILD
2495c635efSGarrett D'Amore };
2595c635efSGarrett D'Amore 
2695c635efSGarrett D'Amore struct	mdoc {
2795c635efSGarrett D'Amore 	struct mparse	 *parse; /* parse pointer */
28*698f87a4SGarrett D'Amore 	char		 *defos; /* default argument for .Os */
2995c635efSGarrett D'Amore 	int		  flags; /* parse flags */
3095c635efSGarrett D'Amore #define	MDOC_HALT	 (1 << 0) /* error in parse: halt */
3195c635efSGarrett D'Amore #define	MDOC_LITERAL	 (1 << 1) /* in a literal scope */
3295c635efSGarrett D'Amore #define	MDOC_PBODY	 (1 << 2) /* in the document body */
3395c635efSGarrett D'Amore #define	MDOC_NEWLINE	 (1 << 3) /* first macro/text in a line */
3495c635efSGarrett D'Amore #define	MDOC_PHRASELIT	 (1 << 4) /* literal within a partila phrase */
3595c635efSGarrett D'Amore #define	MDOC_PPHRASE	 (1 << 5) /* within a partial phrase */
3695c635efSGarrett D'Amore #define	MDOC_FREECOL	 (1 << 6) /* `It' invocation should close */
3795c635efSGarrett D'Amore #define	MDOC_SYNOPSIS	 (1 << 7) /* SYNOPSIS-style formatting */
38*698f87a4SGarrett D'Amore #define	MDOC_KEEP	 (1 << 8) /* in a word keep */
39*698f87a4SGarrett D'Amore #define	MDOC_SMOFF	 (1 << 9) /* spacing is off */
4095c635efSGarrett D'Amore 	enum mdoc_next	  next; /* where to put the next node */
4195c635efSGarrett D'Amore 	struct mdoc_node *last; /* the last node parsed */
4295c635efSGarrett D'Amore 	struct mdoc_node *first; /* the first node parsed */
4395c635efSGarrett D'Amore 	struct mdoc_meta  meta; /* document meta-data */
4495c635efSGarrett D'Amore 	enum mdoc_sec	  lastnamed;
4595c635efSGarrett D'Amore 	enum mdoc_sec	  lastsec;
4695c635efSGarrett D'Amore 	struct roff	 *roff;
4795c635efSGarrett D'Amore };
4895c635efSGarrett D'Amore 
49*698f87a4SGarrett D'Amore #define	MACRO_PROT_ARGS	struct mdoc *mdoc, \
5095c635efSGarrett D'Amore 			enum mdoct tok, \
5195c635efSGarrett D'Amore 			int line, \
5295c635efSGarrett D'Amore 			int ppos, \
5395c635efSGarrett D'Amore 			int *pos, \
5495c635efSGarrett D'Amore 			char *buf
5595c635efSGarrett D'Amore 
5695c635efSGarrett D'Amore struct	mdoc_macro {
5795c635efSGarrett D'Amore 	int		(*fp)(MACRO_PROT_ARGS);
5895c635efSGarrett D'Amore 	int		  flags;
5995c635efSGarrett D'Amore #define	MDOC_CALLABLE	 (1 << 0)
6095c635efSGarrett D'Amore #define	MDOC_PARSED	 (1 << 1)
6195c635efSGarrett D'Amore #define	MDOC_EXPLICIT	 (1 << 2)
6295c635efSGarrett D'Amore #define	MDOC_PROLOGUE	 (1 << 3)
6395c635efSGarrett D'Amore #define	MDOC_IGNDELIM	 (1 << 4)
64*698f87a4SGarrett D'Amore #define	MDOC_JOIN	 (1 << 5)
6595c635efSGarrett D'Amore };
6695c635efSGarrett D'Amore 
6795c635efSGarrett D'Amore enum	margserr {
6895c635efSGarrett D'Amore 	ARGS_ERROR,
6995c635efSGarrett D'Amore 	ARGS_EOLN, /* end-of-line */
7095c635efSGarrett D'Amore 	ARGS_WORD, /* normal word */
7195c635efSGarrett D'Amore 	ARGS_PUNCT, /* series of punctuation */
7295c635efSGarrett D'Amore 	ARGS_QWORD, /* quoted word */
7395c635efSGarrett D'Amore 	ARGS_PHRASE, /* Ta'd phrase (-column) */
7495c635efSGarrett D'Amore 	ARGS_PPHRASE, /* tabbed phrase (-column) */
7595c635efSGarrett D'Amore 	ARGS_PEND /* last phrase (-column) */
7695c635efSGarrett D'Amore };
7795c635efSGarrett D'Amore 
7895c635efSGarrett D'Amore enum	margverr {
7995c635efSGarrett D'Amore 	ARGV_ERROR,
8095c635efSGarrett D'Amore 	ARGV_EOLN, /* end of line */
8195c635efSGarrett D'Amore 	ARGV_ARG, /* valid argument */
8295c635efSGarrett D'Amore 	ARGV_WORD /* normal word (or bad argument---same thing) */
8395c635efSGarrett D'Amore };
8495c635efSGarrett D'Amore 
8595c635efSGarrett D'Amore /*
8695c635efSGarrett D'Amore  * A punctuation delimiter is opening, closing, or "middle mark"
8795c635efSGarrett D'Amore  * punctuation.  These govern spacing.
8895c635efSGarrett D'Amore  * Opening punctuation (e.g., the opening parenthesis) suppresses the
8995c635efSGarrett D'Amore  * following space; closing punctuation (e.g., the closing parenthesis)
9095c635efSGarrett D'Amore  * suppresses the leading space; middle punctuation (e.g., the vertical
9195c635efSGarrett D'Amore  * bar) can do either.  The middle punctuation delimiter bends the rules
9295c635efSGarrett D'Amore  * depending on usage.
9395c635efSGarrett D'Amore  */
9495c635efSGarrett D'Amore enum	mdelim {
9595c635efSGarrett D'Amore 	DELIM_NONE = 0,
9695c635efSGarrett D'Amore 	DELIM_OPEN,
9795c635efSGarrett D'Amore 	DELIM_MIDDLE,
9895c635efSGarrett D'Amore 	DELIM_CLOSE,
9995c635efSGarrett D'Amore 	DELIM_MAX
10095c635efSGarrett D'Amore };
10195c635efSGarrett D'Amore 
10295c635efSGarrett D'Amore extern	const struct mdoc_macro *const mdoc_macros;
10395c635efSGarrett D'Amore 
10495c635efSGarrett D'Amore __BEGIN_DECLS
10595c635efSGarrett D'Amore 
106*698f87a4SGarrett D'Amore #define		  mdoc_pmsg(mdoc, l, p, t) \
107*698f87a4SGarrett D'Amore 		  mandoc_msg((t), (mdoc)->parse, (l), (p), NULL)
108*698f87a4SGarrett D'Amore #define		  mdoc_nmsg(mdoc, n, t) \
109*698f87a4SGarrett D'Amore 		  mandoc_msg((t), (mdoc)->parse, (n)->line, (n)->pos, NULL)
11095c635efSGarrett D'Amore int		  mdoc_macro(MACRO_PROT_ARGS);
11195c635efSGarrett D'Amore int		  mdoc_word_alloc(struct mdoc *,
11295c635efSGarrett D'Amore 			int, int, const char *);
113*698f87a4SGarrett D'Amore void		  mdoc_word_append(struct mdoc *, const char *);
11495c635efSGarrett D'Amore int		  mdoc_elem_alloc(struct mdoc *, int, int,
11595c635efSGarrett D'Amore 			enum mdoct, struct mdoc_arg *);
11695c635efSGarrett D'Amore int		  mdoc_block_alloc(struct mdoc *, int, int,
11795c635efSGarrett D'Amore 			enum mdoct, struct mdoc_arg *);
11895c635efSGarrett D'Amore int		  mdoc_head_alloc(struct mdoc *, int, int, enum mdoct);
11995c635efSGarrett D'Amore int		  mdoc_tail_alloc(struct mdoc *, int, int, enum mdoct);
12095c635efSGarrett D'Amore int		  mdoc_body_alloc(struct mdoc *, int, int, enum mdoct);
121*698f87a4SGarrett D'Amore int		  mdoc_endbody_alloc(struct mdoc *, int, int, enum mdoct,
122*698f87a4SGarrett D'Amore 			struct mdoc_node *, enum mdoc_endbody);
12395c635efSGarrett D'Amore void		  mdoc_node_delete(struct mdoc *, struct mdoc_node *);
124*698f87a4SGarrett D'Amore int		  mdoc_node_relink(struct mdoc *, struct mdoc_node *);
12595c635efSGarrett D'Amore void		  mdoc_hash_init(void);
12695c635efSGarrett D'Amore enum mdoct	  mdoc_hash_find(const char *);
12795c635efSGarrett D'Amore const char	 *mdoc_a2att(const char *);
12895c635efSGarrett D'Amore const char	 *mdoc_a2lib(const char *);
12995c635efSGarrett D'Amore const char	 *mdoc_a2st(const char *);
13095c635efSGarrett D'Amore const char	 *mdoc_a2arch(const char *);
13195c635efSGarrett D'Amore const char	 *mdoc_a2vol(const char *);
13295c635efSGarrett D'Amore int		  mdoc_valid_pre(struct mdoc *, struct mdoc_node *);
13395c635efSGarrett D'Amore int		  mdoc_valid_post(struct mdoc *);
13495c635efSGarrett D'Amore enum margverr	  mdoc_argv(struct mdoc *, int, enum mdoct,
13595c635efSGarrett D'Amore 			struct mdoc_arg **, int *, char *);
13695c635efSGarrett D'Amore void		  mdoc_argv_free(struct mdoc_arg *);
13795c635efSGarrett D'Amore enum margserr	  mdoc_args(struct mdoc *, int,
13895c635efSGarrett D'Amore 			int *, char *, enum mdoct, char **);
13995c635efSGarrett D'Amore enum margserr	  mdoc_zargs(struct mdoc *, int,
14095c635efSGarrett D'Amore 			int *, char *, char **);
14195c635efSGarrett D'Amore int		  mdoc_macroend(struct mdoc *);
14295c635efSGarrett D'Amore enum mdelim	  mdoc_isdelim(const char *);
14395c635efSGarrett D'Amore 
14495c635efSGarrett D'Amore __END_DECLS
14595c635efSGarrett D'Amore 
14695c635efSGarrett D'Amore #endif /*!LIBMDOC_H*/
147