version 1.333, 2019/07/26 18:01:43 |
version 1.334, 2019/07/26 21:03:19 |
|
|
}; |
}; |
|
|
struct curparse { |
struct curparse { |
struct mparse *mp; |
|
struct manoutput *outopts; /* output options */ |
struct manoutput *outopts; /* output options */ |
void *outdata; /* data for output */ |
void *outdata; /* data for output */ |
char *os_s; /* operating system for display */ |
|
int wstop; /* stop after a file with a warning */ |
int wstop; /* stop after a file with a warning */ |
enum mandoc_os os_e; /* check base system conventions */ |
|
enum outt outtype; /* which output to use */ |
enum outt outtype; /* which output to use */ |
}; |
}; |
|
|
Line 99 static int fs_search(const struct mansearch *, |
|
Line 96 static int fs_search(const struct mansearch *, |
|
const struct manpaths *, int, char**, |
const struct manpaths *, int, char**, |
struct manpage **, size_t *); |
struct manpage **, size_t *); |
static void outdata_alloc(struct curparse *); |
static void outdata_alloc(struct curparse *); |
static void parse(struct curparse *, int, const char *); |
static void parse(struct mparse *, int, const char *, |
|
struct curparse *); |
static void passthrough(int, int); |
static void passthrough(int, int); |
static void run_pager(struct tag_files *); |
static void run_pager(struct tag_files *); |
static pid_t spawn_pager(struct tag_files *); |
static pid_t spawn_pager(struct tag_files *); |
static void usage(enum argmode) __attribute__((__noreturn__)); |
static void usage(enum argmode) __attribute__((__noreturn__)); |
static int woptions(struct curparse *, char *); |
static int woptions(char *, enum mandoc_os *, int *); |
|
|
static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9}; |
static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9}; |
static char help_arg[] = "help"; |
static char help_arg[] = "help"; |
Line 114 static char *help_argv[] = {help_arg, NULL}; |
|
Line 112 static char *help_argv[] = {help_arg, NULL}; |
|
int |
int |
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
{ |
{ |
struct manconf conf; |
struct manconf conf; /* Manpaths and output options. */ |
struct mansearch search; |
|
struct curparse curp; |
struct curparse curp; |
struct winsize ws; |
struct winsize ws; /* Result of ioctl(TIOCGWINSZ). */ |
struct tag_files *tag_files; |
struct mansearch search; /* Search options. */ |
struct manpage *res, *resp; |
struct manpage *res, *resp; /* Search results. */ |
|
struct mparse *mp; /* Opaque parser object. */ |
|
struct tag_files *tag_files; /* Tagging state variables. */ |
|
const char *conf_file; /* -C: alternate config file. */ |
|
const char *os_s; /* -I: Operating system for display. */ |
const char *progname, *sec, *thisarg; |
const char *progname, *sec, *thisarg; |
char *conf_file, *defpaths, *auxpaths; |
char *defpaths; /* -M: override manpaths. */ |
char *oarg, *tagarg; |
char *auxpaths; /* -m: additional manpaths. */ |
|
char *oarg; /* -O: output option string. */ |
|
char *tagarg; /* -O tag: default value. */ |
unsigned char *uc; |
unsigned char *uc; |
size_t i, sz, ssz; |
size_t sz; /* Number of elements in res[]. */ |
|
size_t i, ssz; |
|
int options; /* Parser options. */ |
|
int show_usage; /* Invalid argument: give up. */ |
|
int use_pager; /* According to command line. */ |
int prio, best_prio; |
int prio, best_prio; |
enum outmode outmode; |
|
int fd, startdir; |
int fd, startdir; |
int show_usage; |
|
int options; |
|
int use_pager; |
|
int c; |
int c; |
|
enum mandoc_os os_e; /* Check base system conventions. */ |
|
enum outmode outmode; /* According to command line. */ |
|
|
#if HAVE_PROGNAME |
#if HAVE_PROGNAME |
progname = getprogname(); |
progname = getprogname(); |
Line 164 main(int argc, char *argv[]) |
|
Line 169 main(int argc, char *argv[]) |
|
/* Search options. */ |
/* Search options. */ |
|
|
memset(&conf, 0, sizeof(conf)); |
memset(&conf, 0, sizeof(conf)); |
conf_file = defpaths = NULL; |
conf_file = NULL; |
auxpaths = NULL; |
defpaths = auxpaths = NULL; |
|
|
memset(&search, 0, sizeof(struct mansearch)); |
memset(&search, 0, sizeof(struct mansearch)); |
search.outkey = "Nd"; |
search.outkey = "Nd"; |
Line 184 main(int argc, char *argv[]) |
|
Line 189 main(int argc, char *argv[]) |
|
|
|
/* Parser and formatter options. */ |
/* Parser and formatter options. */ |
|
|
|
os_e = MANDOC_OS_OTHER; |
|
os_s = NULL; |
memset(&curp, 0, sizeof(struct curparse)); |
memset(&curp, 0, sizeof(struct curparse)); |
curp.outtype = OUTT_LOCALE; |
curp.outtype = OUTT_LOCALE; |
curp.outopts = &conf.output; |
curp.outopts = &conf.output; |
Line 224 main(int argc, char *argv[]) |
|
Line 231 main(int argc, char *argv[]) |
|
"-I %s", optarg); |
"-I %s", optarg); |
return mandoc_msg_getrc(); |
return mandoc_msg_getrc(); |
} |
} |
if (curp.os_s != NULL) { |
if (os_s != NULL) { |
mandoc_msg(MANDOCERR_BADARG_DUPE, 0, 0, |
mandoc_msg(MANDOCERR_BADARG_DUPE, 0, 0, |
"-I %s", optarg); |
"-I %s", optarg); |
return mandoc_msg_getrc(); |
return mandoc_msg_getrc(); |
} |
} |
curp.os_s = mandoc_strdup(optarg + 3); |
os_s = optarg + 3; |
break; |
break; |
case 'K': |
case 'K': |
options &= ~(MPARSE_UTF8 | MPARSE_LATIN1); |
options &= ~(MPARSE_UTF8 | MPARSE_LATIN1); |
Line 295 main(int argc, char *argv[]) |
|
Line 302 main(int argc, char *argv[]) |
|
} |
} |
break; |
break; |
case 'W': |
case 'W': |
if (woptions(&curp, optarg) == -1) |
if (woptions(optarg, &os_e, &curp.wstop) == -1) |
return mandoc_msg_getrc(); |
return mandoc_msg_getrc(); |
break; |
break; |
case 'w': |
case 'w': |
Line 548 main(int argc, char *argv[]) |
|
Line 555 main(int argc, char *argv[]) |
|
} |
} |
|
|
mchars_alloc(); |
mchars_alloc(); |
curp.mp = mparse_alloc(options, curp.os_e, curp.os_s); |
mp = mparse_alloc(options, os_e, os_s); |
|
|
if (argc < 1) { |
if (argc < 1) { |
if (use_pager) { |
if (use_pager) { |
Line 558 main(int argc, char *argv[]) |
|
Line 565 main(int argc, char *argv[]) |
|
} |
} |
thisarg = "<stdin>"; |
thisarg = "<stdin>"; |
mandoc_msg_setinfilename(thisarg); |
mandoc_msg_setinfilename(thisarg); |
parse(&curp, STDIN_FILENO, thisarg); |
parse(mp, STDIN_FILENO, thisarg, &curp); |
mandoc_msg_setinfilename(NULL); |
mandoc_msg_setinfilename(NULL); |
} |
} |
|
|
Line 588 main(int argc, char *argv[]) |
|
Line 595 main(int argc, char *argv[]) |
|
thisarg = *argv; |
thisarg = *argv; |
|
|
mandoc_msg_setinfilename(thisarg); |
mandoc_msg_setinfilename(thisarg); |
fd = mparse_open(curp.mp, thisarg); |
fd = mparse_open(mp, thisarg); |
if (fd != -1) { |
if (fd != -1) { |
if (use_pager) { |
if (use_pager) { |
use_pager = 0; |
use_pager = 0; |
Line 598 main(int argc, char *argv[]) |
|
Line 605 main(int argc, char *argv[]) |
|
} |
} |
|
|
if (resp == NULL || resp->form == FORM_SRC) |
if (resp == NULL || resp->form == FORM_SRC) |
parse(&curp, fd, thisarg); |
parse(mp, fd, thisarg, &curp); |
else |
else |
passthrough(fd, conf.output.synopsisonly); |
passthrough(fd, conf.output.synopsisonly); |
|
|
Line 634 main(int argc, char *argv[]) |
|
Line 641 main(int argc, char *argv[]) |
|
else |
else |
argv++; |
argv++; |
if (--argc) |
if (--argc) |
mparse_reset(curp.mp); |
mparse_reset(mp); |
} |
} |
if (startdir != -1) { |
if (startdir != -1) { |
(void)fchdir(startdir); |
(void)fchdir(startdir); |
Line 660 main(int argc, char *argv[]) |
|
Line 667 main(int argc, char *argv[]) |
|
} |
} |
} |
} |
mandoc_xr_free(); |
mandoc_xr_free(); |
mparse_free(curp.mp); |
mparse_free(mp); |
mchars_free(); |
mchars_free(); |
|
|
out: |
out: |
|
|
manconf_free(&conf); |
manconf_free(&conf); |
mansearch_free(res, sz); |
mansearch_free(res, sz); |
} |
} |
free(curp.os_s); |
|
|
|
if (tag_files != NULL) { |
if (tag_files != NULL) { |
fclose(stdout); |
fclose(stdout); |
Line 836 fs_search(const struct mansearch *cfg, const struct ma |
|
Line 842 fs_search(const struct mansearch *cfg, const struct ma |
|
} |
} |
|
|
static void |
static void |
parse(struct curparse *curp, int fd, const char *file) |
parse(struct mparse *mp, int fd, const char *file, struct curparse *curp) |
{ |
{ |
struct roff_meta *meta; |
struct roff_meta *meta; |
|
|
Line 845 parse(struct curparse *curp, int fd, const char *file) |
|
Line 851 parse(struct curparse *curp, int fd, const char *file) |
|
assert(file); |
assert(file); |
assert(fd >= 0); |
assert(fd >= 0); |
|
|
mparse_readfd(curp->mp, fd, file); |
mparse_readfd(mp, fd, file); |
if (fd != STDIN_FILENO) |
if (fd != STDIN_FILENO) |
close(fd); |
close(fd); |
|
|
Line 863 parse(struct curparse *curp, int fd, const char *file) |
|
Line 869 parse(struct curparse *curp, int fd, const char *file) |
|
html_reset(curp); |
html_reset(curp); |
|
|
mandoc_xr_reset(); |
mandoc_xr_reset(); |
meta = mparse_result(curp->mp); |
meta = mparse_result(mp); |
|
|
/* Execute the out device, if it exists. */ |
/* Execute the out device, if it exists. */ |
|
|
Line 901 parse(struct curparse *curp, int fd, const char *file) |
|
Line 907 parse(struct curparse *curp, int fd, const char *file) |
|
tree_man(curp->outdata, meta); |
tree_man(curp->outdata, meta); |
break; |
break; |
case OUTT_MAN: |
case OUTT_MAN: |
mparse_copy(curp->mp); |
mparse_copy(mp); |
break; |
break; |
case OUTT_PDF: |
case OUTT_PDF: |
case OUTT_ASCII: |
case OUTT_ASCII: |
|
|
} |
} |
|
|
static int |
static int |
woptions(struct curparse *curp, char *arg) |
woptions(char *arg, enum mandoc_os *os_e, int *wstop) |
{ |
{ |
char *v, *o; |
char *v, *o; |
const char *toks[11]; |
const char *toks[11]; |
Line 1062 woptions(struct curparse *curp, char *arg) |
|
Line 1068 woptions(struct curparse *curp, char *arg) |
|
o = arg; |
o = arg; |
switch (getsubopt(&arg, (char * const *)toks, &v)) { |
switch (getsubopt(&arg, (char * const *)toks, &v)) { |
case 0: |
case 0: |
curp->wstop = 1; |
*wstop = 1; |
break; |
break; |
case 1: |
case 1: |
case 2: |
case 2: |
Line 1085 woptions(struct curparse *curp, char *arg) |
|
Line 1091 woptions(struct curparse *curp, char *arg) |
|
break; |
break; |
case 8: |
case 8: |
mandoc_msg_setmin(MANDOCERR_BASE); |
mandoc_msg_setmin(MANDOCERR_BASE); |
curp->os_e = MANDOC_OS_OPENBSD; |
*os_e = MANDOC_OS_OPENBSD; |
break; |
break; |
case 9: |
case 9: |
mandoc_msg_setmin(MANDOCERR_BASE); |
mandoc_msg_setmin(MANDOCERR_BASE); |
curp->os_e = MANDOC_OS_NETBSD; |
*os_e = MANDOC_OS_NETBSD; |
break; |
break; |
default: |
default: |
mandoc_msg(MANDOCERR_BADARG_BAD, 0, 0, "-W %s", o); |
mandoc_msg(MANDOCERR_BADARG_BAD, 0, 0, "-W %s", o); |