xref: /titanic_41/usr/src/cmd/mandoc/libmdoc.h (revision 32a712da90cea6ff9a05f51e7844944ccfa28d5e)
1*32a712daSGarrett D'Amore /*	$Id: libmdoc.h,v 1.78 2011/12/02 01:37:14 schwarze Exp $ */
2*32a712daSGarrett D'Amore /*
3*32a712daSGarrett D'Amore  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4*32a712daSGarrett D'Amore  *
5*32a712daSGarrett D'Amore  * Permission to use, copy, modify, and distribute this software for any
6*32a712daSGarrett D'Amore  * purpose with or without fee is hereby granted, provided that the above
7*32a712daSGarrett D'Amore  * copyright notice and this permission notice appear in all copies.
8*32a712daSGarrett D'Amore  *
9*32a712daSGarrett D'Amore  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*32a712daSGarrett D'Amore  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*32a712daSGarrett D'Amore  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*32a712daSGarrett D'Amore  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*32a712daSGarrett D'Amore  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*32a712daSGarrett D'Amore  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*32a712daSGarrett D'Amore  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*32a712daSGarrett D'Amore  */
17*32a712daSGarrett D'Amore #ifndef LIBMDOC_H
18*32a712daSGarrett D'Amore #define LIBMDOC_H
19*32a712daSGarrett D'Amore 
20*32a712daSGarrett D'Amore enum	mdoc_next {
21*32a712daSGarrett D'Amore 	MDOC_NEXT_SIBLING = 0,
22*32a712daSGarrett D'Amore 	MDOC_NEXT_CHILD
23*32a712daSGarrett D'Amore };
24*32a712daSGarrett D'Amore 
25*32a712daSGarrett D'Amore struct	mdoc {
26*32a712daSGarrett D'Amore 	struct mparse	 *parse; /* parse pointer */
27*32a712daSGarrett D'Amore 	int		  flags; /* parse flags */
28*32a712daSGarrett D'Amore #define	MDOC_HALT	 (1 << 0) /* error in parse: halt */
29*32a712daSGarrett D'Amore #define	MDOC_LITERAL	 (1 << 1) /* in a literal scope */
30*32a712daSGarrett D'Amore #define	MDOC_PBODY	 (1 << 2) /* in the document body */
31*32a712daSGarrett D'Amore #define	MDOC_NEWLINE	 (1 << 3) /* first macro/text in a line */
32*32a712daSGarrett D'Amore #define	MDOC_PHRASELIT	 (1 << 4) /* literal within a partila phrase */
33*32a712daSGarrett D'Amore #define	MDOC_PPHRASE	 (1 << 5) /* within a partial phrase */
34*32a712daSGarrett D'Amore #define	MDOC_FREECOL	 (1 << 6) /* `It' invocation should close */
35*32a712daSGarrett D'Amore #define	MDOC_SYNOPSIS	 (1 << 7) /* SYNOPSIS-style formatting */
36*32a712daSGarrett D'Amore 	enum mdoc_next	  next; /* where to put the next node */
37*32a712daSGarrett D'Amore 	struct mdoc_node *last; /* the last node parsed */
38*32a712daSGarrett D'Amore 	struct mdoc_node *first; /* the first node parsed */
39*32a712daSGarrett D'Amore 	struct mdoc_meta  meta; /* document meta-data */
40*32a712daSGarrett D'Amore 	enum mdoc_sec	  lastnamed;
41*32a712daSGarrett D'Amore 	enum mdoc_sec	  lastsec;
42*32a712daSGarrett D'Amore 	struct roff	 *roff;
43*32a712daSGarrett D'Amore };
44*32a712daSGarrett D'Amore 
45*32a712daSGarrett D'Amore #define	MACRO_PROT_ARGS	struct mdoc *m, \
46*32a712daSGarrett D'Amore 			enum mdoct tok, \
47*32a712daSGarrett D'Amore 			int line, \
48*32a712daSGarrett D'Amore 			int ppos, \
49*32a712daSGarrett D'Amore 			int *pos, \
50*32a712daSGarrett D'Amore 			char *buf
51*32a712daSGarrett D'Amore 
52*32a712daSGarrett D'Amore struct	mdoc_macro {
53*32a712daSGarrett D'Amore 	int		(*fp)(MACRO_PROT_ARGS);
54*32a712daSGarrett D'Amore 	int		  flags;
55*32a712daSGarrett D'Amore #define	MDOC_CALLABLE	 (1 << 0)
56*32a712daSGarrett D'Amore #define	MDOC_PARSED	 (1 << 1)
57*32a712daSGarrett D'Amore #define	MDOC_EXPLICIT	 (1 << 2)
58*32a712daSGarrett D'Amore #define	MDOC_PROLOGUE	 (1 << 3)
59*32a712daSGarrett D'Amore #define	MDOC_IGNDELIM	 (1 << 4)
60*32a712daSGarrett D'Amore 	/* Reserved words in arguments treated as text. */
61*32a712daSGarrett D'Amore };
62*32a712daSGarrett D'Amore 
63*32a712daSGarrett D'Amore enum	margserr {
64*32a712daSGarrett D'Amore 	ARGS_ERROR,
65*32a712daSGarrett D'Amore 	ARGS_EOLN, /* end-of-line */
66*32a712daSGarrett D'Amore 	ARGS_WORD, /* normal word */
67*32a712daSGarrett D'Amore 	ARGS_PUNCT, /* series of punctuation */
68*32a712daSGarrett D'Amore 	ARGS_QWORD, /* quoted word */
69*32a712daSGarrett D'Amore 	ARGS_PHRASE, /* Ta'd phrase (-column) */
70*32a712daSGarrett D'Amore 	ARGS_PPHRASE, /* tabbed phrase (-column) */
71*32a712daSGarrett D'Amore 	ARGS_PEND /* last phrase (-column) */
72*32a712daSGarrett D'Amore };
73*32a712daSGarrett D'Amore 
74*32a712daSGarrett D'Amore enum	margverr {
75*32a712daSGarrett D'Amore 	ARGV_ERROR,
76*32a712daSGarrett D'Amore 	ARGV_EOLN, /* end of line */
77*32a712daSGarrett D'Amore 	ARGV_ARG, /* valid argument */
78*32a712daSGarrett D'Amore 	ARGV_WORD /* normal word (or bad argument---same thing) */
79*32a712daSGarrett D'Amore };
80*32a712daSGarrett D'Amore 
81*32a712daSGarrett D'Amore /*
82*32a712daSGarrett D'Amore  * A punctuation delimiter is opening, closing, or "middle mark"
83*32a712daSGarrett D'Amore  * punctuation.  These govern spacing.
84*32a712daSGarrett D'Amore  * Opening punctuation (e.g., the opening parenthesis) suppresses the
85*32a712daSGarrett D'Amore  * following space; closing punctuation (e.g., the closing parenthesis)
86*32a712daSGarrett D'Amore  * suppresses the leading space; middle punctuation (e.g., the vertical
87*32a712daSGarrett D'Amore  * bar) can do either.  The middle punctuation delimiter bends the rules
88*32a712daSGarrett D'Amore  * depending on usage.
89*32a712daSGarrett D'Amore  */
90*32a712daSGarrett D'Amore enum	mdelim {
91*32a712daSGarrett D'Amore 	DELIM_NONE = 0,
92*32a712daSGarrett D'Amore 	DELIM_OPEN,
93*32a712daSGarrett D'Amore 	DELIM_MIDDLE,
94*32a712daSGarrett D'Amore 	DELIM_CLOSE,
95*32a712daSGarrett D'Amore 	DELIM_MAX
96*32a712daSGarrett D'Amore };
97*32a712daSGarrett D'Amore 
98*32a712daSGarrett D'Amore extern	const struct mdoc_macro *const mdoc_macros;
99*32a712daSGarrett D'Amore 
100*32a712daSGarrett D'Amore __BEGIN_DECLS
101*32a712daSGarrett D'Amore 
102*32a712daSGarrett D'Amore #define		  mdoc_pmsg(m, l, p, t) \
103*32a712daSGarrett D'Amore 		  mandoc_msg((t), (m)->parse, (l), (p), NULL)
104*32a712daSGarrett D'Amore #define		  mdoc_nmsg(m, n, t) \
105*32a712daSGarrett D'Amore 		  mandoc_msg((t), (m)->parse, (n)->line, (n)->pos, NULL)
106*32a712daSGarrett D'Amore int		  mdoc_macro(MACRO_PROT_ARGS);
107*32a712daSGarrett D'Amore int		  mdoc_word_alloc(struct mdoc *,
108*32a712daSGarrett D'Amore 			int, int, const char *);
109*32a712daSGarrett D'Amore int		  mdoc_elem_alloc(struct mdoc *, int, int,
110*32a712daSGarrett D'Amore 			enum mdoct, struct mdoc_arg *);
111*32a712daSGarrett D'Amore int		  mdoc_block_alloc(struct mdoc *, int, int,
112*32a712daSGarrett D'Amore 			enum mdoct, struct mdoc_arg *);
113*32a712daSGarrett D'Amore int		  mdoc_head_alloc(struct mdoc *, int, int, enum mdoct);
114*32a712daSGarrett D'Amore int		  mdoc_tail_alloc(struct mdoc *, int, int, enum mdoct);
115*32a712daSGarrett D'Amore int		  mdoc_body_alloc(struct mdoc *, int, int, enum mdoct);
116*32a712daSGarrett D'Amore int		  mdoc_endbody_alloc(struct mdoc *m, int line, int pos,
117*32a712daSGarrett D'Amore 			enum mdoct tok, struct mdoc_node *body,
118*32a712daSGarrett D'Amore 			enum mdoc_endbody end);
119*32a712daSGarrett D'Amore void		  mdoc_node_delete(struct mdoc *, struct mdoc_node *);
120*32a712daSGarrett D'Amore void		  mdoc_hash_init(void);
121*32a712daSGarrett D'Amore enum mdoct	  mdoc_hash_find(const char *);
122*32a712daSGarrett D'Amore const char	 *mdoc_a2att(const char *);
123*32a712daSGarrett D'Amore const char	 *mdoc_a2lib(const char *);
124*32a712daSGarrett D'Amore const char	 *mdoc_a2st(const char *);
125*32a712daSGarrett D'Amore const char	 *mdoc_a2arch(const char *);
126*32a712daSGarrett D'Amore const char	 *mdoc_a2vol(const char *);
127*32a712daSGarrett D'Amore int		  mdoc_valid_pre(struct mdoc *, struct mdoc_node *);
128*32a712daSGarrett D'Amore int		  mdoc_valid_post(struct mdoc *);
129*32a712daSGarrett D'Amore enum margverr	  mdoc_argv(struct mdoc *, int, enum mdoct,
130*32a712daSGarrett D'Amore 			struct mdoc_arg **, int *, char *);
131*32a712daSGarrett D'Amore void		  mdoc_argv_free(struct mdoc_arg *);
132*32a712daSGarrett D'Amore enum margserr	  mdoc_args(struct mdoc *, int,
133*32a712daSGarrett D'Amore 			int *, char *, enum mdoct, char **);
134*32a712daSGarrett D'Amore enum margserr	  mdoc_zargs(struct mdoc *, int,
135*32a712daSGarrett D'Amore 			int *, char *, char **);
136*32a712daSGarrett D'Amore int		  mdoc_macroend(struct mdoc *);
137*32a712daSGarrett D'Amore enum mdelim	  mdoc_isdelim(const char *);
138*32a712daSGarrett D'Amore 
139*32a712daSGarrett D'Amore __END_DECLS
140*32a712daSGarrett D'Amore 
141*32a712daSGarrett D'Amore #endif /*!LIBMDOC_H*/
142