]>
git.cameronkatri.com Git - mandoc.git/blob - man_action.c
e303468bde387b295542895eedf23d42e7d8b3ca
1 /* $Id: man_action.c,v 1.5 2009/03/26 14:38:11 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/utsname.h>
31 extern char *strptime(const char *, const char *, struct tm
*);
35 int (*post
)(struct man
*);
39 static int post_TH(struct man
*);
40 static time_t man_atotime(const char *);
42 const struct actions man_actions
[MAN_MAX
] = {
68 man_action_post(struct man
*m
)
71 if (MAN_ACTED
& m
->last
->flags
)
73 m
->last
->flags
|= MAN_ACTED
;
75 switch (m
->last
->type
) {
81 if (NULL
== man_actions
[m
->last
->tok
].post
)
83 return((*man_actions
[m
->last
->tok
].post
)(m
));
90 post_TH(struct man
*m
)
101 free(m
->meta
.source
);
103 m
->meta
.title
= m
->meta
.vol
= m
->meta
.source
= NULL
;
107 /* ->TITLE<- MSEC DATE SOURCE VOL */
112 if (NULL
== (m
->meta
.title
= strdup(n
->string
)))
113 return(man_verr(m
, n
->line
, n
->pos
, "malloc"));
115 /* TITLE ->MSEC<- DATE SOURCE VOL */
121 lval
= strtol(n
->string
, &ep
, 10);
122 if (n
->string
[0] != '\0' && *ep
== '\0')
123 m
->meta
.msec
= (int)lval
;
124 else if ( ! man_vwarn(m
, n
->line
, n
->pos
, "invalid section"))
127 /* TITLE MSEC ->DATE<- SOURCE VOL */
129 if (NULL
== (n
= n
->next
))
130 m
->meta
.date
= time(NULL
);
131 else if (0 == (m
->meta
.date
= man_atotime(n
->string
))) {
132 if ( ! man_vwarn(m
, n
->line
, n
->pos
, "invalid date"))
134 m
->meta
.date
= time(NULL
);
137 /* TITLE MSEC DATE ->SOURCE<- VOL */
139 if (n
&& (n
= n
->next
))
140 if (NULL
== (m
->meta
.source
= strdup(n
->string
)))
141 return(man_verr(m
, n
->line
, n
->pos
, "malloc"));
143 /* TITLE MSEC DATE SOURCE ->VOL<- */
145 if (n
&& (n
= n
->next
))
146 if (NULL
== (m
->meta
.vol
= strdup(n
->string
)))
147 return(man_verr(m
, n
->line
, n
->pos
, "malloc"));
150 * The end document shouldn't have the prologue macros as part
151 * of the syntax tree (they encompass only meta-data).
154 if (m
->last
->parent
->child
== m
->last
) {
155 assert(MAN_ROOT
== m
->last
->parent
->type
);
156 m
->last
->parent
->child
= NULL
;
158 m
->last
= m
->last
->parent
;
159 m
->next
= MAN_NEXT_CHILD
;
160 assert(m
->last
== m
->first
);
162 assert(m
->last
->prev
);
163 m
->last
->prev
->next
= NULL
;
165 m
->last
= m
->last
->prev
;
166 m
->next
= MAN_NEXT_SIBLING
;
169 man_node_freelist(n
);
175 man_atotime(const char *p
)
180 (void)memset(&tm
, 0, sizeof(struct tm
));
182 if ((pp
= strptime(p
, "%b %d %Y", &tm
)) && 0 == *pp
)
184 if ((pp
= strptime(p
, "%d %b %Y", &tm
)) && 0 == *pp
)
186 if ((pp
= strptime(p
, "%b %d, %Y", &tm
)) && 0 == *pp
)
188 if ((pp
= strptime(p
, "%b %Y", &tm
)) && 0 == *pp
)