/* $Id: main.c,v 1.269 2016/07/12 05:18:38 kristaps Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014-2016 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2010 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"
#include <assert.h>
#include <ctype.h>
#if HAVE_ERR
#include <err.h>
#endif
#include <errno.h>
#include <fcntl.h>
#include <glob.h>
#include <sandbox.h>
#endif
#include <signal.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "mandoc_aux.h"
#include "mandoc.h"
#include "roff.h"
#include "mdoc.h"
#include "man.h"
#include "tag.h"
#include "main.h"
#include "manconf.h"
#include "mansearch.h"
# if !defined(lint)
# define __attribute__(x)
# endif
#endif /* !defined(__GNUC__) || (__GNUC__ < 2) */
enum outmode {
OUTMODE_DEF = 0,
};
enum outt {
};
struct curparse {
};
const char *, const char *,
const struct manpaths *, int, char**,
static int koptions(int *, char *);
#if HAVE_SQLITE3
int mandocdb(int, char**);
#endif
static int moptions(int *, char *);
const char *, int, int, const char *);
static void passthrough(const char *, int, int);
int
{
const char *progname;
char *auxpaths;
char *defos;
unsigned char *uc;
const char *sec;
int fd;
int show_usage;
int options;
int use_pager;
int c;
#if HAVE_PROGNAME
progname = getprogname();
#else
if (argc < 1)
else
++progname;
#endif
#if HAVE_SQLITE3
#endif
#if HAVE_PLEDGE
#endif
#endif
/* Search options. */
else
/* Parser and formatter options. */
use_pager = 1;
show_usage = 0;
"aC:cfhI:iK:klM:m:O:S:s:T:VW:w"))) {
switch (c) {
case 'a':
break;
case 'C':
break;
case 'c':
use_pager = 0;
break;
case 'f':
break;
case 'h':
use_pager = 0;
break;
case 'I':
return (int)MANDOCLEVEL_BADARG;
}
if (defos) {
return (int)MANDOCLEVEL_BADARG;
}
break;
case 'i':
break;
case 'K':
return (int)MANDOCLEVEL_BADARG;
break;
case 'k':
break;
case 'l':
break;
case 'M':
break;
case 'm':
break;
case 'O':
break;
case 'S':
break;
case 's':
break;
case 'T':
return (int)MANDOCLEVEL_BADARG;
break;
case 'W':
return (int)MANDOCLEVEL_BADARG;
break;
case 'w':
break;
default:
show_usage = 1;
break;
}
}
if (show_usage)
/* Postprocess options. */
if (outmode == OUTMODE_DEF) {
case ARG_FILE:
use_pager = 0;
break;
case ARG_NAME:
break;
default:
break;
}
}
if (outmode == OUTMODE_FLN ||
outmode == OUTMODE_LST ||
use_pager = 0;
#if HAVE_PLEDGE
if (!use_pager)
#endif
/* Parse arguments. */
if (argc > 0) {
}
/*
* Quirks for help(1)
* and for a man(1) section argument without -s.
*/
if (*progname == 'h') {
if (argc == 0) {
argc = 1;
}
} else if (argc > 1 &&
argv++;
argc--;
}
#ifdef MACHINE
#endif
}
rc = MANDOCLEVEL_OK;
/* man(1), whatis(1), apropos(1) */
if (argc == 0)
outmode == OUTMODE_ONE)
/* Access the mandoc database. */
#if HAVE_SQLITE3
mansearch_setup(1);
#else
fputs("mandoc: database support not compiled in\n",
stderr);
return (int)MANDOCLEVEL_BADARG;
}
sz = 0;
#endif
if (sz == 0) {
else
warnx("nothing appropriate");
}
if (sz == 0) {
goto out;
}
/*
* For standard man(1) and -a output mode,
* prepare for copying filename pointers
* into the program parameter array.
*/
if (outmode == OUTMODE_ONE) {
argc = 1;
best_prio = 20;
} else if (outmode == OUTMODE_ALL)
/* Iterate all matching manuals. */
for (i = 0; i < sz; i++) {
if (outmode == OUTMODE_FLN)
else if (outmode == OUTMODE_LST)
else if (outmode == OUTMODE_ONE) {
/* Search for the best section. */
if (sec[0] == '\0')
continue;
prio += 10;
continue;
}
}
/*
* For man(1), -a and -i output mode, fall through
* to the main mandoc(1) code iterating files
* and running the parsers on each of them.
*/
goto out;
}
/* mandoc(1) */
#if HAVE_PLEDGE
if (use_pager) {
} else {
}
#endif
return (int)MANDOCLEVEL_BADARG;
mchars_alloc();
/*
* Conditionally start up the lookaside buffer before parsing.
*/
if (argc < 1) {
if (use_pager)
}
while (argc > 0) {
if (fd != -1) {
if (use_pager) {
use_pager = 0;
}
/* For .so only; ignore failure. */
} else
} else if (rc < MANDOCLEVEL_ERROR)
break;
resp++;
else
argv++;
if (--argc)
}
case OUTT_HTML:
break;
case OUTT_UTF8:
case OUTT_LOCALE:
case OUTT_ASCII:
break;
case OUTT_PDF:
case OUTT_PS:
break;
default:
break;
}
}
mchars_free();
out:
manconf_free(&conf);
#if HAVE_SQLITE3
mansearch_setup(0);
#endif
}
/*
* When using a pager, finish writing both temporary files,
* fork it, wait for the user to close it, and clean up.
*/
tag_write();
pager_pid = 0;
for (;;) {
/* Stop here until moved to the foreground. */
(void)tcsetpgrp(STDIN_FILENO,
man_pgid);
continue;
} else
continue;
}
/* Once in the foreground, activate the pager. */
if (pager_pid) {
} else
/* Wait for the pager to stop or exit. */
continue;
if (pid == -1) {
warn("wait");
break;
}
if (!WIFSTOPPED(status))
break;
}
tag_unlink();
}
return (int)rc;
}
static void
{
switch (argmode) {
case ARG_FILE:
fputs("usage: mandoc [-acfhkl] [-I os=name] "
"[-K encoding] [-mformat] [-O option]\n"
"\t [-T output] [-W level] [file ...]\n", stderr);
break;
case ARG_NAME:
fputs("usage: man [-acfhklw] [-C file] [-I os=name] "
"[-K encoding] [-M path] [-m path]\n"
"\t [-O option=value] [-S subsection] [-s section] "
"[-T output] [-W level]\n"
"\t [section] name ...\n", stderr);
break;
case ARG_WORD:
fputs("usage: whatis [-acfhklw] [-C file] "
"[-M path] [-m path] [-O outkey] [-S arch]\n"
"\t [-s section] name ...\n", stderr);
break;
case ARG_EXPR:
fputs("usage: apropos [-acfhklw] [-C file] "
"[-M path] [-m path] [-O outkey] [-S arch]\n"
"\t [-s section] expression ...\n", stderr);
break;
}
exit((int)MANDOCLEVEL_BADARG);
}
static int
{
char *file;
goto found;
goto found;
}
goto found;
}
if (globres == 0)
if (globres != 0)
return 0;
#if HAVE_SQLITE3
warnx("outdated mandoc.db lacks %s(%s) entry, run %s %s",
#endif
return 1;
}
static void
{
const char *const sections[] =
{"1", "8", "6", "2", "3", "5", "7", "4", "9", "3p"};
while (argc) {
return;
return;
}
argv++;
argc--;
}
}
static void
{
/* Begin by parsing the file itself. */
if (fd != STDIN_FILENO)
/*
* With -Wstop and warnings or errors of at least the requested
* level, do not produce output.
*/
return;
/* If unset, allocate output dev now (if applicable). */
case OUTT_HTML:
break;
case OUTT_UTF8:
break;
case OUTT_LOCALE:
break;
case OUTT_ASCII:
break;
case OUTT_PDF:
break;
case OUTT_PS:
break;
default:
break;
}
}
/* Execute the out device, if it exists. */
return;
case OUTT_HTML:
break;
case OUTT_TREE:
break;
case OUTT_MAN:
break;
case OUTT_PDF:
case OUTT_ASCII:
case OUTT_UTF8:
case OUTT_LOCALE:
case OUTT_PS:
break;
default:
break;
}
}
case OUTT_HTML:
break;
case OUTT_TREE:
break;
case OUTT_MAN:
break;
case OUTT_PDF:
case OUTT_ASCII:
case OUTT_UTF8:
case OUTT_LOCALE:
case OUTT_PS:
break;
default:
break;
}
}
}
static void
{
const char *syscall;
int print;
linesz = 0;
syscall = "fdopen";
goto fail;
}
print = 0;
if (synopsis_only) {
if (print) {
goto done;
cp++;
} else {
print = 1;
continue;
}
}
syscall = "fputs";
goto fail;
}
}
syscall = "getline";
goto fail;
}
done:
return;
fail:
if (rc < MANDOCLEVEL_SYSERR)
}
static int
{
*options |= MPARSE_UTF8;
*options &= ~MPARSE_LATIN1;
*options |= MPARSE_LATIN1;
*options &= ~MPARSE_UTF8;
} else {
return 0;
}
return 1;
}
static int
{
/* nothing to do */;
*options |= MPARSE_MDOC;
/* nothing to do */;
*options |= MPARSE_MAN;
else {
return 0;
}
return 1;
}
static int
{
else {
return 0;
}
return 1;
}
static int
{
char *v, *o;
toks[0] = "stop";
while (*arg) {
o = arg;
case 0:
break;
case 1:
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
warnx("-W %s: Bad argument", o);
return 0;
}
}
return 1;
}
static void
{
const char *mparse_msg;
if (line)
if (msg)
}
static pid_t
{
const char *pager;
char *cp;
int argc;
pager = "more -s";
/*
* Parse the pager command into words.
* Intentionally do not do anything fancy here.
*/
argc = 0;
break;
*cp++ = '\0';
while (*cp == ' ')
cp++;
if (*cp == '\0')
break;
}
/* For less(1), use the tag file. */
}
}
case -1:
case 0:
break;
default:
#if HAVE_PLEDGE
#endif
return pager_pid;
}
/* The child process becomes the pager. */
/* Do not start the pager before controlling the terminal. */
}