]>
git.cameronkatri.com Git - mandoc.git/blob - man_action.c
1 /* $Id: man_action.c,v 1.41 2010/07/31 23:52:58 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2010 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
] = {
81 man_action_post(struct man
*m
)
84 if (MAN_ACTED
& m
->last
->flags
)
86 m
->last
->flags
|= MAN_ACTED
;
88 switch (m
->last
->type
) {
97 if (NULL
== man_actions
[m
->last
->tok
].post
)
99 return((*man_actions
[m
->last
->tok
].post
)(m
));
104 post_fi(struct man
*m
)
107 if ( ! (MAN_LITERAL
& m
->flags
))
108 if ( ! man_nmsg(m
, m
->last
, MANDOCERR_NOSCOPE
))
110 m
->flags
&= ~MAN_LITERAL
;
116 post_nf(struct man
*m
)
119 if (MAN_LITERAL
& m
->flags
)
120 if ( ! man_nmsg(m
, m
->last
, MANDOCERR_SCOPEREP
))
122 m
->flags
|= MAN_LITERAL
;
128 post_TH(struct man
*m
)
137 free(m
->meta
.source
);
141 free(m
->meta
.rawdate
);
143 m
->meta
.title
= m
->meta
.vol
= m
->meta
.rawdate
=
144 m
->meta
.msec
= m
->meta
.source
= NULL
;
147 /* ->TITLE<- MSEC DATE SOURCE VOL */
151 m
->meta
.title
= mandoc_strdup(n
->string
);
153 /* TITLE ->MSEC<- DATE SOURCE VOL */
157 m
->meta
.msec
= mandoc_strdup(n
->string
);
159 /* TITLE MSEC ->DATE<- SOURCE VOL */
162 * Try to parse the date. If this works, stash the epoch (this
163 * is optimal because we can reformat it in the canonical form).
164 * If it doesn't parse, isn't specified at all, or is an empty
165 * string, then use the current date.
169 if (n
&& n
->string
&& *n
->string
) {
170 m
->meta
.date
= mandoc_a2time
171 (MTIME_ISO_8601
, n
->string
);
172 if (0 == m
->meta
.date
) {
173 if ( ! man_nmsg(m
, n
, MANDOCERR_BADDATE
))
175 m
->meta
.rawdate
= mandoc_strdup(n
->string
);
178 m
->meta
.date
= time(NULL
);
180 /* TITLE MSEC DATE ->SOURCE<- VOL */
182 if (n
&& (n
= n
->next
))
183 m
->meta
.source
= mandoc_strdup(n
->string
);
185 /* TITLE MSEC DATE SOURCE ->VOL<- */
187 if (n
&& (n
= n
->next
))
188 m
->meta
.vol
= mandoc_strdup(n
->string
);
191 * Remove the `TH' node after we've processed it for our
194 man_node_delete(m
, m
->last
);
200 post_AT(struct man
*m
)
202 static const char * const unix_versions
[] = {
206 "System V Release 2",
210 struct man_node
*n
, *nn
;
214 if (NULL
== n
|| MAN_TEXT
!= n
->type
)
215 p
= unix_versions
[0];
218 if (0 == strcmp(s
, "3"))
219 p
= unix_versions
[0];
220 else if (0 == strcmp(s
, "4"))
221 p
= unix_versions
[1];
222 else if (0 == strcmp(s
, "5")) {
224 if (nn
&& MAN_TEXT
== nn
->type
&& nn
->string
[0])
225 p
= unix_versions
[3];
227 p
= unix_versions
[2];
229 p
= unix_versions
[0];
233 free(m
->meta
.source
);
235 m
->meta
.source
= mandoc_strdup(p
);
242 post_UC(struct man
*m
)
244 static const char * const bsd_versions
[] = {
245 "3rd Berkeley Distribution",
246 "4th Berkeley Distribution",
247 "4.2 Berkeley Distribution",
248 "4.3 Berkeley Distribution",
249 "4.4 Berkeley Distribution",
257 if (NULL
== n
|| MAN_TEXT
!= n
->type
)
261 if (0 == strcmp(s
, "3"))
263 else if (0 == strcmp(s
, "4"))
265 else if (0 == strcmp(s
, "5"))
267 else if (0 == strcmp(s
, "6"))
269 else if (0 == strcmp(s
, "7"))
276 free(m
->meta
.source
);
278 m
->meta
.source
= mandoc_strdup(p
);