version 1.205, 2015/10/22 22:06:43 |
version 1.211, 2016/01/04 14:44:57 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2011-2015 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2011-2016 Ingo Schwarze <schwarze@openbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
|
|
#include <assert.h> |
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
|
#if HAVE_ERR |
#include <err.h> |
#include <err.h> |
|
#endif |
#include <errno.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#if HAVE_FTS |
#if HAVE_FTS |
Line 154 static void parse_man(struct mpage *, const struct ro |
|
Line 156 static void parse_man(struct mpage *, const struct ro |
|
const struct roff_node *); |
const struct roff_node *); |
static void parse_mdoc(struct mpage *, const struct roff_meta *, |
static void parse_mdoc(struct mpage *, const struct roff_meta *, |
const struct roff_node *); |
const struct roff_node *); |
static int parse_mdoc_body(struct mpage *, const struct roff_meta *, |
|
const struct roff_node *); |
|
static int parse_mdoc_head(struct mpage *, const struct roff_meta *, |
static int parse_mdoc_head(struct mpage *, const struct roff_meta *, |
const struct roff_node *); |
const struct roff_node *); |
static int parse_mdoc_Fd(struct mpage *, const struct roff_meta *, |
static int parse_mdoc_Fd(struct mpage *, const struct roff_meta *, |
Line 171 static int parse_mdoc_Nm(struct mpage *, const struct |
|
Line 171 static int parse_mdoc_Nm(struct mpage *, const struct |
|
const struct roff_node *); |
const struct roff_node *); |
static int parse_mdoc_Sh(struct mpage *, const struct roff_meta *, |
static int parse_mdoc_Sh(struct mpage *, const struct roff_meta *, |
const struct roff_node *); |
const struct roff_node *); |
|
static int parse_mdoc_Va(struct mpage *, const struct roff_meta *, |
|
const struct roff_node *); |
static int parse_mdoc_Xr(struct mpage *, const struct roff_meta *, |
static int parse_mdoc_Xr(struct mpage *, const struct roff_meta *, |
const struct roff_node *); |
const struct roff_node *); |
static void putkey(const struct mpage *, char *, uint64_t); |
static void putkey(const struct mpage *, char *, uint64_t); |
Line 183 static int set_basedir(const char *, int); |
|
Line 185 static int set_basedir(const char *, int); |
|
static int treescan(void); |
static int treescan(void); |
static size_t utf8(unsigned int, char [7]); |
static size_t utf8(unsigned int, char [7]); |
|
|
extern char *__progname; |
|
|
|
static char tempfilename[32]; |
static char tempfilename[32]; |
static int nodb; /* no database changes */ |
static int nodb; /* no database changes */ |
static int mparse_options; /* abort the parse early */ |
static int mparse_options; /* abort the parse early */ |
Line 242 static const struct mdoc_handler mdocs[MDOC_MAX] = { |
|
Line 242 static const struct mdoc_handler mdocs[MDOC_MAX] = { |
|
{ NULL, TYPE_Pa }, /* Pa */ |
{ NULL, TYPE_Pa }, /* Pa */ |
{ NULL, 0 }, /* Rv */ |
{ NULL, 0 }, /* Rv */ |
{ NULL, TYPE_St }, /* St */ |
{ NULL, TYPE_St }, /* St */ |
{ NULL, TYPE_Va }, /* Va */ |
{ parse_mdoc_Va, TYPE_Va }, /* Va */ |
{ parse_mdoc_body, TYPE_Va }, /* Vt */ |
{ parse_mdoc_Va, TYPE_Vt }, /* Vt */ |
{ parse_mdoc_Xr, 0 }, /* Xr */ |
{ parse_mdoc_Xr, 0 }, /* Xr */ |
{ NULL, 0 }, /* %A */ |
{ NULL, 0 }, /* %A */ |
{ NULL, 0 }, /* %B */ |
{ NULL, 0 }, /* %B */ |
Line 335 mandocdb(int argc, char *argv[]) |
|
Line 335 mandocdb(int argc, char *argv[]) |
|
{ |
{ |
struct manconf conf; |
struct manconf conf; |
struct mparse *mp; |
struct mparse *mp; |
const char *path_arg; |
const char *path_arg, *progname; |
size_t j, sz; |
size_t j, sz; |
int ch, i; |
int ch, i; |
|
|
|
#if HAVE_PLEDGE |
|
if (pledge("stdio rpath wpath cpath fattr flock proc exec", NULL) == -1) { |
|
perror("pledge"); |
|
return (int)MANDOCLEVEL_SYSERR; |
|
} |
|
#endif |
|
|
memset(&conf, 0, sizeof(conf)); |
memset(&conf, 0, sizeof(conf)); |
memset(stmts, 0, STMT__MAX * sizeof(sqlite3_stmt *)); |
memset(stmts, 0, STMT__MAX * sizeof(sqlite3_stmt *)); |
|
|
Line 412 mandocdb(int argc, char *argv[]) |
|
Line 419 mandocdb(int argc, char *argv[]) |
|
argc -= optind; |
argc -= optind; |
argv += optind; |
argv += optind; |
|
|
|
#if HAVE_PLEDGE |
|
if (nodb) { |
|
if (pledge("stdio rpath", NULL) == -1) { |
|
perror("pledge"); |
|
return (int)MANDOCLEVEL_SYSERR; |
|
} |
|
} |
|
#endif |
|
|
if (OP_CONFFILE == op && argc > 0) { |
if (OP_CONFFILE == op && argc > 0) { |
warnx("-C: Too many arguments"); |
warnx("-C: Too many arguments"); |
goto usage; |
goto usage; |
Line 437 mandocdb(int argc, char *argv[]) |
|
Line 453 mandocdb(int argc, char *argv[]) |
|
* The existing database is usable. Process |
* The existing database is usable. Process |
* all files specified on the command-line. |
* all files specified on the command-line. |
*/ |
*/ |
|
#if HAVE_PLEDGE |
|
if (!nodb) { |
|
if (pledge("stdio rpath wpath cpath fattr flock", NULL) == -1) { |
|
perror("pledge"); |
|
exitcode = (int)MANDOCLEVEL_SYSERR; |
|
goto out; |
|
} |
|
} |
|
#endif |
use_all = 1; |
use_all = 1; |
for (i = 0; i < argc; i++) |
for (i = 0; i < argc; i++) |
filescan(argv[i]); |
filescan(argv[i]); |
|
|
ohash_delete(&mlinks); |
ohash_delete(&mlinks); |
return exitcode; |
return exitcode; |
usage: |
usage: |
|
progname = getprogname(); |
fprintf(stderr, "usage: %s [-aDnpQ] [-C file] [-Tutf8]\n" |
fprintf(stderr, "usage: %s [-aDnpQ] [-C file] [-Tutf8]\n" |
" %s [-aDnpQ] [-Tutf8] dir ...\n" |
" %s [-aDnpQ] [-Tutf8] dir ...\n" |
" %s [-DnpQ] [-Tutf8] -d dir [file ...]\n" |
" %s [-DnpQ] [-Tutf8] -d dir [file ...]\n" |
" %s [-Dnp] -u dir [file ...]\n" |
" %s [-Dnp] -u dir [file ...]\n" |
" %s [-Q] -t file ...\n", |
" %s [-Q] -t file ...\n", |
__progname, __progname, __progname, |
progname, progname, progname, progname, progname); |
__progname, __progname); |
|
|
|
return (int)MANDOCLEVEL_BADARG; |
return (int)MANDOCLEVEL_BADARG; |
} |
} |
Line 1269 parse_cat(struct mpage *mpage, int fd) |
|
Line 1294 parse_cat(struct mpage *mpage, int fd) |
|
{ |
{ |
FILE *stream; |
FILE *stream; |
char *line, *p, *title; |
char *line, *p, *title; |
size_t len, plen, titlesz; |
size_t linesz, plen, titlesz; |
|
ssize_t len; |
|
int offs; |
|
|
stream = (-1 == fd) ? |
stream = (-1 == fd) ? |
fopen(mpage->mlinks->file, "r") : |
fopen(mpage->mlinks->file, "r") : |
Line 1282 parse_cat(struct mpage *mpage, int fd) |
|
Line 1309 parse_cat(struct mpage *mpage, int fd) |
|
return; |
return; |
} |
} |
|
|
|
line = NULL; |
|
linesz = 0; |
|
|
/* Skip to first blank line. */ |
/* Skip to first blank line. */ |
|
|
while (NULL != (line = fgetln(stream, &len))) |
while (getline(&line, &linesz, stream) != -1) |
if ('\n' == *line) |
if (*line == '\n') |
break; |
break; |
|
|
/* |
/* |
Line 1293 parse_cat(struct mpage *mpage, int fd) |
|
Line 1323 parse_cat(struct mpage *mpage, int fd) |
|
* is the first section header. Skip to it. |
* is the first section header. Skip to it. |
*/ |
*/ |
|
|
while (NULL != (line = fgetln(stream, &len))) |
while (getline(&line, &linesz, stream) != -1) |
if ('\n' != *line && ' ' != *line) |
if (*line != '\n' && *line != ' ') |
break; |
break; |
|
|
/* |
/* |
Line 1307 parse_cat(struct mpage *mpage, int fd) |
|
Line 1337 parse_cat(struct mpage *mpage, int fd) |
|
titlesz = 0; |
titlesz = 0; |
title = NULL; |
title = NULL; |
|
|
while (NULL != (line = fgetln(stream, &len))) { |
while ((len = getline(&line, &linesz, stream)) != -1) { |
if (' ' != *line || '\n' != line[len - 1]) |
if (*line != ' ') |
break; |
break; |
while (len > 0 && isspace((unsigned char)*line)) { |
offs = 0; |
line++; |
while (isspace((unsigned char)line[offs])) |
len--; |
offs++; |
} |
if (line[offs] == '\0') |
if (1 == len) |
|
continue; |
continue; |
title = mandoc_realloc(title, titlesz + len); |
title = mandoc_realloc(title, titlesz + len - offs); |
memcpy(title + titlesz, line, len); |
memcpy(title + titlesz, line + offs, len - offs); |
titlesz += len; |
titlesz += len - offs; |
title[titlesz - 1] = ' '; |
title[titlesz - 1] = ' '; |
} |
} |
|
free(line); |
|
|
/* |
/* |
* If no page content can be found, or the input line |
* If no page content can be found, or the input line |
Line 1338 parse_cat(struct mpage *mpage, int fd) |
|
Line 1368 parse_cat(struct mpage *mpage, int fd) |
|
return; |
return; |
} |
} |
|
|
title = mandoc_realloc(title, titlesz + 1); |
title[titlesz - 1] = '\0'; |
title[titlesz] = '\0'; |
|
|
|
/* |
/* |
* Skip to the first dash. |
* Skip to the first dash. |
Line 1660 parse_mdoc_Fo(struct mpage *mpage, const struct roff_m |
|
Line 1689 parse_mdoc_Fo(struct mpage *mpage, const struct roff_m |
|
} |
} |
|
|
static int |
static int |
|
parse_mdoc_Va(struct mpage *mpage, const struct roff_meta *meta, |
|
const struct roff_node *n) |
|
{ |
|
char *cp; |
|
|
|
if (n->type != ROFFT_ELEM && n->type != ROFFT_BODY) |
|
return 0; |
|
|
|
if (n->nchild == 1 && n->child->type == ROFFT_TEXT) |
|
return 1; |
|
|
|
cp = NULL; |
|
deroff(&cp, n); |
|
if (cp != NULL) { |
|
putkey(mpage, cp, TYPE_Vt | (n->tok == MDOC_Va || |
|
n->type == ROFFT_BODY ? TYPE_Va : 0)); |
|
free(cp); |
|
} |
|
|
|
return 0; |
|
} |
|
|
|
static int |
parse_mdoc_Xr(struct mpage *mpage, const struct roff_meta *meta, |
parse_mdoc_Xr(struct mpage *mpage, const struct roff_meta *meta, |
const struct roff_node *n) |
const struct roff_node *n) |
{ |
{ |
Line 1725 parse_mdoc_head(struct mpage *mpage, const struct roff |
|
Line 1777 parse_mdoc_head(struct mpage *mpage, const struct roff |
|
{ |
{ |
|
|
return n->type == ROFFT_HEAD; |
return n->type == ROFFT_HEAD; |
} |
|
|
|
static int |
|
parse_mdoc_body(struct mpage *mpage, const struct roff_meta *meta, |
|
const struct roff_node *n) |
|
{ |
|
|
|
return n->type == ROFFT_BODY; |
|
} |
} |
|
|
/* |
/* |