version 1.259, 2015/11/20 21:59:54 |
version 1.268, 2016/07/10 14:05:13 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010-2012, 2014-2016 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org> |
* Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
|
|
#include <stdint.h> |
#include <stdint.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
#include <time.h> |
#include <unistd.h> |
#include <unistd.h> |
|
|
#include "mandoc_aux.h" |
#include "mandoc_aux.h" |
Line 123 main(int argc, char *argv[]) |
|
Line 124 main(int argc, char *argv[]) |
|
unsigned char *uc; |
unsigned char *uc; |
struct manpage *res, *resp; |
struct manpage *res, *resp; |
char *conf_file, *defpaths; |
char *conf_file, *defpaths; |
size_t isec, i, sz; |
const char *sec; |
|
size_t i, sz; |
int prio, best_prio; |
int prio, best_prio; |
char sec; |
|
enum mandoclevel rctmp; |
|
enum outmode outmode; |
enum outmode outmode; |
int fd; |
int fd; |
int show_usage; |
int show_usage; |
Line 299 main(int argc, char *argv[]) |
|
Line 299 main(int argc, char *argv[]) |
|
use_pager = 0; |
use_pager = 0; |
|
|
#if HAVE_PLEDGE |
#if HAVE_PLEDGE |
if (!use_pager && pledge("stdio rpath flock", NULL) == -1) |
if (!use_pager) |
err((int)MANDOCLEVEL_SYSERR, "pledge"); |
if (pledge("stdio rpath flock", NULL) == -1) |
|
err((int)MANDOCLEVEL_SYSERR, "pledge"); |
#endif |
#endif |
|
|
/* Parse arguments. */ |
/* Parse arguments. */ |
Line 389 main(int argc, char *argv[]) |
|
Line 390 main(int argc, char *argv[]) |
|
|
|
if (outmode == OUTMODE_ONE) { |
if (outmode == OUTMODE_ONE) { |
argc = 1; |
argc = 1; |
best_prio = 10; |
best_prio = 20; |
} else if (outmode == OUTMODE_ALL) |
} else if (outmode == OUTMODE_ALL) |
argc = (int)sz; |
argc = (int)sz; |
|
|
Line 405 main(int argc, char *argv[]) |
|
Line 406 main(int argc, char *argv[]) |
|
res[i].output); |
res[i].output); |
else if (outmode == OUTMODE_ONE) { |
else if (outmode == OUTMODE_ONE) { |
/* Search for the best section. */ |
/* Search for the best section. */ |
isec = strcspn(res[i].file, "123456789"); |
sec = res[i].file; |
sec = res[i].file[isec]; |
sec += strcspn(sec, "123456789"); |
if ('\0' == sec) |
if (sec[0] == '\0') |
continue; |
continue; |
prio = sec_prios[sec - '1']; |
prio = sec_prios[sec[0] - '1']; |
|
if (sec[1] != '/') |
|
prio += 10; |
if (prio >= best_prio) |
if (prio >= best_prio) |
continue; |
continue; |
best_prio = prio; |
best_prio = prio; |
Line 430 main(int argc, char *argv[]) |
|
Line 433 main(int argc, char *argv[]) |
|
/* mandoc(1) */ |
/* mandoc(1) */ |
|
|
#if HAVE_PLEDGE |
#if HAVE_PLEDGE |
if (pledge(use_pager ? "stdio rpath tmppath tty proc exec" : |
if (use_pager) { |
"stdio rpath", NULL) == -1) |
if (pledge("stdio rpath tmppath tty proc exec", NULL) == -1) |
err((int)MANDOCLEVEL_SYSERR, "pledge"); |
err((int)MANDOCLEVEL_SYSERR, "pledge"); |
|
} else { |
|
if (pledge("stdio rpath", NULL) == -1) |
|
err((int)MANDOCLEVEL_SYSERR, "pledge"); |
|
} |
#endif |
#endif |
|
|
if (search.argmode == ARG_FILE && ! moptions(&options, auxpaths)) |
if (search.argmode == ARG_FILE && ! moptions(&options, auxpaths)) |
Line 454 main(int argc, char *argv[]) |
|
Line 461 main(int argc, char *argv[]) |
|
} |
} |
|
|
while (argc > 0) { |
while (argc > 0) { |
rctmp = mparse_open(curp.mp, &fd, |
fd = mparse_open(curp.mp, resp != NULL ? resp->file : *argv); |
resp != NULL ? resp->file : *argv); |
|
if (rc < rctmp) |
|
rc = rctmp; |
|
|
|
if (fd != -1) { |
if (fd != -1) { |
if (use_pager) { |
if (use_pager) { |
tag_files = tag_init(); |
tag_files = tag_init(); |
Line 476 main(int argc, char *argv[]) |
|
Line 479 main(int argc, char *argv[]) |
|
conf.output.synopsisonly); |
conf.output.synopsisonly); |
|
|
if (argc > 1 && curp.outtype <= OUTT_UTF8) |
if (argc > 1 && curp.outtype <= OUTT_UTF8) |
ascii_sepline(curp.outdata); |
terminal_sepline(curp.outdata); |
} |
} else if (rc < MANDOCLEVEL_ERROR) |
|
rc = MANDOCLEVEL_ERROR; |
|
|
if (MANDOCLEVEL_OK != rc && curp.wstop) |
if (MANDOCLEVEL_OK != rc && curp.wstop) |
break; |
break; |
Line 660 fs_lookup(const struct manpaths *paths, size_t ipath, |
|
Line 664 fs_lookup(const struct manpaths *paths, size_t ipath, |
|
|
|
found: |
found: |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
warnx("outdated mandoc.db lacks %s(%s) entry, run makewhatis %s", |
warnx("outdated mandoc.db lacks %s(%s) entry, run %s %s", |
name, sec, paths->paths[ipath]); |
name, sec, BINM_MAKEWHATIS, paths->paths[ipath]); |
#endif |
#endif |
*res = mandoc_reallocarray(*res, ++*ressz, sizeof(struct manpage)); |
*res = mandoc_reallocarray(*res, ++*ressz, sizeof(struct manpage)); |
page = *res + (*ressz - 1); |
page = *res + (*ressz - 1); |
Line 680 fs_search(const struct mansearch *cfg, const struct ma |
|
Line 684 fs_search(const struct mansearch *cfg, const struct ma |
|
int argc, char **argv, struct manpage **res, size_t *ressz) |
int argc, char **argv, struct manpage **res, size_t *ressz) |
{ |
{ |
const char *const sections[] = |
const char *const sections[] = |
{"1", "8", "6", "2", "3", "3p", "5", "7", "4", "9"}; |
{"1", "8", "6", "2", "3", "5", "7", "4", "9", "3p"}; |
const size_t nsec = sizeof(sections)/sizeof(sections[0]); |
const size_t nsec = sizeof(sections)/sizeof(sections[0]); |
|
|
size_t ipath, isec, lastsz; |
size_t ipath, isec, lastsz; |
Line 719 parse(struct curparse *curp, int fd, const char *file) |
|
Line 723 parse(struct curparse *curp, int fd, const char *file) |
|
/* Begin by parsing the file itself. */ |
/* Begin by parsing the file itself. */ |
|
|
assert(file); |
assert(file); |
assert(fd >= -1); |
assert(fd >= 0); |
|
|
rctmp = mparse_readfd(curp->mp, fd, file); |
rctmp = mparse_readfd(curp->mp, fd, file); |
|
if (fd != STDIN_FILENO) |
|
close(fd); |
if (rc < rctmp) |
if (rc < rctmp) |
rc = rctmp; |
rc = rctmp; |
|
|
Line 1015 mmsg(enum mandocerr t, enum mandoclevel lvl, |
|
Line 1021 mmsg(enum mandocerr t, enum mandoclevel lvl, |
|
static pid_t |
static pid_t |
spawn_pager(struct tag_files *tag_files) |
spawn_pager(struct tag_files *tag_files) |
{ |
{ |
|
const struct timespec timeout = { 0, 100000000 }; /* 0.1s */ |
#define MAX_PAGER_ARGS 16 |
#define MAX_PAGER_ARGS 16 |
char *argv[MAX_PAGER_ARGS]; |
char *argv[MAX_PAGER_ARGS]; |
const char *pager; |
const char *pager; |
Line 1048 spawn_pager(struct tag_files *tag_files) |
|
Line 1055 spawn_pager(struct tag_files *tag_files) |
|
break; |
break; |
} |
} |
|
|
/* For more(1) and less(1), use the tag file. */ |
/* For less(1), use the tag file. */ |
|
|
if ((cmdlen = strlen(argv[0])) >= 4) { |
if ((cmdlen = strlen(argv[0])) >= 4) { |
cp = argv[0] + cmdlen - 4; |
cp = argv[0] + cmdlen - 4; |
if (strcmp(cp, "less") == 0 || strcmp(cp, "more") == 0) { |
if (strcmp(cp, "less") == 0) { |
argv[argc++] = mandoc_strdup("-T"); |
argv[argc++] = mandoc_strdup("-T"); |
argv[argc++] = tag_files->tfn; |
argv[argc++] = tag_files->tfn; |
} |
} |
Line 1064 spawn_pager(struct tag_files *tag_files) |
|
Line 1071 spawn_pager(struct tag_files *tag_files) |
|
case -1: |
case -1: |
err((int)MANDOCLEVEL_SYSERR, "fork"); |
err((int)MANDOCLEVEL_SYSERR, "fork"); |
case 0: |
case 0: |
/* Set pgrp in both parent and child to avoid racing exec. */ |
|
(void)setpgid(0, 0); |
|
break; |
break; |
default: |
default: |
(void)setpgid(pager_pid, 0); |
(void)setpgid(pager_pid, 0); |
Line 1084 spawn_pager(struct tag_files *tag_files) |
|
Line 1089 spawn_pager(struct tag_files *tag_files) |
|
err((int)MANDOCLEVEL_SYSERR, "pager stdout"); |
err((int)MANDOCLEVEL_SYSERR, "pager stdout"); |
close(tag_files->ofd); |
close(tag_files->ofd); |
close(tag_files->tfd); |
close(tag_files->tfd); |
|
|
|
/* Do not start the pager before controlling the terminal. */ |
|
|
|
while (tcgetpgrp(STDIN_FILENO) != getpid()) |
|
nanosleep(&timeout, NULL); |
|
|
execvp(argv[0], argv); |
execvp(argv[0], argv); |
err((int)MANDOCLEVEL_SYSERR, "exec %s", argv[0]); |
err((int)MANDOCLEVEL_SYSERR, "exec %s", argv[0]); |
} |
} |