1 /* $OpenBSD$ */
2 /*
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 #include "config.h"
19
20 #include <sys/types.h>
21
22 #include <assert.h>
23 #include <ctype.h>
24 #include <errno.h>
103
104 n = man->last;
105 man->last = man->last->child;
106 while (man->last != NULL) {
107 man_node_validate(man);
108 if (man->last == n)
109 man->last = man->last->child;
110 else
111 man->last = man->last->next;
112 }
113
114 man->last = n;
115 man->next = ROFF_NEXT_SIBLING;
116 switch (n->type) {
117 case ROFFT_TEXT:
118 check_text(man, n);
119 break;
120 case ROFFT_ROOT:
121 check_root(man, n);
122 break;
123 case ROFFT_EQN:
124 case ROFFT_TBL:
125 break;
126 default:
127 if (n->tok < ROFF_MAX) {
128 switch (n->tok) {
129 case ROFF_br:
130 case ROFF_sp:
131 post_vs(man, n);
132 break;
133 default:
134 roff_validate(man);
135 break;
136 }
137 break;
138 }
139 assert(n->tok >= MAN_TH && n->tok < MAN_MAX);
140 cp = man_valids + n->tok;
141 if (*cp)
142 (*cp)(man, n);
143 if (man->last == n)
144 man_state(man, n);
145 break;
146 }
147 }
148
149 static void
150 check_root(CHKARGS)
151 {
152
153 assert((man->flags & (MAN_BLINE | MAN_ELINE)) == 0);
154
155 if (NULL == man->first->child)
156 mandoc_msg(MANDOCERR_DOC_EMPTY, man->parse,
157 n->line, n->pos, NULL);
158 else
159 man->meta.hasbody = 1;
160
161 if (NULL == man->meta.title) {
162 mandoc_msg(MANDOCERR_TH_NOTITLE, man->parse,
163 n->line, n->pos, NULL);
164
165 /*
166 * If a title hasn't been set, do so now (by
167 * implication, date and section also aren't set).
168 */
169
170 man->meta.title = mandoc_strdup("");
171 man->meta.msec = mandoc_strdup("");
172 man->meta.date = man->quick ? mandoc_strdup("") :
173 mandoc_normdate(man, NULL, n->line, n->pos);
174 }
175
|
1 /* $OpenBSD$ */
2 /*
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 #include "config.h"
19
20 #include <sys/types.h>
21
22 #include <assert.h>
23 #include <ctype.h>
24 #include <errno.h>
103
104 n = man->last;
105 man->last = man->last->child;
106 while (man->last != NULL) {
107 man_node_validate(man);
108 if (man->last == n)
109 man->last = man->last->child;
110 else
111 man->last = man->last->next;
112 }
113
114 man->last = n;
115 man->next = ROFF_NEXT_SIBLING;
116 switch (n->type) {
117 case ROFFT_TEXT:
118 check_text(man, n);
119 break;
120 case ROFFT_ROOT:
121 check_root(man, n);
122 break;
123 case ROFFT_COMMENT:
124 case ROFFT_EQN:
125 case ROFFT_TBL:
126 break;
127 default:
128 if (n->tok < ROFF_MAX) {
129 switch (n->tok) {
130 case ROFF_br:
131 case ROFF_sp:
132 post_vs(man, n);
133 break;
134 default:
135 roff_validate(man);
136 break;
137 }
138 break;
139 }
140 assert(n->tok >= MAN_TH && n->tok < MAN_MAX);
141 cp = man_valids + n->tok;
142 if (*cp)
143 (*cp)(man, n);
144 if (man->last == n)
145 man_state(man, n);
146 break;
147 }
148 }
149
150 static void
151 check_root(CHKARGS)
152 {
153 assert((man->flags & (MAN_BLINE | MAN_ELINE)) == 0);
154
155 if (n->last == NULL || n->last->type == ROFFT_COMMENT)
156 mandoc_msg(MANDOCERR_DOC_EMPTY, man->parse,
157 n->line, n->pos, NULL);
158 else
159 man->meta.hasbody = 1;
160
161 if (NULL == man->meta.title) {
162 mandoc_msg(MANDOCERR_TH_NOTITLE, man->parse,
163 n->line, n->pos, NULL);
164
165 /*
166 * If a title hasn't been set, do so now (by
167 * implication, date and section also aren't set).
168 */
169
170 man->meta.title = mandoc_strdup("");
171 man->meta.msec = mandoc_strdup("");
172 man->meta.date = man->quick ? mandoc_strdup("") :
173 mandoc_normdate(man, NULL, n->line, n->pos);
174 }
175
|