/* $Id: read.c,v 1.149 2016/07/10 13:34:30 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2016 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2010, 2012 Joerg Sonnenberger <joerg@netbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "config.h"
#if HAVE_MMAP
#endif
#include <assert.h>
#include <ctype.h>
#if HAVE_ERR
#include <err.h>
#endif
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <zlib.h>
#include "mandoc_aux.h"
#include "mandoc.h"
#include "roff.h"
#include "mdoc.h"
#include "man.h"
#include "libmandoc.h"
#include "roff_int.h"
struct mparse {
};
static void choose_parser(struct mparse *);
static int read_whole_file(struct mparse *, const char *, int,
struct buf *, int *);
static void mparse_end(struct mparse *);
const char *);
};
"ok",
"generic warning",
/* related to the prologue */
"missing manual title, using UNTITLED",
"missing manual title, using \"\"",
"lower case character in document title",
"missing manual section, using \"\"",
"unknown manual section",
"missing date, using today's date",
"cannot parse date, using it verbatim",
"missing Os macro, using \"\"",
"duplicate prologue macro",
"late prologue macro",
"skipping late title macro",
"prologue macros out of order",
/* related to document structure */
".so is fragile, better use ln(1)",
"no document body",
"content before first section header",
"first section is not \"NAME\"",
"NAME section without name",
"NAME section without description",
"description not at the end of NAME",
"bad NAME section content",
"missing description line, using \"\"",
"sections out of conventional order",
"duplicate section title",
"unexpected section",
"unusual Xr order",
"unusual Xr punctuation",
"AUTHORS section without An macro",
/* related to macros and nesting */
"obsolete macro",
"macro neither callable nor escaped",
"skipping paragraph macro",
"moving paragraph macro out of list",
"skipping no-space macro",
"blocks badly nested",
"nested displays are not portable",
"moving content out of list",
"fill mode already enabled, skipping",
"fill mode already disabled, skipping",
"line scope broken",
/* related to missing macro arguments */
"skipping empty request",
"conditional request controls empty scope",
"skipping empty macro",
"empty block",
"empty argument, using 0n",
"missing display type, using -ragged",
"list type is not the first argument",
"missing -width in -tag list, using 8n",
"missing utility name, using \"\"",
"missing function name, using \"\"",
"empty head in list item",
"empty list item",
"missing font type, using \\fR",
"unknown font type, using \\fR",
"nothing follows prefix",
"empty reference block",
"missing -std argument, adding it",
"missing option string, using \"\"",
"missing resource identifier, using \"\"",
"missing eqn box, using \"\"",
/* related to bad macro arguments */
"unterminated quoted argument",
"duplicate argument",
"skipping duplicate argument",
"skipping duplicate display type",
"skipping duplicate list type",
"skipping -width argument",
"wrong number of cells",
"unknown AT&T UNIX version",
"comma in function argument",
"parenthesis in function name",
"invalid content in Rs block",
"invalid Boolean argument",
"unknown font, skipping request",
"odd number of characters in request",
/* related to plain text */
"blank line in fill mode, using .sp",
"tab in filled text",
"whitespace at end of input line",
"bad comment style",
"invalid escape sequence",
"undefined string, using \"\"",
/* related to tables */
"tbl line starts with span",
"tbl column starts with span",
"skipping vertical bar in tbl layout",
"generic error",
/* related to tables */
"non-alphabetic character in tbl options",
"skipping unknown tbl option",
"missing tbl option argument",
"wrong tbl option argument size",
"empty tbl layout",
"invalid character in tbl layout",
"unmatched parenthesis in tbl layout",
"tbl without any data cells",
"ignoring data in spanned tbl cell",
"ignoring extra tbl data cells",
"data block open at end of tbl",
/* related to document structure and macros */
NULL,
"input stack limit exceeded, infinite loop?",
"skipping bad character",
"skipping unknown macro",
"skipping insecure request",
"skipping item outside list",
"skipping column outside column list",
"skipping end of block that is not open",
"fewer RS blocks open, skipping",
"inserting missing end of block",
"appending missing end of block",
/* related to request and macro arguments */
"escaped character not allowed in a name",
"NOT IMPLEMENTED: Bd -file",
"skipping display without arguments",
"missing list type, using -item",
"missing manual name, using \"\"",
"uname(3) system call failed, using UNKNOWN",
"unknown standard specifier",
"skipping request without numeric argument",
"NOT IMPLEMENTED: .so with absolute path or \"..\"",
".so request failed",
"skipping all arguments",
"skipping excess arguments",
"divide by zero",
"unsupported feature",
"input too large",
"unsupported control character",
"unsupported roff request",
"eqn delim option in tbl",
"unsupported tbl layout modifier",
"ignoring macro in table",
};
"SUCCESS",
"RESERVED",
"WARNING",
"ERROR",
"UNSUPP",
"BADARG",
"SYSERR"
};
static void
{
}
static void
{
int format;
/*
* If neither command line arguments -mdoc or -man select
* a parser nor the roff parser found a .Dd or .TH macro
* yet, look ahead in the main input buffer.
*/
cp++;
break;
}
format = MPARSE_MAN;
break;
}
}
break;
cp++;
}
}
}
if (format == MPARSE_MDOC) {
} else {
}
}
/*
* Main parse routine for a buffer.
* It assumes encoding and line numbering are already set up.
* It can recurse directly (for invocations of user-defined
* macros, inline equations, and input line traps)
* and indirectly (for .so file inclusion).
*/
static void
{
const char *save_file;
char *cp;
int of;
int fd;
unsigned char c;
pos = 0;
break;
if (start) {
curp->reparse_count = 0;
if (lnn < 3 &&
}
/*
* When finding an unescaped newline character,
* leave the character loop to process the line.
* Skip a preceding carriage return, if any.
*/
++i;
++i;
++lnn;
break;
}
/*
* Make sure we have space for the worst
* case of 11 bytes: "\\[u10ffff]\0"
*/
/*
* Encode 8-bit input.
*/
if (c & 0x80) {
i++;
}
continue;
}
/*
* Exclude control characters.
*/
if (c == 0x7f || (c < 0x20 && c != 0x09)) {
c > 0x0a ? MANDOCERR_CHAR_BAD :
i++;
if (c != '\r')
continue;
}
/* Trailing backslash = a plain char. */
continue;
}
/*
* Found escape and at least one other character.
* When it's a newline character, skip it.
* When there is a carriage return in between,
* skip that one as well.
*/
++i;
i += 2;
++lnn;
continue;
}
i += 2;
/* Comment, skip to end of line */
++i;
++lnn;
break;
}
}
/* Backout trailing whitespaces */
break;
break;
}
break;
}
/* Catch escaped bogus characters. */
if ( ! (isascii(c) &&
i += 2;
continue;
}
/* Some other escape sequence, copy & cont. */
}
/*
* A significant amount of complexity is contained by
* the roff preprocessor. It's line-oriented but can be
* expressed on one line, so we need at times to
* readjust our starting point and re-run it. The roff
* preprocessor can also readjust the buffers with new
* data, so we pass them in wholesale.
*/
of = 0;
/*
* Maintain a lookaside buffer of all parsed lines. We
* only do this if mparse_keep() has been invoked (the
* buffer may be accessed with mparse_getkeep()).
*/
}
switch (rr) {
case ROFF_REPARSE:
else
pos = 0;
continue;
case ROFF_APPEND:
continue;
case ROFF_RERUN:
goto rerun;
case ROFF_IGN:
pos = 0;
continue;
case ROFF_SO:
return;
}
/*
* We remove `so' clauses from our lookaside
* buffer because we're going to descend into
* the file recursively.
*/
} else {
".sp\nSee the file %s.\n.sp",
of = 0;
}
pos = 0;
continue;
default:
break;
}
/*
* If input parsers have not been allocated, do so now.
* We keep these instanced between parsers, but set them
* locally per parse routine since we can use different
* parsers with each one.
*/
/*
* Lastly, push down into the parsers themselves.
* If libroff returns ROFF_TBL, then add it to the
* currently open parse. Since we only get here if
* there does exist data (see tbl_data.c), we're
* guaranteed that something's been allocated.
* Do the same for ROFF_EQN.
*/
break;
/* Temporary buffers typically are not full. */
break;
/* Start the next input line. */
pos = 0;
}
}
static int
{
#if HAVE_MMAP
/*
* If we're a regular file, try just reading in the whole entry
* via mmap(). This is faster than reading it into blocks, and
* since each file is only a few bytes to begin with, I'm not
* concerned that this is going to tank any machines.
*/
return 0;
}
*with_mmap = 1;
return 1;
}
#endif
} else
/*
* If this isn't a regular file (like, say, stdin), then we must
* go the old way and just read things in bit by bit.
*/
*with_mmap = 0;
off = 0;
for (;;) {
0, 0, NULL);
break;
}
}
if (ssz == 0) {
return 1;
}
if (ssz == -1)
}
return 0;
}
static void
{
else
}
static void
{
const char *svfile;
static int recursion_depth;
if (64 < recursion_depth) {
return;
}
/* Line number is per-file. */
/* Skip an UTF-8 byte order mark. */
offset = 3;
} else
offset = 0;
if (--recursion_depth == 0)
}
enum mandoclevel
const char *file)
{
return curp->file_status;
}
/*
* Read the whole file into memory and call the parsers.
* Called recursively when an .so request is encountered.
*/
enum mandoclevel
{
int with_mmap;
int save_filenc;
(MPARSE_UTF8 | MPARSE_LATIN1);
#if HAVE_MMAP
if (with_mmap)
else
#endif
}
return curp->file_status;
}
int
{
char *cp;
int fd;
/* First try to use the filename as it is. */
return fd;
/*
* If that doesn't work and the filename doesn't
* already end in .gz, try appending .gz.
*/
if (fd != -1) {
return fd;
}
}
/* Neither worked, give up. */
return -1;
}
struct mparse *
const char *defos)
{
}
return curp;
}
void
{
}
void
{
}
void
char **sodest)
{
return;
}
if (man)
}
void
{
}
void
{
level--;
return;
if (m->mmsg)
if (m->file_status < level)
m->file_status = level;
}
const char *
{
return mandocerrs[er];
}
const char *
{
return mandoclevels[lvl];
}
void
{
}
const char *
{
}