Annotation of mandoc/libmdoc.h, Revision 1.7
1.7 ! kristaps 1: /* $Id: libmdoc.h,v 1.6 2009/04/12 19:45:26 kristaps Exp $ */
1.1 kristaps 2: /*
1.7 ! kristaps 3: * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
1.1 kristaps 4: *
5: * Permission to use, copy, modify, and distribute this software for any
1.6 kristaps 6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
1.1 kristaps 8: *
1.6 kristaps 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.
1.1 kristaps 16: */
17: #ifndef LIBMDOC_H
18: #define LIBMDOC_H
19:
20: #include "mdoc.h"
21:
22: enum mdoc_next {
23: MDOC_NEXT_SIBLING = 0,
24: MDOC_NEXT_CHILD
25: };
26:
27: struct mdoc {
28: void *data;
29: struct mdoc_cb cb;
30: void *htab;
31: int flags;
32: #define MDOC_HALT (1 << 0)
33: #define MDOC_LITERAL (1 << 1)
34: int pflags;
35: enum mdoc_next next;
36: struct mdoc_node *last;
37: struct mdoc_node *first;
38: struct mdoc_meta meta;
39: enum mdoc_sec lastnamed;
40: enum mdoc_sec lastsec;
41: };
42:
43:
44: #define MACRO_PROT_ARGS struct mdoc *mdoc, int tok, int line, \
45: int ppos, int *pos, char *buf
46:
47: struct mdoc_macro {
48: int (*fp)(MACRO_PROT_ARGS);
49: int flags;
50: #define MDOC_CALLABLE (1 << 0)
51: #define MDOC_PARSED (1 << 1)
52: #define MDOC_EXPLICIT (1 << 2)
53: #define MDOC_PROLOGUE (1 << 3)
54: #define MDOC_IGNDELIM (1 << 4)
55: /* Reserved words in arguments treated as text. */
56: };
57:
58: #define mdoc_nwarn(mdoc, node, type, fmt, ...) \
59: mdoc_vwarn((mdoc), (node)->line, \
60: (node)->pos, (type), (fmt), ##__VA_ARGS__)
61:
62: #define mdoc_nerr(mdoc, node, fmt, ...) \
63: mdoc_verr((mdoc), (node)->line, \
64: (node)->pos, (fmt), ##__VA_ARGS__)
65:
66: #define mdoc_warn(mdoc, type, fmt, ...) \
67: mdoc_vwarn((mdoc), (mdoc)->last->line, \
68: (mdoc)->last->pos, (type), (fmt), ##__VA_ARGS__)
69:
70: #define mdoc_err(mdoc, fmt, ...) \
71: mdoc_verr((mdoc), (mdoc)->last->line, \
72: (mdoc)->last->pos, (fmt), ##__VA_ARGS__)
73:
74: #define mdoc_msg(mdoc, fmt, ...) \
75: mdoc_vmsg((mdoc), (mdoc)->last->line, \
76: (mdoc)->last->pos, (fmt), ##__VA_ARGS__)
77:
78: #define mdoc_pmsg(mdoc, line, pos, fmt, ...) \
79: mdoc_vmsg((mdoc), (line), \
80: (pos), (fmt), ##__VA_ARGS__)
81:
82: #define mdoc_pwarn(mdoc, line, pos, type, fmt, ...) \
83: mdoc_vwarn((mdoc), (line), \
84: (pos), (type), (fmt), ##__VA_ARGS__)
85:
86: #define mdoc_perr(mdoc, line, pos, fmt, ...) \
87: mdoc_verr((mdoc), (line), \
88: (pos), (fmt), ##__VA_ARGS__)
89:
90: extern const struct mdoc_macro *const mdoc_macros;
91:
92: __BEGIN_DECLS
93:
94: int mdoc_vwarn(struct mdoc *, int, int,
95: enum mdoc_warn, const char *, ...);
96: void mdoc_vmsg(struct mdoc *, int, int,
97: const char *, ...);
98: int mdoc_verr(struct mdoc *, int, int,
99: const char *, ...);
100: int mdoc_macro(MACRO_PROT_ARGS);
101: int mdoc_word_alloc(struct mdoc *,
102: int, int, const char *);
103: int mdoc_elem_alloc(struct mdoc *, int, int,
104: int, struct mdoc_arg *);
105: int mdoc_block_alloc(struct mdoc *, int, int,
106: int, struct mdoc_arg *);
107: int mdoc_head_alloc(struct mdoc *, int, int, int);
108: int mdoc_tail_alloc(struct mdoc *, int, int, int);
109: int mdoc_body_alloc(struct mdoc *, int, int, int);
110: void mdoc_node_free(struct mdoc_node *);
111: void mdoc_node_freelist(struct mdoc_node *);
1.4 kristaps 112: void *mdoc_hash_alloc(void);
113: int mdoc_hash_find(const void *, const char *);
114: void mdoc_hash_free(void *);
1.1 kristaps 115: int mdoc_iscdelim(char);
116: int mdoc_isdelim(const char *);
117: size_t mdoc_isescape(const char *);
118: enum mdoc_sec mdoc_atosec(const char *);
119: time_t mdoc_atotime(const char *);
120:
121: size_t mdoc_macro2len(int);
122: const char *mdoc_a2arch(const char *);
123: const char *mdoc_a2vol(const char *);
124: const char *mdoc_a2msec(const char *);
125: int mdoc_valid_pre(struct mdoc *,
126: const struct mdoc_node *);
127: int mdoc_valid_post(struct mdoc *);
128: int mdoc_action_pre(struct mdoc *,
129: const struct mdoc_node *);
130: int mdoc_action_post(struct mdoc *);
131: int mdoc_argv(struct mdoc *, int, int,
132: struct mdoc_arg **, int *, char *);
133: #define ARGV_ERROR (-1)
134: #define ARGV_EOLN (0)
135: #define ARGV_ARG (1)
136: #define ARGV_WORD (2)
137: void mdoc_argv_free(struct mdoc_arg *);
138: int mdoc_args(struct mdoc *, int,
139: int *, char *, int, char **);
140: #define ARGS_ERROR (-1)
141: #define ARGS_EOLN (0)
142: #define ARGS_WORD (1)
143: #define ARGS_PUNCT (2)
144: #define ARGS_QWORD (3)
145: #define ARGS_PHRASE (4)
146:
1.2 kristaps 147: int mdoc_macroend(struct mdoc *);
1.1 kristaps 148:
149: __END_DECLS
150:
151: #endif /*!LIBMDOC_H*/
CVSweb