]>
git.cameronkatri.com Git - mandoc.git/blob - man_action.c
1 /* $Id: man_action.c,v 1.30 2010/03/27 10:04:56 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
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.
26 #include "libmandoc.h"
29 int (*post
)(struct man
*);
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
*);
37 const struct actions man_actions
[MAN_MAX
] = {
74 { post_de
}, /* dei */
76 { post_de
}, /* ami */
83 man_action_post(struct man
*m
)
86 if (MAN_ACTED
& m
->last
->flags
)
88 m
->last
->flags
|= MAN_ACTED
;
90 switch (m
->last
->type
) {
99 if (NULL
== man_actions
[m
->last
->tok
].post
)
101 return((*man_actions
[m
->last
->tok
].post
)(m
));
106 post_fi(struct man
*m
)
109 if ( ! (MAN_LITERAL
& m
->flags
))
110 if ( ! man_nwarn(m
, m
->last
, WNLITERAL
))
112 m
->flags
&= ~MAN_LITERAL
;
118 post_de(struct man
*m
)
122 * XXX: for the time being, we indiscriminately remove roff
123 * instructions from the parse stream.
125 if (MAN_BLOCK
== m
->last
->type
)
126 man_node_delete(m
, m
->last
);
132 post_nf(struct man
*m
)
135 if (MAN_LITERAL
& m
->flags
)
136 if ( ! man_nwarn(m
, m
->last
, WOLITERAL
))
138 m
->flags
|= MAN_LITERAL
;
144 post_TH(struct man
*m
)
155 free(m
->meta
.source
);
157 m
->meta
.title
= m
->meta
.vol
= m
->meta
.source
= NULL
;
161 /* ->TITLE<- MSEC DATE SOURCE VOL */
165 m
->meta
.title
= mandoc_strdup(n
->string
);
167 /* TITLE ->MSEC<- DATE SOURCE VOL */
172 lval
= strtol(n
->string
, &ep
, 10);
173 if (n
->string
[0] != '\0' && *ep
== '\0')
174 m
->meta
.msec
= (int)lval
;
175 else if ( ! man_nwarn(m
, n
, WMSEC
))
178 /* TITLE MSEC ->DATE<- SOURCE VOL */
182 m
->meta
.date
= mandoc_a2time
183 (MTIME_ISO_8601
, n
->string
);
185 if (0 == m
->meta
.date
) {
186 if ( ! man_nwarn(m
, n
, WDATE
))
188 m
->meta
.date
= time(NULL
);
191 m
->meta
.date
= time(NULL
);
193 /* TITLE MSEC DATE ->SOURCE<- VOL */
195 if (n
&& (n
= n
->next
))
196 m
->meta
.source
= mandoc_strdup(n
->string
);
198 /* TITLE MSEC DATE SOURCE ->VOL<- */
200 if (n
&& (n
= n
->next
))
201 m
->meta
.vol
= mandoc_strdup(n
->string
);
204 * Remove the `TH' node after we've processed it for our
207 man_node_delete(m
, m
->last
);