xref: /titanic_41/usr/src/cmd/mandoc/libmdoc.h (revision ffb8ebfab4941f959e7caea93ecfb348cfa3515e)
1*ffb8ebfaSGarrett D'Amore /*	$Id: libmdoc.h,v 1.82 2013/10/21 23:47:58 schwarze Exp $ */
232a712daSGarrett D'Amore /*
332a712daSGarrett D'Amore  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4*ffb8ebfaSGarrett D'Amore  * Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org>
532a712daSGarrett D'Amore  *
632a712daSGarrett D'Amore  * Permission to use, copy, modify, and distribute this software for any
732a712daSGarrett D'Amore  * purpose with or without fee is hereby granted, provided that the above
832a712daSGarrett D'Amore  * copyright notice and this permission notice appear in all copies.
932a712daSGarrett D'Amore  *
1032a712daSGarrett D'Amore  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1132a712daSGarrett D'Amore  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1232a712daSGarrett D'Amore  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1332a712daSGarrett D'Amore  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1432a712daSGarrett D'Amore  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1532a712daSGarrett D'Amore  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1632a712daSGarrett D'Amore  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1732a712daSGarrett D'Amore  */
1832a712daSGarrett D'Amore #ifndef LIBMDOC_H
1932a712daSGarrett D'Amore #define LIBMDOC_H
2032a712daSGarrett D'Amore 
2132a712daSGarrett D'Amore enum	mdoc_next {
2232a712daSGarrett D'Amore 	MDOC_NEXT_SIBLING = 0,
2332a712daSGarrett D'Amore 	MDOC_NEXT_CHILD
2432a712daSGarrett D'Amore };
2532a712daSGarrett D'Amore 
2632a712daSGarrett D'Amore struct	mdoc {
2732a712daSGarrett D'Amore 	struct mparse	 *parse; /* parse pointer */
28*ffb8ebfaSGarrett D'Amore 	char		 *defos; /* default argument for .Os */
2932a712daSGarrett D'Amore 	int		  flags; /* parse flags */
3032a712daSGarrett D'Amore #define	MDOC_HALT	 (1 << 0) /* error in parse: halt */
3132a712daSGarrett D'Amore #define	MDOC_LITERAL	 (1 << 1) /* in a literal scope */
3232a712daSGarrett D'Amore #define	MDOC_PBODY	 (1 << 2) /* in the document body */
3332a712daSGarrett D'Amore #define	MDOC_NEWLINE	 (1 << 3) /* first macro/text in a line */
3432a712daSGarrett D'Amore #define	MDOC_PHRASELIT	 (1 << 4) /* literal within a partila phrase */
3532a712daSGarrett D'Amore #define	MDOC_PPHRASE	 (1 << 5) /* within a partial phrase */
3632a712daSGarrett D'Amore #define	MDOC_FREECOL	 (1 << 6) /* `It' invocation should close */
3732a712daSGarrett D'Amore #define	MDOC_SYNOPSIS	 (1 << 7) /* SYNOPSIS-style formatting */
38*ffb8ebfaSGarrett D'Amore #define	MDOC_KEEP	 (1 << 8) /* in a word keep */
39*ffb8ebfaSGarrett D'Amore #define	MDOC_SMOFF	 (1 << 9) /* spacing is off */
4032a712daSGarrett D'Amore 	enum mdoc_next	  next; /* where to put the next node */
4132a712daSGarrett D'Amore 	struct mdoc_node *last; /* the last node parsed */
4232a712daSGarrett D'Amore 	struct mdoc_node *first; /* the first node parsed */
4332a712daSGarrett D'Amore 	struct mdoc_meta  meta; /* document meta-data */
4432a712daSGarrett D'Amore 	enum mdoc_sec	  lastnamed;
4532a712daSGarrett D'Amore 	enum mdoc_sec	  lastsec;
4632a712daSGarrett D'Amore 	struct roff	 *roff;
4732a712daSGarrett D'Amore };
4832a712daSGarrett D'Amore 
49*ffb8ebfaSGarrett D'Amore #define	MACRO_PROT_ARGS	struct mdoc *mdoc, \
5032a712daSGarrett D'Amore 			enum mdoct tok, \
5132a712daSGarrett D'Amore 			int line, \
5232a712daSGarrett D'Amore 			int ppos, \
5332a712daSGarrett D'Amore 			int *pos, \
5432a712daSGarrett D'Amore 			char *buf
5532a712daSGarrett D'Amore 
5632a712daSGarrett D'Amore struct	mdoc_macro {
5732a712daSGarrett D'Amore 	int		(*fp)(MACRO_PROT_ARGS);
5832a712daSGarrett D'Amore 	int		  flags;
5932a712daSGarrett D'Amore #define	MDOC_CALLABLE	 (1 << 0)
6032a712daSGarrett D'Amore #define	MDOC_PARSED	 (1 << 1)
6132a712daSGarrett D'Amore #define	MDOC_EXPLICIT	 (1 << 2)
6232a712daSGarrett D'Amore #define	MDOC_PROLOGUE	 (1 << 3)
6332a712daSGarrett D'Amore #define	MDOC_IGNDELIM	 (1 << 4)
64*ffb8ebfaSGarrett D'Amore #define	MDOC_JOIN	 (1 << 5)
6532a712daSGarrett D'Amore };
6632a712daSGarrett D'Amore 
6732a712daSGarrett D'Amore enum	margserr {
6832a712daSGarrett D'Amore 	ARGS_ERROR,
6932a712daSGarrett D'Amore 	ARGS_EOLN, /* end-of-line */
7032a712daSGarrett D'Amore 	ARGS_WORD, /* normal word */
7132a712daSGarrett D'Amore 	ARGS_PUNCT, /* series of punctuation */
7232a712daSGarrett D'Amore 	ARGS_QWORD, /* quoted word */
7332a712daSGarrett D'Amore 	ARGS_PHRASE, /* Ta'd phrase (-column) */
7432a712daSGarrett D'Amore 	ARGS_PPHRASE, /* tabbed phrase (-column) */
7532a712daSGarrett D'Amore 	ARGS_PEND /* last phrase (-column) */
7632a712daSGarrett D'Amore };
7732a712daSGarrett D'Amore 
7832a712daSGarrett D'Amore enum	margverr {
7932a712daSGarrett D'Amore 	ARGV_ERROR,
8032a712daSGarrett D'Amore 	ARGV_EOLN, /* end of line */
8132a712daSGarrett D'Amore 	ARGV_ARG, /* valid argument */
8232a712daSGarrett D'Amore 	ARGV_WORD /* normal word (or bad argument---same thing) */
8332a712daSGarrett D'Amore };
8432a712daSGarrett D'Amore 
8532a712daSGarrett D'Amore /*
8632a712daSGarrett D'Amore  * A punctuation delimiter is opening, closing, or "middle mark"
8732a712daSGarrett D'Amore  * punctuation.  These govern spacing.
8832a712daSGarrett D'Amore  * Opening punctuation (e.g., the opening parenthesis) suppresses the
8932a712daSGarrett D'Amore  * following space; closing punctuation (e.g., the closing parenthesis)
9032a712daSGarrett D'Amore  * suppresses the leading space; middle punctuation (e.g., the vertical
9132a712daSGarrett D'Amore  * bar) can do either.  The middle punctuation delimiter bends the rules
9232a712daSGarrett D'Amore  * depending on usage.
9332a712daSGarrett D'Amore  */
9432a712daSGarrett D'Amore enum	mdelim {
9532a712daSGarrett D'Amore 	DELIM_NONE = 0,
9632a712daSGarrett D'Amore 	DELIM_OPEN,
9732a712daSGarrett D'Amore 	DELIM_MIDDLE,
9832a712daSGarrett D'Amore 	DELIM_CLOSE,
9932a712daSGarrett D'Amore 	DELIM_MAX
10032a712daSGarrett D'Amore };
10132a712daSGarrett D'Amore 
10232a712daSGarrett D'Amore extern	const struct mdoc_macro *const mdoc_macros;
10332a712daSGarrett D'Amore 
10432a712daSGarrett D'Amore __BEGIN_DECLS
10532a712daSGarrett D'Amore 
106*ffb8ebfaSGarrett D'Amore #define		  mdoc_pmsg(mdoc, l, p, t) \
107*ffb8ebfaSGarrett D'Amore 		  mandoc_msg((t), (mdoc)->parse, (l), (p), NULL)
108*ffb8ebfaSGarrett D'Amore #define		  mdoc_nmsg(mdoc, n, t) \
109*ffb8ebfaSGarrett D'Amore 		  mandoc_msg((t), (mdoc)->parse, (n)->line, (n)->pos, NULL)
11032a712daSGarrett D'Amore int		  mdoc_macro(MACRO_PROT_ARGS);
11132a712daSGarrett D'Amore int		  mdoc_word_alloc(struct mdoc *,
11232a712daSGarrett D'Amore 			int, int, const char *);
113*ffb8ebfaSGarrett D'Amore void		  mdoc_word_append(struct mdoc *, const char *);
11432a712daSGarrett D'Amore int		  mdoc_elem_alloc(struct mdoc *, int, int,
11532a712daSGarrett D'Amore 			enum mdoct, struct mdoc_arg *);
11632a712daSGarrett D'Amore int		  mdoc_block_alloc(struct mdoc *, int, int,
11732a712daSGarrett D'Amore 			enum mdoct, struct mdoc_arg *);
11832a712daSGarrett D'Amore int		  mdoc_head_alloc(struct mdoc *, int, int, enum mdoct);
11932a712daSGarrett D'Amore int		  mdoc_tail_alloc(struct mdoc *, int, int, enum mdoct);
12032a712daSGarrett D'Amore int		  mdoc_body_alloc(struct mdoc *, int, int, enum mdoct);
121*ffb8ebfaSGarrett D'Amore int		  mdoc_endbody_alloc(struct mdoc *, int, int, enum mdoct,
122*ffb8ebfaSGarrett D'Amore 			struct mdoc_node *, enum mdoc_endbody);
12332a712daSGarrett D'Amore void		  mdoc_node_delete(struct mdoc *, struct mdoc_node *);
124*ffb8ebfaSGarrett D'Amore int		  mdoc_node_relink(struct mdoc *, struct mdoc_node *);
12532a712daSGarrett D'Amore void		  mdoc_hash_init(void);
12632a712daSGarrett D'Amore enum mdoct	  mdoc_hash_find(const char *);
12732a712daSGarrett D'Amore const char	 *mdoc_a2att(const char *);
12832a712daSGarrett D'Amore const char	 *mdoc_a2lib(const char *);
12932a712daSGarrett D'Amore const char	 *mdoc_a2st(const char *);
13032a712daSGarrett D'Amore const char	 *mdoc_a2arch(const char *);
13132a712daSGarrett D'Amore const char	 *mdoc_a2vol(const char *);
13232a712daSGarrett D'Amore int		  mdoc_valid_pre(struct mdoc *, struct mdoc_node *);
13332a712daSGarrett D'Amore int		  mdoc_valid_post(struct mdoc *);
13432a712daSGarrett D'Amore enum margverr	  mdoc_argv(struct mdoc *, int, enum mdoct,
13532a712daSGarrett D'Amore 			struct mdoc_arg **, int *, char *);
13632a712daSGarrett D'Amore void		  mdoc_argv_free(struct mdoc_arg *);
13732a712daSGarrett D'Amore enum margserr	  mdoc_args(struct mdoc *, int,
13832a712daSGarrett D'Amore 			int *, char *, enum mdoct, char **);
13932a712daSGarrett D'Amore enum margserr	  mdoc_zargs(struct mdoc *, int,
14032a712daSGarrett D'Amore 			int *, char *, char **);
14132a712daSGarrett D'Amore int		  mdoc_macroend(struct mdoc *);
14232a712daSGarrett D'Amore enum mdelim	  mdoc_isdelim(const char *);
14332a712daSGarrett D'Amore 
14432a712daSGarrett D'Amore __END_DECLS
14532a712daSGarrett D'Amore 
14632a712daSGarrett D'Amore #endif /*!LIBMDOC_H*/
147