]>
git.cameronkatri.com Git - mandoc.git/blob - man_action.c
1 /* $Id: man_action.c,v 1.22 2009/10/30 05:58:37 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.
17 #include <sys/utsname.h>
25 #include "libmandoc.h"
28 int (*post
)(struct man
*);
31 static int post_TH(struct man
*);
32 static int post_fi(struct man
*);
33 static int post_nf(struct man
*);
35 const struct actions man_actions
[MAN_MAX
] = {
70 static time_t man_atotime(const char *);
72 extern char *strptime(const char *, const char *, struct tm
*);
77 man_action_post(struct man
*m
)
80 if (MAN_ACTED
& m
->last
->flags
)
82 m
->last
->flags
|= MAN_ACTED
;
84 switch (m
->last
->type
) {
93 if (NULL
== man_actions
[m
->last
->tok
].post
)
95 return((*man_actions
[m
->last
->tok
].post
)(m
));
100 post_fi(struct man
*m
)
103 if ( ! (MAN_LITERAL
& m
->flags
))
104 if ( ! man_nwarn(m
, m
->last
, WNLITERAL
))
106 m
->flags
&= ~MAN_LITERAL
;
112 post_nf(struct man
*m
)
115 if (MAN_LITERAL
& m
->flags
)
116 if ( ! man_nwarn(m
, m
->last
, WOLITERAL
))
118 m
->flags
|= MAN_LITERAL
;
124 post_TH(struct man
*m
)
135 free(m
->meta
.source
);
137 m
->meta
.title
= m
->meta
.vol
= m
->meta
.source
= NULL
;
141 /* ->TITLE<- MSEC DATE SOURCE VOL */
145 m
->meta
.title
= mandoc_strdup(n
->string
);
147 /* TITLE ->MSEC<- DATE SOURCE VOL */
153 lval
= strtol(n
->string
, &ep
, 10);
154 if (n
->string
[0] != '\0' && *ep
== '\0')
155 m
->meta
.msec
= (int)lval
;
156 else if ( ! man_nwarn(m
, n
, WMSEC
))
159 /* TITLE MSEC ->DATE<- SOURCE VOL */
161 if (NULL
== (n
= n
->next
))
162 m
->meta
.date
= time(NULL
);
163 else if (0 == (m
->meta
.date
= man_atotime(n
->string
))) {
164 if ( ! man_nwarn(m
, n
, WDATE
))
166 m
->meta
.date
= time(NULL
);
169 /* TITLE MSEC DATE ->SOURCE<- VOL */
171 if (n
&& (n
= n
->next
))
172 m
->meta
.source
= mandoc_strdup(n
->string
);
174 /* TITLE MSEC DATE SOURCE ->VOL<- */
176 if (n
&& (n
= n
->next
))
177 m
->meta
.vol
= mandoc_strdup(n
->string
);
180 * The end document shouldn't have the prologue macros as part
181 * of the syntax tree (they encompass only meta-data).
184 if (m
->last
->parent
->child
== m
->last
) {
185 m
->last
->parent
->child
= NULL
;
187 m
->last
= m
->last
->parent
;
188 m
->next
= MAN_NEXT_CHILD
;
190 assert(m
->last
->prev
);
191 m
->last
->prev
->next
= NULL
;
193 m
->last
= m
->last
->prev
;
194 m
->next
= MAN_NEXT_SIBLING
;
197 man_node_freelist(n
);
203 man_atotime(const char *p
)
208 memset(&tm
, 0, sizeof(struct tm
));
210 if ((pp
= strptime(p
, "%b %d %Y", &tm
)) && 0 == *pp
)
212 if ((pp
= strptime(p
, "%d %b %Y", &tm
)) && 0 == *pp
)
214 if ((pp
= strptime(p
, "%b %d, %Y", &tm
)) && 0 == *pp
)
216 if ((pp
= strptime(p
, "%b %Y", &tm
)) && 0 == *pp
)