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