xref: /titanic_50/usr/src/cmd/mandoc/libmdoc.h (revision 260e9a87725c090ba5835b1f9f0b62fa2f96036f)
1*260e9a87SYuri Pankov /*	$Id: libmdoc.h,v 1.97 2015/02/02 04:26:44 schwarze Exp $ */
295c635efSGarrett D'Amore /*
395c635efSGarrett D'Amore  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4*260e9a87SYuri Pankov  * Copyright (c) 2013, 2014 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 
1995c635efSGarrett D'Amore enum	mdoc_next {
2095c635efSGarrett D'Amore 	MDOC_NEXT_SIBLING = 0,
2195c635efSGarrett D'Amore 	MDOC_NEXT_CHILD
2295c635efSGarrett D'Amore };
2395c635efSGarrett D'Amore 
2495c635efSGarrett D'Amore struct	mdoc {
2595c635efSGarrett D'Amore 	struct mparse	 *parse; /* parse pointer */
26*260e9a87SYuri Pankov 	const char	 *defos; /* default argument for .Os */
27*260e9a87SYuri Pankov 	int		  quick; /* abort parse early */
2895c635efSGarrett D'Amore 	int		  flags; /* parse flags */
2995c635efSGarrett D'Amore #define	MDOC_LITERAL	 (1 << 1) /* in a literal scope */
3095c635efSGarrett D'Amore #define	MDOC_PBODY	 (1 << 2) /* in the document body */
3195c635efSGarrett D'Amore #define	MDOC_NEWLINE	 (1 << 3) /* first macro/text in a line */
3295c635efSGarrett D'Amore #define	MDOC_PHRASELIT	 (1 << 4) /* literal within a partila phrase */
3395c635efSGarrett D'Amore #define	MDOC_PPHRASE	 (1 << 5) /* within a partial phrase */
3495c635efSGarrett D'Amore #define	MDOC_FREECOL	 (1 << 6) /* `It' invocation should close */
3595c635efSGarrett D'Amore #define	MDOC_SYNOPSIS	 (1 << 7) /* SYNOPSIS-style formatting */
36698f87a4SGarrett D'Amore #define	MDOC_KEEP	 (1 << 8) /* in a word keep */
37698f87a4SGarrett D'Amore #define	MDOC_SMOFF	 (1 << 9) /* spacing is off */
38*260e9a87SYuri Pankov #define	MDOC_NODELIMC	 (1 << 10) /* disable closing delimiter handling */
3995c635efSGarrett D'Amore 	enum mdoc_next	  next; /* where to put the next node */
4095c635efSGarrett D'Amore 	struct mdoc_node *last; /* the last node parsed */
4195c635efSGarrett D'Amore 	struct mdoc_node *first; /* the first node parsed */
42*260e9a87SYuri Pankov 	struct mdoc_node *last_es; /* the most recent Es node */
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 
49698f87a4SGarrett 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 {
57*260e9a87SYuri Pankov 	void		(*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)
64698f87a4SGarrett 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 /*
7995c635efSGarrett D'Amore  * A punctuation delimiter is opening, closing, or "middle mark"
8095c635efSGarrett D'Amore  * punctuation.  These govern spacing.
8195c635efSGarrett D'Amore  * Opening punctuation (e.g., the opening parenthesis) suppresses the
8295c635efSGarrett D'Amore  * following space; closing punctuation (e.g., the closing parenthesis)
8395c635efSGarrett D'Amore  * suppresses the leading space; middle punctuation (e.g., the vertical
8495c635efSGarrett D'Amore  * bar) can do either.  The middle punctuation delimiter bends the rules
8595c635efSGarrett D'Amore  * depending on usage.
8695c635efSGarrett D'Amore  */
8795c635efSGarrett D'Amore enum	mdelim {
8895c635efSGarrett D'Amore 	DELIM_NONE = 0,
8995c635efSGarrett D'Amore 	DELIM_OPEN,
9095c635efSGarrett D'Amore 	DELIM_MIDDLE,
9195c635efSGarrett D'Amore 	DELIM_CLOSE,
9295c635efSGarrett D'Amore 	DELIM_MAX
9395c635efSGarrett D'Amore };
9495c635efSGarrett D'Amore 
9595c635efSGarrett D'Amore extern	const struct mdoc_macro *const mdoc_macros;
9695c635efSGarrett D'Amore 
9795c635efSGarrett D'Amore __BEGIN_DECLS
9895c635efSGarrett D'Amore 
99*260e9a87SYuri Pankov void		  mdoc_macro(MACRO_PROT_ARGS);
100*260e9a87SYuri Pankov void		  mdoc_word_alloc(struct mdoc *, int, int, const char *);
101698f87a4SGarrett D'Amore void		  mdoc_word_append(struct mdoc *, const char *);
102*260e9a87SYuri Pankov void		  mdoc_elem_alloc(struct mdoc *, int, int,
10395c635efSGarrett D'Amore 			enum mdoct, struct mdoc_arg *);
104*260e9a87SYuri Pankov struct mdoc_node *mdoc_block_alloc(struct mdoc *, int, int,
10595c635efSGarrett D'Amore 			enum mdoct, struct mdoc_arg *);
106*260e9a87SYuri Pankov struct mdoc_node *mdoc_head_alloc(struct mdoc *, int, int, enum mdoct);
107*260e9a87SYuri Pankov void		  mdoc_tail_alloc(struct mdoc *, int, int, enum mdoct);
108*260e9a87SYuri Pankov struct mdoc_node *mdoc_body_alloc(struct mdoc *, int, int, enum mdoct);
109*260e9a87SYuri Pankov struct mdoc_node *mdoc_endbody_alloc(struct mdoc *, int, int, enum mdoct,
110698f87a4SGarrett D'Amore 			struct mdoc_node *, enum mdoc_endbody);
11195c635efSGarrett D'Amore void		  mdoc_node_delete(struct mdoc *, struct mdoc_node *);
112*260e9a87SYuri Pankov void		  mdoc_node_relink(struct mdoc *, struct mdoc_node *);
11395c635efSGarrett D'Amore void		  mdoc_hash_init(void);
11495c635efSGarrett D'Amore enum mdoct	  mdoc_hash_find(const char *);
11595c635efSGarrett D'Amore const char	 *mdoc_a2att(const char *);
11695c635efSGarrett D'Amore const char	 *mdoc_a2lib(const char *);
11795c635efSGarrett D'Amore const char	 *mdoc_a2st(const char *);
11895c635efSGarrett D'Amore const char	 *mdoc_a2arch(const char *);
119*260e9a87SYuri Pankov void		  mdoc_valid_pre(struct mdoc *, struct mdoc_node *);
120*260e9a87SYuri Pankov void		  mdoc_valid_post(struct mdoc *);
121*260e9a87SYuri Pankov void		  mdoc_argv(struct mdoc *, int, enum mdoct,
12295c635efSGarrett D'Amore 			struct mdoc_arg **, int *, char *);
12395c635efSGarrett D'Amore void		  mdoc_argv_free(struct mdoc_arg *);
12495c635efSGarrett D'Amore enum margserr	  mdoc_args(struct mdoc *, int,
12595c635efSGarrett D'Amore 			int *, char *, enum mdoct, char **);
126*260e9a87SYuri Pankov void		  mdoc_macroend(struct mdoc *);
12795c635efSGarrett D'Amore enum mdelim	  mdoc_isdelim(const char *);
12895c635efSGarrett D'Amore 
12995c635efSGarrett D'Amore __END_DECLS
130