version 1.206, 2014/12/15 18:05:57 |
version 1.212, 2015/01/13 13:22:22 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010, 2011, 2012, 2014 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010-2012, 2014, 2015 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 |
Line 114 main(int argc, char *argv[]) |
|
Line 114 main(int argc, char *argv[]) |
|
struct manpaths paths; |
struct manpaths paths; |
char *auxpaths; |
char *auxpaths; |
char *defos; |
char *defos; |
|
unsigned char *uc; |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
struct manpage *res, *resp; |
struct manpage *res, *resp; |
char *conf_file, *defpaths; |
char *conf_file, *defpaths; |
Line 205 main(int argc, char *argv[]) |
|
Line 206 main(int argc, char *argv[]) |
|
case 'I': |
case 'I': |
if (strncmp(optarg, "os=", 3)) { |
if (strncmp(optarg, "os=", 3)) { |
fprintf(stderr, |
fprintf(stderr, |
"%s: -I%s: Bad argument\n", |
"%s: -I %s: Bad argument\n", |
progname, optarg); |
progname, optarg); |
return((int)MANDOCLEVEL_BADARG); |
return((int)MANDOCLEVEL_BADARG); |
} |
} |
if (defos) { |
if (defos) { |
fprintf(stderr, |
fprintf(stderr, |
"%s: -I%s: Duplicate argument\n", |
"%s: -I %s: Duplicate argument\n", |
progname, optarg); |
progname, optarg); |
return((int)MANDOCLEVEL_BADARG); |
return((int)MANDOCLEVEL_BADARG); |
} |
} |
Line 309 main(int argc, char *argv[]) |
|
Line 310 main(int argc, char *argv[]) |
|
argv = help_argv; |
argv = help_argv; |
argc = 1; |
argc = 1; |
} |
} |
} else if (argv[0] != NULL && ( |
} else if (argc > 1 && |
(isdigit((unsigned char)argv[0][0]) && |
((uc = argv[0]) != NULL) && |
(argv[0][1] == '\0' || !strcmp(argv[0], "3p"))) || |
((isdigit(uc[0]) && (uc[1] == '\0' || |
(argv[0][0] == 'n' && argv[0][1] == '\0'))) { |
(isalpha(uc[1]) && uc[2] == '\0'))) || |
search.sec = argv[0]; |
(uc[0] == 'n' && uc[1] == '\0'))) { |
|
search.sec = uc; |
argv++; |
argv++; |
argc--; |
argc--; |
} |
} |
Line 400 main(int argc, char *argv[]) |
|
Line 402 main(int argc, char *argv[]) |
|
|
|
/* mandoc(1) */ |
/* mandoc(1) */ |
|
|
if ( ! moptions(&options, auxpaths)) |
if (search.argmode == ARG_FILE && ! moptions(&options, auxpaths)) |
return((int)MANDOCLEVEL_BADARG); |
return((int)MANDOCLEVEL_BADARG); |
|
|
if (use_pager && isatty(STDOUT_FILENO)) |
|
spawn_pager(); |
|
|
|
curp.mchars = mchars_alloc(); |
curp.mchars = mchars_alloc(); |
curp.mp = mparse_alloc(options, curp.wlevel, mmsg, |
curp.mp = mparse_alloc(options, curp.wlevel, mmsg, |
curp.mchars, defos); |
curp.mchars, defos); |
Line 416 main(int argc, char *argv[]) |
|
Line 415 main(int argc, char *argv[]) |
|
if (OUTT_MAN == curp.outtype) |
if (OUTT_MAN == curp.outtype) |
mparse_keep(curp.mp); |
mparse_keep(curp.mp); |
|
|
if (argc == 0) |
if (argc == 0) { |
|
if (use_pager && isatty(STDOUT_FILENO)) |
|
spawn_pager(); |
parse(&curp, STDIN_FILENO, "<stdin>", &rc); |
parse(&curp, STDIN_FILENO, "<stdin>", &rc); |
|
} |
|
|
while (argc) { |
while (argc) { |
|
rc = mparse_open(curp.mp, &fd, |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
if (resp != NULL) { |
resp != NULL ? resp->file : |
rc = mparse_open(curp.mp, &fd, resp->file); |
#endif |
if (fd == -1) |
*argv); |
/* nothing */; |
|
|
if (fd != -1) { |
|
if (use_pager && isatty(STDOUT_FILENO)) |
|
spawn_pager(); |
|
use_pager = 0; |
|
|
|
#if HAVE_SQLITE3 |
|
if (resp == NULL) |
|
#endif |
|
parse(&curp, fd, *argv, &rc); |
|
#if HAVE_SQLITE3 |
else if (resp->form & FORM_SRC) { |
else if (resp->form & FORM_SRC) { |
/* For .so only; ignore failure. */ |
/* For .so only; ignore failure. */ |
chdir(paths.paths[resp->ipath]); |
chdir(paths.paths[resp->ipath]); |
Line 432 main(int argc, char *argv[]) |
|
Line 445 main(int argc, char *argv[]) |
|
} else |
} else |
rc = passthrough(resp->file, fd, |
rc = passthrough(resp->file, fd, |
synopsis_only); |
synopsis_only); |
resp++; |
|
} else |
|
#endif |
#endif |
{ |
|
rc = mparse_open(curp.mp, &fd, *argv++); |
|
if (fd != -1) |
|
parse(&curp, fd, argv[-1], &rc); |
|
} |
|
|
|
if (mparse_wait(curp.mp) != MANDOCLEVEL_OK) |
if (mparse_wait(curp.mp) != MANDOCLEVEL_OK) |
rc = MANDOCLEVEL_SYSERR; |
rc = MANDOCLEVEL_SYSERR; |
|
|
|
if (argc > 1 && curp.outtype <= OUTT_UTF8) |
|
ascii_sepline(curp.outdata); |
|
} |
|
|
if (MANDOCLEVEL_OK != rc && curp.wstop) |
if (MANDOCLEVEL_OK != rc && curp.wstop) |
break; |
break; |
argc--; |
|
|
#if HAVE_SQLITE3 |
|
if (resp != NULL) |
|
resp++; |
|
else |
|
#endif |
|
argv++; |
|
if (--argc) |
|
mparse_reset(curp.mp); |
} |
} |
|
|
if (curp.outfree) |
if (curp.outfree) |
Line 487 usage(enum argmode argmode) |
|
Line 505 usage(enum argmode argmode) |
|
"\t [-Toutput] [-Wlevel] [file ...]\n", stderr); |
"\t [-Toutput] [-Wlevel] [file ...]\n", stderr); |
break; |
break; |
case ARG_NAME: |
case ARG_NAME: |
fputs("usage: man [-acfhklVw] [-C file] " |
fputs("usage: man [-acfhklVw] [-C file] [-I os=name] " |
"[-M path] [-m path] [-S arch] [-s section]\n" |
"[-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); |
"\t [section] name ...\n", stderr); |
break; |
break; |
case ARG_WORD: |
case ARG_WORD: |
Line 610 parse(struct curparse *curp, int fd, const char *file, |
|
Line 630 parse(struct curparse *curp, int fd, const char *file, |
|
if (mdoc && curp->outmdoc) |
if (mdoc && curp->outmdoc) |
(*curp->outmdoc)(curp->outdata, mdoc); |
(*curp->outmdoc)(curp->outdata, mdoc); |
|
|
cleanup: |
cleanup: |
|
|
mparse_reset(curp->mp); |
|
|
|
if (*level < rc) |
if (*level < rc) |
*level = rc; |
*level = rc; |
} |
} |
Line 632 passthrough(const char *file, int fd, int synopsis_onl |
|
Line 649 passthrough(const char *file, int fd, int synopsis_onl |
|
ssize_t nw; |
ssize_t nw; |
int print; |
int print; |
|
|
|
fflush(stdout); |
|
|
if ((stream = fdopen(fd, "r")) == NULL) { |
if ((stream = fdopen(fd, "r")) == NULL) { |
close(fd); |
close(fd); |
syscall = "fdopen"; |
syscall = "fdopen"; |
Line 697 koptions(int *options, char *arg) |
|
Line 716 koptions(int *options, char *arg) |
|
} else if ( ! strcmp(arg, "us-ascii")) { |
} else if ( ! strcmp(arg, "us-ascii")) { |
*options &= ~(MPARSE_UTF8 | MPARSE_LATIN1); |
*options &= ~(MPARSE_UTF8 | MPARSE_LATIN1); |
} else { |
} else { |
fprintf(stderr, "%s: -K%s: Bad argument\n", |
fprintf(stderr, "%s: -K %s: Bad argument\n", |
progname, arg); |
progname, arg); |
return(0); |
return(0); |
} |
} |
Line 717 moptions(int *options, char *arg) |
|
Line 736 moptions(int *options, char *arg) |
|
else if (0 == strcmp(arg, "an")) |
else if (0 == strcmp(arg, "an")) |
*options |= MPARSE_MAN; |
*options |= MPARSE_MAN; |
else { |
else { |
fprintf(stderr, "%s: -m%s: Bad argument\n", |
fprintf(stderr, "%s: -m %s: Bad argument\n", |
progname, arg); |
progname, arg); |
return(0); |
return(0); |
} |
} |
Line 751 toptions(struct curparse *curp, char *arg) |
|
Line 770 toptions(struct curparse *curp, char *arg) |
|
else if (0 == strcmp(arg, "pdf")) |
else if (0 == strcmp(arg, "pdf")) |
curp->outtype = OUTT_PDF; |
curp->outtype = OUTT_PDF; |
else { |
else { |
fprintf(stderr, "%s: -T%s: Bad argument\n", |
fprintf(stderr, "%s: -T %s: Bad argument\n", |
progname, arg); |
progname, arg); |
return(0); |
return(0); |
} |
} |
Line 790 woptions(struct curparse *curp, char *arg) |
|
Line 809 woptions(struct curparse *curp, char *arg) |
|
curp->wlevel = MANDOCLEVEL_FATAL; |
curp->wlevel = MANDOCLEVEL_FATAL; |
break; |
break; |
default: |
default: |
fprintf(stderr, "%s: -W%s: Bad argument\n", |
fprintf(stderr, "%s: -W %s: Bad argument\n", |
progname, o); |
progname, o); |
return(0); |
return(0); |
} |
} |