]>
git.cameronkatri.com Git - mandoc.git/blob - read.c
1 /* $Id: read.c,v 1.200 2018/08/25 16:53:39 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010-2018 Ingo Schwarze <schwarze@openbsd.org>
5 * Copyright (c) 2010, 2012 Joerg Sonnenberger <joerg@netbsd.org>
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/types.h>
36 #include "mandoc_aux.h"
41 #include "libmandoc.h"
43 #define REPARSE_LIMIT 1000
46 struct roff
*roff
; /* roff parser (!NULL) */
47 struct roff_man
*man
; /* man parser */
48 char *sodest
; /* filename pointed to by .so */
49 const char *file
; /* filename of current input file */
50 struct buf
*primary
; /* buffer currently being parsed */
51 struct buf
*secondary
; /* copy of top level input */
52 struct buf
*loop
; /* open .while request line */
53 const char *os_s
; /* default operating system */
54 mandocmsg mmsg
; /* warning/error message handler */
55 enum mandoclevel file_status
; /* status of current parse */
56 enum mandocerr mmin
; /* ignore messages below this */
57 int options
; /* parser options */
58 int gzip
; /* current input file is gzipped */
59 int filenc
; /* encoding of the current file */
60 int reparse_count
; /* finite interp. stack */
61 int line
; /* line number in the file */
64 static void choose_parser(struct mparse
*);
65 static void free_buf_list(struct buf
*);
66 static void resize_buf(struct buf
*, size_t);
67 static int mparse_buf_r(struct mparse
*, struct buf
, size_t, int);
68 static int read_whole_file(struct mparse
*, const char *, int,
70 static void mparse_end(struct mparse
*);
71 static void mparse_parse_buffer(struct mparse
*, struct buf
,
74 static const enum mandocerr mandoclimits
[MANDOCLEVEL_MAX
] = {
84 static const char * const mandocerrs
[MANDOCERR_MAX
] = {
87 "base system convention",
91 "unknown architecture",
92 "operating system explicitly specified",
94 "referenced manual not found",
96 "generic style suggestion",
98 "legacy man(7) date format",
99 "normalizing date format to",
100 "lower case character in document title",
102 "possible typo in section name",
103 "unterminated quoted argument",
105 "consider using OS macro",
106 "errnos out of order",
108 "trailing delimiter",
109 "no blank before trailing delimiter",
110 "fill mode already enabled, skipping",
111 "fill mode already disabled, skipping",
112 "verbatim \"--\", maybe consider using \\(em",
113 "function name without markup",
114 "whitespace at end of input line",
119 /* related to the prologue */
120 "missing manual title, using UNTITLED",
121 "missing manual title, using \"\"",
122 "missing manual section, using \"\"",
123 "unknown manual section",
124 "missing date, using today's date",
125 "cannot parse date, using it verbatim",
126 "date in the future, using it anyway",
127 "missing Os macro, using \"\"",
128 "late prologue macro",
129 "prologue macros out of order",
131 /* related to document structure */
132 ".so is fragile, better use ln(1)",
134 "content before first section header",
135 "first section is not \"NAME\"",
136 "NAME section without Nm before Nd",
137 "NAME section without description",
138 "description not at the end of NAME",
139 "bad NAME section content",
140 "missing comma before name",
141 "missing description line, using \"\"",
142 "description line outside NAME section",
143 "sections out of conventional order",
144 "duplicate section title",
145 "unexpected section",
146 "cross reference to self",
148 "unusual Xr punctuation",
149 "AUTHORS section without An macro",
151 /* related to macros and nesting */
153 "macro neither callable nor escaped",
154 "skipping paragraph macro",
155 "moving paragraph macro out of list",
156 "skipping no-space macro",
157 "blocks badly nested",
158 "nested displays are not portable",
159 "moving content out of list",
160 "first macro on line",
162 "skipping blank line in line scope",
164 /* related to missing macro arguments */
165 "skipping empty request",
166 "conditional request controls empty scope",
167 "skipping empty macro",
169 "empty argument, using 0n",
170 "missing display type, using -ragged",
171 "list type is not the first argument",
172 "missing -width in -tag list, using 6n",
173 "missing utility name, using \"\"",
174 "missing function name, using \"\"",
175 "empty head in list item",
177 "missing argument, using next line",
178 "missing font type, using \\fR",
179 "unknown font type, using \\fR",
180 "nothing follows prefix",
181 "empty reference block",
182 "missing section argument",
183 "missing -std argument, adding it",
184 "missing option string, using \"\"",
185 "missing resource identifier, using \"\"",
186 "missing eqn box, using \"\"",
188 /* related to bad macro arguments */
189 "duplicate argument",
190 "skipping duplicate argument",
191 "skipping duplicate display type",
192 "skipping duplicate list type",
193 "skipping -width argument",
194 "wrong number of cells",
195 "unknown AT&T UNIX version",
196 "comma in function argument",
197 "parenthesis in function name",
198 "unknown library name",
199 "invalid content in Rs block",
200 "invalid Boolean argument",
201 "argument contains two font escapes",
202 "unknown font, skipping request",
203 "odd number of characters in request",
205 /* related to plain text */
206 "blank line in fill mode, using .sp",
207 "tab in filled text",
208 "new sentence, new line",
209 "invalid escape sequence",
210 "undefined string, using \"\"",
212 /* related to tables */
213 "tbl line starts with span",
214 "tbl column starts with span",
215 "skipping vertical bar in tbl layout",
219 /* related to tables */
220 "non-alphabetic character in tbl options",
221 "skipping unknown tbl option",
222 "missing tbl option argument",
223 "wrong tbl option argument size",
225 "invalid character in tbl layout",
226 "unmatched parenthesis in tbl layout",
227 "tbl without any data cells",
228 "ignoring data in spanned tbl cell",
229 "ignoring extra tbl data cells",
230 "data block open at end of tbl",
232 /* related to document structure and macros */
234 "duplicate prologue macro",
235 "skipping late title macro",
236 "input stack limit exceeded, infinite loop?",
237 "skipping bad character",
238 "skipping unknown macro",
239 "ignoring request outside macro",
240 "skipping insecure request",
241 "skipping item outside list",
242 "skipping column outside column list",
243 "skipping end of block that is not open",
244 "fewer RS blocks open, skipping",
245 "inserting missing end of block",
246 "appending missing end of block",
248 /* related to request and macro arguments */
249 "escaped character not allowed in a name",
250 "using macro argument outside macro",
251 "argument number is not numeric",
252 "NOT IMPLEMENTED: Bd -file",
253 "skipping display without arguments",
254 "missing list type, using -item",
255 "argument is not numeric, using 1",
256 "argument is not a character",
257 "missing manual name, using \"\"",
258 "uname(3) system call failed, using UNKNOWN",
259 "unknown standard specifier",
260 "skipping request without numeric argument",
262 "NOT IMPLEMENTED: .so with absolute path or \"..\"",
263 ".so request failed",
264 "skipping all arguments",
265 "skipping excess arguments",
268 "unsupported feature",
270 "unsupported control character",
271 "unsupported roff request",
272 "nested .while loops",
273 "end of scope with open .while loop",
274 "end of .while loop in inner scope",
275 "cannot continue this .while loop",
276 "eqn delim option in tbl",
277 "unsupported tbl layout modifier",
278 "ignoring macro in table",
281 static const char * const mandoclevels
[MANDOCLEVEL_MAX
] = {
293 resize_buf(struct buf
*buf
, size_t initial
)
296 buf
->sz
= buf
->sz
> initial
/2 ? 2 * buf
->sz
: initial
;
297 buf
->buf
= mandoc_realloc(buf
->buf
, buf
->sz
);
301 free_buf_list(struct buf
*buf
)
305 while (buf
!= NULL
) {
314 choose_parser(struct mparse
*curp
)
320 * If neither command line arguments -mdoc or -man select
321 * a parser nor the roff parser found a .Dd or .TH macro
322 * yet, look ahead in the main input buffer.
325 if ((format
= roff_getformat(curp
->roff
)) == 0) {
326 cp
= curp
->primary
->buf
;
327 ep
= cp
+ curp
->primary
->sz
;
329 if (*cp
== '.' || *cp
== '\'') {
331 if (cp
[0] == 'D' && cp
[1] == 'd') {
332 format
= MPARSE_MDOC
;
335 if (cp
[0] == 'T' && cp
[1] == 'H') {
340 cp
= memchr(cp
, '\n', ep
- cp
);
347 if (format
== MPARSE_MDOC
) {
348 curp
->man
->macroset
= MACROSET_MDOC
;
349 if (curp
->man
->mdocmac
== NULL
)
350 curp
->man
->mdocmac
= roffhash_alloc(MDOC_Dd
, MDOC_MAX
);
352 curp
->man
->macroset
= MACROSET_MAN
;
353 if (curp
->man
->manmac
== NULL
)
354 curp
->man
->manmac
= roffhash_alloc(MAN_TH
, MAN_MAX
);
356 curp
->man
->first
->tok
= TOKEN_NONE
;
360 * Main parse routine for a buffer.
361 * It assumes encoding and line numbering are already set up.
362 * It can recurse directly (for invocations of user-defined
363 * macros, inline equations, and input line traps)
364 * and indirectly (for .so file inclusion).
367 mparse_buf_r(struct mparse
*curp
, struct buf blk
, size_t i
, int start
)
370 struct buf
*firstln
, *lastln
, *thisln
, *loop
;
371 const char *save_file
;
373 size_t pos
; /* byte number in the ln buffer */
374 int line_result
, result
;
376 int lnn
; /* line number in the real file */
378 int inloop
; /* Saw .while on this level. */
382 ln
.buf
= mandoc_malloc(ln
.sz
);
384 firstln
= loop
= NULL
;
390 while (i
< blk
.sz
&& (blk
.buf
[i
] != '\0' || pos
!= 0)) {
393 curp
->reparse_count
= 0;
396 curp
->filenc
& MPARSE_UTF8
&&
397 curp
->filenc
& MPARSE_LATIN1
)
398 curp
->filenc
= preconv_cue(&blk
, i
);
401 while (i
< blk
.sz
&& (start
|| blk
.buf
[i
] != '\0')) {
404 * When finding an unescaped newline character,
405 * leave the character loop to process the line.
406 * Skip a preceding carriage return, if any.
409 if ('\r' == blk
.buf
[i
] && i
+ 1 < blk
.sz
&&
410 '\n' == blk
.buf
[i
+ 1])
412 if ('\n' == blk
.buf
[i
]) {
419 * Make sure we have space for the worst
420 * case of 12 bytes: "\\[u10ffff]\n\0"
423 if (pos
+ 12 > ln
.sz
)
424 resize_buf(&ln
, 256);
427 * Encode 8-bit input.
432 if ( ! (curp
->filenc
&& preconv_encode(
433 &blk
, &i
, &ln
, &pos
, &curp
->filenc
))) {
434 mandoc_vmsg(MANDOCERR_CHAR_BAD
, curp
,
435 curp
->line
, pos
, "0x%x", c
);
443 * Exclude control characters.
446 if (c
== 0x7f || (c
< 0x20 && c
!= 0x09)) {
447 mandoc_vmsg(c
== 0x00 || c
== 0x04 ||
448 c
> 0x0a ? MANDOCERR_CHAR_BAD
:
449 MANDOCERR_CHAR_UNSUPP
,
450 curp
, curp
->line
, pos
, "0x%x", c
);
457 ln
.buf
[pos
++] = blk
.buf
[i
++];
462 * Maintain a lookaside buffer of all lines.
463 * parsed from this input source.
466 thisln
= mandoc_malloc(sizeof(*thisln
));
467 thisln
->buf
= mandoc_strdup(ln
.buf
);
468 thisln
->sz
= strlen(ln
.buf
) + 1;
470 if (firstln
== NULL
) {
471 firstln
= lastln
= thisln
;
472 if (curp
->secondary
== NULL
)
473 curp
->secondary
= firstln
;
475 lastln
->next
= thisln
;
479 /* XXX Ugly hack to mark the end of the input. */
481 if (i
== blk
.sz
|| blk
.buf
[i
] == '\0') {
482 ln
.buf
[pos
++] = '\n';
487 * A significant amount of complexity is contained by
488 * the roff preprocessor. It's line-oriented but can be
489 * expressed on one line, so we need at times to
490 * readjust our starting point and re-run it. The roff
491 * preprocessor can also readjust the buffers with new
492 * data, so we pass them in wholesale.
497 line_result
= roff_parseln(curp
->roff
, curp
->line
, &ln
, &of
);
499 /* Process options. */
501 if (line_result
& ROFF_APPEND
)
502 assert(line_result
== (ROFF_IGN
| ROFF_APPEND
));
504 if (line_result
& ROFF_USERCALL
)
505 assert((line_result
& ROFF_MASK
) == ROFF_REPARSE
);
507 if (line_result
& ROFF_USERRET
) {
508 assert(line_result
== (ROFF_IGN
| ROFF_USERRET
));
510 /* Return from the current macro. */
511 result
= ROFF_USERRET
;
516 switch (line_result
& ROFF_LOOPMASK
) {
520 if (curp
->loop
!= NULL
) {
521 if (loop
== curp
->loop
)
523 mandoc_msg(MANDOCERR_WHILE_NEST
,
524 curp
, curp
->line
, pos
, NULL
);
532 if (curp
->loop
== NULL
) {
533 mandoc_msg(MANDOCERR_WHILE_FAIL
,
534 curp
, curp
->line
, pos
, NULL
);
538 mandoc_msg(MANDOCERR_WHILE_INTO
,
539 curp
, curp
->line
, pos
, NULL
);
540 curp
->loop
= loop
= NULL
;
543 if (line_result
& ROFF_LOOPCONT
)
546 curp
->loop
= loop
= NULL
;
554 /* Process the main instruction from the roff parser. */
556 switch (line_result
& ROFF_MASK
) {
560 if (curp
->man
->macroset
== MACROSET_NONE
)
562 if ((curp
->man
->macroset
== MACROSET_MDOC
?
563 mdoc_parseln(curp
->man
, curp
->line
, ln
.buf
, of
) :
564 man_parseln(curp
->man
, curp
->line
, ln
.buf
, of
)
571 if (++curp
->reparse_count
> REPARSE_LIMIT
) {
572 /* Abort and return to the top level. */
574 mandoc_msg(MANDOCERR_ROFFLOOP
, curp
,
575 curp
->line
, pos
, NULL
);
578 result
= mparse_buf_r(curp
, ln
, of
, 0);
579 if (line_result
& ROFF_USERCALL
) {
580 roff_userret(curp
->roff
);
581 /* Continue normally. */
582 if (result
& ROFF_USERRET
)
585 if (start
== 0 && result
!= ROFF_CONT
)
589 if ( ! (curp
->options
& MPARSE_SO
) &&
590 (i
>= blk
.sz
|| blk
.buf
[i
] == '\0')) {
591 curp
->sodest
= mandoc_strdup(ln
.buf
+ of
);
594 save_file
= curp
->file
;
595 if ((fd
= mparse_open(curp
, ln
.buf
+ of
)) != -1) {
596 mparse_readfd(curp
, fd
, ln
.buf
+ of
);
598 curp
->file
= save_file
;
600 curp
->file
= save_file
;
601 mandoc_vmsg(MANDOCERR_SO_FAIL
,
602 curp
, curp
->line
, pos
,
603 ".so %s", ln
.buf
+ of
);
604 ln
.sz
= mandoc_asprintf(&cp
,
605 ".sp\nSee the file %s.\n.sp",
610 mparse_buf_r(curp
, ln
, of
, 0);
617 /* Start the next input line. */
620 (line_result
& ROFF_LOOPMASK
) == ROFF_IGN
)
624 if ((line_result
& ROFF_APPEND
) == 0)
626 if (ln
.sz
< loop
->sz
)
627 resize_buf(&ln
, loop
->sz
);
628 (void)strlcat(ln
.buf
, loop
->buf
, ln
.sz
);
633 pos
= (line_result
& ROFF_APPEND
) ? strlen(ln
.buf
) : 0;
637 if (result
!= ROFF_USERRET
)
638 mandoc_msg(MANDOCERR_WHILE_OUTOF
, curp
,
639 curp
->line
, pos
, NULL
);
643 if (firstln
!= curp
->secondary
)
644 free_buf_list(firstln
);
649 read_whole_file(struct mparse
*curp
, const char *file
, int fd
,
650 struct buf
*fb
, int *with_mmap
)
656 int gzerrnum
, retval
;
658 if (fstat(fd
, &st
) == -1) {
659 mandoc_vmsg(MANDOCERR_FILE
, curp
, 0, 0,
660 "fstat: %s", strerror(errno
));
665 * If we're a regular file, try just reading in the whole entry
666 * via mmap(). This is faster than reading it into blocks, and
667 * since each file is only a few bytes to begin with, I'm not
668 * concerned that this is going to tank any machines.
671 if (curp
->gzip
== 0 && S_ISREG(st
.st_mode
)) {
672 if (st
.st_size
> 0x7fffffff) {
673 mandoc_msg(MANDOCERR_TOOLARGE
, curp
, 0, 0, NULL
);
677 fb
->sz
= (size_t)st
.st_size
;
678 fb
->buf
= mmap(NULL
, fb
->sz
, PROT_READ
, MAP_SHARED
, fd
, 0);
679 if (fb
->buf
!= MAP_FAILED
)
685 * Duplicating the file descriptor is required
686 * because we will have to call gzclose(3)
687 * to free memory used internally by zlib,
688 * but that will also close the file descriptor,
689 * which this function must not do.
691 if ((fd
= dup(fd
)) == -1) {
692 mandoc_vmsg(MANDOCERR_FILE
, curp
, 0, 0,
693 "dup: %s", strerror(errno
));
696 if ((gz
= gzdopen(fd
, "rb")) == NULL
) {
697 mandoc_vmsg(MANDOCERR_FILE
, curp
, 0, 0,
698 "gzdopen: %s", strerror(errno
));
706 * If this isn't a regular file (like, say, stdin), then we must
707 * go the old way and just read things in bit by bit.
717 if (fb
->sz
== (1U << 31)) {
718 mandoc_msg(MANDOCERR_TOOLARGE
, curp
,
722 resize_buf(fb
, 65536);
725 gzread(gz
, fb
->buf
+ (int)off
, fb
->sz
- off
) :
726 read(fd
, fb
->buf
+ (int)off
, fb
->sz
- off
);
734 (void)gzerror(gz
, &gzerrnum
);
735 mandoc_vmsg(MANDOCERR_FILE
, curp
, 0, 0, "read: %s",
736 curp
->gzip
&& gzerrnum
!= Z_ERRNO
?
737 zError(gzerrnum
) : strerror(errno
));
743 if (curp
->gzip
&& (gzerrnum
= gzclose(gz
)) != Z_OK
)
744 mandoc_vmsg(MANDOCERR_FILE
, curp
, 0, 0, "gzclose: %s",
745 gzerrnum
== Z_ERRNO
? strerror(errno
) :
755 mparse_end(struct mparse
*curp
)
757 if (curp
->man
->macroset
== MACROSET_NONE
)
758 curp
->man
->macroset
= MACROSET_MAN
;
759 if (curp
->man
->macroset
== MACROSET_MDOC
)
760 mdoc_endparse(curp
->man
);
762 man_endparse(curp
->man
);
763 roff_endparse(curp
->roff
);
767 mparse_parse_buffer(struct mparse
*curp
, struct buf blk
, const char *file
)
769 struct buf
*svprimary
;
772 static int recursion_depth
;
774 if (64 < recursion_depth
) {
775 mandoc_msg(MANDOCERR_ROFFLOOP
, curp
, curp
->line
, 0, NULL
);
779 /* Line number is per-file. */
782 svprimary
= curp
->primary
;
783 curp
->primary
= &blk
;
787 /* Skip an UTF-8 byte order mark. */
788 if (curp
->filenc
& MPARSE_UTF8
&& blk
.sz
> 2 &&
789 (unsigned char)blk
.buf
[0] == 0xef &&
790 (unsigned char)blk
.buf
[1] == 0xbb &&
791 (unsigned char)blk
.buf
[2] == 0xbf) {
793 curp
->filenc
&= ~MPARSE_LATIN1
;
797 mparse_buf_r(curp
, blk
, offset
, 1);
799 if (--recursion_depth
== 0)
802 curp
->primary
= svprimary
;
807 mparse_readmem(struct mparse
*curp
, void *buf
, size_t len
,
815 mparse_parse_buffer(curp
, blk
, file
);
816 return curp
->file_status
;
820 * Read the whole file into memory and call the parsers.
821 * Called recursively when an .so request is encountered.
824 mparse_readfd(struct mparse
*curp
, int fd
, const char *file
)
830 if (read_whole_file(curp
, file
, fd
, &blk
, &with_mmap
)) {
831 save_filenc
= curp
->filenc
;
832 curp
->filenc
= curp
->options
&
833 (MPARSE_UTF8
| MPARSE_LATIN1
);
834 mparse_parse_buffer(curp
, blk
, file
);
835 curp
->filenc
= save_filenc
;
837 munmap(blk
.buf
, blk
.sz
);
841 return curp
->file_status
;
845 mparse_open(struct mparse
*curp
, const char *file
)
851 cp
= strrchr(file
, '.');
852 curp
->gzip
= (cp
!= NULL
&& ! strcmp(cp
+ 1, "gz"));
854 /* First try to use the filename as it is. */
856 if ((fd
= open(file
, O_RDONLY
)) != -1)
860 * If that doesn't work and the filename doesn't
861 * already end in .gz, try appending .gz.
865 mandoc_asprintf(&cp
, "%s.gz", file
);
866 fd
= open(cp
, O_RDONLY
);
874 /* Neither worked, give up. */
876 mandoc_msg(MANDOCERR_FILE
, curp
, 0, 0, strerror(errno
));
881 mparse_alloc(int options
, enum mandocerr mmin
, mandocmsg mmsg
,
882 enum mandoc_os os_e
, const char *os_s
)
886 curp
= mandoc_calloc(1, sizeof(struct mparse
));
888 curp
->options
= options
;
893 curp
->roff
= roff_alloc(curp
, options
);
894 curp
->man
= roff_man_alloc(curp
->roff
, curp
, curp
->os_s
,
895 curp
->options
& MPARSE_QUICK
? 1 : 0);
896 if (curp
->options
& MPARSE_MDOC
) {
897 curp
->man
->macroset
= MACROSET_MDOC
;
898 if (curp
->man
->mdocmac
== NULL
)
899 curp
->man
->mdocmac
= roffhash_alloc(MDOC_Dd
, MDOC_MAX
);
900 } else if (curp
->options
& MPARSE_MAN
) {
901 curp
->man
->macroset
= MACROSET_MAN
;
902 if (curp
->man
->manmac
== NULL
)
903 curp
->man
->manmac
= roffhash_alloc(MAN_TH
, MAN_MAX
);
905 curp
->man
->first
->tok
= TOKEN_NONE
;
906 curp
->man
->meta
.os_e
= os_e
;
911 mparse_reset(struct mparse
*curp
)
913 roff_reset(curp
->roff
);
914 roff_man_reset(curp
->man
);
915 free_buf_list(curp
->secondary
);
916 curp
->secondary
= NULL
;
921 curp
->file_status
= MANDOCLEVEL_OK
;
926 mparse_free(struct mparse
*curp
)
928 roffhash_free(curp
->man
->mdocmac
);
929 roffhash_free(curp
->man
->manmac
);
930 roff_man_free(curp
->man
);
931 roff_free(curp
->roff
);
932 free_buf_list(curp
->secondary
);
938 mparse_result(struct mparse
*curp
, struct roff_man
**man
,
942 if (sodest
&& NULL
!= (*sodest
= curp
->sodest
)) {
951 mparse_updaterc(struct mparse
*curp
, enum mandoclevel
*rc
)
953 if (curp
->file_status
> *rc
)
954 *rc
= curp
->file_status
;
958 mandoc_vmsg(enum mandocerr t
, struct mparse
*m
,
959 int ln
, int pos
, const char *fmt
, ...)
965 (void)vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
968 mandoc_msg(t
, m
, ln
, pos
, buf
);
972 mandoc_msg(enum mandocerr er
, struct mparse
*m
,
973 int ln
, int col
, const char *msg
)
975 enum mandoclevel level
;
977 if (er
< m
->mmin
&& er
!= MANDOCERR_FILE
)
980 level
= MANDOCLEVEL_UNSUPP
;
981 while (er
< mandoclimits
[level
])
985 (*m
->mmsg
)(er
, level
, m
->file
, ln
, col
, msg
);
987 if (m
->file_status
< level
)
988 m
->file_status
= level
;
992 mparse_strerror(enum mandocerr er
)
995 return mandocerrs
[er
];
999 mparse_strlevel(enum mandoclevel lvl
)
1001 return mandoclevels
[lvl
];
1005 mparse_copy(const struct mparse
*p
)
1009 for (buf
= p
->secondary
; buf
!= NULL
; buf
= buf
->next
)