summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2014-03-19 21:51:00 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2014-03-19 21:51:00 +0000
commit6804cc5abb795c1c223e3529b538c92745486a52 (patch)
tree5b54ff84ac9a71ba8741ba0364cdf21f93ee5ff4 /usr.bin/mandoc
parent51c2e602a464552f9446900a6b07c47671b963fb (diff)
Generalize the mparse_alloc() and roff_alloc() functions by giving
them an "options" argument, replacing the existing "inttype" and "quick" arguments, preparing for a future MPARSE_SO option. Store this argument in struct mparse and struct roff, replacing the existing "inttype", "parsetype", and "quick" members. No functional change except one tiny cosmetic fix in roff_TH().
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r--usr.bin/mandoc/libmandoc.h6
-rw-r--r--usr.bin/mandoc/main.c22
-rw-r--r--usr.bin/mandoc/mandoc.h18
-rw-r--r--usr.bin/mandoc/mandocdb.c12
-rw-r--r--usr.bin/mandoc/read.c36
-rw-r--r--usr.bin/mandoc/roff.c14
6 files changed, 50 insertions, 58 deletions
diff --git a/usr.bin/mandoc/libmandoc.h b/usr.bin/mandoc/libmandoc.h
index 884a280d9f8..72f908b2fe5 100644
--- a/usr.bin/mandoc/libmandoc.h
+++ b/usr.bin/mandoc/libmandoc.h
@@ -1,7 +1,7 @@
-/* $Id: libmandoc.h,v 1.25 2014/01/06 21:33:00 schwarze Exp $ */
+/* $Id: libmandoc.h,v 1.26 2014/03/19 21:50:59 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -63,7 +63,7 @@ int man_addspan(struct man *, const struct tbl_span *);
int man_addeqn(struct man *, const struct eqn *);
void roff_free(struct roff *);
-struct roff *roff_alloc(enum mparset, struct mparse *, int);
+struct roff *roff_alloc(struct mparse *, int);
void roff_reset(struct roff *);
enum rofferr roff_parseln(struct roff *, int,
char **, size_t *, int, int *);
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
index fe49dcfed78..5e0e4c740f2 100644
--- a/usr.bin/mandoc/main.c
+++ b/usr.bin/mandoc/main.c
@@ -1,7 +1,7 @@
-/* $Id: main.c,v 1.86 2014/01/06 00:53:14 schwarze Exp $ */
+/* $Id: main.c,v 1.87 2014/03/19 21:50:59 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2011, 2012, 2014 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -61,7 +61,7 @@ struct curparse {
int apropos(int, char**);
int mandocdb(int, char**);
-static int moptions(enum mparset *, char *);
+static int moptions(int *, char *);
static void mmsg(enum mandocerr, enum mandoclevel,
const char *, int, int, const char *);
static void parse(struct curparse *, int,
@@ -78,7 +78,7 @@ main(int argc, char *argv[])
{
int c;
struct curparse curp;
- enum mparset type;
+ int options;
enum mandoclevel rc;
char *defos;
@@ -97,7 +97,7 @@ main(int argc, char *argv[])
memset(&curp, 0, sizeof(struct curparse));
- type = MPARSE_AUTO;
+ options = MPARSE_SO;
curp.outtype = OUTT_ASCII;
curp.wlevel = MANDOCLEVEL_FATAL;
defos = NULL;
@@ -119,7 +119,7 @@ main(int argc, char *argv[])
defos = mandoc_strdup(optarg + 3);
break;
case ('m'):
- if ( ! moptions(&type, optarg))
+ if ( ! moptions(&options, optarg))
return((int)MANDOCLEVEL_BADARG);
break;
case ('O'):
@@ -142,7 +142,7 @@ main(int argc, char *argv[])
/* NOTREACHED */
}
- curp.mp = mparse_alloc(type, curp.wlevel, mmsg, defos, 0);
+ curp.mp = mparse_alloc(options, curp.wlevel, mmsg, defos);
/*
* Conditionally start up the lookaside buffer before parsing.
@@ -313,15 +313,15 @@ parse(struct curparse *curp, int fd,
}
static int
-moptions(enum mparset *tflags, char *arg)
+moptions(int *options, char *arg)
{
if (0 == strcmp(arg, "doc"))
- *tflags = MPARSE_MDOC;
+ *options |= MPARSE_MDOC;
else if (0 == strcmp(arg, "andoc"))
- *tflags = MPARSE_AUTO;
+ /* nothing to do */;
else if (0 == strcmp(arg, "an"))
- *tflags = MPARSE_MAN;
+ *options |= MPARSE_MAN;
else {
fprintf(stderr, "%s: Bad argument\n", arg);
return(0);
diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h
index 14c5ed42d5b..0b655737ac2 100644
--- a/usr.bin/mandoc/mandoc.h
+++ b/usr.bin/mandoc/mandoc.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc.h,v 1.59 2014/01/22 20:58:35 schwarze Exp $ */
+/* $Id: mandoc.h,v 1.60 2014/03/19 21:50:59 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -372,15 +372,12 @@ struct eqn {
};
/*
- * The type of parse sequence. This value is usually passed via the
- * mandoc(1) command line of -man and -mdoc. It's almost exclusively
- * -mandoc but the others have been retained for compatibility.
+ * Parse options.
*/
-enum mparset {
- MPARSE_AUTO, /* magically determine the document type */
- MPARSE_MDOC, /* assume -mdoc */
- MPARSE_MAN /* assume -man */
-};
+#define MPARSE_MDOC 1 /* assume -mdoc */
+#define MPARSE_MAN 2 /* assume -man */
+#define MPARSE_SO 4 /* honour .so requests */
+#define MPARSE_QUICK 8 /* abort the parse early */
enum mandoc_esc {
ESCAPE_ERROR = 0, /* bail! unparsable escape */
@@ -422,8 +419,7 @@ int mchars_spec2cp(const struct mchars *,
const char *, size_t);
const char *mchars_spec2str(const struct mchars *,
const char *, size_t, size_t *);
-struct mparse *mparse_alloc(enum mparset, enum mandoclevel,
- mandocmsg, char *, int);
+struct mparse *mparse_alloc(int, enum mandoclevel, mandocmsg, char *);
void mparse_free(struct mparse *);
void mparse_keep(struct mparse *);
enum mandoclevel mparse_readfd(struct mparse *, int, const char *);
diff --git a/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c
index fc10814aad2..fd0916f9921 100644
--- a/usr.bin/mandoc/mandocdb.c
+++ b/usr.bin/mandoc/mandocdb.c
@@ -1,4 +1,4 @@
-/* $Id: mandocdb.c,v 1.72 2014/03/18 16:56:06 schwarze Exp $ */
+/* $Id: mandocdb.c,v 1.73 2014/03/19 21:50:59 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -164,7 +164,7 @@ static size_t utf8(unsigned int, char [7]);
static char tempfilename[32];
static char *progname;
static int nodb; /* no database changes */
-static int quick; /* abort the parse early */
+static int mparse_options; /* abort the parse early */
static int use_all; /* use all found files */
static int verb; /* print what we're doing */
static int warnings; /* warn about crap */
@@ -343,6 +343,7 @@ mandocdb(int argc, char *argv[])
path_arg = NULL;
op = OP_DEFAULT;
+ mparse_options = MPARSE_SO;
while (-1 != (ch = getopt(argc, argv, "aC:d:nQT:tu:vW")))
switch (ch) {
@@ -363,7 +364,7 @@ mandocdb(int argc, char *argv[])
nodb = 1;
break;
case ('Q'):
- quick = 1;
+ mparse_options |= MPARSE_QUICK;
break;
case ('T'):
if (strcmp(optarg, "utf8")) {
@@ -403,8 +404,7 @@ mandocdb(int argc, char *argv[])
}
exitcode = (int)MANDOCLEVEL_OK;
- mp = mparse_alloc(MPARSE_AUTO,
- MANDOCLEVEL_FATAL, NULL, NULL, quick);
+ mp = mparse_alloc(mparse_options, MANDOCLEVEL_FATAL, NULL, NULL);
mc = mchars_alloc();
ohash_init(&mpages, 6, &mpages_info);
@@ -1977,7 +1977,7 @@ dbopen(int real)
rc = sqlite3_open_v2(MANDOC_DB "~", &db, ofl, NULL);
if (SQLITE_OK == rc)
goto create_tables;
- if (quick) {
+ if (MPARSE_QUICK & mparse_options) {
exitcode = (int)MANDOCLEVEL_SYSERR;
say(MANDOC_DB "~", "%s", sqlite3_errmsg(db));
return(0);
diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c
index efdb0aa7cab..586840b514b 100644
--- a/usr.bin/mandoc/read.c
+++ b/usr.bin/mandoc/read.c
@@ -1,4 +1,4 @@
-/* $Id: read.c,v 1.21 2014/01/06 21:33:00 schwarze Exp $ */
+/* $Id: read.c,v 1.22 2014/03/19 21:50:59 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -45,7 +45,7 @@ struct mparse {
enum mandoclevel file_status; /* status of current parse */
enum mandoclevel wlevel; /* ignore messages below this */
int line; /* line number in the file */
- enum mparset inttype; /* which parser to use */
+ int options; /* parser options */
struct man *pman; /* persistent man parser */
struct mdoc *pmdoc; /* persistent mdoc parser */
struct man *man; /* man parser */
@@ -56,7 +56,6 @@ struct mparse {
const char *file;
struct buf *secondary;
char *defos; /* default operating system */
- int quick; /* abort the parse early */
};
static void resize_buf(struct buf *, size_t);
@@ -247,36 +246,36 @@ pset(const char *buf, int pos, struct mparse *curp)
return;
}
- switch (curp->inttype) {
- case (MPARSE_MDOC):
+ if (MPARSE_MDOC & curp->options) {
if (NULL == curp->pmdoc)
- curp->pmdoc = mdoc_alloc(curp->roff, curp,
- curp->defos, curp->quick);
+ curp->pmdoc = mdoc_alloc(
+ curp->roff, curp, curp->defos,
+ MPARSE_QUICK & curp->options ? 1 : 0);
assert(curp->pmdoc);
curp->mdoc = curp->pmdoc;
return;
- case (MPARSE_MAN):
+ } else if (MPARSE_MAN & curp->options) {
if (NULL == curp->pman)
curp->pman = man_alloc(curp->roff, curp,
- curp->quick);
+ MPARSE_QUICK & curp->options ? 1 : 0);
assert(curp->pman);
curp->man = curp->pman;
return;
- default:
- break;
}
if (pos >= 3 && 0 == memcmp(buf, ".Dd", 3)) {
if (NULL == curp->pmdoc)
- curp->pmdoc = mdoc_alloc(curp->roff, curp,
- curp->defos, curp->quick);
+ curp->pmdoc = mdoc_alloc(
+ curp->roff, curp, curp->defos,
+ MPARSE_QUICK & curp->options ? 1 : 0);
assert(curp->pmdoc);
curp->mdoc = curp->pmdoc;
return;
}
if (NULL == curp->pman)
- curp->pman = man_alloc(curp->roff, curp, curp->quick);
+ curp->pman = man_alloc(curp->roff, curp,
+ MPARSE_QUICK & curp->options ? 1 : 0);
assert(curp->pman);
curp->man = curp->pman;
}
@@ -740,8 +739,8 @@ out:
}
struct mparse *
-mparse_alloc(enum mparset inttype, enum mandoclevel wlevel,
- mandocmsg mmsg, char *defos, int quick)
+mparse_alloc(int options, enum mandoclevel wlevel,
+ mandocmsg mmsg, char *defos)
{
struct mparse *curp;
@@ -749,13 +748,12 @@ mparse_alloc(enum mparset inttype, enum mandoclevel wlevel,
curp = mandoc_calloc(1, sizeof(struct mparse));
+ curp->options = options;
curp->wlevel = wlevel;
curp->mmsg = mmsg;
- curp->inttype = inttype;
curp->defos = defos;
- curp->quick = quick;
- curp->roff = roff_alloc(inttype, curp, curp->quick);
+ curp->roff = roff_alloc(curp, options);
return(curp);
}
diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c
index d9994f642a8..9a9f8770705 100644
--- a/usr.bin/mandoc/roff.c
+++ b/usr.bin/mandoc/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.71 2014/03/08 04:43:39 schwarze Exp $ */
+/* $Id: roff.c,v 1.72 2014/03/19 21:50:59 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -99,9 +99,8 @@ struct roffreg {
};
struct roff {
- enum mparset parsetype; /* requested parse type */
struct mparse *parse; /* parse point */
- int quick; /* skip standard macro deletion */
+ int options; /* parse options */
struct roffnode *last; /* leaf of stack */
int rstack[RSTACK_MAX]; /* stack of !`ie' rules */
char control; /* control character */
@@ -459,14 +458,13 @@ roff_free(struct roff *r)
struct roff *
-roff_alloc(enum mparset type, struct mparse *parse, int quick)
+roff_alloc(struct mparse *parse, int options)
{
struct roff *r;
r = mandoc_calloc(1, sizeof(struct roff));
- r->parsetype = type;
r->parse = parse;
- r->quick = quick;
+ r->options = options;
r->rstackpos = -1;
roffhash_init();
@@ -1548,7 +1546,7 @@ roff_Dd(ROFF_ARGS)
{
const char *const *cp;
- if (0 == r->quick && MPARSE_MDOC != r->parsetype)
+ if (0 == ((MPARSE_MDOC | MPARSE_QUICK) & r->options))
for (cp = __mdoc_reserved; *cp; cp++)
roff_setstr(r, *cp, NULL, 0);
@@ -1561,7 +1559,7 @@ roff_TH(ROFF_ARGS)
{
const char *const *cp;
- if (0 == r->quick && MPARSE_MDOC != r->parsetype)
+ if (0 == (MPARSE_QUICK & r->options))
for (cp = __man_reserved; *cp; cp++)
roff_setstr(r, *cp, NULL, 0);