]>
git.cameronkatri.com Git - mandoc.git/blob - man_action.c
1 /* $Id: man_action.c,v 1.20 2009/10/24 05:45:04 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>
27 int (*post
)(struct man
*);
30 static int post_TH(struct man
*);
31 static int post_fi(struct man
*);
32 static int post_nf(struct man
*);
34 const struct actions man_actions
[MAN_MAX
] = {
69 static time_t man_atotime(const char *);
71 extern char *strptime(const char *, const char *, struct tm
*);
76 man_action_post(struct man
*m
)
79 if (MAN_ACTED
& m
->last
->flags
)
81 m
->last
->flags
|= MAN_ACTED
;
83 switch (m
->last
->type
) {
92 if (NULL
== man_actions
[m
->last
->tok
].post
)
94 return((*man_actions
[m
->last
->tok
].post
)(m
));
99 post_fi(struct man
*m
)
102 if ( ! (MAN_LITERAL
& m
->flags
))
103 if ( ! man_nwarn(m
, m
->last
, WNLITERAL
))
105 m
->flags
&= ~MAN_LITERAL
;
111 post_nf(struct man
*m
)
114 if (MAN_LITERAL
& m
->flags
)
115 if ( ! man_nwarn(m
, m
->last
, WOLITERAL
))
117 m
->flags
|= MAN_LITERAL
;
123 post_TH(struct man
*m
)
134 free(m
->meta
.source
);
136 m
->meta
.title
= m
->meta
.vol
= m
->meta
.source
= NULL
;
140 /* ->TITLE<- MSEC DATE SOURCE VOL */
145 if (NULL
== (m
->meta
.title
= strdup(n
->string
)))
146 return(man_nerr(m
, n
, WNMEM
));
148 /* TITLE ->MSEC<- DATE SOURCE VOL */
154 lval
= strtol(n
->string
, &ep
, 10);
155 if (n
->string
[0] != '\0' && *ep
== '\0')
156 m
->meta
.msec
= (int)lval
;
157 else if ( ! man_nwarn(m
, n
, WMSEC
))
160 /* TITLE MSEC ->DATE<- SOURCE VOL */
162 if (NULL
== (n
= n
->next
))
163 m
->meta
.date
= time(NULL
);
164 else if (0 == (m
->meta
.date
= man_atotime(n
->string
))) {
165 if ( ! man_nwarn(m
, n
, WDATE
))
167 m
->meta
.date
= time(NULL
);
170 /* TITLE MSEC DATE ->SOURCE<- VOL */
172 if (n
&& (n
= n
->next
))
173 if (NULL
== (m
->meta
.source
= strdup(n
->string
)))
174 return(man_nerr(m
, n
, WNMEM
));
176 /* TITLE MSEC DATE SOURCE ->VOL<- */
178 if (n
&& (n
= n
->next
))
179 if (NULL
== (m
->meta
.vol
= strdup(n
->string
)))
180 return(man_nerr(m
, n
, WNMEM
));
183 * The end document shouldn't have the prologue macros as part
184 * of the syntax tree (they encompass only meta-data).
187 if (m
->last
->parent
->child
== m
->last
) {
188 m
->last
->parent
->child
= NULL
;
190 m
->last
= m
->last
->parent
;
191 m
->next
= MAN_NEXT_CHILD
;
193 assert(m
->last
->prev
);
194 m
->last
->prev
->next
= NULL
;
196 m
->last
= m
->last
->prev
;
197 m
->next
= MAN_NEXT_SIBLING
;
200 man_node_freelist(n
);
206 man_atotime(const char *p
)
211 bzero(&tm
, sizeof(struct tm
));
213 if ((pp
= strptime(p
, "%b %d %Y", &tm
)) && 0 == *pp
)
215 if ((pp
= strptime(p
, "%d %b %Y", &tm
)) && 0 == *pp
)
217 if ((pp
= strptime(p
, "%b %d, %Y", &tm
)) && 0 == *pp
)
219 if ((pp
= strptime(p
, "%b %Y", &tm
)) && 0 == *pp
)