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