1 /* $Id: man_action.c,v 1.24 2009/11/02 06:22:45 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>
24 #include "libmandoc.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] = {
71 man_action_post(struct man *m)
74 if (MAN_ACTED & m->last->flags)
76 m->last->flags |= MAN_ACTED;
78 switch (m->last->type) {
87 if (NULL == man_actions[m->last->tok].post)
89 return((*man_actions[m->last->tok].post)(m));
94 post_fi(struct man *m)
97 if ( ! (MAN_LITERAL & m->flags))
98 if ( ! man_nwarn(m, m->last, WNLITERAL))
100 m->flags &= ~MAN_LITERAL;
106 post_nf(struct man *m)
109 if (MAN_LITERAL & m->flags)
110 if ( ! man_nwarn(m, m->last, WOLITERAL))
112 m->flags |= MAN_LITERAL;
118 post_TH(struct man *m)
129 free(m->meta.source);
131 m->meta.title = m->meta.vol = m->meta.source = NULL;
135 /* ->TITLE<- MSEC DATE SOURCE VOL */
139 m->meta.title = mandoc_strdup(n->string);
141 /* TITLE ->MSEC<- DATE SOURCE VOL */
146 lval = strtol(n->string, &ep, 10);
147 if (n->string[0] != '\0' && *ep == '\0')
148 m->meta.msec = (int)lval;
149 else if ( ! man_nwarn(m, n, WMSEC))
152 /* TITLE MSEC ->DATE<- SOURCE VOL */
156 m->meta.date = mandoc_a2time
157 (MTIME_ISO_8601, n->string);
159 if (0 == m->meta.date) {
160 if ( ! man_nwarn(m, n, WDATE))
162 m->meta.date = time(NULL);
165 m->meta.date = time(NULL);
167 /* TITLE MSEC DATE ->SOURCE<- VOL */
169 if (n && (n = n->next))
170 m->meta.source = mandoc_strdup(n->string);
172 /* TITLE MSEC DATE SOURCE ->VOL<- */
174 if (n && (n = n->next))
175 m->meta.vol = mandoc_strdup(n->string);
178 * The end document shouldn't have the prologue macros as part
179 * of the syntax tree (they encompass only meta-data).
182 if (m->last->parent->child == m->last) {
183 m->last->parent->child = NULL;
185 m->last = m->last->parent;
186 m->next = MAN_NEXT_CHILD;
188 assert(m->last->prev);
189 m->last->prev->next = NULL;
191 m->last = m->last->prev;
192 m->next = MAN_NEXT_SIBLING;
195 man_node_freelist(n);