]> git.cameronkatri.com Git - mandoc.git/blob - man_action.c
Clarify -man -T[x]html handling of `br' within `B'.
[mandoc.git] / man_action.c
1 /* $Id: man_action.c,v 1.26 2010/03/22 14:03:03 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
4 *
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.
8 *
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.
16 */
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include <sys/utsname.h>
22
23 #include <assert.h>
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include "libman.h"
28 #include "libmandoc.h"
29
30 struct actions {
31 int (*post)(struct man *);
32 };
33
34 static int post_TH(struct man *);
35 static int post_fi(struct man *);
36 static int post_nf(struct man *);
37
38 const struct actions man_actions[MAN_MAX] = {
39 { NULL }, /* br */
40 { post_TH }, /* TH */
41 { NULL }, /* SH */
42 { NULL }, /* SS */
43 { NULL }, /* TP */
44 { NULL }, /* LP */
45 { NULL }, /* PP */
46 { NULL }, /* P */
47 { NULL }, /* IP */
48 { NULL }, /* HP */
49 { NULL }, /* SM */
50 { NULL }, /* SB */
51 { NULL }, /* BI */
52 { NULL }, /* IB */
53 { NULL }, /* BR */
54 { NULL }, /* RB */
55 { NULL }, /* R */
56 { NULL }, /* B */
57 { NULL }, /* I */
58 { NULL }, /* IR */
59 { NULL }, /* RI */
60 { NULL }, /* na */
61 { NULL }, /* i */
62 { NULL }, /* sp */
63 { post_nf }, /* nf */
64 { post_fi }, /* fi */
65 { NULL }, /* r */
66 { NULL }, /* RE */
67 { NULL }, /* RS */
68 { NULL }, /* DT */
69 { NULL }, /* UC */
70 { NULL }, /* PD */
71 };
72
73
74 int
75 man_action_post(struct man *m)
76 {
77
78 if (MAN_ACTED & m->last->flags)
79 return(1);
80 m->last->flags |= MAN_ACTED;
81
82 switch (m->last->type) {
83 case (MAN_TEXT):
84 /* FALLTHROUGH */
85 case (MAN_ROOT):
86 return(1);
87 default:
88 break;
89 }
90
91 if (NULL == man_actions[m->last->tok].post)
92 return(1);
93 return((*man_actions[m->last->tok].post)(m));
94 }
95
96
97 static int
98 post_fi(struct man *m)
99 {
100
101 if ( ! (MAN_LITERAL & m->flags))
102 if ( ! man_nwarn(m, m->last, WNLITERAL))
103 return(0);
104 m->flags &= ~MAN_LITERAL;
105 return(1);
106 }
107
108
109 static int
110 post_nf(struct man *m)
111 {
112
113 if (MAN_LITERAL & m->flags)
114 if ( ! man_nwarn(m, m->last, WOLITERAL))
115 return(0);
116 m->flags |= MAN_LITERAL;
117 return(1);
118 }
119
120
121 static int
122 post_TH(struct man *m)
123 {
124 struct man_node *n;
125 char *ep;
126 long lval;
127
128 if (m->meta.title)
129 free(m->meta.title);
130 if (m->meta.vol)
131 free(m->meta.vol);
132 if (m->meta.source)
133 free(m->meta.source);
134
135 m->meta.title = m->meta.vol = m->meta.source = NULL;
136 m->meta.msec = 0;
137 m->meta.date = 0;
138
139 /* ->TITLE<- MSEC DATE SOURCE VOL */
140
141 n = m->last->child;
142 assert(n);
143 m->meta.title = mandoc_strdup(n->string);
144
145 /* TITLE ->MSEC<- DATE SOURCE VOL */
146
147 n = n->next;
148 assert(n);
149
150 lval = strtol(n->string, &ep, 10);
151 if (n->string[0] != '\0' && *ep == '\0')
152 m->meta.msec = (int)lval;
153 else if ( ! man_nwarn(m, n, WMSEC))
154 return(0);
155
156 /* TITLE MSEC ->DATE<- SOURCE VOL */
157
158 n = n->next;
159 if (n) {
160 m->meta.date = mandoc_a2time
161 (MTIME_ISO_8601, n->string);
162
163 if (0 == m->meta.date) {
164 if ( ! man_nwarn(m, n, WDATE))
165 return(0);
166 m->meta.date = time(NULL);
167 }
168 } else
169 m->meta.date = time(NULL);
170
171 /* TITLE MSEC DATE ->SOURCE<- VOL */
172
173 if (n && (n = n->next))
174 m->meta.source = mandoc_strdup(n->string);
175
176 /* TITLE MSEC DATE SOURCE ->VOL<- */
177
178 if (n && (n = n->next))
179 m->meta.vol = mandoc_strdup(n->string);
180
181 n = m->last;
182 man_node_unlink(m, n);
183 man_node_freelist(n);
184 return(1);
185 }