]> git.cameronkatri.com Git - mandoc.git/blob - man_action.c
The `am', `ami', `de', and holy `dei' are all being properly ignored.
[mandoc.git] / man_action.c
1 /* $Id: man_action.c,v 1.33 2010/05/15 20:51:40 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008, 2009 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 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include <assert.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include "libman.h"
26 #include "libmandoc.h"
27
28 struct actions {
29 int (*post)(struct man *);
30 };
31
32 static int post_TH(struct man *);
33 static int post_de(struct man *);
34 static int post_fi(struct man *);
35 static int post_nf(struct man *);
36
37 const struct actions man_actions[MAN_MAX] = {
38 { NULL }, /* br */
39 { post_TH }, /* TH */
40 { NULL }, /* SH */
41 { NULL }, /* SS */
42 { NULL }, /* TP */
43 { NULL }, /* LP */
44 { NULL }, /* PP */
45 { NULL }, /* P */
46 { NULL }, /* IP */
47 { NULL }, /* HP */
48 { NULL }, /* SM */
49 { NULL }, /* SB */
50 { NULL }, /* BI */
51 { NULL }, /* IB */
52 { NULL }, /* BR */
53 { NULL }, /* RB */
54 { NULL }, /* R */
55 { NULL }, /* B */
56 { NULL }, /* I */
57 { NULL }, /* IR */
58 { NULL }, /* RI */
59 { NULL }, /* na */
60 { NULL }, /* i */
61 { NULL }, /* sp */
62 { post_nf }, /* nf */
63 { post_fi }, /* fi */
64 { NULL }, /* r */
65 { NULL }, /* RE */
66 { NULL }, /* RS */
67 { NULL }, /* DT */
68 { NULL }, /* UC */
69 { NULL }, /* PD */
70 { NULL }, /* Sp */
71 { post_nf }, /* Vb */
72 { post_fi }, /* Ve */
73 { post_de }, /* de */
74 { post_de }, /* dei */
75 { post_de }, /* am */
76 { post_de }, /* ami */
77 { NULL }, /* . */
78 };
79
80
81 int
82 man_action_post(struct man *m)
83 {
84
85 if (MAN_ACTED & m->last->flags)
86 return(1);
87 m->last->flags |= MAN_ACTED;
88
89 switch (m->last->type) {
90 case (MAN_TEXT):
91 /* FALLTHROUGH */
92 case (MAN_ROOT):
93 return(1);
94 default:
95 break;
96 }
97
98 if (NULL == man_actions[m->last->tok].post)
99 return(1);
100 return((*man_actions[m->last->tok].post)(m));
101 }
102
103
104 static int
105 post_fi(struct man *m)
106 {
107
108 if ( ! (MAN_LITERAL & m->flags))
109 if ( ! man_nwarn(m, m->last, WNLITERAL))
110 return(0);
111 m->flags &= ~MAN_LITERAL;
112 return(1);
113 }
114
115
116 static int
117 post_de(struct man *m)
118 {
119
120 /*
121 * XXX: for the time being, we indiscriminately remove roff
122 * instructions from the parse stream.
123 */
124 if (MAN_BLOCK == m->last->type)
125 man_node_delete(m, m->last);
126 return(1);
127 }
128
129
130 static int
131 post_nf(struct man *m)
132 {
133
134 if (MAN_LITERAL & m->flags)
135 if ( ! man_nwarn(m, m->last, WOLITERAL))
136 return(0);
137 m->flags |= MAN_LITERAL;
138 return(1);
139 }
140
141
142 static int
143 post_TH(struct man *m)
144 {
145 struct man_node *n;
146
147 if (m->meta.title)
148 free(m->meta.title);
149 if (m->meta.vol)
150 free(m->meta.vol);
151 if (m->meta.source)
152 free(m->meta.source);
153 if (m->meta.msec)
154 free(m->meta.msec);
155
156 m->meta.title = m->meta.vol =
157 m->meta.msec = m->meta.source = NULL;
158 m->meta.date = 0;
159
160 /* ->TITLE<- MSEC DATE SOURCE VOL */
161
162 n = m->last->child;
163 assert(n);
164 m->meta.title = mandoc_strdup(n->string);
165
166 /* TITLE ->MSEC<- DATE SOURCE VOL */
167
168 n = n->next;
169 assert(n);
170 m->meta.msec = mandoc_strdup(n->string);
171
172 /* TITLE MSEC ->DATE<- SOURCE VOL */
173
174 n = n->next;
175 if (n) {
176 m->meta.date = mandoc_a2time
177 (MTIME_ISO_8601, n->string);
178 if (0 == m->meta.date) {
179 if ( ! man_nwarn(m, n, WDATE))
180 return(0);
181 m->meta.date = time(NULL);
182 }
183 } else
184 m->meta.date = time(NULL);
185
186 /* TITLE MSEC DATE ->SOURCE<- VOL */
187
188 if (n && (n = n->next))
189 m->meta.source = mandoc_strdup(n->string);
190
191 /* TITLE MSEC DATE SOURCE ->VOL<- */
192
193 if (n && (n = n->next))
194 m->meta.vol = mandoc_strdup(n->string);
195
196 /*
197 * Remove the `TH' node after we've processed it for our
198 * meta-data.
199 */
200 man_node_delete(m, m->last);
201 return(1);
202 }