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