]>
git.cameronkatri.com Git - mandoc.git/blob - man_action.c
1 /* $Id: man_action.c,v 1.39 2010/05/26 14:03:54 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
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.
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.
27 #include "libmandoc.h"
30 int (*post
)(struct man
*);
33 static int post_TH(struct man
*);
34 static int post_fi(struct man
*);
35 static int post_nf(struct man
*);
36 static int post_AT(struct man
*);
37 static int post_UC(struct man
*);
39 const struct actions man_actions
[MAN_MAX
] = {
80 man_action_post(struct man
*m
)
83 if (MAN_ACTED
& m
->last
->flags
)
85 m
->last
->flags
|= MAN_ACTED
;
87 switch (m
->last
->type
) {
96 if (NULL
== man_actions
[m
->last
->tok
].post
)
98 return((*man_actions
[m
->last
->tok
].post
)(m
));
103 post_fi(struct man
*m
)
106 if ( ! (MAN_LITERAL
& m
->flags
))
107 if ( ! man_nmsg(m
, m
->last
, MANDOCERR_NOSCOPE
))
109 m
->flags
&= ~MAN_LITERAL
;
115 post_nf(struct man
*m
)
118 if (MAN_LITERAL
& m
->flags
)
119 if ( ! man_nmsg(m
, m
->last
, MANDOCERR_SCOPEREP
))
121 m
->flags
|= MAN_LITERAL
;
127 post_TH(struct man
*m
)
136 free(m
->meta
.source
);
140 free(m
->meta
.rawdate
);
142 m
->meta
.title
= m
->meta
.vol
= m
->meta
.rawdate
=
143 m
->meta
.msec
= m
->meta
.source
= NULL
;
146 /* ->TITLE<- MSEC DATE SOURCE VOL */
150 m
->meta
.title
= mandoc_strdup(n
->string
);
152 /* TITLE ->MSEC<- DATE SOURCE VOL */
156 m
->meta
.msec
= mandoc_strdup(n
->string
);
158 /* TITLE MSEC ->DATE<- SOURCE VOL */
161 * Try to parse the date. If this works, stash the epoch (this
162 * is optimal because we can reformat it in the canonical form).
163 * If it doesn't parse, isn't specified at all, or is an empty
164 * string, then use the current date.
168 if (n
&& n
->string
&& *n
->string
) {
169 m
->meta
.date
= mandoc_a2time
170 (MTIME_ISO_8601
, n
->string
);
171 if (0 == m
->meta
.date
) {
172 if ( ! man_nmsg(m
, n
, MANDOCERR_BADDATE
))
174 m
->meta
.rawdate
= mandoc_strdup(n
->string
);
177 m
->meta
.date
= time(NULL
);
179 /* TITLE MSEC DATE ->SOURCE<- VOL */
181 if (n
&& (n
= n
->next
))
182 m
->meta
.source
= mandoc_strdup(n
->string
);
184 /* TITLE MSEC DATE SOURCE ->VOL<- */
186 if (n
&& (n
= n
->next
))
187 m
->meta
.vol
= mandoc_strdup(n
->string
);
190 * Remove the `TH' node after we've processed it for our
193 man_node_delete(m
, m
->last
);
199 post_AT(struct man
*m
)
201 static const char * const unix_versions
[] = {
205 "System V Release 2",
209 struct man_node
*n
, *nn
;
213 if (NULL
== n
|| MAN_TEXT
!= n
->type
)
214 p
= unix_versions
[0];
217 if (0 == strcmp(s
, "3"))
218 p
= unix_versions
[0];
219 else if (0 == strcmp(s
, "4"))
220 p
= unix_versions
[1];
221 else if (0 == strcmp(s
, "5")) {
223 if (nn
&& MAN_TEXT
== nn
->type
&& nn
->string
[0])
224 p
= unix_versions
[3];
226 p
= unix_versions
[2];
228 p
= unix_versions
[0];
232 free(m
->meta
.source
);
234 m
->meta
.source
= mandoc_strdup(p
);
241 post_UC(struct man
*m
)
243 static const char * const bsd_versions
[] = {
244 "3rd Berkeley Distribution",
245 "4th Berkeley Distribution",
246 "4.2 Berkeley Distribution",
247 "4.3 Berkeley Distribution",
248 "4.4 Berkeley Distribution",
256 if (NULL
== n
|| MAN_TEXT
!= n
->type
)
260 if (0 == strcmp(s
, "3"))
262 else if (0 == strcmp(s
, "4"))
264 else if (0 == strcmp(s
, "5"))
266 else if (0 == strcmp(s
, "6"))
268 else if (0 == strcmp(s
, "7"))
275 free(m
->meta
.source
);
277 m
->meta
.source
= mandoc_strdup(p
);