summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmandoc.h4
-rw-r--r--main.c20
-rw-r--r--mandoc.h16
-rw-r--r--mandocdb.c10
-rw-r--r--read.c34
-rw-r--r--roff.c12
6 files changed, 44 insertions, 52 deletions
diff --git a/libmandoc.h b/libmandoc.h
index c3a71304..d10fed38 100644
--- a/libmandoc.h
+++ b/libmandoc.h
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* 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
@@ -66,7 +66,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/main.c b/main.c
index 712a6b8e..20d02e7a 100644
--- a/main.c
+++ b/main.c
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* 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
@@ -67,7 +67,7 @@ struct curparse {
char outopts[BUFSIZ]; /* buf of output opts */
};
-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,
@@ -84,7 +84,7 @@ main(int argc, char *argv[])
{
int c;
struct curparse curp;
- enum mparset type;
+ int options;
enum mandoclevel rc;
char *defos;
@@ -96,7 +96,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;
@@ -118,7 +118,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'):
@@ -141,7 +141,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.
@@ -312,15 +312,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/mandoc.h b/mandoc.h
index 1827ce6d..268ed343 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -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/mandocdb.c b/mandocdb.c
index d8315f93..6cf259a2 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -172,7 +172,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 */
@@ -351,6 +351,7 @@ main(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) {
@@ -371,7 +372,7 @@ main(int argc, char *argv[])
nodb = 1;
break;
case ('Q'):
- quick = 1;
+ mparse_options |= MPARSE_QUICK;
break;
case ('T'):
if (strcmp(optarg, "utf8")) {
@@ -411,8 +412,7 @@ main(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);
@@ -1985,7 +1985,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/read.c b/read.c
index 3ada7840..43e7a758 100644
--- a/read.c
+++ b/read.c
@@ -53,7 +53,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 */
@@ -64,7 +64,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);
@@ -255,36 +254,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;
}
@@ -765,8 +764,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;
@@ -774,13 +773,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/roff.c b/roff.c
index ecfaad61..28e14528 100644
--- a/roff.c
+++ b/roff.c
@@ -103,9 +103,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 */
@@ -463,14 +462,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();
@@ -1552,7 +1550,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);
@@ -1565,7 +1563,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);